parse each block index

pull/31/head
Rich-Harris 9 years ago
parent 4a32e59f2e
commit 8c8b6ccfa4

@ -83,8 +83,16 @@ export default function mustache ( parser ) {
parser.requireWhitespace();
block.context = parser.read( validIdentifier ); // TODO check it's not a keyword
if ( !block.context ) parser.error( `Expected name` );
parser.allowWhitespace();
if ( parser.eat( ',' ) ) {
parser.allowWhitespace();
block.index = parser.read( validIdentifier );
if ( !block.index ) parser.error( `Expected name` );
parser.allowWhitespace();
}
}
parser.eat( '}}', true );

@ -0,0 +1,3 @@
{{#each animals as animal, i}}
<p>{{i}}: {{animal}}</p>
{{/each}}

@ -0,0 +1,63 @@
{
"html": {
"start": 0,
"end": 66,
"type": "Fragment",
"children": [
{
"start": 0,
"end": 66,
"type": "EachBlock",
"expression": {
"start": 8,
"end": 15,
"type": "Identifier",
"name": "animals"
},
"context": "animal",
"index": "i",
"children": [
{
"start": 32,
"end": 56,
"type": "Element",
"name": "p",
"attributes": [],
"children": [
{
"start": 35,
"end": 40,
"type": "MustacheTag",
"expression": {
"start": 37,
"end": 38,
"type": "Identifier",
"name": "i"
}
},
{
"start": 40,
"end": 42,
"type": "Text",
"data": ": "
},
{
"start": 42,
"end": 52,
"type": "MustacheTag",
"expression": {
"start": 44,
"end": 50,
"type": "Identifier",
"name": "animal"
}
}
]
}
]
}
]
},
"css": null,
"js": null
}

@ -1 +1,3 @@
{{#each animals as animal}}<p>{{animal}}</p>{{/each}}
{{#each animals as animal}}
<p>{{animal}}</p>
{{/each}}

@ -1,12 +1,12 @@
{
"html": {
"start": 0,
"end": 53,
"end": 56,
"type": "Fragment",
"children": [
{
"start": 0,
"end": 53,
"end": 56,
"type": "EachBlock",
"expression": {
"start": 8,
@ -17,19 +17,19 @@
"context": "animal",
"children": [
{
"start": 27,
"end": 44,
"start": 29,
"end": 46,
"type": "Element",
"name": "p",
"attributes": [],
"children": [
{
"start": 30,
"end": 40,
"start": 32,
"end": 42,
"type": "MustacheTag",
"expression": {
"start": 32,
"end": 38,
"start": 34,
"end": 40,
"type": "Identifier",
"name": "animal"
}

Loading…
Cancel
Save