( binding: Binding )
| 608 | // the module an import or a require reads a binding from, and the name it |
| 609 | // reads, "*" for the whole module |
| 610 | const sourceOf = ( |
| 611 | binding: Binding |
| 612 | ): [specifier: string, name: string] | undefined => { |
| 613 | const declaration = binding.declaration |
| 614 | switch (declaration.type) { |
| 615 | case "ImportSpecifier": |
| 616 | case "ImportDefaultSpecifier": |
| 617 | case "ImportNamespaceSpecifier": |
| 618 | return [ |
| 619 | (declaration.parent as ImportDeclaration).source.value, |
| 620 | declaration.type === "ImportSpecifier" ? |
| 621 | exportNameOf(declaration.imported) |
| 622 | : declaration.type === "ImportDefaultSpecifier" ? "default" |
| 623 | : "*" |
| 624 | ] |
| 625 | case "VariableDeclarator": { |
| 626 | const init = declaration.init && unwrapExpression(declaration.init) |
| 627 | const loaded = |
| 628 | init?.type === "CallExpression" ? loadedSourceOf(init) : undefined |
| 629 | if (loaded?.type !== "Literal" || typeof loaded.value !== "string") return |
| 630 | if (declaration.id.type === "Identifier") return [loaded.value, "*"] |
| 631 | // e.g. `const { register } = require("registry")` |
| 632 | const property = |
| 633 | declaration.id.type === "ObjectPattern" ? |
| 634 | declaration.id.properties.find( |
| 635 | property => |
| 636 | property.type === "Property" && property.value === binding.id |
| 637 | ) |
| 638 | : undefined |
| 639 | const name = |
| 640 | property?.type === "Property" ? keyNameOf(property) : undefined |
| 641 | return typeof name === "string" ? [loaded.value, name] : undefined |
| 642 | } |
| 643 | } |
| 644 | } |
| 645 | |
| 646 | // e.g. `exports` or `module.exports` |
| 647 | const isExportsOf = (node: Node): boolean => { |
no test coverage detected