]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-sfc): do not skip TSInstantiationExpression when transforming props...
authorlinzhe <40790268+linzhe141@users.noreply.github.com>
Fri, 11 Oct 2024 02:51:57 +0000 (10:51 +0800)
committerGitHub <noreply@github.com>
Fri, 11 Oct 2024 02:51:57 +0000 (10:51 +0800)
packages/compiler-sfc/__tests__/compileScript/__snapshots__/definePropsDestructure.spec.ts.snap
packages/compiler-sfc/__tests__/compileScript/definePropsDestructure.spec.ts
packages/compiler-sfc/src/script/definePropsDestructure.ts

index 12d5a67db7e52c2fa11fd2e5b7012874eb9bd097..1044b0e167cbdd12e57de493d59cde1c2f71539d 100644 (file)
@@ -320,3 +320,22 @@ return { rest }
 
 }"
 `;
+
+exports[`sfc reactive props destructure > with TSInstantiationExpression 1`] = `
+"import { defineComponent as _defineComponent } from 'vue'
+type Foo = <T extends string | number>(data: T) => void
+      
+export default /*@__PURE__*/_defineComponent({
+  props: {
+    value: { type: Function }
+  },
+  setup(__props: any) {
+
+      
+      const foo = __props.value<123>
+      
+return () => {}
+}
+
+})"
+`;
index 106e469f1884f1421208a9c85737771b0b4f404a..50602eb59bc0fa607d36e3507ff3eca7551f0322 100644 (file)
@@ -198,6 +198,21 @@ describe('sfc reactive props destructure', () => {
   }`)
   })
 
+  test('with TSInstantiationExpression', () => {
+    const { content } = compile(
+      `
+      <script setup lang="ts">
+      type Foo = <T extends string | number>(data: T) => void
+      const { value } = defineProps<{ value: Foo }>()
+      const foo = value<123>
+      </script>
+    `,
+      { isProd: true },
+    )
+    assertCode(content)
+    expect(content).toMatch(`const foo = __props.value<123>`)
+  })
+
   test('aliasing', () => {
     const { content, bindings } = compile(`
       <script setup>
index f9a56e32e441978606115ef3ee8487d43eb22a75..27b4d445bbeb83be254ced0ce651379c4b813100 100644 (file)
@@ -10,6 +10,7 @@ import type {
 import { walk } from 'estree-walker'
 import {
   BindingTypes,
+  TS_NODE_TYPES,
   extractIdentifiers,
   isFunctionType,
   isInDestructureAssignment,
@@ -240,10 +241,7 @@ export function transformDestructuredProps(
       if (
         parent &&
         parent.type.startsWith('TS') &&
-        parent.type !== 'TSAsExpression' &&
-        parent.type !== 'TSNonNullExpression' &&
-        parent.type !== 'TSSatisfiesExpression' &&
-        parent.type !== 'TSTypeAssertion'
+        !TS_NODE_TYPES.includes(parent.type)
       ) {
         return this.skip()
       }