@markw65/monkeyc-optimizer 1.1.56 → 1.1.58

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 CHANGED
@@ -2,6 +2,21 @@
2
2
 
3
3
  All notable changes to the "monkeyc-optimizer" package will be documented in this file.
4
4
 
5
+ ### 1.1.58
6
+
7
+ - Update to [@markw65/prettier-plugin-monkeyc@1.0.57](https://github.com/markw65/prettier-plugin-monkeyc/blob/main/CHANGELOG.md#1057)
8
+ - Just updates exported types. No change in functionality
9
+ - Properly quote paths in the generated jungle
10
+ - Take account of all references from resource files
11
+ - Include Null in the types of uninitialized variables in their initialize method
12
+
13
+ ### 1.1.57
14
+
15
+ - Include ConditionalExpression and LogicalExpression in evaluateFunction
16
+ - Fix personality search path (Fixes # 27)
17
+ - Use fully qualified names for enum typedefs (Fixes # 28)
18
+ - Fix auto-inlining of protected functions (Fixes #29)
19
+
5
20
  ### 1.1.56
6
21
 
7
22
  - Fix regression caused by the fix to #24 (Fixes #26)
package/build/api.cjs CHANGED
@@ -18,47 +18,47 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var api_exports = {};
20
20
  __export(api_exports, {
21
- checkCompilerVersion: () => import_chunk_M3LMSSY7.checkCompilerVersion,
22
- collectNamespaces: () => import_chunk_M3LMSSY7.collectNamespaces,
23
- createDocumentationMap: () => import_chunk_M3LMSSY7.createDocumentationMap,
24
- diagnostic: () => import_chunk_M3LMSSY7.diagnostic,
25
- diagnosticHelper: () => import_chunk_M3LMSSY7.diagnosticHelper,
26
- findNamesInScope: () => import_chunk_M3LMSSY7.findNamesInScope,
27
- findUsingForNode: () => import_chunk_M3LMSSY7.findUsingForNode,
28
- formatAst: () => import_chunk_M3LMSSY7.formatAst,
29
- formatAstLongLines: () => import_chunk_M3LMSSY7.formatAstLongLines,
30
- formatScopedName: () => import_chunk_M3LMSSY7.formatScopedName,
31
- getApiFunctionInfo: () => import_chunk_M3LMSSY7.getApiFunctionInfo,
32
- getApiMapping: () => import_chunk_M3LMSSY7.getApiMapping,
33
- getSuperClasses: () => import_chunk_M3LMSSY7.getSuperClasses,
21
+ checkCompilerVersion: () => import_chunk_XC5IVRTO.checkCompilerVersion,
22
+ collectNamespaces: () => import_chunk_XC5IVRTO.collectNamespaces,
23
+ createDocumentationMap: () => import_chunk_XC5IVRTO.createDocumentationMap,
24
+ diagnostic: () => import_chunk_XC5IVRTO.diagnostic,
25
+ diagnosticHelper: () => import_chunk_XC5IVRTO.diagnosticHelper,
26
+ findNamesInScope: () => import_chunk_XC5IVRTO.findNamesInScope,
27
+ findUsingForNode: () => import_chunk_XC5IVRTO.findUsingForNode,
28
+ formatAst: () => import_chunk_XC5IVRTO.formatAst,
29
+ formatAstLongLines: () => import_chunk_XC5IVRTO.formatAstLongLines,
30
+ formatScopedName: () => import_chunk_XC5IVRTO.formatScopedName,
31
+ getApiFunctionInfo: () => import_chunk_XC5IVRTO.getApiFunctionInfo,
32
+ getApiMapping: () => import_chunk_XC5IVRTO.getApiMapping,
33
+ getSuperClasses: () => import_chunk_XC5IVRTO.getSuperClasses,
34
34
  hasProperty: () => import_chunk_MBTLUWXR.hasProperty,
35
- isClassVariable: () => import_chunk_M3LMSSY7.isClassVariable,
36
- isLocal: () => import_chunk_M3LMSSY7.isLocal,
37
- isLookupCandidate: () => import_chunk_M3LMSSY7.isLookupCandidate,
38
- isStateNode: () => import_chunk_M3LMSSY7.isStateNode,
39
- lookupByFullName: () => import_chunk_M3LMSSY7.lookupByFullName,
40
- lookupNext: () => import_chunk_M3LMSSY7.lookupNext,
41
- lookupResultContains: () => import_chunk_M3LMSSY7.lookupResultContains,
42
- lookupWithType: () => import_chunk_M3LMSSY7.lookupWithType,
43
- makeToyboxLink: () => import_chunk_M3LMSSY7.makeToyboxLink,
44
- mapVarDeclsByType: () => import_chunk_M3LMSSY7.mapVarDeclsByType,
45
- markInvokeClassMethod: () => import_chunk_M3LMSSY7.markInvokeClassMethod,
46
- parseSdkVersion: () => import_chunk_M3LMSSY7.parseSdkVersion,
47
- resolveDiagnostics: () => import_chunk_M3LMSSY7.resolveDiagnostics,
48
- resolveDiagnosticsMap: () => import_chunk_M3LMSSY7.resolveDiagnosticsMap,
49
- sameLookupResult: () => import_chunk_M3LMSSY7.sameLookupResult,
35
+ isClassVariable: () => import_chunk_XC5IVRTO.isClassVariable,
36
+ isLocal: () => import_chunk_XC5IVRTO.isLocal,
37
+ isLookupCandidate: () => import_chunk_XC5IVRTO.isLookupCandidate,
38
+ isStateNode: () => import_chunk_XC5IVRTO.isStateNode,
39
+ lookupByFullName: () => import_chunk_XC5IVRTO.lookupByFullName,
40
+ lookupNext: () => import_chunk_XC5IVRTO.lookupNext,
41
+ lookupResultContains: () => import_chunk_XC5IVRTO.lookupResultContains,
42
+ lookupWithType: () => import_chunk_XC5IVRTO.lookupWithType,
43
+ makeToyboxLink: () => import_chunk_XC5IVRTO.makeToyboxLink,
44
+ mapVarDeclsByType: () => import_chunk_XC5IVRTO.mapVarDeclsByType,
45
+ markInvokeClassMethod: () => import_chunk_XC5IVRTO.markInvokeClassMethod,
46
+ parseSdkVersion: () => import_chunk_XC5IVRTO.parseSdkVersion,
47
+ resolveDiagnostics: () => import_chunk_XC5IVRTO.resolveDiagnostics,
48
+ resolveDiagnosticsMap: () => import_chunk_XC5IVRTO.resolveDiagnosticsMap,
49
+ sameLookupResult: () => import_chunk_XC5IVRTO.sameLookupResult,
50
50
  traverseAst: () => import_chunk_MBTLUWXR.traverseAst,
51
- variableDeclarationName: () => import_chunk_M3LMSSY7.variableDeclarationName,
52
- visitReferences: () => import_chunk_M3LMSSY7.visitReferences,
53
- visit_resources: () => import_chunk_M3LMSSY7.visit_resources,
54
- visitorNode: () => import_chunk_M3LMSSY7.visitorNode
51
+ variableDeclarationName: () => import_chunk_XC5IVRTO.variableDeclarationName,
52
+ visitReferences: () => import_chunk_XC5IVRTO.visitReferences,
53
+ visit_resources: () => import_chunk_XC5IVRTO.visit_resources,
54
+ visitorNode: () => import_chunk_XC5IVRTO.visitorNode
55
55
  });
56
56
  module.exports = __toCommonJS(api_exports);
57
- var import_chunk_M3LMSSY7 = require("./chunk-M3LMSSY7.cjs");
57
+ var import_chunk_XC5IVRTO = require("./chunk-XC5IVRTO.cjs");
58
58
  var import_chunk_SG7ODKRM = require("./chunk-SG7ODKRM.cjs");
59
59
  var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.cjs");
60
60
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
61
- (0, import_chunk_M3LMSSY7.init_api)();
61
+ (0, import_chunk_XC5IVRTO.init_api)();
62
62
  // Annotate the CommonJS export names for ESM import in node:
63
63
  0 && (module.exports = {
64
64
  checkCompilerVersion,
@@ -26,8 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var chunk_M3LMSSY7_exports = {};
30
- __export(chunk_M3LMSSY7_exports, {
29
+ var chunk_XC5IVRTO_exports = {};
30
+ __export(chunk_XC5IVRTO_exports, {
31
31
  EnumTagsConst: () => EnumTagsConst,
32
32
  LastTypeTag: () => LastTypeTag,
33
33
  ObjectLikeTagsConst: () => ObjectLikeTagsConst,
@@ -133,7 +133,7 @@ __export(chunk_M3LMSSY7_exports, {
133
133
  visitorNode: () => visitorNode,
134
134
  xml_util_exports: () => xml_util_exports
135
135
  });
136
- module.exports = __toCommonJS(chunk_M3LMSSY7_exports);
136
+ module.exports = __toCommonJS(chunk_XC5IVRTO_exports);
137
137
  var import_chunk_SG7ODKRM = require("./chunk-SG7ODKRM.cjs");
138
138
  var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.cjs");
139
139
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
@@ -5560,6 +5560,20 @@ var init_function_info = (0, import_chunk_ABYVSU2C.__esm)({
5560
5560
  (0, import_chunk_MBTLUWXR.init_ast)();
5561
5561
  }
5562
5562
  });
5563
+ var StateNodeAttributes;
5564
+ var init_optimizer_types = (0, import_chunk_ABYVSU2C.__esm)({
5565
+ "src/optimizer-types.ts"() {
5566
+ "use strict";
5567
+ StateNodeAttributes = /* @__PURE__ */ ((StateNodeAttributes2) => {
5568
+ StateNodeAttributes2[StateNodeAttributes2["NONE"] = 0] = "NONE";
5569
+ StateNodeAttributes2[StateNodeAttributes2["PUBLIC"] = 1] = "PUBLIC";
5570
+ StateNodeAttributes2[StateNodeAttributes2["PROTECTED"] = 2] = "PROTECTED";
5571
+ StateNodeAttributes2[StateNodeAttributes2["PRIVATE"] = 4] = "PRIVATE";
5572
+ StateNodeAttributes2[StateNodeAttributes2["STATIC"] = 8] = "STATIC";
5573
+ return StateNodeAttributes2;
5574
+ })(StateNodeAttributes || {});
5575
+ }
5576
+ });
5563
5577
  function renameIdentifier(ident, newName) {
5564
5578
  if (!ident.original) {
5565
5579
  ident.original = ident.name;
@@ -5826,7 +5840,7 @@ function canInline(state, func, args) {
5826
5840
  }
5827
5841
  return safeArgs.every((arg) => arg !== null);
5828
5842
  }
5829
- function inliningLooksUseful(func, node) {
5843
+ function inliningLooksUseful(state, func, node) {
5830
5844
  while (true) {
5831
5845
  if (node.type === "BinaryExpression" && node.operator === "as") {
5832
5846
  node = node.left;
@@ -5839,10 +5853,42 @@ function inliningLooksUseful(func, node) {
5839
5853
  if (node.type === "Literal")
5840
5854
  return true;
5841
5855
  if (node.type === "Identifier") {
5842
- if (func.params.length === 1 && variableDeclarationName(func.params[0]) === node.name) {
5856
+ if (func.node.params.length === 1 && variableDeclarationName(func.node.params[0]) === node.name) {
5843
5857
  return 1;
5844
5858
  }
5845
- return true;
5859
+ const stack = func.stack;
5860
+ if (!stack)
5861
+ return false;
5862
+ const calleeClass = stack[stack.length - 1].sn;
5863
+ if (calleeClass.type !== "ClassDeclaration") {
5864
+ return true;
5865
+ }
5866
+ const [, results] = state.lookupNonlocal(node, null, stack);
5867
+ if (!results)
5868
+ return false;
5869
+ const attrs = results.reduce(
5870
+ (attrs2, result) => attrs2 | result.results.reduce(
5871
+ (attrs3, sn) => attrs3 | (isStateNode(sn) ? sn.attributes & (4 | 2) : 0),
5872
+ 0
5873
+ ),
5874
+ 0
5875
+ );
5876
+ if (!attrs)
5877
+ return true;
5878
+ if (state.stack[stack.length - 1] === stack[stack.length - 1]) {
5879
+ return true;
5880
+ }
5881
+ if (attrs & 4)
5882
+ return false;
5883
+ for (let i = state.stack.length; i--; ) {
5884
+ const callerClass = state.stack[i].sn;
5885
+ if (callerClass.type === "ClassDeclaration") {
5886
+ if (getSuperClasses(callerClass)?.has(calleeClass)) {
5887
+ return true;
5888
+ }
5889
+ break;
5890
+ }
5891
+ }
5846
5892
  }
5847
5893
  return false;
5848
5894
  }
@@ -5868,7 +5914,8 @@ function shouldInline(state, func, call, context) {
5868
5914
  if (func.node.body && func.node.body.body.length === 1 && func.node.body.body[0].type === "ReturnStatement" && func.node.body.body[0].argument && func.node.params.length === args.length) {
5869
5915
  inlineAsExpression = true;
5870
5916
  autoInline = inliningLooksUseful(
5871
- func.node,
5917
+ state,
5918
+ func,
5872
5919
  func.node.body.body[0].argument
5873
5920
  );
5874
5921
  }
@@ -6492,23 +6539,10 @@ var init_inliner = (0, import_chunk_ABYVSU2C.__esm)({
6492
6539
  init_api();
6493
6540
  (0, import_chunk_MBTLUWXR.init_ast)();
6494
6541
  init_function_info();
6542
+ init_optimizer_types();
6495
6543
  init_variable_renamer();
6496
6544
  }
6497
6545
  });
6498
- var StateNodeAttributes;
6499
- var init_optimizer_types = (0, import_chunk_ABYVSU2C.__esm)({
6500
- "src/optimizer-types.ts"() {
6501
- "use strict";
6502
- StateNodeAttributes = /* @__PURE__ */ ((StateNodeAttributes2) => {
6503
- StateNodeAttributes2[StateNodeAttributes2["NONE"] = 0] = "NONE";
6504
- StateNodeAttributes2[StateNodeAttributes2["PUBLIC"] = 1] = "PUBLIC";
6505
- StateNodeAttributes2[StateNodeAttributes2["PROTECTED"] = 2] = "PROTECTED";
6506
- StateNodeAttributes2[StateNodeAttributes2["PRIVATE"] = 4] = "PRIVATE";
6507
- StateNodeAttributes2[StateNodeAttributes2["STATIC"] = 8] = "STATIC";
6508
- return StateNodeAttributes2;
6509
- })(StateNodeAttributes || {});
6510
- }
6511
- });
6512
6546
  function pragmaChecker(state, ast, diagnostics) {
6513
6547
  const comments = ast.comments;
6514
6548
  if (!comments)
@@ -12755,12 +12789,12 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
12755
12789
  const order = getPostOrder(graph).reverse();
12756
12790
  const queue = new DataflowQueue();
12757
12791
  let selfClassDecl = null;
12758
- if (!(func.attributes & 8)) {
12759
- const klass = func.stack?.[func.stack?.length - 1].sn;
12760
- if (klass && klass.type === "ClassDeclaration") {
12761
- selfClassDecl = klass;
12762
- }
12792
+ const isStatic = !!(func.attributes & 8);
12793
+ const klass = func.stack?.[func.stack?.length - 1].sn;
12794
+ if (klass && klass.type === "ClassDeclaration") {
12795
+ selfClassDecl = klass;
12763
12796
  }
12797
+ const isInitialize = selfClassDecl && func.name === "initialize";
12764
12798
  order.forEach((block, i) => {
12765
12799
  block.order = i;
12766
12800
  });
@@ -12960,7 +12994,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
12960
12994
  );
12961
12995
  }
12962
12996
  }
12963
- if (selfClassDecl) {
12997
+ if (!isStatic && selfClassDecl) {
12964
12998
  const baseObj = getObjectValue(baseElem.type);
12965
12999
  if (baseObj && baseObj.klass.type === 16384 && (0, import_chunk_SG7ODKRM.some)(
12966
13000
  baseObj.klass.value,
@@ -13021,6 +13055,9 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
13021
13055
  cur,
13022
13056
  decl.type === "Literal" ? typeFromLiteral(decl) : typeFromTypeStateNode(state, decl, true)
13023
13057
  );
13058
+ if (isInitialize && decl.type === "VariableDeclarator" && !decl.node.init && decl.node.kind === "var" && decl.stack[decl.stack.length - 1].sn === selfClassDecl) {
13059
+ cur.type |= 1;
13060
+ }
13024
13061
  return cur;
13025
13062
  },
13026
13063
  {
@@ -16535,6 +16572,8 @@ function evaluateFunction(istate, func, args) {
16535
16572
  case "ReturnStatement":
16536
16573
  case "UnaryExpression":
16537
16574
  case "BinaryExpression":
16575
+ case "ConditionalExpression":
16576
+ case "LogicalExpression":
16538
16577
  case "Literal":
16539
16578
  case "Identifier":
16540
16579
  return;
@@ -17021,19 +17060,25 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
17021
17060
  Object.values(fnMap).forEach((f) => {
17022
17061
  collectNamespaces(f.ast, state);
17023
17062
  });
17024
- const cleanupAll = () => Object.values(fnMap).reduce((changes, f) => {
17025
- (0, import_chunk_MBTLUWXR.traverseAst)(f.ast, void 0, (node) => {
17026
- const ret = cleanup(state, node, f.ast);
17027
- if (ret === false) {
17028
- changes = true;
17029
- state.removeNodeComments(node, f.ast);
17030
- } else if (ret) {
17031
- changes = true;
17032
- }
17033
- return ret;
17034
- });
17035
- return changes;
17036
- }, false);
17063
+ const cleanupAll = () => {
17064
+ const usedDecls = findRezRefs(state);
17065
+ return Object.values(fnMap).reduce((changes, f) => {
17066
+ (0, import_chunk_MBTLUWXR.traverseAst)(f.ast, void 0, (node) => {
17067
+ if (usedDecls.has(node)) {
17068
+ return null;
17069
+ }
17070
+ const ret = cleanup(state, node, f.ast, usedDecls);
17071
+ if (ret === false) {
17072
+ changes = true;
17073
+ state.removeNodeComments(node, f.ast);
17074
+ } else if (ret) {
17075
+ changes = true;
17076
+ }
17077
+ return ret;
17078
+ });
17079
+ return changes;
17080
+ }, false);
17081
+ };
17037
17082
  do {
17038
17083
  state.usedByName = {};
17039
17084
  state.calledFunctions = {};
@@ -17044,7 +17089,9 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
17044
17089
  });
17045
17090
  state.exposed = state.nextExposed;
17046
17091
  state.nextExposed = {};
17047
- } while (cleanupAll() && state.config?.iterateOptimizer);
17092
+ if (!cleanupAll())
17093
+ break;
17094
+ } while (state.config?.iterateOptimizer);
17048
17095
  delete state.pre;
17049
17096
  delete state.post;
17050
17097
  if (state.config?.minimizeModules ?? true) {
@@ -17093,6 +17140,53 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
17093
17140
  sdkVersion: state.sdkVersion
17094
17141
  };
17095
17142
  }
17143
+ function findRezRefs(state) {
17144
+ const usedDecls = /* @__PURE__ */ new Set();
17145
+ state.rezAst && visitReferences(
17146
+ state,
17147
+ state.rezAst,
17148
+ null,
17149
+ false,
17150
+ (node, results, error) => {
17151
+ if (error)
17152
+ return;
17153
+ results.forEach(
17154
+ (result) => result.results.forEach((sn) => {
17155
+ switch (sn.type) {
17156
+ case "ModuleDeclaration":
17157
+ case "Program":
17158
+ case "BlockStatement":
17159
+ return;
17160
+ case "Identifier":
17161
+ case "BinaryExpression":
17162
+ return;
17163
+ case "EnumStringMember":
17164
+ if (sn.system)
17165
+ return;
17166
+ usedDecls.add(sn);
17167
+ break;
17168
+ case "ClassDeclaration":
17169
+ case "FunctionDeclaration":
17170
+ case "EnumDeclaration":
17171
+ case "TypedefDeclaration":
17172
+ if (sn.node.attrs?.system)
17173
+ return;
17174
+ case "VariableDeclarator":
17175
+ if (sn.fullName.startsWith("$.Toybox") || sn.fullName.startsWith("$.Rez")) {
17176
+ return;
17177
+ }
17178
+ usedDecls.add(sn.node);
17179
+ break;
17180
+ default:
17181
+ unhandledType(sn);
17182
+ }
17183
+ })
17184
+ );
17185
+ return void 0;
17186
+ }
17187
+ );
17188
+ return usedDecls;
17189
+ }
17096
17190
  function maybeCalled(state, func) {
17097
17191
  if (!func.body) {
17098
17192
  return true;
@@ -17113,13 +17207,15 @@ function maybeCalled(state, func) {
17113
17207
  }
17114
17208
  return false;
17115
17209
  }
17116
- function cleanup(state, node, ast) {
17210
+ function cleanup(state, node, ast, usedNodes) {
17117
17211
  switch (node.type) {
17118
17212
  case "ThisExpression":
17119
17213
  node.text = "self";
17120
17214
  break;
17121
17215
  case "EnumStringBody":
17122
17216
  if (node.members.every((m) => {
17217
+ if (usedNodes.has(m))
17218
+ return false;
17123
17219
  const name = "name" in m ? m.name : m.id.name;
17124
17220
  return (0, import_chunk_MBTLUWXR.hasProperty)(state.index, name) && !(0, import_chunk_MBTLUWXR.hasProperty)(state.exposed, name) && !(0, import_chunk_MBTLUWXR.hasProperty)(state.usedByName, name);
17125
17221
  })) {
@@ -17132,7 +17228,7 @@ function cleanup(state, node, ast) {
17132
17228
  })
17133
17229
  );
17134
17230
  if (!enumType.has(null)) {
17135
- node.enumType = [...enumType].join(" or ");
17231
+ node.enumType = [...enumType].map((t) => t === "Null" ? t : `Toybox.Lang.${t}`).join(" or ");
17136
17232
  node.members.splice(0);
17137
17233
  }
17138
17234
  }
@@ -17267,6 +17363,7 @@ var init_mc_rewrite = (0, import_chunk_ABYVSU2C.__esm)({
17267
17363
  init_unused_exprs();
17268
17364
  (0, import_chunk_SG7ODKRM.init_util)();
17269
17365
  init_variable_renamer();
17366
+ init_data_flow();
17270
17367
  }
17271
17368
  });
17272
17369
  var negativeFixups;
@@ -17939,126 +18036,132 @@ function visitReferences(state, ast, name, defn, callback, includeDefs = false,
17939
18036
  }
17940
18037
  checkResults([id.name, [{ parent: parent.sn, results }]], id);
17941
18038
  };
17942
- state.pre = (node) => {
17943
- if (filter && !filter(node))
17944
- return [];
17945
- switch (node.type) {
17946
- case "AttributeList":
18039
+ const { pre, post } = state;
18040
+ try {
18041
+ state.pre = (node) => {
18042
+ if (filter && !filter(node))
17947
18043
  return [];
17948
- case "UnaryExpression":
17949
- if (node.operator === ":")
18044
+ switch (node.type) {
18045
+ case "AttributeList":
17950
18046
  return [];
17951
- break;
17952
- case "BinaryExpression":
17953
- if (node.operator === "has") {
17954
- if (node.right.type === "UnaryExpression" && node.right.operator === ":") {
17955
- if (!name || node.right.argument.name === name) {
17956
- return checkResults(
17957
- lookup2({
17958
- type: "MemberExpression",
17959
- object: node.left,
17960
- property: node.right.argument,
17961
- computed: false
17962
- }),
17963
- node
17964
- );
18047
+ case "UnaryExpression":
18048
+ if (node.operator === ":")
18049
+ return [];
18050
+ break;
18051
+ case "BinaryExpression":
18052
+ if (node.operator === "has") {
18053
+ if (node.right.type === "UnaryExpression" && node.right.operator === ":") {
18054
+ if (!name || node.right.argument.name === name) {
18055
+ return checkResults(
18056
+ lookup2({
18057
+ type: "MemberExpression",
18058
+ object: node.left,
18059
+ property: node.right.argument,
18060
+ computed: false
18061
+ }),
18062
+ node
18063
+ );
18064
+ }
17965
18065
  }
17966
18066
  }
17967
- }
17968
- break;
17969
- case "CallExpression":
17970
- if (node.callee.type === "Identifier") {
17971
- if ((!name || node.callee.name === name) && (!filter || filter(node.callee))) {
17972
- checkResults(lookup2(node.callee, true), node.callee);
18067
+ break;
18068
+ case "CallExpression":
18069
+ if (node.callee.type === "Identifier") {
18070
+ if ((!name || node.callee.name === name) && (!filter || filter(node.callee))) {
18071
+ checkResults(lookup2(node.callee, true), node.callee);
18072
+ }
18073
+ return ["arguments"];
17973
18074
  }
17974
- return ["arguments"];
17975
- }
17976
- break;
17977
- case "Identifier":
17978
- if (!name || node.name === name) {
17979
- return checkResults(lookup2(node), node);
17980
- }
17981
- break;
17982
- case "MemberExpression": {
17983
- const property = isLookupCandidate(node);
17984
- if (property) {
17985
- if (!name || property.name === name) {
17986
- return checkResults(lookup2(node), node) || ["object"];
18075
+ break;
18076
+ case "Identifier":
18077
+ if (!name || node.name === name) {
18078
+ return checkResults(lookup2(node), node);
17987
18079
  }
17988
- return ["object"];
17989
- }
17990
- break;
17991
- }
17992
- case "MethodDefinition": {
17993
- if (!state.inType) {
17994
- throw new Error("Method definition outside of type!");
17995
- }
17996
- if (node.params) {
17997
- node.params.forEach((param) => {
17998
- if (param.type === "BinaryExpression") {
17999
- state.traverse(param.right);
18080
+ break;
18081
+ case "MemberExpression": {
18082
+ const property = isLookupCandidate(node);
18083
+ if (property) {
18084
+ if (!name || property.name === name) {
18085
+ return checkResults(lookup2(node), node) || ["object"];
18000
18086
  }
18001
- });
18002
- }
18003
- return ["returnType"];
18004
- }
18005
- case "ModuleDeclaration":
18006
- if (includeDefs) {
18007
- visitDef(node.id);
18008
- }
18009
- return ["body"];
18010
- case "ClassDeclaration":
18011
- if (includeDefs) {
18012
- visitDef(node.id, node);
18013
- }
18014
- return ["body", "superClass"];
18015
- case "FunctionDeclaration":
18016
- if (includeDefs) {
18017
- visitDef(node.id, node);
18018
- }
18019
- return ["params", "returnType", "body"];
18020
- case "TypedefDeclaration":
18021
- if (includeDefs) {
18022
- visitDef(node.id, node, "type_decls");
18023
- }
18024
- return ["ts"];
18025
- case "VariableDeclarator":
18026
- if (includeDefs) {
18027
- visitDef(node.id, node);
18087
+ return ["object"];
18088
+ }
18089
+ break;
18028
18090
  }
18029
- if (node.id.type === "BinaryExpression") {
18030
- state.traverse(node.id.right);
18091
+ case "MethodDefinition": {
18092
+ if (!state.inType) {
18093
+ throw new Error("Method definition outside of type!");
18094
+ }
18095
+ if (node.params) {
18096
+ node.params.forEach((param) => {
18097
+ if (param.type === "BinaryExpression") {
18098
+ state.traverse(param.right);
18099
+ }
18100
+ });
18101
+ }
18102
+ return ["returnType"];
18031
18103
  }
18032
- return ["init"];
18033
- case "EnumDeclaration":
18034
- if (includeDefs) {
18035
- if (node.id) {
18104
+ case "ModuleDeclaration":
18105
+ if (includeDefs) {
18106
+ visitDef(node.id);
18107
+ }
18108
+ return ["body"];
18109
+ case "ClassDeclaration":
18110
+ if (includeDefs) {
18111
+ visitDef(node.id, node);
18112
+ }
18113
+ return ["body", "superClass"];
18114
+ case "FunctionDeclaration":
18115
+ if (includeDefs) {
18116
+ visitDef(node.id, node);
18117
+ }
18118
+ return ["params", "returnType", "body"];
18119
+ case "TypedefDeclaration":
18120
+ if (includeDefs) {
18036
18121
  visitDef(node.id, node, "type_decls");
18037
18122
  }
18123
+ return ["ts"];
18124
+ case "VariableDeclarator":
18125
+ if (includeDefs) {
18126
+ visitDef(node.id, node);
18127
+ }
18128
+ if (node.id.type === "BinaryExpression") {
18129
+ state.traverse(node.id.right);
18130
+ }
18131
+ return ["init"];
18132
+ case "EnumDeclaration":
18133
+ if (includeDefs) {
18134
+ if (node.id) {
18135
+ visitDef(node.id, node, "type_decls");
18136
+ }
18137
+ break;
18138
+ }
18139
+ return [];
18140
+ case "EnumStringMember": {
18141
+ if (!filter || filter(node.id)) {
18142
+ checkResults(
18143
+ [node.id.name, [{ parent: state.top().sn, results: [node] }]],
18144
+ node
18145
+ );
18146
+ }
18038
18147
  break;
18039
18148
  }
18040
- return [];
18041
- case "EnumStringMember": {
18042
- if (!filter || filter(node.id)) {
18043
- checkResults(
18044
- [node.id.name, [{ parent: state.top().sn, results: [node] }]],
18045
- node
18046
- );
18047
- }
18048
- break;
18149
+ case "CatchClause":
18150
+ if (includeDefs)
18151
+ break;
18152
+ if (node.param && node.param.type !== "Identifier") {
18153
+ state.traverse(node.param.right);
18154
+ }
18155
+ return ["body"];
18049
18156
  }
18050
- case "CatchClause":
18051
- if (includeDefs)
18052
- break;
18053
- if (node.param && node.param.type !== "Identifier") {
18054
- state.traverse(node.param.right);
18055
- }
18056
- return ["body"];
18057
- }
18058
- return null;
18059
- };
18060
- collectNamespaces(ast, state);
18061
- delete state.pre;
18157
+ return null;
18158
+ };
18159
+ delete state.post;
18160
+ collectNamespaces(ast, state);
18161
+ } finally {
18162
+ state.pre = pre;
18163
+ state.post = post;
18164
+ }
18062
18165
  }
18063
18166
  var init_visitor = (0, import_chunk_ABYVSU2C.__esm)({
18064
18167
  "src/visitor.ts"() {
@@ -27530,7 +27633,11 @@ async function default_jungle() {
27530
27633
  assign(id, [qname(base)]);
27531
27634
  }
27532
27635
  rassign(`${id}.resourcePath`, [literal(rez)], base);
27533
- rassign(`${id}.personality`, [literal(rez)], base);
27636
+ rassign(
27637
+ `${id}.personality`,
27638
+ [literal(`${connectiq}/Devices/${id}`), literal(rez)],
27639
+ base
27640
+ );
27534
27641
  languages.forEach(
27535
27642
  (l) => rassign(`${id}.lang.${l.id}`, [literal(`${rez}-${l.id}`)], base)
27536
27643
  );
@@ -28689,7 +28796,14 @@ async function generateOptimizedProject(options) {
28689
28796
  const jungle_dir = path4.resolve(workspace, config.outputPath);
28690
28797
  await fs6.mkdir(jungle_dir, { recursive: true });
28691
28798
  const relative_path = (s) => path4.relative(jungle_dir, s);
28692
- let relative_manifest = relative_path(manifest);
28799
+ const quoted_relative_path = (s) => {
28800
+ const rel = relative_path(s);
28801
+ if (/[^-*._$/\\\w]/.test(rel)) {
28802
+ return `"${rel}"`;
28803
+ }
28804
+ return rel;
28805
+ };
28806
+ let relative_manifest = quoted_relative_path(manifest);
28693
28807
  const manifestOk = (!config.checkManifest || await checkManifest(
28694
28808
  xml,
28695
28809
  targets.map((t) => t.product)
@@ -28835,8 +28949,8 @@ async function generateOptimizedProject(options) {
28835
28949
  ).join(";")}`
28836
28950
  );
28837
28951
  }
28838
- process_field(prefix, qualifier, "resourcePath", relative_path);
28839
- process_field(prefix, qualifier, "personality", relative_path);
28952
+ process_field(prefix, qualifier, "resourcePath", quoted_relative_path);
28953
+ process_field(prefix, qualifier, "personality", quoted_relative_path);
28840
28954
  process_field(prefix, qualifier, "excludeAnnotations");
28841
28955
  const qLang = qualifier.lang;
28842
28956
  if (qLang) {
@@ -28845,7 +28959,7 @@ async function generateOptimizedProject(options) {
28845
28959
  if ((0, import_chunk_MBTLUWXR.hasProperty)(devLang, key) || !(0, import_chunk_MBTLUWXR.hasProperty)(languagesToInclude, key)) {
28846
28960
  return null;
28847
28961
  }
28848
- const mapped = map_field(qLang, key, relative_path);
28962
+ const mapped = map_field(qLang, key, quoted_relative_path);
28849
28963
  if (!mapped)
28850
28964
  return null;
28851
28965
  return [key, mapped];
@@ -28912,17 +29026,9 @@ async function fileInfoFromConfig(workspace, output, buildConfig, extraExcludes,
28912
29026
  buildConfig.sourcePath,
28913
29027
  ".mc"
28914
29028
  );
28915
- let personality = buildConfig.personality;
28916
- if (buildConfig.products) {
28917
- personality = (personality ?? []).concat(
28918
- buildConfig.products.map(
28919
- (product) => `${connectiq}/Devices/${product}/personality.mss`
28920
- )
28921
- );
28922
- }
28923
29029
  const { files: personalityFiles } = await filesFromPaths(
28924
29030
  workspace,
28925
- personality,
29031
+ buildConfig.personality,
28926
29032
  ".mss"
28927
29033
  );
28928
29034
  const excludeAnnotations = Object.assign(
@@ -29006,7 +29112,13 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
29006
29112
  ).then(({ fnMap: fnMap2 }) => fnMap2);
29007
29113
  }).flat()
29008
29114
  );
29009
- barrelFnMaps.forEach((barrelFnMap) => Object.assign(fnMap, barrelFnMap));
29115
+ barrelFnMaps.forEach(
29116
+ (barrelFnMap) => Object.entries(barrelFnMap).forEach(([key, value2]) => {
29117
+ if (!(0, import_chunk_MBTLUWXR.hasProperty)(fnMap, key)) {
29118
+ fnMap[key] = value2;
29119
+ }
29120
+ })
29121
+ );
29010
29122
  }
29011
29123
  const actualOptimizedFiles = (await (0, import_chunk_SG7ODKRM.globa)(path4.join(output, "**", "*.mc"), { mark: true })).filter((file) => !file.endsWith("/")).sort();
29012
29124
  const {
@@ -29030,7 +29142,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
29030
29142
  const opt_time = await (0, import_chunk_SG7ODKRM.first_modified)(
29031
29143
  Object.values(fnMap).map((v) => v.output)
29032
29144
  );
29033
- if (source_time < opt_time && 1713286417604 < opt_time) {
29145
+ if (source_time < opt_time && 1713815963058 < opt_time) {
29034
29146
  return {
29035
29147
  hasTests,
29036
29148
  diagnostics: prevDiagnostics,
@@ -29069,7 +29181,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
29069
29181
  hasTests: hasTests2,
29070
29182
  diagnostics,
29071
29183
  sdkVersion,
29072
- optimizerVersion: "1.1.56",
29184
+ optimizerVersion: "1.1.58",
29073
29185
  ...Object.fromEntries(
29074
29186
  configOptionsToCheck.map((option) => [option, config[option]])
29075
29187
  )
@@ -18,28 +18,28 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var optimizer_exports = {};
20
20
  __export(optimizer_exports, {
21
- StateNodeAttributes: () => import_chunk_M3LMSSY7.StateNodeAttributes,
22
- buildOptimizedProject: () => import_chunk_M3LMSSY7.buildOptimizedProject,
21
+ StateNodeAttributes: () => import_chunk_XC5IVRTO.StateNodeAttributes,
22
+ buildOptimizedProject: () => import_chunk_XC5IVRTO.buildOptimizedProject,
23
23
  copyRecursiveAsNeeded: () => import_chunk_SG7ODKRM.copyRecursiveAsNeeded,
24
- defaultConfig: () => import_chunk_M3LMSSY7.defaultConfig,
25
- display: () => import_chunk_M3LMSSY7.display,
26
- generateOneConfig: () => import_chunk_M3LMSSY7.generateOneConfig,
27
- generateOptimizedProject: () => import_chunk_M3LMSSY7.generateOptimizedProject,
28
- getConfig: () => import_chunk_M3LMSSY7.getConfig,
29
- getProjectAnalysis: () => import_chunk_M3LMSSY7.getProjectAnalysis,
30
- get_jungle: () => import_chunk_M3LMSSY7.get_jungle,
31
- isErrorWithLocation: () => import_chunk_M3LMSSY7.isErrorWithLocation,
32
- launchSimulator: () => import_chunk_M3LMSSY7.launchSimulator,
33
- manifestProducts: () => import_chunk_M3LMSSY7.manifestProducts,
34
- mctree: () => import_chunk_M3LMSSY7.mctree,
35
- simulateProgram: () => import_chunk_M3LMSSY7.simulateProgram
24
+ defaultConfig: () => import_chunk_XC5IVRTO.defaultConfig,
25
+ display: () => import_chunk_XC5IVRTO.display,
26
+ generateOneConfig: () => import_chunk_XC5IVRTO.generateOneConfig,
27
+ generateOptimizedProject: () => import_chunk_XC5IVRTO.generateOptimizedProject,
28
+ getConfig: () => import_chunk_XC5IVRTO.getConfig,
29
+ getProjectAnalysis: () => import_chunk_XC5IVRTO.getProjectAnalysis,
30
+ get_jungle: () => import_chunk_XC5IVRTO.get_jungle,
31
+ isErrorWithLocation: () => import_chunk_XC5IVRTO.isErrorWithLocation,
32
+ launchSimulator: () => import_chunk_XC5IVRTO.launchSimulator,
33
+ manifestProducts: () => import_chunk_XC5IVRTO.manifestProducts,
34
+ mctree: () => import_chunk_XC5IVRTO.mctree,
35
+ simulateProgram: () => import_chunk_XC5IVRTO.simulateProgram
36
36
  });
37
37
  module.exports = __toCommonJS(optimizer_exports);
38
- var import_chunk_M3LMSSY7 = require("./chunk-M3LMSSY7.cjs");
38
+ var import_chunk_XC5IVRTO = require("./chunk-XC5IVRTO.cjs");
39
39
  var import_chunk_SG7ODKRM = require("./chunk-SG7ODKRM.cjs");
40
40
  var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.cjs");
41
41
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
42
- (0, import_chunk_M3LMSSY7.init_optimizer)();
42
+ (0, import_chunk_XC5IVRTO.init_optimizer)();
43
43
  // Annotate the CommonJS export names for ESM import in node:
44
44
  0 && (module.exports = {
45
45
  StateNodeAttributes,
@@ -18,25 +18,25 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var sdk_util_exports = {};
20
20
  __export(sdk_util_exports, {
21
- SectionKinds: () => import_chunk_M3LMSSY7.SectionKinds,
22
- appSupport: () => import_chunk_M3LMSSY7.appSupport,
23
- connectiq: () => import_chunk_M3LMSSY7.connectiq,
24
- getDeviceInfo: () => import_chunk_M3LMSSY7.getDeviceInfo,
25
- getFunctionDocumentation: () => import_chunk_M3LMSSY7.getFunctionDocumentation,
26
- getLanguages: () => import_chunk_M3LMSSY7.getLanguages,
27
- getSdkPath: () => import_chunk_M3LMSSY7.getSdkPath,
28
- isWin: () => import_chunk_M3LMSSY7.isWin,
29
- optimizeProgram: () => import_chunk_M3LMSSY7.optimizeProgram,
30
- readPrg: () => import_chunk_M3LMSSY7.readPrg,
31
- readPrgWithOffsets: () => import_chunk_M3LMSSY7.readPrgWithOffsets,
32
- xmlUtil: () => import_chunk_M3LMSSY7.xml_util_exports
21
+ SectionKinds: () => import_chunk_XC5IVRTO.SectionKinds,
22
+ appSupport: () => import_chunk_XC5IVRTO.appSupport,
23
+ connectiq: () => import_chunk_XC5IVRTO.connectiq,
24
+ getDeviceInfo: () => import_chunk_XC5IVRTO.getDeviceInfo,
25
+ getFunctionDocumentation: () => import_chunk_XC5IVRTO.getFunctionDocumentation,
26
+ getLanguages: () => import_chunk_XC5IVRTO.getLanguages,
27
+ getSdkPath: () => import_chunk_XC5IVRTO.getSdkPath,
28
+ isWin: () => import_chunk_XC5IVRTO.isWin,
29
+ optimizeProgram: () => import_chunk_XC5IVRTO.optimizeProgram,
30
+ readPrg: () => import_chunk_XC5IVRTO.readPrg,
31
+ readPrgWithOffsets: () => import_chunk_XC5IVRTO.readPrgWithOffsets,
32
+ xmlUtil: () => import_chunk_XC5IVRTO.xml_util_exports
33
33
  });
34
34
  module.exports = __toCommonJS(sdk_util_exports);
35
- var import_chunk_M3LMSSY7 = require("./chunk-M3LMSSY7.cjs");
35
+ var import_chunk_XC5IVRTO = require("./chunk-XC5IVRTO.cjs");
36
36
  var import_chunk_SG7ODKRM = require("./chunk-SG7ODKRM.cjs");
37
37
  var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.cjs");
38
38
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
39
- (0, import_chunk_M3LMSSY7.init_sdk_util)();
39
+ (0, import_chunk_XC5IVRTO.init_sdk_util)();
40
40
  // Annotate the CommonJS export names for ESM import in node:
41
41
  0 && (module.exports = {
42
42
  SectionKinds,
@@ -21,17 +21,17 @@ __export(worker_thread_exports, {
21
21
  default: () => worker_thread_default
22
22
  });
23
23
  module.exports = __toCommonJS(worker_thread_exports);
24
- var import_chunk_M3LMSSY7 = require("./chunk-M3LMSSY7.cjs");
24
+ var import_chunk_XC5IVRTO = require("./chunk-XC5IVRTO.cjs");
25
25
  var import_chunk_SG7ODKRM = require("./chunk-SG7ODKRM.cjs");
26
26
  var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.cjs");
27
27
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
28
28
  var import_node_worker_threads = require("node:worker_threads");
29
29
  var require_worker_thread = (0, import_chunk_ABYVSU2C.__commonJS)({
30
30
  "src/worker-thread.ts"() {
31
- (0, import_chunk_M3LMSSY7.init_worker_task)();
31
+ (0, import_chunk_XC5IVRTO.init_worker_task)();
32
32
  if (import_node_worker_threads.parentPort) {
33
33
  import_node_worker_threads.parentPort.on("message", async (task) => {
34
- return import_node_worker_threads.parentPort.postMessage(await (0, import_chunk_M3LMSSY7.performTask)(task));
34
+ return import_node_worker_threads.parentPort.postMessage(await (0, import_chunk_XC5IVRTO.performTask)(task));
35
35
  });
36
36
  }
37
37
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@markw65/monkeyc-optimizer",
3
3
  "type": "commonjs",
4
- "version": "1.1.56",
4
+ "version": "1.1.58",
5
5
  "description": "Source to source optimizer for Garmin Monkey C code",
6
6
  "main": "build/optimizer.cjs",
7
7
  "types": "build/src/optimizer.d.ts",
@@ -52,7 +52,7 @@
52
52
  "author": "markw65",
53
53
  "license": "MIT",
54
54
  "dependencies": {
55
- "@markw65/prettier-plugin-monkeyc": "^1.0.56"
55
+ "@markw65/prettier-plugin-monkeyc": "^1.0.57"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@markw65/peggy-optimizer": "^1.0.1",