* Given a local reference, we might notice that it's an import/export and recursively search for references of that. * If at an import, look locally for the symbol it imports. * If at an export, look for all imports of it. * This doesn't handle export specifiers; that is d
(node, symbol, checker, comingFromExport)
| 136597 | * @param comingFromExport If we are doing a search for all exports, don't bother looking backwards for the imported symbol, since that's the reason we're here. |
| 136598 | */ |
| 136599 | function getImportOrExportSymbol(node, symbol, checker, comingFromExport) { |
| 136600 | return comingFromExport ? getExport() : getExport() || getImport(); |
| 136601 | function getExport() { |
| 136602 | var _a; |
| 136603 | var parent = node.parent; |
| 136604 | var grandparent = parent.parent; |
| 136605 | if (symbol.exportSymbol) { |
| 136606 | if (parent.kind === 206 /* SyntaxKind.PropertyAccessExpression */) { |
| 136607 | // When accessing an export of a JS module, there's no alias. The symbol will still be flagged as an export even though we're at the use. |
| 136608 | // So check that we are at the declaration. |
| 136609 | return ((_a = symbol.declarations) === null || _a === void 0 ? void 0 : _a.some(function (d) { return d === parent; })) && ts.isBinaryExpression(grandparent) |
| 136610 | ? getSpecialPropertyExport(grandparent, /*useLhsSymbol*/ false) |
| 136611 | : undefined; |
| 136612 | } |
| 136613 | else { |
| 136614 | return exportInfo(symbol.exportSymbol, getExportKindForDeclaration(parent)); |
| 136615 | } |
| 136616 | } |
| 136617 | else { |
| 136618 | var exportNode = getExportNode(parent, node); |
| 136619 | if (exportNode && ts.hasSyntacticModifier(exportNode, 1 /* ModifierFlags.Export */)) { |
| 136620 | if (ts.isImportEqualsDeclaration(exportNode) && exportNode.moduleReference === node) { |
| 136621 | // We're at `Y` in `export import X = Y`. This is not the exported symbol, the left-hand-side is. So treat this as an import statement. |
| 136622 | if (comingFromExport) { |
| 136623 | return undefined; |
| 136624 | } |
| 136625 | var lhsSymbol = checker.getSymbolAtLocation(exportNode.name); |
| 136626 | return { kind: 0 /* ImportExport.Import */, symbol: lhsSymbol }; |
| 136627 | } |
| 136628 | else { |
| 136629 | return exportInfo(symbol, getExportKindForDeclaration(exportNode)); |
| 136630 | } |
| 136631 | } |
| 136632 | else if (ts.isNamespaceExport(parent)) { |
| 136633 | return exportInfo(symbol, 0 /* ExportKind.Named */); |
| 136634 | } |
| 136635 | // If we are in `export = a;` or `export default a;`, `parent` is the export assignment. |
| 136636 | else if (ts.isExportAssignment(parent)) { |
| 136637 | return getExportAssignmentExport(parent); |
| 136638 | } |
| 136639 | // If we are in `export = class A {};` (or `export = class A {};`) at `A`, `parent.parent` is the export assignment. |
| 136640 | else if (ts.isExportAssignment(grandparent)) { |
| 136641 | return getExportAssignmentExport(grandparent); |
| 136642 | } |
| 136643 | // Similar for `module.exports =` and `exports.A =`. |
| 136644 | else if (ts.isBinaryExpression(parent)) { |
| 136645 | return getSpecialPropertyExport(parent, /*useLhsSymbol*/ true); |
| 136646 | } |
| 136647 | else if (ts.isBinaryExpression(grandparent)) { |
| 136648 | return getSpecialPropertyExport(grandparent, /*useLhsSymbol*/ true); |
| 136649 | } |
| 136650 | else if (ts.isJSDocTypedefTag(parent)) { |
| 136651 | return exportInfo(symbol, 0 /* ExportKind.Named */); |
| 136652 | } |
| 136653 | } |
| 136654 | function getExportAssignmentExport(ex) { |
| 136655 | // Get the symbol for the `export =` node; its parent is the module it's the export of. |
| 136656 | if (!ex.symbol.parent) |