diff --git a/packages/compiler-sfc/__tests__/compileScript/defineProps.spec.ts b/packages/compiler-sfc/__tests__/compileScript/defineProps.spec.ts index 3ac9e9009..4d2d417d3 100644 --- a/packages/compiler-sfc/__tests__/compileScript/defineProps.spec.ts +++ b/packages/compiler-sfc/__tests__/compileScript/defineProps.spec.ts @@ -627,5 +627,19 @@ const props = defineProps({ foo: String }) `) }).toThrow(`cannot accept both type and non-type arguments`) }) + + test('withDefaults (locally variable)', () => { + expect(() => { + compile(` + + `) + }).toThrow(`cannot reference locally declared variables`) + }) }) }) diff --git a/packages/compiler-sfc/src/compileScript.ts b/packages/compiler-sfc/src/compileScript.ts index 78104c20a..d81712f5c 100644 --- a/packages/compiler-sfc/src/compileScript.ts +++ b/packages/compiler-sfc/src/compileScript.ts @@ -197,7 +197,7 @@ export function compileScript( string, { node: Statement - useWithDefaults: boolean + needHoist?: boolean } > = {} @@ -268,14 +268,13 @@ export function compileScript( if ( binding && binding !== BindingTypes.LITERAL_CONST && - !withDefaultsVariables[id.name].useWithDefaults + !withDefaultsVariables[id.name].needHoist ) { ctx.error( - `\`${method}()\` in