From 312649f69ae0284481e172b29f0973955dd28b80 Mon Sep 17 00:00:00 2001 From: Johnson Chu Date: Wed, 26 Apr 2023 04:45:59 +0800 Subject: [PATCH] fix: cannot recognize `./__VLS_types` in es module close #2661 --- .../src/generators/script.ts | 14 +++++------ .../src/generators/template.ts | 24 +++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/vue-language-core/src/generators/script.ts b/packages/vue-language-core/src/generators/script.ts index d03951691..8c054056d 100644 --- a/packages/vue-language-core/src/generators/script.ts +++ b/packages/vue-language-core/src/generators/script.ts @@ -587,13 +587,13 @@ declare function defineProp(value?: T | (() => T), required?: boolean, rest?: // fill $props if (scriptSetupRanges.propsTypeArg) { // NOTE: defineProps is inaccurate for $props - codes.push(`$props: (await import('./__VLS_types')).makeOptional(defineProps<`); + codes.push(`$props: (await import('./__VLS_types.d.ts')).makeOptional(defineProps<`); addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.propsTypeArg.start, scriptSetupRanges.propsTypeArg.end); codes.push(`>()),\n`); } else if (scriptSetupRanges.propsRuntimeArg) { // NOTE: defineProps is inaccurate for $props - codes.push(`$props: (await import('./__VLS_types')).makeOptional(defineProps(`); + codes.push(`$props: (await import('./__VLS_types.d.ts')).makeOptional(defineProps(`); addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.propsRuntimeArg.start, scriptSetupRanges.propsRuntimeArg.end); codes.push(`)),\n`); } @@ -794,13 +794,13 @@ declare function defineProp(value?: T | (() => T), required?: boolean, rest?: codes.push(`let __VLS_ctx!: ${useGlobalThisTypeInCtx ? 'typeof globalThis &' : ''}`); if (sfc.scriptSetup) { - codes.push(`InstanceType {}>> & `); + codes.push(`InstanceType {}>> & `); } - codes.push(`InstanceType {}>> & {\n`); + codes.push(`InstanceType {}>> & {\n`); /* CSS Module */ for (const cssModule of cssModuleClasses) { - codes.push(`${cssModule.style.module}: Record & import('./__VLS_types').Prettify<{}`); + codes.push(`${cssModule.style.module}: Record & import('./__VLS_types.d.ts').Prettify<{}`); for (const classNameRange of cssModule.classNameRanges) { generateCssClassProperty( cssModule.index, @@ -817,8 +817,8 @@ declare function defineProp(value?: T | (() => T), required?: boolean, rest?: /* Components */ codes.push('/* Components */\n'); codes.push(`let __VLS_localComponents!: NonNullable & typeof __VLS_componentsOption & typeof __VLS_ctx;\n`); - codes.push(`let __VLS_otherComponents!: typeof __VLS_localComponents & import('./__VLS_types').GlobalComponents;\n`); - codes.push(`let __VLS_own!: import('./__VLS_types').SelfComponent { ${getSlotsPropertyName(vueCompilerOptions.target)}: typeof __VLS_slots })>;\n`); + codes.push(`let __VLS_otherComponents!: typeof __VLS_localComponents & import('./__VLS_types.d.ts').GlobalComponents;\n`); + codes.push(`let __VLS_own!: import('./__VLS_types.d.ts').SelfComponent { ${getSlotsPropertyName(vueCompilerOptions.target)}: typeof __VLS_slots })>;\n`); codes.push(`let __VLS_components!: typeof __VLS_otherComponents & Omit;\n`); /* Style Scoped */ diff --git a/packages/vue-language-core/src/generators/template.ts b/packages/vue-language-core/src/generators/template.ts index c0923bc16..ffdec89d4 100644 --- a/packages/vue-language-core/src/generators/template.ts +++ b/packages/vue-language-core/src/generators/template.ts @@ -166,7 +166,7 @@ export function generate( const varName = validTsVar.test(tagName) ? tagName : capitalize(camelize(tagName.replace(/:/g, '-'))); codes.push( - `& import("./__VLS_types").WithComponent<"${varName}", typeof __VLS_components, `, + `& import('./__VLS_types.d.ts').WithComponent<'${varName}', typeof __VLS_components, `, // order is important: https://github.com/johnsoncodehk/volar/issues/2010 `"${capitalize(camelize(tagName))}", `, `"${camelize(tagName)}", `, @@ -446,7 +446,7 @@ export function generate( codes.push([leftExpressionText, 'template', leftExpressionRange.start, capabilitiesPresets.all]); formatCodes.push(...createFormatCode(leftExpressionText, leftExpressionRange.start, formatBrackets.normal)); } - codes.push(`] of (await import('./__VLS_types')).getVForSourceType`); + codes.push(`] of (await import('./__VLS_types.d.ts')).getVForSourceType`); if (source.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) { codes.push( ...createInterpolationCode( @@ -520,7 +520,7 @@ export function generate( if (isNamespacedTag) { codes.push( - `const ${componentVar} = (await import('./__VLS_types')).asFunctionalComponent(${tag}, new ${tag}({`, + `const ${componentVar} = (await import('./__VLS_types.d.ts')).asFunctionalComponent(${tag}, new ${tag}({`, ...createPropsCode(node, props, 'slots'), '}));\n', ); @@ -533,7 +533,7 @@ export function generate( ';\n', ); codes.push( - `const ${componentVar} = (await import('./__VLS_types')).asFunctionalComponent(`, + `const ${componentVar} = (await import('./__VLS_types.d.ts')).asFunctionalComponent(`, `${dynamicTagVar}, `, `new ${dynamicTagVar}({`, ...createPropsCode(node, props, 'slots'), @@ -542,7 +542,7 @@ export function generate( } else { codes.push( - `const ${componentVar} = (await import('./__VLS_types')).asFunctionalComponent(`, + `const ${componentVar} = (await import('./__VLS_types.d.ts')).asFunctionalComponent(`, `__VLS_templateComponents['${componentVars[tag] ?? tag}'], `, `new __VLS_templateComponents['${componentVars[tag] ?? tag}']({`, ...createPropsCode(node, props, 'slots'), @@ -592,12 +592,12 @@ export function generate( tagOffsets.length ? ['', 'template', tagOffsets[0] + tag.length, capabilitiesPresets.diagnosticOnly] : dynamicTagExp ? ['', 'template', startTagOffset + tag.length, capabilitiesPresets.diagnosticOnly] : '', - `, ...(await import('./__VLS_types')).functionalComponentArgsRest(${componentVar}));\n`, + `, ...(await import('./__VLS_types.d.ts')).functionalComponentArgsRest(${componentVar}));\n`, ); if (tag !== 'template') { componentCtxVar = `__VLS_${elementIndex++}`; - codes.push(`const ${componentCtxVar} = (await import('./__VLS_types')).pickFunctionalComponentCtx(${componentVar}, ${componentInstanceVar})!;\n`); + codes.push(`const ${componentCtxVar} = (await import('./__VLS_types.d.ts')).pickFunctionalComponentCtx(${componentVar}, ${componentInstanceVar})!;\n`); parentEl = node; } @@ -636,7 +636,7 @@ export function generate( if (vScope?.type === CompilerDOM.NodeTypes.DIRECTIVE && vScope.exp) { const scopeVar = `__VLS_${elementIndex++}`; - const condition = `(await import('./__VLS_types')).withScope(__VLS_ctx, ${scopeVar})`; + const condition = `(await import('./__VLS_types.d.ts')).withScope(__VLS_ctx, ${scopeVar})`; codes.push(`const ${scopeVar} = `); codes.push([ @@ -696,7 +696,7 @@ export function generate( slotDir.exp.loc.start.offset, capabilitiesPresets.all, ], - `] = (await import('./__VLS_types')).getSlotParams(`, + `] = (await import('./__VLS_types.d.ts')).getSlotParams(`, ); } else { @@ -708,7 +708,7 @@ export function generate( slotDir.exp.loc.start.offset, capabilitiesPresets.all, ], - ` = (await import('./__VLS_types')).getSlotParam(`, + ` = (await import('./__VLS_types.d.ts')).getSlotParam(`, ); } } @@ -781,7 +781,7 @@ export function generate( const eventVar = `__VLS_${elementIndex++}`; codes.push( `let ${eventVar} = { '${prop.arg.loc.source}': `, - `(await import('./__VLS_types')).pickEvent(${componentCtxVar}.emit!, '${prop.arg.loc.source}' as const, (await import('./__VLS_types')).componentProps(${componentVar}, ${componentInstanceVar})`, + `(await import('./__VLS_types.d.ts')).pickEvent(${componentCtxVar}.emit!, '${prop.arg.loc.source}' as const, (await import('./__VLS_types.d.ts')).componentProps(${componentVar}, ${componentInstanceVar})`, ...createPropertyAccessCode([ camelize('on-' + prop.arg.loc.source), // onClickOutside 'template', @@ -1344,7 +1344,7 @@ export function generate( prop.loc.start.offset, capabilitiesPresets.diagnosticOnly, ], - `(await import('./__VLS_types')).directiveFunction(__VLS_ctx.`, + `(await import('./__VLS_types.d.ts')).directiveFunction(__VLS_ctx.`, [ camelize('v-' + prop.name), 'template',