Launch Week Day 5: Introducing Reachability for PHP.Learn More
Socket
Book a DemoSign in
Socket

@glimmer/compiler

Package Overview
Dependencies
Maintainers
15
Versions
303
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@glimmer/compiler - npm Package Compare versions

Comparing version
0.94.4
to
0.94.5
+1747
-4
dist/dev/index.d.ts

@@ -1,4 +0,1747 @@

export { buildStatement, buildStatements, c, NEWLINE, ProgramSymbols, s, unicode, } from './lib/builder/builder';
export { type BuilderStatement } from './lib/builder/builder-interface';
export { defaultId, precompile, precompileJSON, type PrecompileOptions } from './lib/compiler';
export { default as WireFormatDebugger } from './lib/wire-format-debug';
type Nullable<T> = T | null;
type Optional<T> = T | undefined;
type Maybe<T> = Nullable<T> | Optional<T>;
type Dict<T = unknown> = Record<string, T>;
type PresentArray<T> = [T, ...T[]];
type CurriedComponent = 0;
type CurriedHelper = 1;
type CurriedModifier = 2;
type CurriedType = CurriedComponent | CurriedHelper | CurriedModifier;
// Statements
type AppendOpcode = 1;
type TrustingAppendOpcode = 2;
type CommentOpcode = 3;
type ModifierOpcode = 4;
type BlockOpcode = 6;
type ComponentOpcode = 8;
type OpenElementOpcode = 10;
type OpenElementWithSplatOpcode = 11;
type FlushElementOpcode = 12;
type CloseElementOpcode = 13;
type StaticAttrOpcode = 14;
type DynamicAttrOpcode = 15;
type ComponentAttrOpcode = 16;
type AttrSplatOpcode = 17;
type YieldOpcode = 18;
type DynamicArgOpcode = 20;
type StaticArgOpcode = 21;
type TrustingDynamicAttrOpcode = 22;
type TrustingComponentAttrOpcode = 23;
type StaticComponentAttrOpcode = 24;
type DebuggerOpcode = 26;
// Expressions
type UndefinedOpcode = 27;
type CallOpcode = 28;
type ConcatOpcode = 29;
// Get
// Get a local value via symbol
type GetSymbolOpcode = 30; // GetPath + 0-2,
// Lexical symbols are values that are in scope in the template in strict mode
type GetLexicalSymbolOpcode = 32;
// If a free variable is not a lexical symbol in strict mode, it must be a keyword.
// FIXME: Why does this make it to the wire format in the first place?
type GetStrictKeywordOpcode = 31;
// a component or helper (`{{<expr> x}}` in append position)
type GetFreeAsComponentOrHelperHeadOpcode = 35;
// a call head `(x)`
type GetFreeAsHelperHeadOpcode = 37;
type GetFreeAsModifierHeadOpcode = 38;
type GetFreeAsComponentHeadOpcode = 39;
// Keyword Statements
type InElementOpcode = 40;
type IfOpcode = 41;
type EachOpcode = 42;
type LetOpcode = 44;
type WithDynamicVarsOpcode = 45;
type InvokeComponentOpcode = 46;
// Keyword Expressions
type HasBlockOpcode = 48;
type HasBlockParamsOpcode = 49;
type CurryOpcode = 50;
type NotOpcode = 51;
type IfInlineOpcode = 52;
type GetDynamicVarOpcode = 53;
type LogOpcode = 54;
type AttrOpcode =
| StaticAttrOpcode
| StaticComponentAttrOpcode
| DynamicAttrOpcode
| TrustingDynamicAttrOpcode
| ComponentAttrOpcode
| TrustingComponentAttrOpcode;
type YieldTo = number;
declare namespace Core {
export type Expression = Expressions.Expression;
export type DebugSymbols = [locals: Record<string, number>, upvars: Record<string, number>];
export type CallArgs = [Params, Hash];
export type Path = [string, ...string[]];
export type ConcatParams = PresentArray<Expression>;
export type Params = Nullable<ConcatParams>;
export type Hash = Nullable<[PresentArray<string>, PresentArray<Expression>]>;
export type Blocks = Nullable<[string[], SerializedInlineBlock[]]>;
export type Args = [Params, Hash];
export type NamedBlock = [string, SerializedInlineBlock];
export type ElementParameters = Nullable<PresentArray<ElementParameter>>;
export type Syntax = Path | Params | ConcatParams | Hash | Blocks | Args;
}
declare namespace Expressions {
export type Path = Core.Path;
export type Params = Core.Params;
export type Hash = Core.Hash;
export type GetSymbol = [GetSymbolOpcode, number];
export type GetLexicalSymbol = [GetLexicalSymbolOpcode, number];
export type GetStrictFree = [GetStrictKeywordOpcode, number];
export type GetFreeAsComponentOrHelperHead = [GetFreeAsComponentOrHelperHeadOpcode, number];
export type GetFreeAsHelperHead = [GetFreeAsHelperHeadOpcode, number];
export type GetFreeAsModifierHead = [GetFreeAsModifierHeadOpcode, number];
export type GetFreeAsComponentHead = [GetFreeAsComponentHeadOpcode, number];
export type GetContextualFree =
| GetFreeAsComponentOrHelperHead
| GetFreeAsHelperHead
| GetFreeAsModifierHead
| GetFreeAsComponentHead;
export type GetFree = GetStrictFree | GetContextualFree;
export type GetVar = GetSymbol | GetLexicalSymbol | GetFree;
export type GetPathSymbol = [GetSymbolOpcode, number, Path];
export type GetPathTemplateSymbol = [GetLexicalSymbolOpcode, number, Path];
export type GetPathFreeAsComponentOrHelperHead = [
GetFreeAsComponentOrHelperHeadOpcode,
number,
Path,
];
export type GetPathFreeAsHelperHead = [GetFreeAsHelperHeadOpcode, number, Path];
export type GetPathFreeAsModifierHead = [GetFreeAsModifierHeadOpcode, number, Path];
export type GetPathFreeAsComponentHead = [GetFreeAsComponentHeadOpcode, number, Path];
export type GetPathContextualFree =
| GetPathFreeAsComponentOrHelperHead
| GetPathFreeAsHelperHead
| GetPathFreeAsModifierHead
| GetPathFreeAsComponentHead;
export type GetPath = GetPathSymbol | GetPathTemplateSymbol | GetPathContextualFree;
export type Get = GetVar | GetPath;
export type StringValue = string;
export type NumberValue = number;
export type BooleanValue = boolean;
export type NullValue = null;
export type Value = StringValue | NumberValue | BooleanValue | NullValue;
export type Undefined = [UndefinedOpcode];
export type TupleExpression =
| Get
| GetDynamicVar
| Concat
| HasBlock
| HasBlockParams
| Curry
| Helper
| Undefined
| IfInline
| Not
| Log;
// TODO get rid of undefined, which is just here to allow trailing undefined in attrs
// it would be better to handle that as an over-the-wire encoding concern
export type Expression = TupleExpression | Value | undefined;
export type Concat = [ConcatOpcode, Core.ConcatParams];
export type Helper = [CallOpcode, Expression, Nullable<Params>, Hash];
export type HasBlock = [HasBlockOpcode, Expression];
export type HasBlockParams = [HasBlockParamsOpcode, Expression];
export type Curry = [CurryOpcode, Expression, CurriedType, Params, Hash];
export type IfInline = [
op: IfInlineOpcode,
condition: Expression,
truthyValue: Expression,
falsyValue?: Nullable<Expression>,
];
export type Not = [op: NotOpcode, value: Expression];
export type GetDynamicVar = [op: GetDynamicVarOpcode, value: Expression];
export type Log = [op: LogOpcode, positional: Params];
}
type TupleExpression = Expressions.TupleExpression;
type ClassAttr = 0;
type IdAttr = 1;
type ValueAttr = 2;
type NameAttr = 3;
type TypeAttr = 4;
type StyleAttr = 5;
type HrefAttr = 6;
type WellKnownAttrName =
| ClassAttr
| IdAttr
| ValueAttr
| NameAttr
| TypeAttr
| StyleAttr
| HrefAttr;
type DivTag = 0;
type SpanTag = 1;
type PTag = 2;
type ATag = 3;
type WellKnownTagName = DivTag | SpanTag | PTag | ATag;
declare namespace Statements {
export type Expression = Expressions.Expression | undefined;
export type Params = Core.Params;
export type Hash = Core.Hash;
export type Blocks = Core.Blocks;
export type Path = Core.Path;
export type Append = [AppendOpcode, Expression];
export type TrustingAppend = [TrustingAppendOpcode, Expression];
export type Comment = [CommentOpcode, string];
export type Modifier = [ModifierOpcode, Expression, Params, Hash];
export type Block = [BlockOpcode, Expression, Params, Hash, Blocks];
export type Component = [
op: ComponentOpcode,
tag: Expression,
parameters: Core.ElementParameters,
args: Hash,
blocks: Blocks,
];
export type OpenElement = [OpenElementOpcode, string | WellKnownTagName];
export type OpenElementWithSplat = [OpenElementWithSplatOpcode, string | WellKnownTagName];
export type FlushElement = [FlushElementOpcode];
export type CloseElement = [CloseElementOpcode];
type Attr<Op extends AttrOpcode> = [
op: Op,
name: string | WellKnownAttrName,
value: Expression,
namespace?: string | undefined,
];
export type StaticAttr = Attr<StaticAttrOpcode>;
export type StaticComponentAttr = Attr<StaticComponentAttrOpcode>;
export type AnyStaticAttr = StaticAttr | StaticComponentAttr;
export type AttrSplat = [AttrSplatOpcode, YieldTo];
export type Yield = [YieldOpcode, YieldTo, Nullable<Params>];
export type DynamicArg = [DynamicArgOpcode, string, Expression];
export type StaticArg = [StaticArgOpcode, string, Expression];
export type DynamicAttr = Attr<DynamicAttrOpcode>;
export type ComponentAttr = Attr<ComponentAttrOpcode>;
export type TrustingDynamicAttr = Attr<TrustingDynamicAttrOpcode>;
export type TrustingComponentAttr = Attr<TrustingComponentAttrOpcode>;
export type AnyDynamicAttr =
| DynamicAttr
| ComponentAttr
| TrustingDynamicAttr
| TrustingComponentAttr;
export type Debugger = [
op: DebuggerOpcode,
locals: Record<string, number>,
upvars: Record<string, number>,
lexical: Record<string, number>,
];
export type InElement = [
op: InElementOpcode,
block: SerializedInlineBlock,
guid: string,
destination: Expression,
insertBefore?: Expression,
];
export type If = [
op: IfOpcode,
condition: Expression,
block: SerializedInlineBlock,
inverse: Nullable<SerializedInlineBlock>,
];
export type Each = [
op: EachOpcode,
condition: Expression,
key: Nullable<Expression>,
block: SerializedInlineBlock,
inverse: Nullable<SerializedInlineBlock>,
];
export type Let = [op: LetOpcode, positional: Core.Params, block: SerializedInlineBlock];
export type WithDynamicVars = [
op: WithDynamicVarsOpcode,
args: Core.Hash,
block: SerializedInlineBlock,
];
export type InvokeComponent = [
op: InvokeComponentOpcode,
definition: Expression,
positional: Core.Params,
named: Core.Hash,
blocks: Blocks | null,
];
/**
* A Handlebars statement
*/
export type Statement =
| Append
| TrustingAppend
| Comment
| Modifier
| Block
| Component
| OpenElement
| OpenElementWithSplat
| FlushElement
| CloseElement
| Attribute
| AttrSplat
| Yield
| StaticArg
| DynamicArg
| Debugger
| InElement
| If
| Each
| Let
| WithDynamicVars
| InvokeComponent;
export type Attribute =
| StaticAttr
| StaticComponentAttr
| DynamicAttr
| TrustingDynamicAttr
| ComponentAttr
| TrustingComponentAttr;
export type ComponentFeature = Modifier | AttrSplat;
export type Argument = StaticArg | DynamicArg;
export type ElementParameter = Attribute | Argument | ComponentFeature;
}
/** A Handlebars statement */
type Statement$2 = Statements.Statement;
type ElementParameter = Statements.ElementParameter;
type SexpSyntax = Statement$2 | TupleExpression;
// TODO this undefined is related to the other TODO in this file
type Syntax$1 = SexpSyntax | Expressions.Value | undefined;
type SerializedInlineBlock = [statements: Statements.Statement[], parameters: number[]];
/**
* A JSON object that the compiled TemplateBlock was serialized into.
*/
type SerializedTemplateBlock = [
statements: Statements.Statement[],
locals: string[],
upvars: string[],
lexicalSymbols?: string[],
];
/**
* A string of Javascript containing a SerializedTemplateWithLazyBlock to be
* concatenated into a Javascript module.
*/
type TemplateJavascript = string;
type BUILDER_LITERAL = 0;
declare const BUILDER_LITERAL: BUILDER_LITERAL;
type BUILDER_COMMENT = 1;
declare const BUILDER_COMMENT: BUILDER_COMMENT;
type BUILDER_APPEND = 2;
declare const BUILDER_APPEND: BUILDER_APPEND;
type BUILDER_MODIFIER = 3;
declare const BUILDER_MODIFIER: BUILDER_MODIFIER;
type BUILDER_DYNAMIC_COMPONENT = 4;
declare const BUILDER_DYNAMIC_COMPONENT: BUILDER_DYNAMIC_COMPONENT;
type BUILDER_GET = 5;
declare const BUILDER_GET: BUILDER_GET;
type BUILDER_CONCAT = 6;
declare const BUILDER_CONCAT: BUILDER_CONCAT;
type BUILDER_HAS_BLOCK = 7;
declare const BUILDER_HAS_BLOCK: BUILDER_HAS_BLOCK;
type BUILDER_HAS_BLOCK_PARAMS = 8;
declare const BUILDER_HAS_BLOCK_PARAMS: BUILDER_HAS_BLOCK_PARAMS;
type BLOCK_HEAD = 'Block';
declare const BLOCK_HEAD: BLOCK_HEAD;
type CALL_HEAD = 'Call';
declare const CALL_HEAD: CALL_HEAD;
type ELEMENT_HEAD = 'Element';
declare const ELEMENT_HEAD: ELEMENT_HEAD;
type APPEND_PATH_HEAD = 'AppendPath';
declare const APPEND_PATH_HEAD: APPEND_PATH_HEAD;
type APPEND_EXPR_HEAD = 'AppendExpr';
declare const APPEND_EXPR_HEAD: APPEND_EXPR_HEAD;
type LITERAL_HEAD = 'Literal';
declare const LITERAL_HEAD: LITERAL_HEAD;
type MODIFIER_HEAD = 'Modifier';
declare const MODIFIER_HEAD: MODIFIER_HEAD;
type DYNAMIC_COMPONENT_HEAD = 'DynamicComponent';
declare const DYNAMIC_COMPONENT_HEAD: DYNAMIC_COMPONENT_HEAD;
type COMMENT_HEAD = 'Comment';
declare const COMMENT_HEAD: COMMENT_HEAD;
type SPLAT_HEAD = 'Splat';
declare const SPLAT_HEAD: SPLAT_HEAD;
type KEYWORD_HEAD = 'Keyword';
declare const KEYWORD_HEAD: KEYWORD_HEAD;
type LOCAL_VAR = 'Local';
declare const LOCAL_VAR: LOCAL_VAR;
type FREE_VAR = 'Free';
declare const FREE_VAR: FREE_VAR;
type ARG_VAR = 'Arg';
declare const ARG_VAR: ARG_VAR;
type BLOCK_VAR = 'Block';
declare const BLOCK_VAR: BLOCK_VAR;
type THIS_VAR = 'This';
declare const THIS_VAR: THIS_VAR;
type VariableKind = LOCAL_VAR | FREE_VAR | ARG_VAR | BLOCK_VAR | THIS_VAR;
type LITERAL_EXPR = 'Literal';
declare const LITERAL_EXPR: LITERAL_EXPR;
type CALL_EXPR = 'Call';
declare const CALL_EXPR: CALL_EXPR;
type GET_PATH_EXPR = 'GetPath';
declare const GET_PATH_EXPR: GET_PATH_EXPR;
type GET_VAR_EXPR = 'GetVar';
declare const GET_VAR_EXPR: GET_VAR_EXPR;
type CONCAT_EXPR = 'Concat';
declare const CONCAT_EXPR: CONCAT_EXPR;
type HAS_BLOCK_EXPR = 'HasBlock';
declare const HAS_BLOCK_EXPR: HAS_BLOCK_EXPR;
type HAS_BLOCK_PARAMS_EXPR = 'HasBlockParams';
declare const HAS_BLOCK_PARAMS_EXPR: HAS_BLOCK_PARAMS_EXPR;
type BuilderParams = BuilderExpression[];
type BuilderHash = Nullable<Dict<BuilderExpression>>;
type BuilderBlockHash = BuilderHash | {
as: string | string[];
};
type BuilderBlocks = Dict<BuilderBlock>;
type BuilderAttrs = Dict<BuilderAttr>;
type NormalizedParams = NormalizedExpression[];
type NormalizedHash = Dict<NormalizedExpression>;
type NormalizedBlock = NormalizedStatement[];
type NormalizedBlocks = Dict<NormalizedBlock>;
type NormalizedAttrs = Dict<NormalizedAttr>;
type NormalizedAttr = SPLAT_HEAD | NormalizedExpression;
interface Variable {
kind: VariableKind;
name: string;
/**
* Differences:
*
* - strict mode variables always refer to in-scope variables
* - loose mode variables use this algorithm:
* 1. otherwise, fall back to `this.<name>`
*/
mode: 'loose' | 'strict';
}
interface Path {
head: Variable;
tail: PresentArray<string>;
}
interface AppendExpr {
kind: APPEND_EXPR_HEAD;
expr: NormalizedExpression;
trusted: boolean;
}
interface AppendPath {
kind: APPEND_PATH_HEAD;
path: NormalizedPath;
trusted: boolean;
}
interface NormalizedKeywordStatement {
kind: KEYWORD_HEAD;
name: string;
params: Nullable<NormalizedParams>;
hash: Nullable<NormalizedHash>;
blockParams: Nullable<string[]>;
blocks: NormalizedBlocks;
}
type NormalizedStatement = {
kind: CALL_HEAD;
head: NormalizedHead;
params: Nullable<NormalizedParams>;
hash: Nullable<NormalizedHash>;
trusted: boolean;
} | {
kind: BLOCK_HEAD;
head: NormalizedHead;
params: Nullable<NormalizedParams>;
hash: Nullable<NormalizedHash>;
blockParams: Nullable<string[]>;
blocks: NormalizedBlocks;
} | NormalizedKeywordStatement | {
kind: ELEMENT_HEAD;
name: string;
attrs: NormalizedAttrs;
block: NormalizedBlock;
} | {
kind: COMMENT_HEAD;
value: string;
} | {
kind: LITERAL_HEAD;
value: string;
} | AppendPath | AppendExpr | {
kind: MODIFIER_HEAD;
params: NormalizedParams;
hash: Nullable<NormalizedHash>;
} | {
kind: DYNAMIC_COMPONENT_HEAD;
expr: NormalizedExpression;
hash: Nullable<NormalizedHash>;
block: NormalizedBlock;
};
type SugaryArrayStatement = BuilderCallExpression | BuilderElement | BuilderBlockStatement;
type BuilderBlockStatement = [string, BuilderBlock | BuilderBlocks] | [string, BuilderParams | BuilderBlockHash, BuilderBlock | BuilderBlocks] | [string, BuilderParams, BuilderBlockHash, BuilderBlock | BuilderBlocks];
type BuilderElement = [string] | [string, BuilderAttrs, BuilderBlock] | [string, BuilderBlock] | [string, BuilderAttrs];
type BuilderComment = [BUILDER_COMMENT, string];
type VerboseStatement = [BUILDER_LITERAL, string] | [BUILDER_COMMENT, string] | [BUILDER_APPEND, BuilderExpression, true] | [BUILDER_APPEND, BuilderExpression] | [BUILDER_MODIFIER, Params, Hash$2] | [BUILDER_DYNAMIC_COMPONENT, BuilderExpression, Hash$2, BuilderBlock];
type BuilderStatement = VerboseStatement | SugaryArrayStatement | TupleBuilderExpression | string;
/**
* The special value 'splat' is used to indicate that the attribute is a splat
*/
type BuilderAttr = BuilderExpression;
type TupleBuilderExpression = [BUILDER_LITERAL, string | boolean | null | undefined] | [BUILDER_GET, string] | [BUILDER_GET, string, string[]] | [BUILDER_CONCAT, ...BuilderExpression[]] | [BUILDER_HAS_BLOCK, string] | [BUILDER_HAS_BLOCK_PARAMS, string] | BuilderCallExpression;
type Params = BuilderParams;
type Hash$2 = Dict<BuilderExpression>;
interface NormalizedCallExpression {
type: CALL_EXPR;
head: NormalizedHead;
params: Nullable<NormalizedParams>;
hash: Nullable<NormalizedHash>;
}
interface NormalizedPath {
type: GET_PATH_EXPR;
path: Path;
}
interface NormalizedVar {
type: GET_VAR_EXPR;
variable: Variable;
}
type NormalizedHead = NormalizedPath | NormalizedVar;
interface NormalizedConcat {
type: CONCAT_EXPR;
params: [NormalizedExpression, ...NormalizedExpression[]];
}
type NormalizedExpression = {
type: LITERAL_EXPR;
value: null | undefined | boolean | string | number;
} | NormalizedCallExpression | NormalizedPath | NormalizedVar | NormalizedConcat | {
type: HAS_BLOCK_EXPR;
name: string;
} | {
type: HAS_BLOCK_PARAMS_EXPR;
name: string;
};
type BuilderExpression = TupleBuilderExpression | BuilderCallExpression | null | undefined | boolean | string | number;
type MiniBuilderBlock = BuilderStatement[];
type BuilderBlock = MiniBuilderBlock;
type BuilderCallExpression = [string] | [string, Params | Hash$2] | [string, Params, Hash$2];
interface Symbols {
top: ProgramSymbols;
freeVar(name: string): number;
arg(name: string): number;
block(name: string): number;
local(name: string): number;
this(): number;
hasLocal(name: string): boolean;
child(params: string[]): LocalSymbols;
}
declare class ProgramSymbols implements Symbols {
_freeVariables: string[];
_symbols: string[];
top: this;
toSymbols(): string[];
toUpvars(): string[];
freeVar(name: string): number;
block(name: string): number;
arg(name: string): number;
local(name: string): never;
this(): number;
hasLocal(_name: string): false;
symbol(name: string): number;
child(locals: string[]): LocalSymbols;
}
declare class LocalSymbols implements Symbols {
private parent;
private locals;
constructor(parent: Symbols, locals: string[]);
get paramSymbols(): number[];
get top(): ProgramSymbols;
freeVar(name: string): number;
arg(name: string): number;
block(name: string): number;
local(name: string): number;
this(): number;
hasLocal(name: string): boolean;
child(locals: string[]): LocalSymbols;
}
declare function buildStatements(statements: BuilderStatement[], symbols: Symbols): Statement$2[];
declare function buildStatement(normalized: NormalizedStatement, symbols?: Symbols): Statement$2[];
declare function s(arr: TemplateStringsArray, ...interpolated: unknown[]): [BUILDER_LITERAL, string];
declare function c(arr: TemplateStringsArray, ...interpolated: unknown[]): BuilderComment;
declare function unicode(charCode: string): string;
declare const NEWLINE = "\n";
/**
* @module
*
* This file contains types for the raw AST returned from the Handlebars parser.
* These types were originally imported from
* https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/handlebars/index.d.ts.
*/
interface CommonNode {
loc: SourceLocation$1;
}
interface SourceLocation$1 {
source: string;
start: Position;
end: Position;
}
interface Position {
line: number;
column: number;
}
interface Program extends CommonNode {
type: 'Program';
body: Statement$1[];
blockParams?: string[];
chained?: boolean;
}
type Statement$1 = MustacheStatement$1 | BlockStatement$1 | DecoratorBlock | PartialStatement | PartialBlockStatement | ContentStatement | CommentStatement$1;
interface CommonMustache extends CommonNode {
path: Expression$1;
params: Expression$1[];
hash: Hash$1;
escaped: boolean;
strip: StripFlags$1;
}
interface MustacheStatement$1 extends CommonMustache {
type: 'MustacheStatement';
}
interface CommonBlock extends CommonNode {
chained: boolean;
path: PathExpression$1 | SubExpression$1;
params: Expression$1[];
hash: Hash$1;
program: Program;
inverse?: Program;
openStrip?: StripFlags$1;
inverseStrip?: StripFlags$1;
closeStrip?: StripFlags$1;
}
interface BlockStatement$1 extends CommonBlock {
type: 'BlockStatement';
}
interface DecoratorBlock extends CommonBlock {
type: 'DecoratorBlock';
}
interface PartialStatement extends CommonNode {
type: 'PartialStatement';
name: PathExpression$1 | SubExpression$1;
params: Expression$1[];
hash: Hash$1;
indent: string;
strip: StripFlags$1;
}
interface PartialBlockStatement extends CommonNode {
type: 'PartialBlockStatement';
name: PathExpression$1 | SubExpression$1;
params: Expression$1[];
hash: Hash$1;
program: Program;
openStrip: StripFlags$1;
closeStrip: StripFlags$1;
}
interface ContentStatement extends CommonNode {
type: 'ContentStatement';
value: string;
original: StripFlags$1;
}
interface CommentStatement$1 extends CommonNode {
type: 'CommentStatement';
value: string;
strip: StripFlags$1;
}
type Expression$1 = SubExpression$1 | PathExpression$1 | Literal$1;
interface SubExpression$1 extends CommonNode {
type: 'SubExpression';
path: PathExpression$1 | SubExpression$1;
params: Expression$1[];
hash: Hash$1;
}
interface PathExpression$1 extends CommonNode {
type: 'PathExpression';
data: boolean;
depth: number;
parts: string[];
original: string;
}
type Literal$1 = StringLiteral$1 | BooleanLiteral$1 | NumberLiteral$1 | UndefinedLiteral$1 | NullLiteral$1;
interface StringLiteral$1 extends CommonNode {
type: 'StringLiteral';
value: string;
original: string;
}
interface BooleanLiteral$1 extends CommonNode {
type: 'BooleanLiteral';
value: boolean;
original: boolean;
}
interface NumberLiteral$1 extends CommonNode {
type: 'NumberLiteral';
value: number;
original: number;
}
interface UndefinedLiteral$1 extends CommonNode {
type: 'UndefinedLiteral';
}
interface NullLiteral$1 extends CommonNode {
type: 'NullLiteral';
}
interface Hash$1 extends CommonNode {
pairs: HashPair$1[];
}
interface HashPair$1 extends CommonNode {
key: string;
value: Expression$1;
}
interface StripFlags$1 {
open: boolean;
close: boolean;
}
declare const visitorKeys: {
readonly Template: readonly ["body"];
readonly Block: readonly ["body"];
readonly MustacheStatement: readonly ["path", "params", "hash"];
readonly BlockStatement: readonly ["path", "params", "hash", "program", "inverse"];
readonly ElementModifierStatement: readonly ["path", "params", "hash"];
readonly CommentStatement: readonly [];
readonly MustacheCommentStatement: readonly [];
readonly ElementNode: readonly ["attributes", "modifiers", "children", "comments"];
readonly AttrNode: readonly ["value"];
readonly TextNode: readonly [];
readonly ConcatStatement: readonly ["parts"];
readonly SubExpression: readonly ["path", "params", "hash"];
readonly PathExpression: readonly [];
readonly StringLiteral: readonly [];
readonly BooleanLiteral: readonly [];
readonly NumberLiteral: readonly [];
readonly NullLiteral: readonly [];
readonly UndefinedLiteral: readonly [];
readonly Hash: readonly ["pairs"];
readonly HashPair: readonly ["value"];
};
type VisitorKeysMap = typeof visitorKeys;
type VisitorKeys = {
[P in keyof VisitorKeysMap]: VisitorKeysMap[P][number];
};
type VisitorKey<N extends Node> = VisitorKeys[N['type']] & keyof N;
declare class WalkerPath<N extends Node> {
node: N;
parent: WalkerPath<Node> | null;
parentKey: string | null;
constructor(node: N, parent?: WalkerPath<Node> | null, parentKey?: string | null);
get parentNode(): Node | null;
parents(): Iterable<WalkerPath<Node> | null>;
}
interface FullNodeTraversal<N extends Node> {
enter?(node: N, path: WalkerPath<N>): void;
exit?(node: N, path: WalkerPath<N>): void;
keys?: KeysVisitor<N>;
}
type NodeHandler<N extends Node> = (node: N, path: WalkerPath<N>) => Node | Node[] | undefined | void;
type NodeTraversal<N extends Node> = FullNodeTraversal<N> | NodeHandler<N>;
type NodeVisitor = {
[P in keyof Nodes]?: NodeTraversal<Nodes[P]>;
} & {
All?: NodeTraversal<Node>;
/**
* @deprecated use Template or Block instead
*/
Program?: NodeTraversal<Template | Block>;
};
interface FullKeyTraversal<N extends Node, K extends string> {
enter?(node: N, key: K): void;
exit?(node: N, key: K): void;
}
type KeyHandler<N extends Node, K extends VisitorKey<N>> = (node: N, key: K) => void;
type KeyTraversal<N extends Node, K extends VisitorKey<N>> = FullKeyTraversal<N, K> | KeyHandler<N, K>;
type KeysVisitor<N extends Node> = {
[P in VisitorKey<N>]?: KeyTraversal<N, P>;
} & {
All?: KeyTraversal<N, VisitorKey<N>>;
/**
* @deprecated use Template or Block instead
*/
Program?: KeyTraversal<Template | Block, 'body'>;
};
declare function traverse(node: Node, visitor: NodeVisitor): void;
type NodeCallback<N extends Node> = (node: N, walker: Walker) => void;
declare class Walker {
order?: unknown | undefined;
stack: unknown[];
constructor(order?: unknown | undefined);
visit<N extends Node>(node: Nullable<N>, visitor: NodeCallback<N>): void;
children<N extends Node>(node: N & Node, callback: NodeCallback<N & Node>): void;
}
type BuilderHead = string | CallableExpression;
type TagDescriptor = string | PathExpression | {
path: PathExpression;
selfClosing?: boolean;
} | {
name: string;
selfClosing?: boolean;
};
declare function buildMustache(path: BuilderHead | Literal, params?: Expression[], hash?: Hash, trusting?: boolean, loc?: SourceLocation, strip?: StripFlags): MustacheStatement;
type PossiblyDeprecatedBlock = Block | Template;
declare function buildBlock(path: BuilderHead, params: Nullable<Expression[]>, hash: Nullable<Hash>, _defaultBlock: PossiblyDeprecatedBlock, _elseBlock?: Nullable<PossiblyDeprecatedBlock>, loc?: SourceLocation, openStrip?: StripFlags, inverseStrip?: StripFlags, closeStrip?: StripFlags): BlockStatement;
declare function buildElementModifier(path: BuilderHead, params?: Expression[], hash?: Hash, loc?: Nullable<SourceLocation>): ElementModifierStatement;
declare function buildComment(value: string, loc?: SourceLocation): CommentStatement;
declare function buildMustacheComment(value: string, loc?: SourceLocation): MustacheCommentStatement;
declare function buildConcat(parts: (TextNode | MustacheStatement)[], loc?: SourceLocation): ConcatStatement;
interface BuildElementOptions {
attrs?: AttrNode[];
modifiers?: ElementModifierStatement[];
children?: Statement[];
comments?: MustacheCommentStatement[];
blockParams?: VarHead[] | string[];
openTag?: SourceLocation;
closeTag?: Maybe<SourceLocation>;
loc?: SourceLocation;
}
declare function buildElement(tag: TagDescriptor, options?: BuildElementOptions): ElementNode;
declare function buildAttr(name: string, value: AttrValue, loc?: SourceLocation): AttrNode;
declare function buildText(chars?: string, loc?: SourceLocation): TextNode;
declare function buildSexpr(path: BuilderHead, params?: Expression[], hash?: Hash, loc?: SourceLocation): SubExpression;
declare function buildThis(loc?: SourceLocation): ThisHead;
declare function buildAtName(name: string, loc?: SourceLocation): AtHead;
declare function buildVar(name: string, loc?: SourceLocation): VarHead;
declare function buildHeadFromString(original: string, loc?: SourceLocation): PathHead;
declare function buildCleanPath(head: PathHead, tail?: string[], loc?: SourceLocation): PathExpression;
declare function buildPath(path: PathExpression | string | {
head: string;
tail: string[];
}, loc?: SourceLocation): PathExpression;
declare function buildPath(path: BuilderHead, loc?: SourceLocation): CallableExpression;
declare function buildPath(path: BuilderHead | Literal | Expression, loc?: SourceLocation): Expression;
declare function buildLiteral<T extends Literal>(type: T['type'], value: T['value'], loc?: SourceLocation): T;
declare function buildHash(pairs?: HashPair[], loc?: SourceLocation): Hash;
declare function buildPair(key: string, value: Expression, loc?: SourceLocation): HashPair;
declare function buildProgram(body?: Statement[], blockParams?: string[], loc?: SourceLocation): Template | Block;
declare function buildBlockItself(body?: Statement[], params?: Array<VarHead | string>, chained?: boolean, loc?: SourceLocation): Block;
declare function buildTemplate(body?: Statement[], blockParams?: string[], loc?: SourceLocation): Template;
declare function buildPosition(line: number, column: number): SourcePosition;
declare function buildLoc(loc: Nullable<SourceLocation>): SourceSpan;
declare function buildLoc(startLine: number, startColumn: number, endLine?: number, endColumn?: number, source?: string): SourceSpan;
declare const _default: {
mustache: typeof buildMustache;
block: typeof buildBlock;
comment: typeof buildComment;
mustacheComment: typeof buildMustacheComment;
element: typeof buildElement;
elementModifier: typeof buildElementModifier;
attr: typeof buildAttr;
text: typeof buildText;
sexpr: typeof buildSexpr;
concat: typeof buildConcat;
hash: typeof buildHash;
pair: typeof buildPair;
literal: typeof buildLiteral;
program: typeof buildProgram;
blockItself: typeof buildBlockItself;
template: typeof buildTemplate;
loc: typeof buildLoc;
pos: typeof buildPosition;
path: typeof buildPath;
fullPath: typeof buildCleanPath;
head: typeof buildHeadFromString;
at: typeof buildAtName;
var: typeof buildVar;
this: typeof buildThis;
string: (value: string) => StringLiteral;
boolean: (value: boolean) => BooleanLiteral;
number: (value: number) => NumberLiteral;
undefined(): UndefinedLiteral;
null(): NullLiteral;
};
/**
ASTPlugins can make changes to the Glimmer template AST before
compilation begins.
*/
interface ASTPluginBuilder<TEnv extends ASTPluginEnvironment = ASTPluginEnvironment> {
(env: TEnv): ASTPlugin;
}
interface ASTPlugin {
name: string;
visitor: NodeVisitor;
}
interface ASTPluginEnvironment {
meta?: object | undefined;
syntax: Syntax;
}
interface HandlebarsParseOptions {
srcName?: string;
ignoreStandalone?: boolean;
}
interface TemplateIdFn {
(src: string): Nullable<string>;
}
interface PrecompileOptions extends PreprocessOptions {
id?: TemplateIdFn;
/**
* Additional non-native keywords.
*
* Local variables (block params or lexical scope) always takes precedence,
* but otherwise, suitable free variable candidates (e.g. those are not part
* of a path) are matched against this list and turned into keywords.
*
* In strict mode compilation, keywords suppresses the undefined reference
* error and will be resolved by the runtime environment.
*
* In loose mode, keywords are currently ignored and since all free variables
* are already resolved by the runtime environment.
*/
keywords?: readonly string[];
/**
* In loose mode, this hook allows embedding environments to customize the name of an
* angle-bracket component. In practice, this means that `<HelloWorld />` in Ember is
* compiled by Glimmer as an invocation of a component named `hello-world`.
*
* It's a little weird that this is needed in addition to the resolver, but it's a
* classic-only feature and it seems fine to leave it alone for classic consumers.
*/
customizeComponentName?: ((input: string) => string) | undefined;
}
interface PrecompileOptionsWithLexicalScope extends PrecompileOptions {
lexicalScope: (variable: string) => boolean;
/**
* If `emit.debugSymbols` is set to `true`, the name of lexical local variables
* will be included in the wire format.
*/
emit?: {
debugSymbols?: boolean;
} | undefined;
}
interface PreprocessOptions {
strictMode?: boolean | undefined;
locals?: string[] | undefined;
meta?: {
moduleName?: string | undefined;
} | undefined;
plugins?: {
ast?: ASTPluginBuilder[] | undefined;
} | undefined;
parseOptions?: HandlebarsParseOptions | undefined;
customizeComponentName?: ((input: string) => string) | undefined;
/**
Useful for specifying a group of options together.
When `'codemod'` we disable all whitespace control in handlebars
(to preserve as much as possible) and we also avoid any
escaping/unescaping of HTML entity codes.
*/
mode?: 'codemod' | 'precompile' | undefined;
}
interface Syntax {
parse: typeof preprocess;
builders: typeof _default;
print: typeof build;
traverse: typeof traverse;
Walker: typeof Walker;
}
declare function preprocess(input: string | Source | Program, options?: PreprocessOptions): Template;
declare class Source {
readonly source: string;
readonly module: string;
static from(source: string, options?: PrecompileOptions): Source;
constructor(source: string, module?: string);
/**
* Validate that the character offset represents a position in the source string.
*/
validate(offset: number): boolean;
slice(start: number, end: number): string;
offsetFor(line: number, column: number): SourceOffset;
spanFor({ start, end }: Readonly<SourceLocation>): SourceSpan;
hbsPosFor(offset: number): Nullable<SourcePosition>;
charPosFor(position: SourcePosition): number | null;
}
/**
* We have already computed the character position of this offset or span.
*/
type CharOffsetKind = 'CharPosition';
/**
* This offset or span was instantiated with a Handlebars SourcePosition or SourceLocation. Its
* character position will be computed on demand.
*/
type HbsPositionKind = 'HbsPosition';
/**
* for (rare) situations where a node is created but there was no source location (e.g. the name
* "default" in default blocks when the word "default" never appeared in source). This is used
* by the internals when there is a legitimate reason for the internals to synthesize a node
* with no location.
*/
type InternalSyntheticKind = 'InternalsSynthetic';
/**
* For situations where a node represents zero parts of the source (for example, empty arguments).
* In general, we attempt to assign these nodes *some* position (empty arguments can be
* positioned immediately after the callee), but it's not always possible
*/
type NonExistentKind = 'NonExistent';
/**
* For situations where a source location was expected, but it didn't correspond to the node in
* the source. This happens if a plugin creates broken locations.
*/
type BrokenKind = 'Broken';
type OffsetKind = CharOffsetKind | HbsPositionKind | InvisibleKind;
/**
* These kinds describe spans that don't have a concrete location in the original source.
*/
type InvisibleKind = BrokenKind | InternalSyntheticKind | NonExistentKind;
type SerializedSourceSlice<Chars extends string = string> = [
chars: Chars,
span: SerializedSourceSpan
];
declare class SourceSlice<Chars extends string = string> {
static synthetic<S extends string>(chars: S): SourceSlice<S>;
static load(source: Source, slice: SerializedSourceSlice): SourceSlice;
readonly chars: Chars;
readonly loc: SourceSpan;
constructor(options: {
loc: SourceSpan;
chars: Chars;
});
getString(): string;
serialize(): SerializedSourceSlice<Chars>;
}
/**
* All spans have these details in common.
*/
interface SpanData {
readonly kind: OffsetKind;
/**
* Convert this span into a string. If the span is broken, return `''`.
*/
asString(): string;
/**
* Gets the module the span was located in.
*/
getModule(): string;
/**
* Get the starting position for this span. Try to avoid creating new position objects, as they
* cache computations.
*/
getStart(): AnyPosition;
/**
* Get the ending position for this span. Try to avoid creating new position objects, as they
* cache computations.
*/
getEnd(): AnyPosition;
/**
* Compute the `SourceLocation` for this span, returned as an instance of `HbsSpan`.
*/
toHbsSpan(): HbsSpan | null;
/**
* For compatibility, whenever the `start` or `end` of a {@see SourceOffset} changes, spans are
* notified of the change so they can update themselves. This shouldn't happen outside of AST
* plugins.
*/
locDidUpdate(changes: {
start?: SourcePosition;
end?: SourcePosition;
}): void;
/**
* Serialize into a {@see SerializedSourceSpan}, which is compact and designed for readability in
* context like AST Explorer. If you need a {@see SourceLocation}, use {@see toJSON}.
*/
serialize(): SerializedSourceSpan;
}
/**
* A `SourceSpan` object represents a span of characters inside of a template source.
*
* There are three kinds of `SourceSpan` objects:
*
* - `ConcreteSourceSpan`, which contains byte offsets
* - `LazySourceSpan`, which contains `SourceLocation`s from the Handlebars AST, which can be
* converted to byte offsets on demand.
* - `InvisibleSourceSpan`, which represent source strings that aren't present in the source,
* because:
* - they were created synthetically
* - their location is nonsensical (the span is broken)
* - they represent nothing in the source (this currently happens only when a bug in the
* upstream Handlebars parser fails to assign a location to empty blocks)
*
* At a high level, all `SourceSpan` objects provide:
*
* - byte offsets
* - source in column and line format
*
* And you can do these operations on `SourceSpan`s:
*
* - collapse it to a `SourceSpan` representing its starting or ending position
* - slice out some characters, optionally skipping some characters at the beginning or end
* - create a new `SourceSpan` with a different starting or ending offset
*
* All SourceSpan objects implement `SourceLocation`, for compatibility. All SourceSpan
* objects have a `toJSON` that emits `SourceLocation`, also for compatibility.
*
* For compatibility, subclasses of `AbstractSourceSpan` must implement `locDidUpdate`, which
* happens when an AST plugin attempts to modify the `start` or `end` of a span directly.
*
* The goal is to avoid creating any problems for use-cases like AST Explorer.
*/
declare class SourceSpan implements SourceLocation {
private data;
static get NON_EXISTENT(): SourceSpan;
static load(source: Source, serialized: SerializedSourceSpan): SourceSpan;
static forHbsLoc(source: Source, loc: SourceLocation): SourceSpan;
static forCharPositions(source: Source, startPos: number, endPos: number): SourceSpan;
static synthetic(chars: string): SourceSpan;
static broken(pos?: SourceLocation): SourceSpan;
readonly isInvisible: boolean;
constructor(data: SpanData & AnySpan);
getStart(): SourceOffset;
getEnd(): SourceOffset;
get loc(): SourceLocation;
get module(): string;
/**
* Get the starting `SourcePosition` for this `SourceSpan`, lazily computing it if needed.
*/
get startPosition(): SourcePosition;
/**
* Get the ending `SourcePosition` for this `SourceSpan`, lazily computing it if needed.
*/
get endPosition(): SourcePosition;
/**
* Support converting ASTv1 nodes into a serialized format using JSON.stringify.
*/
toJSON(): SourceLocation;
/**
* Create a new span with the current span's end and a new beginning.
*/
withStart(other: SourceOffset): SourceSpan;
/**
* Create a new span with the current span's beginning and a new ending.
*/
withEnd(other: SourceOffset): SourceSpan;
asString(): string;
/**
* Convert this `SourceSpan` into a `SourceSlice`. In debug mode, this method optionally checks
* that the byte offsets represented by this `SourceSpan` actually correspond to the expected
* string.
*/
toSlice(expected?: string): SourceSlice;
/**
* For compatibility with SourceLocation in AST plugins
*
* @deprecated use startPosition instead
*/
get start(): SourcePosition;
/**
* For compatibility with SourceLocation in AST plugins
*
* @deprecated use withStart instead
*/
set start(position: SourcePosition);
/**
* For compatibility with SourceLocation in AST plugins
*
* @deprecated use endPosition instead
*/
get end(): SourcePosition;
/**
* For compatibility with SourceLocation in AST plugins
*
* @deprecated use withEnd instead
*/
set end(position: SourcePosition);
/**
* For compatibility with SourceLocation in AST plugins
*
* @deprecated use module instead
*/
get source(): string;
collapse(where: 'start' | 'end'): SourceSpan;
extend(other: SourceSpan): SourceSpan;
serialize(): SerializedSourceSpan;
slice({ skipStart, skipEnd }: {
skipStart?: number;
skipEnd?: number;
}): SourceSpan;
sliceStartChars({ skipStart, chars }: {
skipStart?: number;
chars: number;
}): SourceSpan;
sliceEndChars({ skipEnd, chars }: {
skipEnd?: number;
chars: number;
}): SourceSpan;
}
type AnySpan = HbsSpan | CharPositionSpan | InvisibleSpan;
declare class CharPositionSpan implements SpanData {
#private;
readonly source: Source;
readonly charPositions: {
start: CharPosition;
end: CharPosition;
};
readonly kind: "CharPosition";
constructor(source: Source, charPositions: {
start: CharPosition;
end: CharPosition;
});
wrap(): SourceSpan;
asString(): string;
getModule(): string;
getStart(): AnyPosition;
getEnd(): AnyPosition;
locDidUpdate(): void;
toHbsSpan(): HbsSpan | null;
serialize(): SerializedSourceSpan;
toCharPosSpan(): this;
}
declare class HbsSpan implements SpanData {
#private;
readonly source: Source;
readonly hbsPositions: {
start: HbsPosition;
end: HbsPosition;
};
readonly kind: "HbsPosition";
constructor(source: Source, hbsPositions: {
start: HbsPosition;
end: HbsPosition;
}, providedHbsLoc?: SourceLocation | null);
serialize(): SerializedConcreteSourceSpan;
wrap(): SourceSpan;
private updateProvided;
locDidUpdate({ start, end }: {
start?: SourcePosition;
end?: SourcePosition;
}): void;
asString(): string;
getModule(): string;
getStart(): AnyPosition;
getEnd(): AnyPosition;
toHbsLoc(): SourceLocation;
toHbsSpan(): this;
toCharPosSpan(): CharPositionSpan | null;
}
declare class InvisibleSpan implements SpanData {
readonly kind: InvisibleKind;
readonly loc: SourceLocation;
readonly string: string | null;
constructor(kind: InvisibleKind, loc: SourceLocation, string?: string | null);
serialize(): SerializedConcreteSourceSpan;
wrap(): SourceSpan;
asString(): string;
locDidUpdate({ start, end }: {
start?: SourcePosition;
end?: SourcePosition;
}): void;
getModule(): string;
getStart(): AnyPosition;
getEnd(): AnyPosition;
toCharPosSpan(): this;
toHbsSpan(): null;
toHbsLoc(): SourceLocation;
}
type SerializedConcreteSourceSpan = /** collapsed */ number | /** normal */ [start: number, size: number] | /** synthetic */ string;
type SerializedSourceSpan = SerializedConcreteSourceSpan;
interface SourceLocation {
start: SourcePosition;
end: SourcePosition;
}
interface SourcePosition {
/** >= 1 */
line: number;
/** >= 0 */
column: number;
}
/**
* All positions have these details in common. Most notably, all three kinds of positions can
* must be able to attempt to convert themselves into {@see CharPosition}.
*/
interface PositionData {
readonly kind: OffsetKind;
toCharPos(): CharPosition | null;
toJSON(): SourcePosition;
}
/**
* Used to indicate that an attempt to convert a `SourcePosition` to a character offset failed. It
* is separate from `null` so that `null` can be used to indicate that the computation wasn't yet
* attempted (and therefore to cache the failure)
*/
declare const BROKEN = "BROKEN";
type BROKEN = 'BROKEN';
type AnyPosition = HbsPosition | CharPosition | InvisiblePosition;
/**
* A `SourceOffset` represents a single position in the source.
*
* There are three kinds of backing data for `SourceOffset` objects:
*
* - `CharPosition`, which contains a character offset into the raw source string
* - `HbsPosition`, which contains a `SourcePosition` from the Handlebars AST, which can be
* converted to a `CharPosition` on demand.
* - `InvisiblePosition`, which represents a position not in source (@see {InvisiblePosition})
*/
declare class SourceOffset {
readonly data: PositionData & AnyPosition;
/**
* Create a `SourceOffset` from a Handlebars `SourcePosition`. It's stored as-is, and converted
* into a character offset on demand, which avoids unnecessarily computing the offset of every
* `SourceLocation`, but also means that broken `SourcePosition`s are not always detected.
*/
static forHbsPos(source: Source, pos: SourcePosition): SourceOffset;
/**
* Create a `SourceOffset` that corresponds to a broken `SourcePosition`. This means that the
* calling code determined (or knows) that the `SourceLocation` doesn't correspond correctly to
* any part of the source.
*/
static broken(pos?: SourcePosition): SourceOffset;
constructor(data: PositionData & AnyPosition);
/**
* Get the character offset for this `SourceOffset`, if possible.
*/
get offset(): number | null;
/**
* Compare this offset with another one.
*
* If both offsets are `HbsPosition`s, they're equivalent as long as their lines and columns are
* the same. This avoids computing offsets unnecessarily.
*
* Otherwise, two `SourceOffset`s are equivalent if their successfully computed character offsets
* are the same.
*/
eql(right: SourceOffset): boolean;
/**
* Create a span that starts from this source offset and ends with another source offset. Avoid
* computing character offsets if both `SourceOffset`s are still lazy.
*/
until(other: SourceOffset): SourceSpan;
/**
* Create a `SourceOffset` by moving the character position represented by this source offset
* forward or backward (if `by` is negative), if possible.
*
* If this `SourceOffset` can't compute a valid character offset, `move` returns a broken offset.
*
* If the resulting character offset is less than 0 or greater than the size of the source, `move`
* returns a broken offset.
*/
move(by: number): SourceOffset;
/**
* Create a new `SourceSpan` that represents a collapsed range at this source offset. Avoid
* computing the character offset if it has not already been computed.
*/
collapsed(): SourceSpan;
/**
* Convert this `SourceOffset` into a Handlebars {@see SourcePosition} for compatibility with
* existing plugins.
*/
toJSON(): SourcePosition;
}
declare class CharPosition implements PositionData {
readonly source: Source;
readonly charPos: number;
readonly kind: "CharPosition";
/** Computed from char offset */
_locPos: HbsPosition | BROKEN | null;
constructor(source: Source, charPos: number);
/**
* This is already a `CharPosition`.
*
* {@see HbsPosition} for the alternative.
*/
toCharPos(): this;
/**
* Produce a Handlebars {@see SourcePosition} for this `CharPosition`. If this `CharPosition` was
* computed using {@see SourceOffset#move}, this will compute the `SourcePosition` for the offset.
*/
toJSON(): SourcePosition;
wrap(): SourceOffset;
/**
* A `CharPosition` always has an offset it can produce without any additional computation.
*/
get offset(): number;
/**
* Convert the current character offset to an `HbsPosition`, if it was not already computed. Once
* a `CharPosition` has computed its `HbsPosition`, it will not need to do compute it again, and
* the same `CharPosition` is retained when used as one of the ends of a `SourceSpan`, so
* computing the `HbsPosition` should be a one-time operation.
*/
toHbsPos(): HbsPosition | null;
}
declare class HbsPosition implements PositionData {
readonly source: Source;
readonly hbsPos: SourcePosition;
readonly kind: "HbsPosition";
_charPos: CharPosition | BROKEN | null;
constructor(source: Source, hbsPos: SourcePosition, charPos?: number | null);
/**
* Lazily compute the character offset from the {@see SourcePosition}. Once an `HbsPosition` has
* computed its `CharPosition`, it will not need to do compute it again, and the same
* `HbsPosition` is retained when used as one of the ends of a `SourceSpan`, so computing the
* `CharPosition` should be a one-time operation.
*/
toCharPos(): CharPosition | null;
/**
* Return the {@see SourcePosition} that this `HbsPosition` was instantiated with. This operation
* does not need to compute anything.
*/
toJSON(): SourcePosition;
wrap(): SourceOffset;
/**
* This is already an `HbsPosition`.
*
* {@see CharPosition} for the alternative.
*/
toHbsPos(): this;
}
declare class InvisiblePosition implements PositionData {
readonly kind: BrokenKind | InternalSyntheticKind | NonExistentKind;
readonly pos: SourcePosition;
constructor(kind: BrokenKind | InternalSyntheticKind | NonExistentKind, pos: SourcePosition);
/**
* A broken position cannot be turned into a {@see CharacterPosition}.
*/
toCharPos(): null;
/**
* The serialization of an `InvisiblePosition is whatever Handlebars {@see SourcePosition} was
* originally identified as broken, non-existent or synthetic.
*
* If an `InvisiblePosition` never had an source offset at all, this method returns
* {@see UNKNOWN_POSITION} for compatibility.
*/
toJSON(): SourcePosition;
wrap(): SourceOffset;
get offset(): null;
}
interface BaseNode {
type: NodeType;
loc: SourceSpan;
}
interface CommonProgram extends BaseNode {
body: Statement[];
}
interface Block extends CommonProgram {
type: 'Block';
params: VarHead[];
chained?: boolean;
/**
* string accessor for params.name
*/
blockParams: string[];
}
type EntityEncodingState = 'transformed' | 'raw';
interface Template extends CommonProgram {
type: 'Template';
blockParams: string[];
}
type CallableExpression = SubExpression | PathExpression;
interface MustacheStatement extends BaseNode {
type: 'MustacheStatement';
path: Expression;
params: Expression[];
hash: Hash;
trusting: boolean;
strip: StripFlags;
/**
* @deprecated use trusting instead
*/
escaped: boolean;
}
interface BlockStatement extends BaseNode {
type: 'BlockStatement';
path: CallableExpression;
params: Expression[];
hash: Hash;
program: Block;
inverse?: Nullable<Block>;
openStrip: StripFlags;
inverseStrip: StripFlags;
closeStrip: StripFlags;
chained?: boolean;
}
interface ElementModifierStatement extends BaseNode {
type: 'ElementModifierStatement';
path: CallableExpression;
params: Expression[];
hash: Hash;
}
interface CommentStatement extends BaseNode {
type: 'CommentStatement';
value: string;
}
interface MustacheCommentStatement extends BaseNode {
type: 'MustacheCommentStatement';
value: string;
}
interface ElementNode extends BaseNode {
type: 'ElementNode';
path: PathExpression;
selfClosing: boolean;
attributes: AttrNode[];
params: VarHead[];
modifiers: ElementModifierStatement[];
comments: MustacheCommentStatement[];
children: Statement[];
/**
* span for the open tag
*/
openTag: SourceSpan;
/**
* span for the close tag, null for void or self-closing tags
*/
closeTag: Nullable<SourceSpan>;
/**
* string accessor for path.original
*/
tag: string;
/**
* string accessor for params.name
*/
blockParams: string[];
}
type StatementName = 'MustacheStatement' | 'CommentStatement' | 'BlockStatement' | 'MustacheCommentStatement' | 'TextNode' | 'ElementNode';
interface AttrNode extends BaseNode {
type: 'AttrNode';
name: string;
value: AttrValue;
}
type AttrValue = TextNode | MustacheStatement | ConcatStatement;
interface TextNode extends BaseNode {
type: 'TextNode';
chars: string;
}
interface ConcatStatement extends BaseNode {
type: 'ConcatStatement';
parts: PresentArray<TextNode | MustacheStatement>;
}
type ExpressionName = 'SubExpression' | 'PathExpression' | LiteralName;
interface SubExpression extends BaseNode {
type: 'SubExpression';
path: CallableExpression;
params: Expression[];
hash: Hash;
}
interface ThisHead {
type: 'ThisHead';
original: 'this';
loc: SourceSpan;
}
interface AtHead {
type: 'AtHead';
name: string;
loc: SourceSpan;
/**
* alias for name
*/
original: string;
}
interface VarHead {
type: 'VarHead';
name: string;
loc: SourceSpan;
/**
* alias for name
*/
original: string;
}
type PathHead = ThisHead | AtHead | VarHead;
interface MinimalPathExpression extends BaseNode {
type: 'PathExpression';
head: PathHead;
tail: string[];
}
interface PathExpression extends MinimalPathExpression {
type: 'PathExpression';
original: string;
head: PathHead;
tail: string[];
/**
* @deprecated use `head` and `tail` instead
*/
parts: readonly string[];
/**
* @deprecated use `head.type` instead
*/
readonly this: boolean;
/**
* @deprecated use `head.type' instead
*/
readonly data: boolean;
}
type LiteralName = 'StringLiteral' | 'BooleanLiteral' | 'NumberLiteral' | 'UndefinedLiteral' | 'NullLiteral';
interface StringLiteral extends BaseNode {
type: 'StringLiteral';
value: string;
/**
* @deprecated use value instead
*/
original: string;
}
interface BooleanLiteral extends BaseNode {
type: 'BooleanLiteral';
value: boolean;
/**
* @deprecated use value instead
*/
original: boolean;
}
interface NumberLiteral extends BaseNode {
type: 'NumberLiteral';
value: number;
/**
* @deprecated use value instead
*/
original: number;
}
interface UndefinedLiteral extends BaseNode {
type: 'UndefinedLiteral';
value: undefined;
/**
* @deprecated use value instead
*/
original: undefined;
}
interface NullLiteral extends BaseNode {
type: 'NullLiteral';
value: null;
/**
* @deprecated use value instead
*/
original: null;
}
interface Hash extends BaseNode {
type: 'Hash';
pairs: HashPair[];
}
interface HashPair extends BaseNode {
type: 'HashPair';
key: string;
value: Expression;
}
interface StripFlags {
open: boolean;
close: boolean;
}
type Nodes = {
Template: Template;
Block: Block;
MustacheStatement: MustacheStatement;
BlockStatement: BlockStatement;
ElementModifierStatement: ElementModifierStatement;
CommentStatement: CommentStatement;
MustacheCommentStatement: MustacheCommentStatement;
ElementNode: ElementNode;
AttrNode: AttrNode;
TextNode: TextNode;
ConcatStatement: ConcatStatement;
SubExpression: SubExpression;
PathExpression: PathExpression;
StringLiteral: StringLiteral;
BooleanLiteral: BooleanLiteral;
NumberLiteral: NumberLiteral;
NullLiteral: NullLiteral;
UndefinedLiteral: UndefinedLiteral;
Hash: Hash;
HashPair: HashPair;
};
type NodeType = keyof Nodes;
type Node = Nodes[NodeType];
type Statement = Nodes[StatementName];
type Literal = Nodes[LiteralName];
type Expression = Nodes[ExpressionName];
interface PrinterOptions {
entityEncoding: EntityEncodingState;
/**
* Used to override the mechanism of printing a given AST.Node.
*
* This will generally only be useful to source -> source codemods
* where you would like to specialize/override the way a given node is
* printed (e.g. you would like to preserve as much of the original
* formatting as possible).
*
* When the provided override returns undefined, the default built in printing
* will be done for the AST.Node.
*
* @param ast the ast node to be printed
* @param options the options specified during the print() invocation
*/
override?(ast: Node, options: PrinterOptions): void | string;
}
declare function build(ast: Node, options?: PrinterOptions): string;
declare const defaultId: TemplateIdFn;
declare function precompileJSON(string: Nullable<string>, options?: PrecompileOptions | PrecompileOptionsWithLexicalScope): [block: SerializedTemplateBlock, usedLocals: string[]];
declare function precompile(source: string, options?: PrecompileOptions | PrecompileOptionsWithLexicalScope): TemplateJavascript;
declare class WireFormatDebugger {
private upvars;
private symbols;
constructor([_statements, symbols, upvars]: SerializedTemplateBlock);
format(program: SerializedTemplateBlock): unknown;
formatOpcode(opcode: Syntax$1): unknown;
private formatCurryType;
private formatElementParams;
private formatParams;
private formatHash;
private formatBlocks;
private formatBlock;
}
export { type BuilderStatement, NEWLINE, type PrecompileOptions, ProgramSymbols, WireFormatDebugger, buildStatement, buildStatements, c, defaultId, precompile, precompileJSON, s, unicode };

@@ -1,4 +0,1747 @@

export { buildStatement, buildStatements, c, NEWLINE, ProgramSymbols, s, unicode, } from './lib/builder/builder';
export { type BuilderStatement } from './lib/builder/builder-interface';
export { defaultId, precompile, precompileJSON, type PrecompileOptions } from './lib/compiler';
export { default as WireFormatDebugger } from './lib/wire-format-debug';
type Nullable<T> = T | null;
type Optional<T> = T | undefined;
type Maybe<T> = Nullable<T> | Optional<T>;
type Dict<T = unknown> = Record<string, T>;
type PresentArray<T> = [T, ...T[]];
type CurriedComponent = 0;
type CurriedHelper = 1;
type CurriedModifier = 2;
type CurriedType = CurriedComponent | CurriedHelper | CurriedModifier;
// Statements
type AppendOpcode = 1;
type TrustingAppendOpcode = 2;
type CommentOpcode = 3;
type ModifierOpcode = 4;
type BlockOpcode = 6;
type ComponentOpcode = 8;
type OpenElementOpcode = 10;
type OpenElementWithSplatOpcode = 11;
type FlushElementOpcode = 12;
type CloseElementOpcode = 13;
type StaticAttrOpcode = 14;
type DynamicAttrOpcode = 15;
type ComponentAttrOpcode = 16;
type AttrSplatOpcode = 17;
type YieldOpcode = 18;
type DynamicArgOpcode = 20;
type StaticArgOpcode = 21;
type TrustingDynamicAttrOpcode = 22;
type TrustingComponentAttrOpcode = 23;
type StaticComponentAttrOpcode = 24;
type DebuggerOpcode = 26;
// Expressions
type UndefinedOpcode = 27;
type CallOpcode = 28;
type ConcatOpcode = 29;
// Get
// Get a local value via symbol
type GetSymbolOpcode = 30; // GetPath + 0-2,
// Lexical symbols are values that are in scope in the template in strict mode
type GetLexicalSymbolOpcode = 32;
// If a free variable is not a lexical symbol in strict mode, it must be a keyword.
// FIXME: Why does this make it to the wire format in the first place?
type GetStrictKeywordOpcode = 31;
// a component or helper (`{{<expr> x}}` in append position)
type GetFreeAsComponentOrHelperHeadOpcode = 35;
// a call head `(x)`
type GetFreeAsHelperHeadOpcode = 37;
type GetFreeAsModifierHeadOpcode = 38;
type GetFreeAsComponentHeadOpcode = 39;
// Keyword Statements
type InElementOpcode = 40;
type IfOpcode = 41;
type EachOpcode = 42;
type LetOpcode = 44;
type WithDynamicVarsOpcode = 45;
type InvokeComponentOpcode = 46;
// Keyword Expressions
type HasBlockOpcode = 48;
type HasBlockParamsOpcode = 49;
type CurryOpcode = 50;
type NotOpcode = 51;
type IfInlineOpcode = 52;
type GetDynamicVarOpcode = 53;
type LogOpcode = 54;
type AttrOpcode =
| StaticAttrOpcode
| StaticComponentAttrOpcode
| DynamicAttrOpcode
| TrustingDynamicAttrOpcode
| ComponentAttrOpcode
| TrustingComponentAttrOpcode;
type YieldTo = number;
declare namespace Core {
export type Expression = Expressions.Expression;
export type DebugSymbols = [locals: Record<string, number>, upvars: Record<string, number>];
export type CallArgs = [Params, Hash];
export type Path = [string, ...string[]];
export type ConcatParams = PresentArray<Expression>;
export type Params = Nullable<ConcatParams>;
export type Hash = Nullable<[PresentArray<string>, PresentArray<Expression>]>;
export type Blocks = Nullable<[string[], SerializedInlineBlock[]]>;
export type Args = [Params, Hash];
export type NamedBlock = [string, SerializedInlineBlock];
export type ElementParameters = Nullable<PresentArray<ElementParameter>>;
export type Syntax = Path | Params | ConcatParams | Hash | Blocks | Args;
}
declare namespace Expressions {
export type Path = Core.Path;
export type Params = Core.Params;
export type Hash = Core.Hash;
export type GetSymbol = [GetSymbolOpcode, number];
export type GetLexicalSymbol = [GetLexicalSymbolOpcode, number];
export type GetStrictFree = [GetStrictKeywordOpcode, number];
export type GetFreeAsComponentOrHelperHead = [GetFreeAsComponentOrHelperHeadOpcode, number];
export type GetFreeAsHelperHead = [GetFreeAsHelperHeadOpcode, number];
export type GetFreeAsModifierHead = [GetFreeAsModifierHeadOpcode, number];
export type GetFreeAsComponentHead = [GetFreeAsComponentHeadOpcode, number];
export type GetContextualFree =
| GetFreeAsComponentOrHelperHead
| GetFreeAsHelperHead
| GetFreeAsModifierHead
| GetFreeAsComponentHead;
export type GetFree = GetStrictFree | GetContextualFree;
export type GetVar = GetSymbol | GetLexicalSymbol | GetFree;
export type GetPathSymbol = [GetSymbolOpcode, number, Path];
export type GetPathTemplateSymbol = [GetLexicalSymbolOpcode, number, Path];
export type GetPathFreeAsComponentOrHelperHead = [
GetFreeAsComponentOrHelperHeadOpcode,
number,
Path,
];
export type GetPathFreeAsHelperHead = [GetFreeAsHelperHeadOpcode, number, Path];
export type GetPathFreeAsModifierHead = [GetFreeAsModifierHeadOpcode, number, Path];
export type GetPathFreeAsComponentHead = [GetFreeAsComponentHeadOpcode, number, Path];
export type GetPathContextualFree =
| GetPathFreeAsComponentOrHelperHead
| GetPathFreeAsHelperHead
| GetPathFreeAsModifierHead
| GetPathFreeAsComponentHead;
export type GetPath = GetPathSymbol | GetPathTemplateSymbol | GetPathContextualFree;
export type Get = GetVar | GetPath;
export type StringValue = string;
export type NumberValue = number;
export type BooleanValue = boolean;
export type NullValue = null;
export type Value = StringValue | NumberValue | BooleanValue | NullValue;
export type Undefined = [UndefinedOpcode];
export type TupleExpression =
| Get
| GetDynamicVar
| Concat
| HasBlock
| HasBlockParams
| Curry
| Helper
| Undefined
| IfInline
| Not
| Log;
// TODO get rid of undefined, which is just here to allow trailing undefined in attrs
// it would be better to handle that as an over-the-wire encoding concern
export type Expression = TupleExpression | Value | undefined;
export type Concat = [ConcatOpcode, Core.ConcatParams];
export type Helper = [CallOpcode, Expression, Nullable<Params>, Hash];
export type HasBlock = [HasBlockOpcode, Expression];
export type HasBlockParams = [HasBlockParamsOpcode, Expression];
export type Curry = [CurryOpcode, Expression, CurriedType, Params, Hash];
export type IfInline = [
op: IfInlineOpcode,
condition: Expression,
truthyValue: Expression,
falsyValue?: Nullable<Expression>,
];
export type Not = [op: NotOpcode, value: Expression];
export type GetDynamicVar = [op: GetDynamicVarOpcode, value: Expression];
export type Log = [op: LogOpcode, positional: Params];
}
type TupleExpression = Expressions.TupleExpression;
type ClassAttr = 0;
type IdAttr = 1;
type ValueAttr = 2;
type NameAttr = 3;
type TypeAttr = 4;
type StyleAttr = 5;
type HrefAttr = 6;
type WellKnownAttrName =
| ClassAttr
| IdAttr
| ValueAttr
| NameAttr
| TypeAttr
| StyleAttr
| HrefAttr;
type DivTag = 0;
type SpanTag = 1;
type PTag = 2;
type ATag = 3;
type WellKnownTagName = DivTag | SpanTag | PTag | ATag;
declare namespace Statements {
export type Expression = Expressions.Expression | undefined;
export type Params = Core.Params;
export type Hash = Core.Hash;
export type Blocks = Core.Blocks;
export type Path = Core.Path;
export type Append = [AppendOpcode, Expression];
export type TrustingAppend = [TrustingAppendOpcode, Expression];
export type Comment = [CommentOpcode, string];
export type Modifier = [ModifierOpcode, Expression, Params, Hash];
export type Block = [BlockOpcode, Expression, Params, Hash, Blocks];
export type Component = [
op: ComponentOpcode,
tag: Expression,
parameters: Core.ElementParameters,
args: Hash,
blocks: Blocks,
];
export type OpenElement = [OpenElementOpcode, string | WellKnownTagName];
export type OpenElementWithSplat = [OpenElementWithSplatOpcode, string | WellKnownTagName];
export type FlushElement = [FlushElementOpcode];
export type CloseElement = [CloseElementOpcode];
type Attr<Op extends AttrOpcode> = [
op: Op,
name: string | WellKnownAttrName,
value: Expression,
namespace?: string | undefined,
];
export type StaticAttr = Attr<StaticAttrOpcode>;
export type StaticComponentAttr = Attr<StaticComponentAttrOpcode>;
export type AnyStaticAttr = StaticAttr | StaticComponentAttr;
export type AttrSplat = [AttrSplatOpcode, YieldTo];
export type Yield = [YieldOpcode, YieldTo, Nullable<Params>];
export type DynamicArg = [DynamicArgOpcode, string, Expression];
export type StaticArg = [StaticArgOpcode, string, Expression];
export type DynamicAttr = Attr<DynamicAttrOpcode>;
export type ComponentAttr = Attr<ComponentAttrOpcode>;
export type TrustingDynamicAttr = Attr<TrustingDynamicAttrOpcode>;
export type TrustingComponentAttr = Attr<TrustingComponentAttrOpcode>;
export type AnyDynamicAttr =
| DynamicAttr
| ComponentAttr
| TrustingDynamicAttr
| TrustingComponentAttr;
export type Debugger = [
op: DebuggerOpcode,
locals: Record<string, number>,
upvars: Record<string, number>,
lexical: Record<string, number>,
];
export type InElement = [
op: InElementOpcode,
block: SerializedInlineBlock,
guid: string,
destination: Expression,
insertBefore?: Expression,
];
export type If = [
op: IfOpcode,
condition: Expression,
block: SerializedInlineBlock,
inverse: Nullable<SerializedInlineBlock>,
];
export type Each = [
op: EachOpcode,
condition: Expression,
key: Nullable<Expression>,
block: SerializedInlineBlock,
inverse: Nullable<SerializedInlineBlock>,
];
export type Let = [op: LetOpcode, positional: Core.Params, block: SerializedInlineBlock];
export type WithDynamicVars = [
op: WithDynamicVarsOpcode,
args: Core.Hash,
block: SerializedInlineBlock,
];
export type InvokeComponent = [
op: InvokeComponentOpcode,
definition: Expression,
positional: Core.Params,
named: Core.Hash,
blocks: Blocks | null,
];
/**
* A Handlebars statement
*/
export type Statement =
| Append
| TrustingAppend
| Comment
| Modifier
| Block
| Component
| OpenElement
| OpenElementWithSplat
| FlushElement
| CloseElement
| Attribute
| AttrSplat
| Yield
| StaticArg
| DynamicArg
| Debugger
| InElement
| If
| Each
| Let
| WithDynamicVars
| InvokeComponent;
export type Attribute =
| StaticAttr
| StaticComponentAttr
| DynamicAttr
| TrustingDynamicAttr
| ComponentAttr
| TrustingComponentAttr;
export type ComponentFeature = Modifier | AttrSplat;
export type Argument = StaticArg | DynamicArg;
export type ElementParameter = Attribute | Argument | ComponentFeature;
}
/** A Handlebars statement */
type Statement$2 = Statements.Statement;
type ElementParameter = Statements.ElementParameter;
type SexpSyntax = Statement$2 | TupleExpression;
// TODO this undefined is related to the other TODO in this file
type Syntax$1 = SexpSyntax | Expressions.Value | undefined;
type SerializedInlineBlock = [statements: Statements.Statement[], parameters: number[]];
/**
* A JSON object that the compiled TemplateBlock was serialized into.
*/
type SerializedTemplateBlock = [
statements: Statements.Statement[],
locals: string[],
upvars: string[],
lexicalSymbols?: string[],
];
/**
* A string of Javascript containing a SerializedTemplateWithLazyBlock to be
* concatenated into a Javascript module.
*/
type TemplateJavascript = string;
type BUILDER_LITERAL = 0;
declare const BUILDER_LITERAL: BUILDER_LITERAL;
type BUILDER_COMMENT = 1;
declare const BUILDER_COMMENT: BUILDER_COMMENT;
type BUILDER_APPEND = 2;
declare const BUILDER_APPEND: BUILDER_APPEND;
type BUILDER_MODIFIER = 3;
declare const BUILDER_MODIFIER: BUILDER_MODIFIER;
type BUILDER_DYNAMIC_COMPONENT = 4;
declare const BUILDER_DYNAMIC_COMPONENT: BUILDER_DYNAMIC_COMPONENT;
type BUILDER_GET = 5;
declare const BUILDER_GET: BUILDER_GET;
type BUILDER_CONCAT = 6;
declare const BUILDER_CONCAT: BUILDER_CONCAT;
type BUILDER_HAS_BLOCK = 7;
declare const BUILDER_HAS_BLOCK: BUILDER_HAS_BLOCK;
type BUILDER_HAS_BLOCK_PARAMS = 8;
declare const BUILDER_HAS_BLOCK_PARAMS: BUILDER_HAS_BLOCK_PARAMS;
type BLOCK_HEAD = 'Block';
declare const BLOCK_HEAD: BLOCK_HEAD;
type CALL_HEAD = 'Call';
declare const CALL_HEAD: CALL_HEAD;
type ELEMENT_HEAD = 'Element';
declare const ELEMENT_HEAD: ELEMENT_HEAD;
type APPEND_PATH_HEAD = 'AppendPath';
declare const APPEND_PATH_HEAD: APPEND_PATH_HEAD;
type APPEND_EXPR_HEAD = 'AppendExpr';
declare const APPEND_EXPR_HEAD: APPEND_EXPR_HEAD;
type LITERAL_HEAD = 'Literal';
declare const LITERAL_HEAD: LITERAL_HEAD;
type MODIFIER_HEAD = 'Modifier';
declare const MODIFIER_HEAD: MODIFIER_HEAD;
type DYNAMIC_COMPONENT_HEAD = 'DynamicComponent';
declare const DYNAMIC_COMPONENT_HEAD: DYNAMIC_COMPONENT_HEAD;
type COMMENT_HEAD = 'Comment';
declare const COMMENT_HEAD: COMMENT_HEAD;
type SPLAT_HEAD = 'Splat';
declare const SPLAT_HEAD: SPLAT_HEAD;
type KEYWORD_HEAD = 'Keyword';
declare const KEYWORD_HEAD: KEYWORD_HEAD;
type LOCAL_VAR = 'Local';
declare const LOCAL_VAR: LOCAL_VAR;
type FREE_VAR = 'Free';
declare const FREE_VAR: FREE_VAR;
type ARG_VAR = 'Arg';
declare const ARG_VAR: ARG_VAR;
type BLOCK_VAR = 'Block';
declare const BLOCK_VAR: BLOCK_VAR;
type THIS_VAR = 'This';
declare const THIS_VAR: THIS_VAR;
type VariableKind = LOCAL_VAR | FREE_VAR | ARG_VAR | BLOCK_VAR | THIS_VAR;
type LITERAL_EXPR = 'Literal';
declare const LITERAL_EXPR: LITERAL_EXPR;
type CALL_EXPR = 'Call';
declare const CALL_EXPR: CALL_EXPR;
type GET_PATH_EXPR = 'GetPath';
declare const GET_PATH_EXPR: GET_PATH_EXPR;
type GET_VAR_EXPR = 'GetVar';
declare const GET_VAR_EXPR: GET_VAR_EXPR;
type CONCAT_EXPR = 'Concat';
declare const CONCAT_EXPR: CONCAT_EXPR;
type HAS_BLOCK_EXPR = 'HasBlock';
declare const HAS_BLOCK_EXPR: HAS_BLOCK_EXPR;
type HAS_BLOCK_PARAMS_EXPR = 'HasBlockParams';
declare const HAS_BLOCK_PARAMS_EXPR: HAS_BLOCK_PARAMS_EXPR;
type BuilderParams = BuilderExpression[];
type BuilderHash = Nullable<Dict<BuilderExpression>>;
type BuilderBlockHash = BuilderHash | {
as: string | string[];
};
type BuilderBlocks = Dict<BuilderBlock>;
type BuilderAttrs = Dict<BuilderAttr>;
type NormalizedParams = NormalizedExpression[];
type NormalizedHash = Dict<NormalizedExpression>;
type NormalizedBlock = NormalizedStatement[];
type NormalizedBlocks = Dict<NormalizedBlock>;
type NormalizedAttrs = Dict<NormalizedAttr>;
type NormalizedAttr = SPLAT_HEAD | NormalizedExpression;
interface Variable {
kind: VariableKind;
name: string;
/**
* Differences:
*
* - strict mode variables always refer to in-scope variables
* - loose mode variables use this algorithm:
* 1. otherwise, fall back to `this.<name>`
*/
mode: 'loose' | 'strict';
}
interface Path {
head: Variable;
tail: PresentArray<string>;
}
interface AppendExpr {
kind: APPEND_EXPR_HEAD;
expr: NormalizedExpression;
trusted: boolean;
}
interface AppendPath {
kind: APPEND_PATH_HEAD;
path: NormalizedPath;
trusted: boolean;
}
interface NormalizedKeywordStatement {
kind: KEYWORD_HEAD;
name: string;
params: Nullable<NormalizedParams>;
hash: Nullable<NormalizedHash>;
blockParams: Nullable<string[]>;
blocks: NormalizedBlocks;
}
type NormalizedStatement = {
kind: CALL_HEAD;
head: NormalizedHead;
params: Nullable<NormalizedParams>;
hash: Nullable<NormalizedHash>;
trusted: boolean;
} | {
kind: BLOCK_HEAD;
head: NormalizedHead;
params: Nullable<NormalizedParams>;
hash: Nullable<NormalizedHash>;
blockParams: Nullable<string[]>;
blocks: NormalizedBlocks;
} | NormalizedKeywordStatement | {
kind: ELEMENT_HEAD;
name: string;
attrs: NormalizedAttrs;
block: NormalizedBlock;
} | {
kind: COMMENT_HEAD;
value: string;
} | {
kind: LITERAL_HEAD;
value: string;
} | AppendPath | AppendExpr | {
kind: MODIFIER_HEAD;
params: NormalizedParams;
hash: Nullable<NormalizedHash>;
} | {
kind: DYNAMIC_COMPONENT_HEAD;
expr: NormalizedExpression;
hash: Nullable<NormalizedHash>;
block: NormalizedBlock;
};
type SugaryArrayStatement = BuilderCallExpression | BuilderElement | BuilderBlockStatement;
type BuilderBlockStatement = [string, BuilderBlock | BuilderBlocks] | [string, BuilderParams | BuilderBlockHash, BuilderBlock | BuilderBlocks] | [string, BuilderParams, BuilderBlockHash, BuilderBlock | BuilderBlocks];
type BuilderElement = [string] | [string, BuilderAttrs, BuilderBlock] | [string, BuilderBlock] | [string, BuilderAttrs];
type BuilderComment = [BUILDER_COMMENT, string];
type VerboseStatement = [BUILDER_LITERAL, string] | [BUILDER_COMMENT, string] | [BUILDER_APPEND, BuilderExpression, true] | [BUILDER_APPEND, BuilderExpression] | [BUILDER_MODIFIER, Params, Hash$2] | [BUILDER_DYNAMIC_COMPONENT, BuilderExpression, Hash$2, BuilderBlock];
type BuilderStatement = VerboseStatement | SugaryArrayStatement | TupleBuilderExpression | string;
/**
* The special value 'splat' is used to indicate that the attribute is a splat
*/
type BuilderAttr = BuilderExpression;
type TupleBuilderExpression = [BUILDER_LITERAL, string | boolean | null | undefined] | [BUILDER_GET, string] | [BUILDER_GET, string, string[]] | [BUILDER_CONCAT, ...BuilderExpression[]] | [BUILDER_HAS_BLOCK, string] | [BUILDER_HAS_BLOCK_PARAMS, string] | BuilderCallExpression;
type Params = BuilderParams;
type Hash$2 = Dict<BuilderExpression>;
interface NormalizedCallExpression {
type: CALL_EXPR;
head: NormalizedHead;
params: Nullable<NormalizedParams>;
hash: Nullable<NormalizedHash>;
}
interface NormalizedPath {
type: GET_PATH_EXPR;
path: Path;
}
interface NormalizedVar {
type: GET_VAR_EXPR;
variable: Variable;
}
type NormalizedHead = NormalizedPath | NormalizedVar;
interface NormalizedConcat {
type: CONCAT_EXPR;
params: [NormalizedExpression, ...NormalizedExpression[]];
}
type NormalizedExpression = {
type: LITERAL_EXPR;
value: null | undefined | boolean | string | number;
} | NormalizedCallExpression | NormalizedPath | NormalizedVar | NormalizedConcat | {
type: HAS_BLOCK_EXPR;
name: string;
} | {
type: HAS_BLOCK_PARAMS_EXPR;
name: string;
};
type BuilderExpression = TupleBuilderExpression | BuilderCallExpression | null | undefined | boolean | string | number;
type MiniBuilderBlock = BuilderStatement[];
type BuilderBlock = MiniBuilderBlock;
type BuilderCallExpression = [string] | [string, Params | Hash$2] | [string, Params, Hash$2];
interface Symbols {
top: ProgramSymbols;
freeVar(name: string): number;
arg(name: string): number;
block(name: string): number;
local(name: string): number;
this(): number;
hasLocal(name: string): boolean;
child(params: string[]): LocalSymbols;
}
declare class ProgramSymbols implements Symbols {
_freeVariables: string[];
_symbols: string[];
top: this;
toSymbols(): string[];
toUpvars(): string[];
freeVar(name: string): number;
block(name: string): number;
arg(name: string): number;
local(name: string): never;
this(): number;
hasLocal(_name: string): false;
symbol(name: string): number;
child(locals: string[]): LocalSymbols;
}
declare class LocalSymbols implements Symbols {
private parent;
private locals;
constructor(parent: Symbols, locals: string[]);
get paramSymbols(): number[];
get top(): ProgramSymbols;
freeVar(name: string): number;
arg(name: string): number;
block(name: string): number;
local(name: string): number;
this(): number;
hasLocal(name: string): boolean;
child(locals: string[]): LocalSymbols;
}
declare function buildStatements(statements: BuilderStatement[], symbols: Symbols): Statement$2[];
declare function buildStatement(normalized: NormalizedStatement, symbols?: Symbols): Statement$2[];
declare function s(arr: TemplateStringsArray, ...interpolated: unknown[]): [BUILDER_LITERAL, string];
declare function c(arr: TemplateStringsArray, ...interpolated: unknown[]): BuilderComment;
declare function unicode(charCode: string): string;
declare const NEWLINE = "\n";
/**
* @module
*
* This file contains types for the raw AST returned from the Handlebars parser.
* These types were originally imported from
* https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/handlebars/index.d.ts.
*/
interface CommonNode {
loc: SourceLocation$1;
}
interface SourceLocation$1 {
source: string;
start: Position;
end: Position;
}
interface Position {
line: number;
column: number;
}
interface Program extends CommonNode {
type: 'Program';
body: Statement$1[];
blockParams?: string[];
chained?: boolean;
}
type Statement$1 = MustacheStatement$1 | BlockStatement$1 | DecoratorBlock | PartialStatement | PartialBlockStatement | ContentStatement | CommentStatement$1;
interface CommonMustache extends CommonNode {
path: Expression$1;
params: Expression$1[];
hash: Hash$1;
escaped: boolean;
strip: StripFlags$1;
}
interface MustacheStatement$1 extends CommonMustache {
type: 'MustacheStatement';
}
interface CommonBlock extends CommonNode {
chained: boolean;
path: PathExpression$1 | SubExpression$1;
params: Expression$1[];
hash: Hash$1;
program: Program;
inverse?: Program;
openStrip?: StripFlags$1;
inverseStrip?: StripFlags$1;
closeStrip?: StripFlags$1;
}
interface BlockStatement$1 extends CommonBlock {
type: 'BlockStatement';
}
interface DecoratorBlock extends CommonBlock {
type: 'DecoratorBlock';
}
interface PartialStatement extends CommonNode {
type: 'PartialStatement';
name: PathExpression$1 | SubExpression$1;
params: Expression$1[];
hash: Hash$1;
indent: string;
strip: StripFlags$1;
}
interface PartialBlockStatement extends CommonNode {
type: 'PartialBlockStatement';
name: PathExpression$1 | SubExpression$1;
params: Expression$1[];
hash: Hash$1;
program: Program;
openStrip: StripFlags$1;
closeStrip: StripFlags$1;
}
interface ContentStatement extends CommonNode {
type: 'ContentStatement';
value: string;
original: StripFlags$1;
}
interface CommentStatement$1 extends CommonNode {
type: 'CommentStatement';
value: string;
strip: StripFlags$1;
}
type Expression$1 = SubExpression$1 | PathExpression$1 | Literal$1;
interface SubExpression$1 extends CommonNode {
type: 'SubExpression';
path: PathExpression$1 | SubExpression$1;
params: Expression$1[];
hash: Hash$1;
}
interface PathExpression$1 extends CommonNode {
type: 'PathExpression';
data: boolean;
depth: number;
parts: string[];
original: string;
}
type Literal$1 = StringLiteral$1 | BooleanLiteral$1 | NumberLiteral$1 | UndefinedLiteral$1 | NullLiteral$1;
interface StringLiteral$1 extends CommonNode {
type: 'StringLiteral';
value: string;
original: string;
}
interface BooleanLiteral$1 extends CommonNode {
type: 'BooleanLiteral';
value: boolean;
original: boolean;
}
interface NumberLiteral$1 extends CommonNode {
type: 'NumberLiteral';
value: number;
original: number;
}
interface UndefinedLiteral$1 extends CommonNode {
type: 'UndefinedLiteral';
}
interface NullLiteral$1 extends CommonNode {
type: 'NullLiteral';
}
interface Hash$1 extends CommonNode {
pairs: HashPair$1[];
}
interface HashPair$1 extends CommonNode {
key: string;
value: Expression$1;
}
interface StripFlags$1 {
open: boolean;
close: boolean;
}
declare const visitorKeys: {
readonly Template: readonly ["body"];
readonly Block: readonly ["body"];
readonly MustacheStatement: readonly ["path", "params", "hash"];
readonly BlockStatement: readonly ["path", "params", "hash", "program", "inverse"];
readonly ElementModifierStatement: readonly ["path", "params", "hash"];
readonly CommentStatement: readonly [];
readonly MustacheCommentStatement: readonly [];
readonly ElementNode: readonly ["attributes", "modifiers", "children", "comments"];
readonly AttrNode: readonly ["value"];
readonly TextNode: readonly [];
readonly ConcatStatement: readonly ["parts"];
readonly SubExpression: readonly ["path", "params", "hash"];
readonly PathExpression: readonly [];
readonly StringLiteral: readonly [];
readonly BooleanLiteral: readonly [];
readonly NumberLiteral: readonly [];
readonly NullLiteral: readonly [];
readonly UndefinedLiteral: readonly [];
readonly Hash: readonly ["pairs"];
readonly HashPair: readonly ["value"];
};
type VisitorKeysMap = typeof visitorKeys;
type VisitorKeys = {
[P in keyof VisitorKeysMap]: VisitorKeysMap[P][number];
};
type VisitorKey<N extends Node> = VisitorKeys[N['type']] & keyof N;
declare class WalkerPath<N extends Node> {
node: N;
parent: WalkerPath<Node> | null;
parentKey: string | null;
constructor(node: N, parent?: WalkerPath<Node> | null, parentKey?: string | null);
get parentNode(): Node | null;
parents(): Iterable<WalkerPath<Node> | null>;
}
interface FullNodeTraversal<N extends Node> {
enter?(node: N, path: WalkerPath<N>): void;
exit?(node: N, path: WalkerPath<N>): void;
keys?: KeysVisitor<N>;
}
type NodeHandler<N extends Node> = (node: N, path: WalkerPath<N>) => Node | Node[] | undefined | void;
type NodeTraversal<N extends Node> = FullNodeTraversal<N> | NodeHandler<N>;
type NodeVisitor = {
[P in keyof Nodes]?: NodeTraversal<Nodes[P]>;
} & {
All?: NodeTraversal<Node>;
/**
* @deprecated use Template or Block instead
*/
Program?: NodeTraversal<Template | Block>;
};
interface FullKeyTraversal<N extends Node, K extends string> {
enter?(node: N, key: K): void;
exit?(node: N, key: K): void;
}
type KeyHandler<N extends Node, K extends VisitorKey<N>> = (node: N, key: K) => void;
type KeyTraversal<N extends Node, K extends VisitorKey<N>> = FullKeyTraversal<N, K> | KeyHandler<N, K>;
type KeysVisitor<N extends Node> = {
[P in VisitorKey<N>]?: KeyTraversal<N, P>;
} & {
All?: KeyTraversal<N, VisitorKey<N>>;
/**
* @deprecated use Template or Block instead
*/
Program?: KeyTraversal<Template | Block, 'body'>;
};
declare function traverse(node: Node, visitor: NodeVisitor): void;
type NodeCallback<N extends Node> = (node: N, walker: Walker) => void;
declare class Walker {
order?: unknown | undefined;
stack: unknown[];
constructor(order?: unknown | undefined);
visit<N extends Node>(node: Nullable<N>, visitor: NodeCallback<N>): void;
children<N extends Node>(node: N & Node, callback: NodeCallback<N & Node>): void;
}
type BuilderHead = string | CallableExpression;
type TagDescriptor = string | PathExpression | {
path: PathExpression;
selfClosing?: boolean;
} | {
name: string;
selfClosing?: boolean;
};
declare function buildMustache(path: BuilderHead | Literal, params?: Expression[], hash?: Hash, trusting?: boolean, loc?: SourceLocation, strip?: StripFlags): MustacheStatement;
type PossiblyDeprecatedBlock = Block | Template;
declare function buildBlock(path: BuilderHead, params: Nullable<Expression[]>, hash: Nullable<Hash>, _defaultBlock: PossiblyDeprecatedBlock, _elseBlock?: Nullable<PossiblyDeprecatedBlock>, loc?: SourceLocation, openStrip?: StripFlags, inverseStrip?: StripFlags, closeStrip?: StripFlags): BlockStatement;
declare function buildElementModifier(path: BuilderHead, params?: Expression[], hash?: Hash, loc?: Nullable<SourceLocation>): ElementModifierStatement;
declare function buildComment(value: string, loc?: SourceLocation): CommentStatement;
declare function buildMustacheComment(value: string, loc?: SourceLocation): MustacheCommentStatement;
declare function buildConcat(parts: (TextNode | MustacheStatement)[], loc?: SourceLocation): ConcatStatement;
interface BuildElementOptions {
attrs?: AttrNode[];
modifiers?: ElementModifierStatement[];
children?: Statement[];
comments?: MustacheCommentStatement[];
blockParams?: VarHead[] | string[];
openTag?: SourceLocation;
closeTag?: Maybe<SourceLocation>;
loc?: SourceLocation;
}
declare function buildElement(tag: TagDescriptor, options?: BuildElementOptions): ElementNode;
declare function buildAttr(name: string, value: AttrValue, loc?: SourceLocation): AttrNode;
declare function buildText(chars?: string, loc?: SourceLocation): TextNode;
declare function buildSexpr(path: BuilderHead, params?: Expression[], hash?: Hash, loc?: SourceLocation): SubExpression;
declare function buildThis(loc?: SourceLocation): ThisHead;
declare function buildAtName(name: string, loc?: SourceLocation): AtHead;
declare function buildVar(name: string, loc?: SourceLocation): VarHead;
declare function buildHeadFromString(original: string, loc?: SourceLocation): PathHead;
declare function buildCleanPath(head: PathHead, tail?: string[], loc?: SourceLocation): PathExpression;
declare function buildPath(path: PathExpression | string | {
head: string;
tail: string[];
}, loc?: SourceLocation): PathExpression;
declare function buildPath(path: BuilderHead, loc?: SourceLocation): CallableExpression;
declare function buildPath(path: BuilderHead | Literal | Expression, loc?: SourceLocation): Expression;
declare function buildLiteral<T extends Literal>(type: T['type'], value: T['value'], loc?: SourceLocation): T;
declare function buildHash(pairs?: HashPair[], loc?: SourceLocation): Hash;
declare function buildPair(key: string, value: Expression, loc?: SourceLocation): HashPair;
declare function buildProgram(body?: Statement[], blockParams?: string[], loc?: SourceLocation): Template | Block;
declare function buildBlockItself(body?: Statement[], params?: Array<VarHead | string>, chained?: boolean, loc?: SourceLocation): Block;
declare function buildTemplate(body?: Statement[], blockParams?: string[], loc?: SourceLocation): Template;
declare function buildPosition(line: number, column: number): SourcePosition;
declare function buildLoc(loc: Nullable<SourceLocation>): SourceSpan;
declare function buildLoc(startLine: number, startColumn: number, endLine?: number, endColumn?: number, source?: string): SourceSpan;
declare const _default: {
mustache: typeof buildMustache;
block: typeof buildBlock;
comment: typeof buildComment;
mustacheComment: typeof buildMustacheComment;
element: typeof buildElement;
elementModifier: typeof buildElementModifier;
attr: typeof buildAttr;
text: typeof buildText;
sexpr: typeof buildSexpr;
concat: typeof buildConcat;
hash: typeof buildHash;
pair: typeof buildPair;
literal: typeof buildLiteral;
program: typeof buildProgram;
blockItself: typeof buildBlockItself;
template: typeof buildTemplate;
loc: typeof buildLoc;
pos: typeof buildPosition;
path: typeof buildPath;
fullPath: typeof buildCleanPath;
head: typeof buildHeadFromString;
at: typeof buildAtName;
var: typeof buildVar;
this: typeof buildThis;
string: (value: string) => StringLiteral;
boolean: (value: boolean) => BooleanLiteral;
number: (value: number) => NumberLiteral;
undefined(): UndefinedLiteral;
null(): NullLiteral;
};
/**
ASTPlugins can make changes to the Glimmer template AST before
compilation begins.
*/
interface ASTPluginBuilder<TEnv extends ASTPluginEnvironment = ASTPluginEnvironment> {
(env: TEnv): ASTPlugin;
}
interface ASTPlugin {
name: string;
visitor: NodeVisitor;
}
interface ASTPluginEnvironment {
meta?: object | undefined;
syntax: Syntax;
}
interface HandlebarsParseOptions {
srcName?: string;
ignoreStandalone?: boolean;
}
interface TemplateIdFn {
(src: string): Nullable<string>;
}
interface PrecompileOptions extends PreprocessOptions {
id?: TemplateIdFn;
/**
* Additional non-native keywords.
*
* Local variables (block params or lexical scope) always takes precedence,
* but otherwise, suitable free variable candidates (e.g. those are not part
* of a path) are matched against this list and turned into keywords.
*
* In strict mode compilation, keywords suppresses the undefined reference
* error and will be resolved by the runtime environment.
*
* In loose mode, keywords are currently ignored and since all free variables
* are already resolved by the runtime environment.
*/
keywords?: readonly string[];
/**
* In loose mode, this hook allows embedding environments to customize the name of an
* angle-bracket component. In practice, this means that `<HelloWorld />` in Ember is
* compiled by Glimmer as an invocation of a component named `hello-world`.
*
* It's a little weird that this is needed in addition to the resolver, but it's a
* classic-only feature and it seems fine to leave it alone for classic consumers.
*/
customizeComponentName?: ((input: string) => string) | undefined;
}
interface PrecompileOptionsWithLexicalScope extends PrecompileOptions {
lexicalScope: (variable: string) => boolean;
/**
* If `emit.debugSymbols` is set to `true`, the name of lexical local variables
* will be included in the wire format.
*/
emit?: {
debugSymbols?: boolean;
} | undefined;
}
interface PreprocessOptions {
strictMode?: boolean | undefined;
locals?: string[] | undefined;
meta?: {
moduleName?: string | undefined;
} | undefined;
plugins?: {
ast?: ASTPluginBuilder[] | undefined;
} | undefined;
parseOptions?: HandlebarsParseOptions | undefined;
customizeComponentName?: ((input: string) => string) | undefined;
/**
Useful for specifying a group of options together.
When `'codemod'` we disable all whitespace control in handlebars
(to preserve as much as possible) and we also avoid any
escaping/unescaping of HTML entity codes.
*/
mode?: 'codemod' | 'precompile' | undefined;
}
interface Syntax {
parse: typeof preprocess;
builders: typeof _default;
print: typeof build;
traverse: typeof traverse;
Walker: typeof Walker;
}
declare function preprocess(input: string | Source | Program, options?: PreprocessOptions): Template;
declare class Source {
readonly source: string;
readonly module: string;
static from(source: string, options?: PrecompileOptions): Source;
constructor(source: string, module?: string);
/**
* Validate that the character offset represents a position in the source string.
*/
validate(offset: number): boolean;
slice(start: number, end: number): string;
offsetFor(line: number, column: number): SourceOffset;
spanFor({ start, end }: Readonly<SourceLocation>): SourceSpan;
hbsPosFor(offset: number): Nullable<SourcePosition>;
charPosFor(position: SourcePosition): number | null;
}
/**
* We have already computed the character position of this offset or span.
*/
type CharOffsetKind = 'CharPosition';
/**
* This offset or span was instantiated with a Handlebars SourcePosition or SourceLocation. Its
* character position will be computed on demand.
*/
type HbsPositionKind = 'HbsPosition';
/**
* for (rare) situations where a node is created but there was no source location (e.g. the name
* "default" in default blocks when the word "default" never appeared in source). This is used
* by the internals when there is a legitimate reason for the internals to synthesize a node
* with no location.
*/
type InternalSyntheticKind = 'InternalsSynthetic';
/**
* For situations where a node represents zero parts of the source (for example, empty arguments).
* In general, we attempt to assign these nodes *some* position (empty arguments can be
* positioned immediately after the callee), but it's not always possible
*/
type NonExistentKind = 'NonExistent';
/**
* For situations where a source location was expected, but it didn't correspond to the node in
* the source. This happens if a plugin creates broken locations.
*/
type BrokenKind = 'Broken';
type OffsetKind = CharOffsetKind | HbsPositionKind | InvisibleKind;
/**
* These kinds describe spans that don't have a concrete location in the original source.
*/
type InvisibleKind = BrokenKind | InternalSyntheticKind | NonExistentKind;
type SerializedSourceSlice<Chars extends string = string> = [
chars: Chars,
span: SerializedSourceSpan
];
declare class SourceSlice<Chars extends string = string> {
static synthetic<S extends string>(chars: S): SourceSlice<S>;
static load(source: Source, slice: SerializedSourceSlice): SourceSlice;
readonly chars: Chars;
readonly loc: SourceSpan;
constructor(options: {
loc: SourceSpan;
chars: Chars;
});
getString(): string;
serialize(): SerializedSourceSlice<Chars>;
}
/**
* All spans have these details in common.
*/
interface SpanData {
readonly kind: OffsetKind;
/**
* Convert this span into a string. If the span is broken, return `''`.
*/
asString(): string;
/**
* Gets the module the span was located in.
*/
getModule(): string;
/**
* Get the starting position for this span. Try to avoid creating new position objects, as they
* cache computations.
*/
getStart(): AnyPosition;
/**
* Get the ending position for this span. Try to avoid creating new position objects, as they
* cache computations.
*/
getEnd(): AnyPosition;
/**
* Compute the `SourceLocation` for this span, returned as an instance of `HbsSpan`.
*/
toHbsSpan(): HbsSpan | null;
/**
* For compatibility, whenever the `start` or `end` of a {@see SourceOffset} changes, spans are
* notified of the change so they can update themselves. This shouldn't happen outside of AST
* plugins.
*/
locDidUpdate(changes: {
start?: SourcePosition;
end?: SourcePosition;
}): void;
/**
* Serialize into a {@see SerializedSourceSpan}, which is compact and designed for readability in
* context like AST Explorer. If you need a {@see SourceLocation}, use {@see toJSON}.
*/
serialize(): SerializedSourceSpan;
}
/**
* A `SourceSpan` object represents a span of characters inside of a template source.
*
* There are three kinds of `SourceSpan` objects:
*
* - `ConcreteSourceSpan`, which contains byte offsets
* - `LazySourceSpan`, which contains `SourceLocation`s from the Handlebars AST, which can be
* converted to byte offsets on demand.
* - `InvisibleSourceSpan`, which represent source strings that aren't present in the source,
* because:
* - they were created synthetically
* - their location is nonsensical (the span is broken)
* - they represent nothing in the source (this currently happens only when a bug in the
* upstream Handlebars parser fails to assign a location to empty blocks)
*
* At a high level, all `SourceSpan` objects provide:
*
* - byte offsets
* - source in column and line format
*
* And you can do these operations on `SourceSpan`s:
*
* - collapse it to a `SourceSpan` representing its starting or ending position
* - slice out some characters, optionally skipping some characters at the beginning or end
* - create a new `SourceSpan` with a different starting or ending offset
*
* All SourceSpan objects implement `SourceLocation`, for compatibility. All SourceSpan
* objects have a `toJSON` that emits `SourceLocation`, also for compatibility.
*
* For compatibility, subclasses of `AbstractSourceSpan` must implement `locDidUpdate`, which
* happens when an AST plugin attempts to modify the `start` or `end` of a span directly.
*
* The goal is to avoid creating any problems for use-cases like AST Explorer.
*/
declare class SourceSpan implements SourceLocation {
private data;
static get NON_EXISTENT(): SourceSpan;
static load(source: Source, serialized: SerializedSourceSpan): SourceSpan;
static forHbsLoc(source: Source, loc: SourceLocation): SourceSpan;
static forCharPositions(source: Source, startPos: number, endPos: number): SourceSpan;
static synthetic(chars: string): SourceSpan;
static broken(pos?: SourceLocation): SourceSpan;
readonly isInvisible: boolean;
constructor(data: SpanData & AnySpan);
getStart(): SourceOffset;
getEnd(): SourceOffset;
get loc(): SourceLocation;
get module(): string;
/**
* Get the starting `SourcePosition` for this `SourceSpan`, lazily computing it if needed.
*/
get startPosition(): SourcePosition;
/**
* Get the ending `SourcePosition` for this `SourceSpan`, lazily computing it if needed.
*/
get endPosition(): SourcePosition;
/**
* Support converting ASTv1 nodes into a serialized format using JSON.stringify.
*/
toJSON(): SourceLocation;
/**
* Create a new span with the current span's end and a new beginning.
*/
withStart(other: SourceOffset): SourceSpan;
/**
* Create a new span with the current span's beginning and a new ending.
*/
withEnd(other: SourceOffset): SourceSpan;
asString(): string;
/**
* Convert this `SourceSpan` into a `SourceSlice`. In debug mode, this method optionally checks
* that the byte offsets represented by this `SourceSpan` actually correspond to the expected
* string.
*/
toSlice(expected?: string): SourceSlice;
/**
* For compatibility with SourceLocation in AST plugins
*
* @deprecated use startPosition instead
*/
get start(): SourcePosition;
/**
* For compatibility with SourceLocation in AST plugins
*
* @deprecated use withStart instead
*/
set start(position: SourcePosition);
/**
* For compatibility with SourceLocation in AST plugins
*
* @deprecated use endPosition instead
*/
get end(): SourcePosition;
/**
* For compatibility with SourceLocation in AST plugins
*
* @deprecated use withEnd instead
*/
set end(position: SourcePosition);
/**
* For compatibility with SourceLocation in AST plugins
*
* @deprecated use module instead
*/
get source(): string;
collapse(where: 'start' | 'end'): SourceSpan;
extend(other: SourceSpan): SourceSpan;
serialize(): SerializedSourceSpan;
slice({ skipStart, skipEnd }: {
skipStart?: number;
skipEnd?: number;
}): SourceSpan;
sliceStartChars({ skipStart, chars }: {
skipStart?: number;
chars: number;
}): SourceSpan;
sliceEndChars({ skipEnd, chars }: {
skipEnd?: number;
chars: number;
}): SourceSpan;
}
type AnySpan = HbsSpan | CharPositionSpan | InvisibleSpan;
declare class CharPositionSpan implements SpanData {
#private;
readonly source: Source;
readonly charPositions: {
start: CharPosition;
end: CharPosition;
};
readonly kind: "CharPosition";
constructor(source: Source, charPositions: {
start: CharPosition;
end: CharPosition;
});
wrap(): SourceSpan;
asString(): string;
getModule(): string;
getStart(): AnyPosition;
getEnd(): AnyPosition;
locDidUpdate(): void;
toHbsSpan(): HbsSpan | null;
serialize(): SerializedSourceSpan;
toCharPosSpan(): this;
}
declare class HbsSpan implements SpanData {
#private;
readonly source: Source;
readonly hbsPositions: {
start: HbsPosition;
end: HbsPosition;
};
readonly kind: "HbsPosition";
constructor(source: Source, hbsPositions: {
start: HbsPosition;
end: HbsPosition;
}, providedHbsLoc?: SourceLocation | null);
serialize(): SerializedConcreteSourceSpan;
wrap(): SourceSpan;
private updateProvided;
locDidUpdate({ start, end }: {
start?: SourcePosition;
end?: SourcePosition;
}): void;
asString(): string;
getModule(): string;
getStart(): AnyPosition;
getEnd(): AnyPosition;
toHbsLoc(): SourceLocation;
toHbsSpan(): this;
toCharPosSpan(): CharPositionSpan | null;
}
declare class InvisibleSpan implements SpanData {
readonly kind: InvisibleKind;
readonly loc: SourceLocation;
readonly string: string | null;
constructor(kind: InvisibleKind, loc: SourceLocation, string?: string | null);
serialize(): SerializedConcreteSourceSpan;
wrap(): SourceSpan;
asString(): string;
locDidUpdate({ start, end }: {
start?: SourcePosition;
end?: SourcePosition;
}): void;
getModule(): string;
getStart(): AnyPosition;
getEnd(): AnyPosition;
toCharPosSpan(): this;
toHbsSpan(): null;
toHbsLoc(): SourceLocation;
}
type SerializedConcreteSourceSpan = /** collapsed */ number | /** normal */ [start: number, size: number] | /** synthetic */ string;
type SerializedSourceSpan = SerializedConcreteSourceSpan;
interface SourceLocation {
start: SourcePosition;
end: SourcePosition;
}
interface SourcePosition {
/** >= 1 */
line: number;
/** >= 0 */
column: number;
}
/**
* All positions have these details in common. Most notably, all three kinds of positions can
* must be able to attempt to convert themselves into {@see CharPosition}.
*/
interface PositionData {
readonly kind: OffsetKind;
toCharPos(): CharPosition | null;
toJSON(): SourcePosition;
}
/**
* Used to indicate that an attempt to convert a `SourcePosition` to a character offset failed. It
* is separate from `null` so that `null` can be used to indicate that the computation wasn't yet
* attempted (and therefore to cache the failure)
*/
declare const BROKEN = "BROKEN";
type BROKEN = 'BROKEN';
type AnyPosition = HbsPosition | CharPosition | InvisiblePosition;
/**
* A `SourceOffset` represents a single position in the source.
*
* There are three kinds of backing data for `SourceOffset` objects:
*
* - `CharPosition`, which contains a character offset into the raw source string
* - `HbsPosition`, which contains a `SourcePosition` from the Handlebars AST, which can be
* converted to a `CharPosition` on demand.
* - `InvisiblePosition`, which represents a position not in source (@see {InvisiblePosition})
*/
declare class SourceOffset {
readonly data: PositionData & AnyPosition;
/**
* Create a `SourceOffset` from a Handlebars `SourcePosition`. It's stored as-is, and converted
* into a character offset on demand, which avoids unnecessarily computing the offset of every
* `SourceLocation`, but also means that broken `SourcePosition`s are not always detected.
*/
static forHbsPos(source: Source, pos: SourcePosition): SourceOffset;
/**
* Create a `SourceOffset` that corresponds to a broken `SourcePosition`. This means that the
* calling code determined (or knows) that the `SourceLocation` doesn't correspond correctly to
* any part of the source.
*/
static broken(pos?: SourcePosition): SourceOffset;
constructor(data: PositionData & AnyPosition);
/**
* Get the character offset for this `SourceOffset`, if possible.
*/
get offset(): number | null;
/**
* Compare this offset with another one.
*
* If both offsets are `HbsPosition`s, they're equivalent as long as their lines and columns are
* the same. This avoids computing offsets unnecessarily.
*
* Otherwise, two `SourceOffset`s are equivalent if their successfully computed character offsets
* are the same.
*/
eql(right: SourceOffset): boolean;
/**
* Create a span that starts from this source offset and ends with another source offset. Avoid
* computing character offsets if both `SourceOffset`s are still lazy.
*/
until(other: SourceOffset): SourceSpan;
/**
* Create a `SourceOffset` by moving the character position represented by this source offset
* forward or backward (if `by` is negative), if possible.
*
* If this `SourceOffset` can't compute a valid character offset, `move` returns a broken offset.
*
* If the resulting character offset is less than 0 or greater than the size of the source, `move`
* returns a broken offset.
*/
move(by: number): SourceOffset;
/**
* Create a new `SourceSpan` that represents a collapsed range at this source offset. Avoid
* computing the character offset if it has not already been computed.
*/
collapsed(): SourceSpan;
/**
* Convert this `SourceOffset` into a Handlebars {@see SourcePosition} for compatibility with
* existing plugins.
*/
toJSON(): SourcePosition;
}
declare class CharPosition implements PositionData {
readonly source: Source;
readonly charPos: number;
readonly kind: "CharPosition";
/** Computed from char offset */
_locPos: HbsPosition | BROKEN | null;
constructor(source: Source, charPos: number);
/**
* This is already a `CharPosition`.
*
* {@see HbsPosition} for the alternative.
*/
toCharPos(): this;
/**
* Produce a Handlebars {@see SourcePosition} for this `CharPosition`. If this `CharPosition` was
* computed using {@see SourceOffset#move}, this will compute the `SourcePosition` for the offset.
*/
toJSON(): SourcePosition;
wrap(): SourceOffset;
/**
* A `CharPosition` always has an offset it can produce without any additional computation.
*/
get offset(): number;
/**
* Convert the current character offset to an `HbsPosition`, if it was not already computed. Once
* a `CharPosition` has computed its `HbsPosition`, it will not need to do compute it again, and
* the same `CharPosition` is retained when used as one of the ends of a `SourceSpan`, so
* computing the `HbsPosition` should be a one-time operation.
*/
toHbsPos(): HbsPosition | null;
}
declare class HbsPosition implements PositionData {
readonly source: Source;
readonly hbsPos: SourcePosition;
readonly kind: "HbsPosition";
_charPos: CharPosition | BROKEN | null;
constructor(source: Source, hbsPos: SourcePosition, charPos?: number | null);
/**
* Lazily compute the character offset from the {@see SourcePosition}. Once an `HbsPosition` has
* computed its `CharPosition`, it will not need to do compute it again, and the same
* `HbsPosition` is retained when used as one of the ends of a `SourceSpan`, so computing the
* `CharPosition` should be a one-time operation.
*/
toCharPos(): CharPosition | null;
/**
* Return the {@see SourcePosition} that this `HbsPosition` was instantiated with. This operation
* does not need to compute anything.
*/
toJSON(): SourcePosition;
wrap(): SourceOffset;
/**
* This is already an `HbsPosition`.
*
* {@see CharPosition} for the alternative.
*/
toHbsPos(): this;
}
declare class InvisiblePosition implements PositionData {
readonly kind: BrokenKind | InternalSyntheticKind | NonExistentKind;
readonly pos: SourcePosition;
constructor(kind: BrokenKind | InternalSyntheticKind | NonExistentKind, pos: SourcePosition);
/**
* A broken position cannot be turned into a {@see CharacterPosition}.
*/
toCharPos(): null;
/**
* The serialization of an `InvisiblePosition is whatever Handlebars {@see SourcePosition} was
* originally identified as broken, non-existent or synthetic.
*
* If an `InvisiblePosition` never had an source offset at all, this method returns
* {@see UNKNOWN_POSITION} for compatibility.
*/
toJSON(): SourcePosition;
wrap(): SourceOffset;
get offset(): null;
}
interface BaseNode {
type: NodeType;
loc: SourceSpan;
}
interface CommonProgram extends BaseNode {
body: Statement[];
}
interface Block extends CommonProgram {
type: 'Block';
params: VarHead[];
chained?: boolean;
/**
* string accessor for params.name
*/
blockParams: string[];
}
type EntityEncodingState = 'transformed' | 'raw';
interface Template extends CommonProgram {
type: 'Template';
blockParams: string[];
}
type CallableExpression = SubExpression | PathExpression;
interface MustacheStatement extends BaseNode {
type: 'MustacheStatement';
path: Expression;
params: Expression[];
hash: Hash;
trusting: boolean;
strip: StripFlags;
/**
* @deprecated use trusting instead
*/
escaped: boolean;
}
interface BlockStatement extends BaseNode {
type: 'BlockStatement';
path: CallableExpression;
params: Expression[];
hash: Hash;
program: Block;
inverse?: Nullable<Block>;
openStrip: StripFlags;
inverseStrip: StripFlags;
closeStrip: StripFlags;
chained?: boolean;
}
interface ElementModifierStatement extends BaseNode {
type: 'ElementModifierStatement';
path: CallableExpression;
params: Expression[];
hash: Hash;
}
interface CommentStatement extends BaseNode {
type: 'CommentStatement';
value: string;
}
interface MustacheCommentStatement extends BaseNode {
type: 'MustacheCommentStatement';
value: string;
}
interface ElementNode extends BaseNode {
type: 'ElementNode';
path: PathExpression;
selfClosing: boolean;
attributes: AttrNode[];
params: VarHead[];
modifiers: ElementModifierStatement[];
comments: MustacheCommentStatement[];
children: Statement[];
/**
* span for the open tag
*/
openTag: SourceSpan;
/**
* span for the close tag, null for void or self-closing tags
*/
closeTag: Nullable<SourceSpan>;
/**
* string accessor for path.original
*/
tag: string;
/**
* string accessor for params.name
*/
blockParams: string[];
}
type StatementName = 'MustacheStatement' | 'CommentStatement' | 'BlockStatement' | 'MustacheCommentStatement' | 'TextNode' | 'ElementNode';
interface AttrNode extends BaseNode {
type: 'AttrNode';
name: string;
value: AttrValue;
}
type AttrValue = TextNode | MustacheStatement | ConcatStatement;
interface TextNode extends BaseNode {
type: 'TextNode';
chars: string;
}
interface ConcatStatement extends BaseNode {
type: 'ConcatStatement';
parts: PresentArray<TextNode | MustacheStatement>;
}
type ExpressionName = 'SubExpression' | 'PathExpression' | LiteralName;
interface SubExpression extends BaseNode {
type: 'SubExpression';
path: CallableExpression;
params: Expression[];
hash: Hash;
}
interface ThisHead {
type: 'ThisHead';
original: 'this';
loc: SourceSpan;
}
interface AtHead {
type: 'AtHead';
name: string;
loc: SourceSpan;
/**
* alias for name
*/
original: string;
}
interface VarHead {
type: 'VarHead';
name: string;
loc: SourceSpan;
/**
* alias for name
*/
original: string;
}
type PathHead = ThisHead | AtHead | VarHead;
interface MinimalPathExpression extends BaseNode {
type: 'PathExpression';
head: PathHead;
tail: string[];
}
interface PathExpression extends MinimalPathExpression {
type: 'PathExpression';
original: string;
head: PathHead;
tail: string[];
/**
* @deprecated use `head` and `tail` instead
*/
parts: readonly string[];
/**
* @deprecated use `head.type` instead
*/
readonly this: boolean;
/**
* @deprecated use `head.type' instead
*/
readonly data: boolean;
}
type LiteralName = 'StringLiteral' | 'BooleanLiteral' | 'NumberLiteral' | 'UndefinedLiteral' | 'NullLiteral';
interface StringLiteral extends BaseNode {
type: 'StringLiteral';
value: string;
/**
* @deprecated use value instead
*/
original: string;
}
interface BooleanLiteral extends BaseNode {
type: 'BooleanLiteral';
value: boolean;
/**
* @deprecated use value instead
*/
original: boolean;
}
interface NumberLiteral extends BaseNode {
type: 'NumberLiteral';
value: number;
/**
* @deprecated use value instead
*/
original: number;
}
interface UndefinedLiteral extends BaseNode {
type: 'UndefinedLiteral';
value: undefined;
/**
* @deprecated use value instead
*/
original: undefined;
}
interface NullLiteral extends BaseNode {
type: 'NullLiteral';
value: null;
/**
* @deprecated use value instead
*/
original: null;
}
interface Hash extends BaseNode {
type: 'Hash';
pairs: HashPair[];
}
interface HashPair extends BaseNode {
type: 'HashPair';
key: string;
value: Expression;
}
interface StripFlags {
open: boolean;
close: boolean;
}
type Nodes = {
Template: Template;
Block: Block;
MustacheStatement: MustacheStatement;
BlockStatement: BlockStatement;
ElementModifierStatement: ElementModifierStatement;
CommentStatement: CommentStatement;
MustacheCommentStatement: MustacheCommentStatement;
ElementNode: ElementNode;
AttrNode: AttrNode;
TextNode: TextNode;
ConcatStatement: ConcatStatement;
SubExpression: SubExpression;
PathExpression: PathExpression;
StringLiteral: StringLiteral;
BooleanLiteral: BooleanLiteral;
NumberLiteral: NumberLiteral;
NullLiteral: NullLiteral;
UndefinedLiteral: UndefinedLiteral;
Hash: Hash;
HashPair: HashPair;
};
type NodeType = keyof Nodes;
type Node = Nodes[NodeType];
type Statement = Nodes[StatementName];
type Literal = Nodes[LiteralName];
type Expression = Nodes[ExpressionName];
interface PrinterOptions {
entityEncoding: EntityEncodingState;
/**
* Used to override the mechanism of printing a given AST.Node.
*
* This will generally only be useful to source -> source codemods
* where you would like to specialize/override the way a given node is
* printed (e.g. you would like to preserve as much of the original
* formatting as possible).
*
* When the provided override returns undefined, the default built in printing
* will be done for the AST.Node.
*
* @param ast the ast node to be printed
* @param options the options specified during the print() invocation
*/
override?(ast: Node, options: PrinterOptions): void | string;
}
declare function build(ast: Node, options?: PrinterOptions): string;
declare const defaultId: TemplateIdFn;
declare function precompileJSON(string: Nullable<string>, options?: PrecompileOptions | PrecompileOptionsWithLexicalScope): [block: SerializedTemplateBlock, usedLocals: string[]];
declare function precompile(source: string, options?: PrecompileOptions | PrecompileOptionsWithLexicalScope): TemplateJavascript;
declare class WireFormatDebugger {
private upvars;
private symbols;
constructor([_statements, symbols, upvars]: SerializedTemplateBlock);
format(program: SerializedTemplateBlock): unknown;
formatOpcode(opcode: Syntax$1): unknown;
private formatCurryType;
private formatElementParams;
private formatParams;
private formatHash;
private formatBlocks;
private formatBlock;
}
export { type BuilderStatement, NEWLINE, type PrecompileOptions, ProgramSymbols, WireFormatDebugger, buildStatement, buildStatements, c, defaultId, precompile, precompileJSON, s, unicode };
+6
-6
{
"name": "@glimmer/compiler",
"version": "0.94.4",
"version": "0.94.5",
"license": "MIT",

@@ -36,6 +36,6 @@ "repository": {

"dependencies": {
"@glimmer/interfaces": "0.94.2",
"@glimmer/syntax": "0.94.3",
"@glimmer/wire-format": "0.94.3",
"@glimmer/util": "0.94.3"
"@glimmer/interfaces": "0.94.3",
"@glimmer/util": "0.94.4",
"@glimmer/wire-format": "0.94.4",
"@glimmer/syntax": "0.94.4"
},

@@ -48,2 +48,3 @@ "devDependencies": {

"typescript": "*",
"@glimmer-workspace/env": "0.92.0",
"@glimmer-workspace/build-support": "0.92.0",

@@ -53,3 +54,2 @@ "@glimmer/constants": "0.92.0",

"@glimmer/debug-util": "0.92.0",
"@glimmer-workspace/env": "0.92.0",
"@glimmer/local-debug-flags": "0.92.0"

@@ -56,0 +56,0 @@ },

import type { VariableKind } from '@glimmer/constants';
import type { Dict, Nullable, PresentArray } from '@glimmer/interfaces';
import { APPEND_EXPR_HEAD, APPEND_PATH_HEAD, BLOCK_HEAD, BUILDER_APPEND, BUILDER_COMMENT, BUILDER_CONCAT, BUILDER_DYNAMIC_COMPONENT, BUILDER_GET, BUILDER_HAS_BLOCK, BUILDER_HAS_BLOCK_PARAMS, BUILDER_LITERAL, BUILDER_MODIFIER, CALL_EXPR, CALL_HEAD, COMMENT_HEAD, CONCAT_EXPR, DYNAMIC_COMPONENT_HEAD, ELEMENT_HEAD, GET_PATH_EXPR, GET_VAR_EXPR, HAS_BLOCK_EXPR, HAS_BLOCK_PARAMS_EXPR, KEYWORD_HEAD, LITERAL_EXPR, LITERAL_HEAD, MODIFIER_HEAD, SPLAT_HEAD } from '@glimmer/constants';
export type BuilderParams = BuilderExpression[];
export type BuilderHash = Nullable<Dict<BuilderExpression>>;
export type BuilderBlockHash = BuilderHash | {
as: string | string[];
};
export type BuilderBlocks = Dict<BuilderBlock>;
export type BuilderAttrs = Dict<BuilderAttr>;
export type NormalizedParams = NormalizedExpression[];
export type NormalizedHash = Dict<NormalizedExpression>;
export type NormalizedBlock = NormalizedStatement[];
export type NormalizedBlocks = Dict<NormalizedBlock>;
export type NormalizedAttrs = Dict<NormalizedAttr>;
export type NormalizedAttr = SPLAT_HEAD | NormalizedExpression;
export interface NormalizedElement {
name: string;
attrs: Nullable<NormalizedAttrs>;
block: Nullable<NormalizedBlock>;
}
export interface NormalizedAngleInvocation {
head: NormalizedExpression;
attrs: Nullable<NormalizedAttrs>;
block: Nullable<NormalizedBlock>;
}
export interface Variable {
kind: VariableKind;
name: string;
/**
* Differences:
*
* - strict mode variables always refer to in-scope variables
* - loose mode variables use this algorithm:
* 1. otherwise, fall back to `this.<name>`
*/
mode: 'loose' | 'strict';
}
export interface Path {
head: Variable;
tail: PresentArray<string>;
}
export interface AppendExpr {
kind: APPEND_EXPR_HEAD;
expr: NormalizedExpression;
trusted: boolean;
}
export interface AppendPath {
kind: APPEND_PATH_HEAD;
path: NormalizedPath;
trusted: boolean;
}
export interface NormalizedKeywordStatement {
kind: KEYWORD_HEAD;
name: string;
params: Nullable<NormalizedParams>;
hash: Nullable<NormalizedHash>;
blockParams: Nullable<string[]>;
blocks: NormalizedBlocks;
}
export type NormalizedStatement = {
kind: CALL_HEAD;
head: NormalizedHead;
params: Nullable<NormalizedParams>;
hash: Nullable<NormalizedHash>;
trusted: boolean;
} | {
kind: BLOCK_HEAD;
head: NormalizedHead;
params: Nullable<NormalizedParams>;
hash: Nullable<NormalizedHash>;
blockParams: Nullable<string[]>;
blocks: NormalizedBlocks;
} | NormalizedKeywordStatement | {
kind: ELEMENT_HEAD;
name: string;
attrs: NormalizedAttrs;
block: NormalizedBlock;
} | {
kind: COMMENT_HEAD;
value: string;
} | {
kind: LITERAL_HEAD;
value: string;
} | AppendPath | AppendExpr | {
kind: MODIFIER_HEAD;
params: NormalizedParams;
hash: Nullable<NormalizedHash>;
} | {
kind: DYNAMIC_COMPONENT_HEAD;
expr: NormalizedExpression;
hash: Nullable<NormalizedHash>;
block: NormalizedBlock;
};
export declare function normalizeStatement(statement: BuilderStatement): NormalizedStatement;
export declare function normalizeAppendHead(head: NormalizedHead, trusted: boolean): AppendExpr | AppendPath;
export type SugaryArrayStatement = BuilderCallExpression | BuilderElement | BuilderBlockStatement;
export declare function normalizeSugaryArrayStatement(statement: SugaryArrayStatement): NormalizedStatement;
export declare function normalizePathHead(whole: string): Variable;
export type BuilderBlockStatement = [string, BuilderBlock | BuilderBlocks] | [string, BuilderParams | BuilderBlockHash, BuilderBlock | BuilderBlocks] | [string, BuilderParams, BuilderBlockHash, BuilderBlock | BuilderBlocks];
export interface NormalizedBuilderBlockStatement {
head: NormalizedHead;
params: Nullable<NormalizedParams>;
hash: Nullable<NormalizedHash>;
blockParams: Nullable<string[]>;
blocks: NormalizedBlocks;
}
export declare function normalizeBuilderBlockStatement(statement: BuilderBlockStatement): NormalizedBuilderBlockStatement;
type Entry<T> = {
[K in keyof T]: [K, T[K]];
}[keyof T];
export declare function entries<D extends Dict>(dict: D, callback: (...entry: Entry<D>) => void): void;
export type BuilderElement = [string] | [string, BuilderAttrs, BuilderBlock] | [string, BuilderBlock] | [string, BuilderAttrs];
export type BuilderComment = [BUILDER_COMMENT, string];
export type InvocationElement = [string] | [string, BuilderAttrs, BuilderBlock] | [string, BuilderBlock] | [string, BuilderAttrs];
export declare function isElement(input: [string, ...unknown[]]): input is BuilderElement;
export declare function extractElement(input: string): Nullable<string>;
export declare function isAngleInvocation(input: [string, ...unknown[]]): input is InvocationElement;
export declare function isBlock(input: [string, ...unknown[]]): input is BuilderBlockStatement;
export type VerboseStatement = [BUILDER_LITERAL, string] | [BUILDER_COMMENT, string] | [BUILDER_APPEND, BuilderExpression, true] | [BUILDER_APPEND, BuilderExpression] | [BUILDER_MODIFIER, Params, Hash] | [BUILDER_DYNAMIC_COMPONENT, BuilderExpression, Hash, BuilderBlock];
export type BuilderStatement = VerboseStatement | SugaryArrayStatement | TupleBuilderExpression | string;
/**
* The special value 'splat' is used to indicate that the attribute is a splat
*/
export type BuilderAttr = BuilderExpression;
export type TupleBuilderExpression = [BUILDER_LITERAL, string | boolean | null | undefined] | [BUILDER_GET, string] | [BUILDER_GET, string, string[]] | [BUILDER_CONCAT, ...BuilderExpression[]] | [BUILDER_HAS_BLOCK, string] | [BUILDER_HAS_BLOCK_PARAMS, string] | BuilderCallExpression;
type Params = BuilderParams;
type Hash = Dict<BuilderExpression>;
export interface NormalizedCallExpression {
type: CALL_EXPR;
head: NormalizedHead;
params: Nullable<NormalizedParams>;
hash: Nullable<NormalizedHash>;
}
export interface NormalizedPath {
type: GET_PATH_EXPR;
path: Path;
}
export interface NormalizedVar {
type: GET_VAR_EXPR;
variable: Variable;
}
export type NormalizedHead = NormalizedPath | NormalizedVar;
export interface NormalizedConcat {
type: CONCAT_EXPR;
params: [NormalizedExpression, ...NormalizedExpression[]];
}
export type NormalizedExpression = {
type: LITERAL_EXPR;
value: null | undefined | boolean | string | number;
} | NormalizedCallExpression | NormalizedPath | NormalizedVar | NormalizedConcat | {
type: HAS_BLOCK_EXPR;
name: string;
} | {
type: HAS_BLOCK_PARAMS_EXPR;
name: string;
};
export declare function normalizeAppendExpression(expression: BuilderExpression, forceTrusted?: boolean): AppendExpr | AppendPath;
export declare function normalizeExpression(expression: BuilderExpression): NormalizedExpression;
export type BuilderExpression = TupleBuilderExpression | BuilderCallExpression | null | undefined | boolean | string | number;
export declare function isBuilderExpression(expr: BuilderExpression | BuilderCallExpression): expr is TupleBuilderExpression | BuilderCallExpression;
export declare function isLiteral(expr: BuilderExpression | BuilderCallExpression): expr is [BUILDER_LITERAL, string | boolean | undefined];
export declare function statementIsExpression(statement: BuilderStatement): statement is TupleBuilderExpression;
export declare function isBuilderCallExpression(value: TupleBuilderExpression | BuilderCallExpression): value is BuilderCallExpression;
export type MiniBuilderBlock = BuilderStatement[];
export type BuilderBlock = MiniBuilderBlock;
export type BuilderCallExpression = [string] | [string, Params | Hash] | [string, Params, Hash];
export declare function normalizeParams(input: Params): NormalizedParams;
export declare function normalizeHash(input: Nullable<Hash>): Nullable<NormalizedHash>;
export declare function normalizeCallExpression(expr: BuilderCallExpression): NormalizedCallExpression;
export {};
import type { AttrNamespace, Expressions, GetContextualFreeOpcode, Nullable, PresentArray, WireFormat } from '@glimmer/interfaces';
import { BUILDER_LITERAL } from '@glimmer/constants';
import { VariableResolutionContext } from '@glimmer/wire-format';
import type { BuilderComment, BuilderStatement, NormalizedAngleInvocation, NormalizedAttrs, NormalizedBlocks, NormalizedExpression, NormalizedHash, NormalizedHead, NormalizedParams, NormalizedPath, NormalizedStatement, Variable } from './builder-interface';
interface Symbols {
top: ProgramSymbols;
freeVar(name: string): number;
arg(name: string): number;
block(name: string): number;
local(name: string): number;
this(): number;
hasLocal(name: string): boolean;
child(params: string[]): LocalSymbols;
}
export declare class ProgramSymbols implements Symbols {
_freeVariables: string[];
_symbols: string[];
top: this;
toSymbols(): string[];
toUpvars(): string[];
freeVar(name: string): number;
block(name: string): number;
arg(name: string): number;
local(name: string): never;
this(): number;
hasLocal(_name: string): false;
symbol(name: string): number;
child(locals: string[]): LocalSymbols;
}
declare class LocalSymbols implements Symbols {
private parent;
private locals;
constructor(parent: Symbols, locals: string[]);
get paramSymbols(): number[];
get top(): ProgramSymbols;
freeVar(name: string): number;
arg(name: string): number;
block(name: string): number;
local(name: string): number;
this(): number;
hasLocal(name: string): boolean;
child(locals: string[]): LocalSymbols;
}
export interface BuilderGetFree {
type: 'GetFree';
head: string;
tail: string[];
}
export declare function buildStatements(statements: BuilderStatement[], symbols: Symbols): WireFormat.Statement[];
export declare function buildNormalizedStatements(statements: NormalizedStatement[], symbols: Symbols): WireFormat.Statement[];
export declare function buildStatement(normalized: NormalizedStatement, symbols?: Symbols): WireFormat.Statement[];
export declare function s(arr: TemplateStringsArray, ...interpolated: unknown[]): [BUILDER_LITERAL, string];
export declare function c(arr: TemplateStringsArray, ...interpolated: unknown[]): BuilderComment;
export declare function unicode(charCode: string): string;
export declare const NEWLINE = "\n";
export declare function buildAngleInvocation({ attrs, block, head }: NormalizedAngleInvocation, symbols: Symbols): WireFormat.Statements.Component;
export declare function buildElementParams(attrs: NormalizedAttrs, symbols: Symbols): {
params: WireFormat.ElementParameter[];
args: WireFormat.Core.Hash;
};
export declare function extractNamespace(name: string): Nullable<AttrNamespace>;
export declare function buildAttributeValue(name: string, value: NormalizedExpression, namespace: Nullable<AttrNamespace>, symbols: Symbols): WireFormat.Attribute[];
type ExprResolution = VariableResolutionContext | 'Append' | 'TrustedAppend' | 'AttrValue' | 'SubExpression' | 'Strict';
export declare function buildExpression(expr: NormalizedExpression, context: ExprResolution, symbols: Symbols): WireFormat.Expression;
export declare function buildCallHead(callHead: NormalizedHead, context: VarResolution, symbols: Symbols): Expressions.GetVar | Expressions.GetPath;
export declare function buildGetPath(head: NormalizedPath, symbols: Symbols): Expressions.GetPath;
type VarResolution = VariableResolutionContext | 'AppendBare' | 'AppendInvoke' | 'TrustedAppendBare' | 'TrustedAppendInvoke' | 'AttrValueBare' | 'AttrValueInvoke' | 'SubExpression' | 'Strict';
export declare function buildVar(head: Variable, context: VarResolution, symbols: Symbols, path: PresentArray<string>): Expressions.GetPath;
export declare function buildVar(head: Variable, context: VarResolution, symbols: Symbols): Expressions.GetVar;
export declare function expressionContextOp(context: VariableResolutionContext): GetContextualFreeOpcode;
export declare function buildParams(exprs: Nullable<NormalizedParams>, symbols: Symbols): Nullable<WireFormat.Core.Params>;
export declare function buildConcat(exprs: [NormalizedExpression, ...NormalizedExpression[]], symbols: Symbols): WireFormat.Core.ConcatParams;
export declare function buildHash(exprs: Nullable<NormalizedHash>, symbols: Symbols): WireFormat.Core.Hash;
export declare function buildBlocks(blocks: NormalizedBlocks, blockParams: Nullable<string[]>, parent: Symbols): WireFormat.Core.Blocks;
export {};
import type { Nullable, SerializedTemplateBlock, TemplateJavascript } from '@glimmer/interfaces';
import type { PrecompileOptions, PrecompileOptionsWithLexicalScope, TemplateIdFn } from '@glimmer/syntax';
export declare const defaultId: TemplateIdFn;
export declare function precompileJSON(string: Nullable<string>, options?: PrecompileOptions | PrecompileOptionsWithLexicalScope): [block: SerializedTemplateBlock, usedLocals: string[]];
export declare function precompile(source: string, options?: PrecompileOptions | PrecompileOptionsWithLexicalScope): TemplateJavascript;
export type { PrecompileOptions };
import type { ASTv2, SymbolTable } from '@glimmer/syntax';
import type { OptionalList } from '../../shared/list';
import type { Result } from '../../shared/result';
import type * as mir from '../2-encoding/mir';
/**
* This is the mutable state for this compiler pass.
*/
export declare class NormalizationState {
readonly isStrict: boolean;
_currentScope: SymbolTable;
_cursorCount: number;
constructor(block: SymbolTable, isStrict: boolean);
generateUniqueCursor(): string;
get scope(): SymbolTable;
visitBlock(block: ASTv2.Block): Result<OptionalList<mir.Statement>>;
}
import type { ASTv2, src } from '@glimmer/syntax';
import type { Result } from '../../shared/result';
import * as mir from '../2-encoding/mir';
/**
* Normalize the AST from @glimmer/syntax into the HIR. The HIR has special
* instructions for keywords like `{{yield}}`, `(has-block)` and
* `{{#in-element}}`.
*
* Most importantly, it also classifies HTML element syntax into:
*
* 1. simple HTML element (with optional splattributes)
* 2. component invocation
*
* Because the @glimmer/syntax AST gives us a string for an element's tag,
* this pass also normalizes that string into an expression.
*
* ```
* // normalized into a path expression whose head is `this` and tail is
* // `["x"]`
* <this.x />
*
* {{#let expr as |t|}}
* // `"t"` is normalized into a variable lookup.
* <t />
*
* // normalized into a path expression whose head is the variable lookup
* // `t` and tail is `["input"]`.
* <t.input />
* {{/let}}
*
* // normalized into a free variable lookup for `SomeComponent` (with the
* // context `ComponentHead`).
* <SomeComponent />
*
* // normalized into a path expression whose head is the free variable
* // `notInScope` (with the context `Expression`), and whose tail is
* // `["SomeComponent"]`. In resolver mode, this path will be rejected later,
* // since it cannot serve as an input to the resolver.
* <notInScope.SomeComponent />
* ```
*/
export default function normalize(source: src.Source, root: ASTv2.Template, isStrict: boolean): Result<mir.Template>;
export { APPEND_KEYWORDS } from './keywords/append';
export { BLOCK_KEYWORDS } from './keywords/block';
export { CALL_KEYWORDS } from './keywords/call';
export { MODIFIER_KEYWORDS } from './keywords/modifier';
export declare const APPEND_KEYWORDS: import("./impl").Keywords<"Append", never>;
export declare const BLOCK_KEYWORDS: import("./impl").Keywords<"Block", never>;
export declare const CALL_KEYWORDS: import("./impl").Keywords<"Call", never>;
import type { ASTv2, KeywordType } from '@glimmer/syntax';
import type { Result } from '../../../shared/result';
import type { NormalizationState } from '../context';
export interface KeywordDelegate<Match extends KeywordMatch, V, Out> {
assert: (options: Match, state: NormalizationState) => Result<V>;
translate: (options: {
node: Match;
state: NormalizationState;
}, param: V) => Result<Out>;
}
export interface Keyword<K extends KeywordType = KeywordType, Out = unknown> {
translate(node: KeywordCandidates[K], state: NormalizationState): Result<Out> | null;
}
export interface BlockKeyword<Out = unknown> {
translate(node: ASTv2.InvokeBlock, state: NormalizationState): Result<Out> | null;
}
export declare const KEYWORD_NODES: {
readonly Call: readonly ["Call"];
readonly Block: readonly ["InvokeBlock"];
readonly Append: readonly ["AppendContent"];
readonly Modifier: readonly ["ElementModifier"];
};
export interface KeywordCandidates {
Call: ASTv2.ExpressionNode;
Block: ASTv2.InvokeBlock;
Append: ASTv2.AppendContent;
Modifier: ASTv2.ElementModifier;
}
export type KeywordCandidate = KeywordCandidates[keyof KeywordCandidates];
export interface KeywordMatches {
Call: ASTv2.CallExpression;
Block: ASTv2.InvokeBlock;
Append: ASTv2.AppendContent;
Modifier: ASTv2.ElementModifier;
}
export type KeywordMatch = KeywordMatches[keyof KeywordMatches];
/**
* A "generic" keyword is something like `has-block`, which makes sense in the context
* of sub-expression or append
*/
export type GenericKeywordNode = ASTv2.AppendContent | ASTv2.CallExpression;
export type KeywordNode = GenericKeywordNode | ASTv2.CallExpression | ASTv2.InvokeBlock | ASTv2.ElementModifier;
export type PossibleKeyword = KeywordNode;
type OutFor<K extends Keyword | BlockKeyword> = K extends BlockKeyword<infer Out> ? Out : K extends Keyword<KeywordType, infer Out> ? Out : never;
export declare class Keywords<K extends KeywordType, KeywordList extends Keyword<K> = never> implements Keyword<K, OutFor<KeywordList>> {
_keywords: Keyword[];
_type: K;
constructor(type: K);
kw<V, S extends string = string, Out = unknown>(name: S, delegate: KeywordDelegate<KeywordMatches[K], V, Out>): this;
translate(node: KeywordCandidates[K], state: NormalizationState): Result<OutFor<KeywordList>> | null;
}
/**
* This function builds keyword definitions for a particular type of AST node (`KeywordType`).
*
* You can build keyword definitions for:
*
* - `Expr`: A `SubExpression` or `PathExpression`
* - `Block`: A `BlockStatement`
* - A `BlockStatement` is a keyword candidate if its head is a
* `PathExpression`
* - `Append`: An `AppendStatement`
*
* A node is a keyword candidate if:
*
* - A `PathExpression` is a keyword candidate if it has no tail, and its
* head expression is a `LocalVarHead` or `FreeVarHead` whose name is
* the keyword's name.
* - A `SubExpression`, `AppendStatement`, or `BlockStatement` is a keyword
* candidate if its head is a keyword candidate.
*
* The keyword infrastructure guarantees that:
*
* - If a node is not a keyword candidate, it is never passed to any keyword's
* `assert` method.
* - If a node is not the `KeywordType` for a particular keyword, it will not
* be passed to the keyword's `assert` method.
*
* `Expr` keywords are used in expression positions and should return HIR
* expressions. `Block` and `Append` keywords are used in statement
* positions and should return HIR statements.
*
* A keyword definition has two parts:
*
* - `match`, which determines whether an AST node matches the keyword, and can
* optionally return some information extracted from the AST node.
* - `translate`, which takes a matching AST node as well as the extracted
* information and returns an appropriate HIR instruction.
*
* # Example
*
* This keyword:
*
* - turns `(hello)` into `"hello"`
* - as long as `hello` is not in scope
* - makes it an error to pass any arguments (such as `(hello world)`)
*
* ```ts
* keywords('SubExpr').kw('hello', {
* assert(node: ExprKeywordNode): Result<void> | false {
* // we don't want to transform `hello` as a `PathExpression`
* if (node.type !== 'SubExpression') {
* return false;
* }
*
* // node.head would be `LocalVarHead` if `hello` was in scope
* if (node.head.type !== 'FreeVarHead') {
* return false;
* }
*
* if (node.params.length || node.hash) {
* return Err(generateSyntaxError(`(hello) does not take any arguments`), node.loc);
* } else {
* return Ok();
* }
* },
*
* translate(node: ASTv2.SubExpression): hir.Expression {
* return ASTv2.builders.literal("hello", node.loc)
* }
* })
* ```
*
* The keyword infrastructure checks to make sure that the node is the right
* type before calling `assert`, so you only need to consider `SubExpression`
* and `PathExpression` here. It also checks to make sure that the node passed
* to `assert` has the keyword name in the right place.
*
* Note the important difference between returning `false` from `assert`,
* which just means that the node didn't match, and returning `Err`, which
* means that the node matched, but there was a keyword-specific syntax
* error.
*/
export declare function keywords<K extends KeywordType>(type: K): Keywords<K>;
export {};
export declare const MODIFIER_KEYWORDS: import("./impl").Keywords<"Modifier", never>;
import type { GenericKeywordNode, KeywordDelegate } from '../impl';
import * as mir from '../../../2-encoding/mir';
export declare function toAppend<T>({ assert, translate, }: KeywordDelegate<GenericKeywordNode, T, mir.ExpressionNode>): KeywordDelegate<GenericKeywordNode, T, mir.AppendTextNode>;
import type { CurriedType } from '@glimmer/interfaces';
import { ASTv2 } from '@glimmer/syntax';
import type { NormalizationState } from '../../context';
import type { KeywordDelegate } from '../impl';
import { Result } from '../../../../shared/result';
import * as mir from '../../../2-encoding/mir';
export declare function assertCurryKeyword(curriedType: CurriedType): (node: ASTv2.AppendContent | ASTv2.InvokeBlock | ASTv2.CallExpression, state: NormalizationState) => Result<{
definition: ASTv2.ExpressionNode;
args: ASTv2.Args;
}>;
export declare function curryKeyword(curriedType: CurriedType): KeywordDelegate<ASTv2.CallExpression | ASTv2.AppendContent, {
definition: ASTv2.ExpressionNode;
args: ASTv2.Args;
}, mir.Curry>;
import type { ASTv2 } from '@glimmer/syntax';
import type { GenericKeywordNode, KeywordDelegate } from '../impl';
import * as mir from '../../../2-encoding/mir';
export declare const getDynamicVarKeyword: KeywordDelegate<GenericKeywordNode, ASTv2.ExpressionNode, mir.GetDynamicVar>;
import { ASTv2, SourceSlice } from '@glimmer/syntax';
import type { KeywordDelegate } from '../impl';
import * as mir from '../../../2-encoding/mir';
export declare function hasBlockKeyword(type: string): KeywordDelegate<ASTv2.CallExpression | ASTv2.AppendContent, SourceSlice, mir.HasBlock | mir.HasBlockParams>;
import type { ASTv2 } from '@glimmer/syntax';
import type { KeywordDelegate } from '../impl';
import * as mir from '../../../2-encoding/mir';
export declare function ifUnlessInlineKeyword(type: string): KeywordDelegate<ASTv2.CallExpression | ASTv2.AppendContent, {
condition: ASTv2.ExpressionNode;
truthy: ASTv2.ExpressionNode;
falsy: ASTv2.ExpressionNode | null;
}, mir.IfInline>;
import type { ASTv2 } from '@glimmer/syntax';
import type { KeywordDelegate } from '../impl';
import * as mir from '../../../2-encoding/mir';
export declare const logKeyword: KeywordDelegate<ASTv2.CallExpression | ASTv2.AppendContent, ASTv2.PositionalArguments, mir.Log>;
export type VALUE_RESOLUTION = 'value';
export declare const VALUE_RESOLUTION: VALUE_RESOLUTION;
export type COMPONENT_RESOLUTION = 'component';
export declare const COMPONENT_RESOLUTION: COMPONENT_RESOLUTION;
export type HELPER_RESOLUTION = 'helper';
export declare const HELPER_RESOLUTION: HELPER_RESOLUTION;
export type MODIFIER_RESOLUTION = 'modifier';
export declare const MODIFIER_RESOLUTION: MODIFIER_RESOLUTION;
export type COMPONENT_OR_HELPER_RESOLUTION = 'component or helper';
export declare const COMPONENT_OR_HELPER_RESOLUTION: COMPONENT_OR_HELPER_RESOLUTION;
export type ResolutionType = VALUE_RESOLUTION | COMPONENT_RESOLUTION | HELPER_RESOLUTION | MODIFIER_RESOLUTION | COMPONENT_OR_HELPER_RESOLUTION;
import { ASTv2 } from '@glimmer/syntax';
import type { NormalizationState } from '../../context';
import { Result } from '../../../../shared/result';
import * as mir from '../../../2-encoding/mir';
export type ValidAttr = mir.StaticAttr | mir.DynamicAttr | mir.SplatAttr;
export interface Classified {
readonly dynamicFeatures: boolean;
arg(attr: ASTv2.AttrNode, classified: ClassifiedElement): Result<mir.NamedArgument>;
toStatement(classified: ClassifiedElement, prepared: PreparedArgs): Result<mir.Statement>;
}
export declare class ClassifiedElement {
readonly element: ASTv2.ElementNode;
readonly state: NormalizationState;
readonly delegate: Classified;
constructor(element: ASTv2.ElementNode, delegate: Classified, state: NormalizationState);
toStatement(): Result<mir.Statement>;
private attr;
private modifier;
private attrs;
private prepare;
}
export interface PreparedArgs {
args: mir.NamedArguments;
params: mir.ElementParameters;
}
export declare function hasDynamicFeatures({ attrs, modifiers, }: Pick<ASTv2.ElementNode, 'attrs' | 'modifiers'>): boolean;
import type { ASTv2 } from '@glimmer/syntax';
import type { Result } from '../../../../shared/result';
import type { Classified, ClassifiedElement, PreparedArgs } from './classified';
import * as mir from '../../../2-encoding/mir';
export declare class ClassifiedComponent implements Classified {
private tag;
private element;
readonly dynamicFeatures = true;
constructor(tag: mir.ExpressionNode, element: ASTv2.InvokeComponent);
arg(attr: ASTv2.ComponentArg, { state }: ClassifiedElement): Result<mir.NamedArgument>;
toStatement(component: ClassifiedElement, { args, params }: PreparedArgs): Result<mir.Statement>;
private blocks;
}
import type { ASTv2, SourceSlice } from '@glimmer/syntax';
import type { Result } from '../../../../shared/result';
import type { Classified, ClassifiedElement, PreparedArgs } from './classified';
import * as mir from '../../../2-encoding/mir';
export declare class ClassifiedSimpleElement implements Classified {
private tag;
private element;
readonly dynamicFeatures: boolean;
constructor(tag: SourceSlice, element: ASTv2.SimpleElement, dynamicFeatures: boolean);
readonly isComponent = false;
arg(attr: ASTv2.ComponentArg): Result<mir.NamedArgument>;
toStatement(classified: ClassifiedElement, { params }: PreparedArgs): Result<mir.Statement>;
}
import type { PresentArray } from '@glimmer/interfaces';
import { ASTv2 } from '@glimmer/syntax';
import type { AnyOptionalList, PresentList } from '../../../shared/list';
import type { NormalizationState } from '../context';
import { Result } from '../../../shared/result';
import * as mir from '../../2-encoding/mir';
export declare class NormalizeExpressions {
visit(node: ASTv2.ExpressionNode, state: NormalizationState): Result<mir.ExpressionNode>;
visitList(nodes: PresentArray<ASTv2.ExpressionNode>, state: NormalizationState): Result<PresentList<mir.ExpressionNode>>;
visitList(nodes: readonly ASTv2.ExpressionNode[], state: NormalizationState): Result<AnyOptionalList<mir.ExpressionNode>>;
/**
* Normalize paths into `hir.Path` or a `hir.Expr` that corresponds to the ref.
*
* TODO since keywords don't support tails anyway, distinguish PathExpression from
* VariableReference in ASTv2.
*/
PathExpression(path: ASTv2.PathExpression): Result<mir.ExpressionNode>;
VariableReference(ref: ASTv2.VariableReference): ASTv2.VariableReference;
Literal(literal: ASTv2.LiteralExpression): ASTv2.LiteralExpression;
Keyword(keyword: ASTv2.KeywordExpression): ASTv2.KeywordExpression;
Interpolate(expr: ASTv2.InterpolateExpression, state: NormalizationState): Result<mir.InterpolateExpression>;
CallExpression(expr: ASTv2.CallExpression, state: NormalizationState): Result<mir.ExpressionNode>;
Args({ positional, named, loc }: ASTv2.Args, state: NormalizationState): Result<mir.Args>;
Positional(positional: ASTv2.PositionalArguments, state: NormalizationState): Result<mir.Positional>;
NamedArguments(named: ASTv2.NamedArguments, state: NormalizationState): Result<mir.NamedArguments>;
}
export declare function convertPathToCallIfKeyword(path: ASTv2.ExpressionNode): ASTv2.ExpressionNode;
export declare const VISIT_EXPRS: NormalizeExpressions;
import { ASTv2 } from '@glimmer/syntax';
import type { NormalizationState } from '../context';
import { OptionalList } from '../../../shared/list';
import { Result } from '../../../shared/result';
import * as mir from '../../2-encoding/mir';
declare class NormalizationStatements {
visitList(nodes: readonly ASTv2.ContentNode[], state: NormalizationState): Result<OptionalList<mir.Statement>>;
visit(node: ASTv2.ContentNode, state: NormalizationState): Result<mir.Statement | null>;
InvokeBlock(node: ASTv2.InvokeBlock, state: NormalizationState): Result<mir.Statement>;
NamedBlocks(blocks: ASTv2.NamedBlocks, state: NormalizationState): Result<mir.NamedBlocks>;
NamedBlock(named: ASTv2.NamedBlock, state: NormalizationState): Result<mir.NamedBlock>;
SimpleElement(element: ASTv2.SimpleElement, state: NormalizationState): Result<mir.Statement>;
Component(component: ASTv2.InvokeComponent, state: NormalizationState): Result<mir.Statement>;
AppendContent(append: ASTv2.AppendContent, state: NormalizationState): Result<mir.Statement>;
TextNode(text: ASTv2.HtmlText): mir.Statement;
HtmlComment(comment: ASTv2.HtmlComment): mir.Statement;
}
export declare const VISIT_STMTS: NormalizationStatements;
export {};
import type { HasSourceSpan } from '@glimmer/syntax';
import type { Result } from '../../../shared/result';
import type * as mir from '../../2-encoding/mir';
import type { ResolutionType } from './constants';
export default class StrictModeValidationPass {
private template;
static validate(template: mir.Template): Result<mir.Template>;
private constructor();
validate(): Result<mir.Template>;
Statements(statements: mir.Statement[]): Result<null>;
NamedBlocks({ blocks }: mir.NamedBlocks): Result<null>;
NamedBlock(block: mir.NamedBlock): Result<null>;
Statement(statement: mir.Statement): Result<null>;
Expressions(expressions: mir.ExpressionNode[]): Result<null>;
Expression(expression: mir.ExpressionNode, span?: HasSourceSpan, resolution?: ResolutionType): Result<null>;
Args(args: mir.Args): Result<null>;
Positional(positional: mir.Positional, span?: HasSourceSpan): Result<null>;
NamedArguments({ entries }: mir.NamedArguments): Result<null>;
NamedArgument(arg: mir.NamedArgument): Result<null>;
ElementParameters({ body }: mir.ElementParameters): Result<null>;
ElementParameter(param: mir.ElementParameter): Result<null>;
DynamicAttr(attr: mir.DynamicAttr): Result<null>;
Modifier(modifier: mir.Modifier): Result<null>;
InElement(inElement: mir.InElement): Result<null>;
Yield(statement: mir.Yield): Result<null>;
AppendTrustedHTML(statement: mir.AppendTrustedHTML): Result<null>;
AppendTextNode(statement: mir.AppendTextNode): Result<null>;
Component(statement: mir.Component): Result<null>;
SimpleElement(statement: mir.SimpleElement): Result<null>;
InvokeBlock(statement: mir.InvokeBlock): Result<null>;
If(statement: mir.If): Result<null>;
Each(statement: mir.Each): Result<null>;
Let(statement: mir.Let): Result<null>;
WithDynamicVars(statement: mir.WithDynamicVars): Result<null>;
InvokeComponent(statement: mir.InvokeComponent): Result<null>;
InterpolateExpression(expression: mir.InterpolateExpression, span: HasSourceSpan, resolution?: ResolutionType): Result<null>;
CallExpression(expression: mir.CallExpression, span: HasSourceSpan, resolution?: ResolutionType): Result<null>;
IfInline(expression: mir.IfInline): Result<null>;
Curry(expression: mir.Curry): Result<null>;
Log(expression: mir.Log): Result<null>;
errorFor(name: string, span: HasSourceSpan, type?: ResolutionType): Result<never>;
}
import type { WellKnownAttrName, WireFormat } from '@glimmer/interfaces';
import type { OptionalList } from '../../shared/list';
import type * as mir from './mir';
declare class WireStatements<S extends WireFormat.Statement = WireFormat.Statement> {
private statements;
constructor(statements: readonly S[]);
toArray(): readonly S[];
}
export declare class ContentEncoder {
list(statements: mir.Statement[]): WireFormat.Statement[];
content(stmt: mir.Statement): WireFormat.Statement | WireStatements;
private visitContent;
Yield({ to, positional }: mir.Yield): WireFormat.Statements.Yield;
InElement({ guid, insertBefore, destination, block, }: mir.InElement): WireFormat.Statements.InElement;
InvokeBlock({ head, args, blocks }: mir.InvokeBlock): WireFormat.Statements.Block;
AppendTrustedHTML({ html }: mir.AppendTrustedHTML): WireFormat.Statements.TrustingAppend;
AppendTextNode({ text }: mir.AppendTextNode): WireFormat.Statements.Append;
AppendComment({ value }: mir.AppendComment): WireFormat.Statements.Comment;
SimpleElement({ tag, params, body, dynamicFeatures }: mir.SimpleElement): WireStatements;
Component({ tag, params, args, blocks }: mir.Component): WireFormat.Statements.Component;
ElementParameters({ body }: mir.ElementParameters): OptionalList<WireFormat.ElementParameter>;
ElementParameter(param: mir.ElementParameter): WireFormat.ElementParameter;
NamedBlocks({ blocks }: mir.NamedBlocks): WireFormat.Core.Blocks;
NamedBlock({ name, body, scope }: mir.NamedBlock): WireFormat.Core.NamedBlock;
If({ condition, block, inverse }: mir.If): WireFormat.Statements.If;
Each({ value, key, block, inverse }: mir.Each): WireFormat.Statements.Each;
Let({ positional, block }: mir.Let): WireFormat.Statements.Let;
WithDynamicVars({ named, block }: mir.WithDynamicVars): WireFormat.Statements.WithDynamicVars;
InvokeComponent({ definition, args, blocks, }: mir.InvokeComponent): WireFormat.Statements.InvokeComponent;
}
export declare const CONTENT: ContentEncoder;
export type StaticAttrArgs = [name: string | WellKnownAttrName, value: string, namespace?: string];
export type DynamicAttrArgs = [
name: string | WellKnownAttrName,
value: WireFormat.Expression,
namespace?: string
];
export {};
import type { PresentArray, WireFormat } from '@glimmer/interfaces';
import type { ASTv2 } from '@glimmer/syntax';
import type * as mir from './mir';
export type HashPair = [string, WireFormat.Expression];
export declare class ExpressionEncoder {
expr(expr: mir.ExpressionNode): WireFormat.Expression;
Literal({ value, }: ASTv2.LiteralExpression): WireFormat.Expressions.Value | WireFormat.Expressions.Undefined;
Missing(): undefined;
HasBlock({ symbol }: mir.HasBlock): WireFormat.Expressions.HasBlock;
HasBlockParams({ symbol }: mir.HasBlockParams): WireFormat.Expressions.HasBlockParams;
Curry({ definition, curriedType, args }: mir.Curry): WireFormat.Expressions.Curry;
Local({ isTemplateLocal, symbol, }: ASTv2.LocalVarReference): WireFormat.Expressions.GetSymbol | WireFormat.Expressions.GetLexicalSymbol;
Keyword({ symbol }: ASTv2.KeywordExpression): WireFormat.Expressions.GetStrictFree;
PathExpression({ head, tail }: mir.PathExpression): WireFormat.Expressions.GetPath;
InterpolateExpression({ parts }: mir.InterpolateExpression): WireFormat.Expressions.Concat;
CallExpression({ callee, args }: mir.CallExpression): WireFormat.Expressions.Helper;
Tail({ members }: mir.Tail): PresentArray<string>;
Args({ positional, named }: mir.Args): WireFormat.Core.Args;
Positional({ list }: mir.Positional): WireFormat.Core.Params;
NamedArgument({ key, value }: mir.NamedArgument): HashPair;
NamedArguments({ entries: pairs }: mir.NamedArguments): WireFormat.Core.Hash;
Not({ value }: mir.Not): WireFormat.Expressions.Not;
IfInline({ condition, truthy, falsy }: mir.IfInline): WireFormat.Expressions.IfInline;
GetDynamicVar({ name }: mir.GetDynamicVar): WireFormat.Expressions.GetDynamicVar;
Log({ positional }: mir.Log): WireFormat.Expressions.Log;
}
export declare const EXPR: ExpressionEncoder;
import type { WireFormat } from '@glimmer/interfaces';
import type * as mir from './mir';
export declare function visit(template: mir.Template): WireFormat.SerializedTemplateBlock;
import type { CurriedType, PresentArray } from '@glimmer/interfaces';
import type { ASTv2, BlockSymbolTable, ProgramSymbolTable, SourceSlice, SymbolTable } from '@glimmer/syntax';
import type { AnyOptionalList, OptionalList, PresentList } from '../../shared/list';
declare const Template_base: ASTv2.TypedNodeConstructor<"Template", {
scope: ProgramSymbolTable;
body: Statement[];
} & ASTv2.BaseNodeFields>;
export declare class Template extends Template_base {
}
declare const InElement_base: ASTv2.TypedNodeConstructor<"InElement", {
guid: string;
insertBefore: ExpressionNode | Missing;
destination: ExpressionNode;
block: NamedBlock;
} & ASTv2.BaseNodeFields>;
export declare class InElement extends InElement_base {
}
declare const Not_base: ASTv2.TypedNodeConstructor<"Not", {
value: ExpressionNode;
} & ASTv2.BaseNodeFields>;
export declare class Not extends Not_base {
}
declare const If_base: ASTv2.TypedNodeConstructor<"If", {
condition: ExpressionNode;
block: NamedBlock;
inverse: NamedBlock | null;
} & ASTv2.BaseNodeFields>;
export declare class If extends If_base {
}
declare const IfInline_base: ASTv2.TypedNodeConstructor<"IfInline", {
condition: ExpressionNode;
truthy: ExpressionNode;
falsy: ExpressionNode | null;
} & ASTv2.BaseNodeFields>;
export declare class IfInline extends IfInline_base {
}
declare const Each_base: ASTv2.TypedNodeConstructor<"Each", {
value: ExpressionNode;
key: ExpressionNode | null;
block: NamedBlock;
inverse: NamedBlock | null;
} & ASTv2.BaseNodeFields>;
export declare class Each extends Each_base {
}
declare const Let_base: ASTv2.TypedNodeConstructor<"Let", {
positional: Positional;
block: NamedBlock;
} & ASTv2.BaseNodeFields>;
export declare class Let extends Let_base {
}
declare const WithDynamicVars_base: ASTv2.TypedNodeConstructor<"WithDynamicVars", {
named: NamedArguments;
block: NamedBlock;
} & ASTv2.BaseNodeFields>;
export declare class WithDynamicVars extends WithDynamicVars_base {
}
declare const GetDynamicVar_base: ASTv2.TypedNodeConstructor<"GetDynamicVar", {
name: ExpressionNode;
} & ASTv2.BaseNodeFields>;
export declare class GetDynamicVar extends GetDynamicVar_base {
}
declare const Log_base: ASTv2.TypedNodeConstructor<"Log", {
positional: Positional;
} & ASTv2.BaseNodeFields>;
export declare class Log extends Log_base {
}
declare const InvokeComponent_base: ASTv2.TypedNodeConstructor<"InvokeComponent", {
definition: ExpressionNode;
args: Args;
blocks: NamedBlocks | null;
} & ASTv2.BaseNodeFields>;
export declare class InvokeComponent extends InvokeComponent_base {
}
declare const NamedBlocks_base: ASTv2.TypedNodeConstructor<"NamedBlocks", {
blocks: OptionalList<NamedBlock>;
} & ASTv2.BaseNodeFields>;
export declare class NamedBlocks extends NamedBlocks_base {
}
declare const NamedBlock_base: ASTv2.TypedNodeConstructor<"NamedBlock", {
scope: BlockSymbolTable;
name: SourceSlice;
body: Statement[];
} & ASTv2.BaseNodeFields>;
export declare class NamedBlock extends NamedBlock_base {
}
declare const AppendTrustedHTML_base: ASTv2.TypedNodeConstructor<"AppendTrustedHTML", {
html: ExpressionNode;
} & ASTv2.BaseNodeFields>;
export declare class AppendTrustedHTML extends AppendTrustedHTML_base {
}
declare const AppendTextNode_base: ASTv2.TypedNodeConstructor<"AppendTextNode", {
text: ExpressionNode;
} & ASTv2.BaseNodeFields>;
export declare class AppendTextNode extends AppendTextNode_base {
}
declare const AppendComment_base: ASTv2.TypedNodeConstructor<"AppendComment", {
value: SourceSlice;
} & ASTv2.BaseNodeFields>;
export declare class AppendComment extends AppendComment_base {
}
declare const Component_base: ASTv2.TypedNodeConstructor<"Component", {
tag: ExpressionNode;
params: ElementParameters;
args: NamedArguments;
blocks: NamedBlocks;
} & ASTv2.BaseNodeFields>;
export declare class Component extends Component_base {
}
export interface AttrKind {
trusting: boolean;
component: boolean;
}
declare const StaticAttr_base: ASTv2.TypedNodeConstructor<"StaticAttr", {
kind: {
component: boolean;
};
name: SourceSlice;
value: SourceSlice;
namespace?: string | undefined;
} & ASTv2.BaseNodeFields>;
export declare class StaticAttr extends StaticAttr_base {
}
declare const DynamicAttr_base: ASTv2.TypedNodeConstructor<"DynamicAttr", {
kind: AttrKind;
name: SourceSlice;
value: ExpressionNode;
namespace?: string | undefined;
} & ASTv2.BaseNodeFields>;
export declare class DynamicAttr extends DynamicAttr_base {
}
declare const SimpleElement_base: ASTv2.TypedNodeConstructor<"SimpleElement", {
tag: SourceSlice;
params: ElementParameters;
body: Statement[];
dynamicFeatures: boolean;
} & ASTv2.BaseNodeFields>;
export declare class SimpleElement extends SimpleElement_base {
}
declare const ElementParameters_base: ASTv2.TypedNodeConstructor<"ElementParameters", {
body: AnyOptionalList<ElementParameter>;
} & ASTv2.BaseNodeFields>;
export declare class ElementParameters extends ElementParameters_base {
}
declare const Yield_base: ASTv2.TypedNodeConstructor<"Yield", {
target: SourceSlice;
to: number;
positional: Positional;
} & ASTv2.BaseNodeFields>;
export declare class Yield extends Yield_base {
}
declare const Debugger_base: ASTv2.TypedNodeConstructor<"Debugger", {
scope: SymbolTable;
} & ASTv2.BaseNodeFields>;
export declare class Debugger extends Debugger_base {
}
declare const CallExpression_base: ASTv2.TypedNodeConstructor<"CallExpression", {
callee: ExpressionNode;
args: Args;
} & ASTv2.BaseNodeFields>;
export declare class CallExpression extends CallExpression_base {
}
declare const Modifier_base: ASTv2.TypedNodeConstructor<"Modifier", {
callee: ExpressionNode;
args: Args;
} & ASTv2.BaseNodeFields>;
export declare class Modifier extends Modifier_base {
}
declare const InvokeBlock_base: ASTv2.TypedNodeConstructor<"InvokeBlock", {
head: ExpressionNode;
args: Args;
blocks: NamedBlocks;
} & ASTv2.BaseNodeFields>;
export declare class InvokeBlock extends InvokeBlock_base {
}
declare const SplatAttr_base: ASTv2.TypedNodeConstructor<"SplatAttr", {
symbol: number;
} & ASTv2.BaseNodeFields>;
export declare class SplatAttr extends SplatAttr_base {
}
declare const PathExpression_base: ASTv2.TypedNodeConstructor<"PathExpression", {
head: ExpressionNode;
tail: Tail;
} & ASTv2.BaseNodeFields>;
export declare class PathExpression extends PathExpression_base {
}
declare const Missing_base: ASTv2.TypedNodeConstructor<"Missing", object & ASTv2.BaseNodeFields>;
export declare class Missing extends Missing_base {
}
declare const InterpolateExpression_base: ASTv2.TypedNodeConstructor<"InterpolateExpression", {
parts: PresentList<ExpressionNode>;
} & ASTv2.BaseNodeFields>;
export declare class InterpolateExpression extends InterpolateExpression_base {
}
declare const HasBlock_base: ASTv2.TypedNodeConstructor<"HasBlock", {
target: SourceSlice;
symbol: number;
} & ASTv2.BaseNodeFields>;
export declare class HasBlock extends HasBlock_base {
}
declare const HasBlockParams_base: ASTv2.TypedNodeConstructor<"HasBlockParams", {
target: SourceSlice;
symbol: number;
} & ASTv2.BaseNodeFields>;
export declare class HasBlockParams extends HasBlockParams_base {
}
declare const Curry_base: ASTv2.TypedNodeConstructor<"Curry", {
definition: ExpressionNode;
curriedType: CurriedType;
args: Args;
} & ASTv2.BaseNodeFields>;
export declare class Curry extends Curry_base {
}
declare const Positional_base: ASTv2.TypedNodeConstructor<"Positional", {
list: OptionalList<ExpressionNode>;
} & ASTv2.BaseNodeFields>;
export declare class Positional extends Positional_base {
}
declare const NamedArguments_base: ASTv2.TypedNodeConstructor<"NamedArguments", {
entries: OptionalList<NamedArgument>;
} & ASTv2.BaseNodeFields>;
export declare class NamedArguments extends NamedArguments_base {
}
declare const NamedArgument_base: ASTv2.TypedNodeConstructor<"NamedArgument", {
key: SourceSlice;
value: ExpressionNode;
} & ASTv2.BaseNodeFields>;
export declare class NamedArgument extends NamedArgument_base {
}
declare const Args_base: ASTv2.TypedNodeConstructor<"Args", {
positional: Positional;
named: NamedArguments;
} & ASTv2.BaseNodeFields>;
export declare class Args extends Args_base {
}
declare const Tail_base: ASTv2.TypedNodeConstructor<"Tail", {
members: PresentArray<SourceSlice>;
} & ASTv2.BaseNodeFields>;
export declare class Tail extends Tail_base {
}
export type ExpressionNode = ASTv2.LiteralExpression | ASTv2.KeywordExpression | ASTv2.VariableReference | Missing | PathExpression | InterpolateExpression | CallExpression | Not | IfInline | HasBlock | HasBlockParams | Curry | GetDynamicVar | Log;
export type ElementParameter = StaticAttr | DynamicAttr | Modifier | SplatAttr;
export type Internal = Args | Positional | NamedArguments | NamedArgument | Tail | NamedBlock | NamedBlocks | ElementParameters;
export type ExprLike = ExpressionNode | Internal;
export type Statement = InElement | Debugger | Yield | AppendTrustedHTML | AppendTextNode | Component | SimpleElement | InvokeBlock | AppendComment | If | Each | Let | WithDynamicVars | InvokeComponent;
export {};
import type { Nullable, PresentArray } from '@glimmer/interfaces';
export interface OptionalList<T> {
map<U>(callback: (input: T) => U): MapList<T, U, AnyOptionalList<T>>;
filter<S extends T>(predicate: (value: T, index: number, array: T[]) => value is S): AnyOptionalList<S>;
toArray(): T[];
toPresentArray(): Nullable<PresentArray<T>>;
into<U, V>(options: {
ifPresent: (array: PresentList<T>) => U;
ifEmpty: () => V;
}): U | V;
}
export declare class PresentList<T> implements OptionalList<T> {
readonly list: PresentArray<T>;
constructor(list: PresentArray<T>);
toArray(): PresentArray<T>;
map<U>(callback: (input: T) => U): MapList<T, U, PresentList<T>>;
filter<S extends T>(predicate: (value: T) => value is S): AnyOptionalList<S>;
toPresentArray(): PresentArray<T>;
into<U, V>({ ifPresent }: {
ifPresent: (array: PresentList<T>) => U;
ifEmpty: () => V;
}): U | V;
}
export declare class EmptyList<T> implements OptionalList<T> {
readonly list: T[];
map<U>(_callback: (input: T) => U): MapList<T, U, EmptyList<T>>;
filter<S extends T>(_predicate: (value: T) => value is S): AnyOptionalList<S>;
toArray(): T[];
toPresentArray(): Nullable<PresentArray<T>>;
into<U, V>({ ifEmpty }: {
ifPresent: (array: PresentList<T>) => U;
ifEmpty: () => V;
}): U | V;
}
export declare function OptionalList<T>(value: readonly T[]): AnyOptionalList<T>;
export type AnyOptionalList<T> = (PresentList<T> | EmptyList<T>) & OptionalList<T>;
export type MapList<T, U, L extends OptionalList<T>> = L extends PresentList<T> ? PresentList<U> : L extends EmptyList<T> ? EmptyList<U> : never;
import type { GlimmerSyntaxError } from '@glimmer/syntax';
import type { AnyOptionalList } from './list';
declare abstract class ResultImpl<T> {
static all<T extends Result<unknown>[]>(...results: T): MapAll<T>;
abstract mapOk<U>(callback: (value: T) => U): Result<U>;
abstract readonly isOk: boolean;
abstract readonly isErr: boolean;
}
export declare const Result: typeof ResultImpl;
declare class OkImpl<T> extends ResultImpl<T> {
readonly value: T;
readonly isOk = true;
readonly isErr = false;
constructor(value: T);
expect(_message?: string): T;
ifOk(callback: (value: T) => void): this;
andThen<U>(callback: (value: T) => Result<U>): Result<U>;
mapOk<U>(callback: (value: T) => U): Result<U>;
ifErr(_callback: (value: GlimmerSyntaxError) => void): this;
mapErr(_callback: (value: GlimmerSyntaxError) => GlimmerSyntaxError): Result<T>;
}
declare class ErrImpl<T> extends ResultImpl<T> {
readonly reason: GlimmerSyntaxError;
readonly isOk = false;
readonly isErr = true;
constructor(reason: GlimmerSyntaxError);
expect(message?: string): T;
andThen<U>(_callback: (value: T) => Result<U>): Result<U>;
mapOk<U>(_callback: (value: T) => U): Result<U>;
ifOk(_callback: (value: T) => void): this;
mapErr(callback: (value: GlimmerSyntaxError) => GlimmerSyntaxError): Result<T>;
ifErr(callback: (value: GlimmerSyntaxError) => void): this;
cast<U>(): Result<U>;
}
export declare function isResult<T>(input: MaybeResult<T>): input is Result<T>;
export declare function intoResult<T>(input: MaybeResult<T>): Result<T>;
export type Result<T> = OkImpl<T> | ErrImpl<T>;
type MapAllOk<T extends Result<unknown>[]> = {
[P in keyof T]: T[P] extends Result<infer Inner> ? Inner : never;
};
type MapAll<T extends Result<unknown>[]> = Result<MapAllOk<T>>;
export declare function Ok<T>(value: T): Result<T>;
export type Ok<T> = OkImpl<T>;
export declare function Err<T>(reason: GlimmerSyntaxError): Result<T>;
export type Err<T> = ErrImpl<T>;
export type MaybeResult<T> = T | Result<T>;
export declare class MapIntoResultArray<T> {
private items;
constructor(items: T[]);
map<U>(mapper: (item: T) => Result<U>): Result<U[]>;
}
export declare class ResultArray<T> {
private items;
constructor(items?: Result<T>[]);
add(item: Result<T>): void;
toArray(): Result<T[]>;
toOptionalList(): Result<AnyOptionalList<T>>;
}
export {};
import type { WellKnownAttrName, WellKnownTagName } from '@glimmer/interfaces';
export declare function getAttrNamespace(attrName: string): string | undefined;
export declare function deflateTagName(tagName: string): string | WellKnownTagName;
export declare function inflateTagName(tagName: string | WellKnownTagName): string;
export declare function deflateAttrName(attrName: string): string | WellKnownAttrName;
export declare function inflateAttrName(attrName: string | WellKnownAttrName): string;
import type { SerializedTemplateBlock, WireFormat } from '@glimmer/interfaces';
export default class WireFormatDebugger {
private upvars;
private symbols;
constructor([_statements, symbols, upvars]: SerializedTemplateBlock);
format(program: SerializedTemplateBlock): unknown;
formatOpcode(opcode: WireFormat.Syntax): unknown;
private formatCurryType;
private formatElementParams;
private formatParams;
private formatHash;
private formatBlocks;
private formatBlock;
}
import type { VariableKind } from '@glimmer/constants';
import type { Dict, Nullable, PresentArray } from '@glimmer/interfaces';
import { APPEND_EXPR_HEAD, APPEND_PATH_HEAD, BLOCK_HEAD, BUILDER_APPEND, BUILDER_COMMENT, BUILDER_CONCAT, BUILDER_DYNAMIC_COMPONENT, BUILDER_GET, BUILDER_HAS_BLOCK, BUILDER_HAS_BLOCK_PARAMS, BUILDER_LITERAL, BUILDER_MODIFIER, CALL_EXPR, CALL_HEAD, COMMENT_HEAD, CONCAT_EXPR, DYNAMIC_COMPONENT_HEAD, ELEMENT_HEAD, GET_PATH_EXPR, GET_VAR_EXPR, HAS_BLOCK_EXPR, HAS_BLOCK_PARAMS_EXPR, KEYWORD_HEAD, LITERAL_EXPR, LITERAL_HEAD, MODIFIER_HEAD, SPLAT_HEAD } from '@glimmer/constants';
export type BuilderParams = BuilderExpression[];
export type BuilderHash = Nullable<Dict<BuilderExpression>>;
export type BuilderBlockHash = BuilderHash | {
as: string | string[];
};
export type BuilderBlocks = Dict<BuilderBlock>;
export type BuilderAttrs = Dict<BuilderAttr>;
export type NormalizedParams = NormalizedExpression[];
export type NormalizedHash = Dict<NormalizedExpression>;
export type NormalizedBlock = NormalizedStatement[];
export type NormalizedBlocks = Dict<NormalizedBlock>;
export type NormalizedAttrs = Dict<NormalizedAttr>;
export type NormalizedAttr = SPLAT_HEAD | NormalizedExpression;
export interface NormalizedElement {
name: string;
attrs: Nullable<NormalizedAttrs>;
block: Nullable<NormalizedBlock>;
}
export interface NormalizedAngleInvocation {
head: NormalizedExpression;
attrs: Nullable<NormalizedAttrs>;
block: Nullable<NormalizedBlock>;
}
export interface Variable {
kind: VariableKind;
name: string;
/**
* Differences:
*
* - strict mode variables always refer to in-scope variables
* - loose mode variables use this algorithm:
* 1. otherwise, fall back to `this.<name>`
*/
mode: 'loose' | 'strict';
}
export interface Path {
head: Variable;
tail: PresentArray<string>;
}
export interface AppendExpr {
kind: APPEND_EXPR_HEAD;
expr: NormalizedExpression;
trusted: boolean;
}
export interface AppendPath {
kind: APPEND_PATH_HEAD;
path: NormalizedPath;
trusted: boolean;
}
export interface NormalizedKeywordStatement {
kind: KEYWORD_HEAD;
name: string;
params: Nullable<NormalizedParams>;
hash: Nullable<NormalizedHash>;
blockParams: Nullable<string[]>;
blocks: NormalizedBlocks;
}
export type NormalizedStatement = {
kind: CALL_HEAD;
head: NormalizedHead;
params: Nullable<NormalizedParams>;
hash: Nullable<NormalizedHash>;
trusted: boolean;
} | {
kind: BLOCK_HEAD;
head: NormalizedHead;
params: Nullable<NormalizedParams>;
hash: Nullable<NormalizedHash>;
blockParams: Nullable<string[]>;
blocks: NormalizedBlocks;
} | NormalizedKeywordStatement | {
kind: ELEMENT_HEAD;
name: string;
attrs: NormalizedAttrs;
block: NormalizedBlock;
} | {
kind: COMMENT_HEAD;
value: string;
} | {
kind: LITERAL_HEAD;
value: string;
} | AppendPath | AppendExpr | {
kind: MODIFIER_HEAD;
params: NormalizedParams;
hash: Nullable<NormalizedHash>;
} | {
kind: DYNAMIC_COMPONENT_HEAD;
expr: NormalizedExpression;
hash: Nullable<NormalizedHash>;
block: NormalizedBlock;
};
export declare function normalizeStatement(statement: BuilderStatement): NormalizedStatement;
export declare function normalizeAppendHead(head: NormalizedHead, trusted: boolean): AppendExpr | AppendPath;
export type SugaryArrayStatement = BuilderCallExpression | BuilderElement | BuilderBlockStatement;
export declare function normalizeSugaryArrayStatement(statement: SugaryArrayStatement): NormalizedStatement;
export declare function normalizePathHead(whole: string): Variable;
export type BuilderBlockStatement = [string, BuilderBlock | BuilderBlocks] | [string, BuilderParams | BuilderBlockHash, BuilderBlock | BuilderBlocks] | [string, BuilderParams, BuilderBlockHash, BuilderBlock | BuilderBlocks];
export interface NormalizedBuilderBlockStatement {
head: NormalizedHead;
params: Nullable<NormalizedParams>;
hash: Nullable<NormalizedHash>;
blockParams: Nullable<string[]>;
blocks: NormalizedBlocks;
}
export declare function normalizeBuilderBlockStatement(statement: BuilderBlockStatement): NormalizedBuilderBlockStatement;
type Entry<T> = {
[K in keyof T]: [K, T[K]];
}[keyof T];
export declare function entries<D extends Dict>(dict: D, callback: (...entry: Entry<D>) => void): void;
export type BuilderElement = [string] | [string, BuilderAttrs, BuilderBlock] | [string, BuilderBlock] | [string, BuilderAttrs];
export type BuilderComment = [BUILDER_COMMENT, string];
export type InvocationElement = [string] | [string, BuilderAttrs, BuilderBlock] | [string, BuilderBlock] | [string, BuilderAttrs];
export declare function isElement(input: [string, ...unknown[]]): input is BuilderElement;
export declare function extractElement(input: string): Nullable<string>;
export declare function isAngleInvocation(input: [string, ...unknown[]]): input is InvocationElement;
export declare function isBlock(input: [string, ...unknown[]]): input is BuilderBlockStatement;
export type VerboseStatement = [BUILDER_LITERAL, string] | [BUILDER_COMMENT, string] | [BUILDER_APPEND, BuilderExpression, true] | [BUILDER_APPEND, BuilderExpression] | [BUILDER_MODIFIER, Params, Hash] | [BUILDER_DYNAMIC_COMPONENT, BuilderExpression, Hash, BuilderBlock];
export type BuilderStatement = VerboseStatement | SugaryArrayStatement | TupleBuilderExpression | string;
/**
* The special value 'splat' is used to indicate that the attribute is a splat
*/
export type BuilderAttr = BuilderExpression;
export type TupleBuilderExpression = [BUILDER_LITERAL, string | boolean | null | undefined] | [BUILDER_GET, string] | [BUILDER_GET, string, string[]] | [BUILDER_CONCAT, ...BuilderExpression[]] | [BUILDER_HAS_BLOCK, string] | [BUILDER_HAS_BLOCK_PARAMS, string] | BuilderCallExpression;
type Params = BuilderParams;
type Hash = Dict<BuilderExpression>;
export interface NormalizedCallExpression {
type: CALL_EXPR;
head: NormalizedHead;
params: Nullable<NormalizedParams>;
hash: Nullable<NormalizedHash>;
}
export interface NormalizedPath {
type: GET_PATH_EXPR;
path: Path;
}
export interface NormalizedVar {
type: GET_VAR_EXPR;
variable: Variable;
}
export type NormalizedHead = NormalizedPath | NormalizedVar;
export interface NormalizedConcat {
type: CONCAT_EXPR;
params: [NormalizedExpression, ...NormalizedExpression[]];
}
export type NormalizedExpression = {
type: LITERAL_EXPR;
value: null | undefined | boolean | string | number;
} | NormalizedCallExpression | NormalizedPath | NormalizedVar | NormalizedConcat | {
type: HAS_BLOCK_EXPR;
name: string;
} | {
type: HAS_BLOCK_PARAMS_EXPR;
name: string;
};
export declare function normalizeAppendExpression(expression: BuilderExpression, forceTrusted?: boolean): AppendExpr | AppendPath;
export declare function normalizeExpression(expression: BuilderExpression): NormalizedExpression;
export type BuilderExpression = TupleBuilderExpression | BuilderCallExpression | null | undefined | boolean | string | number;
export declare function isBuilderExpression(expr: BuilderExpression | BuilderCallExpression): expr is TupleBuilderExpression | BuilderCallExpression;
export declare function isLiteral(expr: BuilderExpression | BuilderCallExpression): expr is [BUILDER_LITERAL, string | boolean | undefined];
export declare function statementIsExpression(statement: BuilderStatement): statement is TupleBuilderExpression;
export declare function isBuilderCallExpression(value: TupleBuilderExpression | BuilderCallExpression): value is BuilderCallExpression;
export type MiniBuilderBlock = BuilderStatement[];
export type BuilderBlock = MiniBuilderBlock;
export type BuilderCallExpression = [string] | [string, Params | Hash] | [string, Params, Hash];
export declare function normalizeParams(input: Params): NormalizedParams;
export declare function normalizeHash(input: Nullable<Hash>): Nullable<NormalizedHash>;
export declare function normalizeCallExpression(expr: BuilderCallExpression): NormalizedCallExpression;
export {};
import type { AttrNamespace, Expressions, GetContextualFreeOpcode, Nullable, PresentArray, WireFormat } from '@glimmer/interfaces';
import { BUILDER_LITERAL } from '@glimmer/constants';
import { VariableResolutionContext } from '@glimmer/wire-format';
import type { BuilderComment, BuilderStatement, NormalizedAngleInvocation, NormalizedAttrs, NormalizedBlocks, NormalizedExpression, NormalizedHash, NormalizedHead, NormalizedParams, NormalizedPath, NormalizedStatement, Variable } from './builder-interface';
interface Symbols {
top: ProgramSymbols;
freeVar(name: string): number;
arg(name: string): number;
block(name: string): number;
local(name: string): number;
this(): number;
hasLocal(name: string): boolean;
child(params: string[]): LocalSymbols;
}
export declare class ProgramSymbols implements Symbols {
_freeVariables: string[];
_symbols: string[];
top: this;
toSymbols(): string[];
toUpvars(): string[];
freeVar(name: string): number;
block(name: string): number;
arg(name: string): number;
local(name: string): never;
this(): number;
hasLocal(_name: string): false;
symbol(name: string): number;
child(locals: string[]): LocalSymbols;
}
declare class LocalSymbols implements Symbols {
private parent;
private locals;
constructor(parent: Symbols, locals: string[]);
get paramSymbols(): number[];
get top(): ProgramSymbols;
freeVar(name: string): number;
arg(name: string): number;
block(name: string): number;
local(name: string): number;
this(): number;
hasLocal(name: string): boolean;
child(locals: string[]): LocalSymbols;
}
export interface BuilderGetFree {
type: 'GetFree';
head: string;
tail: string[];
}
export declare function buildStatements(statements: BuilderStatement[], symbols: Symbols): WireFormat.Statement[];
export declare function buildNormalizedStatements(statements: NormalizedStatement[], symbols: Symbols): WireFormat.Statement[];
export declare function buildStatement(normalized: NormalizedStatement, symbols?: Symbols): WireFormat.Statement[];
export declare function s(arr: TemplateStringsArray, ...interpolated: unknown[]): [BUILDER_LITERAL, string];
export declare function c(arr: TemplateStringsArray, ...interpolated: unknown[]): BuilderComment;
export declare function unicode(charCode: string): string;
export declare const NEWLINE = "\n";
export declare function buildAngleInvocation({ attrs, block, head }: NormalizedAngleInvocation, symbols: Symbols): WireFormat.Statements.Component;
export declare function buildElementParams(attrs: NormalizedAttrs, symbols: Symbols): {
params: WireFormat.ElementParameter[];
args: WireFormat.Core.Hash;
};
export declare function extractNamespace(name: string): Nullable<AttrNamespace>;
export declare function buildAttributeValue(name: string, value: NormalizedExpression, namespace: Nullable<AttrNamespace>, symbols: Symbols): WireFormat.Attribute[];
type ExprResolution = VariableResolutionContext | 'Append' | 'TrustedAppend' | 'AttrValue' | 'SubExpression' | 'Strict';
export declare function buildExpression(expr: NormalizedExpression, context: ExprResolution, symbols: Symbols): WireFormat.Expression;
export declare function buildCallHead(callHead: NormalizedHead, context: VarResolution, symbols: Symbols): Expressions.GetVar | Expressions.GetPath;
export declare function buildGetPath(head: NormalizedPath, symbols: Symbols): Expressions.GetPath;
type VarResolution = VariableResolutionContext | 'AppendBare' | 'AppendInvoke' | 'TrustedAppendBare' | 'TrustedAppendInvoke' | 'AttrValueBare' | 'AttrValueInvoke' | 'SubExpression' | 'Strict';
export declare function buildVar(head: Variable, context: VarResolution, symbols: Symbols, path: PresentArray<string>): Expressions.GetPath;
export declare function buildVar(head: Variable, context: VarResolution, symbols: Symbols): Expressions.GetVar;
export declare function expressionContextOp(context: VariableResolutionContext): GetContextualFreeOpcode;
export declare function buildParams(exprs: Nullable<NormalizedParams>, symbols: Symbols): Nullable<WireFormat.Core.Params>;
export declare function buildConcat(exprs: [NormalizedExpression, ...NormalizedExpression[]], symbols: Symbols): WireFormat.Core.ConcatParams;
export declare function buildHash(exprs: Nullable<NormalizedHash>, symbols: Symbols): WireFormat.Core.Hash;
export declare function buildBlocks(blocks: NormalizedBlocks, blockParams: Nullable<string[]>, parent: Symbols): WireFormat.Core.Blocks;
export {};
import type { Nullable, SerializedTemplateBlock, TemplateJavascript } from '@glimmer/interfaces';
import type { PrecompileOptions, PrecompileOptionsWithLexicalScope, TemplateIdFn } from '@glimmer/syntax';
export declare const defaultId: TemplateIdFn;
export declare function precompileJSON(string: Nullable<string>, options?: PrecompileOptions | PrecompileOptionsWithLexicalScope): [block: SerializedTemplateBlock, usedLocals: string[]];
export declare function precompile(source: string, options?: PrecompileOptions | PrecompileOptionsWithLexicalScope): TemplateJavascript;
export type { PrecompileOptions };
import type { ASTv2, SymbolTable } from '@glimmer/syntax';
import type { OptionalList } from '../../shared/list';
import type { Result } from '../../shared/result';
import type * as mir from '../2-encoding/mir';
/**
* This is the mutable state for this compiler pass.
*/
export declare class NormalizationState {
readonly isStrict: boolean;
_currentScope: SymbolTable;
_cursorCount: number;
constructor(block: SymbolTable, isStrict: boolean);
generateUniqueCursor(): string;
get scope(): SymbolTable;
visitBlock(block: ASTv2.Block): Result<OptionalList<mir.Statement>>;
}
import type { ASTv2, src } from '@glimmer/syntax';
import type { Result } from '../../shared/result';
import * as mir from '../2-encoding/mir';
/**
* Normalize the AST from @glimmer/syntax into the HIR. The HIR has special
* instructions for keywords like `{{yield}}`, `(has-block)` and
* `{{#in-element}}`.
*
* Most importantly, it also classifies HTML element syntax into:
*
* 1. simple HTML element (with optional splattributes)
* 2. component invocation
*
* Because the @glimmer/syntax AST gives us a string for an element's tag,
* this pass also normalizes that string into an expression.
*
* ```
* // normalized into a path expression whose head is `this` and tail is
* // `["x"]`
* <this.x />
*
* {{#let expr as |t|}}
* // `"t"` is normalized into a variable lookup.
* <t />
*
* // normalized into a path expression whose head is the variable lookup
* // `t` and tail is `["input"]`.
* <t.input />
* {{/let}}
*
* // normalized into a free variable lookup for `SomeComponent` (with the
* // context `ComponentHead`).
* <SomeComponent />
*
* // normalized into a path expression whose head is the free variable
* // `notInScope` (with the context `Expression`), and whose tail is
* // `["SomeComponent"]`. In resolver mode, this path will be rejected later,
* // since it cannot serve as an input to the resolver.
* <notInScope.SomeComponent />
* ```
*/
export default function normalize(source: src.Source, root: ASTv2.Template, isStrict: boolean): Result<mir.Template>;
export { APPEND_KEYWORDS } from './keywords/append';
export { BLOCK_KEYWORDS } from './keywords/block';
export { CALL_KEYWORDS } from './keywords/call';
export { MODIFIER_KEYWORDS } from './keywords/modifier';
export declare const APPEND_KEYWORDS: import("./impl").Keywords<"Append", never>;
export declare const BLOCK_KEYWORDS: import("./impl").Keywords<"Block", never>;
export declare const CALL_KEYWORDS: import("./impl").Keywords<"Call", never>;
import type { ASTv2, KeywordType } from '@glimmer/syntax';
import type { Result } from '../../../shared/result';
import type { NormalizationState } from '../context';
export interface KeywordDelegate<Match extends KeywordMatch, V, Out> {
assert: (options: Match, state: NormalizationState) => Result<V>;
translate: (options: {
node: Match;
state: NormalizationState;
}, param: V) => Result<Out>;
}
export interface Keyword<K extends KeywordType = KeywordType, Out = unknown> {
translate(node: KeywordCandidates[K], state: NormalizationState): Result<Out> | null;
}
export interface BlockKeyword<Out = unknown> {
translate(node: ASTv2.InvokeBlock, state: NormalizationState): Result<Out> | null;
}
export declare const KEYWORD_NODES: {
readonly Call: readonly ["Call"];
readonly Block: readonly ["InvokeBlock"];
readonly Append: readonly ["AppendContent"];
readonly Modifier: readonly ["ElementModifier"];
};
export interface KeywordCandidates {
Call: ASTv2.ExpressionNode;
Block: ASTv2.InvokeBlock;
Append: ASTv2.AppendContent;
Modifier: ASTv2.ElementModifier;
}
export type KeywordCandidate = KeywordCandidates[keyof KeywordCandidates];
export interface KeywordMatches {
Call: ASTv2.CallExpression;
Block: ASTv2.InvokeBlock;
Append: ASTv2.AppendContent;
Modifier: ASTv2.ElementModifier;
}
export type KeywordMatch = KeywordMatches[keyof KeywordMatches];
/**
* A "generic" keyword is something like `has-block`, which makes sense in the context
* of sub-expression or append
*/
export type GenericKeywordNode = ASTv2.AppendContent | ASTv2.CallExpression;
export type KeywordNode = GenericKeywordNode | ASTv2.CallExpression | ASTv2.InvokeBlock | ASTv2.ElementModifier;
export type PossibleKeyword = KeywordNode;
type OutFor<K extends Keyword | BlockKeyword> = K extends BlockKeyword<infer Out> ? Out : K extends Keyword<KeywordType, infer Out> ? Out : never;
export declare class Keywords<K extends KeywordType, KeywordList extends Keyword<K> = never> implements Keyword<K, OutFor<KeywordList>> {
_keywords: Keyword[];
_type: K;
constructor(type: K);
kw<V, S extends string = string, Out = unknown>(name: S, delegate: KeywordDelegate<KeywordMatches[K], V, Out>): this;
translate(node: KeywordCandidates[K], state: NormalizationState): Result<OutFor<KeywordList>> | null;
}
/**
* This function builds keyword definitions for a particular type of AST node (`KeywordType`).
*
* You can build keyword definitions for:
*
* - `Expr`: A `SubExpression` or `PathExpression`
* - `Block`: A `BlockStatement`
* - A `BlockStatement` is a keyword candidate if its head is a
* `PathExpression`
* - `Append`: An `AppendStatement`
*
* A node is a keyword candidate if:
*
* - A `PathExpression` is a keyword candidate if it has no tail, and its
* head expression is a `LocalVarHead` or `FreeVarHead` whose name is
* the keyword's name.
* - A `SubExpression`, `AppendStatement`, or `BlockStatement` is a keyword
* candidate if its head is a keyword candidate.
*
* The keyword infrastructure guarantees that:
*
* - If a node is not a keyword candidate, it is never passed to any keyword's
* `assert` method.
* - If a node is not the `KeywordType` for a particular keyword, it will not
* be passed to the keyword's `assert` method.
*
* `Expr` keywords are used in expression positions and should return HIR
* expressions. `Block` and `Append` keywords are used in statement
* positions and should return HIR statements.
*
* A keyword definition has two parts:
*
* - `match`, which determines whether an AST node matches the keyword, and can
* optionally return some information extracted from the AST node.
* - `translate`, which takes a matching AST node as well as the extracted
* information and returns an appropriate HIR instruction.
*
* # Example
*
* This keyword:
*
* - turns `(hello)` into `"hello"`
* - as long as `hello` is not in scope
* - makes it an error to pass any arguments (such as `(hello world)`)
*
* ```ts
* keywords('SubExpr').kw('hello', {
* assert(node: ExprKeywordNode): Result<void> | false {
* // we don't want to transform `hello` as a `PathExpression`
* if (node.type !== 'SubExpression') {
* return false;
* }
*
* // node.head would be `LocalVarHead` if `hello` was in scope
* if (node.head.type !== 'FreeVarHead') {
* return false;
* }
*
* if (node.params.length || node.hash) {
* return Err(generateSyntaxError(`(hello) does not take any arguments`), node.loc);
* } else {
* return Ok();
* }
* },
*
* translate(node: ASTv2.SubExpression): hir.Expression {
* return ASTv2.builders.literal("hello", node.loc)
* }
* })
* ```
*
* The keyword infrastructure checks to make sure that the node is the right
* type before calling `assert`, so you only need to consider `SubExpression`
* and `PathExpression` here. It also checks to make sure that the node passed
* to `assert` has the keyword name in the right place.
*
* Note the important difference between returning `false` from `assert`,
* which just means that the node didn't match, and returning `Err`, which
* means that the node matched, but there was a keyword-specific syntax
* error.
*/
export declare function keywords<K extends KeywordType>(type: K): Keywords<K>;
export {};
export declare const MODIFIER_KEYWORDS: import("./impl").Keywords<"Modifier", never>;
import type { GenericKeywordNode, KeywordDelegate } from '../impl';
import * as mir from '../../../2-encoding/mir';
export declare function toAppend<T>({ assert, translate, }: KeywordDelegate<GenericKeywordNode, T, mir.ExpressionNode>): KeywordDelegate<GenericKeywordNode, T, mir.AppendTextNode>;
import type { CurriedType } from '@glimmer/interfaces';
import { ASTv2 } from '@glimmer/syntax';
import type { NormalizationState } from '../../context';
import type { KeywordDelegate } from '../impl';
import { Result } from '../../../../shared/result';
import * as mir from '../../../2-encoding/mir';
export declare function assertCurryKeyword(curriedType: CurriedType): (node: ASTv2.AppendContent | ASTv2.InvokeBlock | ASTv2.CallExpression, state: NormalizationState) => Result<{
definition: ASTv2.ExpressionNode;
args: ASTv2.Args;
}>;
export declare function curryKeyword(curriedType: CurriedType): KeywordDelegate<ASTv2.CallExpression | ASTv2.AppendContent, {
definition: ASTv2.ExpressionNode;
args: ASTv2.Args;
}, mir.Curry>;
import type { ASTv2 } from '@glimmer/syntax';
import type { GenericKeywordNode, KeywordDelegate } from '../impl';
import * as mir from '../../../2-encoding/mir';
export declare const getDynamicVarKeyword: KeywordDelegate<GenericKeywordNode, ASTv2.ExpressionNode, mir.GetDynamicVar>;
import { ASTv2, SourceSlice } from '@glimmer/syntax';
import type { KeywordDelegate } from '../impl';
import * as mir from '../../../2-encoding/mir';
export declare function hasBlockKeyword(type: string): KeywordDelegate<ASTv2.CallExpression | ASTv2.AppendContent, SourceSlice, mir.HasBlock | mir.HasBlockParams>;
import type { ASTv2 } from '@glimmer/syntax';
import type { KeywordDelegate } from '../impl';
import * as mir from '../../../2-encoding/mir';
export declare function ifUnlessInlineKeyword(type: string): KeywordDelegate<ASTv2.CallExpression | ASTv2.AppendContent, {
condition: ASTv2.ExpressionNode;
truthy: ASTv2.ExpressionNode;
falsy: ASTv2.ExpressionNode | null;
}, mir.IfInline>;
import type { ASTv2 } from '@glimmer/syntax';
import type { KeywordDelegate } from '../impl';
import * as mir from '../../../2-encoding/mir';
export declare const logKeyword: KeywordDelegate<ASTv2.CallExpression | ASTv2.AppendContent, ASTv2.PositionalArguments, mir.Log>;
export type VALUE_RESOLUTION = 'value';
export declare const VALUE_RESOLUTION: VALUE_RESOLUTION;
export type COMPONENT_RESOLUTION = 'component';
export declare const COMPONENT_RESOLUTION: COMPONENT_RESOLUTION;
export type HELPER_RESOLUTION = 'helper';
export declare const HELPER_RESOLUTION: HELPER_RESOLUTION;
export type MODIFIER_RESOLUTION = 'modifier';
export declare const MODIFIER_RESOLUTION: MODIFIER_RESOLUTION;
export type COMPONENT_OR_HELPER_RESOLUTION = 'component or helper';
export declare const COMPONENT_OR_HELPER_RESOLUTION: COMPONENT_OR_HELPER_RESOLUTION;
export type ResolutionType = VALUE_RESOLUTION | COMPONENT_RESOLUTION | HELPER_RESOLUTION | MODIFIER_RESOLUTION | COMPONENT_OR_HELPER_RESOLUTION;
import { ASTv2 } from '@glimmer/syntax';
import type { NormalizationState } from '../../context';
import { Result } from '../../../../shared/result';
import * as mir from '../../../2-encoding/mir';
export type ValidAttr = mir.StaticAttr | mir.DynamicAttr | mir.SplatAttr;
export interface Classified {
readonly dynamicFeatures: boolean;
arg(attr: ASTv2.AttrNode, classified: ClassifiedElement): Result<mir.NamedArgument>;
toStatement(classified: ClassifiedElement, prepared: PreparedArgs): Result<mir.Statement>;
}
export declare class ClassifiedElement {
readonly element: ASTv2.ElementNode;
readonly state: NormalizationState;
readonly delegate: Classified;
constructor(element: ASTv2.ElementNode, delegate: Classified, state: NormalizationState);
toStatement(): Result<mir.Statement>;
private attr;
private modifier;
private attrs;
private prepare;
}
export interface PreparedArgs {
args: mir.NamedArguments;
params: mir.ElementParameters;
}
export declare function hasDynamicFeatures({ attrs, modifiers, }: Pick<ASTv2.ElementNode, 'attrs' | 'modifiers'>): boolean;
import type { ASTv2 } from '@glimmer/syntax';
import type { Result } from '../../../../shared/result';
import type { Classified, ClassifiedElement, PreparedArgs } from './classified';
import * as mir from '../../../2-encoding/mir';
export declare class ClassifiedComponent implements Classified {
private tag;
private element;
readonly dynamicFeatures = true;
constructor(tag: mir.ExpressionNode, element: ASTv2.InvokeComponent);
arg(attr: ASTv2.ComponentArg, { state }: ClassifiedElement): Result<mir.NamedArgument>;
toStatement(component: ClassifiedElement, { args, params }: PreparedArgs): Result<mir.Statement>;
private blocks;
}
import type { ASTv2, SourceSlice } from '@glimmer/syntax';
import type { Result } from '../../../../shared/result';
import type { Classified, ClassifiedElement, PreparedArgs } from './classified';
import * as mir from '../../../2-encoding/mir';
export declare class ClassifiedSimpleElement implements Classified {
private tag;
private element;
readonly dynamicFeatures: boolean;
constructor(tag: SourceSlice, element: ASTv2.SimpleElement, dynamicFeatures: boolean);
readonly isComponent = false;
arg(attr: ASTv2.ComponentArg): Result<mir.NamedArgument>;
toStatement(classified: ClassifiedElement, { params }: PreparedArgs): Result<mir.Statement>;
}
import type { PresentArray } from '@glimmer/interfaces';
import { ASTv2 } from '@glimmer/syntax';
import type { AnyOptionalList, PresentList } from '../../../shared/list';
import type { NormalizationState } from '../context';
import { Result } from '../../../shared/result';
import * as mir from '../../2-encoding/mir';
export declare class NormalizeExpressions {
visit(node: ASTv2.ExpressionNode, state: NormalizationState): Result<mir.ExpressionNode>;
visitList(nodes: PresentArray<ASTv2.ExpressionNode>, state: NormalizationState): Result<PresentList<mir.ExpressionNode>>;
visitList(nodes: readonly ASTv2.ExpressionNode[], state: NormalizationState): Result<AnyOptionalList<mir.ExpressionNode>>;
/**
* Normalize paths into `hir.Path` or a `hir.Expr` that corresponds to the ref.
*
* TODO since keywords don't support tails anyway, distinguish PathExpression from
* VariableReference in ASTv2.
*/
PathExpression(path: ASTv2.PathExpression): Result<mir.ExpressionNode>;
VariableReference(ref: ASTv2.VariableReference): ASTv2.VariableReference;
Literal(literal: ASTv2.LiteralExpression): ASTv2.LiteralExpression;
Keyword(keyword: ASTv2.KeywordExpression): ASTv2.KeywordExpression;
Interpolate(expr: ASTv2.InterpolateExpression, state: NormalizationState): Result<mir.InterpolateExpression>;
CallExpression(expr: ASTv2.CallExpression, state: NormalizationState): Result<mir.ExpressionNode>;
Args({ positional, named, loc }: ASTv2.Args, state: NormalizationState): Result<mir.Args>;
Positional(positional: ASTv2.PositionalArguments, state: NormalizationState): Result<mir.Positional>;
NamedArguments(named: ASTv2.NamedArguments, state: NormalizationState): Result<mir.NamedArguments>;
}
export declare function convertPathToCallIfKeyword(path: ASTv2.ExpressionNode): ASTv2.ExpressionNode;
export declare const VISIT_EXPRS: NormalizeExpressions;
import { ASTv2 } from '@glimmer/syntax';
import type { NormalizationState } from '../context';
import { OptionalList } from '../../../shared/list';
import { Result } from '../../../shared/result';
import * as mir from '../../2-encoding/mir';
declare class NormalizationStatements {
visitList(nodes: readonly ASTv2.ContentNode[], state: NormalizationState): Result<OptionalList<mir.Statement>>;
visit(node: ASTv2.ContentNode, state: NormalizationState): Result<mir.Statement | null>;
InvokeBlock(node: ASTv2.InvokeBlock, state: NormalizationState): Result<mir.Statement>;
NamedBlocks(blocks: ASTv2.NamedBlocks, state: NormalizationState): Result<mir.NamedBlocks>;
NamedBlock(named: ASTv2.NamedBlock, state: NormalizationState): Result<mir.NamedBlock>;
SimpleElement(element: ASTv2.SimpleElement, state: NormalizationState): Result<mir.Statement>;
Component(component: ASTv2.InvokeComponent, state: NormalizationState): Result<mir.Statement>;
AppendContent(append: ASTv2.AppendContent, state: NormalizationState): Result<mir.Statement>;
TextNode(text: ASTv2.HtmlText): mir.Statement;
HtmlComment(comment: ASTv2.HtmlComment): mir.Statement;
}
export declare const VISIT_STMTS: NormalizationStatements;
export {};
import type { HasSourceSpan } from '@glimmer/syntax';
import type { Result } from '../../../shared/result';
import type * as mir from '../../2-encoding/mir';
import type { ResolutionType } from './constants';
export default class StrictModeValidationPass {
private template;
static validate(template: mir.Template): Result<mir.Template>;
private constructor();
validate(): Result<mir.Template>;
Statements(statements: mir.Statement[]): Result<null>;
NamedBlocks({ blocks }: mir.NamedBlocks): Result<null>;
NamedBlock(block: mir.NamedBlock): Result<null>;
Statement(statement: mir.Statement): Result<null>;
Expressions(expressions: mir.ExpressionNode[]): Result<null>;
Expression(expression: mir.ExpressionNode, span?: HasSourceSpan, resolution?: ResolutionType): Result<null>;
Args(args: mir.Args): Result<null>;
Positional(positional: mir.Positional, span?: HasSourceSpan): Result<null>;
NamedArguments({ entries }: mir.NamedArguments): Result<null>;
NamedArgument(arg: mir.NamedArgument): Result<null>;
ElementParameters({ body }: mir.ElementParameters): Result<null>;
ElementParameter(param: mir.ElementParameter): Result<null>;
DynamicAttr(attr: mir.DynamicAttr): Result<null>;
Modifier(modifier: mir.Modifier): Result<null>;
InElement(inElement: mir.InElement): Result<null>;
Yield(statement: mir.Yield): Result<null>;
AppendTrustedHTML(statement: mir.AppendTrustedHTML): Result<null>;
AppendTextNode(statement: mir.AppendTextNode): Result<null>;
Component(statement: mir.Component): Result<null>;
SimpleElement(statement: mir.SimpleElement): Result<null>;
InvokeBlock(statement: mir.InvokeBlock): Result<null>;
If(statement: mir.If): Result<null>;
Each(statement: mir.Each): Result<null>;
Let(statement: mir.Let): Result<null>;
WithDynamicVars(statement: mir.WithDynamicVars): Result<null>;
InvokeComponent(statement: mir.InvokeComponent): Result<null>;
InterpolateExpression(expression: mir.InterpolateExpression, span: HasSourceSpan, resolution?: ResolutionType): Result<null>;
CallExpression(expression: mir.CallExpression, span: HasSourceSpan, resolution?: ResolutionType): Result<null>;
IfInline(expression: mir.IfInline): Result<null>;
Curry(expression: mir.Curry): Result<null>;
Log(expression: mir.Log): Result<null>;
errorFor(name: string, span: HasSourceSpan, type?: ResolutionType): Result<never>;
}
import type { WellKnownAttrName, WireFormat } from '@glimmer/interfaces';
import type { OptionalList } from '../../shared/list';
import type * as mir from './mir';
declare class WireStatements<S extends WireFormat.Statement = WireFormat.Statement> {
private statements;
constructor(statements: readonly S[]);
toArray(): readonly S[];
}
export declare class ContentEncoder {
list(statements: mir.Statement[]): WireFormat.Statement[];
content(stmt: mir.Statement): WireFormat.Statement | WireStatements;
private visitContent;
Yield({ to, positional }: mir.Yield): WireFormat.Statements.Yield;
InElement({ guid, insertBefore, destination, block, }: mir.InElement): WireFormat.Statements.InElement;
InvokeBlock({ head, args, blocks }: mir.InvokeBlock): WireFormat.Statements.Block;
AppendTrustedHTML({ html }: mir.AppendTrustedHTML): WireFormat.Statements.TrustingAppend;
AppendTextNode({ text }: mir.AppendTextNode): WireFormat.Statements.Append;
AppendComment({ value }: mir.AppendComment): WireFormat.Statements.Comment;
SimpleElement({ tag, params, body, dynamicFeatures }: mir.SimpleElement): WireStatements;
Component({ tag, params, args, blocks }: mir.Component): WireFormat.Statements.Component;
ElementParameters({ body }: mir.ElementParameters): OptionalList<WireFormat.ElementParameter>;
ElementParameter(param: mir.ElementParameter): WireFormat.ElementParameter;
NamedBlocks({ blocks }: mir.NamedBlocks): WireFormat.Core.Blocks;
NamedBlock({ name, body, scope }: mir.NamedBlock): WireFormat.Core.NamedBlock;
If({ condition, block, inverse }: mir.If): WireFormat.Statements.If;
Each({ value, key, block, inverse }: mir.Each): WireFormat.Statements.Each;
Let({ positional, block }: mir.Let): WireFormat.Statements.Let;
WithDynamicVars({ named, block }: mir.WithDynamicVars): WireFormat.Statements.WithDynamicVars;
InvokeComponent({ definition, args, blocks, }: mir.InvokeComponent): WireFormat.Statements.InvokeComponent;
}
export declare const CONTENT: ContentEncoder;
export type StaticAttrArgs = [name: string | WellKnownAttrName, value: string, namespace?: string];
export type DynamicAttrArgs = [
name: string | WellKnownAttrName,
value: WireFormat.Expression,
namespace?: string
];
export {};
import type { PresentArray, WireFormat } from '@glimmer/interfaces';
import type { ASTv2 } from '@glimmer/syntax';
import type * as mir from './mir';
export type HashPair = [string, WireFormat.Expression];
export declare class ExpressionEncoder {
expr(expr: mir.ExpressionNode): WireFormat.Expression;
Literal({ value, }: ASTv2.LiteralExpression): WireFormat.Expressions.Value | WireFormat.Expressions.Undefined;
Missing(): undefined;
HasBlock({ symbol }: mir.HasBlock): WireFormat.Expressions.HasBlock;
HasBlockParams({ symbol }: mir.HasBlockParams): WireFormat.Expressions.HasBlockParams;
Curry({ definition, curriedType, args }: mir.Curry): WireFormat.Expressions.Curry;
Local({ isTemplateLocal, symbol, }: ASTv2.LocalVarReference): WireFormat.Expressions.GetSymbol | WireFormat.Expressions.GetLexicalSymbol;
Keyword({ symbol }: ASTv2.KeywordExpression): WireFormat.Expressions.GetStrictFree;
PathExpression({ head, tail }: mir.PathExpression): WireFormat.Expressions.GetPath;
InterpolateExpression({ parts }: mir.InterpolateExpression): WireFormat.Expressions.Concat;
CallExpression({ callee, args }: mir.CallExpression): WireFormat.Expressions.Helper;
Tail({ members }: mir.Tail): PresentArray<string>;
Args({ positional, named }: mir.Args): WireFormat.Core.Args;
Positional({ list }: mir.Positional): WireFormat.Core.Params;
NamedArgument({ key, value }: mir.NamedArgument): HashPair;
NamedArguments({ entries: pairs }: mir.NamedArguments): WireFormat.Core.Hash;
Not({ value }: mir.Not): WireFormat.Expressions.Not;
IfInline({ condition, truthy, falsy }: mir.IfInline): WireFormat.Expressions.IfInline;
GetDynamicVar({ name }: mir.GetDynamicVar): WireFormat.Expressions.GetDynamicVar;
Log({ positional }: mir.Log): WireFormat.Expressions.Log;
}
export declare const EXPR: ExpressionEncoder;
import type { WireFormat } from '@glimmer/interfaces';
import type * as mir from './mir';
export declare function visit(template: mir.Template): WireFormat.SerializedTemplateBlock;
import type { CurriedType, PresentArray } from '@glimmer/interfaces';
import type { ASTv2, BlockSymbolTable, ProgramSymbolTable, SourceSlice, SymbolTable } from '@glimmer/syntax';
import type { AnyOptionalList, OptionalList, PresentList } from '../../shared/list';
declare const Template_base: ASTv2.TypedNodeConstructor<"Template", {
scope: ProgramSymbolTable;
body: Statement[];
} & ASTv2.BaseNodeFields>;
export declare class Template extends Template_base {
}
declare const InElement_base: ASTv2.TypedNodeConstructor<"InElement", {
guid: string;
insertBefore: ExpressionNode | Missing;
destination: ExpressionNode;
block: NamedBlock;
} & ASTv2.BaseNodeFields>;
export declare class InElement extends InElement_base {
}
declare const Not_base: ASTv2.TypedNodeConstructor<"Not", {
value: ExpressionNode;
} & ASTv2.BaseNodeFields>;
export declare class Not extends Not_base {
}
declare const If_base: ASTv2.TypedNodeConstructor<"If", {
condition: ExpressionNode;
block: NamedBlock;
inverse: NamedBlock | null;
} & ASTv2.BaseNodeFields>;
export declare class If extends If_base {
}
declare const IfInline_base: ASTv2.TypedNodeConstructor<"IfInline", {
condition: ExpressionNode;
truthy: ExpressionNode;
falsy: ExpressionNode | null;
} & ASTv2.BaseNodeFields>;
export declare class IfInline extends IfInline_base {
}
declare const Each_base: ASTv2.TypedNodeConstructor<"Each", {
value: ExpressionNode;
key: ExpressionNode | null;
block: NamedBlock;
inverse: NamedBlock | null;
} & ASTv2.BaseNodeFields>;
export declare class Each extends Each_base {
}
declare const Let_base: ASTv2.TypedNodeConstructor<"Let", {
positional: Positional;
block: NamedBlock;
} & ASTv2.BaseNodeFields>;
export declare class Let extends Let_base {
}
declare const WithDynamicVars_base: ASTv2.TypedNodeConstructor<"WithDynamicVars", {
named: NamedArguments;
block: NamedBlock;
} & ASTv2.BaseNodeFields>;
export declare class WithDynamicVars extends WithDynamicVars_base {
}
declare const GetDynamicVar_base: ASTv2.TypedNodeConstructor<"GetDynamicVar", {
name: ExpressionNode;
} & ASTv2.BaseNodeFields>;
export declare class GetDynamicVar extends GetDynamicVar_base {
}
declare const Log_base: ASTv2.TypedNodeConstructor<"Log", {
positional: Positional;
} & ASTv2.BaseNodeFields>;
export declare class Log extends Log_base {
}
declare const InvokeComponent_base: ASTv2.TypedNodeConstructor<"InvokeComponent", {
definition: ExpressionNode;
args: Args;
blocks: NamedBlocks | null;
} & ASTv2.BaseNodeFields>;
export declare class InvokeComponent extends InvokeComponent_base {
}
declare const NamedBlocks_base: ASTv2.TypedNodeConstructor<"NamedBlocks", {
blocks: OptionalList<NamedBlock>;
} & ASTv2.BaseNodeFields>;
export declare class NamedBlocks extends NamedBlocks_base {
}
declare const NamedBlock_base: ASTv2.TypedNodeConstructor<"NamedBlock", {
scope: BlockSymbolTable;
name: SourceSlice;
body: Statement[];
} & ASTv2.BaseNodeFields>;
export declare class NamedBlock extends NamedBlock_base {
}
declare const AppendTrustedHTML_base: ASTv2.TypedNodeConstructor<"AppendTrustedHTML", {
html: ExpressionNode;
} & ASTv2.BaseNodeFields>;
export declare class AppendTrustedHTML extends AppendTrustedHTML_base {
}
declare const AppendTextNode_base: ASTv2.TypedNodeConstructor<"AppendTextNode", {
text: ExpressionNode;
} & ASTv2.BaseNodeFields>;
export declare class AppendTextNode extends AppendTextNode_base {
}
declare const AppendComment_base: ASTv2.TypedNodeConstructor<"AppendComment", {
value: SourceSlice;
} & ASTv2.BaseNodeFields>;
export declare class AppendComment extends AppendComment_base {
}
declare const Component_base: ASTv2.TypedNodeConstructor<"Component", {
tag: ExpressionNode;
params: ElementParameters;
args: NamedArguments;
blocks: NamedBlocks;
} & ASTv2.BaseNodeFields>;
export declare class Component extends Component_base {
}
export interface AttrKind {
trusting: boolean;
component: boolean;
}
declare const StaticAttr_base: ASTv2.TypedNodeConstructor<"StaticAttr", {
kind: {
component: boolean;
};
name: SourceSlice;
value: SourceSlice;
namespace?: string | undefined;
} & ASTv2.BaseNodeFields>;
export declare class StaticAttr extends StaticAttr_base {
}
declare const DynamicAttr_base: ASTv2.TypedNodeConstructor<"DynamicAttr", {
kind: AttrKind;
name: SourceSlice;
value: ExpressionNode;
namespace?: string | undefined;
} & ASTv2.BaseNodeFields>;
export declare class DynamicAttr extends DynamicAttr_base {
}
declare const SimpleElement_base: ASTv2.TypedNodeConstructor<"SimpleElement", {
tag: SourceSlice;
params: ElementParameters;
body: Statement[];
dynamicFeatures: boolean;
} & ASTv2.BaseNodeFields>;
export declare class SimpleElement extends SimpleElement_base {
}
declare const ElementParameters_base: ASTv2.TypedNodeConstructor<"ElementParameters", {
body: AnyOptionalList<ElementParameter>;
} & ASTv2.BaseNodeFields>;
export declare class ElementParameters extends ElementParameters_base {
}
declare const Yield_base: ASTv2.TypedNodeConstructor<"Yield", {
target: SourceSlice;
to: number;
positional: Positional;
} & ASTv2.BaseNodeFields>;
export declare class Yield extends Yield_base {
}
declare const Debugger_base: ASTv2.TypedNodeConstructor<"Debugger", {
scope: SymbolTable;
} & ASTv2.BaseNodeFields>;
export declare class Debugger extends Debugger_base {
}
declare const CallExpression_base: ASTv2.TypedNodeConstructor<"CallExpression", {
callee: ExpressionNode;
args: Args;
} & ASTv2.BaseNodeFields>;
export declare class CallExpression extends CallExpression_base {
}
declare const Modifier_base: ASTv2.TypedNodeConstructor<"Modifier", {
callee: ExpressionNode;
args: Args;
} & ASTv2.BaseNodeFields>;
export declare class Modifier extends Modifier_base {
}
declare const InvokeBlock_base: ASTv2.TypedNodeConstructor<"InvokeBlock", {
head: ExpressionNode;
args: Args;
blocks: NamedBlocks;
} & ASTv2.BaseNodeFields>;
export declare class InvokeBlock extends InvokeBlock_base {
}
declare const SplatAttr_base: ASTv2.TypedNodeConstructor<"SplatAttr", {
symbol: number;
} & ASTv2.BaseNodeFields>;
export declare class SplatAttr extends SplatAttr_base {
}
declare const PathExpression_base: ASTv2.TypedNodeConstructor<"PathExpression", {
head: ExpressionNode;
tail: Tail;
} & ASTv2.BaseNodeFields>;
export declare class PathExpression extends PathExpression_base {
}
declare const Missing_base: ASTv2.TypedNodeConstructor<"Missing", object & ASTv2.BaseNodeFields>;
export declare class Missing extends Missing_base {
}
declare const InterpolateExpression_base: ASTv2.TypedNodeConstructor<"InterpolateExpression", {
parts: PresentList<ExpressionNode>;
} & ASTv2.BaseNodeFields>;
export declare class InterpolateExpression extends InterpolateExpression_base {
}
declare const HasBlock_base: ASTv2.TypedNodeConstructor<"HasBlock", {
target: SourceSlice;
symbol: number;
} & ASTv2.BaseNodeFields>;
export declare class HasBlock extends HasBlock_base {
}
declare const HasBlockParams_base: ASTv2.TypedNodeConstructor<"HasBlockParams", {
target: SourceSlice;
symbol: number;
} & ASTv2.BaseNodeFields>;
export declare class HasBlockParams extends HasBlockParams_base {
}
declare const Curry_base: ASTv2.TypedNodeConstructor<"Curry", {
definition: ExpressionNode;
curriedType: CurriedType;
args: Args;
} & ASTv2.BaseNodeFields>;
export declare class Curry extends Curry_base {
}
declare const Positional_base: ASTv2.TypedNodeConstructor<"Positional", {
list: OptionalList<ExpressionNode>;
} & ASTv2.BaseNodeFields>;
export declare class Positional extends Positional_base {
}
declare const NamedArguments_base: ASTv2.TypedNodeConstructor<"NamedArguments", {
entries: OptionalList<NamedArgument>;
} & ASTv2.BaseNodeFields>;
export declare class NamedArguments extends NamedArguments_base {
}
declare const NamedArgument_base: ASTv2.TypedNodeConstructor<"NamedArgument", {
key: SourceSlice;
value: ExpressionNode;
} & ASTv2.BaseNodeFields>;
export declare class NamedArgument extends NamedArgument_base {
}
declare const Args_base: ASTv2.TypedNodeConstructor<"Args", {
positional: Positional;
named: NamedArguments;
} & ASTv2.BaseNodeFields>;
export declare class Args extends Args_base {
}
declare const Tail_base: ASTv2.TypedNodeConstructor<"Tail", {
members: PresentArray<SourceSlice>;
} & ASTv2.BaseNodeFields>;
export declare class Tail extends Tail_base {
}
export type ExpressionNode = ASTv2.LiteralExpression | ASTv2.KeywordExpression | ASTv2.VariableReference | Missing | PathExpression | InterpolateExpression | CallExpression | Not | IfInline | HasBlock | HasBlockParams | Curry | GetDynamicVar | Log;
export type ElementParameter = StaticAttr | DynamicAttr | Modifier | SplatAttr;
export type Internal = Args | Positional | NamedArguments | NamedArgument | Tail | NamedBlock | NamedBlocks | ElementParameters;
export type ExprLike = ExpressionNode | Internal;
export type Statement = InElement | Debugger | Yield | AppendTrustedHTML | AppendTextNode | Component | SimpleElement | InvokeBlock | AppendComment | If | Each | Let | WithDynamicVars | InvokeComponent;
export {};
import type { Nullable, PresentArray } from '@glimmer/interfaces';
export interface OptionalList<T> {
map<U>(callback: (input: T) => U): MapList<T, U, AnyOptionalList<T>>;
filter<S extends T>(predicate: (value: T, index: number, array: T[]) => value is S): AnyOptionalList<S>;
toArray(): T[];
toPresentArray(): Nullable<PresentArray<T>>;
into<U, V>(options: {
ifPresent: (array: PresentList<T>) => U;
ifEmpty: () => V;
}): U | V;
}
export declare class PresentList<T> implements OptionalList<T> {
readonly list: PresentArray<T>;
constructor(list: PresentArray<T>);
toArray(): PresentArray<T>;
map<U>(callback: (input: T) => U): MapList<T, U, PresentList<T>>;
filter<S extends T>(predicate: (value: T) => value is S): AnyOptionalList<S>;
toPresentArray(): PresentArray<T>;
into<U, V>({ ifPresent }: {
ifPresent: (array: PresentList<T>) => U;
ifEmpty: () => V;
}): U | V;
}
export declare class EmptyList<T> implements OptionalList<T> {
readonly list: T[];
map<U>(_callback: (input: T) => U): MapList<T, U, EmptyList<T>>;
filter<S extends T>(_predicate: (value: T) => value is S): AnyOptionalList<S>;
toArray(): T[];
toPresentArray(): Nullable<PresentArray<T>>;
into<U, V>({ ifEmpty }: {
ifPresent: (array: PresentList<T>) => U;
ifEmpty: () => V;
}): U | V;
}
export declare function OptionalList<T>(value: readonly T[]): AnyOptionalList<T>;
export type AnyOptionalList<T> = (PresentList<T> | EmptyList<T>) & OptionalList<T>;
export type MapList<T, U, L extends OptionalList<T>> = L extends PresentList<T> ? PresentList<U> : L extends EmptyList<T> ? EmptyList<U> : never;
import type { GlimmerSyntaxError } from '@glimmer/syntax';
import type { AnyOptionalList } from './list';
declare abstract class ResultImpl<T> {
static all<T extends Result<unknown>[]>(...results: T): MapAll<T>;
abstract mapOk<U>(callback: (value: T) => U): Result<U>;
abstract readonly isOk: boolean;
abstract readonly isErr: boolean;
}
export declare const Result: typeof ResultImpl;
declare class OkImpl<T> extends ResultImpl<T> {
readonly value: T;
readonly isOk = true;
readonly isErr = false;
constructor(value: T);
expect(_message?: string): T;
ifOk(callback: (value: T) => void): this;
andThen<U>(callback: (value: T) => Result<U>): Result<U>;
mapOk<U>(callback: (value: T) => U): Result<U>;
ifErr(_callback: (value: GlimmerSyntaxError) => void): this;
mapErr(_callback: (value: GlimmerSyntaxError) => GlimmerSyntaxError): Result<T>;
}
declare class ErrImpl<T> extends ResultImpl<T> {
readonly reason: GlimmerSyntaxError;
readonly isOk = false;
readonly isErr = true;
constructor(reason: GlimmerSyntaxError);
expect(message?: string): T;
andThen<U>(_callback: (value: T) => Result<U>): Result<U>;
mapOk<U>(_callback: (value: T) => U): Result<U>;
ifOk(_callback: (value: T) => void): this;
mapErr(callback: (value: GlimmerSyntaxError) => GlimmerSyntaxError): Result<T>;
ifErr(callback: (value: GlimmerSyntaxError) => void): this;
cast<U>(): Result<U>;
}
export declare function isResult<T>(input: MaybeResult<T>): input is Result<T>;
export declare function intoResult<T>(input: MaybeResult<T>): Result<T>;
export type Result<T> = OkImpl<T> | ErrImpl<T>;
type MapAllOk<T extends Result<unknown>[]> = {
[P in keyof T]: T[P] extends Result<infer Inner> ? Inner : never;
};
type MapAll<T extends Result<unknown>[]> = Result<MapAllOk<T>>;
export declare function Ok<T>(value: T): Result<T>;
export type Ok<T> = OkImpl<T>;
export declare function Err<T>(reason: GlimmerSyntaxError): Result<T>;
export type Err<T> = ErrImpl<T>;
export type MaybeResult<T> = T | Result<T>;
export declare class MapIntoResultArray<T> {
private items;
constructor(items: T[]);
map<U>(mapper: (item: T) => Result<U>): Result<U[]>;
}
export declare class ResultArray<T> {
private items;
constructor(items?: Result<T>[]);
add(item: Result<T>): void;
toArray(): Result<T[]>;
toOptionalList(): Result<AnyOptionalList<T>>;
}
export {};
import type { WellKnownAttrName, WellKnownTagName } from '@glimmer/interfaces';
export declare function getAttrNamespace(attrName: string): string | undefined;
export declare function deflateTagName(tagName: string): string | WellKnownTagName;
export declare function inflateTagName(tagName: string | WellKnownTagName): string;
export declare function deflateAttrName(attrName: string): string | WellKnownAttrName;
export declare function inflateAttrName(attrName: string | WellKnownAttrName): string;
import type { SerializedTemplateBlock, WireFormat } from '@glimmer/interfaces';
export default class WireFormatDebugger {
private upvars;
private symbols;
constructor([_statements, symbols, upvars]: SerializedTemplateBlock);
format(program: SerializedTemplateBlock): unknown;
formatOpcode(opcode: WireFormat.Syntax): unknown;
private formatCurryType;
private formatElementParams;
private formatParams;
private formatHash;
private formatBlocks;
private formatBlock;
}