@markw65/monkeyc-optimizer 1.0.40 → 1.0.42
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 +22 -0
- package/build/api.cjs +439 -196
- package/build/optimizer.cjs +284 -207
- package/build/sdk-util.cjs +44 -10
- package/build/src/api.d.ts +4 -2
- package/build/src/jungles.d.ts +6 -1
- package/build/src/mc-rewrite.d.ts +3 -2
- package/build/src/optimizer-types.d.ts +3 -0
- package/build/src/optimizer.d.ts +6 -5
- package/build/src/resources.d.ts +11 -3
- package/build/src/util.d.ts +7 -2
- package/build/src/visitor.d.ts +1 -1
- package/build/src/xml-util.d.ts +32 -12
- package/build/util.cjs +6941 -3141
- package/package.json +4 -4
package/build/api.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
0 && (module.exports = {checkCompilerVersion,collectNamespaces,findUsingForNode,formatAst,getApiFunctionInfo,getApiMapping,hasProperty,isLookupCandidate,isStateNode,markInvokeClassMethod,parseSdkVersion,sameLookupResult,traverseAst,variableDeclarationName,visitReferences,visitorNode});
|
|
1
|
+
0 && (module.exports = {checkCompilerVersion,collectNamespaces,findUsingForNode,formatAst,getApiFunctionInfo,getApiMapping,hasProperty,isLookupCandidate,isStateNode,markInvokeClassMethod,parseSdkVersion,sameLookupResult,traverseAst,variableDeclarationName,visitReferences,visit_resources,visitorNode});
|
|
2
2
|
/******/ (() => { // webpackBootstrap
|
|
3
3
|
/******/ var __webpack_modules__ = ({
|
|
4
4
|
|
|
5
|
-
/***/
|
|
5
|
+
/***/ 2789:
|
|
6
6
|
/***/ ((module) => {
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -273,6 +273,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
273
273
|
"traverseAst": () => (/* reexport */ ast_traverseAst),
|
|
274
274
|
"variableDeclarationName": () => (/* binding */ api_variableDeclarationName),
|
|
275
275
|
"visitReferences": () => (/* reexport */ visitor_visitReferences),
|
|
276
|
+
"visit_resources": () => (/* reexport */ visit_resources),
|
|
276
277
|
"visitorNode": () => (/* reexport */ visitorNode)
|
|
277
278
|
});
|
|
278
279
|
|
|
@@ -2158,7 +2159,7 @@ function getPreOrder(head) {
|
|
|
2158
2159
|
}
|
|
2159
2160
|
|
|
2160
2161
|
// EXTERNAL MODULE: ./node_modules/priorityqueuejs/index.js
|
|
2161
|
-
var priorityqueuejs = __webpack_require__(
|
|
2162
|
+
var priorityqueuejs = __webpack_require__(2789);
|
|
2162
2163
|
;// CONCATENATED MODULE: ./src/pre.ts
|
|
2163
2164
|
|
|
2164
2165
|
|
|
@@ -3338,7 +3339,7 @@ function getFileASTs(fnMap) {
|
|
|
3338
3339
|
return ok;
|
|
3339
3340
|
}, true));
|
|
3340
3341
|
}
|
|
3341
|
-
async function analyze(fnMap, resourcesMap, config) {
|
|
3342
|
+
async function analyze(fnMap, resourcesMap, manifestXML, config) {
|
|
3342
3343
|
let hasTests = false;
|
|
3343
3344
|
let markApi = true;
|
|
3344
3345
|
const preState = {
|
|
@@ -3401,7 +3402,7 @@ async function analyze(fnMap, resourcesMap, config) {
|
|
|
3401
3402
|
return null;
|
|
3402
3403
|
},
|
|
3403
3404
|
};
|
|
3404
|
-
await getApiMapping(preState, resourcesMap);
|
|
3405
|
+
await getApiMapping(preState, resourcesMap, manifestXML);
|
|
3405
3406
|
markApi = false;
|
|
3406
3407
|
const state = preState;
|
|
3407
3408
|
await getFileASTs(fnMap);
|
|
@@ -3431,13 +3432,12 @@ function reportMissingSymbols(state, config) {
|
|
|
3431
3432
|
if (diagnosticType &&
|
|
3432
3433
|
!config?.compilerOptions?.includes("--Eno-invalid-symbol")) {
|
|
3433
3434
|
const checkTypes = config?.typeCheckLevel && config.typeCheckLevel !== "Off";
|
|
3434
|
-
|
|
3435
|
-
visitReferences(state,
|
|
3435
|
+
const report = (ast) => {
|
|
3436
|
+
visitReferences(state, ast, null, false, (node, results, error) => {
|
|
3436
3437
|
if (node.type === "BinaryExpression" && node.operator === "has") {
|
|
3437
3438
|
// Its not an error to check whether a property exists...
|
|
3438
3439
|
return undefined;
|
|
3439
3440
|
}
|
|
3440
|
-
const nodeStr = formatAst(node);
|
|
3441
3441
|
if (!error) {
|
|
3442
3442
|
if (state.sdkVersion === 4001006 &&
|
|
3443
3443
|
compiler2DiagnosticType &&
|
|
@@ -3460,19 +3460,22 @@ function reportMissingSymbols(state, config) {
|
|
|
3460
3460
|
return false;
|
|
3461
3461
|
});
|
|
3462
3462
|
})) {
|
|
3463
|
-
diagnostic(state, node.loc, `The expression ${
|
|
3463
|
+
diagnostic(state, node.loc, `The expression ${formatAst(node)} will fail at runtime using sdk-4.1.6`, compiler2DiagnosticType);
|
|
3464
3464
|
}
|
|
3465
3465
|
return undefined;
|
|
3466
3466
|
}
|
|
3467
|
+
let nodeStr;
|
|
3467
3468
|
if (state.inType) {
|
|
3468
|
-
if (!checkTypes || nodeStr.match(/^Void|Null$/)) {
|
|
3469
|
+
if (!checkTypes || (nodeStr = formatAst(node)).match(/^Void|Null$/)) {
|
|
3469
3470
|
return undefined;
|
|
3470
3471
|
}
|
|
3471
3472
|
}
|
|
3472
|
-
diagnostic(state, node.loc, `Undefined symbol ${nodeStr}`, diagnosticType);
|
|
3473
|
+
diagnostic(state, node.loc, `Undefined symbol ${nodeStr || formatAst(node)}`, diagnosticType);
|
|
3473
3474
|
return false;
|
|
3474
3475
|
});
|
|
3475
|
-
}
|
|
3476
|
+
};
|
|
3477
|
+
Object.values(state.fnMap).forEach((v) => v.ast && report(v.ast));
|
|
3478
|
+
state.rezAst && report(state.rezAst);
|
|
3476
3479
|
}
|
|
3477
3480
|
}
|
|
3478
3481
|
function compareLiteralLike(a, b) {
|
|
@@ -3769,8 +3772,8 @@ function markFunctionCalled(state, func) {
|
|
|
3769
3772
|
}
|
|
3770
3773
|
pushUnique(state.calledFunctions[func.id.name], func);
|
|
3771
3774
|
}
|
|
3772
|
-
async function optimizeMonkeyC(fnMap, resourcesMap, config) {
|
|
3773
|
-
const state = (await analyze(fnMap, resourcesMap, config));
|
|
3775
|
+
async function optimizeMonkeyC(fnMap, resourcesMap, manifestXML, config) {
|
|
3776
|
+
const state = (await analyze(fnMap, resourcesMap, manifestXML, config));
|
|
3774
3777
|
state.localsStack = [{}];
|
|
3775
3778
|
state.calledFunctions = {};
|
|
3776
3779
|
state.usedByName = {};
|
|
@@ -4560,198 +4563,397 @@ const external_sdk_util_cjs_namespaceObject = require("./sdk-util.cjs");
|
|
|
4560
4563
|
* This is unavoidably ad-hoc. Garmin has arbitrary rules for how
|
|
4561
4564
|
* resources can be nested, which we need to mimic here.
|
|
4562
4565
|
*/
|
|
4563
|
-
function visit_resources(elements, parent,
|
|
4566
|
+
function visit_resources(elements, parent, v) {
|
|
4567
|
+
const visitor = typeof v === "function"
|
|
4568
|
+
? {
|
|
4569
|
+
visit: v,
|
|
4570
|
+
}
|
|
4571
|
+
: v;
|
|
4572
|
+
const pname = parent ? parent.name : null;
|
|
4573
|
+
const error = (e) => visitor.error && visitor.error(e, pname);
|
|
4574
|
+
const visit = (e, module) => visitor.visit && visitor.visit(e, module, parent);
|
|
4564
4575
|
elements.forEach((e) => {
|
|
4565
|
-
|
|
4566
|
-
|
|
4567
|
-
// another resources), and any of their contents
|
|
4568
|
-
case "resources":
|
|
4569
|
-
if (parent) {
|
|
4570
|
-
error(e, parent);
|
|
4571
|
-
return;
|
|
4572
|
-
}
|
|
4573
|
-
visit_resources(external_sdk_util_cjs_namespaceObject.xmlUtil.elementKids(e), "resources", visitor, error);
|
|
4574
|
-
return;
|
|
4575
|
-
// Each of these is a list that can contain certain kinds of resource.
|
|
4576
|
-
// They can only occur at the top level, or under a <resources> list.
|
|
4577
|
-
case "strings":
|
|
4578
|
-
case "fonts":
|
|
4579
|
-
case "animations":
|
|
4580
|
-
case "bitmaps":
|
|
4581
|
-
case "layouts":
|
|
4582
|
-
case "menus":
|
|
4583
|
-
case "drawables":
|
|
4584
|
-
case "properties":
|
|
4585
|
-
case "settings":
|
|
4586
|
-
case "fitContributions":
|
|
4587
|
-
case "jsonDataResources":
|
|
4588
|
-
case "complications":
|
|
4589
|
-
if (parent && parent !== "resources") {
|
|
4590
|
-
error(e, parent);
|
|
4591
|
-
return;
|
|
4592
|
-
}
|
|
4593
|
-
visit_resources(external_sdk_util_cjs_namespaceObject.xmlUtil.elementKids(e), e.name, visitor, error);
|
|
4594
|
-
return;
|
|
4595
|
-
// These are the resources themselves. Some can occur at top level; most
|
|
4596
|
-
// are restricted to <resources> or one or more of the specific lists above
|
|
4597
|
-
case "string":
|
|
4598
|
-
if (parent !== "strings" && parent !== "resources") {
|
|
4599
|
-
error(e, parent);
|
|
4600
|
-
return;
|
|
4601
|
-
}
|
|
4602
|
-
visitor(e, "Strings");
|
|
4603
|
-
return;
|
|
4604
|
-
case "font":
|
|
4605
|
-
if (parent !== "fonts" && parent !== "resources") {
|
|
4606
|
-
error(e, parent);
|
|
4607
|
-
return;
|
|
4608
|
-
}
|
|
4609
|
-
visitor(e, "Fonts");
|
|
4610
|
-
return;
|
|
4611
|
-
case "animation":
|
|
4612
|
-
if (parent !== "animations" && parent !== "resources") {
|
|
4613
|
-
error(e, parent);
|
|
4614
|
-
return;
|
|
4615
|
-
}
|
|
4616
|
-
visitor(e, "Drawables");
|
|
4617
|
-
return;
|
|
4618
|
-
case "menu":
|
|
4619
|
-
case "menu2":
|
|
4620
|
-
case "checkbox-menu":
|
|
4621
|
-
case "action-menu":
|
|
4622
|
-
if (parent && parent !== "menus" && parent !== "resources") {
|
|
4623
|
-
error(e, parent);
|
|
4624
|
-
return;
|
|
4625
|
-
}
|
|
4626
|
-
visitor(e, "Menus");
|
|
4627
|
-
return;
|
|
4628
|
-
case "bitmap":
|
|
4629
|
-
if (parent !== "bitmaps" &&
|
|
4630
|
-
parent !== "drawables" &&
|
|
4631
|
-
parent !== "resources") {
|
|
4632
|
-
error(e, parent);
|
|
4633
|
-
return;
|
|
4634
|
-
}
|
|
4635
|
-
visitor(e, "Drawables");
|
|
4636
|
-
return;
|
|
4637
|
-
case "layout":
|
|
4638
|
-
if (parent && parent !== "layouts" && parent !== "resources") {
|
|
4639
|
-
error(e, parent);
|
|
4640
|
-
return;
|
|
4641
|
-
}
|
|
4642
|
-
visitor(e, "Layouts");
|
|
4643
|
-
return;
|
|
4644
|
-
case "drawable-list":
|
|
4645
|
-
if (parent && parent !== "drawables" && parent !== "resources") {
|
|
4646
|
-
error(e, parent);
|
|
4647
|
-
return;
|
|
4648
|
-
}
|
|
4649
|
-
visitor(e, "Drawables");
|
|
4650
|
-
return;
|
|
4651
|
-
case "property":
|
|
4652
|
-
if (parent !== "properties" && parent !== "resources") {
|
|
4653
|
-
error(e, parent);
|
|
4654
|
-
return;
|
|
4655
|
-
}
|
|
4656
|
-
visitor(e, "Properties");
|
|
4657
|
-
return;
|
|
4658
|
-
case "setting":
|
|
4659
|
-
if (parent !== "settings" && parent !== "resources") {
|
|
4660
|
-
error(e, parent);
|
|
4661
|
-
return;
|
|
4662
|
-
}
|
|
4663
|
-
visitor(e, null);
|
|
4664
|
-
return;
|
|
4665
|
-
case "group":
|
|
4666
|
-
if (parent !== "settings" /* && parent !== "resources" */) {
|
|
4667
|
-
error(e, parent);
|
|
4668
|
-
return;
|
|
4669
|
-
}
|
|
4670
|
-
visitor(e, null);
|
|
4671
|
-
return;
|
|
4672
|
-
case "fitField":
|
|
4673
|
-
if (parent !== "fitContributions" && parent !== "resources") {
|
|
4674
|
-
error(e, parent);
|
|
4675
|
-
return;
|
|
4676
|
-
}
|
|
4677
|
-
visitor(e, null);
|
|
4678
|
-
return;
|
|
4679
|
-
case "jsonData":
|
|
4680
|
-
if (parent && parent != "jsonDataResources" && parent !== "resources") {
|
|
4681
|
-
error(e, parent);
|
|
4682
|
-
return;
|
|
4683
|
-
}
|
|
4684
|
-
visitor(e, "JsonData");
|
|
4685
|
-
return;
|
|
4686
|
-
case "build":
|
|
4687
|
-
if (parent && parent !== "resources") {
|
|
4688
|
-
error(e, parent);
|
|
4689
|
-
return;
|
|
4690
|
-
}
|
|
4691
|
-
visitor(e, null);
|
|
4692
|
-
return;
|
|
4576
|
+
if (visitor.pre ? visitor.pre(e) === false : e.type !== "element") {
|
|
4577
|
+
return;
|
|
4693
4578
|
}
|
|
4579
|
+
if (e.type == "element") {
|
|
4580
|
+
switch (e.name) {
|
|
4581
|
+
// <resources> can contain any of the resource lists (except
|
|
4582
|
+
// another resources), and any of their contents
|
|
4583
|
+
case "resources":
|
|
4584
|
+
if (parent) {
|
|
4585
|
+
error(e);
|
|
4586
|
+
break;
|
|
4587
|
+
}
|
|
4588
|
+
e.children && visit_resources(e.children, e, visitor);
|
|
4589
|
+
break;
|
|
4590
|
+
// Each of these is a list that can contain certain kinds of resource.
|
|
4591
|
+
// They can only occur at the top level, or under a <resources> list.
|
|
4592
|
+
case "strings":
|
|
4593
|
+
case "fonts":
|
|
4594
|
+
case "animations":
|
|
4595
|
+
case "bitmaps":
|
|
4596
|
+
case "layouts":
|
|
4597
|
+
case "menus":
|
|
4598
|
+
case "drawables":
|
|
4599
|
+
case "properties":
|
|
4600
|
+
case "settings":
|
|
4601
|
+
case "fitContributions":
|
|
4602
|
+
case "jsonDataResources":
|
|
4603
|
+
case "complications":
|
|
4604
|
+
if (pname && pname !== "resources") {
|
|
4605
|
+
error(e);
|
|
4606
|
+
break;
|
|
4607
|
+
}
|
|
4608
|
+
visit_resources(external_sdk_util_cjs_namespaceObject.xmlUtil.elementKids(e), e, visitor);
|
|
4609
|
+
break;
|
|
4610
|
+
// These are the resources themselves. Some can occur at top level; most
|
|
4611
|
+
// are restricted to <resources> or one or more of the specific lists above
|
|
4612
|
+
case "string":
|
|
4613
|
+
if (pname !== "strings" && pname !== "resources") {
|
|
4614
|
+
error(e);
|
|
4615
|
+
break;
|
|
4616
|
+
}
|
|
4617
|
+
visit(e, "Strings");
|
|
4618
|
+
break;
|
|
4619
|
+
case "font":
|
|
4620
|
+
if (pname !== "fonts" && pname !== "resources") {
|
|
4621
|
+
error(e);
|
|
4622
|
+
break;
|
|
4623
|
+
}
|
|
4624
|
+
visit(e, "Fonts");
|
|
4625
|
+
break;
|
|
4626
|
+
case "animation":
|
|
4627
|
+
if (pname !== "animations" && pname !== "resources") {
|
|
4628
|
+
error(e);
|
|
4629
|
+
break;
|
|
4630
|
+
}
|
|
4631
|
+
visit(e, "Drawables");
|
|
4632
|
+
break;
|
|
4633
|
+
case "menu":
|
|
4634
|
+
case "menu2":
|
|
4635
|
+
case "checkbox-menu":
|
|
4636
|
+
case "action-menu":
|
|
4637
|
+
if (pname && pname !== "menus" && pname !== "resources") {
|
|
4638
|
+
error(e);
|
|
4639
|
+
break;
|
|
4640
|
+
}
|
|
4641
|
+
visit(e, "Menus");
|
|
4642
|
+
break;
|
|
4643
|
+
case "bitmap":
|
|
4644
|
+
if (pname !== "bitmaps" &&
|
|
4645
|
+
pname !== "drawables" &&
|
|
4646
|
+
pname !== "resources") {
|
|
4647
|
+
error(e);
|
|
4648
|
+
break;
|
|
4649
|
+
}
|
|
4650
|
+
visit(e, "Drawables");
|
|
4651
|
+
break;
|
|
4652
|
+
case "layout":
|
|
4653
|
+
if (pname && pname !== "layouts" && pname !== "resources") {
|
|
4654
|
+
error(e);
|
|
4655
|
+
break;
|
|
4656
|
+
}
|
|
4657
|
+
visit(e, "Layouts");
|
|
4658
|
+
break;
|
|
4659
|
+
case "drawable-list":
|
|
4660
|
+
if (pname && pname !== "drawables" && pname !== "resources") {
|
|
4661
|
+
error(e);
|
|
4662
|
+
break;
|
|
4663
|
+
}
|
|
4664
|
+
visit(e, "Drawables");
|
|
4665
|
+
break;
|
|
4666
|
+
case "property":
|
|
4667
|
+
if (pname !== "properties" && pname !== "resources") {
|
|
4668
|
+
error(e);
|
|
4669
|
+
break;
|
|
4670
|
+
}
|
|
4671
|
+
visit(e, "Properties");
|
|
4672
|
+
break;
|
|
4673
|
+
case "setting":
|
|
4674
|
+
if (pname !== "settings" && pname !== "resources") {
|
|
4675
|
+
error(e);
|
|
4676
|
+
break;
|
|
4677
|
+
}
|
|
4678
|
+
visit(e, "Settings");
|
|
4679
|
+
break;
|
|
4680
|
+
case "group":
|
|
4681
|
+
if (pname !== "settings" /* && pname !== "resources" */) {
|
|
4682
|
+
error(e);
|
|
4683
|
+
break;
|
|
4684
|
+
}
|
|
4685
|
+
visit(e, "Settings");
|
|
4686
|
+
break;
|
|
4687
|
+
case "fitField":
|
|
4688
|
+
if (pname !== "fitContributions" && pname !== "resources") {
|
|
4689
|
+
error(e);
|
|
4690
|
+
break;
|
|
4691
|
+
}
|
|
4692
|
+
visit(e, "FitFields");
|
|
4693
|
+
break;
|
|
4694
|
+
case "jsonData":
|
|
4695
|
+
if (pname && pname != "jsonDataResources" && pname !== "resources") {
|
|
4696
|
+
error(e);
|
|
4697
|
+
break;
|
|
4698
|
+
}
|
|
4699
|
+
visit(e, "JsonData");
|
|
4700
|
+
break;
|
|
4701
|
+
case "build":
|
|
4702
|
+
if (pname && pname !== "resources") {
|
|
4703
|
+
error(e);
|
|
4704
|
+
break;
|
|
4705
|
+
}
|
|
4706
|
+
visit(e, null);
|
|
4707
|
+
break;
|
|
4708
|
+
}
|
|
4709
|
+
}
|
|
4710
|
+
if (visitor.post)
|
|
4711
|
+
visitor.post(e);
|
|
4694
4712
|
});
|
|
4695
4713
|
}
|
|
4696
|
-
function add_resources_to_ast(ast, resources) {
|
|
4714
|
+
function add_resources_to_ast(ast, resources, manifestXML) {
|
|
4715
|
+
const modules = {
|
|
4716
|
+
Drawables: true,
|
|
4717
|
+
Fonts: true,
|
|
4718
|
+
JsonData: true,
|
|
4719
|
+
Layouts: true,
|
|
4720
|
+
Menus: true,
|
|
4721
|
+
Strings: true,
|
|
4722
|
+
Properties: false,
|
|
4723
|
+
Settings: false,
|
|
4724
|
+
FitFields: false,
|
|
4725
|
+
};
|
|
4726
|
+
const outerLoc = ast.loc && { ...ast.loc };
|
|
4727
|
+
const makeModule = (m) => ({
|
|
4728
|
+
type: "ModuleDeclaration",
|
|
4729
|
+
id: { type: "Identifier", name: m },
|
|
4730
|
+
body: { type: "BlockStatement", body: [] },
|
|
4731
|
+
loc: outerLoc,
|
|
4732
|
+
});
|
|
4733
|
+
const makeImport = (type, module, as) => {
|
|
4734
|
+
const id = makeScopedName(module);
|
|
4735
|
+
return type === "Using" && as
|
|
4736
|
+
? { type, id, as: makeIdentifier(as) }
|
|
4737
|
+
: { type, id };
|
|
4738
|
+
};
|
|
4739
|
+
ast.body.push(makeImport("ImportModule", "Toybox.Lang"), makeImport("Using", "Toybox.WatchUi"), makeImport("Using", "Toybox.WatchUi", "Ui"), makeImport("Using", "Toybox.Graphics"), makeImport("Using", "Toybox.Graphics", "Gfx"));
|
|
4697
4740
|
Object.entries(resources).forEach(([barrel, resourceMap]) => {
|
|
4698
|
-
|
|
4699
|
-
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
|
|
4741
|
+
let body = ast.body;
|
|
4742
|
+
if (barrel !== "") {
|
|
4743
|
+
const module = makeModule(barrel);
|
|
4744
|
+
body.push(module);
|
|
4745
|
+
body = module.body.body;
|
|
4746
|
+
}
|
|
4747
|
+
const rez = makeModule("Rez");
|
|
4748
|
+
body.push(rez);
|
|
4749
|
+
const hiddenRez = makeModule("*Rez*");
|
|
4750
|
+
rez.body.body.push(hiddenRez);
|
|
4751
|
+
if (manifestXML && manifestXML.body instanceof external_sdk_util_cjs_namespaceObject.xmlUtil.Nodes) {
|
|
4752
|
+
manifestXML.body
|
|
4753
|
+
.children("iq:application")
|
|
4754
|
+
.elements.forEach((e) => add_one_resource(rez, e));
|
|
4755
|
+
}
|
|
4756
|
+
const rezModules = Object.fromEntries(Object.entries(modules).map(([moduleName, isPublic]) => {
|
|
4757
|
+
const module = makeModule(moduleName);
|
|
4758
|
+
(isPublic ? rez : hiddenRez).body.body.push(module);
|
|
4759
|
+
return [moduleName, module];
|
|
4760
|
+
}));
|
|
4707
4761
|
Object.values(resourceMap).forEach((rez) => {
|
|
4708
|
-
if (!rez ||
|
|
4762
|
+
if (!rez || rez.body instanceof Error)
|
|
4709
4763
|
return;
|
|
4710
4764
|
visit_resources(rez.body.elements, null, (e, s) => {
|
|
4711
4765
|
if (!s)
|
|
4712
4766
|
return;
|
|
4713
4767
|
if (!ast_hasProperty(rezModules, s))
|
|
4714
4768
|
return;
|
|
4715
|
-
rezModules[s]
|
|
4716
|
-
|
|
4717
|
-
return;
|
|
4769
|
+
const module = rezModules[s];
|
|
4770
|
+
add_one_resource(module, e);
|
|
4718
4771
|
});
|
|
4719
4772
|
});
|
|
4720
|
-
|
|
4721
|
-
|
|
4722
|
-
|
|
4723
|
-
|
|
4724
|
-
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
|
|
4731
|
-
|
|
4773
|
+
});
|
|
4774
|
+
}
|
|
4775
|
+
function makeIdentifier(name, loc) {
|
|
4776
|
+
return wrap({ type: "Identifier", name }, loc);
|
|
4777
|
+
}
|
|
4778
|
+
function makeMemberExpression(object, property) {
|
|
4779
|
+
return wrap({
|
|
4780
|
+
type: "MemberExpression",
|
|
4781
|
+
object,
|
|
4782
|
+
property,
|
|
4783
|
+
computed: false,
|
|
4784
|
+
}, object.loc && locRange(object.loc, property.loc));
|
|
4785
|
+
}
|
|
4786
|
+
function makeScopedName(dotted, l) {
|
|
4787
|
+
const loc = l && adjustLoc(l, 0, l.start.offset - l.end.offset);
|
|
4788
|
+
return dotted.split(".").reduce(({ cur, offset }, next) => {
|
|
4789
|
+
const id = makeIdentifier(next, loc && adjustLoc(loc, offset, offset + next.length));
|
|
4790
|
+
if (!cur) {
|
|
4791
|
+
cur = id;
|
|
4732
4792
|
}
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
|
|
4740
|
-
|
|
4741
|
-
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
|
|
4745
|
-
|
|
4746
|
-
|
|
4747
|
-
|
|
4748
|
-
|
|
4749
|
-
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
}
|
|
4793
|
+
else {
|
|
4794
|
+
cur = makeMemberExpression(cur, id);
|
|
4795
|
+
}
|
|
4796
|
+
offset += next.length + 1;
|
|
4797
|
+
return { cur, offset };
|
|
4798
|
+
}, { cur: null, offset: 0 }).cur;
|
|
4799
|
+
}
|
|
4800
|
+
function visit_resource_refs(e) {
|
|
4801
|
+
const result = [];
|
|
4802
|
+
const stringToScopedName = (element, id, dotted, l) => {
|
|
4803
|
+
const match = dotted.match(/^(@)?([\w_$]+\s*\.\s*)*[\w_$]+$/);
|
|
4804
|
+
if (!match)
|
|
4805
|
+
return;
|
|
4806
|
+
let offset = 0;
|
|
4807
|
+
if (match[1]) {
|
|
4808
|
+
offset = 1;
|
|
4809
|
+
}
|
|
4810
|
+
else if ((element === "drawable" && id === "class") ||
|
|
4811
|
+
(element === "iq:application" && id === "entry")) {
|
|
4812
|
+
// nothing to do
|
|
4813
|
+
}
|
|
4814
|
+
else {
|
|
4815
|
+
return;
|
|
4816
|
+
}
|
|
4817
|
+
const dn = makeScopedName(dotted.substring(offset), adjustLoc(l, offset, 0));
|
|
4818
|
+
if (dn)
|
|
4819
|
+
result.push(dn);
|
|
4820
|
+
};
|
|
4821
|
+
visit_resources([e], null, {
|
|
4822
|
+
pre(node) {
|
|
4823
|
+
if (node.type === "element") {
|
|
4824
|
+
Object.values(node.attr).forEach((attr) => {
|
|
4825
|
+
if (!attr || !attr.value.loc)
|
|
4826
|
+
return;
|
|
4827
|
+
const loc = adjustLoc(attr.value.loc);
|
|
4828
|
+
attr &&
|
|
4829
|
+
stringToScopedName(node.name, attr.name.value, attr.value.value, loc);
|
|
4830
|
+
});
|
|
4831
|
+
if (node.children &&
|
|
4832
|
+
node.children.length === 1 &&
|
|
4833
|
+
node.children[0].type === "chardata") {
|
|
4834
|
+
stringToScopedName(node.name, null, node.children[0].value, node.children[0].loc);
|
|
4835
|
+
}
|
|
4836
|
+
return;
|
|
4837
|
+
}
|
|
4838
|
+
},
|
|
4754
4839
|
});
|
|
4840
|
+
return result;
|
|
4841
|
+
}
|
|
4842
|
+
function wrap(node, loc) {
|
|
4843
|
+
if (loc) {
|
|
4844
|
+
node.loc = loc;
|
|
4845
|
+
node.start = loc.start.offset;
|
|
4846
|
+
node.end = loc.end.offset;
|
|
4847
|
+
}
|
|
4848
|
+
return node;
|
|
4849
|
+
}
|
|
4850
|
+
function locRange(start, end) {
|
|
4851
|
+
return {
|
|
4852
|
+
source: start.source || end.source,
|
|
4853
|
+
start: start.start,
|
|
4854
|
+
end: end.end,
|
|
4855
|
+
};
|
|
4856
|
+
}
|
|
4857
|
+
function adjustLoc(loc, start = 1, end = -1) {
|
|
4858
|
+
/* Attributes are quoted, so skip the quotes */
|
|
4859
|
+
return {
|
|
4860
|
+
source: loc.source,
|
|
4861
|
+
start: {
|
|
4862
|
+
offset: loc.start.offset + start,
|
|
4863
|
+
line: loc.start.line,
|
|
4864
|
+
column: loc.start.column + start,
|
|
4865
|
+
},
|
|
4866
|
+
end: {
|
|
4867
|
+
offset: loc.end.offset + end,
|
|
4868
|
+
line: loc.end.line,
|
|
4869
|
+
column: loc.end.column + end,
|
|
4870
|
+
},
|
|
4871
|
+
};
|
|
4872
|
+
}
|
|
4873
|
+
function add_one_resource(module, e) {
|
|
4874
|
+
let id;
|
|
4875
|
+
let func;
|
|
4876
|
+
const varDecl = () => {
|
|
4877
|
+
const loc = id && adjustLoc(id.value.loc);
|
|
4878
|
+
return wrap({
|
|
4879
|
+
type: "VariableDeclaration",
|
|
4880
|
+
declarations: [
|
|
4881
|
+
wrap({
|
|
4882
|
+
type: "VariableDeclarator",
|
|
4883
|
+
kind: "var",
|
|
4884
|
+
id: makeIdentifier(id ? id.value.value : "*invalid*", loc),
|
|
4885
|
+
init,
|
|
4886
|
+
}, loc),
|
|
4887
|
+
],
|
|
4888
|
+
kind: "var",
|
|
4889
|
+
}, loc);
|
|
4890
|
+
};
|
|
4891
|
+
const classDecl = (parent) => {
|
|
4892
|
+
if (!id)
|
|
4893
|
+
return null;
|
|
4894
|
+
const loc = id.value.loc;
|
|
4895
|
+
const items = init
|
|
4896
|
+
? [{ type: "ClassElement", item: varDecl(), loc }]
|
|
4897
|
+
: [];
|
|
4898
|
+
return {
|
|
4899
|
+
type: "ClassDeclaration",
|
|
4900
|
+
body: { type: "ClassBody", body: items, loc },
|
|
4901
|
+
id: makeIdentifier(id.value.value, loc),
|
|
4902
|
+
superClass: makeScopedName(parent),
|
|
4903
|
+
loc,
|
|
4904
|
+
};
|
|
4905
|
+
};
|
|
4906
|
+
switch (e.name) {
|
|
4907
|
+
case "font":
|
|
4908
|
+
case "string":
|
|
4909
|
+
case "jsonData":
|
|
4910
|
+
case "animation":
|
|
4911
|
+
case "bitmap":
|
|
4912
|
+
case "layout":
|
|
4913
|
+
case "drawable-list":
|
|
4914
|
+
case "property":
|
|
4915
|
+
case "fitField":
|
|
4916
|
+
id = e.attr.id;
|
|
4917
|
+
func = varDecl;
|
|
4918
|
+
break;
|
|
4919
|
+
case "menu":
|
|
4920
|
+
id = e.attr.id;
|
|
4921
|
+
func = () => classDecl("Ui.Menu");
|
|
4922
|
+
break;
|
|
4923
|
+
case "menu2":
|
|
4924
|
+
id = e.attr.id;
|
|
4925
|
+
func = () => classDecl("Ui.Menu2");
|
|
4926
|
+
break;
|
|
4927
|
+
case "checkbox-menu":
|
|
4928
|
+
id = e.attr.id;
|
|
4929
|
+
func = () => classDecl("Ui.CheckboxMenu");
|
|
4930
|
+
break;
|
|
4931
|
+
case "action-menu":
|
|
4932
|
+
id = e.attr.id;
|
|
4933
|
+
func = () => classDecl("Ui.Menu2");
|
|
4934
|
+
break;
|
|
4935
|
+
case "setting":
|
|
4936
|
+
case "group":
|
|
4937
|
+
func = varDecl;
|
|
4938
|
+
break;
|
|
4939
|
+
case "iq:application":
|
|
4940
|
+
func = varDecl;
|
|
4941
|
+
break;
|
|
4942
|
+
}
|
|
4943
|
+
if (!func)
|
|
4944
|
+
return;
|
|
4945
|
+
const elements = visit_resource_refs(e);
|
|
4946
|
+
const init = elements.length
|
|
4947
|
+
? { type: "ArrayExpression", elements }
|
|
4948
|
+
: undefined;
|
|
4949
|
+
if (!id) {
|
|
4950
|
+
if (!init)
|
|
4951
|
+
return;
|
|
4952
|
+
}
|
|
4953
|
+
const item = func();
|
|
4954
|
+
if (item) {
|
|
4955
|
+
module.body.body.push(item);
|
|
4956
|
+
}
|
|
4755
4957
|
}
|
|
4756
4958
|
|
|
4757
4959
|
;// CONCATENATED MODULE: ./src/visitor.ts
|
|
@@ -4761,7 +4963,10 @@ function visitorNode(node) {
|
|
|
4761
4963
|
return node;
|
|
4762
4964
|
}
|
|
4763
4965
|
if (node.type === "MemberExpression") {
|
|
4764
|
-
return node.property
|
|
4966
|
+
return node.property.type === "UnaryExpression" &&
|
|
4967
|
+
node.property.operator === ":"
|
|
4968
|
+
? node.property.argument
|
|
4969
|
+
: node.property;
|
|
4765
4970
|
}
|
|
4766
4971
|
if (node.type === "BinaryExpression" &&
|
|
4767
4972
|
node.operator === "has" &&
|
|
@@ -4771,7 +4976,7 @@ function visitorNode(node) {
|
|
|
4771
4976
|
}
|
|
4772
4977
|
return node;
|
|
4773
4978
|
}
|
|
4774
|
-
function visitor_visitReferences(state, ast, name, defn, callback) {
|
|
4979
|
+
function visitor_visitReferences(state, ast, name, defn, callback, includeDefs = false, filter = null) {
|
|
4775
4980
|
const checkResults = ([name, results], node) => {
|
|
4776
4981
|
if (name && results) {
|
|
4777
4982
|
if (!defn || (0,external_api_cjs_namespaceObject.sameLookupResult)(results, defn)) {
|
|
@@ -4788,6 +4993,8 @@ function visitor_visitReferences(state, ast, name, defn, callback) {
|
|
|
4788
4993
|
return null;
|
|
4789
4994
|
};
|
|
4790
4995
|
state.pre = (node) => {
|
|
4996
|
+
if (filter && !filter(node))
|
|
4997
|
+
return [];
|
|
4791
4998
|
switch (node.type) {
|
|
4792
4999
|
case "AttributeList":
|
|
4793
5000
|
return [];
|
|
@@ -4857,11 +5064,36 @@ function visitor_visitReferences(state, ast, name, defn, callback) {
|
|
|
4857
5064
|
return ["returnType"];
|
|
4858
5065
|
}
|
|
4859
5066
|
case "ModuleDeclaration":
|
|
5067
|
+
if (includeDefs)
|
|
5068
|
+
break;
|
|
4860
5069
|
return ["body"];
|
|
4861
5070
|
case "ClassDeclaration":
|
|
5071
|
+
if (includeDefs)
|
|
5072
|
+
break;
|
|
4862
5073
|
return ["body", "superClass"];
|
|
4863
5074
|
case "FunctionDeclaration":
|
|
5075
|
+
if (includeDefs)
|
|
5076
|
+
break;
|
|
4864
5077
|
return ["params", "returnType", "body"];
|
|
5078
|
+
case "TypedefDeclaration":
|
|
5079
|
+
if (includeDefs)
|
|
5080
|
+
break;
|
|
5081
|
+
return ["ts"];
|
|
5082
|
+
case "VariableDeclarator":
|
|
5083
|
+
if (includeDefs)
|
|
5084
|
+
break;
|
|
5085
|
+
return ["init"];
|
|
5086
|
+
case "EnumDeclaration":
|
|
5087
|
+
if (includeDefs)
|
|
5088
|
+
break;
|
|
5089
|
+
return [];
|
|
5090
|
+
case "CatchClause":
|
|
5091
|
+
if (includeDefs)
|
|
5092
|
+
break;
|
|
5093
|
+
if (node.param && node.param.type !== "Identifier") {
|
|
5094
|
+
state.traverse(node.param.right);
|
|
5095
|
+
}
|
|
5096
|
+
return ["body"];
|
|
4865
5097
|
}
|
|
4866
5098
|
return null;
|
|
4867
5099
|
};
|
|
@@ -4923,7 +5155,7 @@ function api_checkCompilerVersion(version, sdkVer) {
|
|
|
4923
5155
|
return sdkVer <= v2;
|
|
4924
5156
|
}
|
|
4925
5157
|
// Extract all enum values from api.mir
|
|
4926
|
-
async function api_getApiMapping(state, resourcesMap) {
|
|
5158
|
+
async function api_getApiMapping(state, resourcesMap, manifestXML) {
|
|
4927
5159
|
// get the path to the currently active sdk
|
|
4928
5160
|
const parser = (prettier_plugin_monkeyc_default()).parsers.monkeyc;
|
|
4929
5161
|
const sdk = await (0,external_sdk_util_cjs_namespaceObject.getSdkPath)();
|
|
@@ -4937,17 +5169,25 @@ async function api_getApiMapping(state, resourcesMap) {
|
|
|
4937
5169
|
const api = (await promises_namespaceObject.readFile(`${sdk}bin/api.mir`))
|
|
4938
5170
|
.toString()
|
|
4939
5171
|
.replace(/\r\n/g, "\n")
|
|
4940
|
-
.replace(/^\s*\[.*?\]\s*$/gm, "")
|
|
4941
|
-
//.replace(/(COLOR_TRANSPARENT|LAYOUT_[HV]ALIGN_\w+) = (\d+)/gm, "$1 = -$2")
|
|
4942
5172
|
.replace(/^(\s*type)\s/gm, "$1def ");
|
|
4943
5173
|
try {
|
|
4944
5174
|
const ast = parser.parse(api, null, {
|
|
4945
5175
|
filepath: "api.mir",
|
|
4946
5176
|
});
|
|
4947
5177
|
if (resourcesMap) {
|
|
4948
|
-
|
|
5178
|
+
const rezAst = state
|
|
5179
|
+
? state.rezAst || { type: "Program", body: [] }
|
|
5180
|
+
: ast;
|
|
5181
|
+
add_resources_to_ast(rezAst, resourcesMap, manifestXML);
|
|
5182
|
+
if (state) {
|
|
5183
|
+
state.rezAst = rezAst;
|
|
5184
|
+
state.manifestXML = manifestXML;
|
|
5185
|
+
}
|
|
4949
5186
|
}
|
|
4950
5187
|
const result = api_collectNamespaces(ast, state);
|
|
5188
|
+
if (state && state.rezAst) {
|
|
5189
|
+
api_collectNamespaces(state.rezAst, state);
|
|
5190
|
+
}
|
|
4951
5191
|
negativeFixups.forEach((fixup) => {
|
|
4952
5192
|
const vs = fixup.split(".").reduce((state, part) => {
|
|
4953
5193
|
const decls = api_isStateNode(state) && state.decls?.[part];
|
|
@@ -5572,6 +5812,9 @@ function api_collectNamespaces(ast, stateIn) {
|
|
|
5572
5812
|
throw new Error("Unexpected enum initializer");
|
|
5573
5813
|
}
|
|
5574
5814
|
if (init != m.init) {
|
|
5815
|
+
if (m.init.enumType) {
|
|
5816
|
+
init.enumType = m.init.enumType;
|
|
5817
|
+
}
|
|
5575
5818
|
m.init = init;
|
|
5576
5819
|
}
|
|
5577
5820
|
if (init.type == "Literal" &&
|