|
|
|
|
@ -33,32 +33,27 @@ export function IfBlock(node, context) {
|
|
|
|
|
let index = 0;
|
|
|
|
|
|
|
|
|
|
/** @type {IfStatement} */
|
|
|
|
|
let current_if = create_if(node, context, index++);
|
|
|
|
|
let if_statement = create_if(node, context, index++);
|
|
|
|
|
|
|
|
|
|
context.state.template.push(current_if, block_close);
|
|
|
|
|
context.state.template.push(if_statement, block_close);
|
|
|
|
|
|
|
|
|
|
let alternate = node.alternate;
|
|
|
|
|
while (
|
|
|
|
|
alternate &&
|
|
|
|
|
alternate.nodes.length === 1 &&
|
|
|
|
|
alternate.nodes[0].type === 'IfBlock' &&
|
|
|
|
|
alternate.nodes[0].elseif
|
|
|
|
|
) {
|
|
|
|
|
const current_node = alternate.nodes[0];
|
|
|
|
|
current_if = current_if.alternate = create_if(current_node, context, index++);
|
|
|
|
|
alternate = current_node.alternate;
|
|
|
|
|
let alt = node.alternate;
|
|
|
|
|
while (alt && alt.nodes.length === 1 && alt.nodes[0].type === 'IfBlock' && alt.nodes[0].elseif) {
|
|
|
|
|
const elseif = alt.nodes[0];
|
|
|
|
|
if_statement = if_statement.alternate = create_if(elseif, context, index++);
|
|
|
|
|
alt = elseif.alternate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @type {string} */
|
|
|
|
|
let else_key;
|
|
|
|
|
if (alternate) {
|
|
|
|
|
current_if.alternate = /** @type {BlockStatement} */ (context.visit(alternate));
|
|
|
|
|
if (alt) {
|
|
|
|
|
if_statement.alternate = /** @type {BlockStatement} */ (context.visit(alt));
|
|
|
|
|
else_key = `<!--[${index}-->`;
|
|
|
|
|
} else {
|
|
|
|
|
current_if.alternate = b.block([]);
|
|
|
|
|
if_statement.alternate = b.block([]);
|
|
|
|
|
else_key = BLOCK_OPEN_ELSE;
|
|
|
|
|
}
|
|
|
|
|
current_if.alternate.body.unshift(
|
|
|
|
|
if_statement.alternate.body.unshift(
|
|
|
|
|
b.stmt(b.assignment('+=', b.id('$$payload.out'), b.literal(else_key)))
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|