From 1ffd48a2f5fd3eead3ea29dae668b7ed1c6f6130 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 30 Jun 2021 12:03:42 -0400 Subject: [PATCH] fix(compiler-sfc): support TS runtime enum in `` + ) + assertCode(content) + expect(bindings).toStrictEqual({ + Foo: BindingTypes.SETUP_CONST + }) + }) }) describe('async/await detection', () => { diff --git a/packages/compiler-sfc/src/compileScript.ts b/packages/compiler-sfc/src/compileScript.ts index ade6d2d2e03..bf4cec6719e 100644 --- a/packages/compiler-sfc/src/compileScript.ts +++ b/packages/compiler-sfc/src/compileScript.ts @@ -937,20 +937,6 @@ export function compileScript( walkDeclaration(node, setupBindings, userImportAlias) } - // Type declarations - if (node.type === 'VariableDeclaration' && node.declare) { - s.remove(start, end) - } - - // move all type declarations to outer scope - if ( - node.type.startsWith('TS') || - (node.type === 'ExportNamedDeclaration' && node.exportKind === 'type') - ) { - recordType(node, declaredTypes) - s.move(start, end, 0) - } - // walk statements & named exports / variable declarations for top level // await if ( @@ -986,6 +972,24 @@ export function compileScript( node ) } + + if (isTS) { + // runtime enum + if (node.type === 'TSEnumDeclaration' && !node.const) { + registerBinding(setupBindings, node.id, BindingTypes.SETUP_CONST) + } + + // move all Type declarations to outer scope + if ( + node.type.startsWith('TS') || + (node.type === 'ExportNamedDeclaration' && + node.exportKind === 'type') || + (node.type === 'VariableDeclaration' && node.declare) + ) { + recordType(node, declaredTypes) + s.move(start, end, 0) + } + } } // in parse only mode, we should have collected all the information we need,