Skip to content

Commit d6df276

Browse files
Add attempt to fix deprecated default export issue
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
1 parent 71db400 commit d6df276

1 file changed

Lines changed: 85 additions & 14 deletions

File tree

src/services/symbolDisplay.ts

Lines changed: 85 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ import {
2020
getCombinedLocalAndExportSymbolFlags,
2121
getDeclarationOfKind,
2222
getExternalModuleImportEqualsDeclarationExpression,
23-
getMeaningFromLocation,
24-
getNameOfDeclaration,
25-
getNodeModifiers,
26-
getObjectFlags,
27-
getParseTreeNode,
28-
getSourceFileOfNode,
29-
getTextOfConstantValue,
30-
getTextOfIdentifierOrLiteral,
31-
getTextOfNode,
23+
getMeaningFromLocation,
24+
getNameOfDeclaration,
25+
getNodeModifiers,
26+
getObjectFlags,
27+
getParseTreeNode,
28+
getSourceFileOfNode,
29+
getTextOfConstantValue,
30+
getTextOfIdentifierOrLiteral,
31+
getTextOfNode,
32+
getJSDocCommentsAndTags,
3233
hasSyntacticModifier,
3334
idText,
3435
ImportEqualsDeclaration,
@@ -48,8 +49,10 @@ import {
4849
isFunctionBlock,
4950
isFunctionExpression,
5051
isFunctionLike,
51-
isIdentifier,
52-
isInExpressionContext,
52+
isIdentifier,
53+
isInExpressionContext,
54+
isJSDoc,
55+
isJSDocDeprecatedTag,
5356
isJsxOpeningLikeElement,
5457
isLet,
5558
isModuleWithStringLiteralName,
@@ -615,9 +618,77 @@ function getSymbolDisplayPartsDocumentationAndSymbolKindWorker(
615618
typeWriterOut.canIncreaseExpansionDepth = true;
616619
}
617620
}
618-
else {
619-
documentationFromAlias = resolvedSymbol.getContextualDocumentationComment(resolvedNode, typeChecker);
620-
tagsFromAlias = resolvedSymbol.getJsDocTags(typeChecker);
621+
else {
622+
documentationFromAlias = resolvedSymbol.getContextualDocumentationComment(resolvedNode, typeChecker);
623+
tagsFromAlias = resolvedSymbol.getJsDocTags(typeChecker);
624+
}
625+
626+
// For default imports, also try to get JSDoc from the corresponding export assignment
627+
if (symbol.name === "default") {
628+
const sourceFile = getSourceFileOfNode(resolvedNode);
629+
console.log(`DEBUG: Looking for export assignment in ${sourceFile.fileName}, statements: ${sourceFile.statements.length}`);
630+
// Find export assignment that exports the resolved symbol as default
631+
for (const statement of sourceFile.statements) {
632+
console.log(`DEBUG: Statement kind: ${statement.kind}, SyntaxKind.ExportAssignment: ${SyntaxKind.ExportAssignment}`);
633+
if (statement.kind === SyntaxKind.ExportAssignment && !(statement as ExportAssignment).isExportEquals) {
634+
const exportAssignment = statement as ExportAssignment;
635+
console.log(`DEBUG: Found export assignment`);
636+
if (isIdentifier(exportAssignment.expression)) {
637+
const exportedSymbol = typeChecker.getSymbolAtLocation(exportAssignment.expression);
638+
console.log(`DEBUG: exportedSymbol === resolvedSymbol: ${exportedSymbol === resolvedSymbol}`);
639+
if (exportedSymbol === resolvedSymbol) {
640+
console.log(`DEBUG: Found matching export assignment`);
641+
// Found the export assignment, get its JSDoc directly from the node
642+
const jsDocCommentsAndTags = getJSDocCommentsAndTags(exportAssignment);
643+
console.log(`DEBUG: JSDoc comments and tags: ${jsDocCommentsAndTags.length}`);
644+
if (jsDocCommentsAndTags.length > 0) {
645+
const exportDoc: SymbolDisplayPart[] = [];
646+
const exportTags: JSDocTagInfo[] = [];
647+
648+
for (const jsDocOrTag of jsDocCommentsAndTags) {
649+
if (isJSDoc(jsDocOrTag)) {
650+
// Extract documentation from JSDoc comment
651+
if (jsDocOrTag.comment) {
652+
const commentText = typeof jsDocOrTag.comment === "string"
653+
? jsDocOrTag.comment
654+
: jsDocOrTag.comment.map(c => c.text || "").join("");
655+
if (commentText) {
656+
exportDoc.push({ text: commentText, kind: "text" });
657+
}
658+
}
659+
660+
// Extract tags from JSDoc
661+
if (jsDocOrTag.tags) {
662+
for (const tag of jsDocOrTag.tags) {
663+
if (isJSDocDeprecatedTag(tag)) {
664+
const tagText = tag.comment
665+
? (typeof tag.comment === "string"
666+
? tag.comment
667+
: tag.comment.map(c => c.text || "").join(""))
668+
: undefined;
669+
exportTags.push({
670+
name: "deprecated",
671+
text: tagText ? [{ text: tagText, kind: "text" }] : undefined
672+
});
673+
}
674+
}
675+
}
676+
}
677+
}
678+
679+
// Use export assignment JSDoc if it exists
680+
if (exportDoc.length > 0) {
681+
documentationFromAlias = exportDoc;
682+
}
683+
if (exportTags.length > 0) {
684+
tagsFromAlias = exportTags;
685+
}
686+
}
687+
break;
688+
}
689+
}
690+
}
691+
}
621692
}
622693
}
623694
}

0 commit comments

Comments
 (0)