diff --git a/src/parse/state/mustache.js b/src/parse/state/mustache.js index 7dad3706e8..bb25fcfc16 100644 --- a/src/parse/state/mustache.js +++ b/src/parse/state/mustache.js @@ -171,6 +171,12 @@ export default function mustache ( parser ) { if ( !block.index ) parser.error( `Expected name` ); parser.allowWhitespace(); } + + if ( parser.eat( '@' ) ) { + block.key = parser.read( validIdentifier ); + if ( !block.key ) parser.error( `Expected name` ); + parser.allowWhitespace(); + } } parser.eat( '}}', true ); diff --git a/test/parser/each-block-keyed/input.html b/test/parser/each-block-keyed/input.html new file mode 100644 index 0000000000..2bc79c9c8b --- /dev/null +++ b/test/parser/each-block-keyed/input.html @@ -0,0 +1,3 @@ +{{#each todos as todo @id}} +

{{todo}}

+{{/each}} diff --git a/test/parser/each-block-keyed/output.json b/test/parser/each-block-keyed/output.json new file mode 100644 index 0000000000..3ace8016ec --- /dev/null +++ b/test/parser/each-block-keyed/output.json @@ -0,0 +1,46 @@ +{ + "html": { + "start": 0, + "end": 54, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 54, + "type": "EachBlock", + "expression": { + "start": 8, + "end": 13, + "type": "Identifier", + "name": "todos" + }, + "context": "todo", + "key": "id", + "children": [ + { + "start": 29, + "end": 44, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 32, + "end": 40, + "type": "MustacheTag", + "expression": { + "start": 34, + "end": 38, + "type": "Identifier", + "name": "todo" + } + } + ] + } + ] + } + ] + }, + "css": null, + "js": null +}