@glimmer/syntax
- Version 0.84.3
- Published
- 4.07 MB
- 4 dependencies
- MIT license
Install
npm i @glimmer/syntax
yarn add @glimmer/syntax
pnpm add @glimmer/syntax
Overview
Overview not available.
Index
Variables
Functions
Classes
Interfaces
Type Aliases
Namespaces
AST
- AtHead
- AttrNode
- AttrValue
- BaseNode
- Block
- BlockStatement
- BlockSymbols
- BooleanLiteral
- Call
- CallNode
- CallParts
- CommentStatement
- CommonProgram
- ConcatStatement
- ElementModifierStatement
- ElementName
- ElementNode
- EntityEncodingState
- Expression
- ExpressionName
- Expressions
- FreeVarHead
- Hash
- HashPair
- Literal
- LiteralName
- LocalVarHead
- MinimalPathExpression
- MustacheCommentStatement
- MustacheStatement
- NamedBlockName
- Node
- Nodes
- NodeType
- NullLiteral
- NumberLiteral
- PartialStatement
- PathExpression
- PathHead
- Position
- PossiblyDeprecatedBlock
- Program
- ProgramSymbols
- SharedNodes
- SourceLocation
- SourcePosition
- Statement
- StatementName
- Statements
- StringLiteral
- StripFlags
- SubExpression
- Symbols
- Template
- TextNode
- ThisHead
- TopLevelStatement
- UndefinedLiteral
- VarHead
ASTv1
- AtHead
- AttrNode
- AttrValue
- BaseNode
- Block
- BlockStatement
- BlockSymbols
- BooleanLiteral
- Call
- CallNode
- CallParts
- CommentStatement
- CommonProgram
- ConcatStatement
- ElementModifierStatement
- ElementName
- ElementNode
- EntityEncodingState
- Expression
- ExpressionName
- Expressions
- FreeVarHead
- Hash
- HashPair
- Literal
- LiteralName
- LocalVarHead
- MinimalPathExpression
- MustacheCommentStatement
- MustacheStatement
- NamedBlockName
- Node
- Nodes
- NodeType
- NullLiteral
- NumberLiteral
- PartialStatement
- PathExpression
- PathHead
- Position
- PossiblyDeprecatedBlock
- Program
- ProgramSymbols
- SharedNodes
- SourceLocation
- SourcePosition
- Statement
- StatementName
- Statements
- StringLiteral
- StripFlags
- SubExpression
- Symbols
- Template
- TextNode
- ThisHead
- TopLevelStatement
- UndefinedLiteral
- VarHead
ASTv2
- AppendContent
- ArgReference
- Args
- ARGUMENT_RESOLUTION
- AttrBlockNode
- AttrNode
- AttrNodeOptions
- BaseNodeFields
- Block
- CallExpression
- CallFields
- CallNode
- ComponentArg
- ContentNode
- DeprecatedCallExpression
- ElementModifier
- ElementNode
- ExpressionNode
- FreeVarNamespace
- FreeVarReference
- FreeVarResolution
- GlimmerComment
- GlimmerParentNodeOptions
- HtmlAttr
- HtmlComment
- HtmlOrSplatAttr
- HtmlText
- InterpolateExpression
- InvokeBlock
- InvokeComponent
- isLiteral()
- LiteralExpression
- LiteralTypes
- LiteralValue
- loadResolution()
- LocalVarReference
- LooseModeResolution
- NamedArgument
- NamedArguments
- NamedBlock
- NamedBlockFields
- NamedBlocks
- node()
- NodeConstructor
- PathExpression
- PositionalArguments
- SerializedBaseNode
- SerializedResolution
- SimpleElement
- SplatAttr
- STRICT_RESOLUTION
- StrictResolution
- StringLiteral
- Template
- ThisReference
- TypedNodeConstructor
- VariableReference
Variables
variable builders
const builders: { mustache: typeof buildMustache; block: typeof buildBlock; partial: typeof buildPartial; 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; blockName: typeof buildNamedBlockName; string: (value: string) => ASTv1.StringLiteral; boolean: (value: boolean) => ASTv1.BooleanLiteral; number: (value: number) => ASTv1.NumberLiteral; undefined(): ASTv1.UndefinedLiteral; null(): ASTv1.NullLiteral;};
variable KEYWORDS_TYPES
const KEYWORDS_TYPES: { [key: string]: KeywordType[] };
This includes the full list of keywords currently in use in the template language, and where their valid usages are.
Functions
function cannotRemoveNode
cannotRemoveNode: ( node: ASTv1.Node, parent: ASTv1.Node, key: string) => TraversalError;
function cannotReplaceNode
cannotReplaceNode: ( node: ASTv1.Node, parent: ASTv1.Node, key: string) => TraversalError;
function generateSyntaxError
generateSyntaxError: ( message: string, location: SourceSpan) => GlimmerSyntaxError;
function getTemplateLocals
getTemplateLocals: ( html: string, options?: GetTemplateLocalsOptions) => string[];
Parses and traverses a given handlebars html template to extract all template locals referenced that could possible come from the parent scope. Can exclude known keywords optionally.
function hasSpan
hasSpan: (span: MaybeHasSourceSpan) => span is HasSourceSpan;
function isKeyword
isKeyword: (word: string) => boolean;
function loc
loc: (span: HasSourceSpan) => SourceSpan;
function maybeLoc
maybeLoc: (location: MaybeHasSourceSpan, fallback: SourceSpan) => SourceSpan;
function node
node: { (): { fields<Fields extends object>(): NodeConstructor<Fields & BaseNodeFields>; }; <T extends string>(name: T): { fields<Fields extends object>(): TypedNodeConstructor< T, Fields & BaseNodeFields >; };};
This is a convenience function for creating ASTv2 nodes, with an optional name and the node's options.
export class HtmlText extends node('HtmlText').fields<{ chars: string }>() {}This creates a new ASTv2 node with the name
'HtmlText'
and one fieldchars: string
(in addition to aloc: SourceOffsets
field, which all nodes have).export class Args extends node().fields<{positional: PositionalArguments;named: NamedArguments}>() {}This creates a new un-named ASTv2 node with two fields (
positional: Positional
and `named: Named, in addition to the generic
loc: SourceOffsets` field).Once you create a node using
node
, it is instantiated with all of its fields (includingloc
):new HtmlText({ loc: offsets, chars: someString });
function normalize
normalize: ( source: Source, options?: PrecompileOptions) => [ast: ASTv2.Template, locals: string[]];
function preprocess
preprocess: ( input: string | Source | HBS.Program, options?: PreprocessOptions) => ASTv1.Template;
function print
print: (ast: ASTv1.Node, options?: PrinterOptions) => string;
function sortByLoc
sortByLoc: (a: ASTv1.Node, b: ASTv1.Node) => -1 | 0 | 1;
function traverse
traverse: (node: ASTv1.Node, visitor: NodeVisitor) => void;
Classes
class BlockSymbolTable
class BlockSymbolTable extends SymbolTable {}
constructor
constructor(parent: SymbolTable, symbols: string[], slots: number[]);
property locals
readonly locals: string[];
property slots
slots: number[];
property symbols
symbols: string[];
method allocate
allocate: (identifier: string) => number;
method allocateBlock
allocateBlock: (name: string) => number;
method allocateFree
allocateFree: (name: string, resolution: ASTv2.FreeVarResolution) => number;
method allocateNamed
allocateNamed: (name: string) => number;
method get
get: (name: string) => [number, boolean];
method getEvalInfo
getEvalInfo: () => Core.EvalInfo;
method getLocalsMap
getLocalsMap: () => Dict<number>;
method has
has: (name: string) => boolean;
method setHasEval
setHasEval: () => void;
class Path
class Walker {}
constructor
constructor(order?: {});
property order
order?: {};
property stack
stack: unknown[];
method children
children: <N extends ASTv1.Node>( node: N & ASTv1.Node, callback: NodeCallback<N & ASTv1.Node>) => void;
method visit
visit: <N extends ASTv1.Node>( node: Option<N>, callback: NodeCallback<N>) => void;
class ProgramSymbolTable
class ProgramSymbolTable extends SymbolTable {}
constructor
constructor( templateLocals: string[], customizeComponentName: (input: string) => string);
property hasEval
readonly hasEval: boolean;
property symbols
symbols: string[];
property upvars
upvars: string[];
method allocate
allocate: (identifier: string) => number;
method allocateBlock
allocateBlock: (name: string) => number;
method allocateFree
allocateFree: (name: string, resolution: ASTv2.FreeVarResolution) => number;
method allocateNamed
allocateNamed: (name: string) => number;
method get
get: (name: string) => [number, boolean];
method getEvalInfo
getEvalInfo: () => Core.EvalInfo;
method getLocalsMap
getLocalsMap: () => Dict<number>;
method getUsedTemplateLocals
getUsedTemplateLocals: () => string[];
method has
has: (name: string) => boolean;
method setHasEval
setHasEval: () => void;
class Source
class Source {}
constructor
constructor(source: string, module?: string);
property module
readonly module: string;
property source
readonly source: string;
method charPosFor
charPosFor: (position: SourcePosition) => number | null;
method check
check: (offset: number) => boolean;
Validate that the character offset represents a position in the source string.
method hbsPosFor
hbsPosFor: (offset: number) => Option<SourcePosition>;
method offsetFor
offsetFor: (line: number, column: number) => SourceOffset;
method slice
slice: (start: number, end: number) => string;
method spanFor
spanFor: ({ start, end }: Readonly<SourceLocation>) => SourceSpan;
class SourceSlice
class SourceSlice<Chars extends string = string> {}
constructor
constructor(options: { loc: SourceSpan; chars: Chars });
property chars
readonly chars: string;
property loc
readonly loc: SourceSpan;
method getString
getString: () => string;
method load
static load: ( source: Source, slice: SerializedSourceSlice<string>) => SourceSlice;
method serialize
serialize: () => SerializedSourceSlice<Chars>;
method synthetic
static synthetic: <S extends string>(chars: S) => SourceSlice<S>;
class SourceSpan
class SourceSpan implements SourceLocation {}
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 containsSourceLocation
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 newSourceSpan
with a different starting or ending offsetAll SourceSpan objects implement
SourceLocation
, for compatibility. All SourceSpan objects have atoJSON
that emitsSourceLocation
, also for compatibility.For compatibility, subclasses of
AbstractSourceSpan
must implementlocDidUpdate
, which happens when an AST plugin attempts to modify thestart
orend
of a span directly.The goal is to avoid creating any problems for use-cases like AST Explorer.
constructor
constructor(data: SpanData & AnySpan);
property end
end: SourcePosition;
For compatibility with SourceLocation in AST plugins
Deprecated
use endPosition instead
property endPosition
readonly endPosition: SourcePosition;
Get the ending
SourcePosition
for thisSourceSpan
, lazily computing it if needed.
property isInvisible
readonly isInvisible: boolean;
property loc
readonly loc: SourceLocation;
property module
readonly module: string;
property NON_EXISTENT
static readonly NON_EXISTENT: SourceSpan;
property source
readonly source: string;
For compatibility with SourceLocation in AST plugins
Deprecated
use module instead
property start
start: SourcePosition;
For compatibility with SourceLocation in AST plugins
Deprecated
use startPosition instead
property startPosition
readonly startPosition: SourcePosition;
Get the starting
SourcePosition
for thisSourceSpan
, lazily computing it if needed.
method asString
asString: () => string;
method broken
static broken: (pos?: SourceLocation) => SourceSpan;
method collapse
collapse: (where: 'start' | 'end') => SourceSpan;
method extend
extend: (other: SourceSpan) => SourceSpan;
method forCharPositions
static forCharPositions: ( source: Source, startPos: number, endPos: number) => SourceSpan;
method forHbsLoc
static forHbsLoc: (source: Source, loc: SourceLocation) => SourceSpan;
method getEnd
getEnd: () => SourceOffset;
method getStart
getStart: () => SourceOffset;
method load
static load: (source: Source, serialized: SerializedSourceSpan) => SourceSpan;
method serialize
serialize: () => SerializedSourceSpan;
method slice
slice: ({ skipStart, skipEnd,}: { skipStart?: number; skipEnd?: number;}) => SourceSpan;
method sliceEndChars
sliceEndChars: ({ skipEnd, chars,}: { skipEnd?: number; chars: number;}) => SourceSpan;
method sliceStartChars
sliceStartChars: ({ skipStart, chars,}: { skipStart?: number; chars: number;}) => SourceSpan;
method synthetic
static synthetic: (chars: string) => SourceSpan;
method toJSON
toJSON: () => SourceLocation;
Support converting ASTv1 nodes into a serialized format using JSON.stringify.
method toSlice
toSlice: (expected?: string) => SourceSlice;
Convert this
SourceSpan
into aSourceSlice
. In debug mode, this method optionally checks that the byte offsets represented by thisSourceSpan
actually correspond to the expected string.
method withEnd
withEnd: (this: SourceSpan, other: SourceOffset) => SourceSpan;
Create a new span with the current span's beginning and a new ending.
method withStart
withStart: (other: SourceOffset) => SourceSpan;
Create a new span with the current span's end and a new beginning.
class SpanList
class SpanList {}
constructor
constructor(span?: SourceSpan[]);
method add
add: (offset: SourceSpan) => void;
method getRangeOffset
getRangeOffset: (fallback: SourceSpan) => SourceSpan;
method range
static range: { (span: PresentArray<HasSourceSpan>): SourceSpan; (span: HasSourceSpan[], fallback: SourceSpan): SourceSpan;};
class SymbolTable
abstract class SymbolTable {}
method allocate
abstract allocate: (identifier: string) => number;
method allocateBlock
abstract allocateBlock: (name: string) => number;
method allocateFree
abstract allocateFree: ( name: string, resolution: ASTv2.FreeVarResolution) => number;
method allocateNamed
abstract allocateNamed: (name: string) => number;
method child
child: (locals: string[]) => BlockSymbolTable;
method get
abstract get: (name: string) => [symbol: number, isRoot: boolean];
method getEvalInfo
abstract getEvalInfo: () => Core.EvalInfo;
method getLocalsMap
abstract getLocalsMap: () => Dict<number>;
method has
abstract has: (name: string) => boolean;
method setHasEval
abstract setHasEval: () => void;
method top
static top: ( locals: string[], customizeComponentName: (input: string) => string) => ProgramSymbolTable;
class Walker
class Walker {}
constructor
constructor(order?: {});
property order
order?: {};
property stack
stack: unknown[];
method children
children: <N extends ASTv1.Node>( node: N & ASTv1.Node, callback: NodeCallback<N & ASTv1.Node>) => void;
method visit
visit: <N extends ASTv1.Node>( node: Option<N>, callback: NodeCallback<N>) => void;
class WalkerPath
class WalkerPath<N extends ASTv1.Node> {}
constructor
constructor( node: ASTv1.Node, parent?: WalkerPath<ASTv1.Node>, parentKey?: string);
property node
node: ASTv1.Node;
property parent
parent: WalkerPath<ASTv1.Node>;
property parentKey
parentKey: string;
property parentNode
readonly parentNode: ASTv1.Node;
method parents
parents: () => Iterable<WalkerPath<ASTv1.Node> | null>;
Interfaces
interface ASTPlugin
interface ASTPlugin {}
interface ASTPluginBuilder
interface ASTPluginBuilder< TEnv extends ASTPluginEnvironment = ASTPluginEnvironment> {}
ASTPlugins can make changes to the Glimmer template AST before compilation begins.
call signature
(env: TEnv): ASTPlugin;
interface ASTPluginEnvironment
interface ASTPluginEnvironment {}
interface GlimmerSyntaxError
interface GlimmerSyntaxError extends Error {}
interface PrecompileOptions
interface PrecompileOptions extends PreprocessOptions {}
property id
id?: TemplateIdFn;
method customizeComponentName
customizeComponentName: (input: string) => string;
interface PreprocessOptions
interface PreprocessOptions {}
property locals
locals?: string[];
property meta
meta?: { moduleName?: string;};
property mode
mode?: 'codemod' | 'precompile';
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.
property parseOptions
parseOptions?: HandlebarsParseOptions;
property plugins
plugins?: { ast?: ASTPluginBuilder[];};
property strictMode
strictMode?: boolean;
method customizeComponentName
customizeComponentName: (input: string) => string;
interface Syntax
interface Syntax {}
interface TemplateIdFn
interface TemplateIdFn {}
call signature
(src: string): Option<string>;
Type Aliases
type HasSourceSpan
type HasSourceSpan = | { loc: SourceSpan; } | SourceSpan | [HasSourceSpan, ...HasSourceSpan[]];
type KeywordType
type KeywordType = 'Call' | 'Modifier' | 'Append' | 'Block';
type MaybeHasSourceSpan
type MaybeHasSourceSpan = | { loc: SourceSpan; } | SourceSpan | MaybeHasSourceSpan[];
type NodeVisitor
type NodeVisitor = { [P in keyof ASTv1.Nodes]?: NodeTraversal<ASTv1.Nodes[P]>;} & { All?: NodeTraversal<ASTv1.Node>;};
Namespaces
namespace AST
module 'dist/types/lib/v1/api.d.ts' {}
interface AtHead
interface AtHead {}
interface AttrNode
interface AttrNode extends BaseNode {}
interface BlockStatement
interface BlockStatement extends BaseNode {}
property chained
chained?: boolean;
property closeStrip
closeStrip: StripFlags;
property hash
hash: Hash;
property inverse
inverse?: Option<Block>;
property inverseStrip
inverseStrip: StripFlags;
property openStrip
openStrip: StripFlags;
property params
params: Expression[];
property path
path: Expression;
property program
program: Block;
property type
type: 'BlockStatement';
interface BlockSymbols
interface BlockSymbols extends Symbols {}
property slots
slots: number[];
interface BooleanLiteral
interface BooleanLiteral extends BaseNode {}
interface Call
interface Call extends BaseNode {}
interface CallParts
interface CallParts {}
interface CommentStatement
interface CommentStatement extends BaseNode {}
interface CommonProgram
interface CommonProgram extends BaseNode {}
property blockParams
blockParams: string[];
property body
body: Statement[];
property chained
chained?: boolean;
interface ConcatStatement
interface ConcatStatement extends BaseNode {}
interface ElementModifierStatement
interface ElementModifierStatement extends BaseNode {}
interface ElementName
interface ElementName {}
interface ElementNode
interface ElementNode extends BaseNode {}
property attributes
attributes: AttrNode[];
property blockParams
blockParams: string[];
property children
children: Statement[];
property comments
comments: MustacheCommentStatement[];
property modifiers
modifiers: ElementModifierStatement[];
property selfClosing
selfClosing: boolean;
property tag
tag: string;
property type
type: 'ElementNode';
interface FreeVarHead
interface FreeVarHead {}
interface Hash
interface Hash extends BaseNode {}
interface HashPair
interface HashPair extends BaseNode {}
interface LocalVarHead
interface LocalVarHead {}
interface MinimalPathExpression
interface MinimalPathExpression extends BaseNode {}
interface MustacheCommentStatement
interface MustacheCommentStatement extends BaseNode {}
interface MustacheStatement
interface MustacheStatement extends BaseNode {}
interface NamedBlockName
interface NamedBlockName {}
interface NullLiteral
interface NullLiteral extends BaseNode {}
interface NumberLiteral
interface NumberLiteral extends BaseNode {}
interface PartialStatement
interface PartialStatement extends BaseNode {}
interface PathExpression
interface PathExpression extends MinimalPathExpression {}
property data
data: boolean;
Deprecated
use `head.type' instead
property head
head: PathHead;
property original
original: string;
property parts
parts: string[];
Deprecated
use
head
andtail
instead
property tail
tail: string[];
property this
this: boolean;
Deprecated
use
head.type
instead
property type
type: 'PathExpression';
interface Position
interface SourcePosition {}
interface Program
interface Program extends CommonProgram {}
interface ProgramSymbols
interface ProgramSymbols extends Symbols {}
property freeVariables
freeVariables: string[];
interface SourceLocation
interface SourceLocation {}
interface SourcePosition
interface SourcePosition {}
interface StringLiteral
interface StringLiteral extends BaseNode {}
interface StripFlags
interface StripFlags {}
interface SubExpression
interface SubExpression extends Call {}
interface Symbols
interface Symbols {}
property symbols
symbols: string[];
method allocate
allocate: (identifier: string) => number;
method allocateBlock
allocateBlock: (name: string) => number;
method allocateFree
allocateFree: (name: string) => number;
method allocateNamed
allocateNamed: (name: string) => number;
method child
child: (locals: string[]) => BlockSymbols;
method get
get: (name: string) => number;
method getEvalInfo
getEvalInfo: () => WireFormat.Core.EvalInfo;
method getLocalsMap
getLocalsMap: () => Dict<number>;
method has
has: (name: string) => boolean;
interface TextNode
interface TextNode extends BaseNode {}
interface ThisHead
interface ThisHead {}
interface UndefinedLiteral
interface UndefinedLiteral extends BaseNode {}
interface VarHead
interface VarHead {}
type AttrValue
type AttrValue = TextNode | MustacheStatement | ConcatStatement;
type CallNode
type CallNode = | MustacheStatement | BlockStatement | ElementModifierStatement | SubExpression;
type EntityEncodingState
type EntityEncodingState = 'transformed' | 'raw';
type Expression
type Expression = Nodes[ExpressionName];
type ExpressionName
type ExpressionName = 'SubExpression' | 'PathExpression' | LiteralName;
type Expressions
type Expressions = Pick<Nodes, ExpressionName>;
type Literal
type Literal = Nodes[LiteralName];
type LiteralName
type LiteralName = | 'StringLiteral' | 'BooleanLiteral' | 'NumberLiteral' | 'UndefinedLiteral' | 'NullLiteral';
type Node
type Node = Nodes[NodeType];
type Nodes
type Nodes = SharedNodes & { Program: Program; Template: Template; Block: Block; BlockStatement: BlockStatement; ElementNode: ElementNode; SubExpression: SubExpression; PathExpression: PathExpression; Hash: Hash; HashPair: HashPair;};
type NodeType
type NodeType = keyof Nodes;
type PathHead
type PathHead = ThisHead | AtHead | VarHead;
type PossiblyDeprecatedBlock
type PossiblyDeprecatedBlock = Block | Template;
type SharedNodes
type SharedNodes = { CommentStatement: CommentStatement; MustacheCommentStatement: MustacheCommentStatement; TextNode: TextNode; StringLiteral: StringLiteral; BooleanLiteral: BooleanLiteral; NumberLiteral: NumberLiteral; NullLiteral: NullLiteral; UndefinedLiteral: UndefinedLiteral; MustacheStatement: MustacheStatement; ElementModifierStatement: ElementModifierStatement; PartialStatement: PartialStatement; AttrNode: AttrNode; ConcatStatement: ConcatStatement;};
type Statement
type Statement = Nodes[StatementName];
type StatementName
type StatementName = | 'MustacheStatement' | 'CommentStatement' | 'BlockStatement' | 'PartialStatement' | 'MustacheCommentStatement' | 'TextNode' | 'ElementNode';
type Statements
type Statements = Pick<Nodes, StatementName>;
type TopLevelStatement
type TopLevelStatement = Statement | Nodes['Block'];
namespace ASTv1
module 'dist/types/lib/v1/api.d.ts' {}
interface AtHead
interface AtHead {}
interface AttrNode
interface AttrNode extends BaseNode {}
interface BlockStatement
interface BlockStatement extends BaseNode {}
property chained
chained?: boolean;
property closeStrip
closeStrip: StripFlags;
property hash
hash: Hash;
property inverse
inverse?: Option<Block>;
property inverseStrip
inverseStrip: StripFlags;
property openStrip
openStrip: StripFlags;
property params
params: Expression[];
property path
path: Expression;
property program
program: Block;
property type
type: 'BlockStatement';
interface BlockSymbols
interface BlockSymbols extends Symbols {}
property slots
slots: number[];
interface BooleanLiteral
interface BooleanLiteral extends BaseNode {}
interface Call
interface Call extends BaseNode {}
interface CallParts
interface CallParts {}
interface CommentStatement
interface CommentStatement extends BaseNode {}
interface CommonProgram
interface CommonProgram extends BaseNode {}
property blockParams
blockParams: string[];
property body
body: Statement[];
property chained
chained?: boolean;
interface ConcatStatement
interface ConcatStatement extends BaseNode {}
interface ElementModifierStatement
interface ElementModifierStatement extends BaseNode {}
interface ElementName
interface ElementName {}
interface ElementNode
interface ElementNode extends BaseNode {}
property attributes
attributes: AttrNode[];
property blockParams
blockParams: string[];
property children
children: Statement[];
property comments
comments: MustacheCommentStatement[];
property modifiers
modifiers: ElementModifierStatement[];
property selfClosing
selfClosing: boolean;
property tag
tag: string;
property type
type: 'ElementNode';
interface FreeVarHead
interface FreeVarHead {}
interface Hash
interface Hash extends BaseNode {}
interface HashPair
interface HashPair extends BaseNode {}
interface LocalVarHead
interface LocalVarHead {}
interface MinimalPathExpression
interface MinimalPathExpression extends BaseNode {}
interface MustacheCommentStatement
interface MustacheCommentStatement extends BaseNode {}
interface MustacheStatement
interface MustacheStatement extends BaseNode {}
interface NamedBlockName
interface NamedBlockName {}
interface NullLiteral
interface NullLiteral extends BaseNode {}
interface NumberLiteral
interface NumberLiteral extends BaseNode {}
interface PartialStatement
interface PartialStatement extends BaseNode {}
interface PathExpression
interface PathExpression extends MinimalPathExpression {}
property data
data: boolean;
Deprecated
use `head.type' instead
property head
head: PathHead;
property original
original: string;
property parts
parts: string[];
Deprecated
use
head
andtail
instead
property tail
tail: string[];
property this
this: boolean;
Deprecated
use
head.type
instead
property type
type: 'PathExpression';
interface Position
interface SourcePosition {}
interface Program
interface Program extends CommonProgram {}
interface ProgramSymbols
interface ProgramSymbols extends Symbols {}
property freeVariables
freeVariables: string[];
interface SourceLocation
interface SourceLocation {}
interface SourcePosition
interface SourcePosition {}
interface StringLiteral
interface StringLiteral extends BaseNode {}
interface StripFlags
interface StripFlags {}
interface SubExpression
interface SubExpression extends Call {}
interface Symbols
interface Symbols {}
property symbols
symbols: string[];
method allocate
allocate: (identifier: string) => number;
method allocateBlock
allocateBlock: (name: string) => number;
method allocateFree
allocateFree: (name: string) => number;
method allocateNamed
allocateNamed: (name: string) => number;
method child
child: (locals: string[]) => BlockSymbols;
method get
get: (name: string) => number;
method getEvalInfo
getEvalInfo: () => WireFormat.Core.EvalInfo;
method getLocalsMap
getLocalsMap: () => Dict<number>;
method has
has: (name: string) => boolean;
interface TextNode
interface TextNode extends BaseNode {}
interface ThisHead
interface ThisHead {}
interface UndefinedLiteral
interface UndefinedLiteral extends BaseNode {}
interface VarHead
interface VarHead {}
type AttrValue
type AttrValue = TextNode | MustacheStatement | ConcatStatement;
type CallNode
type CallNode = | MustacheStatement | BlockStatement | ElementModifierStatement | SubExpression;
type EntityEncodingState
type EntityEncodingState = 'transformed' | 'raw';
type Expression
type Expression = Nodes[ExpressionName];
type ExpressionName
type ExpressionName = 'SubExpression' | 'PathExpression' | LiteralName;
type Expressions
type Expressions = Pick<Nodes, ExpressionName>;
type Literal
type Literal = Nodes[LiteralName];
type LiteralName
type LiteralName = | 'StringLiteral' | 'BooleanLiteral' | 'NumberLiteral' | 'UndefinedLiteral' | 'NullLiteral';
type Node
type Node = Nodes[NodeType];
type Nodes
type Nodes = SharedNodes & { Program: Program; Template: Template; Block: Block; BlockStatement: BlockStatement; ElementNode: ElementNode; SubExpression: SubExpression; PathExpression: PathExpression; Hash: Hash; HashPair: HashPair;};
type NodeType
type NodeType = keyof Nodes;
type PathHead
type PathHead = ThisHead | AtHead | VarHead;
type PossiblyDeprecatedBlock
type PossiblyDeprecatedBlock = Block | Template;
type SharedNodes
type SharedNodes = { CommentStatement: CommentStatement; MustacheCommentStatement: MustacheCommentStatement; TextNode: TextNode; StringLiteral: StringLiteral; BooleanLiteral: BooleanLiteral; NumberLiteral: NumberLiteral; NullLiteral: NullLiteral; UndefinedLiteral: UndefinedLiteral; MustacheStatement: MustacheStatement; ElementModifierStatement: ElementModifierStatement; PartialStatement: PartialStatement; AttrNode: AttrNode; ConcatStatement: ConcatStatement;};
type Statement
type Statement = Nodes[StatementName];
type StatementName
type StatementName = | 'MustacheStatement' | 'CommentStatement' | 'BlockStatement' | 'PartialStatement' | 'MustacheCommentStatement' | 'TextNode' | 'ElementNode';
type Statements
type Statements = Pick<Nodes, StatementName>;
type TopLevelStatement
type TopLevelStatement = Statement | Nodes['Block'];
namespace ASTv2
module 'dist/types/lib/v2-a/api.d.ts' {}
variable ARGUMENT_RESOLUTION
const ARGUMENT_RESOLUTION: LooseModeResolution;
variable STRICT_RESOLUTION
const STRICT_RESOLUTION: StrictResolution;
function isLiteral
isLiteral: <K extends keyof LiteralTypes = keyof LiteralTypes>( node: ExpressionNode, kind?: K) => node is StringLiteral;
Returns true if an input is a literal.
function loadResolution
loadResolution: (resolution: SerializedResolution) => FreeVarResolution;
function node
node: { (): { fields<Fields extends object>(): NodeConstructor<Fields & BaseNodeFields>; }; <T extends string>(name: T): { fields<Fields extends object>(): TypedNodeConstructor< T, Fields & BaseNodeFields >; };};
This is a convenience function for creating ASTv2 nodes, with an optional name and the node's options.
export class HtmlText extends node('HtmlText').fields<{ chars: string }>() {}This creates a new ASTv2 node with the name
'HtmlText'
and one fieldchars: string
(in addition to aloc: SourceOffsets
field, which all nodes have).export class Args extends node().fields<{positional: PositionalArguments;named: NamedArguments}>() {}This creates a new un-named ASTv2 node with two fields (
positional: Positional
and `named: Named, in addition to the generic
loc: SourceOffsets` field).Once you create a node using
node
, it is instantiated with all of its fields (includingloc
):new HtmlText({ loc: offsets, chars: someString });
class AppendContent
class AppendContent extends AppendContent_base {}
class ArgReference
class ArgReference extends ArgReference_base {}
Corresponds to
@<ident>
at the beginning of an expression.
class Args
class Args extends Args_base {}
Corresponds to syntaxes with positional and named arguments:
- SubExpression - Invoking Append - Invoking attributes - InvokeBlock
If
Args
is empty, theSourceOffsets
for this node should be the collapsed position immediately after the parent call node'scallee
.
class Block
class Block extends Block_base {}
Represents a block. In principle this could be merged with
NamedBlock
, because all cases involving blocks have at least a notional name.
class CallExpression
class CallExpression extends CallExpression_base {}
Corresponds to a parenthesized call expression.
(x)(x.y)(x y)(x.y z)
class ComponentArg
class ComponentArg extends ComponentArg_base {}
Corresponds to an argument passed by a component (
@x=<value>
)
method toNamedArgument
toNamedArgument: () => NamedArgument;
Convert the component argument into a named argument node
class DeprecatedCallExpression
class DeprecatedCallExpression extends DeprecatedCallExpression_base {}
Corresponds to a possible deprecated helper call. Must be:
1. A free variable (not this.foo, not @foo, not local). 2. Argument-less. 3. In a component invocation's named argument position. 4. Not parenthesized (not @bar={{(helper)}}). 5. Not interpolated (not @bar="{{helper}}").
<Foo @bar={{helper}} />
class ElementModifier
class ElementModifier extends ElementModifier_base {}
An
ElementModifier
is just a normal call node in modifier position.
class FreeVarReference
class FreeVarReference extends FreeVarReference_base {}
Corresponds to
<ident>
at the beginning of an expression, when<ident>
is *not* in the current block's scope.The
resolution: FreeVarResolution
field describes how to resolve the free variable.Note: In strict mode, it must always be a variable that is in a concrete JavaScript scope that the template will be installed into.
class GlimmerComment
class GlimmerComment extends GlimmerComment_base {}
class HtmlAttr
class HtmlAttr extends HtmlAttr_base {}
HtmlAttr
nodes are valid HTML attributes, with or without a value.Exceptions:
-
...attributes
isSplatAttr
-@x=<value>
isComponentArg
class HtmlComment
class HtmlComment extends HtmlComment_base {}
class HtmlText
class HtmlText extends HtmlText_base {}
class InterpolateExpression
class InterpolateExpression extends InterpolateExpression_base {}
Corresponds to an interpolation in attribute value position.
<a href="{{url}}.html"
class InvokeBlock
class InvokeBlock extends InvokeBlock_base {}
class InvokeComponent
class InvokeComponent extends InvokeComponent_base {}
Corresponds to a component invocation. When the content of a component invocation contains no named blocks,
blocks
contains a single named block named"default"
. When a component invocation is self-closing,blocks
is empty.
property args
readonly args: Args;
class LiteralExpression
class LiteralExpression extends LiteralExpression_base {}
Corresponds to a Handlebars literal.
See Also
{LiteralValue}
method toSlice
toSlice: (this: StringLiteral) => SourceSlice;
class LocalVarReference
class LocalVarReference extends LocalVarReference_base {}
Corresponds to
<ident>
at the beginning of an expression, when<ident>
is in the current block's scope.
class LooseModeResolution
class LooseModeResolution {}
A
LooseModeResolution
includes:- 0 or more namespaces to resolve the variable in - optional fallback behavior
In practice, there are a limited number of possible combinations of these degrees of freedom, and they are captured by the
Ambiguity
union below.
constructor
constructor(ambiguity: Ambiguity, isAngleBracket?: boolean);
property ambiguity
readonly ambiguity: Ambiguity;
property isAngleBracket
readonly isAngleBracket: boolean;
method append
static append: ({ invoke }: { invoke: boolean }) => LooseModeResolution;
Append resolution is used when the variable should be resolved in both the
component
andhelper
namespaces. Fallback resolution is optional.{{x}}^
x
should be resolved in thecomponent
andhelper
namespaces with fallback resolution.{{x y}}^
x
should be resolved in thecomponent
andhelper
namespaces without fallback resolution.See Also
{ComponentOrHelperAmbiguity}
method attr
static attr: () => LooseModeResolution;
Attribute resolution is used when the variable should be resolved as a
helper
with fallback resolution.<a href={{x}} /><a href="{{x}}.html" />^ resolved in the
helper
namespace with fallbackSee Also
{HelperAmbiguity}
method fallback
static fallback: () => LooseModeResolution;
Fallback resolution is used when no namespaced resolutions are possible, but fallback resolution is still allowed.
{{x.y}}See Also
{FallbackAmbiguity}
method namespaced
static namespaced: ( namespace: FreeVarNamespace, isAngleBracket?: boolean) => LooseModeResolution;
Namespaced resolution is used in an unambiguous syntax position:
1.
(sexp)
(namespace:Helper
) 2.{{#block}}
(namespace:Component
) 3.<a {{modifier}}>
(namespace:Modifier
) 4.<Component />
(namespace:Component
)See Also
{NamespacedAmbiguity}
method resolution
resolution: () => GetContextualFreeOp;
method serialize
serialize: () => SerializedResolution;
method trustingAppend
static trustingAppend: ({ invoke }: { invoke: boolean }) => LooseModeResolution;
Trusting append resolution is used when the variable should be resolved in both the
component
andhelper
namespaces. Fallback resolution is optional.{{{x}}}^
x
should be resolved in thecomponent
andhelper
namespaces with fallback resolution.{{{x y}}}^
x
should be resolved in thecomponent
andhelper
namespaces without fallback resolution.See Also
{HelperAmbiguity}
class NamedArgument
class NamedArgument {}
Corresponds to a single named argument.
x=<expr>
constructor
constructor(options: { name: SourceSlice; value: ExpressionNode });
property loc
readonly loc: SourceSpan;
property name
readonly name: SourceSlice<string>;
property value
readonly value: ExpressionNode;
class NamedArguments
class NamedArguments extends NamedArguments_base {}
Corresponds to named arguments.
If
PositionalArguments
andNamedArguments
are empty, theSourceOffsets
for this node should be the same as theArgs
node that contains this node.If
PositionalArguments
is not empty butNamedArguments
is empty, theSourceOffsets
for this node should be the collapsed position immediately after the last positional argument.
class NamedBlock
class NamedBlock extends NamedBlock_base {}
Corresponds to a single named block. This is used for anonymous named blocks (
default
andelse
).
property args
readonly args: Args;
class NamedBlocks
class NamedBlocks extends NamedBlocks_base {}
Corresponds to a collection of named blocks.
method get
get: { (name: 'default'): NamedBlock; (name: string): NamedBlock };
Get the
NamedBlock
for a given name.
class PathExpression
class PathExpression extends PathExpression_base {}
Corresponds to a path in expression position.
thisthis.x@x@x.yxx.y
class PositionalArguments
class PositionalArguments extends PositionalArguments_base {}
Corresponds to positional arguments.
If
PositionalArguments
is empty, theSourceOffsets
for this node should be the collapsed position immediately after the parent call node'scallee
.
class SimpleElement
class SimpleElement extends SimpleElement_base {}
Corresponds to a simple HTML element. The AST allows component arguments and modifiers to support future extensions.
property args
readonly args: Args;
class SplatAttr
class SplatAttr extends SplatAttr_base {}
class StrictResolution
class StrictResolution {}
Strict resolution is used:
1. in a strict mode template 2. in an unambiguous invocation with dot paths
property isAngleBracket
readonly isAngleBracket: boolean;
method resolution
resolution: () => GetContextualFreeOp;
method serialize
serialize: () => SerializedResolution;
class Template
class Template extends Template_base {}
Corresponds to an entire template.
class ThisReference
class ThisReference extends ThisReference_base {}
Corresponds to
this
at the head of an expression.
interface AttrNodeOptions
interface AttrNodeOptions {}
interface BaseNodeFields
interface BaseNodeFields {}
property loc
loc: SourceSpan;
interface CallFields
interface CallFields extends BaseNodeFields {}
interface GlimmerParentNodeOptions
interface GlimmerParentNodeOptions extends BaseNodeFields {}
property body
body: readonly ContentNode[];
interface LiteralTypes
interface LiteralTypes {}
interface NamedBlockFields
interface NamedBlockFields extends BaseNodeFields {}