瀏覽代碼

wip: move type declarations out of setup

Evan You 6 年之前
父節點
當前提交
a44d53003e
共有 1 個文件被更改,包括 8 次插入1 次删除
  1. 8 1
      packages/compiler-sfc/src/compileScript.ts

+ 8 - 1
packages/compiler-sfc/src/compileScript.ts

@@ -344,10 +344,17 @@ export function compileScriptSetup(
     ) {
       const index = node.id.start! + startOffset
       s.overwrite(index, index + emitVar.length, '__emit__')
-      s.move(start, end, 0)
       emitType = `typeof __emit__`
       extractEmits(node, typeDeclaredEmits)
     }
+
+    // move all type declarations to outer scope
+    if (
+      node.type.startsWith('TS') ||
+      (node.type === 'ExportNamedDeclaration' && node.exportKind === 'type')
+    ) {
+      s.move(start, end, 0)
+    }
   }
 
   // check default export to make sure it doesn't reference setup scope