diff --git a/compiler/parse/state/mustache.js b/compiler/parse/state/mustache.js index beba91da12..0305a89296 100644 --- a/compiler/parse/state/mustache.js +++ b/compiler/parse/state/mustache.js @@ -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 ); diff --git a/test/parser/each-block-indexed/input.svelte b/test/parser/each-block-indexed/input.svelte new file mode 100644 index 0000000000..5c1c74da66 --- /dev/null +++ b/test/parser/each-block-indexed/input.svelte @@ -0,0 +1,3 @@ +{{#each animals as animal, i}} +
{{i}}: {{animal}}
+{{/each}} diff --git a/test/parser/each-block-indexed/output.json b/test/parser/each-block-indexed/output.json new file mode 100644 index 0000000000..46c4ac34eb --- /dev/null +++ b/test/parser/each-block-indexed/output.json @@ -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 +} diff --git a/test/parser/each-block/input.svelte b/test/parser/each-block/input.svelte index 002481b7e3..23bfc3c465 100644 --- a/test/parser/each-block/input.svelte +++ b/test/parser/each-block/input.svelte @@ -1 +1,3 @@ -{{#each animals as animal}}{{animal}}
{{/each}} +{{#each animals as animal}} +{{animal}}
+{{/each}} diff --git a/test/parser/each-block/output.json b/test/parser/each-block/output.json index 8dda2ae77f..d0534c3206 100644 --- a/test/parser/each-block/output.json +++ b/test/parser/each-block/output.json @@ -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" }