diff --git a/src/parse/state/mustache.ts b/src/parse/state/mustache.ts index de4d00037b..41762c2575 100644 --- a/src/parse/state/mustache.ts +++ b/src/parse/state/mustache.ts @@ -274,8 +274,8 @@ export default function mustache(parser: Parser) { parser.allowWhitespace(); } - if (parser.eat('key')) { - parser.requireWhitespace(); + if (parser.eat('(')) { + parser.allowWhitespace(); const expression = readExpression(parser); @@ -292,6 +292,8 @@ export default function mustache(parser: Parser) { block.key = expression.property.name; parser.allowWhitespace(); + parser.eat(')', true); + parser.allowWhitespace(); } else if (parser.eat('@')) { block.key = parser.readIdentifier(); if (!block.key) parser.error(`Expected name`); diff --git a/test/parser/samples/each-block-keyed/input-v2.html b/test/parser/samples/each-block-keyed/input-v2.html index 3cc00ce93e..46348678d4 100644 --- a/test/parser/samples/each-block-keyed/input-v2.html +++ b/test/parser/samples/each-block-keyed/input-v2.html @@ -1,3 +1,3 @@ -{#each todos as todo key todo.id} +{#each todos as todo (todo.id)}

{todo}

{/each} diff --git a/test/parser/samples/each-block-keyed/output-v2.json b/test/parser/samples/each-block-keyed/output-v2.json index 514682b770..461992347b 100644 --- a/test/parser/samples/each-block-keyed/output-v2.json +++ b/test/parser/samples/each-block-keyed/output-v2.json @@ -1,13 +1,13 @@ { - "hash": "3sm0ec", + "hash": "1x6az5m", "html": { "start": 0, - "end": 56, + "end": 54, "type": "Fragment", "children": [ { "start": 0, - "end": 56, + "end": 54, "type": "EachBlock", "expression": { "type": "Identifier", @@ -17,20 +17,20 @@ }, "children": [ { - "start": 35, - "end": 48, + "start": 33, + "end": 46, "type": "Element", "name": "p", "attributes": [], "children": [ { - "start": 38, - "end": 44, + "start": 36, + "end": 42, "type": "MustacheTag", "expression": { "type": "Identifier", - "start": 39, - "end": 43, + "start": 37, + "end": 41, "name": "todo" } } diff --git a/test/runtime/samples/each-block-keyed/main-v2.html b/test/runtime/samples/each-block-keyed/main-v2.html new file mode 100644 index 0000000000..3be42ebc77 --- /dev/null +++ b/test/runtime/samples/each-block-keyed/main-v2.html @@ -0,0 +1,3 @@ +{#each todos as todo, i (todo.id)} +

{i+1}: {todo.description}

+{/each}