@danielx/civet 0.6.3 → 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 +2148 -2137
- package/dist/main.js +2148 -2137
- package/dist/main.mjs +2148 -2137
- 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;
|
|
@@ -53,6 +166,13 @@ var require_lib = __commonJS({
|
|
|
53
166
|
}
|
|
54
167
|
return false;
|
|
55
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
|
+
};
|
|
56
176
|
function blockWithPrefix(prefixStatements, block) {
|
|
57
177
|
if (prefixStatements && prefixStatements.length) {
|
|
58
178
|
const indent = getIndent(block.expressions[0]);
|
|
@@ -83,6 +203,126 @@ var require_lib = __commonJS({
|
|
|
83
203
|
removeParentPointers(node);
|
|
84
204
|
return deepCopy(node);
|
|
85
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
|
+
}
|
|
86
326
|
function deepCopy(node) {
|
|
87
327
|
if (node == null)
|
|
88
328
|
return node;
|
|
@@ -97,6 +337,356 @@ var require_lib = __commonJS({
|
|
|
97
337
|
})
|
|
98
338
|
);
|
|
99
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
|
+
}
|
|
100
690
|
function removeParentPointers(node) {
|
|
101
691
|
if (node == null)
|
|
102
692
|
return;
|
|
@@ -218,10 +808,123 @@ var require_lib = __commonJS({
|
|
|
218
808
|
node.hoistDec = null;
|
|
219
809
|
});
|
|
220
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
|
+
}
|
|
221
905
|
function isFunction(node) {
|
|
222
906
|
const { type } = node;
|
|
223
907
|
return type === "FunctionExpression" || type === "ArrowFunction" || type === "MethodDefinition" || node.async;
|
|
224
908
|
}
|
|
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
|
+
}
|
|
225
928
|
function gatherRecursiveWithinFunction(node, predicate) {
|
|
226
929
|
return gatherRecursive(node, predicate, isFunction);
|
|
227
930
|
}
|
|
@@ -258,62 +961,6 @@ var require_lib = __commonJS({
|
|
|
258
961
|
if (target.token)
|
|
259
962
|
return target.token.match(/^ ?/)[0];
|
|
260
963
|
}
|
|
261
|
-
function needsRef(exp) {
|
|
262
|
-
switch (exp.type) {
|
|
263
|
-
case "Identifier":
|
|
264
|
-
case "Literal":
|
|
265
|
-
case "Ref":
|
|
266
|
-
return false;
|
|
267
|
-
default:
|
|
268
|
-
return true;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
function maybeRef(exp, base = "ref") {
|
|
272
|
-
if (!needsRef(exp))
|
|
273
|
-
return exp;
|
|
274
|
-
return {
|
|
275
|
-
type: "Ref",
|
|
276
|
-
base,
|
|
277
|
-
id: base
|
|
278
|
-
};
|
|
279
|
-
}
|
|
280
|
-
function literalValue(literal) {
|
|
281
|
-
let { raw } = literal;
|
|
282
|
-
switch (raw) {
|
|
283
|
-
case "null":
|
|
284
|
-
return null;
|
|
285
|
-
case "true":
|
|
286
|
-
return true;
|
|
287
|
-
case "false":
|
|
288
|
-
return false;
|
|
289
|
-
}
|
|
290
|
-
if (raw.startsWith('"') && raw.endsWith('"') || raw.startsWith("'") && raw.endsWith("'")) {
|
|
291
|
-
return raw.slice(1, -1);
|
|
292
|
-
}
|
|
293
|
-
const numeric = literal.children.find(
|
|
294
|
-
(child) => child.type === "NumericLiteral"
|
|
295
|
-
);
|
|
296
|
-
if (numeric) {
|
|
297
|
-
raw = raw.replace(/_/g, "");
|
|
298
|
-
const { token } = numeric;
|
|
299
|
-
if (token.endsWith("n")) {
|
|
300
|
-
return BigInt(raw.slice(0, -1));
|
|
301
|
-
} else if (token.match(/[\.eE]/)) {
|
|
302
|
-
return parseFloat(raw);
|
|
303
|
-
} else if (token.startsWith("0")) {
|
|
304
|
-
switch (token.charAt(1).toLowerCase()) {
|
|
305
|
-
case "x":
|
|
306
|
-
return parseInt(raw.replace(/0[xX]/, ""), 16);
|
|
307
|
-
case "b":
|
|
308
|
-
return parseInt(raw.replace(/0[bB]/, ""), 2);
|
|
309
|
-
case "o":
|
|
310
|
-
return parseInt(raw.replace(/0[oO]/, ""), 8);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
return parseInt(raw, 10);
|
|
314
|
-
}
|
|
315
|
-
throw new Error("Unrecognized literal " + JSON.stringify(literal));
|
|
316
|
-
}
|
|
317
964
|
function forRange(open, forDeclaration, range, stepExp, close) {
|
|
318
965
|
const { start, end, inclusive } = range;
|
|
319
966
|
const counterRef = {
|
|
@@ -401,6 +1048,79 @@ var require_lib = __commonJS({
|
|
|
401
1048
|
insertRestSplices(statements, splices, thisAssignments);
|
|
402
1049
|
return [splices, thisAssignments];
|
|
403
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
|
+
}
|
|
404
1124
|
function modifyString(str) {
|
|
405
1125
|
return str.replace(/(^.?|[^\\]{2})(\\\\)*\n/g, "$1$2\\n");
|
|
406
1126
|
}
|
|
@@ -488,6 +1208,20 @@ var require_lib = __commonJS({
|
|
|
488
1208
|
}
|
|
489
1209
|
return parts;
|
|
490
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
|
+
}
|
|
491
1225
|
function processCoffeeInterpolation(s, parts, e, $loc) {
|
|
492
1226
|
if (parts.length === 0 || parts.length === 1 && parts[0].token != null) {
|
|
493
1227
|
return {
|
|
@@ -576,55 +1310,914 @@ var require_lib = __commonJS({
|
|
|
576
1310
|
thisAssignments
|
|
577
1311
|
};
|
|
578
1312
|
}
|
|
579
|
-
function
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
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 = [];
|
|
587
1432
|
switch (exp.type) {
|
|
588
|
-
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) {
|
|
589
1572
|
case "Literal":
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
1573
|
+
case "RegularExpressionLiteral":
|
|
1574
|
+
case "StringLiteral":
|
|
1575
|
+
case "PinPattern":
|
|
1576
|
+
return sep;
|
|
594
1577
|
default:
|
|
595
|
-
|
|
596
|
-
...exp,
|
|
597
|
-
children: [...pre, "(", exp.children, ")", post]
|
|
598
|
-
};
|
|
599
|
-
return {
|
|
600
|
-
type: "ParenthesizedExpression",
|
|
601
|
-
children: ["(", expression, ")"],
|
|
602
|
-
expression
|
|
603
|
-
};
|
|
1578
|
+
return [ws, nonMatcherBindings(e), sep];
|
|
604
1579
|
}
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
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, "]"];
|
|
611
1620
|
return {
|
|
612
|
-
|
|
1621
|
+
...pattern,
|
|
613
1622
|
children,
|
|
614
|
-
|
|
1623
|
+
elements
|
|
615
1624
|
};
|
|
616
1625
|
}
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
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]
|
|
628
2221
|
};
|
|
629
2222
|
}
|
|
630
2223
|
}
|
|
@@ -633,14 +2226,198 @@ var require_lib = __commonJS({
|
|
|
633
2226
|
children: [...pre, exp, post]
|
|
634
2227
|
};
|
|
635
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
|
+
}
|
|
636
2402
|
module2.exports = {
|
|
2403
|
+
addParentPointers,
|
|
2404
|
+
addPostfixStatement,
|
|
2405
|
+
adjustAtBindings,
|
|
2406
|
+
adjustBindingElements,
|
|
637
2407
|
aliasBinding,
|
|
638
2408
|
arrayElementHasTrailingComma,
|
|
2409
|
+
attachPostfixStatementAsExpression,
|
|
639
2410
|
blockWithPrefix,
|
|
640
2411
|
clone,
|
|
2412
|
+
constructInvocation,
|
|
2413
|
+
constructPipeStep,
|
|
641
2414
|
convertMethodToFunction,
|
|
642
2415
|
convertObjectToJSXAttributes,
|
|
2416
|
+
dedentBlockString,
|
|
2417
|
+
dedentBlockSubstitutions,
|
|
643
2418
|
deepCopy,
|
|
2419
|
+
expressionizeIfClause,
|
|
2420
|
+
expressionizeIteration,
|
|
644
2421
|
findAncestor,
|
|
645
2422
|
forRange,
|
|
646
2423
|
gatherBindingCode,
|
|
@@ -653,17 +2430,36 @@ var require_lib = __commonJS({
|
|
|
653
2430
|
hasAwait,
|
|
654
2431
|
hasYield,
|
|
655
2432
|
hoistRefDecs,
|
|
2433
|
+
insertReturn,
|
|
2434
|
+
insertSwitchReturns,
|
|
656
2435
|
insertTrimmingSpace,
|
|
2436
|
+
isEmptyBareBlock,
|
|
657
2437
|
isFunction,
|
|
2438
|
+
isVoidType,
|
|
2439
|
+
isWhitespaceOrEmpty,
|
|
658
2440
|
lastAccessInCallExpression,
|
|
659
2441
|
literalValue,
|
|
2442
|
+
makeAsConst,
|
|
2443
|
+
makeLeftHandSideExpression,
|
|
660
2444
|
modifyString,
|
|
2445
|
+
needsRef,
|
|
2446
|
+
processBinaryOpExpression,
|
|
2447
|
+
processCallMemberExpression,
|
|
661
2448
|
processCoffeeInterpolation,
|
|
662
2449
|
processConstAssignmentDeclaration,
|
|
663
2450
|
processLetAssignmentDeclaration,
|
|
2451
|
+
processParams,
|
|
2452
|
+
processProgram,
|
|
2453
|
+
processReturnValue,
|
|
664
2454
|
processUnaryExpression,
|
|
2455
|
+
prune: prune2,
|
|
665
2456
|
quoteString,
|
|
666
|
-
removeParentPointers
|
|
2457
|
+
removeParentPointers,
|
|
2458
|
+
reorderBindingRestProperty,
|
|
2459
|
+
replaceNodes,
|
|
2460
|
+
skipIfOnlyWS,
|
|
2461
|
+
typeOfJSX,
|
|
2462
|
+
wrapIIFE
|
|
667
2463
|
};
|
|
668
2464
|
}
|
|
669
2465
|
});
|
|
@@ -1958,13 +3754,13 @@ ${input.slice(result.pos)}
|
|
|
1958
3754
|
var $R65 = $R(new RegExp("[ \\t]*", "suy"));
|
|
1959
3755
|
var Program$0 = $TS($S(Reset, Init, $E(EOS), TopLevelStatements, __), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
|
|
1960
3756
|
var statements = $4;
|
|
1961
|
-
|
|
3757
|
+
processProgram({
|
|
1962
3758
|
type: "BlockStatement",
|
|
1963
3759
|
expressions: statements,
|
|
1964
3760
|
children: [statements],
|
|
1965
3761
|
bare: true,
|
|
1966
3762
|
root: true
|
|
1967
|
-
});
|
|
3763
|
+
}, module2.config, module2, ReservedWord);
|
|
1968
3764
|
return $0;
|
|
1969
3765
|
});
|
|
1970
3766
|
function Program(state) {
|
|
@@ -2339,7 +4135,7 @@ ${input.slice(result.pos)}
|
|
|
2339
4135
|
var ws = $4;
|
|
2340
4136
|
var args = $5;
|
|
2341
4137
|
var close = $6;
|
|
2342
|
-
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)) {
|
|
2343
4139
|
return $skip;
|
|
2344
4140
|
}
|
|
2345
4141
|
return [ta?.[0], open, insertTrimmingSpace(ws, ""), args, close];
|
|
@@ -2744,7 +4540,7 @@ ${input.slice(result.pos)}
|
|
|
2744
4540
|
}
|
|
2745
4541
|
var BinaryOpExpression$0 = $TS($S(UnaryExpression, $Q(BinaryOpRHS)), function($skip, $loc, $0, $1, $2) {
|
|
2746
4542
|
if ($2.length)
|
|
2747
|
-
return
|
|
4543
|
+
return processBinaryOpExpression($0);
|
|
2748
4544
|
return $1;
|
|
2749
4545
|
});
|
|
2750
4546
|
function BinaryOpExpression(state) {
|
|
@@ -3734,7 +5530,7 @@ ${input.slice(result.pos)}
|
|
|
3734
5530
|
var ExtendsTarget$0 = $TS($S(ExpressionWithIndentedApplicationForbidden, $E(TypeArguments)), function($skip, $loc, $0, $1, $2) {
|
|
3735
5531
|
var exp = $1;
|
|
3736
5532
|
var ta = $2;
|
|
3737
|
-
exp =
|
|
5533
|
+
exp = makeLeftHandSideExpression(exp);
|
|
3738
5534
|
if (ta)
|
|
3739
5535
|
return [exp, ta];
|
|
3740
5536
|
return exp;
|
|
@@ -4285,14 +6081,14 @@ ${input.slice(result.pos)}
|
|
|
4285
6081
|
}
|
|
4286
6082
|
var CallExpression$0 = $TS($S($EXPECT($L14, fail, 'CallExpression "super"'), ArgumentsWithTrailingMemberExpressions, $Q(CallExpressionRest)), function($skip, $loc, $0, $1, $2, $3) {
|
|
4287
6083
|
var rest = $3;
|
|
4288
|
-
return
|
|
6084
|
+
return processCallMemberExpression({
|
|
4289
6085
|
type: "CallExpression",
|
|
4290
6086
|
children: [$1, ...$2, ...rest.flat()]
|
|
4291
6087
|
});
|
|
4292
6088
|
});
|
|
4293
6089
|
var CallExpression$1 = $TS($S($EXPECT($L15, fail, 'CallExpression "import"'), ArgumentsWithTrailingMemberExpressions, $Q(CallExpressionRest)), function($skip, $loc, $0, $1, $2, $3) {
|
|
4294
6090
|
var rest = $3;
|
|
4295
|
-
return
|
|
6091
|
+
return processCallMemberExpression({
|
|
4296
6092
|
type: "CallExpression",
|
|
4297
6093
|
children: [$1, ...$2, ...rest.flat()]
|
|
4298
6094
|
});
|
|
@@ -4303,7 +6099,7 @@ ${input.slice(result.pos)}
|
|
|
4303
6099
|
var rest = $3;
|
|
4304
6100
|
if (rest.length || trailing.length) {
|
|
4305
6101
|
rest = rest.flat();
|
|
4306
|
-
return
|
|
6102
|
+
return processCallMemberExpression({
|
|
4307
6103
|
type: "CallExpression",
|
|
4308
6104
|
children: [member, ...trailing, ...rest]
|
|
4309
6105
|
});
|
|
@@ -4446,7 +6242,7 @@ ${input.slice(result.pos)}
|
|
|
4446
6242
|
var MemberExpression$0 = $TS($S($C(PrimaryExpression, SuperProperty, MetaProperty), $Q(MemberExpressionRest)), function($skip, $loc, $0, $1, $2) {
|
|
4447
6243
|
var rest = $2;
|
|
4448
6244
|
if (rest.length || Array.isArray($1)) {
|
|
4449
|
-
return
|
|
6245
|
+
return processCallMemberExpression({
|
|
4450
6246
|
type: "MemberExpression",
|
|
4451
6247
|
children: [$1, ...rest].flat()
|
|
4452
6248
|
});
|
|
@@ -5257,7 +7053,7 @@ ${input.slice(result.pos)}
|
|
|
5257
7053
|
var props = $0;
|
|
5258
7054
|
if (!props)
|
|
5259
7055
|
return { children: [], names: [] };
|
|
5260
|
-
return
|
|
7056
|
+
return reorderBindingRestProperty(props);
|
|
5261
7057
|
});
|
|
5262
7058
|
function ObjectBindingPatternContent(state) {
|
|
5263
7059
|
let eventData;
|
|
@@ -5349,7 +7145,7 @@ ${input.slice(result.pos)}
|
|
|
5349
7145
|
var elements = $0;
|
|
5350
7146
|
if (!elements)
|
|
5351
7147
|
return { children: [], names: [], length: 0 };
|
|
5352
|
-
return
|
|
7148
|
+
return adjustBindingElements(elements);
|
|
5353
7149
|
});
|
|
5354
7150
|
function ArrayBindingPatternContent(state) {
|
|
5355
7151
|
let eventData;
|
|
@@ -5465,7 +7261,7 @@ ${input.slice(result.pos)}
|
|
|
5465
7261
|
var props = $2;
|
|
5466
7262
|
if (!props.length)
|
|
5467
7263
|
return $skip;
|
|
5468
|
-
return
|
|
7264
|
+
return reorderBindingRestProperty(props.flat());
|
|
5469
7265
|
});
|
|
5470
7266
|
function NestedBindingProperties(state) {
|
|
5471
7267
|
let eventData;
|
|
@@ -5641,7 +7437,7 @@ ${input.slice(result.pos)}
|
|
|
5641
7437
|
var elements = $2;
|
|
5642
7438
|
if (!elements.length)
|
|
5643
7439
|
return $skip;
|
|
5644
|
-
return
|
|
7440
|
+
return adjustBindingElements(elements.flat());
|
|
5645
7441
|
});
|
|
5646
7442
|
function NestedBindingElements(state) {
|
|
5647
7443
|
let eventData;
|
|
@@ -5828,7 +7624,7 @@ ${input.slice(result.pos)}
|
|
|
5828
7624
|
var FunctionDeclaration$0 = $TS($S(FunctionExpression), function($skip, $loc, $0, $1) {
|
|
5829
7625
|
if ($1.id)
|
|
5830
7626
|
return $1;
|
|
5831
|
-
return
|
|
7627
|
+
return makeLeftHandSideExpression($1);
|
|
5832
7628
|
});
|
|
5833
7629
|
function FunctionDeclaration(state) {
|
|
5834
7630
|
let eventData;
|
|
@@ -6114,9 +7910,10 @@ ${input.slice(result.pos)}
|
|
|
6114
7910
|
return result;
|
|
6115
7911
|
}
|
|
6116
7912
|
}
|
|
6117
|
-
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) {
|
|
6118
7914
|
var callExpRest = $1;
|
|
6119
|
-
var
|
|
7915
|
+
var unaryPostfix = $2;
|
|
7916
|
+
var binopRHS = $3;
|
|
6120
7917
|
if (!callExpRest && !binopRHS)
|
|
6121
7918
|
return $skip;
|
|
6122
7919
|
const ref = {
|
|
@@ -6124,7 +7921,7 @@ ${input.slice(result.pos)}
|
|
|
6124
7921
|
base: "$",
|
|
6125
7922
|
id: "$"
|
|
6126
7923
|
};
|
|
6127
|
-
|
|
7924
|
+
let exp = {
|
|
6128
7925
|
type: "AmpersandRef",
|
|
6129
7926
|
children: [ref],
|
|
6130
7927
|
names: [],
|
|
@@ -6133,9 +7930,12 @@ ${input.slice(result.pos)}
|
|
|
6133
7930
|
if (callExpRest) {
|
|
6134
7931
|
exp.children.push(...callExpRest[1]);
|
|
6135
7932
|
}
|
|
7933
|
+
if (unaryPostfix) {
|
|
7934
|
+
exp = processUnaryExpression([], exp, unaryPostfix);
|
|
7935
|
+
}
|
|
6136
7936
|
if (binopRHS) {
|
|
6137
7937
|
return {
|
|
6138
|
-
children:
|
|
7938
|
+
children: processBinaryOpExpression([exp, binopRHS[1]]),
|
|
6139
7939
|
ref
|
|
6140
7940
|
};
|
|
6141
7941
|
}
|
|
@@ -8987,7 +10787,7 @@ ${input.slice(result.pos)}
|
|
|
8987
10787
|
var statement = $1;
|
|
8988
10788
|
var post = $2;
|
|
8989
10789
|
if (post)
|
|
8990
|
-
return
|
|
10790
|
+
return addPostfixStatement(statement, ...post);
|
|
8991
10791
|
return statement;
|
|
8992
10792
|
});
|
|
8993
10793
|
function PostfixedStatement(state) {
|
|
@@ -9016,7 +10816,7 @@ ${input.slice(result.pos)}
|
|
|
9016
10816
|
var expression = $1;
|
|
9017
10817
|
var post = $2;
|
|
9018
10818
|
if (post)
|
|
9019
|
-
return
|
|
10819
|
+
return attachPostfixStatementAsExpression(expression, post);
|
|
9020
10820
|
return expression;
|
|
9021
10821
|
});
|
|
9022
10822
|
function PostfixedExpression(state) {
|
|
@@ -9045,7 +10845,7 @@ ${input.slice(result.pos)}
|
|
|
9045
10845
|
var expression = $1;
|
|
9046
10846
|
var post = $2;
|
|
9047
10847
|
if (post)
|
|
9048
|
-
return
|
|
10848
|
+
return attachPostfixStatementAsExpression(expression, post);
|
|
9049
10849
|
return expression;
|
|
9050
10850
|
});
|
|
9051
10851
|
function NonPipelinePostfixedExpression(state) {
|
|
@@ -9107,7 +10907,7 @@ ${input.slice(result.pos)}
|
|
|
9107
10907
|
var Statement$7 = LabelledStatement;
|
|
9108
10908
|
var Statement$8 = $TS($S(ExpressionStatement), function($skip, $loc, $0, $1) {
|
|
9109
10909
|
if ($1.type === "ObjectExpression" || $1.type === "FunctionExpression" && !$1.id) {
|
|
9110
|
-
return
|
|
10910
|
+
return makeLeftHandSideExpression($1);
|
|
9111
10911
|
}
|
|
9112
10912
|
return $1;
|
|
9113
10913
|
});
|
|
@@ -9390,7 +11190,7 @@ ${input.slice(result.pos)}
|
|
|
9390
11190
|
var clause = $1;
|
|
9391
11191
|
var b = $2;
|
|
9392
11192
|
var e = $3;
|
|
9393
|
-
return
|
|
11193
|
+
return expressionizeIfClause(clause, b, e);
|
|
9394
11194
|
});
|
|
9395
11195
|
function IfExpression(state) {
|
|
9396
11196
|
let eventData;
|
|
@@ -9418,7 +11218,7 @@ ${input.slice(result.pos)}
|
|
|
9418
11218
|
var clause = $1;
|
|
9419
11219
|
var b = $2;
|
|
9420
11220
|
var e = $3;
|
|
9421
|
-
return
|
|
11221
|
+
return expressionizeIfClause(clause, b, e);
|
|
9422
11222
|
});
|
|
9423
11223
|
function UnlessExpression(state) {
|
|
9424
11224
|
let eventData;
|
|
@@ -10519,7 +12319,7 @@ ${input.slice(result.pos)}
|
|
|
10519
12319
|
var e = $0;
|
|
10520
12320
|
return {
|
|
10521
12321
|
type: "SwitchExpression",
|
|
10522
|
-
children:
|
|
12322
|
+
children: wrapIIFE(e.children),
|
|
10523
12323
|
expression: e.expression,
|
|
10524
12324
|
caseBlock: e.caseBlock
|
|
10525
12325
|
};
|
|
@@ -10886,7 +12686,7 @@ ${input.slice(result.pos)}
|
|
|
10886
12686
|
return {
|
|
10887
12687
|
type: "TryExpression",
|
|
10888
12688
|
blocks: t.blocks,
|
|
10889
|
-
children:
|
|
12689
|
+
children: wrapIIFE(t)
|
|
10890
12690
|
};
|
|
10891
12691
|
});
|
|
10892
12692
|
function TryExpression(state) {
|
|
@@ -11850,7 +13650,7 @@ ${input.slice(result.pos)}
|
|
|
11850
13650
|
var DebuggerExpression$0 = $TS($S(Debugger), function($skip, $loc, $0, $1) {
|
|
11851
13651
|
return {
|
|
11852
13652
|
type: "DebuggerExpression",
|
|
11853
|
-
children:
|
|
13653
|
+
children: wrapIIFE($1)
|
|
11854
13654
|
};
|
|
11855
13655
|
});
|
|
11856
13656
|
function DebuggerExpression(state) {
|
|
@@ -11878,7 +13678,7 @@ ${input.slice(result.pos)}
|
|
|
11878
13678
|
var ThrowExpression$0 = $TS($S(Throw, ExtendedExpression), function($skip, $loc, $0, $1, $2) {
|
|
11879
13679
|
return {
|
|
11880
13680
|
type: "ThrowExpression",
|
|
11881
|
-
children:
|
|
13681
|
+
children: wrapIIFE($0)
|
|
11882
13682
|
};
|
|
11883
13683
|
});
|
|
11884
13684
|
function ThrowExpression(state) {
|
|
@@ -13759,7 +15559,7 @@ ${input.slice(result.pos)}
|
|
|
13759
15559
|
}
|
|
13760
15560
|
}
|
|
13761
15561
|
var TemplateLiteral$0 = $TS($S(TripleTick, $Q($C(TemplateBlockCharacters, TemplateSubstitution)), TripleTick), function($skip, $loc, $0, $1, $2, $3) {
|
|
13762
|
-
return
|
|
15562
|
+
return dedentBlockSubstitutions($0);
|
|
13763
15563
|
});
|
|
13764
15564
|
var TemplateLiteral$1 = $TS($S(Backtick, $Q($C(TemplateCharacters, TemplateSubstitution)), Backtick), function($skip, $loc, $0, $1, $2, $3) {
|
|
13765
15565
|
return {
|
|
@@ -13768,7 +15568,7 @@ ${input.slice(result.pos)}
|
|
|
13768
15568
|
};
|
|
13769
15569
|
});
|
|
13770
15570
|
var TemplateLiteral$2 = $TS($S(TripleDoubleQuote, $Q($C(TripleDoubleStringCharacters, CoffeeStringSubstitution)), TripleDoubleQuote), function($skip, $loc, $0, $1, $2, $3) {
|
|
13771
|
-
return
|
|
15571
|
+
return dedentBlockSubstitutions($0);
|
|
13772
15572
|
});
|
|
13773
15573
|
var TemplateLiteral$3 = $TS($S(TripleSingleQuote, TripleSingleStringCharacters, TripleSingleQuote), function($skip, $loc, $0, $1, $2, $3) {
|
|
13774
15574
|
var s = $1;
|
|
@@ -13776,7 +15576,7 @@ ${input.slice(result.pos)}
|
|
|
13776
15576
|
var e = $3;
|
|
13777
15577
|
return {
|
|
13778
15578
|
type: "TemplateLiteral",
|
|
13779
|
-
children: [s,
|
|
15579
|
+
children: [s, dedentBlockString(str), e]
|
|
13780
15580
|
};
|
|
13781
15581
|
});
|
|
13782
15582
|
var TemplateLiteral$4 = CoffeeInterpolatedDoubleQuotedString;
|
|
@@ -16543,7 +18343,7 @@ ${input.slice(result.pos)}
|
|
|
16543
18343
|
],
|
|
16544
18344
|
jsxChildren: [$1].concat($2.map(([, tag]) => tag))
|
|
16545
18345
|
};
|
|
16546
|
-
const type =
|
|
18346
|
+
const type = typeOfJSX(jsx, module2.config, module2.getRef);
|
|
16547
18347
|
return type ? [
|
|
16548
18348
|
{ ts: true, children: ["("] },
|
|
16549
18349
|
jsx,
|
|
@@ -17023,7 +18823,7 @@ ${input.slice(result.pos)}
|
|
|
17023
18823
|
}
|
|
17024
18824
|
if (exprs.length === 1) {
|
|
17025
18825
|
let root = exprs[0];
|
|
17026
|
-
while (root.length &&
|
|
18826
|
+
while (root.length && isWhitespaceOrEmpty(root[root.length - 1])) {
|
|
17027
18827
|
root = root.slice(0, -1);
|
|
17028
18828
|
}
|
|
17029
18829
|
while (root?.length === 1)
|
|
@@ -17103,7 +18903,7 @@ ${input.slice(result.pos)}
|
|
|
17103
18903
|
children: [".", id],
|
|
17104
18904
|
name: id
|
|
17105
18905
|
};
|
|
17106
|
-
const expr =
|
|
18906
|
+
const expr = processCallMemberExpression({
|
|
17107
18907
|
type: "CallExpression",
|
|
17108
18908
|
children: [at, access, ...rest.flat()]
|
|
17109
18909
|
});
|
|
@@ -17127,7 +18927,7 @@ ${input.slice(result.pos)}
|
|
|
17127
18927
|
var JSXAttribute$4 = $TS($S(Identifier, $P(InlineJSXCallExpressionRest), $Y(JSXAttributeSpace)), function($skip, $loc, $0, $1, $2, $3) {
|
|
17128
18928
|
var id = $1;
|
|
17129
18929
|
var rest = $2;
|
|
17130
|
-
const expr =
|
|
18930
|
+
const expr = processCallMemberExpression({
|
|
17131
18931
|
type: "CallExpression",
|
|
17132
18932
|
children: [id, ...rest.flat()]
|
|
17133
18933
|
});
|
|
@@ -17325,7 +19125,7 @@ ${input.slice(result.pos)}
|
|
|
17325
19125
|
}
|
|
17326
19126
|
var InlineJSXAttributeValue$0 = $TS($S(InlineJSXUnaryExpression, $Q(InlineJSXBinaryOpRHS)), function($skip, $loc, $0, $1, $2) {
|
|
17327
19127
|
if ($2.length)
|
|
17328
|
-
return
|
|
19128
|
+
return processBinaryOpExpression($0);
|
|
17329
19129
|
return $1;
|
|
17330
19130
|
});
|
|
17331
19131
|
function InlineJSXAttributeValue(state) {
|
|
@@ -17484,7 +19284,7 @@ ${input.slice(result.pos)}
|
|
|
17484
19284
|
var InlineJSXCallExpression$0 = $TS($S($EXPECT($L14, fail, 'InlineJSXCallExpression "super"'), ExplicitArguments, $Q(InlineJSXCallExpressionRest)), function($skip, $loc, $0, $1, $2, $3) {
|
|
17485
19285
|
var args = $2;
|
|
17486
19286
|
var rest = $3;
|
|
17487
|
-
return
|
|
19287
|
+
return processCallMemberExpression({
|
|
17488
19288
|
type: "CallExpression",
|
|
17489
19289
|
children: [
|
|
17490
19290
|
$1,
|
|
@@ -17496,7 +19296,7 @@ ${input.slice(result.pos)}
|
|
|
17496
19296
|
var InlineJSXCallExpression$1 = $TS($S($EXPECT($L15, fail, 'InlineJSXCallExpression "import"'), ExplicitArguments, $Q(InlineJSXCallExpressionRest)), function($skip, $loc, $0, $1, $2, $3) {
|
|
17497
19297
|
var args = $2;
|
|
17498
19298
|
var rest = $3;
|
|
17499
|
-
return
|
|
19299
|
+
return processCallMemberExpression({
|
|
17500
19300
|
type: "CallExpression",
|
|
17501
19301
|
children: [
|
|
17502
19302
|
$1,
|
|
@@ -17510,7 +19310,7 @@ ${input.slice(result.pos)}
|
|
|
17510
19310
|
var rest = $2;
|
|
17511
19311
|
if (rest.length) {
|
|
17512
19312
|
rest = rest.flat();
|
|
17513
|
-
return
|
|
19313
|
+
return processCallMemberExpression({
|
|
17514
19314
|
type: "CallExpression",
|
|
17515
19315
|
children: [member, ...rest]
|
|
17516
19316
|
});
|
|
@@ -17578,7 +19378,7 @@ ${input.slice(result.pos)}
|
|
|
17578
19378
|
var InlineJSXMemberExpression$0 = $TS($S($C(InlineJSXPrimaryExpression, SuperProperty, MetaProperty), $Q(InlineJSXMemberExpressionRest)), function($skip, $loc, $0, $1, $2) {
|
|
17579
19379
|
var rest = $2;
|
|
17580
19380
|
if (rest.length || Array.isArray($1)) {
|
|
17581
|
-
return
|
|
19381
|
+
return processCallMemberExpression({
|
|
17582
19382
|
type: "MemberExpression",
|
|
17583
19383
|
children: [$1, ...rest].flat()
|
|
17584
19384
|
});
|
|
@@ -18671,7 +20471,7 @@ ${input.slice(result.pos)}
|
|
|
18671
20471
|
...block.properties.map((property, i) => {
|
|
18672
20472
|
let init, isString;
|
|
18673
20473
|
if (property.init) {
|
|
18674
|
-
init =
|
|
20474
|
+
init = replaceNodes(
|
|
18675
20475
|
deepCopy(property.init),
|
|
18676
20476
|
(n) => n.type === "Identifier" && names.has(n.name),
|
|
18677
20477
|
(n) => [id, '["', n.name, '"]']
|
|
@@ -21017,1999 +22817,214 @@ ${input.slice(result.pos)}
|
|
|
21017
22817
|
multiLineImplicitObjectLiteralForbidden: {
|
|
21018
22818
|
get() {
|
|
21019
22819
|
const { forbidMultiLineImplicitObjectLiteral: s } = module2;
|
|
21020
|
-
return s[s.length - 1];
|
|
21021
|
-
}
|
|
21022
|
-
},
|
|
21023
|
-
newlineBinaryOpForbidden: {
|
|
21024
|
-
get() {
|
|
21025
|
-
const { forbidNewlineBinaryOp: s } = module2;
|
|
21026
|
-
return s[s.length - 1];
|
|
21027
|
-
}
|
|
21028
|
-
},
|
|
21029
|
-
currentJSXTag: {
|
|
21030
|
-
get() {
|
|
21031
|
-
const { JSXTagStack: s } = module2;
|
|
21032
|
-
return s[s.length - 1];
|
|
21033
|
-
}
|
|
21034
|
-
}
|
|
21035
|
-
});
|
|
21036
|
-
}
|
|
21037
|
-
module2.config = parse2.config = {
|
|
21038
|
-
autoVar: false,
|
|
21039
|
-
autoLet: false,
|
|
21040
|
-
coffeeBinaryExistential: false,
|
|
21041
|
-
coffeeBooleans: false,
|
|
21042
|
-
coffeeClasses: false,
|
|
21043
|
-
coffeeComment: false,
|
|
21044
|
-
coffeeDo: false,
|
|
21045
|
-
coffeeEq: false,
|
|
21046
|
-
coffeeForLoops: false,
|
|
21047
|
-
coffeeInterpolation: false,
|
|
21048
|
-
coffeeIsnt: false,
|
|
21049
|
-
coffeeJSX: false,
|
|
21050
|
-
coffeeLineContinuation: false,
|
|
21051
|
-
coffeeNot: false,
|
|
21052
|
-
coffeeOf: false,
|
|
21053
|
-
coffeePrototype: false,
|
|
21054
|
-
defaultElement: "div",
|
|
21055
|
-
implicitReturns: true,
|
|
21056
|
-
objectIs: false,
|
|
21057
|
-
react: false,
|
|
21058
|
-
solid: false,
|
|
21059
|
-
client: false,
|
|
21060
|
-
rewriteTsImports: true,
|
|
21061
|
-
server: false,
|
|
21062
|
-
tab: void 0,
|
|
21063
|
-
verbose: false
|
|
21064
|
-
};
|
|
21065
|
-
module2.asAny = {
|
|
21066
|
-
ts: true,
|
|
21067
|
-
children: [" as any"]
|
|
21068
|
-
};
|
|
21069
|
-
module2.asConst = {
|
|
21070
|
-
ts: true,
|
|
21071
|
-
children: [" as const"]
|
|
21072
|
-
};
|
|
21073
|
-
module2.prelude = [];
|
|
21074
|
-
const preludeVar = "var ";
|
|
21075
|
-
const declareRef = {
|
|
21076
|
-
indexOf(indexOfRef) {
|
|
21077
|
-
const typeSuffix = {
|
|
21078
|
-
ts: true,
|
|
21079
|
-
children: [": <T>(this: T[], searchElement: T) => boolean"]
|
|
21080
|
-
};
|
|
21081
|
-
module2.prelude.push(["", [preludeVar, indexOfRef, typeSuffix, " = [].indexOf", module2.asAny, ";\n"]]);
|
|
21082
|
-
},
|
|
21083
|
-
hasProp(hasPropRef) {
|
|
21084
|
-
const typeSuffix = {
|
|
21085
|
-
ts: true,
|
|
21086
|
-
children: [": <T>(this: T, prop: keyof T) => boolean"]
|
|
21087
|
-
};
|
|
21088
|
-
module2.prelude.push(["", [preludeVar, hasPropRef, typeSuffix, " = {}.hasOwnProperty", module2.asAny, ";\n"]]);
|
|
21089
|
-
},
|
|
21090
|
-
is(isRef) {
|
|
21091
|
-
const typeSuffix = {
|
|
21092
|
-
ts: true,
|
|
21093
|
-
children: [": { <B, A extends B> (a: A, b: B): b is A, <A, B> (a: A, b: B): a is A & B }"]
|
|
21094
|
-
};
|
|
21095
|
-
module2.prelude.push(["", [preludeVar, isRef, typeSuffix, " = Object.is", module2.asAny, ";\n"]]);
|
|
21096
|
-
},
|
|
21097
|
-
modulo(moduloRef) {
|
|
21098
|
-
const typeSuffix = {
|
|
21099
|
-
ts: true,
|
|
21100
|
-
children: [": (a: number, b: number) => number"]
|
|
21101
|
-
};
|
|
21102
|
-
module2.prelude.push(["", [preludeVar, moduloRef, typeSuffix, " = (a, b) => (a % b + b) % b;", "\n"]]);
|
|
21103
|
-
},
|
|
21104
|
-
xor(xorRef) {
|
|
21105
|
-
const typeSuffix = {
|
|
21106
|
-
ts: true,
|
|
21107
|
-
children: [": (a: unknown, b: unknown) => boolean"]
|
|
21108
|
-
};
|
|
21109
|
-
module2.prelude.push(["", [preludeVar, xorRef, typeSuffix, " = (a, b) => a ? !b && a : b;", "\n"]]);
|
|
21110
|
-
},
|
|
21111
|
-
xnor(xnorRef) {
|
|
21112
|
-
const typeSuffix = {
|
|
21113
|
-
ts: true,
|
|
21114
|
-
children: [": (a: unknown, b: unknown) => boolean"]
|
|
21115
|
-
};
|
|
21116
|
-
module2.prelude.push(["", [preludeVar, xnorRef, typeSuffix, " = (a, b) => a ? b : !b || a;", "\n"]]);
|
|
21117
|
-
},
|
|
21118
|
-
returnSymbol(ref) {
|
|
21119
|
-
module2.prelude.push({
|
|
21120
|
-
children: [
|
|
21121
|
-
preludeVar,
|
|
21122
|
-
ref,
|
|
21123
|
-
` = Symbol("return")';
|
|
21124
|
-
`
|
|
21125
|
-
]
|
|
21126
|
-
});
|
|
21127
|
-
},
|
|
21128
|
-
JSX(jsxRef) {
|
|
21129
|
-
module2.prelude.push({
|
|
21130
|
-
ts: true,
|
|
21131
|
-
children: [
|
|
21132
|
-
"import type { JSX as ",
|
|
21133
|
-
jsxRef,
|
|
21134
|
-
" } from 'solid-js';\n"
|
|
21135
|
-
]
|
|
21136
|
-
});
|
|
21137
|
-
},
|
|
21138
|
-
IntrinsicElements(intrinsicElementsRef) {
|
|
21139
|
-
const JSX = module2.getRef("JSX");
|
|
21140
|
-
module2.prelude.push({
|
|
21141
|
-
ts: true,
|
|
21142
|
-
children: [
|
|
21143
|
-
"type ",
|
|
21144
|
-
intrinsicElementsRef,
|
|
21145
|
-
"<K extends keyof ",
|
|
21146
|
-
JSX,
|
|
21147
|
-
".IntrinsicElements> =\n",
|
|
21148
|
-
" ",
|
|
21149
|
-
JSX,
|
|
21150
|
-
".IntrinsicElements[K] extends ",
|
|
21151
|
-
JSX,
|
|
21152
|
-
".DOMAttributes<infer T> ? T : unknown;\n"
|
|
21153
|
-
]
|
|
21154
|
-
});
|
|
21155
|
-
}
|
|
21156
|
-
};
|
|
21157
|
-
const refs = {};
|
|
21158
|
-
module2.getRef = function(base) {
|
|
21159
|
-
if (refs.hasOwnProperty(base))
|
|
21160
|
-
return refs[base];
|
|
21161
|
-
const ref = {
|
|
21162
|
-
type: "Ref",
|
|
21163
|
-
base,
|
|
21164
|
-
id: base
|
|
21165
|
-
};
|
|
21166
|
-
if (declareRef.hasOwnProperty(base))
|
|
21167
|
-
declareRef[base](ref);
|
|
21168
|
-
return refs[base] = ref;
|
|
21169
|
-
};
|
|
21170
|
-
module2.makeAsConst = function(node) {
|
|
21171
|
-
if (node.type === "Literal" && node.raw !== "null" || node.type === "ArrayExpression" || node.type === "ObjectExpression") {
|
|
21172
|
-
return { ...node, children: [...node.children, module2.asConst] };
|
|
21173
|
-
}
|
|
21174
|
-
return node;
|
|
21175
|
-
};
|
|
21176
|
-
module2.typeOfJSX = function(node) {
|
|
21177
|
-
switch (node.type) {
|
|
21178
|
-
case "JSXElement":
|
|
21179
|
-
return module2.typeOfJSXElement(node);
|
|
21180
|
-
case "JSXFragment":
|
|
21181
|
-
return module2.typeOfJSXFragment(node);
|
|
21182
|
-
}
|
|
21183
|
-
};
|
|
21184
|
-
module2.typeOfJSXElement = function(node) {
|
|
21185
|
-
if (module2.config.solid) {
|
|
21186
|
-
if (module2.config.server && !module2.config.client) {
|
|
21187
|
-
return ["string"];
|
|
21188
|
-
}
|
|
21189
|
-
let { tag } = node;
|
|
21190
|
-
const clientType = tag[0] === tag[0].toLowerCase() ? [module2.getRef("IntrinsicElements"), '<"', tag, '">'] : ["ReturnType<typeof ", tag, ">"];
|
|
21191
|
-
if (module2.config.server) {
|
|
21192
|
-
return ["string", " | ", clientType];
|
|
21193
|
-
} else {
|
|
21194
|
-
return clientType;
|
|
21195
|
-
}
|
|
21196
|
-
}
|
|
21197
|
-
};
|
|
21198
|
-
module2.typeOfJSXFragment = function(node) {
|
|
21199
|
-
if (module2.config.solid) {
|
|
21200
|
-
let type = [];
|
|
21201
|
-
let lastType;
|
|
21202
|
-
for (let child of node.jsxChildren) {
|
|
21203
|
-
switch (child.type) {
|
|
21204
|
-
case "JSXText":
|
|
21205
|
-
if (lastType !== "JSXText") {
|
|
21206
|
-
type.push("string");
|
|
21207
|
-
}
|
|
21208
|
-
break;
|
|
21209
|
-
case "JSXElement":
|
|
21210
|
-
type.push(module2.typeOfJSXElement(child));
|
|
21211
|
-
break;
|
|
21212
|
-
case "JSXFragment":
|
|
21213
|
-
type.push(...module2.typeOfJSXFragment(child));
|
|
21214
|
-
break;
|
|
21215
|
-
case "JSXChildExpression":
|
|
21216
|
-
if (child.expression) {
|
|
21217
|
-
type.push(["typeof ", child.expression]);
|
|
21218
|
-
}
|
|
21219
|
-
break;
|
|
21220
|
-
default:
|
|
21221
|
-
throw new Error(`unknown child in JSXFragment: ${JSON.stringify(child)}`);
|
|
21222
|
-
}
|
|
21223
|
-
lastType = child.type;
|
|
21224
|
-
}
|
|
21225
|
-
if (type.length === 1) {
|
|
21226
|
-
return type[0];
|
|
21227
|
-
} else {
|
|
21228
|
-
type = type.flatMap((t) => [t, ", "]);
|
|
21229
|
-
type.pop();
|
|
21230
|
-
return ["[", type, "]"];
|
|
21231
|
-
}
|
|
21232
|
-
}
|
|
21233
|
-
};
|
|
21234
|
-
Object.defineProperty(module2.config, "deno", {
|
|
21235
|
-
set(b) {
|
|
21236
|
-
module2.config.rewriteTsImports = !b;
|
|
21237
|
-
}
|
|
21238
|
-
});
|
|
21239
|
-
module2.config.deno = typeof Deno !== "undefined";
|
|
21240
|
-
Object.defineProperty(module2.config, "coffeeCompat", {
|
|
21241
|
-
set(b) {
|
|
21242
|
-
for (const option of [
|
|
21243
|
-
"autoVar",
|
|
21244
|
-
"coffeeBinaryExistential",
|
|
21245
|
-
"coffeeBooleans",
|
|
21246
|
-
"coffeeClasses",
|
|
21247
|
-
"coffeeComment",
|
|
21248
|
-
"coffeeDo",
|
|
21249
|
-
"coffeeEq",
|
|
21250
|
-
"coffeeForLoops",
|
|
21251
|
-
"coffeeInterpolation",
|
|
21252
|
-
"coffeeIsnt",
|
|
21253
|
-
"coffeeJSX",
|
|
21254
|
-
"coffeeLineContinuation",
|
|
21255
|
-
"coffeeNot",
|
|
21256
|
-
"coffeeOf",
|
|
21257
|
-
"coffeePrototype"
|
|
21258
|
-
]) {
|
|
21259
|
-
module2.config[option] = b;
|
|
21260
|
-
}
|
|
21261
|
-
if (b) {
|
|
21262
|
-
module2.config.objectIs = false;
|
|
21263
|
-
}
|
|
21264
|
-
}
|
|
21265
|
-
});
|
|
21266
|
-
});
|
|
21267
|
-
function Reset(state) {
|
|
21268
|
-
let eventData;
|
|
21269
|
-
if (state.events) {
|
|
21270
|
-
const result = state.events.enter?.("Reset", state);
|
|
21271
|
-
if (result) {
|
|
21272
|
-
if (result.cache)
|
|
21273
|
-
return result.cache;
|
|
21274
|
-
eventData = result.data;
|
|
21275
|
-
}
|
|
21276
|
-
}
|
|
21277
|
-
if (state.tokenize) {
|
|
21278
|
-
const result = $TOKEN("Reset", state, Reset$0(state));
|
|
21279
|
-
if (state.events)
|
|
21280
|
-
state.events.exit?.("Reset", state, result, eventData);
|
|
21281
|
-
return result;
|
|
21282
|
-
} else {
|
|
21283
|
-
const result = Reset$0(state);
|
|
21284
|
-
if (state.events)
|
|
21285
|
-
state.events.exit?.("Reset", state, result, eventData);
|
|
21286
|
-
return result;
|
|
21287
|
-
}
|
|
21288
|
-
}
|
|
21289
|
-
var Init$0 = $TS($S($E(Shebang), $Q(DirectivePrologue), $EXPECT($L0, fail, 'Init ""')), function($skip, $loc, $0, $1, $2, $3) {
|
|
21290
|
-
var directives = $2;
|
|
21291
|
-
directives.forEach((directive) => {
|
|
21292
|
-
if (directive.type === "CivetPrologue") {
|
|
21293
|
-
Object.assign(module2.config, directive.config);
|
|
21294
|
-
}
|
|
21295
|
-
});
|
|
21296
|
-
module2.processCallMemberExpression = (node) => {
|
|
21297
|
-
const { children } = node;
|
|
21298
|
-
for (let i = 0; i < children.length; i++) {
|
|
21299
|
-
const glob = children[i];
|
|
21300
|
-
if (glob?.type === "PropertyGlob") {
|
|
21301
|
-
const prefix = children.slice(0, i).concat(glob.dot);
|
|
21302
|
-
const parts = [];
|
|
21303
|
-
for (const part of glob.object.properties) {
|
|
21304
|
-
if (part.type === "MethodDefinition") {
|
|
21305
|
-
throw new Error("Glob pattern cannot have method definition");
|
|
21306
|
-
}
|
|
21307
|
-
if (part.value && !["CallExpression", "MemberExpression", "Identifier"].includes(part.value.type)) {
|
|
21308
|
-
throw new Error("Glob pattern must have call or member expression value");
|
|
21309
|
-
}
|
|
21310
|
-
let value = part.value ?? part.name;
|
|
21311
|
-
const wValue = getTrimmingSpace(part.value);
|
|
21312
|
-
value = prefix.concat(insertTrimmingSpace(value, ""));
|
|
21313
|
-
if (wValue)
|
|
21314
|
-
value.unshift(wValue);
|
|
21315
|
-
if (part.type === "SpreadProperty") {
|
|
21316
|
-
parts.push({
|
|
21317
|
-
type: part.type,
|
|
21318
|
-
value,
|
|
21319
|
-
dots: part.dots,
|
|
21320
|
-
delim: part.delim,
|
|
21321
|
-
names: part.names,
|
|
21322
|
-
children: part.children.slice(0, 2).concat(value, part.delim)
|
|
21323
|
-
});
|
|
21324
|
-
} else {
|
|
21325
|
-
parts.push({
|
|
21326
|
-
type: part.type === "Identifier" ? "Property" : part.type,
|
|
21327
|
-
name: part.name,
|
|
21328
|
-
value,
|
|
21329
|
-
delim: part.delim,
|
|
21330
|
-
names: part.names,
|
|
21331
|
-
children: [
|
|
21332
|
-
module2.isWhitespaceOrEmpty(part.children[0]) && part.children[0],
|
|
21333
|
-
part.name,
|
|
21334
|
-
module2.isWhitespaceOrEmpty(part.children[2]) && part.children[2],
|
|
21335
|
-
part.children[3]?.token === ":" ? part.children[3] : ":",
|
|
21336
|
-
value,
|
|
21337
|
-
part.delim
|
|
21338
|
-
]
|
|
21339
|
-
});
|
|
21340
|
-
}
|
|
21341
|
-
}
|
|
21342
|
-
const object = {
|
|
21343
|
-
type: "ObjectExpression",
|
|
21344
|
-
children: [
|
|
21345
|
-
glob.object.children[0],
|
|
21346
|
-
...parts,
|
|
21347
|
-
glob.object.children.at(-1)
|
|
21348
|
-
],
|
|
21349
|
-
properties: parts
|
|
21350
|
-
};
|
|
21351
|
-
if (i === children.length - 1)
|
|
21352
|
-
return object;
|
|
21353
|
-
return module2.processCallMemberExpression({
|
|
21354
|
-
...node,
|
|
21355
|
-
children: [object, ...children.slice(i + 1)]
|
|
21356
|
-
});
|
|
21357
|
-
} else if (glob?.type === "PropertyBind") {
|
|
21358
|
-
const prefix = children.slice(0, i);
|
|
21359
|
-
return module2.processCallMemberExpression({
|
|
21360
|
-
...node,
|
|
21361
|
-
children: [
|
|
21362
|
-
prefix,
|
|
21363
|
-
{
|
|
21364
|
-
...glob,
|
|
21365
|
-
type: "PropertyAccess",
|
|
21366
|
-
children: [...glob.children, ".bind(", prefix, ")"]
|
|
21367
|
-
},
|
|
21368
|
-
...children.slice(i + 1)
|
|
21369
|
-
]
|
|
21370
|
-
});
|
|
21371
|
-
}
|
|
21372
|
-
}
|
|
21373
|
-
return node;
|
|
21374
|
-
};
|
|
21375
|
-
module2.needsRef = function(expression, base = "ref") {
|
|
21376
|
-
switch (expression.type) {
|
|
21377
|
-
case "Ref":
|
|
21378
|
-
case "Identifier":
|
|
21379
|
-
case "Literal":
|
|
21380
|
-
return;
|
|
21381
|
-
default:
|
|
21382
|
-
return {
|
|
21383
|
-
type: "Ref",
|
|
21384
|
-
base,
|
|
21385
|
-
id: base
|
|
21386
|
-
};
|
|
21387
|
-
}
|
|
21388
|
-
};
|
|
21389
|
-
module2.expressionizeIfClause = function(clause, b, e) {
|
|
21390
|
-
const children = clause.children.slice(1);
|
|
21391
|
-
children.push("?", b);
|
|
21392
|
-
if (e) {
|
|
21393
|
-
children.push(e[0], ":", ...e.slice(2));
|
|
21394
|
-
} else {
|
|
21395
|
-
children.push(":void 0");
|
|
21396
|
-
}
|
|
21397
|
-
return {
|
|
21398
|
-
type: "IfExpression",
|
|
21399
|
-
children
|
|
21400
|
-
};
|
|
21401
|
-
};
|
|
21402
|
-
module2.addPostfixStatement = function(statement, ws, post) {
|
|
21403
|
-
let children, expressions;
|
|
21404
|
-
if (post.blockPrefix?.length) {
|
|
21405
|
-
let indent = post.blockPrefix[0][0];
|
|
21406
|
-
expressions = [...post.blockPrefix, [indent, statement]];
|
|
21407
|
-
children = [" {\n", ...expressions, "\n", indent?.slice?.(0, -2), "}"];
|
|
21408
|
-
} else {
|
|
21409
|
-
expressions = [["", statement]];
|
|
21410
|
-
children = [" { ", ...expressions, " }"];
|
|
21411
|
-
}
|
|
21412
|
-
const block = {
|
|
21413
|
-
type: "BlockStatement",
|
|
21414
|
-
children,
|
|
21415
|
-
expressions
|
|
21416
|
-
};
|
|
21417
|
-
children = [...post.children];
|
|
21418
|
-
children.push(block);
|
|
21419
|
-
if (!module2.isWhitespaceOrEmpty(ws))
|
|
21420
|
-
children.push(ws);
|
|
21421
|
-
post = { ...post, children, block };
|
|
21422
|
-
if (post.type === "IfStatement") {
|
|
21423
|
-
post.then = block;
|
|
21424
|
-
}
|
|
21425
|
-
return post;
|
|
21426
|
-
};
|
|
21427
|
-
function expressionizeIteration(exp) {
|
|
21428
|
-
const i = exp.children.indexOf(exp.block);
|
|
21429
|
-
if (exp.subtype === "DoStatement") {
|
|
21430
|
-
insertReturn(exp.block);
|
|
21431
|
-
exp.children.splice(i, 1, ...module2.wrapIIFE(exp.children, exp.async));
|
|
21432
|
-
return;
|
|
21433
|
-
}
|
|
21434
|
-
const resultsRef = {
|
|
21435
|
-
type: "Ref",
|
|
21436
|
-
base: "results",
|
|
21437
|
-
id: "results"
|
|
21438
|
-
};
|
|
21439
|
-
insertPush(exp.block, resultsRef);
|
|
21440
|
-
exp.children.splice(
|
|
21441
|
-
i,
|
|
21442
|
-
1,
|
|
21443
|
-
module2.wrapIIFE([
|
|
21444
|
-
"const ",
|
|
21445
|
-
resultsRef,
|
|
21446
|
-
"=[];",
|
|
21447
|
-
...exp.children,
|
|
21448
|
-
"; return ",
|
|
21449
|
-
resultsRef
|
|
21450
|
-
], exp.async)
|
|
21451
|
-
);
|
|
21452
|
-
}
|
|
21453
|
-
module2.wrapIIFE = (exp, async) => {
|
|
21454
|
-
let prefix, suffix;
|
|
21455
|
-
if (async) {
|
|
21456
|
-
prefix = "(async ()=>";
|
|
21457
|
-
suffix = ")()";
|
|
21458
|
-
} else if (hasAwait(exp)) {
|
|
21459
|
-
prefix = "(await (async ()=>";
|
|
21460
|
-
suffix = ")())";
|
|
21461
|
-
} else {
|
|
21462
|
-
prefix = "(()=>";
|
|
21463
|
-
suffix = ")()";
|
|
21464
|
-
}
|
|
21465
|
-
const expressions = Array.isArray(exp) ? [[...exp]] : [exp];
|
|
21466
|
-
const block = {
|
|
21467
|
-
type: "BlockStatement",
|
|
21468
|
-
expressions,
|
|
21469
|
-
children: ["{", expressions, "}"],
|
|
21470
|
-
bare: false
|
|
21471
|
-
};
|
|
21472
|
-
return [
|
|
21473
|
-
prefix,
|
|
21474
|
-
block,
|
|
21475
|
-
suffix
|
|
21476
|
-
];
|
|
21477
|
-
};
|
|
21478
|
-
function wrapIterationReturningResults(statement, outerRef) {
|
|
21479
|
-
if (statement.type === "DoStatement") {
|
|
21480
|
-
if (outerRef) {
|
|
21481
|
-
insertPush(statement.block, outerRef);
|
|
21482
|
-
} else {
|
|
21483
|
-
insertReturn(statement.block);
|
|
21484
|
-
}
|
|
21485
|
-
return;
|
|
21486
|
-
}
|
|
21487
|
-
const resultsRef = {
|
|
21488
|
-
type: "Ref",
|
|
21489
|
-
base: "results",
|
|
21490
|
-
id: "results"
|
|
21491
|
-
};
|
|
21492
|
-
const declaration = {
|
|
21493
|
-
type: "Declaration",
|
|
21494
|
-
children: ["const ", resultsRef, "=[];"]
|
|
21495
|
-
};
|
|
21496
|
-
insertPush(statement.block, resultsRef);
|
|
21497
|
-
statement.children.unshift(declaration);
|
|
21498
|
-
if (outerRef) {
|
|
21499
|
-
statement.children.push(";", outerRef, ".push(", resultsRef, ");");
|
|
21500
|
-
} else {
|
|
21501
|
-
statement.children.push(";return ", resultsRef, ";");
|
|
21502
|
-
}
|
|
21503
|
-
}
|
|
21504
|
-
function insertPush(node, ref) {
|
|
21505
|
-
if (!node)
|
|
21506
|
-
return;
|
|
21507
|
-
switch (node.type) {
|
|
21508
|
-
case "BlockStatement":
|
|
21509
|
-
if (node.expressions.length) {
|
|
21510
|
-
const last = node.expressions[node.expressions.length - 1];
|
|
21511
|
-
insertPush(last, ref);
|
|
21512
|
-
} else {
|
|
21513
|
-
node.expressions.push([ref, ".push(void 0);"]);
|
|
21514
|
-
}
|
|
21515
|
-
return;
|
|
21516
|
-
case "CaseBlock":
|
|
21517
|
-
node.clauses.forEach((clause) => {
|
|
21518
|
-
insertPush(clause, ref);
|
|
21519
|
-
});
|
|
21520
|
-
return;
|
|
21521
|
-
case "WhenClause":
|
|
21522
|
-
insertPush(node.block, ref);
|
|
21523
|
-
return;
|
|
21524
|
-
case "DefaultClause":
|
|
21525
|
-
insertPush(node.block, ref);
|
|
21526
|
-
return;
|
|
21527
|
-
}
|
|
21528
|
-
if (!Array.isArray(node))
|
|
21529
|
-
return;
|
|
21530
|
-
const [, exp] = node;
|
|
21531
|
-
if (!exp)
|
|
21532
|
-
return;
|
|
21533
|
-
const indent = getIndent(node);
|
|
21534
|
-
switch (exp.type) {
|
|
21535
|
-
case "BreakStatement":
|
|
21536
|
-
case "ContinueStatement":
|
|
21537
|
-
case "DebuggerStatement":
|
|
21538
|
-
case "EmptyStatement":
|
|
21539
|
-
case "ReturnStatement":
|
|
21540
|
-
case "ThrowStatement":
|
|
21541
|
-
case "Declaration":
|
|
21542
|
-
return;
|
|
21543
|
-
case "ForStatement":
|
|
21544
|
-
case "IterationStatement":
|
|
21545
|
-
case "DoStatement":
|
|
21546
|
-
wrapIterationReturningResults(exp, ref);
|
|
21547
|
-
return;
|
|
21548
|
-
case "BlockStatement":
|
|
21549
|
-
insertPush(exp.expressions[exp.expressions.length - 1], ref);
|
|
21550
|
-
return;
|
|
21551
|
-
case "IfStatement":
|
|
21552
|
-
insertPush(exp.then, ref);
|
|
21553
|
-
if (exp.else)
|
|
21554
|
-
insertPush(exp.else[2], ref);
|
|
21555
|
-
else
|
|
21556
|
-
exp.children.push([" else {\n", indent, ref, ".push(undefined)\n", indent, "}"]);
|
|
21557
|
-
return;
|
|
21558
|
-
case "PatternMatchingStatement":
|
|
21559
|
-
insertPush(exp.children[0][0], ref);
|
|
21560
|
-
return;
|
|
21561
|
-
case "SwitchStatement":
|
|
21562
|
-
insertPush(exp.children[2], ref);
|
|
21563
|
-
return;
|
|
21564
|
-
case "TryStatement":
|
|
21565
|
-
exp.blocks.forEach((block) => insertPush(block, ref));
|
|
21566
|
-
return;
|
|
21567
|
-
}
|
|
21568
|
-
if (node[node.length - 1]?.type === "SemicolonDelimiter")
|
|
21569
|
-
return;
|
|
21570
|
-
node.splice(1, 0, ref, ".push(");
|
|
21571
|
-
node.push(")");
|
|
21572
|
-
}
|
|
21573
|
-
function wrapWithReturn(expression) {
|
|
21574
|
-
const children = expression ? ["return ", expression] : ["return"];
|
|
21575
|
-
return {
|
|
21576
|
-
type: "ReturnStatement",
|
|
21577
|
-
children
|
|
21578
|
-
};
|
|
21579
|
-
}
|
|
21580
|
-
function insertSwitchReturns(exp) {
|
|
21581
|
-
switch (exp.type) {
|
|
21582
|
-
case "SwitchStatement":
|
|
21583
|
-
exp.caseBlock.clauses.forEach((clause) => {
|
|
21584
|
-
insertReturn(clause);
|
|
21585
|
-
});
|
|
21586
|
-
return;
|
|
21587
|
-
case "SwitchExpression":
|
|
21588
|
-
exp.caseBlock.clauses.forEach(insertReturn);
|
|
21589
|
-
return;
|
|
21590
|
-
}
|
|
21591
|
-
}
|
|
21592
|
-
function insertReturn(node) {
|
|
21593
|
-
if (!node)
|
|
21594
|
-
return;
|
|
21595
|
-
switch (node.type) {
|
|
21596
|
-
case "BlockStatement":
|
|
21597
|
-
if (node.expressions.length) {
|
|
21598
|
-
const last = node.expressions[node.expressions.length - 1];
|
|
21599
|
-
insertReturn(last);
|
|
21600
|
-
} else {
|
|
21601
|
-
if (node.parent.type === "CatchClause") {
|
|
21602
|
-
node.expressions.push(["return"]);
|
|
21603
|
-
}
|
|
21604
|
-
}
|
|
21605
|
-
return;
|
|
21606
|
-
case "WhenClause":
|
|
21607
|
-
node.children.splice(node.children.indexOf(node.break), 1);
|
|
21608
|
-
if (node.block.expressions.length) {
|
|
21609
|
-
insertReturn(node.block);
|
|
21610
|
-
} else {
|
|
21611
|
-
node.block.expressions.push(wrapWithReturn());
|
|
21612
|
-
}
|
|
21613
|
-
return;
|
|
21614
|
-
case "DefaultClause":
|
|
21615
|
-
insertReturn(node.block);
|
|
21616
|
-
return;
|
|
21617
|
-
}
|
|
21618
|
-
if (!Array.isArray(node))
|
|
21619
|
-
return;
|
|
21620
|
-
const [, exp, semi] = node;
|
|
21621
|
-
if (semi?.type === "SemicolonDelimiter")
|
|
21622
|
-
return;
|
|
21623
|
-
let indent = getIndent(node);
|
|
21624
|
-
if (!exp)
|
|
21625
|
-
return;
|
|
21626
|
-
switch (exp.type) {
|
|
21627
|
-
case "BreakStatement":
|
|
21628
|
-
case "ContinueStatement":
|
|
21629
|
-
case "DebuggerStatement":
|
|
21630
|
-
case "EmptyStatement":
|
|
21631
|
-
case "ReturnStatement":
|
|
21632
|
-
case "ThrowStatement":
|
|
21633
|
-
case "Declaration":
|
|
21634
|
-
return;
|
|
21635
|
-
case "ForStatement":
|
|
21636
|
-
case "IterationStatement":
|
|
21637
|
-
case "DoStatement":
|
|
21638
|
-
wrapIterationReturningResults(exp);
|
|
21639
|
-
return;
|
|
21640
|
-
case "BlockStatement":
|
|
21641
|
-
insertReturn(exp.expressions[exp.expressions.length - 1]);
|
|
21642
|
-
return;
|
|
21643
|
-
case "IfStatement":
|
|
21644
|
-
insertReturn(exp.then);
|
|
21645
|
-
if (exp.else)
|
|
21646
|
-
insertReturn(exp.else[2]);
|
|
21647
|
-
else
|
|
21648
|
-
exp.children.push(["", {
|
|
21649
|
-
type: "ReturnStatement",
|
|
21650
|
-
children: [";return"]
|
|
21651
|
-
}]);
|
|
21652
|
-
return;
|
|
21653
|
-
case "PatternMatchingStatement":
|
|
21654
|
-
insertReturn(exp.children[0][0]);
|
|
21655
|
-
return;
|
|
21656
|
-
case "SwitchStatement":
|
|
21657
|
-
insertSwitchReturns(exp);
|
|
21658
|
-
return;
|
|
21659
|
-
case "TryStatement":
|
|
21660
|
-
exp.blocks.forEach((block) => insertReturn(block));
|
|
21661
|
-
return;
|
|
21662
|
-
}
|
|
21663
|
-
if (node[node.length - 1]?.type === "SemicolonDelimiter")
|
|
21664
|
-
return;
|
|
21665
|
-
const returnStatement = wrapWithReturn(node[1]);
|
|
21666
|
-
node.splice(1, 1, returnStatement);
|
|
21667
|
-
}
|
|
21668
|
-
module2.makeLeftHandSideExpression = function(expression) {
|
|
21669
|
-
switch (expression.type) {
|
|
21670
|
-
case "Ref":
|
|
21671
|
-
case "Identifier":
|
|
21672
|
-
case "Literal":
|
|
21673
|
-
case "CallExpression":
|
|
21674
|
-
case "MemberExpression":
|
|
21675
|
-
case "ParenthesizedExpression":
|
|
21676
|
-
return expression;
|
|
21677
|
-
default:
|
|
21678
|
-
return {
|
|
21679
|
-
type: "ParenthesizedExpression",
|
|
21680
|
-
children: ["(", expression, ")"],
|
|
21681
|
-
expression
|
|
21682
|
-
};
|
|
21683
|
-
}
|
|
21684
|
-
};
|
|
21685
|
-
module2.isWhitespaceOrEmpty = function(node) {
|
|
21686
|
-
if (!node)
|
|
21687
|
-
return true;
|
|
21688
|
-
if (node.type === "Ref")
|
|
21689
|
-
return false;
|
|
21690
|
-
if (node.token)
|
|
21691
|
-
return node.token.match(/^\s*$/);
|
|
21692
|
-
if (node.children)
|
|
21693
|
-
node = node.children;
|
|
21694
|
-
if (!node.length)
|
|
21695
|
-
return true;
|
|
21696
|
-
if (typeof node === "string")
|
|
21697
|
-
return node.match(/^\s*$/);
|
|
21698
|
-
if (Array.isArray(node))
|
|
21699
|
-
return node.every(module2.isWhitespaceOrEmpty);
|
|
21700
|
-
};
|
|
21701
|
-
module2.isTemplateLiteral = function(node) {
|
|
21702
|
-
let s = node;
|
|
21703
|
-
while (s && s[0] && !s.token)
|
|
21704
|
-
s = s[0];
|
|
21705
|
-
return s.token?.startsWith?.("`");
|
|
21706
|
-
};
|
|
21707
|
-
module2.isEmptyBareBlock = function(node) {
|
|
21708
|
-
if (node?.type !== "BlockStatement")
|
|
21709
|
-
return false;
|
|
21710
|
-
const { bare, expressions } = node;
|
|
21711
|
-
return bare && (expressions.length === 0 || expressions.length === 1 && expressions[0][1]?.type === "EmptyStatement");
|
|
21712
|
-
};
|
|
21713
|
-
module2.processBinaryOpExpression = function($02) {
|
|
21714
|
-
const expandedOps = module2.expandChainedComparisons($02);
|
|
21715
|
-
let i = 2;
|
|
21716
|
-
while (i < expandedOps.length) {
|
|
21717
|
-
const op = expandedOps[i];
|
|
21718
|
-
if (op.special) {
|
|
21719
|
-
let [a, wsOp, op2, wsB, b] = expandedOps.slice(i - 2, i + 3);
|
|
21720
|
-
if (op2.token === "instanceof" && b.type === "Literal" && b.children?.[0]?.type === "StringLiteral") {
|
|
21721
|
-
a = ["typeof ", module2.makeLeftHandSideExpression(a)];
|
|
21722
|
-
if (op2.negated) {
|
|
21723
|
-
op2 = { ...op2, token: "!==", negated: false };
|
|
21724
|
-
} else {
|
|
21725
|
-
op2 = { ...op2, token: "===" };
|
|
21726
|
-
}
|
|
21727
|
-
}
|
|
21728
|
-
if (op2.asConst) {
|
|
21729
|
-
a = module2.makeAsConst(a);
|
|
21730
|
-
b = module2.makeAsConst(b);
|
|
21731
|
-
}
|
|
21732
|
-
let children;
|
|
21733
|
-
if (op2.call) {
|
|
21734
|
-
wsOp = insertTrimmingSpace(wsOp, "");
|
|
21735
|
-
if (op2.reversed) {
|
|
21736
|
-
wsB = insertTrimmingSpace(wsB, "");
|
|
21737
|
-
children = [wsOp, op2.call, "(", wsB, b, ", ", a, ")", op2.suffix];
|
|
21738
|
-
} else {
|
|
21739
|
-
children = [wsOp, op2.call, "(", a, ",", wsB, b, ")", op2.suffix];
|
|
21740
|
-
}
|
|
21741
|
-
} else if (op2.method) {
|
|
21742
|
-
wsOp = insertTrimmingSpace(wsOp, "");
|
|
21743
|
-
wsB = insertTrimmingSpace(wsB, "");
|
|
21744
|
-
if (op2.reversed) {
|
|
21745
|
-
children = [wsB, b, wsOp, ".", op2.method, "(", a, ")"];
|
|
21746
|
-
} else {
|
|
21747
|
-
children = [a, wsOp, ".", op2.method, "(", wsB, b, ")"];
|
|
21748
|
-
}
|
|
21749
|
-
} else if (op2.token) {
|
|
21750
|
-
children = [a, wsOp, op2, wsB, b];
|
|
21751
|
-
if (op2.negated)
|
|
21752
|
-
children = ["(", ...children, ")"];
|
|
21753
|
-
} else {
|
|
21754
|
-
throw new Error("Unknown operator: " + JSON.stringify(op2));
|
|
21755
|
-
}
|
|
21756
|
-
if (op2.negated)
|
|
21757
|
-
children.unshift("!");
|
|
21758
|
-
expandedOps.splice(i - 2, 5, {
|
|
21759
|
-
children
|
|
21760
|
-
});
|
|
21761
|
-
} else {
|
|
21762
|
-
i += 4;
|
|
21763
|
-
}
|
|
21764
|
-
}
|
|
21765
|
-
return expandedOps;
|
|
21766
|
-
};
|
|
21767
|
-
module2.expandChainedComparisons = function([first, binops]) {
|
|
21768
|
-
const relationalOps = ["==", "===", "!=", "!==", "<", "<=", ">", ">=", "in"];
|
|
21769
|
-
const lowerPrecedenceOps = ["??", "&&", "||", "&", "|", "^"];
|
|
21770
|
-
let results = [];
|
|
21771
|
-
let i = 0;
|
|
21772
|
-
let l = binops.length;
|
|
21773
|
-
let start = 0;
|
|
21774
|
-
let chains = [];
|
|
21775
|
-
while (i < l) {
|
|
21776
|
-
const [, op] = binops[i];
|
|
21777
|
-
if (relationalOps.includes(op.token) || op.relational) {
|
|
21778
|
-
chains.push(i);
|
|
21779
|
-
} else if (lowerPrecedenceOps.includes(op.token)) {
|
|
21780
|
-
processChains();
|
|
21781
|
-
first = [];
|
|
21782
|
-
}
|
|
21783
|
-
i++;
|
|
21784
|
-
}
|
|
21785
|
-
processChains();
|
|
21786
|
-
return results;
|
|
21787
|
-
function processChains() {
|
|
21788
|
-
if (chains.length > 1) {
|
|
21789
|
-
chains.forEach((index, k) => {
|
|
21790
|
-
if (k > 0) {
|
|
21791
|
-
results.push(" ", "&&", " ");
|
|
21792
|
-
}
|
|
21793
|
-
const [pre, op, post, exp] = binops[index];
|
|
21794
|
-
let endIndex;
|
|
21795
|
-
if (k < chains.length - 1) {
|
|
21796
|
-
endIndex = chains[k + 1];
|
|
21797
|
-
} else {
|
|
21798
|
-
endIndex = i + 1;
|
|
21799
|
-
}
|
|
21800
|
-
results = results.concat(first, ...binops.slice(start, endIndex));
|
|
21801
|
-
first = [exp].concat(binops.slice(index + 1, endIndex));
|
|
21802
|
-
start = endIndex;
|
|
21803
|
-
});
|
|
21804
|
-
} else {
|
|
21805
|
-
results = results.concat(first, ...binops.slice(start, i + 1));
|
|
21806
|
-
start = i + 1;
|
|
21807
|
-
}
|
|
21808
|
-
chains.length = 0;
|
|
21809
|
-
}
|
|
21810
|
-
};
|
|
21811
|
-
module2.parsePosition = function() {
|
|
21812
|
-
let s = Error().stack.split(/\n at /);
|
|
21813
|
-
s.shift();
|
|
21814
|
-
s = s.filter((e) => !e.match(/^eval/)).map((e) => e.split(" ")[0]);
|
|
21815
|
-
s = s.slice(1, s.indexOf("Program") + 1);
|
|
21816
|
-
return s;
|
|
21817
|
-
};
|
|
21818
|
-
module2.prune = function(node) {
|
|
21819
|
-
if (node === null || node === void 0)
|
|
21820
|
-
return;
|
|
21821
|
-
if (node.length === 0)
|
|
21822
|
-
return;
|
|
21823
|
-
if (Array.isArray(node)) {
|
|
21824
|
-
const a = node.map((n) => module2.prune(n)).filter((n) => !!n);
|
|
21825
|
-
if (a.length > 1)
|
|
21826
|
-
return a;
|
|
21827
|
-
if (a.length === 1)
|
|
21828
|
-
return a[0];
|
|
21829
|
-
return;
|
|
21830
|
-
}
|
|
21831
|
-
if (node.children != null) {
|
|
21832
|
-
node.children = module2.prune(node.children);
|
|
21833
|
-
return node;
|
|
21834
|
-
}
|
|
21835
|
-
return node;
|
|
21836
|
-
};
|
|
21837
|
-
module2.skipIfOnlyWS = function(target) {
|
|
21838
|
-
if (!target)
|
|
21839
|
-
return target;
|
|
21840
|
-
if (Array.isArray(target)) {
|
|
21841
|
-
if (target.length === 1) {
|
|
21842
|
-
return module2.skipIfOnlyWS(target[0]);
|
|
21843
|
-
} else if (target.every((e) => module2.skipIfOnlyWS(e) === void 0)) {
|
|
21844
|
-
return void 0;
|
|
21845
|
-
}
|
|
21846
|
-
return target;
|
|
21847
|
-
}
|
|
21848
|
-
if (target.token != null && target.token.trim() === "") {
|
|
21849
|
-
return void 0;
|
|
21850
|
-
}
|
|
21851
|
-
return target;
|
|
21852
|
-
};
|
|
21853
|
-
const initialSpacingRe = /^(?:\r?\n|\n)*((?:\r?\n|\n)\s+)/;
|
|
21854
|
-
module2.dedentBlockSubstitutions = function($02) {
|
|
21855
|
-
const [s, strWithSubstitutions, e] = $02;
|
|
21856
|
-
if (strWithSubstitutions.length === 0) {
|
|
21857
|
-
return $02;
|
|
21858
|
-
}
|
|
21859
|
-
let initialSpacing, i = 0, l = strWithSubstitutions.length, results = [s];
|
|
21860
|
-
const { token } = strWithSubstitutions[0];
|
|
21861
|
-
if (token) {
|
|
21862
|
-
initialSpacing = token.match(initialSpacingRe);
|
|
21863
|
-
} else {
|
|
21864
|
-
initialSpacing = false;
|
|
21865
|
-
}
|
|
21866
|
-
while (i < l) {
|
|
21867
|
-
let segment = strWithSubstitutions[i];
|
|
21868
|
-
if (segment.token) {
|
|
21869
|
-
segment = module2.dedentBlockString(segment, initialSpacing, false);
|
|
21870
|
-
if (i === 0) {
|
|
21871
|
-
segment.token = segment.token.replace(/^(\r?\n|\n)/, "");
|
|
21872
|
-
}
|
|
21873
|
-
if (i === l - 1) {
|
|
21874
|
-
segment.token = segment.token.replace(/(\r?\n|\n)[ \t]*$/, "");
|
|
21875
|
-
}
|
|
21876
|
-
results.push(segment);
|
|
21877
|
-
} else {
|
|
21878
|
-
results.push(segment);
|
|
21879
|
-
}
|
|
21880
|
-
i++;
|
|
21881
|
-
}
|
|
21882
|
-
results.push(e);
|
|
21883
|
-
return {
|
|
21884
|
-
type: "TemplateLiteral",
|
|
21885
|
-
children: results
|
|
21886
|
-
};
|
|
21887
|
-
};
|
|
21888
|
-
module2.dedentBlockString = function({ $loc: $loc2, token: str }, spacing, trim = true) {
|
|
21889
|
-
if (spacing == null)
|
|
21890
|
-
spacing = str.match(initialSpacingRe);
|
|
21891
|
-
if (spacing) {
|
|
21892
|
-
str = str.replaceAll(spacing[1], "\n");
|
|
21893
|
-
const l = spacing.length;
|
|
21894
|
-
$loc2.pos += l;
|
|
21895
|
-
$loc2.length -= l;
|
|
21896
|
-
}
|
|
21897
|
-
if (trim) {
|
|
21898
|
-
str = str.replace(/^(\r?\n|\n)/, "").replace(/(\r?\n|\n)[ \t]*$/, "");
|
|
21899
|
-
}
|
|
21900
|
-
str = str.replace(/(\\.|`|\$\{)/g, (s) => {
|
|
21901
|
-
if (s[0] === "\\") {
|
|
21902
|
-
return s;
|
|
21903
|
-
}
|
|
21904
|
-
return `\\${s}`;
|
|
21905
|
-
});
|
|
21906
|
-
return {
|
|
21907
|
-
$loc: $loc2,
|
|
21908
|
-
token: str
|
|
21909
|
-
};
|
|
21910
|
-
};
|
|
21911
|
-
module2.adjustBindingElements = function(elements) {
|
|
21912
|
-
const names = elements.flatMap((p) => p.names || []), { length } = elements;
|
|
21913
|
-
let blockPrefix, restIndex = -1, restCount = 0;
|
|
21914
|
-
elements.forEach(({ type }, i) => {
|
|
21915
|
-
if (type === "BindingRestElement") {
|
|
21916
|
-
if (restIndex < 0)
|
|
21917
|
-
restIndex = i;
|
|
21918
|
-
restCount++;
|
|
21919
|
-
}
|
|
21920
|
-
});
|
|
21921
|
-
if (restCount === 0) {
|
|
21922
|
-
return {
|
|
21923
|
-
children: elements,
|
|
21924
|
-
names,
|
|
21925
|
-
blockPrefix,
|
|
21926
|
-
length
|
|
21927
|
-
};
|
|
21928
|
-
} else if (restCount === 1) {
|
|
21929
|
-
const rest = elements[restIndex];
|
|
21930
|
-
const after = elements.slice(restIndex + 1);
|
|
21931
|
-
const restIdentifier = rest.binding.ref || rest.binding;
|
|
21932
|
-
names.push(...rest.names || []);
|
|
21933
|
-
let l = after.length;
|
|
21934
|
-
if (l) {
|
|
21935
|
-
if (arrayElementHasTrailingComma(after[l - 1]))
|
|
21936
|
-
l++;
|
|
21937
|
-
blockPrefix = {
|
|
21938
|
-
type: "PostRestBindingElements",
|
|
21939
|
-
children: ["[", insertTrimmingSpace(after, ""), "] = ", restIdentifier, ".splice(-", l.toString(), ")"],
|
|
21940
|
-
names: after.flatMap((p) => p.names)
|
|
21941
|
-
};
|
|
21942
|
-
}
|
|
21943
|
-
return {
|
|
21944
|
-
names,
|
|
21945
|
-
children: [...elements.slice(0, restIndex), {
|
|
21946
|
-
...rest,
|
|
21947
|
-
children: rest.children.slice(0, -1)
|
|
21948
|
-
}],
|
|
21949
|
-
blockPrefix,
|
|
21950
|
-
length
|
|
21951
|
-
};
|
|
21952
|
-
}
|
|
21953
|
-
const err = {
|
|
21954
|
-
type: "Error",
|
|
21955
|
-
children: ["Multiple rest elements in array pattern"]
|
|
21956
|
-
};
|
|
21957
|
-
return {
|
|
21958
|
-
names,
|
|
21959
|
-
children: [...elements, err],
|
|
21960
|
-
blockPrefix,
|
|
21961
|
-
length
|
|
21962
|
-
};
|
|
21963
|
-
};
|
|
21964
|
-
module2.reorderBindingRestProperty = function(props) {
|
|
21965
|
-
const names = props.flatMap((p) => p.names);
|
|
21966
|
-
let restIndex = -1;
|
|
21967
|
-
let restCount = 0;
|
|
21968
|
-
props.forEach(({ type }, i) => {
|
|
21969
|
-
if (type === "BindingRestProperty") {
|
|
21970
|
-
if (restIndex < 0)
|
|
21971
|
-
restIndex = i;
|
|
21972
|
-
restCount++;
|
|
21973
|
-
}
|
|
21974
|
-
});
|
|
21975
|
-
if (restCount === 0) {
|
|
21976
|
-
return {
|
|
21977
|
-
children: props,
|
|
21978
|
-
names
|
|
21979
|
-
};
|
|
21980
|
-
} else if (restCount === 1) {
|
|
21981
|
-
let after = props.slice(restIndex + 1);
|
|
21982
|
-
let rest = props[restIndex];
|
|
21983
|
-
props = props.slice(0, restIndex);
|
|
21984
|
-
if (after.length) {
|
|
21985
|
-
const [restDelim] = rest.children.slice(-1), lastAfterProp = after[after.length - 1], lastAfterChildren = lastAfterProp.children, [lastDelim] = lastAfterChildren.slice(-1);
|
|
21986
|
-
rest = { ...rest, children: [...rest.children.slice(0, -1), lastDelim] };
|
|
21987
|
-
after = [...after.slice(0, -1), { ...lastAfterProp, children: [...lastAfterChildren.slice(0, -1), restDelim] }];
|
|
21988
|
-
}
|
|
21989
|
-
const children = [...props, ...after, rest];
|
|
21990
|
-
return {
|
|
21991
|
-
children,
|
|
21992
|
-
names
|
|
21993
|
-
};
|
|
21994
|
-
}
|
|
21995
|
-
return {
|
|
21996
|
-
children: [{
|
|
21997
|
-
type: "Error",
|
|
21998
|
-
message: "Multiple rest properties in object pattern"
|
|
21999
|
-
}, props]
|
|
22000
|
-
};
|
|
22001
|
-
};
|
|
22002
|
-
function addParentPointers(node, parent) {
|
|
22003
|
-
if (node == null)
|
|
22004
|
-
return;
|
|
22005
|
-
if (typeof node !== "object")
|
|
22006
|
-
return;
|
|
22007
|
-
if (Array.isArray(node)) {
|
|
22008
|
-
for (const child of node) {
|
|
22009
|
-
addParentPointers(child, parent);
|
|
22010
|
-
}
|
|
22011
|
-
return;
|
|
22012
|
-
}
|
|
22013
|
-
node.parent = parent;
|
|
22014
|
-
if (node.children) {
|
|
22015
|
-
for (const child of node.children) {
|
|
22016
|
-
addParentPointers(child, node);
|
|
22017
|
-
}
|
|
22018
|
-
}
|
|
22019
|
-
}
|
|
22020
|
-
module2.replaceNodes = (root, predicate, replacer) => {
|
|
22021
|
-
if (root == null)
|
|
22022
|
-
return root;
|
|
22023
|
-
const array = Array.isArray(root) ? root : root.children;
|
|
22024
|
-
if (!array)
|
|
22025
|
-
return root;
|
|
22026
|
-
array.forEach((node, i) => {
|
|
22027
|
-
if (node == null)
|
|
22028
|
-
return;
|
|
22029
|
-
if (predicate(node)) {
|
|
22030
|
-
array[i] = replacer(node, root);
|
|
22031
|
-
} else {
|
|
22032
|
-
module2.replaceNodes(node, predicate, replacer);
|
|
22033
|
-
}
|
|
22034
|
-
});
|
|
22035
|
-
return root;
|
|
22036
|
-
};
|
|
22037
|
-
function processParams(f) {
|
|
22038
|
-
const { type, parameters, block } = f;
|
|
22039
|
-
if (type === "ArrowFunction" && parameters && parameters.tp && parameters.tp.parameters.length === 1) {
|
|
22040
|
-
parameters.tp.parameters.push(",");
|
|
22041
|
-
}
|
|
22042
|
-
if (!block)
|
|
22043
|
-
return;
|
|
22044
|
-
const { expressions } = block;
|
|
22045
|
-
if (!expressions)
|
|
22046
|
-
return;
|
|
22047
|
-
const { blockPrefix } = parameters;
|
|
22048
|
-
let indent;
|
|
22049
|
-
if (!expressions.length) {
|
|
22050
|
-
indent = "";
|
|
22051
|
-
} else {
|
|
22052
|
-
indent = expressions[0][0];
|
|
22053
|
-
}
|
|
22054
|
-
const [splices, thisAssignments] = gatherBindingCode(parameters, {
|
|
22055
|
-
injectParamProps: f.name === "constructor"
|
|
22056
|
-
});
|
|
22057
|
-
const delimiter = {
|
|
22058
|
-
type: "SemicolonDelimiter",
|
|
22059
|
-
children: [";"]
|
|
22060
|
-
};
|
|
22061
|
-
const prefix = splices.map((s) => ["let ", s]).concat(thisAssignments).map(
|
|
22062
|
-
(s) => s.type ? {
|
|
22063
|
-
...s,
|
|
22064
|
-
children: [indent, ...s.children, delimiter]
|
|
22065
|
-
} : [indent, s, delimiter]
|
|
22066
|
-
);
|
|
22067
|
-
expressions.unshift(...prefix);
|
|
22068
|
-
}
|
|
22069
|
-
function adjustAtBindings(statements, asThis = false) {
|
|
22070
|
-
gatherRecursiveAll(statements, (n) => n.type === "AtBindingProperty").forEach((binding) => {
|
|
22071
|
-
const { ref } = binding;
|
|
22072
|
-
if (asThis) {
|
|
22073
|
-
const atBinding = binding.binding;
|
|
22074
|
-
atBinding.children.pop();
|
|
22075
|
-
atBinding.type = void 0;
|
|
22076
|
-
binding.children.unshift(ref.id, ": this.", ref.base);
|
|
22077
|
-
binding.type = "Property";
|
|
22078
|
-
binding.ref = void 0;
|
|
22079
|
-
return;
|
|
22080
|
-
}
|
|
22081
|
-
if (ref.names[0] !== ref.base) {
|
|
22082
|
-
binding.children.unshift(ref.base, ": ");
|
|
22083
|
-
}
|
|
22084
|
-
});
|
|
22085
|
-
}
|
|
22086
|
-
function processReturnValue(func) {
|
|
22087
|
-
const { block } = func;
|
|
22088
|
-
const values = gatherRecursiveWithinFunction(
|
|
22089
|
-
block,
|
|
22090
|
-
({ type }) => type === "ReturnValue"
|
|
22091
|
-
);
|
|
22092
|
-
if (!values.length)
|
|
22093
|
-
return false;
|
|
22094
|
-
const ref = {
|
|
22095
|
-
type: "Ref",
|
|
22096
|
-
base: "ret",
|
|
22097
|
-
id: "ret"
|
|
22098
|
-
};
|
|
22099
|
-
let declared;
|
|
22100
|
-
values.forEach((value) => {
|
|
22101
|
-
value.children = [ref];
|
|
22102
|
-
const ancestor = findAncestor(
|
|
22103
|
-
value,
|
|
22104
|
-
({ type }) => type === "Declaration",
|
|
22105
|
-
isFunction
|
|
22106
|
-
);
|
|
22107
|
-
if (ancestor)
|
|
22108
|
-
declared = true;
|
|
22109
|
-
});
|
|
22110
|
-
if (!declared) {
|
|
22111
|
-
let returnType = func.returnType ?? func.signature?.returnType;
|
|
22112
|
-
if (returnType) {
|
|
22113
|
-
const { t } = returnType;
|
|
22114
|
-
if (t.type === "TypePredicate") {
|
|
22115
|
-
returnType = ": boolean";
|
|
22116
|
-
} else if (t.type === "AssertsType") {
|
|
22117
|
-
returnType = void 0;
|
|
22118
|
-
}
|
|
22119
|
-
}
|
|
22120
|
-
block.expressions.unshift([
|
|
22121
|
-
getIndent(block.expressions[0]),
|
|
22122
|
-
{
|
|
22123
|
-
type: "Declaration",
|
|
22124
|
-
children: ["let ", ref, returnType],
|
|
22125
|
-
names: []
|
|
22126
|
-
},
|
|
22127
|
-
";"
|
|
22128
|
-
]);
|
|
22129
|
-
}
|
|
22130
|
-
gatherRecursiveWithinFunction(
|
|
22131
|
-
block,
|
|
22132
|
-
(r) => r.type === "ReturnStatement" && !r.expression
|
|
22133
|
-
).forEach((r) => {
|
|
22134
|
-
r.expression = ref;
|
|
22135
|
-
r.children.splice(-1, 1, " ", ref);
|
|
22136
|
-
});
|
|
22137
|
-
if (block.children.at(-2)?.type !== "ReturnStatement") {
|
|
22138
|
-
block.expressions.push([
|
|
22139
|
-
[getIndent(block.expressions.at(-1))],
|
|
22140
|
-
{
|
|
22141
|
-
type: "ReturnStatement",
|
|
22142
|
-
expression: ref,
|
|
22143
|
-
children: ["return ", ref]
|
|
22144
|
-
}
|
|
22145
|
-
]);
|
|
22146
|
-
}
|
|
22147
|
-
return true;
|
|
22148
|
-
}
|
|
22149
|
-
function isVoidType(t) {
|
|
22150
|
-
return t?.type === "LiteralType" && t.t.type === "VoidType";
|
|
22151
|
-
}
|
|
22152
|
-
function processFunctions(statements) {
|
|
22153
|
-
gatherRecursiveAll(statements, ({ type }) => type === "FunctionExpression" || type === "ArrowFunction").forEach((f) => {
|
|
22154
|
-
processParams(f);
|
|
22155
|
-
if (!processReturnValue(f) && module2.config.implicitReturns) {
|
|
22156
|
-
const { block, returnType } = f;
|
|
22157
|
-
const isVoid = isVoidType(returnType?.t);
|
|
22158
|
-
const isBlock = block?.type === "BlockStatement";
|
|
22159
|
-
if (!isVoid && isBlock) {
|
|
22160
|
-
insertReturn(block);
|
|
22161
|
-
}
|
|
22162
|
-
}
|
|
22163
|
-
});
|
|
22164
|
-
gatherRecursiveAll(statements, ({ type }) => type === "MethodDefinition").forEach((f) => {
|
|
22165
|
-
processParams(f);
|
|
22166
|
-
if (!processReturnValue(f) && module2.config.implicitReturns) {
|
|
22167
|
-
const { signature, block } = f;
|
|
22168
|
-
const isConstructor = signature.name === "constructor";
|
|
22169
|
-
const isVoid = isVoidType(signature.returnType?.t);
|
|
22170
|
-
const isSet = signature.modifier?.set;
|
|
22171
|
-
if (!isConstructor && !isSet && !isVoid) {
|
|
22172
|
-
insertReturn(block);
|
|
22173
|
-
}
|
|
22174
|
-
}
|
|
22175
|
-
});
|
|
22176
|
-
}
|
|
22177
|
-
function processSwitchExpressions(statements) {
|
|
22178
|
-
if (module2.config.implicitReturns) {
|
|
22179
|
-
gatherRecursiveAll(statements, (n) => n.type === "SwitchExpression").forEach(insertSwitchReturns);
|
|
22180
|
-
}
|
|
22181
|
-
}
|
|
22182
|
-
function processTryExpressions(statements) {
|
|
22183
|
-
if (module2.config.implicitReturns) {
|
|
22184
|
-
gatherRecursiveAll(statements, (n) => n.type === "TryExpression").forEach(({ blocks }) => {
|
|
22185
|
-
blocks.forEach(insertReturn);
|
|
22186
|
-
});
|
|
22187
|
-
}
|
|
22188
|
-
}
|
|
22189
|
-
function processBindingPatternLHS(lhs, tail) {
|
|
22190
|
-
adjustAtBindings(lhs, true);
|
|
22191
|
-
const [splices, thisAssignments] = gatherBindingCode(lhs);
|
|
22192
|
-
tail.push(...splices.map((s) => [", ", s]), ...thisAssignments.map((a) => [", ", a]));
|
|
22193
|
-
}
|
|
22194
|
-
function processAssignments(statements) {
|
|
22195
|
-
gatherRecursiveAll(statements, (n) => n.type === "AssignmentExpression" && n.names === null).forEach((exp) => {
|
|
22196
|
-
let { lhs: $12, exp: $22 } = exp, tail = [], i = 0, len = $12.length;
|
|
22197
|
-
if ($12.some((left) => left[left.length - 1].special)) {
|
|
22198
|
-
if ($12.length !== 1) {
|
|
22199
|
-
throw new Error("Only one assignment with id= is allowed");
|
|
22200
|
-
}
|
|
22201
|
-
const [, lhs, , op] = $12[0];
|
|
22202
|
-
const { call } = op;
|
|
22203
|
-
op[op.length - 1] = "=";
|
|
22204
|
-
$22 = [call, "(", lhs, ", ", $22, ")"];
|
|
22205
|
-
}
|
|
22206
|
-
let wrapped = false;
|
|
22207
|
-
while (i < len) {
|
|
22208
|
-
const lastAssignment = $12[i++];
|
|
22209
|
-
const [, lhs, , op] = lastAssignment;
|
|
22210
|
-
if (op.token !== "=")
|
|
22211
|
-
continue;
|
|
22212
|
-
if (lhs.type === "ObjectExpression" || lhs.type === "ObjectBindingPattern") {
|
|
22213
|
-
if (!wrapped) {
|
|
22214
|
-
wrapped = true;
|
|
22215
|
-
lhs.children.splice(0, 0, "(");
|
|
22216
|
-
tail.push(")");
|
|
22217
|
-
}
|
|
22218
|
-
}
|
|
22219
|
-
}
|
|
22220
|
-
i = len - 1;
|
|
22221
|
-
while (i >= 0) {
|
|
22222
|
-
const lastAssignment = $12[i];
|
|
22223
|
-
if (lastAssignment[3].token === "=") {
|
|
22224
|
-
const lhs = lastAssignment[1];
|
|
22225
|
-
if (lhs.type === "MemberExpression") {
|
|
22226
|
-
const members = lhs.children;
|
|
22227
|
-
const lastMember = members[members.length - 1];
|
|
22228
|
-
if (lastMember.type === "SliceExpression") {
|
|
22229
|
-
const { start, end, children: c } = lastMember;
|
|
22230
|
-
c[0].token = ".splice(";
|
|
22231
|
-
c[1] = start;
|
|
22232
|
-
c[2] = ", ";
|
|
22233
|
-
if (end)
|
|
22234
|
-
c[3] = [end, " - ", start];
|
|
22235
|
-
else
|
|
22236
|
-
c[3] = ["1/0"];
|
|
22237
|
-
c[4] = [", ...", $22];
|
|
22238
|
-
c[5] = ")";
|
|
22239
|
-
lastAssignment.pop();
|
|
22240
|
-
if (module2.isWhitespaceOrEmpty(lastAssignment[2]))
|
|
22241
|
-
lastAssignment.pop();
|
|
22242
|
-
if ($12.length > 1) {
|
|
22243
|
-
throw new Error("Not implemented yet! TODO: Handle multiple splice assignments");
|
|
22244
|
-
}
|
|
22245
|
-
exp.children = [$12];
|
|
22246
|
-
exp.names = [];
|
|
22247
|
-
return;
|
|
22248
|
-
}
|
|
22249
|
-
} else if (lhs.type === "ObjectBindingPattern" || lhs.type === "ArrayBindingPattern") {
|
|
22250
|
-
processBindingPatternLHS(lhs, tail);
|
|
22251
|
-
}
|
|
22252
|
-
}
|
|
22253
|
-
i--;
|
|
22254
|
-
}
|
|
22255
|
-
const names = $12.flatMap(([, l]) => l.names || []);
|
|
22256
|
-
exp.children = [$12, $22, ...tail];
|
|
22257
|
-
exp.names = names;
|
|
22258
|
-
});
|
|
22259
|
-
gatherRecursiveAll(statements, (n) => n.type === "AssignmentExpression" || n.type === "UpdateExpression").forEach((exp) => {
|
|
22260
|
-
function extractAssignment(lhs) {
|
|
22261
|
-
let expr = lhs;
|
|
22262
|
-
while (expr.type === "ParenthesizedExpression") {
|
|
22263
|
-
expr = expr.expression;
|
|
22264
|
-
}
|
|
22265
|
-
if (expr.type === "AssignmentExpression" || expr.type === "UpdateExpression") {
|
|
22266
|
-
if (expr.type === "UpdateExpression" && expr.children[0] === expr.assigned) {
|
|
22267
|
-
post.push([", ", lhs]);
|
|
22268
|
-
} else {
|
|
22269
|
-
pre.push([lhs, ", "]);
|
|
22270
|
-
}
|
|
22271
|
-
return expr.assigned;
|
|
22272
|
-
}
|
|
22273
|
-
}
|
|
22274
|
-
const pre = [], post = [];
|
|
22275
|
-
switch (exp.type) {
|
|
22276
|
-
case "AssignmentExpression":
|
|
22277
|
-
if (!exp.lhs)
|
|
22278
|
-
return;
|
|
22279
|
-
exp.lhs.forEach((lhsPart, i) => {
|
|
22280
|
-
let newLhs2 = extractAssignment(lhsPart[1]);
|
|
22281
|
-
if (newLhs2) {
|
|
22282
|
-
lhsPart[1] = newLhs2;
|
|
22283
|
-
}
|
|
22284
|
-
});
|
|
22285
|
-
break;
|
|
22286
|
-
case "UpdateExpression":
|
|
22287
|
-
let newLhs = extractAssignment(exp.assigned);
|
|
22288
|
-
if (newLhs) {
|
|
22289
|
-
const i = exp.children.indexOf(exp.assigned);
|
|
22290
|
-
exp.assigned = exp.children[i] = newLhs;
|
|
22291
|
-
}
|
|
22292
|
-
break;
|
|
22293
|
-
}
|
|
22294
|
-
if (pre.length)
|
|
22295
|
-
exp.children.unshift(...pre);
|
|
22296
|
-
if (post.length)
|
|
22297
|
-
exp.children.push(...post);
|
|
22298
|
-
});
|
|
22299
|
-
}
|
|
22300
|
-
module2.attachPostfixStatementAsExpression = function(exp, post) {
|
|
22301
|
-
let clause;
|
|
22302
|
-
switch (post[1].type) {
|
|
22303
|
-
case "ForStatement":
|
|
22304
|
-
case "IterationStatement":
|
|
22305
|
-
case "DoStatement":
|
|
22306
|
-
clause = module2.addPostfixStatement(exp, ...post);
|
|
22307
|
-
return {
|
|
22308
|
-
type: "IterationExpression",
|
|
22309
|
-
children: [clause],
|
|
22310
|
-
block: clause.block
|
|
22311
|
-
};
|
|
22312
|
-
case "IfStatement":
|
|
22313
|
-
clause = module2.expressionizeIfClause(post[1], exp);
|
|
22314
|
-
return clause;
|
|
22315
|
-
default:
|
|
22316
|
-
throw new Error("Unknown postfix statement");
|
|
22317
|
-
}
|
|
22318
|
-
};
|
|
22319
|
-
function getPatternConditions(pattern, ref, conditions) {
|
|
22320
|
-
if (pattern.rest)
|
|
22321
|
-
return;
|
|
22322
|
-
switch (pattern.type) {
|
|
22323
|
-
case "ArrayBindingPattern": {
|
|
22324
|
-
const { elements, length } = pattern, hasRest = elements.some((e) => e.rest), comparator = hasRest ? " >= " : " === ", l = [comparator, (length - hasRest).toString()];
|
|
22325
|
-
conditions.push(
|
|
22326
|
-
["Array.isArray(", ref, ")"],
|
|
22327
|
-
[ref, ".length", l]
|
|
22328
|
-
);
|
|
22329
|
-
elements.forEach(({ children: [, e] }, i) => {
|
|
22330
|
-
const subRef = [ref, "[", i.toString(), "]"];
|
|
22331
|
-
getPatternConditions(e, subRef, conditions);
|
|
22332
|
-
});
|
|
22333
|
-
const postRest = pattern.children.find((c) => c?.blockPrefix);
|
|
22334
|
-
if (postRest) {
|
|
22335
|
-
const postElements = postRest.blockPrefix.children[1], { length: postLength } = postElements;
|
|
22336
|
-
postElements.forEach(({ children: [, e] }, i) => {
|
|
22337
|
-
const subRef = [ref, "[", ref, ".length - ", (postLength + i).toString(), "]"];
|
|
22338
|
-
getPatternConditions(e, subRef, conditions);
|
|
22339
|
-
});
|
|
22340
|
-
}
|
|
22341
|
-
break;
|
|
22342
|
-
}
|
|
22343
|
-
case "ObjectBindingPattern": {
|
|
22344
|
-
conditions.push(
|
|
22345
|
-
["typeof ", ref, " === 'object'"],
|
|
22346
|
-
[ref, " != null"]
|
|
22347
|
-
);
|
|
22348
|
-
pattern.properties.forEach((p) => {
|
|
22349
|
-
switch (p.type) {
|
|
22350
|
-
case "PinProperty":
|
|
22351
|
-
case "BindingProperty": {
|
|
22352
|
-
const { name, value } = p;
|
|
22353
|
-
let subRef;
|
|
22354
|
-
switch (name.type) {
|
|
22355
|
-
case "ComputedPropertyName":
|
|
22356
|
-
conditions.push([name.expression, " in ", ref]);
|
|
22357
|
-
subRef = [ref, name];
|
|
22358
|
-
break;
|
|
22359
|
-
case "Literal":
|
|
22360
|
-
case "StringLiteral":
|
|
22361
|
-
case "NumericLiteral":
|
|
22362
|
-
conditions.push([name, " in ", ref]);
|
|
22363
|
-
subRef = [ref, "[", name, "]"];
|
|
22364
|
-
break;
|
|
22365
|
-
default:
|
|
22366
|
-
conditions.push(["'", name, "' in ", ref]);
|
|
22367
|
-
subRef = [ref, ".", name];
|
|
22368
|
-
}
|
|
22369
|
-
if (value) {
|
|
22370
|
-
getPatternConditions(value, subRef, conditions);
|
|
22371
|
-
}
|
|
22372
|
-
break;
|
|
22373
|
-
}
|
|
22374
|
-
}
|
|
22375
|
-
});
|
|
22376
|
-
break;
|
|
22377
|
-
}
|
|
22378
|
-
case "ConditionFragment":
|
|
22379
|
-
conditions.push(
|
|
22380
|
-
[ref, " ", pattern.children]
|
|
22381
|
-
);
|
|
22382
|
-
break;
|
|
22383
|
-
case "RegularExpressionLiteral": {
|
|
22384
|
-
conditions.push(
|
|
22385
|
-
["typeof ", ref, " === 'string'"],
|
|
22386
|
-
[pattern, ".test(", ref, ")"]
|
|
22387
|
-
);
|
|
22388
|
-
break;
|
|
22389
|
-
}
|
|
22390
|
-
case "PinPattern":
|
|
22391
|
-
conditions.push([
|
|
22392
|
-
ref,
|
|
22393
|
-
" === ",
|
|
22394
|
-
pattern.identifier
|
|
22395
|
-
]);
|
|
22396
|
-
break;
|
|
22397
|
-
case "Literal":
|
|
22398
|
-
conditions.push([
|
|
22399
|
-
ref,
|
|
22400
|
-
" === ",
|
|
22401
|
-
pattern
|
|
22402
|
-
]);
|
|
22403
|
-
break;
|
|
22404
|
-
default:
|
|
22405
|
-
break;
|
|
22406
|
-
}
|
|
22407
|
-
}
|
|
22408
|
-
function elideMatchersFromArrayBindings(elements) {
|
|
22409
|
-
return elements.map((el) => {
|
|
22410
|
-
if (el.type === "BindingRestElement") {
|
|
22411
|
-
return ["", el, void 0];
|
|
22412
|
-
}
|
|
22413
|
-
const { children: [ws, e, sep] } = el;
|
|
22414
|
-
switch (e.type) {
|
|
22415
|
-
case "Literal":
|
|
22416
|
-
case "RegularExpressionLiteral":
|
|
22417
|
-
case "StringLiteral":
|
|
22418
|
-
case "PinPattern":
|
|
22419
|
-
return sep;
|
|
22420
|
-
default:
|
|
22421
|
-
return [ws, nonMatcherBindings(e), sep];
|
|
22422
|
-
}
|
|
22423
|
-
});
|
|
22424
|
-
}
|
|
22425
|
-
function elideMatchersFromPropertyBindings(properties) {
|
|
22426
|
-
return properties.map((p) => {
|
|
22427
|
-
switch (p.type) {
|
|
22428
|
-
case "BindingProperty": {
|
|
22429
|
-
const { children, name, value } = p;
|
|
22430
|
-
const [ws] = children;
|
|
22431
|
-
const sep = children[children.length - 1];
|
|
22432
|
-
switch (value && value.type) {
|
|
22433
|
-
case "ArrayBindingPattern":
|
|
22434
|
-
case "ObjectBindingPattern":
|
|
22435
|
-
return {
|
|
22436
|
-
...p,
|
|
22437
|
-
children: [ws, name, ": ", nonMatcherBindings(value)]
|
|
22438
|
-
};
|
|
22439
|
-
case "Identifier":
|
|
22440
|
-
return p;
|
|
22441
|
-
case "Literal":
|
|
22442
|
-
case "RegularExpressionLiteral":
|
|
22443
|
-
case "StringLiteral":
|
|
22444
|
-
default:
|
|
22445
|
-
return {
|
|
22446
|
-
...p,
|
|
22447
|
-
children: [ws, name, sep]
|
|
22448
|
-
};
|
|
22449
|
-
}
|
|
22450
|
-
}
|
|
22451
|
-
case "PinProperty":
|
|
22452
|
-
case "BindingRestProperty":
|
|
22453
|
-
default:
|
|
22454
|
-
return p;
|
|
22455
|
-
}
|
|
22456
|
-
});
|
|
22457
|
-
}
|
|
22458
|
-
function nonMatcherBindings(pattern) {
|
|
22459
|
-
switch (pattern.type) {
|
|
22460
|
-
case "ArrayBindingPattern": {
|
|
22461
|
-
const elements = elideMatchersFromArrayBindings(pattern.elements);
|
|
22462
|
-
const children = ["[", elements, "]"];
|
|
22463
|
-
return {
|
|
22464
|
-
...pattern,
|
|
22465
|
-
children,
|
|
22466
|
-
elements
|
|
22467
|
-
};
|
|
22468
|
-
}
|
|
22469
|
-
case "PostRestBindingElements": {
|
|
22470
|
-
const els = elideMatchersFromArrayBindings(pattern.children[1]);
|
|
22471
|
-
return {
|
|
22472
|
-
...pattern,
|
|
22473
|
-
children: [
|
|
22474
|
-
pattern.children[0],
|
|
22475
|
-
els,
|
|
22476
|
-
...pattern.children.slice(2)
|
|
22477
|
-
]
|
|
22478
|
-
};
|
|
22479
|
-
}
|
|
22480
|
-
case "ObjectBindingPattern":
|
|
22481
|
-
return ["{", elideMatchersFromPropertyBindings(pattern.properties), "}"];
|
|
22482
|
-
default:
|
|
22483
|
-
return pattern;
|
|
22484
|
-
}
|
|
22485
|
-
}
|
|
22486
|
-
function aggregateDuplicateBindings(bindings) {
|
|
22487
|
-
const props = gatherRecursiveAll(bindings, (n) => n.type === "BindingProperty");
|
|
22488
|
-
const arrayBindings = gatherRecursiveAll(bindings, (n) => n.type === "ArrayBindingPattern");
|
|
22489
|
-
arrayBindings.forEach((a) => {
|
|
22490
|
-
const { elements } = a;
|
|
22491
|
-
elements.forEach((element) => {
|
|
22492
|
-
if (Array.isArray(element)) {
|
|
22493
|
-
const [, e] = element;
|
|
22494
|
-
if (e.type === "Identifier") {
|
|
22495
|
-
props.push(e);
|
|
22496
|
-
} else if (e.type === "BindingRestElement") {
|
|
22497
|
-
props.push(e);
|
|
22498
|
-
}
|
|
22499
|
-
}
|
|
22500
|
-
});
|
|
22501
|
-
});
|
|
22502
|
-
const declarations = [];
|
|
22503
|
-
const propsGroupedByName = /* @__PURE__ */ new Map();
|
|
22504
|
-
for (const p of props) {
|
|
22505
|
-
const { name, value } = p;
|
|
22506
|
-
const key = value?.name || name?.name || name;
|
|
22507
|
-
if (propsGroupedByName.has(key)) {
|
|
22508
|
-
propsGroupedByName.get(key).push(p);
|
|
22509
|
-
} else {
|
|
22510
|
-
propsGroupedByName.set(key, [p]);
|
|
22511
|
-
}
|
|
22512
|
-
}
|
|
22513
|
-
propsGroupedByName.forEach((shared, key) => {
|
|
22514
|
-
if (!key)
|
|
22515
|
-
return;
|
|
22516
|
-
if (ReservedWord({
|
|
22517
|
-
pos: 0,
|
|
22518
|
-
input: key
|
|
22519
|
-
})) {
|
|
22520
|
-
shared.forEach((p) => {
|
|
22521
|
-
const ref = {
|
|
22522
|
-
type: "Ref",
|
|
22523
|
-
base: `_${key}`,
|
|
22524
|
-
id: key
|
|
22525
|
-
};
|
|
22526
|
-
aliasBinding(p, ref);
|
|
22527
|
-
});
|
|
22528
|
-
return;
|
|
22529
|
-
}
|
|
22530
|
-
if (shared.length === 1)
|
|
22531
|
-
return;
|
|
22532
|
-
const refs = shared.map((p) => {
|
|
22533
|
-
const ref = {
|
|
22534
|
-
type: "Ref",
|
|
22535
|
-
base: key,
|
|
22536
|
-
id: key
|
|
22537
|
-
};
|
|
22538
|
-
aliasBinding(p, ref);
|
|
22539
|
-
return ref;
|
|
22540
|
-
});
|
|
22541
|
-
declarations.push(["const ", key, " = [", ...refs.map((r, i) => {
|
|
22542
|
-
return i === 0 ? r : [", ", r];
|
|
22543
|
-
}), "]"]);
|
|
22544
|
-
});
|
|
22545
|
-
return declarations;
|
|
22546
|
-
}
|
|
22547
|
-
function processPatternMatching(statements) {
|
|
22548
|
-
gatherRecursiveAll(statements, (n) => n.type === "SwitchStatement" || n.type === "SwitchExpression").forEach((s) => {
|
|
22549
|
-
const { caseBlock } = s;
|
|
22550
|
-
const { clauses } = caseBlock;
|
|
22551
|
-
let errors = false;
|
|
22552
|
-
let isPattern = false;
|
|
22553
|
-
if (clauses.some((c) => c.type === "PatternClause")) {
|
|
22554
|
-
isPattern = true;
|
|
22555
|
-
clauses.forEach((c) => {
|
|
22556
|
-
if (!(c.type === "PatternClause" || c.type === "DefaultClause")) {
|
|
22557
|
-
errors = true;
|
|
22558
|
-
c.children.push({
|
|
22559
|
-
type: "Error",
|
|
22560
|
-
message: "Can't mix pattern matching and non-pattern matching clauses"
|
|
22561
|
-
});
|
|
22562
|
-
}
|
|
22563
|
-
});
|
|
22564
|
-
}
|
|
22565
|
-
if (errors || !isPattern)
|
|
22566
|
-
return;
|
|
22567
|
-
let { expression } = s;
|
|
22568
|
-
if (expression.type === "ParenthesizedExpression") {
|
|
22569
|
-
expression = expression.expression;
|
|
22570
|
-
}
|
|
22571
|
-
let ref = module2.needsRef(expression, "m") || expression;
|
|
22572
|
-
let hoistDec = ref !== expression ? [["", ["const ", ref, " = ", expression], ";"]] : void 0;
|
|
22573
|
-
let prev = [], root = prev;
|
|
22574
|
-
const l = clauses.length;
|
|
22575
|
-
clauses.forEach((c, i) => {
|
|
22576
|
-
if (c.type === "DefaultClause") {
|
|
22577
|
-
prev.push(c.block);
|
|
22578
|
-
return;
|
|
22579
|
-
}
|
|
22580
|
-
let { patterns, block } = c;
|
|
22581
|
-
let pattern = patterns[0];
|
|
22582
|
-
const indent = block.expressions?.[0]?.[0] || "";
|
|
22583
|
-
const alternativeConditions = patterns.map((pattern2, i2) => {
|
|
22584
|
-
const conditions = [];
|
|
22585
|
-
getPatternConditions(pattern2, ref, conditions);
|
|
22586
|
-
return conditions;
|
|
22587
|
-
});
|
|
22588
|
-
const conditionExpression = alternativeConditions.map((conditions, i2) => {
|
|
22589
|
-
const conditionArray = conditions.map((c2, i3) => {
|
|
22590
|
-
if (i3 === 0)
|
|
22591
|
-
return c2;
|
|
22592
|
-
return [" && ", ...c2];
|
|
22593
|
-
});
|
|
22594
|
-
if (i2 === 0)
|
|
22595
|
-
return conditionArray;
|
|
22596
|
-
return [" || ", ...conditionArray];
|
|
22597
|
-
});
|
|
22598
|
-
const condition = {
|
|
22599
|
-
type: "ParenthesizedExpression",
|
|
22600
|
-
children: ["(", conditionExpression, ")"],
|
|
22601
|
-
expression: conditionExpression
|
|
22602
|
-
};
|
|
22603
|
-
const prefix = [];
|
|
22604
|
-
switch (pattern.type) {
|
|
22605
|
-
case "ArrayBindingPattern":
|
|
22606
|
-
if (pattern.length === 0)
|
|
22607
|
-
break;
|
|
22608
|
-
case "ObjectBindingPattern": {
|
|
22609
|
-
if (pattern.properties?.length === 0)
|
|
22610
|
-
break;
|
|
22611
|
-
let [splices, thisAssignments] = gatherBindingCode(pattern);
|
|
22612
|
-
const patternBindings = nonMatcherBindings(pattern);
|
|
22613
|
-
splices = splices.map((s2) => [", ", nonMatcherBindings(s2)]);
|
|
22614
|
-
thisAssignments = thisAssignments.map((a) => [indent, a, ";"]);
|
|
22615
|
-
const duplicateDeclarations = aggregateDuplicateBindings([patternBindings, splices]);
|
|
22616
|
-
prefix.push([indent, "const ", patternBindings, " = ", ref, splices, ";"]);
|
|
22617
|
-
prefix.push(...thisAssignments);
|
|
22618
|
-
prefix.push(...duplicateDeclarations.map((d) => [indent, d, ";"]));
|
|
22619
|
-
break;
|
|
22620
|
-
}
|
|
22621
|
-
}
|
|
22622
|
-
block.expressions.unshift(...prefix);
|
|
22623
|
-
const next = [];
|
|
22624
|
-
if (block.bare) {
|
|
22625
|
-
block.children.unshift(" {");
|
|
22626
|
-
block.children.push("}");
|
|
22627
|
-
block.bare = false;
|
|
22628
|
-
}
|
|
22629
|
-
if (i < l - 1)
|
|
22630
|
-
next.push("\n", "else ");
|
|
22631
|
-
prev.push(["", {
|
|
22632
|
-
type: "IfStatement",
|
|
22633
|
-
children: ["if", condition, block, next],
|
|
22634
|
-
then: block,
|
|
22635
|
-
else: next,
|
|
22636
|
-
hoistDec
|
|
22637
|
-
}]);
|
|
22638
|
-
hoistDec = void 0;
|
|
22639
|
-
prev = next;
|
|
22640
|
-
});
|
|
22641
|
-
if (module2.config.implicitReturns && s.type === "SwitchExpression") {
|
|
22642
|
-
insertReturn(root[0]);
|
|
22643
|
-
root.splice(0, 1, module2.wrapIIFE(root[0]));
|
|
22644
|
-
}
|
|
22645
|
-
s.type = "PatternMatchingStatement";
|
|
22646
|
-
s.children = [root];
|
|
22647
|
-
addParentPointers(s, s.parent);
|
|
22648
|
-
});
|
|
22649
|
-
}
|
|
22650
|
-
function processPipelineExpressions(statements) {
|
|
22651
|
-
gatherRecursiveAll(statements, (n) => n.type === "PipelineExpression").forEach((s) => {
|
|
22652
|
-
const [ws, , body] = s.children;
|
|
22653
|
-
let [, arg] = s.children;
|
|
22654
|
-
let i = 0, l = body.length;
|
|
22655
|
-
const refDec = [];
|
|
22656
|
-
const children = [ws, refDec];
|
|
22657
|
-
let usingRef = null;
|
|
22658
|
-
for (i = 0; i < l; i++) {
|
|
22659
|
-
const step = body[i];
|
|
22660
|
-
const [leadingComment, pipe, trailingComment, expr] = step;
|
|
22661
|
-
const returns = pipe.token === "||>";
|
|
22662
|
-
let ref, result, returning = returns ? arg : null;
|
|
22663
|
-
if (pipe.token === "|>=") {
|
|
22664
|
-
let initRef;
|
|
22665
|
-
if (i === 0) {
|
|
22666
|
-
outer:
|
|
22667
|
-
switch (arg.type) {
|
|
22668
|
-
case "MemberExpression":
|
|
22669
|
-
if (arg.children.length <= 2)
|
|
22670
|
-
break;
|
|
22671
|
-
case "CallExpression":
|
|
22672
|
-
const access = arg.children.pop();
|
|
22673
|
-
switch (access.type) {
|
|
22674
|
-
case "PropertyAccess":
|
|
22675
|
-
case "SliceExpression":
|
|
22676
|
-
break;
|
|
22677
|
-
default:
|
|
22678
|
-
children.unshift({
|
|
22679
|
-
type: "Error",
|
|
22680
|
-
$loc: pipe.token.$loc,
|
|
22681
|
-
message: `Can't assign to ${access.type}`
|
|
22682
|
-
});
|
|
22683
|
-
arg.children.push(access);
|
|
22684
|
-
break outer;
|
|
22685
|
-
}
|
|
22686
|
-
usingRef = module2.needsRef({});
|
|
22687
|
-
initRef = {
|
|
22688
|
-
type: "AssignmentExpression",
|
|
22689
|
-
children: [usingRef, " = ", arg, ","]
|
|
22690
|
-
};
|
|
22691
|
-
arg = {
|
|
22692
|
-
type: "MemberExpression",
|
|
22693
|
-
children: [usingRef, access]
|
|
22694
|
-
};
|
|
22695
|
-
break;
|
|
22696
|
-
}
|
|
22697
|
-
children.pop();
|
|
22698
|
-
const lhs = [[
|
|
22699
|
-
[refDec, initRef],
|
|
22700
|
-
arg,
|
|
22701
|
-
[],
|
|
22702
|
-
{ token: "=", children: [" = "] }
|
|
22703
|
-
]];
|
|
22704
|
-
Object.assign(s, {
|
|
22705
|
-
type: "AssignmentExpression",
|
|
22706
|
-
children: [lhs, children],
|
|
22707
|
-
names: null,
|
|
22708
|
-
lhs,
|
|
22709
|
-
assigned: arg,
|
|
22710
|
-
exp: children
|
|
22711
|
-
});
|
|
22712
|
-
arg = clone(arg);
|
|
22713
|
-
if (arg.children[0].type === "Ref") {
|
|
22714
|
-
arg.children[0] = usingRef;
|
|
22715
|
-
}
|
|
22716
|
-
} else {
|
|
22717
|
-
children.unshift({
|
|
22718
|
-
type: "Error",
|
|
22719
|
-
$loc: pipe.token.$loc,
|
|
22720
|
-
message: "Can't use |>= in the middle of a pipeline"
|
|
22721
|
-
});
|
|
22722
|
-
}
|
|
22723
|
-
} else {
|
|
22724
|
-
s.children = children;
|
|
22725
|
-
}
|
|
22726
|
-
if (returns && (ref = module2.needsRef(arg))) {
|
|
22727
|
-
usingRef = usingRef || ref;
|
|
22728
|
-
arg = {
|
|
22729
|
-
type: "ParenthesizedExpression",
|
|
22730
|
-
children: ["(", {
|
|
22731
|
-
type: "AssignmentExpression",
|
|
22732
|
-
children: [usingRef, " = ", arg]
|
|
22733
|
-
}, ")"]
|
|
22734
|
-
};
|
|
22735
|
-
returning = usingRef;
|
|
22820
|
+
return s[s.length - 1];
|
|
22736
22821
|
}
|
|
22737
|
-
|
|
22738
|
-
|
|
22739
|
-
|
|
22740
|
-
|
|
22741
|
-
|
|
22742
|
-
},
|
|
22743
|
-
arg,
|
|
22744
|
-
returning
|
|
22745
|
-
);
|
|
22746
|
-
if (result.type === "ReturnStatement") {
|
|
22747
|
-
if (i < l - 1) {
|
|
22748
|
-
result.children.push({
|
|
22749
|
-
type: "Error",
|
|
22750
|
-
message: "Can't continue a pipeline after returning"
|
|
22751
|
-
});
|
|
22752
|
-
}
|
|
22753
|
-
arg = result;
|
|
22754
|
-
if (children[children.length - 1] === ",") {
|
|
22755
|
-
children.pop();
|
|
22756
|
-
children.push(";");
|
|
22757
|
-
}
|
|
22758
|
-
break;
|
|
22822
|
+
},
|
|
22823
|
+
newlineBinaryOpForbidden: {
|
|
22824
|
+
get() {
|
|
22825
|
+
const { forbidNewlineBinaryOp: s } = module2;
|
|
22826
|
+
return s[s.length - 1];
|
|
22759
22827
|
}
|
|
22760
|
-
|
|
22761
|
-
|
|
22762
|
-
|
|
22763
|
-
|
|
22764
|
-
|
|
22828
|
+
},
|
|
22829
|
+
currentJSXTag: {
|
|
22830
|
+
get() {
|
|
22831
|
+
const { JSXTagStack: s } = module2;
|
|
22832
|
+
return s[s.length - 1];
|
|
22765
22833
|
}
|
|
22766
22834
|
}
|
|
22767
|
-
if (usingRef) {
|
|
22768
|
-
refDec.unshift("let ", usingRef, ";");
|
|
22769
|
-
}
|
|
22770
|
-
children.push(arg);
|
|
22771
|
-
addParentPointers(s, s.parent);
|
|
22772
22835
|
});
|
|
22773
22836
|
}
|
|
22774
|
-
module2.
|
|
22775
|
-
|
|
22776
|
-
|
|
22777
|
-
|
|
22778
|
-
|
|
22779
|
-
|
|
22780
|
-
|
|
22781
|
-
|
|
22782
|
-
|
|
22783
|
-
|
|
22784
|
-
|
|
22785
|
-
|
|
22786
|
-
|
|
22787
|
-
|
|
22788
|
-
|
|
22789
|
-
|
|
22790
|
-
|
|
22791
|
-
|
|
22792
|
-
|
|
22793
|
-
|
|
22794
|
-
|
|
22795
|
-
|
|
22796
|
-
|
|
22797
|
-
|
|
22798
|
-
|
|
22799
|
-
|
|
22800
|
-
|
|
22801
|
-
|
|
22802
|
-
|
|
22803
|
-
|
|
22804
|
-
|
|
22805
|
-
|
|
22806
|
-
|
|
22807
|
-
|
|
22808
|
-
|
|
22809
|
-
|
|
22810
|
-
|
|
22811
|
-
|
|
22812
|
-
|
|
22813
|
-
|
|
22814
|
-
|
|
22815
|
-
|
|
22816
|
-
|
|
22817
|
-
|
|
22818
|
-
|
|
22819
|
-
|
|
22820
|
-
|
|
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
|
+
]
|
|
22821
22922
|
});
|
|
22822
|
-
}
|
|
22823
|
-
|
|
22824
|
-
|
|
22825
|
-
|
|
22826
|
-
|
|
22827
|
-
|
|
22828
|
-
|
|
22829
|
-
|
|
22830
|
-
|
|
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
|
+
]
|
|
22831
22932
|
});
|
|
22832
|
-
|
|
22833
|
-
|
|
22834
|
-
|
|
22835
|
-
|
|
22836
|
-
|
|
22837
|
-
|
|
22838
|
-
|
|
22839
|
-
|
|
22840
|
-
|
|
22841
|
-
|
|
22842
|
-
|
|
22843
|
-
|
|
22844
|
-
|
|
22845
|
-
|
|
22846
|
-
|
|
22847
|
-
|
|
22848
|
-
|
|
22849
|
-
if (!hasDec(x))
|
|
22850
|
-
return a.indexOf(x) === i;
|
|
22851
|
-
}).forEach(pushVar);
|
|
22852
|
-
const fnNodes = gatherNodes(statements, (s) => s.type === "FunctionExpression");
|
|
22853
|
-
const forNodes = gatherNodes(statements, (s) => s.type === "ForStatement");
|
|
22854
|
-
const blockNodes = new Set(gatherNodes(statements, (s) => s.type === "BlockStatement"));
|
|
22855
|
-
fnNodes.forEach(({ block }) => blockNodes.delete(block));
|
|
22856
|
-
forNodes.forEach(({ block }) => blockNodes.delete(block));
|
|
22857
|
-
blockNodes.forEach((block) => {
|
|
22858
|
-
createVarDecs(block.expressions, scopes, pushVar);
|
|
22859
|
-
});
|
|
22860
|
-
forNodes.forEach(({ block, declaration }) => {
|
|
22861
|
-
scopes.push(new Set(declaration.names));
|
|
22862
|
-
createVarDecs(block.expressions, scopes, pushVar);
|
|
22863
|
-
scopes.pop();
|
|
22864
|
-
});
|
|
22865
|
-
fnNodes.forEach(({ block, parameters }) => {
|
|
22866
|
-
scopes.push(new Set(parameters.names));
|
|
22867
|
-
createVarDecs(block.expressions, scopes);
|
|
22868
|
-
scopes.pop();
|
|
22869
|
-
});
|
|
22870
|
-
if (varIds.length) {
|
|
22871
|
-
const indent = getIndent(statements[0]);
|
|
22872
|
-
let delimiter = ";";
|
|
22873
|
-
if (statements[0][1]?.parent?.root) {
|
|
22874
|
-
delimiter = ";\n";
|
|
22875
|
-
}
|
|
22876
|
-
statements.unshift([indent, "var ", varIds.join(", "), delimiter]);
|
|
22877
|
-
}
|
|
22878
|
-
scopes.pop();
|
|
22879
|
-
}
|
|
22880
|
-
function createLetDecs(statements, scopes) {
|
|
22881
|
-
function findVarDecs(statements2, decs) {
|
|
22882
|
-
const declarationNames = gatherRecursive(
|
|
22883
|
-
statements2,
|
|
22884
|
-
(node) => node.type === "Declaration" && node.children && node.children.length > 0 && node.children[0].token && node.children[0].token.startsWith("var") || node.type === "FunctionExpression"
|
|
22885
|
-
).filter((node) => node.type === "Declaration").flatMap((node) => node.names);
|
|
22886
|
-
return new Set(declarationNames);
|
|
22887
|
-
}
|
|
22888
|
-
let declaredIdentifiers = findVarDecs(statements);
|
|
22889
|
-
function hasDec(name) {
|
|
22890
|
-
return declaredIdentifiers.has(name) || scopes.some((s) => s.has(name));
|
|
22891
|
-
}
|
|
22892
|
-
function gatherBlockOrOther(statement) {
|
|
22893
|
-
return gatherNodes(statement, (s) => s.type === "BlockStatement" || s.type === "AssignmentExpression" || s.type === "Declaration").flatMap((node) => {
|
|
22894
|
-
if (node.type == "BlockStatement")
|
|
22895
|
-
return node.bare ? gatherBlockOrOther(node.expressions) : node;
|
|
22896
|
-
else if (node.children && node.children.length)
|
|
22897
|
-
return [...gatherBlockOrOther(node.children), node];
|
|
22898
|
-
else
|
|
22899
|
-
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
|
+
]
|
|
22900
22950
|
});
|
|
22901
22951
|
}
|
|
22902
|
-
|
|
22903
|
-
|
|
22904
|
-
|
|
22905
|
-
|
|
22906
|
-
|
|
22907
|
-
|
|
22908
|
-
|
|
22909
|
-
|
|
22910
|
-
|
|
22911
|
-
|
|
22912
|
-
|
|
22913
|
-
|
|
22914
|
-
|
|
22915
|
-
|
|
22916
|
-
|
|
22917
|
-
|
|
22918
|
-
|
|
22919
|
-
|
|
22920
|
-
|
|
22921
|
-
|
|
22922
|
-
|
|
22923
|
-
|
|
22924
|
-
|
|
22925
|
-
|
|
22926
|
-
|
|
22927
|
-
|
|
22928
|
-
|
|
22929
|
-
|
|
22930
|
-
|
|
22931
|
-
|
|
22932
|
-
|
|
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;
|
|
22933
22992
|
}
|
|
22934
|
-
if (
|
|
22935
|
-
|
|
22936
|
-
let firstIdentifier = gatherNodes(statement[1], (node) => node.type == "Identifier")[0];
|
|
22937
|
-
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)
|
|
22938
|
-
statement[1].children.unshift(["let "]);
|
|
22939
|
-
else {
|
|
22940
|
-
let tail = "\n";
|
|
22941
|
-
if (gatherNodes(indent, (node) => node.token && node.token.endsWith("\n")).length > 0)
|
|
22942
|
-
tail = void 0;
|
|
22943
|
-
targetStatements.push([indent, "let ", undeclaredIdentifiers.join(", "), tail]);
|
|
22944
|
-
}
|
|
22993
|
+
if (b) {
|
|
22994
|
+
module2.config.objectIs = false;
|
|
22945
22995
|
}
|
|
22946
|
-
targetStatements.push(statement);
|
|
22947
|
-
}
|
|
22948
|
-
scopes.pop();
|
|
22949
|
-
statements.splice(0, statements.length, targetStatements);
|
|
22950
|
-
}
|
|
22951
|
-
module2.constructInvocation = function(fn, arg) {
|
|
22952
|
-
const fnArr = [fn.leadingComment, fn.expr, fn.trailingComment];
|
|
22953
|
-
let expr = fn.expr;
|
|
22954
|
-
while (expr.type === "ParenthesizedExpression") {
|
|
22955
|
-
expr = expr.expression;
|
|
22956
|
-
}
|
|
22957
|
-
if (expr.ampersandBlock) {
|
|
22958
|
-
const { ref, body } = expr;
|
|
22959
|
-
ref.type = "PipedExpression";
|
|
22960
|
-
ref.children = [module2.makeLeftHandSideExpression(arg)];
|
|
22961
|
-
return {
|
|
22962
|
-
type: "UnwrappedExpression",
|
|
22963
|
-
children: [module2.skipIfOnlyWS(fn.leadingComment), ...body, module2.skipIfOnlyWS(fn.trailingComment)]
|
|
22964
|
-
};
|
|
22965
|
-
}
|
|
22966
|
-
expr = fn.expr;
|
|
22967
|
-
const lhs = module2.makeLeftHandSideExpression(expr);
|
|
22968
|
-
let comment = module2.skipIfOnlyWS(fn.trailingComment);
|
|
22969
|
-
if (comment)
|
|
22970
|
-
lhs.children.splice(2, 0, comment);
|
|
22971
|
-
comment = module2.skipIfOnlyWS(fn.leadingComment);
|
|
22972
|
-
if (comment)
|
|
22973
|
-
lhs.children.splice(1, 0, comment);
|
|
22974
|
-
switch (arg.type) {
|
|
22975
|
-
case "CommaExpression":
|
|
22976
|
-
arg = module2.makeLeftHandSideExpression(arg);
|
|
22977
|
-
break;
|
|
22978
22996
|
}
|
|
22979
|
-
|
|
22980
|
-
|
|
22981
|
-
|
|
22982
|
-
|
|
22983
|
-
|
|
22984
|
-
|
|
22985
|
-
|
|
22986
|
-
|
|
22987
|
-
|
|
22988
|
-
|
|
22989
|
-
if (returning) {
|
|
22990
|
-
return [
|
|
22991
|
-
children,
|
|
22992
|
-
returning
|
|
22993
|
-
];
|
|
22994
|
-
}
|
|
22995
|
-
return [
|
|
22996
|
-
children,
|
|
22997
|
-
null
|
|
22998
|
-
];
|
|
22999
|
-
case "return":
|
|
23000
|
-
return [{
|
|
23001
|
-
type: "ReturnStatement",
|
|
23002
|
-
children
|
|
23003
|
-
}, 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;
|
|
23004
23007
|
}
|
|
23005
|
-
|
|
23006
|
-
|
|
23007
|
-
|
|
23008
|
-
|
|
23009
|
-
|
|
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);
|
|
23010
23026
|
}
|
|
23011
|
-
|
|
23012
|
-
};
|
|
23027
|
+
});
|
|
23013
23028
|
return $0;
|
|
23014
23029
|
});
|
|
23015
23030
|
function Init(state) {
|
|
@@ -23314,44 +23329,40 @@ ${input.slice(result.pos)}
|
|
|
23314
23329
|
exports.parse = parse2;
|
|
23315
23330
|
exports.default = { parse: parse2 };
|
|
23316
23331
|
var {
|
|
23317
|
-
|
|
23318
|
-
|
|
23332
|
+
addPostfixStatement,
|
|
23333
|
+
adjustBindingElements,
|
|
23334
|
+
attachPostfixStatementAsExpression,
|
|
23319
23335
|
blockWithPrefix,
|
|
23320
|
-
clone,
|
|
23321
|
-
convertMethodToFunction,
|
|
23322
23336
|
convertObjectToJSXAttributes,
|
|
23323
23337
|
deepCopy,
|
|
23324
|
-
|
|
23338
|
+
dedentBlockString,
|
|
23339
|
+
dedentBlockSubstitutions,
|
|
23340
|
+
expressionizeIfClause,
|
|
23325
23341
|
forRange,
|
|
23326
23342
|
gatherBindingCode,
|
|
23327
|
-
gatherNodes,
|
|
23328
|
-
gatherRecursive,
|
|
23329
|
-
gatherRecursiveAll,
|
|
23330
|
-
gatherRecursiveWithinFunction,
|
|
23331
|
-
getIndent,
|
|
23332
23343
|
getTrimmingSpace,
|
|
23333
23344
|
hasAwait,
|
|
23334
23345
|
hasYield,
|
|
23335
|
-
hoistRefDecs,
|
|
23336
23346
|
insertTrimmingSpace,
|
|
23337
|
-
|
|
23347
|
+
isEmptyBareBlock,
|
|
23348
|
+
isWhitespaceOrEmpty,
|
|
23338
23349
|
lastAccessInCallExpression,
|
|
23339
23350
|
literalValue,
|
|
23351
|
+
makeLeftHandSideExpression,
|
|
23340
23352
|
modifyString,
|
|
23353
|
+
processBinaryOpExpression,
|
|
23354
|
+
processCallMemberExpression,
|
|
23341
23355
|
processCoffeeInterpolation,
|
|
23342
23356
|
processConstAssignmentDeclaration,
|
|
23343
23357
|
processLetAssignmentDeclaration,
|
|
23358
|
+
processProgram,
|
|
23344
23359
|
processUnaryExpression,
|
|
23345
23360
|
quoteString,
|
|
23346
|
-
|
|
23361
|
+
reorderBindingRestProperty,
|
|
23362
|
+
replaceNodes,
|
|
23363
|
+
typeOfJSX,
|
|
23364
|
+
wrapIIFE
|
|
23347
23365
|
} = require_lib();
|
|
23348
|
-
var assert = {
|
|
23349
|
-
equal(a, b, msg) {
|
|
23350
|
-
if (a !== b) {
|
|
23351
|
-
throw new Error(`Assertion failed [${msg}]: ${a} !== ${b}`);
|
|
23352
|
-
}
|
|
23353
|
-
}
|
|
23354
|
-
};
|
|
23355
23366
|
}
|
|
23356
23367
|
});
|
|
23357
23368
|
|