* Classify a raw statement + parsed expression into a typed Statement. * Determined at parse time from token type + expression shape.
(raw: RawStmt, expr: ASTNode)
| 54 | * Determined at parse time from token type + expression shape. |
| 55 | */ |
| 56 | function classifyStatement(raw: RawStmt, expr: ASTNode): Statement { |
| 57 | // Query(...) → query declaration — check BEFORE $var to handle `$foo = Query(...)` correctly |
| 58 | if (expr.k === "Comp" && expr.name === RESERVED_CALLS.Query) { |
| 59 | const deps = collectQueryDeps(expr.args[1]); |
| 60 | return { |
| 61 | kind: "query", |
| 62 | id: raw.id, |
| 63 | call: { callee: RESERVED_CALLS.Query, args: expr.args }, |
| 64 | expr, |
| 65 | deps: deps.length > 0 ? deps : undefined, |
| 66 | }; |
| 67 | } |
| 68 | // Mutation(...) → mutation declaration |
| 69 | if (expr.k === "Comp" && expr.name === RESERVED_CALLS.Mutation) { |
| 70 | return { |
| 71 | kind: "mutation", |
| 72 | id: raw.id, |
| 73 | call: { callee: RESERVED_CALLS.Mutation, args: expr.args }, |
| 74 | expr, |
| 75 | }; |
| 76 | } |
| 77 | // $variables → state declaration |
| 78 | if (raw.idTokenType === T.StateVar) { |
| 79 | return { kind: "state", id: raw.id, init: expr }; |
| 80 | } |
| 81 | // Everything else → value declaration |
| 82 | return { kind: "value", id: raw.id, expr }; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Extract typed statements from the symbol table. |
no test coverage detected