( node: Node, module: SourceModule, seen = new Set<string>() )
| 6079 | // e.g. `register` of `import { register } from "registry"`, or |
| 6080 | // `registry_1.register` of `const registry_1 = require("./registry")` |
| 6081 | private definitionOf( |
| 6082 | node: Node, |
| 6083 | module: SourceModule, |
| 6084 | seen = new Set<string>() |
| 6085 | ): [Node, SourceModule] | undefined { |
| 6086 | node = namedFunctionOf(unwrapChain(node), module) |
| 6087 | if ( |
| 6088 | isFunctionNode(node) || |
| 6089 | node.type === "ClassDeclaration" || |
| 6090 | node.type === "ClassExpression" |
| 6091 | ) |
| 6092 | return [node, module] |
| 6093 | const [object, member] = |
| 6094 | node.type === "MemberExpression" ? |
| 6095 | [unwrapChain(node.object), memberNameOf(node)] |
| 6096 | : [node, undefined] |
| 6097 | const binding = |
| 6098 | object.type === "Identifier" ? |
| 6099 | (module.scopes.byId.get(object)?.binding ?? |
| 6100 | module.scopes.bindingsById.get(object)) |
| 6101 | : undefined |
| 6102 | if (!binding || binding.writes.length) return |
| 6103 | const source = sourceOf(binding) |
| 6104 | if (!source) { |
| 6105 | if (member !== undefined) return |
| 6106 | if (binding.kind === "function" || binding.kind === "class") |
| 6107 | return [binding.declaration, module] |
| 6108 | const init = |
| 6109 | binding.kind === "const" && |
| 6110 | binding.declaration.type === "VariableDeclarator" && |
| 6111 | binding.declaration.init |
| 6112 | return init ? this.definitionOf(init, module, seen) : undefined |
| 6113 | } |
| 6114 | const [specifier, imported] = source |
| 6115 | const name = |
| 6116 | imported === "*" ? member |
| 6117 | : member === undefined ? imported |
| 6118 | : undefined |
| 6119 | const target = |
| 6120 | typeof name === "string" ? |
| 6121 | this.packageModuleOf(specifier, module) |
| 6122 | : undefined |
| 6123 | return target && this.exportedDefinitionOf(target, name as string, seen) |
| 6124 | } |
| 6125 | |
| 6126 | private exportedDefinitionOf( |
| 6127 | module: SourceModule, |
no test coverage detected