jexl-lezer 0.4.1 → 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 +21 -21
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +21 -21
- package/package.json +17 -7
- package/rollup.config.js +3 -3
- 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
package/test/jsx.txt
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Self-closing element {"dialect": "jsx"}
|
|
2
|
+
|
|
3
|
+
<img/>
|
|
4
|
+
|
|
5
|
+
==>
|
|
6
|
+
|
|
7
|
+
Script(ExpressionStatement(JSXElement(JSXSelfClosingTag(JSXStartTag,JSXBuiltin(JSXIdentifier),JSXSelfCloseEndTag))))
|
|
8
|
+
|
|
9
|
+
# Regular element {"dialect": "jsx"}
|
|
10
|
+
|
|
11
|
+
<Foo>bar</Foo>
|
|
12
|
+
|
|
13
|
+
==>
|
|
14
|
+
|
|
15
|
+
Script(ExpressionStatement(JSXElement(
|
|
16
|
+
JSXOpenTag(JSXStartTag, JSXIdentifier, JSXEndTag),
|
|
17
|
+
JSXText,
|
|
18
|
+
JSXCloseTag(JSXStartCloseTag, JSXIdentifier, JSXEndTag))))
|
|
19
|
+
|
|
20
|
+
# Fragment {"dialect": "jsx"}
|
|
21
|
+
|
|
22
|
+
<>bar</>
|
|
23
|
+
|
|
24
|
+
==>
|
|
25
|
+
|
|
26
|
+
Script(ExpressionStatement(JSXElement(
|
|
27
|
+
JSXFragmentTag(JSXStartTag, JSXEndTag),
|
|
28
|
+
JSXText,
|
|
29
|
+
JSXCloseTag(JSXStartCloseTag, JSXEndTag))))
|
|
30
|
+
|
|
31
|
+
# Namespaced name {"dialect": "jsx"}
|
|
32
|
+
|
|
33
|
+
<blah-namespace:img/>
|
|
34
|
+
|
|
35
|
+
==>
|
|
36
|
+
|
|
37
|
+
Script(ExpressionStatement(JSXElement(
|
|
38
|
+
JSXSelfClosingTag(JSXStartTag,JSXNamespacedName(JSXIdentifier, JSXIdentifier),JSXSelfCloseEndTag))))
|
|
39
|
+
|
|
40
|
+
# Member name {"dialect": "jsx"}
|
|
41
|
+
|
|
42
|
+
<pkg.Component/>
|
|
43
|
+
|
|
44
|
+
==>
|
|
45
|
+
|
|
46
|
+
Script(ExpressionStatement(JSXElement(
|
|
47
|
+
JSXSelfClosingTag(JSXStartTag,JSXMemberExpression(JSXIdentifier, JSXIdentifier),JSXSelfCloseEndTag))))
|
|
48
|
+
|
|
49
|
+
# Nested tags {"dialect": "jsx"}
|
|
50
|
+
|
|
51
|
+
<a><b.C>text</b.C>{x} {...y}</a>
|
|
52
|
+
|
|
53
|
+
==>
|
|
54
|
+
|
|
55
|
+
Script(ExpressionStatement(JSXElement(
|
|
56
|
+
JSXOpenTag(JSXStartTag, JSXBuiltin(JSXIdentifier), JSXEndTag),
|
|
57
|
+
JSXElement(
|
|
58
|
+
JSXOpenTag(JSXStartTag, JSXMemberExpression(JSXIdentifier, JSXIdentifier), JSXEndTag),
|
|
59
|
+
JSXText,
|
|
60
|
+
JSXCloseTag(JSXStartCloseTag, JSXMemberExpression(JSXIdentifier, JSXIdentifier), JSXEndTag)),
|
|
61
|
+
JSXEscape(VariableName),
|
|
62
|
+
JSXText,
|
|
63
|
+
JSXEscape(Spread, VariableName),
|
|
64
|
+
JSXCloseTag(JSXStartCloseTag, JSXBuiltin(JSXIdentifier), JSXEndTag))))
|
|
65
|
+
|
|
66
|
+
# Attributes {"dialect": "jsx"}
|
|
67
|
+
|
|
68
|
+
<Foo a="1" b {...attrs} c={c}></Foo>
|
|
69
|
+
|
|
70
|
+
==>
|
|
71
|
+
|
|
72
|
+
Script(ExpressionStatement(JSXElement(
|
|
73
|
+
JSXOpenTag(JSXStartTag, JSXIdentifier,
|
|
74
|
+
JSXAttribute(JSXIdentifier, Equals, JSXAttributeValue),
|
|
75
|
+
JSXAttribute(JSXIdentifier),
|
|
76
|
+
JSXSpreadAttribute(Spread, VariableName),
|
|
77
|
+
JSXAttribute(JSXIdentifier, Equals, JSXEscape(VariableName)),
|
|
78
|
+
JSXEndTag),
|
|
79
|
+
JSXCloseTag(JSXStartCloseTag, JSXIdentifier, JSXEndTag))))
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# No semicolons
|
|
2
|
+
|
|
3
|
+
x
|
|
4
|
+
if (a) {
|
|
5
|
+
var b = c
|
|
6
|
+
d
|
|
7
|
+
} else
|
|
8
|
+
e
|
|
9
|
+
|
|
10
|
+
==>
|
|
11
|
+
|
|
12
|
+
Script(
|
|
13
|
+
ExpressionStatement(VariableName),
|
|
14
|
+
IfStatement(if,ParenthesizedExpression(VariableName),Block(
|
|
15
|
+
VariableDeclaration(var,VariableDefinition,Equals,VariableName),
|
|
16
|
+
ExpressionStatement(VariableName)),
|
|
17
|
+
else,ExpressionStatement(VariableName)))
|
|
18
|
+
|
|
19
|
+
# Continued expressions on new line
|
|
20
|
+
|
|
21
|
+
x
|
|
22
|
+
+ 2
|
|
23
|
+
foo
|
|
24
|
+
(bar)
|
|
25
|
+
|
|
26
|
+
==>
|
|
27
|
+
|
|
28
|
+
Script(
|
|
29
|
+
ExpressionStatement(BinaryExpression(VariableName,ArithOp,Number)),
|
|
30
|
+
ExpressionStatement(CallExpression(VariableName,ArgList(VariableName))))
|
|
31
|
+
|
|
32
|
+
# Doesn't parse postfix ops on a new line
|
|
33
|
+
|
|
34
|
+
x
|
|
35
|
+
++y
|
|
36
|
+
|
|
37
|
+
==>
|
|
38
|
+
|
|
39
|
+
Script(
|
|
40
|
+
ExpressionStatement(VariableName),
|
|
41
|
+
ExpressionStatement(UnaryExpression(ArithOp,VariableName)))
|
|
42
|
+
|
|
43
|
+
# Eagerly cut return/break/continue
|
|
44
|
+
|
|
45
|
+
return 2
|
|
46
|
+
return
|
|
47
|
+
2
|
|
48
|
+
continue foo
|
|
49
|
+
continue
|
|
50
|
+
foo
|
|
51
|
+
break bar
|
|
52
|
+
break
|
|
53
|
+
bar
|
|
54
|
+
|
|
55
|
+
==>
|
|
56
|
+
|
|
57
|
+
Script(
|
|
58
|
+
ReturnStatement(return,Number),
|
|
59
|
+
ReturnStatement(return),
|
|
60
|
+
ExpressionStatement(Number),
|
|
61
|
+
ContinueStatement(continue,Label),
|
|
62
|
+
ContinueStatement(continue),
|
|
63
|
+
ExpressionStatement(VariableName),
|
|
64
|
+
BreakStatement(break,Label),
|
|
65
|
+
BreakStatement(break),
|
|
66
|
+
ExpressionStatement(VariableName))
|
|
67
|
+
|
|
68
|
+
# Cut return regardless of whitespace
|
|
69
|
+
|
|
70
|
+
{ return }
|
|
71
|
+
|
|
72
|
+
return // foo
|
|
73
|
+
;
|
|
74
|
+
|
|
75
|
+
==>
|
|
76
|
+
|
|
77
|
+
Script(Block(ReturnStatement(return)),ReturnStatement(return,LineComment))
|
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
# Variable declaration
|
|
2
|
+
|
|
3
|
+
var a = b
|
|
4
|
+
, c = d;
|
|
5
|
+
const [x] = y = 3;
|
|
6
|
+
|
|
7
|
+
==>
|
|
8
|
+
|
|
9
|
+
Script(
|
|
10
|
+
VariableDeclaration(var,VariableDefinition,Equals,VariableName,VariableDefinition,Equals,VariableName),
|
|
11
|
+
VariableDeclaration(const,ArrayPattern(VariableDefinition),Equals,AssignmentExpression(VariableName,Equals,Number)))
|
|
12
|
+
|
|
13
|
+
# Function declaration
|
|
14
|
+
|
|
15
|
+
function a(a, b) { return 3; }
|
|
16
|
+
function b({b}, c = d, e = f) {}
|
|
17
|
+
|
|
18
|
+
==>
|
|
19
|
+
|
|
20
|
+
Script(
|
|
21
|
+
FunctionDeclaration(function,VariableDefinition,ParamList(VariableDefinition,VariableDefinition),Block(ReturnStatement(return,Number))),
|
|
22
|
+
FunctionDeclaration(function,VariableDefinition,ParamList(
|
|
23
|
+
ObjectPattern(PatternProperty(PropertyName)),VariableDefinition,Equals,VariableName,VariableDefinition,Equals,VariableName),Block))
|
|
24
|
+
|
|
25
|
+
# Async functions
|
|
26
|
+
|
|
27
|
+
async function foo() {}
|
|
28
|
+
|
|
29
|
+
class Foo { async bar() {} }
|
|
30
|
+
|
|
31
|
+
async (a) => { return foo; };
|
|
32
|
+
|
|
33
|
+
==>
|
|
34
|
+
|
|
35
|
+
Script(
|
|
36
|
+
FunctionDeclaration(async,function,VariableDefinition,ParamList,Block),
|
|
37
|
+
ClassDeclaration(class,VariableDefinition,ClassBody(MethodDeclaration(async,PropertyDefinition,ParamList,Block))),
|
|
38
|
+
ExpressionStatement(ArrowFunction(async,ParamList(VariableDefinition),Arrow,Block(ReturnStatement(return,VariableName)))))
|
|
39
|
+
|
|
40
|
+
# If statements
|
|
41
|
+
|
|
42
|
+
if (x) log(y);
|
|
43
|
+
|
|
44
|
+
if (a.b) {
|
|
45
|
+
d;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (a) {
|
|
49
|
+
c;
|
|
50
|
+
d;
|
|
51
|
+
} else {
|
|
52
|
+
e;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (1) if (2) b; else c;
|
|
56
|
+
|
|
57
|
+
==>
|
|
58
|
+
|
|
59
|
+
Script(
|
|
60
|
+
IfStatement(if,ParenthesizedExpression(VariableName),ExpressionStatement(CallExpression(VariableName,ArgList(VariableName)))),
|
|
61
|
+
IfStatement(if,ParenthesizedExpression(MemberExpression(VariableName,PropertyName)),Block(ExpressionStatement(VariableName))),
|
|
62
|
+
IfStatement(if,ParenthesizedExpression(VariableName),Block(ExpressionStatement(VariableName),ExpressionStatement(VariableName)),
|
|
63
|
+
else,Block(ExpressionStatement(VariableName))),
|
|
64
|
+
IfStatement(if,ParenthesizedExpression(Number),IfStatement(if,ParenthesizedExpression(Number),ExpressionStatement(VariableName),
|
|
65
|
+
else,ExpressionStatement(VariableName))))
|
|
66
|
+
|
|
67
|
+
# While loop
|
|
68
|
+
|
|
69
|
+
while (1) debugger;
|
|
70
|
+
while (2) {
|
|
71
|
+
a;
|
|
72
|
+
b;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
==>
|
|
76
|
+
|
|
77
|
+
Script(
|
|
78
|
+
WhileStatement(while,ParenthesizedExpression(Number),DebuggerStatement(debugger)),
|
|
79
|
+
WhileStatement(while,ParenthesizedExpression(Number),Block(ExpressionStatement(VariableName),ExpressionStatement(VariableName))))
|
|
80
|
+
|
|
81
|
+
# Labels
|
|
82
|
+
|
|
83
|
+
foo: 1;
|
|
84
|
+
foo: while(2) break foo;
|
|
85
|
+
|
|
86
|
+
==>
|
|
87
|
+
|
|
88
|
+
Script(
|
|
89
|
+
LabeledStatement(Label,ExpressionStatement(Number)),
|
|
90
|
+
LabeledStatement(Label,WhileStatement(while,ParenthesizedExpression(Number),BreakStatement(break,Label))))
|
|
91
|
+
|
|
92
|
+
# Try
|
|
93
|
+
|
|
94
|
+
try { throw new Error; } catch {}
|
|
95
|
+
try { 1; } catch (x) { 2; } finally { 3; }
|
|
96
|
+
|
|
97
|
+
==>
|
|
98
|
+
|
|
99
|
+
Script(
|
|
100
|
+
TryStatement(try,Block(ThrowStatement(throw,NewExpression(new,VariableName))),CatchClause(catch,Block)),
|
|
101
|
+
TryStatement(try,Block(ExpressionStatement(Number)),
|
|
102
|
+
CatchClause(catch,VariableDefinition,Block(ExpressionStatement(Number))),
|
|
103
|
+
FinallyClause(finally,Block(ExpressionStatement(Number)))))
|
|
104
|
+
|
|
105
|
+
# Switch
|
|
106
|
+
|
|
107
|
+
switch (x) {
|
|
108
|
+
case 1:
|
|
109
|
+
return true;
|
|
110
|
+
case 2:
|
|
111
|
+
case 50 * 3:
|
|
112
|
+
console.log("ok");
|
|
113
|
+
default:
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
==>
|
|
118
|
+
|
|
119
|
+
Script(SwitchStatement(switch,ParenthesizedExpression(VariableName),SwitchBody(
|
|
120
|
+
CaseLabel(case,Number),
|
|
121
|
+
ReturnStatement(return,BooleanLiteral),
|
|
122
|
+
CaseLabel(case,Number),
|
|
123
|
+
CaseLabel(case,BinaryExpression(Number,ArithOp,Number)),
|
|
124
|
+
ExpressionStatement(CallExpression(MemberExpression(VariableName,PropertyName),ArgList(String))),
|
|
125
|
+
DefaultLabel(default),
|
|
126
|
+
ReturnStatement(return,BooleanLiteral))))
|
|
127
|
+
|
|
128
|
+
# For
|
|
129
|
+
|
|
130
|
+
for (let x = 1; x < 10; x++) {}
|
|
131
|
+
for (const y of z) {}
|
|
132
|
+
for (var m in n) {}
|
|
133
|
+
for (q in r) {}
|
|
134
|
+
for (var a, b; c; d) continue;
|
|
135
|
+
for (i = 0, init(); i < 10; i++) {}
|
|
136
|
+
for (;;) {}
|
|
137
|
+
for (const {thing} in things) thing;
|
|
138
|
+
for await (let x of stream) {}
|
|
139
|
+
|
|
140
|
+
==>
|
|
141
|
+
|
|
142
|
+
Script(
|
|
143
|
+
ForStatement(for,ForSpec(VariableDeclaration(let,VariableDefinition,Equals,Number),
|
|
144
|
+
BinaryExpression(VariableName,CompareOp,Number),PostfixExpression(VariableName,ArithOp)),Block),
|
|
145
|
+
ForStatement(for,ForOfSpec(const,VariableDefinition,of,VariableName),Block),
|
|
146
|
+
ForStatement(for,ForInSpec(var,VariableDefinition,in,VariableName),Block),
|
|
147
|
+
ForStatement(for,ForInSpec(VariableName,in,VariableName),Block),
|
|
148
|
+
ForStatement(for,ForSpec(VariableDeclaration(var,VariableDefinition,VariableDefinition),VariableName,VariableName),ContinueStatement(continue)),
|
|
149
|
+
ForStatement(for,ForSpec(SequenceExpression(AssignmentExpression(VariableName,Equals,Number),
|
|
150
|
+
CallExpression(VariableName,ArgList)),BinaryExpression(VariableName,CompareOp,Number),PostfixExpression(VariableName,ArithOp)),Block),
|
|
151
|
+
ForStatement(for,ForSpec,Block),
|
|
152
|
+
ForStatement(for,ForInSpec(const,ObjectPattern(PatternProperty(PropertyName)),in,VariableName),ExpressionStatement(VariableName)),
|
|
153
|
+
ForStatement(for,await,ForOfSpec(let,VariableDefinition,of,VariableName),Block))
|
|
154
|
+
|
|
155
|
+
# Labeled statements
|
|
156
|
+
|
|
157
|
+
theLoop: for (;;) {
|
|
158
|
+
if (a) {
|
|
159
|
+
break theLoop;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
==>
|
|
164
|
+
|
|
165
|
+
Script(LabeledStatement(Label,ForStatement(for,ForSpec,Block(
|
|
166
|
+
IfStatement(if,ParenthesizedExpression(VariableName),Block(BreakStatement(break,Label)))))))
|
|
167
|
+
|
|
168
|
+
# Classes
|
|
169
|
+
|
|
170
|
+
class Foo {
|
|
171
|
+
static one(a) { return a; };
|
|
172
|
+
two(b) { return b; }
|
|
173
|
+
finally() {}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
class Foo extends require('another-class') {
|
|
177
|
+
constructor() { super(); }
|
|
178
|
+
bar() { super.a(); }
|
|
179
|
+
prop;
|
|
180
|
+
etc = 20;
|
|
181
|
+
static { f() }
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
==>
|
|
185
|
+
|
|
186
|
+
Script(
|
|
187
|
+
ClassDeclaration(class,VariableDefinition,ClassBody(
|
|
188
|
+
MethodDeclaration(static,PropertyDefinition,ParamList(VariableDefinition),Block(ReturnStatement(return,VariableName))),
|
|
189
|
+
MethodDeclaration(PropertyDefinition,ParamList(VariableDefinition),Block(ReturnStatement(return,VariableName))),
|
|
190
|
+
MethodDeclaration(PropertyDefinition,ParamList,Block))),
|
|
191
|
+
ClassDeclaration(class,VariableDefinition,extends,CallExpression(VariableName,ArgList(String)),ClassBody(
|
|
192
|
+
MethodDeclaration(PropertyDefinition,ParamList,Block(ExpressionStatement(CallExpression(super,ArgList)))),
|
|
193
|
+
MethodDeclaration(PropertyDefinition,ParamList,Block(ExpressionStatement(CallExpression(MemberExpression(super,PropertyName),ArgList)))),
|
|
194
|
+
PropertyDeclaration(PropertyDefinition),
|
|
195
|
+
PropertyDeclaration(PropertyDefinition,Equals,Number),
|
|
196
|
+
StaticBlock(static, Block(ExpressionStatement(CallExpression(VariableName,ArgList)))))))
|
|
197
|
+
|
|
198
|
+
# Private properties
|
|
199
|
+
|
|
200
|
+
class Foo {
|
|
201
|
+
#bar() { this.#a() + this?.#prop == #prop in this; }
|
|
202
|
+
#prop;
|
|
203
|
+
#etc = 20;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
==>
|
|
207
|
+
|
|
208
|
+
Script(ClassDeclaration(class,VariableDefinition,ClassBody(
|
|
209
|
+
MethodDeclaration(PrivatePropertyDefinition,ParamList,Block(
|
|
210
|
+
ExpressionStatement(BinaryExpression(
|
|
211
|
+
BinaryExpression(
|
|
212
|
+
CallExpression(MemberExpression(this,PrivatePropertyName),ArgList),
|
|
213
|
+
ArithOp,
|
|
214
|
+
MemberExpression(this,PrivatePropertyName)),
|
|
215
|
+
CompareOp,
|
|
216
|
+
BinaryExpression(PrivatePropertyName, in, this))))),
|
|
217
|
+
PropertyDeclaration(PrivatePropertyDefinition),
|
|
218
|
+
PropertyDeclaration(PrivatePropertyDefinition,Equals,Number))))
|
|
219
|
+
|
|
220
|
+
# Computed properties
|
|
221
|
+
|
|
222
|
+
class Foo {
|
|
223
|
+
[x] = 44;
|
|
224
|
+
[Symbol.iterator]() {}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
==>
|
|
228
|
+
|
|
229
|
+
Script(ClassDeclaration(class,VariableDefinition,ClassBody(
|
|
230
|
+
PropertyDeclaration(VariableName,Equals,Number),
|
|
231
|
+
MethodDeclaration(MemberExpression(VariableName,PropertyName),ParamList,Block))))
|
|
232
|
+
|
|
233
|
+
# Imports
|
|
234
|
+
|
|
235
|
+
import defaultMember from "module-name";
|
|
236
|
+
import * as name from "module-name";
|
|
237
|
+
import { member } from "module-name";
|
|
238
|
+
import { member1, member2 as alias2 } from "module-name";
|
|
239
|
+
import defaultMember, { member1, member2 as alias2, } from "module-name";
|
|
240
|
+
import "module-name";
|
|
241
|
+
import defer x from "y";
|
|
242
|
+
import defer from "y";
|
|
243
|
+
|
|
244
|
+
==>
|
|
245
|
+
|
|
246
|
+
Script(
|
|
247
|
+
ImportDeclaration(import,VariableDefinition,from,String),
|
|
248
|
+
ImportDeclaration(import,Star,as,VariableDefinition,from,String),
|
|
249
|
+
ImportDeclaration(import,ImportGroup(VariableDefinition),from,String),
|
|
250
|
+
ImportDeclaration(import,ImportGroup(VariableDefinition,VariableName,as,VariableDefinition),from,String),
|
|
251
|
+
ImportDeclaration(import,VariableDefinition,ImportGroup(VariableDefinition,VariableName,as,VariableDefinition),from,String),
|
|
252
|
+
ImportDeclaration(import,String),
|
|
253
|
+
ImportDeclaration(import,defer,VariableDefinition,from,String),
|
|
254
|
+
ImportDeclaration(import,VariableDefinition,from,String))
|
|
255
|
+
|
|
256
|
+
# Exports
|
|
257
|
+
|
|
258
|
+
export { name1, name2, name3 as x, nameN };
|
|
259
|
+
export let a, b = 2;
|
|
260
|
+
export default 2 + 2;
|
|
261
|
+
export default function() { }
|
|
262
|
+
export default async function name1() { }
|
|
263
|
+
export { name1 as default, } from "foo";
|
|
264
|
+
export * from 'foo';
|
|
265
|
+
|
|
266
|
+
==>
|
|
267
|
+
|
|
268
|
+
Script(
|
|
269
|
+
ExportDeclaration(export,ExportGroup(VariableName,VariableName,VariableName,as,VariableName,VariableName)),
|
|
270
|
+
ExportDeclaration(export,VariableDeclaration(let,VariableDefinition,VariableDefinition,Equals,Number)),
|
|
271
|
+
ExportDeclaration(export,default,BinaryExpression(Number,ArithOp,Number)),
|
|
272
|
+
ExportDeclaration(export,default,FunctionDeclaration(function,ParamList,Block)),
|
|
273
|
+
ExportDeclaration(export,default,FunctionDeclaration(async,function,VariableDefinition,ParamList,Block)),
|
|
274
|
+
ExportDeclaration(export,ExportGroup(VariableName,as,VariableName),from,String),
|
|
275
|
+
ExportDeclaration(export,Star,from,String))
|
|
276
|
+
|
|
277
|
+
# Empty statements
|
|
278
|
+
|
|
279
|
+
if (true) { ; };;;
|
|
280
|
+
|
|
281
|
+
==>
|
|
282
|
+
|
|
283
|
+
Script(IfStatement(if,ParenthesizedExpression(BooleanLiteral),Block))
|
|
284
|
+
|
|
285
|
+
# Comments
|
|
286
|
+
|
|
287
|
+
/* a */
|
|
288
|
+
one;
|
|
289
|
+
|
|
290
|
+
/* b **/
|
|
291
|
+
two;
|
|
292
|
+
|
|
293
|
+
/* c ***/
|
|
294
|
+
three;
|
|
295
|
+
|
|
296
|
+
/* d
|
|
297
|
+
|
|
298
|
+
***/
|
|
299
|
+
four;
|
|
300
|
+
|
|
301
|
+
y // comment
|
|
302
|
+
* z;
|
|
303
|
+
|
|
304
|
+
==>
|
|
305
|
+
|
|
306
|
+
Script(
|
|
307
|
+
BlockComment,
|
|
308
|
+
ExpressionStatement(VariableName),
|
|
309
|
+
BlockComment,
|
|
310
|
+
ExpressionStatement(VariableName),
|
|
311
|
+
BlockComment,
|
|
312
|
+
ExpressionStatement(VariableName),
|
|
313
|
+
BlockComment,
|
|
314
|
+
ExpressionStatement(VariableName),
|
|
315
|
+
ExpressionStatement(BinaryExpression(VariableName,LineComment,ArithOp,VariableName)))
|
|
316
|
+
|
|
317
|
+
# Recover from invalid char
|
|
318
|
+
|
|
319
|
+
const {foobar} = {};
|
|
320
|
+
|
|
321
|
+
==>
|
|
322
|
+
|
|
323
|
+
Script(VariableDeclaration(
|
|
324
|
+
const,
|
|
325
|
+
ObjectPattern("{",PatternProperty(PropertyName,⚠),"}"),
|
|
326
|
+
Equals,
|
|
327
|
+
ObjectExpression))
|
|
328
|
+
|
|
329
|
+
# Sync back to statement
|
|
330
|
+
|
|
331
|
+
function f() {
|
|
332
|
+
log(a b --c)
|
|
333
|
+
}
|
|
334
|
+
function g() {}
|
|
335
|
+
|
|
336
|
+
==>
|
|
337
|
+
|
|
338
|
+
Script(
|
|
339
|
+
FunctionDeclaration(function,VariableDefinition,ParamList,Block(ExpressionStatement(CallExpression(VariableName,ArgList(...))))),
|
|
340
|
+
FunctionDeclaration(function,VariableDefinition,ParamList,Block))
|
|
341
|
+
|
|
342
|
+
# Destructuring
|
|
343
|
+
|
|
344
|
+
({x} = y);
|
|
345
|
+
[u, v] = w;
|
|
346
|
+
let [a,, b = 0] = c;
|
|
347
|
+
let {x, y: z = 1} = d;
|
|
348
|
+
let {[f]: m} = e;
|
|
349
|
+
|
|
350
|
+
==>
|
|
351
|
+
|
|
352
|
+
Script(
|
|
353
|
+
ExpressionStatement(ParenthesizedExpression(AssignmentExpression(
|
|
354
|
+
ObjectPattern(PatternProperty(PropertyName)),Equals,VariableName))),
|
|
355
|
+
ExpressionStatement(AssignmentExpression(ArrayPattern(VariableDefinition,VariableDefinition),Equals,VariableName)),
|
|
356
|
+
VariableDeclaration(let,ArrayPattern(VariableDefinition,VariableDefinition,Equals,Number),Equals,VariableName),
|
|
357
|
+
VariableDeclaration(let,ObjectPattern(
|
|
358
|
+
PatternProperty(PropertyName),
|
|
359
|
+
PatternProperty(PropertyName,VariableDefinition,Equals,Number)
|
|
360
|
+
),Equals,VariableName),
|
|
361
|
+
VariableDeclaration(let,ObjectPattern(PatternProperty(VariableName,VariableDefinition)),Equals,VariableName))
|
|
362
|
+
|
|
363
|
+
# Generators
|
|
364
|
+
|
|
365
|
+
function* foo() { yield 1 }
|
|
366
|
+
|
|
367
|
+
class B {
|
|
368
|
+
*method() {}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
({*x() {}})
|
|
372
|
+
|
|
373
|
+
==>
|
|
374
|
+
|
|
375
|
+
Script(
|
|
376
|
+
FunctionDeclaration(function,Star,VariableDefinition,ParamList,Block(
|
|
377
|
+
ExpressionStatement(YieldExpression(yield,Number)))),
|
|
378
|
+
ClassDeclaration(class,VariableDefinition,ClassBody(
|
|
379
|
+
MethodDeclaration(Star,PropertyDefinition,ParamList,Block))),
|
|
380
|
+
ExpressionStatement(ParenthesizedExpression(ObjectExpression(Property(Star,PropertyDefinition,ParamList,Block)))))
|
|
381
|
+
|
|
382
|
+
# Hashbang
|
|
383
|
+
|
|
384
|
+
#!/bin/env node
|
|
385
|
+
foo()
|
|
386
|
+
|
|
387
|
+
==>
|
|
388
|
+
|
|
389
|
+
Script(Hashbang,ExpressionStatement(CallExpression(VariableName,ArgList)))
|
|
390
|
+
|
|
391
|
+
# new.target
|
|
392
|
+
|
|
393
|
+
function MyObj() {
|
|
394
|
+
if (!new.target) {
|
|
395
|
+
throw new Error('Must construct MyObj with new');
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
==>
|
|
400
|
+
|
|
401
|
+
Script(
|
|
402
|
+
FunctionDeclaration(function,VariableDefinition,ParamList,Block(
|
|
403
|
+
IfStatement(if,ParenthesizedExpression(UnaryExpression(LogicOp,NewTarget(new,PropertyName))), Block(
|
|
404
|
+
ThrowStatement(throw,NewExpression(new,VariableName,ArgList(String))))))))
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {parser} from "../dist/index.js"
|
|
2
|
+
import {fileTests} from "@lezer/generator/dist/test"
|
|
3
|
+
|
|
4
|
+
import * as fs from "fs"
|
|
5
|
+
import * as path from "path"
|
|
6
|
+
import {fileURLToPath} from "url"
|
|
7
|
+
let caseDir = path.dirname(fileURLToPath(import.meta.url))
|
|
8
|
+
|
|
9
|
+
for (let file of fs.readdirSync(caseDir)) {
|
|
10
|
+
if (!/\.txt$/.test(file)) continue
|
|
11
|
+
|
|
12
|
+
let name = /^[^\.]*/.exec(file)[0]
|
|
13
|
+
describe(name, () => {
|
|
14
|
+
for (let {name, run} of fileTests(fs.readFileSync(path.join(caseDir, file), "utf8"), file))
|
|
15
|
+
it(name, () => run(parser))
|
|
16
|
+
})
|
|
17
|
+
}
|