@markw65/monkeyc-optimizer 1.0.42 → 1.0.44
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/README.md +21 -0
- package/build/api.cjs +404 -89
- package/build/optimizer.cjs +260 -49
- package/build/sdk-util.cjs +343 -2
- package/build/src/ast.d.ts +6 -3
- package/build/src/inliner.d.ts +2 -2
- package/build/src/optimizer-types.d.ts +1 -0
- package/build/src/resources.d.ts +3 -4
- package/build/src/worker-pool.d.ts +4 -0
- package/build/src/worker-task.d.ts +29 -0
- package/build/src/xml-util.d.ts +19 -7
- package/build/util.cjs +1 -1
- package/package.json +2 -2
- package/build/src/estree-types.d.ts +0 -324
package/build/api.cjs
CHANGED
|
@@ -466,7 +466,13 @@ function ast_withLoc(node, start, end) {
|
|
|
466
466
|
node.end = start.end;
|
|
467
467
|
node.loc = { ...(node.loc || start.loc), start: start.loc.start };
|
|
468
468
|
}
|
|
469
|
-
if (end
|
|
469
|
+
if (end === false) {
|
|
470
|
+
if (node.loc) {
|
|
471
|
+
node.loc.end = node.loc.start;
|
|
472
|
+
node.end = node.start;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
else if (end && end.loc) {
|
|
470
476
|
node.end = end.end;
|
|
471
477
|
node.loc = { ...(node.loc || end.loc), end: end.loc.end };
|
|
472
478
|
}
|
|
@@ -518,7 +524,9 @@ function ast_getNodeValue(node) {
|
|
|
518
524
|
return [node, "Long"];
|
|
519
525
|
}
|
|
520
526
|
if (type === "string") {
|
|
521
|
-
return
|
|
527
|
+
return node.raw.startsWith("'")
|
|
528
|
+
? [node, "Char"]
|
|
529
|
+
: [node, "String"];
|
|
522
530
|
}
|
|
523
531
|
if (type === "boolean") {
|
|
524
532
|
return [node, "Boolean"];
|
|
@@ -829,6 +837,12 @@ function getArgSafety(state, func, args, requireAll) {
|
|
|
829
837
|
let allSafe = true;
|
|
830
838
|
if (!args.every((arg, i) => {
|
|
831
839
|
switch (arg.type) {
|
|
840
|
+
case "UnaryExpression":
|
|
841
|
+
if (arg.operator === ":") {
|
|
842
|
+
safeArgs.push(true);
|
|
843
|
+
return true;
|
|
844
|
+
}
|
|
845
|
+
break;
|
|
832
846
|
case "Literal":
|
|
833
847
|
safeArgs.push(true);
|
|
834
848
|
return true;
|
|
@@ -1408,7 +1422,16 @@ function inlineWithArgs(state, func, call, context) {
|
|
|
1408
1422
|
withLocDeep(body, context, context, true);
|
|
1409
1423
|
return body;
|
|
1410
1424
|
}
|
|
1411
|
-
function
|
|
1425
|
+
function isTypecheckArg(node, arg) {
|
|
1426
|
+
return (node.type === "CallExpression" &&
|
|
1427
|
+
node.callee.type === "Identifier" &&
|
|
1428
|
+
node.callee.name === ":typecheck" &&
|
|
1429
|
+
(arg === null ||
|
|
1430
|
+
(node.arguments.length === 1 &&
|
|
1431
|
+
node.arguments[0].type === "Literal" &&
|
|
1432
|
+
node.arguments[0].value === arg)));
|
|
1433
|
+
}
|
|
1434
|
+
function inlineFunctionHelper(state, func, call, context) {
|
|
1412
1435
|
if (context) {
|
|
1413
1436
|
return inlineWithArgs(state, func, call, context);
|
|
1414
1437
|
}
|
|
@@ -1419,6 +1442,33 @@ function inliner_inlineFunction(state, func, call, context) {
|
|
|
1419
1442
|
state.localsStack[state.localsStack.length - 1].map = map;
|
|
1420
1443
|
return ret && withLocDeep(ret, call, call, true);
|
|
1421
1444
|
}
|
|
1445
|
+
function inliner_inlineFunction(state, func, call, context) {
|
|
1446
|
+
const ret = inlineFunctionHelper(state, func, call, context);
|
|
1447
|
+
if (!ret)
|
|
1448
|
+
return ret;
|
|
1449
|
+
const typecheckFalse = func.node.attrs?.attributes?.elements.find((attr) => isTypecheckArg(attr, false));
|
|
1450
|
+
if (!typecheckFalse) {
|
|
1451
|
+
return ret;
|
|
1452
|
+
}
|
|
1453
|
+
const callerSn = state.stack.find((sn) => sn.type === "FunctionDeclaration");
|
|
1454
|
+
if (!callerSn) {
|
|
1455
|
+
return ret;
|
|
1456
|
+
}
|
|
1457
|
+
const caller = callerSn.node;
|
|
1458
|
+
if (!caller.attrs) {
|
|
1459
|
+
caller.attrs = withLoc({
|
|
1460
|
+
type: "AttributeList",
|
|
1461
|
+
}, caller, false);
|
|
1462
|
+
}
|
|
1463
|
+
if (!caller.attrs.attributes) {
|
|
1464
|
+
caller.attrs.attributes = withLoc({ type: "Attributes", elements: [] }, caller.attrs, false);
|
|
1465
|
+
}
|
|
1466
|
+
if (caller.attrs.attributes.elements.find((attr) => isTypecheckArg(attr, null))) {
|
|
1467
|
+
return ret;
|
|
1468
|
+
}
|
|
1469
|
+
caller.attrs.attributes.elements.unshift(withLocDeep({ ...typecheckFalse }, caller.attrs, false));
|
|
1470
|
+
return ret;
|
|
1471
|
+
}
|
|
1422
1472
|
function applyTypeIfNeeded(node) {
|
|
1423
1473
|
if ("enumType" in node && node.enumType) {
|
|
1424
1474
|
node = {
|
|
@@ -1574,7 +1624,7 @@ function pragma_checker_pragmaChecker(state, ast, diagnostics) {
|
|
|
1574
1624
|
if (quote == '"') {
|
|
1575
1625
|
return haystack.includes(needle);
|
|
1576
1626
|
}
|
|
1577
|
-
const re = new RegExp(needle.replace(/@([
|
|
1627
|
+
const re = new RegExp(needle.replace(/@([-\d.\w]+|"[^"]*")/g, (_match, pat) => `(?:${pat}|pre_${pat.replace(/[".]/g, "_")}(?:_\\d+)?)`));
|
|
1578
1628
|
return re.test(haystack);
|
|
1579
1629
|
};
|
|
1580
1630
|
next();
|
|
@@ -3524,7 +3574,7 @@ function getLiteralNode(node) {
|
|
|
3524
3574
|
case "-": {
|
|
3525
3575
|
const [arg, type] = ast_getNodeValue(node.argument);
|
|
3526
3576
|
if (type === "Number" || type === "Long") {
|
|
3527
|
-
return replacementLiteral(
|
|
3577
|
+
return replacementLiteral(node, -arg.value, type);
|
|
3528
3578
|
}
|
|
3529
3579
|
}
|
|
3530
3580
|
}
|
|
@@ -3574,8 +3624,14 @@ function isBooleanExpression(state, node) {
|
|
|
3574
3624
|
}
|
|
3575
3625
|
return false;
|
|
3576
3626
|
}
|
|
3627
|
+
function roundToFloat(value) {
|
|
3628
|
+
return new Float32Array([value])[0];
|
|
3629
|
+
}
|
|
3577
3630
|
function replacementLiteral(arg, value, type) {
|
|
3578
|
-
if (
|
|
3631
|
+
if (value === null) {
|
|
3632
|
+
type = "Null";
|
|
3633
|
+
}
|
|
3634
|
+
else if (typeof value === "boolean") {
|
|
3579
3635
|
type = "Boolean";
|
|
3580
3636
|
}
|
|
3581
3637
|
else if (type === "Number") {
|
|
@@ -3584,32 +3640,189 @@ function replacementLiteral(arg, value, type) {
|
|
|
3584
3640
|
else if (type === "Long") {
|
|
3585
3641
|
value = BigInt.asIntN(64, BigInt(value));
|
|
3586
3642
|
}
|
|
3643
|
+
else if (type === "Float") {
|
|
3644
|
+
value = roundToFloat(Number(value));
|
|
3645
|
+
}
|
|
3646
|
+
let raw = type === "String"
|
|
3647
|
+
? JSON.stringify(value)
|
|
3648
|
+
: type === "Char"
|
|
3649
|
+
? value === "'"
|
|
3650
|
+
? "'\\''"
|
|
3651
|
+
: "'" + JSON.stringify(value).slice(1, -1) + "'"
|
|
3652
|
+
: value == null
|
|
3653
|
+
? "null"
|
|
3654
|
+
: value.toString();
|
|
3655
|
+
if (type === "Long") {
|
|
3656
|
+
raw += "l";
|
|
3657
|
+
}
|
|
3658
|
+
else if (type === "Double") {
|
|
3659
|
+
raw += "d";
|
|
3660
|
+
}
|
|
3661
|
+
else if (type === "Float" && prettier_plugin_monkeyc_namespaceObject.LiteralIntegerRe.test(raw)) {
|
|
3662
|
+
raw += "f";
|
|
3663
|
+
}
|
|
3664
|
+
const { start, end, loc } = arg;
|
|
3587
3665
|
return {
|
|
3588
|
-
|
|
3666
|
+
type: "Literal",
|
|
3589
3667
|
value,
|
|
3590
|
-
raw
|
|
3668
|
+
raw,
|
|
3669
|
+
start,
|
|
3670
|
+
end,
|
|
3671
|
+
loc,
|
|
3591
3672
|
};
|
|
3592
3673
|
}
|
|
3674
|
+
function classify(arg) {
|
|
3675
|
+
switch (arg) {
|
|
3676
|
+
case "Number":
|
|
3677
|
+
return { big: false, int: true };
|
|
3678
|
+
case "Long":
|
|
3679
|
+
return { big: true, int: true };
|
|
3680
|
+
case "Float":
|
|
3681
|
+
return { big: false, int: false };
|
|
3682
|
+
case "Double":
|
|
3683
|
+
return { big: true, int: false };
|
|
3684
|
+
}
|
|
3685
|
+
return null;
|
|
3686
|
+
}
|
|
3687
|
+
function common_arith_types(left, right) {
|
|
3688
|
+
const l = classify(left);
|
|
3689
|
+
if (!l)
|
|
3690
|
+
return null;
|
|
3691
|
+
const r = classify(right);
|
|
3692
|
+
if (!r)
|
|
3693
|
+
return null;
|
|
3694
|
+
if (l.big || r.big) {
|
|
3695
|
+
return l.int && r.int
|
|
3696
|
+
? ["Long", (v) => BigInt.asIntN(64, BigInt(v))]
|
|
3697
|
+
: ["Double", (v) => Number(v)];
|
|
3698
|
+
}
|
|
3699
|
+
else {
|
|
3700
|
+
return l.int && r.int
|
|
3701
|
+
? ["Number", (v) => BigInt.asIntN(32, BigInt(v))]
|
|
3702
|
+
: ["Float", (v) => roundToFloat(Number(v))];
|
|
3703
|
+
}
|
|
3704
|
+
}
|
|
3705
|
+
function common_bitwise_types(left, right) {
|
|
3706
|
+
if (left === "Boolean" && right === "Boolean") {
|
|
3707
|
+
return ["Boolean", (v) => (v ? true : false)];
|
|
3708
|
+
}
|
|
3709
|
+
const l = classify(left);
|
|
3710
|
+
if (!l)
|
|
3711
|
+
return null;
|
|
3712
|
+
const r = classify(right);
|
|
3713
|
+
if (!r)
|
|
3714
|
+
return null;
|
|
3715
|
+
if (!l.int || !r.int)
|
|
3716
|
+
return null;
|
|
3717
|
+
return l.big || r.big
|
|
3718
|
+
? ["Long", (v) => BigInt.asIntN(64, BigInt(v))]
|
|
3719
|
+
: ["Number", (v) => Number(BigInt.asIntN(32, BigInt(v)))];
|
|
3720
|
+
}
|
|
3721
|
+
function plus_types(left, right) {
|
|
3722
|
+
if (left === "String" || right === "String") {
|
|
3723
|
+
// Boolean + String is an error, and
|
|
3724
|
+
// Float/Double + String is legal, but its hard to predict
|
|
3725
|
+
// the way the float will be formatted (and it won't match
|
|
3726
|
+
// what javascript would do by default)
|
|
3727
|
+
if (/Float|Double|Boolean/.test(left + right)) {
|
|
3728
|
+
return null;
|
|
3729
|
+
}
|
|
3730
|
+
return ["String", String];
|
|
3731
|
+
}
|
|
3732
|
+
if (left === "Char" || right === "Char") {
|
|
3733
|
+
if (left === right) {
|
|
3734
|
+
// adding two chars produces a string
|
|
3735
|
+
return ["String", String];
|
|
3736
|
+
}
|
|
3737
|
+
if (/Number|Long/.test(left + right)) {
|
|
3738
|
+
return ["Char", (v) => v];
|
|
3739
|
+
}
|
|
3740
|
+
}
|
|
3741
|
+
return common_arith_types(left, right);
|
|
3742
|
+
}
|
|
3743
|
+
function shift_mod_types(left, right) {
|
|
3744
|
+
const result = common_bitwise_types(left, right);
|
|
3745
|
+
if (result && result[0] === "Boolean") {
|
|
3746
|
+
return null;
|
|
3747
|
+
}
|
|
3748
|
+
return result;
|
|
3749
|
+
}
|
|
3593
3750
|
const operators = {
|
|
3594
|
-
"+":
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
"
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
"
|
|
3611
|
-
|
|
3612
|
-
|
|
3751
|
+
"+": {
|
|
3752
|
+
typeFn: plus_types,
|
|
3753
|
+
valueFn: (left, right) => typeof left === "string" && typeof right !== "string"
|
|
3754
|
+
? String.fromCharCode(left.charCodeAt(0) + Number(right))
|
|
3755
|
+
: typeof left !== "string" && typeof right === "string"
|
|
3756
|
+
? String.fromCharCode(right.charCodeAt(0) + Number(left))
|
|
3757
|
+
: left + right,
|
|
3758
|
+
},
|
|
3759
|
+
"-": {
|
|
3760
|
+
typeFn: common_arith_types,
|
|
3761
|
+
valueFn: (left, right) => left - right,
|
|
3762
|
+
},
|
|
3763
|
+
"*": {
|
|
3764
|
+
typeFn: common_arith_types,
|
|
3765
|
+
valueFn: (left, right) => left * right,
|
|
3766
|
+
},
|
|
3767
|
+
"/": {
|
|
3768
|
+
typeFn: common_arith_types,
|
|
3769
|
+
valueFn: (left, right) => left / right,
|
|
3770
|
+
},
|
|
3771
|
+
"%": {
|
|
3772
|
+
typeFn: shift_mod_types,
|
|
3773
|
+
valueFn: (left, right) => left % right,
|
|
3774
|
+
},
|
|
3775
|
+
"&": {
|
|
3776
|
+
typeFn: common_bitwise_types,
|
|
3777
|
+
valueFn: (left, right) => left & right,
|
|
3778
|
+
},
|
|
3779
|
+
"|": {
|
|
3780
|
+
typeFn: common_bitwise_types,
|
|
3781
|
+
valueFn: (left, right) => left | right,
|
|
3782
|
+
},
|
|
3783
|
+
"^": {
|
|
3784
|
+
typeFn: common_bitwise_types,
|
|
3785
|
+
valueFn: (left, right) => left ^ right,
|
|
3786
|
+
},
|
|
3787
|
+
"<<": {
|
|
3788
|
+
typeFn: shift_mod_types,
|
|
3789
|
+
valueFn: (left, right) => typeof right === "bigint"
|
|
3790
|
+
? left << right
|
|
3791
|
+
: left << right,
|
|
3792
|
+
},
|
|
3793
|
+
">>": {
|
|
3794
|
+
typeFn: shift_mod_types,
|
|
3795
|
+
valueFn: (left, right) => typeof right === "bigint"
|
|
3796
|
+
? left >> right
|
|
3797
|
+
: left >> right,
|
|
3798
|
+
},
|
|
3799
|
+
"==": {
|
|
3800
|
+
typeFn: () => ["Boolean", (v) => v],
|
|
3801
|
+
valueFn: (left, right) =>
|
|
3802
|
+
// two string literals will compare unequal, becuase string
|
|
3803
|
+
// equality is object equality.
|
|
3804
|
+
typeof left === "string" ? false : left === right,
|
|
3805
|
+
},
|
|
3806
|
+
"!=": {
|
|
3807
|
+
typeFn: () => ["Boolean", (v) => v],
|
|
3808
|
+
valueFn: (left, right) => typeof left === "string" ? true : left !== right,
|
|
3809
|
+
},
|
|
3810
|
+
"<=": {
|
|
3811
|
+
typeFn: common_arith_types,
|
|
3812
|
+
valueFn: (left, right) => left <= right,
|
|
3813
|
+
},
|
|
3814
|
+
">=": {
|
|
3815
|
+
typeFn: common_arith_types,
|
|
3816
|
+
valueFn: (left, right) => left >= right,
|
|
3817
|
+
},
|
|
3818
|
+
"<": {
|
|
3819
|
+
typeFn: common_arith_types,
|
|
3820
|
+
valueFn: (left, right) => left < right,
|
|
3821
|
+
},
|
|
3822
|
+
">": {
|
|
3823
|
+
typeFn: common_arith_types,
|
|
3824
|
+
valueFn: (left, right) => left > right,
|
|
3825
|
+
},
|
|
3613
3826
|
as: null,
|
|
3614
3827
|
instanceof: null,
|
|
3615
3828
|
has: null,
|
|
@@ -3622,23 +3835,31 @@ function optimizeNode(state, node) {
|
|
|
3622
3835
|
break;
|
|
3623
3836
|
switch (node.operator) {
|
|
3624
3837
|
case "+":
|
|
3625
|
-
if (type === "Number" ||
|
|
3838
|
+
if (type === "Number" ||
|
|
3839
|
+
type === "Long" ||
|
|
3840
|
+
type === "Float" ||
|
|
3841
|
+
type === "Double" ||
|
|
3842
|
+
type === "Char" ||
|
|
3843
|
+
type === "String") {
|
|
3626
3844
|
return arg;
|
|
3627
3845
|
}
|
|
3628
3846
|
break;
|
|
3629
3847
|
case "-":
|
|
3630
|
-
if (type === "Number" ||
|
|
3631
|
-
|
|
3848
|
+
if (type === "Number" ||
|
|
3849
|
+
type === "Long" ||
|
|
3850
|
+
type === "Float" ||
|
|
3851
|
+
type === "Double") {
|
|
3852
|
+
return replacementLiteral(node, -arg.value, type);
|
|
3632
3853
|
}
|
|
3633
3854
|
break;
|
|
3634
3855
|
case "!":
|
|
3635
3856
|
case "~":
|
|
3636
3857
|
{
|
|
3637
3858
|
if (type === "Number" || type === "Long") {
|
|
3638
|
-
return replacementLiteral(
|
|
3859
|
+
return replacementLiteral(node, ~BigInt(arg.value), type);
|
|
3639
3860
|
}
|
|
3640
3861
|
if (type === "Boolean" && node.operator == "!") {
|
|
3641
|
-
return replacementLiteral(
|
|
3862
|
+
return replacementLiteral(node, !arg.value, type);
|
|
3642
3863
|
}
|
|
3643
3864
|
}
|
|
3644
3865
|
break;
|
|
@@ -3652,23 +3873,13 @@ function optimizeNode(state, node) {
|
|
|
3652
3873
|
const [right, right_type] = getNodeValue(node.right);
|
|
3653
3874
|
if (!left || !right)
|
|
3654
3875
|
break;
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
if (node.operator !== "==" && node.operator !== "!=") {
|
|
3660
|
-
break;
|
|
3661
|
-
}
|
|
3662
|
-
value = operators[node.operator](left.value, right.value);
|
|
3663
|
-
type = "Boolean";
|
|
3664
|
-
}
|
|
3665
|
-
else {
|
|
3666
|
-
type = left_type;
|
|
3667
|
-
value = op(BigInt(left.value), BigInt(right.value));
|
|
3668
|
-
}
|
|
3876
|
+
const type = op.typeFn(left_type, right_type);
|
|
3877
|
+
if (!type)
|
|
3878
|
+
break;
|
|
3879
|
+
const value = op.valueFn(type[1](left.value), type[1](right.value));
|
|
3669
3880
|
if (value === null)
|
|
3670
3881
|
break;
|
|
3671
|
-
return replacementLiteral(
|
|
3882
|
+
return replacementLiteral(node, value, type[0]);
|
|
3672
3883
|
}
|
|
3673
3884
|
break;
|
|
3674
3885
|
}
|
|
@@ -4559,6 +4770,8 @@ const external_sdk_util_cjs_namespaceObject = require("./sdk-util.cjs");
|
|
|
4559
4770
|
;// CONCATENATED MODULE: ./src/resources.ts
|
|
4560
4771
|
|
|
4561
4772
|
|
|
4773
|
+
|
|
4774
|
+
|
|
4562
4775
|
/*
|
|
4563
4776
|
* This is unavoidably ad-hoc. Garmin has arbitrary rules for how
|
|
4564
4777
|
* resources can be nested, which we need to mimic here.
|
|
@@ -4711,7 +4924,7 @@ function visit_resources(elements, parent, v) {
|
|
|
4711
4924
|
visitor.post(e);
|
|
4712
4925
|
});
|
|
4713
4926
|
}
|
|
4714
|
-
function add_resources_to_ast(ast, resources, manifestXML) {
|
|
4927
|
+
function add_resources_to_ast(state, ast, resources, manifestXML) {
|
|
4715
4928
|
const modules = {
|
|
4716
4929
|
Drawables: true,
|
|
4717
4930
|
Fonts: true,
|
|
@@ -4748,10 +4961,12 @@ function add_resources_to_ast(ast, resources, manifestXML) {
|
|
|
4748
4961
|
body.push(rez);
|
|
4749
4962
|
const hiddenRez = makeModule("*Rez*");
|
|
4750
4963
|
rez.body.body.push(hiddenRez);
|
|
4751
|
-
if (
|
|
4964
|
+
if (barrel === "" &&
|
|
4965
|
+
manifestXML &&
|
|
4966
|
+
manifestXML.body instanceof external_sdk_util_cjs_namespaceObject.xmlUtil.Nodes) {
|
|
4752
4967
|
manifestXML.body
|
|
4753
4968
|
.children("iq:application")
|
|
4754
|
-
.elements.forEach((e) => add_one_resource(rez, e));
|
|
4969
|
+
.elements.forEach((e) => add_one_resource(state, manifestXML, rez, e));
|
|
4755
4970
|
}
|
|
4756
4971
|
const rezModules = Object.fromEntries(Object.entries(modules).map(([moduleName, isPublic]) => {
|
|
4757
4972
|
const module = makeModule(moduleName);
|
|
@@ -4767,7 +4982,7 @@ function add_resources_to_ast(ast, resources, manifestXML) {
|
|
|
4767
4982
|
if (!ast_hasProperty(rezModules, s))
|
|
4768
4983
|
return;
|
|
4769
4984
|
const module = rezModules[s];
|
|
4770
|
-
add_one_resource(module, e);
|
|
4985
|
+
add_one_resource(state, rez, module, e);
|
|
4771
4986
|
});
|
|
4772
4987
|
});
|
|
4773
4988
|
});
|
|
@@ -4785,7 +5000,7 @@ function makeMemberExpression(object, property) {
|
|
|
4785
5000
|
}
|
|
4786
5001
|
function makeScopedName(dotted, l) {
|
|
4787
5002
|
const loc = l && adjustLoc(l, 0, l.start.offset - l.end.offset);
|
|
4788
|
-
return dotted.split(
|
|
5003
|
+
return dotted.split(/\s*\.\s*/).reduce(({ cur, offset }, next) => {
|
|
4789
5004
|
const id = makeIdentifier(next, loc && adjustLoc(loc, offset, offset + next.length));
|
|
4790
5005
|
if (!cur) {
|
|
4791
5006
|
cur = id;
|
|
@@ -4797,44 +5012,144 @@ function makeScopedName(dotted, l) {
|
|
|
4797
5012
|
return { cur, offset };
|
|
4798
5013
|
}, { cur: null, offset: 0 }).cur;
|
|
4799
5014
|
}
|
|
4800
|
-
|
|
5015
|
+
const drawableSkips = {
|
|
5016
|
+
x: { center: true, left: true, right: true, start: true },
|
|
5017
|
+
y: { center: true, top: true, bottom: true, start: true },
|
|
5018
|
+
width: { fill: true },
|
|
5019
|
+
height: { fill: true },
|
|
5020
|
+
a: { fill: true },
|
|
5021
|
+
b: { fill: true },
|
|
5022
|
+
color: {},
|
|
5023
|
+
corner_radius: {},
|
|
5024
|
+
radius: {},
|
|
5025
|
+
border_width: {},
|
|
5026
|
+
border_color: {},
|
|
5027
|
+
foreground: {},
|
|
5028
|
+
background: {},
|
|
5029
|
+
font: {},
|
|
5030
|
+
justification: {},
|
|
5031
|
+
};
|
|
5032
|
+
function addPositions(base, pos) {
|
|
5033
|
+
const result = { ...base };
|
|
5034
|
+
if (pos.line > 1) {
|
|
5035
|
+
result.line += pos.line - 1;
|
|
5036
|
+
result.column = pos.column;
|
|
5037
|
+
}
|
|
5038
|
+
else {
|
|
5039
|
+
result.column += pos.column - 1;
|
|
5040
|
+
}
|
|
5041
|
+
result.offset += pos.offset;
|
|
5042
|
+
return result;
|
|
5043
|
+
}
|
|
5044
|
+
function visit_resource_refs(state, doc, e) {
|
|
4801
5045
|
const result = [];
|
|
4802
|
-
const
|
|
4803
|
-
|
|
4804
|
-
|
|
4805
|
-
|
|
4806
|
-
let offset = 0;
|
|
4807
|
-
if (match[1]) {
|
|
4808
|
-
offset = 1;
|
|
5046
|
+
const parseArg = (name, loc, skip) => {
|
|
5047
|
+
if (name.startsWith("@")) {
|
|
5048
|
+
name = name.substring(1);
|
|
5049
|
+
loc = adjustLoc(loc, 1, 0);
|
|
4809
5050
|
}
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
// nothing to do
|
|
5051
|
+
if (ast_hasProperty(skip, name)) {
|
|
5052
|
+
return;
|
|
4813
5053
|
}
|
|
4814
|
-
|
|
5054
|
+
if (/^([\w_$]+\s*\.\s*)*[\w_$]+$/.test(name)) {
|
|
5055
|
+
const dn = makeScopedName(name, loc);
|
|
5056
|
+
if (dn)
|
|
5057
|
+
result.push(dn);
|
|
4815
5058
|
return;
|
|
4816
5059
|
}
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
|
|
5060
|
+
// We wrap the expression in parentheses, so adjust
|
|
5061
|
+
// the start position by 1 character to compensate
|
|
5062
|
+
// for the opening '('
|
|
5063
|
+
const startPos = adjustLoc(loc, -1, 0).start;
|
|
5064
|
+
try {
|
|
5065
|
+
const expr = prettier_plugin_monkeyc_default().parsers.monkeyc.parse(`(${name})`, null, {
|
|
5066
|
+
filepath: loc.source || undefined,
|
|
5067
|
+
singleExpression: true,
|
|
5068
|
+
});
|
|
5069
|
+
ast_traverseAst(expr, (node) => {
|
|
5070
|
+
if (node.loc) {
|
|
5071
|
+
node.loc = {
|
|
5072
|
+
source: node.loc.source,
|
|
5073
|
+
start: addPositions(startPos, node.loc.start),
|
|
5074
|
+
end: addPositions(startPos, node.loc.end),
|
|
5075
|
+
};
|
|
5076
|
+
node.start = (node.start || 0) + startPos.offset;
|
|
5077
|
+
node.end = (node.end || 0) + startPos.offset;
|
|
5078
|
+
}
|
|
5079
|
+
});
|
|
5080
|
+
result.push(expr);
|
|
5081
|
+
}
|
|
5082
|
+
catch (ex) {
|
|
5083
|
+
if (state) {
|
|
5084
|
+
const check = state.config?.checkInvalidSymbols;
|
|
5085
|
+
if (check !== "OFF" && ex instanceof Error) {
|
|
5086
|
+
const error = ex;
|
|
5087
|
+
if (error.location) {
|
|
5088
|
+
const location = {
|
|
5089
|
+
source: error.location.source,
|
|
5090
|
+
start: addPositions(startPos, error.location.start),
|
|
5091
|
+
end: addPositions(startPos, error.location.end),
|
|
5092
|
+
};
|
|
5093
|
+
inliner_diagnostic(state, location, ex.message, check || "WARNING");
|
|
5094
|
+
}
|
|
5095
|
+
}
|
|
5096
|
+
}
|
|
5097
|
+
}
|
|
4820
5098
|
};
|
|
4821
|
-
|
|
4822
|
-
|
|
4823
|
-
|
|
4824
|
-
|
|
4825
|
-
|
|
4826
|
-
|
|
4827
|
-
|
|
4828
|
-
|
|
4829
|
-
|
|
4830
|
-
|
|
4831
|
-
if (
|
|
4832
|
-
|
|
4833
|
-
|
|
4834
|
-
|
|
5099
|
+
const stringToScopedName = (element, id, dotted, l) => {
|
|
5100
|
+
dotted = doc.processRefs(dotted);
|
|
5101
|
+
if (dotted.startsWith("@")) {
|
|
5102
|
+
return parseArg(dotted, l);
|
|
5103
|
+
}
|
|
5104
|
+
if (/^\s*(true|false|null|NaN|(0x|#)[0-9a-f]+|[-+]?\d+%?)\s*$/i.test(dotted)) {
|
|
5105
|
+
return;
|
|
5106
|
+
}
|
|
5107
|
+
switch (element.name) {
|
|
5108
|
+
case "param":
|
|
5109
|
+
if (id === null) {
|
|
5110
|
+
parseArg(dotted, l);
|
|
5111
|
+
}
|
|
5112
|
+
return;
|
|
5113
|
+
case "drawable":
|
|
5114
|
+
if (id === "class") {
|
|
5115
|
+
parseArg(dotted, l);
|
|
4835
5116
|
}
|
|
4836
5117
|
return;
|
|
5118
|
+
case "shape":
|
|
5119
|
+
case "bitmap":
|
|
5120
|
+
case "drawable-list":
|
|
5121
|
+
case "text-area":
|
|
5122
|
+
case "label":
|
|
5123
|
+
if (id && ast_hasProperty(drawableSkips, id)) {
|
|
5124
|
+
parseArg(dotted, l, drawableSkips[id]);
|
|
5125
|
+
}
|
|
5126
|
+
return;
|
|
5127
|
+
case "iq:application":
|
|
5128
|
+
if (id === "entry") {
|
|
5129
|
+
parseArg(dotted, l);
|
|
5130
|
+
}
|
|
5131
|
+
return;
|
|
5132
|
+
default:
|
|
5133
|
+
return;
|
|
5134
|
+
}
|
|
5135
|
+
};
|
|
5136
|
+
external_sdk_util_cjs_namespaceObject.xmlUtil.visit_xml([e], {
|
|
5137
|
+
pre(node) {
|
|
5138
|
+
if (node.type !== "element")
|
|
5139
|
+
return false;
|
|
5140
|
+
Object.values(node.attr).forEach((attr) => {
|
|
5141
|
+
if (!attr || !attr.value.loc)
|
|
5142
|
+
return;
|
|
5143
|
+
const loc = adjustLoc(attr.value.loc);
|
|
5144
|
+
attr &&
|
|
5145
|
+
stringToScopedName(node, attr.name.value, attr.value.value, loc);
|
|
5146
|
+
});
|
|
5147
|
+
const content = doc.textContent(node);
|
|
5148
|
+
if (content) {
|
|
5149
|
+
stringToScopedName(node, null, content, locRange(node.children[0].loc, node.children[node.children.length - 1].loc));
|
|
5150
|
+
return false;
|
|
4837
5151
|
}
|
|
5152
|
+
return;
|
|
4838
5153
|
},
|
|
4839
5154
|
});
|
|
4840
5155
|
return result;
|
|
@@ -4870,7 +5185,7 @@ function adjustLoc(loc, start = 1, end = -1) {
|
|
|
4870
5185
|
},
|
|
4871
5186
|
};
|
|
4872
5187
|
}
|
|
4873
|
-
function add_one_resource(module, e) {
|
|
5188
|
+
function add_one_resource(state, doc, module, e) {
|
|
4874
5189
|
let id;
|
|
4875
5190
|
let func;
|
|
4876
5191
|
const varDecl = () => {
|
|
@@ -4883,24 +5198,24 @@ function add_one_resource(module, e) {
|
|
|
4883
5198
|
kind: "var",
|
|
4884
5199
|
id: makeIdentifier(id ? id.value.value : "*invalid*", loc),
|
|
4885
5200
|
init,
|
|
4886
|
-
}, loc),
|
|
5201
|
+
}, e.loc),
|
|
4887
5202
|
],
|
|
4888
5203
|
kind: "var",
|
|
4889
|
-
}, loc);
|
|
5204
|
+
}, e.loc);
|
|
4890
5205
|
};
|
|
4891
5206
|
const classDecl = (parent) => {
|
|
4892
5207
|
if (!id)
|
|
4893
5208
|
return null;
|
|
4894
5209
|
const loc = id.value.loc;
|
|
4895
5210
|
const items = init
|
|
4896
|
-
? [{ type: "ClassElement", item: varDecl(), loc }]
|
|
5211
|
+
? [{ type: "ClassElement", item: varDecl(), loc: e.loc }]
|
|
4897
5212
|
: [];
|
|
4898
5213
|
return {
|
|
4899
5214
|
type: "ClassDeclaration",
|
|
4900
|
-
body: { type: "ClassBody", body: items, loc },
|
|
5215
|
+
body: { type: "ClassBody", body: items, loc: e.loc },
|
|
4901
5216
|
id: makeIdentifier(id.value.value, loc),
|
|
4902
5217
|
superClass: makeScopedName(parent),
|
|
4903
|
-
loc,
|
|
5218
|
+
loc: e.loc,
|
|
4904
5219
|
};
|
|
4905
5220
|
};
|
|
4906
5221
|
switch (e.name) {
|
|
@@ -4942,7 +5257,7 @@ function add_one_resource(module, e) {
|
|
|
4942
5257
|
}
|
|
4943
5258
|
if (!func)
|
|
4944
5259
|
return;
|
|
4945
|
-
const elements = visit_resource_refs(e);
|
|
5260
|
+
const elements = visit_resource_refs(state, doc, e);
|
|
4946
5261
|
const init = elements.length
|
|
4947
5262
|
? { type: "ArrayExpression", elements }
|
|
4948
5263
|
: undefined;
|
|
@@ -5178,7 +5493,7 @@ async function api_getApiMapping(state, resourcesMap, manifestXML) {
|
|
|
5178
5493
|
const rezAst = state
|
|
5179
5494
|
? state.rezAst || { type: "Program", body: [] }
|
|
5180
5495
|
: ast;
|
|
5181
|
-
add_resources_to_ast(rezAst, resourcesMap, manifestXML);
|
|
5496
|
+
add_resources_to_ast(state, rezAst, resourcesMap, manifestXML);
|
|
5182
5497
|
if (state) {
|
|
5183
5498
|
state.rezAst = rezAst;
|
|
5184
5499
|
state.manifestXML = manifestXML;
|