Skip to content

Commit

Permalink
fix(compiler-sfc): should properly walk desutructured props when reac…
Browse files Browse the repository at this point in the history
…tive destructure is not enabled

close #11325
  • Loading branch information
yyx990803 committed Jul 17, 2024
1 parent f476b7f commit 0fd6193
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default /*#__PURE__*/_defineComponent({
const { foo } = __props
return { }
return { foo }
}
})"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
})

Expand Down
4 changes: 3 additions & 1 deletion packages/compiler-sfc/src/compileScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ export function compileScript(
setupBindings,
vueImportAliases,
hoistStatic,
!!ctx.propsDestructureDecl,
)
}

Expand Down Expand Up @@ -1054,6 +1055,7 @@ function walkDeclaration(
bindings: Record<string, BindingTypes>,
userImportAliases: Record<string, string>,
hoistStatic: boolean,
isPropsDestructureEnabled = false,
): boolean {
let isAllLiteral = false

Expand Down Expand Up @@ -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') {
Expand Down

0 comments on commit 0fd6193

Please # to comment.