import type { AttrCtor } from '../expr/attr'; import type { CallCtor } from '../expr/call'; import type { SubscriptCtor } from '../expr/subscript'; import type { ReturnCtor } from '../stmt/return'; type Ctor = (...args: Array) => any; type Factory = { (...args: Parameters): ReturnType; /** Sets the implementation of this factory. */ set(fn: T): void; }; function createFactory(name: string): Factory { let impl: T | undefined; const slot = ((...args: Parameters) => { if (!impl) throw new Error(`${name} factory not registered`); return impl(...args); }) as Factory; slot.set = (fn: T) => { impl = fn; }; return slot; } export const f = { /** Factory for creating property access expressions (e.g., `obj.foo`). */ attr: createFactory('attr'), /** Factory for creating function or method call expressions (e.g., `fn(arg)`). */ call: createFactory('call'), /** Factory for creating return statements. */ return: createFactory('return'), /** Factory for creating slice expressions. */ slice: createFactory('slice'), };