diff --git a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap index c282b7eb4d6..7e3a35a7cf0 100644 --- a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap @@ -610,10 +610,15 @@ export default { function c() {} class d {} -return { a, b, c, d, x } +return { aa, bb, cc, dd, a, b, c, d, xx, x } } -}" +} + import { xx } from './x' + let aa = 1 + const bb = 2 + function cc() {} + class dd {}" `; exports[`SFC compile + + `) + 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) } } }