Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slight improvement to SymbolDisplay for 'module.exports =' #25013

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/services/symbolDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,11 @@ namespace ts.SymbolDisplay {
const isExternalModuleDeclaration =
isModuleWithStringLiteralName(resolvedNode) &&
hasModifier(resolvedNode, ModifierFlags.Ambient);
const shouldUseAliasName = symbol.name !== "default" && !isExternalModuleDeclaration;
const shouldUseAliasName = symbol.name !== InternalSymbolName.Default && symbol.name !== InternalSymbolName.ExportEquals && !isExternalModuleDeclaration;
const resolvedInfo = getSymbolDisplayPartsDocumentationAndSymbolKind(
typeChecker,
resolvedSymbol,
getSourceFileOfNode(resolvedNode),
resolvedNode.getSourceFile(),
resolvedNode,
declarationName,
semanticMeaning,
Expand All @@ -402,16 +402,18 @@ namespace ts.SymbolDisplay {
}
}

switch (symbol.declarations[0].kind) {
const kind = symbol.declarations[0].kind;
switch (kind) {
case SyntaxKind.NamespaceExportDeclaration:
displayParts.push(keywordPart(SyntaxKind.ExportKeyword));
displayParts.push(spacePart());
displayParts.push(keywordPart(SyntaxKind.NamespaceKeyword));
break;
case SyntaxKind.BinaryExpression: // For `module.exports =`
case SyntaxKind.ExportAssignment:
displayParts.push(keywordPart(SyntaxKind.ExportKeyword));
displayParts.push(spacePart());
displayParts.push(keywordPart((symbol.declarations[0] as ExportAssignment).isExportEquals ? SyntaxKind.EqualsToken : SyntaxKind.DefaultKeyword));
displayParts.push(keywordPart(kind === SyntaxKind.BinaryExpression || (symbol.declarations[0] as ExportAssignment).isExportEquals ? SyntaxKind.EqualsToken : SyntaxKind.DefaultKeyword));
break;
case SyntaxKind.ExportSpecifier:
displayParts.push(keywordPart(SyntaxKind.ExportKeyword));
Expand Down
4 changes: 2 additions & 2 deletions tests/cases/fourslash/findAllRefs_importType_js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const [r0, r1, r2, r3, r4, r5] = test.ranges();
verify.referenceGroups(r0, [
{ definition: "(local class) C", ranges: [r0] },
// TODO: This definition is really ugly
{ definition: "(alias) (local class) export=\nimport export=", ranges: [r3] },
{ definition: "(alias) (local class) C\nexport = export=", ranges: [r3] },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure this looks any better than the previous one..

]);
verify.referenceGroups([r1, r5], [
{ definition: "class D\n(property) D: typeof D", ranges: [r1, r5, r5] }, // TODO: should only reference r5 once
Expand All @@ -33,5 +33,5 @@ verify.referenceGroups(r2, [
verify.referenceGroups([r3, r4], [
{ definition: 'module "/a"', ranges: [r4] },
{ definition: "(local class) C", ranges: [r0] },
{ definition: "(alias) (local class) export=\nimport export=", ranges: [r3] },
{ definition: "(alias) (local class) C\nexport = export=", ranges: [r3] },
]);