/** * @license * Copyright 2023 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ import ts from 'typescript'; export declare const PartType: { readonly ATTRIBUTE: 1; readonly CHILD: 2; readonly PROPERTY: 3; readonly BOOLEAN_ATTRIBUTE: 4; readonly EVENT: 5; readonly ELEMENT: 6; readonly COMMENT_PART: 7; }; export type PartType = (typeof PartType)[keyof typeof PartType]; export declare const AttributeKind: { readonly ATTRIBUTE: 1; readonly PROPERTY: 3; readonly BOOLEAN_ATTRIBUTE: 4; readonly EVENT: 5; }; export type AttributeKind = (typeof AttributeKind)[keyof typeof AttributeKind]; export type TemplatePart = { type: typeof PartType.CHILD | typeof PartType.COMMENT_PART | typeof PartType.ELEMENT; index: number; } | { type: typeof PartType.ATTRIBUTE; index: number; name: string; strings: Array; ctorType: AttributeKind; }; /** * Mapping of part constructors to a unique identifier alias. If undefined, the * constructor will not be imported. */ export interface AttributePartConstructorAliases { AttributePart?: ts.Identifier; PropertyPart?: ts.Identifier; BooleanAttributePart?: ts.Identifier; EventPart?: ts.Identifier; } /** * Add Parts constructors import. To avoid identifier collisions, each part * constructor is mapped to a unique identifier. Imports are added as requested * by the parameters in the `attributePartConstructorNameMap`. If no identifier * is provided for a part, then the part will be ignored. This helps keep file * size down and prevents the creation of unusued identifiers. * * This uses a namespace import for g3 compatibility. * * ```ts * import * as litHtmlPrivate_1 from "lit-html/private-ssr-support.js"; * const { AttributePart: , PropertyPart: , BooleanAttributePart: , EventPart: } = litHtmlPrivate_1._$LH; * ``` * * @param options * @param {ts.NodeFactory} options.factory * Factory for updating and creating AST nodes. * @param {ts.SourceFile} options.sourceFile * The sourcefile to add the parts constructor import. * @param {ts.Statement} options.securityBrand * the tag function declaration for the security brand. * @param {AttributePartConstructorAliases} options.attributePartConstructorNameMap * a map to the unique identifier for each attribute part constructor. */ export declare const addPartConstructorImport: ({ factory, sourceFile, securityBrand, attributePartConstructorNameMap, }: { sourceFile: ts.SourceFile; securityBrand: ts.Statement; factory: ts.NodeFactory; attributePartConstructorNameMap: AttributePartConstructorAliases; }) => ts.SourceFile; /** * From a variable name, preparedHtml string, and a list of parts, return the * AST defining a CompiledTemplate. * * Creates: * * ```ts * const = { h: ``, parts: }; * ``` */ export declare const createCompiledTemplate: ({ f, variableName, securityBrand, preparedHtml, parts, }: { f: ts.NodeFactory; variableName: ts.Identifier; securityBrand: ts.Identifier; preparedHtml: string; parts: ts.ArrayLiteralExpression; }) => ts.VariableStatement; /** * Creates a CompiledTemplateResult with the shape: * * ```ts * {['_$litType$']: , values: } * ``` * * where `templateExpression` contains the dynamic values from the original * `html` tagged template. */ export declare const createCompiledTemplateResult: ({ f, variableName, templateExpression, }: { f: ts.NodeFactory; variableName: ts.Identifier; templateExpression: ts.TemplateLiteral; }) => ts.ObjectLiteralExpression; /** * Create the TemplateParts array. * * As an example output, a single BooleanAttributePart looks something like: * * ```ts * [{ type: 1, index: 0, name: "data-attr", strings: ["", ""], ctor: _B }] * ``` */ export declare const createTemplateParts: ({ f, parts, attributePartConstructorNameMap, }: { f: ts.NodeFactory; parts: TemplatePart[]; attributePartConstructorNameMap: AttributePartConstructorAliases; }) => ts.ArrayLiteralExpression; /** * Create an identity function to be the security brand for the preparedHtml. * * Returns the following: * * ```ts * const = i => i; * ``` */ export declare const createSecurityBrandTagFunction: ({ f, securityBrandIdent, }: { f: ts.NodeFactory; securityBrandIdent: ts.Identifier; }) => ts.VariableStatement; //# sourceMappingURL=ast-fragments.d.ts.map