* Extract typed statements from the symbol table. * State defaults are materialized to plain values (no raw AST in output).
( stmts: Statement[], ctx: MaterializeCtx, )
| 87 | * State defaults are materialized to plain values (no raw AST in output). |
| 88 | */ |
| 89 | function extractStatements( |
| 90 | stmts: Statement[], |
| 91 | ctx: MaterializeCtx, |
| 92 | ): { |
| 93 | stateDeclarations: Record<string, unknown>; |
| 94 | queryStatements: QueryStatementInfo[]; |
| 95 | mutationStatements: MutationStatementInfo[]; |
| 96 | } { |
| 97 | const stateDeclarations: Record<string, unknown> = {}; |
| 98 | const queryStatements: QueryStatementInfo[] = []; |
| 99 | const mutationStatements: MutationStatementInfo[] = []; |
| 100 | |
| 101 | for (const stmt of stmts) { |
| 102 | switch (stmt.kind) { |
| 103 | case "state": |
| 104 | stateDeclarations[stmt.id] = materializeValue(stmt.init, ctx); |
| 105 | break; |
| 106 | case "query": |
| 107 | queryStatements.push({ |
| 108 | statementId: stmt.id, |
| 109 | toolAST: stmt.call.args[0] ?? null, |
| 110 | argsAST: stmt.call.args[1] ?? null, |
| 111 | defaultsAST: stmt.call.args[2] ?? null, |
| 112 | refreshAST: stmt.call.args[3] ?? null, |
| 113 | deps: stmt.deps, |
| 114 | complete: true, |
| 115 | }); |
| 116 | break; |
| 117 | case "mutation": |
| 118 | mutationStatements.push({ |
| 119 | statementId: stmt.id, |
| 120 | toolAST: stmt.call.args[0] ?? null, |
| 121 | argsAST: stmt.call.args[1] ?? null, |
| 122 | }); |
| 123 | break; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | // Auto-declare: any $var referenced in code but not explicitly declared → null default. |
| 128 | // collectQueryDeps already walks AST for StateRef nodes — reuse it here. |
| 129 | for (const stmt of stmts) { |
| 130 | const nodes = |
| 131 | stmt.kind === "state" |
| 132 | ? [stmt.init] |
| 133 | : stmt.kind === "value" |
| 134 | ? [stmt.expr] |
| 135 | : stmt.kind === "query" || stmt.kind === "mutation" |
| 136 | ? stmt.call.args |
| 137 | : []; |
| 138 | for (const node of nodes) { |
| 139 | for (const dep of collectQueryDeps(node)) { |
| 140 | if (!(dep in stateDeclarations)) { |
| 141 | stateDeclarations[dep] = null; |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 |
no test coverage detected