UNPKG

marko

Version:

Optimized runtime for Marko templates.

115 lines (114 loc) • 5.65 kB
import { types as t } from "@marko/compiler"; import type { AccessorPrefix } from "../../common/accessor.debug"; import type { WalkCode } from "../../common/types"; import * as ContentType from "./constants/content-type"; import type * as Step from "./constants/step"; import * as StructureKind from "./constants/structure-kind"; import { type Opt, Sorted } from "./optional"; import { type Binding, type InputBinding, type ParamBinding, type ReferencedBindings, type Sources } from "./references"; import { type SerializeReason } from "./serialize-reasons"; export interface ParamSerializeReasonGroup { id: symbol; reason: NonNullable<Sources["param"]>; } export type ParamSerializeReasonGroups = [ ParamSerializeReasonGroup, ...ParamSerializeReasonGroup[] ]; type ContentType = ContentType.Value; export { ContentType, StructureKind }; export type StructureRef = StructureSectionRef | StructureExportRef; export interface StructureSectionRef { kind: typeof StructureKind.SectionRef; section: Section; } export interface StructureExportRef { kind: typeof StructureKind.ExportRef; program: t.ProgramExtra; path: string; hint: string; } export type StructureOp = string | Step.Value | StructureVisit | StructureChild; export interface StructureVisit { kind: typeof StructureKind.Visit; code: typeof WalkCode.Get | typeof WalkCode.Replace | typeof WalkCode.DynamicTagWithVar; claimed: boolean; } export interface StructureChild { kind: typeof StructureKind.Child; name: string; hasVar: boolean; renderer?: StructureRef; } export interface Section { id: number; name: string; loc: t.SourceLocation | undefined; depth: number; parent: Section | undefined; sectionAccessor: { binding: Binding; prefix: AccessorPrefix; } | undefined; params: undefined | ParamBinding | InputBinding; referencedLocalClosures: ReferencedBindings; referencedClosures: ReferencedBindings; referencedHoists: ReferencedBindings; bindings: ReferencedBindings; hoisted: ReferencedBindings; hoistedTo: ReferencedBindings; serializeReason: undefined | SerializeReason; serializeReasons: Map<symbol, SerializeReason>; paramReasonGroups: ParamSerializeReasonGroups | undefined; returnValueExpr: t.NodeExtra | undefined; returnSerializeReason: SerializeReason | undefined; isHoistThrough: true | undefined; upstreamExpression: t.NodeExtra | undefined; downstreamBinding: { binding: Binding; properties: Opt<string>; } | false | undefined; hasAbortSignal: boolean; /** Count of distinct `$signal` expression roots; analyze allocates each * root's `abortId` from this so translates read, never re-derive. */ abortSignalExprs: number; readsOwner: boolean; isBranch: boolean; content: null | { startType: ContentType; endType: ContentType; singleChild: boolean; }; structure: StructureOp[] | null; } declare module "@marko/compiler/dist/types" { interface ProgramExtra { section?: Section; sections?: Section[]; } interface MarkoTagBodyExtra { section?: Section; } } export declare const sectionUtil: Sorted<Section>; export declare function startSection(path: t.NodePath<t.MarkoTagBody | t.Program>): Section | undefined; export declare function getOrCreateSection(path: t.NodePath<any>): Section; export declare function getSectionForBody(body: t.NodePath<t.MarkoTagBody | t.Program>): Section | undefined; export declare function getSection(path: t.NodePath): Section; export declare const getScopeIdIdentifier: (section: Section) => t.Identifier; export declare const getSectionParentIsOwner: (section: Section) => boolean, setSectionParentIsOwner: (section: Section, value: boolean) => void; export declare const getBranchRendererArgs: (section: Section) => [template?: t.Expression | undefined, walks?: t.Expression | undefined, setup?: t.Expression | undefined, params?: t.Expression | undefined], setBranchRendererArgs: (section: Section, value: [template?: t.Expression | undefined, walks?: t.Expression | undefined, setup?: t.Expression | undefined, params?: t.Expression | undefined]) => void; export declare function forEachSection(fn: (section: Section) => void): void; export declare function forEachSectionReverse(fn: (section: Section) => void): void; export declare function getNodeContentType(path: t.NodePath<t.Statement>, extraMember: "startType" | "endType", contentInfo?: Section["content"]): ContentType.Value | null; export declare function getSectionRegisterReasons(section: Section): false | SerializeReason; export declare function isImmediateOwner(section: Section, binding: Binding): boolean; export declare function isDirectClosure(section: Section, closure: Binding): boolean; export declare function isDynamicClosure(section: Section, closure: Binding): boolean; export declare function getDynamicClosureIndex(closure: Binding, closureSection: Section): number; export declare function getDirectClosures(section: Section): Opt<Binding>; export declare function isSameOrChildSection(section: Section, other: Section): boolean; export declare function getCommonSection(section: Section, other: Section): Section; export declare function finalizeParamSerializeReasonGroups(section: Section): void; export declare function getParamReasonGroupIndex(section: Section, reason: ParamSerializeReasonGroup["reason"]): number; export declare function groupParamsBySection(params: Sources["param"]): Map<Section, import("./optional").OneMany<InputBinding | ParamBinding>>;