Merge pull request #15846 from Microsoft/findAllRefs_symbolNoName

findAllReferences: In `export default foo`, symbol name is `foo`
This commit is contained in:
Andy 2017-05-15 10:38:21 -07:00 committed by GitHub
commit 687ab54d17
3 changed files with 25 additions and 4 deletions

View File

@ -4032,6 +4032,10 @@ namespace ts {
return node.kind === SyntaxKind.ExportSpecifier;
}
export function isExportAssignment(node: Node): node is ExportAssignment {
return node.kind === SyntaxKind.ExportAssignment;
}
export function isModuleOrEnumDeclaration(node: Node): node is ModuleDeclaration | EnumDeclaration {
return node.kind === SyntaxKind.ModuleDeclaration || node.kind === SyntaxKind.EnumDeclaration;
}

View File

@ -526,17 +526,18 @@ namespace ts.FindAllReferences {
return isExternalModuleSymbol(exportingModuleSymbol) ? { exportingModuleSymbol, exportKind } : undefined;
}
function symbolName(symbol: Symbol): string {
function symbolName(symbol: Symbol): string | undefined {
if (symbol.name !== "default") {
return symbol.name;
}
const name = forEach(symbol.declarations, decl => {
return forEach(symbol.declarations, decl => {
if (isExportAssignment(decl)) {
return isIdentifier(decl.expression) ? decl.expression.text : undefined;
}
const name = getNameOfDeclaration(decl);
return name && name.kind === SyntaxKind.Identifier && name.text;
});
Debug.assert(!!name);
return name;
}
/** If at an export specifier, go to the symbol it refers to. */

View File

@ -0,0 +1,16 @@
/// <reference path='fourslash.ts' />
// @Filename: /a.ts
////const [|{| "isWriteAccess": true, "isDefinition": true |}a|] = 0;
////export default [|a|];
// @Filename: /b.ts
////import [|{| "isWriteAccess": true, "isDefinition": true |}a|] from "./a";
////[|a|];
const [r0, r1, r2, r3] = test.ranges();
verify.referenceGroups([r0, r1], [
{ definition: "const a: 0", ranges: [r0, r1] },
{ definition: "import a", ranges: [r2, r3] }
]);
verify.singleReferenceGroup("import a", [r2, r3]);