@danielx/civet 0.6.2 → 0.6.4
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/dist/browser.js +2172 -2128
- package/dist/main.js +2172 -2128
- package/dist/main.mjs +2172 -2128
- package/package.json +1 -1
package/dist/browser.js
CHANGED
|
@@ -31,6 +31,119 @@ var Civet = (() => {
|
|
|
31
31
|
var require_lib = __commonJS({
|
|
32
32
|
"source/lib.js"(exports, module) {
|
|
33
33
|
"use strict";
|
|
34
|
+
function addParentPointers(node, parent) {
|
|
35
|
+
if (node == null)
|
|
36
|
+
return;
|
|
37
|
+
if (typeof node !== "object")
|
|
38
|
+
return;
|
|
39
|
+
if (Array.isArray(node)) {
|
|
40
|
+
for (const child of node) {
|
|
41
|
+
addParentPointers(child, parent);
|
|
42
|
+
}
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
node.parent = parent;
|
|
46
|
+
if (node.children) {
|
|
47
|
+
for (const child of node.children) {
|
|
48
|
+
addParentPointers(child, node);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function addPostfixStatement(statement, ws, post) {
|
|
53
|
+
let children, expressions;
|
|
54
|
+
if (post.blockPrefix?.length) {
|
|
55
|
+
let indent = post.blockPrefix[0][0];
|
|
56
|
+
expressions = [...post.blockPrefix, [indent, statement]];
|
|
57
|
+
children = [" {\n", ...expressions, "\n", indent?.slice?.(0, -2), "}"];
|
|
58
|
+
} else {
|
|
59
|
+
expressions = [["", statement]];
|
|
60
|
+
children = [" { ", ...expressions, " }"];
|
|
61
|
+
}
|
|
62
|
+
const block = {
|
|
63
|
+
type: "BlockStatement",
|
|
64
|
+
children,
|
|
65
|
+
expressions
|
|
66
|
+
};
|
|
67
|
+
children = [...post.children];
|
|
68
|
+
children.push(block);
|
|
69
|
+
if (!isWhitespaceOrEmpty(ws))
|
|
70
|
+
children.push(ws);
|
|
71
|
+
post = { ...post, children, block };
|
|
72
|
+
if (post.type === "IfStatement") {
|
|
73
|
+
post.then = block;
|
|
74
|
+
}
|
|
75
|
+
return post;
|
|
76
|
+
}
|
|
77
|
+
function adjustAtBindings(statements, asThis = false) {
|
|
78
|
+
gatherRecursiveAll(statements, (n) => n.type === "AtBindingProperty").forEach((binding) => {
|
|
79
|
+
const { ref } = binding;
|
|
80
|
+
if (asThis) {
|
|
81
|
+
const atBinding = binding.binding;
|
|
82
|
+
atBinding.children.pop();
|
|
83
|
+
atBinding.type = void 0;
|
|
84
|
+
binding.children.unshift(ref.id, ": this.", ref.base);
|
|
85
|
+
binding.type = "Property";
|
|
86
|
+
binding.ref = void 0;
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (ref.names[0] !== ref.base) {
|
|
90
|
+
binding.children.unshift(ref.base, ": ");
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
function adjustBindingElements(elements) {
|
|
95
|
+
const names = elements.flatMap((p) => p.names || []), { length } = elements;
|
|
96
|
+
let blockPrefix, restIndex = -1, restCount = 0;
|
|
97
|
+
elements.forEach(({ type }, i) => {
|
|
98
|
+
if (type === "BindingRestElement") {
|
|
99
|
+
if (restIndex < 0)
|
|
100
|
+
restIndex = i;
|
|
101
|
+
restCount++;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
if (restCount === 0) {
|
|
105
|
+
return {
|
|
106
|
+
children: elements,
|
|
107
|
+
names,
|
|
108
|
+
blockPrefix,
|
|
109
|
+
length
|
|
110
|
+
};
|
|
111
|
+
} else if (restCount === 1) {
|
|
112
|
+
const rest = elements[restIndex];
|
|
113
|
+
const after = elements.slice(restIndex + 1);
|
|
114
|
+
const restIdentifier = rest.binding.ref || rest.binding;
|
|
115
|
+
names.push(...rest.names || []);
|
|
116
|
+
let l = after.length;
|
|
117
|
+
if (l) {
|
|
118
|
+
if (arrayElementHasTrailingComma(after[l - 1]))
|
|
119
|
+
l++;
|
|
120
|
+
blockPrefix = {
|
|
121
|
+
type: "PostRestBindingElements",
|
|
122
|
+
children: ["[", insertTrimmingSpace(after, ""), "] = ", restIdentifier, ".splice(-", l.toString(), ")"],
|
|
123
|
+
names: after.flatMap((p) => p.names)
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
names,
|
|
128
|
+
children: [...elements.slice(0, restIndex), {
|
|
129
|
+
...rest,
|
|
130
|
+
children: rest.children.slice(0, -1)
|
|
131
|
+
}],
|
|
132
|
+
blockPrefix,
|
|
133
|
+
length
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
const err = {
|
|
137
|
+
type: "Error",
|
|
138
|
+
children: ["Multiple rest elements in array pattern"]
|
|
139
|
+
};
|
|
140
|
+
return {
|
|
141
|
+
names,
|
|
142
|
+
children: [...elements, err],
|
|
143
|
+
blockPrefix,
|
|
144
|
+
length
|
|
145
|
+
};
|
|
146
|
+
}
|
|
34
147
|
function aliasBinding(p, ref) {
|
|
35
148
|
if (p.type === "Identifier") {
|
|
36
149
|
p.children[0] = ref;
|
|
@@ -43,6 +156,24 @@ var Civet = (() => {
|
|
|
43
156
|
p.children.push(": ", ref);
|
|
44
157
|
}
|
|
45
158
|
}
|
|
159
|
+
function arrayElementHasTrailingComma(elementNode) {
|
|
160
|
+
const { children } = elementNode, { length } = children;
|
|
161
|
+
const lastChild = children[length - 1];
|
|
162
|
+
if (lastChild) {
|
|
163
|
+
const l2 = lastChild.length;
|
|
164
|
+
if (lastChild[l2 - 1]?.token === ",") {
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
var assert = {
|
|
171
|
+
equal(a, b, msg) {
|
|
172
|
+
if (a !== b) {
|
|
173
|
+
throw new Error(`Assertion failed [${msg}]: ${a} !== ${b}`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
};
|
|
46
177
|
function blockWithPrefix(prefixStatements, block) {
|
|
47
178
|
if (prefixStatements && prefixStatements.length) {
|
|
48
179
|
const indent = getIndent(block.expressions[0]);
|
|
@@ -73,6 +204,126 @@ var Civet = (() => {
|
|
|
73
204
|
removeParentPointers(node);
|
|
74
205
|
return deepCopy(node);
|
|
75
206
|
}
|
|
207
|
+
function constructInvocation(fn, arg) {
|
|
208
|
+
const fnArr = [fn.leadingComment, fn.expr, fn.trailingComment];
|
|
209
|
+
let expr = fn.expr;
|
|
210
|
+
while (expr.type === "ParenthesizedExpression") {
|
|
211
|
+
expr = expr.expression;
|
|
212
|
+
}
|
|
213
|
+
if (expr.ampersandBlock) {
|
|
214
|
+
const { ref, body } = expr;
|
|
215
|
+
ref.type = "PipedExpression";
|
|
216
|
+
ref.children = [makeLeftHandSideExpression(arg)];
|
|
217
|
+
return {
|
|
218
|
+
type: "UnwrappedExpression",
|
|
219
|
+
children: [skipIfOnlyWS(fn.leadingComment), ...body, skipIfOnlyWS(fn.trailingComment)]
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
expr = fn.expr;
|
|
223
|
+
const lhs = makeLeftHandSideExpression(expr);
|
|
224
|
+
let comment = skipIfOnlyWS(fn.trailingComment);
|
|
225
|
+
if (comment)
|
|
226
|
+
lhs.children.splice(2, 0, comment);
|
|
227
|
+
comment = skipIfOnlyWS(fn.leadingComment);
|
|
228
|
+
if (comment)
|
|
229
|
+
lhs.children.splice(1, 0, comment);
|
|
230
|
+
switch (arg.type) {
|
|
231
|
+
case "CommaExpression":
|
|
232
|
+
arg = makeLeftHandSideExpression(arg);
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
return {
|
|
236
|
+
type: "CallExpression",
|
|
237
|
+
children: [lhs, "(", arg, ")"]
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
function constructPipeStep(fn, arg, returning) {
|
|
241
|
+
const children = [[fn.leadingComment, fn.expr, fn.trailingComment].map(skipIfOnlyWS), " ", arg];
|
|
242
|
+
switch (fn.expr.token) {
|
|
243
|
+
case "yield":
|
|
244
|
+
case "await":
|
|
245
|
+
if (returning) {
|
|
246
|
+
return [
|
|
247
|
+
children,
|
|
248
|
+
returning
|
|
249
|
+
];
|
|
250
|
+
}
|
|
251
|
+
return [
|
|
252
|
+
children,
|
|
253
|
+
null
|
|
254
|
+
];
|
|
255
|
+
case "return":
|
|
256
|
+
return [{
|
|
257
|
+
type: "ReturnStatement",
|
|
258
|
+
children
|
|
259
|
+
}, null];
|
|
260
|
+
}
|
|
261
|
+
if (returning) {
|
|
262
|
+
return [
|
|
263
|
+
constructInvocation(fn, arg),
|
|
264
|
+
returning
|
|
265
|
+
];
|
|
266
|
+
}
|
|
267
|
+
return [constructInvocation(fn, arg), null];
|
|
268
|
+
}
|
|
269
|
+
var initialSpacingRe = /^(?:\r?\n|\n)*((?:\r?\n|\n)\s+)/;
|
|
270
|
+
function dedentBlockString({ $loc, token: str }, spacing, trim = true) {
|
|
271
|
+
if (spacing == null)
|
|
272
|
+
spacing = str.match(initialSpacingRe);
|
|
273
|
+
if (spacing) {
|
|
274
|
+
str = str.replaceAll(spacing[1], "\n");
|
|
275
|
+
const l = spacing.length;
|
|
276
|
+
$loc.pos += l;
|
|
277
|
+
$loc.length -= l;
|
|
278
|
+
}
|
|
279
|
+
if (trim) {
|
|
280
|
+
str = str.replace(/^(\r?\n|\n)/, "").replace(/(\r?\n|\n)[ \t]*$/, "");
|
|
281
|
+
}
|
|
282
|
+
str = str.replace(/(\\.|`|\$\{)/g, (s) => {
|
|
283
|
+
if (s[0] === "\\") {
|
|
284
|
+
return s;
|
|
285
|
+
}
|
|
286
|
+
return `\\${s}`;
|
|
287
|
+
});
|
|
288
|
+
return {
|
|
289
|
+
$loc,
|
|
290
|
+
token: str
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
function dedentBlockSubstitutions($0) {
|
|
294
|
+
const [s, strWithSubstitutions, e] = $0;
|
|
295
|
+
if (strWithSubstitutions.length === 0) {
|
|
296
|
+
return $0;
|
|
297
|
+
}
|
|
298
|
+
let initialSpacing, i = 0, l = strWithSubstitutions.length, results = [s];
|
|
299
|
+
const { token } = strWithSubstitutions[0];
|
|
300
|
+
if (token) {
|
|
301
|
+
initialSpacing = token.match(initialSpacingRe);
|
|
302
|
+
} else {
|
|
303
|
+
initialSpacing = false;
|
|
304
|
+
}
|
|
305
|
+
while (i < l) {
|
|
306
|
+
let segment = strWithSubstitutions[i];
|
|
307
|
+
if (segment.token) {
|
|
308
|
+
segment = dedentBlockString(segment, initialSpacing, false);
|
|
309
|
+
if (i === 0) {
|
|
310
|
+
segment.token = segment.token.replace(/^(\r?\n|\n)/, "");
|
|
311
|
+
}
|
|
312
|
+
if (i === l - 1) {
|
|
313
|
+
segment.token = segment.token.replace(/(\r?\n|\n)[ \t]*$/, "");
|
|
314
|
+
}
|
|
315
|
+
results.push(segment);
|
|
316
|
+
} else {
|
|
317
|
+
results.push(segment);
|
|
318
|
+
}
|
|
319
|
+
i++;
|
|
320
|
+
}
|
|
321
|
+
results.push(e);
|
|
322
|
+
return {
|
|
323
|
+
type: "TemplateLiteral",
|
|
324
|
+
children: results
|
|
325
|
+
};
|
|
326
|
+
}
|
|
76
327
|
function deepCopy(node) {
|
|
77
328
|
if (node == null)
|
|
78
329
|
return node;
|
|
@@ -87,6 +338,356 @@ var Civet = (() => {
|
|
|
87
338
|
})
|
|
88
339
|
);
|
|
89
340
|
}
|
|
341
|
+
function expressionizeIfClause(clause, b, e) {
|
|
342
|
+
const children = clause.children.slice(1);
|
|
343
|
+
children.push("?", b);
|
|
344
|
+
if (e) {
|
|
345
|
+
children.push(e[0], ":", ...e.slice(2));
|
|
346
|
+
} else {
|
|
347
|
+
children.push(":void 0");
|
|
348
|
+
}
|
|
349
|
+
return {
|
|
350
|
+
type: "IfExpression",
|
|
351
|
+
children
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
function expressionizeIteration(exp) {
|
|
355
|
+
const i = exp.children.indexOf(exp.block);
|
|
356
|
+
if (exp.subtype === "DoStatement") {
|
|
357
|
+
insertReturn(exp.block);
|
|
358
|
+
exp.children.splice(i, 1, ...wrapIIFE(exp.children, exp.async));
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
const resultsRef = {
|
|
362
|
+
type: "Ref",
|
|
363
|
+
base: "results",
|
|
364
|
+
id: "results"
|
|
365
|
+
};
|
|
366
|
+
insertPush(exp.block, resultsRef);
|
|
367
|
+
exp.children.splice(
|
|
368
|
+
i,
|
|
369
|
+
1,
|
|
370
|
+
wrapIIFE([
|
|
371
|
+
"const ",
|
|
372
|
+
resultsRef,
|
|
373
|
+
"=[];",
|
|
374
|
+
...exp.children,
|
|
375
|
+
"; return ",
|
|
376
|
+
resultsRef
|
|
377
|
+
], exp.async)
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
function processBinaryOpExpression($0) {
|
|
381
|
+
const expandedOps = expandChainedComparisons($0);
|
|
382
|
+
let i = 2;
|
|
383
|
+
while (i < expandedOps.length) {
|
|
384
|
+
const op = expandedOps[i];
|
|
385
|
+
if (op.special) {
|
|
386
|
+
let [a, wsOp, op2, wsB, b] = expandedOps.slice(i - 2, i + 3);
|
|
387
|
+
if (op2.token === "instanceof" && b.type === "Literal" && b.children?.[0]?.type === "StringLiteral") {
|
|
388
|
+
a = ["typeof ", makeLeftHandSideExpression(a)];
|
|
389
|
+
if (op2.negated) {
|
|
390
|
+
op2 = { ...op2, token: "!==", negated: false };
|
|
391
|
+
} else {
|
|
392
|
+
op2 = { ...op2, token: "===" };
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
if (op2.asConst) {
|
|
396
|
+
a = makeAsConst(a);
|
|
397
|
+
b = makeAsConst(b);
|
|
398
|
+
}
|
|
399
|
+
let children;
|
|
400
|
+
if (op2.call) {
|
|
401
|
+
wsOp = insertTrimmingSpace(wsOp, "");
|
|
402
|
+
if (op2.reversed) {
|
|
403
|
+
wsB = insertTrimmingSpace(wsB, "");
|
|
404
|
+
children = [wsOp, op2.call, "(", wsB, b, ", ", a, ")", op2.suffix];
|
|
405
|
+
} else {
|
|
406
|
+
children = [wsOp, op2.call, "(", a, ",", wsB, b, ")", op2.suffix];
|
|
407
|
+
}
|
|
408
|
+
} else if (op2.method) {
|
|
409
|
+
wsOp = insertTrimmingSpace(wsOp, "");
|
|
410
|
+
wsB = insertTrimmingSpace(wsB, "");
|
|
411
|
+
if (op2.reversed) {
|
|
412
|
+
children = [wsB, b, wsOp, ".", op2.method, "(", a, ")"];
|
|
413
|
+
} else {
|
|
414
|
+
children = [a, wsOp, ".", op2.method, "(", wsB, b, ")"];
|
|
415
|
+
}
|
|
416
|
+
} else if (op2.token) {
|
|
417
|
+
children = [a, wsOp, op2, wsB, b];
|
|
418
|
+
if (op2.negated)
|
|
419
|
+
children = ["(", ...children, ")"];
|
|
420
|
+
} else {
|
|
421
|
+
throw new Error("Unknown operator: " + JSON.stringify(op2));
|
|
422
|
+
}
|
|
423
|
+
if (op2.negated)
|
|
424
|
+
children.unshift("!");
|
|
425
|
+
expandedOps.splice(i - 2, 5, {
|
|
426
|
+
children
|
|
427
|
+
});
|
|
428
|
+
} else {
|
|
429
|
+
i += 4;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
return expandedOps;
|
|
433
|
+
}
|
|
434
|
+
function processCallMemberExpression(node) {
|
|
435
|
+
const { children } = node;
|
|
436
|
+
for (let i = 0; i < children.length; i++) {
|
|
437
|
+
const glob = children[i];
|
|
438
|
+
if (glob?.type === "PropertyGlob") {
|
|
439
|
+
const prefix = children.slice(0, i).concat(glob.dot);
|
|
440
|
+
const parts = [];
|
|
441
|
+
for (const part of glob.object.properties) {
|
|
442
|
+
if (part.type === "MethodDefinition") {
|
|
443
|
+
throw new Error("Glob pattern cannot have method definition");
|
|
444
|
+
}
|
|
445
|
+
if (part.value && !["CallExpression", "MemberExpression", "Identifier"].includes(part.value.type)) {
|
|
446
|
+
throw new Error("Glob pattern must have call or member expression value");
|
|
447
|
+
}
|
|
448
|
+
let value = part.value ?? part.name;
|
|
449
|
+
const wValue = getTrimmingSpace(part.value);
|
|
450
|
+
value = prefix.concat(insertTrimmingSpace(value, ""));
|
|
451
|
+
if (wValue)
|
|
452
|
+
value.unshift(wValue);
|
|
453
|
+
if (part.type === "SpreadProperty") {
|
|
454
|
+
parts.push({
|
|
455
|
+
type: part.type,
|
|
456
|
+
value,
|
|
457
|
+
dots: part.dots,
|
|
458
|
+
delim: part.delim,
|
|
459
|
+
names: part.names,
|
|
460
|
+
children: part.children.slice(0, 2).concat(value, part.delim)
|
|
461
|
+
});
|
|
462
|
+
} else {
|
|
463
|
+
parts.push({
|
|
464
|
+
type: part.type === "Identifier" ? "Property" : part.type,
|
|
465
|
+
name: part.name,
|
|
466
|
+
value,
|
|
467
|
+
delim: part.delim,
|
|
468
|
+
names: part.names,
|
|
469
|
+
children: [
|
|
470
|
+
isWhitespaceOrEmpty(part.children[0]) && part.children[0],
|
|
471
|
+
part.name,
|
|
472
|
+
isWhitespaceOrEmpty(part.children[2]) && part.children[2],
|
|
473
|
+
part.children[3]?.token === ":" ? part.children[3] : ":",
|
|
474
|
+
value,
|
|
475
|
+
part.delim
|
|
476
|
+
]
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
const object = {
|
|
481
|
+
type: "ObjectExpression",
|
|
482
|
+
children: [
|
|
483
|
+
glob.object.children[0],
|
|
484
|
+
...parts,
|
|
485
|
+
glob.object.children.at(-1)
|
|
486
|
+
],
|
|
487
|
+
properties: parts
|
|
488
|
+
};
|
|
489
|
+
if (i === children.length - 1)
|
|
490
|
+
return object;
|
|
491
|
+
return processCallMemberExpression({
|
|
492
|
+
...node,
|
|
493
|
+
children: [object, ...children.slice(i + 1)]
|
|
494
|
+
});
|
|
495
|
+
} else if (glob?.type === "PropertyBind") {
|
|
496
|
+
const prefix = children.slice(0, i);
|
|
497
|
+
return processCallMemberExpression({
|
|
498
|
+
...node,
|
|
499
|
+
children: [
|
|
500
|
+
prefix,
|
|
501
|
+
{
|
|
502
|
+
...glob,
|
|
503
|
+
type: "PropertyAccess",
|
|
504
|
+
children: [...glob.children, ".bind(", prefix, ")"]
|
|
505
|
+
},
|
|
506
|
+
...children.slice(i + 1)
|
|
507
|
+
]
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
return node;
|
|
512
|
+
}
|
|
513
|
+
function wrapIterationReturningResults(statement, outerRef) {
|
|
514
|
+
if (statement.type === "DoStatement") {
|
|
515
|
+
if (outerRef) {
|
|
516
|
+
insertPush(statement.block, outerRef);
|
|
517
|
+
} else {
|
|
518
|
+
insertReturn(statement.block);
|
|
519
|
+
}
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
const resultsRef = {
|
|
523
|
+
type: "Ref",
|
|
524
|
+
base: "results",
|
|
525
|
+
id: "results"
|
|
526
|
+
};
|
|
527
|
+
const declaration = {
|
|
528
|
+
type: "Declaration",
|
|
529
|
+
children: ["const ", resultsRef, "=[];"]
|
|
530
|
+
};
|
|
531
|
+
insertPush(statement.block, resultsRef);
|
|
532
|
+
statement.children.unshift(declaration);
|
|
533
|
+
if (outerRef) {
|
|
534
|
+
statement.children.push(";", outerRef, ".push(", resultsRef, ");");
|
|
535
|
+
} else {
|
|
536
|
+
statement.children.push(";return ", resultsRef, ";");
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
function insertPush(node, ref) {
|
|
540
|
+
if (!node)
|
|
541
|
+
return;
|
|
542
|
+
switch (node.type) {
|
|
543
|
+
case "BlockStatement":
|
|
544
|
+
if (node.expressions.length) {
|
|
545
|
+
const last = node.expressions[node.expressions.length - 1];
|
|
546
|
+
insertPush(last, ref);
|
|
547
|
+
} else {
|
|
548
|
+
node.expressions.push([ref, ".push(void 0);"]);
|
|
549
|
+
}
|
|
550
|
+
return;
|
|
551
|
+
case "CaseBlock":
|
|
552
|
+
node.clauses.forEach((clause) => {
|
|
553
|
+
insertPush(clause, ref);
|
|
554
|
+
});
|
|
555
|
+
return;
|
|
556
|
+
case "WhenClause":
|
|
557
|
+
insertPush(node.block, ref);
|
|
558
|
+
return;
|
|
559
|
+
case "DefaultClause":
|
|
560
|
+
insertPush(node.block, ref);
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
if (!Array.isArray(node))
|
|
564
|
+
return;
|
|
565
|
+
const [, exp] = node;
|
|
566
|
+
if (!exp)
|
|
567
|
+
return;
|
|
568
|
+
const indent = getIndent(node);
|
|
569
|
+
switch (exp.type) {
|
|
570
|
+
case "BreakStatement":
|
|
571
|
+
case "ContinueStatement":
|
|
572
|
+
case "DebuggerStatement":
|
|
573
|
+
case "EmptyStatement":
|
|
574
|
+
case "ReturnStatement":
|
|
575
|
+
case "ThrowStatement":
|
|
576
|
+
case "Declaration":
|
|
577
|
+
return;
|
|
578
|
+
case "ForStatement":
|
|
579
|
+
case "IterationStatement":
|
|
580
|
+
case "DoStatement":
|
|
581
|
+
wrapIterationReturningResults(exp, ref);
|
|
582
|
+
return;
|
|
583
|
+
case "BlockStatement":
|
|
584
|
+
insertPush(exp.expressions[exp.expressions.length - 1], ref);
|
|
585
|
+
return;
|
|
586
|
+
case "IfStatement":
|
|
587
|
+
insertPush(exp.then, ref);
|
|
588
|
+
if (exp.else)
|
|
589
|
+
insertPush(exp.else[2], ref);
|
|
590
|
+
else
|
|
591
|
+
exp.children.push([" else {\n", indent, ref, ".push(undefined)\n", indent, "}"]);
|
|
592
|
+
return;
|
|
593
|
+
case "PatternMatchingStatement":
|
|
594
|
+
insertPush(exp.children[0][0], ref);
|
|
595
|
+
return;
|
|
596
|
+
case "SwitchStatement":
|
|
597
|
+
insertPush(exp.children[2], ref);
|
|
598
|
+
return;
|
|
599
|
+
case "TryStatement":
|
|
600
|
+
exp.blocks.forEach((block) => insertPush(block, ref));
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
if (node[node.length - 1]?.type === "SemicolonDelimiter")
|
|
604
|
+
return;
|
|
605
|
+
node.splice(1, 0, ref, ".push(");
|
|
606
|
+
node.push(")");
|
|
607
|
+
}
|
|
608
|
+
function wrapWithReturn(expression) {
|
|
609
|
+
const children = expression ? ["return ", expression] : ["return"];
|
|
610
|
+
return {
|
|
611
|
+
type: "ReturnStatement",
|
|
612
|
+
children
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
function expandChainedComparisons([first, binops]) {
|
|
616
|
+
const relationalOps = ["==", "===", "!=", "!==", "<", "<=", ">", ">=", "in"];
|
|
617
|
+
const lowerPrecedenceOps = ["??", "&&", "||", "&", "|", "^"];
|
|
618
|
+
let results = [];
|
|
619
|
+
let i = 0;
|
|
620
|
+
let l = binops.length;
|
|
621
|
+
let start = 0;
|
|
622
|
+
let chains = [];
|
|
623
|
+
while (i < l) {
|
|
624
|
+
const [, op] = binops[i];
|
|
625
|
+
if (relationalOps.includes(op.token) || op.relational) {
|
|
626
|
+
chains.push(i);
|
|
627
|
+
} else if (lowerPrecedenceOps.includes(op.token)) {
|
|
628
|
+
processChains();
|
|
629
|
+
first = [];
|
|
630
|
+
}
|
|
631
|
+
i++;
|
|
632
|
+
}
|
|
633
|
+
processChains();
|
|
634
|
+
return results;
|
|
635
|
+
function processChains() {
|
|
636
|
+
if (chains.length > 1) {
|
|
637
|
+
chains.forEach((index, k) => {
|
|
638
|
+
if (k > 0) {
|
|
639
|
+
results.push(" ", "&&", " ");
|
|
640
|
+
}
|
|
641
|
+
const [pre, op, post, exp] = binops[index];
|
|
642
|
+
let endIndex;
|
|
643
|
+
if (k < chains.length - 1) {
|
|
644
|
+
endIndex = chains[k + 1];
|
|
645
|
+
} else {
|
|
646
|
+
endIndex = i + 1;
|
|
647
|
+
}
|
|
648
|
+
results = results.concat(first, ...binops.slice(start, endIndex));
|
|
649
|
+
first = [exp].concat(binops.slice(index + 1, endIndex));
|
|
650
|
+
start = endIndex;
|
|
651
|
+
});
|
|
652
|
+
} else {
|
|
653
|
+
results = results.concat(first, ...binops.slice(start, i + 1));
|
|
654
|
+
start = i + 1;
|
|
655
|
+
}
|
|
656
|
+
chains.length = 0;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
function processParams(f) {
|
|
660
|
+
const { type, parameters, block } = f;
|
|
661
|
+
if (type === "ArrowFunction" && parameters && parameters.tp && parameters.tp.parameters.length === 1) {
|
|
662
|
+
parameters.tp.parameters.push(",");
|
|
663
|
+
}
|
|
664
|
+
if (!block)
|
|
665
|
+
return;
|
|
666
|
+
const { expressions } = block;
|
|
667
|
+
if (!expressions)
|
|
668
|
+
return;
|
|
669
|
+
const { blockPrefix } = parameters;
|
|
670
|
+
let indent;
|
|
671
|
+
if (!expressions.length) {
|
|
672
|
+
indent = "";
|
|
673
|
+
} else {
|
|
674
|
+
indent = expressions[0][0];
|
|
675
|
+
}
|
|
676
|
+
const [splices, thisAssignments] = gatherBindingCode(parameters, {
|
|
677
|
+
injectParamProps: f.name === "constructor"
|
|
678
|
+
});
|
|
679
|
+
const delimiter = {
|
|
680
|
+
type: "SemicolonDelimiter",
|
|
681
|
+
children: [";"]
|
|
682
|
+
};
|
|
683
|
+
const prefix = splices.map((s) => ["let ", s]).concat(thisAssignments).map(
|
|
684
|
+
(s) => s.type ? {
|
|
685
|
+
...s,
|
|
686
|
+
children: [indent, ...s.children, delimiter]
|
|
687
|
+
} : [indent, s, delimiter]
|
|
688
|
+
);
|
|
689
|
+
expressions.unshift(...prefix);
|
|
690
|
+
}
|
|
90
691
|
function removeParentPointers(node) {
|
|
91
692
|
if (node == null)
|
|
92
693
|
return;
|
|
@@ -185,7 +786,7 @@ var Civet = (() => {
|
|
|
185
786
|
function hoistRefDecs(statements) {
|
|
186
787
|
gatherRecursiveAll(statements, (s) => s.hoistDec).forEach((node) => {
|
|
187
788
|
const { hoistDec } = node;
|
|
188
|
-
|
|
789
|
+
let outer = closest(node, ["IfStatement", "IterationStatement"]);
|
|
189
790
|
if (!outer) {
|
|
190
791
|
node.children.push({
|
|
191
792
|
type: "Error",
|
|
@@ -193,7 +794,11 @@ var Civet = (() => {
|
|
|
193
794
|
});
|
|
194
795
|
return;
|
|
195
796
|
}
|
|
196
|
-
|
|
797
|
+
let block = outer.parent;
|
|
798
|
+
if (block.type === "PatternMatchingStatement") {
|
|
799
|
+
outer = block;
|
|
800
|
+
block = block.parent;
|
|
801
|
+
}
|
|
197
802
|
const { expressions } = block;
|
|
198
803
|
const index = expressions.findIndex(([, s]) => outer === s);
|
|
199
804
|
if (index < 0)
|
|
@@ -204,11 +809,124 @@ var Civet = (() => {
|
|
|
204
809
|
node.hoistDec = null;
|
|
205
810
|
});
|
|
206
811
|
}
|
|
812
|
+
function insertReturn(node) {
|
|
813
|
+
if (!node)
|
|
814
|
+
return;
|
|
815
|
+
switch (node.type) {
|
|
816
|
+
case "BlockStatement":
|
|
817
|
+
if (node.expressions.length) {
|
|
818
|
+
const last = node.expressions[node.expressions.length - 1];
|
|
819
|
+
insertReturn(last);
|
|
820
|
+
} else {
|
|
821
|
+
if (node.parent.type === "CatchClause") {
|
|
822
|
+
node.expressions.push(["return"]);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
return;
|
|
826
|
+
case "WhenClause":
|
|
827
|
+
node.children.splice(node.children.indexOf(node.break), 1);
|
|
828
|
+
if (node.block.expressions.length) {
|
|
829
|
+
insertReturn(node.block);
|
|
830
|
+
} else {
|
|
831
|
+
node.block.expressions.push(wrapWithReturn());
|
|
832
|
+
}
|
|
833
|
+
return;
|
|
834
|
+
case "DefaultClause":
|
|
835
|
+
insertReturn(node.block);
|
|
836
|
+
return;
|
|
837
|
+
}
|
|
838
|
+
if (!Array.isArray(node))
|
|
839
|
+
return;
|
|
840
|
+
const [, exp, semi] = node;
|
|
841
|
+
if (semi?.type === "SemicolonDelimiter")
|
|
842
|
+
return;
|
|
843
|
+
let indent = getIndent(node);
|
|
844
|
+
if (!exp)
|
|
845
|
+
return;
|
|
846
|
+
switch (exp.type) {
|
|
847
|
+
case "BreakStatement":
|
|
848
|
+
case "ContinueStatement":
|
|
849
|
+
case "DebuggerStatement":
|
|
850
|
+
case "EmptyStatement":
|
|
851
|
+
case "ReturnStatement":
|
|
852
|
+
case "ThrowStatement":
|
|
853
|
+
case "Declaration":
|
|
854
|
+
return;
|
|
855
|
+
case "ForStatement":
|
|
856
|
+
case "IterationStatement":
|
|
857
|
+
case "DoStatement":
|
|
858
|
+
wrapIterationReturningResults(exp);
|
|
859
|
+
return;
|
|
860
|
+
case "BlockStatement":
|
|
861
|
+
insertReturn(exp.expressions[exp.expressions.length - 1]);
|
|
862
|
+
return;
|
|
863
|
+
case "IfStatement":
|
|
864
|
+
insertReturn(exp.then);
|
|
865
|
+
if (exp.else)
|
|
866
|
+
insertReturn(exp.else[2]);
|
|
867
|
+
else
|
|
868
|
+
exp.children.push(["", {
|
|
869
|
+
type: "ReturnStatement",
|
|
870
|
+
children: [";return"]
|
|
871
|
+
}]);
|
|
872
|
+
return;
|
|
873
|
+
case "PatternMatchingStatement":
|
|
874
|
+
insertReturn(exp.children[0][0]);
|
|
875
|
+
return;
|
|
876
|
+
case "SwitchStatement":
|
|
877
|
+
insertSwitchReturns(exp);
|
|
878
|
+
return;
|
|
879
|
+
case "TryStatement":
|
|
880
|
+
exp.blocks.forEach((block) => insertReturn(block));
|
|
881
|
+
return;
|
|
882
|
+
}
|
|
883
|
+
if (node[node.length - 1]?.type === "SemicolonDelimiter")
|
|
884
|
+
return;
|
|
885
|
+
const returnStatement = wrapWithReturn(node[1]);
|
|
886
|
+
node.splice(1, 1, returnStatement);
|
|
887
|
+
}
|
|
888
|
+
function insertSwitchReturns(exp) {
|
|
889
|
+
switch (exp.type) {
|
|
890
|
+
case "SwitchStatement":
|
|
891
|
+
exp.caseBlock.clauses.forEach((clause) => {
|
|
892
|
+
insertReturn(clause);
|
|
893
|
+
});
|
|
894
|
+
return;
|
|
895
|
+
case "SwitchExpression":
|
|
896
|
+
exp.caseBlock.clauses.forEach(insertReturn);
|
|
897
|
+
return;
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
function isEmptyBareBlock(node) {
|
|
901
|
+
if (node?.type !== "BlockStatement")
|
|
902
|
+
return false;
|
|
903
|
+
const { bare, expressions } = node;
|
|
904
|
+
return bare && (expressions.length === 0 || expressions.length === 1 && expressions[0][1]?.type === "EmptyStatement");
|
|
905
|
+
}
|
|
207
906
|
function isFunction(node) {
|
|
208
907
|
const { type } = node;
|
|
209
908
|
return type === "FunctionExpression" || type === "ArrowFunction" || type === "MethodDefinition" || node.async;
|
|
210
909
|
}
|
|
211
|
-
function
|
|
910
|
+
function isVoidType(t) {
|
|
911
|
+
return t?.type === "LiteralType" && t.t.type === "VoidType";
|
|
912
|
+
}
|
|
913
|
+
function isWhitespaceOrEmpty(node) {
|
|
914
|
+
if (!node)
|
|
915
|
+
return true;
|
|
916
|
+
if (node.type === "Ref")
|
|
917
|
+
return false;
|
|
918
|
+
if (node.token)
|
|
919
|
+
return node.token.match(/^\s*$/);
|
|
920
|
+
if (node.children)
|
|
921
|
+
node = node.children;
|
|
922
|
+
if (!node.length)
|
|
923
|
+
return true;
|
|
924
|
+
if (typeof node === "string")
|
|
925
|
+
return node.match(/^\s*$/);
|
|
926
|
+
if (Array.isArray(node))
|
|
927
|
+
return node.every(isWhitespaceOrEmpty);
|
|
928
|
+
}
|
|
929
|
+
function gatherRecursiveWithinFunction(node, predicate) {
|
|
212
930
|
return gatherRecursive(node, predicate, isFunction);
|
|
213
931
|
}
|
|
214
932
|
function insertTrimmingSpace(target, c) {
|
|
@@ -244,62 +962,6 @@ var Civet = (() => {
|
|
|
244
962
|
if (target.token)
|
|
245
963
|
return target.token.match(/^ ?/)[0];
|
|
246
964
|
}
|
|
247
|
-
function needsRef(exp) {
|
|
248
|
-
switch (exp.type) {
|
|
249
|
-
case "Identifier":
|
|
250
|
-
case "Literal":
|
|
251
|
-
case "Ref":
|
|
252
|
-
return false;
|
|
253
|
-
default:
|
|
254
|
-
return true;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
function maybeRef(exp, base = "ref") {
|
|
258
|
-
if (!needsRef(exp))
|
|
259
|
-
return exp;
|
|
260
|
-
return {
|
|
261
|
-
type: "Ref",
|
|
262
|
-
base,
|
|
263
|
-
id: base
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
function literalValue(literal) {
|
|
267
|
-
let { raw } = literal;
|
|
268
|
-
switch (raw) {
|
|
269
|
-
case "null":
|
|
270
|
-
return null;
|
|
271
|
-
case "true":
|
|
272
|
-
return true;
|
|
273
|
-
case "false":
|
|
274
|
-
return false;
|
|
275
|
-
}
|
|
276
|
-
if (raw.startsWith('"') && raw.endsWith('"') || raw.startsWith("'") && raw.endsWith("'")) {
|
|
277
|
-
return raw.slice(1, -1);
|
|
278
|
-
}
|
|
279
|
-
const numeric = literal.children.find(
|
|
280
|
-
(child) => child.type === "NumericLiteral"
|
|
281
|
-
);
|
|
282
|
-
if (numeric) {
|
|
283
|
-
raw = raw.replace(/_/g, "");
|
|
284
|
-
const { token } = numeric;
|
|
285
|
-
if (token.endsWith("n")) {
|
|
286
|
-
return BigInt(raw.slice(0, -1));
|
|
287
|
-
} else if (token.match(/[\.eE]/)) {
|
|
288
|
-
return parseFloat(raw);
|
|
289
|
-
} else if (token.startsWith("0")) {
|
|
290
|
-
switch (token.charAt(1).toLowerCase()) {
|
|
291
|
-
case "x":
|
|
292
|
-
return parseInt(raw.replace(/0[xX]/, ""), 16);
|
|
293
|
-
case "b":
|
|
294
|
-
return parseInt(raw.replace(/0[bB]/, ""), 2);
|
|
295
|
-
case "o":
|
|
296
|
-
return parseInt(raw.replace(/0[oO]/, ""), 8);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
return parseInt(raw, 10);
|
|
300
|
-
}
|
|
301
|
-
throw new Error("Unrecognized literal " + JSON.stringify(literal));
|
|
302
|
-
}
|
|
303
965
|
function forRange(open, forDeclaration, range, stepExp, close) {
|
|
304
966
|
const { start, end, inclusive } = range;
|
|
305
967
|
const counterRef = {
|
|
@@ -387,6 +1049,79 @@ var Civet = (() => {
|
|
|
387
1049
|
insertRestSplices(statements, splices, thisAssignments);
|
|
388
1050
|
return [splices, thisAssignments];
|
|
389
1051
|
}
|
|
1052
|
+
function literalValue(literal) {
|
|
1053
|
+
let { raw } = literal;
|
|
1054
|
+
switch (raw) {
|
|
1055
|
+
case "null":
|
|
1056
|
+
return null;
|
|
1057
|
+
case "true":
|
|
1058
|
+
return true;
|
|
1059
|
+
case "false":
|
|
1060
|
+
return false;
|
|
1061
|
+
}
|
|
1062
|
+
if (raw.startsWith('"') && raw.endsWith('"') || raw.startsWith("'") && raw.endsWith("'")) {
|
|
1063
|
+
return raw.slice(1, -1);
|
|
1064
|
+
}
|
|
1065
|
+
const numeric = literal.children.find(
|
|
1066
|
+
(child) => child.type === "NumericLiteral"
|
|
1067
|
+
);
|
|
1068
|
+
if (numeric) {
|
|
1069
|
+
raw = raw.replace(/_/g, "");
|
|
1070
|
+
const { token } = numeric;
|
|
1071
|
+
if (token.endsWith("n")) {
|
|
1072
|
+
return BigInt(raw.slice(0, -1));
|
|
1073
|
+
} else if (token.match(/[\.eE]/)) {
|
|
1074
|
+
return parseFloat(raw);
|
|
1075
|
+
} else if (token.startsWith("0")) {
|
|
1076
|
+
switch (token.charAt(1).toLowerCase()) {
|
|
1077
|
+
case "x":
|
|
1078
|
+
return parseInt(raw.replace(/0[xX]/, ""), 16);
|
|
1079
|
+
case "b":
|
|
1080
|
+
return parseInt(raw.replace(/0[bB]/, ""), 2);
|
|
1081
|
+
case "o":
|
|
1082
|
+
return parseInt(raw.replace(/0[oO]/, ""), 8);
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
return parseInt(raw, 10);
|
|
1086
|
+
}
|
|
1087
|
+
throw new Error("Unrecognized literal " + JSON.stringify(literal));
|
|
1088
|
+
}
|
|
1089
|
+
var asConst = {
|
|
1090
|
+
ts: true,
|
|
1091
|
+
children: [" as const"]
|
|
1092
|
+
};
|
|
1093
|
+
function makeAsConst(node) {
|
|
1094
|
+
if (node.type === "Literal" && node.raw !== "null" || node.type === "ArrayExpression" || node.type === "ObjectExpression") {
|
|
1095
|
+
return { ...node, children: [...node.children, asConst] };
|
|
1096
|
+
}
|
|
1097
|
+
return node;
|
|
1098
|
+
}
|
|
1099
|
+
function makeLeftHandSideExpression(expression) {
|
|
1100
|
+
switch (expression.type) {
|
|
1101
|
+
case "Ref":
|
|
1102
|
+
case "Identifier":
|
|
1103
|
+
case "Literal":
|
|
1104
|
+
case "CallExpression":
|
|
1105
|
+
case "MemberExpression":
|
|
1106
|
+
case "ParenthesizedExpression":
|
|
1107
|
+
return expression;
|
|
1108
|
+
default:
|
|
1109
|
+
return {
|
|
1110
|
+
type: "ParenthesizedExpression",
|
|
1111
|
+
children: ["(", expression, ")"],
|
|
1112
|
+
expression
|
|
1113
|
+
};
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
function maybeRef(exp, base = "ref") {
|
|
1117
|
+
if (!needsRef(exp))
|
|
1118
|
+
return exp;
|
|
1119
|
+
return {
|
|
1120
|
+
type: "Ref",
|
|
1121
|
+
base,
|
|
1122
|
+
id: base
|
|
1123
|
+
};
|
|
1124
|
+
}
|
|
390
1125
|
function modifyString(str) {
|
|
391
1126
|
return str.replace(/(^.?|[^\\]{2})(\\\\)*\n/g, "$1$2\\n");
|
|
392
1127
|
}
|
|
@@ -474,6 +1209,20 @@ var Civet = (() => {
|
|
|
474
1209
|
}
|
|
475
1210
|
return parts;
|
|
476
1211
|
}
|
|
1212
|
+
function needsRef(expression, base = "ref") {
|
|
1213
|
+
switch (expression.type) {
|
|
1214
|
+
case "Ref":
|
|
1215
|
+
case "Identifier":
|
|
1216
|
+
case "Literal":
|
|
1217
|
+
return;
|
|
1218
|
+
default:
|
|
1219
|
+
return {
|
|
1220
|
+
type: "Ref",
|
|
1221
|
+
base,
|
|
1222
|
+
id: base
|
|
1223
|
+
};
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
477
1226
|
function processCoffeeInterpolation(s, parts, e, $loc) {
|
|
478
1227
|
if (parts.length === 0 || parts.length === 1 && parts[0].token != null) {
|
|
479
1228
|
return {
|
|
@@ -562,55 +1311,914 @@ var Civet = (() => {
|
|
|
562
1311
|
thisAssignments
|
|
563
1312
|
};
|
|
564
1313
|
}
|
|
565
|
-
function
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
1314
|
+
function processFunctions(statements, config) {
|
|
1315
|
+
gatherRecursiveAll(statements, ({ type }) => type === "FunctionExpression" || type === "ArrowFunction").forEach((f) => {
|
|
1316
|
+
processParams(f);
|
|
1317
|
+
if (!processReturnValue(f) && config.implicitReturns) {
|
|
1318
|
+
const { block, returnType } = f;
|
|
1319
|
+
const isVoid = isVoidType(returnType?.t);
|
|
1320
|
+
const isBlock = block?.type === "BlockStatement";
|
|
1321
|
+
if (!isVoid && isBlock) {
|
|
1322
|
+
insertReturn(block);
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
});
|
|
1326
|
+
gatherRecursiveAll(statements, ({ type }) => type === "MethodDefinition").forEach((f) => {
|
|
1327
|
+
processParams(f);
|
|
1328
|
+
if (!processReturnValue(f) && config.implicitReturns) {
|
|
1329
|
+
const { signature, block } = f;
|
|
1330
|
+
const isConstructor = signature.name === "constructor";
|
|
1331
|
+
const isVoid = isVoidType(signature.returnType?.t);
|
|
1332
|
+
const isSet = signature.modifier?.set;
|
|
1333
|
+
if (!isConstructor && !isSet && !isVoid) {
|
|
1334
|
+
insertReturn(block);
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
});
|
|
1338
|
+
}
|
|
1339
|
+
function processSwitchExpressions(statements) {
|
|
1340
|
+
gatherRecursiveAll(statements, (n) => n.type === "SwitchExpression").forEach(insertSwitchReturns);
|
|
1341
|
+
}
|
|
1342
|
+
function processTryExpressions(statements) {
|
|
1343
|
+
gatherRecursiveAll(statements, (n) => n.type === "TryExpression").forEach(({ blocks }) => {
|
|
1344
|
+
blocks.forEach(insertReturn);
|
|
1345
|
+
});
|
|
1346
|
+
}
|
|
1347
|
+
function processBindingPatternLHS(lhs, tail) {
|
|
1348
|
+
adjustAtBindings(lhs, true);
|
|
1349
|
+
const [splices, thisAssignments] = gatherBindingCode(lhs);
|
|
1350
|
+
tail.push(...splices.map((s) => [", ", s]), ...thisAssignments.map((a) => [", ", a]));
|
|
1351
|
+
}
|
|
1352
|
+
function processAssignments(statements) {
|
|
1353
|
+
gatherRecursiveAll(statements, (n) => n.type === "AssignmentExpression" && n.names === null).forEach((exp) => {
|
|
1354
|
+
let { lhs: $1, exp: $2 } = exp, tail = [], i = 0, len = $1.length;
|
|
1355
|
+
if ($1.some((left) => left[left.length - 1].special)) {
|
|
1356
|
+
if ($1.length !== 1) {
|
|
1357
|
+
throw new Error("Only one assignment with id= is allowed");
|
|
1358
|
+
}
|
|
1359
|
+
const [, lhs, , op] = $1[0];
|
|
1360
|
+
const { call } = op;
|
|
1361
|
+
op[op.length - 1] = "=";
|
|
1362
|
+
$2 = [call, "(", lhs, ", ", $2, ")"];
|
|
1363
|
+
}
|
|
1364
|
+
let wrapped = false;
|
|
1365
|
+
while (i < len) {
|
|
1366
|
+
const lastAssignment = $1[i++];
|
|
1367
|
+
const [, lhs, , op] = lastAssignment;
|
|
1368
|
+
if (op.token !== "=")
|
|
1369
|
+
continue;
|
|
1370
|
+
if (lhs.type === "ObjectExpression" || lhs.type === "ObjectBindingPattern") {
|
|
1371
|
+
if (!wrapped) {
|
|
1372
|
+
wrapped = true;
|
|
1373
|
+
lhs.children.splice(0, 0, "(");
|
|
1374
|
+
tail.push(")");
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
i = len - 1;
|
|
1379
|
+
while (i >= 0) {
|
|
1380
|
+
const lastAssignment = $1[i];
|
|
1381
|
+
if (lastAssignment[3].token === "=") {
|
|
1382
|
+
const lhs = lastAssignment[1];
|
|
1383
|
+
if (lhs.type === "MemberExpression") {
|
|
1384
|
+
const members = lhs.children;
|
|
1385
|
+
const lastMember = members[members.length - 1];
|
|
1386
|
+
if (lastMember.type === "SliceExpression") {
|
|
1387
|
+
const { start, end, children: c } = lastMember;
|
|
1388
|
+
c[0].token = ".splice(";
|
|
1389
|
+
c[1] = start;
|
|
1390
|
+
c[2] = ", ";
|
|
1391
|
+
if (end)
|
|
1392
|
+
c[3] = [end, " - ", start];
|
|
1393
|
+
else
|
|
1394
|
+
c[3] = ["1/0"];
|
|
1395
|
+
c[4] = [", ...", $2];
|
|
1396
|
+
c[5] = ")";
|
|
1397
|
+
lastAssignment.pop();
|
|
1398
|
+
if (isWhitespaceOrEmpty(lastAssignment[2]))
|
|
1399
|
+
lastAssignment.pop();
|
|
1400
|
+
if ($1.length > 1) {
|
|
1401
|
+
throw new Error("Not implemented yet! TODO: Handle multiple splice assignments");
|
|
1402
|
+
}
|
|
1403
|
+
exp.children = [$1];
|
|
1404
|
+
exp.names = [];
|
|
1405
|
+
return;
|
|
1406
|
+
}
|
|
1407
|
+
} else if (lhs.type === "ObjectBindingPattern" || lhs.type === "ArrayBindingPattern") {
|
|
1408
|
+
processBindingPatternLHS(lhs, tail);
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
i--;
|
|
1412
|
+
}
|
|
1413
|
+
const names = $1.flatMap(([, l]) => l.names || []);
|
|
1414
|
+
exp.children = [$1, $2, ...tail];
|
|
1415
|
+
exp.names = names;
|
|
1416
|
+
});
|
|
1417
|
+
gatherRecursiveAll(statements, (n) => n.type === "AssignmentExpression" || n.type === "UpdateExpression").forEach((exp) => {
|
|
1418
|
+
function extractAssignment(lhs) {
|
|
1419
|
+
let expr = lhs;
|
|
1420
|
+
while (expr.type === "ParenthesizedExpression") {
|
|
1421
|
+
expr = expr.expression;
|
|
1422
|
+
}
|
|
1423
|
+
if (expr.type === "AssignmentExpression" || expr.type === "UpdateExpression") {
|
|
1424
|
+
if (expr.type === "UpdateExpression" && expr.children[0] === expr.assigned) {
|
|
1425
|
+
post.push([", ", lhs]);
|
|
1426
|
+
} else {
|
|
1427
|
+
pre.push([lhs, ", "]);
|
|
1428
|
+
}
|
|
1429
|
+
return expr.assigned;
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
const pre = [], post = [];
|
|
573
1433
|
switch (exp.type) {
|
|
574
|
-
case "
|
|
1434
|
+
case "AssignmentExpression":
|
|
1435
|
+
if (!exp.lhs)
|
|
1436
|
+
return;
|
|
1437
|
+
exp.lhs.forEach((lhsPart, i) => {
|
|
1438
|
+
let newLhs2 = extractAssignment(lhsPart[1]);
|
|
1439
|
+
if (newLhs2) {
|
|
1440
|
+
lhsPart[1] = newLhs2;
|
|
1441
|
+
}
|
|
1442
|
+
});
|
|
1443
|
+
break;
|
|
1444
|
+
case "UpdateExpression":
|
|
1445
|
+
let newLhs = extractAssignment(exp.assigned);
|
|
1446
|
+
if (newLhs) {
|
|
1447
|
+
const i = exp.children.indexOf(exp.assigned);
|
|
1448
|
+
exp.assigned = exp.children[i] = newLhs;
|
|
1449
|
+
}
|
|
1450
|
+
break;
|
|
1451
|
+
}
|
|
1452
|
+
if (pre.length)
|
|
1453
|
+
exp.children.unshift(...pre);
|
|
1454
|
+
if (post.length)
|
|
1455
|
+
exp.children.push(...post);
|
|
1456
|
+
});
|
|
1457
|
+
}
|
|
1458
|
+
function attachPostfixStatementAsExpression(exp, post) {
|
|
1459
|
+
let clause;
|
|
1460
|
+
switch (post[1].type) {
|
|
1461
|
+
case "ForStatement":
|
|
1462
|
+
case "IterationStatement":
|
|
1463
|
+
case "DoStatement":
|
|
1464
|
+
clause = addPostfixStatement(exp, ...post);
|
|
1465
|
+
return {
|
|
1466
|
+
type: "IterationExpression",
|
|
1467
|
+
children: [clause],
|
|
1468
|
+
block: clause.block
|
|
1469
|
+
};
|
|
1470
|
+
case "IfStatement":
|
|
1471
|
+
clause = expressionizeIfClause(post[1], exp);
|
|
1472
|
+
return clause;
|
|
1473
|
+
default:
|
|
1474
|
+
throw new Error("Unknown postfix statement");
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
function getPatternConditions(pattern, ref, conditions) {
|
|
1478
|
+
if (pattern.rest)
|
|
1479
|
+
return;
|
|
1480
|
+
switch (pattern.type) {
|
|
1481
|
+
case "ArrayBindingPattern": {
|
|
1482
|
+
const { elements, length } = pattern, hasRest = elements.some((e) => e.rest), comparator = hasRest ? " >= " : " === ", l = [comparator, (length - hasRest).toString()];
|
|
1483
|
+
conditions.push(
|
|
1484
|
+
["Array.isArray(", ref, ")"],
|
|
1485
|
+
[ref, ".length", l]
|
|
1486
|
+
);
|
|
1487
|
+
elements.forEach(({ children: [, e] }, i) => {
|
|
1488
|
+
const subRef = [ref, "[", i.toString(), "]"];
|
|
1489
|
+
getPatternConditions(e, subRef, conditions);
|
|
1490
|
+
});
|
|
1491
|
+
const postRest = pattern.children.find((c) => c?.blockPrefix);
|
|
1492
|
+
if (postRest) {
|
|
1493
|
+
const postElements = postRest.blockPrefix.children[1], { length: postLength } = postElements;
|
|
1494
|
+
postElements.forEach(({ children: [, e] }, i) => {
|
|
1495
|
+
const subRef = [ref, "[", ref, ".length - ", (postLength + i).toString(), "]"];
|
|
1496
|
+
getPatternConditions(e, subRef, conditions);
|
|
1497
|
+
});
|
|
1498
|
+
}
|
|
1499
|
+
break;
|
|
1500
|
+
}
|
|
1501
|
+
case "ObjectBindingPattern": {
|
|
1502
|
+
conditions.push(
|
|
1503
|
+
["typeof ", ref, " === 'object'"],
|
|
1504
|
+
[ref, " != null"]
|
|
1505
|
+
);
|
|
1506
|
+
pattern.properties.forEach((p) => {
|
|
1507
|
+
switch (p.type) {
|
|
1508
|
+
case "PinProperty":
|
|
1509
|
+
case "BindingProperty": {
|
|
1510
|
+
const { name, value } = p;
|
|
1511
|
+
let subRef;
|
|
1512
|
+
switch (name.type) {
|
|
1513
|
+
case "ComputedPropertyName":
|
|
1514
|
+
conditions.push([name.expression, " in ", ref]);
|
|
1515
|
+
subRef = [ref, name];
|
|
1516
|
+
break;
|
|
1517
|
+
case "Literal":
|
|
1518
|
+
case "StringLiteral":
|
|
1519
|
+
case "NumericLiteral":
|
|
1520
|
+
conditions.push([name, " in ", ref]);
|
|
1521
|
+
subRef = [ref, "[", name, "]"];
|
|
1522
|
+
break;
|
|
1523
|
+
default:
|
|
1524
|
+
conditions.push(["'", name, "' in ", ref]);
|
|
1525
|
+
subRef = [ref, ".", name];
|
|
1526
|
+
}
|
|
1527
|
+
if (value) {
|
|
1528
|
+
getPatternConditions(value, subRef, conditions);
|
|
1529
|
+
}
|
|
1530
|
+
break;
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
});
|
|
1534
|
+
break;
|
|
1535
|
+
}
|
|
1536
|
+
case "ConditionFragment":
|
|
1537
|
+
conditions.push(
|
|
1538
|
+
[ref, " ", pattern.children]
|
|
1539
|
+
);
|
|
1540
|
+
break;
|
|
1541
|
+
case "RegularExpressionLiteral": {
|
|
1542
|
+
conditions.push(
|
|
1543
|
+
["typeof ", ref, " === 'string'"],
|
|
1544
|
+
[pattern, ".test(", ref, ")"]
|
|
1545
|
+
);
|
|
1546
|
+
break;
|
|
1547
|
+
}
|
|
1548
|
+
case "PinPattern":
|
|
1549
|
+
conditions.push([
|
|
1550
|
+
ref,
|
|
1551
|
+
" === ",
|
|
1552
|
+
pattern.identifier
|
|
1553
|
+
]);
|
|
1554
|
+
break;
|
|
1555
|
+
case "Literal":
|
|
1556
|
+
conditions.push([
|
|
1557
|
+
ref,
|
|
1558
|
+
" === ",
|
|
1559
|
+
pattern
|
|
1560
|
+
]);
|
|
1561
|
+
break;
|
|
1562
|
+
default:
|
|
1563
|
+
break;
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
function elideMatchersFromArrayBindings(elements) {
|
|
1567
|
+
return elements.map((el) => {
|
|
1568
|
+
if (el.type === "BindingRestElement") {
|
|
1569
|
+
return ["", el, void 0];
|
|
1570
|
+
}
|
|
1571
|
+
const { children: [ws, e, sep] } = el;
|
|
1572
|
+
switch (e.type) {
|
|
575
1573
|
case "Literal":
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
1574
|
+
case "RegularExpressionLiteral":
|
|
1575
|
+
case "StringLiteral":
|
|
1576
|
+
case "PinPattern":
|
|
1577
|
+
return sep;
|
|
580
1578
|
default:
|
|
581
|
-
|
|
582
|
-
...exp,
|
|
583
|
-
children: [...pre, "(", exp.children, ")", post]
|
|
584
|
-
};
|
|
585
|
-
return {
|
|
586
|
-
type: "ParenthesizedExpression",
|
|
587
|
-
children: ["(", expression, ")"],
|
|
588
|
-
expression
|
|
589
|
-
};
|
|
1579
|
+
return [ws, nonMatcherBindings(e), sep];
|
|
590
1580
|
}
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
1581
|
+
});
|
|
1582
|
+
}
|
|
1583
|
+
function elideMatchersFromPropertyBindings(properties) {
|
|
1584
|
+
return properties.map((p) => {
|
|
1585
|
+
switch (p.type) {
|
|
1586
|
+
case "BindingProperty": {
|
|
1587
|
+
const { children, name, value } = p;
|
|
1588
|
+
const [ws] = children;
|
|
1589
|
+
const sep = children[children.length - 1];
|
|
1590
|
+
switch (value && value.type) {
|
|
1591
|
+
case "ArrayBindingPattern":
|
|
1592
|
+
case "ObjectBindingPattern":
|
|
1593
|
+
return {
|
|
1594
|
+
...p,
|
|
1595
|
+
children: [ws, name, ": ", nonMatcherBindings(value)]
|
|
1596
|
+
};
|
|
1597
|
+
case "Identifier":
|
|
1598
|
+
return p;
|
|
1599
|
+
case "Literal":
|
|
1600
|
+
case "RegularExpressionLiteral":
|
|
1601
|
+
case "StringLiteral":
|
|
1602
|
+
default:
|
|
1603
|
+
return {
|
|
1604
|
+
...p,
|
|
1605
|
+
children: [ws, name, sep]
|
|
1606
|
+
};
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
case "PinProperty":
|
|
1610
|
+
case "BindingRestProperty":
|
|
1611
|
+
default:
|
|
1612
|
+
return p;
|
|
1613
|
+
}
|
|
1614
|
+
});
|
|
1615
|
+
}
|
|
1616
|
+
function nonMatcherBindings(pattern) {
|
|
1617
|
+
switch (pattern.type) {
|
|
1618
|
+
case "ArrayBindingPattern": {
|
|
1619
|
+
const elements = elideMatchersFromArrayBindings(pattern.elements);
|
|
1620
|
+
const children = ["[", elements, "]"];
|
|
597
1621
|
return {
|
|
598
|
-
|
|
1622
|
+
...pattern,
|
|
599
1623
|
children,
|
|
600
|
-
|
|
1624
|
+
elements
|
|
601
1625
|
};
|
|
602
1626
|
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
1627
|
+
case "PostRestBindingElements": {
|
|
1628
|
+
const els = elideMatchersFromArrayBindings(pattern.children[1]);
|
|
1629
|
+
return {
|
|
1630
|
+
...pattern,
|
|
1631
|
+
children: [
|
|
1632
|
+
pattern.children[0],
|
|
1633
|
+
els,
|
|
1634
|
+
...pattern.children.slice(2)
|
|
1635
|
+
]
|
|
1636
|
+
};
|
|
1637
|
+
}
|
|
1638
|
+
case "ObjectBindingPattern":
|
|
1639
|
+
return ["{", elideMatchersFromPropertyBindings(pattern.properties), "}"];
|
|
1640
|
+
default:
|
|
1641
|
+
return pattern;
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
function aggregateDuplicateBindings(bindings, ReservedWord) {
|
|
1645
|
+
const props = gatherRecursiveAll(bindings, (n) => n.type === "BindingProperty");
|
|
1646
|
+
const arrayBindings = gatherRecursiveAll(bindings, (n) => n.type === "ArrayBindingPattern");
|
|
1647
|
+
arrayBindings.forEach((a) => {
|
|
1648
|
+
const { elements } = a;
|
|
1649
|
+
elements.forEach((element) => {
|
|
1650
|
+
if (Array.isArray(element)) {
|
|
1651
|
+
const [, e] = element;
|
|
1652
|
+
if (e.type === "Identifier") {
|
|
1653
|
+
props.push(e);
|
|
1654
|
+
} else if (e.type === "BindingRestElement") {
|
|
1655
|
+
props.push(e);
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
});
|
|
1659
|
+
});
|
|
1660
|
+
const declarations = [];
|
|
1661
|
+
const propsGroupedByName = /* @__PURE__ */ new Map();
|
|
1662
|
+
for (const p of props) {
|
|
1663
|
+
const { name, value } = p;
|
|
1664
|
+
const key = value?.name || name?.name || name;
|
|
1665
|
+
if (propsGroupedByName.has(key)) {
|
|
1666
|
+
propsGroupedByName.get(key).push(p);
|
|
1667
|
+
} else {
|
|
1668
|
+
propsGroupedByName.set(key, [p]);
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
propsGroupedByName.forEach((shared, key) => {
|
|
1672
|
+
if (!key)
|
|
1673
|
+
return;
|
|
1674
|
+
if (ReservedWord({
|
|
1675
|
+
pos: 0,
|
|
1676
|
+
input: key
|
|
1677
|
+
})) {
|
|
1678
|
+
shared.forEach((p) => {
|
|
1679
|
+
const ref = {
|
|
1680
|
+
type: "Ref",
|
|
1681
|
+
base: `_${key}`,
|
|
1682
|
+
id: key
|
|
1683
|
+
};
|
|
1684
|
+
aliasBinding(p, ref);
|
|
1685
|
+
});
|
|
1686
|
+
return;
|
|
1687
|
+
}
|
|
1688
|
+
if (shared.length === 1)
|
|
1689
|
+
return;
|
|
1690
|
+
const refs = shared.map((p) => {
|
|
1691
|
+
const ref = {
|
|
1692
|
+
type: "Ref",
|
|
1693
|
+
base: key,
|
|
1694
|
+
id: key
|
|
1695
|
+
};
|
|
1696
|
+
aliasBinding(p, ref);
|
|
1697
|
+
return ref;
|
|
1698
|
+
});
|
|
1699
|
+
declarations.push(["const ", key, " = [", ...refs.map((r, i) => {
|
|
1700
|
+
return i === 0 ? r : [", ", r];
|
|
1701
|
+
}), "]"]);
|
|
1702
|
+
});
|
|
1703
|
+
return declarations;
|
|
1704
|
+
}
|
|
1705
|
+
function processPatternMatching(statements, ReservedWord) {
|
|
1706
|
+
gatherRecursiveAll(statements, (n) => n.type === "SwitchStatement" || n.type === "SwitchExpression").forEach((s) => {
|
|
1707
|
+
const { caseBlock } = s;
|
|
1708
|
+
const { clauses } = caseBlock;
|
|
1709
|
+
let errors = false;
|
|
1710
|
+
let isPattern = false;
|
|
1711
|
+
if (clauses.some((c) => c.type === "PatternClause")) {
|
|
1712
|
+
isPattern = true;
|
|
1713
|
+
clauses.forEach((c) => {
|
|
1714
|
+
if (!(c.type === "PatternClause" || c.type === "DefaultClause")) {
|
|
1715
|
+
errors = true;
|
|
1716
|
+
c.children.push({
|
|
1717
|
+
type: "Error",
|
|
1718
|
+
message: "Can't mix pattern matching and non-pattern matching clauses"
|
|
1719
|
+
});
|
|
1720
|
+
}
|
|
1721
|
+
});
|
|
1722
|
+
}
|
|
1723
|
+
if (errors || !isPattern)
|
|
1724
|
+
return;
|
|
1725
|
+
let { expression } = s;
|
|
1726
|
+
if (expression.type === "ParenthesizedExpression") {
|
|
1727
|
+
expression = expression.expression;
|
|
1728
|
+
}
|
|
1729
|
+
let ref = needsRef(expression, "m") || expression;
|
|
1730
|
+
let hoistDec = ref !== expression ? [["", ["const ", ref, " = ", expression], ";"]] : void 0;
|
|
1731
|
+
let prev = [], root = prev;
|
|
1732
|
+
const l = clauses.length;
|
|
1733
|
+
clauses.forEach((c, i) => {
|
|
1734
|
+
if (c.type === "DefaultClause") {
|
|
1735
|
+
prev.push(c.block);
|
|
1736
|
+
return;
|
|
1737
|
+
}
|
|
1738
|
+
let { patterns, block } = c;
|
|
1739
|
+
let pattern = patterns[0];
|
|
1740
|
+
const indent = block.expressions?.[0]?.[0] || "";
|
|
1741
|
+
const alternativeConditions = patterns.map((pattern2, i2) => {
|
|
1742
|
+
const conditions = [];
|
|
1743
|
+
getPatternConditions(pattern2, ref, conditions);
|
|
1744
|
+
return conditions;
|
|
1745
|
+
});
|
|
1746
|
+
const conditionExpression = alternativeConditions.map((conditions, i2) => {
|
|
1747
|
+
const conditionArray = conditions.map((c2, i3) => {
|
|
1748
|
+
if (i3 === 0)
|
|
1749
|
+
return c2;
|
|
1750
|
+
return [" && ", ...c2];
|
|
1751
|
+
});
|
|
1752
|
+
if (i2 === 0)
|
|
1753
|
+
return conditionArray;
|
|
1754
|
+
return [" || ", ...conditionArray];
|
|
1755
|
+
});
|
|
1756
|
+
const condition = {
|
|
1757
|
+
type: "ParenthesizedExpression",
|
|
1758
|
+
children: ["(", conditionExpression, ")"],
|
|
1759
|
+
expression: conditionExpression
|
|
1760
|
+
};
|
|
1761
|
+
const prefix = [];
|
|
1762
|
+
switch (pattern.type) {
|
|
1763
|
+
case "ArrayBindingPattern":
|
|
1764
|
+
if (pattern.length === 0)
|
|
1765
|
+
break;
|
|
1766
|
+
case "ObjectBindingPattern": {
|
|
1767
|
+
if (pattern.properties?.length === 0)
|
|
1768
|
+
break;
|
|
1769
|
+
let [splices, thisAssignments] = gatherBindingCode(pattern);
|
|
1770
|
+
const patternBindings = nonMatcherBindings(pattern);
|
|
1771
|
+
splices = splices.map((s2) => [", ", nonMatcherBindings(s2)]);
|
|
1772
|
+
thisAssignments = thisAssignments.map((a) => [indent, a, ";"]);
|
|
1773
|
+
const duplicateDeclarations = aggregateDuplicateBindings([patternBindings, splices], ReservedWord);
|
|
1774
|
+
prefix.push([indent, "const ", patternBindings, " = ", ref, splices, ";"]);
|
|
1775
|
+
prefix.push(...thisAssignments);
|
|
1776
|
+
prefix.push(...duplicateDeclarations.map((d) => [indent, d, ";"]));
|
|
1777
|
+
break;
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
block.expressions.unshift(...prefix);
|
|
1781
|
+
const next = [];
|
|
1782
|
+
if (block.bare) {
|
|
1783
|
+
block.children.unshift(" {");
|
|
1784
|
+
block.children.push("}");
|
|
1785
|
+
block.bare = false;
|
|
1786
|
+
}
|
|
1787
|
+
if (i < l - 1)
|
|
1788
|
+
next.push("\n", "else ");
|
|
1789
|
+
prev.push(["", {
|
|
1790
|
+
type: "IfStatement",
|
|
1791
|
+
children: ["if", condition, block, next],
|
|
1792
|
+
then: block,
|
|
1793
|
+
else: next,
|
|
1794
|
+
hoistDec
|
|
1795
|
+
}]);
|
|
1796
|
+
hoistDec = void 0;
|
|
1797
|
+
prev = next;
|
|
1798
|
+
});
|
|
1799
|
+
if (s.type === "SwitchExpression") {
|
|
1800
|
+
insertReturn(root[0]);
|
|
1801
|
+
root.splice(0, 1, wrapIIFE(root[0]));
|
|
1802
|
+
}
|
|
1803
|
+
s.type = "PatternMatchingStatement";
|
|
1804
|
+
s.children = [root];
|
|
1805
|
+
addParentPointers(s, s.parent);
|
|
1806
|
+
});
|
|
1807
|
+
}
|
|
1808
|
+
function processPipelineExpressions(statements) {
|
|
1809
|
+
gatherRecursiveAll(statements, (n) => n.type === "PipelineExpression").forEach((s) => {
|
|
1810
|
+
const [ws, , body] = s.children;
|
|
1811
|
+
let [, arg] = s.children;
|
|
1812
|
+
let i = 0, l = body.length;
|
|
1813
|
+
const refDec = [];
|
|
1814
|
+
const children = [ws, refDec];
|
|
1815
|
+
let usingRef = null;
|
|
1816
|
+
for (i = 0; i < l; i++) {
|
|
1817
|
+
const step = body[i];
|
|
1818
|
+
const [leadingComment, pipe, trailingComment, expr] = step;
|
|
1819
|
+
const returns = pipe.token === "||>";
|
|
1820
|
+
let ref, result, returning = returns ? arg : null;
|
|
1821
|
+
if (pipe.token === "|>=") {
|
|
1822
|
+
let initRef;
|
|
1823
|
+
if (i === 0) {
|
|
1824
|
+
outer:
|
|
1825
|
+
switch (arg.type) {
|
|
1826
|
+
case "MemberExpression":
|
|
1827
|
+
if (arg.children.length <= 2)
|
|
1828
|
+
break;
|
|
1829
|
+
case "CallExpression":
|
|
1830
|
+
const access = arg.children.pop();
|
|
1831
|
+
switch (access.type) {
|
|
1832
|
+
case "PropertyAccess":
|
|
1833
|
+
case "SliceExpression":
|
|
1834
|
+
break;
|
|
1835
|
+
default:
|
|
1836
|
+
children.unshift({
|
|
1837
|
+
type: "Error",
|
|
1838
|
+
$loc: pipe.token.$loc,
|
|
1839
|
+
message: `Can't assign to ${access.type}`
|
|
1840
|
+
});
|
|
1841
|
+
arg.children.push(access);
|
|
1842
|
+
break outer;
|
|
1843
|
+
}
|
|
1844
|
+
usingRef = needsRef({});
|
|
1845
|
+
initRef = {
|
|
1846
|
+
type: "AssignmentExpression",
|
|
1847
|
+
children: [usingRef, " = ", arg, ","]
|
|
1848
|
+
};
|
|
1849
|
+
arg = {
|
|
1850
|
+
type: "MemberExpression",
|
|
1851
|
+
children: [usingRef, access]
|
|
1852
|
+
};
|
|
1853
|
+
break;
|
|
1854
|
+
}
|
|
1855
|
+
children.pop();
|
|
1856
|
+
const lhs = [[
|
|
1857
|
+
[refDec, initRef],
|
|
1858
|
+
arg,
|
|
1859
|
+
[],
|
|
1860
|
+
{ token: "=", children: [" = "] }
|
|
1861
|
+
]];
|
|
1862
|
+
Object.assign(s, {
|
|
1863
|
+
type: "AssignmentExpression",
|
|
1864
|
+
children: [lhs, children],
|
|
1865
|
+
names: null,
|
|
1866
|
+
lhs,
|
|
1867
|
+
assigned: arg,
|
|
1868
|
+
exp: children
|
|
1869
|
+
});
|
|
1870
|
+
arg = clone(arg);
|
|
1871
|
+
if (arg.children[0].type === "Ref") {
|
|
1872
|
+
arg.children[0] = usingRef;
|
|
1873
|
+
}
|
|
1874
|
+
} else {
|
|
1875
|
+
children.unshift({
|
|
1876
|
+
type: "Error",
|
|
1877
|
+
$loc: pipe.token.$loc,
|
|
1878
|
+
message: "Can't use |>= in the middle of a pipeline"
|
|
1879
|
+
});
|
|
1880
|
+
}
|
|
1881
|
+
} else {
|
|
1882
|
+
s.children = children;
|
|
1883
|
+
}
|
|
1884
|
+
if (returns && (ref = needsRef(arg))) {
|
|
1885
|
+
usingRef = usingRef || ref;
|
|
1886
|
+
arg = {
|
|
1887
|
+
type: "ParenthesizedExpression",
|
|
1888
|
+
children: ["(", {
|
|
1889
|
+
type: "AssignmentExpression",
|
|
1890
|
+
children: [usingRef, " = ", arg]
|
|
1891
|
+
}, ")"]
|
|
1892
|
+
};
|
|
1893
|
+
returning = usingRef;
|
|
1894
|
+
}
|
|
1895
|
+
[result, returning] = constructPipeStep(
|
|
1896
|
+
{
|
|
1897
|
+
leadingComment: skipIfOnlyWS(leadingComment),
|
|
1898
|
+
trailingComment: skipIfOnlyWS(trailingComment),
|
|
1899
|
+
expr
|
|
1900
|
+
},
|
|
1901
|
+
arg,
|
|
1902
|
+
returning
|
|
1903
|
+
);
|
|
1904
|
+
if (result.type === "ReturnStatement") {
|
|
1905
|
+
if (i < l - 1) {
|
|
1906
|
+
result.children.push({
|
|
1907
|
+
type: "Error",
|
|
1908
|
+
message: "Can't continue a pipeline after returning"
|
|
1909
|
+
});
|
|
1910
|
+
}
|
|
1911
|
+
arg = result;
|
|
1912
|
+
if (children[children.length - 1] === ",") {
|
|
1913
|
+
children.pop();
|
|
1914
|
+
children.push(";");
|
|
1915
|
+
}
|
|
1916
|
+
break;
|
|
1917
|
+
}
|
|
1918
|
+
if (returning) {
|
|
1919
|
+
arg = returning;
|
|
1920
|
+
children.push(result, ",");
|
|
1921
|
+
} else {
|
|
1922
|
+
arg = result;
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
if (usingRef) {
|
|
1926
|
+
refDec.unshift("let ", usingRef, ";");
|
|
1927
|
+
}
|
|
1928
|
+
children.push(arg);
|
|
1929
|
+
addParentPointers(s, s.parent);
|
|
1930
|
+
});
|
|
1931
|
+
}
|
|
1932
|
+
function processProgram(root, config, m, ReservedWord) {
|
|
1933
|
+
assert.equal(m.forbidClassImplicitCall.length, 1, "forbidClassImplicitCall");
|
|
1934
|
+
assert.equal(m.forbidIndentedApplication.length, 1, "forbidIndentedApplication");
|
|
1935
|
+
assert.equal(m.forbidTrailingMemberProperty.length, 1, "forbidTrailingMemberProperty");
|
|
1936
|
+
assert.equal(m.forbidMultiLineImplicitObjectLiteral.length, 1, "forbidMultiLineImplicitObjectLiteral");
|
|
1937
|
+
assert.equal(m.JSXTagStack.length, 0, "JSXTagStack should be empty");
|
|
1938
|
+
addParentPointers(root);
|
|
1939
|
+
const { expressions: statements } = root;
|
|
1940
|
+
processPipelineExpressions(statements);
|
|
1941
|
+
processAssignments(statements);
|
|
1942
|
+
processPatternMatching(statements, ReservedWord);
|
|
1943
|
+
processFunctions(statements, config);
|
|
1944
|
+
processSwitchExpressions(statements);
|
|
1945
|
+
processTryExpressions(statements);
|
|
1946
|
+
hoistRefDecs(statements);
|
|
1947
|
+
gatherRecursiveAll(statements, (n) => n.type === "IterationExpression").forEach((e) => expressionizeIteration(e));
|
|
1948
|
+
statements.unshift(...m.prelude);
|
|
1949
|
+
if (config.autoLet) {
|
|
1950
|
+
createLetDecs(statements, []);
|
|
1951
|
+
} else if (config.autoVar) {
|
|
1952
|
+
createVarDecs(statements, []);
|
|
1953
|
+
}
|
|
1954
|
+
populateRefs(statements);
|
|
1955
|
+
adjustAtBindings(statements);
|
|
1956
|
+
}
|
|
1957
|
+
function findDecs(statements) {
|
|
1958
|
+
const declarationNames = gatherNodes(statements, ({ type }) => type === "Declaration").flatMap((d) => d.names);
|
|
1959
|
+
return new Set(declarationNames);
|
|
1960
|
+
}
|
|
1961
|
+
function populateRefs(statements) {
|
|
1962
|
+
const refNodes = gatherRecursive(statements, ({ type }) => type === "Ref");
|
|
1963
|
+
if (refNodes.length) {
|
|
1964
|
+
const ids = gatherRecursive(statements, (s) => s.type === "Identifier");
|
|
1965
|
+
const names = new Set(ids.flatMap(({ names: names2 }) => names2 || []));
|
|
1966
|
+
refNodes.forEach((ref) => {
|
|
1967
|
+
const { type, base } = ref;
|
|
1968
|
+
if (type !== "Ref")
|
|
1969
|
+
return;
|
|
1970
|
+
ref.type = "Identifier";
|
|
1971
|
+
let n = 0;
|
|
1972
|
+
let name = base;
|
|
1973
|
+
while (names.has(name)) {
|
|
1974
|
+
n++;
|
|
1975
|
+
name = `${base}${n}`;
|
|
1976
|
+
}
|
|
1977
|
+
names.add(name);
|
|
1978
|
+
ref.children = ref.names = [name];
|
|
1979
|
+
});
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
function createVarDecs(statements, scopes, pushVar) {
|
|
1983
|
+
function hasDec(name) {
|
|
1984
|
+
return scopes.some((s) => s.has(name));
|
|
1985
|
+
}
|
|
1986
|
+
function findAssignments(statements2, decs2) {
|
|
1987
|
+
let assignmentStatements2 = gatherNodes(statements2, (node) => {
|
|
1988
|
+
return node.type === "AssignmentExpression";
|
|
1989
|
+
});
|
|
1990
|
+
if (assignmentStatements2.length) {
|
|
1991
|
+
assignmentStatements2 = assignmentStatements2.concat(findAssignments(assignmentStatements2.map((s) => s.children), decs2));
|
|
1992
|
+
}
|
|
1993
|
+
return assignmentStatements2;
|
|
1994
|
+
}
|
|
1995
|
+
if (!pushVar) {
|
|
1996
|
+
pushVar = function(name) {
|
|
1997
|
+
varIds.push(name);
|
|
1998
|
+
decs.add(name);
|
|
1999
|
+
};
|
|
2000
|
+
}
|
|
2001
|
+
const decs = findDecs(statements);
|
|
2002
|
+
scopes.push(decs);
|
|
2003
|
+
const varIds = [];
|
|
2004
|
+
const assignmentStatements = findAssignments(statements, scopes);
|
|
2005
|
+
const undeclaredIdentifiers = assignmentStatements.flatMap((a) => a.names);
|
|
2006
|
+
undeclaredIdentifiers.filter((x, i, a) => {
|
|
2007
|
+
if (!hasDec(x))
|
|
2008
|
+
return a.indexOf(x) === i;
|
|
2009
|
+
}).forEach(pushVar);
|
|
2010
|
+
const fnNodes = gatherNodes(statements, (s) => s.type === "FunctionExpression");
|
|
2011
|
+
const forNodes = gatherNodes(statements, (s) => s.type === "ForStatement");
|
|
2012
|
+
const blockNodes = new Set(gatherNodes(statements, (s) => s.type === "BlockStatement"));
|
|
2013
|
+
fnNodes.forEach(({ block }) => blockNodes.delete(block));
|
|
2014
|
+
forNodes.forEach(({ block }) => blockNodes.delete(block));
|
|
2015
|
+
blockNodes.forEach((block) => {
|
|
2016
|
+
createVarDecs(block.expressions, scopes, pushVar);
|
|
2017
|
+
});
|
|
2018
|
+
forNodes.forEach(({ block, declaration }) => {
|
|
2019
|
+
scopes.push(new Set(declaration.names));
|
|
2020
|
+
createVarDecs(block.expressions, scopes, pushVar);
|
|
2021
|
+
scopes.pop();
|
|
2022
|
+
});
|
|
2023
|
+
fnNodes.forEach(({ block, parameters }) => {
|
|
2024
|
+
scopes.push(new Set(parameters.names));
|
|
2025
|
+
createVarDecs(block.expressions, scopes);
|
|
2026
|
+
scopes.pop();
|
|
2027
|
+
});
|
|
2028
|
+
if (varIds.length) {
|
|
2029
|
+
const indent = getIndent(statements[0]);
|
|
2030
|
+
let delimiter = ";";
|
|
2031
|
+
if (statements[0][1]?.parent?.root) {
|
|
2032
|
+
delimiter = ";\n";
|
|
2033
|
+
}
|
|
2034
|
+
statements.unshift([indent, "var ", varIds.join(", "), delimiter]);
|
|
2035
|
+
}
|
|
2036
|
+
scopes.pop();
|
|
2037
|
+
}
|
|
2038
|
+
function createLetDecs(statements, scopes) {
|
|
2039
|
+
function findVarDecs(statements2, decs) {
|
|
2040
|
+
const declarationNames = gatherRecursive(
|
|
2041
|
+
statements2,
|
|
2042
|
+
(node) => node.type === "Declaration" && node.children && node.children.length > 0 && node.children[0].token && node.children[0].token.startsWith("var") || node.type === "FunctionExpression"
|
|
2043
|
+
).filter((node) => node.type === "Declaration").flatMap((node) => node.names);
|
|
2044
|
+
return new Set(declarationNames);
|
|
2045
|
+
}
|
|
2046
|
+
let declaredIdentifiers = findVarDecs(statements);
|
|
2047
|
+
function hasDec(name) {
|
|
2048
|
+
return declaredIdentifiers.has(name) || scopes.some((s) => s.has(name));
|
|
2049
|
+
}
|
|
2050
|
+
function gatherBlockOrOther(statement) {
|
|
2051
|
+
return gatherNodes(statement, (s) => s.type === "BlockStatement" || s.type === "AssignmentExpression" || s.type === "Declaration").flatMap((node) => {
|
|
2052
|
+
if (node.type == "BlockStatement")
|
|
2053
|
+
return node.bare ? gatherBlockOrOther(node.expressions) : node;
|
|
2054
|
+
else if (node.children && node.children.length)
|
|
2055
|
+
return [...gatherBlockOrOther(node.children), node];
|
|
2056
|
+
else
|
|
2057
|
+
return [];
|
|
2058
|
+
});
|
|
2059
|
+
}
|
|
2060
|
+
let currentScope = /* @__PURE__ */ new Set();
|
|
2061
|
+
scopes.push(currentScope);
|
|
2062
|
+
const fnNodes = gatherNodes(statements, (s) => s.type === "FunctionExpression");
|
|
2063
|
+
const forNodes = gatherNodes(statements, (s) => s.type === "ForStatement");
|
|
2064
|
+
let targetStatements = [];
|
|
2065
|
+
for (const statement of statements) {
|
|
2066
|
+
const nodes = gatherBlockOrOther(statement);
|
|
2067
|
+
let undeclaredIdentifiers = [];
|
|
2068
|
+
for (const node of nodes) {
|
|
2069
|
+
if (node.type == "BlockStatement") {
|
|
2070
|
+
let block = node;
|
|
2071
|
+
let fnNode = fnNodes.find((fnNode2) => fnNode2.block === block);
|
|
2072
|
+
let forNode = forNodes.find((forNode2) => forNode2.block === block);
|
|
2073
|
+
if (fnNode != null) {
|
|
2074
|
+
scopes.push(new Set(fnNode.parameters.names));
|
|
2075
|
+
createLetDecs(block.expressions, scopes);
|
|
2076
|
+
scopes.pop();
|
|
2077
|
+
} else if (forNode != null) {
|
|
2078
|
+
scopes.push(new Set(forNode.declaration.names));
|
|
2079
|
+
createLetDecs(block.expressions, scopes);
|
|
2080
|
+
scopes.pop();
|
|
2081
|
+
} else
|
|
2082
|
+
createLetDecs(block.expressions, scopes);
|
|
2083
|
+
continue;
|
|
2084
|
+
}
|
|
2085
|
+
if (node.names == null)
|
|
2086
|
+
continue;
|
|
2087
|
+
let names = node.names.filter((name) => !hasDec(name));
|
|
2088
|
+
if (node.type == "AssignmentExpression")
|
|
2089
|
+
undeclaredIdentifiers.push(...names);
|
|
2090
|
+
names.forEach((name) => currentScope.add(name));
|
|
2091
|
+
}
|
|
2092
|
+
if (undeclaredIdentifiers.length > 0) {
|
|
2093
|
+
let indent = statement[0];
|
|
2094
|
+
let firstIdentifier = gatherNodes(statement[1], (node) => node.type == "Identifier")[0];
|
|
2095
|
+
if (undeclaredIdentifiers.length == 1 && statement[1].type == "AssignmentExpression" && statement[1].names.length == 1 && statement[1].names[0] == undeclaredIdentifiers[0] && firstIdentifier && firstIdentifier.names == undeclaredIdentifiers[0] && gatherNodes(statement[1], (node) => node.type === "ObjectBindingPattern").length == 0)
|
|
2096
|
+
statement[1].children.unshift(["let "]);
|
|
2097
|
+
else {
|
|
2098
|
+
let tail = "\n";
|
|
2099
|
+
if (gatherNodes(indent, (node) => node.token && node.token.endsWith("\n")).length > 0)
|
|
2100
|
+
tail = void 0;
|
|
2101
|
+
targetStatements.push([indent, "let ", undeclaredIdentifiers.join(", "), tail]);
|
|
2102
|
+
}
|
|
2103
|
+
}
|
|
2104
|
+
targetStatements.push(statement);
|
|
2105
|
+
}
|
|
2106
|
+
scopes.pop();
|
|
2107
|
+
statements.splice(0, statements.length, targetStatements);
|
|
2108
|
+
}
|
|
2109
|
+
function processReturnValue(func) {
|
|
2110
|
+
const { block } = func;
|
|
2111
|
+
const values = gatherRecursiveWithinFunction(
|
|
2112
|
+
block,
|
|
2113
|
+
({ type }) => type === "ReturnValue"
|
|
2114
|
+
);
|
|
2115
|
+
if (!values.length)
|
|
2116
|
+
return false;
|
|
2117
|
+
const ref = {
|
|
2118
|
+
type: "Ref",
|
|
2119
|
+
base: "ret",
|
|
2120
|
+
id: "ret"
|
|
2121
|
+
};
|
|
2122
|
+
let declared;
|
|
2123
|
+
values.forEach((value) => {
|
|
2124
|
+
value.children = [ref];
|
|
2125
|
+
const ancestor = findAncestor(
|
|
2126
|
+
value,
|
|
2127
|
+
({ type }) => type === "Declaration",
|
|
2128
|
+
isFunction
|
|
2129
|
+
);
|
|
2130
|
+
if (ancestor)
|
|
2131
|
+
declared = true;
|
|
2132
|
+
});
|
|
2133
|
+
if (!declared) {
|
|
2134
|
+
let returnType = func.returnType ?? func.signature?.returnType;
|
|
2135
|
+
if (returnType) {
|
|
2136
|
+
const { t } = returnType;
|
|
2137
|
+
if (t.type === "TypePredicate") {
|
|
2138
|
+
returnType = ": boolean";
|
|
2139
|
+
} else if (t.type === "AssertsType") {
|
|
2140
|
+
returnType = void 0;
|
|
2141
|
+
}
|
|
2142
|
+
}
|
|
2143
|
+
block.expressions.unshift([
|
|
2144
|
+
getIndent(block.expressions[0]),
|
|
2145
|
+
{
|
|
2146
|
+
type: "Declaration",
|
|
2147
|
+
children: ["let ", ref, returnType],
|
|
2148
|
+
names: []
|
|
2149
|
+
},
|
|
2150
|
+
";"
|
|
2151
|
+
]);
|
|
2152
|
+
}
|
|
2153
|
+
gatherRecursiveWithinFunction(
|
|
2154
|
+
block,
|
|
2155
|
+
(r) => r.type === "ReturnStatement" && !r.expression
|
|
2156
|
+
).forEach((r) => {
|
|
2157
|
+
r.expression = ref;
|
|
2158
|
+
r.children.splice(-1, 1, " ", ref);
|
|
2159
|
+
});
|
|
2160
|
+
if (block.children.at(-2)?.type !== "ReturnStatement") {
|
|
2161
|
+
block.expressions.push([
|
|
2162
|
+
[getIndent(block.expressions.at(-1))],
|
|
2163
|
+
{
|
|
2164
|
+
type: "ReturnStatement",
|
|
2165
|
+
expression: ref,
|
|
2166
|
+
children: ["return ", ref]
|
|
2167
|
+
}
|
|
2168
|
+
]);
|
|
2169
|
+
}
|
|
2170
|
+
return true;
|
|
2171
|
+
}
|
|
2172
|
+
function processUnaryExpression(pre, exp, post) {
|
|
2173
|
+
if (!(pre.length || post))
|
|
2174
|
+
return exp;
|
|
2175
|
+
if (post?.token === "?") {
|
|
2176
|
+
post = {
|
|
2177
|
+
$loc: post.$loc,
|
|
2178
|
+
token: " != null"
|
|
2179
|
+
};
|
|
2180
|
+
switch (exp.type) {
|
|
2181
|
+
case "Identifier":
|
|
2182
|
+
case "Literal":
|
|
2183
|
+
case "AmpersandRef":
|
|
2184
|
+
return {
|
|
2185
|
+
...exp,
|
|
2186
|
+
children: [...pre, ...exp.children, post]
|
|
2187
|
+
};
|
|
2188
|
+
default:
|
|
2189
|
+
const expression = {
|
|
2190
|
+
...exp,
|
|
2191
|
+
children: [...pre, "(", exp.children, ")", post]
|
|
2192
|
+
};
|
|
2193
|
+
return {
|
|
2194
|
+
type: "ParenthesizedExpression",
|
|
2195
|
+
children: ["(", expression, ")"],
|
|
2196
|
+
expression
|
|
2197
|
+
};
|
|
2198
|
+
}
|
|
2199
|
+
}
|
|
2200
|
+
if (exp.type === "Literal") {
|
|
2201
|
+
if (pre.length === 1 && pre[0].token === "-") {
|
|
2202
|
+
const children = [pre[0], ...exp.children];
|
|
2203
|
+
if (post)
|
|
2204
|
+
exp.children.push(post);
|
|
2205
|
+
return {
|
|
2206
|
+
type: "Literal",
|
|
2207
|
+
children,
|
|
2208
|
+
raw: `-${exp.raw}`
|
|
2209
|
+
};
|
|
2210
|
+
}
|
|
2211
|
+
}
|
|
2212
|
+
const l = pre.length;
|
|
2213
|
+
if (l) {
|
|
2214
|
+
const last = pre[l - 1];
|
|
2215
|
+
if (last.type === "Await" && last.op) {
|
|
2216
|
+
if (exp.type !== "ParenthesizedExpression") {
|
|
2217
|
+
exp = ["(", exp, ")"];
|
|
2218
|
+
}
|
|
2219
|
+
exp = {
|
|
2220
|
+
type: "CallExpression",
|
|
2221
|
+
children: [" Promise", last.op, exp]
|
|
614
2222
|
};
|
|
615
2223
|
}
|
|
616
2224
|
}
|
|
@@ -619,13 +2227,198 @@ var Civet = (() => {
|
|
|
619
2227
|
children: [...pre, exp, post]
|
|
620
2228
|
};
|
|
621
2229
|
}
|
|
2230
|
+
function prune2(node) {
|
|
2231
|
+
if (node === null || node === void 0)
|
|
2232
|
+
return;
|
|
2233
|
+
if (node.length === 0)
|
|
2234
|
+
return;
|
|
2235
|
+
if (Array.isArray(node)) {
|
|
2236
|
+
const a = node.map((n) => prune2(n)).filter((n) => !!n);
|
|
2237
|
+
if (a.length > 1)
|
|
2238
|
+
return a;
|
|
2239
|
+
if (a.length === 1)
|
|
2240
|
+
return a[0];
|
|
2241
|
+
return;
|
|
2242
|
+
}
|
|
2243
|
+
if (node.children != null) {
|
|
2244
|
+
node.children = prune2(node.children);
|
|
2245
|
+
return node;
|
|
2246
|
+
}
|
|
2247
|
+
return node;
|
|
2248
|
+
}
|
|
2249
|
+
function reorderBindingRestProperty(props) {
|
|
2250
|
+
const names = props.flatMap((p) => p.names);
|
|
2251
|
+
let restIndex = -1;
|
|
2252
|
+
let restCount = 0;
|
|
2253
|
+
props.forEach(({ type }, i) => {
|
|
2254
|
+
if (type === "BindingRestProperty") {
|
|
2255
|
+
if (restIndex < 0)
|
|
2256
|
+
restIndex = i;
|
|
2257
|
+
restCount++;
|
|
2258
|
+
}
|
|
2259
|
+
});
|
|
2260
|
+
if (restCount === 0) {
|
|
2261
|
+
return {
|
|
2262
|
+
children: props,
|
|
2263
|
+
names
|
|
2264
|
+
};
|
|
2265
|
+
} else if (restCount === 1) {
|
|
2266
|
+
let after = props.slice(restIndex + 1);
|
|
2267
|
+
let rest = props[restIndex];
|
|
2268
|
+
props = props.slice(0, restIndex);
|
|
2269
|
+
if (after.length) {
|
|
2270
|
+
const [restDelim] = rest.children.slice(-1), lastAfterProp = after[after.length - 1], lastAfterChildren = lastAfterProp.children, [lastDelim] = lastAfterChildren.slice(-1);
|
|
2271
|
+
rest = { ...rest, children: [...rest.children.slice(0, -1), lastDelim] };
|
|
2272
|
+
after = [...after.slice(0, -1), { ...lastAfterProp, children: [...lastAfterChildren.slice(0, -1), restDelim] }];
|
|
2273
|
+
}
|
|
2274
|
+
const children = [...props, ...after, rest];
|
|
2275
|
+
return {
|
|
2276
|
+
children,
|
|
2277
|
+
names
|
|
2278
|
+
};
|
|
2279
|
+
}
|
|
2280
|
+
return {
|
|
2281
|
+
children: [{
|
|
2282
|
+
type: "Error",
|
|
2283
|
+
message: "Multiple rest properties in object pattern"
|
|
2284
|
+
}, props]
|
|
2285
|
+
};
|
|
2286
|
+
}
|
|
2287
|
+
function replaceNodes(root, predicate, replacer) {
|
|
2288
|
+
if (root == null)
|
|
2289
|
+
return root;
|
|
2290
|
+
const array = Array.isArray(root) ? root : root.children;
|
|
2291
|
+
if (!array)
|
|
2292
|
+
return root;
|
|
2293
|
+
array.forEach((node, i) => {
|
|
2294
|
+
if (node == null)
|
|
2295
|
+
return;
|
|
2296
|
+
if (predicate(node)) {
|
|
2297
|
+
array[i] = replacer(node, root);
|
|
2298
|
+
} else {
|
|
2299
|
+
replaceNodes(node, predicate, replacer);
|
|
2300
|
+
}
|
|
2301
|
+
});
|
|
2302
|
+
return root;
|
|
2303
|
+
}
|
|
2304
|
+
function skipIfOnlyWS(target) {
|
|
2305
|
+
if (!target)
|
|
2306
|
+
return target;
|
|
2307
|
+
if (Array.isArray(target)) {
|
|
2308
|
+
if (target.length === 1) {
|
|
2309
|
+
return skipIfOnlyWS(target[0]);
|
|
2310
|
+
} else if (target.every((e) => skipIfOnlyWS(e) === void 0)) {
|
|
2311
|
+
return void 0;
|
|
2312
|
+
}
|
|
2313
|
+
return target;
|
|
2314
|
+
}
|
|
2315
|
+
if (target.token != null && target.token.trim() === "") {
|
|
2316
|
+
return void 0;
|
|
2317
|
+
}
|
|
2318
|
+
return target;
|
|
2319
|
+
}
|
|
2320
|
+
function typeOfJSX(node, config, getRef) {
|
|
2321
|
+
switch (node.type) {
|
|
2322
|
+
case "JSXElement":
|
|
2323
|
+
return typeOfJSXElement(node, config, getRef);
|
|
2324
|
+
case "JSXFragment":
|
|
2325
|
+
return typeOfJSXFragment(node, config, getRef);
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2328
|
+
function typeOfJSXElement(node, config, getRef) {
|
|
2329
|
+
if (config.solid) {
|
|
2330
|
+
if (config.server && !config.client) {
|
|
2331
|
+
return ["string"];
|
|
2332
|
+
}
|
|
2333
|
+
let { tag } = node;
|
|
2334
|
+
const clientType = tag[0] === tag[0].toLowerCase() ? [getRef("IntrinsicElements"), '<"', tag, '">'] : ["ReturnType<typeof ", tag, ">"];
|
|
2335
|
+
if (config.server) {
|
|
2336
|
+
return ["string", " | ", clientType];
|
|
2337
|
+
} else {
|
|
2338
|
+
return clientType;
|
|
2339
|
+
}
|
|
2340
|
+
}
|
|
2341
|
+
}
|
|
2342
|
+
function typeOfJSXFragment(node, config, getRef) {
|
|
2343
|
+
if (config.solid) {
|
|
2344
|
+
let type = [];
|
|
2345
|
+
let lastType;
|
|
2346
|
+
for (let child of node.jsxChildren) {
|
|
2347
|
+
switch (child.type) {
|
|
2348
|
+
case "JSXText":
|
|
2349
|
+
if (lastType !== "JSXText") {
|
|
2350
|
+
type.push("string");
|
|
2351
|
+
}
|
|
2352
|
+
break;
|
|
2353
|
+
case "JSXElement":
|
|
2354
|
+
type.push(typeOfJSXElement(child, config, getRef));
|
|
2355
|
+
break;
|
|
2356
|
+
case "JSXFragment":
|
|
2357
|
+
type.push(...typeOfJSXFragment(child, config, getRef));
|
|
2358
|
+
break;
|
|
2359
|
+
case "JSXChildExpression":
|
|
2360
|
+
if (child.expression) {
|
|
2361
|
+
type.push(["typeof ", child.expression]);
|
|
2362
|
+
}
|
|
2363
|
+
break;
|
|
2364
|
+
default:
|
|
2365
|
+
throw new Error(`unknown child in JSXFragment: ${JSON.stringify(child)}`);
|
|
2366
|
+
}
|
|
2367
|
+
lastType = child.type;
|
|
2368
|
+
}
|
|
2369
|
+
if (type.length === 1) {
|
|
2370
|
+
return type[0];
|
|
2371
|
+
} else {
|
|
2372
|
+
type = type.flatMap((t) => [t, ", "]);
|
|
2373
|
+
type.pop();
|
|
2374
|
+
return ["[", type, "]"];
|
|
2375
|
+
}
|
|
2376
|
+
}
|
|
2377
|
+
}
|
|
2378
|
+
function wrapIIFE(exp, async) {
|
|
2379
|
+
let prefix, suffix;
|
|
2380
|
+
if (async) {
|
|
2381
|
+
prefix = "(async ()=>";
|
|
2382
|
+
suffix = ")()";
|
|
2383
|
+
} else if (hasAwait(exp)) {
|
|
2384
|
+
prefix = "(await (async ()=>";
|
|
2385
|
+
suffix = ")())";
|
|
2386
|
+
} else {
|
|
2387
|
+
prefix = "(()=>";
|
|
2388
|
+
suffix = ")()";
|
|
2389
|
+
}
|
|
2390
|
+
const expressions = Array.isArray(exp) ? [[...exp]] : [exp];
|
|
2391
|
+
const block = {
|
|
2392
|
+
type: "BlockStatement",
|
|
2393
|
+
expressions,
|
|
2394
|
+
children: ["{", expressions, "}"],
|
|
2395
|
+
bare: false
|
|
2396
|
+
};
|
|
2397
|
+
return [
|
|
2398
|
+
prefix,
|
|
2399
|
+
block,
|
|
2400
|
+
suffix
|
|
2401
|
+
];
|
|
2402
|
+
}
|
|
622
2403
|
module.exports = {
|
|
2404
|
+
addParentPointers,
|
|
2405
|
+
addPostfixStatement,
|
|
2406
|
+
adjustAtBindings,
|
|
2407
|
+
adjustBindingElements,
|
|
623
2408
|
aliasBinding,
|
|
2409
|
+
arrayElementHasTrailingComma,
|
|
2410
|
+
attachPostfixStatementAsExpression,
|
|
624
2411
|
blockWithPrefix,
|
|
625
2412
|
clone,
|
|
2413
|
+
constructInvocation,
|
|
2414
|
+
constructPipeStep,
|
|
626
2415
|
convertMethodToFunction,
|
|
627
2416
|
convertObjectToJSXAttributes,
|
|
2417
|
+
dedentBlockString,
|
|
2418
|
+
dedentBlockSubstitutions,
|
|
628
2419
|
deepCopy,
|
|
2420
|
+
expressionizeIfClause,
|
|
2421
|
+
expressionizeIteration,
|
|
629
2422
|
findAncestor,
|
|
630
2423
|
forRange,
|
|
631
2424
|
gatherBindingCode,
|
|
@@ -638,17 +2431,36 @@ var Civet = (() => {
|
|
|
638
2431
|
hasAwait,
|
|
639
2432
|
hasYield,
|
|
640
2433
|
hoistRefDecs,
|
|
2434
|
+
insertReturn,
|
|
2435
|
+
insertSwitchReturns,
|
|
641
2436
|
insertTrimmingSpace,
|
|
2437
|
+
isEmptyBareBlock,
|
|
642
2438
|
isFunction,
|
|
2439
|
+
isVoidType,
|
|
2440
|
+
isWhitespaceOrEmpty,
|
|
643
2441
|
lastAccessInCallExpression,
|
|
644
2442
|
literalValue,
|
|
2443
|
+
makeAsConst,
|
|
2444
|
+
makeLeftHandSideExpression,
|
|
645
2445
|
modifyString,
|
|
2446
|
+
needsRef,
|
|
2447
|
+
processBinaryOpExpression,
|
|
2448
|
+
processCallMemberExpression,
|
|
646
2449
|
processCoffeeInterpolation,
|
|
647
2450
|
processConstAssignmentDeclaration,
|
|
648
2451
|
processLetAssignmentDeclaration,
|
|
2452
|
+
processParams,
|
|
2453
|
+
processProgram,
|
|
2454
|
+
processReturnValue,
|
|
649
2455
|
processUnaryExpression,
|
|
2456
|
+
prune: prune2,
|
|
650
2457
|
quoteString,
|
|
651
|
-
removeParentPointers
|
|
2458
|
+
removeParentPointers,
|
|
2459
|
+
reorderBindingRestProperty,
|
|
2460
|
+
replaceNodes,
|
|
2461
|
+
skipIfOnlyWS,
|
|
2462
|
+
typeOfJSX,
|
|
2463
|
+
wrapIIFE
|
|
652
2464
|
};
|
|
653
2465
|
}
|
|
654
2466
|
});
|
|
@@ -1943,13 +3755,13 @@ ${input.slice(result.pos)}
|
|
|
1943
3755
|
var $R65 = $R(new RegExp("[ \\t]*", "suy"));
|
|
1944
3756
|
var Program$0 = $TS($S(Reset, Init, $E(EOS), TopLevelStatements, __), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
|
|
1945
3757
|
var statements = $4;
|
|
1946
|
-
|
|
3758
|
+
processProgram({
|
|
1947
3759
|
type: "BlockStatement",
|
|
1948
3760
|
expressions: statements,
|
|
1949
3761
|
children: [statements],
|
|
1950
3762
|
bare: true,
|
|
1951
3763
|
root: true
|
|
1952
|
-
});
|
|
3764
|
+
}, module.config, module, ReservedWord);
|
|
1953
3765
|
return $0;
|
|
1954
3766
|
});
|
|
1955
3767
|
function Program(state) {
|
|
@@ -2324,7 +4136,7 @@ ${input.slice(result.pos)}
|
|
|
2324
4136
|
var ws = $4;
|
|
2325
4137
|
var args = $5;
|
|
2326
4138
|
var close = $6;
|
|
2327
|
-
if (args.length === 1 && args[0].type === "IterationExpression" && args[0].subtype !== "DoStatement" && !args[0].async &&
|
|
4139
|
+
if (args.length === 1 && args[0].type === "IterationExpression" && args[0].subtype !== "DoStatement" && !args[0].async && isEmptyBareBlock(args[0].block)) {
|
|
2328
4140
|
return $skip;
|
|
2329
4141
|
}
|
|
2330
4142
|
return [ta?.[0], open, insertTrimmingSpace(ws, ""), args, close];
|
|
@@ -2729,7 +4541,7 @@ ${input.slice(result.pos)}
|
|
|
2729
4541
|
}
|
|
2730
4542
|
var BinaryOpExpression$0 = $TS($S(UnaryExpression, $Q(BinaryOpRHS)), function($skip, $loc, $0, $1, $2) {
|
|
2731
4543
|
if ($2.length)
|
|
2732
|
-
return
|
|
4544
|
+
return processBinaryOpExpression($0);
|
|
2733
4545
|
return $1;
|
|
2734
4546
|
});
|
|
2735
4547
|
function BinaryOpExpression(state) {
|
|
@@ -3719,7 +5531,7 @@ ${input.slice(result.pos)}
|
|
|
3719
5531
|
var ExtendsTarget$0 = $TS($S(ExpressionWithIndentedApplicationForbidden, $E(TypeArguments)), function($skip, $loc, $0, $1, $2) {
|
|
3720
5532
|
var exp = $1;
|
|
3721
5533
|
var ta = $2;
|
|
3722
|
-
exp =
|
|
5534
|
+
exp = makeLeftHandSideExpression(exp);
|
|
3723
5535
|
if (ta)
|
|
3724
5536
|
return [exp, ta];
|
|
3725
5537
|
return exp;
|
|
@@ -4270,14 +6082,14 @@ ${input.slice(result.pos)}
|
|
|
4270
6082
|
}
|
|
4271
6083
|
var CallExpression$0 = $TS($S($EXPECT($L14, fail, 'CallExpression "super"'), ArgumentsWithTrailingMemberExpressions, $Q(CallExpressionRest)), function($skip, $loc, $0, $1, $2, $3) {
|
|
4272
6084
|
var rest = $3;
|
|
4273
|
-
return
|
|
6085
|
+
return processCallMemberExpression({
|
|
4274
6086
|
type: "CallExpression",
|
|
4275
6087
|
children: [$1, ...$2, ...rest.flat()]
|
|
4276
6088
|
});
|
|
4277
6089
|
});
|
|
4278
6090
|
var CallExpression$1 = $TS($S($EXPECT($L15, fail, 'CallExpression "import"'), ArgumentsWithTrailingMemberExpressions, $Q(CallExpressionRest)), function($skip, $loc, $0, $1, $2, $3) {
|
|
4279
6091
|
var rest = $3;
|
|
4280
|
-
return
|
|
6092
|
+
return processCallMemberExpression({
|
|
4281
6093
|
type: "CallExpression",
|
|
4282
6094
|
children: [$1, ...$2, ...rest.flat()]
|
|
4283
6095
|
});
|
|
@@ -4288,7 +6100,7 @@ ${input.slice(result.pos)}
|
|
|
4288
6100
|
var rest = $3;
|
|
4289
6101
|
if (rest.length || trailing.length) {
|
|
4290
6102
|
rest = rest.flat();
|
|
4291
|
-
return
|
|
6103
|
+
return processCallMemberExpression({
|
|
4292
6104
|
type: "CallExpression",
|
|
4293
6105
|
children: [member, ...trailing, ...rest]
|
|
4294
6106
|
});
|
|
@@ -4431,7 +6243,7 @@ ${input.slice(result.pos)}
|
|
|
4431
6243
|
var MemberExpression$0 = $TS($S($C(PrimaryExpression, SuperProperty, MetaProperty), $Q(MemberExpressionRest)), function($skip, $loc, $0, $1, $2) {
|
|
4432
6244
|
var rest = $2;
|
|
4433
6245
|
if (rest.length || Array.isArray($1)) {
|
|
4434
|
-
return
|
|
6246
|
+
return processCallMemberExpression({
|
|
4435
6247
|
type: "MemberExpression",
|
|
4436
6248
|
children: [$1, ...rest].flat()
|
|
4437
6249
|
});
|
|
@@ -5242,7 +7054,7 @@ ${input.slice(result.pos)}
|
|
|
5242
7054
|
var props = $0;
|
|
5243
7055
|
if (!props)
|
|
5244
7056
|
return { children: [], names: [] };
|
|
5245
|
-
return
|
|
7057
|
+
return reorderBindingRestProperty(props);
|
|
5246
7058
|
});
|
|
5247
7059
|
function ObjectBindingPatternContent(state) {
|
|
5248
7060
|
let eventData;
|
|
@@ -5334,7 +7146,7 @@ ${input.slice(result.pos)}
|
|
|
5334
7146
|
var elements = $0;
|
|
5335
7147
|
if (!elements)
|
|
5336
7148
|
return { children: [], names: [], length: 0 };
|
|
5337
|
-
return
|
|
7149
|
+
return adjustBindingElements(elements);
|
|
5338
7150
|
});
|
|
5339
7151
|
function ArrayBindingPatternContent(state) {
|
|
5340
7152
|
let eventData;
|
|
@@ -5450,7 +7262,7 @@ ${input.slice(result.pos)}
|
|
|
5450
7262
|
var props = $2;
|
|
5451
7263
|
if (!props.length)
|
|
5452
7264
|
return $skip;
|
|
5453
|
-
return
|
|
7265
|
+
return reorderBindingRestProperty(props.flat());
|
|
5454
7266
|
});
|
|
5455
7267
|
function NestedBindingProperties(state) {
|
|
5456
7268
|
let eventData;
|
|
@@ -5626,7 +7438,7 @@ ${input.slice(result.pos)}
|
|
|
5626
7438
|
var elements = $2;
|
|
5627
7439
|
if (!elements.length)
|
|
5628
7440
|
return $skip;
|
|
5629
|
-
return
|
|
7441
|
+
return adjustBindingElements(elements.flat());
|
|
5630
7442
|
});
|
|
5631
7443
|
function NestedBindingElements(state) {
|
|
5632
7444
|
let eventData;
|
|
@@ -5813,7 +7625,7 @@ ${input.slice(result.pos)}
|
|
|
5813
7625
|
var FunctionDeclaration$0 = $TS($S(FunctionExpression), function($skip, $loc, $0, $1) {
|
|
5814
7626
|
if ($1.id)
|
|
5815
7627
|
return $1;
|
|
5816
|
-
return
|
|
7628
|
+
return makeLeftHandSideExpression($1);
|
|
5817
7629
|
});
|
|
5818
7630
|
function FunctionDeclaration(state) {
|
|
5819
7631
|
let eventData;
|
|
@@ -6099,9 +7911,10 @@ ${input.slice(result.pos)}
|
|
|
6099
7911
|
return result;
|
|
6100
7912
|
}
|
|
6101
7913
|
}
|
|
6102
|
-
var AmpersandBlockRHSBody$0 = $TS($S($E($S($N(_), $P(CallExpressionRest))), $E($S($N($EXPECT($R3, fail, "AmpersandBlockRHSBody /[&]/")), $P(BinaryOpRHS)))), function($skip, $loc, $0, $1, $2) {
|
|
7914
|
+
var AmpersandBlockRHSBody$0 = $TS($S($E($S($N(_), $P(CallExpressionRest))), $E(QuestionMark), $E($S($N($EXPECT($R3, fail, "AmpersandBlockRHSBody /[&]/")), $P(BinaryOpRHS)))), function($skip, $loc, $0, $1, $2, $3) {
|
|
6103
7915
|
var callExpRest = $1;
|
|
6104
|
-
var
|
|
7916
|
+
var unaryPostfix = $2;
|
|
7917
|
+
var binopRHS = $3;
|
|
6105
7918
|
if (!callExpRest && !binopRHS)
|
|
6106
7919
|
return $skip;
|
|
6107
7920
|
const ref = {
|
|
@@ -6109,7 +7922,7 @@ ${input.slice(result.pos)}
|
|
|
6109
7922
|
base: "$",
|
|
6110
7923
|
id: "$"
|
|
6111
7924
|
};
|
|
6112
|
-
|
|
7925
|
+
let exp = {
|
|
6113
7926
|
type: "AmpersandRef",
|
|
6114
7927
|
children: [ref],
|
|
6115
7928
|
names: [],
|
|
@@ -6118,9 +7931,12 @@ ${input.slice(result.pos)}
|
|
|
6118
7931
|
if (callExpRest) {
|
|
6119
7932
|
exp.children.push(...callExpRest[1]);
|
|
6120
7933
|
}
|
|
7934
|
+
if (unaryPostfix) {
|
|
7935
|
+
exp = processUnaryExpression([], exp, unaryPostfix);
|
|
7936
|
+
}
|
|
6121
7937
|
if (binopRHS) {
|
|
6122
7938
|
return {
|
|
6123
|
-
children:
|
|
7939
|
+
children: processBinaryOpExpression([exp, binopRHS[1]]),
|
|
6124
7940
|
ref
|
|
6125
7941
|
};
|
|
6126
7942
|
}
|
|
@@ -8972,7 +10788,7 @@ ${input.slice(result.pos)}
|
|
|
8972
10788
|
var statement = $1;
|
|
8973
10789
|
var post = $2;
|
|
8974
10790
|
if (post)
|
|
8975
|
-
return
|
|
10791
|
+
return addPostfixStatement(statement, ...post);
|
|
8976
10792
|
return statement;
|
|
8977
10793
|
});
|
|
8978
10794
|
function PostfixedStatement(state) {
|
|
@@ -9001,7 +10817,7 @@ ${input.slice(result.pos)}
|
|
|
9001
10817
|
var expression = $1;
|
|
9002
10818
|
var post = $2;
|
|
9003
10819
|
if (post)
|
|
9004
|
-
return
|
|
10820
|
+
return attachPostfixStatementAsExpression(expression, post);
|
|
9005
10821
|
return expression;
|
|
9006
10822
|
});
|
|
9007
10823
|
function PostfixedExpression(state) {
|
|
@@ -9030,7 +10846,7 @@ ${input.slice(result.pos)}
|
|
|
9030
10846
|
var expression = $1;
|
|
9031
10847
|
var post = $2;
|
|
9032
10848
|
if (post)
|
|
9033
|
-
return
|
|
10849
|
+
return attachPostfixStatementAsExpression(expression, post);
|
|
9034
10850
|
return expression;
|
|
9035
10851
|
});
|
|
9036
10852
|
function NonPipelinePostfixedExpression(state) {
|
|
@@ -9092,7 +10908,7 @@ ${input.slice(result.pos)}
|
|
|
9092
10908
|
var Statement$7 = LabelledStatement;
|
|
9093
10909
|
var Statement$8 = $TS($S(ExpressionStatement), function($skip, $loc, $0, $1) {
|
|
9094
10910
|
if ($1.type === "ObjectExpression" || $1.type === "FunctionExpression" && !$1.id) {
|
|
9095
|
-
return
|
|
10911
|
+
return makeLeftHandSideExpression($1);
|
|
9096
10912
|
}
|
|
9097
10913
|
return $1;
|
|
9098
10914
|
});
|
|
@@ -9375,7 +11191,7 @@ ${input.slice(result.pos)}
|
|
|
9375
11191
|
var clause = $1;
|
|
9376
11192
|
var b = $2;
|
|
9377
11193
|
var e = $3;
|
|
9378
|
-
return
|
|
11194
|
+
return expressionizeIfClause(clause, b, e);
|
|
9379
11195
|
});
|
|
9380
11196
|
function IfExpression(state) {
|
|
9381
11197
|
let eventData;
|
|
@@ -9403,7 +11219,7 @@ ${input.slice(result.pos)}
|
|
|
9403
11219
|
var clause = $1;
|
|
9404
11220
|
var b = $2;
|
|
9405
11221
|
var e = $3;
|
|
9406
|
-
return
|
|
11222
|
+
return expressionizeIfClause(clause, b, e);
|
|
9407
11223
|
});
|
|
9408
11224
|
function UnlessExpression(state) {
|
|
9409
11225
|
let eventData;
|
|
@@ -10504,7 +12320,7 @@ ${input.slice(result.pos)}
|
|
|
10504
12320
|
var e = $0;
|
|
10505
12321
|
return {
|
|
10506
12322
|
type: "SwitchExpression",
|
|
10507
|
-
children:
|
|
12323
|
+
children: wrapIIFE(e.children),
|
|
10508
12324
|
expression: e.expression,
|
|
10509
12325
|
caseBlock: e.caseBlock
|
|
10510
12326
|
};
|
|
@@ -10871,7 +12687,7 @@ ${input.slice(result.pos)}
|
|
|
10871
12687
|
return {
|
|
10872
12688
|
type: "TryExpression",
|
|
10873
12689
|
blocks: t.blocks,
|
|
10874
|
-
children:
|
|
12690
|
+
children: wrapIIFE(t)
|
|
10875
12691
|
};
|
|
10876
12692
|
});
|
|
10877
12693
|
function TryExpression(state) {
|
|
@@ -11835,7 +13651,7 @@ ${input.slice(result.pos)}
|
|
|
11835
13651
|
var DebuggerExpression$0 = $TS($S(Debugger), function($skip, $loc, $0, $1) {
|
|
11836
13652
|
return {
|
|
11837
13653
|
type: "DebuggerExpression",
|
|
11838
|
-
children:
|
|
13654
|
+
children: wrapIIFE($1)
|
|
11839
13655
|
};
|
|
11840
13656
|
});
|
|
11841
13657
|
function DebuggerExpression(state) {
|
|
@@ -11863,7 +13679,7 @@ ${input.slice(result.pos)}
|
|
|
11863
13679
|
var ThrowExpression$0 = $TS($S(Throw, ExtendedExpression), function($skip, $loc, $0, $1, $2) {
|
|
11864
13680
|
return {
|
|
11865
13681
|
type: "ThrowExpression",
|
|
11866
|
-
children:
|
|
13682
|
+
children: wrapIIFE($0)
|
|
11867
13683
|
};
|
|
11868
13684
|
});
|
|
11869
13685
|
function ThrowExpression(state) {
|
|
@@ -13744,7 +15560,7 @@ ${input.slice(result.pos)}
|
|
|
13744
15560
|
}
|
|
13745
15561
|
}
|
|
13746
15562
|
var TemplateLiteral$0 = $TS($S(TripleTick, $Q($C(TemplateBlockCharacters, TemplateSubstitution)), TripleTick), function($skip, $loc, $0, $1, $2, $3) {
|
|
13747
|
-
return
|
|
15563
|
+
return dedentBlockSubstitutions($0);
|
|
13748
15564
|
});
|
|
13749
15565
|
var TemplateLiteral$1 = $TS($S(Backtick, $Q($C(TemplateCharacters, TemplateSubstitution)), Backtick), function($skip, $loc, $0, $1, $2, $3) {
|
|
13750
15566
|
return {
|
|
@@ -13753,7 +15569,7 @@ ${input.slice(result.pos)}
|
|
|
13753
15569
|
};
|
|
13754
15570
|
});
|
|
13755
15571
|
var TemplateLiteral$2 = $TS($S(TripleDoubleQuote, $Q($C(TripleDoubleStringCharacters, CoffeeStringSubstitution)), TripleDoubleQuote), function($skip, $loc, $0, $1, $2, $3) {
|
|
13756
|
-
return
|
|
15572
|
+
return dedentBlockSubstitutions($0);
|
|
13757
15573
|
});
|
|
13758
15574
|
var TemplateLiteral$3 = $TS($S(TripleSingleQuote, TripleSingleStringCharacters, TripleSingleQuote), function($skip, $loc, $0, $1, $2, $3) {
|
|
13759
15575
|
var s = $1;
|
|
@@ -13761,7 +15577,7 @@ ${input.slice(result.pos)}
|
|
|
13761
15577
|
var e = $3;
|
|
13762
15578
|
return {
|
|
13763
15579
|
type: "TemplateLiteral",
|
|
13764
|
-
children: [s,
|
|
15580
|
+
children: [s, dedentBlockString(str), e]
|
|
13765
15581
|
};
|
|
13766
15582
|
});
|
|
13767
15583
|
var TemplateLiteral$4 = CoffeeInterpolatedDoubleQuotedString;
|
|
@@ -16528,7 +18344,7 @@ ${input.slice(result.pos)}
|
|
|
16528
18344
|
],
|
|
16529
18345
|
jsxChildren: [$1].concat($2.map(([, tag]) => tag))
|
|
16530
18346
|
};
|
|
16531
|
-
const type =
|
|
18347
|
+
const type = typeOfJSX(jsx, module.config, module.getRef);
|
|
16532
18348
|
return type ? [
|
|
16533
18349
|
{ ts: true, children: ["("] },
|
|
16534
18350
|
jsx,
|
|
@@ -17008,7 +18824,7 @@ ${input.slice(result.pos)}
|
|
|
17008
18824
|
}
|
|
17009
18825
|
if (exprs.length === 1) {
|
|
17010
18826
|
let root = exprs[0];
|
|
17011
|
-
while (root.length &&
|
|
18827
|
+
while (root.length && isWhitespaceOrEmpty(root[root.length - 1])) {
|
|
17012
18828
|
root = root.slice(0, -1);
|
|
17013
18829
|
}
|
|
17014
18830
|
while (root?.length === 1)
|
|
@@ -17088,7 +18904,7 @@ ${input.slice(result.pos)}
|
|
|
17088
18904
|
children: [".", id],
|
|
17089
18905
|
name: id
|
|
17090
18906
|
};
|
|
17091
|
-
const expr =
|
|
18907
|
+
const expr = processCallMemberExpression({
|
|
17092
18908
|
type: "CallExpression",
|
|
17093
18909
|
children: [at, access, ...rest.flat()]
|
|
17094
18910
|
});
|
|
@@ -17112,7 +18928,7 @@ ${input.slice(result.pos)}
|
|
|
17112
18928
|
var JSXAttribute$4 = $TS($S(Identifier, $P(InlineJSXCallExpressionRest), $Y(JSXAttributeSpace)), function($skip, $loc, $0, $1, $2, $3) {
|
|
17113
18929
|
var id = $1;
|
|
17114
18930
|
var rest = $2;
|
|
17115
|
-
const expr =
|
|
18931
|
+
const expr = processCallMemberExpression({
|
|
17116
18932
|
type: "CallExpression",
|
|
17117
18933
|
children: [id, ...rest.flat()]
|
|
17118
18934
|
});
|
|
@@ -17310,7 +19126,7 @@ ${input.slice(result.pos)}
|
|
|
17310
19126
|
}
|
|
17311
19127
|
var InlineJSXAttributeValue$0 = $TS($S(InlineJSXUnaryExpression, $Q(InlineJSXBinaryOpRHS)), function($skip, $loc, $0, $1, $2) {
|
|
17312
19128
|
if ($2.length)
|
|
17313
|
-
return
|
|
19129
|
+
return processBinaryOpExpression($0);
|
|
17314
19130
|
return $1;
|
|
17315
19131
|
});
|
|
17316
19132
|
function InlineJSXAttributeValue(state) {
|
|
@@ -17469,7 +19285,7 @@ ${input.slice(result.pos)}
|
|
|
17469
19285
|
var InlineJSXCallExpression$0 = $TS($S($EXPECT($L14, fail, 'InlineJSXCallExpression "super"'), ExplicitArguments, $Q(InlineJSXCallExpressionRest)), function($skip, $loc, $0, $1, $2, $3) {
|
|
17470
19286
|
var args = $2;
|
|
17471
19287
|
var rest = $3;
|
|
17472
|
-
return
|
|
19288
|
+
return processCallMemberExpression({
|
|
17473
19289
|
type: "CallExpression",
|
|
17474
19290
|
children: [
|
|
17475
19291
|
$1,
|
|
@@ -17481,7 +19297,7 @@ ${input.slice(result.pos)}
|
|
|
17481
19297
|
var InlineJSXCallExpression$1 = $TS($S($EXPECT($L15, fail, 'InlineJSXCallExpression "import"'), ExplicitArguments, $Q(InlineJSXCallExpressionRest)), function($skip, $loc, $0, $1, $2, $3) {
|
|
17482
19298
|
var args = $2;
|
|
17483
19299
|
var rest = $3;
|
|
17484
|
-
return
|
|
19300
|
+
return processCallMemberExpression({
|
|
17485
19301
|
type: "CallExpression",
|
|
17486
19302
|
children: [
|
|
17487
19303
|
$1,
|
|
@@ -17495,7 +19311,7 @@ ${input.slice(result.pos)}
|
|
|
17495
19311
|
var rest = $2;
|
|
17496
19312
|
if (rest.length) {
|
|
17497
19313
|
rest = rest.flat();
|
|
17498
|
-
return
|
|
19314
|
+
return processCallMemberExpression({
|
|
17499
19315
|
type: "CallExpression",
|
|
17500
19316
|
children: [member, ...rest]
|
|
17501
19317
|
});
|
|
@@ -17563,7 +19379,7 @@ ${input.slice(result.pos)}
|
|
|
17563
19379
|
var InlineJSXMemberExpression$0 = $TS($S($C(InlineJSXPrimaryExpression, SuperProperty, MetaProperty), $Q(InlineJSXMemberExpressionRest)), function($skip, $loc, $0, $1, $2) {
|
|
17564
19380
|
var rest = $2;
|
|
17565
19381
|
if (rest.length || Array.isArray($1)) {
|
|
17566
|
-
return
|
|
19382
|
+
return processCallMemberExpression({
|
|
17567
19383
|
type: "MemberExpression",
|
|
17568
19384
|
children: [$1, ...rest].flat()
|
|
17569
19385
|
});
|
|
@@ -18656,7 +20472,7 @@ ${input.slice(result.pos)}
|
|
|
18656
20472
|
...block.properties.map((property, i) => {
|
|
18657
20473
|
let init, isString;
|
|
18658
20474
|
if (property.init) {
|
|
18659
|
-
init =
|
|
20475
|
+
init = replaceNodes(
|
|
18660
20476
|
deepCopy(property.init),
|
|
18661
20477
|
(n) => n.type === "Identifier" && names.has(n.name),
|
|
18662
20478
|
(n) => [id, '["', n.name, '"]']
|
|
@@ -19273,7 +21089,10 @@ ${input.slice(result.pos)}
|
|
|
19273
21089
|
var dots = $2;
|
|
19274
21090
|
if (!dots)
|
|
19275
21091
|
return type;
|
|
19276
|
-
|
|
21092
|
+
const ws = getTrimmingSpace(type);
|
|
21093
|
+
if (!ws)
|
|
21094
|
+
return [dots[1], dots[0], type];
|
|
21095
|
+
return [ws, dots[1], dots[0], insertTrimmingSpace(type, "")];
|
|
19277
21096
|
});
|
|
19278
21097
|
function TypeElement(state) {
|
|
19279
21098
|
let eventData;
|
|
@@ -20998,1987 +22817,215 @@ ${input.slice(result.pos)}
|
|
|
20998
22817
|
},
|
|
20999
22818
|
multiLineImplicitObjectLiteralForbidden: {
|
|
21000
22819
|
get() {
|
|
21001
|
-
const { forbidMultiLineImplicitObjectLiteral: s } = module;
|
|
21002
|
-
return s[s.length - 1];
|
|
21003
|
-
}
|
|
21004
|
-
},
|
|
21005
|
-
newlineBinaryOpForbidden: {
|
|
21006
|
-
get() {
|
|
21007
|
-
const { forbidNewlineBinaryOp: s } = module;
|
|
21008
|
-
return s[s.length - 1];
|
|
21009
|
-
}
|
|
21010
|
-
},
|
|
21011
|
-
currentJSXTag: {
|
|
21012
|
-
get() {
|
|
21013
|
-
const { JSXTagStack: s } = module;
|
|
21014
|
-
return s[s.length - 1];
|
|
21015
|
-
}
|
|
21016
|
-
}
|
|
21017
|
-
});
|
|
21018
|
-
}
|
|
21019
|
-
module.config = parse2.config = {
|
|
21020
|
-
autoVar: false,
|
|
21021
|
-
autoLet: false,
|
|
21022
|
-
coffeeBinaryExistential: false,
|
|
21023
|
-
coffeeBooleans: false,
|
|
21024
|
-
coffeeClasses: false,
|
|
21025
|
-
coffeeComment: false,
|
|
21026
|
-
coffeeDo: false,
|
|
21027
|
-
coffeeEq: false,
|
|
21028
|
-
coffeeForLoops: false,
|
|
21029
|
-
coffeeInterpolation: false,
|
|
21030
|
-
coffeeIsnt: false,
|
|
21031
|
-
coffeeJSX: false,
|
|
21032
|
-
coffeeLineContinuation: false,
|
|
21033
|
-
coffeeNot: false,
|
|
21034
|
-
coffeeOf: false,
|
|
21035
|
-
coffeePrototype: false,
|
|
21036
|
-
defaultElement: "div",
|
|
21037
|
-
implicitReturns: true,
|
|
21038
|
-
objectIs: false,
|
|
21039
|
-
react: false,
|
|
21040
|
-
solid: false,
|
|
21041
|
-
client: false,
|
|
21042
|
-
rewriteTsImports: true,
|
|
21043
|
-
server: false,
|
|
21044
|
-
tab: void 0,
|
|
21045
|
-
verbose: false
|
|
21046
|
-
};
|
|
21047
|
-
module.asAny = {
|
|
21048
|
-
ts: true,
|
|
21049
|
-
children: [" as any"]
|
|
21050
|
-
};
|
|
21051
|
-
module.asConst = {
|
|
21052
|
-
ts: true,
|
|
21053
|
-
children: [" as const"]
|
|
21054
|
-
};
|
|
21055
|
-
module.prelude = [];
|
|
21056
|
-
const preludeVar = "var ";
|
|
21057
|
-
const declareRef = {
|
|
21058
|
-
indexOf(indexOfRef) {
|
|
21059
|
-
const typeSuffix = {
|
|
21060
|
-
ts: true,
|
|
21061
|
-
children: [": <T>(this: T[], searchElement: T) => boolean"]
|
|
21062
|
-
};
|
|
21063
|
-
module.prelude.push(["", [preludeVar, indexOfRef, typeSuffix, " = [].indexOf", module.asAny, ";\n"]]);
|
|
21064
|
-
},
|
|
21065
|
-
hasProp(hasPropRef) {
|
|
21066
|
-
const typeSuffix = {
|
|
21067
|
-
ts: true,
|
|
21068
|
-
children: [": <T>(this: T, prop: keyof T) => boolean"]
|
|
21069
|
-
};
|
|
21070
|
-
module.prelude.push(["", [preludeVar, hasPropRef, typeSuffix, " = {}.hasOwnProperty", module.asAny, ";\n"]]);
|
|
21071
|
-
},
|
|
21072
|
-
is(isRef) {
|
|
21073
|
-
const typeSuffix = {
|
|
21074
|
-
ts: true,
|
|
21075
|
-
children: [": { <B, A extends B> (a: A, b: B): b is A, <A, B> (a: A, b: B): a is A & B }"]
|
|
21076
|
-
};
|
|
21077
|
-
module.prelude.push(["", [preludeVar, isRef, typeSuffix, " = Object.is", module.asAny, ";\n"]]);
|
|
21078
|
-
},
|
|
21079
|
-
modulo(moduloRef) {
|
|
21080
|
-
const typeSuffix = {
|
|
21081
|
-
ts: true,
|
|
21082
|
-
children: [": (a: number, b: number) => number"]
|
|
21083
|
-
};
|
|
21084
|
-
module.prelude.push(["", [preludeVar, moduloRef, typeSuffix, " = (a, b) => (a % b + b) % b;", "\n"]]);
|
|
21085
|
-
},
|
|
21086
|
-
xor(xorRef) {
|
|
21087
|
-
const typeSuffix = {
|
|
21088
|
-
ts: true,
|
|
21089
|
-
children: [": (a: unknown, b: unknown) => boolean"]
|
|
21090
|
-
};
|
|
21091
|
-
module.prelude.push(["", [preludeVar, xorRef, typeSuffix, " = (a, b) => a ? !b && a : b;", "\n"]]);
|
|
21092
|
-
},
|
|
21093
|
-
xnor(xnorRef) {
|
|
21094
|
-
const typeSuffix = {
|
|
21095
|
-
ts: true,
|
|
21096
|
-
children: [": (a: unknown, b: unknown) => boolean"]
|
|
21097
|
-
};
|
|
21098
|
-
module.prelude.push(["", [preludeVar, xnorRef, typeSuffix, " = (a, b) => a ? b : !b || a;", "\n"]]);
|
|
21099
|
-
},
|
|
21100
|
-
returnSymbol(ref) {
|
|
21101
|
-
module.prelude.push({
|
|
21102
|
-
children: [
|
|
21103
|
-
preludeVar,
|
|
21104
|
-
ref,
|
|
21105
|
-
` = Symbol("return")';
|
|
21106
|
-
`
|
|
21107
|
-
]
|
|
21108
|
-
});
|
|
21109
|
-
},
|
|
21110
|
-
JSX(jsxRef) {
|
|
21111
|
-
module.prelude.push({
|
|
21112
|
-
ts: true,
|
|
21113
|
-
children: [
|
|
21114
|
-
"import type { JSX as ",
|
|
21115
|
-
jsxRef,
|
|
21116
|
-
" } from 'solid-js';\n"
|
|
21117
|
-
]
|
|
21118
|
-
});
|
|
21119
|
-
},
|
|
21120
|
-
IntrinsicElements(intrinsicElementsRef) {
|
|
21121
|
-
const JSX = module.getRef("JSX");
|
|
21122
|
-
module.prelude.push({
|
|
21123
|
-
ts: true,
|
|
21124
|
-
children: [
|
|
21125
|
-
"type ",
|
|
21126
|
-
intrinsicElementsRef,
|
|
21127
|
-
"<K extends keyof ",
|
|
21128
|
-
JSX,
|
|
21129
|
-
".IntrinsicElements> =\n",
|
|
21130
|
-
" ",
|
|
21131
|
-
JSX,
|
|
21132
|
-
".IntrinsicElements[K] extends ",
|
|
21133
|
-
JSX,
|
|
21134
|
-
".DOMAttributes<infer T> ? T : unknown;\n"
|
|
21135
|
-
]
|
|
21136
|
-
});
|
|
21137
|
-
}
|
|
21138
|
-
};
|
|
21139
|
-
const refs = {};
|
|
21140
|
-
module.getRef = function(base) {
|
|
21141
|
-
if (refs.hasOwnProperty(base))
|
|
21142
|
-
return refs[base];
|
|
21143
|
-
const ref = {
|
|
21144
|
-
type: "Ref",
|
|
21145
|
-
base,
|
|
21146
|
-
id: base
|
|
21147
|
-
};
|
|
21148
|
-
if (declareRef.hasOwnProperty(base))
|
|
21149
|
-
declareRef[base](ref);
|
|
21150
|
-
return refs[base] = ref;
|
|
21151
|
-
};
|
|
21152
|
-
module.makeAsConst = function(node) {
|
|
21153
|
-
if (node.type === "Literal" && node.raw !== "null" || node.type === "ArrayExpression" || node.type === "ObjectExpression") {
|
|
21154
|
-
return { ...node, children: [...node.children, module.asConst] };
|
|
21155
|
-
}
|
|
21156
|
-
return node;
|
|
21157
|
-
};
|
|
21158
|
-
module.typeOfJSX = function(node) {
|
|
21159
|
-
switch (node.type) {
|
|
21160
|
-
case "JSXElement":
|
|
21161
|
-
return module.typeOfJSXElement(node);
|
|
21162
|
-
case "JSXFragment":
|
|
21163
|
-
return module.typeOfJSXFragment(node);
|
|
21164
|
-
}
|
|
21165
|
-
};
|
|
21166
|
-
module.typeOfJSXElement = function(node) {
|
|
21167
|
-
if (module.config.solid) {
|
|
21168
|
-
if (module.config.server && !module.config.client) {
|
|
21169
|
-
return ["string"];
|
|
21170
|
-
}
|
|
21171
|
-
let { tag } = node;
|
|
21172
|
-
const clientType = tag[0] === tag[0].toLowerCase() ? [module.getRef("IntrinsicElements"), '<"', tag, '">'] : ["ReturnType<typeof ", tag, ">"];
|
|
21173
|
-
if (module.config.server) {
|
|
21174
|
-
return ["string", " | ", clientType];
|
|
21175
|
-
} else {
|
|
21176
|
-
return clientType;
|
|
21177
|
-
}
|
|
21178
|
-
}
|
|
21179
|
-
};
|
|
21180
|
-
module.typeOfJSXFragment = function(node) {
|
|
21181
|
-
if (module.config.solid) {
|
|
21182
|
-
let type = [];
|
|
21183
|
-
let lastType;
|
|
21184
|
-
for (let child of node.jsxChildren) {
|
|
21185
|
-
switch (child.type) {
|
|
21186
|
-
case "JSXText":
|
|
21187
|
-
if (lastType !== "JSXText") {
|
|
21188
|
-
type.push("string");
|
|
21189
|
-
}
|
|
21190
|
-
break;
|
|
21191
|
-
case "JSXElement":
|
|
21192
|
-
type.push(module.typeOfJSXElement(child));
|
|
21193
|
-
break;
|
|
21194
|
-
case "JSXFragment":
|
|
21195
|
-
type.push(...module.typeOfJSXFragment(child));
|
|
21196
|
-
break;
|
|
21197
|
-
case "JSXChildExpression":
|
|
21198
|
-
if (child.expression) {
|
|
21199
|
-
type.push(["typeof ", child.expression]);
|
|
21200
|
-
}
|
|
21201
|
-
break;
|
|
21202
|
-
default:
|
|
21203
|
-
throw new Error(`unknown child in JSXFragment: ${JSON.stringify(child)}`);
|
|
21204
|
-
}
|
|
21205
|
-
lastType = child.type;
|
|
21206
|
-
}
|
|
21207
|
-
if (type.length === 1) {
|
|
21208
|
-
return type[0];
|
|
21209
|
-
} else {
|
|
21210
|
-
type = type.flatMap((t) => [t, ", "]);
|
|
21211
|
-
type.pop();
|
|
21212
|
-
return ["[", type, "]"];
|
|
21213
|
-
}
|
|
21214
|
-
}
|
|
21215
|
-
};
|
|
21216
|
-
Object.defineProperty(module.config, "deno", {
|
|
21217
|
-
set(b) {
|
|
21218
|
-
module.config.rewriteTsImports = !b;
|
|
21219
|
-
}
|
|
21220
|
-
});
|
|
21221
|
-
module.config.deno = typeof Deno !== "undefined";
|
|
21222
|
-
Object.defineProperty(module.config, "coffeeCompat", {
|
|
21223
|
-
set(b) {
|
|
21224
|
-
for (const option of [
|
|
21225
|
-
"autoVar",
|
|
21226
|
-
"coffeeBinaryExistential",
|
|
21227
|
-
"coffeeBooleans",
|
|
21228
|
-
"coffeeClasses",
|
|
21229
|
-
"coffeeComment",
|
|
21230
|
-
"coffeeDo",
|
|
21231
|
-
"coffeeEq",
|
|
21232
|
-
"coffeeForLoops",
|
|
21233
|
-
"coffeeInterpolation",
|
|
21234
|
-
"coffeeIsnt",
|
|
21235
|
-
"coffeeJSX",
|
|
21236
|
-
"coffeeLineContinuation",
|
|
21237
|
-
"coffeeNot",
|
|
21238
|
-
"coffeeOf",
|
|
21239
|
-
"coffeePrototype"
|
|
21240
|
-
]) {
|
|
21241
|
-
module.config[option] = b;
|
|
21242
|
-
}
|
|
21243
|
-
if (b) {
|
|
21244
|
-
module.config.objectIs = false;
|
|
21245
|
-
}
|
|
21246
|
-
}
|
|
21247
|
-
});
|
|
21248
|
-
});
|
|
21249
|
-
function Reset(state) {
|
|
21250
|
-
let eventData;
|
|
21251
|
-
if (state.events) {
|
|
21252
|
-
const result = state.events.enter?.("Reset", state);
|
|
21253
|
-
if (result) {
|
|
21254
|
-
if (result.cache)
|
|
21255
|
-
return result.cache;
|
|
21256
|
-
eventData = result.data;
|
|
21257
|
-
}
|
|
21258
|
-
}
|
|
21259
|
-
if (state.tokenize) {
|
|
21260
|
-
const result = $TOKEN("Reset", state, Reset$0(state));
|
|
21261
|
-
if (state.events)
|
|
21262
|
-
state.events.exit?.("Reset", state, result, eventData);
|
|
21263
|
-
return result;
|
|
21264
|
-
} else {
|
|
21265
|
-
const result = Reset$0(state);
|
|
21266
|
-
if (state.events)
|
|
21267
|
-
state.events.exit?.("Reset", state, result, eventData);
|
|
21268
|
-
return result;
|
|
21269
|
-
}
|
|
21270
|
-
}
|
|
21271
|
-
var Init$0 = $TS($S($E(Shebang), $Q(DirectivePrologue), $EXPECT($L0, fail, 'Init ""')), function($skip, $loc, $0, $1, $2, $3) {
|
|
21272
|
-
var directives = $2;
|
|
21273
|
-
directives.forEach((directive) => {
|
|
21274
|
-
if (directive.type === "CivetPrologue") {
|
|
21275
|
-
Object.assign(module.config, directive.config);
|
|
21276
|
-
}
|
|
21277
|
-
});
|
|
21278
|
-
module.processCallMemberExpression = (node) => {
|
|
21279
|
-
const { children } = node;
|
|
21280
|
-
for (let i = 0; i < children.length; i++) {
|
|
21281
|
-
const glob = children[i];
|
|
21282
|
-
if (glob?.type === "PropertyGlob") {
|
|
21283
|
-
const prefix = children.slice(0, i).concat(glob.dot);
|
|
21284
|
-
const parts = [];
|
|
21285
|
-
for (const part of glob.object.properties) {
|
|
21286
|
-
if (part.type === "MethodDefinition") {
|
|
21287
|
-
throw new Error("Glob pattern cannot have method definition");
|
|
21288
|
-
}
|
|
21289
|
-
if (part.value && !["CallExpression", "MemberExpression", "Identifier"].includes(part.value.type)) {
|
|
21290
|
-
throw new Error("Glob pattern must have call or member expression value");
|
|
21291
|
-
}
|
|
21292
|
-
let value = part.value ?? part.name;
|
|
21293
|
-
const wValue = getTrimmingSpace(part.value);
|
|
21294
|
-
value = prefix.concat(insertTrimmingSpace(value, ""));
|
|
21295
|
-
if (wValue)
|
|
21296
|
-
value.unshift(wValue);
|
|
21297
|
-
if (part.type === "SpreadProperty") {
|
|
21298
|
-
parts.push({
|
|
21299
|
-
type: part.type,
|
|
21300
|
-
value,
|
|
21301
|
-
dots: part.dots,
|
|
21302
|
-
delim: part.delim,
|
|
21303
|
-
names: part.names,
|
|
21304
|
-
children: part.children.slice(0, 2).concat(value, part.delim)
|
|
21305
|
-
});
|
|
21306
|
-
} else {
|
|
21307
|
-
parts.push({
|
|
21308
|
-
type: part.type === "Identifier" ? "Property" : part.type,
|
|
21309
|
-
name: part.name,
|
|
21310
|
-
value,
|
|
21311
|
-
delim: part.delim,
|
|
21312
|
-
names: part.names,
|
|
21313
|
-
children: [
|
|
21314
|
-
module.isWhitespaceOrEmpty(part.children[0]) && part.children[0],
|
|
21315
|
-
part.name,
|
|
21316
|
-
module.isWhitespaceOrEmpty(part.children[2]) && part.children[2],
|
|
21317
|
-
part.children[3]?.token === ":" ? part.children[3] : ":",
|
|
21318
|
-
value,
|
|
21319
|
-
part.delim
|
|
21320
|
-
]
|
|
21321
|
-
});
|
|
21322
|
-
}
|
|
21323
|
-
}
|
|
21324
|
-
const object = {
|
|
21325
|
-
type: "ObjectExpression",
|
|
21326
|
-
children: [
|
|
21327
|
-
glob.object.children[0],
|
|
21328
|
-
...parts,
|
|
21329
|
-
glob.object.children.at(-1)
|
|
21330
|
-
],
|
|
21331
|
-
properties: parts
|
|
21332
|
-
};
|
|
21333
|
-
if (i === children.length - 1)
|
|
21334
|
-
return object;
|
|
21335
|
-
return module.processCallMemberExpression({
|
|
21336
|
-
...node,
|
|
21337
|
-
children: [object, ...children.slice(i + 1)]
|
|
21338
|
-
});
|
|
21339
|
-
} else if (glob?.type === "PropertyBind") {
|
|
21340
|
-
const prefix = children.slice(0, i);
|
|
21341
|
-
return module.processCallMemberExpression({
|
|
21342
|
-
...node,
|
|
21343
|
-
children: [
|
|
21344
|
-
prefix,
|
|
21345
|
-
{
|
|
21346
|
-
...glob,
|
|
21347
|
-
type: "PropertyAccess",
|
|
21348
|
-
children: [...glob.children, ".bind(", prefix, ")"]
|
|
21349
|
-
},
|
|
21350
|
-
...children.slice(i + 1)
|
|
21351
|
-
]
|
|
21352
|
-
});
|
|
21353
|
-
}
|
|
21354
|
-
}
|
|
21355
|
-
return node;
|
|
21356
|
-
};
|
|
21357
|
-
module.needsRef = function(expression, base = "ref") {
|
|
21358
|
-
switch (expression.type) {
|
|
21359
|
-
case "Ref":
|
|
21360
|
-
case "Identifier":
|
|
21361
|
-
case "Literal":
|
|
21362
|
-
return;
|
|
21363
|
-
default:
|
|
21364
|
-
return {
|
|
21365
|
-
type: "Ref",
|
|
21366
|
-
base,
|
|
21367
|
-
id: base
|
|
21368
|
-
};
|
|
21369
|
-
}
|
|
21370
|
-
};
|
|
21371
|
-
module.expressionizeIfClause = function(clause, b, e) {
|
|
21372
|
-
const children = clause.children.slice(1);
|
|
21373
|
-
children.push("?", b);
|
|
21374
|
-
if (e) {
|
|
21375
|
-
children.push(e[0], ":", ...e.slice(2));
|
|
21376
|
-
} else {
|
|
21377
|
-
children.push(":void 0");
|
|
21378
|
-
}
|
|
21379
|
-
return {
|
|
21380
|
-
type: "IfExpression",
|
|
21381
|
-
children
|
|
21382
|
-
};
|
|
21383
|
-
};
|
|
21384
|
-
module.addPostfixStatement = function(statement, ws, post) {
|
|
21385
|
-
let children, expressions;
|
|
21386
|
-
if (post.blockPrefix?.length) {
|
|
21387
|
-
let indent = post.blockPrefix[0][0];
|
|
21388
|
-
expressions = [...post.blockPrefix, [indent, statement]];
|
|
21389
|
-
children = [" {\n", ...expressions, "\n", indent?.slice?.(0, -2), "}"];
|
|
21390
|
-
} else {
|
|
21391
|
-
expressions = [["", statement]];
|
|
21392
|
-
children = [" { ", ...expressions, " }"];
|
|
21393
|
-
}
|
|
21394
|
-
const block = {
|
|
21395
|
-
type: "BlockStatement",
|
|
21396
|
-
children,
|
|
21397
|
-
expressions
|
|
21398
|
-
};
|
|
21399
|
-
children = [...post.children];
|
|
21400
|
-
children.push(block);
|
|
21401
|
-
if (!module.isWhitespaceOrEmpty(ws))
|
|
21402
|
-
children.push(ws);
|
|
21403
|
-
post = { ...post, children, block };
|
|
21404
|
-
if (post.type === "IfStatement") {
|
|
21405
|
-
post.then = block;
|
|
21406
|
-
}
|
|
21407
|
-
return post;
|
|
21408
|
-
};
|
|
21409
|
-
function expressionizeIteration(exp) {
|
|
21410
|
-
const i = exp.children.indexOf(exp.block);
|
|
21411
|
-
if (exp.subtype === "DoStatement") {
|
|
21412
|
-
insertReturn(exp.block);
|
|
21413
|
-
exp.children.splice(i, 1, ...module.wrapIIFE(exp.children, exp.async));
|
|
21414
|
-
return;
|
|
21415
|
-
}
|
|
21416
|
-
const resultsRef = {
|
|
21417
|
-
type: "Ref",
|
|
21418
|
-
base: "results",
|
|
21419
|
-
id: "results"
|
|
21420
|
-
};
|
|
21421
|
-
insertPush(exp.block, resultsRef);
|
|
21422
|
-
exp.children.splice(
|
|
21423
|
-
i,
|
|
21424
|
-
1,
|
|
21425
|
-
module.wrapIIFE([
|
|
21426
|
-
"const ",
|
|
21427
|
-
resultsRef,
|
|
21428
|
-
"=[];",
|
|
21429
|
-
...exp.children,
|
|
21430
|
-
"; return ",
|
|
21431
|
-
resultsRef
|
|
21432
|
-
], exp.async)
|
|
21433
|
-
);
|
|
21434
|
-
}
|
|
21435
|
-
module.wrapIIFE = (exp, async) => {
|
|
21436
|
-
let prefix, suffix;
|
|
21437
|
-
if (async) {
|
|
21438
|
-
prefix = "(async ()=>{";
|
|
21439
|
-
suffix = "})()";
|
|
21440
|
-
} else if (hasAwait(exp)) {
|
|
21441
|
-
prefix = "(await (async ()=>{";
|
|
21442
|
-
suffix = "})())";
|
|
21443
|
-
} else {
|
|
21444
|
-
prefix = "(()=>{";
|
|
21445
|
-
suffix = "})()";
|
|
21446
|
-
}
|
|
21447
|
-
if (Array.isArray(exp)) {
|
|
21448
|
-
return [prefix, ...exp, suffix];
|
|
21449
|
-
} else {
|
|
21450
|
-
return [prefix, exp, suffix];
|
|
21451
|
-
}
|
|
21452
|
-
};
|
|
21453
|
-
function wrapIterationReturningResults(statement, outerRef) {
|
|
21454
|
-
if (statement.type === "DoStatement") {
|
|
21455
|
-
if (outerRef) {
|
|
21456
|
-
insertPush(statement.block, outerRef);
|
|
21457
|
-
} else {
|
|
21458
|
-
insertReturn(statement.block);
|
|
21459
|
-
}
|
|
21460
|
-
return;
|
|
21461
|
-
}
|
|
21462
|
-
const resultsRef = {
|
|
21463
|
-
type: "Ref",
|
|
21464
|
-
base: "results",
|
|
21465
|
-
id: "results"
|
|
21466
|
-
};
|
|
21467
|
-
const declaration = {
|
|
21468
|
-
type: "Declaration",
|
|
21469
|
-
children: ["const ", resultsRef, "=[];"]
|
|
21470
|
-
};
|
|
21471
|
-
insertPush(statement.block, resultsRef);
|
|
21472
|
-
statement.children.unshift(declaration);
|
|
21473
|
-
if (outerRef) {
|
|
21474
|
-
statement.children.push(";", outerRef, ".push(", resultsRef, ");");
|
|
21475
|
-
} else {
|
|
21476
|
-
statement.children.push(";return ", resultsRef, ";");
|
|
21477
|
-
}
|
|
21478
|
-
}
|
|
21479
|
-
function insertPush(node, ref) {
|
|
21480
|
-
if (!node)
|
|
21481
|
-
return;
|
|
21482
|
-
switch (node.type) {
|
|
21483
|
-
case "BlockStatement":
|
|
21484
|
-
if (node.expressions.length) {
|
|
21485
|
-
const last = node.expressions[node.expressions.length - 1];
|
|
21486
|
-
insertPush(last, ref);
|
|
21487
|
-
} else {
|
|
21488
|
-
node.expressions.push([ref, ".push(void 0);"]);
|
|
21489
|
-
}
|
|
21490
|
-
return;
|
|
21491
|
-
case "CaseBlock":
|
|
21492
|
-
node.clauses.forEach((clause) => {
|
|
21493
|
-
insertPush(clause, ref);
|
|
21494
|
-
});
|
|
21495
|
-
return;
|
|
21496
|
-
case "WhenClause":
|
|
21497
|
-
insertPush(node.block, ref);
|
|
21498
|
-
return;
|
|
21499
|
-
case "DefaultClause":
|
|
21500
|
-
insertPush(node.block, ref);
|
|
21501
|
-
return;
|
|
21502
|
-
}
|
|
21503
|
-
if (!Array.isArray(node))
|
|
21504
|
-
return;
|
|
21505
|
-
const [, exp] = node;
|
|
21506
|
-
if (!exp)
|
|
21507
|
-
return;
|
|
21508
|
-
const indent = getIndent(node);
|
|
21509
|
-
switch (exp.type) {
|
|
21510
|
-
case "BreakStatement":
|
|
21511
|
-
case "ContinueStatement":
|
|
21512
|
-
case "DebuggerStatement":
|
|
21513
|
-
case "EmptyStatement":
|
|
21514
|
-
case "ReturnStatement":
|
|
21515
|
-
case "ThrowStatement":
|
|
21516
|
-
case "Declaration":
|
|
21517
|
-
return;
|
|
21518
|
-
case "ForStatement":
|
|
21519
|
-
case "IterationStatement":
|
|
21520
|
-
case "DoStatement":
|
|
21521
|
-
wrapIterationReturningResults(exp, ref);
|
|
21522
|
-
return;
|
|
21523
|
-
case "BlockStatement":
|
|
21524
|
-
insertPush(exp.expressions[exp.expressions.length - 1], ref);
|
|
21525
|
-
return;
|
|
21526
|
-
case "IfStatement":
|
|
21527
|
-
insertPush(exp.then, ref);
|
|
21528
|
-
if (exp.else)
|
|
21529
|
-
insertPush(exp.else[2], ref);
|
|
21530
|
-
else
|
|
21531
|
-
exp.children.push([" else {\n", indent, ref, ".push(undefined)\n", indent, "}"]);
|
|
21532
|
-
return;
|
|
21533
|
-
case "PatternMatchingStatement":
|
|
21534
|
-
insertPush(exp.children[0][0], ref);
|
|
21535
|
-
return;
|
|
21536
|
-
case "SwitchStatement":
|
|
21537
|
-
insertPush(exp.children[2], ref);
|
|
21538
|
-
return;
|
|
21539
|
-
case "TryStatement":
|
|
21540
|
-
exp.blocks.forEach((block) => insertPush(block, ref));
|
|
21541
|
-
return;
|
|
21542
|
-
}
|
|
21543
|
-
if (node[node.length - 1]?.type === "SemicolonDelimiter")
|
|
21544
|
-
return;
|
|
21545
|
-
node.splice(1, 0, ref, ".push(");
|
|
21546
|
-
node.push(")");
|
|
21547
|
-
}
|
|
21548
|
-
function wrapWithReturn(expression) {
|
|
21549
|
-
const children = expression ? ["return ", expression] : ["return"];
|
|
21550
|
-
return {
|
|
21551
|
-
type: "ReturnStatement",
|
|
21552
|
-
children
|
|
21553
|
-
};
|
|
21554
|
-
}
|
|
21555
|
-
function insertSwitchReturns(exp) {
|
|
21556
|
-
switch (exp.type) {
|
|
21557
|
-
case "SwitchStatement":
|
|
21558
|
-
exp.caseBlock.clauses.forEach((clause) => {
|
|
21559
|
-
insertReturn(clause);
|
|
21560
|
-
});
|
|
21561
|
-
return;
|
|
21562
|
-
case "SwitchExpression":
|
|
21563
|
-
exp.caseBlock.clauses.forEach(insertReturn);
|
|
21564
|
-
return;
|
|
21565
|
-
}
|
|
21566
|
-
}
|
|
21567
|
-
function insertReturn(node) {
|
|
21568
|
-
if (!node)
|
|
21569
|
-
return;
|
|
21570
|
-
switch (node.type) {
|
|
21571
|
-
case "BlockStatement":
|
|
21572
|
-
if (node.expressions.length) {
|
|
21573
|
-
const last = node.expressions[node.expressions.length - 1];
|
|
21574
|
-
insertReturn(last);
|
|
21575
|
-
} else {
|
|
21576
|
-
if (node.parent.type === "CatchClause") {
|
|
21577
|
-
node.expressions.push(["return"]);
|
|
21578
|
-
}
|
|
21579
|
-
}
|
|
21580
|
-
return;
|
|
21581
|
-
case "WhenClause":
|
|
21582
|
-
node.children.splice(node.children.indexOf(node.break), 1);
|
|
21583
|
-
if (node.block.expressions.length) {
|
|
21584
|
-
insertReturn(node.block);
|
|
21585
|
-
} else {
|
|
21586
|
-
node.block.expressions.push(wrapWithReturn());
|
|
21587
|
-
}
|
|
21588
|
-
return;
|
|
21589
|
-
case "DefaultClause":
|
|
21590
|
-
insertReturn(node.block);
|
|
21591
|
-
return;
|
|
21592
|
-
}
|
|
21593
|
-
if (!Array.isArray(node))
|
|
21594
|
-
return;
|
|
21595
|
-
const [, exp, semi] = node;
|
|
21596
|
-
if (semi?.type === "SemicolonDelimiter")
|
|
21597
|
-
return;
|
|
21598
|
-
let indent = getIndent(node);
|
|
21599
|
-
if (!exp)
|
|
21600
|
-
return;
|
|
21601
|
-
switch (exp.type) {
|
|
21602
|
-
case "BreakStatement":
|
|
21603
|
-
case "ContinueStatement":
|
|
21604
|
-
case "DebuggerStatement":
|
|
21605
|
-
case "EmptyStatement":
|
|
21606
|
-
case "ReturnStatement":
|
|
21607
|
-
case "ThrowStatement":
|
|
21608
|
-
case "Declaration":
|
|
21609
|
-
return;
|
|
21610
|
-
case "ForStatement":
|
|
21611
|
-
case "IterationStatement":
|
|
21612
|
-
case "DoStatement":
|
|
21613
|
-
wrapIterationReturningResults(exp);
|
|
21614
|
-
return;
|
|
21615
|
-
case "BlockStatement":
|
|
21616
|
-
insertReturn(exp.expressions[exp.expressions.length - 1]);
|
|
21617
|
-
return;
|
|
21618
|
-
case "IfStatement":
|
|
21619
|
-
insertReturn(exp.then);
|
|
21620
|
-
if (exp.else)
|
|
21621
|
-
insertReturn(exp.else[2]);
|
|
21622
|
-
else
|
|
21623
|
-
exp.children.push(["", {
|
|
21624
|
-
type: "ReturnStatement",
|
|
21625
|
-
children: [";return"]
|
|
21626
|
-
}]);
|
|
21627
|
-
return;
|
|
21628
|
-
case "PatternMatchingStatement":
|
|
21629
|
-
insertReturn(exp.children[0][0]);
|
|
21630
|
-
return;
|
|
21631
|
-
case "SwitchStatement":
|
|
21632
|
-
insertSwitchReturns(exp);
|
|
21633
|
-
return;
|
|
21634
|
-
case "TryStatement":
|
|
21635
|
-
exp.blocks.forEach((block) => insertReturn(block));
|
|
21636
|
-
return;
|
|
21637
|
-
}
|
|
21638
|
-
if (node[node.length - 1]?.type === "SemicolonDelimiter")
|
|
21639
|
-
return;
|
|
21640
|
-
const returnStatement = wrapWithReturn(node[1]);
|
|
21641
|
-
node.splice(1, 1, returnStatement);
|
|
21642
|
-
}
|
|
21643
|
-
module.makeLeftHandSideExpression = function(expression) {
|
|
21644
|
-
switch (expression.type) {
|
|
21645
|
-
case "Ref":
|
|
21646
|
-
case "Identifier":
|
|
21647
|
-
case "Literal":
|
|
21648
|
-
case "CallExpression":
|
|
21649
|
-
case "MemberExpression":
|
|
21650
|
-
case "ParenthesizedExpression":
|
|
21651
|
-
return expression;
|
|
21652
|
-
default:
|
|
21653
|
-
return {
|
|
21654
|
-
type: "ParenthesizedExpression",
|
|
21655
|
-
children: ["(", expression, ")"],
|
|
21656
|
-
expression
|
|
21657
|
-
};
|
|
21658
|
-
}
|
|
21659
|
-
};
|
|
21660
|
-
module.isWhitespaceOrEmpty = function(node) {
|
|
21661
|
-
if (!node)
|
|
21662
|
-
return true;
|
|
21663
|
-
if (node.type === "Ref")
|
|
21664
|
-
return false;
|
|
21665
|
-
if (node.token)
|
|
21666
|
-
return node.token.match(/^\s*$/);
|
|
21667
|
-
if (node.children)
|
|
21668
|
-
node = node.children;
|
|
21669
|
-
if (!node.length)
|
|
21670
|
-
return true;
|
|
21671
|
-
if (typeof node === "string")
|
|
21672
|
-
return node.match(/^\s*$/);
|
|
21673
|
-
if (Array.isArray(node))
|
|
21674
|
-
return node.every(module.isWhitespaceOrEmpty);
|
|
21675
|
-
};
|
|
21676
|
-
module.isTemplateLiteral = function(node) {
|
|
21677
|
-
let s = node;
|
|
21678
|
-
while (s && s[0] && !s.token)
|
|
21679
|
-
s = s[0];
|
|
21680
|
-
return s.token?.startsWith?.("`");
|
|
21681
|
-
};
|
|
21682
|
-
module.isEmptyBareBlock = function(node) {
|
|
21683
|
-
if (node?.type !== "BlockStatement")
|
|
21684
|
-
return false;
|
|
21685
|
-
const { bare, expressions } = node;
|
|
21686
|
-
return bare && (expressions.length === 0 || expressions.length === 1 && expressions[0][1]?.type === "EmptyStatement");
|
|
21687
|
-
};
|
|
21688
|
-
module.processBinaryOpExpression = function($02) {
|
|
21689
|
-
const expandedOps = module.expandChainedComparisons($02);
|
|
21690
|
-
let i = 2;
|
|
21691
|
-
while (i < expandedOps.length) {
|
|
21692
|
-
const op = expandedOps[i];
|
|
21693
|
-
if (op.special) {
|
|
21694
|
-
let [a, wsOp, op2, wsB, b] = expandedOps.slice(i - 2, i + 3);
|
|
21695
|
-
if (op2.token === "instanceof" && b.type === "Literal" && b.children?.[0]?.type === "StringLiteral") {
|
|
21696
|
-
a = ["typeof ", module.makeLeftHandSideExpression(a)];
|
|
21697
|
-
if (op2.negated) {
|
|
21698
|
-
op2 = { ...op2, token: "!==", negated: false };
|
|
21699
|
-
} else {
|
|
21700
|
-
op2 = { ...op2, token: "===" };
|
|
21701
|
-
}
|
|
21702
|
-
}
|
|
21703
|
-
if (op2.asConst) {
|
|
21704
|
-
a = module.makeAsConst(a);
|
|
21705
|
-
b = module.makeAsConst(b);
|
|
21706
|
-
}
|
|
21707
|
-
let children;
|
|
21708
|
-
if (op2.call) {
|
|
21709
|
-
wsOp = insertTrimmingSpace(wsOp, "");
|
|
21710
|
-
if (op2.reversed) {
|
|
21711
|
-
wsB = insertTrimmingSpace(wsB, "");
|
|
21712
|
-
children = [wsOp, op2.call, "(", wsB, b, ", ", a, ")", op2.suffix];
|
|
21713
|
-
} else {
|
|
21714
|
-
children = [wsOp, op2.call, "(", a, ",", wsB, b, ")", op2.suffix];
|
|
21715
|
-
}
|
|
21716
|
-
} else if (op2.method) {
|
|
21717
|
-
wsOp = insertTrimmingSpace(wsOp, "");
|
|
21718
|
-
wsB = insertTrimmingSpace(wsB, "");
|
|
21719
|
-
if (op2.reversed) {
|
|
21720
|
-
children = [wsB, b, wsOp, ".", op2.method, "(", a, ")"];
|
|
21721
|
-
} else {
|
|
21722
|
-
children = [a, wsOp, ".", op2.method, "(", wsB, b, ")"];
|
|
21723
|
-
}
|
|
21724
|
-
} else if (op2.token) {
|
|
21725
|
-
children = [a, wsOp, op2, wsB, b];
|
|
21726
|
-
if (op2.negated)
|
|
21727
|
-
children = ["(", ...children, ")"];
|
|
21728
|
-
} else {
|
|
21729
|
-
throw new Error("Unknown operator: " + JSON.stringify(op2));
|
|
21730
|
-
}
|
|
21731
|
-
if (op2.negated)
|
|
21732
|
-
children.unshift("!");
|
|
21733
|
-
expandedOps.splice(i - 2, 5, {
|
|
21734
|
-
children
|
|
21735
|
-
});
|
|
21736
|
-
} else {
|
|
21737
|
-
i += 4;
|
|
21738
|
-
}
|
|
21739
|
-
}
|
|
21740
|
-
return expandedOps;
|
|
21741
|
-
};
|
|
21742
|
-
module.expandChainedComparisons = function([first, binops]) {
|
|
21743
|
-
const relationalOps = ["==", "===", "!=", "!==", "<", "<=", ">", ">=", "in"];
|
|
21744
|
-
const lowerPrecedenceOps = ["??", "&&", "||", "&", "|", "^"];
|
|
21745
|
-
let results = [];
|
|
21746
|
-
let i = 0;
|
|
21747
|
-
let l = binops.length;
|
|
21748
|
-
let start = 0;
|
|
21749
|
-
let chains = [];
|
|
21750
|
-
while (i < l) {
|
|
21751
|
-
const [, op] = binops[i];
|
|
21752
|
-
if (relationalOps.includes(op.token) || op.relational) {
|
|
21753
|
-
chains.push(i);
|
|
21754
|
-
} else if (lowerPrecedenceOps.includes(op.token)) {
|
|
21755
|
-
processChains();
|
|
21756
|
-
first = [];
|
|
21757
|
-
}
|
|
21758
|
-
i++;
|
|
21759
|
-
}
|
|
21760
|
-
processChains();
|
|
21761
|
-
return results;
|
|
21762
|
-
function processChains() {
|
|
21763
|
-
if (chains.length > 1) {
|
|
21764
|
-
chains.forEach((index, k) => {
|
|
21765
|
-
if (k > 0) {
|
|
21766
|
-
results.push(" ", "&&", " ");
|
|
21767
|
-
}
|
|
21768
|
-
const [pre, op, post, exp] = binops[index];
|
|
21769
|
-
let endIndex;
|
|
21770
|
-
if (k < chains.length - 1) {
|
|
21771
|
-
endIndex = chains[k + 1];
|
|
21772
|
-
} else {
|
|
21773
|
-
endIndex = i + 1;
|
|
21774
|
-
}
|
|
21775
|
-
results = results.concat(first, ...binops.slice(start, endIndex));
|
|
21776
|
-
first = [exp].concat(binops.slice(index + 1, endIndex));
|
|
21777
|
-
start = endIndex;
|
|
21778
|
-
});
|
|
21779
|
-
} else {
|
|
21780
|
-
results = results.concat(first, ...binops.slice(start, i + 1));
|
|
21781
|
-
start = i + 1;
|
|
21782
|
-
}
|
|
21783
|
-
chains.length = 0;
|
|
21784
|
-
}
|
|
21785
|
-
};
|
|
21786
|
-
module.parsePosition = function() {
|
|
21787
|
-
let s = Error().stack.split(/\n at /);
|
|
21788
|
-
s.shift();
|
|
21789
|
-
s = s.filter((e) => !e.match(/^eval/)).map((e) => e.split(" ")[0]);
|
|
21790
|
-
s = s.slice(1, s.indexOf("Program") + 1);
|
|
21791
|
-
return s;
|
|
21792
|
-
};
|
|
21793
|
-
module.prune = function(node) {
|
|
21794
|
-
if (node === null || node === void 0)
|
|
21795
|
-
return;
|
|
21796
|
-
if (node.length === 0)
|
|
21797
|
-
return;
|
|
21798
|
-
if (Array.isArray(node)) {
|
|
21799
|
-
const a = node.map((n) => module.prune(n)).filter((n) => !!n);
|
|
21800
|
-
if (a.length > 1)
|
|
21801
|
-
return a;
|
|
21802
|
-
if (a.length === 1)
|
|
21803
|
-
return a[0];
|
|
21804
|
-
return;
|
|
21805
|
-
}
|
|
21806
|
-
if (node.children != null) {
|
|
21807
|
-
node.children = module.prune(node.children);
|
|
21808
|
-
return node;
|
|
21809
|
-
}
|
|
21810
|
-
return node;
|
|
21811
|
-
};
|
|
21812
|
-
module.skipIfOnlyWS = function(target) {
|
|
21813
|
-
if (!target)
|
|
21814
|
-
return target;
|
|
21815
|
-
if (Array.isArray(target)) {
|
|
21816
|
-
if (target.length === 1) {
|
|
21817
|
-
return module.skipIfOnlyWS(target[0]);
|
|
21818
|
-
} else if (target.every((e) => module.skipIfOnlyWS(e) === void 0)) {
|
|
21819
|
-
return void 0;
|
|
21820
|
-
}
|
|
21821
|
-
return target;
|
|
21822
|
-
}
|
|
21823
|
-
if (target.token != null && target.token.trim() === "") {
|
|
21824
|
-
return void 0;
|
|
21825
|
-
}
|
|
21826
|
-
return target;
|
|
21827
|
-
};
|
|
21828
|
-
const initialSpacingRe = /^(?:\r?\n|\n)*((?:\r?\n|\n)\s+)/;
|
|
21829
|
-
module.dedentBlockSubstitutions = function($02) {
|
|
21830
|
-
const [s, strWithSubstitutions, e] = $02;
|
|
21831
|
-
if (strWithSubstitutions.length === 0) {
|
|
21832
|
-
return $02;
|
|
21833
|
-
}
|
|
21834
|
-
let initialSpacing, i = 0, l = strWithSubstitutions.length, results = [s];
|
|
21835
|
-
const { token } = strWithSubstitutions[0];
|
|
21836
|
-
if (token) {
|
|
21837
|
-
initialSpacing = token.match(initialSpacingRe);
|
|
21838
|
-
} else {
|
|
21839
|
-
initialSpacing = false;
|
|
21840
|
-
}
|
|
21841
|
-
while (i < l) {
|
|
21842
|
-
let segment = strWithSubstitutions[i];
|
|
21843
|
-
if (segment.token) {
|
|
21844
|
-
segment = module.dedentBlockString(segment, initialSpacing, false);
|
|
21845
|
-
if (i === 0) {
|
|
21846
|
-
segment.token = segment.token.replace(/^(\r?\n|\n)/, "");
|
|
21847
|
-
}
|
|
21848
|
-
if (i === l - 1) {
|
|
21849
|
-
segment.token = segment.token.replace(/(\r?\n|\n)[ \t]*$/, "");
|
|
21850
|
-
}
|
|
21851
|
-
results.push(segment);
|
|
21852
|
-
} else {
|
|
21853
|
-
results.push(segment);
|
|
21854
|
-
}
|
|
21855
|
-
i++;
|
|
21856
|
-
}
|
|
21857
|
-
results.push(e);
|
|
21858
|
-
return {
|
|
21859
|
-
type: "TemplateLiteral",
|
|
21860
|
-
children: results
|
|
21861
|
-
};
|
|
21862
|
-
};
|
|
21863
|
-
module.dedentBlockString = function({ $loc: $loc2, token: str }, spacing, trim = true) {
|
|
21864
|
-
if (spacing == null)
|
|
21865
|
-
spacing = str.match(initialSpacingRe);
|
|
21866
|
-
if (spacing) {
|
|
21867
|
-
str = str.replaceAll(spacing[1], "\n");
|
|
21868
|
-
const l = spacing.length;
|
|
21869
|
-
$loc2.pos += l;
|
|
21870
|
-
$loc2.length -= l;
|
|
21871
|
-
}
|
|
21872
|
-
if (trim) {
|
|
21873
|
-
str = str.replace(/^(\r?\n|\n)/, "").replace(/(\r?\n|\n)[ \t]*$/, "");
|
|
21874
|
-
}
|
|
21875
|
-
str = str.replace(/(\\.|`|\$\{)/g, (s) => {
|
|
21876
|
-
if (s[0] === "\\") {
|
|
21877
|
-
return s;
|
|
21878
|
-
}
|
|
21879
|
-
return `\\${s}`;
|
|
21880
|
-
});
|
|
21881
|
-
return {
|
|
21882
|
-
$loc: $loc2,
|
|
21883
|
-
token: str
|
|
21884
|
-
};
|
|
21885
|
-
};
|
|
21886
|
-
module.adjustBindingElements = function(elements) {
|
|
21887
|
-
const names = elements.flatMap((p) => p.names || []), { length } = elements;
|
|
21888
|
-
let blockPrefix, restIndex = -1, restCount = 0;
|
|
21889
|
-
elements.forEach(({ type }, i) => {
|
|
21890
|
-
if (type === "BindingRestElement") {
|
|
21891
|
-
if (restIndex < 0)
|
|
21892
|
-
restIndex = i;
|
|
21893
|
-
restCount++;
|
|
21894
|
-
}
|
|
21895
|
-
});
|
|
21896
|
-
if (restCount === 0) {
|
|
21897
|
-
return {
|
|
21898
|
-
children: elements,
|
|
21899
|
-
names,
|
|
21900
|
-
blockPrefix,
|
|
21901
|
-
length
|
|
21902
|
-
};
|
|
21903
|
-
} else if (restCount === 1) {
|
|
21904
|
-
const rest = elements[restIndex];
|
|
21905
|
-
const after = elements.slice(restIndex + 1);
|
|
21906
|
-
const restIdentifier = rest.binding.ref || rest.binding;
|
|
21907
|
-
names.push(...rest.names || []);
|
|
21908
|
-
if (after.length) {
|
|
21909
|
-
blockPrefix = {
|
|
21910
|
-
type: "PostRestBindingElements",
|
|
21911
|
-
children: ["[", insertTrimmingSpace(after, ""), "] = ", restIdentifier, ".splice(-", after.length.toString(), ")"],
|
|
21912
|
-
names: after.flatMap((p) => p.names)
|
|
21913
|
-
};
|
|
21914
|
-
}
|
|
21915
|
-
return {
|
|
21916
|
-
names,
|
|
21917
|
-
children: [...elements.slice(0, restIndex), {
|
|
21918
|
-
...rest,
|
|
21919
|
-
children: rest.children.slice(0, -1)
|
|
21920
|
-
}],
|
|
21921
|
-
blockPrefix,
|
|
21922
|
-
length
|
|
21923
|
-
};
|
|
21924
|
-
}
|
|
21925
|
-
const err = {
|
|
21926
|
-
type: "Error",
|
|
21927
|
-
children: ["Multiple rest elements in array pattern"]
|
|
21928
|
-
};
|
|
21929
|
-
return {
|
|
21930
|
-
names,
|
|
21931
|
-
children: [...elements, err],
|
|
21932
|
-
blockPrefix,
|
|
21933
|
-
length
|
|
21934
|
-
};
|
|
21935
|
-
};
|
|
21936
|
-
module.reorderBindingRestProperty = function(props) {
|
|
21937
|
-
const names = props.flatMap((p) => p.names);
|
|
21938
|
-
let restIndex = -1;
|
|
21939
|
-
let restCount = 0;
|
|
21940
|
-
props.forEach(({ type }, i) => {
|
|
21941
|
-
if (type === "BindingRestProperty") {
|
|
21942
|
-
if (restIndex < 0)
|
|
21943
|
-
restIndex = i;
|
|
21944
|
-
restCount++;
|
|
21945
|
-
}
|
|
21946
|
-
});
|
|
21947
|
-
if (restCount === 0) {
|
|
21948
|
-
return {
|
|
21949
|
-
children: props,
|
|
21950
|
-
names
|
|
21951
|
-
};
|
|
21952
|
-
} else if (restCount === 1) {
|
|
21953
|
-
let after = props.slice(restIndex + 1);
|
|
21954
|
-
let rest = props[restIndex];
|
|
21955
|
-
props = props.slice(0, restIndex);
|
|
21956
|
-
if (after.length) {
|
|
21957
|
-
const [restDelim] = rest.children.slice(-1), lastAfterProp = after[after.length - 1], lastAfterChildren = lastAfterProp.children, [lastDelim] = lastAfterChildren.slice(-1);
|
|
21958
|
-
rest = { ...rest, children: [...rest.children.slice(0, -1), lastDelim] };
|
|
21959
|
-
after = [...after.slice(0, -1), { ...lastAfterProp, children: [...lastAfterChildren.slice(0, -1), restDelim] }];
|
|
21960
|
-
}
|
|
21961
|
-
const children = [...props, ...after, rest];
|
|
21962
|
-
return {
|
|
21963
|
-
children,
|
|
21964
|
-
names
|
|
21965
|
-
};
|
|
21966
|
-
}
|
|
21967
|
-
return {
|
|
21968
|
-
children: [{
|
|
21969
|
-
type: "Error",
|
|
21970
|
-
message: "Multiple rest properties in object pattern"
|
|
21971
|
-
}, props]
|
|
21972
|
-
};
|
|
21973
|
-
};
|
|
21974
|
-
function addParentPointers(node, parent) {
|
|
21975
|
-
if (node == null)
|
|
21976
|
-
return;
|
|
21977
|
-
if (typeof node !== "object")
|
|
21978
|
-
return;
|
|
21979
|
-
if (Array.isArray(node)) {
|
|
21980
|
-
for (const child of node) {
|
|
21981
|
-
addParentPointers(child, parent);
|
|
21982
|
-
}
|
|
21983
|
-
return;
|
|
21984
|
-
}
|
|
21985
|
-
node.parent = parent;
|
|
21986
|
-
if (node.children) {
|
|
21987
|
-
for (const child of node.children) {
|
|
21988
|
-
addParentPointers(child, node);
|
|
21989
|
-
}
|
|
21990
|
-
}
|
|
21991
|
-
}
|
|
21992
|
-
module.replaceNodes = (root, predicate, replacer) => {
|
|
21993
|
-
if (root == null)
|
|
21994
|
-
return root;
|
|
21995
|
-
const array = Array.isArray(root) ? root : root.children;
|
|
21996
|
-
if (!array)
|
|
21997
|
-
return root;
|
|
21998
|
-
array.forEach((node, i) => {
|
|
21999
|
-
if (node == null)
|
|
22000
|
-
return;
|
|
22001
|
-
if (predicate(node)) {
|
|
22002
|
-
array[i] = replacer(node, root);
|
|
22003
|
-
} else {
|
|
22004
|
-
module.replaceNodes(node, predicate, replacer);
|
|
22005
|
-
}
|
|
22006
|
-
});
|
|
22007
|
-
return root;
|
|
22008
|
-
};
|
|
22009
|
-
function processParams(f) {
|
|
22010
|
-
const { type, parameters, block } = f;
|
|
22011
|
-
if (type === "ArrowFunction" && parameters && parameters.tp && parameters.tp.parameters.length === 1) {
|
|
22012
|
-
parameters.tp.parameters.push(",");
|
|
22013
|
-
}
|
|
22014
|
-
if (!block)
|
|
22015
|
-
return;
|
|
22016
|
-
const { expressions } = block;
|
|
22017
|
-
if (!expressions)
|
|
22018
|
-
return;
|
|
22019
|
-
const { blockPrefix } = parameters;
|
|
22020
|
-
let indent;
|
|
22021
|
-
if (!expressions.length) {
|
|
22022
|
-
indent = "";
|
|
22023
|
-
} else {
|
|
22024
|
-
indent = expressions[0][0];
|
|
22025
|
-
}
|
|
22026
|
-
const [splices, thisAssignments] = gatherBindingCode(parameters, {
|
|
22027
|
-
injectParamProps: f.name === "constructor"
|
|
22028
|
-
});
|
|
22029
|
-
const delimiter = {
|
|
22030
|
-
type: "SemicolonDelimiter",
|
|
22031
|
-
children: [";"]
|
|
22032
|
-
};
|
|
22033
|
-
const prefix = splices.map((s) => ["let ", s]).concat(thisAssignments).map(
|
|
22034
|
-
(s) => s.type ? {
|
|
22035
|
-
...s,
|
|
22036
|
-
children: [indent, ...s.children, delimiter]
|
|
22037
|
-
} : [indent, s, delimiter]
|
|
22038
|
-
);
|
|
22039
|
-
expressions.unshift(...prefix);
|
|
22040
|
-
}
|
|
22041
|
-
function adjustAtBindings(statements, asThis = false) {
|
|
22042
|
-
gatherRecursiveAll(statements, (n) => n.type === "AtBindingProperty").forEach((binding) => {
|
|
22043
|
-
const { ref } = binding;
|
|
22044
|
-
if (asThis) {
|
|
22045
|
-
const atBinding = binding.binding;
|
|
22046
|
-
atBinding.children.pop();
|
|
22047
|
-
atBinding.type = void 0;
|
|
22048
|
-
binding.children.unshift(ref.id, ": this.", ref.base);
|
|
22049
|
-
binding.type = "Property";
|
|
22050
|
-
binding.ref = void 0;
|
|
22051
|
-
return;
|
|
22052
|
-
}
|
|
22053
|
-
if (ref.names[0] !== ref.base) {
|
|
22054
|
-
binding.children.unshift(ref.base, ": ");
|
|
22055
|
-
}
|
|
22056
|
-
});
|
|
22057
|
-
}
|
|
22058
|
-
function processReturnValue(func) {
|
|
22059
|
-
const { block } = func;
|
|
22060
|
-
const values = gatherRecursiveWithinFunction(
|
|
22061
|
-
block,
|
|
22062
|
-
({ type }) => type === "ReturnValue"
|
|
22063
|
-
);
|
|
22064
|
-
if (!values.length)
|
|
22065
|
-
return false;
|
|
22066
|
-
const ref = {
|
|
22067
|
-
type: "Ref",
|
|
22068
|
-
base: "ret",
|
|
22069
|
-
id: "ret"
|
|
22070
|
-
};
|
|
22071
|
-
let declared;
|
|
22072
|
-
values.forEach((value) => {
|
|
22073
|
-
value.children = [ref];
|
|
22074
|
-
const ancestor = findAncestor(
|
|
22075
|
-
value,
|
|
22076
|
-
({ type }) => type === "Declaration",
|
|
22077
|
-
isFunction
|
|
22078
|
-
);
|
|
22079
|
-
if (ancestor)
|
|
22080
|
-
declared = true;
|
|
22081
|
-
});
|
|
22082
|
-
if (!declared) {
|
|
22083
|
-
let returnType = func.returnType ?? func.signature?.returnType;
|
|
22084
|
-
if (returnType) {
|
|
22085
|
-
const { t } = returnType;
|
|
22086
|
-
if (t.type === "TypePredicate") {
|
|
22087
|
-
returnType = ": boolean";
|
|
22088
|
-
} else if (t.type === "AssertsType") {
|
|
22089
|
-
returnType = void 0;
|
|
22090
|
-
}
|
|
22091
|
-
}
|
|
22092
|
-
block.expressions.unshift([
|
|
22093
|
-
getIndent(block.expressions[0]),
|
|
22094
|
-
{
|
|
22095
|
-
type: "Declaration",
|
|
22096
|
-
children: ["let ", ref, returnType],
|
|
22097
|
-
names: []
|
|
22098
|
-
},
|
|
22099
|
-
";"
|
|
22100
|
-
]);
|
|
22101
|
-
}
|
|
22102
|
-
gatherRecursiveWithinFunction(
|
|
22103
|
-
block,
|
|
22104
|
-
(r) => r.type === "ReturnStatement" && !r.expression
|
|
22105
|
-
).forEach((r) => {
|
|
22106
|
-
r.expression = ref;
|
|
22107
|
-
r.children.splice(-1, 1, " ", ref);
|
|
22108
|
-
});
|
|
22109
|
-
if (block.children.at(-2)?.type !== "ReturnStatement") {
|
|
22110
|
-
block.expressions.push([
|
|
22111
|
-
[getIndent(block.expressions.at(-1))],
|
|
22112
|
-
{
|
|
22113
|
-
type: "ReturnStatement",
|
|
22114
|
-
expression: ref,
|
|
22115
|
-
children: ["return ", ref]
|
|
22116
|
-
}
|
|
22117
|
-
]);
|
|
22118
|
-
}
|
|
22119
|
-
return true;
|
|
22120
|
-
}
|
|
22121
|
-
function isVoidType(t) {
|
|
22122
|
-
return t?.type === "LiteralType" && t.t.type === "VoidType";
|
|
22123
|
-
}
|
|
22124
|
-
function processFunctions(statements) {
|
|
22125
|
-
gatherRecursiveAll(statements, ({ type }) => type === "FunctionExpression" || type === "ArrowFunction").forEach((f) => {
|
|
22126
|
-
processParams(f);
|
|
22127
|
-
if (!processReturnValue(f) && module.config.implicitReturns) {
|
|
22128
|
-
const { block, returnType } = f;
|
|
22129
|
-
const isVoid = isVoidType(returnType?.t);
|
|
22130
|
-
const isBlock = block?.type === "BlockStatement";
|
|
22131
|
-
if (!isVoid && isBlock) {
|
|
22132
|
-
insertReturn(block);
|
|
22133
|
-
}
|
|
22134
|
-
}
|
|
22135
|
-
});
|
|
22136
|
-
gatherRecursiveAll(statements, ({ type }) => type === "MethodDefinition").forEach((f) => {
|
|
22137
|
-
processParams(f);
|
|
22138
|
-
if (!processReturnValue(f) && module.config.implicitReturns) {
|
|
22139
|
-
const { signature, block } = f;
|
|
22140
|
-
const isConstructor = signature.name === "constructor";
|
|
22141
|
-
const isVoid = isVoidType(signature.returnType?.t);
|
|
22142
|
-
const isSet = signature.modifier?.set;
|
|
22143
|
-
if (!isConstructor && !isSet && !isVoid) {
|
|
22144
|
-
insertReturn(block);
|
|
22145
|
-
}
|
|
22146
|
-
}
|
|
22147
|
-
});
|
|
22148
|
-
}
|
|
22149
|
-
function processSwitchExpressions(statements) {
|
|
22150
|
-
if (module.config.implicitReturns) {
|
|
22151
|
-
gatherRecursiveAll(statements, (n) => n.type === "SwitchExpression").forEach(insertSwitchReturns);
|
|
22152
|
-
}
|
|
22153
|
-
}
|
|
22154
|
-
function processTryExpressions(statements) {
|
|
22155
|
-
if (module.config.implicitReturns) {
|
|
22156
|
-
gatherRecursiveAll(statements, (n) => n.type === "TryExpression").forEach(({ blocks }) => {
|
|
22157
|
-
blocks.forEach(insertReturn);
|
|
22158
|
-
});
|
|
22159
|
-
}
|
|
22160
|
-
}
|
|
22161
|
-
function processBindingPatternLHS(lhs, tail) {
|
|
22162
|
-
adjustAtBindings(lhs, true);
|
|
22163
|
-
const [splices, thisAssignments] = gatherBindingCode(lhs);
|
|
22164
|
-
tail.push(...splices.map((s) => [", ", s]), ...thisAssignments.map((a) => [", ", a]));
|
|
22165
|
-
}
|
|
22166
|
-
function processAssignments(statements) {
|
|
22167
|
-
gatherRecursiveAll(statements, (n) => n.type === "AssignmentExpression" && n.names === null).forEach((exp) => {
|
|
22168
|
-
let { lhs: $12, exp: $22 } = exp, tail = [], i = 0, len = $12.length;
|
|
22169
|
-
if ($12.some((left) => left[left.length - 1].special)) {
|
|
22170
|
-
if ($12.length !== 1) {
|
|
22171
|
-
throw new Error("Only one assignment with id= is allowed");
|
|
22172
|
-
}
|
|
22173
|
-
const [, lhs, , op] = $12[0];
|
|
22174
|
-
const { call } = op;
|
|
22175
|
-
op[op.length - 1] = "=";
|
|
22176
|
-
$22 = [call, "(", lhs, ", ", $22, ")"];
|
|
22177
|
-
}
|
|
22178
|
-
let wrapped = false;
|
|
22179
|
-
while (i < len) {
|
|
22180
|
-
const lastAssignment = $12[i++];
|
|
22181
|
-
const [, lhs, , op] = lastAssignment;
|
|
22182
|
-
if (op.token !== "=")
|
|
22183
|
-
continue;
|
|
22184
|
-
if (lhs.type === "ObjectExpression" || lhs.type === "ObjectBindingPattern") {
|
|
22185
|
-
if (!wrapped) {
|
|
22186
|
-
wrapped = true;
|
|
22187
|
-
lhs.children.splice(0, 0, "(");
|
|
22188
|
-
tail.push(")");
|
|
22189
|
-
}
|
|
22190
|
-
}
|
|
22191
|
-
}
|
|
22192
|
-
i = len - 1;
|
|
22193
|
-
while (i >= 0) {
|
|
22194
|
-
const lastAssignment = $12[i];
|
|
22195
|
-
if (lastAssignment[3].token === "=") {
|
|
22196
|
-
const lhs = lastAssignment[1];
|
|
22197
|
-
if (lhs.type === "MemberExpression") {
|
|
22198
|
-
const members = lhs.children;
|
|
22199
|
-
const lastMember = members[members.length - 1];
|
|
22200
|
-
if (lastMember.type === "SliceExpression") {
|
|
22201
|
-
const { start, end, children: c } = lastMember;
|
|
22202
|
-
c[0].token = ".splice(";
|
|
22203
|
-
c[1] = start;
|
|
22204
|
-
c[2] = ", ";
|
|
22205
|
-
if (end)
|
|
22206
|
-
c[3] = [end, " - ", start];
|
|
22207
|
-
else
|
|
22208
|
-
c[3] = ["1/0"];
|
|
22209
|
-
c[4] = [", ...", $22];
|
|
22210
|
-
c[5] = ")";
|
|
22211
|
-
lastAssignment.pop();
|
|
22212
|
-
if (module.isWhitespaceOrEmpty(lastAssignment[2]))
|
|
22213
|
-
lastAssignment.pop();
|
|
22214
|
-
if ($12.length > 1) {
|
|
22215
|
-
throw new Error("Not implemented yet! TODO: Handle multiple splice assignments");
|
|
22216
|
-
}
|
|
22217
|
-
exp.children = [$12];
|
|
22218
|
-
exp.names = [];
|
|
22219
|
-
return;
|
|
22220
|
-
}
|
|
22221
|
-
} else if (lhs.type === "ObjectBindingPattern" || lhs.type === "ArrayBindingPattern") {
|
|
22222
|
-
processBindingPatternLHS(lhs, tail);
|
|
22223
|
-
}
|
|
22224
|
-
}
|
|
22225
|
-
i--;
|
|
22226
|
-
}
|
|
22227
|
-
const names = $12.flatMap(([, l]) => l.names || []);
|
|
22228
|
-
exp.children = [$12, $22, ...tail];
|
|
22229
|
-
exp.names = names;
|
|
22230
|
-
});
|
|
22231
|
-
gatherRecursiveAll(statements, (n) => n.type === "AssignmentExpression" || n.type === "UpdateExpression").forEach((exp) => {
|
|
22232
|
-
function extractAssignment(lhs) {
|
|
22233
|
-
let expr = lhs;
|
|
22234
|
-
while (expr.type === "ParenthesizedExpression") {
|
|
22235
|
-
expr = expr.expression;
|
|
22236
|
-
}
|
|
22237
|
-
if (expr.type === "AssignmentExpression" || expr.type === "UpdateExpression") {
|
|
22238
|
-
if (expr.type === "UpdateExpression" && expr.children[0] === expr.assigned) {
|
|
22239
|
-
post.push([", ", lhs]);
|
|
22240
|
-
} else {
|
|
22241
|
-
pre.push([lhs, ", "]);
|
|
22242
|
-
}
|
|
22243
|
-
return expr.assigned;
|
|
22244
|
-
}
|
|
22245
|
-
}
|
|
22246
|
-
const pre = [], post = [];
|
|
22247
|
-
switch (exp.type) {
|
|
22248
|
-
case "AssignmentExpression":
|
|
22249
|
-
if (!exp.lhs)
|
|
22250
|
-
return;
|
|
22251
|
-
exp.lhs.forEach((lhsPart, i) => {
|
|
22252
|
-
let newLhs2 = extractAssignment(lhsPart[1]);
|
|
22253
|
-
if (newLhs2) {
|
|
22254
|
-
lhsPart[1] = newLhs2;
|
|
22255
|
-
}
|
|
22256
|
-
});
|
|
22257
|
-
break;
|
|
22258
|
-
case "UpdateExpression":
|
|
22259
|
-
let newLhs = extractAssignment(exp.assigned);
|
|
22260
|
-
if (newLhs) {
|
|
22261
|
-
const i = exp.children.indexOf(exp.assigned);
|
|
22262
|
-
exp.assigned = exp.children[i] = newLhs;
|
|
22263
|
-
}
|
|
22264
|
-
break;
|
|
22265
|
-
}
|
|
22266
|
-
if (pre.length)
|
|
22267
|
-
exp.children.unshift(...pre);
|
|
22268
|
-
if (post.length)
|
|
22269
|
-
exp.children.push(...post);
|
|
22270
|
-
});
|
|
22271
|
-
}
|
|
22272
|
-
module.attachPostfixStatementAsExpression = function(exp, post) {
|
|
22273
|
-
let clause;
|
|
22274
|
-
switch (post[1].type) {
|
|
22275
|
-
case "ForStatement":
|
|
22276
|
-
case "IterationStatement":
|
|
22277
|
-
case "DoStatement":
|
|
22278
|
-
clause = module.addPostfixStatement(exp, ...post);
|
|
22279
|
-
return {
|
|
22280
|
-
type: "IterationExpression",
|
|
22281
|
-
children: [clause],
|
|
22282
|
-
block: clause.block
|
|
22283
|
-
};
|
|
22284
|
-
case "IfStatement":
|
|
22285
|
-
clause = module.expressionizeIfClause(post[1], exp);
|
|
22286
|
-
return clause;
|
|
22287
|
-
default:
|
|
22288
|
-
throw new Error("Unknown postfix statement");
|
|
22289
|
-
}
|
|
22290
|
-
};
|
|
22291
|
-
function getPatternConditions(pattern, ref, conditions) {
|
|
22292
|
-
if (pattern.rest)
|
|
22293
|
-
return;
|
|
22294
|
-
switch (pattern.type) {
|
|
22295
|
-
case "ArrayBindingPattern": {
|
|
22296
|
-
const { elements, length } = pattern, hasRest = elements.some((e) => e.rest), comparator = hasRest ? " >= " : " === ", l = [comparator, (length - hasRest).toString()];
|
|
22297
|
-
conditions.push(
|
|
22298
|
-
["Array.isArray(", ref, ")"],
|
|
22299
|
-
[ref, ".length", l]
|
|
22300
|
-
);
|
|
22301
|
-
elements.forEach(({ children: [, e] }, i) => {
|
|
22302
|
-
const subRef = [ref, "[", i.toString(), "]"];
|
|
22303
|
-
getPatternConditions(e, subRef, conditions);
|
|
22304
|
-
});
|
|
22305
|
-
const postRest = pattern.children.find((c) => c?.blockPrefix);
|
|
22306
|
-
if (postRest) {
|
|
22307
|
-
const postElements = postRest.blockPrefix.children[1], { length: postLength } = postElements;
|
|
22308
|
-
postElements.forEach(({ children: [, e] }, i) => {
|
|
22309
|
-
const subRef = [ref, "[", ref, ".length - ", (postLength + i).toString(), "]"];
|
|
22310
|
-
getPatternConditions(e, subRef, conditions);
|
|
22311
|
-
});
|
|
22312
|
-
}
|
|
22313
|
-
break;
|
|
22314
|
-
}
|
|
22315
|
-
case "ObjectBindingPattern": {
|
|
22316
|
-
conditions.push(
|
|
22317
|
-
["typeof ", ref, " === 'object'"],
|
|
22318
|
-
[ref, " != null"]
|
|
22319
|
-
);
|
|
22320
|
-
pattern.properties.forEach((p) => {
|
|
22321
|
-
switch (p.type) {
|
|
22322
|
-
case "PinProperty":
|
|
22323
|
-
case "BindingProperty": {
|
|
22324
|
-
const { name, value } = p;
|
|
22325
|
-
let subRef;
|
|
22326
|
-
switch (name.type) {
|
|
22327
|
-
case "ComputedPropertyName":
|
|
22328
|
-
conditions.push([name.expression, " in ", ref]);
|
|
22329
|
-
subRef = [ref, name];
|
|
22330
|
-
break;
|
|
22331
|
-
case "Literal":
|
|
22332
|
-
case "StringLiteral":
|
|
22333
|
-
case "NumericLiteral":
|
|
22334
|
-
conditions.push([name, " in ", ref]);
|
|
22335
|
-
subRef = [ref, "[", name, "]"];
|
|
22336
|
-
break;
|
|
22337
|
-
default:
|
|
22338
|
-
conditions.push(["'", name, "' in ", ref]);
|
|
22339
|
-
subRef = [ref, ".", name];
|
|
22340
|
-
}
|
|
22341
|
-
if (value) {
|
|
22342
|
-
getPatternConditions(value, subRef, conditions);
|
|
22343
|
-
}
|
|
22344
|
-
break;
|
|
22345
|
-
}
|
|
22346
|
-
}
|
|
22347
|
-
});
|
|
22348
|
-
break;
|
|
22349
|
-
}
|
|
22350
|
-
case "ConditionFragment":
|
|
22351
|
-
conditions.push(
|
|
22352
|
-
[ref, " ", pattern.children]
|
|
22353
|
-
);
|
|
22354
|
-
break;
|
|
22355
|
-
case "RegularExpressionLiteral": {
|
|
22356
|
-
conditions.push(
|
|
22357
|
-
["typeof ", ref, " === 'string'"],
|
|
22358
|
-
[pattern, ".test(", ref, ")"]
|
|
22359
|
-
);
|
|
22360
|
-
break;
|
|
22361
|
-
}
|
|
22362
|
-
case "PinPattern":
|
|
22363
|
-
conditions.push([
|
|
22364
|
-
ref,
|
|
22365
|
-
" === ",
|
|
22366
|
-
pattern.identifier
|
|
22367
|
-
]);
|
|
22368
|
-
break;
|
|
22369
|
-
case "Literal":
|
|
22370
|
-
conditions.push([
|
|
22371
|
-
ref,
|
|
22372
|
-
" === ",
|
|
22373
|
-
pattern
|
|
22374
|
-
]);
|
|
22375
|
-
break;
|
|
22376
|
-
default:
|
|
22377
|
-
break;
|
|
22378
|
-
}
|
|
22379
|
-
}
|
|
22380
|
-
function elideMatchersFromArrayBindings(elements) {
|
|
22381
|
-
return elements.map((el) => {
|
|
22382
|
-
if (el.type === "BindingRestElement") {
|
|
22383
|
-
return ["", el, void 0];
|
|
22384
|
-
}
|
|
22385
|
-
const { children: [ws, e, sep] } = el;
|
|
22386
|
-
switch (e.type) {
|
|
22387
|
-
case "Literal":
|
|
22388
|
-
case "RegularExpressionLiteral":
|
|
22389
|
-
case "StringLiteral":
|
|
22390
|
-
case "PinPattern":
|
|
22391
|
-
return sep;
|
|
22392
|
-
default:
|
|
22393
|
-
return [ws, nonMatcherBindings(e), sep];
|
|
22394
|
-
}
|
|
22395
|
-
});
|
|
22396
|
-
}
|
|
22397
|
-
function elideMatchersFromPropertyBindings(properties) {
|
|
22398
|
-
return properties.map((p) => {
|
|
22399
|
-
switch (p.type) {
|
|
22400
|
-
case "BindingProperty": {
|
|
22401
|
-
const { children, name, value } = p;
|
|
22402
|
-
const [ws] = children;
|
|
22403
|
-
const sep = children[children.length - 1];
|
|
22404
|
-
switch (value && value.type) {
|
|
22405
|
-
case "ArrayBindingPattern":
|
|
22406
|
-
case "ObjectBindingPattern":
|
|
22407
|
-
return {
|
|
22408
|
-
...p,
|
|
22409
|
-
children: [ws, name, ": ", nonMatcherBindings(value)]
|
|
22410
|
-
};
|
|
22411
|
-
case "Identifier":
|
|
22412
|
-
return p;
|
|
22413
|
-
case "Literal":
|
|
22414
|
-
case "RegularExpressionLiteral":
|
|
22415
|
-
case "StringLiteral":
|
|
22416
|
-
default:
|
|
22417
|
-
return {
|
|
22418
|
-
...p,
|
|
22419
|
-
children: [ws, name, sep]
|
|
22420
|
-
};
|
|
22421
|
-
}
|
|
22422
|
-
}
|
|
22423
|
-
case "PinProperty":
|
|
22424
|
-
case "BindingRestProperty":
|
|
22425
|
-
default:
|
|
22426
|
-
return p;
|
|
22427
|
-
}
|
|
22428
|
-
});
|
|
22429
|
-
}
|
|
22430
|
-
function nonMatcherBindings(pattern) {
|
|
22431
|
-
switch (pattern.type) {
|
|
22432
|
-
case "ArrayBindingPattern": {
|
|
22433
|
-
const elements = elideMatchersFromArrayBindings(pattern.elements);
|
|
22434
|
-
const children = ["[", elements, "]"];
|
|
22435
|
-
return {
|
|
22436
|
-
...pattern,
|
|
22437
|
-
children,
|
|
22438
|
-
elements
|
|
22439
|
-
};
|
|
22440
|
-
}
|
|
22441
|
-
case "PostRestBindingElements": {
|
|
22442
|
-
const els = elideMatchersFromArrayBindings(pattern.children[1]);
|
|
22443
|
-
return {
|
|
22444
|
-
...pattern,
|
|
22445
|
-
children: [
|
|
22446
|
-
pattern.children[0],
|
|
22447
|
-
els,
|
|
22448
|
-
...pattern.children.slice(2)
|
|
22449
|
-
]
|
|
22450
|
-
};
|
|
22451
|
-
}
|
|
22452
|
-
case "ObjectBindingPattern":
|
|
22453
|
-
return ["{", elideMatchersFromPropertyBindings(pattern.properties), "}"];
|
|
22454
|
-
default:
|
|
22455
|
-
return pattern;
|
|
22456
|
-
}
|
|
22457
|
-
}
|
|
22458
|
-
function aggregateDuplicateBindings(bindings) {
|
|
22459
|
-
const props = gatherRecursiveAll(bindings, (n) => n.type === "BindingProperty");
|
|
22460
|
-
const arrayBindings = gatherRecursiveAll(bindings, (n) => n.type === "ArrayBindingPattern");
|
|
22461
|
-
arrayBindings.forEach((a) => {
|
|
22462
|
-
const { elements } = a;
|
|
22463
|
-
elements.forEach((element) => {
|
|
22464
|
-
if (Array.isArray(element)) {
|
|
22465
|
-
const [, e] = element;
|
|
22466
|
-
if (e.type === "Identifier") {
|
|
22467
|
-
props.push(e);
|
|
22468
|
-
} else if (e.type === "BindingRestElement") {
|
|
22469
|
-
props.push(e);
|
|
22470
|
-
}
|
|
22471
|
-
}
|
|
22472
|
-
});
|
|
22473
|
-
});
|
|
22474
|
-
const declarations = [];
|
|
22475
|
-
const propsGroupedByName = /* @__PURE__ */ new Map();
|
|
22476
|
-
for (const p of props) {
|
|
22477
|
-
const { name, value } = p;
|
|
22478
|
-
const key = value?.name || name?.name || name;
|
|
22479
|
-
if (propsGroupedByName.has(key)) {
|
|
22480
|
-
propsGroupedByName.get(key).push(p);
|
|
22481
|
-
} else {
|
|
22482
|
-
propsGroupedByName.set(key, [p]);
|
|
22483
|
-
}
|
|
22484
|
-
}
|
|
22485
|
-
propsGroupedByName.forEach((shared, key) => {
|
|
22486
|
-
if (!key)
|
|
22487
|
-
return;
|
|
22488
|
-
if (ReservedWord({
|
|
22489
|
-
pos: 0,
|
|
22490
|
-
input: key
|
|
22491
|
-
})) {
|
|
22492
|
-
shared.forEach((p) => {
|
|
22493
|
-
const ref = {
|
|
22494
|
-
type: "Ref",
|
|
22495
|
-
base: `_${key}`,
|
|
22496
|
-
id: key
|
|
22497
|
-
};
|
|
22498
|
-
aliasBinding(p, ref);
|
|
22499
|
-
});
|
|
22500
|
-
return;
|
|
22501
|
-
}
|
|
22502
|
-
if (shared.length === 1)
|
|
22503
|
-
return;
|
|
22504
|
-
const refs = shared.map((p) => {
|
|
22505
|
-
const ref = {
|
|
22506
|
-
type: "Ref",
|
|
22507
|
-
base: key,
|
|
22508
|
-
id: key
|
|
22509
|
-
};
|
|
22510
|
-
aliasBinding(p, ref);
|
|
22511
|
-
return ref;
|
|
22512
|
-
});
|
|
22513
|
-
declarations.push(["const ", key, " = [", ...refs.map((r, i) => {
|
|
22514
|
-
return i === 0 ? r : [", ", r];
|
|
22515
|
-
}), "]"]);
|
|
22516
|
-
});
|
|
22517
|
-
return declarations;
|
|
22518
|
-
}
|
|
22519
|
-
function processPatternMatching(statements) {
|
|
22520
|
-
gatherRecursiveAll(statements, (n) => n.type === "SwitchStatement" || n.type === "SwitchExpression").forEach((s) => {
|
|
22521
|
-
const { caseBlock } = s;
|
|
22522
|
-
const { clauses } = caseBlock;
|
|
22523
|
-
let errors = false;
|
|
22524
|
-
let isPattern = false;
|
|
22525
|
-
if (clauses.some((c) => c.type === "PatternClause")) {
|
|
22526
|
-
isPattern = true;
|
|
22527
|
-
clauses.forEach((c) => {
|
|
22528
|
-
if (!(c.type === "PatternClause" || c.type === "DefaultClause")) {
|
|
22529
|
-
errors = true;
|
|
22530
|
-
c.children.push({
|
|
22531
|
-
type: "Error",
|
|
22532
|
-
message: "Can't mix pattern matching and non-pattern matching clauses"
|
|
22533
|
-
});
|
|
22534
|
-
}
|
|
22535
|
-
});
|
|
22536
|
-
}
|
|
22537
|
-
if (errors || !isPattern)
|
|
22538
|
-
return;
|
|
22539
|
-
let { expression } = s;
|
|
22540
|
-
if (expression.type === "ParenthesizedExpression") {
|
|
22541
|
-
expression = expression.expression;
|
|
22542
|
-
}
|
|
22543
|
-
let ref = module.needsRef(expression, "m") || expression;
|
|
22544
|
-
let prev = [], root = prev;
|
|
22545
|
-
const l = clauses.length;
|
|
22546
|
-
clauses.forEach((c, i) => {
|
|
22547
|
-
if (c.type === "DefaultClause") {
|
|
22548
|
-
prev.push(c.block);
|
|
22549
|
-
return;
|
|
22550
|
-
}
|
|
22551
|
-
let { patterns, block } = c;
|
|
22552
|
-
let pattern = patterns[0];
|
|
22553
|
-
const indent = block.expressions?.[0]?.[0] || "";
|
|
22554
|
-
const alternativeConditions = patterns.map((pattern2, i2) => {
|
|
22555
|
-
const conditions = [];
|
|
22556
|
-
getPatternConditions(pattern2, ref, conditions);
|
|
22557
|
-
return conditions;
|
|
22558
|
-
});
|
|
22559
|
-
const conditionExpression = alternativeConditions.map((conditions, i2) => {
|
|
22560
|
-
const conditionArray = conditions.map((c2, i3) => {
|
|
22561
|
-
if (i3 === 0)
|
|
22562
|
-
return c2;
|
|
22563
|
-
return [" && ", ...c2];
|
|
22564
|
-
});
|
|
22565
|
-
if (i2 === 0)
|
|
22566
|
-
return conditionArray;
|
|
22567
|
-
return [" || ", ...conditionArray];
|
|
22568
|
-
});
|
|
22569
|
-
const condition = {
|
|
22570
|
-
type: "ParenthesizedExpression",
|
|
22571
|
-
children: ["(", conditionExpression, ")"],
|
|
22572
|
-
expression: conditionExpression
|
|
22573
|
-
};
|
|
22574
|
-
const prefix = [];
|
|
22575
|
-
switch (pattern.type) {
|
|
22576
|
-
case "ArrayBindingPattern":
|
|
22577
|
-
if (pattern.length === 0)
|
|
22578
|
-
break;
|
|
22579
|
-
case "ObjectBindingPattern": {
|
|
22580
|
-
if (pattern.properties?.length === 0)
|
|
22581
|
-
break;
|
|
22582
|
-
let [splices, thisAssignments] = gatherBindingCode(pattern);
|
|
22583
|
-
const patternBindings = nonMatcherBindings(pattern);
|
|
22584
|
-
splices = splices.map((s2) => [", ", nonMatcherBindings(s2)]);
|
|
22585
|
-
thisAssignments = thisAssignments.map((a) => [indent, a, ";"]);
|
|
22586
|
-
const duplicateDeclarations = aggregateDuplicateBindings([patternBindings, splices]);
|
|
22587
|
-
prefix.push([indent, "const ", patternBindings, " = ", ref, splices, ";"]);
|
|
22588
|
-
prefix.push(...thisAssignments);
|
|
22589
|
-
prefix.push(...duplicateDeclarations.map((d) => [indent, d, ";"]));
|
|
22590
|
-
break;
|
|
22591
|
-
}
|
|
22592
|
-
}
|
|
22593
|
-
block.expressions.unshift(...prefix);
|
|
22594
|
-
const next = [];
|
|
22595
|
-
if (block.bare) {
|
|
22596
|
-
block.children.unshift(" {");
|
|
22597
|
-
block.children.push("}");
|
|
22598
|
-
block.bare = false;
|
|
22599
|
-
}
|
|
22600
|
-
if (i < l - 1)
|
|
22601
|
-
next.push("\n", "else ");
|
|
22602
|
-
prev.push(["", {
|
|
22603
|
-
type: "IfStatement",
|
|
22604
|
-
children: ["if", condition, block, next],
|
|
22605
|
-
then: block,
|
|
22606
|
-
else: next
|
|
22607
|
-
}]);
|
|
22608
|
-
prev = next;
|
|
22609
|
-
});
|
|
22610
|
-
if (module.config.implicitReturns && s.type === "SwitchExpression") {
|
|
22611
|
-
insertReturn(root[0]);
|
|
22612
|
-
root.splice(0, 1, module.wrapIIFE(root[0]));
|
|
22613
|
-
}
|
|
22614
|
-
s.type = "PatternMatchingStatement";
|
|
22615
|
-
s.children = [root];
|
|
22616
|
-
addParentPointers(s, s.parent);
|
|
22617
|
-
});
|
|
22618
|
-
}
|
|
22619
|
-
function processPipelineExpressions(statements) {
|
|
22620
|
-
gatherRecursiveAll(statements, (n) => n.type === "PipelineExpression").forEach((s) => {
|
|
22621
|
-
const [ws, , body] = s.children;
|
|
22622
|
-
let [, arg] = s.children;
|
|
22623
|
-
let i = 0, l = body.length;
|
|
22624
|
-
const refDec = [];
|
|
22625
|
-
const children = [ws, refDec];
|
|
22626
|
-
let usingRef = null;
|
|
22627
|
-
for (i = 0; i < l; i++) {
|
|
22628
|
-
const step = body[i];
|
|
22629
|
-
const [leadingComment, pipe, trailingComment, expr] = step;
|
|
22630
|
-
const returns = pipe.token === "||>";
|
|
22631
|
-
let ref, result, returning = returns ? arg : null;
|
|
22632
|
-
if (pipe.token === "|>=") {
|
|
22633
|
-
let initRef;
|
|
22634
|
-
if (i === 0) {
|
|
22635
|
-
outer:
|
|
22636
|
-
switch (arg.type) {
|
|
22637
|
-
case "MemberExpression":
|
|
22638
|
-
if (arg.children.length <= 2)
|
|
22639
|
-
break;
|
|
22640
|
-
case "CallExpression":
|
|
22641
|
-
const access = arg.children.pop();
|
|
22642
|
-
switch (access.type) {
|
|
22643
|
-
case "PropertyAccess":
|
|
22644
|
-
case "SliceExpression":
|
|
22645
|
-
break;
|
|
22646
|
-
default:
|
|
22647
|
-
children.unshift({
|
|
22648
|
-
type: "Error",
|
|
22649
|
-
$loc: pipe.token.$loc,
|
|
22650
|
-
message: `Can't assign to ${access.type}`
|
|
22651
|
-
});
|
|
22652
|
-
arg.children.push(access);
|
|
22653
|
-
break outer;
|
|
22654
|
-
}
|
|
22655
|
-
usingRef = module.needsRef({});
|
|
22656
|
-
initRef = {
|
|
22657
|
-
type: "AssignmentExpression",
|
|
22658
|
-
children: [usingRef, " = ", arg, ","]
|
|
22659
|
-
};
|
|
22660
|
-
arg = {
|
|
22661
|
-
type: "MemberExpression",
|
|
22662
|
-
children: [usingRef, access]
|
|
22663
|
-
};
|
|
22664
|
-
break;
|
|
22665
|
-
}
|
|
22666
|
-
children.pop();
|
|
22667
|
-
const lhs = [[
|
|
22668
|
-
[refDec, initRef],
|
|
22669
|
-
arg,
|
|
22670
|
-
[],
|
|
22671
|
-
{ token: "=", children: [" = "] }
|
|
22672
|
-
]];
|
|
22673
|
-
Object.assign(s, {
|
|
22674
|
-
type: "AssignmentExpression",
|
|
22675
|
-
children: [lhs, children],
|
|
22676
|
-
names: null,
|
|
22677
|
-
lhs,
|
|
22678
|
-
assigned: arg,
|
|
22679
|
-
exp: children
|
|
22680
|
-
});
|
|
22681
|
-
arg = clone(arg);
|
|
22682
|
-
if (arg.children[0].type === "Ref") {
|
|
22683
|
-
arg.children[0] = usingRef;
|
|
22684
|
-
}
|
|
22685
|
-
} else {
|
|
22686
|
-
children.unshift({
|
|
22687
|
-
type: "Error",
|
|
22688
|
-
$loc: pipe.token.$loc,
|
|
22689
|
-
message: "Can't use |>= in the middle of a pipeline"
|
|
22690
|
-
});
|
|
22691
|
-
}
|
|
22692
|
-
} else {
|
|
22693
|
-
s.children = children;
|
|
22694
|
-
}
|
|
22695
|
-
if (returns && (ref = module.needsRef(arg))) {
|
|
22696
|
-
usingRef = usingRef || ref;
|
|
22697
|
-
arg = {
|
|
22698
|
-
type: "ParenthesizedExpression",
|
|
22699
|
-
children: ["(", {
|
|
22700
|
-
type: "AssignmentExpression",
|
|
22701
|
-
children: [usingRef, " = ", arg]
|
|
22702
|
-
}, ")"]
|
|
22703
|
-
};
|
|
22704
|
-
returning = usingRef;
|
|
22820
|
+
const { forbidMultiLineImplicitObjectLiteral: s } = module;
|
|
22821
|
+
return s[s.length - 1];
|
|
22705
22822
|
}
|
|
22706
|
-
|
|
22707
|
-
|
|
22708
|
-
|
|
22709
|
-
|
|
22710
|
-
|
|
22711
|
-
},
|
|
22712
|
-
arg,
|
|
22713
|
-
returning
|
|
22714
|
-
);
|
|
22715
|
-
if (result.type === "ReturnStatement") {
|
|
22716
|
-
if (i < l - 1) {
|
|
22717
|
-
result.children.push({
|
|
22718
|
-
type: "Error",
|
|
22719
|
-
message: "Can't continue a pipeline after returning"
|
|
22720
|
-
});
|
|
22721
|
-
}
|
|
22722
|
-
arg = result;
|
|
22723
|
-
if (children[children.length - 1] === ",") {
|
|
22724
|
-
children.pop();
|
|
22725
|
-
children.push(";");
|
|
22726
|
-
}
|
|
22727
|
-
break;
|
|
22823
|
+
},
|
|
22824
|
+
newlineBinaryOpForbidden: {
|
|
22825
|
+
get() {
|
|
22826
|
+
const { forbidNewlineBinaryOp: s } = module;
|
|
22827
|
+
return s[s.length - 1];
|
|
22728
22828
|
}
|
|
22729
|
-
|
|
22730
|
-
|
|
22731
|
-
|
|
22732
|
-
|
|
22733
|
-
|
|
22829
|
+
},
|
|
22830
|
+
currentJSXTag: {
|
|
22831
|
+
get() {
|
|
22832
|
+
const { JSXTagStack: s } = module;
|
|
22833
|
+
return s[s.length - 1];
|
|
22734
22834
|
}
|
|
22735
22835
|
}
|
|
22736
|
-
if (usingRef) {
|
|
22737
|
-
refDec.unshift("let ", usingRef, ";");
|
|
22738
|
-
}
|
|
22739
|
-
children.push(arg);
|
|
22740
|
-
addParentPointers(s, s.parent);
|
|
22741
22836
|
});
|
|
22742
22837
|
}
|
|
22743
|
-
module.
|
|
22744
|
-
|
|
22745
|
-
|
|
22746
|
-
|
|
22747
|
-
|
|
22748
|
-
|
|
22749
|
-
|
|
22750
|
-
|
|
22751
|
-
|
|
22752
|
-
|
|
22753
|
-
|
|
22754
|
-
|
|
22755
|
-
|
|
22756
|
-
|
|
22757
|
-
|
|
22758
|
-
|
|
22759
|
-
|
|
22760
|
-
|
|
22761
|
-
|
|
22762
|
-
|
|
22763
|
-
|
|
22764
|
-
|
|
22765
|
-
|
|
22766
|
-
|
|
22767
|
-
|
|
22768
|
-
|
|
22769
|
-
|
|
22770
|
-
|
|
22771
|
-
|
|
22772
|
-
|
|
22773
|
-
|
|
22774
|
-
|
|
22775
|
-
|
|
22776
|
-
|
|
22777
|
-
|
|
22778
|
-
|
|
22779
|
-
|
|
22780
|
-
|
|
22781
|
-
|
|
22782
|
-
|
|
22783
|
-
|
|
22784
|
-
|
|
22785
|
-
|
|
22786
|
-
|
|
22787
|
-
|
|
22788
|
-
|
|
22789
|
-
|
|
22838
|
+
module.config = parse2.config = {
|
|
22839
|
+
autoVar: false,
|
|
22840
|
+
autoLet: false,
|
|
22841
|
+
coffeeBinaryExistential: false,
|
|
22842
|
+
coffeeBooleans: false,
|
|
22843
|
+
coffeeClasses: false,
|
|
22844
|
+
coffeeComment: false,
|
|
22845
|
+
coffeeDo: false,
|
|
22846
|
+
coffeeEq: false,
|
|
22847
|
+
coffeeForLoops: false,
|
|
22848
|
+
coffeeInterpolation: false,
|
|
22849
|
+
coffeeIsnt: false,
|
|
22850
|
+
coffeeJSX: false,
|
|
22851
|
+
coffeeLineContinuation: false,
|
|
22852
|
+
coffeeNot: false,
|
|
22853
|
+
coffeeOf: false,
|
|
22854
|
+
coffeePrototype: false,
|
|
22855
|
+
defaultElement: "div",
|
|
22856
|
+
implicitReturns: true,
|
|
22857
|
+
objectIs: false,
|
|
22858
|
+
react: false,
|
|
22859
|
+
solid: false,
|
|
22860
|
+
client: false,
|
|
22861
|
+
rewriteTsImports: true,
|
|
22862
|
+
server: false,
|
|
22863
|
+
tab: void 0,
|
|
22864
|
+
verbose: false
|
|
22865
|
+
};
|
|
22866
|
+
const asAny = {
|
|
22867
|
+
ts: true,
|
|
22868
|
+
children: [" as any"]
|
|
22869
|
+
};
|
|
22870
|
+
module.prelude = [];
|
|
22871
|
+
const preludeVar = "var ";
|
|
22872
|
+
const declareRef = {
|
|
22873
|
+
indexOf(indexOfRef) {
|
|
22874
|
+
const typeSuffix = {
|
|
22875
|
+
ts: true,
|
|
22876
|
+
children: [": <T>(this: T[], searchElement: T) => boolean"]
|
|
22877
|
+
};
|
|
22878
|
+
module.prelude.push(["", [preludeVar, indexOfRef, typeSuffix, " = [].indexOf", asAny, ";\n"]]);
|
|
22879
|
+
},
|
|
22880
|
+
hasProp(hasPropRef) {
|
|
22881
|
+
const typeSuffix = {
|
|
22882
|
+
ts: true,
|
|
22883
|
+
children: [": <T>(this: T, prop: keyof T) => boolean"]
|
|
22884
|
+
};
|
|
22885
|
+
module.prelude.push(["", [preludeVar, hasPropRef, typeSuffix, " = {}.hasOwnProperty", asAny, ";\n"]]);
|
|
22886
|
+
},
|
|
22887
|
+
is(isRef) {
|
|
22888
|
+
const typeSuffix = {
|
|
22889
|
+
ts: true,
|
|
22890
|
+
children: [": { <B, A extends B> (a: A, b: B): b is A, <A, B> (a: A, b: B): a is A & B }"]
|
|
22891
|
+
};
|
|
22892
|
+
module.prelude.push(["", [preludeVar, isRef, typeSuffix, " = Object.is", asAny, ";\n"]]);
|
|
22893
|
+
},
|
|
22894
|
+
modulo(moduloRef) {
|
|
22895
|
+
const typeSuffix = {
|
|
22896
|
+
ts: true,
|
|
22897
|
+
children: [": (a: number, b: number) => number"]
|
|
22898
|
+
};
|
|
22899
|
+
module.prelude.push(["", [preludeVar, moduloRef, typeSuffix, " = (a, b) => (a % b + b) % b;", "\n"]]);
|
|
22900
|
+
},
|
|
22901
|
+
xor(xorRef) {
|
|
22902
|
+
const typeSuffix = {
|
|
22903
|
+
ts: true,
|
|
22904
|
+
children: [": (a: unknown, b: unknown) => boolean"]
|
|
22905
|
+
};
|
|
22906
|
+
module.prelude.push(["", [preludeVar, xorRef, typeSuffix, " = (a, b) => a ? !b && a : b;", "\n"]]);
|
|
22907
|
+
},
|
|
22908
|
+
xnor(xnorRef) {
|
|
22909
|
+
const typeSuffix = {
|
|
22910
|
+
ts: true,
|
|
22911
|
+
children: [": (a: unknown, b: unknown) => boolean"]
|
|
22912
|
+
};
|
|
22913
|
+
module.prelude.push(["", [preludeVar, xnorRef, typeSuffix, " = (a, b) => a ? b : !b || a;", "\n"]]);
|
|
22914
|
+
},
|
|
22915
|
+
returnSymbol(ref) {
|
|
22916
|
+
module.prelude.push({
|
|
22917
|
+
children: [
|
|
22918
|
+
preludeVar,
|
|
22919
|
+
ref,
|
|
22920
|
+
` = Symbol("return")';
|
|
22921
|
+
`
|
|
22922
|
+
]
|
|
22790
22923
|
});
|
|
22791
|
-
}
|
|
22792
|
-
|
|
22793
|
-
|
|
22794
|
-
|
|
22795
|
-
|
|
22796
|
-
|
|
22797
|
-
|
|
22798
|
-
|
|
22799
|
-
|
|
22924
|
+
},
|
|
22925
|
+
JSX(jsxRef) {
|
|
22926
|
+
module.prelude.push({
|
|
22927
|
+
ts: true,
|
|
22928
|
+
children: [
|
|
22929
|
+
"import type { JSX as ",
|
|
22930
|
+
jsxRef,
|
|
22931
|
+
" } from 'solid-js';\n"
|
|
22932
|
+
]
|
|
22800
22933
|
});
|
|
22801
|
-
|
|
22802
|
-
|
|
22803
|
-
|
|
22804
|
-
|
|
22805
|
-
|
|
22806
|
-
|
|
22807
|
-
|
|
22808
|
-
|
|
22809
|
-
|
|
22810
|
-
|
|
22811
|
-
|
|
22812
|
-
|
|
22813
|
-
|
|
22814
|
-
|
|
22815
|
-
|
|
22816
|
-
|
|
22817
|
-
|
|
22818
|
-
if (!hasDec(x))
|
|
22819
|
-
return a.indexOf(x) === i;
|
|
22820
|
-
}).forEach(pushVar);
|
|
22821
|
-
const fnNodes = gatherNodes(statements, (s) => s.type === "FunctionExpression");
|
|
22822
|
-
const forNodes = gatherNodes(statements, (s) => s.type === "ForStatement");
|
|
22823
|
-
const blockNodes = new Set(gatherNodes(statements, (s) => s.type === "BlockStatement"));
|
|
22824
|
-
fnNodes.forEach(({ block }) => blockNodes.delete(block));
|
|
22825
|
-
forNodes.forEach(({ block }) => blockNodes.delete(block));
|
|
22826
|
-
blockNodes.forEach((block) => {
|
|
22827
|
-
createVarDecs(block.expressions, scopes, pushVar);
|
|
22828
|
-
});
|
|
22829
|
-
forNodes.forEach(({ block, declaration }) => {
|
|
22830
|
-
scopes.push(new Set(declaration.names));
|
|
22831
|
-
createVarDecs(block.expressions, scopes, pushVar);
|
|
22832
|
-
scopes.pop();
|
|
22833
|
-
});
|
|
22834
|
-
fnNodes.forEach(({ block, parameters }) => {
|
|
22835
|
-
scopes.push(new Set(parameters.names));
|
|
22836
|
-
createVarDecs(block.expressions, scopes);
|
|
22837
|
-
scopes.pop();
|
|
22838
|
-
});
|
|
22839
|
-
if (varIds.length) {
|
|
22840
|
-
const indent = getIndent(statements[0]);
|
|
22841
|
-
let delimiter = ";";
|
|
22842
|
-
if (statements[0][1]?.parent?.root) {
|
|
22843
|
-
delimiter = ";\n";
|
|
22844
|
-
}
|
|
22845
|
-
statements.unshift([indent, "var ", varIds.join(", "), delimiter]);
|
|
22846
|
-
}
|
|
22847
|
-
scopes.pop();
|
|
22848
|
-
}
|
|
22849
|
-
function createLetDecs(statements, scopes) {
|
|
22850
|
-
function findVarDecs(statements2, decs) {
|
|
22851
|
-
const declarationNames = gatherRecursive(
|
|
22852
|
-
statements2,
|
|
22853
|
-
(node) => node.type === "Declaration" && node.children && node.children.length > 0 && node.children[0].token && node.children[0].token.startsWith("var") || node.type === "FunctionExpression"
|
|
22854
|
-
).filter((node) => node.type === "Declaration").flatMap((node) => node.names);
|
|
22855
|
-
return new Set(declarationNames);
|
|
22856
|
-
}
|
|
22857
|
-
let declaredIdentifiers = findVarDecs(statements);
|
|
22858
|
-
function hasDec(name) {
|
|
22859
|
-
return declaredIdentifiers.has(name) || scopes.some((s) => s.has(name));
|
|
22860
|
-
}
|
|
22861
|
-
function gatherBlockOrOther(statement) {
|
|
22862
|
-
return gatherNodes(statement, (s) => s.type === "BlockStatement" || s.type === "AssignmentExpression" || s.type === "Declaration").flatMap((node) => {
|
|
22863
|
-
if (node.type == "BlockStatement")
|
|
22864
|
-
return node.bare ? gatherBlockOrOther(node.expressions) : node;
|
|
22865
|
-
else if (node.children && node.children.length)
|
|
22866
|
-
return [...gatherBlockOrOther(node.children), node];
|
|
22867
|
-
else
|
|
22868
|
-
return [];
|
|
22934
|
+
},
|
|
22935
|
+
IntrinsicElements(intrinsicElementsRef) {
|
|
22936
|
+
const JSX = module.getRef("JSX");
|
|
22937
|
+
module.prelude.push({
|
|
22938
|
+
ts: true,
|
|
22939
|
+
children: [
|
|
22940
|
+
"type ",
|
|
22941
|
+
intrinsicElementsRef,
|
|
22942
|
+
"<K extends keyof ",
|
|
22943
|
+
JSX,
|
|
22944
|
+
".IntrinsicElements> =\n",
|
|
22945
|
+
" ",
|
|
22946
|
+
JSX,
|
|
22947
|
+
".IntrinsicElements[K] extends ",
|
|
22948
|
+
JSX,
|
|
22949
|
+
".DOMAttributes<infer T> ? T : unknown;\n"
|
|
22950
|
+
]
|
|
22869
22951
|
});
|
|
22870
22952
|
}
|
|
22871
|
-
|
|
22872
|
-
|
|
22873
|
-
|
|
22874
|
-
|
|
22875
|
-
|
|
22876
|
-
|
|
22877
|
-
|
|
22878
|
-
|
|
22879
|
-
|
|
22880
|
-
|
|
22881
|
-
|
|
22882
|
-
|
|
22883
|
-
|
|
22884
|
-
|
|
22885
|
-
|
|
22886
|
-
|
|
22887
|
-
|
|
22888
|
-
|
|
22889
|
-
|
|
22890
|
-
|
|
22891
|
-
|
|
22892
|
-
|
|
22893
|
-
|
|
22894
|
-
|
|
22895
|
-
|
|
22896
|
-
|
|
22897
|
-
|
|
22898
|
-
|
|
22899
|
-
|
|
22900
|
-
|
|
22901
|
-
|
|
22953
|
+
};
|
|
22954
|
+
const refs = {};
|
|
22955
|
+
module.getRef = function(base) {
|
|
22956
|
+
if (refs.hasOwnProperty(base))
|
|
22957
|
+
return refs[base];
|
|
22958
|
+
const ref = {
|
|
22959
|
+
type: "Ref",
|
|
22960
|
+
base,
|
|
22961
|
+
id: base
|
|
22962
|
+
};
|
|
22963
|
+
if (declareRef.hasOwnProperty(base))
|
|
22964
|
+
declareRef[base](ref);
|
|
22965
|
+
return refs[base] = ref;
|
|
22966
|
+
};
|
|
22967
|
+
Object.defineProperty(module.config, "deno", {
|
|
22968
|
+
set(b) {
|
|
22969
|
+
module.config.rewriteTsImports = !b;
|
|
22970
|
+
}
|
|
22971
|
+
});
|
|
22972
|
+
module.config.deno = typeof Deno !== "undefined";
|
|
22973
|
+
Object.defineProperty(module.config, "coffeeCompat", {
|
|
22974
|
+
set(b) {
|
|
22975
|
+
for (const option of [
|
|
22976
|
+
"autoVar",
|
|
22977
|
+
"coffeeBinaryExistential",
|
|
22978
|
+
"coffeeBooleans",
|
|
22979
|
+
"coffeeClasses",
|
|
22980
|
+
"coffeeComment",
|
|
22981
|
+
"coffeeDo",
|
|
22982
|
+
"coffeeEq",
|
|
22983
|
+
"coffeeForLoops",
|
|
22984
|
+
"coffeeInterpolation",
|
|
22985
|
+
"coffeeIsnt",
|
|
22986
|
+
"coffeeJSX",
|
|
22987
|
+
"coffeeLineContinuation",
|
|
22988
|
+
"coffeeNot",
|
|
22989
|
+
"coffeeOf",
|
|
22990
|
+
"coffeePrototype"
|
|
22991
|
+
]) {
|
|
22992
|
+
module.config[option] = b;
|
|
22902
22993
|
}
|
|
22903
|
-
if (
|
|
22904
|
-
|
|
22905
|
-
let firstIdentifier = gatherNodes(statement[1], (node) => node.type == "Identifier")[0];
|
|
22906
|
-
if (undeclaredIdentifiers.length == 1 && statement[1].type == "AssignmentExpression" && statement[1].names.length == 1 && statement[1].names[0] == undeclaredIdentifiers[0] && firstIdentifier && firstIdentifier.names == undeclaredIdentifiers[0] && gatherNodes(statement[1], (node) => node.type === "ObjectBindingPattern").length == 0)
|
|
22907
|
-
statement[1].children.unshift(["let "]);
|
|
22908
|
-
else {
|
|
22909
|
-
let tail = "\n";
|
|
22910
|
-
if (gatherNodes(indent, (node) => node.token && node.token.endsWith("\n")).length > 0)
|
|
22911
|
-
tail = void 0;
|
|
22912
|
-
targetStatements.push([indent, "let ", undeclaredIdentifiers.join(", "), tail]);
|
|
22913
|
-
}
|
|
22994
|
+
if (b) {
|
|
22995
|
+
module.config.objectIs = false;
|
|
22914
22996
|
}
|
|
22915
|
-
targetStatements.push(statement);
|
|
22916
|
-
}
|
|
22917
|
-
scopes.pop();
|
|
22918
|
-
statements.splice(0, statements.length, targetStatements);
|
|
22919
|
-
}
|
|
22920
|
-
module.constructInvocation = function(fn, arg) {
|
|
22921
|
-
const fnArr = [fn.leadingComment, fn.expr, fn.trailingComment];
|
|
22922
|
-
let expr = fn.expr;
|
|
22923
|
-
while (expr.type === "ParenthesizedExpression") {
|
|
22924
|
-
expr = expr.expression;
|
|
22925
|
-
}
|
|
22926
|
-
if (expr.ampersandBlock) {
|
|
22927
|
-
const { ref, body } = expr;
|
|
22928
|
-
ref.type = "PipedExpression";
|
|
22929
|
-
ref.children = [module.makeLeftHandSideExpression(arg)];
|
|
22930
|
-
return {
|
|
22931
|
-
type: "UnwrappedExpression",
|
|
22932
|
-
children: [module.skipIfOnlyWS(fn.leadingComment), ...body, module.skipIfOnlyWS(fn.trailingComment)]
|
|
22933
|
-
};
|
|
22934
|
-
}
|
|
22935
|
-
expr = fn.expr;
|
|
22936
|
-
const lhs = module.makeLeftHandSideExpression(expr);
|
|
22937
|
-
let comment = module.skipIfOnlyWS(fn.trailingComment);
|
|
22938
|
-
if (comment)
|
|
22939
|
-
lhs.children.splice(2, 0, comment);
|
|
22940
|
-
comment = module.skipIfOnlyWS(fn.leadingComment);
|
|
22941
|
-
if (comment)
|
|
22942
|
-
lhs.children.splice(1, 0, comment);
|
|
22943
|
-
switch (arg.type) {
|
|
22944
|
-
case "CommaExpression":
|
|
22945
|
-
arg = module.makeLeftHandSideExpression(arg);
|
|
22946
|
-
break;
|
|
22947
22997
|
}
|
|
22948
|
-
|
|
22949
|
-
|
|
22950
|
-
|
|
22951
|
-
|
|
22952
|
-
|
|
22953
|
-
|
|
22954
|
-
|
|
22955
|
-
|
|
22956
|
-
|
|
22957
|
-
|
|
22958
|
-
if (returning) {
|
|
22959
|
-
return [
|
|
22960
|
-
children,
|
|
22961
|
-
returning
|
|
22962
|
-
];
|
|
22963
|
-
}
|
|
22964
|
-
return [
|
|
22965
|
-
children,
|
|
22966
|
-
null
|
|
22967
|
-
];
|
|
22968
|
-
case "return":
|
|
22969
|
-
return [{
|
|
22970
|
-
type: "ReturnStatement",
|
|
22971
|
-
children
|
|
22972
|
-
}, null];
|
|
22998
|
+
});
|
|
22999
|
+
});
|
|
23000
|
+
function Reset(state) {
|
|
23001
|
+
let eventData;
|
|
23002
|
+
if (state.events) {
|
|
23003
|
+
const result = state.events.enter?.("Reset", state);
|
|
23004
|
+
if (result) {
|
|
23005
|
+
if (result.cache)
|
|
23006
|
+
return result.cache;
|
|
23007
|
+
eventData = result.data;
|
|
22973
23008
|
}
|
|
22974
|
-
|
|
22975
|
-
|
|
22976
|
-
|
|
22977
|
-
|
|
22978
|
-
|
|
23009
|
+
}
|
|
23010
|
+
if (state.tokenize) {
|
|
23011
|
+
const result = $TOKEN("Reset", state, Reset$0(state));
|
|
23012
|
+
if (state.events)
|
|
23013
|
+
state.events.exit?.("Reset", state, result, eventData);
|
|
23014
|
+
return result;
|
|
23015
|
+
} else {
|
|
23016
|
+
const result = Reset$0(state);
|
|
23017
|
+
if (state.events)
|
|
23018
|
+
state.events.exit?.("Reset", state, result, eventData);
|
|
23019
|
+
return result;
|
|
23020
|
+
}
|
|
23021
|
+
}
|
|
23022
|
+
var Init$0 = $TS($S($E(Shebang), $Q(DirectivePrologue), $EXPECT($L0, fail, 'Init ""')), function($skip, $loc, $0, $1, $2, $3) {
|
|
23023
|
+
var directives = $2;
|
|
23024
|
+
directives.forEach((directive) => {
|
|
23025
|
+
if (directive.type === "CivetPrologue") {
|
|
23026
|
+
Object.assign(module.config, directive.config);
|
|
22979
23027
|
}
|
|
22980
|
-
|
|
22981
|
-
};
|
|
23028
|
+
});
|
|
22982
23029
|
return $0;
|
|
22983
23030
|
});
|
|
22984
23031
|
function Init(state) {
|
|
@@ -23283,43 +23330,40 @@ ${input.slice(result.pos)}
|
|
|
23283
23330
|
exports.parse = parse2;
|
|
23284
23331
|
exports.default = { parse: parse2 };
|
|
23285
23332
|
var {
|
|
23286
|
-
|
|
23333
|
+
addPostfixStatement,
|
|
23334
|
+
adjustBindingElements,
|
|
23335
|
+
attachPostfixStatementAsExpression,
|
|
23287
23336
|
blockWithPrefix,
|
|
23288
|
-
clone,
|
|
23289
|
-
convertMethodToFunction,
|
|
23290
23337
|
convertObjectToJSXAttributes,
|
|
23291
23338
|
deepCopy,
|
|
23292
|
-
|
|
23339
|
+
dedentBlockString,
|
|
23340
|
+
dedentBlockSubstitutions,
|
|
23341
|
+
expressionizeIfClause,
|
|
23293
23342
|
forRange,
|
|
23294
23343
|
gatherBindingCode,
|
|
23295
|
-
gatherNodes,
|
|
23296
|
-
gatherRecursive,
|
|
23297
|
-
gatherRecursiveAll,
|
|
23298
|
-
gatherRecursiveWithinFunction,
|
|
23299
|
-
getIndent,
|
|
23300
23344
|
getTrimmingSpace,
|
|
23301
23345
|
hasAwait,
|
|
23302
23346
|
hasYield,
|
|
23303
|
-
hoistRefDecs,
|
|
23304
23347
|
insertTrimmingSpace,
|
|
23305
|
-
|
|
23348
|
+
isEmptyBareBlock,
|
|
23349
|
+
isWhitespaceOrEmpty,
|
|
23306
23350
|
lastAccessInCallExpression,
|
|
23307
23351
|
literalValue,
|
|
23352
|
+
makeLeftHandSideExpression,
|
|
23308
23353
|
modifyString,
|
|
23354
|
+
processBinaryOpExpression,
|
|
23355
|
+
processCallMemberExpression,
|
|
23309
23356
|
processCoffeeInterpolation,
|
|
23310
23357
|
processConstAssignmentDeclaration,
|
|
23311
23358
|
processLetAssignmentDeclaration,
|
|
23359
|
+
processProgram,
|
|
23312
23360
|
processUnaryExpression,
|
|
23313
23361
|
quoteString,
|
|
23314
|
-
|
|
23362
|
+
reorderBindingRestProperty,
|
|
23363
|
+
replaceNodes,
|
|
23364
|
+
typeOfJSX,
|
|
23365
|
+
wrapIIFE
|
|
23315
23366
|
} = require_lib();
|
|
23316
|
-
var assert = {
|
|
23317
|
-
equal(a, b, msg) {
|
|
23318
|
-
if (a !== b) {
|
|
23319
|
-
throw new Error(`Assertion failed [${msg}]: ${a} !== ${b}`);
|
|
23320
|
-
}
|
|
23321
|
-
}
|
|
23322
|
-
};
|
|
23323
23367
|
}
|
|
23324
23368
|
});
|
|
23325
23369
|
|