Преглед изворни кода

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

close #8289
Evan You пре 2 година
родитељ
комит
f25bd37c67

+ 20 - 0
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 - 0
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 - 0
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
   }