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