1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
|
// |reftest| skip
loadRelativeToScript('Match.js');
var { Pattern, MatchError } = Match;
function program(elts) {
return Pattern({ type: "Program", body: elts });
}
function exprStmt(expr) {
return Pattern({ type: "ExpressionStatement", expression: expr });
}
function throwStmt(expr) {
return Pattern({ type: "ThrowStatement", argument: expr });
}
function returnStmt(expr) {
return Pattern({ type: "ReturnStatement", argument: expr });
}
function yieldExpr(expr) {
return Pattern({ type: "YieldExpression", argument: expr });
}
function lit(val) {
return Pattern({ type: "Literal", value: val });
}
function comp(name) {
return Pattern({ type: "ComputedName", name: name });
}
function spread(val) {
return Pattern({ type: "SpreadExpression", expression: val});
}
var thisExpr = Pattern({ type: "ThisExpression" });
function funDecl(id, params, body, defaults=[], rest=null) {
return Pattern({ type: "FunctionDeclaration",
id: id,
params: params,
defaults: defaults,
body: body,
rest: rest,
generator: false });
}
function genFunDecl(style, id, params, body) {
return Pattern({ type: "FunctionDeclaration",
id: id,
params: params,
defaults: [],
body: body,
generator: true,
style: style });
}
function asyncFunDecl(id, params, body) {
return Pattern({ type: "FunctionDeclaration",
id: id,
params: params,
defaults: [],
body: body,
generator: true,
async: true,
style: "es6" });
}
function varDecl(decls) {
return Pattern({ type: "VariableDeclaration", declarations: decls, kind: "var" });
}
function letDecl(decls) {
return Pattern({ type: "VariableDeclaration", declarations: decls, kind: "let" });
}
function constDecl(decls) {
return Pattern({ type: "VariableDeclaration", declarations: decls, kind: "const" });
}
function ident(name) {
return Pattern({ type: "Identifier", name: name });
}
function dotExpr(obj, id) {
return Pattern({ type: "MemberExpression", computed: false, object: obj, property: id });
}
function memExpr(obj, id) {
return Pattern({ type: "MemberExpression", computed: true, object: obj, property: id });
}
function forStmt(init, test, update, body) {
return Pattern({ type: "ForStatement", init: init, test: test, update: update, body: body });
}
function forOfStmt(lhs, rhs, body) {
return Pattern({ type: "ForOfStatement", left: lhs, right: rhs, body: body });
}
function forInStmt(lhs, rhs, body) {
return Pattern({ type: "ForInStatement", left: lhs, right: rhs, body: body, each: false });
}
function forEachInStmt(lhs, rhs, body) {
return Pattern({ type: "ForInStatement", left: lhs, right: rhs, body: body, each: true });
}
function breakStmt(lab) {
return Pattern({ type: "BreakStatement", label: lab });
}
function continueStmt(lab) {
return Pattern({ type: "ContinueStatement", label: lab });
}
function blockStmt(body) {
return Pattern({ type: "BlockStatement", body: body });
}
function literal(val) {
return Pattern({ type: "Literal", value: val });
}
var emptyStmt = Pattern({ type: "EmptyStatement" });
function ifStmt(test, cons, alt) {
return Pattern({ type: "IfStatement", test: test, alternate: alt, consequent: cons });
}
function labStmt(lab, stmt) {
return Pattern({ type: "LabeledStatement", label: lab, body: stmt });
}
function withStmt(obj, stmt) {
return Pattern({ type: "WithStatement", object: obj, body: stmt });
}
function whileStmt(test, stmt) {
return Pattern({ type: "WhileStatement", test: test, body: stmt });
}
function doStmt(stmt, test) {
return Pattern({ type: "DoWhileStatement", test: test, body: stmt });
}
function switchStmt(disc, cases) {
return Pattern({ type: "SwitchStatement", discriminant: disc, cases: cases });
}
function caseClause(test, stmts) {
return Pattern({ type: "SwitchCase", test: test, consequent: stmts });
}
function defaultClause(stmts) {
return Pattern({ type: "SwitchCase", test: null, consequent: stmts });
}
function catchClause(id, guard, body) {
return Pattern({ type: "CatchClause", param: id, guard: guard, body: body });
}
function tryStmt(body, guarded, unguarded, fin) {
return Pattern({ type: "TryStatement", block: body, guardedHandlers: guarded, handler: unguarded, finalizer: fin });
}
function letStmt(head, body) {
return Pattern({ type: "LetStatement", head: head, body: body });
}
function superProp(id) {
return dotExpr(Pattern({ type: "Super" }), id);
}
function superElem(id) {
return memExpr(Pattern({ type: "Super" }), id);
}
function classStmt(id, heritage, body) {
return Pattern({ type: "ClassStatement",
id: id,
superClass: heritage,
body: body});
}
function classExpr(id, heritage, body) {
return Pattern({ type: "ClassExpression",
id: id,
superClass: heritage,
body: body});
}
function classMethod(id, body, kind, static) {
return Pattern({ type: "ClassMethod",
name: id,
body: body,
kind: kind,
static: static });
}
function funExpr(id, args, body, gen) {
return Pattern({ type: "FunctionExpression",
id: id,
params: args,
body: body,
generator: false });
}
function genFunExpr(style, id, args, body) {
return Pattern({ type: "FunctionExpression",
id: id,
params: args,
body: body,
generator: true,
style: style });
}
function asyncFunExpr(id, args, body) {
return Pattern({ type: "FunctionExpression",
id: id,
params: args,
body: body,
generator: true,
async: true,
style: "es6" });
}
function arrowExpr(args, body) {
return Pattern({ type: "ArrowFunctionExpression",
params: args,
body: body });
}
function asyncArrowExpr(isExpression, args, body) {
return Pattern({ type: "ArrowFunctionExpression",
params: args,
body: body,
generator: true,
async: true,
expression: isExpression,
style: "es6" });
}
function metaProperty(meta, property) {
return Pattern({ type: "MetaProperty",
meta: meta,
property: property });
}
function newTarget() {
return metaProperty(ident("new"), ident("target"));
}
function unExpr(op, arg) {
return Pattern({ type: "UnaryExpression", operator: op, argument: arg });
}
function binExpr(op, left, right) {
return Pattern({ type: "BinaryExpression", operator: op, left: left, right: right });
}
function aExpr(op, left, right) {
return Pattern({ type: "AssignmentExpression", operator: op, left: left, right: right });
}
function updExpr(op, arg, prefix) {
return Pattern({ type: "UpdateExpression", operator: op, argument: arg, prefix: prefix });
}
function logExpr(op, left, right) {
return Pattern({ type: "LogicalExpression", operator: op, left: left, right: right });
}
function condExpr(test, cons, alt) {
return Pattern({ type: "ConditionalExpression", test: test, consequent: cons, alternate: alt });
}
function seqExpr(exprs) {
return Pattern({ type: "SequenceExpression", expressions: exprs });
}
function newExpr(callee, args) {
return Pattern({ type: "NewExpression", callee: callee, arguments: args });
}
function callExpr(callee, args) {
return Pattern({ type: "CallExpression", callee: callee, arguments: args });
}
function superCallExpr(args) {
return callExpr({ type: "Super" }, args);
}
function arrExpr(elts) {
return Pattern({ type: "ArrayExpression", elements: elts });
}
function objExpr(elts) {
return Pattern({ type: "ObjectExpression", properties: elts });
}
function computedName(elts) {
return Pattern({ type: "ComputedName", name: elts });
}
function templateLit(elts) {
return Pattern({ type: "TemplateLiteral", elements: elts });
}
function taggedTemplate(tagPart, templatePart) {
return Pattern({ type: "TaggedTemplate", callee: tagPart, arguments : templatePart });
}
function template(raw, cooked, ...args) {
return Pattern([{ type: "CallSiteObject", raw: raw, cooked: cooked}, ...args]);
}
function compExpr(body, blocks, filter, style) {
if (style == "legacy" || !filter)
return Pattern({ type: "ComprehensionExpression", body, blocks, filter, style });
else
return Pattern({ type: "ComprehensionExpression", body, blocks: blocks.concat(compIf(filter)), filter: null, style });
}
function genExpr(body, blocks, filter, style) {
if (style == "legacy" || !filter)
return Pattern({ type: "GeneratorExpression", body, blocks, filter, style });
else
return Pattern({ type: "GeneratorExpression", body, blocks: blocks.concat(compIf(filter)), filter: null, style });
}
function graphExpr(idx, body) {
return Pattern({ type: "GraphExpression", index: idx, expression: body });
}
function idxExpr(idx) {
return Pattern({ type: "GraphIndexExpression", index: idx });
}
function compBlock(left, right) {
return Pattern({ type: "ComprehensionBlock", left: left, right: right, each: false, of: false });
}
function compEachBlock(left, right) {
return Pattern({ type: "ComprehensionBlock", left: left, right: right, each: true, of: false });
}
function compOfBlock(left, right) {
return Pattern({ type: "ComprehensionBlock", left: left, right: right, each: false, of: true });
}
function compIf(test) {
return Pattern({ type: "ComprehensionIf", test: test });
}
function arrPatt(elts) {
return Pattern({ type: "ArrayPattern", elements: elts });
}
function objPatt(elts) {
return Pattern({ type: "ObjectPattern", properties: elts });
}
function assignElem(target, defaultExpr = null, targetIdent = typeof target == 'string' ? ident(target) : target) {
return defaultExpr ? aExpr('=', targetIdent, defaultExpr) : targetIdent;
}
function assignProp(property, target, defaultExpr = null, shorthand = !target, targetProp = target || ident(property)) {
return Pattern({
type: "Property", key: ident(property), shorthand,
value: defaultExpr ? aExpr('=', targetProp, defaultExpr) : targetProp });
}
|