Skip to content

Commit 0fd6193

Browse files
committed
fix(compiler-sfc): should properly walk desutructured props when reactive destructure is not enabled
close #11325
1 parent f476b7f commit 0fd6193

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

packages/compiler-sfc/__tests__/compileScript/__snapshots__/defineProps.spec.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export default /*#__PURE__*/_defineComponent({
8787
8888
const { foo } = __props
8989
90-
return { }
90+
return { foo }
9191
}
9292
9393
})"

packages/compiler-sfc/__tests__/compileScript/defineProps.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ const props = defineProps({ foo: String })
591591

592592
// #8289
593593
test('destructure without enabling reactive destructure', () => {
594-
const { content } = compile(
594+
const { content, bindings } = compile(
595595
`<script setup lang="ts">
596596
const { foo } = defineProps<{
597597
foo: Foo
@@ -602,6 +602,10 @@ const props = defineProps({ foo: String })
602602
},
603603
)
604604
expect(content).toMatch(`const { foo } = __props`)
605+
expect(content).toMatch(`return { foo }`)
606+
expect(bindings).toStrictEqual({
607+
foo: BindingTypes.SETUP_CONST,
608+
})
605609
assertCode(content)
606610
})
607611

packages/compiler-sfc/src/compileScript.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ export function compileScript(
601601
setupBindings,
602602
vueImportAliases,
603603
hoistStatic,
604+
!!ctx.propsDestructureDecl,
604605
)
605606
}
606607

@@ -1054,6 +1055,7 @@ function walkDeclaration(
10541055
bindings: Record<string, BindingTypes>,
10551056
userImportAliases: Record<string, string>,
10561057
hoistStatic: boolean,
1058+
isPropsDestructureEnabled = false,
10571059
): boolean {
10581060
let isAllLiteral = false
10591061

@@ -1122,7 +1124,7 @@ function walkDeclaration(
11221124
}
11231125
registerBinding(bindings, id, bindingType)
11241126
} else {
1125-
if (isCallOf(init, DEFINE_PROPS)) {
1127+
if (isCallOf(init, DEFINE_PROPS) && isPropsDestructureEnabled) {
11261128
continue
11271129
}
11281130
if (id.type === 'ObjectPattern') {

0 commit comments

Comments
 (0)