marko
Version:
Optimized runtime for Marko templates.
52 lines (51 loc) • 2.58 kB
TypeScript
import { types as t } from "@marko/compiler";
import { type MarkoRootPath } from "./get-root";
import { type RegisteredFnExtra } from "./references";
declare const kRegisteredExports: unique symbol;
declare module "@marko/compiler/dist/types" {
interface ProgramExtra {
[kRegisteredExports]?: Map<string, RegisteredExport>;
}
interface ImportDeclarationExtra {
/** Each local binding the template registers -> the export it imports. */
registeredImports?: Map<string, RegisteredExport>;
}
}
/**
* An export registered under an id: the template that declares it, and the
* canonical name it is exported under.
*/
export interface RegisteredExport {
registerId: string;
exportName: string;
filename: string;
}
export declare function trackFunction(fn: t.NodePath<t.Function>, fnExtra: RegisteredFnExtra, markoRoot: MarkoRootPath): void;
export declare function canIgnoreRegister(markoRoot: MarkoRootPath, exprRoot: t.NodePath<t.Node>): boolean;
export declare function addFunctionReasons(): void;
export declare function finalizeRegistrations(): void;
/**
* Tracks a template imported as a default export. The server writes a template
* only as a binding's value, so the importing template registers it when one may.
*/
export declare function trackImportedTemplate(importDecl: t.NodePath<t.ImportDeclaration>, local: string, templateFile: t.BabelFile): void;
/**
* Tracks an export imported from another template that registers under an id,
* if it does. The importing template registers it (under that id) when client
* code reads its own references.
*/
export declare function trackImport(importDecl: t.NodePath<t.ImportDeclaration>, local: string, registered: RegisteredExport | undefined, fnRoots?: Set<t.NodeExtra>): void;
/**
* Finds the id reserved for an export, following `export ... from` hops. Each
* template only records the exports it declares, so this resolves on demand:
* a template in an import cycle is read while it is still analyzing, and would
* hand out an incomplete map if the ids were pushed ahead of time.
*/
export declare function resolveRegisteredExport(file: t.BabelFile, exportName: string, seen?: Set<string>): RegisteredExport | undefined;
/**
* Writes the registrations for module scoped functions: the ones this template
* exports and registers itself, and the ones it imports from a template that
* reserved a register id without registering it; and for templates it imports.
*/
export declare function writeModuleRegistrations(program: t.NodePath<t.Program>): void;
export {};