change :elseif to :else if - fixes #2137

pull/2138/head
Richard Harris 6 years ago
parent c672ad8df7
commit 6c85f6a6b5

@ -86,7 +86,18 @@ export default function mustache(parser: Parser) {
block.end = parser.index;
parser.stack.pop();
} else if (parser.eat(':elseif')) {
} else if (parser.eat(':else')) {
if (parser.eat('if')) {
parser.error({
code: 'invalid-elseif',
message: `'elseif' should be 'else if'`
});
}
parser.allowWhitespace();
// :else if
if (parser.eat('if')) {
const block = parser.current();
if (block.type !== 'IfBlock')
parser.error({
@ -118,7 +129,10 @@ export default function mustache(parser: Parser) {
};
parser.stack.push(block.else.children[0]);
} else if (parser.eat(':else')) {
}
// :else
else {
const block = parser.current();
if (block.type !== 'IfBlock' && block.type !== 'EachBlock') {
parser.error({
@ -138,6 +152,7 @@ export default function mustache(parser: Parser) {
};
parser.stack.push(block.else);
}
} else if (parser.eat(':then')) {
// TODO DRY out this and the next section
const pendingBlock = parser.current();

@ -1,12 +1,12 @@
{
"html": {
"start": 0,
"end": 88,
"end": 89,
"type": "Fragment",
"children": [
{
"start": 0,
"end": 88,
"end": 89,
"type": "IfBlock",
"expression": {
"type": "BinaryExpression",
@ -45,45 +45,45 @@
}
],
"else": {
"start": 57,
"end": 83,
"start": 58,
"end": 84,
"type": "ElseBlock",
"children": [
{
"start": 57,
"end": 88,
"start": 58,
"end": 89,
"type": "IfBlock",
"elseif": true,
"expression": {
"type": "BinaryExpression",
"start": 51,
"end": 56,
"start": 52,
"end": 57,
"left": {
"type": "Identifier",
"start": 51,
"end": 52,
"start": 52,
"end": 53,
"name": "x"
},
"operator": "<",
"right": {
"type": "Literal",
"start": 55,
"end": 56,
"start": 56,
"end": 57,
"value": 5,
"raw": "5"
}
},
"children": [
{
"start": 59,
"end": 82,
"start": 60,
"end": 83,
"type": "Element",
"name": "p",
"attributes": [],
"children": [
{
"start": 62,
"end": 78,
"start": 63,
"end": 79,
"type": "Text",
"data": "x is less than 5"
}
@ -95,8 +95,5 @@
}
}
]
},
"css": null,
"instance": null,
"module": null
}
}
Loading…
Cancel
Save