@danielx/civet 0.11.8 → 0.11.9
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 +11 -0
- package/dist/browser.js +59 -34
- package/dist/browser.min.js +1 -1
- package/dist/main.js +57 -22
- package/dist/main.mjs +57 -22
- package/dist/ts-service/index.js.map +2 -2
- package/dist/ts-service/index.mjs.map +2 -2
- package/package.json +6 -12
package/dist/main.js
CHANGED
|
@@ -504,6 +504,7 @@ __export(lib_exports, {
|
|
|
504
504
|
braceBlock: () => braceBlock,
|
|
505
505
|
bracedBlock: () => bracedBlock,
|
|
506
506
|
buildExportSplitClause: () => buildExportSplitClause,
|
|
507
|
+
canExpressionizeIfAsTernary: () => canExpressionizeIfAsTernary,
|
|
507
508
|
convertArrowFunctionToMethod: () => convertArrowFunctionToMethod,
|
|
508
509
|
convertFunctionToMethod: () => convertFunctionToMethod,
|
|
509
510
|
convertNamedImportsToObject: () => convertNamedImportsToObject,
|
|
@@ -950,12 +951,13 @@ function prepend(prefix, node) {
|
|
|
950
951
|
}
|
|
951
952
|
if (Array.isArray(node)) {
|
|
952
953
|
return [prefix, ...node];
|
|
953
|
-
} else {
|
|
954
|
-
assert(isParent(node), "prepend: can't glom into an AST leaf");
|
|
954
|
+
} else if (isParent(node)) {
|
|
955
955
|
return {
|
|
956
956
|
...node,
|
|
957
957
|
children: [prefix, ...node.children]
|
|
958
958
|
};
|
|
959
|
+
} else {
|
|
960
|
+
return [prefix, node];
|
|
959
961
|
}
|
|
960
962
|
}
|
|
961
963
|
function append(node, suffix) {
|
|
@@ -5680,6 +5682,9 @@ function prependStatementExpressionBlock(initializer, statement) {
|
|
|
5680
5682
|
return;
|
|
5681
5683
|
}
|
|
5682
5684
|
const statementExp = exp.statement;
|
|
5685
|
+
if (statementExp.type === "IfStatement" && canExpressionizeIfAsTernary(statementExp)) {
|
|
5686
|
+
return;
|
|
5687
|
+
}
|
|
5683
5688
|
const blockStatement = [ws || "", statementExp, ";"];
|
|
5684
5689
|
const pre = [blockStatement];
|
|
5685
5690
|
let ref;
|
|
@@ -7462,6 +7467,25 @@ function expressionizeBlock(blockOrExpression) {
|
|
|
7462
7467
|
return blockOrExpression;
|
|
7463
7468
|
}
|
|
7464
7469
|
}
|
|
7470
|
+
function canExpressionizeIfAsTernary(statement) {
|
|
7471
|
+
const { then: b, else: e } = statement;
|
|
7472
|
+
return canExpressionizeBlock(b) && (e ? canExpressionizeBlock(e.block) : true);
|
|
7473
|
+
}
|
|
7474
|
+
function canExpressionizeBlock(blockOrExpression) {
|
|
7475
|
+
if (blockOrExpression && typeof blockOrExpression === "object" && "expressions" in blockOrExpression) {
|
|
7476
|
+
const { expressions } = blockOrExpression;
|
|
7477
|
+
let results1 = true;
|
|
7478
|
+
for (const [, s] of expressions) {
|
|
7479
|
+
if (!isExpression(s)) {
|
|
7480
|
+
results1 = false;
|
|
7481
|
+
break;
|
|
7482
|
+
}
|
|
7483
|
+
}
|
|
7484
|
+
return results1;
|
|
7485
|
+
}
|
|
7486
|
+
;
|
|
7487
|
+
return;
|
|
7488
|
+
}
|
|
7465
7489
|
function expressionizeIfStatement(statement) {
|
|
7466
7490
|
const { condition, then: b, else: e } = statement;
|
|
7467
7491
|
const [...condRest] = condition.children, [closeParen] = condRest.splice(-1);
|
|
@@ -8596,11 +8620,11 @@ function attachPostfixStatementAsExpression(exp, post) {
|
|
|
8596
8620
|
}
|
|
8597
8621
|
}
|
|
8598
8622
|
function processTypes(node) {
|
|
8599
|
-
const
|
|
8623
|
+
const results2 = [];
|
|
8600
8624
|
for (let ref22 = gatherRecursiveAll(node, ($13) => $13.type === "TypeUnary"), i12 = 0, len11 = ref22.length; i12 < len11; i12++) {
|
|
8601
8625
|
const unary = ref22[i12];
|
|
8602
8626
|
let suffixIndex = unary.suffix.length - 1;
|
|
8603
|
-
const
|
|
8627
|
+
const results3 = [];
|
|
8604
8628
|
while (suffixIndex >= 0) {
|
|
8605
8629
|
const suffix = unary.suffix[suffixIndex];
|
|
8606
8630
|
if (typeof suffix === "object" && suffix != null && "token" in suffix && suffix.token === "?") {
|
|
@@ -8660,7 +8684,7 @@ function processTypes(node) {
|
|
|
8660
8684
|
children: [prefix, replace, outer]
|
|
8661
8685
|
});
|
|
8662
8686
|
}
|
|
8663
|
-
|
|
8687
|
+
results3.push(replaceNode(unary, replace, parent));
|
|
8664
8688
|
} else if (typeof suffix === "object" && suffix != null && "type" in suffix && suffix.type === "NonNullAssertion") {
|
|
8665
8689
|
const {} = suffix;
|
|
8666
8690
|
let m7;
|
|
@@ -8715,15 +8739,15 @@ function processTypes(node) {
|
|
|
8715
8739
|
children: [prefix, replace, outer]
|
|
8716
8740
|
});
|
|
8717
8741
|
}
|
|
8718
|
-
|
|
8742
|
+
results3.push(replaceNode(unary, replace, parent));
|
|
8719
8743
|
} else {
|
|
8720
|
-
|
|
8744
|
+
results3.push(suffixIndex--);
|
|
8721
8745
|
}
|
|
8722
8746
|
}
|
|
8723
|
-
|
|
8747
|
+
results2.push(results3);
|
|
8724
8748
|
}
|
|
8725
8749
|
;
|
|
8726
|
-
return
|
|
8750
|
+
return results2;
|
|
8727
8751
|
}
|
|
8728
8752
|
function processStatementExpressions(statements) {
|
|
8729
8753
|
for (let ref24 = gatherRecursiveAll(statements, ($14) => $14.type === "StatementExpression"), i13 = 0, len12 = ref24.length; i13 < len12; i13++) {
|
|
@@ -8908,12 +8932,12 @@ function processCoffeeClasses(statements) {
|
|
|
8908
8932
|
index + 1,
|
|
8909
8933
|
0,
|
|
8910
8934
|
...(() => {
|
|
8911
|
-
const
|
|
8935
|
+
const results4 = [];
|
|
8912
8936
|
for (let i16 = 0, len15 = autoBinds.length; i16 < len15; i16++) {
|
|
8913
8937
|
const [, a] = autoBinds[i16];
|
|
8914
|
-
|
|
8938
|
+
results4.push([indent, ["this.", a.name, " = this.", a.name, ".bind(this)"], ";"]);
|
|
8915
8939
|
}
|
|
8916
|
-
return
|
|
8940
|
+
return results4;
|
|
8917
8941
|
})()
|
|
8918
8942
|
);
|
|
8919
8943
|
}
|
|
@@ -17558,11 +17582,12 @@ function PropertyAccess$5($$ctx, $$state) {
|
|
|
17558
17582
|
optional: modifier?.token === "?"
|
|
17559
17583
|
};
|
|
17560
17584
|
if (id) {
|
|
17585
|
+
const access = id.unicode ? ["prototype[", propertyKey(id), "]"] : ["prototype.", id];
|
|
17561
17586
|
return {
|
|
17562
17587
|
type: "PropertyAccess",
|
|
17563
17588
|
name: id.name,
|
|
17564
17589
|
dot: start,
|
|
17565
|
-
children: [start,
|
|
17590
|
+
children: [start, ...access]
|
|
17566
17591
|
};
|
|
17567
17592
|
} else {
|
|
17568
17593
|
return {
|
|
@@ -17686,10 +17711,11 @@ function PropertyBind($$ctx, $$state) {
|
|
|
17686
17711
|
var dot = $3;
|
|
17687
17712
|
var id = $4;
|
|
17688
17713
|
var args = $5;
|
|
17714
|
+
const children = id.unicode ? [modifier, modifier?.token === "?" ? dot : null, "[", propertyKey(id), "]"] : [modifier, dot, id];
|
|
17689
17715
|
return {
|
|
17690
17716
|
type: "PropertyBind",
|
|
17691
17717
|
name: id.name,
|
|
17692
|
-
children
|
|
17718
|
+
children,
|
|
17693
17719
|
// omit `@` from children
|
|
17694
17720
|
args: args?.children.slice(1, -1) ?? []
|
|
17695
17721
|
// remove the parens from the arg list, or give an empty list
|
|
@@ -17725,10 +17751,11 @@ function PropertyBindExplicitArguments($$ctx, $$state) {
|
|
|
17725
17751
|
var dot = $3;
|
|
17726
17752
|
var id = $4;
|
|
17727
17753
|
var args = $5;
|
|
17754
|
+
const children = id.unicode ? [modifier, modifier?.token === "?" ? dot : null, "[", propertyKey(id), "]"] : [modifier, dot, id];
|
|
17728
17755
|
return {
|
|
17729
17756
|
type: "PropertyBind",
|
|
17730
17757
|
name: id.name,
|
|
17731
|
-
children
|
|
17758
|
+
children,
|
|
17732
17759
|
// omit `@` from children
|
|
17733
17760
|
args: args?.children.slice(1, -1) ?? []
|
|
17734
17761
|
// remove the parens from the arg list, or give an empty list
|
|
@@ -21874,9 +21901,16 @@ function SymbolLiteral($$ctx, $$state) {
|
|
|
21874
21901
|
const $$m = (function($skip, $loc, $0, $1, $2) {
|
|
21875
21902
|
var colon = $1;
|
|
21876
21903
|
var id = $2;
|
|
21877
|
-
let name, token;
|
|
21904
|
+
let name, token, quoted;
|
|
21878
21905
|
if (id.type === "Identifier") {
|
|
21879
|
-
(
|
|
21906
|
+
if (id.unicode) {
|
|
21907
|
+
name = id.unicode;
|
|
21908
|
+
token = { $loc: id.children?.[0]?.$loc, token: `"${id.unicode}"` };
|
|
21909
|
+
quoted = true;
|
|
21910
|
+
} else {
|
|
21911
|
+
({ name, children: [token] } = id);
|
|
21912
|
+
quoted = false;
|
|
21913
|
+
}
|
|
21880
21914
|
} else {
|
|
21881
21915
|
name = literalValue({
|
|
21882
21916
|
type: "Literal",
|
|
@@ -21885,17 +21919,18 @@ function SymbolLiteral($$ctx, $$state) {
|
|
|
21885
21919
|
children: [id]
|
|
21886
21920
|
});
|
|
21887
21921
|
token = id;
|
|
21922
|
+
quoted = true;
|
|
21888
21923
|
}
|
|
21889
21924
|
if (config.symbols.includes(name)) {
|
|
21890
21925
|
return {
|
|
21891
21926
|
type: "SymbolLiteral",
|
|
21892
|
-
children:
|
|
21893
|
-
{ ...colon, token: "Symbol." },
|
|
21894
|
-
token
|
|
21895
|
-
] : [
|
|
21927
|
+
children: quoted ? [
|
|
21896
21928
|
{ ...colon, token: "Symbol[" },
|
|
21897
21929
|
token,
|
|
21898
21930
|
"]"
|
|
21931
|
+
] : [
|
|
21932
|
+
{ ...colon, token: "Symbol." },
|
|
21933
|
+
token
|
|
21899
21934
|
],
|
|
21900
21935
|
name
|
|
21901
21936
|
};
|
|
@@ -21904,7 +21939,7 @@ function SymbolLiteral($$ctx, $$state) {
|
|
|
21904
21939
|
type: "SymbolLiteral",
|
|
21905
21940
|
children: [
|
|
21906
21941
|
{ ...colon, token: "Symbol.for(" },
|
|
21907
|
-
|
|
21942
|
+
quoted ? token : ['"', token, '"'],
|
|
21908
21943
|
")"
|
|
21909
21944
|
],
|
|
21910
21945
|
name
|
package/dist/main.mjs
CHANGED
|
@@ -483,6 +483,7 @@ __export(lib_exports, {
|
|
|
483
483
|
braceBlock: () => braceBlock,
|
|
484
484
|
bracedBlock: () => bracedBlock,
|
|
485
485
|
buildExportSplitClause: () => buildExportSplitClause,
|
|
486
|
+
canExpressionizeIfAsTernary: () => canExpressionizeIfAsTernary,
|
|
486
487
|
convertArrowFunctionToMethod: () => convertArrowFunctionToMethod,
|
|
487
488
|
convertFunctionToMethod: () => convertFunctionToMethod,
|
|
488
489
|
convertNamedImportsToObject: () => convertNamedImportsToObject,
|
|
@@ -929,12 +930,13 @@ function prepend(prefix, node) {
|
|
|
929
930
|
}
|
|
930
931
|
if (Array.isArray(node)) {
|
|
931
932
|
return [prefix, ...node];
|
|
932
|
-
} else {
|
|
933
|
-
assert(isParent(node), "prepend: can't glom into an AST leaf");
|
|
933
|
+
} else if (isParent(node)) {
|
|
934
934
|
return {
|
|
935
935
|
...node,
|
|
936
936
|
children: [prefix, ...node.children]
|
|
937
937
|
};
|
|
938
|
+
} else {
|
|
939
|
+
return [prefix, node];
|
|
938
940
|
}
|
|
939
941
|
}
|
|
940
942
|
function append(node, suffix) {
|
|
@@ -5659,6 +5661,9 @@ function prependStatementExpressionBlock(initializer, statement) {
|
|
|
5659
5661
|
return;
|
|
5660
5662
|
}
|
|
5661
5663
|
const statementExp = exp.statement;
|
|
5664
|
+
if (statementExp.type === "IfStatement" && canExpressionizeIfAsTernary(statementExp)) {
|
|
5665
|
+
return;
|
|
5666
|
+
}
|
|
5662
5667
|
const blockStatement = [ws || "", statementExp, ";"];
|
|
5663
5668
|
const pre = [blockStatement];
|
|
5664
5669
|
let ref;
|
|
@@ -7441,6 +7446,25 @@ function expressionizeBlock(blockOrExpression) {
|
|
|
7441
7446
|
return blockOrExpression;
|
|
7442
7447
|
}
|
|
7443
7448
|
}
|
|
7449
|
+
function canExpressionizeIfAsTernary(statement) {
|
|
7450
|
+
const { then: b, else: e } = statement;
|
|
7451
|
+
return canExpressionizeBlock(b) && (e ? canExpressionizeBlock(e.block) : true);
|
|
7452
|
+
}
|
|
7453
|
+
function canExpressionizeBlock(blockOrExpression) {
|
|
7454
|
+
if (blockOrExpression && typeof blockOrExpression === "object" && "expressions" in blockOrExpression) {
|
|
7455
|
+
const { expressions } = blockOrExpression;
|
|
7456
|
+
let results1 = true;
|
|
7457
|
+
for (const [, s] of expressions) {
|
|
7458
|
+
if (!isExpression(s)) {
|
|
7459
|
+
results1 = false;
|
|
7460
|
+
break;
|
|
7461
|
+
}
|
|
7462
|
+
}
|
|
7463
|
+
return results1;
|
|
7464
|
+
}
|
|
7465
|
+
;
|
|
7466
|
+
return;
|
|
7467
|
+
}
|
|
7444
7468
|
function expressionizeIfStatement(statement) {
|
|
7445
7469
|
const { condition, then: b, else: e } = statement;
|
|
7446
7470
|
const [...condRest] = condition.children, [closeParen] = condRest.splice(-1);
|
|
@@ -8575,11 +8599,11 @@ function attachPostfixStatementAsExpression(exp, post) {
|
|
|
8575
8599
|
}
|
|
8576
8600
|
}
|
|
8577
8601
|
function processTypes(node) {
|
|
8578
|
-
const
|
|
8602
|
+
const results2 = [];
|
|
8579
8603
|
for (let ref22 = gatherRecursiveAll(node, ($13) => $13.type === "TypeUnary"), i12 = 0, len11 = ref22.length; i12 < len11; i12++) {
|
|
8580
8604
|
const unary = ref22[i12];
|
|
8581
8605
|
let suffixIndex = unary.suffix.length - 1;
|
|
8582
|
-
const
|
|
8606
|
+
const results3 = [];
|
|
8583
8607
|
while (suffixIndex >= 0) {
|
|
8584
8608
|
const suffix = unary.suffix[suffixIndex];
|
|
8585
8609
|
if (typeof suffix === "object" && suffix != null && "token" in suffix && suffix.token === "?") {
|
|
@@ -8639,7 +8663,7 @@ function processTypes(node) {
|
|
|
8639
8663
|
children: [prefix, replace, outer]
|
|
8640
8664
|
});
|
|
8641
8665
|
}
|
|
8642
|
-
|
|
8666
|
+
results3.push(replaceNode(unary, replace, parent));
|
|
8643
8667
|
} else if (typeof suffix === "object" && suffix != null && "type" in suffix && suffix.type === "NonNullAssertion") {
|
|
8644
8668
|
const {} = suffix;
|
|
8645
8669
|
let m7;
|
|
@@ -8694,15 +8718,15 @@ function processTypes(node) {
|
|
|
8694
8718
|
children: [prefix, replace, outer]
|
|
8695
8719
|
});
|
|
8696
8720
|
}
|
|
8697
|
-
|
|
8721
|
+
results3.push(replaceNode(unary, replace, parent));
|
|
8698
8722
|
} else {
|
|
8699
|
-
|
|
8723
|
+
results3.push(suffixIndex--);
|
|
8700
8724
|
}
|
|
8701
8725
|
}
|
|
8702
|
-
|
|
8726
|
+
results2.push(results3);
|
|
8703
8727
|
}
|
|
8704
8728
|
;
|
|
8705
|
-
return
|
|
8729
|
+
return results2;
|
|
8706
8730
|
}
|
|
8707
8731
|
function processStatementExpressions(statements) {
|
|
8708
8732
|
for (let ref24 = gatherRecursiveAll(statements, ($14) => $14.type === "StatementExpression"), i13 = 0, len12 = ref24.length; i13 < len12; i13++) {
|
|
@@ -8887,12 +8911,12 @@ function processCoffeeClasses(statements) {
|
|
|
8887
8911
|
index + 1,
|
|
8888
8912
|
0,
|
|
8889
8913
|
...(() => {
|
|
8890
|
-
const
|
|
8914
|
+
const results4 = [];
|
|
8891
8915
|
for (let i16 = 0, len15 = autoBinds.length; i16 < len15; i16++) {
|
|
8892
8916
|
const [, a] = autoBinds[i16];
|
|
8893
|
-
|
|
8917
|
+
results4.push([indent, ["this.", a.name, " = this.", a.name, ".bind(this)"], ";"]);
|
|
8894
8918
|
}
|
|
8895
|
-
return
|
|
8919
|
+
return results4;
|
|
8896
8920
|
})()
|
|
8897
8921
|
);
|
|
8898
8922
|
}
|
|
@@ -17537,11 +17561,12 @@ function PropertyAccess$5($$ctx, $$state) {
|
|
|
17537
17561
|
optional: modifier?.token === "?"
|
|
17538
17562
|
};
|
|
17539
17563
|
if (id) {
|
|
17564
|
+
const access = id.unicode ? ["prototype[", propertyKey(id), "]"] : ["prototype.", id];
|
|
17540
17565
|
return {
|
|
17541
17566
|
type: "PropertyAccess",
|
|
17542
17567
|
name: id.name,
|
|
17543
17568
|
dot: start,
|
|
17544
|
-
children: [start,
|
|
17569
|
+
children: [start, ...access]
|
|
17545
17570
|
};
|
|
17546
17571
|
} else {
|
|
17547
17572
|
return {
|
|
@@ -17665,10 +17690,11 @@ function PropertyBind($$ctx, $$state) {
|
|
|
17665
17690
|
var dot = $3;
|
|
17666
17691
|
var id = $4;
|
|
17667
17692
|
var args = $5;
|
|
17693
|
+
const children = id.unicode ? [modifier, modifier?.token === "?" ? dot : null, "[", propertyKey(id), "]"] : [modifier, dot, id];
|
|
17668
17694
|
return {
|
|
17669
17695
|
type: "PropertyBind",
|
|
17670
17696
|
name: id.name,
|
|
17671
|
-
children
|
|
17697
|
+
children,
|
|
17672
17698
|
// omit `@` from children
|
|
17673
17699
|
args: args?.children.slice(1, -1) ?? []
|
|
17674
17700
|
// remove the parens from the arg list, or give an empty list
|
|
@@ -17704,10 +17730,11 @@ function PropertyBindExplicitArguments($$ctx, $$state) {
|
|
|
17704
17730
|
var dot = $3;
|
|
17705
17731
|
var id = $4;
|
|
17706
17732
|
var args = $5;
|
|
17733
|
+
const children = id.unicode ? [modifier, modifier?.token === "?" ? dot : null, "[", propertyKey(id), "]"] : [modifier, dot, id];
|
|
17707
17734
|
return {
|
|
17708
17735
|
type: "PropertyBind",
|
|
17709
17736
|
name: id.name,
|
|
17710
|
-
children
|
|
17737
|
+
children,
|
|
17711
17738
|
// omit `@` from children
|
|
17712
17739
|
args: args?.children.slice(1, -1) ?? []
|
|
17713
17740
|
// remove the parens from the arg list, or give an empty list
|
|
@@ -21853,9 +21880,16 @@ function SymbolLiteral($$ctx, $$state) {
|
|
|
21853
21880
|
const $$m = (function($skip, $loc, $0, $1, $2) {
|
|
21854
21881
|
var colon = $1;
|
|
21855
21882
|
var id = $2;
|
|
21856
|
-
let name, token;
|
|
21883
|
+
let name, token, quoted;
|
|
21857
21884
|
if (id.type === "Identifier") {
|
|
21858
|
-
(
|
|
21885
|
+
if (id.unicode) {
|
|
21886
|
+
name = id.unicode;
|
|
21887
|
+
token = { $loc: id.children?.[0]?.$loc, token: `"${id.unicode}"` };
|
|
21888
|
+
quoted = true;
|
|
21889
|
+
} else {
|
|
21890
|
+
({ name, children: [token] } = id);
|
|
21891
|
+
quoted = false;
|
|
21892
|
+
}
|
|
21859
21893
|
} else {
|
|
21860
21894
|
name = literalValue({
|
|
21861
21895
|
type: "Literal",
|
|
@@ -21864,17 +21898,18 @@ function SymbolLiteral($$ctx, $$state) {
|
|
|
21864
21898
|
children: [id]
|
|
21865
21899
|
});
|
|
21866
21900
|
token = id;
|
|
21901
|
+
quoted = true;
|
|
21867
21902
|
}
|
|
21868
21903
|
if (config.symbols.includes(name)) {
|
|
21869
21904
|
return {
|
|
21870
21905
|
type: "SymbolLiteral",
|
|
21871
|
-
children:
|
|
21872
|
-
{ ...colon, token: "Symbol." },
|
|
21873
|
-
token
|
|
21874
|
-
] : [
|
|
21906
|
+
children: quoted ? [
|
|
21875
21907
|
{ ...colon, token: "Symbol[" },
|
|
21876
21908
|
token,
|
|
21877
21909
|
"]"
|
|
21910
|
+
] : [
|
|
21911
|
+
{ ...colon, token: "Symbol." },
|
|
21912
|
+
token
|
|
21878
21913
|
],
|
|
21879
21914
|
name
|
|
21880
21915
|
};
|
|
@@ -21883,7 +21918,7 @@ function SymbolLiteral($$ctx, $$state) {
|
|
|
21883
21918
|
type: "SymbolLiteral",
|
|
21884
21919
|
children: [
|
|
21885
21920
|
{ ...colon, token: "Symbol.for(" },
|
|
21886
|
-
|
|
21921
|
+
quoted ? token : ['"', token, '"'],
|
|
21887
21922
|
")"
|
|
21888
21923
|
],
|
|
21889
21924
|
name
|