UNPKG

marko

Version:

Optimized runtime for Marko templates.

75 lines (74 loc) • 4.44 kB
import { types as t } from "@marko/compiler"; import { type Binding, type Getter, type ReferencedBindings } from "./bindings"; import { type Opt } from "./optional"; import { type Section } from "./sections"; import { type PlaceSlot } from "./slots"; export interface Signal { identifier: t.Identifier; referencedBindings: ReferencedBindings; section: Section; build: undefined | (() => t.Expression | undefined); register?: boolean; referenced?: boolean; values: Array<{ signal: Signal; /** None for a signal that runs on the scope alone. */ value: t.Expression | undefined; }>; intersections: Opt<Signal>; /** Signals this one forwards into: they must declare first when the * forward simplifies to a bare, eagerly evaluated reference. */ forwards: Opt<Signal>; render: t.Statement[]; effect: t.Statement[]; hasHTMLEffect: boolean; storesValue: boolean; forceStore: boolean; inline: { value: t.Expression | undefined; } | undefined; export: boolean; extraArgs: t.Expression[] | undefined; prependStatements: t.Statement[] | undefined; buildAssignment: ((valueSection: Section, value: t.Expression) => t.Expression | undefined) | undefined; } type closureSignalBuilder = (closure: Binding, render: t.Expression) => t.Expression; export type ClosureHop = { kind: "if"; nodeBinding: Binding; index: number; } | { kind: "for"; nodeBinding: Binding; }; export declare const getSignals: (section: Section) => Map<unknown, Signal>; export declare function setClosureSignalBuilder(tag: t.NodePath<t.MarkoTag>, hop: ClosureHop, build?: closureSignalBuilder): void; export declare function buildClosureHop(hop: ClosureHop, render: t.Expression): t.CallExpression; export declare function setSectionOwnerResumedByMarker(section: Section): void; export declare function getContentClosureValues(bodySection: Section): { scope: t.Identifier; levels: t.Expression[]; } | undefined; export declare function writeSlot(slot: PlaceSlot | undefined, expression: t.Expression): string | undefined; export declare function setSectionDebugVar(section: Section, accessor: string, name: string, loc: t.SourceLocation | null | undefined): void; export declare function addWriteScopeBuilder(section: Section, builder: (writeCall: t.Expression) => t.Expression): void; export declare const getHTMLSectionStatements: (section: Section) => t.Statement[]; declare const setReturnValueIdentifier: (section: Section, value: t.Identifier | undefined) => void; export { setReturnValueIdentifier }; export declare function getBindingGetterIdentifier(binding: Binding, getterSection: Getter["hoisted"]): t.Identifier; export declare function getSignal(section: Section, referencedBindings: ReferencedBindings, name?: string): Signal; export declare function initValue(binding: Binding, isLet?: boolean): Signal; export declare function signalHasWork(signal: Signal): boolean; export declare function buildSignalFn(signal: Signal): t.Expression; export declare function getSignalValueIdentifier(signal: Signal): t.Identifier; export declare function trimEmptyArgs(args: (t.Expression | undefined | false)[]): t.Expression[]; export declare function addStatement(type: "render" | "effect", targetSection: Section, referencedBindings: ReferencedBindings, statement: t.Statement | t.Statement[] | t.Expression, isPure?: boolean): void; export declare function addTagStatement(tag: t.NodePath<t.MarkoTag>, statement: t.Statement): void; export declare function addValue(targetSection: Section, referencedBindings: ReferencedBindings, signal: Signal, value?: t.Expression): void; export declare function getResumeRegisterId(section: Section, referencedBindings: string | ReferencedBindings, type?: string): string; export declare function writeSignals(section: Section): Set<Signal>; export declare function writeRegisteredFns(): void; export declare function addHTMLEffectCall(section: Section, referencedBindings?: ReferencedBindings): void; export declare function writeHTMLResumeStatements(path: t.NodePath<t.MarkoTag> | t.NodePath<t.Program>): void; export declare function getSetup(section: Section): Signal | undefined; export declare function replaceRegisteredFunctionNode(node: t.Node): t.CallExpression | t.ClassPrivateProperty | t.ClassProperty | t.Identifier | t.ObjectProperty | t.VariableDeclaration | undefined;