Glimmer.js Wire-Format
We have a glimmer template as follows, please bear with me for missing syntax highlights:
template.hbs
{{#if @condition}}
<p class="intro">Hello, world</p>
{{/if}}
Here, the compiler encounters an if
condition and the corresponding OpCode is 41:
wire-format.d.ts
export type If = [
op: SexpOpcodes.If,
condition: Expression,
block: SerializedInlineBlock,
inverse: Option<SerializedInlineBlock>
];
The If
block takes in 4 arguments as listed above. First being OpCode itself, followed by the block for condition. Last two are set of lines to be executed in true
and false
conditions respectively. Last arg is optional which takes null
. So, the above line can be converted to:
output.js
[
41,
[30, 1],
[
[
[1, ' '],
[10, 2],
[14, 0, 'intro'],
[12],
[1, 'Hello, world'],
[13],
[1, 'n'],
],
[],
],
null,
],
Other OpCodes for above examples with explanation are listed here:
Opcode | Explanation |
---|---|
30 | GetSymbol: Here, the second argument is 1 , which is the index number in symbol table to lookupcondition variable |
1 | Append: due to whitespace / newline before the condition itself, it is appended to the wire-format |
10 | OpenElement
|
14 | StaticAttr
|
12 | FlushElement |
13 | CloseElement |
41 | If |