@handlebars/parser 1.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/cjs/parser.js +52 -54
- package/dist/esm/parser.js +52 -54
- package/package.json +1 -1
- package/spec/parser.js +35 -0
- package/src/handlebars.yy +11 -16
- package/types/ast.d.ts +2 -2
package/package.json
CHANGED
package/spec/parser.js
CHANGED
|
@@ -282,6 +282,41 @@ describe('parser', function() {
|
|
|
282
282
|
);
|
|
283
283
|
});
|
|
284
284
|
|
|
285
|
+
it('parses mustaches with sub-expressions as the callable', function() {
|
|
286
|
+
equals(
|
|
287
|
+
astFor('{{(my-helper foo)}}'),
|
|
288
|
+
'{{ PATH:my-helper [PATH:foo] [] }}\n'
|
|
289
|
+
);
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it('parses mustaches with sub-expressions as the callable (with args)', function() {
|
|
293
|
+
equals(
|
|
294
|
+
astFor('{{(my-helper foo) bar}}'),
|
|
295
|
+
'{{ PATH:my-helper [PATH:foo] [PATH:bar] }}\n'
|
|
296
|
+
);
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it('parses sub-expressions with a sub-expression as the callable', function() {
|
|
300
|
+
equals(
|
|
301
|
+
astFor('{{((my-helper foo))}}'),
|
|
302
|
+
'{{ PATH:my-helper [PATH:foo] [] [] }}\n'
|
|
303
|
+
);
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
it('parses sub-expressions with a sub-expression as the callable (with args)', function() {
|
|
307
|
+
equals(
|
|
308
|
+
astFor('{{((my-helper foo) bar)}}'),
|
|
309
|
+
'{{ PATH:my-helper [PATH:foo] [PATH:bar] [] }}\n'
|
|
310
|
+
);
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
it('parses arguments with a sub-expression as the callable (with args)', function() {
|
|
314
|
+
equals(
|
|
315
|
+
astFor('{{my-helper ((foo) bar) baz=((foo bar))}}'),
|
|
316
|
+
'{{ PATH:my-helper [PATH:foo [] [PATH:bar]] HASH{baz=PATH:foo [PATH:bar] []} }}\n'
|
|
317
|
+
);
|
|
318
|
+
});
|
|
319
|
+
|
|
285
320
|
it('parses inverse block with block params', function() {
|
|
286
321
|
equals(
|
|
287
322
|
astFor('{{^foo as |bar baz|}}content{{/foo}}'),
|
package/src/handlebars.yy
CHANGED
|
@@ -43,7 +43,7 @@ rawBlock
|
|
|
43
43
|
;
|
|
44
44
|
|
|
45
45
|
openRawBlock
|
|
46
|
-
: OPEN_RAW_BLOCK helperName
|
|
46
|
+
: OPEN_RAW_BLOCK helperName expr* hash? CLOSE_RAW_BLOCK -> { path: $2, params: $3, hash: $4 }
|
|
47
47
|
;
|
|
48
48
|
|
|
49
49
|
block
|
|
@@ -52,15 +52,15 @@ block
|
|
|
52
52
|
;
|
|
53
53
|
|
|
54
54
|
openBlock
|
|
55
|
-
: OPEN_BLOCK helperName
|
|
55
|
+
: OPEN_BLOCK helperName expr* hash? blockParams? CLOSE -> { open: $1, path: $2, params: $3, hash: $4, blockParams: $5, strip: yy.stripFlags($1, $6) }
|
|
56
56
|
;
|
|
57
57
|
|
|
58
58
|
openInverse
|
|
59
|
-
: OPEN_INVERSE helperName
|
|
59
|
+
: OPEN_INVERSE helperName expr* hash? blockParams? CLOSE -> { path: $2, params: $3, hash: $4, blockParams: $5, strip: yy.stripFlags($1, $6) }
|
|
60
60
|
;
|
|
61
61
|
|
|
62
62
|
openInverseChain
|
|
63
|
-
: OPEN_INVERSE_CHAIN helperName
|
|
63
|
+
: OPEN_INVERSE_CHAIN helperName expr* hash? blockParams? CLOSE -> { path: $2, params: $3, hash: $4, blockParams: $5, strip: yy.stripFlags($1, $6) }
|
|
64
64
|
;
|
|
65
65
|
|
|
66
66
|
inverseAndProgram
|
|
@@ -85,12 +85,12 @@ closeBlock
|
|
|
85
85
|
mustache
|
|
86
86
|
// Parsing out the '&' escape token at AST level saves ~500 bytes after min due to the removal of one parser node.
|
|
87
87
|
// This also allows for handler unification as all mustache node instances can utilize the same handler
|
|
88
|
-
: OPEN
|
|
89
|
-
| OPEN_UNESCAPED
|
|
88
|
+
: OPEN expr expr* hash? CLOSE -> yy.prepareMustache($2, $3, $4, $1, yy.stripFlags($1, $5), @$)
|
|
89
|
+
| OPEN_UNESCAPED expr expr* hash? CLOSE_UNESCAPED -> yy.prepareMustache($2, $3, $4, $1, yy.stripFlags($1, $5), @$)
|
|
90
90
|
;
|
|
91
91
|
|
|
92
92
|
partial
|
|
93
|
-
: OPEN_PARTIAL
|
|
93
|
+
: OPEN_PARTIAL expr expr* hash? CLOSE {
|
|
94
94
|
$$ = {
|
|
95
95
|
type: 'PartialStatement',
|
|
96
96
|
name: $2,
|
|
@@ -106,16 +106,16 @@ partialBlock
|
|
|
106
106
|
: openPartialBlock program closeBlock -> yy.preparePartialBlock($1, $2, $3, @$)
|
|
107
107
|
;
|
|
108
108
|
openPartialBlock
|
|
109
|
-
: OPEN_PARTIAL_BLOCK
|
|
109
|
+
: OPEN_PARTIAL_BLOCK expr expr* hash? CLOSE -> { path: $2, params: $3, hash: $4, strip: yy.stripFlags($1, $5) }
|
|
110
110
|
;
|
|
111
111
|
|
|
112
|
-
|
|
112
|
+
expr
|
|
113
113
|
: helperName -> $1
|
|
114
114
|
| sexpr -> $1
|
|
115
115
|
;
|
|
116
116
|
|
|
117
117
|
sexpr
|
|
118
|
-
: OPEN_SEXPR
|
|
118
|
+
: OPEN_SEXPR expr expr* hash? CLOSE_SEXPR {
|
|
119
119
|
$$ = {
|
|
120
120
|
type: 'SubExpression',
|
|
121
121
|
path: $2,
|
|
@@ -130,7 +130,7 @@ hash
|
|
|
130
130
|
;
|
|
131
131
|
|
|
132
132
|
hashSegment
|
|
133
|
-
: ID EQUALS
|
|
133
|
+
: ID EQUALS expr -> {type: 'HashPair', key: yy.id($1), value: $3, loc: yy.locInfo(@$)}
|
|
134
134
|
;
|
|
135
135
|
|
|
136
136
|
blockParams
|
|
@@ -147,11 +147,6 @@ helperName
|
|
|
147
147
|
| NULL -> {type: 'NullLiteral', original: null, value: null, loc: yy.locInfo(@$)}
|
|
148
148
|
;
|
|
149
149
|
|
|
150
|
-
partialName
|
|
151
|
-
: helperName -> $1
|
|
152
|
-
| sexpr -> $1
|
|
153
|
-
;
|
|
154
|
-
|
|
155
150
|
dataName
|
|
156
151
|
: DATA pathSegments -> yy.preparePath(true, $2, @$)
|
|
157
152
|
;
|
package/types/ast.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export interface Statement extends Node {}
|
|
|
23
23
|
|
|
24
24
|
export interface MustacheStatement extends Statement {
|
|
25
25
|
type: 'MustacheStatement';
|
|
26
|
-
path: PathExpression | Literal;
|
|
26
|
+
path: SubExpression | PathExpression | Literal;
|
|
27
27
|
params: Expression[];
|
|
28
28
|
hash: Hash;
|
|
29
29
|
escaped: boolean;
|
|
@@ -81,7 +81,7 @@ export interface Expression extends Node {}
|
|
|
81
81
|
|
|
82
82
|
export interface SubExpression extends Expression {
|
|
83
83
|
type: 'SubExpression';
|
|
84
|
-
path: PathExpression;
|
|
84
|
+
path: SubExpression | PathExpression;
|
|
85
85
|
params: Expression[];
|
|
86
86
|
hash: Hash;
|
|
87
87
|
}
|