@danielx/civet 0.9.2 → 0.9.3
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/CHANGELOG.md +7 -0
- package/dist/browser.js +329 -144
- package/dist/main.js +331 -86
- package/dist/main.mjs +331 -86
- package/dist/unplugin/unplugin.js +3 -13
- package/dist/unplugin/unplugin.mjs +3 -13
- package/package.json +2 -2
package/dist/main.mjs
CHANGED
|
@@ -494,6 +494,7 @@ __export(lib_civet_exports, {
|
|
|
494
494
|
append: () => append,
|
|
495
495
|
attachPostfixStatementAsExpression: () => attachPostfixStatementAsExpression,
|
|
496
496
|
blockWithPrefix: () => blockWithPrefix,
|
|
497
|
+
braceBlock: () => braceBlock,
|
|
497
498
|
convertNamedImportsToObject: () => convertNamedImportsToObject,
|
|
498
499
|
convertObjectToJSXAttributes: () => convertObjectToJSXAttributes,
|
|
499
500
|
convertWithClause: () => convertWithClause,
|
|
@@ -974,6 +975,57 @@ function literalValue(literal) {
|
|
|
974
975
|
}
|
|
975
976
|
}
|
|
976
977
|
}
|
|
978
|
+
function literalType(literal) {
|
|
979
|
+
let t;
|
|
980
|
+
switch (literal.type) {
|
|
981
|
+
case "RegularExpressionLiteral": {
|
|
982
|
+
t = "RegExp";
|
|
983
|
+
break;
|
|
984
|
+
}
|
|
985
|
+
case "TemplateLiteral": {
|
|
986
|
+
t = "string";
|
|
987
|
+
break;
|
|
988
|
+
}
|
|
989
|
+
case "Literal": {
|
|
990
|
+
switch (literal.subtype) {
|
|
991
|
+
case "NullLiteral": {
|
|
992
|
+
t = "null";
|
|
993
|
+
break;
|
|
994
|
+
}
|
|
995
|
+
case "BooleanLiteral": {
|
|
996
|
+
t = "boolean";
|
|
997
|
+
break;
|
|
998
|
+
}
|
|
999
|
+
case "NumericLiteral": {
|
|
1000
|
+
if (literal.raw.endsWith("n")) {
|
|
1001
|
+
t = "bigint";
|
|
1002
|
+
} else {
|
|
1003
|
+
t = "number";
|
|
1004
|
+
}
|
|
1005
|
+
;
|
|
1006
|
+
break;
|
|
1007
|
+
}
|
|
1008
|
+
case "StringLiteral": {
|
|
1009
|
+
t = "string";
|
|
1010
|
+
break;
|
|
1011
|
+
}
|
|
1012
|
+
default: {
|
|
1013
|
+
throw new Error(`unknown literal subtype ${literal.subtype}`);
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
;
|
|
1017
|
+
break;
|
|
1018
|
+
}
|
|
1019
|
+
default: {
|
|
1020
|
+
throw new Error(`unknown literal type ${literal.type}`);
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
return {
|
|
1024
|
+
type: "TypeLiteral",
|
|
1025
|
+
t,
|
|
1026
|
+
children: [t]
|
|
1027
|
+
};
|
|
1028
|
+
}
|
|
977
1029
|
function makeNumericLiteral(n) {
|
|
978
1030
|
const s = n.toString();
|
|
979
1031
|
return {
|
|
@@ -1286,7 +1338,7 @@ function skipIfOnlyWS(target) {
|
|
|
1286
1338
|
return target;
|
|
1287
1339
|
}
|
|
1288
1340
|
function spliceChild(node, child, del, ...replacements) {
|
|
1289
|
-
const children = node
|
|
1341
|
+
const children = Array.isArray(node) ? node : node.children;
|
|
1290
1342
|
if (!Array.isArray(children)) {
|
|
1291
1343
|
throw new Error("spliceChild: non-array node has no children field");
|
|
1292
1344
|
}
|
|
@@ -1721,14 +1773,41 @@ function gatherBindingCode(statements, opts) {
|
|
|
1721
1773
|
const thisAssignments = [];
|
|
1722
1774
|
const splices = [];
|
|
1723
1775
|
function insertRestSplices(s, p, thisAssignments2) {
|
|
1724
|
-
|
|
1725
|
-
|
|
1776
|
+
let m;
|
|
1777
|
+
for (let ref2 = gatherRecursiveAll(
|
|
1778
|
+
s,
|
|
1779
|
+
(n) => n.blockPrefix || opts?.injectParamProps && n.accessModifier || n.type === "AtBinding" || opts?.assignPins && (m = n.type, m === "PinPattern" || m === "PinProperty")
|
|
1780
|
+
), i3 = 0, len22 = ref2.length; i3 < len22; i3++) {
|
|
1781
|
+
let n = ref2[i3];
|
|
1726
1782
|
if (n.type === "AtBinding") {
|
|
1727
1783
|
const { ref } = n;
|
|
1728
1784
|
const { id } = ref;
|
|
1729
1785
|
thisAssignments2.push([`this.${id} = `, ref]);
|
|
1730
1786
|
continue;
|
|
1731
1787
|
}
|
|
1788
|
+
if (opts?.assignPins) {
|
|
1789
|
+
if (n.type === "PinProperty") {
|
|
1790
|
+
n.children = n.children.flatMap(($2) => $2 === n.name ? [n.name, ": ", n.value] : $2);
|
|
1791
|
+
updateParentPointers(n);
|
|
1792
|
+
n = n.value;
|
|
1793
|
+
}
|
|
1794
|
+
if (n.type === "PinPattern") {
|
|
1795
|
+
n.ref = makeRef(
|
|
1796
|
+
n.expression.type === "Identifier" ? n.expression.name : "pin"
|
|
1797
|
+
);
|
|
1798
|
+
n.children = [n.ref];
|
|
1799
|
+
updateParentPointers(n);
|
|
1800
|
+
thisAssignments2.push({
|
|
1801
|
+
type: "AssignmentExpression",
|
|
1802
|
+
children: [n.expression, " = ", n.ref],
|
|
1803
|
+
names: [],
|
|
1804
|
+
lhs: n.expression,
|
|
1805
|
+
assigned: n.expression,
|
|
1806
|
+
expression: n.ref
|
|
1807
|
+
});
|
|
1808
|
+
continue;
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1732
1811
|
if (opts?.injectParamProps && n.type === "Parameter" && n.accessModifier) {
|
|
1733
1812
|
for (let ref3 = n.names, i4 = 0, len3 = ref3.length; i4 < len3; i4++) {
|
|
1734
1813
|
const id = ref3[i4];
|
|
@@ -3564,20 +3643,21 @@ function processParams(f) {
|
|
|
3564
3643
|
indent = expressions[0][0];
|
|
3565
3644
|
}
|
|
3566
3645
|
const [splices, thisAssignments] = gatherBindingCode(parameters, {
|
|
3567
|
-
injectParamProps: isConstructor
|
|
3646
|
+
injectParamProps: isConstructor,
|
|
3647
|
+
assignPins: true
|
|
3568
3648
|
});
|
|
3569
3649
|
if (isConstructor) {
|
|
3570
3650
|
const { ancestor } = findAncestor(f, ($9) => $9.type === "ClassExpression");
|
|
3571
3651
|
if (ancestor != null) {
|
|
3572
3652
|
const fields = new Set(gatherRecursiveWithinFunction(ancestor, ($10) => $10.type === "FieldDefinition").map(($11) => $11.id).filter((a3) => typeof a3 === "object" && a3 != null && "type" in a3 && a3.type === "Identifier").map(($12) => $12.name));
|
|
3573
3653
|
const classExpressions = ancestor.body.expressions;
|
|
3574
|
-
let
|
|
3575
|
-
assert.notEqual(
|
|
3654
|
+
let index2 = findChildIndex(classExpressions, f);
|
|
3655
|
+
assert.notEqual(index2, -1, "Could not find constructor in class");
|
|
3576
3656
|
let m4;
|
|
3577
|
-
while (m4 = classExpressions[
|
|
3578
|
-
|
|
3657
|
+
while (m4 = classExpressions[index2 - 1]?.[1], typeof m4 === "object" && m4 != null && "type" in m4 && m4.type === "MethodDefinition" && "name" in m4 && m4.name === "constructor") {
|
|
3658
|
+
index2--;
|
|
3579
3659
|
}
|
|
3580
|
-
const fStatement = classExpressions[
|
|
3660
|
+
const fStatement = classExpressions[index2];
|
|
3581
3661
|
for (let ref18 = gatherRecursive(parameters, ($13) => $13.type === "Parameter"), i9 = 0, len8 = ref18.length; i9 < len8; i9++) {
|
|
3582
3662
|
const parameter = ref18[i9];
|
|
3583
3663
|
const { accessModifier } = parameter;
|
|
@@ -3598,7 +3678,7 @@ function processParams(f) {
|
|
|
3598
3678
|
if (fields.has(id)) {
|
|
3599
3679
|
continue;
|
|
3600
3680
|
}
|
|
3601
|
-
classExpressions.splice(
|
|
3681
|
+
classExpressions.splice(index2++, 0, [fStatement[0], {
|
|
3602
3682
|
type: "FieldDefinition",
|
|
3603
3683
|
id,
|
|
3604
3684
|
typeSuffix,
|
|
@@ -3635,25 +3715,31 @@ function processParams(f) {
|
|
|
3635
3715
|
if (!prefix.length) {
|
|
3636
3716
|
return;
|
|
3637
3717
|
}
|
|
3718
|
+
let index = -1;
|
|
3638
3719
|
if (isConstructor) {
|
|
3639
|
-
|
|
3640
|
-
expressions,
|
|
3641
|
-
(a4) => typeof a4 === "object" && a4 != null && "type" in a4 && a4.type === "CallExpression" && "children" in a4 && Array.isArray(a4.children) && a4.children.length >= 1 && typeof a4.children[0] === "object" && a4.children[0] != null && "token" in a4.children[0] && a4.children[0].token === "super"
|
|
3642
|
-
);
|
|
3643
|
-
if (superCalls.length) {
|
|
3644
|
-
const { child } = findAncestor(superCalls[0], (a5) => a5 === block);
|
|
3645
|
-
const index = findChildIndex(expressions, child);
|
|
3646
|
-
if (index < 0) {
|
|
3647
|
-
throw new Error("Could not find super call within top-level expressions");
|
|
3648
|
-
}
|
|
3649
|
-
expressions.splice(index + 1, 0, ...prefix);
|
|
3650
|
-
return;
|
|
3651
|
-
}
|
|
3720
|
+
index = findSuperCall(block);
|
|
3652
3721
|
}
|
|
3653
|
-
expressions.
|
|
3722
|
+
expressions.splice(index + 1, 0, ...prefix);
|
|
3654
3723
|
updateParentPointers(block);
|
|
3655
3724
|
braceBlock(block);
|
|
3656
3725
|
}
|
|
3726
|
+
function findSuperCall(block) {
|
|
3727
|
+
const { expressions } = block;
|
|
3728
|
+
const superCalls = gatherNodes(
|
|
3729
|
+
expressions,
|
|
3730
|
+
(a4) => typeof a4 === "object" && a4 != null && "type" in a4 && a4.type === "CallExpression" && "children" in a4 && Array.isArray(a4.children) && a4.children.length >= 1 && typeof a4.children[0] === "object" && a4.children[0] != null && "token" in a4.children[0] && a4.children[0].token === "super"
|
|
3731
|
+
);
|
|
3732
|
+
if (superCalls.length) {
|
|
3733
|
+
const { child } = findAncestor(superCalls[0], (a5) => a5 === block);
|
|
3734
|
+
const index = findChildIndex(expressions, child);
|
|
3735
|
+
if (index < 0) {
|
|
3736
|
+
throw new Error("Could not find super call within top-level expressions");
|
|
3737
|
+
}
|
|
3738
|
+
return index;
|
|
3739
|
+
} else {
|
|
3740
|
+
return -1;
|
|
3741
|
+
}
|
|
3742
|
+
}
|
|
3657
3743
|
function processSignature(f) {
|
|
3658
3744
|
const { block, signature } = f;
|
|
3659
3745
|
if (!f.async?.length && hasAwait(block)) {
|
|
@@ -4946,18 +5032,47 @@ function processDeclarations(statements) {
|
|
|
4946
5032
|
for (let ref1 = gatherRecursiveAll(statements, ($) => $.type === "Declaration"), i1 = 0, len1 = ref1.length; i1 < len1; i1++) {
|
|
4947
5033
|
const declaration = ref1[i1];
|
|
4948
5034
|
const { bindings } = declaration;
|
|
4949
|
-
|
|
4950
|
-
|
|
4951
|
-
|
|
4952
|
-
|
|
5035
|
+
if (!(bindings != null)) {
|
|
5036
|
+
continue;
|
|
5037
|
+
}
|
|
5038
|
+
for (let i2 = 0, len22 = bindings.length; i2 < len22; i2++) {
|
|
5039
|
+
const binding = bindings[i2];
|
|
5040
|
+
let { typeSuffix, initializer } = binding;
|
|
5041
|
+
if (typeSuffix && typeSuffix.optional) {
|
|
5042
|
+
if (initializer && !typeSuffix.t) {
|
|
5043
|
+
const expression = trimFirstSpace(initializer.expression);
|
|
5044
|
+
let m;
|
|
5045
|
+
if (m = expression.type, m === "Identifier" || m === "MemberExpression") {
|
|
5046
|
+
typeSuffix.children.push(": ", typeSuffix.t = {
|
|
5047
|
+
type: "TypeTypeof",
|
|
5048
|
+
children: ["typeof ", expression],
|
|
5049
|
+
expression
|
|
5050
|
+
});
|
|
5051
|
+
} else if (expression.type === "Literal" || expression.type === "RegularExpressionLiteral" || expression.type === "TemplateLiteral") {
|
|
5052
|
+
typeSuffix.children.push(": ", typeSuffix.t = literalType(expression));
|
|
5053
|
+
} else {
|
|
5054
|
+
spliceChild(binding, typeSuffix, 1, {
|
|
5055
|
+
type: "Error",
|
|
5056
|
+
message: `Optional type can only be inferred from literals or member expressions, not ${expression.type}`
|
|
5057
|
+
});
|
|
5058
|
+
continue;
|
|
5059
|
+
}
|
|
5060
|
+
}
|
|
5061
|
+
if (typeSuffix.t) {
|
|
5062
|
+
convertOptionalType(typeSuffix);
|
|
5063
|
+
} else {
|
|
5064
|
+
spliceChild(binding, typeSuffix, 1);
|
|
5065
|
+
binding.children.push(initializer = binding.initializer = {
|
|
5066
|
+
type: "Initializer",
|
|
5067
|
+
expression: "undefined",
|
|
5068
|
+
children: [" = ", "undefined"]
|
|
5069
|
+
});
|
|
5070
|
+
}
|
|
4953
5071
|
}
|
|
4954
|
-
const { initializer } = binding;
|
|
4955
5072
|
if (initializer) {
|
|
4956
|
-
|
|
5073
|
+
prependStatementExpressionBlock(initializer, declaration);
|
|
4957
5074
|
}
|
|
4958
|
-
|
|
4959
|
-
return;
|
|
4960
|
-
});
|
|
5075
|
+
}
|
|
4961
5076
|
}
|
|
4962
5077
|
}
|
|
4963
5078
|
function prependStatementExpressionBlock(initializer, statement) {
|
|
@@ -5120,16 +5235,16 @@ function processDeclarationConditionStatement(s) {
|
|
|
5120
5235
|
if (conditions.length) {
|
|
5121
5236
|
let children = condition.children;
|
|
5122
5237
|
if (s.negated) {
|
|
5123
|
-
let
|
|
5124
|
-
if (!(
|
|
5238
|
+
let m1;
|
|
5239
|
+
if (!(m1 = condition.expression, typeof m1 === "object" && m1 != null && "type" in m1 && m1.type === "UnaryExpression" && "children" in m1 && Array.isArray(m1.children) && len2(m1.children, 2) && Array.isArray(m1.children[0]) && len2(m1.children[0], 1) && m1.children[0][0] === "!" && typeof m1.children[1] === "object" && m1.children[1] != null && "type" in m1.children[1] && m1.children[1].type === "ParenthesizedExpression")) {
|
|
5125
5240
|
throw new Error("Unsupported negated condition");
|
|
5126
5241
|
}
|
|
5127
5242
|
;
|
|
5128
5243
|
({ children } = condition.expression.children[1]);
|
|
5129
5244
|
}
|
|
5130
5245
|
children.unshift("(");
|
|
5131
|
-
for (let
|
|
5132
|
-
const c = conditions[
|
|
5246
|
+
for (let i3 = 0, len3 = conditions.length; i3 < len3; i3++) {
|
|
5247
|
+
const c = conditions[i3];
|
|
5133
5248
|
children.push(" && ", c);
|
|
5134
5249
|
}
|
|
5135
5250
|
children.push(")");
|
|
@@ -5250,7 +5365,8 @@ function dynamizeFromClause(from) {
|
|
|
5250
5365
|
if (ref3 = from[from.length - 1]?.assertion) {
|
|
5251
5366
|
const assert2 = ref3;
|
|
5252
5367
|
let ref4;
|
|
5253
|
-
ref4 = from[from.length - 1]
|
|
5368
|
+
ref4 = from[from.length - 1];
|
|
5369
|
+
ref4.children = ref4.children.filter((a2) => a2 !== assert2);
|
|
5254
5370
|
from.push(", {", assert2.keyword, ":", assert2.object, "}");
|
|
5255
5371
|
}
|
|
5256
5372
|
return ["(", ...from, ")"];
|
|
@@ -6284,12 +6400,10 @@ function createVarDecs(block, scopes, pushVar) {
|
|
|
6284
6400
|
}
|
|
6285
6401
|
return assignmentStatements2;
|
|
6286
6402
|
}
|
|
6287
|
-
|
|
6288
|
-
|
|
6289
|
-
|
|
6290
|
-
|
|
6291
|
-
};
|
|
6292
|
-
}
|
|
6403
|
+
pushVar ??= (name) => {
|
|
6404
|
+
varIds.push(name);
|
|
6405
|
+
return decs.add(name);
|
|
6406
|
+
};
|
|
6293
6407
|
const { expressions: statements } = block;
|
|
6294
6408
|
const decs = findDecs(statements);
|
|
6295
6409
|
scopes.push(decs);
|
|
@@ -7889,6 +8003,91 @@ function processBreaksContinues(statements) {
|
|
|
7889
8003
|
delete label.special;
|
|
7890
8004
|
}
|
|
7891
8005
|
}
|
|
8006
|
+
function processCoffeeClasses(statements) {
|
|
8007
|
+
for (let ref21 = gatherRecursiveAll(statements, ($13) => $13.type === "ClassExpression"), i11 = 0, len9 = ref21.length; i11 < len9; i11++) {
|
|
8008
|
+
const ce = ref21[i11];
|
|
8009
|
+
const { expressions } = ce.body;
|
|
8010
|
+
const indent = expressions[0]?.[0] ?? "\n";
|
|
8011
|
+
const autoBinds = expressions.filter(($14) => $14[1]?.autoBind);
|
|
8012
|
+
if (autoBinds.length) {
|
|
8013
|
+
let construct;
|
|
8014
|
+
for (const [, c] of expressions) {
|
|
8015
|
+
if (typeof c === "object" && c != null && "type" in c && c.type === "MethodDefinition" && "name" in c && c.name === "constructor" && c.block) {
|
|
8016
|
+
construct = c;
|
|
8017
|
+
break;
|
|
8018
|
+
}
|
|
8019
|
+
}
|
|
8020
|
+
if (!construct) {
|
|
8021
|
+
const parametersList = [];
|
|
8022
|
+
const parameters = {
|
|
8023
|
+
type: "Parameters",
|
|
8024
|
+
children: [parametersList],
|
|
8025
|
+
parameters: parametersList,
|
|
8026
|
+
names: []
|
|
8027
|
+
};
|
|
8028
|
+
const signature = {
|
|
8029
|
+
type: "MethodSignature",
|
|
8030
|
+
children: ["constructor(", parameters, ")"],
|
|
8031
|
+
parameters,
|
|
8032
|
+
modifier: {},
|
|
8033
|
+
returnType: void 0
|
|
8034
|
+
};
|
|
8035
|
+
const block = makeEmptyBlock();
|
|
8036
|
+
construct = {
|
|
8037
|
+
...signature,
|
|
8038
|
+
type: "MethodDefinition",
|
|
8039
|
+
name: "constructor",
|
|
8040
|
+
block,
|
|
8041
|
+
signature,
|
|
8042
|
+
children: [...signature.children, block]
|
|
8043
|
+
};
|
|
8044
|
+
expressions.unshift([indent, construct]);
|
|
8045
|
+
}
|
|
8046
|
+
const index = findSuperCall(construct.block);
|
|
8047
|
+
construct.block.expressions.splice(
|
|
8048
|
+
index + 1,
|
|
8049
|
+
0,
|
|
8050
|
+
...(() => {
|
|
8051
|
+
const results3 = [];
|
|
8052
|
+
for (let i12 = 0, len10 = autoBinds.length; i12 < len10; i12++) {
|
|
8053
|
+
const [, a] = autoBinds[i12];
|
|
8054
|
+
results3.push([indent, ["this.", a.name, " = this.", a.name, ".bind(this)"], ";"]);
|
|
8055
|
+
}
|
|
8056
|
+
return results3;
|
|
8057
|
+
})()
|
|
8058
|
+
);
|
|
8059
|
+
}
|
|
8060
|
+
const privates = expressions.filter(($15) => $15[1]?.type === "CoffeeClassPrivate");
|
|
8061
|
+
if (!privates.length) {
|
|
8062
|
+
continue;
|
|
8063
|
+
}
|
|
8064
|
+
const { parent } = ce;
|
|
8065
|
+
for (let i13 = expressions.length + -1; i13 >= 0; --i13) {
|
|
8066
|
+
const i = i13;
|
|
8067
|
+
if (expressions[i][1]?.type === "CoffeeClassPrivate") {
|
|
8068
|
+
expressions.splice(i, 1);
|
|
8069
|
+
}
|
|
8070
|
+
}
|
|
8071
|
+
let wrapped = wrapIIFE([
|
|
8072
|
+
...privates,
|
|
8073
|
+
[indent, wrapWithReturn(ce)]
|
|
8074
|
+
]);
|
|
8075
|
+
if (ce && typeof ce === "object" && "binding" in ce) {
|
|
8076
|
+
let { binding } = ce;
|
|
8077
|
+
binding = trimFirstSpace(binding);
|
|
8078
|
+
wrapped = makeNode({
|
|
8079
|
+
type: "AssignmentExpression",
|
|
8080
|
+
children: [binding, " = ", wrapped],
|
|
8081
|
+
lhs: binding,
|
|
8082
|
+
// TODO: incorrect shape
|
|
8083
|
+
assigned: binding,
|
|
8084
|
+
expression: wrapped,
|
|
8085
|
+
names: [ce.name]
|
|
8086
|
+
});
|
|
8087
|
+
}
|
|
8088
|
+
replaceNode(ce, wrapped, parent);
|
|
8089
|
+
}
|
|
8090
|
+
}
|
|
7892
8091
|
function processProgram(root) {
|
|
7893
8092
|
const state2 = getState();
|
|
7894
8093
|
const config2 = getConfig();
|
|
@@ -7903,7 +8102,7 @@ function processProgram(root) {
|
|
|
7903
8102
|
if (config2.iife || config2.repl) {
|
|
7904
8103
|
rootIIFE = wrapIIFE(root.expressions, root.topLevelAwait);
|
|
7905
8104
|
const newExpressions = [["", rootIIFE]];
|
|
7906
|
-
root.children = root.children.map(($
|
|
8105
|
+
root.children = root.children.map(($16) => $16 === root.expressions ? newExpressions : $16);
|
|
7907
8106
|
root.expressions = newExpressions;
|
|
7908
8107
|
}
|
|
7909
8108
|
addParentPointers(root);
|
|
@@ -7922,6 +8121,9 @@ function processProgram(root) {
|
|
|
7922
8121
|
processBreaksContinues(statements);
|
|
7923
8122
|
hoistRefDecs(statements);
|
|
7924
8123
|
processFunctions(statements, config2);
|
|
8124
|
+
if (config2.coffeeClasses) {
|
|
8125
|
+
processCoffeeClasses(statements);
|
|
8126
|
+
}
|
|
7925
8127
|
statements.unshift(...state2.prelude);
|
|
7926
8128
|
if (config2.autoLet) {
|
|
7927
8129
|
createConstLetDecs(statements, [], "let");
|
|
@@ -7945,10 +8147,10 @@ async function processProgramAsync(root) {
|
|
|
7945
8147
|
await processComptime(statements);
|
|
7946
8148
|
}
|
|
7947
8149
|
function processRepl(root, rootIIFE) {
|
|
7948
|
-
const topBlock = gatherRecursive(rootIIFE, ($
|
|
8150
|
+
const topBlock = gatherRecursive(rootIIFE, ($17) => $17.type === "BlockStatement")[0];
|
|
7949
8151
|
let i = 0;
|
|
7950
|
-
for (let
|
|
7951
|
-
const decl =
|
|
8152
|
+
for (let ref22 = gatherRecursiveWithinFunction(topBlock, ($18) => $18.type === "Declaration"), i14 = 0, len11 = ref22.length; i14 < len11; i14++) {
|
|
8153
|
+
const decl = ref22[i14];
|
|
7952
8154
|
if (!decl.names?.length) {
|
|
7953
8155
|
continue;
|
|
7954
8156
|
}
|
|
@@ -7961,8 +8163,8 @@ function processRepl(root, rootIIFE) {
|
|
|
7961
8163
|
root.expressions.splice(i++, 0, ["", `var ${decl.names.join(",")}`, ";"]);
|
|
7962
8164
|
}
|
|
7963
8165
|
}
|
|
7964
|
-
for (let
|
|
7965
|
-
const func =
|
|
8166
|
+
for (let ref23 = gatherRecursive(topBlock, ($19) => $19.type === "FunctionExpression"), i15 = 0, len12 = ref23.length; i15 < len12; i15++) {
|
|
8167
|
+
const func = ref23[i15];
|
|
7966
8168
|
if (func.name && func.parent?.type === "BlockStatement") {
|
|
7967
8169
|
if (func.parent === topBlock) {
|
|
7968
8170
|
replaceNode(func, void 0);
|
|
@@ -7974,8 +8176,8 @@ function processRepl(root, rootIIFE) {
|
|
|
7974
8176
|
}
|
|
7975
8177
|
}
|
|
7976
8178
|
}
|
|
7977
|
-
for (let
|
|
7978
|
-
const classExp =
|
|
8179
|
+
for (let ref24 = gatherRecursiveWithinFunction(topBlock, ($20) => $20.type === "ClassExpression"), i16 = 0, len13 = ref24.length; i16 < len13; i16++) {
|
|
8180
|
+
const classExp = ref24[i16];
|
|
7979
8181
|
let m8;
|
|
7980
8182
|
if (classExp.name && classExp.parent === topBlock || (m8 = classExp.parent, typeof m8 === "object" && m8 != null && "type" in m8 && m8.type === "ReturnStatement" && "parent" in m8 && m8.parent === topBlock)) {
|
|
7981
8183
|
classExp.children.unshift(classExp.name, "=");
|
|
@@ -7984,7 +8186,7 @@ function processRepl(root, rootIIFE) {
|
|
|
7984
8186
|
}
|
|
7985
8187
|
}
|
|
7986
8188
|
function populateRefs(statements) {
|
|
7987
|
-
const refNodes = gatherRecursive(statements, ($
|
|
8189
|
+
const refNodes = gatherRecursive(statements, ($21) => $21.type === "Ref");
|
|
7988
8190
|
if (refNodes.length) {
|
|
7989
8191
|
const ids = gatherRecursive(statements, (s) => s.type === "Identifier");
|
|
7990
8192
|
const names = new Set(ids.flatMap(({ names: names2 }) => names2 || []));
|
|
@@ -8006,8 +8208,8 @@ function populateRefs(statements) {
|
|
|
8006
8208
|
function processPlaceholders(statements) {
|
|
8007
8209
|
const placeholderMap = /* @__PURE__ */ new Map();
|
|
8008
8210
|
const liftedIfs = /* @__PURE__ */ new Set();
|
|
8009
|
-
for (let
|
|
8010
|
-
const exp =
|
|
8211
|
+
for (let ref25 = gatherRecursiveAll(statements, ($22) => $22.type === "Placeholder"), i17 = 0, len14 = ref25.length; i17 < len14; i17++) {
|
|
8212
|
+
const exp = ref25[i17];
|
|
8011
8213
|
let ancestor;
|
|
8012
8214
|
if (exp.subtype === ".") {
|
|
8013
8215
|
({ ancestor } = findAncestor(
|
|
@@ -8116,11 +8318,11 @@ function processPlaceholders(statements) {
|
|
|
8116
8318
|
for (const [ancestor, placeholders] of placeholderMap) {
|
|
8117
8319
|
let ref = makeRef("$");
|
|
8118
8320
|
let typeSuffix;
|
|
8119
|
-
for (let
|
|
8120
|
-
const placeholder = placeholders[
|
|
8321
|
+
for (let i18 = 0, len15 = placeholders.length; i18 < len15; i18++) {
|
|
8322
|
+
const placeholder = placeholders[i18];
|
|
8121
8323
|
typeSuffix ??= placeholder.typeSuffix;
|
|
8122
|
-
let
|
|
8123
|
-
(
|
|
8324
|
+
let ref26;
|
|
8325
|
+
(ref26 = placeholder.children)[ref26.length - 1] = ref;
|
|
8124
8326
|
}
|
|
8125
8327
|
const { parent } = ancestor;
|
|
8126
8328
|
const body = maybeUnwrap(ancestor);
|
|
@@ -8141,16 +8343,16 @@ function processPlaceholders(statements) {
|
|
|
8141
8343
|
}
|
|
8142
8344
|
case "PipelineExpression": {
|
|
8143
8345
|
const i = findChildIndex(parent, ancestor);
|
|
8144
|
-
let
|
|
8346
|
+
let ref27;
|
|
8145
8347
|
if (i === 1) {
|
|
8146
|
-
|
|
8348
|
+
ref27 = ancestor === parent.children[i];
|
|
8147
8349
|
} else if (i === 2) {
|
|
8148
|
-
|
|
8350
|
+
ref27 = ancestor === parent.children[i][findChildIndex(parent.children[i], ancestor)][3];
|
|
8149
8351
|
} else {
|
|
8150
|
-
|
|
8352
|
+
ref27 = void 0;
|
|
8151
8353
|
}
|
|
8152
8354
|
;
|
|
8153
|
-
outer =
|
|
8355
|
+
outer = ref27;
|
|
8154
8356
|
break;
|
|
8155
8357
|
}
|
|
8156
8358
|
case "AssignmentExpression":
|
|
@@ -8165,9 +8367,9 @@ function processPlaceholders(statements) {
|
|
|
8165
8367
|
fnExp = makeLeftHandSideExpression(fnExp);
|
|
8166
8368
|
}
|
|
8167
8369
|
replaceNode(ancestor, fnExp, parent);
|
|
8168
|
-
let
|
|
8169
|
-
if (
|
|
8170
|
-
const ws =
|
|
8370
|
+
let ref28;
|
|
8371
|
+
if (ref28 = getTrimmingSpace(body)) {
|
|
8372
|
+
const ws = ref28;
|
|
8171
8373
|
inplaceInsertTrimmingSpace(body, "");
|
|
8172
8374
|
inplacePrepend(ws, fnExp);
|
|
8173
8375
|
}
|
|
@@ -8211,8 +8413,8 @@ function reorderBindingRestProperty(props) {
|
|
|
8211
8413
|
}
|
|
8212
8414
|
];
|
|
8213
8415
|
}
|
|
8214
|
-
let
|
|
8215
|
-
if (Array.isArray(rest.delim) && (
|
|
8416
|
+
let ref29;
|
|
8417
|
+
if (Array.isArray(rest.delim) && (ref29 = rest.delim)[ref29.length - 1]?.token === ",") {
|
|
8216
8418
|
rest.delim = rest.delim.slice(0, -1);
|
|
8217
8419
|
rest.children = [...rest.children.slice(0, -1), rest.delim];
|
|
8218
8420
|
}
|
|
@@ -10743,8 +10945,7 @@ var FieldDefinition$0 = (0, import_lib2.$TS)((0, import_lib2.$S)(CoffeeClassesEn
|
|
|
10743
10945
|
var id = $2;
|
|
10744
10946
|
var exp = $6;
|
|
10745
10947
|
switch (exp.type) {
|
|
10746
|
-
|
|
10747
|
-
case "FunctionExpression":
|
|
10948
|
+
case "FunctionExpression": {
|
|
10748
10949
|
const fnTokenIndex = exp.children.findIndex((c) => c?.token?.startsWith("function"));
|
|
10749
10950
|
const children = exp.children.slice();
|
|
10750
10951
|
if (exp.generator) {
|
|
@@ -10754,8 +10955,29 @@ var FieldDefinition$0 = (0, import_lib2.$TS)((0, import_lib2.$S)(CoffeeClassesEn
|
|
|
10754
10955
|
}
|
|
10755
10956
|
return {
|
|
10756
10957
|
...exp,
|
|
10958
|
+
type: "MethodDefinition",
|
|
10959
|
+
name: id.name,
|
|
10960
|
+
signature: { ...exp.signature, id, name: id.name },
|
|
10757
10961
|
children
|
|
10758
10962
|
};
|
|
10963
|
+
}
|
|
10964
|
+
case "ArrowFunction": {
|
|
10965
|
+
const block = { ...exp.block };
|
|
10966
|
+
const children = exp.children.filter((c) => !(Array.isArray(c) && c[c.length - 1]?.token?.includes("=>"))).map((c) => c === exp.block ? block : c);
|
|
10967
|
+
children.unshift(id);
|
|
10968
|
+
exp = {
|
|
10969
|
+
...exp,
|
|
10970
|
+
type: "MethodDefinition",
|
|
10971
|
+
name: id.name,
|
|
10972
|
+
signature: { ...exp.signature, id, name: id.name },
|
|
10973
|
+
block,
|
|
10974
|
+
children,
|
|
10975
|
+
autoBind: true
|
|
10976
|
+
};
|
|
10977
|
+
block.parent = exp;
|
|
10978
|
+
braceBlock(block);
|
|
10979
|
+
return exp;
|
|
10980
|
+
}
|
|
10759
10981
|
default:
|
|
10760
10982
|
return {
|
|
10761
10983
|
type: "FieldDefinition",
|
|
@@ -10765,11 +10987,11 @@ var FieldDefinition$0 = (0, import_lib2.$TS)((0, import_lib2.$S)(CoffeeClassesEn
|
|
|
10765
10987
|
}
|
|
10766
10988
|
});
|
|
10767
10989
|
var FieldDefinition$1 = (0, import_lib2.$TS)((0, import_lib2.$S)(InsertReadonly, ClassElementName, (0, import_lib2.$E)(TypeSuffix), __, ConstAssignment, MaybeNestedExpression), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
|
|
10768
|
-
var
|
|
10990
|
+
var readonly = $1;
|
|
10769
10991
|
var id = $2;
|
|
10770
10992
|
var typeSuffix = $3;
|
|
10771
10993
|
var ca = $5;
|
|
10772
|
-
|
|
10994
|
+
readonly.children[0].$loc = {
|
|
10773
10995
|
pos: ca.$loc.pos - 1,
|
|
10774
10996
|
length: ca.$loc.length + 1
|
|
10775
10997
|
};
|
|
@@ -10777,21 +10999,36 @@ var FieldDefinition$1 = (0, import_lib2.$TS)((0, import_lib2.$S)(InsertReadonly,
|
|
|
10777
10999
|
type: "FieldDefinition",
|
|
10778
11000
|
id,
|
|
10779
11001
|
typeSuffix,
|
|
10780
|
-
children: $0
|
|
11002
|
+
children: $0,
|
|
11003
|
+
readonly
|
|
11004
|
+
};
|
|
11005
|
+
});
|
|
11006
|
+
var FieldDefinition$2 = (0, import_lib2.$TS)((0, import_lib2.$S)(CoffeeClassesEnabled, ActualAssignment), function($skip, $loc, $0, $1, $2) {
|
|
11007
|
+
var assignment = $2;
|
|
11008
|
+
return {
|
|
11009
|
+
type: "CoffeeClassPrivate",
|
|
11010
|
+
children: [assignment],
|
|
11011
|
+
assignment
|
|
10781
11012
|
};
|
|
10782
11013
|
});
|
|
10783
|
-
var FieldDefinition$
|
|
11014
|
+
var FieldDefinition$3 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$E)((0, import_lib2.$S)(Abstract, (0, import_lib2.$E)(_))), (0, import_lib2.$E)((0, import_lib2.$S)(Readonly, (0, import_lib2.$E)(_))), ClassElementName, (0, import_lib2.$E)(TypeSuffix), (0, import_lib2.$E)(Initializer)), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
|
|
11015
|
+
var abstract = $1;
|
|
11016
|
+
var readonly = $2;
|
|
10784
11017
|
var id = $3;
|
|
10785
11018
|
var typeSuffix = $4;
|
|
11019
|
+
var initializer = $5;
|
|
10786
11020
|
return {
|
|
10787
11021
|
type: "FieldDefinition",
|
|
10788
11022
|
children: $0,
|
|
10789
|
-
ts:
|
|
11023
|
+
ts: abstract ? true : void 0,
|
|
10790
11024
|
id,
|
|
10791
|
-
typeSuffix
|
|
11025
|
+
typeSuffix,
|
|
11026
|
+
abstract,
|
|
11027
|
+
readonly,
|
|
11028
|
+
initializer
|
|
10792
11029
|
};
|
|
10793
11030
|
});
|
|
10794
|
-
var FieldDefinition$$ = [FieldDefinition$0, FieldDefinition$1, FieldDefinition$2];
|
|
11031
|
+
var FieldDefinition$$ = [FieldDefinition$0, FieldDefinition$1, FieldDefinition$2, FieldDefinition$3];
|
|
10795
11032
|
function FieldDefinition(ctx, state2) {
|
|
10796
11033
|
return (0, import_lib2.$EVENT_C)(ctx, state2, "FieldDefinition", FieldDefinition$$);
|
|
10797
11034
|
}
|
|
@@ -11598,7 +11835,7 @@ var PinPattern$0 = (0, import_lib2.$TS)((0, import_lib2.$S)(Caret, SingleLineExp
|
|
|
11598
11835
|
var expression = $2;
|
|
11599
11836
|
return {
|
|
11600
11837
|
type: "PinPattern",
|
|
11601
|
-
children:
|
|
11838
|
+
children: [expression],
|
|
11602
11839
|
expression
|
|
11603
11840
|
};
|
|
11604
11841
|
});
|
|
@@ -11813,6 +12050,7 @@ var BindingProperty$2 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2
|
|
|
11813
12050
|
name: binding,
|
|
11814
12051
|
value: {
|
|
11815
12052
|
type: "PinPattern",
|
|
12053
|
+
children: [binding],
|
|
11816
12054
|
expression: binding
|
|
11817
12055
|
}
|
|
11818
12056
|
};
|
|
@@ -12681,7 +12919,7 @@ function LiteralContent(ctx, state2) {
|
|
|
12681
12919
|
return (0, import_lib2.$EVENT_C)(ctx, state2, "LiteralContent", LiteralContent$$);
|
|
12682
12920
|
}
|
|
12683
12921
|
var NullLiteral$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$EXPECT)($L38, 'NullLiteral "null"'), NonIdContinue), function($skip, $loc, $0, $1, $2) {
|
|
12684
|
-
return { $loc, token: $1 };
|
|
12922
|
+
return { type: "NullLiteral", $loc, token: $1 };
|
|
12685
12923
|
});
|
|
12686
12924
|
function NullLiteral(ctx, state2) {
|
|
12687
12925
|
return (0, import_lib2.$EVENT)(ctx, state2, "NullLiteral", NullLiteral$0);
|
|
@@ -12696,17 +12934,17 @@ var _BooleanLiteral$0 = (0, import_lib2.$T)((0, import_lib2.$S)(CoffeeBooleansEn
|
|
|
12696
12934
|
return value[1];
|
|
12697
12935
|
});
|
|
12698
12936
|
var _BooleanLiteral$1 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$C)((0, import_lib2.$EXPECT)($L39, '_BooleanLiteral "true"'), (0, import_lib2.$EXPECT)($L40, '_BooleanLiteral "false"')), NonIdContinue), function($skip, $loc, $0, $1, $2) {
|
|
12699
|
-
return { $loc, token: $1 };
|
|
12937
|
+
return { type: "BooleanLiteral", $loc, token: $1 };
|
|
12700
12938
|
});
|
|
12701
12939
|
var _BooleanLiteral$$ = [_BooleanLiteral$0, _BooleanLiteral$1];
|
|
12702
12940
|
function _BooleanLiteral(ctx, state2) {
|
|
12703
12941
|
return (0, import_lib2.$EVENT_C)(ctx, state2, "_BooleanLiteral", _BooleanLiteral$$);
|
|
12704
12942
|
}
|
|
12705
12943
|
var CoffeeScriptBooleanLiteral$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$C)((0, import_lib2.$EXPECT)($L41, 'CoffeeScriptBooleanLiteral "yes"'), (0, import_lib2.$EXPECT)($L42, 'CoffeeScriptBooleanLiteral "on"')), NonIdContinue), function($skip, $loc, $0, $1, $2) {
|
|
12706
|
-
return { $loc, token: "true" };
|
|
12944
|
+
return { type: "BooleanLiteral", $loc, token: "true" };
|
|
12707
12945
|
});
|
|
12708
12946
|
var CoffeeScriptBooleanLiteral$1 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$C)((0, import_lib2.$EXPECT)($L43, 'CoffeeScriptBooleanLiteral "no"'), (0, import_lib2.$EXPECT)($L44, 'CoffeeScriptBooleanLiteral "off"')), NonIdContinue), function($skip, $loc, $0, $1, $2) {
|
|
12709
|
-
return { $loc, token: "false" };
|
|
12947
|
+
return { type: "BooleanLiteral", $loc, token: "false" };
|
|
12710
12948
|
});
|
|
12711
12949
|
var CoffeeScriptBooleanLiteral$$ = [CoffeeScriptBooleanLiteral$0, CoffeeScriptBooleanLiteral$1];
|
|
12712
12950
|
function CoffeeScriptBooleanLiteral(ctx, state2) {
|
|
@@ -16592,7 +16830,12 @@ function CoffeeDoubleQuotedStringCharacters(ctx, state2) {
|
|
|
16592
16830
|
}
|
|
16593
16831
|
var RegularExpressionLiteral$0 = HeregexLiteral;
|
|
16594
16832
|
var RegularExpressionLiteral$1 = (0, import_lib2.$TV)((0, import_lib2.$TEXT)((0, import_lib2.$S)((0, import_lib2.$EXPECT)($L77, 'RegularExpressionLiteral "/"'), RegularExpressionBody, (0, import_lib2.$EXPECT)($L77, 'RegularExpressionLiteral "/"'), RegularExpressionFlags)), function($skip, $loc, $0, $1) {
|
|
16595
|
-
|
|
16833
|
+
var raw = $0;
|
|
16834
|
+
return {
|
|
16835
|
+
type: "RegularExpressionLiteral",
|
|
16836
|
+
raw,
|
|
16837
|
+
children: [{ $loc, token: raw }]
|
|
16838
|
+
};
|
|
16596
16839
|
});
|
|
16597
16840
|
var RegularExpressionLiteral$$ = [RegularExpressionLiteral$0, RegularExpressionLiteral$1];
|
|
16598
16841
|
function RegularExpressionLiteral(ctx, state2) {
|
|
@@ -18980,9 +19223,11 @@ function UnknownAlias(ctx, state2) {
|
|
|
18980
19223
|
}
|
|
18981
19224
|
var TypePrimary$0 = (0, import_lib2.$S)((0, import_lib2.$E)(_), Infer, (0, import_lib2.$E)(_), IdentifierName, (0, import_lib2.$E)((0, import_lib2.$S)(NotDedented, ExtendsToken, Type)));
|
|
18982
19225
|
var TypePrimary$1 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$E)(_), Typeof, (0, import_lib2.$E)(_), UnaryExpression), function($skip, $loc, $0, $1, $2, $3, $4) {
|
|
19226
|
+
var expression = $4;
|
|
18983
19227
|
return {
|
|
18984
|
-
type: "
|
|
18985
|
-
children: $0
|
|
19228
|
+
type: "TypeTypeof",
|
|
19229
|
+
children: $0,
|
|
19230
|
+
expression
|
|
18986
19231
|
};
|
|
18987
19232
|
});
|
|
18988
19233
|
var TypePrimary$2 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$E)(_), TypeTuple), function($skip, $loc, $0, $1, $2) {
|