Skip to content

Commit 433a58c

Browse files
committed
fix(compiler-sfc): props bindings should not override user declared bindings
fix #8148
1 parent 01f43c1 commit 433a58c

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

packages/compiler-sfc/__tests__/compileScript/defineProps.spec.ts

+15
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,21 @@ const props = defineProps({ foo: String })
571571
).toMatch(`foo: { type: Number`)
572572
})
573573

574+
// #8148
575+
test('should not override local bindings', () => {
576+
const { bindings } = compile(`
577+
<script setup lang="ts">
578+
import { computed } from 'vue'
579+
defineProps<{ bar: string }>()
580+
const bar = computed(() => 1)
581+
</script>
582+
`)
583+
expect(bindings).toStrictEqual({
584+
bar: BindingTypes.SETUP_MAYBE_REF,
585+
computed: BindingTypes.SETUP_CONST
586+
})
587+
})
588+
574589
describe('errors', () => {
575590
test('w/ both type and non-type args', () => {
576591
expect(() => {

packages/compiler-sfc/src/script/defineProps.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ export function processDefineProps(
5858
// register bindings
5959
if (ctx.propsRuntimeDecl) {
6060
for (const key of getObjectOrArrayExpressionKeys(ctx.propsRuntimeDecl)) {
61-
ctx.bindingMetadata[key] = BindingTypes.PROPS
61+
if (!(key in ctx.bindingMetadata)) {
62+
ctx.bindingMetadata[key] = BindingTypes.PROPS
63+
}
6264
}
6365
}
6466

@@ -170,7 +172,9 @@ function genRuntimePropsFromTypes(ctx: ScriptCompileContext) {
170172
for (const prop of props) {
171173
propStrings.push(genRuntimePropFromType(ctx, prop, hasStaticDefaults))
172174
// register bindings
173-
ctx.bindingMetadata[prop.key] = BindingTypes.PROPS
175+
if (!(prop.key in ctx.bindingMetadata)) {
176+
ctx.bindingMetadata[prop.key] = BindingTypes.PROPS
177+
}
174178
}
175179

176180
let propsDecls = `{

0 commit comments

Comments
 (0)