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

Method inputExpressionOf

ark/aot/precompile.ts:5500–5576  ·  view source on GitHub ↗
(
		input: Input,
		site: Site,
		module: SourceModule,
		prefix: string
	)

Source from the content-addressed store, hash-verified

5498 }
5499
5500 private inputExpressionOf(
5501 input: Input,
5502 site: Site,
5503 module: SourceModule,
5504 prefix: string
5505 ): PassedInput | string {
5506 const isVisible = (binding: Binding) =>
5507 ![...module.scopes.bindingsById.values()].some(
5508 other =>
5509 other !== binding &&
5510 other.name === binding.name &&
5511 contains(other.scope.node, site) &&
5512 contains(binding.scope.node, other.scope.node)
5513 )
5514 if (input.kind === "local") {
5515 const binding = this.bindingsByInput.get(input)!
5516 return isVisible(binding) ?
5517 { expression: binding.name, label: binding.name, binding }
5518 : `\`${binding.name}\` (${module.positionOf(binding.id)}) is shadowed where the site is written, so its factory can't receive it`
5519 }
5520 let namespace: PassedInput | undefined
5521 const importing: PassedInput[] = []
5522 for (const binding of module.scopes.bindingsById.values()) {
5523 if (
5524 binding.kind !== "import" ||
5525 !isVisible(binding) ||
5526 !this.isKept(binding.declaration.parent!, module)
5527 )
5528 continue
5529 const target = this.graph.importOf(binding, module)
5530 if (target.kind === "namespace" && target.module.id === input.file) {
5531 const expression = appendStringifiedKey(binding.name, input.name)
5532 namespace = { expression, label: expression, binding }
5533 } else if (
5534 (target.kind === "json" &&
5535 target.id === input.file &&
5536 (target.name ?? "default") === input.name) ||
5537 ((target.kind === "binding" || target.kind === "expression") &&
5538 target.module.id === input.file &&
5539 (target.name ?? "default") === input.name)
5540 ) {
5541 importing.push({
5542 expression: binding.name,
5543 label: binding.name,
5544 binding
5545 })
5546 }
5547 }
5548 // the binding the site names, where another imports the value too, as
5549 // through a re-export, so a mock of what the site reads reaches it
5550 if (importing.length) {
5551 return (
5552 importing.find(({ binding }) =>
5553 binding!.references.some(({ id }) => contains(site, id))
5554 ) ?? importing[0]
5555 )
5556 }
5557 if (namespace) return namespace

Callers 2

receiveInputsMethod · 0.95
receiveHelperMethod · 0.95

Calls 12

isKeptMethod · 0.95
isOnCycleMethod · 0.95
containsFunction · 0.90
specifierOfFunction · 0.90
hashOfFunction · 0.90
positionOfMethod · 0.80
importOfMethod · 0.80
findMethod · 0.80
getMethod · 0.65
resolveMethod · 0.65
pushMethod · 0.45
pathOfMethod · 0.45

Tested by

no test coverage detected