packages/@glimmer/compiler/lib/passes/1-normalization/README.md
The purpose of the precompiler's initial pass is normalizing the AST into a HIR (High-Level IR).
(has-block), {{#in-element}} and {{yield}}) from user-space invocations.<div>)<CapCase />)<f.input />)<:NamedBlock>)The input AST tags each node with a SourceLocation (a starting and ending position, each represented as a pair of line and column). Pass 0 normalizes the SourceLocations into SourceOffsets, represented as simple byte offsets.
In some cases, the AST fragment that corresponds to a HIR node does not contain a source location. For example, the key in a HashPair is a simple string, and a list of positional parameters is not grouped into a parent node. Where possible, Pass 0 attempts to tag the HIR output with a SourceOffsets.
The algorithms below elide
SourceOffsetstagging for clarity.
Process-Expression(with a single expr)
(with optional context: ExpressionContext, defaulting to ExpressionContext.Default)
Match the expr's type:
AST.Literal => normalize it into a hir.LiteralAST.SubExpression =>
hir.Exprhir.Exprs.AST.PathExpression =>
this, translate to hir.GetThis@arg, translate to hir.GetArghir.GetVar(context: context)hir.StrictGetVarProcess-Statement(with a single statement)
Match the statement's type:
PartialStatement => error (Handlebars > syntax is not supported)MustacheCommentStatement => do nothingTextNode => normalize to hir.AppendTextNode(chars)CommentStatement => normalize to hir.AppendComment(chars)BlockStatement =>
statement is a keyword, check syntax and translate it into a hir.Statementhir.NamedBlocks
hir.Blockhir.BlockProcessing-Expressions(context: BlockHead))(with list of exprs)
params be the result of map(exprs, Process-Expression)hir.Params(params)(with list of hash pairs)
hir-pairs be the result of map(pairs, Process-HashPair)hir.Hash(hir-pairs)(with name and value)
expr be the result of Process Expression(value)hir.HashPair(name: name, value: expr)