Skip to content

Commit

Permalink
feat: support jsdoc for jsx IntrinsicElements
Browse files Browse the repository at this point in the history
close #1212
  • Loading branch information
johnsoncodehk committed Jun 2, 2022
1 parent a734e21 commit 4250f23
Showing 1 changed file with 46 additions and 27 deletions.
73 changes: 46 additions & 27 deletions packages/vue-code-gen/src/generators/template.ts
Expand Up @@ -159,40 +159,59 @@ export function generate(

if (!isNamespacedTag) {
// split tagRanges to fix end tag definition original select range mapping to start tag
for (const tagRange of tagRanges) {
tsCodeGen.addText(`// @ts-ignore\n`);
tsCodeGen.addText(`({ `);
writeObjectProperty2(
tagName,
[tagRange],
{
vueTag: 'template',
capabilities: capabilitiesSet.tagHover,
},
);
tsCodeGen.addText(`: {} as `);
tsCodeGen.addText(`__VLS_types.PickNotAny<`.repeat(componentNames.size - 1));
const names = [...componentNames];
for (let i = 0; i < names.length; i++) {
if (i > 0) {
tsCodeGen.addText(', ');
}
tsCodeGen.addText(`typeof __VLS_rawComponents`);
writePropertyAccess2(
names[i],
if (isIntrinsicElement(experimentalRuntimeMode, tagName)) {
for (const tagRange of tagRanges) {
tsCodeGen.addText(`(<`);
writeObjectProperty2(
tagName,
[tagRange],
{
vueTag: 'template',
capabilities: capabilitiesSet.tagReference,
normalizeNewName: tagName === names[i] ? undefined : unHyphenatComponentName,
applyNewName: keepHyphenateName,
capabilities: {
...capabilitiesSet.tagHover,
...capabilitiesSet.tagReference,
},
},
);
if (i > 0) {
tsCodeGen.addText('>');
tsCodeGen.addText(` />);\n`);
}
}
else {
for (const tagRange of tagRanges) {
tsCodeGen.addText(`// @ts-ignore\n`);
tsCodeGen.addText(`({ `);
writeObjectProperty2(
tagName,
[tagRange],
{
vueTag: 'template',
capabilities: capabilitiesSet.tagHover,
},
);
tsCodeGen.addText(`: {} as `);
tsCodeGen.addText(`__VLS_types.PickNotAny<`.repeat(componentNames.size - 1));
const names = [...componentNames];
for (let i = 0; i < names.length; i++) {
if (i > 0) {
tsCodeGen.addText(', ');
}
tsCodeGen.addText(`typeof __VLS_rawComponents`);
writePropertyAccess2(
names[i],
[tagRange],
{
vueTag: 'template',
capabilities: capabilitiesSet.tagReference,
normalizeNewName: tagName === names[i] ? undefined : unHyphenatComponentName,
applyNewName: keepHyphenateName,
},
);
if (i > 0) {
tsCodeGen.addText('>');
}
}
tsCodeGen.addText(` });\n`);
}
tsCodeGen.addText(` });\n`);
}
}

Expand Down

0 comments on commit 4250f23

Please sign in to comment.