(binding: Binding, module: SourceModule)
| 1456 | } |
| 1457 | |
| 1458 | importOf(binding: Binding, module: SourceModule): ImportTarget { |
| 1459 | const declaration = binding.declaration |
| 1460 | const source = |
| 1461 | ( |
| 1462 | declaration.type === "ImportSpecifier" || |
| 1463 | declaration.type === "ImportDefaultSpecifier" || |
| 1464 | declaration.type === "ImportNamespaceSpecifier" |
| 1465 | ) ? |
| 1466 | (declaration.parent as Extract<Node, { type: "ImportDeclaration" }>) |
| 1467 | .source.value |
| 1468 | : undefined |
| 1469 | if (source === undefined) { |
| 1470 | return { |
| 1471 | kind: "unresolved", |
| 1472 | message: `\`${binding.name}\` is a TypeScript import-equals declaration` |
| 1473 | } |
| 1474 | } |
| 1475 | const target = this.resolve(source, module) |
| 1476 | if (!(target instanceof SourceModule)) { |
| 1477 | if (target.kind === "json") { |
| 1478 | return ( |
| 1479 | declaration.type === "ImportNamespaceSpecifier" ? |
| 1480 | { ...target, name: "*" } |
| 1481 | : declaration.type === "ImportDefaultSpecifier" ? |
| 1482 | { ...target, name: "default" } |
| 1483 | : this.jsonExportOf( |
| 1484 | target, |
| 1485 | exportNameOf((declaration as ImportSpecifier).imported) |
| 1486 | ) |
| 1487 | ) |
| 1488 | } |
| 1489 | return ( |
| 1490 | target.kind !== "arktypeNamespace" || |
| 1491 | declaration.type === "ImportNamespaceSpecifier" |
| 1492 | ) ? |
| 1493 | target |
| 1494 | : arktypeExportOf( |
| 1495 | target, |
| 1496 | declaration.type === "ImportSpecifier" ? |
| 1497 | exportNameOf(declaration.imported) |
| 1498 | : "default" |
| 1499 | ) |
| 1500 | } |
| 1501 | return ( |
| 1502 | declaration.type === "ImportNamespaceSpecifier" ? |
| 1503 | { kind: "namespace", module: target } |
| 1504 | : declaration.type === "ImportDefaultSpecifier" ? |
| 1505 | this.exportOf(target, "default") |
| 1506 | : this.exportOf( |
| 1507 | target, |
| 1508 | exportNameOf((declaration as ImportSpecifier).imported) |
| 1509 | ) |
| 1510 | ) |
| 1511 | } |
| 1512 | |
| 1513 | exportOf( |
| 1514 | module: SourceModule, |
no test coverage detected