Skip to content

Commit

Permalink
fix(compiler-sfc): do not skip TSInstantiationExpression when transfo…
Browse files Browse the repository at this point in the history
…rming props destructure (#12064)
  • Loading branch information
linzhe141 authored Oct 11, 2024
1 parent 76a8223 commit d3ecde8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {}
}
})"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
6 changes: 2 additions & 4 deletions packages/compiler-sfc/src/script/definePropsDestructure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
import { walk } from 'estree-walker'
import {
BindingTypes,
TS_NODE_TYPES,
extractIdentifiers,
isFunctionType,
isInDestructureAssignment,
Expand Down Expand Up @@ -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()
}
Expand Down

0 comments on commit d3ecde8

Please sign in to comment.