From 872b3f7ec5e1a41c60018bb1f64d841c309b8939 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 17 Aug 2021 15:52:48 -0400 Subject: [PATCH] fix(compiler-sfc): should also expose regular script block bindings when ` + + `) + expect(content).toMatch('return { aa, bb, cc, dd, a, b, c, d, xx, x }') + expect(bindings).toStrictEqual({ + x: BindingTypes.SETUP_MAYBE_REF, + a: BindingTypes.SETUP_LET, + b: BindingTypes.SETUP_CONST, + c: BindingTypes.SETUP_CONST, + d: BindingTypes.SETUP_CONST, + xx: BindingTypes.SETUP_MAYBE_REF, + aa: BindingTypes.SETUP_LET, + bb: BindingTypes.SETUP_CONST, + cc: BindingTypes.SETUP_CONST, + dd: BindingTypes.SETUP_CONST + }) assertCode(content) - expect(content).toMatch('return { a, b, c, d, x }') }) test('defineProps()', () => { diff --git a/packages/compiler-sfc/src/compileScript.ts b/packages/compiler-sfc/src/compileScript.ts index 68129564e1c..5aa8a9f5533 100644 --- a/packages/compiler-sfc/src/compileScript.ts +++ b/packages/compiler-sfc/src/compileScript.ts @@ -827,6 +827,13 @@ export function compileScript( ) } } + } else if ( + (node.type === 'VariableDeclaration' || + node.type === 'FunctionDeclaration' || + node.type === 'ClassDeclaration') && + !node.declare + ) { + walkDeclaration(node, setupBindings, userImportAlias) } } }