fix(compiler-sfc): should properly walk desutructured props when reactive destructure is not enabled

close #11325
This commit is contained in:
Evan You 2024-07-17 11:41:02 +08:00
parent f476b7f030
commit 0fd6193def
No known key found for this signature in database
GPG Key ID: 00E9AB7A6704CE0A
3 changed files with 9 additions and 3 deletions

View File

@ -87,7 +87,7 @@ export default /*#__PURE__*/_defineComponent({
const { foo } = __props
return { }
return { foo }
}
})"

View File

@ -591,7 +591,7 @@ const props = defineProps({ foo: String })
// #8289
test('destructure without enabling reactive destructure', () => {
const { content } = compile(
const { content, bindings } = compile(
`<script setup lang="ts">
const { foo } = defineProps<{
foo: Foo
@ -602,6 +602,10 @@ const props = defineProps({ foo: String })
},
)
expect(content).toMatch(`const { foo } = __props`)
expect(content).toMatch(`return { foo }`)
expect(bindings).toStrictEqual({
foo: BindingTypes.SETUP_CONST,
})
assertCode(content)
})

View File

@ -601,6 +601,7 @@ export function compileScript(
setupBindings,
vueImportAliases,
hoistStatic,
!!ctx.propsDestructureDecl,
)
}
@ -1054,6 +1055,7 @@ function walkDeclaration(
bindings: Record<string, BindingTypes>,
userImportAliases: Record<string, string>,
hoistStatic: boolean,
isPropsDestructureEnabled = false,
): boolean {
let isAllLiteral = false
@ -1122,7 +1124,7 @@ function walkDeclaration(
}
registerBinding(bindings, id, bindingType)
} else {
if (isCallOf(init, DEFINE_PROPS)) {
if (isCallOf(init, DEFINE_PROPS) && isPropsDestructureEnabled) {
continue
}
if (id.type === 'ObjectPattern') {