jexl-lezer 0.4.0 → 0.5.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/README.md +14 -1
- package/dist/index.cjs +25 -294
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +24 -293
- package/package.json +17 -7
- package/rollup.config.js +4 -4
- package/src/highlight.js +62 -192
- package/src/{jexl.grammar → javascript.grammar} +735 -745
- package/src/parser.js +21 -21
- package/src/parser.terms.js +166 -165
- package/test/decorator.txt +64 -0
- package/test/expression.txt +686 -0
- package/test/jsx.txt +79 -0
- package/test/semicolon.txt +77 -0
- package/test/statement.txt +404 -0
- package/test/test-javascript.js +17 -0
- package/test/typescript.txt +401 -0
|
@@ -0,0 +1,686 @@
|
|
|
1
|
+
# Minimal
|
|
2
|
+
|
|
3
|
+
0
|
|
4
|
+
|
|
5
|
+
==>
|
|
6
|
+
|
|
7
|
+
Script(ExpressionStatement(Number))
|
|
8
|
+
|
|
9
|
+
# Strings
|
|
10
|
+
|
|
11
|
+
"A string with \"double\" and 'single' quotes";
|
|
12
|
+
'A string with "double" and \'single\' quotes';
|
|
13
|
+
'\\';
|
|
14
|
+
"\\";
|
|
15
|
+
|
|
16
|
+
'A string with new \
|
|
17
|
+
line';
|
|
18
|
+
|
|
19
|
+
==>
|
|
20
|
+
|
|
21
|
+
Script(ExpressionStatement(String(Escape,Escape)),
|
|
22
|
+
ExpressionStatement(String(Escape,Escape)),
|
|
23
|
+
ExpressionStatement(String(Escape)),
|
|
24
|
+
ExpressionStatement(String(Escape)),
|
|
25
|
+
ExpressionStatement(String(Escape)))
|
|
26
|
+
|
|
27
|
+
# Numbers
|
|
28
|
+
|
|
29
|
+
101;
|
|
30
|
+
3.14;
|
|
31
|
+
3.14e+1;
|
|
32
|
+
0x1ABCDEFabcdef;
|
|
33
|
+
0o7632157312;
|
|
34
|
+
0b1010101001;
|
|
35
|
+
1e+3;
|
|
36
|
+
|
|
37
|
+
==>
|
|
38
|
+
|
|
39
|
+
Script(
|
|
40
|
+
ExpressionStatement(Number),
|
|
41
|
+
ExpressionStatement(Number),
|
|
42
|
+
ExpressionStatement(Number),
|
|
43
|
+
ExpressionStatement(Number),
|
|
44
|
+
ExpressionStatement(Number),
|
|
45
|
+
ExpressionStatement(Number),
|
|
46
|
+
ExpressionStatement(Number))
|
|
47
|
+
|
|
48
|
+
# Identifiers
|
|
49
|
+
|
|
50
|
+
theVar;
|
|
51
|
+
theVar2;
|
|
52
|
+
$_;
|
|
53
|
+
é象𫝄;
|
|
54
|
+
últimaVez;
|
|
55
|
+
県;
|
|
56
|
+
|
|
57
|
+
==>
|
|
58
|
+
|
|
59
|
+
Script(
|
|
60
|
+
ExpressionStatement(VariableName),
|
|
61
|
+
ExpressionStatement(VariableName),
|
|
62
|
+
ExpressionStatement(VariableName),
|
|
63
|
+
ExpressionStatement(VariableName),
|
|
64
|
+
ExpressionStatement(VariableName),
|
|
65
|
+
ExpressionStatement(VariableName))
|
|
66
|
+
|
|
67
|
+
# RegExps
|
|
68
|
+
|
|
69
|
+
/one\\/;
|
|
70
|
+
/one/g;
|
|
71
|
+
/one/i;
|
|
72
|
+
/one/gim;
|
|
73
|
+
/on\/e/gim;
|
|
74
|
+
/on[^/]afe/gim;
|
|
75
|
+
/[\]/]/;
|
|
76
|
+
|
|
77
|
+
==>
|
|
78
|
+
|
|
79
|
+
Script(
|
|
80
|
+
ExpressionStatement(RegExp),
|
|
81
|
+
ExpressionStatement(RegExp),
|
|
82
|
+
ExpressionStatement(RegExp),
|
|
83
|
+
ExpressionStatement(RegExp),
|
|
84
|
+
ExpressionStatement(RegExp),
|
|
85
|
+
ExpressionStatement(RegExp),
|
|
86
|
+
ExpressionStatement(RegExp))
|
|
87
|
+
|
|
88
|
+
# Arrays
|
|
89
|
+
|
|
90
|
+
[];
|
|
91
|
+
[ "item1" ];
|
|
92
|
+
[ "item1", ];
|
|
93
|
+
[ "item1", item2 ];
|
|
94
|
+
[ , item2 ];
|
|
95
|
+
[ item2 = 5 ];
|
|
96
|
+
[ a, ...b, c ];
|
|
97
|
+
|
|
98
|
+
==>
|
|
99
|
+
|
|
100
|
+
Script(
|
|
101
|
+
ExpressionStatement(ArrayExpression),
|
|
102
|
+
ExpressionStatement(ArrayExpression(String)),
|
|
103
|
+
ExpressionStatement(ArrayExpression(String)),
|
|
104
|
+
ExpressionStatement(ArrayExpression(String,VariableName)),
|
|
105
|
+
ExpressionStatement(ArrayExpression(VariableName)),
|
|
106
|
+
ExpressionStatement(ArrayExpression(AssignmentExpression(VariableName,Equals,Number))),
|
|
107
|
+
ExpressionStatement(ArrayExpression(VariableName, Spread, VariableName, VariableName)))
|
|
108
|
+
|
|
109
|
+
# Functions
|
|
110
|
+
|
|
111
|
+
[
|
|
112
|
+
function() {},
|
|
113
|
+
function(arg1, ...arg2) {
|
|
114
|
+
arg2;
|
|
115
|
+
},
|
|
116
|
+
function stuff() {},
|
|
117
|
+
function trailing(a,) {},
|
|
118
|
+
function trailing(a,b,) {}
|
|
119
|
+
]
|
|
120
|
+
|
|
121
|
+
==>
|
|
122
|
+
|
|
123
|
+
Script(ExpressionStatement(ArrayExpression(
|
|
124
|
+
FunctionExpression(function,ParamList,Block),
|
|
125
|
+
FunctionExpression(function,ParamList(VariableDefinition,Spread,VariableDefinition), Block(ExpressionStatement(VariableName))),
|
|
126
|
+
FunctionExpression(function,VariableDefinition,ParamList,Block),
|
|
127
|
+
FunctionExpression(function,VariableDefinition,ParamList(VariableDefinition), Block),
|
|
128
|
+
FunctionExpression(function,VariableDefinition,ParamList(VariableDefinition,VariableDefinition),Block))))
|
|
129
|
+
|
|
130
|
+
# Arrow functions
|
|
131
|
+
|
|
132
|
+
a => 1;
|
|
133
|
+
() => 2;
|
|
134
|
+
(d, e) => 3;
|
|
135
|
+
(f, g,) => {
|
|
136
|
+
return h;
|
|
137
|
+
};
|
|
138
|
+
async () => 4;
|
|
139
|
+
|
|
140
|
+
==>
|
|
141
|
+
|
|
142
|
+
Script(
|
|
143
|
+
ExpressionStatement(ArrowFunction(ParamList(VariableDefinition),Arrow,Number)),
|
|
144
|
+
ExpressionStatement(ArrowFunction(ParamList,Arrow,Number)),
|
|
145
|
+
ExpressionStatement(ArrowFunction(ParamList(VariableDefinition,VariableDefinition),Arrow,Number)),
|
|
146
|
+
ExpressionStatement(ArrowFunction(ParamList(VariableDefinition,VariableDefinition),Arrow,Block(ReturnStatement(return,VariableName)))),
|
|
147
|
+
ExpressionStatement(ArrowFunction(async,ParamList,Arrow,Number)))
|
|
148
|
+
|
|
149
|
+
# Arrow function followed by comma
|
|
150
|
+
|
|
151
|
+
({
|
|
152
|
+
a: () => 1,
|
|
153
|
+
b: "x"
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
==>
|
|
157
|
+
|
|
158
|
+
Script(ExpressionStatement(ParenthesizedExpression(ObjectExpression(
|
|
159
|
+
Property(PropertyDefinition,ArrowFunction(ParamList,Arrow,Number)),
|
|
160
|
+
Property(PropertyDefinition,String)))))
|
|
161
|
+
|
|
162
|
+
# Long potential arrow function
|
|
163
|
+
|
|
164
|
+
(assign = [to, from], from = assign[0], to = assign[1]);
|
|
165
|
+
|
|
166
|
+
==>
|
|
167
|
+
|
|
168
|
+
Script(ExpressionStatement(ParenthesizedExpression(SequenceExpression(
|
|
169
|
+
AssignmentExpression(VariableName,Equals,ArrayExpression(VariableName,VariableName)),
|
|
170
|
+
AssignmentExpression(VariableName,Equals,MemberExpression(VariableName,Number)),
|
|
171
|
+
AssignmentExpression(VariableName,Equals,MemberExpression(VariableName,Number))))))
|
|
172
|
+
|
|
173
|
+
# Ternary operator
|
|
174
|
+
|
|
175
|
+
condition ? case1 : case2;
|
|
176
|
+
|
|
177
|
+
x.y = some.condition ? 2**x : 1 - 2;
|
|
178
|
+
|
|
179
|
+
==>
|
|
180
|
+
|
|
181
|
+
Script(
|
|
182
|
+
ExpressionStatement(ConditionalExpression(VariableName,LogicOp,VariableName,LogicOp,VariableName)),
|
|
183
|
+
ExpressionStatement(AssignmentExpression(
|
|
184
|
+
MemberExpression(VariableName,PropertyName),Equals,
|
|
185
|
+
ConditionalExpression(
|
|
186
|
+
MemberExpression(VariableName,PropertyName),LogicOp,
|
|
187
|
+
BinaryExpression(Number,ArithOp,VariableName),LogicOp,
|
|
188
|
+
BinaryExpression(Number,ArithOp,Number)))))
|
|
189
|
+
|
|
190
|
+
# Type operators
|
|
191
|
+
|
|
192
|
+
typeof x;
|
|
193
|
+
x instanceof String;
|
|
194
|
+
|
|
195
|
+
==>
|
|
196
|
+
|
|
197
|
+
Script(ExpressionStatement(UnaryExpression(typeof,VariableName)),
|
|
198
|
+
ExpressionStatement(BinaryExpression(VariableName,instanceof,VariableName)))
|
|
199
|
+
|
|
200
|
+
# Delete
|
|
201
|
+
|
|
202
|
+
delete thing['prop'];
|
|
203
|
+
true ? delete thing.prop : null;
|
|
204
|
+
|
|
205
|
+
==>
|
|
206
|
+
|
|
207
|
+
Script(
|
|
208
|
+
ExpressionStatement(UnaryExpression(delete,MemberExpression(VariableName,String))),
|
|
209
|
+
ExpressionStatement(ConditionalExpression(BooleanLiteral,LogicOp,
|
|
210
|
+
UnaryExpression(delete,MemberExpression(VariableName,PropertyName)),LogicOp,null)))
|
|
211
|
+
|
|
212
|
+
# Void
|
|
213
|
+
|
|
214
|
+
a = void b();
|
|
215
|
+
|
|
216
|
+
==>
|
|
217
|
+
|
|
218
|
+
Script(ExpressionStatement(AssignmentExpression(VariableName,Equals,UnaryExpression(void,CallExpression(VariableName,ArgList)))))
|
|
219
|
+
|
|
220
|
+
# Augmented assignment
|
|
221
|
+
|
|
222
|
+
s |= 1;
|
|
223
|
+
t %= 2;
|
|
224
|
+
w ^= 3;
|
|
225
|
+
x += 4;
|
|
226
|
+
y.z *= 5;
|
|
227
|
+
z += 1;
|
|
228
|
+
a >>= 1;
|
|
229
|
+
b >>>= 1;
|
|
230
|
+
c <<= 1;
|
|
231
|
+
|
|
232
|
+
==>
|
|
233
|
+
|
|
234
|
+
Script(
|
|
235
|
+
ExpressionStatement(AssignmentExpression(VariableName,UpdateOp,Number)),
|
|
236
|
+
ExpressionStatement(AssignmentExpression(VariableName,UpdateOp,Number)),
|
|
237
|
+
ExpressionStatement(AssignmentExpression(VariableName,UpdateOp,Number)),
|
|
238
|
+
ExpressionStatement(AssignmentExpression(VariableName,UpdateOp,Number)),
|
|
239
|
+
ExpressionStatement(AssignmentExpression(MemberExpression(VariableName,PropertyName),UpdateOp,Number)),
|
|
240
|
+
ExpressionStatement(AssignmentExpression(VariableName,UpdateOp,Number)),
|
|
241
|
+
ExpressionStatement(AssignmentExpression(VariableName,UpdateOp,Number)),
|
|
242
|
+
ExpressionStatement(AssignmentExpression(VariableName,UpdateOp,Number)),
|
|
243
|
+
ExpressionStatement(AssignmentExpression(VariableName,UpdateOp,Number)))
|
|
244
|
+
|
|
245
|
+
# Operator precedence
|
|
246
|
+
|
|
247
|
+
a <= b && c >= d;
|
|
248
|
+
a.b = c ? d : e;
|
|
249
|
+
a && b(c) && d;
|
|
250
|
+
a && new b(c) && d;
|
|
251
|
+
typeof a == b && c instanceof d;
|
|
252
|
+
|
|
253
|
+
==>
|
|
254
|
+
|
|
255
|
+
Script(
|
|
256
|
+
ExpressionStatement(BinaryExpression(BinaryExpression(VariableName,CompareOp,VariableName),LogicOp,
|
|
257
|
+
BinaryExpression(VariableName,CompareOp,VariableName))),
|
|
258
|
+
ExpressionStatement(AssignmentExpression(MemberExpression(VariableName,PropertyName),Equals,
|
|
259
|
+
ConditionalExpression(VariableName,LogicOp,VariableName,LogicOp,VariableName))),
|
|
260
|
+
ExpressionStatement(BinaryExpression(BinaryExpression(VariableName,LogicOp,CallExpression(VariableName,ArgList(VariableName))),LogicOp,
|
|
261
|
+
VariableName)),
|
|
262
|
+
ExpressionStatement(BinaryExpression(BinaryExpression(VariableName,LogicOp,NewExpression(new,VariableName,ArgList(VariableName))),LogicOp,
|
|
263
|
+
VariableName)),
|
|
264
|
+
ExpressionStatement(BinaryExpression(BinaryExpression(UnaryExpression(typeof,VariableName),CompareOp,VariableName),LogicOp,
|
|
265
|
+
BinaryExpression(VariableName,instanceof,VariableName))))
|
|
266
|
+
|
|
267
|
+
# Rest args
|
|
268
|
+
|
|
269
|
+
foo(...rest);
|
|
270
|
+
|
|
271
|
+
==>
|
|
272
|
+
|
|
273
|
+
Script(ExpressionStatement(CallExpression(VariableName,ArgList(Spread,VariableName))))
|
|
274
|
+
|
|
275
|
+
# Forward slashes after parenthesized expressions
|
|
276
|
+
|
|
277
|
+
(foo - bar) / baz;
|
|
278
|
+
if (foo - bar) /baz/;
|
|
279
|
+
(this.a() / this.b() - 1) / 2;
|
|
280
|
+
|
|
281
|
+
==>
|
|
282
|
+
|
|
283
|
+
Script(
|
|
284
|
+
ExpressionStatement(BinaryExpression(ParenthesizedExpression(BinaryExpression(VariableName,ArithOp,VariableName)),ArithOp,VariableName)),
|
|
285
|
+
IfStatement(if,ParenthesizedExpression(BinaryExpression(VariableName,ArithOp,VariableName)),
|
|
286
|
+
ExpressionStatement(RegExp)),
|
|
287
|
+
ExpressionStatement(BinaryExpression(ParenthesizedExpression(
|
|
288
|
+
BinaryExpression(
|
|
289
|
+
BinaryExpression(
|
|
290
|
+
CallExpression(MemberExpression(this,PropertyName),ArgList),ArithOp,
|
|
291
|
+
CallExpression(MemberExpression(this,PropertyName),ArgList)),ArithOp,Number)),ArithOp,Number)))
|
|
292
|
+
|
|
293
|
+
# Yield expressions
|
|
294
|
+
|
|
295
|
+
yield db.users.where('[endpoint+email]');
|
|
296
|
+
yield* a;
|
|
297
|
+
yield [22];
|
|
298
|
+
|
|
299
|
+
==>
|
|
300
|
+
|
|
301
|
+
Script(
|
|
302
|
+
ExpressionStatement(YieldExpression(yield,
|
|
303
|
+
CallExpression(MemberExpression(MemberExpression(VariableName,PropertyName),PropertyName),ArgList(String)))),
|
|
304
|
+
ExpressionStatement(YieldExpression(yield,Star,VariableName)),
|
|
305
|
+
ExpressionStatement(YieldExpression(yield,ArrayExpression(Number))))
|
|
306
|
+
|
|
307
|
+
# Template strings
|
|
308
|
+
|
|
309
|
+
`one line`;
|
|
310
|
+
`multi
|
|
311
|
+
line`;
|
|
312
|
+
|
|
313
|
+
`multi
|
|
314
|
+
${2 + 2}
|
|
315
|
+
hello
|
|
316
|
+
${1, 2}
|
|
317
|
+
line`;
|
|
318
|
+
|
|
319
|
+
`$$$$`;
|
|
320
|
+
`$`;
|
|
321
|
+
`$$$$${ async }`;
|
|
322
|
+
|
|
323
|
+
`\\\``;
|
|
324
|
+
|
|
325
|
+
`one${`two${`three`}`}`;
|
|
326
|
+
|
|
327
|
+
f`hi${there}`;
|
|
328
|
+
|
|
329
|
+
==>
|
|
330
|
+
|
|
331
|
+
Script(
|
|
332
|
+
ExpressionStatement(TemplateString),
|
|
333
|
+
ExpressionStatement(TemplateString),
|
|
334
|
+
ExpressionStatement(TemplateString(
|
|
335
|
+
Interpolation(InterpolationStart,BinaryExpression(Number,ArithOp,Number),InterpolationEnd),
|
|
336
|
+
Interpolation(InterpolationStart,SequenceExpression(Number,Number),InterpolationEnd))),
|
|
337
|
+
ExpressionStatement(TemplateString),
|
|
338
|
+
ExpressionStatement(TemplateString),
|
|
339
|
+
ExpressionStatement(TemplateString(Interpolation(InterpolationStart,VariableName,InterpolationEnd))),
|
|
340
|
+
ExpressionStatement(TemplateString(Escape,Escape)),
|
|
341
|
+
ExpressionStatement(TemplateString(Interpolation(InterpolationStart,TemplateString(
|
|
342
|
+
Interpolation(InterpolationStart,TemplateString,InterpolationEnd)),InterpolationEnd))),
|
|
343
|
+
ExpressionStatement(TaggedTemplateExpression(VariableName,TemplateString(
|
|
344
|
+
Interpolation(InterpolationStart,VariableName,InterpolationEnd)))))
|
|
345
|
+
|
|
346
|
+
# Atoms
|
|
347
|
+
|
|
348
|
+
this;
|
|
349
|
+
null;
|
|
350
|
+
undefined;
|
|
351
|
+
true;
|
|
352
|
+
false;
|
|
353
|
+
|
|
354
|
+
==>
|
|
355
|
+
|
|
356
|
+
Script(
|
|
357
|
+
ExpressionStatement(this),
|
|
358
|
+
ExpressionStatement(null),
|
|
359
|
+
ExpressionStatement(VariableName),
|
|
360
|
+
ExpressionStatement(BooleanLiteral),
|
|
361
|
+
ExpressionStatement(BooleanLiteral))
|
|
362
|
+
|
|
363
|
+
# Objects
|
|
364
|
+
|
|
365
|
+
foo({},
|
|
366
|
+
{ a: "b" },
|
|
367
|
+
{ c: "d", "e": f, 1: 2 },
|
|
368
|
+
{
|
|
369
|
+
g,
|
|
370
|
+
[methodName]() {}
|
|
371
|
+
},
|
|
372
|
+
{b, get},
|
|
373
|
+
{a,});
|
|
374
|
+
|
|
375
|
+
==>
|
|
376
|
+
|
|
377
|
+
Script(ExpressionStatement(CallExpression(VariableName,ArgList(
|
|
378
|
+
ObjectExpression,
|
|
379
|
+
ObjectExpression(Property(PropertyDefinition,String)),
|
|
380
|
+
ObjectExpression(Property(PropertyDefinition,String),Property(String,VariableName),Property(Number,Number)),
|
|
381
|
+
ObjectExpression(Property(PropertyDefinition),Property(VariableName,ParamList,Block)),
|
|
382
|
+
ObjectExpression(Property(PropertyDefinition),Property(PropertyDefinition)),
|
|
383
|
+
ObjectExpression(Property(PropertyDefinition))))))
|
|
384
|
+
|
|
385
|
+
# Method definitions
|
|
386
|
+
|
|
387
|
+
({
|
|
388
|
+
foo: true,
|
|
389
|
+
|
|
390
|
+
add(a, b) {
|
|
391
|
+
return a + b;
|
|
392
|
+
},
|
|
393
|
+
|
|
394
|
+
get bar() { return c; },
|
|
395
|
+
|
|
396
|
+
set bar(a) { c = a; },
|
|
397
|
+
|
|
398
|
+
*barGenerator() { yield c; },
|
|
399
|
+
|
|
400
|
+
get() { return 1; }
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
==>
|
|
404
|
+
|
|
405
|
+
Script(ExpressionStatement(ParenthesizedExpression(ObjectExpression(
|
|
406
|
+
Property(PropertyDefinition,BooleanLiteral),
|
|
407
|
+
Property(PropertyDefinition,ParamList(VariableDefinition,VariableDefinition),
|
|
408
|
+
Block(ReturnStatement(return,BinaryExpression(VariableName,ArithOp,VariableName)))),
|
|
409
|
+
Property(get,PropertyDefinition,ParamList,Block(ReturnStatement(return,VariableName))),
|
|
410
|
+
Property(set,PropertyDefinition,ParamList(VariableDefinition),
|
|
411
|
+
Block(ExpressionStatement(AssignmentExpression(VariableName,Equals,VariableName)))),
|
|
412
|
+
Property(Star,PropertyDefinition,ParamList,Block(ExpressionStatement(YieldExpression(yield,VariableName)))),
|
|
413
|
+
Property(PropertyDefinition,ParamList,Block(ReturnStatement(return,Number)))))))
|
|
414
|
+
|
|
415
|
+
# Keyword property names
|
|
416
|
+
|
|
417
|
+
({
|
|
418
|
+
finally() {},
|
|
419
|
+
catch() {},
|
|
420
|
+
get: function () {},
|
|
421
|
+
set() {},
|
|
422
|
+
static: true,
|
|
423
|
+
async: true,
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
==>
|
|
427
|
+
|
|
428
|
+
Script(ExpressionStatement(ParenthesizedExpression(ObjectExpression(
|
|
429
|
+
Property(PropertyDefinition,ParamList,Block),
|
|
430
|
+
Property(PropertyDefinition,ParamList,Block),
|
|
431
|
+
Property(PropertyDefinition,FunctionExpression(function,ParamList,Block)),
|
|
432
|
+
Property(PropertyDefinition,ParamList,Block),
|
|
433
|
+
Property(PropertyDefinition,BooleanLiteral),
|
|
434
|
+
Property(PropertyDefinition,BooleanLiteral)))))
|
|
435
|
+
|
|
436
|
+
# Generator functions
|
|
437
|
+
|
|
438
|
+
[
|
|
439
|
+
function *() {},
|
|
440
|
+
function *generateStuff(arg1, arg2) {
|
|
441
|
+
yield;
|
|
442
|
+
yield arg2;
|
|
443
|
+
}
|
|
444
|
+
];
|
|
445
|
+
|
|
446
|
+
==>
|
|
447
|
+
|
|
448
|
+
Script(ExpressionStatement(ArrayExpression(
|
|
449
|
+
FunctionExpression(function,Star,ParamList,Block),
|
|
450
|
+
FunctionExpression(function,Star,VariableDefinition,ParamList(VariableDefinition,VariableDefinition),Block(
|
|
451
|
+
ExpressionStatement(VariableName),
|
|
452
|
+
ExpressionStatement(YieldExpression(yield,VariableName)))))))
|
|
453
|
+
|
|
454
|
+
# Member expressions
|
|
455
|
+
|
|
456
|
+
x.someProperty;
|
|
457
|
+
x?.other;
|
|
458
|
+
x[someVariable];
|
|
459
|
+
f()["some-string"];
|
|
460
|
+
return returned.promise().done(a).fail(b);
|
|
461
|
+
|
|
462
|
+
==>
|
|
463
|
+
|
|
464
|
+
Script(
|
|
465
|
+
ExpressionStatement(MemberExpression(VariableName,PropertyName)),
|
|
466
|
+
ExpressionStatement(MemberExpression(VariableName,PropertyName)),
|
|
467
|
+
ExpressionStatement(MemberExpression(VariableName,VariableName)),
|
|
468
|
+
ExpressionStatement(MemberExpression(CallExpression(VariableName,ArgList),String)),
|
|
469
|
+
ReturnStatement(return,CallExpression(MemberExpression(CallExpression(MemberExpression(CallExpression(
|
|
470
|
+
MemberExpression(VariableName,PropertyName),ArgList),PropertyName),ArgList(VariableName)),PropertyName),ArgList(VariableName))))
|
|
471
|
+
|
|
472
|
+
# Callback chain
|
|
473
|
+
|
|
474
|
+
return this.map(function (a) {
|
|
475
|
+
return a.b;
|
|
476
|
+
})
|
|
477
|
+
|
|
478
|
+
// a comment
|
|
479
|
+
|
|
480
|
+
.filter(function (c) {
|
|
481
|
+
return 2;
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
==>
|
|
485
|
+
|
|
486
|
+
Script(ReturnStatement(return,CallExpression(MemberExpression(CallExpression(MemberExpression(this,PropertyName),
|
|
487
|
+
ArgList(FunctionExpression(function,ParamList(VariableDefinition),Block(ReturnStatement(return,MemberExpression(VariableName,PropertyName)))))),
|
|
488
|
+
LineComment,PropertyName),ArgList(FunctionExpression(function,ParamList(VariableDefinition),Block(ReturnStatement(return,Number)))))))
|
|
489
|
+
|
|
490
|
+
# Function calls
|
|
491
|
+
|
|
492
|
+
x.someMethod(arg1, "arg2");
|
|
493
|
+
(function(x, y) {
|
|
494
|
+
|
|
495
|
+
}(a, b));
|
|
496
|
+
f(new foo.bar(1), 2);
|
|
497
|
+
|
|
498
|
+
==>
|
|
499
|
+
|
|
500
|
+
Script(
|
|
501
|
+
ExpressionStatement(CallExpression(MemberExpression(VariableName,PropertyName),ArgList(VariableName,String))),
|
|
502
|
+
ExpressionStatement(ParenthesizedExpression(CallExpression(FunctionExpression(function,ParamList(VariableDefinition,VariableDefinition),Block),
|
|
503
|
+
ArgList(VariableName,VariableName)))),
|
|
504
|
+
ExpressionStatement(CallExpression(VariableName,ArgList(NewExpression(new,MemberExpression(VariableName,PropertyName),ArgList(Number)),Number))))
|
|
505
|
+
|
|
506
|
+
# Constructor calls
|
|
507
|
+
|
|
508
|
+
new foo(1);
|
|
509
|
+
new module.Klass(1, "two");
|
|
510
|
+
new Thing;
|
|
511
|
+
|
|
512
|
+
==>
|
|
513
|
+
|
|
514
|
+
Script(
|
|
515
|
+
ExpressionStatement(NewExpression(new,VariableName,ArgList(Number))),
|
|
516
|
+
ExpressionStatement(NewExpression(new,MemberExpression(VariableName,PropertyName),ArgList(Number,String))),
|
|
517
|
+
ExpressionStatement(NewExpression(new,VariableName)))
|
|
518
|
+
|
|
519
|
+
# Await Expressions
|
|
520
|
+
|
|
521
|
+
await asyncFunction();
|
|
522
|
+
await asyncPromise;
|
|
523
|
+
|
|
524
|
+
==>
|
|
525
|
+
|
|
526
|
+
Script(
|
|
527
|
+
ExpressionStatement(AwaitExpression(await,CallExpression(VariableName,ArgList))),
|
|
528
|
+
ExpressionStatement(AwaitExpression(await,VariableName)))
|
|
529
|
+
|
|
530
|
+
# Numeric operators
|
|
531
|
+
|
|
532
|
+
i++;
|
|
533
|
+
i--;
|
|
534
|
+
i + j * 3 - j % 5;
|
|
535
|
+
2 ** i * 3;
|
|
536
|
+
2 * i ** 3;
|
|
537
|
+
+x;
|
|
538
|
+
-x;
|
|
539
|
+
|
|
540
|
+
==>
|
|
541
|
+
|
|
542
|
+
Script(
|
|
543
|
+
ExpressionStatement(PostfixExpression(VariableName,ArithOp)),
|
|
544
|
+
ExpressionStatement(PostfixExpression(VariableName,ArithOp)),
|
|
545
|
+
ExpressionStatement(BinaryExpression(BinaryExpression(VariableName,ArithOp,BinaryExpression(VariableName,ArithOp,Number)),ArithOp,BinaryExpression(VariableName,ArithOp,Number))),
|
|
546
|
+
ExpressionStatement(BinaryExpression(BinaryExpression(Number,ArithOp,VariableName),ArithOp,Number)),
|
|
547
|
+
ExpressionStatement(BinaryExpression(Number,ArithOp,BinaryExpression(VariableName,ArithOp,Number))),
|
|
548
|
+
ExpressionStatement(UnaryExpression(ArithOp,VariableName)),
|
|
549
|
+
ExpressionStatement(UnaryExpression(ArithOp,VariableName)))
|
|
550
|
+
|
|
551
|
+
# Boolean operators
|
|
552
|
+
|
|
553
|
+
i || j;
|
|
554
|
+
i && j;
|
|
555
|
+
i ?? j;
|
|
556
|
+
!a && !b || !c && !d;
|
|
557
|
+
|
|
558
|
+
==>
|
|
559
|
+
|
|
560
|
+
Script(
|
|
561
|
+
ExpressionStatement(BinaryExpression(VariableName,LogicOp,VariableName)),
|
|
562
|
+
ExpressionStatement(BinaryExpression(VariableName,LogicOp,VariableName)),
|
|
563
|
+
ExpressionStatement(BinaryExpression(VariableName,LogicOp,VariableName)),
|
|
564
|
+
ExpressionStatement(BinaryExpression(BinaryExpression(UnaryExpression(LogicOp,VariableName),LogicOp,
|
|
565
|
+
UnaryExpression(LogicOp,VariableName)),LogicOp,BinaryExpression(UnaryExpression(LogicOp,VariableName),LogicOp,
|
|
566
|
+
UnaryExpression(LogicOp,VariableName)))))
|
|
567
|
+
|
|
568
|
+
# Bitwise operators
|
|
569
|
+
|
|
570
|
+
i >> j;
|
|
571
|
+
i >>> j;
|
|
572
|
+
i << j;
|
|
573
|
+
i & j;
|
|
574
|
+
i | j;
|
|
575
|
+
~i ^ ~j;
|
|
576
|
+
|
|
577
|
+
==>
|
|
578
|
+
|
|
579
|
+
Script(
|
|
580
|
+
ExpressionStatement(BinaryExpression(VariableName,BitOp,VariableName)),
|
|
581
|
+
ExpressionStatement(BinaryExpression(VariableName,BitOp,VariableName)),
|
|
582
|
+
ExpressionStatement(BinaryExpression(VariableName,BitOp,VariableName)),
|
|
583
|
+
ExpressionStatement(BinaryExpression(VariableName,BitOp,VariableName)),
|
|
584
|
+
ExpressionStatement(BinaryExpression(VariableName,BitOp,VariableName)),
|
|
585
|
+
ExpressionStatement(BinaryExpression(UnaryExpression(BitOp,VariableName),BitOp,UnaryExpression(BitOp,VariableName))))
|
|
586
|
+
|
|
587
|
+
# Relational operators
|
|
588
|
+
|
|
589
|
+
x < y;
|
|
590
|
+
x <= y;
|
|
591
|
+
x == y;
|
|
592
|
+
x === y;
|
|
593
|
+
x != y;
|
|
594
|
+
x !== y;
|
|
595
|
+
x > y;
|
|
596
|
+
x >= y;
|
|
597
|
+
|
|
598
|
+
==>
|
|
599
|
+
|
|
600
|
+
Script(
|
|
601
|
+
ExpressionStatement(BinaryExpression(VariableName,CompareOp,VariableName)),
|
|
602
|
+
ExpressionStatement(BinaryExpression(VariableName,CompareOp,VariableName)),
|
|
603
|
+
ExpressionStatement(BinaryExpression(VariableName,CompareOp,VariableName)),
|
|
604
|
+
ExpressionStatement(BinaryExpression(VariableName,CompareOp,VariableName)),
|
|
605
|
+
ExpressionStatement(BinaryExpression(VariableName,CompareOp,VariableName)),
|
|
606
|
+
ExpressionStatement(BinaryExpression(VariableName,CompareOp,VariableName)),
|
|
607
|
+
ExpressionStatement(BinaryExpression(VariableName,CompareOp,VariableName)),
|
|
608
|
+
ExpressionStatement(BinaryExpression(VariableName,CompareOp,VariableName)))
|
|
609
|
+
|
|
610
|
+
# Word operators
|
|
611
|
+
|
|
612
|
+
x in y;
|
|
613
|
+
x instanceof y;
|
|
614
|
+
!x instanceof y;
|
|
615
|
+
|
|
616
|
+
==>
|
|
617
|
+
|
|
618
|
+
Script(
|
|
619
|
+
ExpressionStatement(BinaryExpression(VariableName,in,VariableName)),
|
|
620
|
+
ExpressionStatement(BinaryExpression(VariableName,instanceof,VariableName)),
|
|
621
|
+
ExpressionStatement(BinaryExpression(UnaryExpression(LogicOp,VariableName),instanceof,VariableName)))
|
|
622
|
+
|
|
623
|
+
# Assignments
|
|
624
|
+
|
|
625
|
+
x = 0;
|
|
626
|
+
x.y = 0;
|
|
627
|
+
x["y"] = 0;
|
|
628
|
+
async = 0;
|
|
629
|
+
[a, b = 2] = foo;
|
|
630
|
+
({a, b, ...d} = c);
|
|
631
|
+
|
|
632
|
+
==>
|
|
633
|
+
|
|
634
|
+
Script(
|
|
635
|
+
ExpressionStatement(AssignmentExpression(VariableName,Equals,Number)),
|
|
636
|
+
ExpressionStatement(AssignmentExpression(MemberExpression(VariableName,PropertyName),Equals,Number)),
|
|
637
|
+
ExpressionStatement(AssignmentExpression(MemberExpression(VariableName,String),Equals,Number)),
|
|
638
|
+
ExpressionStatement(AssignmentExpression(VariableName,Equals,Number)),
|
|
639
|
+
ExpressionStatement(AssignmentExpression(ArrayPattern(VariableDefinition,VariableDefinition,Equals,Number),Equals,VariableName)),
|
|
640
|
+
ExpressionStatement(ParenthesizedExpression(AssignmentExpression(ObjectPattern(
|
|
641
|
+
PatternProperty(PropertyName),PatternProperty(PropertyName),PatternProperty(Spread,VariableDefinition)),Equals,VariableName))))
|
|
642
|
+
|
|
643
|
+
# Comma operator
|
|
644
|
+
|
|
645
|
+
a = 1, b = 2;
|
|
646
|
+
c = {d: (3, 4 + 5)};
|
|
647
|
+
|
|
648
|
+
==>
|
|
649
|
+
|
|
650
|
+
Script(
|
|
651
|
+
ExpressionStatement(SequenceExpression(AssignmentExpression(VariableName,Equals,Number),AssignmentExpression(VariableName,Equals,Number))),
|
|
652
|
+
ExpressionStatement(AssignmentExpression(VariableName,Equals,ObjectExpression(
|
|
653
|
+
Property(PropertyDefinition,ParenthesizedExpression(SequenceExpression(Number,BinaryExpression(Number,ArithOp,Number))))))))
|
|
654
|
+
|
|
655
|
+
# Punctuation
|
|
656
|
+
|
|
657
|
+
(foo(1, 2), bar);
|
|
658
|
+
|
|
659
|
+
==>
|
|
660
|
+
|
|
661
|
+
Script(ExpressionStatement(ParenthesizedExpression(
|
|
662
|
+
"(",SequenceExpression(CallExpression(VariableName,ArgList("(",Number,Number,")")),",",VariableName),")")))
|
|
663
|
+
|
|
664
|
+
# Doesn't choke on unfinished ternary operator
|
|
665
|
+
|
|
666
|
+
1?1
|
|
667
|
+
|
|
668
|
+
==>
|
|
669
|
+
|
|
670
|
+
Script(ExpressionStatement(ConditionalExpression(Number,LogicOp,Number,⚠)))
|
|
671
|
+
|
|
672
|
+
# Can handle unterminated template literals
|
|
673
|
+
|
|
674
|
+
`f
|
|
675
|
+
|
|
676
|
+
==>
|
|
677
|
+
|
|
678
|
+
Script(ExpressionStatement(TemplateString(⚠)))
|
|
679
|
+
|
|
680
|
+
# Ternary with leading-dot number
|
|
681
|
+
|
|
682
|
+
a?.2:.3
|
|
683
|
+
|
|
684
|
+
==>
|
|
685
|
+
|
|
686
|
+
Script(ExpressionStatement(ConditionalExpression(VariableName,LogicOp,Number,LogicOp,Number)))
|