( modules: readonly SourceModule[], options?: ThisReadsOptions )
| 1488 | } |
| 1489 | |
| 1490 | const buildThisReadsContext = ( |
| 1491 | modules: readonly SourceModule[], |
| 1492 | options?: ThisReadsOptions |
| 1493 | ): ThisReadsContext => { |
| 1494 | const resolve = options?.resolve ?? (() => undefined) |
| 1495 | const importersById = new Map<string, ThisImportEdge[]>() |
| 1496 | const addEdge = ( |
| 1497 | specifier: string, |
| 1498 | importer: SourceModule, |
| 1499 | edge: ThisImportEdge |
| 1500 | ) => { |
| 1501 | const target = resolve(specifier, importer) |
| 1502 | if (!target) return |
| 1503 | const edges = importersById.get(target.id) |
| 1504 | if (edges) edges.push(edge) |
| 1505 | else importersById.set(target.id, [edge]) |
| 1506 | } |
| 1507 | let hasDynamicImport = false |
| 1508 | const uncalledKeys = new Set<string>() |
| 1509 | let hasProtoInheritance = false |
| 1510 | let hasDescriptorRead = false |
| 1511 | let hasEscapedPrototype = false |
| 1512 | let patchesBuiltins = false |
| 1513 | |
| 1514 | for (const module of modules) { |
| 1515 | for (const statement of module.program.body) { |
| 1516 | if (statement.type === "ImportDeclaration") { |
| 1517 | if (statement.importKind === "type") continue |
| 1518 | for (const specifier of statement.specifiers) { |
| 1519 | if ( |
| 1520 | specifier.type === "ImportSpecifier" && |
| 1521 | specifier.importKind === "type" |
| 1522 | ) |
| 1523 | continue |
| 1524 | const binding = module.scopes.bindingsById.get(specifier.local)! |
| 1525 | addEdge( |
| 1526 | statement.source.value, |
| 1527 | module, |
| 1528 | specifier.type === "ImportNamespaceSpecifier" ? |
| 1529 | { kind: "namespace", binding, module } |
| 1530 | : { |
| 1531 | kind: "named", |
| 1532 | name: |
| 1533 | specifier.type === "ImportDefaultSpecifier" ? |
| 1534 | "default" |
| 1535 | : exportNameOf(specifier.imported), |
| 1536 | binding, |
| 1537 | module |
| 1538 | } |
| 1539 | ) |
| 1540 | } |
| 1541 | } else if (statement.type === "ExportNamedDeclaration") { |
| 1542 | if (!statement.source || statement.exportKind === "type") continue |
| 1543 | for (const specifier of statement.specifiers) { |
| 1544 | if (specifier.exportKind === "type") continue |
| 1545 | addEdge(statement.source.value, module, { |
| 1546 | kind: "reexport", |
| 1547 | name: exportNameOf(specifier.local), |
no test coverage detected