MCPcopy
hub / github.com/thesysdev/openui / resolveRef

Function resolveRef

packages/lang-core/src/parser/materialize.ts:42–73  ·  view source on GitHub ↗

* 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")

Source from the content-addressed store, hash-verified

40 * for Query/Mutation declarations. Shared by materializeValue and materializeExpr.
41 */
42function 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

Callers 2

materializeExprInternalFunction · 0.85
materializeValueFunction · 0.85

Calls 7

isReservedCallFunction · 0.90
isElementNodeFunction · 0.90
materializeValueFunction · 0.85
materializeExprFunction · 0.85
hasMethod · 0.80
pushMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected