Skip to content

Commit

Permalink
fix: cannot recognize ./__VLS_types in es module
Browse files Browse the repository at this point in the history
close #2661
  • Loading branch information
johnsoncodehk committed Apr 25, 2023
1 parent 3c564b0 commit 312649f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
14 changes: 7 additions & 7 deletions packages/vue-language-core/src/generators/script.ts
Expand Up @@ -587,13 +587,13 @@ declare function defineProp<T>(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`);
}
Expand Down Expand Up @@ -794,13 +794,13 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:

codes.push(`let __VLS_ctx!: ${useGlobalThisTypeInCtx ? 'typeof globalThis &' : ''}`);
if (sfc.scriptSetup) {
codes.push(`InstanceType<import('./__VLS_types').PickNotAny<typeof __VLS_publicComponent, new () => {}>> & `);
codes.push(`InstanceType<import('./__VLS_types.d.ts').PickNotAny<typeof __VLS_publicComponent, new () => {}>> & `);
}
codes.push(`InstanceType<import('./__VLS_types').PickNotAny<typeof __VLS_internalComponent, new () => {}>> & {\n`);
codes.push(`InstanceType<import('./__VLS_types.d.ts').PickNotAny<typeof __VLS_internalComponent, new () => {}>> & {\n`);

/* CSS Module */
for (const cssModule of cssModuleClasses) {
codes.push(`${cssModule.style.module}: Record<string, string> & import('./__VLS_types').Prettify<{}`);
codes.push(`${cssModule.style.module}: Record<string, string> & import('./__VLS_types.d.ts').Prettify<{}`);
for (const classNameRange of cssModule.classNameRanges) {
generateCssClassProperty(
cssModule.index,
Expand All @@ -817,8 +817,8 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
/* Components */
codes.push('/* Components */\n');
codes.push(`let __VLS_localComponents!: NonNullable<typeof __VLS_internalComponent extends { components: infer C } ? C : {}> & 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<typeof __VLS_name, typeof __VLS_internalComponent & typeof __VLS_publicComponent & (new () => { ${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<typeof __VLS_name, typeof __VLS_internalComponent & typeof __VLS_publicComponent & (new () => { ${getSlotsPropertyName(vueCompilerOptions.target)}: typeof __VLS_slots })>;\n`);
codes.push(`let __VLS_components!: typeof __VLS_otherComponents & Omit<typeof __VLS_own, keyof typeof __VLS_otherComponents>;\n`);

/* Style Scoped */
Expand Down
24 changes: 12 additions & 12 deletions packages/vue-language-core/src/generators/template.ts
Expand Up @@ -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)}", `,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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',
);
Expand All @@ -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'),
Expand All @@ -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'),
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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([
Expand Down Expand Up @@ -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 {
Expand All @@ -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(`,
);
}
}
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 312649f

Please sign in to comment.