|
|
@ -86,58 +86,73 @@ export default function mustache(parser: Parser) {
|
|
|
|
|
|
|
|
|
|
|
|
block.end = parser.index;
|
|
|
|
block.end = parser.index;
|
|
|
|
parser.stack.pop();
|
|
|
|
parser.stack.pop();
|
|
|
|
} else if (parser.eat(':elseif')) {
|
|
|
|
} else if (parser.eat(':else')) {
|
|
|
|
const block = parser.current();
|
|
|
|
if (parser.eat('if')) {
|
|
|
|
if (block.type !== 'IfBlock')
|
|
|
|
|
|
|
|
parser.error({
|
|
|
|
parser.error({
|
|
|
|
code: `invalid-elseif-placement`,
|
|
|
|
code: 'invalid-elseif',
|
|
|
|
message: 'Cannot have an {:elseif ...} block outside an {#if ...} block'
|
|
|
|
message: `'elseif' should be 'else if'`
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
parser.requireWhitespace();
|
|
|
|
parser.allowWhitespace();
|
|
|
|
|
|
|
|
|
|
|
|
const expression = readExpression(parser);
|
|
|
|
// :else if
|
|
|
|
|
|
|
|
if (parser.eat('if')) {
|
|
|
|
|
|
|
|
const block = parser.current();
|
|
|
|
|
|
|
|
if (block.type !== 'IfBlock')
|
|
|
|
|
|
|
|
parser.error({
|
|
|
|
|
|
|
|
code: `invalid-elseif-placement`,
|
|
|
|
|
|
|
|
message: 'Cannot have an {:else if ...} block outside an {#if ...} block'
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
parser.allowWhitespace();
|
|
|
|
parser.requireWhitespace();
|
|
|
|
parser.eat('}', true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
block.else = {
|
|
|
|
const expression = readExpression(parser);
|
|
|
|
start: parser.index,
|
|
|
|
|
|
|
|
end: null,
|
|
|
|
|
|
|
|
type: 'ElseBlock',
|
|
|
|
|
|
|
|
children: [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
start: parser.index,
|
|
|
|
|
|
|
|
end: null,
|
|
|
|
|
|
|
|
type: 'IfBlock',
|
|
|
|
|
|
|
|
elseif: true,
|
|
|
|
|
|
|
|
expression,
|
|
|
|
|
|
|
|
children: [],
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parser.stack.push(block.else.children[0]);
|
|
|
|
parser.allowWhitespace();
|
|
|
|
} else if (parser.eat(':else')) {
|
|
|
|
parser.eat('}', true);
|
|
|
|
const block = parser.current();
|
|
|
|
|
|
|
|
if (block.type !== 'IfBlock' && block.type !== 'EachBlock') {
|
|
|
|
block.else = {
|
|
|
|
parser.error({
|
|
|
|
start: parser.index,
|
|
|
|
code: `invalid-else-placement`,
|
|
|
|
end: null,
|
|
|
|
message: 'Cannot have an {:else} block outside an {#if ...} or {#each ...} block'
|
|
|
|
type: 'ElseBlock',
|
|
|
|
});
|
|
|
|
children: [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
start: parser.index,
|
|
|
|
|
|
|
|
end: null,
|
|
|
|
|
|
|
|
type: 'IfBlock',
|
|
|
|
|
|
|
|
elseif: true,
|
|
|
|
|
|
|
|
expression,
|
|
|
|
|
|
|
|
children: [],
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parser.stack.push(block.else.children[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
parser.allowWhitespace();
|
|
|
|
// :else
|
|
|
|
parser.eat('}', true);
|
|
|
|
else {
|
|
|
|
|
|
|
|
const block = parser.current();
|
|
|
|
|
|
|
|
if (block.type !== 'IfBlock' && block.type !== 'EachBlock') {
|
|
|
|
|
|
|
|
parser.error({
|
|
|
|
|
|
|
|
code: `invalid-else-placement`,
|
|
|
|
|
|
|
|
message: 'Cannot have an {:else} block outside an {#if ...} or {#each ...} block'
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parser.allowWhitespace();
|
|
|
|
|
|
|
|
parser.eat('}', true);
|
|
|
|
|
|
|
|
|
|
|
|
block.else = {
|
|
|
|
block.else = {
|
|
|
|
start: parser.index,
|
|
|
|
start: parser.index,
|
|
|
|
end: null,
|
|
|
|
end: null,
|
|
|
|
type: 'ElseBlock',
|
|
|
|
type: 'ElseBlock',
|
|
|
|
children: [],
|
|
|
|
children: [],
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
parser.stack.push(block.else);
|
|
|
|
parser.stack.push(block.else);
|
|
|
|
|
|
|
|
}
|
|
|
|
} else if (parser.eat(':then')) {
|
|
|
|
} else if (parser.eat(':then')) {
|
|
|
|
// TODO DRY out this and the next section
|
|
|
|
// TODO DRY out this and the next section
|
|
|
|
const pendingBlock = parser.current();
|
|
|
|
const pendingBlock = parser.current();
|
|
|
|