mirror of https://github.com/vuejs/core.git
fix(compiler-sfc): should properly walk desutructured props when reactive destructure is not enabled
close #11325
This commit is contained in:
parent
f476b7f030
commit
0fd6193def
|
@ -87,7 +87,7 @@ export default /*#__PURE__*/_defineComponent({
|
||||||
|
|
||||||
const { foo } = __props
|
const { foo } = __props
|
||||||
|
|
||||||
return { }
|
return { foo }
|
||||||
}
|
}
|
||||||
|
|
||||||
})"
|
})"
|
||||||
|
|
|
@ -591,7 +591,7 @@ const props = defineProps({ foo: String })
|
||||||
|
|
||||||
// #8289
|
// #8289
|
||||||
test('destructure without enabling reactive destructure', () => {
|
test('destructure without enabling reactive destructure', () => {
|
||||||
const { content } = compile(
|
const { content, bindings } = compile(
|
||||||
`<script setup lang="ts">
|
`<script setup lang="ts">
|
||||||
const { foo } = defineProps<{
|
const { foo } = defineProps<{
|
||||||
foo: Foo
|
foo: Foo
|
||||||
|
@ -602,6 +602,10 @@ const props = defineProps({ foo: String })
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
expect(content).toMatch(`const { foo } = __props`)
|
expect(content).toMatch(`const { foo } = __props`)
|
||||||
|
expect(content).toMatch(`return { foo }`)
|
||||||
|
expect(bindings).toStrictEqual({
|
||||||
|
foo: BindingTypes.SETUP_CONST,
|
||||||
|
})
|
||||||
assertCode(content)
|
assertCode(content)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -601,6 +601,7 @@ export function compileScript(
|
||||||
setupBindings,
|
setupBindings,
|
||||||
vueImportAliases,
|
vueImportAliases,
|
||||||
hoistStatic,
|
hoistStatic,
|
||||||
|
!!ctx.propsDestructureDecl,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1054,6 +1055,7 @@ function walkDeclaration(
|
||||||
bindings: Record<string, BindingTypes>,
|
bindings: Record<string, BindingTypes>,
|
||||||
userImportAliases: Record<string, string>,
|
userImportAliases: Record<string, string>,
|
||||||
hoistStatic: boolean,
|
hoistStatic: boolean,
|
||||||
|
isPropsDestructureEnabled = false,
|
||||||
): boolean {
|
): boolean {
|
||||||
let isAllLiteral = false
|
let isAllLiteral = false
|
||||||
|
|
||||||
|
@ -1122,7 +1124,7 @@ function walkDeclaration(
|
||||||
}
|
}
|
||||||
registerBinding(bindings, id, bindingType)
|
registerBinding(bindings, id, bindingType)
|
||||||
} else {
|
} else {
|
||||||
if (isCallOf(init, DEFINE_PROPS)) {
|
if (isCallOf(init, DEFINE_PROPS) && isPropsDestructureEnabled) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if (id.type === 'ObjectPattern') {
|
if (id.type === 'ObjectPattern') {
|
||||||
|
|
Loading…
Reference in New Issue