MCPcopy Index your code
hub / github.com/nodejs/node / getReferencedSymbolsForModule

Function getReferencedSymbolsForModule

test/fixtures/snapshot/typescript.js:137525–137580  ·  view source on GitHub ↗
(program, symbol, excludeImportTypeOfExportEquals, sourceFiles, sourceFilesSet)

Source from the content-addressed store, hash-verified

137523 return program.getSourceFiles().indexOf(sourceFile);
137524 }
137525 function getReferencedSymbolsForModule(program, symbol, excludeImportTypeOfExportEquals, sourceFiles, sourceFilesSet) {
137526 ts.Debug.assert(!!symbol.valueDeclaration);
137527 var references = ts.mapDefined(FindAllReferences.findModuleReferences(program, sourceFiles, symbol), function (reference) {
137528 if (reference.kind === "import") {
137529 var parent = reference.literal.parent;
137530 if (ts.isLiteralTypeNode(parent)) {
137531 var importType = ts.cast(parent.parent, ts.isImportTypeNode);
137532 if (excludeImportTypeOfExportEquals && !importType.qualifier) {
137533 return undefined;
137534 }
137535 }
137536 // import("foo") with no qualifier will reference the `export =` of the module, which may be referenced anyway.
137537 return nodeEntry(reference.literal);
137538 }
137539 else {
137540 return {
137541 kind: 0 /* EntryKind.Span */,
137542 fileName: reference.referencingFile.fileName,
137543 textSpan: ts.createTextSpanFromRange(reference.ref),
137544 };
137545 }
137546 });
137547 if (symbol.declarations) {
137548 for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) {
137549 var decl = _a[_i];
137550 switch (decl.kind) {
137551 case 305 /* SyntaxKind.SourceFile */:
137552 // Don't include the source file itself. (This may not be ideal behavior, but awkward to include an entire file as a reference.)
137553 break;
137554 case 261 /* SyntaxKind.ModuleDeclaration */:
137555 if (sourceFilesSet.has(decl.getSourceFile().fileName)) {
137556 references.push(nodeEntry(decl.name));
137557 }
137558 break;
137559 default:
137560 // This may be merged with something.
137561 ts.Debug.assert(!!(symbol.flags & 33554432 /* SymbolFlags.Transient */), "Expected a module symbol to be declared by a SourceFile or ModuleDeclaration.");
137562 }
137563 }
137564 }
137565 var exported = symbol.exports.get("export=" /* InternalSymbolName.ExportEquals */);
137566 if (exported === null || exported === void 0 ? void 0 : exported.declarations) {
137567 for (var _b = 0, _c = exported.declarations; _b < _c.length; _b++) {
137568 var decl = _c[_b];
137569 var sourceFile = decl.getSourceFile();
137570 if (sourceFilesSet.has(sourceFile.fileName)) {
137571 // At `module.exports = ...`, reference node is `module`
137572 var node = ts.isBinaryExpression(decl) && ts.isPropertyAccessExpression(decl.left) ? decl.left.expression :
137573 ts.isExportAssignment(decl) ? ts.Debug.checkDefined(ts.findChildOfKind(decl, 93 /* SyntaxKind.ExportKeyword */, sourceFile)) :
137574 ts.getNameOfDeclaration(decl) || decl;
137575 references.push(nodeEntry(node));
137576 }
137577 }
137578 }
137579 return references.length ? [{ definition: { type: 0 /* DefinitionKind.Symbol */, symbol: symbol }, references: references }] : ts.emptyArray;
137580 }
137581 /** As in a `readonly prop: any` or `constructor(readonly prop: any)`, not a `readonly any[]`. */
137582 function isReadonlyTypeOperator(node) {

Calls 5

nodeEntryFunction · 0.85
assertMethod · 0.80
hasMethod · 0.65
getMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected