Skip to content

Commit

Permalink
simplify fix
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Jul 13, 2023
1 parent edbb60f commit d68ff98
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
2 changes: 1 addition & 1 deletion packages/vue-language-core/src/generators/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
const templateStart = getLength(codes);
codes.push(varName);
const templateEnd = getLength(codes);
codes.push(`: {} as typeof `);
codes.push(`: ${varName} as typeof `);

const scriptStart = getLength(codes);
codes.push(varName);
Expand Down
39 changes: 17 additions & 22 deletions packages/vue-language-core/src/generators/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,8 @@ export function generate(
codes.push('}\n');
}

function toCanonicalComponentNames(tagText: string) {
return validTsVar.test(tagText) ? [tagText] : [
capitalize(camelize(tagText.replace(/:/g, '-'))),
camelize(tagText.replace(/:/g, '-'))
];
function toCanonicalComponentName(tagText: string) {
return validTsVar.test(tagText) ? tagText : capitalize(camelize(tagText.replace(/:/g, '-')));
}

function getPossibleOriginalComponentName(tagText: string) {
Expand All @@ -206,7 +203,7 @@ export function generate(
continue;

codes.push(
`& __VLS_WithComponent<'${toCanonicalComponentNames(tagName)[0]}', typeof __VLS_localComponents, `,
`& __VLS_WithComponent<'${toCanonicalComponentName(tagName)}', typeof __VLS_localComponents, `,
// order is important: https://github.com/vuejs/language-tools/issues/2010
`"${capitalize(camelize(tagName))}", `,
`"${camelize(tagName)}", `,
Expand Down Expand Up @@ -256,22 +253,20 @@ export function generate(
'// @ts-ignore\n', // #2304
'[',
);
const validNames = toCanonicalComponentNames(tagName);
const validName = toCanonicalComponentName(tagName);
for (const tagRange of tagRanges) {
for (const validName of validNames) {
codes.push([
validName,
'template',
tagRange,
{
completion: {
additional: true,
autoImportOnly: true,
},
codes.push([
validName,
'template',
tagRange,
{
completion: {
additional: true,
autoImportOnly: true,
},
]);
codes.push(',');
}
},
]);
codes.push(',');
}
codes.push(`];\n`);
}
Expand Down Expand Up @@ -683,7 +678,7 @@ export function generate(
for (const componentName of getPossibleOriginalComponentName(tag)) {
codes.push(`'${componentName}' extends keyof typeof __VLS_ctx ? typeof __VLS_ctx${validTsVar.test(componentName) ? `.${componentName}` : `['${componentName}']`} : `);
}
codes.push(`typeof __VLS_resolvedLocalAndGlobalComponents['${toCanonicalComponentNames(tag)[0]}'];\n`);
codes.push(`typeof __VLS_resolvedLocalAndGlobalComponents['${toCanonicalComponentName(tag)}'];\n`);
}

codes.push(
Expand Down Expand Up @@ -722,7 +717,7 @@ export function generate(
);
}
else {
const key = toCanonicalComponentNames(tag)[0];
const key = toCanonicalComponentName(tag);
codes.push(`({} as { ${key}: typeof ${var_originalComponent} }).`);
codes.push(
[
Expand Down

0 comments on commit d68ff98

Please sign in to comment.