( node: Node, module: SourceModule, held: Held )
| 5735 | // each use of a value is followed to what holds it next, and any the build |
| 5736 | // doesn't know leaves its value unknown, as code it can't see may write it |
| 5737 | private mayWriteFrom( |
| 5738 | node: Node, |
| 5739 | module: SourceModule, |
| 5740 | held: Held |
| 5741 | ): Node | undefined { |
| 5742 | for (;;) { |
| 5743 | // e.g. `o.a` of `o = { a: type("string") }` or `{ ...o }` of |
| 5744 | // `o = { a: "string" }`, sharing nothing the program can change |
| 5745 | if (held.depth <= held.copied) return |
| 5746 | const [operand, parent] = operatorOf(node) |
| 5747 | switch (parent?.type) { |
| 5748 | case "MemberExpression": { |
| 5749 | // e.g. `o[k]`, reading `k` as a key |
| 5750 | if (parent.object !== operand) return |
| 5751 | // a write to a level it copied changes what it made |
| 5752 | if (isWriteTarget(parent)) |
| 5753 | return held.copied ? undefined : writeOf(parent) |
| 5754 | const [callee, call] = operatorOf(parent) |
| 5755 | if (call?.type === "CallExpression" && call.callee === callee) { |
| 5756 | const name = memberNameOf(parent) |
| 5757 | if (!held.copied && (name as never) in mutatingMethods) return call |
| 5758 | // e.g. `T.or(o)` or `schemas.user(data)`, calling a Type |
| 5759 | if ( |
| 5760 | isOnlyArk(this.kindOf(operand, module)) || |
| 5761 | isOnlyArk(this.kindOf(parent, module)) |
| 5762 | ) |
| 5763 | return |
| 5764 | // e.g. `o.reset()` given `o = { reset() { this.a = 1 } }`, run |
| 5765 | // with its receiver as `this` |
| 5766 | const method = this.methodOf(parent, module, this.finalKindOfKey) |
| 5767 | if (method) { |
| 5768 | const [write] = this.mayWritesThroughThis(...method, held) |
| 5769 | return ( |
| 5770 | !write || method[1] === module ? write |
| 5771 | : this.escapes.has(write) ? this.escape(call) |
| 5772 | : call |
| 5773 | ) |
| 5774 | } |
| 5775 | const builtin = |
| 5776 | typeof name === "string" ? heldByMethod[name] : undefined |
| 5777 | // one the build doesn't know may do anything with its receiver |
| 5778 | if (!builtin) return this.escape(call) |
| 5779 | const write = |
| 5780 | builtin[1] && |
| 5781 | call.arguments[0] && |
| 5782 | this.mayWriteInCallback( |
| 5783 | call, |
| 5784 | call.arguments[0], |
| 5785 | module, |
| 5786 | held, |
| 5787 | builtin[1] |
| 5788 | ) |
| 5789 | if (write) return write |
| 5790 | const next = heldThrough(held, builtin[0]) |
| 5791 | if (!next) return |
| 5792 | node = call |
| 5793 | held = next |
| 5794 | continue |
no test coverage detected