( node: Node, module: SourceModule, held: boolean, reach: Reach )
| 5063 | } |
| 5064 | |
| 5065 | private reaches( |
| 5066 | node: Node, |
| 5067 | module: SourceModule, |
| 5068 | held: boolean, |
| 5069 | reach: Reach |
| 5070 | ): boolean { |
| 5071 | const seen = held ? reach.held : reach.exact |
| 5072 | if (seen.has(node)) return false |
| 5073 | seen.add(node) |
| 5074 | const follow = (next: Node) => this.reaches(next, module, held, reach) |
| 5075 | const followExact = (next: Node) => this.reaches(next, module, false, reach) |
| 5076 | const followHeld = (next: Node) => this.reaches(next, module, true, reach) |
| 5077 | const [operand, operator] = operatorOf(node) |
| 5078 | switch (operator?.type) { |
| 5079 | case "MemberExpression": { |
| 5080 | if (operator.object !== operand || isWriteTarget(operator)) return false |
| 5081 | // a read off what may be a Scope is checked by scopeReadOf |
| 5082 | if (!held) return !mayBeOtherArk(this.kindOf(operand, module)) |
| 5083 | const kind = this.kindOf(operator, module) |
| 5084 | return ( |
| 5085 | (mayBeOtherArk(kind) && followExact(operator)) || |
| 5086 | (mayHoldArk(kind) && follow(operator)) |
| 5087 | ) |
| 5088 | } |
| 5089 | case "CallExpression": |
| 5090 | case "NewExpression": { |
| 5091 | if (operator.callee === operand) return held |
| 5092 | const fn = this.functionOf(operator.callee, module) |
| 5093 | if (fn?.[1] !== module) return true |
| 5094 | // e.g. `hand($)` with `hand = s => each(s)` |
| 5095 | const param = runtimeParamsOf(fn[0])[ |
| 5096 | operator.arguments.indexOf(operand as never) |
| 5097 | ] |
| 5098 | return ( |
| 5099 | param?.type !== "Identifier" || |
| 5100 | this.readsReachUnseen( |
| 5101 | module.scopes.bindingsById.get(param), |
| 5102 | module, |
| 5103 | held, |
| 5104 | reach |
| 5105 | ) |
| 5106 | ) |
| 5107 | } |
| 5108 | case "ConditionalExpression": |
| 5109 | case "LogicalExpression": |
| 5110 | return ( |
| 5111 | (operator.type === "LogicalExpression" || |
| 5112 | operator.test !== operand) && |
| 5113 | follow(operator) |
| 5114 | ) |
| 5115 | case "SequenceExpression": |
| 5116 | return ( |
| 5117 | operator.expressions[operator.expressions.length - 1] === operand && |
| 5118 | follow(operator) |
| 5119 | ) |
| 5120 | case "AwaitExpression": |
| 5121 | return follow(operator) |
| 5122 | case "ArrowFunctionExpression": |
no test coverage detected