diff --git a/packages/language-core/lib/codegen/template/element.ts b/packages/language-core/lib/codegen/template/element.ts index 6776fe8ddb..eeded19b4b 100644 --- a/packages/language-core/lib/codegen/template/element.ts +++ b/packages/language-core/lib/codegen/template/element.ts @@ -95,8 +95,9 @@ export function* generateComponent( ]; } else { + const shouldCapitalize = matchImportName[0].toUpperCase() === matchImportName[0]; yield* generateCamelized( - capitalize(node.tag), + shouldCapitalize ? capitalize(node.tag) : node.tag, tagOffset, { ...ctx.codeFeatures.withoutHighlightAndCompletion, @@ -144,15 +145,15 @@ export function* generateComponent( yield `)${endOfLine}`; } else if (!isComponentTag) { - yield `const ${var_originalComponent} = __VLS_resolvedLocalAndGlobalComponents.`; + yield `const ${var_originalComponent} = ({} as __VLS_WithComponent<'${getCanonicalComponentName(node.tag)}', __VLS_LocalComponents, `; + yield getPossibleOriginalComponentNames(node.tag, false) + .map(name => `'${name}'`) + .join(`, `); + yield `>).`; yield* generateCanonicalComponentName( node.tag, startTagOffset, - { - // with hover support - ...ctx.codeFeatures.withoutHighlightAndCompletionAndNavigation, - ...ctx.codeFeatures.verification, - } + ctx.codeFeatures.withoutHighlightAndCompletionAndNavigation ); yield `${endOfLine}`; @@ -413,13 +414,13 @@ function* generateVScope( return [refName, offset]; } -export function getCanonicalComponentName(tagText: string) { +function getCanonicalComponentName(tagText: string) { return variableNameRegex.test(tagText) ? tagText : capitalize(camelize(tagText.replace(colonReg, '-'))); } -export function getPossibleOriginalComponentNames(tagText: string, deduplicate: boolean) { +function getPossibleOriginalComponentNames(tagText: string, deduplicate: boolean) { const name1 = capitalize(camelize(tagText)); const name2 = camelize(tagText); const name3 = tagText; diff --git a/packages/language-core/lib/codegen/template/index.ts b/packages/language-core/lib/codegen/template/index.ts index c98f11676a..7d82290baa 100644 --- a/packages/language-core/lib/codegen/template/index.ts +++ b/packages/language-core/lib/codegen/template/index.ts @@ -5,7 +5,6 @@ import { getSlotsPropertyName } from '../../utils/shared'; import { endOfLine, newLine, wrapWith } from '../utils'; import { generateStringLiteralKey } from '../utils/stringLiteralKey'; import { TemplateCodegenContext, createTemplateCodegenContext } from './context'; -import { getCanonicalComponentName, getPossibleOriginalComponentNames } from './element'; import { generateObjectProperty } from './objectProperty'; import { generateStyleScopedClassReferences } from './styleScopedClasses'; import { generateTemplateChild, getVForNode } from './templateChild'; @@ -40,8 +39,6 @@ export function* generateTemplate(options: TemplateCodegenOptions): Generator { } } -function* generatePreResolveComponents(options: TemplateCodegenOptions): Generator { - yield `let __VLS_resolvedLocalAndGlobalComponents!: Required<{}`; - if (options.template.ast) { - const components = new Set(); - for (const node of forEachElementNode(options.template.ast)) { - if ( - node.tagType === CompilerDOM.ElementTypes.COMPONENT - && node.tag.toLowerCase() !== 'component' - && !node.tag.includes('.') // namespace tag - ) { - if (components.has(node.tag)) { - continue; - } - components.add(node.tag); - yield newLine; - yield ` & __VLS_WithComponent<'${getCanonicalComponentName(node.tag)}', __VLS_LocalComponents, `; - yield getPossibleOriginalComponentNames(node.tag, false) - .map(name => `'${name}'`) - .join(', '); - yield `>`; - } - } - } - yield `>${endOfLine}`; -} - export function* forEachElementNode(node: CompilerDOM.RootNode | CompilerDOM.TemplateChildNode): Generator { if (node.type === CompilerDOM.NodeTypes.ROOT) { for (const child of node.children) { diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/#5067/comp.vue b/test-workspace/tsc/passedFixtures/vue3_strictTemplate/#5067/comp.vue new file mode 100644 index 0000000000..41fb2f26e2 --- /dev/null +++ b/test-workspace/tsc/passedFixtures/vue3_strictTemplate/#5067/comp.vue @@ -0,0 +1,8 @@ + diff --git a/test-workspace/tsc/passedFixtures/vue3_strictTemplate/#5067/main.vue b/test-workspace/tsc/passedFixtures/vue3_strictTemplate/#5067/main.vue new file mode 100644 index 0000000000..6e72f7ebd8 --- /dev/null +++ b/test-workspace/tsc/passedFixtures/vue3_strictTemplate/#5067/main.vue @@ -0,0 +1,30 @@ + + +