Skip to content

Commit 687ab54

Browse files
author
Andy
authored
Merge pull request microsoft#15846 from Microsoft/findAllRefs_symbolNoName
findAllReferences: In `export default foo`, symbol name is `foo`
2 parents 278fb80 + 5eb2bd0 commit 687ab54

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

src/compiler/utilities.ts

+4
Original file line numberDiff line numberDiff line change
@@ -4032,6 +4032,10 @@ namespace ts {
40324032
return node.kind === SyntaxKind.ExportSpecifier;
40334033
}
40344034

4035+
export function isExportAssignment(node: Node): node is ExportAssignment {
4036+
return node.kind === SyntaxKind.ExportAssignment;
4037+
}
4038+
40354039
export function isModuleOrEnumDeclaration(node: Node): node is ModuleDeclaration | EnumDeclaration {
40364040
return node.kind === SyntaxKind.ModuleDeclaration || node.kind === SyntaxKind.EnumDeclaration;
40374041
}

src/services/importTracker.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -526,17 +526,18 @@ namespace ts.FindAllReferences {
526526
return isExternalModuleSymbol(exportingModuleSymbol) ? { exportingModuleSymbol, exportKind } : undefined;
527527
}
528528

529-
function symbolName(symbol: Symbol): string {
529+
function symbolName(symbol: Symbol): string | undefined {
530530
if (symbol.name !== "default") {
531531
return symbol.name;
532532
}
533533

534-
const name = forEach(symbol.declarations, decl => {
534+
return forEach(symbol.declarations, decl => {
535+
if (isExportAssignment(decl)) {
536+
return isIdentifier(decl.expression) ? decl.expression.text : undefined;
537+
}
535538
const name = getNameOfDeclaration(decl);
536539
return name && name.kind === SyntaxKind.Identifier && name.text;
537540
});
538-
Debug.assert(!!name);
539-
return name;
540541
}
541542

542543
/** If at an export specifier, go to the symbol it refers to. */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @Filename: /a.ts
4+
////const [|{| "isWriteAccess": true, "isDefinition": true |}a|] = 0;
5+
////export default [|a|];
6+
7+
// @Filename: /b.ts
8+
////import [|{| "isWriteAccess": true, "isDefinition": true |}a|] from "./a";
9+
////[|a|];
10+
11+
const [r0, r1, r2, r3] = test.ranges();
12+
verify.referenceGroups([r0, r1], [
13+
{ definition: "const a: 0", ranges: [r0, r1] },
14+
{ definition: "import a", ranges: [r2, r3] }
15+
]);
16+
verify.singleReferenceGroup("import a", [r2, r3]);

0 commit comments

Comments
 (0)