Support finding references at module in module.exports = or export in export = (#28221)

* Support finding references at `module` in `module.exports =` or `export` in `export =`

* Add json test
This commit is contained in:
Andy
2018-11-09 09:38:45 -08:00
committed by GitHub
parent 69c61cd166
commit aaf1d8055b
8 changed files with 82 additions and 19 deletions

View File

@@ -28100,6 +28100,9 @@ namespace ts {
case SyntaxKind.ImportType:
return isLiteralImportTypeNode(node) ? getSymbolAtLocation(node.argument.literal) : undefined;
case SyntaxKind.ExportKeyword:
return isExportAssignment(node.parent) ? Debug.assertDefined(node.parent.symbol) : undefined;
default:
return undefined;
}

View File

@@ -368,6 +368,10 @@ namespace ts.FindAllReferences.Core {
return !options.implementations && isStringLiteral(node) ? getReferencesForStringLiteral(node, sourceFiles, cancellationToken) : undefined;
}
if (symbol.escapedName === InternalSymbolName.ExportEquals) {
return getReferencedSymbolsForModule(program, symbol.parent!, /*excludeImportTypeOfExportEquals*/ false, sourceFiles, sourceFilesSet);
}
let moduleReferences: SymbolAndEntries[] = emptyArray;
const moduleSourceFile = isModuleSymbol(symbol);
let referencedNode: Node | undefined = node;
@@ -427,6 +431,22 @@ namespace ts.FindAllReferences.Core {
}
}
const exported = symbol.exports!.get(InternalSymbolName.ExportEquals);
if (exported) {
for (const decl of exported.declarations) {
const sourceFile = decl.getSourceFile();
if (sourceFilesSet.has(sourceFile.fileName)) {
// At `module.exports = ...`, reference node is `module`
const node = isBinaryExpression(decl) && isPropertyAccessExpression(decl.left)
? decl.left.expression
: isExportAssignment(decl)
? Debug.assertDefined(findChildOfKind(decl, SyntaxKind.ExportKeyword, sourceFile))
: getNameOfDeclaration(decl) || decl;
references.push(nodeEntry(node));
}
}
}
return references.length ? [{ definition: { type: DefinitionKind.Symbol, symbol }, references }] : emptyArray;
}