Skip to content

Commit

Permalink
fix: don't hoisting defineProps type arg without experimentalRfc436
Browse files Browse the repository at this point in the history
close #1994
  • Loading branch information
johnsoncodehk committed Oct 11, 2022
1 parent 485a670 commit 69655fc
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions vue-language-tools/vue-language-core/src/generators/script.ts
Expand Up @@ -263,13 +263,13 @@ export function generate(
codeGen.push(`>`);
}
codeGen.push('(');
if (scriptSetupRanges.propsTypeArg) {
if (vueCompilerOptions.experimentalRfc436 && scriptSetupRanges.propsTypeArg) {
codeGen.push('__VLS_props: ');
addVirtualCode('scriptSetup', scriptSetupRanges.propsTypeArg.start, scriptSetupRanges.propsTypeArg.end);
}
codeGen.push(') => {\n');
codeGen.push('const __VLS_setup = async () => {\n');
if (scriptSetupRanges.propsTypeArg) {
if (vueCompilerOptions.experimentalRfc436 && scriptSetupRanges.propsTypeArg) {
addVirtualCode('scriptSetup', scriptSetupRanges.importSectionEndOffset, scriptSetupRanges.propsTypeArg.start);
codeGen.push('typeof __VLS_props');
addVirtualCode('scriptSetup', scriptSetupRanges.propsTypeArg.end);
Expand Down Expand Up @@ -308,7 +308,14 @@ export function generate(
codeGen.push(`__VLS_WithDefaults<`);
}

codeGen.push(`__VLS_TypePropsToRuntimeProps<typeof __VLS_props>`);
codeGen.push(`__VLS_TypePropsToRuntimeProps<`);
if (vueCompilerOptions.experimentalRfc436) {
codeGen.push(`typeof __VLS_props`);
}
else {
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.propsTypeArg.start, scriptSetupRanges.propsTypeArg.end);
}
codeGen.push(`>`);

if (scriptSetupRanges.withDefaultsArg) {
codeGen.push(`, typeof __VLS_withDefaultsArg`);
Expand Down

0 comments on commit 69655fc

Please sign in to comment.