update keyed each block syntax

pull/1330/head
Rich Harris 7 years ago
parent 9bba8d18d1
commit 7576d7dc93

@ -274,8 +274,8 @@ export default function mustache(parser: Parser) {
parser.allowWhitespace(); parser.allowWhitespace();
} }
if (parser.eat('key')) { if (parser.eat('(')) {
parser.requireWhitespace(); parser.allowWhitespace();
const expression = readExpression(parser); const expression = readExpression(parser);
@ -292,6 +292,8 @@ export default function mustache(parser: Parser) {
block.key = expression.property.name; block.key = expression.property.name;
parser.allowWhitespace(); parser.allowWhitespace();
parser.eat(')', true);
parser.allowWhitespace();
} else if (parser.eat('@')) { } else if (parser.eat('@')) {
block.key = parser.readIdentifier(); block.key = parser.readIdentifier();
if (!block.key) parser.error(`Expected name`); if (!block.key) parser.error(`Expected name`);

@ -1,3 +1,3 @@
{#each todos as todo key todo.id} {#each todos as todo (todo.id)}
<p>{todo}</p> <p>{todo}</p>
{/each} {/each}

@ -1,13 +1,13 @@
{ {
"hash": "3sm0ec", "hash": "1x6az5m",
"html": { "html": {
"start": 0, "start": 0,
"end": 56, "end": 54,
"type": "Fragment", "type": "Fragment",
"children": [ "children": [
{ {
"start": 0, "start": 0,
"end": 56, "end": 54,
"type": "EachBlock", "type": "EachBlock",
"expression": { "expression": {
"type": "Identifier", "type": "Identifier",
@ -17,20 +17,20 @@
}, },
"children": [ "children": [
{ {
"start": 35, "start": 33,
"end": 48, "end": 46,
"type": "Element", "type": "Element",
"name": "p", "name": "p",
"attributes": [], "attributes": [],
"children": [ "children": [
{ {
"start": 38, "start": 36,
"end": 44, "end": 42,
"type": "MustacheTag", "type": "MustacheTag",
"expression": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 39, "start": 37,
"end": 43, "end": 41,
"name": "todo" "name": "todo"
} }
} }

@ -0,0 +1,3 @@
{#each todos as todo, i (todo.id)}
<p>{i+1}: {todo.description}</p>
{/each}
Loading…
Cancel
Save