* Resolve a Ref node: inline from symbol table, detect cycles, emit RuntimeRef * for Query/Mutation declarations. Shared by materializeValue and materializeExpr.
(name: string, ctx: MaterializeCtx, mode: "value" | "expr")
| 40 | * for Query/Mutation declarations. Shared by materializeValue and materializeExpr. |
| 41 | */ |
| 42 | function resolveRef(name: string, ctx: MaterializeCtx, mode: "value" | "expr"): unknown | ASTNode { |
| 43 | if (ctx.visited.has(name)) { |
| 44 | ctx.unres.push(name); |
| 45 | return mode === "expr" ? { k: "Ph", n: name } : null; |
| 46 | } |
| 47 | if (!ctx.syms.has(name)) { |
| 48 | ctx.unres.push(name); |
| 49 | return mode === "expr" ? { k: "Ph", n: name } : null; |
| 50 | } |
| 51 | const target = ctx.syms.get(name)!; |
| 52 | ctx.unreached?.delete(name); |
| 53 | // Query/Mutation declarations → RuntimeRef (resolved at runtime by evaluator) |
| 54 | if (target.k === "Comp" && isReservedCall(target.name)) { |
| 55 | const refType = |
| 56 | target.name === RESERVED_CALLS.Mutation ? ("mutation" as const) : ("query" as const); |
| 57 | return { k: "RuntimeRef", n: name, refType }; |
| 58 | } |
| 59 | ctx.visited.add(name); |
| 60 | const prevStatementId = ctx.currentStatementId; |
| 61 | ctx.currentStatementId = name; |
| 62 | try { |
| 63 | const result = mode === "value" ? materializeValue(target, ctx) : materializeExpr(target, ctx); |
| 64 | // Tag ElementNode with its source statement name |
| 65 | if (mode === "value" && isElementNode(result)) { |
| 66 | result.statementId = name; |
| 67 | } |
| 68 | return result; |
| 69 | } finally { |
| 70 | ctx.currentStatementId = prevStatementId; |
| 71 | ctx.visited.delete(name); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * If node is a lazy builtin like Each(arr, varName, template), temporarily |
no test coverage detected