(root: BaseNode)
| 224 | // a keyword's predicate isn't user code. a union's cases hold what its branches |
| 225 | // do. every node finding none reaches none too, so a cycle is walked once |
| 226 | const reachesUserCode = (root: BaseNode): boolean => { |
| 227 | const final = isResolutionFinal() |
| 228 | const reached = new Set<BaseNode>() |
| 229 | const reaches = (node: BaseNode): boolean => { |
| 230 | if (node.userCode) return true |
| 231 | if (!node.hasAlias || reached.has(node)) return false |
| 232 | if (node.c.reachesUserCode !== undefined) return node.c.reachesUserCode |
| 233 | reached.add(node) |
| 234 | const found = |
| 235 | node.is("alias") ? |
| 236 | reaches(node.resolution) |
| 237 | : node.children.some(reaches) || |
| 238 | (!node.is("union") && node.otherRefs.some(reaches)) |
| 239 | if (found && final) node.c.reachesUserCode = true |
| 240 | return found |
| 241 | } |
| 242 | if (reaches(root)) return true |
| 243 | if (final) for (const node of reached) node.c.reachesUserCode = false |
| 244 | return false |
| 245 | } |
| 246 | |
| 247 | // 0 compares data itself, 1 reads a primitive it points to, 2 walks an object |
| 248 | const branchCost = (branch: BaseRoot): number => { |
no test coverage detected