@glimmer/syntax
- Version 0.92.0
- Published
- 1.52 MB
- 5 dependencies
- MIT license
Install
npm i @glimmer/syntax
yarn add @glimmer/syntax
pnpm add @glimmer/syntax
Overview
Overview not available.
Index
Variables
Functions
- buildAtName()
- buildAttr()
- buildBlock()
- buildBlockItself()
- buildCleanPath()
- buildComment()
- buildConcat()
- buildElement()
- buildElementModifier()
- buildHash()
- buildHeadFromString()
- buildLiteral()
- buildLoc()
- buildMustache()
- buildMustacheComment()
- buildPair()
- buildPath()
- buildPosition()
- buildProgram()
- buildSexpr()
- buildTemplate()
- buildText()
- buildThis()
- buildVar()
- cannotRemoveNode()
- cannotReplaceNode()
- generateSyntaxError()
- getTemplateLocals()
- getVoidTags()
- hasSpan()
- isKeyword()
- isVoidTag()
- loc()
- maybeLoc()
- node()
- normalize()
- preprocess()
- print()
- sortByLoc()
- traverse()
Classes
Interfaces
Type Aliases
Namespaces
AST
- AnyPosition
- AnySpan
- ASTPlugin
- ASTPluginBuilder
- ASTPluginEnvironment
- AtHead
- Attribute
- AttrNode
- AttrPart
- AttrSexp
- AttrValue
- BaseNode
- Block
- BlockStatement
- BooleanLiteral
- BROKEN
- BROKEN
- BROKEN_LOCATION
- build()
- buildAtName()
- buildAttr()
- buildBlock()
- buildBlockItself()
- buildCleanPath()
- buildComment()
- buildConcat()
- buildElement()
- buildElementModifier()
- BuildElementOptions
- BuilderHead
- buildHash()
- buildHeadFromString()
- buildLiteral()
- buildLoc()
- buildMustache()
- buildMustacheComment()
- buildPair()
- buildPath()
- buildPosition()
- buildProgram()
- buildSexpr()
- buildTemplate()
- buildText()
- buildThis()
- buildVar()
- CallableExpression
- CallNode
- CallParts
- CharPosition
- CharPositionSpan
- CommentStatement
- CommonProgram
- ConcatStatement
- ElementComment
- ElementModifierStatement
- ElementNode
- ElementParts
- EndTag
- EntityEncodingState
- ExhaustiveCheck
- ExhaustiveMatcher
- Expression
- ExpressionName
- Expressions
- FullKeyTraversal
- FullNodeTraversal
- getVoidTags()
- HandlebarsNodeVisitors
- HandlebarsParseOptions
- Hash
- HashPair
- HasSourceLocation
- HasSourceSpan
- hasSpan()
- HasSpan
- HbsPosition
- HbsSpan
- InvisiblePosition
- InvisibleSpan
- IsInvisible
- IsInvisible
- isLocatedWithPositions()
- isLocatedWithPositionsArray()
- isVoidTag()
- KeyHandler
- KeysVisitor
- KeyTraversal
- Literal
- LiteralName
- loc()
- LocatedWithOptionalPositions
- LocatedWithOptionalSpan
- LocatedWithPositions
- LocatedWithSpan
- LocSexp
- match()
- MatchAny
- MatchAny
- Matcher
- Matches
- MatchFn
- MaybeHasSourceLocation
- MaybeHasSourceSpan
- MaybeHasSpan
- maybeLoc()
- MinimalPathExpression
- ModifierSexp
- MustacheCommentStatement
- MustacheStatement
- Node
- NodeCallback
- NodeHandler
- Nodes
- NodeTraversal
- NodeType
- NodeVisitor
- NON_EXISTENT_LOCATION
- NullLiteral
- NumberLiteral
- OffsetKind
- ParentNode
- Parser
- ParserNodeBuilder
- PathExpression
- PathHead
- PathSexp
- Pattern
- PendingError
- PositionData
- PossiblyDeprecatedBlock
- PrecompileOptions
- PrecompileOptionsWithLexicalScope
- preprocess()
- PreprocessOptions
- Printer
- PrinterOptions
- Program
- publicBuilder
- SerializedConcreteSourceSpan
- SerializedSourceSlice
- SerializedSourceSpan
- SexpValue
- Source
- SourceLocation
- SourceOffset
- SourcePosition
- SourceSlice
- SourceSpan
- span
- SpanData
- SpanList
- StartTag
- Statement
- StatementName
- Statements
- StringLiteral
- StripFlags
- SubExpression
- SubNode
- SubNodes
- SubNodeType
- Syntax
- SYNTHETIC
- SYNTHETIC_LOCATION
- TagDescriptor
- Template
- TemplateIdFn
- TEMPORARY_LOCATION
- TextNode
- ThisHead
- TokenizerEventHandlers
- TopLevelStatement
- ToSourceOffset
- traverse()
- UndefinedLiteral
- UNKNOWN_POSITION
- VarHead
- VisitorKey
- visitorKeys
- VisitorKeys
- VisitorKeysMap
- voidMap
- Walker
- WalkerPath
- When
ASTv1
- AnyPosition
- AnySpan
- ASTPlugin
- ASTPluginBuilder
- ASTPluginEnvironment
- AtHead
- Attribute
- AttrNode
- AttrPart
- AttrSexp
- AttrValue
- BaseNode
- Block
- BlockStatement
- BooleanLiteral
- BROKEN
- BROKEN
- BROKEN_LOCATION
- build()
- buildAtName()
- buildAttr()
- buildBlock()
- buildBlockItself()
- buildCleanPath()
- buildComment()
- buildConcat()
- buildElement()
- buildElementModifier()
- BuildElementOptions
- BuilderHead
- buildHash()
- buildHeadFromString()
- buildLiteral()
- buildLoc()
- buildMustache()
- buildMustacheComment()
- buildPair()
- buildPath()
- buildPosition()
- buildProgram()
- buildSexpr()
- buildTemplate()
- buildText()
- buildThis()
- buildVar()
- CallableExpression
- CallNode
- CallParts
- CharPosition
- CharPositionSpan
- CommentStatement
- CommonProgram
- ConcatStatement
- ElementComment
- ElementModifierStatement
- ElementNode
- ElementParts
- EndTag
- EntityEncodingState
- ExhaustiveCheck
- ExhaustiveMatcher
- Expression
- ExpressionName
- Expressions
- FullKeyTraversal
- FullNodeTraversal
- getVoidTags()
- HandlebarsNodeVisitors
- HandlebarsParseOptions
- Hash
- HashPair
- HasSourceLocation
- HasSourceSpan
- hasSpan()
- HasSpan
- HbsPosition
- HbsSpan
- InvisiblePosition
- InvisibleSpan
- IsInvisible
- IsInvisible
- isLocatedWithPositions()
- isLocatedWithPositionsArray()
- isVoidTag()
- KeyHandler
- KeysVisitor
- KeyTraversal
- Literal
- LiteralName
- loc()
- LocatedWithOptionalPositions
- LocatedWithOptionalSpan
- LocatedWithPositions
- LocatedWithSpan
- LocSexp
- match()
- MatchAny
- MatchAny
- Matcher
- Matches
- MatchFn
- MaybeHasSourceLocation
- MaybeHasSourceSpan
- MaybeHasSpan
- maybeLoc()
- MinimalPathExpression
- ModifierSexp
- MustacheCommentStatement
- MustacheStatement
- Node
- NodeCallback
- NodeHandler
- Nodes
- NodeTraversal
- NodeType
- NodeVisitor
- NON_EXISTENT_LOCATION
- NullLiteral
- NumberLiteral
- OffsetKind
- ParentNode
- Parser
- ParserNodeBuilder
- PathExpression
- PathHead
- PathSexp
- Pattern
- PendingError
- PositionData
- PossiblyDeprecatedBlock
- PrecompileOptions
- PrecompileOptionsWithLexicalScope
- preprocess()
- PreprocessOptions
- Printer
- PrinterOptions
- Program
- publicBuilder
- SerializedConcreteSourceSpan
- SerializedSourceSlice
- SerializedSourceSpan
- SexpValue
- Source
- SourceLocation
- SourceOffset
- SourcePosition
- SourceSlice
- SourceSpan
- span
- SpanData
- SpanList
- StartTag
- Statement
- StatementName
- Statements
- StringLiteral
- StripFlags
- SubExpression
- SubNode
- SubNodes
- SubNodeType
- Syntax
- SYNTHETIC
- SYNTHETIC_LOCATION
- TagDescriptor
- Template
- TemplateIdFn
- TEMPORARY_LOCATION
- TextNode
- ThisHead
- TokenizerEventHandlers
- TopLevelStatement
- ToSourceOffset
- traverse()
- UndefinedLiteral
- UNKNOWN_POSITION
- VarHead
- VisitorKey
- visitorKeys
- VisitorKeys
- VisitorKeysMap
- voidMap
- Walker
- WalkerPath
- When
ASTv2
- AnyPosition
- AnySpan
- AppendContent
- AppendContent_base
- ArgReference
- ArgReference_base
- Args
- Args_base
- ASTPlugin
- ASTPluginBuilder
- ASTPluginEnvironment
- AttrBlockNode
- Attribute
- AttrNode
- AttrNodeOptions
- AttrSexp
- BaseNodeFields
- Block
- Block_base
- BlockSymbolTable
- BROKEN
- BROKEN
- BROKEN_LOCATION
- build()
- buildAtName()
- buildAttr()
- buildBlock()
- buildBlockItself()
- buildCleanPath()
- buildComment()
- buildConcat()
- buildElement()
- buildElementModifier()
- BuildElementOptions
- BuilderHead
- buildHash()
- buildHeadFromString()
- buildLiteral()
- buildLoc()
- buildMustache()
- buildMustacheComment()
- buildPair()
- buildPath()
- buildPosition()
- buildProgram()
- buildSexpr()
- buildTemplate()
- buildText()
- buildThis()
- buildVar()
- CalleeNode
- CallExpression
- CallExpression_base
- CallFields
- CallNode
- CharPosition
- CharPositionSpan
- COMPONENT_NAMESPACE
- ComponentArg
- ComponentArg_base
- ContentNode
- ElementComment
- ElementModifier
- ElementModifier_base
- ElementNode
- ElementParts
- EndTag
- ExhaustiveCheck
- ExhaustiveMatcher
- ExpressionNode
- FreeVarNamespace
- FreeVarReference
- FreeVarReference_base
- FreeVarResolution
- FullKeyTraversal
- FullNodeTraversal
- getVoidTags()
- GlimmerComment
- GlimmerComment_base
- GlimmerParentNodeOptions
- HandlebarsNodeVisitors
- HandlebarsParseOptions
- HasSourceLocation
- HbsPosition
- HbsSpan
- HELPER_NAMESPACE
- HTML_RESOLUTION
- HtmlAttr
- HtmlAttr_base
- HtmlComment
- HtmlComment_base
- HtmlOrSplatAttr
- HtmlResolution
- HtmlText
- HtmlText_base
- InterpolateExpression
- InterpolateExpression_base
- InvisiblePosition
- InvisibleSpan
- InvokeBlock
- InvokeBlock_base
- InvokeComponent
- InvokeComponent_base
- InvokeComponentFields
- IsInvisible
- IsInvisible
- isLiteral()
- isLocatedWithPositions()
- isLocatedWithPositionsArray()
- isStrictResolution()
- isVoidTag()
- KeyHandler
- KeysVisitor
- KeyTraversal
- KeywordExpression
- KeywordExpression_base
- LiteralExpression
- LiteralExpression_base
- LiteralTypes
- LiteralValue
- loadResolution()
- LocalVarReference
- LocalVarReference_base
- LocatedWithOptionalPositions
- LocatedWithOptionalSpan
- LocatedWithPositions
- LocatedWithSpan
- LocSexp
- LooseModeResolution
- match()
- MatchAny
- MatchAny
- Matcher
- Matches
- MatchFn
- MaybeHasSourceLocation
- MODIFIER_NAMESPACE
- ModifierSexp
- NamedArgument
- NamedArguments
- NamedArguments_base
- NamedBlock
- NamedBlock_base
- NamedBlockFields
- NamedBlocks
- NamedBlocks_base
- Namespaces
- node()
- NodeCallback
- NodeConstructor
- NodeHandler
- NodeTraversal
- NodeVisitor
- NON_EXISTENT_LOCATION
- OffsetKind
- Parser
- ParserNodeBuilder
- PathExpression
- PathExpression_base
- PathSexp
- Pattern
- PendingError
- PositionalArguments
- PositionalArguments_base
- PositionData
- PossiblyDeprecatedBlock
- PrecompileOptions
- PrecompileOptionsWithLexicalScope
- preprocess()
- PreprocessOptions
- Printer
- PrinterOptions
- ProgramSymbolTable
- publicBuilder
- SerializedBaseNode
- SerializedConcreteSourceSpan
- SerializedResolution
- SerializedSourceSlice
- SerializedSourceSpan
- SexpValue
- SimpleElement
- SimpleElement_base
- SimpleElementOptions
- Source
- SourceLocation
- SourceOffset
- SourcePosition
- SourceSlice
- SourceSpan
- span
- SpanData
- SplatAttr
- SplatAttr_base
- StartTag
- STRICT_RESOLUTION
- StrictResolution
- StringLiteral
- SymbolTable
- SymbolTableOptions
- Syntax
- SYNTHETIC
- SYNTHETIC_LOCATION
- TagDescriptor
- Template
- Template_base
- TemplateIdFn
- TEMPORARY_LOCATION
- ThisReference
- ThisReference_base
- TokenizerEventHandlers
- traverse()
- TypedNode
- TypedNodeConstructor
- UNKNOWN_POSITION
- Upvar
- VariableReference
- VisitorKey
- visitorKeys
- VisitorKeys
- VisitorKeysMap
- voidMap
- Walker
- WalkerPath
- When
HBS
- BlockStatement
- BooleanLiteral
- CommentStatement
- CommonBlock
- CommonMustache
- CommonNode
- ContentStatement
- Decorator
- DecoratorBlock
- Expression
- Hash
- HashPair
- Literal
- MustacheStatement
- Node
- NodeMap
- NodeType
- NullLiteral
- NumberLiteral
- Output
- PartialBlockStatement
- PartialStatement
- PathExpression
- Position
- Program
- SourceLocation
- Statement
- StringLiteral
- StripFlags
- SubExpression
- UndefinedLiteral
src
- AnyPosition
- AnySpan
- ASTPlugin
- ASTPluginBuilder
- ASTPluginEnvironment
- Attribute
- AttrSexp
- BROKEN
- BROKEN
- BROKEN_LOCATION
- build()
- buildAtName()
- buildAttr()
- buildBlock()
- buildBlockItself()
- buildCleanPath()
- buildComment()
- buildConcat()
- buildElement()
- buildElementModifier()
- BuildElementOptions
- BuilderHead
- buildHash()
- buildHeadFromString()
- buildLiteral()
- buildLoc()
- buildMustache()
- buildMustacheComment()
- buildPair()
- buildPath()
- buildPosition()
- buildProgram()
- buildSexpr()
- buildTemplate()
- buildText()
- buildThis()
- buildVar()
- CharPosition
- CharPositionSpan
- ElementComment
- ElementParts
- EndTag
- ExhaustiveCheck
- ExhaustiveMatcher
- FullKeyTraversal
- FullNodeTraversal
- getVoidTags()
- HandlebarsNodeVisitors
- HandlebarsParseOptions
- HasSourceLocation
- HasSourceSpan
- hasSpan()
- HasSpan
- HbsPosition
- HbsSpan
- InvisiblePosition
- InvisibleSpan
- IsInvisible
- IsInvisible
- isLocatedWithPositions()
- isLocatedWithPositionsArray()
- isVoidTag()
- KeyHandler
- KeysVisitor
- KeyTraversal
- loc()
- LocatedWithOptionalPositions
- LocatedWithOptionalSpan
- LocatedWithPositions
- LocatedWithSpan
- LocSexp
- match()
- MatchAny
- MatchAny
- Matcher
- Matches
- MatchFn
- MaybeHasSourceLocation
- MaybeHasSourceSpan
- MaybeHasSpan
- maybeLoc()
- ModifierSexp
- NodeCallback
- NodeHandler
- NodeTraversal
- NodeVisitor
- NON_EXISTENT_LOCATION
- OffsetKind
- Parser
- ParserNodeBuilder
- PathSexp
- Pattern
- PendingError
- PositionData
- PossiblyDeprecatedBlock
- PrecompileOptions
- PrecompileOptionsWithLexicalScope
- preprocess()
- PreprocessOptions
- Printer
- PrinterOptions
- publicBuilder
- SerializedConcreteSourceSpan
- SerializedSourceSlice
- SerializedSourceSpan
- SexpValue
- Source
- SourceLocation
- SourceOffset
- SourcePosition
- SourceSlice
- SourceSpan
- span
- SpanData
- SpanList
- StartTag
- Syntax
- SYNTHETIC
- SYNTHETIC_LOCATION
- TagDescriptor
- TemplateIdFn
- TEMPORARY_LOCATION
- TokenizerEventHandlers
- ToSourceOffset
- traverse()
- UNKNOWN_POSITION
- VisitorKey
- visitorKeys
- VisitorKeys
- VisitorKeysMap
- voidMap
- Walker
- WalkerPath
- When
Variables
variable BROKEN
const BROKEN: string;
Used to indicate that an attempt to convert a
SourcePosition
to a character offset failed. It is separate fromnull
so thatnull
can be used to indicate that the computation wasn't yet attempted (and therefore to cache the failure)
variable builders
const builders: { 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) => ASTv1.StringLiteral; boolean: (value: boolean) => ASTv1.BooleanLiteral; number: (value: number) => ASTv1.NumberLiteral; undefined(): ASTv1.UndefinedLiteral; null(): ASTv1.NullLiteral;};
variable IsInvisible
const IsInvisible: string;
variable KEYWORDS_TYPES
const KEYWORDS_TYPES: { action: ('Call' | 'Modifier')[]; component: ('Block' | 'Call' | 'Append')[]; debugger: 'Append'[]; 'each-in': 'Block'[]; each: 'Block'[]; 'has-block-params': ('Call' | 'Append')[]; 'has-block': ('Call' | 'Append')[]; helper: ('Call' | 'Append')[]; if: ('Block' | 'Call' | 'Append')[]; 'in-element': 'Block'[]; let: 'Block'[]; log: ('Call' | 'Append')[]; modifier: ('Call' | 'Modifier')[]; mount: 'Append'[]; mut: ('Call' | 'Append')[]; outlet: 'Append'[]; readonly: ('Call' | 'Append')[]; unbound: ('Call' | 'Append')[]; unless: ('Block' | 'Call' | 'Append')[]; yield: 'Append'[];};
This includes the full list of keywords currently in use in the template language, and where their valid usages are.
variable MatchAny
const MatchAny: string;
This file implements the DSL used by span and offset in places where they need to exhaustively consider all combinations of states (Handlebars offsets, character offsets and invisible/broken offsets).
It's probably overkill, but it makes the code that uses it clear. It could be refactored or removed.
variable print
const print: (ast: ASTv1.Node, options?: PrinterOptions) => string;
variable publicBuilder
const publicBuilder: { mustache: ( path: BuilderHead | ASTv1.Literal, params?: ASTv1.Expression[], hash?: ASTv1.Hash, trusting?: boolean, loc?: SourceLocation, strip?: ASTv1.StripFlags ) => ASTv1.MustacheStatement; block: ( path: BuilderHead, params: Nullable<ASTv1.Expression[]>, hash: Nullable<ASTv1.Hash>, _defaultBlock: PossiblyDeprecatedBlock, _elseBlock?: Nullable<PossiblyDeprecatedBlock>, loc?: SourceLocation, openStrip?: ASTv1.StripFlags, inverseStrip?: ASTv1.StripFlags, closeStrip?: ASTv1.StripFlags ) => ASTv1.BlockStatement; comment: (value: string, loc?: SourceLocation) => ASTv1.CommentStatement; mustacheComment: ( value: string, loc?: SourceLocation ) => ASTv1.MustacheCommentStatement; element: ( tag: TagDescriptor, options?: BuildElementOptions ) => ASTv1.ElementNode; elementModifier: ( path: BuilderHead, params?: ASTv1.Expression[], hash?: ASTv1.Hash, loc?: Nullable<SourceLocation> ) => ASTv1.ElementModifierStatement; attr: ( name: string, value: ASTv1.AttrValue, loc?: SourceLocation ) => ASTv1.AttrNode; text: (chars?: string, loc?: SourceLocation) => ASTv1.TextNode; sexpr: ( path: BuilderHead, params?: ASTv1.Expression[], hash?: ASTv1.Hash, loc?: SourceLocation ) => ASTv1.SubExpression; concat: ( parts: (ASTv1.MustacheStatement | ASTv1.TextNode)[], loc?: SourceLocation ) => ASTv1.ConcatStatement; hash: (pairs?: ASTv1.HashPair[], loc?: SourceLocation) => ASTv1.Hash; pair: ( key: string, value: ASTv1.Expression, loc?: SourceLocation ) => ASTv1.HashPair; literal: <T extends ASTv1.Literal>( type: T['type'], value: T['value'], loc?: SourceLocation ) => T; program: ( body?: ASTv1.Statement[], blockParams?: string[], loc?: SourceLocation ) => ASTv1.Template | ASTv1.Block; blockItself: ( body?: ASTv1.Statement[], params?: (string | ASTv1.VarHead)[], chained?: boolean, loc?: SourceLocation ) => ASTv1.Block; template: ( body?: ASTv1.Statement[], blockParams?: string[], loc?: SourceLocation ) => ASTv1.Template; loc: { (loc: Nullable<SourceLocation>): SourceSpan; ( startLine: number, startColumn: number, endLine?: number, endColumn?: number, source?: string ): SourceSpan; }; pos: (line: number, column: number) => SourcePosition; path: { ( path: string | ASTv1.PathExpression | { head: string; tail: string[] }, loc?: SourceLocation ): ASTv1.PathExpression; (path: BuilderHead, loc?: SourceLocation): ASTv1.CallableExpression; (path: BuilderHead | ASTv1.Literal, loc?: SourceLocation): ASTv1.Expression; (path: ASTv1.Expression, loc?: SourceLocation): ASTv1.Expression; }; fullPath: ( head: ASTv1.PathHead, tail?: string[], loc?: SourceLocation ) => ASTv1.PathExpression; head: (original: string, loc?: SourceLocation) => ASTv1.PathHead; at: (name: string, loc?: SourceLocation) => ASTv1.AtHead; var: (name: string, loc?: SourceLocation) => ASTv1.VarHead; this: (loc?: SourceLocation) => ASTv1.ThisHead; string: (value: string) => ASTv1.StringLiteral; boolean: (value: boolean) => ASTv1.BooleanLiteral; number: (value: number) => ASTv1.NumberLiteral; undefined(): ASTv1.UndefinedLiteral; null(): ASTv1.NullLiteral;};
variable span
const span: MatchFn<SourceSpan>;
variable TraversalError
const TraversalError: TraversalErrorConstructor;
variable visitorKeys
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'];};
Functions
function buildAtName
buildAtName: (name: string, loc?: SourceLocation) => ASTv1.AtHead;
function buildAttr
buildAttr: ( name: string, value: ASTv1.AttrValue, loc?: SourceLocation) => ASTv1.AttrNode;
function buildBlock
buildBlock: ( path: BuilderHead, params: Nullable<ASTv1.Expression[]>, hash: Nullable<ASTv1.Hash>, _defaultBlock: PossiblyDeprecatedBlock, _elseBlock?: Nullable<PossiblyDeprecatedBlock>, loc?: SourceLocation, openStrip?: ASTv1.StripFlags, inverseStrip?: ASTv1.StripFlags, closeStrip?: ASTv1.StripFlags) => ASTv1.BlockStatement;
function buildBlockItself
buildBlockItself: ( body?: ASTv1.Statement[], params?: Array<ASTv1.VarHead | string>, chained?: boolean, loc?: SourceLocation) => ASTv1.Block;
function buildCleanPath
buildCleanPath: ( head: ASTv1.PathHead, tail?: string[], loc?: SourceLocation) => ASTv1.PathExpression;
function buildComment
buildComment: (value: string, loc?: SourceLocation) => ASTv1.CommentStatement;
function buildConcat
buildConcat: ( parts: (ASTv1.TextNode | ASTv1.MustacheStatement)[], loc?: SourceLocation) => ASTv1.ConcatStatement;
function buildElement
buildElement: ( tag: TagDescriptor, options?: BuildElementOptions) => ASTv1.ElementNode;
function buildElementModifier
buildElementModifier: ( path: BuilderHead, params?: ASTv1.Expression[], hash?: ASTv1.Hash, loc?: Nullable<SourceLocation>) => ASTv1.ElementModifierStatement;
function buildHash
buildHash: (pairs?: ASTv1.HashPair[], loc?: SourceLocation) => ASTv1.Hash;
function buildHeadFromString
buildHeadFromString: (original: string, loc?: SourceLocation) => ASTv1.PathHead;
function buildLiteral
buildLiteral: <T extends ASTv1.Literal>( type: T['type'], value: T['value'], loc?: SourceLocation) => T;
function buildLoc
buildLoc: { (loc: Nullable<SourceLocation>): SourceSpan; ( startLine: number, startColumn: number, endLine?: number, endColumn?: number, source?: string ): SourceSpan;};
function buildMustache
buildMustache: ( path: BuilderHead | ASTv1.Literal, params?: ASTv1.Expression[], hash?: ASTv1.Hash, trusting?: boolean, loc?: SourceLocation, strip?: ASTv1.StripFlags) => ASTv1.MustacheStatement;
function buildMustacheComment
buildMustacheComment: ( value: string, loc?: SourceLocation) => ASTv1.MustacheCommentStatement;
function buildPair
buildPair: ( key: string, value: ASTv1.Expression, loc?: SourceLocation) => ASTv1.HashPair;
function buildPath
buildPath: { ( path: ASTv1.PathExpression | string | { head: string; tail: string[] }, loc?: SourceLocation ): ASTv1.PathExpression; (path: BuilderHead, loc?: SourceLocation): ASTv1.CallableExpression; (path: BuilderHead | ASTv1.Literal, loc?: SourceLocation): ASTv1.Expression; (path: ASTv1.Expression, loc?: SourceLocation): ASTv1.Expression;};
function buildPosition
buildPosition: (line: number, column: number) => SourcePosition;
function buildProgram
buildProgram: ( body?: ASTv1.Statement[], blockParams?: string[], loc?: SourceLocation) => ASTv1.Template | ASTv1.Block;
function buildSexpr
buildSexpr: ( path: BuilderHead, params?: ASTv1.Expression[], hash?: ASTv1.Hash, loc?: SourceLocation) => ASTv1.SubExpression;
function buildTemplate
buildTemplate: ( body?: ASTv1.Statement[], blockParams?: string[], loc?: SourceLocation) => ASTv1.Template;
function buildText
buildText: (chars?: string, loc?: SourceLocation) => ASTv1.TextNode;
function buildThis
buildThis: (loc?: SourceLocation) => ASTv1.ThisHead;
function buildVar
buildVar: (name: string, loc?: SourceLocation) => ASTv1.VarHead;
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: src.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 getVoidTags
getVoidTags: () => string[];
function hasSpan
hasSpan: (span: MaybeHasSourceSpan) => span is HasSourceSpan;
function isKeyword
isKeyword: { (word: string): word is | 'action' | 'component' | 'debugger' | 'each-in' | 'each' | 'has-block-params' | 'has-block' | 'helper' | 'if' | 'in-element' | 'let' | 'log' | 'modifier' | 'mount' | 'mut' | 'outlet' | 'readonly' | 'unbound' | 'unless' | 'yield'; (word: string, type: KeywordType): boolean;};
function isVoidTag
isVoidTag: (tag: string) => boolean;
Examples when true: - link - liNK
Examples when false: - Link (component)
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?: PrecompileOptionsWithLexicalScope) => [ast: ASTv2.Template, locals: string[]];
function preprocess
preprocess: ( input: string | src.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 getDebugInfo
getDebugInfo: () => Core.DebugInfo;
method getKeyword
getKeyword: (name: string) => number;
method getLocalsMap
getLocalsMap: () => Dict<number>;
method has
has: (name: string) => boolean;
method hasKeyword
hasKeyword: (name: string) => boolean;
method hasLexical
hasLexical: (name: string) => boolean;
method setHasDebugger
setHasDebugger: () => 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: Nullable<N>, visitor: NodeCallback<N>) => void;
class ProgramSymbolTable
class ProgramSymbolTable extends SymbolTable {}
constructor
constructor( templateLocals: readonly string[], keywords: readonly string[], options: SymbolTableOptions);
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 getDebugInfo
getDebugInfo: () => Core.DebugInfo;
method getKeyword
getKeyword: (name: string) => number;
method getLocalsMap
getLocalsMap: () => Dict<number>;
method getUsedTemplateLocals
getUsedTemplateLocals: () => string[];
method has
has: (name: string) => boolean;
method hasKeyword
hasKeyword: (name: string) => boolean;
method hasLexical
hasLexical: (name: string) => boolean;
method setHasDebugger
setHasDebugger: () => void;
class SourceSlice
class SourceSlice<Chars extends string = string> {}
constructor
constructor(options: { loc: src.SourceSpan; chars: Chars });
property chars
readonly chars: string;
property loc
readonly loc: src.SourceSpan;
method getString
getString: () => string;
method load
static load: ( source: src.Source, slice: SerializedSourceSlice<string>) => SourceSlice;
method serialize
serialize: () => SerializedSourceSlice<Chars>;
method synthetic
static synthetic: <S extends string>(chars: S) => SourceSlice<S>;
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 getDebugInfo
abstract getDebugInfo: () => Core.DebugInfo;
method getKeyword
abstract getKeyword: (name: string) => number;
method getLocalsMap
abstract getLocalsMap: () => Dict<number>;
method has
abstract has: (name: string) => boolean;
method hasKeyword
abstract hasKeyword: (name: string) => boolean;
method hasLexical
abstract hasLexical: (name: string) => boolean;
method setHasDebugger
abstract setHasDebugger: () => void;
method top
static top: ( locals: readonly string[], keywords: readonly string[], options: SymbolTableOptions) => 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: Nullable<N>, visitor: 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 customizeComponentName
customizeComponentName?: ((input: string) => string) | undefined;
property id
id?: TemplateIdFn;
property keywords
keywords?: readonly string[];
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.
interface PrecompileOptionsWithLexicalScope
interface PrecompileOptionsWithLexicalScope extends PrecompileOptions {}
property lexicalScope
lexicalScope: (variable: string) => boolean;
interface PreprocessOptions
interface PreprocessOptions {}
property customizeComponentName
customizeComponentName?: ((input: string) => string) | undefined;
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;
interface Syntax
interface Syntax {}
interface TemplateIdFn
interface TemplateIdFn {}
call signature
(src: string): Nullable<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>; /** * @deprecated use Template or Block instead */ Program?: NodeTraversal<ASTv1.Template | ASTv1.Block>;};
Namespaces
namespace AST
namespace AST {}
variable BROKEN
const BROKEN: string;
Used to indicate that an attempt to convert a
SourcePosition
to a character offset failed. It is separate fromnull
so thatnull
can be used to indicate that the computation wasn't yet attempted (and therefore to cache the failure)
variable BROKEN_LOCATION
const BROKEN_LOCATION: Readonly<{ readonly source: '(broken)'; readonly start: Readonly<{ readonly line: 1; readonly column: 0 }>; readonly end: Readonly<{ readonly line: 1; readonly column: 0 }>;}>;
variable IsInvisible
const IsInvisible: string;
variable MatchAny
const MatchAny: string;
This file implements the DSL used by span and offset in places where they need to exhaustively consider all combinations of states (Handlebars offsets, character offsets and invisible/broken offsets).
It's probably overkill, but it makes the code that uses it clear. It could be refactored or removed.
variable NON_EXISTENT_LOCATION
const NON_EXISTENT_LOCATION: Readonly<{ readonly source: '(nonexistent)'; readonly start: Readonly<{ readonly line: 1; readonly column: 0 }>; readonly end: Readonly<{ readonly line: 1; readonly column: 0 }>;}>;
variable print
const print: (ast: Node, options?: PrinterOptions) => string;
variable publicBuilder
const publicBuilder: { mustache: ( path: Literal | BuilderHead, params?: Expression[], hash?: Hash, trusting?: boolean, loc?: SourceLocation, strip?: StripFlags ) => MustacheStatement; block: ( path: BuilderHead, params: Nullable<Expression[]>, hash: Nullable<Hash>, _defaultBlock: PossiblyDeprecatedBlock, _elseBlock?: Nullable<PossiblyDeprecatedBlock>, loc?: SourceLocation, openStrip?: StripFlags, inverseStrip?: StripFlags, closeStrip?: StripFlags ) => BlockStatement; comment: (value: string, loc?: SourceLocation) => CommentStatement; mustacheComment: ( value: string, loc?: SourceLocation ) => MustacheCommentStatement; element: (tag: TagDescriptor, options?: BuildElementOptions) => ElementNode; elementModifier: ( path: BuilderHead, params?: Expression[], hash?: Hash, loc?: Nullable<SourceLocation> ) => ElementModifierStatement; attr: (name: string, value: AttrValue, loc?: SourceLocation) => AttrNode; text: (chars?: string, loc?: SourceLocation) => TextNode; sexpr: ( path: BuilderHead, params?: Expression[], hash?: Hash, loc?: SourceLocation ) => SubExpression; concat: ( parts: (MustacheStatement | TextNode)[], loc?: SourceLocation ) => ConcatStatement; hash: (pairs?: HashPair[], loc?: SourceLocation) => Hash; pair: (key: string, value: Expression, loc?: SourceLocation) => HashPair; literal: <T extends Literal>( type: T['type'], value: T['value'], loc?: SourceLocation ) => T; program: ( body?: Statement[], blockParams?: string[], loc?: SourceLocation ) => Template | Block; blockItself: ( body?: Statement[], params?: (string | VarHead)[], chained?: boolean, loc?: SourceLocation ) => Block; template: ( body?: Statement[], blockParams?: string[], loc?: SourceLocation ) => Template; loc: { (loc: Nullable<SourceLocation>): SourceSpan; ( startLine: number, startColumn: number, endLine?: number, endColumn?: number, source?: string ): SourceSpan; }; pos: (line: number, column: number) => SourcePosition; path: { ( path: string | PathExpression | { head: string; tail: string[] }, loc?: SourceLocation ): PathExpression; (path: BuilderHead, loc?: SourceLocation): CallableExpression; (path: Literal | BuilderHead, loc?: SourceLocation): Expression; (path: Expression, loc?: SourceLocation): Expression; }; fullPath: ( head: PathHead, tail?: string[], loc?: SourceLocation ) => PathExpression; head: (original: string, loc?: SourceLocation) => PathHead; at: (name: string, loc?: SourceLocation) => AtHead; var: (name: string, loc?: SourceLocation) => VarHead; this: (loc?: SourceLocation) => ThisHead; string: (value: string) => StringLiteral; boolean: (value: boolean) => BooleanLiteral; number: (value: number) => NumberLiteral; undefined(): UndefinedLiteral; null(): NullLiteral;};
variable span
const span: MatchFn<SourceSpan>;
variable SYNTHETIC
const SYNTHETIC: Readonly<{ readonly source: '(synthetic)'; readonly start: Readonly<{ readonly line: 1; readonly column: 0 }>; readonly end: Readonly<{ readonly line: 1; readonly column: 0 }>;}>;
Deprecated
variable SYNTHETIC_LOCATION
const SYNTHETIC_LOCATION: Readonly<{ readonly source: '(synthetic)'; readonly start: Readonly<{ readonly line: 1; readonly column: 0 }>; readonly end: Readonly<{ readonly line: 1; readonly column: 0 }>;}>;
variable TEMPORARY_LOCATION
const TEMPORARY_LOCATION: Readonly<{ readonly source: '(temporary)'; readonly start: Readonly<{ readonly line: 1; readonly column: 0 }>; readonly end: Readonly<{ readonly line: 1; readonly column: 0 }>;}>;
variable UNKNOWN_POSITION
const UNKNOWN_POSITION: Readonly<{ readonly line: 1; readonly column: 0 }>;
variable visitorKeys
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'];};
variable voidMap
const voidMap: Set<string>;
function build
build: (ast: ASTv1.Node, options?: PrinterOptions) => string;
function buildAtName
buildAtName: (name: string, loc?: SourceLocation) => ASTv1.AtHead;
function buildAttr
buildAttr: ( name: string, value: ASTv1.AttrValue, loc?: SourceLocation) => ASTv1.AttrNode;
function buildBlock
buildBlock: ( path: BuilderHead, params: Nullable<Expression[]>, hash: Nullable<Hash>, _defaultBlock: PossiblyDeprecatedBlock, _elseBlock?: Nullable<PossiblyDeprecatedBlock>, loc?: SourceLocation, openStrip?: ASTv1.StripFlags, inverseStrip?: ASTv1.StripFlags, closeStrip?: ASTv1.StripFlags) => ASTv1.BlockStatement;
function buildBlockItself
buildBlockItself: ( body?: ASTv1.Statement[], params?: Array<ASTv1.VarHead | string>, chained?: boolean, loc?: SourceLocation) => ASTv1.Block;
function buildCleanPath
buildCleanPath: ( head: ASTv1.PathHead, tail?: string[], loc?: SourceLocation) => ASTv1.PathExpression;
function buildComment
buildComment: (value: string, loc?: SourceLocation) => ASTv1.CommentStatement;
function buildConcat
buildConcat: ( parts: (ASTv1.TextNode | ASTv1.MustacheStatement)[], loc?: SourceLocation) => ASTv1.ConcatStatement;
function buildElement
buildElement: ( tag: TagDescriptor, options?: BuildElementOptions) => ASTv1.ElementNode;
function buildElementModifier
buildElementModifier: ( path: BuilderHead, params?: ASTv1.Expression[], hash?: ASTv1.Hash, loc?: Nullable<SourceLocation>) => ASTv1.ElementModifierStatement;
function buildHash
buildHash: (pairs?: ASTv1.HashPair[], loc?: SourceLocation) => ASTv1.Hash;
function buildHeadFromString
buildHeadFromString: (original: string, loc?: SourceLocation) => ASTv1.PathHead;
function buildLiteral
buildLiteral: <T extends Literal>( type: T['type'], value: T['value'], loc?: SourceLocation) => T;
function buildLoc
buildLoc: { (loc: Nullable<SourceLocation>): SourceSpan; ( startLine: number, startColumn: number, endLine?: number, endColumn?: number, source?: string ): SourceSpan;};
function buildMustache
buildMustache: ( path: BuilderHead | ASTv1.Literal, params?: ASTv1.Expression[], hash?: ASTv1.Hash, trusting?: boolean, loc?: SourceLocation, strip?: ASTv1.StripFlags) => ASTv1.MustacheStatement;
function buildMustacheComment
buildMustacheComment: ( value: string, loc?: SourceLocation) => ASTv1.MustacheCommentStatement;
function buildPair
buildPair: ( key: string, value: ASTv1.Expression, loc?: SourceLocation) => ASTv1.HashPair;
function buildPath
buildPath: { ( path: ASTv1.PathExpression | string | { head: string; tail: string[] }, loc?: SourceLocation ): ASTv1.PathExpression; (path: BuilderHead, loc?: SourceLocation): CallableExpression; (path: Literal | BuilderHead, loc?: SourceLocation): Expression; (path: Expression, loc?: SourceLocation): Expression;};
function buildPosition
buildPosition: (line: number, column: number) => SourcePosition;
function buildProgram
buildProgram: ( body?: ASTv1.Statement[], blockParams?: string[], loc?: SourceLocation) => ASTv1.Template | ASTv1.Block;
function buildSexpr
buildSexpr: ( path: BuilderHead, params?: ASTv1.Expression[], hash?: ASTv1.Hash, loc?: SourceLocation) => ASTv1.SubExpression;
function buildTemplate
buildTemplate: ( body?: ASTv1.Statement[], blockParams?: string[], loc?: SourceLocation) => ASTv1.Template;
function buildText
buildText: (chars?: string, loc?: SourceLocation) => ASTv1.TextNode;
function buildThis
buildThis: (loc?: SourceLocation) => ASTv1.ThisHead;
function buildVar
buildVar: (name: string, loc?: SourceLocation) => ASTv1.VarHead;
function getVoidTags
getVoidTags: () => string[];
function hasSpan
hasSpan: (span: MaybeHasSourceSpan) => span is HasSourceSpan;
function isLocatedWithPositions
isLocatedWithPositions: ( location: LocatedWithOptionalPositions) => location is LocatedWithPositions;
function isLocatedWithPositionsArray
isLocatedWithPositionsArray: ( location: LocatedWithOptionalPositions[]) => location is PresentArray<LocatedWithPositions>;
function isVoidTag
isVoidTag: (tag: string) => boolean;
Examples when true: - link - liNK
Examples when false: - Link (component)
function loc
loc: (span: HasSourceSpan) => SourceSpan;
function match
match: <Out>( callback: (m: Matcher<Out, Matches>) => ExhaustiveMatcher<Out>) => MatchFn<Out>;
function maybeLoc
maybeLoc: (location: MaybeHasSourceSpan, fallback: SourceSpan) => SourceSpan;
function preprocess
preprocess: ( input: string | src.Source | HBS.Program, options?: PreprocessOptions) => ASTv1.Template;
function traverse
traverse: (node: ASTv1.Node, visitor: NodeVisitor) => void;
class CharPosition
class CharPosition implements PositionData {}
constructor
constructor(source: Source, charPos: number);
property charPos
readonly charPos: number;
property kind
readonly kind: string;
property offset
readonly offset: number;
A
CharPosition
always has an offset it can produce without any additional computation.
property source
readonly source: Source;
method toCharPos
toCharPos: () => CharPosition;
This is already a
CharPosition
.for the alternative.
method toHbsPos
toHbsPos: () => HbsPosition;
Convert the current character offset to an
HbsPosition
, if it was not already computed. Once aCharPosition
has computed itsHbsPosition
, it will not need to do compute it again, and the sameCharPosition
is retained when used as one of the ends of aSourceSpan
, so computing theHbsPosition
should be a one-time operation.
method toJSON
toJSON: () => SourcePosition;
Produce a Handlebars for this
CharPosition
. If thisCharPosition
was computed using , this will compute theSourcePosition
for the offset.
method wrap
wrap: () => SourceOffset;
class CharPositionSpan
class CharPositionSpan implements SpanData {}
constructor
constructor( source: Source, charPositions: { start: CharPosition; end: CharPosition });
property charPositions
readonly charPositions: { start: CharPosition; end: CharPosition };
property kind
readonly kind: string;
property source
readonly source: Source;
method asString
asString: () => string;
method getEnd
getEnd: () => AnyPosition;
method getModule
getModule: () => string;
method getStart
getStart: () => AnyPosition;
method locDidUpdate
locDidUpdate: () => void;
method serialize
serialize: () => SerializedSourceSpan;
method toCharPosSpan
toCharPosSpan: () => CharPositionSpan;
method toHbsSpan
toHbsSpan: () => HbsSpan;
method wrap
wrap: () => SourceSpan;
class HandlebarsNodeVisitors
abstract class HandlebarsNodeVisitors extends Parser {}
property pendingError
protected pendingError: Nullable<PendingError>;
method appendDynamicAttributeValuePart
appendDynamicAttributeValuePart: (part: ASTv1.MustacheStatement) => void;
method appendToCommentData
abstract appendToCommentData: (s: string) => void;
method beginAttributeValue
abstract beginAttributeValue: (quoted: boolean) => void;
method BlockStatement
BlockStatement: (block: HBS.BlockStatement) => ASTv1.BlockStatement | void;
method BooleanLiteral
BooleanLiteral: (boolean: HBS.BooleanLiteral) => ASTv1.BooleanLiteral;
method CommentStatement
CommentStatement: ( rawComment: HBS.CommentStatement) => Nullable<MustacheCommentStatement>;
method ContentStatement
ContentStatement: (content: HBS.ContentStatement) => void;
method Decorator
Decorator: (decorator: HBS.Decorator) => never;
method DecoratorBlock
DecoratorBlock: (decoratorBlock: HBS.DecoratorBlock) => never;
method finalizeTextPart
finalizeTextPart: () => void;
method finishAttributeValue
abstract finishAttributeValue: () => void;
method Hash
Hash: (hash: HBS.Hash) => ASTv1.Hash;
method MustacheStatement
MustacheStatement: ( rawMustache: HBS.MustacheStatement) => ASTv1.MustacheStatement | void;
method NullLiteral
NullLiteral: (nul: HBS.NullLiteral) => ASTv1.NullLiteral;
method NumberLiteral
NumberLiteral: (number: HBS.NumberLiteral) => ASTv1.NumberLiteral;
method parse
parse: (program: HBS.Program, blockParams: string[]) => ASTv1.Template;
method PartialBlockStatement
PartialBlockStatement: (partialBlock: HBS.PartialBlockStatement) => never;
method PartialStatement
PartialStatement: (partial: HBS.PartialStatement) => never;
method PathExpression
PathExpression: (path: HBS.PathExpression) => ASTv1.PathExpression;
method Program
Program: (program: HBS.Program, blockParams?: ASTv1.VarHead[]) => ASTv1.Block;
method startTextPart
startTextPart: () => void;
method StringLiteral
StringLiteral: (string: HBS.StringLiteral) => ASTv1.StringLiteral;
method SubExpression
SubExpression: (sexpr: HBS.SubExpression) => ASTv1.SubExpression;
method UndefinedLiteral
UndefinedLiteral: (undef: HBS.UndefinedLiteral) => ASTv1.UndefinedLiteral;
class HbsPosition
class HbsPosition implements PositionData {}
constructor
constructor(source: Source, hbsPos: SourcePosition, charPos?: number);
property hbsPos
readonly hbsPos: SourcePosition;
property kind
readonly kind: string;
property source
readonly source: Source;
method toCharPos
toCharPos: () => CharPosition;
Lazily compute the character offset from the . Once an
HbsPosition
has computed itsCharPosition
, it will not need to do compute it again, and the sameHbsPosition
is retained when used as one of the ends of aSourceSpan
, so computing theCharPosition
should be a one-time operation.
method toHbsPos
toHbsPos: () => HbsPosition;
This is already an
HbsPosition
.for the alternative.
method toJSON
toJSON: () => SourcePosition;
Return the that this
HbsPosition
was instantiated with. This operation does not need to compute anything.
method wrap
wrap: () => SourceOffset;
class HbsSpan
class HbsSpan implements SpanData {}
constructor
constructor( source: Source, hbsPositions: { start: HbsPosition; end: HbsPosition }, providedHbsLoc?: SourceLocation);
property hbsPositions
readonly hbsPositions: { start: HbsPosition; end: HbsPosition };
property kind
readonly kind: string;
property source
readonly source: Source;
method asString
asString: () => string;
method getEnd
getEnd: () => AnyPosition;
method getModule
getModule: () => string;
method getStart
getStart: () => AnyPosition;
method locDidUpdate
locDidUpdate: ({ start, end,}: { start?: SourcePosition; end?: SourcePosition;}) => void;
method serialize
serialize: () => SerializedConcreteSourceSpan;
method toCharPosSpan
toCharPosSpan: () => CharPositionSpan;
method toHbsLoc
toHbsLoc: () => SourceLocation;
method toHbsSpan
toHbsSpan: () => HbsSpan;
method wrap
wrap: () => SourceSpan;
class InvisiblePosition
class InvisiblePosition implements PositionData {}
constructor
constructor( kind: | OffsetKind.InternalsSynthetic | OffsetKind.NonExistent | OffsetKind.Broken, pos: SourcePosition);
property kind
readonly kind: | OffsetKind.InternalsSynthetic | OffsetKind.NonExistent | OffsetKind.Broken;
property offset
readonly offset: null;
property pos
readonly pos: SourcePosition;
method toCharPos
toCharPos: () => null;
A broken position cannot be turned into a .
method toJSON
toJSON: () => SourcePosition;
The serialization of an `InvisiblePosition is whatever Handlebars was originally identified as broken, non-existent or synthetic.
If an
InvisiblePosition
never had an source offset at all, this method returns for compatibility.
method wrap
wrap: () => SourceOffset;
class InvisibleSpan
class InvisibleSpan implements SpanData {}
constructor
constructor( kind: | OffsetKind.InternalsSynthetic | OffsetKind.NonExistent | OffsetKind.Broken, loc: SourceLocation, string?: string);
property kind
readonly kind: | OffsetKind.InternalsSynthetic | OffsetKind.NonExistent | OffsetKind.Broken;
property loc
readonly loc: SourceLocation;
property string
readonly string: string;
method asString
asString: () => string;
method getEnd
getEnd: () => AnyPosition;
method getModule
getModule: () => string;
method getStart
getStart: () => AnyPosition;
method locDidUpdate
locDidUpdate: ({ start, end,}: { start?: SourcePosition; end?: SourcePosition;}) => void;
method serialize
serialize: () => SerializedConcreteSourceSpan;
method toCharPosSpan
toCharPosSpan: () => InvisibleSpan;
method toHbsLoc
toHbsLoc: () => SourceLocation;
method toHbsSpan
toHbsSpan: () => null;
method wrap
wrap: () => SourceSpan;
class Matcher
class Matcher<Out, M extends Matches = Matches> {}
method check
protected check: () => MatchFn<Out>;
You didn't exhaustively match all possibilities.
method when
when: { ( left: OffsetKind.CharPosition, right: OffsetKind.HbsPosition, callback: (left: CharPosition, right: HbsPosition) => Out ): ExhaustiveCheck<Out, M, 'Char,Hbs'>; ( left: OffsetKind.HbsPosition, right: OffsetKind.CharPosition, callback: (left: HbsPosition, right: CharPosition) => Out ): ExhaustiveCheck<Out, M, 'Hbs,Char'>; ( left: OffsetKind.HbsPosition, right: OffsetKind.HbsPosition, callback: (left: HbsPosition, right: HbsPosition) => Out ): ExhaustiveCheck<Out, M, 'Hbs,Hbs'>; ( left: OffsetKind.CharPosition, right: OffsetKind.CharPosition, callback: (left: CharPosition, right: CharPosition) => Out ): ExhaustiveCheck<Out, M, 'Char,Char'>; ( left: 'IS_INVISIBLE', right: 'MATCH_ANY', callback: (left: InvisiblePosition, right: PositionData) => Out ): Matcher<Out, Exclude<M, 'Invisible,Any'>>; ( left: 'MATCH_ANY', right: 'IS_INVISIBLE', callback: (left: PositionData, right: InvisiblePosition) => Out ): ExhaustiveCheck<Out, M, 'Any,Invisible'>; ( left: 'MATCH_ANY', right: 'MATCH_ANY', callback: (left: PositionData, right: PositionData) => Out ): ExhaustiveMatcher<Out>;};
class Parser
abstract class Parser {}
constructor
constructor( source: src.Source, entityParser?: EntityParser, mode?: 'precompile' | 'codemod');
property currentAttr
readonly currentAttr: Attribute;
property currentAttribute
currentAttribute: Nullable<Attribute>;
property currentComment
readonly currentComment: ParserNodeBuilder<CommentStatement>;
property currentData
readonly currentData: ParserNodeBuilder<TextNode>;
property currentEndTag
readonly currentEndTag: ParserNodeBuilder<EndTag>;
property currentNode
currentNode: Nullable< Readonly< | ParserNodeBuilder<CommentStatement> | ParserNodeBuilder<TextNode> | ParserNodeBuilder<StartTag> | ParserNodeBuilder<EndTag> >>;
property currentStartTag
readonly currentStartTag: ParserNodeBuilder<StartTag>;
property currentTag
readonly currentTag: ParserNodeBuilder<StartTag> | ParserNodeBuilder<EndTag>;
property elementStack
protected elementStack: ParentNode[];
property source
readonly source: src.Source;
property tokenizer
tokenizer: EventedTokenizer;
method acceptNode
acceptNode: <T extends keyof HBS.NodeMap>(node: HBS.Node<T>) => HBS.Output<T>;
method appendToAttributeName
abstract appendToAttributeName: (char: string) => void;
method appendToAttributeValue
abstract appendToAttributeValue: (char: string) => void;
method appendToCommentData
abstract appendToCommentData: (char: string) => void;
method appendToData
abstract appendToData: (char: string) => void;
method appendToTagName
abstract appendToTagName: (char: string) => void;
method beginAttribute
abstract beginAttribute: () => void;
method beginAttributeValue
abstract beginAttributeValue: (quoted: boolean) => void;
method beginComment
abstract beginComment: () => void;
method beginData
abstract beginData: () => void;
method beginEndTag
abstract beginEndTag: () => void;
method beginStartTag
abstract beginStartTag: () => void;
method BlockStatement
abstract BlockStatement: ( node: HBS.BlockStatement) => HBS.Output<'BlockStatement'>;
method BooleanLiteral
abstract BooleanLiteral: ( node: HBS.BooleanLiteral) => HBS.Output<'BooleanLiteral'>;
method CommentStatement
abstract CommentStatement: ( node: HBS.CommentStatement) => HBS.Output<'CommentStatement'>;
method ContentStatement
abstract ContentStatement: ( node: HBS.ContentStatement) => HBS.Output<'ContentStatement'>;
method currentElement
currentElement: () => ASTv1.ParentNode;
method Decorator
abstract Decorator: (node: HBS.Decorator) => HBS.Output<'Decorator'>;
method DecoratorBlock
abstract DecoratorBlock: ( node: HBS.DecoratorBlock) => HBS.Output<'DecoratorBlock'>;
method finish
finish: <T extends { loc: src.SourceSpan }>(node: ParserNodeBuilder<T>) => T;
method finishAttributeValue
abstract finishAttributeValue: () => void;
method finishComment
abstract finishComment: () => void;
method finishData
abstract finishData: () => void;
method finishTag
abstract finishTag: () => void;
method markTagAsSelfClosing
abstract markTagAsSelfClosing: () => void;
method MustacheStatement
abstract MustacheStatement: ( node: HBS.MustacheStatement) => HBS.Output<'MustacheStatement'>;
method NullLiteral
abstract NullLiteral: (node: HBS.NullLiteral) => HBS.Output<'NullLiteral'>;
method NumberLiteral
abstract NumberLiteral: (node: HBS.NumberLiteral) => HBS.Output<'NumberLiteral'>;
method offset
offset: () => src.SourceOffset;
method parse
abstract parse: (node: HBS.Program, locals: string[]) => ASTv1.Template;
method PartialBlockStatement
abstract PartialBlockStatement: ( node: HBS.PartialBlockStatement) => HBS.Output<'PartialBlockStatement'>;
method PartialStatement
abstract PartialStatement: ( node: HBS.PartialStatement) => HBS.Output<'PartialStatement'>;
method PathExpression
abstract PathExpression: ( node: HBS.PathExpression) => HBS.Output<'PathExpression'>;
method pos
pos: ({ line, column }: src.SourcePosition) => src.SourceOffset;
method Program
abstract Program: (node: HBS.Program) => HBS.Output<'Program'>;
method reportSyntaxError
abstract reportSyntaxError: (error: string) => void;
method reset
abstract reset: () => void;
method sourceForNode
sourceForNode: (node: HBS.Node, endNode?: { loc: HBS.SourceLocation }) => string;
method StringLiteral
abstract StringLiteral: (node: HBS.StringLiteral) => HBS.Output<'StringLiteral'>;
method SubExpression
abstract SubExpression: (node: HBS.SubExpression) => HBS.Output<'SubExpression'>;
method tagOpen
abstract tagOpen: () => void;
method UndefinedLiteral
abstract UndefinedLiteral: ( node: HBS.UndefinedLiteral) => HBS.Output<'UndefinedLiteral'>;
class Printer
class Printer {}
constructor
constructor(options: PrinterOptions);
method AttrNode
AttrNode: (attr: ASTv1.AttrNode) => void;
method AttrNodeValue
AttrNodeValue: (value: ASTv1.AttrNode['value']) => void;
method Block
Block: (block: ASTv1.Block) => void;
method BlockParams
BlockParams: (blockParams: string[]) => void;
method BlockStatement
BlockStatement: (block: ASTv1.BlockStatement) => void;
method BooleanLiteral
BooleanLiteral: (bool: ASTv1.BooleanLiteral) => void;
method CloseElementNode
CloseElementNode: (el: ASTv1.ElementNode) => void;
method CommentStatement
CommentStatement: (comment: ASTv1.CommentStatement) => void;
method ConcatStatement
ConcatStatement: (concat: ASTv1.ConcatStatement) => void;
method ElementModifierStatement
ElementModifierStatement: (mod: ASTv1.ElementModifierStatement) => void;
method ElementNode
ElementNode: (el: ASTv1.ElementNode) => void;
method Expression
Expression: (expression: ASTv1.Expression) => void;
method handledByOverride
handledByOverride: ( node: ASTv1.Node, ensureLeadingWhitespace?: boolean) => boolean;
method Hash
Hash: (hash: ASTv1.Hash) => void;
method HashPair
HashPair: (pair: ASTv1.HashPair) => void;
method Literal
Literal: (literal: ASTv1.Literal) => void;
method MustacheCommentStatement
MustacheCommentStatement: (comment: ASTv1.MustacheCommentStatement) => void;
method MustacheStatement
MustacheStatement: (mustache: ASTv1.MustacheStatement) => void;
method Node
Node: (node: ASTv1.Node) => void;
method NullLiteral
NullLiteral: (node: ASTv1.NullLiteral) => void;
method NumberLiteral
NumberLiteral: (number: ASTv1.NumberLiteral) => void;
method OpenElementNode
OpenElementNode: (el: ASTv1.ElementNode) => void;
method Params
Params: (params: ASTv1.Expression[]) => void;
method PathExpression
PathExpression: (path: ASTv1.PathExpression) => void;
method print
print: (node: ASTv1.Node) => string;
method StringLiteral
StringLiteral: (str: ASTv1.StringLiteral) => void;
method SubExpression
SubExpression: (sexp: ASTv1.SubExpression) => void;
method Template
Template: (template: ASTv1.Template) => void;
method TextNode
TextNode: (text: ASTv1.TextNode, isAttr?: boolean) => void;
method TopLevelStatement
TopLevelStatement: ( statement: ASTv1.TopLevelStatement | ASTv1.Template | ASTv1.AttrNode) => void;
method TopLevelStatements
TopLevelStatements: (statements: ASTv1.TopLevelStatement[]) => void;
method UndefinedLiteral
UndefinedLiteral: (node: ASTv1.UndefinedLiteral) => 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 from
static from: (source: string, options?: PrecompileOptions) => Source;
method hbsPosFor
hbsPosFor: (offset: number) => Nullable<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 SourceOffset
class SourceOffset {}
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 aSourcePosition
from the Handlebars AST, which can be converted to aCharPosition
on demand. -InvisiblePosition
, which represents a position not in source (@see {InvisiblePosition})
constructor
constructor(data: PositionData & AnyPosition);
property data
readonly data: PositionData & AnyPosition;
property offset
readonly offset: number;
Get the character offset for this
SourceOffset
, if possible.
method broken
static broken: (pos?: SourcePosition) => SourceOffset;
Create a
SourceOffset
that corresponds to a brokenSourcePosition
. This means that the calling code determined (or knows) that theSourceLocation
doesn't correspond correctly to any part of the source.
method collapsed
collapsed: () => SourceSpan;
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.
method eql
eql: (right: SourceOffset) => boolean;
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.
method forHbsPos
static forHbsPos: (source: Source, pos: SourcePosition) => SourceOffset;
Create a
SourceOffset
from a HandlebarsSourcePosition
. It's stored as-is, and converted into a character offset on demand, which avoids unnecessarily computing the offset of everySourceLocation
, but also means that brokenSourcePosition
s are not always detected.
method move
move: (by: number) => SourceOffset;
Create a
SourceOffset
by moving the character position represented by this source offset forward or backward (ifby
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.
method toJSON
toJSON: () => SourcePosition;
Convert this
SourceOffset
into a Handlebars for compatibility with existing plugins.
method until
until: (other: SourceOffset) => SourceSpan;
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.
class SourceSlice
class SourceSlice<Chars extends string = string> {}
constructor
constructor(options: { loc: src.SourceSpan; chars: Chars });
property chars
readonly chars: string;
property loc
readonly loc: src.SourceSpan;
method getString
getString: () => string;
method load
static load: ( source: src.Source, slice: SerializedSourceSlice<string>) => SourceSlice<string>;
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<string>;
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: (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 TokenizerEventHandlers
class TokenizerEventHandlers extends HandlebarsNodeVisitors {}
method appendToAttributeName
appendToAttributeName: (char: string) => void;
method appendToAttributeValue
appendToAttributeValue: (char: string) => void;
method appendToCommentData
appendToCommentData: (char: string) => void;
method appendToData
appendToData: (char: string) => void;
method appendToTagName
appendToTagName: (char: string) => void;
method assembleAttributeValue
assembleAttributeValue: ( parts: ASTv1.AttrPart[], isQuoted: boolean, isDynamic: boolean, span: src.SourceSpan) => ASTv1.AttrValue;
method assembleConcatenatedValue
assembleConcatenatedValue: ( parts: (ASTv1.MustacheStatement | ASTv1.TextNode)[]) => ASTv1.ConcatStatement;
method beginAttribute
beginAttribute: () => void;
method beginAttributeValue
beginAttributeValue: (isQuoted: boolean) => void;
method beginComment
beginComment: () => void;
method beginData
beginData: () => void;
method beginEndTag
beginEndTag: () => void;
method beginStartTag
beginStartTag: () => void;
method finishAttributeValue
finishAttributeValue: () => void;
method finishComment
finishComment: () => void;
method finishData
finishData: () => void;
method finishEndTag
finishEndTag: (isVoid: boolean) => void;
method finishStartTag
finishStartTag: () => void;
method finishTag
finishTag: () => void;
method markTagAsSelfClosing
markTagAsSelfClosing: () => void;
method reportSyntaxError
reportSyntaxError: (message: string) => void;
method reset
reset: () => void;
method tagOpen
tagOpen: () => void;
method validateEndTag
validateEndTag: ( tag: StartTag | EndTag, element: ASTv1.ElementNode, selfClosing: boolean) => void;
class Walker
class Walker {}
constructor
constructor(order?: {});
property order
order?: {};
property stack
stack: unknown[];
method children
children: <N extends Node>( node: N & ASTv1.Node, callback: NodeCallback<N & ASTv1.Node>) => void;
method visit
visit: <N extends Node>(node: Nullable<N>, visitor: NodeCallback<N>) => void;
class WalkerPath
class WalkerPath<N extends ASTv1.Node> {}
constructor
constructor(node: Node, parent?: WalkerPath<Node>, parentKey?: string);
property node
node: Node;
property parent
parent: WalkerPath<Node>;
property parentKey
parentKey: string;
property parentNode
readonly parentNode: Node;
method parents
parents: () => Iterable<WalkerPath<Node>>;
class When
class When<Out> {}
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 AtHead
interface AtHead {}
interface Attribute
interface Attribute {}
property currentPart
currentPart: ASTv1.TextNode | null;
property isDynamic
isDynamic: boolean;
property isQuoted
isQuoted: boolean;
property name
name: string;
property parts
parts: (ASTv1.MustacheStatement | ASTv1.TextNode)[];
property start
start: src.SourceOffset;
property valueSpan
valueSpan: src.SourceSpan;
interface AttrNode
interface AttrNode extends BaseNode {}
interface Block
interface Block extends CommonProgram {}
property blockParams
blockParams: string[];
string accessor for params.name
property chained
chained?: boolean;
property params
params: VarHead[];
property type
type: 'Block';
interface BlockStatement
interface BlockStatement extends BaseNode {}
property chained
chained?: boolean;
property closeStrip
closeStrip: StripFlags;
property hash
hash: Hash;
property inverse
inverse?: Nullable<Block>;
property inverseStrip
inverseStrip: StripFlags;
property openStrip
openStrip: StripFlags;
property params
params: Expression[];
property path
path: CallableExpression;
property program
program: Block;
property type
type: 'BlockStatement';
interface BooleanLiteral
interface BooleanLiteral extends BaseNode {}
interface BuildElementOptions
interface BuildElementOptions {}
property attrs
attrs?: ASTv1.AttrNode[];
property blockParams
blockParams?: ASTv1.VarHead[] | string[];
property children
children?: ASTv1.Statement[];
property closeTag
closeTag?: Nullable<SourceLocation>;
property comments
comments?: ASTv1.MustacheCommentStatement[];
property loc
loc?: SourceLocation;
property modifiers
modifiers?: ASTv1.ElementModifierStatement[];
property openTag
openTag?: SourceLocation;
interface CallParts
interface CallParts {}
interface CommentStatement
interface CommentStatement extends BaseNode {}
interface CommonProgram
interface CommonProgram extends BaseNode {}
property body
body: Statement[];
interface ConcatStatement
interface ConcatStatement extends BaseNode {}
interface ElementModifierStatement
interface ElementModifierStatement extends BaseNode {}
interface ElementNode
interface ElementNode extends BaseNode {}
property attributes
attributes: AttrNode[];
property blockParams
blockParams: string[];
string accessor for params.name
property children
children: Statement[];
property closeTag
closeTag: Nullable<src.SourceSpan>;
span for the close tag, null for void or self-closing tags
property comments
comments: MustacheCommentStatement[];
property modifiers
modifiers: ElementModifierStatement[];
property openTag
openTag: src.SourceSpan;
span for the open tag
property params
params: VarHead[];
property path
path: PathExpression;
property selfClosing
selfClosing: boolean;
property tag
tag: string;
string accessor for path.original
property type
type: 'ElementNode';
interface EndTag
interface EndTag {}
interface ExhaustiveMatcher
interface ExhaustiveMatcher<Out> {}
method check
check: () => MatchFn<Out>;
interface FullKeyTraversal
interface FullKeyTraversal<N extends ASTv1.Node, K extends string> {}
interface FullNodeTraversal
interface FullNodeTraversal<N extends ASTv1.Node> {}
interface HandlebarsParseOptions
interface HandlebarsParseOptions {}
property ignoreStandalone
ignoreStandalone?: boolean;
property srcName
srcName?: string;
interface Hash
interface Hash extends BaseNode {}
interface HashPair
interface HashPair extends BaseNode {}
interface MinimalPathExpression
interface MinimalPathExpression extends BaseNode {}
interface MustacheCommentStatement
interface MustacheCommentStatement extends BaseNode {}
interface MustacheStatement
interface MustacheStatement extends BaseNode {}
interface NullLiteral
interface NullLiteral extends BaseNode {}
interface NumberLiteral
interface NumberLiteral extends BaseNode {}
interface PathExpression
interface PathExpression extends MinimalPathExpression {}
property data
readonly data: boolean;
Deprecated
use `head.type' instead
property head
head: PathHead;
property original
original: string;
property parts
parts: readonly string[];
Deprecated
use
head
andtail
instead
property tail
tail: string[];
property this
readonly this: boolean;
Deprecated
use
head.type
instead
property type
type: 'PathExpression';
interface PendingError
interface PendingError {}
interface PositionData
interface PositionData {}
All positions have these details in common. Most notably, all three kinds of positions can must be able to attempt to convert themselves into .
interface PrecompileOptions
interface PrecompileOptions extends PreprocessOptions {}
property customizeComponentName
customizeComponentName?: ((input: string) => string) | undefined;
property id
id?: TemplateIdFn;
property keywords
keywords?: readonly string[];
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.
interface PrecompileOptionsWithLexicalScope
interface PrecompileOptionsWithLexicalScope extends PrecompileOptions {}
property lexicalScope
lexicalScope: (variable: string) => boolean;
interface PreprocessOptions
interface PreprocessOptions {}
property customizeComponentName
customizeComponentName?: ((input: string) => string) | undefined;
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;
interface PrinterOptions
interface PrinterOptions {}
property entityEncoding
entityEncoding: ASTv1.EntityEncodingState;
method override
override: (ast: ASTv1.Node, options: PrinterOptions) => void | string;
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.
Parameter ast
the ast node to be printed
Parameter options
the options specified during the print() invocation
interface SourceLocation
interface SourceLocation {}
interface SourcePosition
interface SourcePosition {}
interface SpanData
interface SpanData {}
All spans have these details in common.
property kind
readonly kind: OffsetKind;
method asString
asString: () => string;
Convert this span into a string. If the span is broken, return
''
.
method getEnd
getEnd: () => AnyPosition;
Get the ending position for this span. Try to avoid creating new position objects, as they cache computations.
method getModule
getModule: () => string;
Gets the module the span was located in.
method getStart
getStart: () => AnyPosition;
Get the starting position for this span. Try to avoid creating new position objects, as they cache computations.
method locDidUpdate
locDidUpdate: (changes: { start?: SourcePosition; end?: SourcePosition;}) => void;
For compatibility, whenever the
start
orend
of a changes, spans are notified of the change so they can update themselves. This shouldn't happen outside of AST plugins.
method serialize
serialize: () => SerializedSourceSpan;
Serialize into a , which is compact and designed for readability in context like AST Explorer. If you need a , use .
method toHbsSpan
toHbsSpan: () => HbsSpan;
Compute the
SourceLocation
for this span, returned as an instance ofHbsSpan
.
interface StartTag
interface StartTag {}
property attributes
readonly attributes: ASTv1.AttrNode[];
property comments
readonly comments: ASTv1.MustacheCommentStatement[];
property loc
readonly loc: src.SourceSpan;
property modifiers
readonly modifiers: ASTv1.ElementModifierStatement[];
property name
name: string;
property nameEnd
nameEnd: Nullable<src.SourceOffset>;
property nameStart
nameStart: Nullable<src.SourceOffset>;
property params
readonly params: ASTv1.VarHead[];
property selfClosing
selfClosing: boolean;
property type
readonly type: 'StartTag';
interface StringLiteral
interface StringLiteral extends BaseNode {}
interface StripFlags
interface StripFlags {}
interface SubExpression
interface SubExpression extends BaseNode {}
interface Syntax
interface Syntax {}
interface Template
interface Template extends CommonProgram {}
property blockParams
blockParams: string[];
property type
type: 'Template';
interface TemplateIdFn
interface TemplateIdFn {}
call signature
(src: string): Nullable<string>;
interface TextNode
interface TextNode extends BaseNode {}
interface ThisHead
interface ThisHead {}
interface UndefinedLiteral
interface UndefinedLiteral extends BaseNode {}
interface VarHead
interface VarHead {}
enum OffsetKind
enum OffsetKind { CharPosition = 'CharPosition', HbsPosition = 'HbsPosition', InternalsSynthetic = 'InternalsSynthetic', NonExistent = 'NonExistent', Broken = 'Broken',}
member Broken
Broken = 'Broken'
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.
member CharPosition
CharPosition = 'CharPosition'
We have already computed the character position of this offset or span.
member HbsPosition
HbsPosition = 'HbsPosition'
This offset or span was instantiated with a Handlebars SourcePosition or SourceLocation. Its character position will be computed on demand.
member InternalsSynthetic
InternalsSynthetic = 'InternalsSynthetic'
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.
member NonExistent
NonExistent = 'NonExistent'
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 AnyPosition
type AnyPosition = HbsPosition | CharPosition | InvisiblePosition;
type AnySpan
type AnySpan = HbsSpan | CharPositionSpan | InvisibleSpan;
type AttrPart
type AttrPart = TextNode | MustacheStatement;
type AttrSexp
type AttrSexp = [string, ASTv1.AttrNode['value'] | string, LocSexp?];
type AttrValue
type AttrValue = TextNode | MustacheStatement | ConcatStatement;
type BROKEN
type BROKEN = 'BROKEN';
type BuilderHead
type BuilderHead = string | ASTv1.CallableExpression;
type CallableExpression
type CallableExpression = SubExpression | PathExpression;
type CallNode
type CallNode = | MustacheStatement | BlockStatement | ElementModifierStatement | SubExpression;
type ElementComment
type ElementComment = ASTv1.MustacheCommentStatement | SourceLocation | string;
type ElementParts
type ElementParts = | ['attrs', ...AttrSexp[]] | ['modifiers', ...ModifierSexp[]] | ['body', ...ASTv1.Statement[]] | ['comments', ...ElementComment[]] | ['as', ...string[]] | ['loc', SourceLocation];
type EntityEncodingState
type EntityEncodingState = 'transformed' | 'raw';
type ExhaustiveCheck
type ExhaustiveCheck<Out, In extends Matches, Removed extends Matches> = Exclude< In, Removed> extends never ? ExhaustiveMatcher<Out> : Matcher<Out, Exclude<In, Removed>>;
type Expression
type Expression = Nodes[ExpressionName];
type ExpressionName
type ExpressionName = 'SubExpression' | 'PathExpression' | LiteralName;
type Expressions
type Expressions = Pick<Nodes, ExpressionName>;
type HasSourceLocation
type HasSourceLocation = | SourceLocation | LocatedWithPositions | PresentArray<LocatedWithPositions>;
type HasSourceSpan
type HasSourceSpan = | { loc: SourceSpan; } | SourceSpan | [HasSourceSpan, ...HasSourceSpan[]];
type HasSpan
type HasSpan = SourceSpan | LocatedWithSpan | PresentArray<LocatedWithSpan>;
type IsInvisible
type IsInvisible = 'IS_INVISIBLE';
type KeyHandler
type KeyHandler<N extends ASTv1.Node, K extends VisitorKey<N>> = ( node: N, key: K) => void;
type KeysVisitor
type KeysVisitor<N extends ASTv1.Node> = { [P in VisitorKey<N>]?: KeyTraversal<N, P>;} & { All?: KeyTraversal<N, VisitorKey<N>>; /** * @deprecated use Template or Block instead */ Program?: KeyTraversal<ASTv1.Template | ASTv1.Block, 'body'>;};
type KeyTraversal
type KeyTraversal<N extends ASTv1.Node, K extends VisitorKey<N>> = | FullKeyTraversal<N, K> | KeyHandler<N, K>;
type Literal
type Literal = Nodes[LiteralName];
type LiteralName
type LiteralName = | 'StringLiteral' | 'BooleanLiteral' | 'NumberLiteral' | 'UndefinedLiteral' | 'NullLiteral';
type LocatedWithOptionalPositions
type LocatedWithOptionalPositions = { loc?: SourceLocation;};
type LocatedWithOptionalSpan
type LocatedWithOptionalSpan = { offsets: SourceSpan | null;};
type LocatedWithPositions
type LocatedWithPositions = { loc: SourceLocation;};
type LocatedWithSpan
type LocatedWithSpan = { offsets: SourceSpan;};
type LocSexp
type LocSexp = ['loc', SourceLocation];
type MatchAny
type MatchAny = 'MATCH_ANY';
type Matches
type Matches = | 'Char,Hbs' | 'Hbs,Char' | 'Hbs,Hbs' | 'Char,Char' | 'Invisible,Any' | 'Any,Invisible';
type MatchFn
type MatchFn<Out> = (left: PositionData, right: PositionData) => Out;
type MaybeHasSourceLocation
type MaybeHasSourceLocation = | null | LocatedWithOptionalPositions | LocatedWithOptionalPositions[];
type MaybeHasSourceSpan
type MaybeHasSourceSpan = | { loc: SourceSpan; } | SourceSpan | MaybeHasSourceSpan[];
type MaybeHasSpan
type MaybeHasSpan = | SourceSpan | LocatedWithOptionalSpan | LocatedWithOptionalSpan[] | null;
type ModifierSexp
type ModifierSexp = | string | [PathSexp, LocSexp?] | [PathSexp, ASTv1.Expression[], LocSexp?] | [PathSexp, ASTv1.Expression[], Dict<ASTv1.Expression>, LocSexp?];
type Node
type Node = Nodes[NodeType];
type NodeCallback
type NodeCallback<N extends ASTv1.Node> = (node: N, walker: Walker) => void;
type NodeHandler
type NodeHandler<N extends ASTv1.Node> = (node: N, path: WalkerPath<N>) => void;
type Nodes
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 NodeTraversal
type NodeTraversal<N extends ASTv1.Node> = FullNodeTraversal<N> | NodeHandler<N>;
type NodeType
type NodeType = keyof Nodes;
type NodeVisitor
type NodeVisitor = { [P in keyof ASTv1.Nodes]?: NodeTraversal<ASTv1.Nodes[P]>;} & { All?: NodeTraversal<ASTv1.Node>; /** * @deprecated use Template or Block instead */ Program?: NodeTraversal<ASTv1.Template | ASTv1.Block>;};
type ParentNode
type ParentNode = Template | Block | ElementNode;
type ParserNodeBuilder
type ParserNodeBuilder< N extends { loc: src.SourceSpan; }> = Omit<N, 'loc'> & { start: src.SourceOffset;};
type PathHead
type PathHead = ThisHead | AtHead | VarHead;
type PathSexp
type PathSexp = string | ['path', string, LocSexp?];
type Pattern
type Pattern = OffsetKind | IsInvisible | MatchAny;
type PossiblyDeprecatedBlock
type PossiblyDeprecatedBlock = ASTv1.Block | ASTv1.Template;
type Program
type Program = Template | Block;
Deprecated
use Template or Block instead
type SerializedConcreteSourceSpan
type SerializedConcreteSourceSpan = /** collapsed */ | number | /** normal */ [start: number, size: number] | /** synthetic */ string;
type SerializedSourceSlice
type SerializedSourceSlice<Chars extends string = string> = [ chars: Chars, span: src.SerializedSourceSpan];
type SerializedSourceSpan
type SerializedSourceSpan = | SerializedConcreteSourceSpan | OffsetKind.NonExistent | OffsetKind.Broken;
type SexpValue
type SexpValue = | string | ASTv1.Expression[] | Dict<ASTv1.Expression> | LocSexp | PathSexp | undefined;
type Statement
type Statement = Nodes[StatementName];
type StatementName
type StatementName = | 'MustacheStatement' | 'CommentStatement' | 'BlockStatement' | 'MustacheCommentStatement' | 'TextNode' | 'ElementNode';
type Statements
type Statements = Pick<Nodes, StatementName>;
type SubNode
type SubNode = SubNodes[SubNodeType];
type SubNodes
type SubNodes = { ThisHead: ThisHead; AtHead: AtHead; VarHead: VarHead;};
type SubNodeType
type SubNodeType = keyof SubNodes;
type TagDescriptor
type TagDescriptor = | string | ASTv1.PathExpression | { path: ASTv1.PathExpression; selfClosing?: boolean; } | { name: string; selfClosing?: boolean; };
type TopLevelStatement
type TopLevelStatement = Statement | Nodes['Block'];
type ToSourceOffset
type ToSourceOffset = number | SourceOffset;
type VisitorKey
type VisitorKey<N extends ASTv1.Node> = VisitorKeys[N['type']] & keyof N;
type VisitorKeys
type VisitorKeys = { [P in keyof VisitorKeysMap]: VisitorKeysMap[P][number];};
type VisitorKeysMap
type VisitorKeysMap = typeof visitorKeys;
namespace ASTv1
namespace ASTv1 {}
variable BROKEN
const BROKEN: string;
Used to indicate that an attempt to convert a
SourcePosition
to a character offset failed. It is separate fromnull
so thatnull
can be used to indicate that the computation wasn't yet attempted (and therefore to cache the failure)
variable BROKEN_LOCATION
const BROKEN_LOCATION: Readonly<{ readonly source: '(broken)'; readonly start: Readonly<{ readonly line: 1; readonly column: 0 }>; readonly end: Readonly<{ readonly line: 1; readonly column: 0 }>;}>;
variable IsInvisible
const IsInvisible: string;
variable MatchAny
const MatchAny: string;
This file implements the DSL used by span and offset in places where they need to exhaustively consider all combinations of states (Handlebars offsets, character offsets and invisible/broken offsets).
It's probably overkill, but it makes the code that uses it clear. It could be refactored or removed.
variable NON_EXISTENT_LOCATION
const NON_EXISTENT_LOCATION: Readonly<{ readonly source: '(nonexistent)'; readonly start: Readonly<{ readonly line: 1; readonly column: 0 }>; readonly end: Readonly<{ readonly line: 1; readonly column: 0 }>;}>;
variable print
const print: (ast: Node, options?: PrinterOptions) => string;
variable publicBuilder
const publicBuilder: { mustache: ( path: Literal | BuilderHead, params?: Expression[], hash?: Hash, trusting?: boolean, loc?: SourceLocation, strip?: StripFlags ) => MustacheStatement; block: ( path: BuilderHead, params: Nullable<Expression[]>, hash: Nullable<Hash>, _defaultBlock: PossiblyDeprecatedBlock, _elseBlock?: Nullable<PossiblyDeprecatedBlock>, loc?: SourceLocation, openStrip?: StripFlags, inverseStrip?: StripFlags, closeStrip?: StripFlags ) => BlockStatement; comment: (value: string, loc?: SourceLocation) => CommentStatement; mustacheComment: ( value: string, loc?: SourceLocation ) => MustacheCommentStatement; element: (tag: TagDescriptor, options?: BuildElementOptions) => ElementNode; elementModifier: ( path: BuilderHead, params?: Expression[], hash?: Hash, loc?: Nullable<SourceLocation> ) => ElementModifierStatement; attr: (name: string, value: AttrValue, loc?: SourceLocation) => AttrNode; text: (chars?: string, loc?: SourceLocation) => TextNode; sexpr: ( path: BuilderHead, params?: Expression[], hash?: Hash, loc?: SourceLocation ) => SubExpression; concat: ( parts: (MustacheStatement | TextNode)[], loc?: SourceLocation ) => ConcatStatement; hash: (pairs?: HashPair[], loc?: SourceLocation) => Hash; pair: (key: string, value: Expression, loc?: SourceLocation) => HashPair; literal: <T extends Literal>( type: T['type'], value: T['value'], loc?: SourceLocation ) => T; program: ( body?: Statement[], blockParams?: string[], loc?: SourceLocation ) => Template | Block; blockItself: ( body?: Statement[], params?: (string | VarHead)[], chained?: boolean, loc?: SourceLocation ) => Block; template: ( body?: Statement[], blockParams?: string[], loc?: SourceLocation ) => Template; loc: { (loc: Nullable<SourceLocation>): SourceSpan; ( startLine: number, startColumn: number, endLine?: number, endColumn?: number, source?: string ): SourceSpan; }; pos: (line: number, column: number) => SourcePosition; path: { ( path: string | PathExpression | { head: string; tail: string[] }, loc?: SourceLocation ): PathExpression; (path: BuilderHead, loc?: SourceLocation): CallableExpression; (path: Literal | BuilderHead, loc?: SourceLocation): Expression; (path: Expression, loc?: SourceLocation): Expression; }; fullPath: ( head: PathHead, tail?: string[], loc?: SourceLocation ) => PathExpression; head: (original: string, loc?: SourceLocation) => PathHead; at: (name: string, loc?: SourceLocation) => AtHead; var: (name: string, loc?: SourceLocation) => VarHead; this: (loc?: SourceLocation) => ThisHead; string: (value: string) => StringLiteral; boolean: (value: boolean) => BooleanLiteral; number: (value: number) => NumberLiteral; undefined(): UndefinedLiteral; null(): NullLiteral;};
variable span
const span: MatchFn<SourceSpan>;
variable SYNTHETIC
const SYNTHETIC: Readonly<{ readonly source: '(synthetic)'; readonly start: Readonly<{ readonly line: 1; readonly column: 0 }>; readonly end: Readonly<{ readonly line: 1; readonly column: 0 }>;}>;
Deprecated
variable SYNTHETIC_LOCATION
const SYNTHETIC_LOCATION: Readonly<{ readonly source: '(synthetic)'; readonly start: Readonly<{ readonly line: 1; readonly column: 0 }>; readonly end: Readonly<{ readonly line: 1; readonly column: 0 }>;}>;
variable TEMPORARY_LOCATION
const TEMPORARY_LOCATION: Readonly<{ readonly source: '(temporary)'; readonly start: Readonly<{ readonly line: 1; readonly column: 0 }>; readonly end: Readonly<{ readonly line: 1; readonly column: 0 }>;}>;
variable UNKNOWN_POSITION
const UNKNOWN_POSITION: Readonly<{ readonly line: 1; readonly column: 0 }>;
variable visitorKeys
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'];};
variable voidMap
const voidMap: Set<string>;
function build
build: (ast: ASTv1.Node, options?: PrinterOptions) => string;
function buildAtName
buildAtName: (name: string, loc?: SourceLocation) => ASTv1.AtHead;
function buildAttr
buildAttr: ( name: string, value: ASTv1.AttrValue, loc?: SourceLocation) => ASTv1.AttrNode;
function buildBlock
buildBlock: ( path: BuilderHead, params: Nullable<Expression[]>, hash: Nullable<Hash>, _defaultBlock: PossiblyDeprecatedBlock, _elseBlock?: Nullable<PossiblyDeprecatedBlock>, loc?: SourceLocation, openStrip?: ASTv1.StripFlags, inverseStrip?: ASTv1.StripFlags, closeStrip?: ASTv1.StripFlags) => ASTv1.BlockStatement;
function buildBlockItself
buildBlockItself: ( body?: ASTv1.Statement[], params?: Array<ASTv1.VarHead | string>, chained?: boolean, loc?: SourceLocation) => ASTv1.Block;
function buildCleanPath
buildCleanPath: ( head: ASTv1.PathHead, tail?: string[], loc?: SourceLocation) => ASTv1.PathExpression;
function buildComment
buildComment: (value: string, loc?: SourceLocation) => ASTv1.CommentStatement;
function buildConcat
buildConcat: ( parts: (ASTv1.TextNode | ASTv1.MustacheStatement)[], loc?: SourceLocation) => ASTv1.ConcatStatement;
function buildElement
buildElement: ( tag: TagDescriptor, options?: BuildElementOptions) => ASTv1.ElementNode;
function buildElementModifier
buildElementModifier: ( path: BuilderHead, params?: ASTv1.Expression[], hash?: ASTv1.Hash, loc?: Nullable<SourceLocation>) => ASTv1.ElementModifierStatement;
function buildHash
buildHash: (pairs?: ASTv1.HashPair[], loc?: SourceLocation) => ASTv1.Hash;
function buildHeadFromString
buildHeadFromString: (original: string, loc?: SourceLocation) => ASTv1.PathHead;
function buildLiteral
buildLiteral: <T extends Literal>( type: T['type'], value: T['value'], loc?: SourceLocation) => T;
function buildLoc
buildLoc: { (loc: Nullable<SourceLocation>): SourceSpan; ( startLine: number, startColumn: number, endLine?: number, endColumn?: number, source?: string ): SourceSpan;};
function buildMustache
buildMustache: ( path: BuilderHead | ASTv1.Literal, params?: ASTv1.Expression[], hash?: ASTv1.Hash, trusting?: boolean, loc?: SourceLocation, strip?: ASTv1.StripFlags) => ASTv1.MustacheStatement;
function buildMustacheComment
buildMustacheComment: ( value: string, loc?: SourceLocation) => ASTv1.MustacheCommentStatement;
function buildPair
buildPair: ( key: string, value: ASTv1.Expression, loc?: SourceLocation) => ASTv1.HashPair;
function buildPath
buildPath: { ( path: ASTv1.PathExpression | string | { head: string; tail: string[] }, loc?: SourceLocation ): ASTv1.PathExpression; (path: BuilderHead, loc?: SourceLocation): CallableExpression; (path: Literal | BuilderHead, loc?: SourceLocation): Expression; (path: Expression, loc?: SourceLocation): Expression;};
function buildPosition
buildPosition: (line: number, column: number) => SourcePosition;
function buildProgram
buildProgram: ( body?: ASTv1.Statement[], blockParams?: string[], loc?: SourceLocation) => ASTv1.Template | ASTv1.Block;
function buildSexpr
buildSexpr: ( path: BuilderHead, params?: ASTv1.Expression[], hash?: ASTv1.Hash, loc?: SourceLocation) => ASTv1.SubExpression;
function buildTemplate
buildTemplate: ( body?: ASTv1.Statement[], blockParams?: string[], loc?: SourceLocation) => ASTv1.Template;
function buildText
buildText: (chars?: string, loc?: SourceLocation) => ASTv1.TextNode;
function buildThis
buildThis: (loc?: SourceLocation) => ASTv1.ThisHead;
function buildVar
buildVar: (name: string, loc?: SourceLocation) => ASTv1.VarHead;
function getVoidTags
getVoidTags: () => string[];
function hasSpan
hasSpan: (span: MaybeHasSourceSpan) => span is HasSourceSpan;
function isLocatedWithPositions
isLocatedWithPositions: ( location: LocatedWithOptionalPositions) => location is LocatedWithPositions;
function isLocatedWithPositionsArray
isLocatedWithPositionsArray: ( location: LocatedWithOptionalPositions[]) => location is PresentArray<LocatedWithPositions>;
function isVoidTag
isVoidTag: (tag: string) => boolean;
Examples when true: - link - liNK
Examples when false: - Link (component)
function loc
loc: (span: HasSourceSpan) => SourceSpan;
function match
match: <Out>( callback: (m: Matcher<Out, Matches>) => ExhaustiveMatcher<Out>) => MatchFn<Out>;
function maybeLoc
maybeLoc: (location: MaybeHasSourceSpan, fallback: SourceSpan) => SourceSpan;
function preprocess
preprocess: ( input: string | src.Source | HBS.Program, options?: PreprocessOptions) => ASTv1.Template;
function traverse
traverse: (node: ASTv1.Node, visitor: NodeVisitor) => void;
class CharPosition
class CharPosition implements PositionData {}
constructor
constructor(source: Source, charPos: number);
property charPos
readonly charPos: number;
property kind
readonly kind: string;
property offset
readonly offset: number;
A
CharPosition
always has an offset it can produce without any additional computation.
property source
readonly source: Source;
method toCharPos
toCharPos: () => CharPosition;
This is already a
CharPosition
.for the alternative.
method toHbsPos
toHbsPos: () => HbsPosition;
Convert the current character offset to an
HbsPosition
, if it was not already computed. Once aCharPosition
has computed itsHbsPosition
, it will not need to do compute it again, and the sameCharPosition
is retained when used as one of the ends of aSourceSpan
, so computing theHbsPosition
should be a one-time operation.
method toJSON
toJSON: () => SourcePosition;
Produce a Handlebars for this
CharPosition
. If thisCharPosition
was computed using , this will compute theSourcePosition
for the offset.
method wrap
wrap: () => SourceOffset;
class CharPositionSpan
class CharPositionSpan implements SpanData {}
constructor
constructor( source: Source, charPositions: { start: CharPosition; end: CharPosition });
property charPositions
readonly charPositions: { start: CharPosition; end: CharPosition };
property kind
readonly kind: string;
property source
readonly source: Source;
method asString
asString: () => string;
method getEnd
getEnd: () => AnyPosition;
method getModule
getModule: () => string;
method getStart
getStart: () => AnyPosition;
method locDidUpdate
locDidUpdate: () => void;
method serialize
serialize: () => SerializedSourceSpan;
method toCharPosSpan
toCharPosSpan: () => CharPositionSpan;
method toHbsSpan
toHbsSpan: () => HbsSpan;
method wrap
wrap: () => SourceSpan;
class HandlebarsNodeVisitors
abstract class HandlebarsNodeVisitors extends Parser {}
property pendingError
protected pendingError: Nullable<PendingError>;
method appendDynamicAttributeValuePart
appendDynamicAttributeValuePart: (part: ASTv1.MustacheStatement) => void;
method appendToCommentData
abstract appendToCommentData: (s: string) => void;
method beginAttributeValue
abstract beginAttributeValue: (quoted: boolean) => void;
method BlockStatement
BlockStatement: (block: HBS.BlockStatement) => ASTv1.BlockStatement | void;
method BooleanLiteral
BooleanLiteral: (boolean: HBS.BooleanLiteral) => ASTv1.BooleanLiteral;
method CommentStatement
CommentStatement: ( rawComment: HBS.CommentStatement) => Nullable<MustacheCommentStatement>;
method ContentStatement
ContentStatement: (content: HBS.ContentStatement) => void;
method Decorator
Decorator: (decorator: HBS.Decorator) => never;
method DecoratorBlock
DecoratorBlock: (decoratorBlock: HBS.DecoratorBlock) => never;
method finalizeTextPart
finalizeTextPart: () => void;
method finishAttributeValue
abstract finishAttributeValue: () => void;
method Hash
Hash: (hash: HBS.Hash) => ASTv1.Hash;
method MustacheStatement
MustacheStatement: ( rawMustache: HBS.MustacheStatement) => ASTv1.MustacheStatement | void;
method NullLiteral
NullLiteral: (nul: HBS.NullLiteral) => ASTv1.NullLiteral;
method NumberLiteral
NumberLiteral: (number: HBS.NumberLiteral) => ASTv1.NumberLiteral;
method parse
parse: (program: HBS.Program, blockParams: string[]) => ASTv1.Template;
method PartialBlockStatement
PartialBlockStatement: (partialBlock: HBS.PartialBlockStatement) => never;
method PartialStatement
PartialStatement: (partial: HBS.PartialStatement) => never;
method PathExpression
PathExpression: (path: HBS.PathExpression) => ASTv1.PathExpression;
method Program
Program: (program: HBS.Program, blockParams?: ASTv1.VarHead[]) => ASTv1.Block;
method startTextPart
startTextPart: () => void;
method StringLiteral
StringLiteral: (string: HBS.StringLiteral) => ASTv1.StringLiteral;
method SubExpression
SubExpression: (sexpr: HBS.SubExpression) => ASTv1.SubExpression;
method UndefinedLiteral
UndefinedLiteral: (undef: HBS.UndefinedLiteral) => ASTv1.UndefinedLiteral;
class HbsPosition
class HbsPosition implements PositionData {}
constructor
constructor(source: Source, hbsPos: SourcePosition, charPos?: number);
property hbsPos
readonly hbsPos: SourcePosition;
property kind
readonly kind: string;
property source
readonly source: Source;
method toCharPos
toCharPos: () => CharPosition;
Lazily compute the character offset from the . Once an
HbsPosition
has computed itsCharPosition
, it will not need to do compute it again, and the sameHbsPosition
is retained when used as one of the ends of aSourceSpan
, so computing theCharPosition
should be a one-time operation.
method toHbsPos
toHbsPos: () => HbsPosition;
This is already an
HbsPosition
.for the alternative.
method toJSON
toJSON: () => SourcePosition;
Return the that this
HbsPosition
was instantiated with. This operation does not need to compute anything.
method wrap
wrap: () => SourceOffset;
class HbsSpan
class HbsSpan implements SpanData {}
constructor
constructor( source: Source, hbsPositions: { start: HbsPosition; end: HbsPosition }, providedHbsLoc?: SourceLocation);
property hbsPositions
readonly hbsPositions: { start: HbsPosition; end: HbsPosition };
property kind
readonly kind: string;
property source
readonly source: Source;
method asString
asString: () => string;
method getEnd
getEnd: () => AnyPosition;
method getModule
getModule: () => string;
method getStart
getStart: () => AnyPosition;
method locDidUpdate
locDidUpdate: ({ start, end,}: { start?: SourcePosition; end?: SourcePosition;}) => void;
method serialize
serialize: () => SerializedConcreteSourceSpan;
method toCharPosSpan
toCharPosSpan: () => CharPositionSpan;
method toHbsLoc
toHbsLoc: () => SourceLocation;
method toHbsSpan
toHbsSpan: () => HbsSpan;
method wrap
wrap: () => SourceSpan;
class InvisiblePosition
class InvisiblePosition implements PositionData {}
constructor
constructor( kind: | OffsetKind.InternalsSynthetic | OffsetKind.NonExistent | OffsetKind.Broken, pos: SourcePosition);
property kind
readonly kind: | OffsetKind.InternalsSynthetic | OffsetKind.NonExistent | OffsetKind.Broken;
property offset
readonly offset: null;
property pos
readonly pos: SourcePosition;
method toCharPos
toCharPos: () => null;
A broken position cannot be turned into a .
method toJSON
toJSON: () => SourcePosition;
The serialization of an `InvisiblePosition is whatever Handlebars was originally identified as broken, non-existent or synthetic.
If an
InvisiblePosition
never had an source offset at all, this method returns for compatibility.
method wrap
wrap: () => SourceOffset;
class InvisibleSpan
class InvisibleSpan implements SpanData {}
constructor
constructor( kind: | OffsetKind.InternalsSynthetic | OffsetKind.NonExistent | OffsetKind.Broken, loc: SourceLocation, string?: string);
property kind
readonly kind: | OffsetKind.InternalsSynthetic | OffsetKind.NonExistent | OffsetKind.Broken;
property loc
readonly loc: SourceLocation;
property string
readonly string: string;
method asString
asString: () => string;
method getEnd
getEnd: () => AnyPosition;
method getModule
getModule: () => string;
method getStart
getStart: () => AnyPosition;
method locDidUpdate
locDidUpdate: ({ start, end,}: { start?: SourcePosition; end?: SourcePosition;}) => void;
method serialize
serialize: () => SerializedConcreteSourceSpan;
method toCharPosSpan
toCharPosSpan: () => InvisibleSpan;
method toHbsLoc
toHbsLoc: () => SourceLocation;
method toHbsSpan
toHbsSpan: () => null;
method wrap
wrap: () => SourceSpan;
class Matcher
class Matcher<Out, M extends Matches = Matches> {}
method check
protected check: () => MatchFn<Out>;
You didn't exhaustively match all possibilities.
method when
when: { ( left: OffsetKind.CharPosition, right: OffsetKind.HbsPosition, callback: (left: CharPosition, right: HbsPosition) => Out ): ExhaustiveCheck<Out, M, 'Char,Hbs'>; ( left: OffsetKind.HbsPosition, right: OffsetKind.CharPosition, callback: (left: HbsPosition, right: CharPosition) => Out ): ExhaustiveCheck<Out, M, 'Hbs,Char'>; ( left: OffsetKind.HbsPosition, right: OffsetKind.HbsPosition, callback: (left: HbsPosition, right: HbsPosition) => Out ): ExhaustiveCheck<Out, M, 'Hbs,Hbs'>; ( left: OffsetKind.CharPosition, right: OffsetKind.CharPosition, callback: (left: CharPosition, right: CharPosition) => Out ): ExhaustiveCheck<Out, M, 'Char,Char'>; ( left: 'IS_INVISIBLE', right: 'MATCH_ANY', callback: (left: InvisiblePosition, right: PositionData) => Out ): Matcher<Out, Exclude<M, 'Invisible,Any'>>; ( left: 'MATCH_ANY', right: 'IS_INVISIBLE', callback: (left: PositionData, right: InvisiblePosition) => Out ): ExhaustiveCheck<Out, M, 'Any,Invisible'>; ( left: 'MATCH_ANY', right: 'MATCH_ANY', callback: (left: PositionData, right: PositionData) => Out ): ExhaustiveMatcher<Out>;};
class Parser
abstract class Parser {}
constructor
constructor( source: src.Source, entityParser?: EntityParser, mode?: 'precompile' | 'codemod');
property currentAttr
readonly currentAttr: Attribute;
property currentAttribute
currentAttribute: Nullable<Attribute>;
property currentComment
readonly currentComment: ParserNodeBuilder<CommentStatement>;
property currentData
readonly currentData: ParserNodeBuilder<TextNode>;
property currentEndTag
readonly currentEndTag: ParserNodeBuilder<EndTag>;
property currentNode
currentNode: Nullable< Readonly< | ParserNodeBuilder<CommentStatement> | ParserNodeBuilder<TextNode> | ParserNodeBuilder<StartTag> | ParserNodeBuilder<EndTag> >>;
property currentStartTag
readonly currentStartTag: ParserNodeBuilder<StartTag>;
property currentTag
readonly currentTag: ParserNodeBuilder<StartTag> | ParserNodeBuilder<EndTag>;
property elementStack
protected elementStack: ParentNode[];
property source
readonly source: src.Source;
property tokenizer
tokenizer: EventedTokenizer;
method acceptNode
acceptNode: <T extends keyof HBS.NodeMap>(node: HBS.Node<T>) => HBS.Output<T>;
method appendToAttributeName
abstract appendToAttributeName: (char: string) => void;
method appendToAttributeValue
abstract appendToAttributeValue: (char: string) => void;
method appendToCommentData
abstract appendToCommentData: (char: string) => void;
method appendToData
abstract appendToData: (char: string) => void;
method appendToTagName
abstract appendToTagName: (char: string) => void;
method beginAttribute
abstract beginAttribute: () => void;
method beginAttributeValue
abstract beginAttributeValue: (quoted: boolean) => void;
method beginComment
abstract beginComment: () => void;
method beginData
abstract beginData: () => void;
method beginEndTag
abstract beginEndTag: () => void;
method beginStartTag
abstract beginStartTag: () => void;
method BlockStatement
abstract BlockStatement: ( node: HBS.BlockStatement) => HBS.Output<'BlockStatement'>;
method BooleanLiteral
abstract BooleanLiteral: ( node: HBS.BooleanLiteral) => HBS.Output<'BooleanLiteral'>;
method CommentStatement
abstract CommentStatement: ( node: HBS.CommentStatement) => HBS.Output<'CommentStatement'>;
method ContentStatement
abstract ContentStatement: ( node: HBS.ContentStatement) => HBS.Output<'ContentStatement'>;
method currentElement
currentElement: () => ASTv1.ParentNode;
method Decorator
abstract Decorator: (node: HBS.Decorator) => HBS.Output<'Decorator'>;
method DecoratorBlock
abstract DecoratorBlock: ( node: HBS.DecoratorBlock) => HBS.Output<'DecoratorBlock'>;
method finish
finish: <T extends { loc: src.SourceSpan }>(node: ParserNodeBuilder<T>) => T;
method finishAttributeValue
abstract finishAttributeValue: () => void;
method finishComment
abstract finishComment: () => void;
method finishData
abstract finishData: () => void;
method finishTag
abstract finishTag: () => void;
method markTagAsSelfClosing
abstract markTagAsSelfClosing: () => void;
method MustacheStatement
abstract MustacheStatement: ( node: HBS.MustacheStatement) => HBS.Output<'MustacheStatement'>;
method NullLiteral
abstract NullLiteral: (node: HBS.NullLiteral) => HBS.Output<'NullLiteral'>;
method NumberLiteral
abstract NumberLiteral: (node: HBS.NumberLiteral) => HBS.Output<'NumberLiteral'>;
method offset
offset: () => src.SourceOffset;
method parse
abstract parse: (node: HBS.Program, locals: string[]) => ASTv1.Template;
method PartialBlockStatement
abstract PartialBlockStatement: ( node: HBS.PartialBlockStatement) => HBS.Output<'PartialBlockStatement'>;
method PartialStatement
abstract PartialStatement: ( node: HBS.PartialStatement) => HBS.Output<'PartialStatement'>;
method PathExpression
abstract PathExpression: ( node: HBS.PathExpression) => HBS.Output<'PathExpression'>;
method pos
pos: ({ line, column }: src.SourcePosition) => src.SourceOffset;
method Program
abstract Program: (node: HBS.Program) => HBS.Output<'Program'>;
method reportSyntaxError
abstract reportSyntaxError: (error: string) => void;
method reset
abstract reset: () => void;
method sourceForNode
sourceForNode: (node: HBS.Node, endNode?: { loc: HBS.SourceLocation }) => string;
method StringLiteral
abstract StringLiteral: (node: HBS.StringLiteral) => HBS.Output<'StringLiteral'>;
method SubExpression
abstract SubExpression: (node: HBS.SubExpression) => HBS.Output<'SubExpression'>;
method tagOpen
abstract tagOpen: () => void;
method UndefinedLiteral
abstract UndefinedLiteral: ( node: HBS.UndefinedLiteral) => HBS.Output<'UndefinedLiteral'>;
class Printer
class Printer {}
constructor
constructor(options: PrinterOptions);
method AttrNode
AttrNode: (attr: ASTv1.AttrNode) => void;
method AttrNodeValue
AttrNodeValue: (value: ASTv1.AttrNode['value']) => void;
method Block
Block: (block: ASTv1.Block) => void;
method BlockParams
BlockParams: (blockParams: string[]) => void;
method BlockStatement
BlockStatement: (block: ASTv1.BlockStatement) => void;
method BooleanLiteral
BooleanLiteral: (bool: ASTv1.BooleanLiteral) => void;
method CloseElementNode
CloseElementNode: (el: ASTv1.ElementNode) => void;
method CommentStatement
CommentStatement: (comment: ASTv1.CommentStatement) => void;
method ConcatStatement
ConcatStatement: (concat: ASTv1.ConcatStatement) => void;
method ElementModifierStatement
ElementModifierStatement: (mod: ASTv1.ElementModifierStatement) => void;
method ElementNode
ElementNode: (el: ASTv1.ElementNode) => void;
method Expression
Expression: (expression: ASTv1.Expression) => void;
method handledByOverride
handledByOverride: ( node: ASTv1.Node, ensureLeadingWhitespace?: boolean) => boolean;
method Hash
Hash: (hash: ASTv1.Hash) => void;
method HashPair
HashPair: (pair: ASTv1.HashPair) => void;
method Literal
Literal: (literal: ASTv1.Literal) => void;
method MustacheCommentStatement
MustacheCommentStatement: (comment: ASTv1.MustacheCommentStatement) => void;
method MustacheStatement
MustacheStatement: (mustache: ASTv1.MustacheStatement) => void;
method Node
Node: (node: ASTv1.Node) => void;
method NullLiteral
NullLiteral: (node: ASTv1.NullLiteral) => void;
method NumberLiteral
NumberLiteral: (number: ASTv1.NumberLiteral) => void;
method OpenElementNode
OpenElementNode: (el: ASTv1.ElementNode) => void;
method Params
Params: (params: ASTv1.Expression[]) => void;
method PathExpression
PathExpression: (path: ASTv1.PathExpression) => void;
method print
print: (node: ASTv1.Node) => string;
method StringLiteral
StringLiteral: (str: ASTv1.StringLiteral) => void;
method SubExpression
SubExpression: (sexp: ASTv1.SubExpression) => void;
method Template
Template: (template: ASTv1.Template) => void;
method TextNode
TextNode: (text: ASTv1.TextNode, isAttr?: boolean) => void;
method TopLevelStatement
TopLevelStatement: ( statement: ASTv1.TopLevelStatement | ASTv1.Template | ASTv1.AttrNode) => void;
method TopLevelStatements
TopLevelStatements: (statements: ASTv1.TopLevelStatement[]) => void;
method UndefinedLiteral
UndefinedLiteral: (node: ASTv1.UndefinedLiteral) => 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 from
static from: (source: string, options?: PrecompileOptions) => Source;
method hbsPosFor
hbsPosFor: (offset: number) => Nullable<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 SourceOffset
class SourceOffset {}
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 aSourcePosition
from the Handlebars AST, which can be converted to aCharPosition
on demand. -InvisiblePosition
, which represents a position not in source (@see {InvisiblePosition})
constructor
constructor(data: PositionData & AnyPosition);
property data
readonly data: PositionData & AnyPosition;
property offset
readonly offset: number;
Get the character offset for this
SourceOffset
, if possible.
method broken
static broken: (pos?: SourcePosition) => SourceOffset;
Create a
SourceOffset
that corresponds to a brokenSourcePosition
. This means that the calling code determined (or knows) that theSourceLocation
doesn't correspond correctly to any part of the source.
method collapsed
collapsed: () => SourceSpan;
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.
method eql
eql: (right: SourceOffset) => boolean;
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.
method forHbsPos
static forHbsPos: (source: Source, pos: SourcePosition) => SourceOffset;
Create a
SourceOffset
from a HandlebarsSourcePosition
. It's stored as-is, and converted into a character offset on demand, which avoids unnecessarily computing the offset of everySourceLocation
, but also means that brokenSourcePosition
s are not always detected.
method move
move: (by: number) => SourceOffset;
Create a
SourceOffset
by moving the character position represented by this source offset forward or backward (ifby
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.
method toJSON
toJSON: () => SourcePosition;
Convert this
SourceOffset
into a Handlebars for compatibility with existing plugins.
method until
until: (other: SourceOffset) => SourceSpan;
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.
class SourceSlice
class SourceSlice<Chars extends string = string> {}
constructor
constructor(options: { loc: src.SourceSpan; chars: Chars });
property chars
readonly chars: string;
property loc
readonly loc: src.SourceSpan;
method getString
getString: () => string;
method load
static load: ( source: src.Source, slice: SerializedSourceSlice<string>) => SourceSlice<string>;
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<string>;
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: (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 TokenizerEventHandlers
class TokenizerEventHandlers extends HandlebarsNodeVisitors {}
method appendToAttributeName
appendToAttributeName: (char: string) => void;
method appendToAttributeValue
appendToAttributeValue: (char: string) => void;
method appendToCommentData
appendToCommentData: (char: string) => void;
method appendToData
appendToData: (char: string) => void;
method appendToTagName
appendToTagName: (char: string) => void;
method assembleAttributeValue
assembleAttributeValue: ( parts: ASTv1.AttrPart[], isQuoted: boolean, isDynamic: boolean, span: src.SourceSpan) => ASTv1.AttrValue;
method assembleConcatenatedValue
assembleConcatenatedValue: ( parts: (ASTv1.MustacheStatement | ASTv1.TextNode)[]) => ASTv1.ConcatStatement;
method beginAttribute
beginAttribute: () => void;
method beginAttributeValue
beginAttributeValue: (isQuoted: boolean) => void;
method beginComment
beginComment: () => void;
method beginData
beginData: () => void;
method beginEndTag
beginEndTag: () => void;
method beginStartTag
beginStartTag: () => void;
method finishAttributeValue
finishAttributeValue: () => void;
method finishComment
finishComment: () => void;
method finishData
finishData: () => void;
method finishEndTag
finishEndTag: (isVoid: boolean) => void;
method finishStartTag
finishStartTag: () => void;
method finishTag
finishTag: () => void;
method markTagAsSelfClosing
markTagAsSelfClosing: () => void;
method reportSyntaxError
reportSyntaxError: (message: string) => void;
method reset
reset: () => void;
method tagOpen
tagOpen: () => void;
method validateEndTag
validateEndTag: ( tag: StartTag | EndTag, element: ASTv1.ElementNode, selfClosing: boolean) => void;
class Walker
class Walker {}
constructor
constructor(order?: {});
property order
order?: {};
property stack
stack: unknown[];
method children
children: <N extends Node>( node: N & ASTv1.Node, callback: NodeCallback<N & ASTv1.Node>) => void;
method visit
visit: <N extends Node>(node: Nullable<N>, visitor: NodeCallback<N>) => void;
class WalkerPath
class WalkerPath<N extends ASTv1.Node> {}
constructor
constructor(node: Node, parent?: WalkerPath<Node>, parentKey?: string);
property node
node: Node;
property parent
parent: WalkerPath<Node>;
property parentKey
parentKey: string;
property parentNode
readonly parentNode: Node;
method parents
parents: () => Iterable<WalkerPath<Node>>;
class When
class When<Out> {}
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 AtHead
interface AtHead {}
interface Attribute
interface Attribute {}
property currentPart
currentPart: ASTv1.TextNode | null;
property isDynamic
isDynamic: boolean;
property isQuoted
isQuoted: boolean;
property name
name: string;
property parts
parts: (ASTv1.MustacheStatement | ASTv1.TextNode)[];
property start
start: src.SourceOffset;
property valueSpan
valueSpan: src.SourceSpan;
interface AttrNode
interface AttrNode extends BaseNode {}
interface Block
interface Block extends CommonProgram {}
property blockParams
blockParams: string[];
string accessor for params.name
property chained
chained?: boolean;
property params
params: VarHead[];
property type
type: 'Block';
interface BlockStatement
interface BlockStatement extends BaseNode {}
property chained
chained?: boolean;
property closeStrip
closeStrip: StripFlags;
property hash
hash: Hash;
property inverse
inverse?: Nullable<Block>;
property inverseStrip
inverseStrip: StripFlags;
property openStrip
openStrip: StripFlags;
property params
params: Expression[];
property path
path: CallableExpression;
property program
program: Block;
property type
type: 'BlockStatement';
interface BooleanLiteral
interface BooleanLiteral extends BaseNode {}
interface BuildElementOptions
interface BuildElementOptions {}
property attrs
attrs?: ASTv1.AttrNode[];
property blockParams
blockParams?: ASTv1.VarHead[] | string[];
property children
children?: ASTv1.Statement[];
property closeTag
closeTag?: Nullable<SourceLocation>;
property comments
comments?: ASTv1.MustacheCommentStatement[];
property loc
loc?: SourceLocation;
property modifiers
modifiers?: ASTv1.ElementModifierStatement[];
property openTag
openTag?: SourceLocation;
interface CallParts
interface CallParts {}
interface CommentStatement
interface CommentStatement extends BaseNode {}
interface CommonProgram
interface CommonProgram extends BaseNode {}
property body
body: Statement[];
interface ConcatStatement
interface ConcatStatement extends BaseNode {}
interface ElementModifierStatement
interface ElementModifierStatement extends BaseNode {}
interface ElementNode
interface ElementNode extends BaseNode {}
property attributes
attributes: AttrNode[];
property blockParams
blockParams: string[];
string accessor for params.name
property children
children: Statement[];
property closeTag
closeTag: Nullable<src.SourceSpan>;
span for the close tag, null for void or self-closing tags
property comments
comments: MustacheCommentStatement[];
property modifiers
modifiers: ElementModifierStatement[];
property openTag
openTag: src.SourceSpan;
span for the open tag
property params
params: VarHead[];
property path
path: PathExpression;
property selfClosing
selfClosing: boolean;
property tag
tag: string;
string accessor for path.original
property type
type: 'ElementNode';
interface EndTag
interface EndTag {}
interface ExhaustiveMatcher
interface ExhaustiveMatcher<Out> {}
method check
check: () => MatchFn<Out>;
interface FullKeyTraversal
interface FullKeyTraversal<N extends ASTv1.Node, K extends string> {}
interface FullNodeTraversal
interface FullNodeTraversal<N extends ASTv1.Node> {}
interface HandlebarsParseOptions
interface HandlebarsParseOptions {}
property ignoreStandalone
ignoreStandalone?: boolean;
property srcName
srcName?: string;
interface Hash
interface Hash extends BaseNode {}
interface HashPair
interface HashPair extends BaseNode {}
interface MinimalPathExpression
interface MinimalPathExpression extends BaseNode {}
interface MustacheCommentStatement
interface MustacheCommentStatement extends BaseNode {}
interface MustacheStatement
interface MustacheStatement extends BaseNode {}
interface NullLiteral
interface NullLiteral extends BaseNode {}
interface NumberLiteral
interface NumberLiteral extends BaseNode {}
interface PathExpression
interface PathExpression extends MinimalPathExpression {}
property data
readonly data: boolean;
Deprecated
use `head.type' instead
property head
head: PathHead;
property original
original: string;
property parts
parts: readonly string[];
Deprecated
use
head
andtail
instead
property tail
tail: string[];
property this
readonly this: boolean;
Deprecated
use
head.type
instead
property type
type: 'PathExpression';
interface PendingError
interface PendingError {}
interface PositionData
interface PositionData {}
All positions have these details in common. Most notably, all three kinds of positions can must be able to attempt to convert themselves into .
interface PrecompileOptions
interface PrecompileOptions extends PreprocessOptions {}
property customizeComponentName
customizeComponentName?: ((input: string) => string) | undefined;
property id
id?: TemplateIdFn;
property keywords
keywords?: readonly string[];
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.
interface PrecompileOptionsWithLexicalScope
interface PrecompileOptionsWithLexicalScope extends PrecompileOptions {}
property lexicalScope
lexicalScope: (variable: string) => boolean;
interface PreprocessOptions
interface PreprocessOptions {}
property customizeComponentName
customizeComponentName?: ((input: string) => string) | undefined;
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;
interface PrinterOptions
interface PrinterOptions {}
property entityEncoding
entityEncoding: ASTv1.EntityEncodingState;
method override
override: (ast: ASTv1.Node, options: PrinterOptions) => void | string;
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.
Parameter ast
the ast node to be printed
Parameter options
the options specified during the print() invocation
interface SourceLocation
interface SourceLocation {}
interface SourcePosition
interface SourcePosition {}
interface SpanData
interface SpanData {}
All spans have these details in common.
property kind
readonly kind: OffsetKind;
method asString
asString: () => string;
Convert this span into a string. If the span is broken, return
''
.
method getEnd
getEnd: () => AnyPosition;
Get the ending position for this span. Try to avoid creating new position objects, as they cache computations.
method getModule
getModule: () => string;
Gets the module the span was located in.
method getStart
getStart: () => AnyPosition;
Get the starting position for this span. Try to avoid creating new position objects, as they cache computations.
method locDidUpdate
locDidUpdate: (changes: { start?: SourcePosition; end?: SourcePosition;}) => void;
For compatibility, whenever the
start
orend
of a changes, spans are notified of the change so they can update themselves. This shouldn't happen outside of AST plugins.
method serialize
serialize: () => SerializedSourceSpan;
Serialize into a , which is compact and designed for readability in context like AST Explorer. If you need a , use .
method toHbsSpan
toHbsSpan: () => HbsSpan;
Compute the
SourceLocation
for this span, returned as an instance ofHbsSpan
.
interface StartTag
interface StartTag {}
property attributes
readonly attributes: ASTv1.AttrNode[];
property comments
readonly comments: ASTv1.MustacheCommentStatement[];
property loc
readonly loc: src.SourceSpan;
property modifiers
readonly modifiers: ASTv1.ElementModifierStatement[];
property name
name: string;
property nameEnd
nameEnd: Nullable<src.SourceOffset>;
property nameStart
nameStart: Nullable<src.SourceOffset>;
property params
readonly params: ASTv1.VarHead[];
property selfClosing
selfClosing: boolean;
property type
readonly type: 'StartTag';
interface StringLiteral
interface StringLiteral extends BaseNode {}
interface StripFlags
interface StripFlags {}
interface SubExpression
interface SubExpression extends BaseNode {}
interface Syntax
interface Syntax {}
interface Template
interface Template extends CommonProgram {}
property blockParams
blockParams: string[];
property type
type: 'Template';
interface TemplateIdFn
interface TemplateIdFn {}
call signature
(src: string): Nullable<string>;
interface TextNode
interface TextNode extends BaseNode {}
interface ThisHead
interface ThisHead {}
interface UndefinedLiteral
interface UndefinedLiteral extends BaseNode {}
interface VarHead
interface VarHead {}
enum OffsetKind
enum OffsetKind { CharPosition = 'CharPosition', HbsPosition = 'HbsPosition', InternalsSynthetic = 'InternalsSynthetic', NonExistent = 'NonExistent', Broken = 'Broken',}
member Broken
Broken = 'Broken'
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.
member CharPosition
CharPosition = 'CharPosition'
We have already computed the character position of this offset or span.
member HbsPosition
HbsPosition = 'HbsPosition'
This offset or span was instantiated with a Handlebars SourcePosition or SourceLocation. Its character position will be computed on demand.
member InternalsSynthetic
InternalsSynthetic = 'InternalsSynthetic'
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.
member NonExistent
NonExistent = 'NonExistent'
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 AnyPosition
type AnyPosition = HbsPosition | CharPosition | InvisiblePosition;
type AnySpan
type AnySpan = HbsSpan | CharPositionSpan | InvisibleSpan;
type AttrPart
type AttrPart = TextNode | MustacheStatement;
type AttrSexp
type AttrSexp = [string, ASTv1.AttrNode['value'] | string, LocSexp?];
type AttrValue
type AttrValue = TextNode | MustacheStatement | ConcatStatement;
type BROKEN
type BROKEN = 'BROKEN';
type BuilderHead
type BuilderHead = string | ASTv1.CallableExpression;
type CallableExpression
type CallableExpression = SubExpression | PathExpression;
type CallNode
type CallNode = | MustacheStatement | BlockStatement | ElementModifierStatement | SubExpression;
type ElementComment
type ElementComment = ASTv1.MustacheCommentStatement | SourceLocation | string;
type ElementParts
type ElementParts = | ['attrs', ...AttrSexp[]] | ['modifiers', ...ModifierSexp[]] | ['body', ...ASTv1.Statement[]] | ['comments', ...ElementComment[]] | ['as', ...string[]] | ['loc', SourceLocation];
type EntityEncodingState
type EntityEncodingState = 'transformed' | 'raw';
type ExhaustiveCheck
type ExhaustiveCheck<Out, In extends Matches, Removed extends Matches> = Exclude< In, Removed> extends never ? ExhaustiveMatcher<Out> : Matcher<Out, Exclude<In, Removed>>;
type Expression
type Expression = Nodes[ExpressionName];
type ExpressionName
type ExpressionName = 'SubExpression' | 'PathExpression' | LiteralName;
type Expressions
type Expressions = Pick<Nodes, ExpressionName>;
type HasSourceLocation
type HasSourceLocation = | SourceLocation | LocatedWithPositions | PresentArray<LocatedWithPositions>;
type HasSourceSpan
type HasSourceSpan = | { loc: SourceSpan; } | SourceSpan | [HasSourceSpan, ...HasSourceSpan[]];
type HasSpan
type HasSpan = SourceSpan | LocatedWithSpan | PresentArray<LocatedWithSpan>;
type IsInvisible
type IsInvisible = 'IS_INVISIBLE';
type KeyHandler
type KeyHandler<N extends ASTv1.Node, K extends VisitorKey<N>> = ( node: N, key: K) => void;
type KeysVisitor
type KeysVisitor<N extends ASTv1.Node> = { [P in VisitorKey<N>]?: KeyTraversal<N, P>;} & { All?: KeyTraversal<N, VisitorKey<N>>; /** * @deprecated use Template or Block instead */ Program?: KeyTraversal<ASTv1.Template | ASTv1.Block, 'body'>;};
type KeyTraversal
type KeyTraversal<N extends ASTv1.Node, K extends VisitorKey<N>> = | FullKeyTraversal<N, K> | KeyHandler<N, K>;
type Literal
type Literal = Nodes[LiteralName];
type LiteralName
type LiteralName = | 'StringLiteral' | 'BooleanLiteral' | 'NumberLiteral' | 'UndefinedLiteral' | 'NullLiteral';
type LocatedWithOptionalPositions
type LocatedWithOptionalPositions = { loc?: SourceLocation;};
type LocatedWithOptionalSpan
type LocatedWithOptionalSpan = { offsets: SourceSpan | null;};
type LocatedWithPositions
type LocatedWithPositions = { loc: SourceLocation;};
type LocatedWithSpan
type LocatedWithSpan = { offsets: SourceSpan;};
type LocSexp
type LocSexp = ['loc', SourceLocation];
type MatchAny
type MatchAny = 'MATCH_ANY';
type Matches
type Matches = | 'Char,Hbs' | 'Hbs,Char' | 'Hbs,Hbs' | 'Char,Char' | 'Invisible,Any' | 'Any,Invisible';
type MatchFn
type MatchFn<Out> = (left: PositionData, right: PositionData) => Out;
type MaybeHasSourceLocation
type MaybeHasSourceLocation = | null | LocatedWithOptionalPositions | LocatedWithOptionalPositions[];
type MaybeHasSourceSpan
type MaybeHasSourceSpan = | { loc: SourceSpan; } | SourceSpan | MaybeHasSourceSpan[];
type MaybeHasSpan
type MaybeHasSpan = | SourceSpan | LocatedWithOptionalSpan | LocatedWithOptionalSpan[] | null;
type ModifierSexp
type ModifierSexp = | string | [PathSexp, LocSexp?] | [PathSexp, ASTv1.Expression[], LocSexp?] | [PathSexp, ASTv1.Expression[], Dict<ASTv1.Expression>, LocSexp?];
type Node
type Node = Nodes[NodeType];
type NodeCallback
type NodeCallback<N extends ASTv1.Node> = (node: N, walker: Walker) => void;
type NodeHandler
type NodeHandler<N extends ASTv1.Node> = (node: N, path: WalkerPath<N>) => void;
type Nodes
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 NodeTraversal
type NodeTraversal<N extends ASTv1.Node> = FullNodeTraversal<N> | NodeHandler<N>;
type NodeType
type NodeType = keyof Nodes;
type NodeVisitor
type NodeVisitor = { [P in keyof ASTv1.Nodes]?: NodeTraversal<ASTv1.Nodes[P]>;} & { All?: NodeTraversal<ASTv1.Node>; /** * @deprecated use Template or Block instead */ Program?: NodeTraversal<ASTv1.Template | ASTv1.Block>;};
type ParentNode
type ParentNode = Template | Block | ElementNode;
type ParserNodeBuilder
type ParserNodeBuilder< N extends { loc: src.SourceSpan; }> = Omit<N, 'loc'> & { start: src.SourceOffset;};
type PathHead
type PathHead = ThisHead | AtHead | VarHead;
type PathSexp
type PathSexp = string | ['path', string, LocSexp?];
type Pattern
type Pattern = OffsetKind | IsInvisible | MatchAny;
type PossiblyDeprecatedBlock
type PossiblyDeprecatedBlock = ASTv1.Block | ASTv1.Template;
type Program
type Program = Template | Block;
Deprecated
use Template or Block instead
type SerializedConcreteSourceSpan
type SerializedConcreteSourceSpan = /** collapsed */ | number | /** normal */ [start: number, size: number] | /** synthetic */ string;
type SerializedSourceSlice
type SerializedSourceSlice<Chars extends string = string> = [ chars: Chars, span: src.SerializedSourceSpan];
type SerializedSourceSpan
type SerializedSourceSpan = | SerializedConcreteSourceSpan | OffsetKind.NonExistent | OffsetKind.Broken;
type SexpValue
type SexpValue = | string | ASTv1.Expression[] | Dict<ASTv1.Expression> | LocSexp | PathSexp | undefined;
type Statement
type Statement = Nodes[StatementName];
type StatementName
type StatementName = | 'MustacheStatement' | 'CommentStatement' | 'BlockStatement' | 'MustacheCommentStatement' | 'TextNode' | 'ElementNode';
type Statements
type Statements = Pick<Nodes, StatementName>;
type SubNode
type SubNode = SubNodes[SubNodeType];
type SubNodes
type SubNodes = { ThisHead: ThisHead; AtHead: AtHead; VarHead: VarHead;};
type SubNodeType
type SubNodeType = keyof SubNodes;
type TagDescriptor
type TagDescriptor = | string | ASTv1.PathExpression | { path: ASTv1.PathExpression; selfClosing?: boolean; } | { name: string; selfClosing?: boolean; };
type TopLevelStatement
type TopLevelStatement = Statement | Nodes['Block'];
type ToSourceOffset
type ToSourceOffset = number | SourceOffset;
type VisitorKey
type VisitorKey<N extends ASTv1.Node> = VisitorKeys[N['type']] & keyof N;
type VisitorKeys
type VisitorKeys = { [P in keyof VisitorKeysMap]: VisitorKeysMap[P][number];};
type VisitorKeysMap
type VisitorKeysMap = typeof visitorKeys;
namespace ASTv2
namespace ASTv2 {}
variable AppendContent_base
const AppendContent_base: TypedNodeConstructor< 'AppendContent', { value: ExpressionNode; trusting: boolean; table: SymbolTable } & BaseNodeFields>;
variable ArgReference_base
const ArgReference_base: TypedNodeConstructor< 'Arg', { name: SourceSlice<string>; symbol: number } & BaseNodeFields>;
variable Args_base
const Args_base: NodeConstructor< { positional: PositionalArguments; named: NamedArguments } & BaseNodeFields>;
variable Block_base
const Block_base: NodeConstructor< { scope: BlockSymbolTable } & GlimmerParentNodeOptions & BaseNodeFields>;
variable BROKEN
const BROKEN: string;
Used to indicate that an attempt to convert a
SourcePosition
to a character offset failed. It is separate fromnull
so thatnull
can be used to indicate that the computation wasn't yet attempted (and therefore to cache the failure)
variable BROKEN_LOCATION
const BROKEN_LOCATION: Readonly<{ readonly source: '(broken)'; readonly start: Readonly<{ readonly line: 1; readonly column: 0 }>; readonly end: Readonly<{ readonly line: 1; readonly column: 0 }>;}>;
variable CallExpression_base
const CallExpression_base: TypedNodeConstructor<'Call', CallFields & BaseNodeFields>;
variable COMPONENT_NAMESPACE
const COMPONENT_NAMESPACE: string;
variable ComponentArg_base
const ComponentArg_base: NodeConstructor<AttrNodeOptions & BaseNodeFields>;
variable ElementModifier_base
const ElementModifier_base: TypedNodeConstructor< 'ElementModifier', CallFields & BaseNodeFields>;
variable FreeVarReference_base
const FreeVarReference_base: TypedNodeConstructor< 'Free', { name: string; resolution: FreeVarResolution; symbol: number } & BaseNodeFields>;
variable GlimmerComment_base
const GlimmerComment_base: TypedNodeConstructor< 'GlimmerComment', { text: SourceSlice<string> } & BaseNodeFields>;
variable HELPER_NAMESPACE
const HELPER_NAMESPACE: string;
variable HTML_RESOLUTION
const HTML_RESOLUTION: { isAngleBracket: true; resolution: () => GetContextualFreeOpcode; serialize: () => SerializedResolution;};
variable HtmlAttr_base
const HtmlAttr_base: TypedNodeConstructor< 'HtmlAttr', AttrNodeOptions & BaseNodeFields>;
variable HtmlComment_base
const HtmlComment_base: TypedNodeConstructor< 'HtmlComment', { text: SourceSlice<string> } & BaseNodeFields>;
variable HtmlText_base
const HtmlText_base: TypedNodeConstructor< 'HtmlText', { chars: string } & BaseNodeFields>;
variable InterpolateExpression_base
const InterpolateExpression_base: TypedNodeConstructor< 'Interpolate', { parts: PresentArray<ExpressionNode> } & BaseNodeFields>;
variable InvokeBlock_base
const InvokeBlock_base: TypedNodeConstructor< 'InvokeBlock', CallFields & { blocks: NamedBlocks } & BaseNodeFields>;
variable InvokeComponent_base
const InvokeComponent_base: TypedNodeConstructor< 'InvokeComponent', InvokeComponentFields & BaseNodeFields>;
variable IsInvisible
const IsInvisible: string;
variable KeywordExpression_base
const KeywordExpression_base: TypedNodeConstructor< 'Keyword', { name: string; symbol: number } & BaseNodeFields>;
variable LiteralExpression_base
const LiteralExpression_base: TypedNodeConstructor< 'Literal', { value: LiteralValue } & BaseNodeFields>;
variable LocalVarReference_base
const LocalVarReference_base: TypedNodeConstructor< 'Local', { name: string; isTemplateLocal: boolean; symbol: number } & BaseNodeFields>;
variable MatchAny
const MatchAny: string;
This file implements the DSL used by span and offset in places where they need to exhaustively consider all combinations of states (Handlebars offsets, character offsets and invisible/broken offsets).
It's probably overkill, but it makes the code that uses it clear. It could be refactored or removed.
variable MODIFIER_NAMESPACE
const MODIFIER_NAMESPACE: string;
variable NamedArguments_base
const NamedArguments_base: NodeConstructor< { entries: readonly NamedArgument[] } & BaseNodeFields>;
variable NamedBlock_base
const NamedBlock_base: NodeConstructor<NamedBlockFields & BaseNodeFields>;
variable NamedBlocks_base
const NamedBlocks_base: NodeConstructor< { blocks: readonly NamedBlock[] } & BaseNodeFields>;
variable NON_EXISTENT_LOCATION
const NON_EXISTENT_LOCATION: Readonly<{ readonly source: '(nonexistent)'; readonly start: Readonly<{ readonly line: 1; readonly column: 0 }>; readonly end: Readonly<{ readonly line: 1; readonly column: 0 }>;}>;
variable PathExpression_base
const PathExpression_base: TypedNodeConstructor< 'Path', { ref: VariableReference; tail: readonly SourceSlice<string>[] } & BaseNodeFields>;
variable PositionalArguments_base
const PositionalArguments_base: NodeConstructor< { exprs: readonly ExpressionNode[] } & BaseNodeFields>;
variable print
const print: (ast: ASTv1.Node, options?: PrinterOptions) => string;
variable publicBuilder
const publicBuilder: { mustache: ( path: ASTv1.Literal | BuilderHead, params?: ASTv1.Expression[], hash?: ASTv1.Hash, trusting?: boolean, loc?: SourceLocation, strip?: ASTv1.StripFlags ) => ASTv1.MustacheStatement; block: ( path: BuilderHead, params: Nullable<ASTv1.Expression[]>, hash: Nullable<ASTv1.Hash>, _defaultBlock: PossiblyDeprecatedBlock, _elseBlock?: Nullable<PossiblyDeprecatedBlock>, loc?: SourceLocation, openStrip?: ASTv1.StripFlags, inverseStrip?: ASTv1.StripFlags, closeStrip?: ASTv1.StripFlags ) => ASTv1.BlockStatement; comment: (value: string, loc?: SourceLocation) => ASTv1.CommentStatement; mustacheComment: ( value: string, loc?: SourceLocation ) => ASTv1.MustacheCommentStatement; element: ( tag: TagDescriptor, options?: BuildElementOptions ) => ASTv1.ElementNode; elementModifier: ( path: BuilderHead, params?: ASTv1.Expression[], hash?: ASTv1.Hash, loc?: Nullable<SourceLocation> ) => ASTv1.ElementModifierStatement; attr: ( name: string, value: ASTv1.AttrValue, loc?: SourceLocation ) => ASTv1.AttrNode; text: (chars?: string, loc?: SourceLocation) => ASTv1.TextNode; sexpr: ( path: BuilderHead, params?: ASTv1.Expression[], hash?: ASTv1.Hash, loc?: SourceLocation ) => ASTv1.SubExpression; concat: ( parts: (ASTv1.MustacheStatement | ASTv1.TextNode)[], loc?: SourceLocation ) => ASTv1.ConcatStatement; hash: (pairs?: ASTv1.HashPair[], loc?: SourceLocation) => ASTv1.Hash; pair: ( key: string, value: ASTv1.Expression, loc?: SourceLocation ) => ASTv1.HashPair; literal: <T extends ASTv1.Literal>( type: T['type'], value: T['value'], loc?: SourceLocation ) => T; program: ( body?: ASTv1.Statement[], blockParams?: string[], loc?: SourceLocation ) => ASTv1.Template | ASTv1.Block; blockItself: ( body?: ASTv1.Statement[], params?: (string | ASTv1.VarHead)[], chained?: boolean, loc?: SourceLocation ) => ASTv1.Block; template: ( body?: ASTv1.Statement[], blockParams?: string[], loc?: SourceLocation ) => ASTv1.Template; loc: { (loc: Nullable<SourceLocation>): SourceSpan; ( startLine: number, startColumn: number, endLine?: number, endColumn?: number, source?: string ): SourceSpan; }; pos: (line: number, column: number) => SourcePosition; path: { ( path: string | ASTv1.PathExpression | { head: string; tail: string[] }, loc?: SourceLocation ): ASTv1.PathExpression; (path: BuilderHead, loc?: SourceLocation): ASTv1.CallableExpression; (path: ASTv1.Literal | BuilderHead, loc?: SourceLocation): ASTv1.Expression; (path: ASTv1.Expression, loc?: SourceLocation): ASTv1.Expression; }; fullPath: ( head: ASTv1.PathHead, tail?: string[], loc?: SourceLocation ) => ASTv1.PathExpression; head: (original: string, loc?: SourceLocation) => ASTv1.PathHead; at: (name: string, loc?: SourceLocation) => ASTv1.AtHead; var: (name: string, loc?: SourceLocation) => ASTv1.VarHead; this: (loc?: SourceLocation) => ASTv1.ThisHead; string: (value: string) => ASTv1.StringLiteral; boolean: (value: boolean) => ASTv1.BooleanLiteral; number: (value: number) => ASTv1.NumberLiteral; undefined(): ASTv1.UndefinedLiteral; null(): ASTv1.NullLiteral;};
variable SimpleElement_base
const SimpleElement_base: TypedNodeConstructor< 'SimpleElement', SimpleElementOptions & BaseNodeFields>;
variable span
const span: MatchFn<SourceSpan>;
variable SplatAttr_base
const SplatAttr_base: TypedNodeConstructor< 'SplatAttr', { symbol: number } & BaseNodeFields>;
variable STRICT_RESOLUTION
const STRICT_RESOLUTION: { resolution: () => GetContextualFreeOpcode; serialize: () => SerializedResolution; isAngleBracket: false;};
Strict resolution is used:
1. in a strict mode template 2. in an local variable invocation with dot paths
variable SYNTHETIC
const SYNTHETIC: Readonly<{ readonly source: '(synthetic)'; readonly start: Readonly<{ readonly line: 1; readonly column: 0 }>; readonly end: Readonly<{ readonly line: 1; readonly column: 0 }>;}>;
Deprecated
variable SYNTHETIC_LOCATION
const SYNTHETIC_LOCATION: Readonly<{ readonly source: '(synthetic)'; readonly start: Readonly<{ readonly line: 1; readonly column: 0 }>; readonly end: Readonly<{ readonly line: 1; readonly column: 0 }>;}>;
variable Template_base
const Template_base: NodeConstructor< { table: ProgramSymbolTable } & GlimmerParentNodeOptions & BaseNodeFields>;
variable TEMPORARY_LOCATION
const TEMPORARY_LOCATION: Readonly<{ readonly source: '(temporary)'; readonly start: Readonly<{ readonly line: 1; readonly column: 0 }>; readonly end: Readonly<{ readonly line: 1; readonly column: 0 }>;}>;
variable ThisReference_base
const ThisReference_base: TypedNodeConstructor<'This', object & BaseNodeFields>;
variable UNKNOWN_POSITION
const UNKNOWN_POSITION: Readonly<{ readonly line: 1; readonly column: 0 }>;
variable visitorKeys
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'];};
variable voidMap
const voidMap: Set<string>;
function build
build: (ast: ASTv1.Node, options?: PrinterOptions) => string;
function buildAtName
buildAtName: (name: string, loc?: SourceLocation) => ASTv1.AtHead;
function buildAttr
buildAttr: ( name: string, value: ASTv1.AttrValue, loc?: SourceLocation) => ASTv1.AttrNode;
function buildBlock
buildBlock: ( path: BuilderHead, params: Nullable<ASTv1.Expression[]>, hash: Nullable<ASTv1.Hash>, _defaultBlock: PossiblyDeprecatedBlock, _elseBlock?: Nullable<PossiblyDeprecatedBlock>, loc?: SourceLocation, openStrip?: ASTv1.StripFlags, inverseStrip?: ASTv1.StripFlags, closeStrip?: ASTv1.StripFlags) => ASTv1.BlockStatement;
function buildBlockItself
buildBlockItself: ( body?: ASTv1.Statement[], params?: Array<ASTv1.VarHead | string>, chained?: boolean, loc?: SourceLocation) => ASTv1.Block;
function buildCleanPath
buildCleanPath: ( head: ASTv1.PathHead, tail?: string[], loc?: SourceLocation) => ASTv1.PathExpression;
function buildComment
buildComment: (value: string, loc?: SourceLocation) => ASTv1.CommentStatement;
function buildConcat
buildConcat: ( parts: (ASTv1.TextNode | ASTv1.MustacheStatement)[], loc?: SourceLocation) => ASTv1.ConcatStatement;
function buildElement
buildElement: ( tag: TagDescriptor, options?: BuildElementOptions) => ASTv1.ElementNode;
function buildElementModifier
buildElementModifier: ( path: BuilderHead, params?: ASTv1.Expression[], hash?: ASTv1.Hash, loc?: Nullable<SourceLocation>) => ASTv1.ElementModifierStatement;
function buildHash
buildHash: (pairs?: ASTv1.HashPair[], loc?: SourceLocation) => ASTv1.Hash;
function buildHeadFromString
buildHeadFromString: (original: string, loc?: SourceLocation) => ASTv1.PathHead;
function buildLiteral
buildLiteral: <T extends ASTv1.Literal>( type: T['type'], value: T['value'], loc?: SourceLocation) => T;
function buildLoc
buildLoc: { (loc: Nullable<SourceLocation>): SourceSpan; ( startLine: number, startColumn: number, endLine?: number, endColumn?: number, source?: string ): SourceSpan;};
function buildMustache
buildMustache: ( path: BuilderHead | ASTv1.Literal, params?: ASTv1.Expression[], hash?: ASTv1.Hash, trusting?: boolean, loc?: SourceLocation, strip?: ASTv1.StripFlags) => ASTv1.MustacheStatement;
function buildMustacheComment
buildMustacheComment: ( value: string, loc?: SourceLocation) => ASTv1.MustacheCommentStatement;
function buildPair
buildPair: ( key: string, value: ASTv1.Expression, loc?: SourceLocation) => ASTv1.HashPair;
function buildPath
buildPath: { ( path: string | ASTv1.PathExpression | { head: string; tail: string[] }, loc?: SourceLocation ): ASTv1.PathExpression; (path: BuilderHead, loc?: SourceLocation): ASTv1.CallableExpression; (path: ASTv1.Literal | BuilderHead, loc?: SourceLocation): ASTv1.Expression; (path: ASTv1.Expression, loc?: SourceLocation): ASTv1.Expression;};
function buildPosition
buildPosition: (line: number, column: number) => SourcePosition;
function buildProgram
buildProgram: ( body?: ASTv1.Statement[], blockParams?: string[], loc?: SourceLocation) => ASTv1.Template | ASTv1.Block;
function buildSexpr
buildSexpr: ( path: BuilderHead, params?: ASTv1.Expression[], hash?: ASTv1.Hash, loc?: SourceLocation) => ASTv1.SubExpression;
function buildTemplate
buildTemplate: ( body?: ASTv1.Statement[], blockParams?: string[], loc?: SourceLocation) => ASTv1.Template;
function buildText
buildText: (chars?: string, loc?: SourceLocation) => ASTv1.TextNode;
function buildThis
buildThis: (loc?: SourceLocation) => ASTv1.ThisHead;
function buildVar
buildVar: (name: string, loc?: SourceLocation) => ASTv1.VarHead;
function getVoidTags
getVoidTags: () => string[];
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 isLocatedWithPositions
isLocatedWithPositions: ( location: LocatedWithOptionalPositions) => location is LocatedWithPositions;
function isLocatedWithPositionsArray
isLocatedWithPositionsArray: ( location: LocatedWithOptionalPositions[]) => location is PresentArray<LocatedWithPositions>;
function isStrictResolution
isStrictResolution: ( value: unknown) => value is { resolution: () => GetContextualFreeOpcode; serialize: () => SerializedResolution; isAngleBracket: false;};
function isVoidTag
isVoidTag: (tag: string) => boolean;
Examples when true: - link - liNK
Examples when false: - Link (component)
function loadResolution
loadResolution: (resolution: SerializedResolution) => FreeVarResolution;
function match
match: <Out>( callback: (m: Matcher<Out, Matches>) => ExhaustiveMatcher<Out>) => MatchFn<Out>;
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 preprocess
preprocess: ( input: string | src.Source | HBS.Program, options?: PreprocessOptions) => ASTv1.Template;
function traverse
traverse: (node: ASTv1.Node, visitor: NodeVisitor) => void;
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 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 getDebugInfo
getDebugInfo: () => Core.DebugInfo;
method getKeyword
getKeyword: (name: string) => number;
method getLocalsMap
getLocalsMap: () => Dict<number>;
method has
has: (name: string) => boolean;
method hasKeyword
hasKeyword: (name: string) => boolean;
method hasLexical
hasLexical: (name: string) => boolean;
method setHasDebugger
setHasDebugger: () => void;
class CallExpression
class CallExpression extends CallExpression_base {}
Corresponds to a parenthesized call expression.
(x)(x.y)(x y)(x.y z)
class CharPosition
class CharPosition implements PositionData {}
constructor
constructor(source: Source, charPos: number);
property charPos
readonly charPos: number;
property kind
readonly kind: string;
property offset
readonly offset: number;
A
CharPosition
always has an offset it can produce without any additional computation.
property source
readonly source: Source;
method toCharPos
toCharPos: () => CharPosition;
This is already a
CharPosition
.for the alternative.
method toHbsPos
toHbsPos: () => HbsPosition;
Convert the current character offset to an
HbsPosition
, if it was not already computed. Once aCharPosition
has computed itsHbsPosition
, it will not need to do compute it again, and the sameCharPosition
is retained when used as one of the ends of aSourceSpan
, so computing theHbsPosition
should be a one-time operation.
method toJSON
toJSON: () => SourcePosition;
Produce a Handlebars for this
CharPosition
. If thisCharPosition
was computed using , this will compute theSourcePosition
for the offset.
method wrap
wrap: () => SourceOffset;
class CharPositionSpan
class CharPositionSpan implements SpanData {}
constructor
constructor( source: Source, charPositions: { start: CharPosition; end: CharPosition });
property charPositions
readonly charPositions: { start: CharPosition; end: CharPosition };
property kind
readonly kind: string;
property source
readonly source: Source;
method asString
asString: () => string;
method getEnd
getEnd: () => AnyPosition;
method getModule
getModule: () => string;
method getStart
getStart: () => AnyPosition;
method locDidUpdate
locDidUpdate: () => void;
method serialize
serialize: () => SerializedSourceSpan;
method toCharPosSpan
toCharPosSpan: () => CharPositionSpan;
method toHbsSpan
toHbsSpan: () => HbsSpan;
method wrap
wrap: () => SourceSpan;
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 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 HandlebarsNodeVisitors
abstract class HandlebarsNodeVisitors extends Parser {}
property pendingError
protected pendingError: Nullable<PendingError>;
method appendDynamicAttributeValuePart
appendDynamicAttributeValuePart: (part: ASTv1.MustacheStatement) => void;
method appendToCommentData
abstract appendToCommentData: (s: string) => void;
method beginAttributeValue
abstract beginAttributeValue: (quoted: boolean) => void;
method BlockStatement
BlockStatement: (block: HBS.BlockStatement) => ASTv1.BlockStatement | void;
method BooleanLiteral
BooleanLiteral: (boolean: HBS.BooleanLiteral) => ASTv1.BooleanLiteral;
method CommentStatement
CommentStatement: ( rawComment: HBS.CommentStatement) => Nullable<ASTv1.MustacheCommentStatement>;
method ContentStatement
ContentStatement: (content: HBS.ContentStatement) => void;
method Decorator
Decorator: (decorator: HBS.Decorator) => never;
method DecoratorBlock
DecoratorBlock: (decoratorBlock: HBS.DecoratorBlock) => never;
method finalizeTextPart
finalizeTextPart: () => void;
method finishAttributeValue
abstract finishAttributeValue: () => void;
method Hash
Hash: (hash: HBS.Hash) => ASTv1.Hash;
method MustacheStatement
MustacheStatement: ( rawMustache: HBS.MustacheStatement) => ASTv1.MustacheStatement | void;
method NullLiteral
NullLiteral: (nul: HBS.NullLiteral) => ASTv1.NullLiteral;
method NumberLiteral
NumberLiteral: (number: HBS.NumberLiteral) => ASTv1.NumberLiteral;
method parse
parse: (program: HBS.Program, blockParams: string[]) => ASTv1.Template;
method PartialBlockStatement
PartialBlockStatement: (partialBlock: HBS.PartialBlockStatement) => never;
method PartialStatement
PartialStatement: (partial: HBS.PartialStatement) => never;
method PathExpression
PathExpression: (path: HBS.PathExpression) => ASTv1.PathExpression;
method Program
Program: (program: HBS.Program, blockParams?: ASTv1.VarHead[]) => ASTv1.Block;
method startTextPart
startTextPart: () => void;
method StringLiteral
StringLiteral: (string: HBS.StringLiteral) => ASTv1.StringLiteral;
method SubExpression
SubExpression: (sexpr: HBS.SubExpression) => ASTv1.SubExpression;
method UndefinedLiteral
UndefinedLiteral: (undef: HBS.UndefinedLiteral) => ASTv1.UndefinedLiteral;
class HbsPosition
class HbsPosition implements PositionData {}
constructor
constructor(source: Source, hbsPos: SourcePosition, charPos?: number);
property hbsPos
readonly hbsPos: SourcePosition;
property kind
readonly kind: string;
property source
readonly source: Source;
method toCharPos
toCharPos: () => CharPosition;
Lazily compute the character offset from the . Once an
HbsPosition
has computed itsCharPosition
, it will not need to do compute it again, and the sameHbsPosition
is retained when used as one of the ends of aSourceSpan
, so computing theCharPosition
should be a one-time operation.
method toHbsPos
toHbsPos: () => HbsPosition;
This is already an
HbsPosition
.for the alternative.
method toJSON
toJSON: () => SourcePosition;
Return the that this
HbsPosition
was instantiated with. This operation does not need to compute anything.
method wrap
wrap: () => SourceOffset;
class HbsSpan
class HbsSpan implements SpanData {}
constructor
constructor( source: Source, hbsPositions: { start: HbsPosition; end: HbsPosition }, providedHbsLoc?: SourceLocation);
property hbsPositions
readonly hbsPositions: { start: HbsPosition; end: HbsPosition };
property kind
readonly kind: string;
property source
readonly source: Source;
method asString
asString: () => string;
method getEnd
getEnd: () => AnyPosition;
method getModule
getModule: () => string;
method getStart
getStart: () => AnyPosition;
method locDidUpdate
locDidUpdate: ({ start, end,}: { start?: SourcePosition; end?: SourcePosition;}) => void;
method serialize
serialize: () => SerializedConcreteSourceSpan;
method toCharPosSpan
toCharPosSpan: () => CharPositionSpan;
method toHbsLoc
toHbsLoc: () => SourceLocation;
method toHbsSpan
toHbsSpan: () => HbsSpan;
method wrap
wrap: () => SourceSpan;
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 InvisiblePosition
class InvisiblePosition implements PositionData {}
constructor
constructor( kind: | OffsetKind.InternalsSynthetic | OffsetKind.NonExistent | OffsetKind.Broken, pos: SourcePosition);
property kind
readonly kind: | OffsetKind.InternalsSynthetic | OffsetKind.NonExistent | OffsetKind.Broken;
property offset
readonly offset: null;
property pos
readonly pos: SourcePosition;
method toCharPos
toCharPos: () => null;
A broken position cannot be turned into a .
method toJSON
toJSON: () => SourcePosition;
The serialization of an `InvisiblePosition is whatever Handlebars was originally identified as broken, non-existent or synthetic.
If an
InvisiblePosition
never had an source offset at all, this method returns for compatibility.
method wrap
wrap: () => SourceOffset;
class InvisibleSpan
class InvisibleSpan implements SpanData {}
constructor
constructor( kind: | OffsetKind.InternalsSynthetic | OffsetKind.NonExistent | OffsetKind.Broken, loc: SourceLocation, string?: string);
property kind
readonly kind: | OffsetKind.InternalsSynthetic | OffsetKind.NonExistent | OffsetKind.Broken;
property loc
readonly loc: SourceLocation;
property string
readonly string: string;
method asString
asString: () => string;
method getEnd
getEnd: () => AnyPosition;
method getModule
getModule: () => string;
method getStart
getStart: () => AnyPosition;
method locDidUpdate
locDidUpdate: ({ start, end,}: { start?: SourcePosition; end?: SourcePosition;}) => void;
method serialize
serialize: () => SerializedConcreteSourceSpan;
method toCharPosSpan
toCharPosSpan: () => InvisibleSpan;
method toHbsLoc
toHbsLoc: () => SourceLocation;
method toHbsSpan
toHbsSpan: () => null;
method wrap
wrap: () => SourceSpan;
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 KeywordExpression
class KeywordExpression extends KeywordExpression_base {}
Corresponds to a known strict-mode keyword. It behaves similarly to a PathExpression with a FreeVarReference, but implies StrictResolution and is guaranteed to not have a tail, since
{{outlet.foo}}
would have been illegal.
class LiteralExpression
class LiteralExpression extends LiteralExpression_base {}
Corresponds to a Handlebars literal.
See Also
{LiteralValue}
method toSlice
toSlice: (this: StringLiteral) => SourceSlice<string>;
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 one or more namespaces to resolve the variable inIn practice, there are a limited number of possible combinations of these degrees of freedom, and they are captured by the
Namespaces
union below.
constructor
constructor(namespaces: Namespaces, isAngleBracket?: boolean);
property isAngleBracket
readonly isAngleBracket: boolean;
property namespaces
readonly namespaces: Namespaces;
method append
static append: () => LooseModeResolution;
Append resolution is used when the variable should be resolved in both the
component
andhelper
namespaces.{{x}}{{x y}}^ In either case,
x
should be resolved in thecomponent
andhelper
namespaces.
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
)
method resolution
resolution: () => GetContextualFreeOpcode;
method serialize
serialize: () => SerializedResolution;
method trustingAppend
static trustingAppend: () => LooseModeResolution;
Trusting append resolution is used when the variable should be resolved only in the
helper
namespaces.{{{x}}}{{{x y}}}^ In either case,
x
should be resolved in thehelper
namespace.
class Matcher
class Matcher<Out, M extends Matches = Matches> {}
method check
protected check: () => MatchFn<Out>;
You didn't exhaustively match all possibilities.
method when
when: { ( left: OffsetKind.CharPosition, right: OffsetKind.HbsPosition, callback: (left: CharPosition, right: HbsPosition) => Out ): ExhaustiveCheck<Out, M, 'Char,Hbs'>; ( left: OffsetKind.HbsPosition, right: OffsetKind.CharPosition, callback: (left: HbsPosition, right: CharPosition) => Out ): ExhaustiveCheck<Out, M, 'Hbs,Char'>; ( left: OffsetKind.HbsPosition, right: OffsetKind.HbsPosition, callback: (left: HbsPosition, right: HbsPosition) => Out ): ExhaustiveCheck<Out, M, 'Hbs,Hbs'>; ( left: OffsetKind.CharPosition, right: OffsetKind.CharPosition, callback: (left: CharPosition, right: CharPosition) => Out ): ExhaustiveCheck<Out, M, 'Char,Char'>; ( left: 'IS_INVISIBLE', right: 'MATCH_ANY', callback: (left: InvisiblePosition, right: PositionData) => Out ): Matcher<Out, Exclude<M, 'Invisible,Any'>>; ( left: 'MATCH_ANY', right: 'IS_INVISIBLE', callback: (left: PositionData, right: InvisiblePosition) => Out ): ExhaustiveCheck<Out, M, 'Any,Invisible'>; ( left: 'MATCH_ANY', right: 'MATCH_ANY', callback: (left: PositionData, right: PositionData) => Out ): ExhaustiveMatcher<Out>;};
class NamedArgument
class NamedArgument {}
Corresponds to a single named argument.
x=<expr>
constructor
constructor(options: { name: SourceSlice<string>; 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 Parser
abstract class Parser {}
constructor
constructor( source: src.Source, entityParser?: EntityParser, mode?: 'precompile' | 'codemod');
property currentAttr
readonly currentAttr: Attribute;
property currentAttribute
currentAttribute: Nullable<Attribute>;
property currentComment
readonly currentComment: ParserNodeBuilder<ASTv1.CommentStatement>;
property currentData
readonly currentData: ParserNodeBuilder<ASTv1.TextNode>;
property currentEndTag
readonly currentEndTag: ParserNodeBuilder<EndTag>;
property currentNode
currentNode: Nullable< Readonly< | ParserNodeBuilder<ASTv1.CommentStatement> | ParserNodeBuilder<ASTv1.TextNode> | ParserNodeBuilder<StartTag> | ParserNodeBuilder<EndTag> >>;
property currentStartTag
readonly currentStartTag: ParserNodeBuilder<StartTag>;
property currentTag
readonly currentTag: ParserNodeBuilder<StartTag> | ParserNodeBuilder<EndTag>;
property elementStack
protected elementStack: ASTv1.ParentNode[];
property source
readonly source: src.Source;
property tokenizer
tokenizer: EventedTokenizer;
method acceptNode
acceptNode: <T extends keyof HBS.NodeMap>(node: HBS.Node<T>) => HBS.Output<T>;
method appendToAttributeName
abstract appendToAttributeName: (char: string) => void;
method appendToAttributeValue
abstract appendToAttributeValue: (char: string) => void;
method appendToCommentData
abstract appendToCommentData: (char: string) => void;
method appendToData
abstract appendToData: (char: string) => void;
method appendToTagName
abstract appendToTagName: (char: string) => void;
method beginAttribute
abstract beginAttribute: () => void;
method beginAttributeValue
abstract beginAttributeValue: (quoted: boolean) => void;
method beginComment
abstract beginComment: () => void;
method beginData
abstract beginData: () => void;
method beginEndTag
abstract beginEndTag: () => void;
method beginStartTag
abstract beginStartTag: () => void;
method BlockStatement
abstract BlockStatement: ( node: HBS.BlockStatement) => HBS.Output<'BlockStatement'>;
method BooleanLiteral
abstract BooleanLiteral: ( node: HBS.BooleanLiteral) => HBS.Output<'BooleanLiteral'>;
method CommentStatement
abstract CommentStatement: ( node: HBS.CommentStatement) => HBS.Output<'CommentStatement'>;
method ContentStatement
abstract ContentStatement: ( node: HBS.ContentStatement) => HBS.Output<'ContentStatement'>;
method currentElement
currentElement: () => ASTv1.ParentNode;
method Decorator
abstract Decorator: (node: HBS.Decorator) => HBS.Output<'Decorator'>;
method DecoratorBlock
abstract DecoratorBlock: ( node: HBS.DecoratorBlock) => HBS.Output<'DecoratorBlock'>;
method finish
finish: <T extends { loc: src.SourceSpan }>(node: ParserNodeBuilder<T>) => T;
method finishAttributeValue
abstract finishAttributeValue: () => void;
method finishComment
abstract finishComment: () => void;
method finishData
abstract finishData: () => void;
method finishTag
abstract finishTag: () => void;
method markTagAsSelfClosing
abstract markTagAsSelfClosing: () => void;
method MustacheStatement
abstract MustacheStatement: ( node: HBS.MustacheStatement) => HBS.Output<'MustacheStatement'>;
method NullLiteral
abstract NullLiteral: (node: HBS.NullLiteral) => HBS.Output<'NullLiteral'>;
method NumberLiteral
abstract NumberLiteral: (node: HBS.NumberLiteral) => HBS.Output<'NumberLiteral'>;
method offset
offset: () => src.SourceOffset;
method parse
abstract parse: (node: HBS.Program, locals: string[]) => ASTv1.Template;
method PartialBlockStatement
abstract PartialBlockStatement: ( node: HBS.PartialBlockStatement) => HBS.Output<'PartialBlockStatement'>;
method PartialStatement
abstract PartialStatement: ( node: HBS.PartialStatement) => HBS.Output<'PartialStatement'>;
method PathExpression
abstract PathExpression: ( node: HBS.PathExpression) => HBS.Output<'PathExpression'>;
method pos
pos: ({ line, column }: src.SourcePosition) => src.SourceOffset;
method Program
abstract Program: (node: HBS.Program) => HBS.Output<'Program'>;
method reportSyntaxError
abstract reportSyntaxError: (error: string) => void;
method reset
abstract reset: () => void;
method sourceForNode
sourceForNode: (node: HBS.Node, endNode?: { loc: HBS.SourceLocation }) => string;
method StringLiteral
abstract StringLiteral: (node: HBS.StringLiteral) => HBS.Output<'StringLiteral'>;
method SubExpression
abstract SubExpression: (node: HBS.SubExpression) => HBS.Output<'SubExpression'>;
method tagOpen
abstract tagOpen: () => void;
method UndefinedLiteral
abstract UndefinedLiteral: ( node: HBS.UndefinedLiteral) => HBS.Output<'UndefinedLiteral'>;
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 Printer
class Printer {}
constructor
constructor(options: PrinterOptions);
method AttrNode
AttrNode: (attr: ASTv1.AttrNode) => void;
method AttrNodeValue
AttrNodeValue: (value: ASTv1.AttrNode['value']) => void;
method Block
Block: (block: ASTv1.Block) => void;
method BlockParams
BlockParams: (blockParams: string[]) => void;
method BlockStatement
BlockStatement: (block: ASTv1.BlockStatement) => void;
method BooleanLiteral
BooleanLiteral: (bool: ASTv1.BooleanLiteral) => void;
method CloseElementNode
CloseElementNode: (el: ASTv1.ElementNode) => void;
method CommentStatement
CommentStatement: (comment: ASTv1.CommentStatement) => void;
method ConcatStatement
ConcatStatement: (concat: ASTv1.ConcatStatement) => void;
method ElementModifierStatement
ElementModifierStatement: (mod: ASTv1.ElementModifierStatement) => void;
method ElementNode
ElementNode: (el: ASTv1.ElementNode) => void;
method Expression
Expression: (expression: ASTv1.Expression) => void;
method handledByOverride
handledByOverride: ( node: ASTv1.Node, ensureLeadingWhitespace?: boolean) => boolean;
method Hash
Hash: (hash: ASTv1.Hash) => void;
method HashPair
HashPair: (pair: ASTv1.HashPair) => void;
method Literal
Literal: (literal: ASTv1.Literal) => void;
method MustacheCommentStatement
MustacheCommentStatement: (comment: ASTv1.MustacheCommentStatement) => void;
method MustacheStatement
MustacheStatement: (mustache: ASTv1.MustacheStatement) => void;
method Node
Node: (node: ASTv1.Node) => void;
method NullLiteral
NullLiteral: (node: ASTv1.NullLiteral) => void;
method NumberLiteral
NumberLiteral: (number: ASTv1.NumberLiteral) => void;
method OpenElementNode
OpenElementNode: (el: ASTv1.ElementNode) => void;
method Params
Params: (params: ASTv1.Expression[]) => void;
method PathExpression
PathExpression: (path: ASTv1.PathExpression) => void;
method print
print: (node: ASTv1.Node) => string;
method StringLiteral
StringLiteral: (str: ASTv1.StringLiteral) => void;
method SubExpression
SubExpression: (sexp: ASTv1.SubExpression) => void;
method Template
Template: (template: ASTv1.Template) => void;
method TextNode
TextNode: (text: ASTv1.TextNode, isAttr?: boolean) => void;
method TopLevelStatement
TopLevelStatement: ( statement: ASTv1.Template | ASTv1.AttrNode | ASTv1.TopLevelStatement) => void;
method TopLevelStatements
TopLevelStatements: (statements: ASTv1.TopLevelStatement[]) => void;
method UndefinedLiteral
UndefinedLiteral: (node: ASTv1.UndefinedLiteral) => void;
class ProgramSymbolTable
class ProgramSymbolTable extends SymbolTable {}
constructor
constructor( templateLocals: readonly string[], keywords: readonly string[], options: SymbolTableOptions);
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 getDebugInfo
getDebugInfo: () => Core.DebugInfo;
method getKeyword
getKeyword: (name: string) => number;
method getLocalsMap
getLocalsMap: () => Dict<number>;
method getUsedTemplateLocals
getUsedTemplateLocals: () => string[];
method has
has: (name: string) => boolean;
method hasKeyword
hasKeyword: (name: string) => boolean;
method hasLexical
hasLexical: (name: string) => boolean;
method setHasDebugger
setHasDebugger: () => void;
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 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 from
static from: (source: string, options?: PrecompileOptions) => Source;
method hbsPosFor
hbsPosFor: (offset: number) => Nullable<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 SourceOffset
class SourceOffset {}
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 aSourcePosition
from the Handlebars AST, which can be converted to aCharPosition
on demand. -InvisiblePosition
, which represents a position not in source (@see {InvisiblePosition})
constructor
constructor(data: PositionData & AnyPosition);
property data
readonly data: PositionData & AnyPosition;
property offset
readonly offset: number;
Get the character offset for this
SourceOffset
, if possible.
method broken
static broken: (pos?: SourcePosition) => SourceOffset;
Create a
SourceOffset
that corresponds to a brokenSourcePosition
. This means that the calling code determined (or knows) that theSourceLocation
doesn't correspond correctly to any part of the source.
method collapsed
collapsed: () => SourceSpan;
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.
method eql
eql: (right: SourceOffset) => boolean;
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.
method forHbsPos
static forHbsPos: (source: Source, pos: SourcePosition) => SourceOffset;
Create a
SourceOffset
from a HandlebarsSourcePosition
. It's stored as-is, and converted into a character offset on demand, which avoids unnecessarily computing the offset of everySourceLocation
, but also means that brokenSourcePosition
s are not always detected.
method move
move: (by: number) => SourceOffset;
Create a
SourceOffset
by moving the character position represented by this source offset forward or backward (ifby
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.
method toJSON
toJSON: () => SourcePosition;
Convert this
SourceOffset
into a Handlebars for compatibility with existing plugins.
method until
until: (other: SourceOffset) => SourceSpan;
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.
class SourceSlice
class SourceSlice<Chars extends string = string> {}
constructor
constructor(options: { loc: src.SourceSpan; chars: Chars });
property chars
readonly chars: string;
property loc
readonly loc: src.SourceSpan;
method getString
getString: () => string;
method load
static load: ( source: src.Source, slice: SerializedSourceSlice<string>) => SourceSlice<string>;
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<string>;
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: (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 SplatAttr
class SplatAttr extends SplatAttr_base {}
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 getDebugInfo
abstract getDebugInfo: () => Core.DebugInfo;
method getKeyword
abstract getKeyword: (name: string) => number;
method getLocalsMap
abstract getLocalsMap: () => Dict<number>;
method has
abstract has: (name: string) => boolean;
method hasKeyword
abstract hasKeyword: (name: string) => boolean;
method hasLexical
abstract hasLexical: (name: string) => boolean;
method setHasDebugger
abstract setHasDebugger: () => void;
method top
static top: ( locals: readonly string[], keywords: readonly string[], options: SymbolTableOptions) => ProgramSymbolTable;
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.
class TokenizerEventHandlers
class TokenizerEventHandlers extends HandlebarsNodeVisitors {}
method appendToAttributeName
appendToAttributeName: (char: string) => void;
method appendToAttributeValue
appendToAttributeValue: (char: string) => void;
method appendToCommentData
appendToCommentData: (char: string) => void;
method appendToData
appendToData: (char: string) => void;
method appendToTagName
appendToTagName: (char: string) => void;
method assembleAttributeValue
assembleAttributeValue: ( parts: ASTv1.AttrPart[], isQuoted: boolean, isDynamic: boolean, span: src.SourceSpan) => ASTv1.AttrValue;
method assembleConcatenatedValue
assembleConcatenatedValue: ( parts: (ASTv1.MustacheStatement | ASTv1.TextNode)[]) => ASTv1.ConcatStatement;
method beginAttribute
beginAttribute: () => void;
method beginAttributeValue
beginAttributeValue: (isQuoted: boolean) => void;
method beginComment
beginComment: () => void;
method beginData
beginData: () => void;
method beginEndTag
beginEndTag: () => void;
method beginStartTag
beginStartTag: () => void;
method finishAttributeValue
finishAttributeValue: () => void;
method finishComment
finishComment: () => void;
method finishData
finishData: () => void;
method finishEndTag
finishEndTag: (isVoid: boolean) => void;
method finishStartTag
finishStartTag: () => void;
method finishTag
finishTag: () => void;
method markTagAsSelfClosing
markTagAsSelfClosing: () => void;
method reportSyntaxError
reportSyntaxError: (message: string) => void;
method reset
reset: () => void;
method tagOpen
tagOpen: () => void;
method validateEndTag
validateEndTag: ( tag: StartTag | EndTag, element: ASTv1.ElementNode, selfClosing: boolean) => void;
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: Nullable<N>, visitor: 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>>;
class When
class When<Out> {}
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 Attribute
interface Attribute {}
property currentPart
currentPart: ASTv1.TextNode | null;
property isDynamic
isDynamic: boolean;
property isQuoted
isQuoted: boolean;
property name
name: string;
property parts
parts: (ASTv1.MustacheStatement | ASTv1.TextNode)[];
property start
start: src.SourceOffset;
property valueSpan
valueSpan: src.SourceSpan;
interface AttrNodeOptions
interface AttrNodeOptions {}
interface BaseNodeFields
interface BaseNodeFields {}
property loc
loc: SourceSpan;
interface BuildElementOptions
interface BuildElementOptions {}
property attrs
attrs?: ASTv1.AttrNode[];
property blockParams
blockParams?: ASTv1.VarHead[] | string[];
property children
children?: ASTv1.Statement[];
property closeTag
closeTag?: Nullable<SourceLocation>;
property comments
comments?: ASTv1.MustacheCommentStatement[];
property loc
loc?: SourceLocation;
property modifiers
modifiers?: ASTv1.ElementModifierStatement[];
property openTag
openTag?: SourceLocation;
interface CallFields
interface CallFields extends BaseNodeFields {}
interface EndTag
interface EndTag {}
interface ExhaustiveMatcher
interface ExhaustiveMatcher<Out> {}
method check
check: () => MatchFn<Out>;
interface FullKeyTraversal
interface FullKeyTraversal<N extends ASTv1.Node, K extends string> {}
interface FullNodeTraversal
interface FullNodeTraversal<N extends ASTv1.Node> {}
interface GlimmerParentNodeOptions
interface GlimmerParentNodeOptions extends BaseNodeFields {}
property body
body: readonly ContentNode[];
interface HandlebarsParseOptions
interface HandlebarsParseOptions {}
property ignoreStandalone
ignoreStandalone?: boolean;
property srcName
srcName?: string;
interface InvokeComponentFields
interface InvokeComponentFields {}
property attrs
attrs: readonly HtmlOrSplatAttr[];
property blocks
blocks: NamedBlocks;
property callee
callee: ExpressionNode;
property componentArgs
componentArgs: readonly ComponentArg[];
property modifiers
modifiers: readonly ElementModifier[];
interface LiteralTypes
interface LiteralTypes {}
interface NamedBlockFields
interface NamedBlockFields extends BaseNodeFields {}
property attrs
attrs: readonly HtmlOrSplatAttr[];
property block
block: Block;
property componentArgs
componentArgs: readonly ComponentArg[];
property modifiers
modifiers: readonly ElementModifier[];
property name
name: SourceSlice;
interface NodeConstructor
interface NodeConstructor<Fields> {}
construct signature
new (fields: Fields): Readonly<Fields>;
interface PendingError
interface PendingError {}
interface PositionData
interface PositionData {}
All positions have these details in common. Most notably, all three kinds of positions can must be able to attempt to convert themselves into .
interface PrecompileOptions
interface PrecompileOptions extends PreprocessOptions {}
property customizeComponentName
customizeComponentName?: ((input: string) => string) | undefined;
property id
id?: TemplateIdFn;
property keywords
keywords?: readonly string[];
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.
interface PrecompileOptionsWithLexicalScope
interface PrecompileOptionsWithLexicalScope extends PrecompileOptions {}
property lexicalScope
lexicalScope: (variable: string) => boolean;
interface PreprocessOptions
interface PreprocessOptions {}
property customizeComponentName
customizeComponentName?: ((input: string) => string) | undefined;
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;
interface PrinterOptions
interface PrinterOptions {}
property entityEncoding
entityEncoding: ASTv1.EntityEncodingState;
method override
override: (ast: ASTv1.Node, options: PrinterOptions) => void | string;
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.
Parameter ast
the ast node to be printed
Parameter options
the options specified during the print() invocation
interface SerializedBaseNode
interface SerializedBaseNode {}
property loc
loc: SerializedSourceSpan;
interface SimpleElementOptions
interface SimpleElementOptions extends BaseNodeFields {}
property attrs
attrs: readonly HtmlOrSplatAttr[];
property body
body: readonly ContentNode[];
property componentArgs
componentArgs: readonly ComponentArg[];
property modifiers
modifiers: readonly ElementModifier[];
property tag
tag: SourceSlice;
interface SourceLocation
interface SourceLocation {}
interface SourcePosition
interface SourcePosition {}
interface SpanData
interface SpanData {}
All spans have these details in common.
property kind
readonly kind: OffsetKind;
method asString
asString: () => string;
Convert this span into a string. If the span is broken, return
''
.
method getEnd
getEnd: () => AnyPosition;
Get the ending position for this span. Try to avoid creating new position objects, as they cache computations.
method getModule
getModule: () => string;
Gets the module the span was located in.
method getStart
getStart: () => AnyPosition;
Get the starting position for this span. Try to avoid creating new position objects, as they cache computations.
method locDidUpdate
locDidUpdate: (changes: { start?: SourcePosition; end?: SourcePosition;}) => void;
For compatibility, whenever the
start
orend
of a changes, spans are notified of the change so they can update themselves. This shouldn't happen outside of AST plugins.
method serialize
serialize: () => SerializedSourceSpan;
Serialize into a , which is compact and designed for readability in context like AST Explorer. If you need a , use .
method toHbsSpan
toHbsSpan: () => HbsSpan;
Compute the
SourceLocation
for this span, returned as an instance ofHbsSpan
.
interface StartTag
interface StartTag {}
property attributes
readonly attributes: ASTv1.AttrNode[];
property comments
readonly comments: ASTv1.MustacheCommentStatement[];
property loc
readonly loc: src.SourceSpan;
property modifiers
readonly modifiers: ASTv1.ElementModifierStatement[];
property name
name: string;
property nameEnd
nameEnd: Nullable<src.SourceOffset>;
property nameStart
nameStart: Nullable<src.SourceOffset>;
property params
readonly params: ASTv1.VarHead[];
property selfClosing
selfClosing: boolean;
property type
readonly type: 'StartTag';
interface SymbolTableOptions
interface SymbolTableOptions {}
property customizeComponentName
customizeComponentName: (input: string) => string;
property lexicalScope
lexicalScope: (variable: string) => boolean;
interface Syntax
interface Syntax {}
interface TemplateIdFn
interface TemplateIdFn {}
call signature
(src: string): Nullable<string>;
interface TypedNodeConstructor
interface TypedNodeConstructor<T extends string, Fields> {}
construct signature
new (options: Fields): TypedNode<T, Fields>;
interface Upvar
interface Upvar {}
property name
readonly name: string;
property resolution
readonly resolution: ASTv2.FreeVarResolution;
enum FreeVarNamespace
enum FreeVarNamespace { Helper = 'Helper', Modifier = 'Modifier', Component = 'Component',}
enum OffsetKind
enum OffsetKind { CharPosition = 'CharPosition', HbsPosition = 'HbsPosition', InternalsSynthetic = 'InternalsSynthetic', NonExistent = 'NonExistent', Broken = 'Broken',}
member Broken
Broken = 'Broken'
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.
member CharPosition
CharPosition = 'CharPosition'
We have already computed the character position of this offset or span.
member HbsPosition
HbsPosition = 'HbsPosition'
This offset or span was instantiated with a Handlebars SourcePosition or SourceLocation. Its character position will be computed on demand.
member InternalsSynthetic
InternalsSynthetic = 'InternalsSynthetic'
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.
member NonExistent
NonExistent = 'NonExistent'
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 AnyPosition
type AnyPosition = HbsPosition | CharPosition | InvisiblePosition;
type AnySpan
type AnySpan = HbsSpan | CharPositionSpan | InvisibleSpan;
type AttrBlockNode
type AttrBlockNode = AttrNode | ElementModifier;
"Attr Block" nodes are allowed inside an open element tag in templates. They interact with the element (or component).
type AttrNode
type AttrNode = HtmlAttr | SplatAttr | ComponentArg;
Attr nodes look like HTML attributes, but are classified as:
1.
HtmlAttr
, which means a regular HTML attribute in Glimmer 2.SplatAttr
, which means...attributes
3.ComponentArg
, which means an attribute whose name begins with@
, and it is therefore a component argument.
type AttrSexp
type AttrSexp = [string, ASTv1.AttrNode['value'] | string, LocSexp?];
type BROKEN
type BROKEN = 'BROKEN';
type BuilderHead
type BuilderHead = string | ASTv1.CallableExpression;
type CalleeNode
type CalleeNode = KeywordExpression | PathExpression | CallExpression;
type CallNode
type CallNode = | CallExpression | InvokeBlock | AppendContent | InvokeComponent | ElementModifier;
type ContentNode
type ContentNode = | HtmlText | HtmlComment | AppendContent | InvokeBlock | InvokeComponent | SimpleElement | GlimmerComment;
Content Nodes are allowed in content positions in templates. They correspond to behavior in the [Data][data] tokenization state in HTML.
[data]: https://html.spec.whatwg.org/multipage/parsing.html#data-state
type ElementComment
type ElementComment = ASTv1.MustacheCommentStatement | SourceLocation | string;
type ElementNode
type ElementNode = NamedBlock | InvokeComponent | SimpleElement;
type ElementParts
type ElementParts = | ['attrs', ...AttrSexp[]] | ['modifiers', ...ModifierSexp[]] | ['body', ...ASTv1.Statement[]] | ['comments', ...ElementComment[]] | ['as', ...string[]] | ['loc', SourceLocation];
type ExhaustiveCheck
type ExhaustiveCheck<Out, In extends Matches, Removed extends Matches> = Exclude< In, Removed> extends never ? ExhaustiveMatcher<Out> : Matcher<Out, Exclude<In, Removed>>;
type ExpressionNode
type ExpressionNode = | LiteralExpression | PathExpression | KeywordExpression | CallExpression | InterpolateExpression;
type FreeVarResolution
type FreeVarResolution = StrictResolution | HtmlResolution | LooseModeResolution;
type HasSourceLocation
type HasSourceLocation = | SourceLocation | LocatedWithPositions | PresentArray<LocatedWithPositions>;
type HtmlOrSplatAttr
type HtmlOrSplatAttr = HtmlAttr | SplatAttr;
HtmlAttr
andSplatAttr
are grouped together because the order of theSplatAttr
node, relative to other attributes, matters.
type HtmlResolution
type HtmlResolution = typeof HTML_RESOLUTION;
type IsInvisible
type IsInvisible = 'IS_INVISIBLE';
type KeyHandler
type KeyHandler<N extends ASTv1.Node, K extends VisitorKey<N>> = ( node: N, key: K) => void;
type KeysVisitor
type KeysVisitor<N extends ASTv1.Node> = { [P in VisitorKey<N>]?: KeyTraversal<N, P>;} & { All?: KeyTraversal<N, VisitorKey<N>>; /** * @deprecated use Template or Block instead */ Program?: KeyTraversal<ASTv1.Template | ASTv1.Block, 'body'>;};
type KeyTraversal
type KeyTraversal<N extends ASTv1.Node, K extends VisitorKey<N>> = | FullKeyTraversal<N, K> | KeyHandler<N, K>;
type LiteralValue
type LiteralValue = string | boolean | number | undefined | null;
A Handlebars literal.
https://handlebarsjs.com/guide/expressions.html#literal-segments
type LocatedWithOptionalPositions
type LocatedWithOptionalPositions = { loc?: SourceLocation;};
type LocatedWithOptionalSpan
type LocatedWithOptionalSpan = { offsets: SourceSpan | null;};
type LocatedWithPositions
type LocatedWithPositions = { loc: SourceLocation;};
type LocatedWithSpan
type LocatedWithSpan = { offsets: SourceSpan;};
type LocSexp
type LocSexp = ['loc', SourceLocation];
type MatchAny
type MatchAny = 'MATCH_ANY';
type Matches
type Matches = | 'Char,Hbs' | 'Hbs,Char' | 'Hbs,Hbs' | 'Char,Char' | 'Invisible,Any' | 'Any,Invisible';
type MatchFn
type MatchFn<Out> = (left: PositionData, right: PositionData) => Out;
type MaybeHasSourceLocation
type MaybeHasSourceLocation = | null | LocatedWithOptionalPositions | LocatedWithOptionalPositions[];
type ModifierSexp
type ModifierSexp = | string | [PathSexp, LocSexp?] | [PathSexp, ASTv1.Expression[], LocSexp?] | [PathSexp, ASTv1.Expression[], Dict<ASTv1.Expression>, LocSexp?];
type Namespaces
type Namespaces = | [FreeVarNamespace.Helper] | [FreeVarNamespace.Modifier] | [FreeVarNamespace.Component] | [FreeVarNamespace.Component, FreeVarNamespace.Helper];
A
Namespaced
must be resolved in one or more namespaces.<X />^
X
is resolved in thecomponent
namespace(x)^
x
is resolved in thehelper
namespace<a {{x}} />^
x
is resolved in themodifier
namespace
type NodeCallback
type NodeCallback<N extends ASTv1.Node> = (node: N, walker: Walker) => void;
type NodeHandler
type NodeHandler<N extends ASTv1.Node> = (node: N, path: WalkerPath<N>) => void;
type NodeTraversal
type NodeTraversal<N extends ASTv1.Node> = FullNodeTraversal<N> | NodeHandler<N>;
type NodeVisitor
type NodeVisitor = { [P in keyof ASTv1.Nodes]?: NodeTraversal<ASTv1.Nodes[P]>;} & { All?: NodeTraversal<ASTv1.Node>; /** * @deprecated use Template or Block instead */ Program?: NodeTraversal<ASTv1.Template | ASTv1.Block>;};
type ParserNodeBuilder
type ParserNodeBuilder< N extends { loc: src.SourceSpan; }> = Omit<N, 'loc'> & { start: src.SourceOffset;};
type PathSexp
type PathSexp = string | ['path', string, LocSexp?];
type Pattern
type Pattern = OffsetKind | IsInvisible | MatchAny;
type PossiblyDeprecatedBlock
type PossiblyDeprecatedBlock = ASTv1.Block | ASTv1.Template;
type SerializedConcreteSourceSpan
type SerializedConcreteSourceSpan = /** collapsed */ | number | /** normal */ [start: number, size: number] | /** synthetic */ string;
type SerializedResolution
type SerializedResolution = | 'Strict' | 'Helper' | 'Modifier' | 'Component' | 'ComponentOrHelper';
type SerializedSourceSlice
type SerializedSourceSlice<Chars extends string = string> = [ chars: Chars, span: src.SerializedSourceSpan];
type SerializedSourceSpan
type SerializedSourceSpan = | SerializedConcreteSourceSpan | OffsetKind.NonExistent | OffsetKind.Broken;
type SexpValue
type SexpValue = | string | ASTv1.Expression[] | Dict<ASTv1.Expression> | LocSexp | PathSexp | undefined;
type StrictResolution
type StrictResolution = typeof STRICT_RESOLUTION;
type StringLiteral
type StringLiteral = LiteralExpression & { value: string;};
type TagDescriptor
type TagDescriptor = | string | ASTv1.PathExpression | { path: ASTv1.PathExpression; selfClosing?: boolean; } | { name: string; selfClosing?: boolean; };
type TypedNode
type TypedNode<T extends string, Fields> = { type: T;} & Readonly<Fields>;
type VariableReference
type VariableReference = | ThisReference | ArgReference | LocalVarReference | FreeVarReference;
type VisitorKey
type VisitorKey<N extends ASTv1.Node> = VisitorKeys[N['type']] & keyof N;
type VisitorKeys
type VisitorKeys = { [P in keyof VisitorKeysMap]: VisitorKeysMap[P][number];};
type VisitorKeysMap
type VisitorKeysMap = typeof visitorKeys;
namespace HBS
namespace HBS {}
interface BlockStatement
interface BlockStatement extends CommonBlock {}
property type
type: 'BlockStatement';
interface BooleanLiteral
interface BooleanLiteral extends CommonNode {}
interface CommentStatement
interface CommentStatement extends CommonNode {}
interface CommonBlock
interface CommonBlock extends CommonNode {}
property chained
chained: boolean;
property closeStrip
closeStrip?: StripFlags;
property hash
hash: Hash;
property inverse
inverse: Program;
property inverseStrip
inverseStrip?: StripFlags;
property openStrip
openStrip?: StripFlags;
property params
params: Expression[];
property path
path: PathExpression | SubExpression;
property program
program: Program;
interface CommonMustache
interface CommonMustache extends CommonNode {}
interface CommonNode
interface CommonNode {}
property loc
loc: SourceLocation;
interface ContentStatement
interface ContentStatement extends CommonNode {}
interface Decorator
interface Decorator extends CommonMustache {}
property type
type: 'DecoratorStatement';
interface DecoratorBlock
interface DecoratorBlock extends CommonBlock {}
property type
type: 'DecoratorBlock';
interface HashPair
interface HashPair extends CommonNode {}
interface MustacheStatement
interface MustacheStatement extends CommonMustache {}
property type
type: 'MustacheStatement';
interface NodeMap
interface NodeMap {}
property BlockStatement
BlockStatement: { input: BlockStatement; output: ASTv1.BlockStatement | void;};
property BooleanLiteral
BooleanLiteral: { input: BooleanLiteral; output: ASTv1.BooleanLiteral;};
property CommentStatement
CommentStatement: { input: CommentStatement; output: ASTv1.MustacheCommentStatement | null;};
property ContentStatement
ContentStatement: { input: ContentStatement; output: void;};
property Decorator
Decorator: { input: Decorator; output: never;};
property DecoratorBlock
DecoratorBlock: { input: DecoratorBlock; output: never;};
property MustacheStatement
MustacheStatement: { input: MustacheStatement; output: ASTv1.MustacheStatement | void;};
property NullLiteral
NullLiteral: { input: NullLiteral; output: ASTv1.NullLiteral;};
property NumberLiteral
NumberLiteral: { input: NumberLiteral; output: ASTv1.NumberLiteral;};
property PartialBlockStatement
PartialBlockStatement: { input: PartialBlockStatement; output: never;};
property PartialStatement
PartialStatement: { input: PartialStatement; output: never;};
property PathExpression
PathExpression: { input: PathExpression; output: ASTv1.PathExpression;};
property Program
Program: { input: Program; output: ASTv1.Block;};
property StringLiteral
StringLiteral: { input: StringLiteral; output: ASTv1.StringLiteral;};
property SubExpression
SubExpression: { input: SubExpression; output: ASTv1.SubExpression;};
property UndefinedLiteral
UndefinedLiteral: { input: UndefinedLiteral; output: ASTv1.UndefinedLiteral;};
interface NullLiteral
interface NullLiteral extends CommonNode {}
property type
type: 'NullLiteral';
interface NumberLiteral
interface NumberLiteral extends CommonNode {}
interface PartialBlockStatement
interface PartialBlockStatement extends CommonNode {}
interface PartialStatement
interface PartialStatement extends CommonNode {}
interface PathExpression
interface PathExpression extends CommonNode {}
interface Program
interface Program extends CommonNode {}
property blockParams
blockParams?: string[];
property body
body: Statement[];
property chained
chained?: boolean;
property type
type: 'Program';
interface SourceLocation
interface SourceLocation {}
interface StringLiteral
interface StringLiteral extends CommonNode {}
interface StripFlags
interface StripFlags {}
interface SubExpression
interface SubExpression extends CommonNode {}
interface UndefinedLiteral
interface UndefinedLiteral extends CommonNode {}
property type
type: 'UndefinedLiteral';
type Expression
type Expression = SubExpression | PathExpression | Literal;
type Literal
type Literal = | StringLiteral | BooleanLiteral | NumberLiteral | UndefinedLiteral | NullLiteral;
type Node
type Node<T extends NodeType = NodeType> = NodeMap[T]['input'];
type NodeType
type NodeType = keyof NodeMap;
type Output
type Output<T extends NodeType> = NodeMap[T]['output'];
type Statement
type Statement = | MustacheStatement | BlockStatement | DecoratorBlock | PartialStatement | PartialBlockStatement | ContentStatement | CommentStatement;
namespace src
namespace src {}
variable BROKEN
const BROKEN: string;
Used to indicate that an attempt to convert a
SourcePosition
to a character offset failed. It is separate fromnull
so thatnull
can be used to indicate that the computation wasn't yet attempted (and therefore to cache the failure)
variable BROKEN_LOCATION
const BROKEN_LOCATION: Readonly<{ readonly source: '(broken)'; readonly start: Readonly<{ readonly line: 1; readonly column: 0 }>; readonly end: Readonly<{ readonly line: 1; readonly column: 0 }>;}>;
variable IsInvisible
const IsInvisible: string;
variable MatchAny
const MatchAny: string;
This file implements the DSL used by span and offset in places where they need to exhaustively consider all combinations of states (Handlebars offsets, character offsets and invisible/broken offsets).
It's probably overkill, but it makes the code that uses it clear. It could be refactored or removed.
variable NON_EXISTENT_LOCATION
const NON_EXISTENT_LOCATION: Readonly<{ readonly source: '(nonexistent)'; readonly start: Readonly<{ readonly line: 1; readonly column: 0 }>; readonly end: Readonly<{ readonly line: 1; readonly column: 0 }>;}>;
variable print
const print: (ast: ASTv1.Node, options?: PrinterOptions) => string;
variable publicBuilder
const publicBuilder: { mustache: ( path: ASTv1.Literal | BuilderHead, params?: ASTv1.Expression[], hash?: ASTv1.Hash, trusting?: boolean, loc?: SourceLocation, strip?: ASTv1.StripFlags ) => ASTv1.MustacheStatement; block: ( path: BuilderHead, params: Nullable<ASTv1.Expression[]>, hash: Nullable<ASTv1.Hash>, _defaultBlock: PossiblyDeprecatedBlock, _elseBlock?: Nullable<PossiblyDeprecatedBlock>, loc?: SourceLocation, openStrip?: ASTv1.StripFlags, inverseStrip?: ASTv1.StripFlags, closeStrip?: ASTv1.StripFlags ) => ASTv1.BlockStatement; comment: (value: string, loc?: SourceLocation) => ASTv1.CommentStatement; mustacheComment: ( value: string, loc?: SourceLocation ) => ASTv1.MustacheCommentStatement; element: ( tag: TagDescriptor, options?: BuildElementOptions ) => ASTv1.ElementNode; elementModifier: ( path: BuilderHead, params?: ASTv1.Expression[], hash?: ASTv1.Hash, loc?: Nullable<SourceLocation> ) => ASTv1.ElementModifierStatement; attr: ( name: string, value: ASTv1.AttrValue, loc?: SourceLocation ) => ASTv1.AttrNode; text: (chars?: string, loc?: SourceLocation) => ASTv1.TextNode; sexpr: ( path: BuilderHead, params?: ASTv1.Expression[], hash?: ASTv1.Hash, loc?: SourceLocation ) => ASTv1.SubExpression; concat: ( parts: (ASTv1.MustacheStatement | ASTv1.TextNode)[], loc?: SourceLocation ) => ASTv1.ConcatStatement; hash: (pairs?: ASTv1.HashPair[], loc?: SourceLocation) => ASTv1.Hash; pair: ( key: string, value: ASTv1.Expression, loc?: SourceLocation ) => ASTv1.HashPair; literal: <T extends ASTv1.Literal>( type: T['type'], value: T['value'], loc?: SourceLocation ) => T; program: ( body?: ASTv1.Statement[], blockParams?: string[], loc?: SourceLocation ) => ASTv1.Template | ASTv1.Block; blockItself: ( body?: ASTv1.Statement[], params?: (string | ASTv1.VarHead)[], chained?: boolean, loc?: SourceLocation ) => ASTv1.Block; template: ( body?: ASTv1.Statement[], blockParams?: string[], loc?: SourceLocation ) => ASTv1.Template; loc: { (loc: Nullable<SourceLocation>): SourceSpan; ( startLine: number, startColumn: number, endLine?: number, endColumn?: number, source?: string ): SourceSpan; }; pos: (line: number, column: number) => SourcePosition; path: { ( path: string | ASTv1.PathExpression | { head: string; tail: string[] }, loc?: SourceLocation ): ASTv1.PathExpression; (path: BuilderHead, loc?: SourceLocation): ASTv1.CallableExpression; (path: ASTv1.Literal | BuilderHead, loc?: SourceLocation): ASTv1.Expression; (path: ASTv1.Expression, loc?: SourceLocation): ASTv1.Expression; }; fullPath: ( head: ASTv1.PathHead, tail?: string[], loc?: SourceLocation ) => ASTv1.PathExpression; head: (original: string, loc?: SourceLocation) => ASTv1.PathHead; at: (name: string, loc?: SourceLocation) => ASTv1.AtHead; var: (name: string, loc?: SourceLocation) => ASTv1.VarHead; this: (loc?: SourceLocation) => ASTv1.ThisHead; string: (value: string) => ASTv1.StringLiteral; boolean: (value: boolean) => ASTv1.BooleanLiteral; number: (value: number) => ASTv1.NumberLiteral; undefined(): ASTv1.UndefinedLiteral; null(): ASTv1.NullLiteral;};
variable span
const span: MatchFn<SourceSpan>;
variable SYNTHETIC
const SYNTHETIC: Readonly<{ readonly source: '(synthetic)'; readonly start: Readonly<{ readonly line: 1; readonly column: 0 }>; readonly end: Readonly<{ readonly line: 1; readonly column: 0 }>;}>;
Deprecated
variable SYNTHETIC_LOCATION
const SYNTHETIC_LOCATION: Readonly<{ readonly source: '(synthetic)'; readonly start: Readonly<{ readonly line: 1; readonly column: 0 }>; readonly end: Readonly<{ readonly line: 1; readonly column: 0 }>;}>;
variable TEMPORARY_LOCATION
const TEMPORARY_LOCATION: Readonly<{ readonly source: '(temporary)'; readonly start: Readonly<{ readonly line: 1; readonly column: 0 }>; readonly end: Readonly<{ readonly line: 1; readonly column: 0 }>;}>;
variable UNKNOWN_POSITION
const UNKNOWN_POSITION: Readonly<{ readonly line: 1; readonly column: 0 }>;
variable visitorKeys
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'];};
variable voidMap
const voidMap: Set<string>;
function build
build: (ast: ASTv1.Node, options?: PrinterOptions) => string;
function buildAtName
buildAtName: (name: string, loc?: SourceLocation) => ASTv1.AtHead;
function buildAttr
buildAttr: ( name: string, value: ASTv1.AttrValue, loc?: SourceLocation) => ASTv1.AttrNode;
function buildBlock
buildBlock: ( path: BuilderHead, params: Nullable<ASTv1.Expression[]>, hash: Nullable<ASTv1.Hash>, _defaultBlock: PossiblyDeprecatedBlock, _elseBlock?: Nullable<PossiblyDeprecatedBlock>, loc?: SourceLocation, openStrip?: ASTv1.StripFlags, inverseStrip?: ASTv1.StripFlags, closeStrip?: ASTv1.StripFlags) => ASTv1.BlockStatement;
function buildBlockItself
buildBlockItself: ( body?: ASTv1.Statement[], params?: Array<ASTv1.VarHead | string>, chained?: boolean, loc?: SourceLocation) => ASTv1.Block;
function buildCleanPath
buildCleanPath: ( head: ASTv1.PathHead, tail?: string[], loc?: SourceLocation) => ASTv1.PathExpression;
function buildComment
buildComment: (value: string, loc?: SourceLocation) => ASTv1.CommentStatement;
function buildConcat
buildConcat: ( parts: (ASTv1.TextNode | ASTv1.MustacheStatement)[], loc?: SourceLocation) => ASTv1.ConcatStatement;
function buildElement
buildElement: ( tag: TagDescriptor, options?: BuildElementOptions) => ASTv1.ElementNode;
function buildElementModifier
buildElementModifier: ( path: BuilderHead, params?: ASTv1.Expression[], hash?: ASTv1.Hash, loc?: Nullable<SourceLocation>) => ASTv1.ElementModifierStatement;
function buildHash
buildHash: (pairs?: ASTv1.HashPair[], loc?: SourceLocation) => ASTv1.Hash;
function buildHeadFromString
buildHeadFromString: (original: string, loc?: SourceLocation) => ASTv1.PathHead;
function buildLiteral
buildLiteral: <T extends ASTv1.Literal>( type: T['type'], value: T['value'], loc?: SourceLocation) => T;
function buildLoc
buildLoc: { (loc: Nullable<SourceLocation>): SourceSpan; ( startLine: number, startColumn: number, endLine?: number, endColumn?: number, source?: string ): SourceSpan;};
function buildMustache
buildMustache: ( path: BuilderHead | ASTv1.Literal, params?: ASTv1.Expression[], hash?: ASTv1.Hash, trusting?: boolean, loc?: SourceLocation, strip?: ASTv1.StripFlags) => ASTv1.MustacheStatement;
function buildMustacheComment
buildMustacheComment: ( value: string, loc?: SourceLocation) => ASTv1.MustacheCommentStatement;
function buildPair
buildPair: ( key: string, value: ASTv1.Expression, loc?: SourceLocation) => ASTv1.HashPair;
function buildPath
buildPath: { ( path: ASTv1.PathExpression | string | { head: string; tail: string[] }, loc?: SourceLocation ): ASTv1.PathExpression; (path: BuilderHead, loc?: SourceLocation): ASTv1.CallableExpression; (path: ASTv1.Literal | BuilderHead, loc?: SourceLocation): ASTv1.Expression; (path: ASTv1.Expression, loc?: SourceLocation): ASTv1.Expression;};
function buildPosition
buildPosition: (line: number, column: number) => SourcePosition;
function buildProgram
buildProgram: ( body?: ASTv1.Statement[], blockParams?: string[], loc?: SourceLocation) => ASTv1.Template | ASTv1.Block;
function buildSexpr
buildSexpr: ( path: BuilderHead, params?: ASTv1.Expression[], hash?: ASTv1.Hash, loc?: SourceLocation) => ASTv1.SubExpression;
function buildTemplate
buildTemplate: ( body?: ASTv1.Statement[], blockParams?: string[], loc?: SourceLocation) => ASTv1.Template;
function buildText
buildText: (chars?: string, loc?: SourceLocation) => ASTv1.TextNode;
function buildThis
buildThis: (loc?: SourceLocation) => ASTv1.ThisHead;
function buildVar
buildVar: (name: string, loc?: SourceLocation) => ASTv1.VarHead;
function getVoidTags
getVoidTags: () => string[];
function hasSpan
hasSpan: (span: MaybeHasSourceSpan) => span is HasSourceSpan;
function isLocatedWithPositions
isLocatedWithPositions: ( location: LocatedWithOptionalPositions) => location is LocatedWithPositions;
function isLocatedWithPositionsArray
isLocatedWithPositionsArray: ( location: LocatedWithOptionalPositions[]) => location is PresentArray<LocatedWithPositions>;
function isVoidTag
isVoidTag: (tag: string) => boolean;
Examples when true: - link - liNK
Examples when false: - Link (component)
function loc
loc: (span: HasSourceSpan) => SourceSpan;
function match
match: <Out>( callback: (m: Matcher<Out, Matches>) => ExhaustiveMatcher<Out>) => MatchFn<Out>;
function maybeLoc
maybeLoc: (location: MaybeHasSourceSpan, fallback: SourceSpan) => SourceSpan;
function preprocess
preprocess: ( input: string | Source | HBS.Program, options?: PreprocessOptions) => ASTv1.Template;
function traverse
traverse: (node: ASTv1.Node, visitor: NodeVisitor) => void;
class CharPosition
class CharPosition implements PositionData {}
constructor
constructor(source: Source, charPos: number);
property charPos
readonly charPos: number;
property kind
readonly kind: string;
property offset
readonly offset: number;
A
CharPosition
always has an offset it can produce without any additional computation.
property source
readonly source: Source;
method toCharPos
toCharPos: () => CharPosition;
This is already a
CharPosition
.for the alternative.
method toHbsPos
toHbsPos: () => HbsPosition;
Convert the current character offset to an
HbsPosition
, if it was not already computed. Once aCharPosition
has computed itsHbsPosition
, it will not need to do compute it again, and the sameCharPosition
is retained when used as one of the ends of aSourceSpan
, so computing theHbsPosition
should be a one-time operation.
method toJSON
toJSON: () => SourcePosition;
Produce a Handlebars for this
CharPosition
. If thisCharPosition
was computed using , this will compute theSourcePosition
for the offset.
method wrap
wrap: () => SourceOffset;
class CharPositionSpan
class CharPositionSpan implements SpanData {}
constructor
constructor( source: Source, charPositions: { start: CharPosition; end: CharPosition });
property charPositions
readonly charPositions: { start: CharPosition; end: CharPosition };
property kind
readonly kind: string;
property source
readonly source: Source;
method asString
asString: () => string;
method getEnd
getEnd: () => AnyPosition;
method getModule
getModule: () => string;
method getStart
getStart: () => AnyPosition;
method locDidUpdate
locDidUpdate: () => void;
method serialize
serialize: () => SerializedSourceSpan;
method toCharPosSpan
toCharPosSpan: () => CharPositionSpan;
method toHbsSpan
toHbsSpan: () => HbsSpan;
method wrap
wrap: () => SourceSpan;
class HandlebarsNodeVisitors
abstract class HandlebarsNodeVisitors extends Parser {}
property pendingError
protected pendingError: Nullable<PendingError>;
method appendDynamicAttributeValuePart
appendDynamicAttributeValuePart: (part: ASTv1.MustacheStatement) => void;
method appendToCommentData
abstract appendToCommentData: (s: string) => void;
method beginAttributeValue
abstract beginAttributeValue: (quoted: boolean) => void;
method BlockStatement
BlockStatement: (block: HBS.BlockStatement) => ASTv1.BlockStatement | void;
method BooleanLiteral
BooleanLiteral: (boolean: HBS.BooleanLiteral) => ASTv1.BooleanLiteral;
method CommentStatement
CommentStatement: ( rawComment: HBS.CommentStatement) => Nullable<ASTv1.MustacheCommentStatement>;
method ContentStatement
ContentStatement: (content: HBS.ContentStatement) => void;
method Decorator
Decorator: (decorator: HBS.Decorator) => never;
method DecoratorBlock
DecoratorBlock: (decoratorBlock: HBS.DecoratorBlock) => never;
method finalizeTextPart
finalizeTextPart: () => void;
method finishAttributeValue
abstract finishAttributeValue: () => void;
method Hash
Hash: (hash: HBS.Hash) => ASTv1.Hash;
method MustacheStatement
MustacheStatement: ( rawMustache: HBS.MustacheStatement) => ASTv1.MustacheStatement | void;
method NullLiteral
NullLiteral: (nul: HBS.NullLiteral) => ASTv1.NullLiteral;
method NumberLiteral
NumberLiteral: (number: HBS.NumberLiteral) => ASTv1.NumberLiteral;
method parse
parse: (program: HBS.Program, blockParams: string[]) => ASTv1.Template;
method PartialBlockStatement
PartialBlockStatement: (partialBlock: HBS.PartialBlockStatement) => never;
method PartialStatement
PartialStatement: (partial: HBS.PartialStatement) => never;
method PathExpression
PathExpression: (path: HBS.PathExpression) => ASTv1.PathExpression;
method Program
Program: (program: HBS.Program, blockParams?: ASTv1.VarHead[]) => ASTv1.Block;
method startTextPart
startTextPart: () => void;
method StringLiteral
StringLiteral: (string: HBS.StringLiteral) => ASTv1.StringLiteral;
method SubExpression
SubExpression: (sexpr: HBS.SubExpression) => ASTv1.SubExpression;
method UndefinedLiteral
UndefinedLiteral: (undef: HBS.UndefinedLiteral) => ASTv1.UndefinedLiteral;
class HbsPosition
class HbsPosition implements PositionData {}
constructor
constructor(source: Source, hbsPos: SourcePosition, charPos?: number);
property hbsPos
readonly hbsPos: SourcePosition;
property kind
readonly kind: string;
property source
readonly source: Source;
method toCharPos
toCharPos: () => CharPosition;
Lazily compute the character offset from the . Once an
HbsPosition
has computed itsCharPosition
, it will not need to do compute it again, and the sameHbsPosition
is retained when used as one of the ends of aSourceSpan
, so computing theCharPosition
should be a one-time operation.
method toHbsPos
toHbsPos: () => HbsPosition;
This is already an
HbsPosition
.for the alternative.
method toJSON
toJSON: () => SourcePosition;
Return the that this
HbsPosition
was instantiated with. This operation does not need to compute anything.
method wrap
wrap: () => SourceOffset;
class HbsSpan
class HbsSpan implements SpanData {}
constructor
constructor( source: Source, hbsPositions: { start: HbsPosition; end: HbsPosition }, providedHbsLoc?: SourceLocation);
property hbsPositions
readonly hbsPositions: { start: HbsPosition; end: HbsPosition };
property kind
readonly kind: string;
property source
readonly source: Source;
method asString
asString: () => string;
method getEnd
getEnd: () => AnyPosition;
method getModule
getModule: () => string;
method getStart
getStart: () => AnyPosition;
method locDidUpdate
locDidUpdate: ({ start, end,}: { start?: SourcePosition; end?: SourcePosition;}) => void;
method serialize
serialize: () => SerializedConcreteSourceSpan;
method toCharPosSpan
toCharPosSpan: () => CharPositionSpan;
method toHbsLoc
toHbsLoc: () => SourceLocation;
method toHbsSpan
toHbsSpan: () => HbsSpan;
method wrap
wrap: () => SourceSpan;
class InvisiblePosition
class InvisiblePosition implements PositionData {}
constructor
constructor( kind: | OffsetKind.InternalsSynthetic | OffsetKind.NonExistent | OffsetKind.Broken, pos: SourcePosition);
property kind
readonly kind: | OffsetKind.InternalsSynthetic | OffsetKind.NonExistent | OffsetKind.Broken;
property offset
readonly offset: null;
property pos
readonly pos: SourcePosition;
method toCharPos
toCharPos: () => null;
A broken position cannot be turned into a .
method toJSON
toJSON: () => SourcePosition;
The serialization of an `InvisiblePosition is whatever Handlebars was originally identified as broken, non-existent or synthetic.
If an
InvisiblePosition
never had an source offset at all, this method returns for compatibility.
method wrap
wrap: () => SourceOffset;
class InvisibleSpan
class InvisibleSpan implements SpanData {}
constructor
constructor( kind: | OffsetKind.InternalsSynthetic | OffsetKind.NonExistent | OffsetKind.Broken, loc: SourceLocation, string?: string);
property kind
readonly kind: | OffsetKind.InternalsSynthetic | OffsetKind.NonExistent | OffsetKind.Broken;
property loc
readonly loc: SourceLocation;
property string
readonly string: string;
method asString
asString: () => string;
method getEnd
getEnd: () => AnyPosition;
method getModule
getModule: () => string;
method getStart
getStart: () => AnyPosition;
method locDidUpdate
locDidUpdate: ({ start, end,}: { start?: SourcePosition; end?: SourcePosition;}) => void;
method serialize
serialize: () => SerializedConcreteSourceSpan;
method toCharPosSpan
toCharPosSpan: () => InvisibleSpan;
method toHbsLoc
toHbsLoc: () => SourceLocation;
method toHbsSpan
toHbsSpan: () => null;
method wrap
wrap: () => SourceSpan;
class Matcher
class Matcher<Out, M extends Matches = Matches> {}
method check
protected check: () => MatchFn<Out>;
You didn't exhaustively match all possibilities.
method when
when: { ( left: OffsetKind.CharPosition, right: OffsetKind.HbsPosition, callback: (left: CharPosition, right: HbsPosition) => Out ): ExhaustiveCheck<Out, M, 'Char,Hbs'>; ( left: OffsetKind.HbsPosition, right: OffsetKind.CharPosition, callback: (left: HbsPosition, right: CharPosition) => Out ): ExhaustiveCheck<Out, M, 'Hbs,Char'>; ( left: OffsetKind.HbsPosition, right: OffsetKind.HbsPosition, callback: (left: HbsPosition, right: HbsPosition) => Out ): ExhaustiveCheck<Out, M, 'Hbs,Hbs'>; ( left: OffsetKind.CharPosition, right: OffsetKind.CharPosition, callback: (left: CharPosition, right: CharPosition) => Out ): ExhaustiveCheck<Out, M, 'Char,Char'>; ( left: 'IS_INVISIBLE', right: 'MATCH_ANY', callback: (left: InvisiblePosition, right: PositionData) => Out ): Matcher<Out, Exclude<M, 'Invisible,Any'>>; ( left: 'MATCH_ANY', right: 'IS_INVISIBLE', callback: (left: PositionData, right: InvisiblePosition) => Out ): ExhaustiveCheck<Out, M, 'Any,Invisible'>; ( left: 'MATCH_ANY', right: 'MATCH_ANY', callback: (left: PositionData, right: PositionData) => Out ): ExhaustiveMatcher<Out>;};
class Parser
abstract class Parser {}
constructor
constructor( source: Source, entityParser?: EntityParser, mode?: 'precompile' | 'codemod');
property currentAttr
readonly currentAttr: Attribute;
property currentAttribute
currentAttribute: Nullable<Attribute>;
property currentComment
readonly currentComment: ParserNodeBuilder<ASTv1.CommentStatement>;
property currentData
readonly currentData: ParserNodeBuilder<ASTv1.TextNode>;
property currentEndTag
readonly currentEndTag: ParserNodeBuilder<EndTag>;
property currentNode
currentNode: Nullable< Readonly< | ParserNodeBuilder<ASTv1.CommentStatement> | ParserNodeBuilder<ASTv1.TextNode> | ParserNodeBuilder<StartTag> | ParserNodeBuilder<EndTag> >>;
property currentStartTag
readonly currentStartTag: ParserNodeBuilder<StartTag>;
property currentTag
readonly currentTag: ParserNodeBuilder<StartTag> | ParserNodeBuilder<EndTag>;
property elementStack
protected elementStack: ASTv1.ParentNode[];
property source
readonly source: Source;
property tokenizer
tokenizer: EventedTokenizer;
method acceptNode
acceptNode: <T extends keyof HBS.NodeMap>(node: HBS.Node<T>) => HBS.Output<T>;
method appendToAttributeName
abstract appendToAttributeName: (char: string) => void;
method appendToAttributeValue
abstract appendToAttributeValue: (char: string) => void;
method appendToCommentData
abstract appendToCommentData: (char: string) => void;
method appendToData
abstract appendToData: (char: string) => void;
method appendToTagName
abstract appendToTagName: (char: string) => void;
method beginAttribute
abstract beginAttribute: () => void;
method beginAttributeValue
abstract beginAttributeValue: (quoted: boolean) => void;
method beginComment
abstract beginComment: () => void;
method beginData
abstract beginData: () => void;
method beginEndTag
abstract beginEndTag: () => void;
method beginStartTag
abstract beginStartTag: () => void;
method BlockStatement
abstract BlockStatement: ( node: HBS.BlockStatement) => HBS.Output<'BlockStatement'>;
method BooleanLiteral
abstract BooleanLiteral: ( node: HBS.BooleanLiteral) => HBS.Output<'BooleanLiteral'>;
method CommentStatement
abstract CommentStatement: ( node: HBS.CommentStatement) => HBS.Output<'CommentStatement'>;
method ContentStatement
abstract ContentStatement: ( node: HBS.ContentStatement) => HBS.Output<'ContentStatement'>;
method currentElement
currentElement: () => ASTv1.ParentNode;
method Decorator
abstract Decorator: (node: HBS.Decorator) => HBS.Output<'Decorator'>;
method DecoratorBlock
abstract DecoratorBlock: ( node: HBS.DecoratorBlock) => HBS.Output<'DecoratorBlock'>;
method finish
finish: <T extends { loc: SourceSpan }>(node: ParserNodeBuilder<T>) => T;
method finishAttributeValue
abstract finishAttributeValue: () => void;
method finishComment
abstract finishComment: () => void;
method finishData
abstract finishData: () => void;
method finishTag
abstract finishTag: () => void;
method markTagAsSelfClosing
abstract markTagAsSelfClosing: () => void;
method MustacheStatement
abstract MustacheStatement: ( node: HBS.MustacheStatement) => HBS.Output<'MustacheStatement'>;
method NullLiteral
abstract NullLiteral: (node: HBS.NullLiteral) => HBS.Output<'NullLiteral'>;
method NumberLiteral
abstract NumberLiteral: (node: HBS.NumberLiteral) => HBS.Output<'NumberLiteral'>;
method offset
offset: () => SourceOffset;
method parse
abstract parse: (node: HBS.Program, locals: string[]) => ASTv1.Template;
method PartialBlockStatement
abstract PartialBlockStatement: ( node: HBS.PartialBlockStatement) => HBS.Output<'PartialBlockStatement'>;
method PartialStatement
abstract PartialStatement: ( node: HBS.PartialStatement) => HBS.Output<'PartialStatement'>;
method PathExpression
abstract PathExpression: ( node: HBS.PathExpression) => HBS.Output<'PathExpression'>;
method pos
pos: ({ line, column }: src.SourcePosition) => SourceOffset;
method Program
abstract Program: (node: HBS.Program) => HBS.Output<'Program'>;
method reportSyntaxError
abstract reportSyntaxError: (error: string) => void;
method reset
abstract reset: () => void;
method sourceForNode
sourceForNode: (node: HBS.Node, endNode?: { loc: HBS.SourceLocation }) => string;
method StringLiteral
abstract StringLiteral: (node: HBS.StringLiteral) => HBS.Output<'StringLiteral'>;
method SubExpression
abstract SubExpression: (node: HBS.SubExpression) => HBS.Output<'SubExpression'>;
method tagOpen
abstract tagOpen: () => void;
method UndefinedLiteral
abstract UndefinedLiteral: ( node: HBS.UndefinedLiteral) => HBS.Output<'UndefinedLiteral'>;
class Printer
class Printer {}
constructor
constructor(options: PrinterOptions);
method AttrNode
AttrNode: (attr: ASTv1.AttrNode) => void;
method AttrNodeValue
AttrNodeValue: (value: ASTv1.AttrNode['value']) => void;
method Block
Block: (block: ASTv1.Block) => void;
method BlockParams
BlockParams: (blockParams: string[]) => void;
method BlockStatement
BlockStatement: (block: ASTv1.BlockStatement) => void;
method BooleanLiteral
BooleanLiteral: (bool: ASTv1.BooleanLiteral) => void;
method CloseElementNode
CloseElementNode: (el: ASTv1.ElementNode) => void;
method CommentStatement
CommentStatement: (comment: ASTv1.CommentStatement) => void;
method ConcatStatement
ConcatStatement: (concat: ASTv1.ConcatStatement) => void;
method ElementModifierStatement
ElementModifierStatement: (mod: ASTv1.ElementModifierStatement) => void;
method ElementNode
ElementNode: (el: ASTv1.ElementNode) => void;
method Expression
Expression: (expression: ASTv1.Expression) => void;
method handledByOverride
handledByOverride: ( node: ASTv1.Node, ensureLeadingWhitespace?: boolean) => boolean;
method Hash
Hash: (hash: ASTv1.Hash) => void;
method HashPair
HashPair: (pair: ASTv1.HashPair) => void;
method Literal
Literal: (literal: ASTv1.Literal) => void;
method MustacheCommentStatement
MustacheCommentStatement: (comment: ASTv1.MustacheCommentStatement) => void;
method MustacheStatement
MustacheStatement: (mustache: ASTv1.MustacheStatement) => void;
method Node
Node: (node: ASTv1.Node) => void;
method NullLiteral
NullLiteral: (node: ASTv1.NullLiteral) => void;
method NumberLiteral
NumberLiteral: (number: ASTv1.NumberLiteral) => void;
method OpenElementNode
OpenElementNode: (el: ASTv1.ElementNode) => void;
method Params
Params: (params: ASTv1.Expression[]) => void;
method PathExpression
PathExpression: (path: ASTv1.PathExpression) => void;
method print
print: (node: ASTv1.Node) => string;
method StringLiteral
StringLiteral: (str: ASTv1.StringLiteral) => void;
method SubExpression
SubExpression: (sexp: ASTv1.SubExpression) => void;
method Template
Template: (template: ASTv1.Template) => void;
method TextNode
TextNode: (text: ASTv1.TextNode, isAttr?: boolean) => void;
method TopLevelStatement
TopLevelStatement: ( statement: ASTv1.TopLevelStatement | ASTv1.Template | ASTv1.AttrNode) => void;
method TopLevelStatements
TopLevelStatements: (statements: ASTv1.TopLevelStatement[]) => void;
method UndefinedLiteral
UndefinedLiteral: (node: ASTv1.UndefinedLiteral) => 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 from
static from: (source: string, options?: PrecompileOptions) => Source;
method hbsPosFor
hbsPosFor: (offset: number) => Nullable<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 SourceOffset
class SourceOffset {}
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 aSourcePosition
from the Handlebars AST, which can be converted to aCharPosition
on demand. -InvisiblePosition
, which represents a position not in source (@see {InvisiblePosition})
constructor
constructor(data: PositionData & AnyPosition);
property data
readonly data: PositionData & AnyPosition;
property offset
readonly offset: number;
Get the character offset for this
SourceOffset
, if possible.
method broken
static broken: (pos?: SourcePosition) => SourceOffset;
Create a
SourceOffset
that corresponds to a brokenSourcePosition
. This means that the calling code determined (or knows) that theSourceLocation
doesn't correspond correctly to any part of the source.
method collapsed
collapsed: () => SourceSpan;
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.
method eql
eql: (right: SourceOffset) => boolean;
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.
method forHbsPos
static forHbsPos: (source: Source, pos: SourcePosition) => SourceOffset;
Create a
SourceOffset
from a HandlebarsSourcePosition
. It's stored as-is, and converted into a character offset on demand, which avoids unnecessarily computing the offset of everySourceLocation
, but also means that brokenSourcePosition
s are not always detected.
method move
move: (by: number) => SourceOffset;
Create a
SourceOffset
by moving the character position represented by this source offset forward or backward (ifby
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.
method toJSON
toJSON: () => SourcePosition;
Convert this
SourceOffset
into a Handlebars for compatibility with existing plugins.
method until
until: (other: SourceOffset) => SourceSpan;
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.
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<string>;
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<string>;
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: (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 TokenizerEventHandlers
class TokenizerEventHandlers extends HandlebarsNodeVisitors {}
method appendToAttributeName
appendToAttributeName: (char: string) => void;
method appendToAttributeValue
appendToAttributeValue: (char: string) => void;
method appendToCommentData
appendToCommentData: (char: string) => void;
method appendToData
appendToData: (char: string) => void;
method appendToTagName
appendToTagName: (char: string) => void;
method assembleAttributeValue
assembleAttributeValue: ( parts: ASTv1.AttrPart[], isQuoted: boolean, isDynamic: boolean, span: SourceSpan) => ASTv1.AttrValue;
method assembleConcatenatedValue
assembleConcatenatedValue: ( parts: (ASTv1.MustacheStatement | ASTv1.TextNode)[]) => ASTv1.ConcatStatement;
method beginAttribute
beginAttribute: () => void;
method beginAttributeValue
beginAttributeValue: (isQuoted: boolean) => void;
method beginComment
beginComment: () => void;
method beginData
beginData: () => void;
method beginEndTag
beginEndTag: () => void;
method beginStartTag
beginStartTag: () => void;
method finishAttributeValue
finishAttributeValue: () => void;
method finishComment
finishComment: () => void;
method finishData
finishData: () => void;
method finishEndTag
finishEndTag: (isVoid: boolean) => void;
method finishStartTag
finishStartTag: () => void;
method finishTag
finishTag: () => void;
method markTagAsSelfClosing
markTagAsSelfClosing: () => void;
method reportSyntaxError
reportSyntaxError: (message: string) => void;
method reset
reset: () => void;
method tagOpen
tagOpen: () => void;
method validateEndTag
validateEndTag: ( tag: StartTag | EndTag, element: ASTv1.ElementNode, selfClosing: boolean) => void;
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: Nullable<N>, visitor: 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>>;
class When
class When<Out> {}
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 Attribute
interface Attribute {}
property currentPart
currentPart: ASTv1.TextNode | null;
property isDynamic
isDynamic: boolean;
property isQuoted
isQuoted: boolean;
property name
name: string;
property parts
parts: (ASTv1.MustacheStatement | ASTv1.TextNode)[];
property start
start: src.SourceOffset;
property valueSpan
valueSpan: src.SourceSpan;
interface BuildElementOptions
interface BuildElementOptions {}
property attrs
attrs?: ASTv1.AttrNode[];
property blockParams
blockParams?: ASTv1.VarHead[] | string[];
property children
children?: ASTv1.Statement[];
property closeTag
closeTag?: Nullable<SourceLocation>;
property comments
comments?: ASTv1.MustacheCommentStatement[];
property loc
loc?: SourceLocation;
property modifiers
modifiers?: ASTv1.ElementModifierStatement[];
property openTag
openTag?: SourceLocation;
interface EndTag
interface EndTag {}
interface ExhaustiveMatcher
interface ExhaustiveMatcher<Out> {}
method check
check: () => MatchFn<Out>;
interface FullKeyTraversal
interface FullKeyTraversal<N extends ASTv1.Node, K extends string> {}
interface FullNodeTraversal
interface FullNodeTraversal<N extends ASTv1.Node> {}
interface HandlebarsParseOptions
interface HandlebarsParseOptions {}
property ignoreStandalone
ignoreStandalone?: boolean;
property srcName
srcName?: string;
interface PendingError
interface PendingError {}
interface PositionData
interface PositionData {}
All positions have these details in common. Most notably, all three kinds of positions can must be able to attempt to convert themselves into .
interface PrecompileOptions
interface PrecompileOptions extends PreprocessOptions {}
property customizeComponentName
customizeComponentName?: ((input: string) => string) | undefined;
property id
id?: TemplateIdFn;
property keywords
keywords?: readonly string[];
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.
interface PrecompileOptionsWithLexicalScope
interface PrecompileOptionsWithLexicalScope extends PrecompileOptions {}
property lexicalScope
lexicalScope: (variable: string) => boolean;
interface PreprocessOptions
interface PreprocessOptions {}
property customizeComponentName
customizeComponentName?: ((input: string) => string) | undefined;
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;
interface PrinterOptions
interface PrinterOptions {}
property entityEncoding
entityEncoding: ASTv1.EntityEncodingState;
method override
override: (ast: ASTv1.Node, options: PrinterOptions) => void | string;
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.
Parameter ast
the ast node to be printed
Parameter options
the options specified during the print() invocation
interface SourceLocation
interface SourceLocation {}
interface SourcePosition
interface SourcePosition {}
interface SpanData
interface SpanData {}
All spans have these details in common.
property kind
readonly kind: OffsetKind;
method asString
asString: () => string;
Convert this span into a string. If the span is broken, return
''
.
method getEnd
getEnd: () => AnyPosition;
Get the ending position for this span. Try to avoid creating new position objects, as they cache computations.
method getModule
getModule: () => string;
Gets the module the span was located in.
method getStart
getStart: () => AnyPosition;
Get the starting position for this span. Try to avoid creating new position objects, as they cache computations.
method locDidUpdate
locDidUpdate: (changes: { start?: SourcePosition; end?: SourcePosition;}) => void;
For compatibility, whenever the
start
orend
of a changes, spans are notified of the change so they can update themselves. This shouldn't happen outside of AST plugins.
method serialize
serialize: () => SerializedSourceSpan;
Serialize into a , which is compact and designed for readability in context like AST Explorer. If you need a , use .
method toHbsSpan
toHbsSpan: () => HbsSpan;
Compute the
SourceLocation
for this span, returned as an instance ofHbsSpan
.
interface StartTag
interface StartTag {}
property attributes
readonly attributes: ASTv1.AttrNode[];
property comments
readonly comments: ASTv1.MustacheCommentStatement[];
property loc
readonly loc: src.SourceSpan;
property modifiers
readonly modifiers: ASTv1.ElementModifierStatement[];
property name
name: string;
property nameEnd
nameEnd: Nullable<src.SourceOffset>;
property nameStart
nameStart: Nullable<src.SourceOffset>;
property params
readonly params: ASTv1.VarHead[];
property selfClosing
selfClosing: boolean;
property type
readonly type: 'StartTag';
interface Syntax
interface Syntax {}
interface TemplateIdFn
interface TemplateIdFn {}
call signature
(src: string): Nullable<string>;
enum OffsetKind
enum OffsetKind { CharPosition = 'CharPosition', HbsPosition = 'HbsPosition', InternalsSynthetic = 'InternalsSynthetic', NonExistent = 'NonExistent', Broken = 'Broken',}
member Broken
Broken = 'Broken'
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.
member CharPosition
CharPosition = 'CharPosition'
We have already computed the character position of this offset or span.
member HbsPosition
HbsPosition = 'HbsPosition'
This offset or span was instantiated with a Handlebars SourcePosition or SourceLocation. Its character position will be computed on demand.
member InternalsSynthetic
InternalsSynthetic = 'InternalsSynthetic'
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.
member NonExistent
NonExistent = 'NonExistent'
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 AnyPosition
type AnyPosition = HbsPosition | CharPosition | InvisiblePosition;
type AnySpan
type AnySpan = HbsSpan | CharPositionSpan | InvisibleSpan;
type AttrSexp
type AttrSexp = [string, ASTv1.AttrNode['value'] | string, LocSexp?];
type BROKEN
type BROKEN = 'BROKEN';
type BuilderHead
type BuilderHead = string | ASTv1.CallableExpression;
type ElementComment
type ElementComment = ASTv1.MustacheCommentStatement | SourceLocation | string;
type ElementParts
type ElementParts = | ['attrs', ...AttrSexp[]] | ['modifiers', ...ModifierSexp[]] | ['body', ...ASTv1.Statement[]] | ['comments', ...ElementComment[]] | ['as', ...string[]] | ['loc', SourceLocation];
type ExhaustiveCheck
type ExhaustiveCheck<Out, In extends Matches, Removed extends Matches> = Exclude< In, Removed> extends never ? ExhaustiveMatcher<Out> : Matcher<Out, Exclude<In, Removed>>;
type HasSourceLocation
type HasSourceLocation = | SourceLocation | LocatedWithPositions | PresentArray<LocatedWithPositions>;
type HasSourceSpan
type HasSourceSpan = | { loc: SourceSpan; } | SourceSpan | [HasSourceSpan, ...HasSourceSpan[]];
type HasSpan
type HasSpan = SourceSpan | LocatedWithSpan | PresentArray<LocatedWithSpan>;
type IsInvisible
type IsInvisible = 'IS_INVISIBLE';
type KeyHandler
type KeyHandler<N extends ASTv1.Node, K extends VisitorKey<N>> = ( node: N, key: K) => void;
type KeysVisitor
type KeysVisitor<N extends ASTv1.Node> = { [P in VisitorKey<N>]?: KeyTraversal<N, P>;} & { All?: KeyTraversal<N, VisitorKey<N>>; /** * @deprecated use Template or Block instead */ Program?: KeyTraversal<ASTv1.Template | ASTv1.Block, 'body'>;};
type KeyTraversal
type KeyTraversal<N extends ASTv1.Node, K extends VisitorKey<N>> = | FullKeyTraversal<N, K> | KeyHandler<N, K>;
type LocatedWithOptionalPositions
type LocatedWithOptionalPositions = { loc?: SourceLocation;};
type LocatedWithOptionalSpan
type LocatedWithOptionalSpan = { offsets: SourceSpan | null;};
type LocatedWithPositions
type LocatedWithPositions = { loc: SourceLocation;};
type LocatedWithSpan
type LocatedWithSpan = { offsets: SourceSpan;};
type LocSexp
type LocSexp = ['loc', SourceLocation];
type MatchAny
type MatchAny = 'MATCH_ANY';
type Matches
type Matches = | 'Char,Hbs' | 'Hbs,Char' | 'Hbs,Hbs' | 'Char,Char' | 'Invisible,Any' | 'Any,Invisible';
type MatchFn
type MatchFn<Out> = (left: PositionData, right: PositionData) => Out;
type MaybeHasSourceLocation
type MaybeHasSourceLocation = | null | LocatedWithOptionalPositions | LocatedWithOptionalPositions[];
type MaybeHasSourceSpan
type MaybeHasSourceSpan = | { loc: SourceSpan; } | SourceSpan | MaybeHasSourceSpan[];
type MaybeHasSpan
type MaybeHasSpan = | SourceSpan | LocatedWithOptionalSpan | LocatedWithOptionalSpan[] | null;
type ModifierSexp
type ModifierSexp = | string | [PathSexp, LocSexp?] | [PathSexp, ASTv1.Expression[], LocSexp?] | [PathSexp, ASTv1.Expression[], Dict<ASTv1.Expression>, LocSexp?];
type NodeCallback
type NodeCallback<N extends ASTv1.Node> = (node: N, walker: Walker) => void;
type NodeHandler
type NodeHandler<N extends ASTv1.Node> = (node: N, path: WalkerPath<N>) => void;
type NodeTraversal
type NodeTraversal<N extends ASTv1.Node> = FullNodeTraversal<N> | NodeHandler<N>;
type NodeVisitor
type NodeVisitor = { [P in keyof ASTv1.Nodes]?: NodeTraversal<ASTv1.Nodes[P]>;} & { All?: NodeTraversal<ASTv1.Node>; /** * @deprecated use Template or Block instead */ Program?: NodeTraversal<ASTv1.Template | ASTv1.Block>;};
type ParserNodeBuilder
type ParserNodeBuilder< N extends { loc: src.SourceSpan; }> = Omit<N, 'loc'> & { start: src.SourceOffset;};
type PathSexp
type PathSexp = string | ['path', string, LocSexp?];
type Pattern
type Pattern = OffsetKind | IsInvisible | MatchAny;
type PossiblyDeprecatedBlock
type PossiblyDeprecatedBlock = ASTv1.Block | ASTv1.Template;
type SerializedConcreteSourceSpan
type SerializedConcreteSourceSpan = /** collapsed */ | number | /** normal */ [start: number, size: number] | /** synthetic */ string;
type SerializedSourceSlice
type SerializedSourceSlice<Chars extends string = string> = [ chars: Chars, span: src.SerializedSourceSpan];
type SerializedSourceSpan
type SerializedSourceSpan = | SerializedConcreteSourceSpan | OffsetKind.NonExistent | OffsetKind.Broken;
type SexpValue
type SexpValue = | string | ASTv1.Expression[] | Dict<ASTv1.Expression> | LocSexp | PathSexp | undefined;
type TagDescriptor
type TagDescriptor = | string | ASTv1.PathExpression | { path: ASTv1.PathExpression; selfClosing?: boolean; } | { name: string; selfClosing?: boolean; };
type ToSourceOffset
type ToSourceOffset = number | SourceOffset;
type VisitorKey
type VisitorKey<N extends ASTv1.Node> = VisitorKeys[N['type']] & keyof N;
type VisitorKeys
type VisitorKeys = { [P in keyof VisitorKeysMap]: VisitorKeysMap[P][number];};
type VisitorKeysMap
type VisitorKeysMap = typeof visitorKeys;
Package Files (1)
Dependencies (5)
Dev Dependencies (7)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@glimmer/syntax
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@glimmer/syntax)
- HTML<a href="https://www.jsdocs.io/package/@glimmer/syntax"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 27311 ms. - Missing or incorrect documentation? Open an issue for this package.