@lwc/ssr-compiler 8.2.0 → 8.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import type { TransformOptions } from '../shared';
2
- export default function compileTemplate(src: string, filename: string, options: TransformOptions): {
1
+ import { type Config as TemplateCompilerConfig } from '@lwc/template-compiler';
2
+ export default function compileTemplate(src: string, filename: string, options: TemplateCompilerConfig): {
3
3
  code: string;
4
4
  };
@@ -1,5 +1,5 @@
1
1
  import type { ImportDeclaration as EsImportDeclaration, Statement as EsStatement } from 'estree';
2
- export declare const bImportHtmlEscape: (...replacementNodes: (import("estree").Node | import("estree").Node[] | null)[]) => EsImportDeclaration;
2
+ export declare const bImportHtmlEscape: () => EsImportDeclaration;
3
3
  export declare const importHtmlEscapeKey = "import:htmlEscape";
4
4
  export declare const isValidIdentifier: (str: string) => boolean;
5
5
  export declare function optimizeAdjacentYieldStmts(statements: EsStatement[]): EsStatement[];
@@ -1,3 +1,3 @@
1
1
  import type { Comment as IrComment } from '@lwc/template-compiler';
2
- import type { Transformer } from './types';
2
+ import type { Transformer } from '../types';
3
3
  export declare const Comment: Transformer<IrComment>;
@@ -1,3 +1,3 @@
1
1
  import type { Component as IrComponent } from '@lwc/template-compiler';
2
- import type { Transformer } from './types';
2
+ import type { Transformer } from '../types';
3
3
  export declare const Component: Transformer<IrComponent>;
@@ -1,3 +1,3 @@
1
- import { type Element as IrElement, ExternalComponent as IrExternalComponent } from '@lwc/template-compiler';
2
- import type { Transformer } from './types';
3
- export declare const Element: Transformer<IrElement | IrExternalComponent>;
1
+ import { type Element as IrElement, ExternalComponent as IrExternalComponent, Slot as IrSlot } from '@lwc/template-compiler';
2
+ import type { Transformer } from '../types';
3
+ export declare const Element: Transformer<IrElement | IrExternalComponent | IrSlot>;
@@ -1,3 +1,3 @@
1
1
  import type { ForEach as IrForEach } from '@lwc/template-compiler';
2
- import type { Transformer } from './types';
2
+ import type { Transformer } from '../types';
3
3
  export declare const ForEach: Transformer<IrForEach>;
@@ -1,3 +1,3 @@
1
1
  import type { ForOf as IrForOf } from '@lwc/template-compiler';
2
- import type { Transformer } from './types';
2
+ import type { Transformer } from '../types';
3
3
  export declare const ForOf: Transformer<IrForOf>;
@@ -1,4 +1,4 @@
1
1
  import type { ElseifBlock as IrElseifBlock, If as IrIf, IfBlock as IrIfBlock } from '@lwc/template-compiler';
2
- import type { Transformer } from './types';
2
+ import type { Transformer } from '../types';
3
3
  export declare const If: Transformer<IrIf>;
4
4
  export declare const IfBlock: Transformer<IrIfBlock | IrElseifBlock>;
@@ -0,0 +1,3 @@
1
+ import { Slot as IrSlot } from '@lwc/template-compiler';
2
+ import type { Transformer } from '../types';
3
+ export declare const Slot: Transformer<IrSlot>;
@@ -1,3 +1,3 @@
1
1
  import type { Text as IrText } from '@lwc/template-compiler';
2
- import type { Transformer } from './types';
2
+ import type { Transformer } from '../types';
3
3
  export declare const Text: Transformer<IrText>;
@@ -1,8 +1,43 @@
1
1
  import type { Node as EsNode } from 'estree';
2
- export declare const placeholder = false;
3
- type ReplacementNode = EsNode | EsNode[] | null;
4
- type ReturnsBool = (node: EsNode | null) => boolean;
5
- export type Validator = ReturnsBool | typeof placeholder;
6
- export declare function esTemplate<RetType = EsNode, ArgTypes extends ReplacementNode[] = ReplacementNode[]>(javascriptSegments: TemplateStringsArray, ...validatorFns: Validator[]): (...replacementNodes: ArgTypes) => RetType;
7
- export declare function esTemplateWithYield<RetType = EsNode, ArgTypes extends ReplacementNode[] = ReplacementNode[]>(javascriptSegments: TemplateStringsArray, ...validatorFns: Validator[]): (...replacementNodes: ArgTypes) => RetType;
2
+ import type { Checker } from 'estree-toolkit/dist/generated/is-type';
3
+ /** Placeholder value to use to opt out of validation. */
4
+ declare const NO_VALIDATION = false;
5
+ /** A function that accepts a node and checks that it is a particular type of node. */
6
+ type Validator<T extends EsNode | null = EsNode | null> = (node: EsNode | null | undefined) => node is T;
7
+ /**
8
+ * A pointer to a previous value in the template literal, indicating that the value should be re-used.
9
+ * @see {@linkcode esTemplate}
10
+ */
11
+ type ValidatorReference = number;
12
+ /** A validator, validation opt-out, or reference to previously-used validator. */
13
+ type ValidatorPlaceholder<T extends EsNode | null> = Validator<T> | ValidatorReference | typeof NO_VALIDATION;
14
+ /** Extracts the type being validated from the validator function. */
15
+ type ValidatedType<T> = T extends Validator<infer V> ? T extends Checker<infer C> ? // estree validator
16
+ C | C[] : // custom validator
17
+ V | Array<NonNullable<V>> : T extends typeof NO_VALIDATION ? // no validation = broadest type possible
18
+ EsNode | EsNode[] | null : never;
19
+ /**
20
+ * Converts the validators and refs used in the template to the list of parameters required by the
21
+ * created template function. Removes back references to previous slots from the list.
22
+ */
23
+ type ToReplacementParameters<Arr extends unknown[]> = Arr extends [infer Head, ...infer Rest] ? Head extends number ? ToReplacementParameters<Rest> : [
24
+ ValidatedType<Head>,
25
+ ...ToReplacementParameters<Rest>
26
+ ] : [];
27
+ /**
28
+ * Template literal tag that generates a builder function. Like estree's `builders`, but for more
29
+ * complex structures. The template values should be estree `is` validators or a back reference to
30
+ * a previous slot (to re-use the referenced value).
31
+ *
32
+ * To have the generated function return a particular node type, the generic comes _after_ the
33
+ * template literal. Kinda weird, but it's necessary to infer the types of the template values.
34
+ * (If it were at the start, we'd need to explicitly provide _all_ type params. Tedious!)
35
+ * @example
36
+ * const bSum = esTemplate`(${is.identifier}, ${is.identifier}) => ${0} + ${1}`<EsArrowFunctionExpression>
37
+ * const sumFuncNode = bSum(b.identifier('a'), b.identifier('b'))
38
+ * // `sumFuncNode` is an AST node representing `(a, b) => a + b`
39
+ */
40
+ export declare function esTemplate<Validators extends ValidatorPlaceholder<EsNode | null>[]>(javascriptSegments: TemplateStringsArray, ...Validators: Validators): <RetType>(...replacementNodes: ToReplacementParameters<Validators>) => RetType;
41
+ /** Similar to {@linkcode esTemplate}, but supports `yield` expressions. */
42
+ export declare function esTemplateWithYield<Validators extends ValidatorPlaceholder<EsNode | null>[]>(javascriptSegments: TemplateStringsArray, ...validators: Validators): <RetType>(...replacementNodes: ToReplacementParameters<Validators>) => RetType;
8
43
  export {};
@@ -1,2 +1,6 @@
1
1
  import type { ImportDeclaration } from 'estree';
2
- export declare const bImportDeclaration: (...replacementNodes: (import("estree").Node | import("estree").Node[] | null)[]) => ImportDeclaration;
2
+ export declare const bImportDeclaration: (replacementNodes_0: import("estree").Identifier | import("estree").Identifier[], replacementNodes_1: (import("estree").SimpleLiteral & {
3
+ value: string;
4
+ }) | NonNullable<import("estree").SimpleLiteral & {
5
+ value: string;
6
+ }>[]) => ImportDeclaration;
@@ -1,5 +1,27 @@
1
- import type { Node } from 'estree';
2
- import type { Validator } from '../estemplate';
3
- export declare const isStringLiteral: (node: Node | null) => boolean;
4
- export declare const isIdentOrRenderCall: (node: Node | null) => boolean;
5
- export declare function isNullableOf(validator: Validator): (node: Node | null) => boolean;
1
+ import type { CallExpression, Identifier, MemberExpression, SimpleLiteral } from 'estree';
2
+ import type { Checker } from 'estree-toolkit/dist/generated/is-type';
3
+ import type { Node } from 'estree-toolkit/dist/helpers';
4
+ /** Node representing a string literal. */
5
+ type StringLiteral = SimpleLiteral & {
6
+ value: string;
7
+ };
8
+ export declare const isStringLiteral: (node: Node | null | undefined) => node is StringLiteral;
9
+ /** Node representing an identifier named "render". */
10
+ type RenderIdentifier = Identifier & {
11
+ name: 'render';
12
+ };
13
+ /** Node representing a member expression `<something>.render`. */
14
+ type RenderMemberExpression = MemberExpression & {
15
+ property: RenderIdentifier;
16
+ };
17
+ /** Node representing a method call `<something>.render()`. */
18
+ type RenderCall = CallExpression & {
19
+ callee: RenderMemberExpression;
20
+ };
21
+ /** Returns `true` if the node is an identifier or `<something>.render()`. */
22
+ export declare const isIdentOrRenderCall: (node: Node | null | undefined) => node is Identifier | RenderCall;
23
+ /** A validator that returns `true` if the node is `null`. */
24
+ type NullableChecker<T extends Node> = (node: Node | null | undefined) => node is T | null;
25
+ /** Extends a validator to return `true` if the node is `null`. */
26
+ export declare function isNullableOf<T extends Node>(validator: Checker<T>): NullableChecker<T>;
27
+ export {};