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
|
||||
|
||||
return { }
|
||||
return { foo }
|
||||
}
|
||||
|
||||
})"
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
|
||||
|
|
|
@ -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') {
|
||||
|
|
Loading…
Reference in New Issue