@danielx/civet 0.6.2 → 0.6.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/dist/browser.js +50 -17
- package/dist/main.js +50 -17
- package/dist/main.mjs +50 -17
- package/package.json +1 -1
package/dist/browser.js
CHANGED
|
@@ -43,6 +43,17 @@ var Civet = (() => {
|
|
|
43
43
|
p.children.push(": ", ref);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
+
function arrayElementHasTrailingComma(elementNode) {
|
|
47
|
+
const { children } = elementNode, { length } = children;
|
|
48
|
+
const lastChild = children[length - 1];
|
|
49
|
+
if (lastChild) {
|
|
50
|
+
const l2 = lastChild.length;
|
|
51
|
+
if (lastChild[l2 - 1]?.token === ",") {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
46
57
|
function blockWithPrefix(prefixStatements, block) {
|
|
47
58
|
if (prefixStatements && prefixStatements.length) {
|
|
48
59
|
const indent = getIndent(block.expressions[0]);
|
|
@@ -185,7 +196,7 @@ var Civet = (() => {
|
|
|
185
196
|
function hoistRefDecs(statements) {
|
|
186
197
|
gatherRecursiveAll(statements, (s) => s.hoistDec).forEach((node) => {
|
|
187
198
|
const { hoistDec } = node;
|
|
188
|
-
|
|
199
|
+
let outer = closest(node, ["IfStatement", "IterationStatement"]);
|
|
189
200
|
if (!outer) {
|
|
190
201
|
node.children.push({
|
|
191
202
|
type: "Error",
|
|
@@ -193,7 +204,11 @@ var Civet = (() => {
|
|
|
193
204
|
});
|
|
194
205
|
return;
|
|
195
206
|
}
|
|
196
|
-
|
|
207
|
+
let block = outer.parent;
|
|
208
|
+
if (block.type === "PatternMatchingStatement") {
|
|
209
|
+
outer = block;
|
|
210
|
+
block = block.parent;
|
|
211
|
+
}
|
|
197
212
|
const { expressions } = block;
|
|
198
213
|
const index = expressions.findIndex(([, s]) => outer === s);
|
|
199
214
|
if (index < 0)
|
|
@@ -621,6 +636,7 @@ var Civet = (() => {
|
|
|
621
636
|
}
|
|
622
637
|
module.exports = {
|
|
623
638
|
aliasBinding,
|
|
639
|
+
arrayElementHasTrailingComma,
|
|
624
640
|
blockWithPrefix,
|
|
625
641
|
clone,
|
|
626
642
|
convertMethodToFunction,
|
|
@@ -19273,7 +19289,10 @@ ${input.slice(result.pos)}
|
|
|
19273
19289
|
var dots = $2;
|
|
19274
19290
|
if (!dots)
|
|
19275
19291
|
return type;
|
|
19276
|
-
|
|
19292
|
+
const ws = getTrimmingSpace(type);
|
|
19293
|
+
if (!ws)
|
|
19294
|
+
return [dots[1], dots[0], type];
|
|
19295
|
+
return [ws, dots[1], dots[0], insertTrimmingSpace(type, "")];
|
|
19277
19296
|
});
|
|
19278
19297
|
function TypeElement(state) {
|
|
19279
19298
|
let eventData;
|
|
@@ -21435,20 +21454,27 @@ ${input.slice(result.pos)}
|
|
|
21435
21454
|
module.wrapIIFE = (exp, async) => {
|
|
21436
21455
|
let prefix, suffix;
|
|
21437
21456
|
if (async) {
|
|
21438
|
-
prefix = "(async ()=>
|
|
21439
|
-
suffix = "
|
|
21457
|
+
prefix = "(async ()=>";
|
|
21458
|
+
suffix = ")()";
|
|
21440
21459
|
} else if (hasAwait(exp)) {
|
|
21441
|
-
prefix = "(await (async ()=>
|
|
21442
|
-
suffix = "
|
|
21443
|
-
} else {
|
|
21444
|
-
prefix = "(()=>{";
|
|
21445
|
-
suffix = "})()";
|
|
21446
|
-
}
|
|
21447
|
-
if (Array.isArray(exp)) {
|
|
21448
|
-
return [prefix, ...exp, suffix];
|
|
21460
|
+
prefix = "(await (async ()=>";
|
|
21461
|
+
suffix = ")())";
|
|
21449
21462
|
} else {
|
|
21450
|
-
|
|
21463
|
+
prefix = "(()=>";
|
|
21464
|
+
suffix = ")()";
|
|
21451
21465
|
}
|
|
21466
|
+
const expressions = Array.isArray(exp) ? [[...exp]] : [exp];
|
|
21467
|
+
const block = {
|
|
21468
|
+
type: "BlockStatement",
|
|
21469
|
+
expressions,
|
|
21470
|
+
children: ["{", expressions, "}"],
|
|
21471
|
+
bare: false
|
|
21472
|
+
};
|
|
21473
|
+
return [
|
|
21474
|
+
prefix,
|
|
21475
|
+
block,
|
|
21476
|
+
suffix
|
|
21477
|
+
];
|
|
21452
21478
|
};
|
|
21453
21479
|
function wrapIterationReturningResults(statement, outerRef) {
|
|
21454
21480
|
if (statement.type === "DoStatement") {
|
|
@@ -21905,10 +21931,13 @@ ${input.slice(result.pos)}
|
|
|
21905
21931
|
const after = elements.slice(restIndex + 1);
|
|
21906
21932
|
const restIdentifier = rest.binding.ref || rest.binding;
|
|
21907
21933
|
names.push(...rest.names || []);
|
|
21908
|
-
|
|
21934
|
+
let l = after.length;
|
|
21935
|
+
if (l) {
|
|
21936
|
+
if (arrayElementHasTrailingComma(after[l - 1]))
|
|
21937
|
+
l++;
|
|
21909
21938
|
blockPrefix = {
|
|
21910
21939
|
type: "PostRestBindingElements",
|
|
21911
|
-
children: ["[", insertTrimmingSpace(after, ""), "] = ", restIdentifier, ".splice(-",
|
|
21940
|
+
children: ["[", insertTrimmingSpace(after, ""), "] = ", restIdentifier, ".splice(-", l.toString(), ")"],
|
|
21912
21941
|
names: after.flatMap((p) => p.names)
|
|
21913
21942
|
};
|
|
21914
21943
|
}
|
|
@@ -22541,6 +22570,7 @@ ${input.slice(result.pos)}
|
|
|
22541
22570
|
expression = expression.expression;
|
|
22542
22571
|
}
|
|
22543
22572
|
let ref = module.needsRef(expression, "m") || expression;
|
|
22573
|
+
let hoistDec = ref !== expression ? [["", ["const ", ref, " = ", expression], ";"]] : void 0;
|
|
22544
22574
|
let prev = [], root = prev;
|
|
22545
22575
|
const l = clauses.length;
|
|
22546
22576
|
clauses.forEach((c, i) => {
|
|
@@ -22603,8 +22633,10 @@ ${input.slice(result.pos)}
|
|
|
22603
22633
|
type: "IfStatement",
|
|
22604
22634
|
children: ["if", condition, block, next],
|
|
22605
22635
|
then: block,
|
|
22606
|
-
else: next
|
|
22636
|
+
else: next,
|
|
22637
|
+
hoistDec
|
|
22607
22638
|
}]);
|
|
22639
|
+
hoistDec = void 0;
|
|
22608
22640
|
prev = next;
|
|
22609
22641
|
});
|
|
22610
22642
|
if (module.config.implicitReturns && s.type === "SwitchExpression") {
|
|
@@ -23284,6 +23316,7 @@ ${input.slice(result.pos)}
|
|
|
23284
23316
|
exports.default = { parse: parse2 };
|
|
23285
23317
|
var {
|
|
23286
23318
|
aliasBinding,
|
|
23319
|
+
arrayElementHasTrailingComma,
|
|
23287
23320
|
blockWithPrefix,
|
|
23288
23321
|
clone,
|
|
23289
23322
|
convertMethodToFunction,
|
package/dist/main.js
CHANGED
|
@@ -42,6 +42,17 @@ var require_lib = __commonJS({
|
|
|
42
42
|
p.children.push(": ", ref);
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
+
function arrayElementHasTrailingComma(elementNode) {
|
|
46
|
+
const { children } = elementNode, { length } = children;
|
|
47
|
+
const lastChild = children[length - 1];
|
|
48
|
+
if (lastChild) {
|
|
49
|
+
const l2 = lastChild.length;
|
|
50
|
+
if (lastChild[l2 - 1]?.token === ",") {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
45
56
|
function blockWithPrefix(prefixStatements, block) {
|
|
46
57
|
if (prefixStatements && prefixStatements.length) {
|
|
47
58
|
const indent = getIndent(block.expressions[0]);
|
|
@@ -184,7 +195,7 @@ var require_lib = __commonJS({
|
|
|
184
195
|
function hoistRefDecs(statements) {
|
|
185
196
|
gatherRecursiveAll(statements, (s) => s.hoistDec).forEach((node) => {
|
|
186
197
|
const { hoistDec } = node;
|
|
187
|
-
|
|
198
|
+
let outer = closest(node, ["IfStatement", "IterationStatement"]);
|
|
188
199
|
if (!outer) {
|
|
189
200
|
node.children.push({
|
|
190
201
|
type: "Error",
|
|
@@ -192,7 +203,11 @@ var require_lib = __commonJS({
|
|
|
192
203
|
});
|
|
193
204
|
return;
|
|
194
205
|
}
|
|
195
|
-
|
|
206
|
+
let block = outer.parent;
|
|
207
|
+
if (block.type === "PatternMatchingStatement") {
|
|
208
|
+
outer = block;
|
|
209
|
+
block = block.parent;
|
|
210
|
+
}
|
|
196
211
|
const { expressions } = block;
|
|
197
212
|
const index = expressions.findIndex(([, s]) => outer === s);
|
|
198
213
|
if (index < 0)
|
|
@@ -620,6 +635,7 @@ var require_lib = __commonJS({
|
|
|
620
635
|
}
|
|
621
636
|
module2.exports = {
|
|
622
637
|
aliasBinding,
|
|
638
|
+
arrayElementHasTrailingComma,
|
|
623
639
|
blockWithPrefix,
|
|
624
640
|
clone,
|
|
625
641
|
convertMethodToFunction,
|
|
@@ -19272,7 +19288,10 @@ ${input.slice(result.pos)}
|
|
|
19272
19288
|
var dots = $2;
|
|
19273
19289
|
if (!dots)
|
|
19274
19290
|
return type;
|
|
19275
|
-
|
|
19291
|
+
const ws = getTrimmingSpace(type);
|
|
19292
|
+
if (!ws)
|
|
19293
|
+
return [dots[1], dots[0], type];
|
|
19294
|
+
return [ws, dots[1], dots[0], insertTrimmingSpace(type, "")];
|
|
19276
19295
|
});
|
|
19277
19296
|
function TypeElement(state) {
|
|
19278
19297
|
let eventData;
|
|
@@ -21434,20 +21453,27 @@ ${input.slice(result.pos)}
|
|
|
21434
21453
|
module2.wrapIIFE = (exp, async) => {
|
|
21435
21454
|
let prefix, suffix;
|
|
21436
21455
|
if (async) {
|
|
21437
|
-
prefix = "(async ()=>
|
|
21438
|
-
suffix = "
|
|
21456
|
+
prefix = "(async ()=>";
|
|
21457
|
+
suffix = ")()";
|
|
21439
21458
|
} else if (hasAwait(exp)) {
|
|
21440
|
-
prefix = "(await (async ()=>
|
|
21441
|
-
suffix = "
|
|
21442
|
-
} else {
|
|
21443
|
-
prefix = "(()=>{";
|
|
21444
|
-
suffix = "})()";
|
|
21445
|
-
}
|
|
21446
|
-
if (Array.isArray(exp)) {
|
|
21447
|
-
return [prefix, ...exp, suffix];
|
|
21459
|
+
prefix = "(await (async ()=>";
|
|
21460
|
+
suffix = ")())";
|
|
21448
21461
|
} else {
|
|
21449
|
-
|
|
21462
|
+
prefix = "(()=>";
|
|
21463
|
+
suffix = ")()";
|
|
21450
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
|
+
];
|
|
21451
21477
|
};
|
|
21452
21478
|
function wrapIterationReturningResults(statement, outerRef) {
|
|
21453
21479
|
if (statement.type === "DoStatement") {
|
|
@@ -21904,10 +21930,13 @@ ${input.slice(result.pos)}
|
|
|
21904
21930
|
const after = elements.slice(restIndex + 1);
|
|
21905
21931
|
const restIdentifier = rest.binding.ref || rest.binding;
|
|
21906
21932
|
names.push(...rest.names || []);
|
|
21907
|
-
|
|
21933
|
+
let l = after.length;
|
|
21934
|
+
if (l) {
|
|
21935
|
+
if (arrayElementHasTrailingComma(after[l - 1]))
|
|
21936
|
+
l++;
|
|
21908
21937
|
blockPrefix = {
|
|
21909
21938
|
type: "PostRestBindingElements",
|
|
21910
|
-
children: ["[", insertTrimmingSpace(after, ""), "] = ", restIdentifier, ".splice(-",
|
|
21939
|
+
children: ["[", insertTrimmingSpace(after, ""), "] = ", restIdentifier, ".splice(-", l.toString(), ")"],
|
|
21911
21940
|
names: after.flatMap((p) => p.names)
|
|
21912
21941
|
};
|
|
21913
21942
|
}
|
|
@@ -22540,6 +22569,7 @@ ${input.slice(result.pos)}
|
|
|
22540
22569
|
expression = expression.expression;
|
|
22541
22570
|
}
|
|
22542
22571
|
let ref = module2.needsRef(expression, "m") || expression;
|
|
22572
|
+
let hoistDec = ref !== expression ? [["", ["const ", ref, " = ", expression], ";"]] : void 0;
|
|
22543
22573
|
let prev = [], root = prev;
|
|
22544
22574
|
const l = clauses.length;
|
|
22545
22575
|
clauses.forEach((c, i) => {
|
|
@@ -22602,8 +22632,10 @@ ${input.slice(result.pos)}
|
|
|
22602
22632
|
type: "IfStatement",
|
|
22603
22633
|
children: ["if", condition, block, next],
|
|
22604
22634
|
then: block,
|
|
22605
|
-
else: next
|
|
22635
|
+
else: next,
|
|
22636
|
+
hoistDec
|
|
22606
22637
|
}]);
|
|
22638
|
+
hoistDec = void 0;
|
|
22607
22639
|
prev = next;
|
|
22608
22640
|
});
|
|
22609
22641
|
if (module2.config.implicitReturns && s.type === "SwitchExpression") {
|
|
@@ -23283,6 +23315,7 @@ ${input.slice(result.pos)}
|
|
|
23283
23315
|
exports.default = { parse: parse2 };
|
|
23284
23316
|
var {
|
|
23285
23317
|
aliasBinding,
|
|
23318
|
+
arrayElementHasTrailingComma,
|
|
23286
23319
|
blockWithPrefix,
|
|
23287
23320
|
clone,
|
|
23288
23321
|
convertMethodToFunction,
|
package/dist/main.mjs
CHANGED
|
@@ -40,6 +40,17 @@ var require_lib = __commonJS({
|
|
|
40
40
|
p.children.push(": ", ref);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
+
function arrayElementHasTrailingComma(elementNode) {
|
|
44
|
+
const { children } = elementNode, { length } = children;
|
|
45
|
+
const lastChild = children[length - 1];
|
|
46
|
+
if (lastChild) {
|
|
47
|
+
const l2 = lastChild.length;
|
|
48
|
+
if (lastChild[l2 - 1]?.token === ",") {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
43
54
|
function blockWithPrefix(prefixStatements, block) {
|
|
44
55
|
if (prefixStatements && prefixStatements.length) {
|
|
45
56
|
const indent = getIndent(block.expressions[0]);
|
|
@@ -182,7 +193,7 @@ var require_lib = __commonJS({
|
|
|
182
193
|
function hoistRefDecs(statements) {
|
|
183
194
|
gatherRecursiveAll(statements, (s) => s.hoistDec).forEach((node) => {
|
|
184
195
|
const { hoistDec } = node;
|
|
185
|
-
|
|
196
|
+
let outer = closest(node, ["IfStatement", "IterationStatement"]);
|
|
186
197
|
if (!outer) {
|
|
187
198
|
node.children.push({
|
|
188
199
|
type: "Error",
|
|
@@ -190,7 +201,11 @@ var require_lib = __commonJS({
|
|
|
190
201
|
});
|
|
191
202
|
return;
|
|
192
203
|
}
|
|
193
|
-
|
|
204
|
+
let block = outer.parent;
|
|
205
|
+
if (block.type === "PatternMatchingStatement") {
|
|
206
|
+
outer = block;
|
|
207
|
+
block = block.parent;
|
|
208
|
+
}
|
|
194
209
|
const { expressions } = block;
|
|
195
210
|
const index = expressions.findIndex(([, s]) => outer === s);
|
|
196
211
|
if (index < 0)
|
|
@@ -618,6 +633,7 @@ var require_lib = __commonJS({
|
|
|
618
633
|
}
|
|
619
634
|
module.exports = {
|
|
620
635
|
aliasBinding,
|
|
636
|
+
arrayElementHasTrailingComma,
|
|
621
637
|
blockWithPrefix,
|
|
622
638
|
clone,
|
|
623
639
|
convertMethodToFunction,
|
|
@@ -19270,7 +19286,10 @@ ${input.slice(result.pos)}
|
|
|
19270
19286
|
var dots = $2;
|
|
19271
19287
|
if (!dots)
|
|
19272
19288
|
return type;
|
|
19273
|
-
|
|
19289
|
+
const ws = getTrimmingSpace(type);
|
|
19290
|
+
if (!ws)
|
|
19291
|
+
return [dots[1], dots[0], type];
|
|
19292
|
+
return [ws, dots[1], dots[0], insertTrimmingSpace(type, "")];
|
|
19274
19293
|
});
|
|
19275
19294
|
function TypeElement(state) {
|
|
19276
19295
|
let eventData;
|
|
@@ -21432,20 +21451,27 @@ ${input.slice(result.pos)}
|
|
|
21432
21451
|
module.wrapIIFE = (exp, async) => {
|
|
21433
21452
|
let prefix, suffix;
|
|
21434
21453
|
if (async) {
|
|
21435
|
-
prefix = "(async ()=>
|
|
21436
|
-
suffix = "
|
|
21454
|
+
prefix = "(async ()=>";
|
|
21455
|
+
suffix = ")()";
|
|
21437
21456
|
} else if (hasAwait(exp)) {
|
|
21438
|
-
prefix = "(await (async ()=>
|
|
21439
|
-
suffix = "
|
|
21440
|
-
} else {
|
|
21441
|
-
prefix = "(()=>{";
|
|
21442
|
-
suffix = "})()";
|
|
21443
|
-
}
|
|
21444
|
-
if (Array.isArray(exp)) {
|
|
21445
|
-
return [prefix, ...exp, suffix];
|
|
21457
|
+
prefix = "(await (async ()=>";
|
|
21458
|
+
suffix = ")())";
|
|
21446
21459
|
} else {
|
|
21447
|
-
|
|
21460
|
+
prefix = "(()=>";
|
|
21461
|
+
suffix = ")()";
|
|
21448
21462
|
}
|
|
21463
|
+
const expressions = Array.isArray(exp) ? [[...exp]] : [exp];
|
|
21464
|
+
const block = {
|
|
21465
|
+
type: "BlockStatement",
|
|
21466
|
+
expressions,
|
|
21467
|
+
children: ["{", expressions, "}"],
|
|
21468
|
+
bare: false
|
|
21469
|
+
};
|
|
21470
|
+
return [
|
|
21471
|
+
prefix,
|
|
21472
|
+
block,
|
|
21473
|
+
suffix
|
|
21474
|
+
];
|
|
21449
21475
|
};
|
|
21450
21476
|
function wrapIterationReturningResults(statement, outerRef) {
|
|
21451
21477
|
if (statement.type === "DoStatement") {
|
|
@@ -21902,10 +21928,13 @@ ${input.slice(result.pos)}
|
|
|
21902
21928
|
const after = elements.slice(restIndex + 1);
|
|
21903
21929
|
const restIdentifier = rest.binding.ref || rest.binding;
|
|
21904
21930
|
names.push(...rest.names || []);
|
|
21905
|
-
|
|
21931
|
+
let l = after.length;
|
|
21932
|
+
if (l) {
|
|
21933
|
+
if (arrayElementHasTrailingComma(after[l - 1]))
|
|
21934
|
+
l++;
|
|
21906
21935
|
blockPrefix = {
|
|
21907
21936
|
type: "PostRestBindingElements",
|
|
21908
|
-
children: ["[", insertTrimmingSpace(after, ""), "] = ", restIdentifier, ".splice(-",
|
|
21937
|
+
children: ["[", insertTrimmingSpace(after, ""), "] = ", restIdentifier, ".splice(-", l.toString(), ")"],
|
|
21909
21938
|
names: after.flatMap((p) => p.names)
|
|
21910
21939
|
};
|
|
21911
21940
|
}
|
|
@@ -22538,6 +22567,7 @@ ${input.slice(result.pos)}
|
|
|
22538
22567
|
expression = expression.expression;
|
|
22539
22568
|
}
|
|
22540
22569
|
let ref = module.needsRef(expression, "m") || expression;
|
|
22570
|
+
let hoistDec = ref !== expression ? [["", ["const ", ref, " = ", expression], ";"]] : void 0;
|
|
22541
22571
|
let prev = [], root = prev;
|
|
22542
22572
|
const l = clauses.length;
|
|
22543
22573
|
clauses.forEach((c, i) => {
|
|
@@ -22600,8 +22630,10 @@ ${input.slice(result.pos)}
|
|
|
22600
22630
|
type: "IfStatement",
|
|
22601
22631
|
children: ["if", condition, block, next],
|
|
22602
22632
|
then: block,
|
|
22603
|
-
else: next
|
|
22633
|
+
else: next,
|
|
22634
|
+
hoistDec
|
|
22604
22635
|
}]);
|
|
22636
|
+
hoistDec = void 0;
|
|
22605
22637
|
prev = next;
|
|
22606
22638
|
});
|
|
22607
22639
|
if (module.config.implicitReturns && s.type === "SwitchExpression") {
|
|
@@ -23281,6 +23313,7 @@ ${input.slice(result.pos)}
|
|
|
23281
23313
|
exports.default = { parse: parse2 };
|
|
23282
23314
|
var {
|
|
23283
23315
|
aliasBinding,
|
|
23316
|
+
arrayElementHasTrailingComma,
|
|
23284
23317
|
blockWithPrefix,
|
|
23285
23318
|
clone,
|
|
23286
23319
|
convertMethodToFunction,
|