Skip to content

Commit

Permalink
fix(compiler-sfc): fix regression on props destructure when transform…
Browse files Browse the repository at this point in the history
… is not enabled

close #8289
  • Loading branch information
yyx990803 committed May 12, 2023
1 parent 80a708f commit f25bd37
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
Expand Up @@ -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'
Expand Down
13 changes: 13 additions & 0 deletions packages/compiler-sfc/__tests__/compileScript/defineProps.spec.ts
Expand Up @@ -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(() => {
Expand Down
1 change: 1 addition & 0 deletions packages/compiler-sfc/src/script/definePropsDestructure.ts
Expand Up @@ -28,6 +28,7 @@ export function processPropsDestructure(
declId: ObjectPattern
) {
if (!ctx.options.propsDestructure && !ctx.options.reactivityTransform) {
ctx.propsIdentifier = ctx.getString(declId)
return
}

Expand Down

0 comments on commit f25bd37

Please sign in to comment.