New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@glimmer/compiler

Package Overview
Dependencies
Maintainers
15
Versions
301
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

to
0.94.5

1751

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 };

12

package.json
{
"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 @@ },