File tree 5 files changed +61
-35
lines changed
5 files changed +61
-35
lines changed Original file line number Diff line number Diff line change @@ -274,7 +274,25 @@ export default function mustache(parser: Parser) {
274
274
parser . allowWhitespace ( ) ;
275
275
}
276
276
277
- if ( parser . eat ( '@' ) ) {
277
+ if ( parser . eat ( 'key' ) ) {
278
+ parser . requireWhitespace ( ) ;
279
+
280
+ const expression = readExpression ( parser ) ;
281
+
282
+ // TODO eventually, we should accept any expression, and turn
283
+ // it into a function. For now, assume that every expression
284
+ // follows the `foo.id` pattern, and equates to `@id`
285
+ if (
286
+ expression . type !== 'MemberExpression' ||
287
+ expression . property . computed ||
288
+ expression . property . type !== 'Identifier'
289
+ ) {
290
+ parser . error ( 'invalid key' , expression . start ) ;
291
+ }
292
+
293
+ block . key = expression . property . name ;
294
+ parser . allowWhitespace ( ) ;
295
+ } else if ( parser . eat ( '@' ) ) {
278
296
block . key = parser . readIdentifier ( ) ;
279
297
if ( ! block . key ) parser . error ( `Expected name` ) ;
280
298
parser . allowWhitespace ( ) ;
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import assert from 'assert';
2
2
import fs from 'fs' ;
3
3
import { svelte , tryToLoadJson } from '../helpers.js' ;
4
4
5
- describe . only ( 'parse' , ( ) => {
5
+ describe ( 'parse' , ( ) => {
6
6
fs . readdirSync ( 'test/parser/samples' ) . forEach ( dir => {
7
7
if ( dir [ 0 ] === '.' ) return ;
8
8
Original file line number Diff line number Diff line change 7
7
"children" : [
8
8
{
9
9
"start" : 0 ,
10
- "end" : 35 ,
11
- "type" : " Text" ,
12
- "data" : " {#each todos as todo key todo.id}\n\t "
13
- },
14
- {
15
- "start" : 35 ,
16
- "end" : 48 ,
17
- "type" : " Element" ,
18
- "name" : " p" ,
19
- "attributes" : [],
10
+ "end" : 56 ,
11
+ "type" : " EachBlock" ,
12
+ "expression" : {
13
+ "type" : " Identifier" ,
14
+ "start" : 7 ,
15
+ "end" : 12 ,
16
+ "name" : " todos"
17
+ },
20
18
"children" : [
21
19
{
22
- "start" : 38 ,
23
- "end" : 44 ,
24
- "type" : " Text" ,
25
- "data" : " {todo}"
20
+ "start" : 35 ,
21
+ "end" : 48 ,
22
+ "type" : " Element" ,
23
+ "name" : " p" ,
24
+ "attributes" : [],
25
+ "children" : [
26
+ {
27
+ "start" : 38 ,
28
+ "end" : 44 ,
29
+ "type" : " MustacheTag" ,
30
+ "expression" : {
31
+ "type" : " Identifier" ,
32
+ "start" : 39 ,
33
+ "end" : 43 ,
34
+ "name" : " todo"
35
+ }
36
+ }
37
+ ]
26
38
}
27
- ]
28
- },
29
- {
30
- "start" : 48 ,
31
- "end" : 56 ,
32
- "type" : " Text" ,
33
- "data" : " \n {/each}"
39
+ ],
40
+ "context" : " todo" ,
41
+ "key" : " id"
34
42
}
35
43
]
36
44
},
Original file line number Diff line number Diff line change 1
1
{
2
- "hash" : 2025411181 ,
2
+ "hash" : " 3sm0ec " ,
3
3
"html" : {
4
4
"start" : 0 ,
5
- "end" : 54 ,
5
+ "end" : 56 ,
6
6
"type" : " Fragment" ,
7
7
"children" : [
8
8
{
9
9
"start" : 0 ,
10
- "end" : 54 ,
10
+ "end" : 56 ,
11
11
"type" : " EachBlock" ,
12
12
"expression" : {
13
13
"type" : " Identifier" ,
14
- "start" : 8 ,
15
- "end" : 13 ,
14
+ "start" : 7 ,
15
+ "end" : 12 ,
16
16
"name" : " todos"
17
17
},
18
18
"children" : [
19
19
{
20
- "start" : 29 ,
21
- "end" : 44 ,
20
+ "start" : 35 ,
21
+ "end" : 48 ,
22
22
"type" : " Element" ,
23
23
"name" : " p" ,
24
24
"attributes" : [],
25
25
"children" : [
26
26
{
27
- "start" : 32 ,
28
- "end" : 40 ,
27
+ "start" : 38 ,
28
+ "end" : 44 ,
29
29
"type" : " MustacheTag" ,
30
30
"expression" : {
31
31
"type" : " Identifier" ,
32
- "start" : 34 ,
33
- "end" : 38 ,
32
+ "start" : 39 ,
33
+ "end" : 43 ,
34
34
"name" : " todo"
35
35
}
36
36
}
Original file line number Diff line number Diff line change 1
- {{yield}}
1
+ {{yield}}
You can’t perform that action at this time.
0 commit comments