Skip to content

Commit f25bd37

Browse files
committed
fix(compiler-sfc): fix regression on props destructure when transform is not enabled
close #8289
1 parent 80a708f commit f25bd37

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

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

+20
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,26 @@ return { props }
3838
})"
3939
`;
4040

41+
exports[`defineProps > destructure without enabling reactive destructure 1`] = `
42+
"import { defineComponent as _defineComponent } from 'vue'
43+
44+
export default /*#__PURE__*/_defineComponent({
45+
props: {
46+
foo: { type: null, required: true }
47+
},
48+
setup(__props: any, { expose: __expose }) {
49+
__expose();
50+
51+
const { foo } = __props;
52+
53+
54+
55+
return { }
56+
}
57+
58+
})"
59+
`;
60+
4161
exports[`defineProps > w/ TS assertion 1`] = `
4262
"import { defineComponent as _defineComponent } from 'vue'
4363

Diff for: packages/compiler-sfc/__tests__/compileScript/defineProps.spec.ts

+13
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,19 @@ const props = defineProps({ foo: String })
586586
})
587587
})
588588

589+
// #8289
590+
test('destructure without enabling reactive destructure', () => {
591+
const { content } = compile(
592+
`<script setup lang="ts">
593+
const { foo } = defineProps<{
594+
foo: Foo
595+
}>()
596+
</script>`
597+
)
598+
expect(content).toMatch(`const { foo } = __props`)
599+
assertCode(content)
600+
})
601+
589602
describe('errors', () => {
590603
test('w/ both type and non-type args', () => {
591604
expect(() => {

Diff for: packages/compiler-sfc/src/script/definePropsDestructure.ts

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export function processPropsDestructure(
2828
declId: ObjectPattern
2929
) {
3030
if (!ctx.options.propsDestructure && !ctx.options.reactivityTransform) {
31+
ctx.propsIdentifier = ctx.getString(declId)
3132
return
3233
}
3334

0 commit comments

Comments
 (0)