Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(language-core): prevent the generation of generics in JS #4836

Merged
merged 12 commits into from
Oct 24, 2024
Prev Previous commit
Next Next commit
support js
  • Loading branch information
johnsoncodehk committed Oct 24, 2024
commit 7f14822643279f3148361705691dce0651ab3106
42 changes: 29 additions & 13 deletions packages/language-core/lib/codegen/script/scriptSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,19 +244,35 @@ function* generateSetupFunction(
}
}
const isTs = options.lang !== 'js' && options.lang !== 'jsx';
if (isTs) {
for (const { define } of scriptSetupRanges.templateRefs) {
if (define?.arg) {
setupCodeModifies.push([
[
`<__VLS_TemplateResult['refs'][`,
generateSfcBlockSection(scriptSetup, define.arg.start, define.arg.end, codeFeatures.navigation),
`], keyof __VLS_TemplateResult['refs']>`
],
define.arg.start - 1,
define.arg.start - 1
]);
}
for (const { define } of scriptSetupRanges.templateRefs) {
if (!define?.arg) {
continue;
}
if (isTs) {
setupCodeModifies.push([
[
`<__VLS_TemplateResult['refs'][`,
generateSfcBlockSection(scriptSetup, define.arg.start, define.arg.end, codeFeatures.navigation),
`], keyof __VLS_TemplateResult['refs']>`
],
define.arg.start - 1,
define.arg.start - 1
]);
}
else {
setupCodeModifies.push([
[`(`],
define.start,
define.start
], [
[
`as __VLS_TemplateResult['refs'][`,
generateSfcBlockSection(scriptSetup, define.arg.start, define.arg.end, codeFeatures.navigation),
`])`
],
define.end,
define.end
]);
}
}
setupCodeModifies = setupCodeModifies.sort((a, b) => a[1] - b[1]);
Expand Down
2 changes: 1 addition & 1 deletion test-workspace/tsc/passedFixtures/vue3/#4826/main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { exactType } from '../../shared';
import Child from './child.vue';

const child = useTemplateRef('child');
exactType(child.value?.a, {} as unknown);
exactType(child.value?.a, {} as HTMLAnchorElement | undefined);
</script>

<template>
Expand Down