| 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 |