MCPcopy Create free account
hub / github.com/arktypeio/arktype / importOf

Method importOf

ark/aot/graph.ts:1458–1511  ·  view source on GitHub ↗
(binding: Binding, module: SourceModule)

Source from the content-addressed store, hash-verified

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,

Callers 15

exportOfMethod · 0.95
arkExportOfMethod · 0.95
keyKindOfMethod · 0.95
queriedOfMethod · 0.95
jsxComponentOfMethod · 0.95
bindingInitOfMethod · 0.95
bindingLiteralOfMethod · 0.95
namespaceExportOfMethod · 0.95
isArktypeImportMethod · 0.95
readsPrimitiveMethod · 0.95
boundFunctionOfMethod · 0.95

Calls 5

resolveMethod · 0.95
jsonExportOfMethod · 0.95
exportOfMethod · 0.95
exportNameOfFunction · 0.90
arktypeExportOfFunction · 0.85

Tested by

no test coverage detected