]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-sfc): fix regression on props destructure when transform is not enabled
authorEvan You <yyx990803@gmail.com>
Fri, 12 May 2023 11:53:36 +0000 (12:53 +0100)
committerEvan You <yyx990803@gmail.com>
Fri, 12 May 2023 11:53:36 +0000 (12:53 +0100)
close #8289

packages/compiler-sfc/__tests__/compileScript/__snapshots__/defineProps.spec.ts.snap
packages/compiler-sfc/__tests__/compileScript/defineProps.spec.ts
packages/compiler-sfc/src/script/definePropsDestructure.ts

index 47328442328861a30a75ca5cbf07d51d5eeec03e..62d9bef5d27df7803db33fdc7b87892f3d58ee3c 100644 (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'
 
index fe5ef293ad4d51f4e2a4784253ec3a39ecb5d98f..43f54b0aa1e8b1e07f8c654d515bce89625d55e2 100644 (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(() => {
index 87a58d9fabf16296bef20e9a5add73e5a3e506fa..1584913855abd3c665bbf8167935aa5360994453 100644 (file)
@@ -28,6 +28,7 @@ export function processPropsDestructure(
   declId: ObjectPattern
 ) {
   if (!ctx.options.propsDestructure && !ctx.options.reactivityTransform) {
+    ctx.propsIdentifier = ctx.getString(declId)
     return
   }