Skip to content

Commit 7576d7d

Browse files
committed
update keyed each block syntax
1 parent 9bba8d1 commit 7576d7d

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

src/parse/state/mustache.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ export default function mustache(parser: Parser) {
274274
parser.allowWhitespace();
275275
}
276276

277-
if (parser.eat('key')) {
278-
parser.requireWhitespace();
277+
if (parser.eat('(')) {
278+
parser.allowWhitespace();
279279

280280
const expression = readExpression(parser);
281281

@@ -292,6 +292,8 @@ export default function mustache(parser: Parser) {
292292

293293
block.key = expression.property.name;
294294
parser.allowWhitespace();
295+
parser.eat(')', true);
296+
parser.allowWhitespace();
295297
} else if (parser.eat('@')) {
296298
block.key = parser.readIdentifier();
297299
if (!block.key) parser.error(`Expected name`);
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
{#each todos as todo key todo.id}
1+
{#each todos as todo (todo.id)}
22
<p>{todo}</p>
33
{/each}

test/parser/samples/each-block-keyed/output-v2.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"hash": "3sm0ec",
2+
"hash": "1x6az5m",
33
"html": {
44
"start": 0,
5-
"end": 56,
5+
"end": 54,
66
"type": "Fragment",
77
"children": [
88
{
99
"start": 0,
10-
"end": 56,
10+
"end": 54,
1111
"type": "EachBlock",
1212
"expression": {
1313
"type": "Identifier",
@@ -17,20 +17,20 @@
1717
},
1818
"children": [
1919
{
20-
"start": 35,
21-
"end": 48,
20+
"start": 33,
21+
"end": 46,
2222
"type": "Element",
2323
"name": "p",
2424
"attributes": [],
2525
"children": [
2626
{
27-
"start": 38,
28-
"end": 44,
27+
"start": 36,
28+
"end": 42,
2929
"type": "MustacheTag",
3030
"expression": {
3131
"type": "Identifier",
32-
"start": 39,
33-
"end": 43,
32+
"start": 37,
33+
"end": 41,
3434
"name": "todo"
3535
}
3636
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{#each todos as todo, i (todo.id)}
2+
<p>{i+1}: {todo.description}</p>
3+
{/each}

0 commit comments

Comments
 (0)