mirror of https://github.com/vuejs/core.git
fix(compiler-sfc): do not skip TSInstantiationExpression when transforming props destructure (#12064)
This commit is contained in:
parent
76a8223199
commit
d3ecde8a69
|
@ -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 () => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
})"
|
||||||
|
`;
|
||||||
|
|
|
@ -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', () => {
|
test('aliasing', () => {
|
||||||
const { content, bindings } = compile(`
|
const { content, bindings } = compile(`
|
||||||
<script setup>
|
<script setup>
|
||||||
|
|
|
@ -10,6 +10,7 @@ import type {
|
||||||
import { walk } from 'estree-walker'
|
import { walk } from 'estree-walker'
|
||||||
import {
|
import {
|
||||||
BindingTypes,
|
BindingTypes,
|
||||||
|
TS_NODE_TYPES,
|
||||||
extractIdentifiers,
|
extractIdentifiers,
|
||||||
isFunctionType,
|
isFunctionType,
|
||||||
isInDestructureAssignment,
|
isInDestructureAssignment,
|
||||||
|
@ -240,10 +241,7 @@ export function transformDestructuredProps(
|
||||||
if (
|
if (
|
||||||
parent &&
|
parent &&
|
||||||
parent.type.startsWith('TS') &&
|
parent.type.startsWith('TS') &&
|
||||||
parent.type !== 'TSAsExpression' &&
|
!TS_NODE_TYPES.includes(parent.type)
|
||||||
parent.type !== 'TSNonNullExpression' &&
|
|
||||||
parent.type !== 'TSSatisfiesExpression' &&
|
|
||||||
parent.type !== 'TSTypeAssertion'
|
|
||||||
) {
|
) {
|
||||||
return this.skip()
|
return this.skip()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue