UNPKG

marko

Version:

Optimized runtime for Marko templates.

49 lines (48 loc) • 2.26 kB
import { types as t } from "@marko/compiler"; declare module "@marko/compiler/dist/types" { interface ProgramExtra { needsCompat?: boolean; isInteractive?: boolean; hasClientStatement?: boolean; page?: boolean; } } interface EntryState { init: boolean; hasClientStatement: boolean; /** Whether a reached template lazily imports another. */ lazy: boolean; /** Depth of enclosing templates whose modules the bundle already loads: * below a root everything arrives through its imports, and a lazy subtree * is loaded by its own load entry. */ bundledDepth: number; /** Depth of enclosing lazy imports, whose load entries bring their assets. */ lazyDepth: number; roots: string[]; /** Assets of templates the bundle never loads; the entry imports them. */ assets: Set<string>; /** Assets that arrive through a bundled template's imports; the entry * imports them itself only when it links nothing (a server only page). */ bundledAssets: Set<string>; /** The most eager way each file has been reached. */ visited: Map<string, Reach>; } /** How a file was reached: 0 eagerly, 1 below a bundled template, 2 only * within a lazy subtree. Lower is more eager, so `seen <= reach` means it was * already visited at least as eagerly and is skipped; a file reached more * eagerly than before is re-visited, since it may then own assets or a root. */ export type Reach = 0 | 1 | 2; type EntryFile = t.BabelFile & { [kState]?: EntryState; }; type VisitChild = (id: string, reach?: Reach) => void; declare const kState: unique symbol; declare const builder: { build(entryFile: EntryFile, exportInit?: boolean): t.Statement[]; visit(file: t.BabelFile, entryFile: EntryFile, visitChild?: VisitChild): void; }; export default builder; export declare function assertVisited<S>(entryFile: t.BabelFile, state: S | undefined): asserts state is S; export declare function createVisited(entryFile: t.BabelFile): Map<string, Reach>; export declare function resolveRelativeToEntry(entryFile: t.BabelFile, file: t.BabelFile, req: string): string; export declare function markReached(visited: Map<string, Reach>, resolved: string, reach: Reach): boolean;