diff --git a/packages/compiler-sfc/__tests__/compileScript/defineProps.spec.ts b/packages/compiler-sfc/__tests__/compileScript/defineProps.spec.ts index cf61c98406c..f52307d41b3 100644 --- a/packages/compiler-sfc/__tests__/compileScript/defineProps.spec.ts +++ b/packages/compiler-sfc/__tests__/compileScript/defineProps.spec.ts @@ -571,6 +571,21 @@ const props = defineProps({ foo: String }) ).toMatch(`foo: { type: Number`) }) + // #8148 + test('should not override local bindings', () => { + const { bindings } = compile(` + + `) + expect(bindings).toStrictEqual({ + bar: BindingTypes.SETUP_MAYBE_REF, + computed: BindingTypes.SETUP_CONST + }) + }) + describe('errors', () => { test('w/ both type and non-type args', () => { expect(() => { diff --git a/packages/compiler-sfc/src/script/defineProps.ts b/packages/compiler-sfc/src/script/defineProps.ts index 16ea02fe3cf..dde415c21a1 100644 --- a/packages/compiler-sfc/src/script/defineProps.ts +++ b/packages/compiler-sfc/src/script/defineProps.ts @@ -58,7 +58,9 @@ export function processDefineProps( // register bindings if (ctx.propsRuntimeDecl) { for (const key of getObjectOrArrayExpressionKeys(ctx.propsRuntimeDecl)) { - ctx.bindingMetadata[key] = BindingTypes.PROPS + if (!(key in ctx.bindingMetadata)) { + ctx.bindingMetadata[key] = BindingTypes.PROPS + } } } @@ -170,7 +172,9 @@ function genRuntimePropsFromTypes(ctx: ScriptCompileContext) { for (const prop of props) { propStrings.push(genRuntimePropFromType(ctx, prop, hasStaticDefaults)) // register bindings - ctx.bindingMetadata[prop.key] = BindingTypes.PROPS + if (!(prop.key in ctx.bindingMetadata)) { + ctx.bindingMetadata[prop.key] = BindingTypes.PROPS + } } let propsDecls = `{