update keyed each block syntax

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

@ -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`);

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

@ -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"
}
}

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