Browse Source

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

close #8289
pull/7594/head
Evan You 2 years ago
parent
commit
f25bd37c67
  1. 20
      packages/compiler-sfc/__tests__/compileScript/__snapshots__/defineProps.spec.ts.snap
  2. 13
      packages/compiler-sfc/__tests__/compileScript/defineProps.spec.ts
  3. 1
      packages/compiler-sfc/src/script/definePropsDestructure.ts

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

@ -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'

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

@ -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(() => {

1
packages/compiler-sfc/src/script/definePropsDestructure.ts

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

Loading…
Cancel
Save