@danielx/civet 0.6.4 → 0.6.6
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 +101 -44
- package/dist/main.js +101 -44
- package/dist/main.mjs +101 -44
- package/package.json +1 -1
package/dist/browser.js
CHANGED
|
@@ -193,13 +193,6 @@ var Civet = (() => {
|
|
|
193
193
|
}
|
|
194
194
|
return block;
|
|
195
195
|
}
|
|
196
|
-
function closest(node, types) {
|
|
197
|
-
do {
|
|
198
|
-
if (types.includes(node.type)) {
|
|
199
|
-
return node;
|
|
200
|
-
}
|
|
201
|
-
} while (node = node.parent);
|
|
202
|
-
}
|
|
203
196
|
function clone(node) {
|
|
204
197
|
removeParentPointers(node);
|
|
205
198
|
return deepCopy(node);
|
|
@@ -436,8 +429,26 @@ var Civet = (() => {
|
|
|
436
429
|
for (let i = 0; i < children.length; i++) {
|
|
437
430
|
const glob = children[i];
|
|
438
431
|
if (glob?.type === "PropertyGlob") {
|
|
439
|
-
|
|
432
|
+
let prefix = children.slice(0, i);
|
|
440
433
|
const parts = [];
|
|
434
|
+
let hoistDec, refAssignment = [];
|
|
435
|
+
if (prefix.length > 1) {
|
|
436
|
+
const ref = {
|
|
437
|
+
type: "Ref",
|
|
438
|
+
base: "ref"
|
|
439
|
+
};
|
|
440
|
+
hoistDec = {
|
|
441
|
+
type: "Declaration",
|
|
442
|
+
children: ["let ", ref],
|
|
443
|
+
names: []
|
|
444
|
+
};
|
|
445
|
+
refAssignment = [{
|
|
446
|
+
type: "AssignmentExpression",
|
|
447
|
+
children: [ref, " = ", prefix]
|
|
448
|
+
}, ","];
|
|
449
|
+
prefix = [ref];
|
|
450
|
+
}
|
|
451
|
+
prefix = prefix.concat(glob.dot);
|
|
441
452
|
for (const part of glob.object.properties) {
|
|
442
453
|
if (part.type === "MethodDefinition") {
|
|
443
454
|
throw new Error("Glob pattern cannot have method definition");
|
|
@@ -480,11 +491,13 @@ var Civet = (() => {
|
|
|
480
491
|
const object = {
|
|
481
492
|
type: "ObjectExpression",
|
|
482
493
|
children: [
|
|
494
|
+
...refAssignment,
|
|
483
495
|
glob.object.children[0],
|
|
484
496
|
...parts,
|
|
485
497
|
glob.object.children.at(-1)
|
|
486
498
|
],
|
|
487
|
-
properties: parts
|
|
499
|
+
properties: parts,
|
|
500
|
+
hoistDec
|
|
488
501
|
};
|
|
489
502
|
if (i === children.length - 1)
|
|
490
503
|
return object;
|
|
@@ -786,29 +799,26 @@ var Civet = (() => {
|
|
|
786
799
|
function hoistRefDecs(statements) {
|
|
787
800
|
gatherRecursiveAll(statements, (s) => s.hoistDec).forEach((node) => {
|
|
788
801
|
const { hoistDec } = node;
|
|
789
|
-
let outer = closest(node, ["IfStatement", "IterationStatement"]);
|
|
790
|
-
if (!outer) {
|
|
791
|
-
node.children.push({
|
|
792
|
-
type: "Error",
|
|
793
|
-
message: "Can't hoist declarations inside expressions yet."
|
|
794
|
-
});
|
|
795
|
-
return;
|
|
796
|
-
}
|
|
797
|
-
let block = outer.parent;
|
|
798
|
-
if (block.type === "PatternMatchingStatement") {
|
|
799
|
-
outer = block;
|
|
800
|
-
block = block.parent;
|
|
801
|
-
}
|
|
802
|
-
const { expressions } = block;
|
|
803
|
-
const index = expressions.findIndex(([, s]) => outer === s);
|
|
804
|
-
if (index < 0)
|
|
805
|
-
throw new Error("Couldn't find expression in block for hoistable declaration.");
|
|
806
|
-
const indent = expressions[index][0];
|
|
807
|
-
hoistDec[0][0] = indent;
|
|
808
|
-
expressions.splice(index, 0, hoistDec);
|
|
809
802
|
node.hoistDec = null;
|
|
803
|
+
while (node.parent?.type !== "BlockStatement") {
|
|
804
|
+
node = node.parent;
|
|
805
|
+
}
|
|
806
|
+
if (node.parent) {
|
|
807
|
+
insertHoistDec(node.parent, node, hoistDec);
|
|
808
|
+
} else {
|
|
809
|
+
throw new Error("Couldn't find block to hoist declaration into.");
|
|
810
|
+
}
|
|
811
|
+
return;
|
|
810
812
|
});
|
|
811
813
|
}
|
|
814
|
+
function insertHoistDec(block, node, dec) {
|
|
815
|
+
const { expressions } = block;
|
|
816
|
+
const index = expressions.findIndex(([, s]) => node === s);
|
|
817
|
+
if (index < 0)
|
|
818
|
+
throw new Error("Couldn't find expression in block for hoistable declaration.");
|
|
819
|
+
const indent = expressions[index][0];
|
|
820
|
+
expressions.splice(index, 0, [indent, dec, ";"]);
|
|
821
|
+
}
|
|
812
822
|
function insertReturn(node) {
|
|
813
823
|
if (!node)
|
|
814
824
|
return;
|
|
@@ -1726,8 +1736,18 @@ var Civet = (() => {
|
|
|
1726
1736
|
if (expression.type === "ParenthesizedExpression") {
|
|
1727
1737
|
expression = expression.expression;
|
|
1728
1738
|
}
|
|
1729
|
-
let ref = needsRef(expression, "m") || expression;
|
|
1730
|
-
|
|
1739
|
+
let hoistDec, refAssignment = [], ref = needsRef(expression, "m") || expression;
|
|
1740
|
+
if (ref !== expression) {
|
|
1741
|
+
hoistDec = {
|
|
1742
|
+
type: "Declaration",
|
|
1743
|
+
children: ["let ", ref],
|
|
1744
|
+
names: []
|
|
1745
|
+
};
|
|
1746
|
+
refAssignment = [{
|
|
1747
|
+
type: "AssignmentExpression",
|
|
1748
|
+
children: [ref, " = ", expression]
|
|
1749
|
+
}, ","];
|
|
1750
|
+
}
|
|
1731
1751
|
let prev = [], root = prev;
|
|
1732
1752
|
const l = clauses.length;
|
|
1733
1753
|
clauses.forEach((c, i) => {
|
|
@@ -1755,7 +1775,7 @@ var Civet = (() => {
|
|
|
1755
1775
|
});
|
|
1756
1776
|
const condition = {
|
|
1757
1777
|
type: "ParenthesizedExpression",
|
|
1758
|
-
children: ["(", conditionExpression, ")"],
|
|
1778
|
+
children: ["(", ...refAssignment, conditionExpression, ")"],
|
|
1759
1779
|
expression: conditionExpression
|
|
1760
1780
|
};
|
|
1761
1781
|
const prefix = [];
|
|
@@ -1794,6 +1814,7 @@ var Civet = (() => {
|
|
|
1794
1814
|
hoistDec
|
|
1795
1815
|
}]);
|
|
1796
1816
|
hoistDec = void 0;
|
|
1817
|
+
refAssignment = [];
|
|
1797
1818
|
prev = next;
|
|
1798
1819
|
});
|
|
1799
1820
|
if (s.type === "SwitchExpression") {
|
|
@@ -2442,6 +2463,7 @@ var Civet = (() => {
|
|
|
2442
2463
|
literalValue,
|
|
2443
2464
|
makeAsConst,
|
|
2444
2465
|
makeLeftHandSideExpression,
|
|
2466
|
+
maybeRef,
|
|
2445
2467
|
modifyString,
|
|
2446
2468
|
needsRef,
|
|
2447
2469
|
processBinaryOpExpression,
|
|
@@ -6309,11 +6331,11 @@ ${input.slice(result.pos)}
|
|
|
6309
6331
|
}
|
|
6310
6332
|
var MemberBracketContent$0 = $TS($S(OpenBracket, $C(SliceParameters, PostfixedExpression), __, CloseBracket), function($skip, $loc, $0, $1, $2, $3, $4) {
|
|
6311
6333
|
var open = $1;
|
|
6312
|
-
var
|
|
6334
|
+
var expression = $2;
|
|
6313
6335
|
var ws = $3;
|
|
6314
6336
|
var close = $4;
|
|
6315
|
-
if (
|
|
6316
|
-
const { start, end, children } =
|
|
6337
|
+
if (expression.type === "SliceParameters") {
|
|
6338
|
+
const { start, end, children } = expression;
|
|
6317
6339
|
return {
|
|
6318
6340
|
type: "SliceExpression",
|
|
6319
6341
|
start,
|
|
@@ -6327,7 +6349,8 @@ ${input.slice(result.pos)}
|
|
|
6327
6349
|
}
|
|
6328
6350
|
return {
|
|
6329
6351
|
type: "Index",
|
|
6330
|
-
children: $0
|
|
6352
|
+
children: $0,
|
|
6353
|
+
expression
|
|
6331
6354
|
};
|
|
6332
6355
|
});
|
|
6333
6356
|
var MemberBracketContent$1 = $TS($S(Dot, $C(TemplateLiteral, StringLiteral)), function($skip, $loc, $0, $1, $2) {
|
|
@@ -9718,12 +9741,40 @@ ${input.slice(result.pos)}
|
|
|
9718
9741
|
const last = lastAccessInCallExpression(value);
|
|
9719
9742
|
if (!last)
|
|
9720
9743
|
return $skip;
|
|
9721
|
-
let name;
|
|
9722
|
-
|
|
9723
|
-
|
|
9724
|
-
|
|
9725
|
-
|
|
9726
|
-
|
|
9744
|
+
let name, hoistDec, ref, refAssignment;
|
|
9745
|
+
const { expression, type } = last;
|
|
9746
|
+
if (type === "Index") {
|
|
9747
|
+
ref = maybeRef(expression);
|
|
9748
|
+
if (ref !== expression) {
|
|
9749
|
+
hoistDec = {
|
|
9750
|
+
type: "Declaration",
|
|
9751
|
+
children: ["let ", ref]
|
|
9752
|
+
};
|
|
9753
|
+
refAssignment = {
|
|
9754
|
+
type: "Assignment",
|
|
9755
|
+
children: [ref, " = ", expression]
|
|
9756
|
+
};
|
|
9757
|
+
name = {
|
|
9758
|
+
type: "ComputedPropertyName",
|
|
9759
|
+
children: [last.children[0], "(", refAssignment, ",", ref, ")", ...last.children.slice(-2)]
|
|
9760
|
+
};
|
|
9761
|
+
value = {
|
|
9762
|
+
...value,
|
|
9763
|
+
children: value.children.map((c) => {
|
|
9764
|
+
if (c === last)
|
|
9765
|
+
return {
|
|
9766
|
+
type: "Index",
|
|
9767
|
+
children: ["[", ref, "]"]
|
|
9768
|
+
};
|
|
9769
|
+
return c;
|
|
9770
|
+
})
|
|
9771
|
+
};
|
|
9772
|
+
} else {
|
|
9773
|
+
name = {
|
|
9774
|
+
type: "ComputedPropertyName",
|
|
9775
|
+
children: last.children
|
|
9776
|
+
};
|
|
9777
|
+
}
|
|
9727
9778
|
} else {
|
|
9728
9779
|
({ name } = last);
|
|
9729
9780
|
if (!name)
|
|
@@ -9734,7 +9785,8 @@ ${input.slice(result.pos)}
|
|
|
9734
9785
|
children: [ws, name, ": ", value],
|
|
9735
9786
|
name,
|
|
9736
9787
|
value,
|
|
9737
|
-
names: []
|
|
9788
|
+
names: [],
|
|
9789
|
+
hoistDec
|
|
9738
9790
|
};
|
|
9739
9791
|
});
|
|
9740
9792
|
function PropertyDefinition(state) {
|
|
@@ -12882,7 +12934,11 @@ ${input.slice(result.pos)}
|
|
|
12882
12934
|
const initCondition = {
|
|
12883
12935
|
type: "AssignmentExpression",
|
|
12884
12936
|
children: [ref, " ", initializer],
|
|
12885
|
-
hoistDec:
|
|
12937
|
+
hoistDec: {
|
|
12938
|
+
type: "Declaration",
|
|
12939
|
+
children: ["let ", ref],
|
|
12940
|
+
names: []
|
|
12941
|
+
},
|
|
12886
12942
|
blockPrefix: [
|
|
12887
12943
|
["", [binding, "= ", ref, ...splices], ";"],
|
|
12888
12944
|
...thisAssignments
|
|
@@ -23350,6 +23406,7 @@ ${input.slice(result.pos)}
|
|
|
23350
23406
|
lastAccessInCallExpression,
|
|
23351
23407
|
literalValue,
|
|
23352
23408
|
makeLeftHandSideExpression,
|
|
23409
|
+
maybeRef,
|
|
23353
23410
|
modifyString,
|
|
23354
23411
|
processBinaryOpExpression,
|
|
23355
23412
|
processCallMemberExpression,
|
package/dist/main.js
CHANGED
|
@@ -192,13 +192,6 @@ var require_lib = __commonJS({
|
|
|
192
192
|
}
|
|
193
193
|
return block;
|
|
194
194
|
}
|
|
195
|
-
function closest(node, types) {
|
|
196
|
-
do {
|
|
197
|
-
if (types.includes(node.type)) {
|
|
198
|
-
return node;
|
|
199
|
-
}
|
|
200
|
-
} while (node = node.parent);
|
|
201
|
-
}
|
|
202
195
|
function clone(node) {
|
|
203
196
|
removeParentPointers(node);
|
|
204
197
|
return deepCopy(node);
|
|
@@ -435,8 +428,26 @@ var require_lib = __commonJS({
|
|
|
435
428
|
for (let i = 0; i < children.length; i++) {
|
|
436
429
|
const glob = children[i];
|
|
437
430
|
if (glob?.type === "PropertyGlob") {
|
|
438
|
-
|
|
431
|
+
let prefix = children.slice(0, i);
|
|
439
432
|
const parts = [];
|
|
433
|
+
let hoistDec, refAssignment = [];
|
|
434
|
+
if (prefix.length > 1) {
|
|
435
|
+
const ref = {
|
|
436
|
+
type: "Ref",
|
|
437
|
+
base: "ref"
|
|
438
|
+
};
|
|
439
|
+
hoistDec = {
|
|
440
|
+
type: "Declaration",
|
|
441
|
+
children: ["let ", ref],
|
|
442
|
+
names: []
|
|
443
|
+
};
|
|
444
|
+
refAssignment = [{
|
|
445
|
+
type: "AssignmentExpression",
|
|
446
|
+
children: [ref, " = ", prefix]
|
|
447
|
+
}, ","];
|
|
448
|
+
prefix = [ref];
|
|
449
|
+
}
|
|
450
|
+
prefix = prefix.concat(glob.dot);
|
|
440
451
|
for (const part of glob.object.properties) {
|
|
441
452
|
if (part.type === "MethodDefinition") {
|
|
442
453
|
throw new Error("Glob pattern cannot have method definition");
|
|
@@ -479,11 +490,13 @@ var require_lib = __commonJS({
|
|
|
479
490
|
const object = {
|
|
480
491
|
type: "ObjectExpression",
|
|
481
492
|
children: [
|
|
493
|
+
...refAssignment,
|
|
482
494
|
glob.object.children[0],
|
|
483
495
|
...parts,
|
|
484
496
|
glob.object.children.at(-1)
|
|
485
497
|
],
|
|
486
|
-
properties: parts
|
|
498
|
+
properties: parts,
|
|
499
|
+
hoistDec
|
|
487
500
|
};
|
|
488
501
|
if (i === children.length - 1)
|
|
489
502
|
return object;
|
|
@@ -785,29 +798,26 @@ var require_lib = __commonJS({
|
|
|
785
798
|
function hoistRefDecs(statements) {
|
|
786
799
|
gatherRecursiveAll(statements, (s) => s.hoistDec).forEach((node) => {
|
|
787
800
|
const { hoistDec } = node;
|
|
788
|
-
let outer = closest(node, ["IfStatement", "IterationStatement"]);
|
|
789
|
-
if (!outer) {
|
|
790
|
-
node.children.push({
|
|
791
|
-
type: "Error",
|
|
792
|
-
message: "Can't hoist declarations inside expressions yet."
|
|
793
|
-
});
|
|
794
|
-
return;
|
|
795
|
-
}
|
|
796
|
-
let block = outer.parent;
|
|
797
|
-
if (block.type === "PatternMatchingStatement") {
|
|
798
|
-
outer = block;
|
|
799
|
-
block = block.parent;
|
|
800
|
-
}
|
|
801
|
-
const { expressions } = block;
|
|
802
|
-
const index = expressions.findIndex(([, s]) => outer === s);
|
|
803
|
-
if (index < 0)
|
|
804
|
-
throw new Error("Couldn't find expression in block for hoistable declaration.");
|
|
805
|
-
const indent = expressions[index][0];
|
|
806
|
-
hoistDec[0][0] = indent;
|
|
807
|
-
expressions.splice(index, 0, hoistDec);
|
|
808
801
|
node.hoistDec = null;
|
|
802
|
+
while (node.parent?.type !== "BlockStatement") {
|
|
803
|
+
node = node.parent;
|
|
804
|
+
}
|
|
805
|
+
if (node.parent) {
|
|
806
|
+
insertHoistDec(node.parent, node, hoistDec);
|
|
807
|
+
} else {
|
|
808
|
+
throw new Error("Couldn't find block to hoist declaration into.");
|
|
809
|
+
}
|
|
810
|
+
return;
|
|
809
811
|
});
|
|
810
812
|
}
|
|
813
|
+
function insertHoistDec(block, node, dec) {
|
|
814
|
+
const { expressions } = block;
|
|
815
|
+
const index = expressions.findIndex(([, s]) => node === s);
|
|
816
|
+
if (index < 0)
|
|
817
|
+
throw new Error("Couldn't find expression in block for hoistable declaration.");
|
|
818
|
+
const indent = expressions[index][0];
|
|
819
|
+
expressions.splice(index, 0, [indent, dec, ";"]);
|
|
820
|
+
}
|
|
811
821
|
function insertReturn(node) {
|
|
812
822
|
if (!node)
|
|
813
823
|
return;
|
|
@@ -1725,8 +1735,18 @@ var require_lib = __commonJS({
|
|
|
1725
1735
|
if (expression.type === "ParenthesizedExpression") {
|
|
1726
1736
|
expression = expression.expression;
|
|
1727
1737
|
}
|
|
1728
|
-
let ref = needsRef(expression, "m") || expression;
|
|
1729
|
-
|
|
1738
|
+
let hoistDec, refAssignment = [], ref = needsRef(expression, "m") || expression;
|
|
1739
|
+
if (ref !== expression) {
|
|
1740
|
+
hoistDec = {
|
|
1741
|
+
type: "Declaration",
|
|
1742
|
+
children: ["let ", ref],
|
|
1743
|
+
names: []
|
|
1744
|
+
};
|
|
1745
|
+
refAssignment = [{
|
|
1746
|
+
type: "AssignmentExpression",
|
|
1747
|
+
children: [ref, " = ", expression]
|
|
1748
|
+
}, ","];
|
|
1749
|
+
}
|
|
1730
1750
|
let prev = [], root = prev;
|
|
1731
1751
|
const l = clauses.length;
|
|
1732
1752
|
clauses.forEach((c, i) => {
|
|
@@ -1754,7 +1774,7 @@ var require_lib = __commonJS({
|
|
|
1754
1774
|
});
|
|
1755
1775
|
const condition = {
|
|
1756
1776
|
type: "ParenthesizedExpression",
|
|
1757
|
-
children: ["(", conditionExpression, ")"],
|
|
1777
|
+
children: ["(", ...refAssignment, conditionExpression, ")"],
|
|
1758
1778
|
expression: conditionExpression
|
|
1759
1779
|
};
|
|
1760
1780
|
const prefix = [];
|
|
@@ -1793,6 +1813,7 @@ var require_lib = __commonJS({
|
|
|
1793
1813
|
hoistDec
|
|
1794
1814
|
}]);
|
|
1795
1815
|
hoistDec = void 0;
|
|
1816
|
+
refAssignment = [];
|
|
1796
1817
|
prev = next;
|
|
1797
1818
|
});
|
|
1798
1819
|
if (s.type === "SwitchExpression") {
|
|
@@ -2441,6 +2462,7 @@ var require_lib = __commonJS({
|
|
|
2441
2462
|
literalValue,
|
|
2442
2463
|
makeAsConst,
|
|
2443
2464
|
makeLeftHandSideExpression,
|
|
2465
|
+
maybeRef,
|
|
2444
2466
|
modifyString,
|
|
2445
2467
|
needsRef,
|
|
2446
2468
|
processBinaryOpExpression,
|
|
@@ -6308,11 +6330,11 @@ ${input.slice(result.pos)}
|
|
|
6308
6330
|
}
|
|
6309
6331
|
var MemberBracketContent$0 = $TS($S(OpenBracket, $C(SliceParameters, PostfixedExpression), __, CloseBracket), function($skip, $loc, $0, $1, $2, $3, $4) {
|
|
6310
6332
|
var open = $1;
|
|
6311
|
-
var
|
|
6333
|
+
var expression = $2;
|
|
6312
6334
|
var ws = $3;
|
|
6313
6335
|
var close = $4;
|
|
6314
|
-
if (
|
|
6315
|
-
const { start, end, children } =
|
|
6336
|
+
if (expression.type === "SliceParameters") {
|
|
6337
|
+
const { start, end, children } = expression;
|
|
6316
6338
|
return {
|
|
6317
6339
|
type: "SliceExpression",
|
|
6318
6340
|
start,
|
|
@@ -6326,7 +6348,8 @@ ${input.slice(result.pos)}
|
|
|
6326
6348
|
}
|
|
6327
6349
|
return {
|
|
6328
6350
|
type: "Index",
|
|
6329
|
-
children: $0
|
|
6351
|
+
children: $0,
|
|
6352
|
+
expression
|
|
6330
6353
|
};
|
|
6331
6354
|
});
|
|
6332
6355
|
var MemberBracketContent$1 = $TS($S(Dot, $C(TemplateLiteral, StringLiteral)), function($skip, $loc, $0, $1, $2) {
|
|
@@ -9717,12 +9740,40 @@ ${input.slice(result.pos)}
|
|
|
9717
9740
|
const last = lastAccessInCallExpression(value);
|
|
9718
9741
|
if (!last)
|
|
9719
9742
|
return $skip;
|
|
9720
|
-
let name;
|
|
9721
|
-
|
|
9722
|
-
|
|
9723
|
-
|
|
9724
|
-
|
|
9725
|
-
|
|
9743
|
+
let name, hoistDec, ref, refAssignment;
|
|
9744
|
+
const { expression, type } = last;
|
|
9745
|
+
if (type === "Index") {
|
|
9746
|
+
ref = maybeRef(expression);
|
|
9747
|
+
if (ref !== expression) {
|
|
9748
|
+
hoistDec = {
|
|
9749
|
+
type: "Declaration",
|
|
9750
|
+
children: ["let ", ref]
|
|
9751
|
+
};
|
|
9752
|
+
refAssignment = {
|
|
9753
|
+
type: "Assignment",
|
|
9754
|
+
children: [ref, " = ", expression]
|
|
9755
|
+
};
|
|
9756
|
+
name = {
|
|
9757
|
+
type: "ComputedPropertyName",
|
|
9758
|
+
children: [last.children[0], "(", refAssignment, ",", ref, ")", ...last.children.slice(-2)]
|
|
9759
|
+
};
|
|
9760
|
+
value = {
|
|
9761
|
+
...value,
|
|
9762
|
+
children: value.children.map((c) => {
|
|
9763
|
+
if (c === last)
|
|
9764
|
+
return {
|
|
9765
|
+
type: "Index",
|
|
9766
|
+
children: ["[", ref, "]"]
|
|
9767
|
+
};
|
|
9768
|
+
return c;
|
|
9769
|
+
})
|
|
9770
|
+
};
|
|
9771
|
+
} else {
|
|
9772
|
+
name = {
|
|
9773
|
+
type: "ComputedPropertyName",
|
|
9774
|
+
children: last.children
|
|
9775
|
+
};
|
|
9776
|
+
}
|
|
9726
9777
|
} else {
|
|
9727
9778
|
({ name } = last);
|
|
9728
9779
|
if (!name)
|
|
@@ -9733,7 +9784,8 @@ ${input.slice(result.pos)}
|
|
|
9733
9784
|
children: [ws, name, ": ", value],
|
|
9734
9785
|
name,
|
|
9735
9786
|
value,
|
|
9736
|
-
names: []
|
|
9787
|
+
names: [],
|
|
9788
|
+
hoistDec
|
|
9737
9789
|
};
|
|
9738
9790
|
});
|
|
9739
9791
|
function PropertyDefinition(state) {
|
|
@@ -12881,7 +12933,11 @@ ${input.slice(result.pos)}
|
|
|
12881
12933
|
const initCondition = {
|
|
12882
12934
|
type: "AssignmentExpression",
|
|
12883
12935
|
children: [ref, " ", initializer],
|
|
12884
|
-
hoistDec:
|
|
12936
|
+
hoistDec: {
|
|
12937
|
+
type: "Declaration",
|
|
12938
|
+
children: ["let ", ref],
|
|
12939
|
+
names: []
|
|
12940
|
+
},
|
|
12885
12941
|
blockPrefix: [
|
|
12886
12942
|
["", [binding, "= ", ref, ...splices], ";"],
|
|
12887
12943
|
...thisAssignments
|
|
@@ -23349,6 +23405,7 @@ ${input.slice(result.pos)}
|
|
|
23349
23405
|
lastAccessInCallExpression,
|
|
23350
23406
|
literalValue,
|
|
23351
23407
|
makeLeftHandSideExpression,
|
|
23408
|
+
maybeRef,
|
|
23352
23409
|
modifyString,
|
|
23353
23410
|
processBinaryOpExpression,
|
|
23354
23411
|
processCallMemberExpression,
|
package/dist/main.mjs
CHANGED
|
@@ -190,13 +190,6 @@ var require_lib = __commonJS({
|
|
|
190
190
|
}
|
|
191
191
|
return block;
|
|
192
192
|
}
|
|
193
|
-
function closest(node, types) {
|
|
194
|
-
do {
|
|
195
|
-
if (types.includes(node.type)) {
|
|
196
|
-
return node;
|
|
197
|
-
}
|
|
198
|
-
} while (node = node.parent);
|
|
199
|
-
}
|
|
200
193
|
function clone(node) {
|
|
201
194
|
removeParentPointers(node);
|
|
202
195
|
return deepCopy(node);
|
|
@@ -433,8 +426,26 @@ var require_lib = __commonJS({
|
|
|
433
426
|
for (let i = 0; i < children.length; i++) {
|
|
434
427
|
const glob = children[i];
|
|
435
428
|
if (glob?.type === "PropertyGlob") {
|
|
436
|
-
|
|
429
|
+
let prefix = children.slice(0, i);
|
|
437
430
|
const parts = [];
|
|
431
|
+
let hoistDec, refAssignment = [];
|
|
432
|
+
if (prefix.length > 1) {
|
|
433
|
+
const ref = {
|
|
434
|
+
type: "Ref",
|
|
435
|
+
base: "ref"
|
|
436
|
+
};
|
|
437
|
+
hoistDec = {
|
|
438
|
+
type: "Declaration",
|
|
439
|
+
children: ["let ", ref],
|
|
440
|
+
names: []
|
|
441
|
+
};
|
|
442
|
+
refAssignment = [{
|
|
443
|
+
type: "AssignmentExpression",
|
|
444
|
+
children: [ref, " = ", prefix]
|
|
445
|
+
}, ","];
|
|
446
|
+
prefix = [ref];
|
|
447
|
+
}
|
|
448
|
+
prefix = prefix.concat(glob.dot);
|
|
438
449
|
for (const part of glob.object.properties) {
|
|
439
450
|
if (part.type === "MethodDefinition") {
|
|
440
451
|
throw new Error("Glob pattern cannot have method definition");
|
|
@@ -477,11 +488,13 @@ var require_lib = __commonJS({
|
|
|
477
488
|
const object = {
|
|
478
489
|
type: "ObjectExpression",
|
|
479
490
|
children: [
|
|
491
|
+
...refAssignment,
|
|
480
492
|
glob.object.children[0],
|
|
481
493
|
...parts,
|
|
482
494
|
glob.object.children.at(-1)
|
|
483
495
|
],
|
|
484
|
-
properties: parts
|
|
496
|
+
properties: parts,
|
|
497
|
+
hoistDec
|
|
485
498
|
};
|
|
486
499
|
if (i === children.length - 1)
|
|
487
500
|
return object;
|
|
@@ -783,29 +796,26 @@ var require_lib = __commonJS({
|
|
|
783
796
|
function hoistRefDecs(statements) {
|
|
784
797
|
gatherRecursiveAll(statements, (s) => s.hoistDec).forEach((node) => {
|
|
785
798
|
const { hoistDec } = node;
|
|
786
|
-
let outer = closest(node, ["IfStatement", "IterationStatement"]);
|
|
787
|
-
if (!outer) {
|
|
788
|
-
node.children.push({
|
|
789
|
-
type: "Error",
|
|
790
|
-
message: "Can't hoist declarations inside expressions yet."
|
|
791
|
-
});
|
|
792
|
-
return;
|
|
793
|
-
}
|
|
794
|
-
let block = outer.parent;
|
|
795
|
-
if (block.type === "PatternMatchingStatement") {
|
|
796
|
-
outer = block;
|
|
797
|
-
block = block.parent;
|
|
798
|
-
}
|
|
799
|
-
const { expressions } = block;
|
|
800
|
-
const index = expressions.findIndex(([, s]) => outer === s);
|
|
801
|
-
if (index < 0)
|
|
802
|
-
throw new Error("Couldn't find expression in block for hoistable declaration.");
|
|
803
|
-
const indent = expressions[index][0];
|
|
804
|
-
hoistDec[0][0] = indent;
|
|
805
|
-
expressions.splice(index, 0, hoistDec);
|
|
806
799
|
node.hoistDec = null;
|
|
800
|
+
while (node.parent?.type !== "BlockStatement") {
|
|
801
|
+
node = node.parent;
|
|
802
|
+
}
|
|
803
|
+
if (node.parent) {
|
|
804
|
+
insertHoistDec(node.parent, node, hoistDec);
|
|
805
|
+
} else {
|
|
806
|
+
throw new Error("Couldn't find block to hoist declaration into.");
|
|
807
|
+
}
|
|
808
|
+
return;
|
|
807
809
|
});
|
|
808
810
|
}
|
|
811
|
+
function insertHoistDec(block, node, dec) {
|
|
812
|
+
const { expressions } = block;
|
|
813
|
+
const index = expressions.findIndex(([, s]) => node === s);
|
|
814
|
+
if (index < 0)
|
|
815
|
+
throw new Error("Couldn't find expression in block for hoistable declaration.");
|
|
816
|
+
const indent = expressions[index][0];
|
|
817
|
+
expressions.splice(index, 0, [indent, dec, ";"]);
|
|
818
|
+
}
|
|
809
819
|
function insertReturn(node) {
|
|
810
820
|
if (!node)
|
|
811
821
|
return;
|
|
@@ -1723,8 +1733,18 @@ var require_lib = __commonJS({
|
|
|
1723
1733
|
if (expression.type === "ParenthesizedExpression") {
|
|
1724
1734
|
expression = expression.expression;
|
|
1725
1735
|
}
|
|
1726
|
-
let ref = needsRef(expression, "m") || expression;
|
|
1727
|
-
|
|
1736
|
+
let hoistDec, refAssignment = [], ref = needsRef(expression, "m") || expression;
|
|
1737
|
+
if (ref !== expression) {
|
|
1738
|
+
hoistDec = {
|
|
1739
|
+
type: "Declaration",
|
|
1740
|
+
children: ["let ", ref],
|
|
1741
|
+
names: []
|
|
1742
|
+
};
|
|
1743
|
+
refAssignment = [{
|
|
1744
|
+
type: "AssignmentExpression",
|
|
1745
|
+
children: [ref, " = ", expression]
|
|
1746
|
+
}, ","];
|
|
1747
|
+
}
|
|
1728
1748
|
let prev = [], root = prev;
|
|
1729
1749
|
const l = clauses.length;
|
|
1730
1750
|
clauses.forEach((c, i) => {
|
|
@@ -1752,7 +1772,7 @@ var require_lib = __commonJS({
|
|
|
1752
1772
|
});
|
|
1753
1773
|
const condition = {
|
|
1754
1774
|
type: "ParenthesizedExpression",
|
|
1755
|
-
children: ["(", conditionExpression, ")"],
|
|
1775
|
+
children: ["(", ...refAssignment, conditionExpression, ")"],
|
|
1756
1776
|
expression: conditionExpression
|
|
1757
1777
|
};
|
|
1758
1778
|
const prefix = [];
|
|
@@ -1791,6 +1811,7 @@ var require_lib = __commonJS({
|
|
|
1791
1811
|
hoistDec
|
|
1792
1812
|
}]);
|
|
1793
1813
|
hoistDec = void 0;
|
|
1814
|
+
refAssignment = [];
|
|
1794
1815
|
prev = next;
|
|
1795
1816
|
});
|
|
1796
1817
|
if (s.type === "SwitchExpression") {
|
|
@@ -2439,6 +2460,7 @@ var require_lib = __commonJS({
|
|
|
2439
2460
|
literalValue,
|
|
2440
2461
|
makeAsConst,
|
|
2441
2462
|
makeLeftHandSideExpression,
|
|
2463
|
+
maybeRef,
|
|
2442
2464
|
modifyString,
|
|
2443
2465
|
needsRef,
|
|
2444
2466
|
processBinaryOpExpression,
|
|
@@ -6306,11 +6328,11 @@ ${input.slice(result.pos)}
|
|
|
6306
6328
|
}
|
|
6307
6329
|
var MemberBracketContent$0 = $TS($S(OpenBracket, $C(SliceParameters, PostfixedExpression), __, CloseBracket), function($skip, $loc, $0, $1, $2, $3, $4) {
|
|
6308
6330
|
var open = $1;
|
|
6309
|
-
var
|
|
6331
|
+
var expression = $2;
|
|
6310
6332
|
var ws = $3;
|
|
6311
6333
|
var close = $4;
|
|
6312
|
-
if (
|
|
6313
|
-
const { start, end, children } =
|
|
6334
|
+
if (expression.type === "SliceParameters") {
|
|
6335
|
+
const { start, end, children } = expression;
|
|
6314
6336
|
return {
|
|
6315
6337
|
type: "SliceExpression",
|
|
6316
6338
|
start,
|
|
@@ -6324,7 +6346,8 @@ ${input.slice(result.pos)}
|
|
|
6324
6346
|
}
|
|
6325
6347
|
return {
|
|
6326
6348
|
type: "Index",
|
|
6327
|
-
children: $0
|
|
6349
|
+
children: $0,
|
|
6350
|
+
expression
|
|
6328
6351
|
};
|
|
6329
6352
|
});
|
|
6330
6353
|
var MemberBracketContent$1 = $TS($S(Dot, $C(TemplateLiteral, StringLiteral)), function($skip, $loc, $0, $1, $2) {
|
|
@@ -9715,12 +9738,40 @@ ${input.slice(result.pos)}
|
|
|
9715
9738
|
const last = lastAccessInCallExpression(value);
|
|
9716
9739
|
if (!last)
|
|
9717
9740
|
return $skip;
|
|
9718
|
-
let name;
|
|
9719
|
-
|
|
9720
|
-
|
|
9721
|
-
|
|
9722
|
-
|
|
9723
|
-
|
|
9741
|
+
let name, hoistDec, ref, refAssignment;
|
|
9742
|
+
const { expression, type } = last;
|
|
9743
|
+
if (type === "Index") {
|
|
9744
|
+
ref = maybeRef(expression);
|
|
9745
|
+
if (ref !== expression) {
|
|
9746
|
+
hoistDec = {
|
|
9747
|
+
type: "Declaration",
|
|
9748
|
+
children: ["let ", ref]
|
|
9749
|
+
};
|
|
9750
|
+
refAssignment = {
|
|
9751
|
+
type: "Assignment",
|
|
9752
|
+
children: [ref, " = ", expression]
|
|
9753
|
+
};
|
|
9754
|
+
name = {
|
|
9755
|
+
type: "ComputedPropertyName",
|
|
9756
|
+
children: [last.children[0], "(", refAssignment, ",", ref, ")", ...last.children.slice(-2)]
|
|
9757
|
+
};
|
|
9758
|
+
value = {
|
|
9759
|
+
...value,
|
|
9760
|
+
children: value.children.map((c) => {
|
|
9761
|
+
if (c === last)
|
|
9762
|
+
return {
|
|
9763
|
+
type: "Index",
|
|
9764
|
+
children: ["[", ref, "]"]
|
|
9765
|
+
};
|
|
9766
|
+
return c;
|
|
9767
|
+
})
|
|
9768
|
+
};
|
|
9769
|
+
} else {
|
|
9770
|
+
name = {
|
|
9771
|
+
type: "ComputedPropertyName",
|
|
9772
|
+
children: last.children
|
|
9773
|
+
};
|
|
9774
|
+
}
|
|
9724
9775
|
} else {
|
|
9725
9776
|
({ name } = last);
|
|
9726
9777
|
if (!name)
|
|
@@ -9731,7 +9782,8 @@ ${input.slice(result.pos)}
|
|
|
9731
9782
|
children: [ws, name, ": ", value],
|
|
9732
9783
|
name,
|
|
9733
9784
|
value,
|
|
9734
|
-
names: []
|
|
9785
|
+
names: [],
|
|
9786
|
+
hoistDec
|
|
9735
9787
|
};
|
|
9736
9788
|
});
|
|
9737
9789
|
function PropertyDefinition(state) {
|
|
@@ -12879,7 +12931,11 @@ ${input.slice(result.pos)}
|
|
|
12879
12931
|
const initCondition = {
|
|
12880
12932
|
type: "AssignmentExpression",
|
|
12881
12933
|
children: [ref, " ", initializer],
|
|
12882
|
-
hoistDec:
|
|
12934
|
+
hoistDec: {
|
|
12935
|
+
type: "Declaration",
|
|
12936
|
+
children: ["let ", ref],
|
|
12937
|
+
names: []
|
|
12938
|
+
},
|
|
12883
12939
|
blockPrefix: [
|
|
12884
12940
|
["", [binding, "= ", ref, ...splices], ";"],
|
|
12885
12941
|
...thisAssignments
|
|
@@ -23347,6 +23403,7 @@ ${input.slice(result.pos)}
|
|
|
23347
23403
|
lastAccessInCallExpression,
|
|
23348
23404
|
literalValue,
|
|
23349
23405
|
makeLeftHandSideExpression,
|
|
23406
|
+
maybeRef,
|
|
23350
23407
|
modifyString,
|
|
23351
23408
|
processBinaryOpExpression,
|
|
23352
23409
|
processCallMemberExpression,
|