]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-sfc): should properly walk desutructured props when reactive destructure...
authorEvan You <evan@vuejs.org>
Wed, 17 Jul 2024 03:41:02 +0000 (11:41 +0800)
committerEvan You <evan@vuejs.org>
Wed, 17 Jul 2024 03:41:58 +0000 (11:41 +0800)
close #11325

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

index ce5eaed18fd8550bdd1af633f8e0bcf3c8e381bb..c51d1d8b95362de2b24ccd43b40113241290fc80 100644 (file)
@@ -87,7 +87,7 @@ export default /*#__PURE__*/_defineComponent({
 
       const { foo } = __props
       
-return {  }
+return { foo }
 }
 
 })"
index d5374ae89b1fa3dea8df73da193f12a106a18b10..813cfc9c3744d9fdc40c39f6dd6091b13a722493 100644 (file)
@@ -591,7 +591,7 @@ const props = defineProps({ foo: String })
 
   // #8289
   test('destructure without enabling reactive destructure', () => {
-    const { content } = compile(
+    const { content, bindings } = compile(
       `<script setup lang="ts">
       const { foo } = defineProps<{
         foo: Foo
@@ -602,6 +602,10 @@ const props = defineProps({ foo: String })
       },
     )
     expect(content).toMatch(`const { foo } = __props`)
+    expect(content).toMatch(`return { foo }`)
+    expect(bindings).toStrictEqual({
+      foo: BindingTypes.SETUP_CONST,
+    })
     assertCode(content)
   })
 
index e8579cf6cf7bc325e312b8099d596fb3c4e28276..8e77bca80d1ea4119e25780a58d2eaa2eae768f6 100644 (file)
@@ -601,6 +601,7 @@ export function compileScript(
         setupBindings,
         vueImportAliases,
         hoistStatic,
+        !!ctx.propsDestructureDecl,
       )
     }
 
@@ -1054,6 +1055,7 @@ function walkDeclaration(
   bindings: Record<string, BindingTypes>,
   userImportAliases: Record<string, string>,
   hoistStatic: boolean,
+  isPropsDestructureEnabled = false,
 ): boolean {
   let isAllLiteral = false
 
@@ -1122,7 +1124,7 @@ function walkDeclaration(
         }
         registerBinding(bindings, id, bindingType)
       } else {
-        if (isCallOf(init, DEFINE_PROPS)) {
+        if (isCallOf(init, DEFINE_PROPS) && isPropsDestructureEnabled) {
           continue
         }
         if (id.type === 'ObjectPattern') {