fix(compiler-sfc): fix regression on props destructure when transform is not enabled

close #8289
This commit is contained in:
Evan You 2023-05-12 12:53:36 +01:00
parent 80a708f17a
commit f25bd37c67
3 changed files with 34 additions and 0 deletions

View File

@ -38,6 +38,26 @@ return { props }
})"
`;
exports[`defineProps > destructure without enabling reactive destructure 1`] = `
"import { defineComponent as _defineComponent } from 'vue'
export default /*#__PURE__*/_defineComponent({
props: {
foo: { type: null, required: true }
},
setup(__props: any, { expose: __expose }) {
__expose();
const { foo } = __props;
return { }
}
})"
`;
exports[`defineProps > w/ TS assertion 1`] = `
"import { defineComponent as _defineComponent } from 'vue'

View File

@ -586,6 +586,19 @@ const props = defineProps({ foo: String })
})
})
// #8289
test('destructure without enabling reactive destructure', () => {
const { content } = compile(
`<script setup lang="ts">
const { foo } = defineProps<{
foo: Foo
}>()
</script>`
)
expect(content).toMatch(`const { foo } = __props`)
assertCode(content)
})
describe('errors', () => {
test('w/ both type and non-type args', () => {
expect(() => {

View File

@ -28,6 +28,7 @@ export function processPropsDestructure(
declId: ObjectPattern
) {
if (!ctx.options.propsDestructure && !ctx.options.reactivityTransform) {
ctx.propsIdentifier = ctx.getString(declId)
return
}