mirror of https://github.com/vuejs/core.git
fix(compiler-sfc): props bindings should not override user declared bindings
fix #8148
This commit is contained in:
parent
01f43c1741
commit
433a58ccb6
|
@ -571,6 +571,21 @@ const props = defineProps({ foo: String })
|
|||
).toMatch(`foo: { type: Number`)
|
||||
})
|
||||
|
||||
// #8148
|
||||
test('should not override local bindings', () => {
|
||||
const { bindings } = compile(`
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
defineProps<{ bar: string }>()
|
||||
const bar = computed(() => 1)
|
||||
</script>
|
||||
`)
|
||||
expect(bindings).toStrictEqual({
|
||||
bar: BindingTypes.SETUP_MAYBE_REF,
|
||||
computed: BindingTypes.SETUP_CONST
|
||||
})
|
||||
})
|
||||
|
||||
describe('errors', () => {
|
||||
test('w/ both type and non-type args', () => {
|
||||
expect(() => {
|
||||
|
|
|
@ -58,9 +58,11 @@ export function processDefineProps(
|
|||
// register bindings
|
||||
if (ctx.propsRuntimeDecl) {
|
||||
for (const key of getObjectOrArrayExpressionKeys(ctx.propsRuntimeDecl)) {
|
||||
if (!(key in ctx.bindingMetadata)) {
|
||||
ctx.bindingMetadata[key] = BindingTypes.PROPS
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// call has type parameters - infer runtime types from it
|
||||
if (node.typeParameters) {
|
||||
|
@ -170,8 +172,10 @@ function genRuntimePropsFromTypes(ctx: ScriptCompileContext) {
|
|||
for (const prop of props) {
|
||||
propStrings.push(genRuntimePropFromType(ctx, prop, hasStaticDefaults))
|
||||
// register bindings
|
||||
if (!(prop.key in ctx.bindingMetadata)) {
|
||||
ctx.bindingMetadata[prop.key] = BindingTypes.PROPS
|
||||
}
|
||||
}
|
||||
|
||||
let propsDecls = `{
|
||||
${propStrings.join(',\n ')}\n }`
|
||||
|
|
Loading…
Reference in New Issue