add each-else support to parser

pull/122/head
Arpad Borsos 8 years ago
parent def48e2c1d
commit fec55a1ccd
No known key found for this signature in database
GPG Key ID: 908EDF65263368B4

@ -112,7 +112,9 @@ export default function mustache ( parser ) {
else if ( parser.eat( 'else' ) ) {
const block = parser.current();
if ( block.type !== 'IfBlock' ) parser.error( 'Cannot have an {{else}} block outside an {{#if ...}} block' );
if ( block.type !== 'IfBlock' && block.type !== 'EachBlock' ) {
parser.error( 'Cannot have an {{else}} block outside an {{#if ...}} or {{#each ...}} block' );
}
parser.allowWhitespace();
parser.eat( '}}', true );

@ -0,0 +1,5 @@
{{#each animals as animal}}
<p>{{animal}}</p>
{{else}}
<p>no animals</p>
{{/each}}

@ -0,0 +1,67 @@
{
"html": {
"start": 0,
"end": 84,
"type": "Fragment",
"children": [
{
"start": 0,
"end": 84,
"type": "EachBlock",
"expression": {
"start": 8,
"end": 15,
"type": "Identifier",
"name": "animals"
},
"context": "animal",
"children": [
{
"start": 29,
"end": 46,
"type": "Element",
"name": "p",
"attributes": [],
"children": [
{
"start": 32,
"end": 42,
"type": "MustacheTag",
"expression": {
"start": 34,
"end": 40,
"type": "Identifier",
"name": "animal"
}
}
]
}
],
"else": {
"children": [
{
"attributes": [],
"children": [
{
"data": "no animals",
"end": 70,
"start": 60,
"type": "Text"
}
],
"end": 74,
"name": "p",
"start": 57,
"type": "Element"
}
],
"end": 75,
"start": 55,
"type": "ElseBlock"
}
}
]
},
"css": null,
"js": null
}
Loading…
Cancel
Save