Skip to content

Commit 8340583

Browse files
committed
parse @id for keyed each blocks (#81)
1 parent 4332310 commit 8340583

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

src/parse/state/mustache.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ export default function mustache ( parser ) {
171171
if ( !block.index ) parser.error( `Expected name` );
172172
parser.allowWhitespace();
173173
}
174+
175+
if ( parser.eat( '@' ) ) {
176+
block.key = parser.read( validIdentifier );
177+
if ( !block.key ) parser.error( `Expected name` );
178+
parser.allowWhitespace();
179+
}
174180
}
175181

176182
parser.eat( '}}', true );
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{{#each todos as todo @id}}
2+
<p>{{todo}}</p>
3+
{{/each}}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"html": {
3+
"start": 0,
4+
"end": 54,
5+
"type": "Fragment",
6+
"children": [
7+
{
8+
"start": 0,
9+
"end": 54,
10+
"type": "EachBlock",
11+
"expression": {
12+
"start": 8,
13+
"end": 13,
14+
"type": "Identifier",
15+
"name": "todos"
16+
},
17+
"context": "todo",
18+
"key": "id",
19+
"children": [
20+
{
21+
"start": 29,
22+
"end": 44,
23+
"type": "Element",
24+
"name": "p",
25+
"attributes": [],
26+
"children": [
27+
{
28+
"start": 32,
29+
"end": 40,
30+
"type": "MustacheTag",
31+
"expression": {
32+
"start": 34,
33+
"end": 38,
34+
"type": "Identifier",
35+
"name": "todo"
36+
}
37+
}
38+
]
39+
}
40+
]
41+
}
42+
]
43+
},
44+
"css": null,
45+
"js": null
46+
}

0 commit comments

Comments
 (0)