@markw65/monkeyc-optimizer 1.1.75 → 1.1.77

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,16 @@
2
2
 
3
3
  All notable changes to the "monkeyc-optimizer" package will be documented in this file.
4
4
 
5
+ ### 1.1.77
6
+
7
+ - Fix an infinite recursion issue with nested classes
8
+ - Fix a problem analyzing 'instanceof Boolean'
9
+
10
+ ### 1.1.76
11
+
12
+ - Fix member expression lookup when base type is exact
13
+ - Fix path-resolution inside locals in jungle files
14
+
5
15
  ### 1.1.75
6
16
 
7
17
  - Fix issues using personality files from barrels
package/build/api.cjs CHANGED
@@ -18,55 +18,57 @@ 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_7GXXJDR3.checkCompilerVersion,
22
- collectNamespaces: () => import_chunk_7GXXJDR3.collectNamespaces,
23
- createDocumentationMap: () => import_chunk_7GXXJDR3.createDocumentationMap,
24
- diagnostic: () => import_chunk_7GXXJDR3.diagnostic,
25
- diagnosticHelper: () => import_chunk_7GXXJDR3.diagnosticHelper,
26
- findNamesInScope: () => import_chunk_7GXXJDR3.findNamesInScope,
27
- findUsingForNode: () => import_chunk_7GXXJDR3.findUsingForNode,
28
- formatAst: () => import_chunk_7GXXJDR3.formatAst,
29
- formatAstLongLines: () => import_chunk_7GXXJDR3.formatAstLongLines,
30
- formatScopedName: () => import_chunk_7GXXJDR3.formatScopedName,
31
- getApiFunctionInfo: () => import_chunk_7GXXJDR3.getApiFunctionInfo,
32
- getApiMapping: () => import_chunk_7GXXJDR3.getApiMapping,
33
- getSuperClasses: () => import_chunk_7GXXJDR3.getSuperClasses,
34
- handleImportUsing: () => import_chunk_7GXXJDR3.handleImportUsing,
21
+ checkCompilerVersion: () => import_chunk_G6WICLD7.checkCompilerVersion,
22
+ collectNamespaces: () => import_chunk_G6WICLD7.collectNamespaces,
23
+ createDocumentationMap: () => import_chunk_G6WICLD7.createDocumentationMap,
24
+ declKey: () => import_chunk_G6WICLD7.declKey,
25
+ diagnostic: () => import_chunk_G6WICLD7.diagnostic,
26
+ diagnosticHelper: () => import_chunk_G6WICLD7.diagnosticHelper,
27
+ findNamesInScope: () => import_chunk_G6WICLD7.findNamesInScope,
28
+ findUsingForNode: () => import_chunk_G6WICLD7.findUsingForNode,
29
+ formatAst: () => import_chunk_G6WICLD7.formatAst,
30
+ formatAstLongLines: () => import_chunk_G6WICLD7.formatAstLongLines,
31
+ formatScopedName: () => import_chunk_G6WICLD7.formatScopedName,
32
+ getApiFunctionInfo: () => import_chunk_G6WICLD7.getApiFunctionInfo,
33
+ getApiMapping: () => import_chunk_G6WICLD7.getApiMapping,
34
+ getSuperClasses: () => import_chunk_G6WICLD7.getSuperClasses,
35
+ handleImportUsing: () => import_chunk_G6WICLD7.handleImportUsing,
35
36
  hasProperty: () => import_chunk_JDC43A3I.hasProperty,
36
- isClassVariable: () => import_chunk_7GXXJDR3.isClassVariable,
37
- isLocal: () => import_chunk_7GXXJDR3.isLocal,
38
- isLookupCandidate: () => import_chunk_7GXXJDR3.isLookupCandidate,
39
- isStateNode: () => import_chunk_7GXXJDR3.isStateNode,
40
- lookupByFullName: () => import_chunk_7GXXJDR3.lookupByFullName,
41
- lookupNext: () => import_chunk_7GXXJDR3.lookupNext,
42
- lookupResultContains: () => import_chunk_7GXXJDR3.lookupResultContains,
43
- lookupWithType: () => import_chunk_7GXXJDR3.lookupWithType,
44
- makeToyboxLink: () => import_chunk_7GXXJDR3.makeToyboxLink,
45
- mapVarDeclsByType: () => import_chunk_7GXXJDR3.mapVarDeclsByType,
46
- markInvokeClassMethod: () => import_chunk_7GXXJDR3.markInvokeClassMethod,
47
- parseSdkVersion: () => import_chunk_7GXXJDR3.parseSdkVersion,
48
- popRootNode: () => import_chunk_7GXXJDR3.popRootNode,
49
- pushRootNode: () => import_chunk_7GXXJDR3.pushRootNode,
50
- resolveDiagnostics: () => import_chunk_7GXXJDR3.resolveDiagnostics,
51
- resolveDiagnosticsMap: () => import_chunk_7GXXJDR3.resolveDiagnosticsMap,
52
- sameLookupResult: () => import_chunk_7GXXJDR3.sameLookupResult,
37
+ isClassVariable: () => import_chunk_G6WICLD7.isClassVariable,
38
+ isLocal: () => import_chunk_G6WICLD7.isLocal,
39
+ isLookupCandidate: () => import_chunk_G6WICLD7.isLookupCandidate,
40
+ isStateNode: () => import_chunk_G6WICLD7.isStateNode,
41
+ lookupByFullName: () => import_chunk_G6WICLD7.lookupByFullName,
42
+ lookupNext: () => import_chunk_G6WICLD7.lookupNext,
43
+ lookupResultContains: () => import_chunk_G6WICLD7.lookupResultContains,
44
+ lookupWithType: () => import_chunk_G6WICLD7.lookupWithType,
45
+ makeToyboxLink: () => import_chunk_G6WICLD7.makeToyboxLink,
46
+ mapVarDeclsByType: () => import_chunk_G6WICLD7.mapVarDeclsByType,
47
+ markInvokeClassMethod: () => import_chunk_G6WICLD7.markInvokeClassMethod,
48
+ parseSdkVersion: () => import_chunk_G6WICLD7.parseSdkVersion,
49
+ popRootNode: () => import_chunk_G6WICLD7.popRootNode,
50
+ pushRootNode: () => import_chunk_G6WICLD7.pushRootNode,
51
+ resolveDiagnostics: () => import_chunk_G6WICLD7.resolveDiagnostics,
52
+ resolveDiagnosticsMap: () => import_chunk_G6WICLD7.resolveDiagnosticsMap,
53
+ sameLookupResult: () => import_chunk_G6WICLD7.sameLookupResult,
53
54
  traverseAst: () => import_chunk_JDC43A3I.traverseAst,
54
- variableDeclarationName: () => import_chunk_7GXXJDR3.variableDeclarationName,
55
- visitReferences: () => import_chunk_7GXXJDR3.visitReferences,
56
- visit_resources: () => import_chunk_7GXXJDR3.visit_resources,
57
- visitorNode: () => import_chunk_7GXXJDR3.visitorNode
55
+ variableDeclarationName: () => import_chunk_G6WICLD7.variableDeclarationName,
56
+ visitReferences: () => import_chunk_G6WICLD7.visitReferences,
57
+ visit_resources: () => import_chunk_G6WICLD7.visit_resources,
58
+ visitorNode: () => import_chunk_G6WICLD7.visitorNode
58
59
  });
59
60
  module.exports = __toCommonJS(api_exports);
60
- var import_chunk_7GXXJDR3 = require("./chunk-7GXXJDR3.cjs");
61
+ var import_chunk_G6WICLD7 = require("./chunk-G6WICLD7.cjs");
61
62
  var import_chunk_NHZRKHZO = require("./chunk-NHZRKHZO.cjs");
62
63
  var import_chunk_JDC43A3I = require("./chunk-JDC43A3I.cjs");
63
64
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
64
- (0, import_chunk_7GXXJDR3.init_api)();
65
+ (0, import_chunk_G6WICLD7.init_api)();
65
66
  // Annotate the CommonJS export names for ESM import in node:
66
67
  0 && (module.exports = {
67
68
  checkCompilerVersion,
68
69
  collectNamespaces,
69
70
  createDocumentationMap,
71
+ declKey,
70
72
  diagnostic,
71
73
  diagnosticHelper,
72
74
  findNamesInScope,
@@ -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_7GXXJDR3_exports = {};
30
- __export(chunk_7GXXJDR3_exports, {
29
+ var chunk_G6WICLD7_exports = {};
30
+ __export(chunk_G6WICLD7_exports, {
31
31
  EnumTagsConst: () => EnumTagsConst,
32
32
  LastTypeTag: () => LastTypeTag,
33
33
  ObjectLikeTagsConst: () => ObjectLikeTagsConst,
@@ -44,6 +44,7 @@ __export(chunk_7GXXJDR3_exports, {
44
44
  connectiq: () => connectiq,
45
45
  couldBe: () => couldBe,
46
46
  createDocumentationMap: () => createDocumentationMap,
47
+ declKey: () => declKey,
47
48
  defaultConfig: () => defaultConfig,
48
49
  diagnostic: () => diagnostic,
49
50
  diagnosticHelper: () => diagnosticHelper,
@@ -138,7 +139,7 @@ __export(chunk_7GXXJDR3_exports, {
138
139
  visitorNode: () => visitorNode,
139
140
  xml_util_exports: () => xml_util_exports
140
141
  });
141
- module.exports = __toCommonJS(chunk_7GXXJDR3_exports);
142
+ module.exports = __toCommonJS(chunk_G6WICLD7_exports);
142
143
  var import_chunk_NHZRKHZO = require("./chunk-NHZRKHZO.cjs");
143
144
  var import_chunk_JDC43A3I = require("./chunk-JDC43A3I.cjs");
144
145
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
@@ -9273,89 +9274,84 @@ function printBlockTrailer(block) {
9273
9274
  `Succs: ${(block.succs || []).map((block2) => block2.order).join(", ")} ExSucc: ${block.exsucc ? block.exsucc.order : ""}`
9274
9275
  );
9275
9276
  }
9276
- function filterDecls(decls, possible, name) {
9277
+ function filterDecls(state, decls, next) {
9278
+ const possible = (0, import_chunk_JDC43A3I.hasProperty)(state.allDeclarations, next.name) && state.allDeclarations[next.name];
9277
9279
  if (!possible)
9278
9280
  return [null, null];
9279
- const result = decls.reduce(
9280
- (cur, decl) => {
9281
- let declSups;
9282
- const found = possible.reduce((flag, poss) => {
9283
- if (decl === poss || poss.type === "ClassDeclaration" && getSuperClasses(poss)?.has(decl)) {
9284
- if (!cur[0]) {
9285
- cur = [/* @__PURE__ */ new Set(), /* @__PURE__ */ new Set()];
9286
- }
9287
- cur[0].add(poss);
9288
- cur[1].add(poss);
9289
- return true;
9290
- } else if (declSups !== void 0 ? declSups?.has(poss) : decl.type === "ClassDeclaration" && (declSups = getSuperClasses(decl))?.has(poss)) {
9291
- if (!cur[0]) {
9292
- cur = [/* @__PURE__ */ new Set([decl]), /* @__PURE__ */ new Set([poss])];
9293
- } else {
9294
- cur[0].add(decl);
9295
- if (Array.from(cur[1]).every((d) => {
9296
- if (decl === d)
9297
- return false;
9298
- if (!declSups.has(d))
9299
- return true;
9300
- if (d.type === "ClassDeclaration" && getSuperClasses(d)?.has(poss)) {
9301
- return false;
9302
- }
9303
- if (poss.type === "ClassDeclaration" && getSuperClasses(poss)?.has(d)) {
9304
- cur[1].delete(d);
9305
- }
9306
- return true;
9307
- })) {
9308
- cur[1].add(poss);
9309
- }
9281
+ const result = decls.reduce((cur, { sn: decl, exact }) => {
9282
+ let declSups;
9283
+ const getDeclSups = () => declSups !== void 0 ? declSups : decl.type === "ClassDeclaration" ? declSups = getSuperClasses(decl) : null;
9284
+ const found = possible.reduce((flag, poss) => {
9285
+ if (decl === poss || !exact && poss.type === "ClassDeclaration" && getSuperClasses(poss)?.has(decl)) {
9286
+ if (!cur) {
9287
+ cur = [/* @__PURE__ */ new Set(), /* @__PURE__ */ new Set(), /* @__PURE__ */ new Set()];
9288
+ }
9289
+ cur[0].add(poss);
9290
+ cur[1].add(poss);
9291
+ if (cur[2].size && decl === poss && decl.type === "ClassDeclaration") {
9292
+ const posSupers = getSuperClasses(decl);
9293
+ if (posSupers) {
9294
+ cur[2].forEach((s) => posSupers.has(s) && cur[2].delete(s));
9310
9295
  }
9311
- return true;
9312
9296
  }
9313
- return flag;
9314
- }, false);
9315
- if (!found) {
9316
- let d = [decl];
9317
- do {
9318
- d.forEach((d2) => {
9319
- const stack = d2.stack;
9320
- possible.forEach((poss) => {
9321
- for (let i = stack.length; i--; ) {
9322
- const sn = stack[i].sn;
9323
- if (sn.decls === poss.decls) {
9324
- if (!cur[0]) {
9325
- cur = [/* @__PURE__ */ new Set(), /* @__PURE__ */ new Set()];
9326
- }
9327
- cur[0].add(decl);
9328
- cur[1].add(poss);
9329
- break;
9330
- }
9331
- if ((0, import_chunk_JDC43A3I.hasProperty)(sn.decls, name)) {
9332
- break;
9297
+ return true;
9298
+ } else if (poss.type === "ClassDeclaration" && getDeclSups()?.has(poss)) {
9299
+ if (!cur) {
9300
+ cur = [/* @__PURE__ */ new Set(), /* @__PURE__ */ new Set(), /* @__PURE__ */ new Set()];
9301
+ }
9302
+ cur[0].add(decl);
9303
+ const supers = Array.from(cur[2]);
9304
+ if (!supers.some((s) => getSuperClasses(s)?.has(poss))) {
9305
+ const posSupers = getSuperClasses(poss);
9306
+ posSupers && supers.forEach((s) => posSupers.has(s) && cur[2].delete(s));
9307
+ cur[2].add(poss);
9308
+ }
9309
+ return true;
9310
+ }
9311
+ return flag;
9312
+ }, false);
9313
+ if (!found) {
9314
+ let d = [decl];
9315
+ do {
9316
+ d.forEach((d2) => {
9317
+ const stack = d2.stack;
9318
+ possible.forEach((poss) => {
9319
+ for (let i = stack.length; i--; ) {
9320
+ const sn = stack[i].sn;
9321
+ if (sn.decls === poss.decls) {
9322
+ if (!cur) {
9323
+ cur = [/* @__PURE__ */ new Set(), /* @__PURE__ */ new Set(), /* @__PURE__ */ new Set()];
9333
9324
  }
9325
+ cur[0].add(decl);
9326
+ cur[1].add(poss);
9327
+ break;
9328
+ }
9329
+ if ((0, import_chunk_JDC43A3I.hasProperty)(sn.decls, next.name)) {
9330
+ break;
9334
9331
  }
9335
- });
9336
- });
9337
- d = d.flatMap((d2) => {
9338
- if (d2.type !== "ClassDeclaration" || !d2.superClass || d2.superClass === true) {
9339
- return [];
9340
9332
  }
9341
- return d2.superClass;
9342
9333
  });
9343
- } while (d.length);
9344
- }
9345
- return cur;
9346
- },
9347
- [null, null]
9348
- );
9349
- if (!result[0])
9334
+ });
9335
+ d = d.flatMap((d2) => {
9336
+ if (d2.type !== "ClassDeclaration" || !d2.superClass || d2.superClass === true) {
9337
+ return [];
9338
+ }
9339
+ return d2.superClass;
9340
+ });
9341
+ } while (d.length);
9342
+ }
9343
+ return cur;
9344
+ }, null);
9345
+ if (!result)
9350
9346
  return [null, null];
9347
+ result[2].forEach((c) => result[1].add(c));
9351
9348
  return [Array.from(result[0]), Array.from(result[1])];
9352
9349
  }
9353
9350
  function findObjectDeclsByProperty(state, object, next) {
9354
- const decls = getStateNodeDeclsFromType(state, object);
9351
+ const decls = getStateNodeDeclsWithExactFromType(state, object);
9355
9352
  if (!decls)
9356
9353
  return [null, null];
9357
- const possibleDecls = (0, import_chunk_JDC43A3I.hasProperty)(state.allDeclarations, next.name) && state.allDeclarations[next.name];
9358
- return filterDecls(decls, possibleDecls, next.name);
9354
+ return filterDecls(state, decls, next);
9359
9355
  }
9360
9356
  function refineObjectTypeByDecls(istate, object, trueDecls) {
9361
9357
  const refinedType = typeFromTypeStateNodes(istate.state, trueDecls);
@@ -12207,6 +12203,9 @@ function setUnionComponent(v, tag, c) {
12207
12203
  }
12208
12204
  }
12209
12205
  function getStateNodeDeclsFromType(state, object) {
12206
+ return getStateNodeDeclsWithExactFromType(state, object).map(({ sn }) => sn);
12207
+ }
12208
+ function getStateNodeDeclsWithExactFromType(state, object) {
12210
12209
  const decls = [];
12211
12210
  if (object.value != null && object.type & (4096 | 16384 | 32768)) {
12212
12211
  forEachUnionComponent(
@@ -12218,20 +12217,15 @@ function getStateNodeDeclsFromType(state, object) {
12218
12217
  switch (type.type) {
12219
12218
  case 32768:
12220
12219
  if (type.value.klass.type === 16384 && type.value.klass.value) {
12221
- if (Array.isArray(type.value.klass.value)) {
12222
- decls.push(...type.value.klass.value);
12223
- } else {
12224
- decls.push(type.value.klass.value);
12225
- }
12220
+ (0, import_chunk_NHZRKHZO.forEach)(
12221
+ type.value.klass.value,
12222
+ (sn) => decls.push({ sn, exact: false })
12223
+ );
12226
12224
  }
12227
12225
  break;
12228
12226
  case 4096:
12229
12227
  case 16384:
12230
- if (Array.isArray(type.value)) {
12231
- decls.push(...type.value);
12232
- } else {
12233
- decls.push(type.value);
12234
- }
12228
+ (0, import_chunk_NHZRKHZO.forEach)(type.value, (sn) => decls.push({ sn, exact: true }));
12235
12229
  break;
12236
12230
  }
12237
12231
  }
@@ -12251,7 +12245,7 @@ function getStateNodeDeclsFromType(state, object) {
12251
12245
  }
12252
12246
  const name = `Toybox.Lang.${typeTagName(bit)}`;
12253
12247
  const sns = lookupByFullName(state, name);
12254
- sns.forEach((sn) => isStateNode(sn) && decls.push(sn));
12248
+ sns.forEach((sn) => isStateNode(sn) && decls.push({ sn, exact: true }));
12255
12249
  bits = next;
12256
12250
  } while (bits);
12257
12251
  }
@@ -12804,7 +12798,7 @@ function buildTypeInfo(state, root, optimizeEquivalencies) {
12804
12798
  }
12805
12799
  }
12806
12800
  const stack = root.stack.slice();
12807
- pushRootNode(stack, root);
12801
+ pushRootNode(state, stack, root);
12808
12802
  const { istate, redo } = propagateTypes(
12809
12803
  { ...state, stack },
12810
12804
  root,
@@ -13834,7 +13828,7 @@ function propagateTypes(state, root, graph, optimizeEquivalencies, copyPropStore
13834
13828
  let result = null;
13835
13829
  if (truthy === (event.kind === 6)) {
13836
13830
  result = intersection(left, right);
13837
- } else if (isExact(right)) {
13831
+ } else if (isExact(right) || right.type === 6) {
13838
13832
  if (right.type === 32768) {
13839
13833
  if (right.value == null) {
13840
13834
  result = cloneType(left);
@@ -16846,6 +16840,10 @@ function collectClassInfo(state) {
16846
16840
  state.allClasses.forEach((elm) => {
16847
16841
  if (elm.stack[elm.stack.length - 1].sn.type === "ClassDeclaration") {
16848
16842
  elm.stack = elm.stack.slice(0, 1);
16843
+ if (!(0, import_chunk_JDC43A3I.hasProperty)(state.nestedClasses, elm.name)) {
16844
+ state.nestedClasses[elm.name] = [];
16845
+ }
16846
+ state.nestedClasses[elm.name].push(elm);
16849
16847
  }
16850
16848
  if (elm.node.superClass) {
16851
16849
  const [name, lookupDefns] = state.lookup(
@@ -16980,6 +16978,7 @@ async function analyze(fnMap, resourcesMap, manifestXML, config, allowParseError
16980
16978
  config,
16981
16979
  allFunctions: {},
16982
16980
  allClasses: [],
16981
+ nestedClasses: {},
16983
16982
  allModules: /* @__PURE__ */ new Set(),
16984
16983
  shouldExclude(node) {
16985
16984
  if ("attrs" in node && node.attrs && "attributes" in node.attrs && node.attrs.attributes && node.loc?.source) {
@@ -18899,12 +18898,12 @@ function checkCompilerVersion(version, sdkVer) {
18899
18898
  }
18900
18899
  return sdkVer <= v2;
18901
18900
  }
18902
- function pushRootNode(stack, root) {
18901
+ function pushRootNode(state, stack, root) {
18903
18902
  if (root.type === "Program")
18904
18903
  return;
18905
18904
  const sn = root.stack?.at(-1)?.sn?.decls?.[root.name]?.find(
18906
18905
  (sn2) => sn2.type === root.type && (root.nodes != null || sn2.node === root.node)
18907
- );
18906
+ ) ?? state.nestedClasses[root.name]?.find((d) => d.node === root.node);
18908
18907
  if (!sn) {
18909
18908
  throw new Error(`Invalid stack for node ${root.fullName}`);
18910
18909
  }
@@ -19504,6 +19503,15 @@ function stateFuncs() {
19504
19503
  case "ModuleDeclaration": {
19505
19504
  const parent = this.top().sn;
19506
19505
  const name = "id" in node ? node.id && node.id.name : void 0;
19506
+ if (name && node.type === "ClassDeclaration") {
19507
+ const sn = this.nestedClasses?.[name]?.find(
19508
+ (d) => d.node === node
19509
+ );
19510
+ if (sn) {
19511
+ this.stack.push({ sn });
19512
+ break;
19513
+ }
19514
+ }
19507
19515
  const fullName = this.stack.map((e) => e.sn.name).concat(name).filter((e) => e != null).join(".");
19508
19516
  const elm = {
19509
19517
  type: node.type,
@@ -28599,7 +28607,13 @@ function evaluate_locals(assignments) {
28599
28607
  while (true) {
28600
28608
  assignments = assignments.filter((a) => {
28601
28609
  if (a.names.length === 1 && a.values.every((v) => v.type === "Literal")) {
28602
- locals[a.names[0]] = a.values;
28610
+ locals[a.names[0]] = a.values.map((v) => {
28611
+ if ("source" in v) {
28612
+ v = { ...v };
28613
+ delete v.source;
28614
+ }
28615
+ return v;
28616
+ });
28603
28617
  return false;
28604
28618
  }
28605
28619
  return true;
@@ -29551,13 +29565,13 @@ async function analyze_module_types(state) {
29551
29565
  const saved = istate.state.stack;
29552
29566
  root.nodes.forEach((stack, node) => {
29553
29567
  istate.state.stack = stack.slice();
29554
- pushRootNode(istate.state.stack, root);
29568
+ pushRootNode(istate.state, istate.state.stack, root);
29555
29569
  evaluate(istate, node);
29556
29570
  popRootNode(istate.state.stack, root);
29557
29571
  });
29558
29572
  istate.state.stack = saved;
29559
29573
  } else {
29560
- pushRootNode(istate.state.stack, root);
29574
+ pushRootNode(istate.state, istate.state.stack, root);
29561
29575
  evaluate(istate, root.node);
29562
29576
  popRootNode(istate.state.stack, root);
29563
29577
  }
@@ -30184,7 +30198,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
30184
30198
  const opt_time = await (0, import_chunk_NHZRKHZO.first_modified)(
30185
30199
  Object.values(fnMap).map((v) => v.output)
30186
30200
  );
30187
- if (source_time < opt_time && 1726412336564 < opt_time) {
30201
+ if (source_time < opt_time && 1727624657655 < opt_time) {
30188
30202
  return {
30189
30203
  hasTests,
30190
30204
  diagnostics: prevDiagnostics,
@@ -30222,7 +30236,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
30222
30236
  hasTests: hasTests2,
30223
30237
  diagnostics,
30224
30238
  sdkVersion,
30225
- optimizerVersion: "1.1.75",
30239
+ optimizerVersion: "1.1.77",
30226
30240
  ...Object.fromEntries(
30227
30241
  configOptionsToCheck.map((option) => [option, config[option]])
30228
30242
  )
@@ -31057,6 +31071,7 @@ var init_sdk_util = (0, import_chunk_ABYVSU2C.__esm)({
31057
31071
  connectiq,
31058
31072
  couldBe,
31059
31073
  createDocumentationMap,
31074
+ declKey,
31060
31075
  defaultConfig,
31061
31076
  diagnostic,
31062
31077
  diagnosticHelper,
@@ -18,30 +18,30 @@ 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_7GXXJDR3.StateNodeAttributes,
22
- buildConfigDescription: () => import_chunk_7GXXJDR3.buildConfigDescription,
23
- buildOptimizedProject: () => import_chunk_7GXXJDR3.buildOptimizedProject,
21
+ StateNodeAttributes: () => import_chunk_G6WICLD7.StateNodeAttributes,
22
+ buildConfigDescription: () => import_chunk_G6WICLD7.buildConfigDescription,
23
+ buildOptimizedProject: () => import_chunk_G6WICLD7.buildOptimizedProject,
24
24
  copyRecursiveAsNeeded: () => import_chunk_NHZRKHZO.copyRecursiveAsNeeded,
25
- defaultConfig: () => import_chunk_7GXXJDR3.defaultConfig,
26
- display: () => import_chunk_7GXXJDR3.display,
27
- generateOneConfig: () => import_chunk_7GXXJDR3.generateOneConfig,
28
- generateOptimizedProject: () => import_chunk_7GXXJDR3.generateOptimizedProject,
29
- getConfig: () => import_chunk_7GXXJDR3.getConfig,
30
- getFnMapAnalysis: () => import_chunk_7GXXJDR3.getFnMapAnalysis,
31
- getProjectAnalysis: () => import_chunk_7GXXJDR3.getProjectAnalysis,
32
- get_jungle: () => import_chunk_7GXXJDR3.get_jungle,
33
- isErrorWithLocation: () => import_chunk_7GXXJDR3.isErrorWithLocation,
34
- launchSimulator: () => import_chunk_7GXXJDR3.launchSimulator,
35
- manifestProducts: () => import_chunk_7GXXJDR3.manifestProducts,
36
- mctree: () => import_chunk_7GXXJDR3.mctree,
37
- simulateProgram: () => import_chunk_7GXXJDR3.simulateProgram
25
+ defaultConfig: () => import_chunk_G6WICLD7.defaultConfig,
26
+ display: () => import_chunk_G6WICLD7.display,
27
+ generateOneConfig: () => import_chunk_G6WICLD7.generateOneConfig,
28
+ generateOptimizedProject: () => import_chunk_G6WICLD7.generateOptimizedProject,
29
+ getConfig: () => import_chunk_G6WICLD7.getConfig,
30
+ getFnMapAnalysis: () => import_chunk_G6WICLD7.getFnMapAnalysis,
31
+ getProjectAnalysis: () => import_chunk_G6WICLD7.getProjectAnalysis,
32
+ get_jungle: () => import_chunk_G6WICLD7.get_jungle,
33
+ isErrorWithLocation: () => import_chunk_G6WICLD7.isErrorWithLocation,
34
+ launchSimulator: () => import_chunk_G6WICLD7.launchSimulator,
35
+ manifestProducts: () => import_chunk_G6WICLD7.manifestProducts,
36
+ mctree: () => import_chunk_G6WICLD7.mctree,
37
+ simulateProgram: () => import_chunk_G6WICLD7.simulateProgram
38
38
  });
39
39
  module.exports = __toCommonJS(optimizer_exports);
40
- var import_chunk_7GXXJDR3 = require("./chunk-7GXXJDR3.cjs");
40
+ var import_chunk_G6WICLD7 = require("./chunk-G6WICLD7.cjs");
41
41
  var import_chunk_NHZRKHZO = require("./chunk-NHZRKHZO.cjs");
42
42
  var import_chunk_JDC43A3I = require("./chunk-JDC43A3I.cjs");
43
43
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
44
- (0, import_chunk_7GXXJDR3.init_optimizer)();
44
+ (0, import_chunk_G6WICLD7.init_optimizer)();
45
45
  // Annotate the CommonJS export names for ESM import in node:
46
46
  0 && (module.exports = {
47
47
  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_7GXXJDR3.SectionKinds,
22
- appSupport: () => import_chunk_7GXXJDR3.appSupport,
23
- connectiq: () => import_chunk_7GXXJDR3.connectiq,
24
- getDeviceInfo: () => import_chunk_7GXXJDR3.getDeviceInfo,
25
- getFunctionDocumentation: () => import_chunk_7GXXJDR3.getFunctionDocumentation,
26
- getLanguages: () => import_chunk_7GXXJDR3.getLanguages,
27
- getSdkPath: () => import_chunk_7GXXJDR3.getSdkPath,
28
- isWin: () => import_chunk_7GXXJDR3.isWin,
29
- optimizeProgram: () => import_chunk_7GXXJDR3.optimizeProgram,
30
- readPrg: () => import_chunk_7GXXJDR3.readPrg,
31
- readPrgWithOffsets: () => import_chunk_7GXXJDR3.readPrgWithOffsets,
32
- xmlUtil: () => import_chunk_7GXXJDR3.xml_util_exports
21
+ SectionKinds: () => import_chunk_G6WICLD7.SectionKinds,
22
+ appSupport: () => import_chunk_G6WICLD7.appSupport,
23
+ connectiq: () => import_chunk_G6WICLD7.connectiq,
24
+ getDeviceInfo: () => import_chunk_G6WICLD7.getDeviceInfo,
25
+ getFunctionDocumentation: () => import_chunk_G6WICLD7.getFunctionDocumentation,
26
+ getLanguages: () => import_chunk_G6WICLD7.getLanguages,
27
+ getSdkPath: () => import_chunk_G6WICLD7.getSdkPath,
28
+ isWin: () => import_chunk_G6WICLD7.isWin,
29
+ optimizeProgram: () => import_chunk_G6WICLD7.optimizeProgram,
30
+ readPrg: () => import_chunk_G6WICLD7.readPrg,
31
+ readPrgWithOffsets: () => import_chunk_G6WICLD7.readPrgWithOffsets,
32
+ xmlUtil: () => import_chunk_G6WICLD7.xml_util_exports
33
33
  });
34
34
  module.exports = __toCommonJS(sdk_util_exports);
35
- var import_chunk_7GXXJDR3 = require("./chunk-7GXXJDR3.cjs");
35
+ var import_chunk_G6WICLD7 = require("./chunk-G6WICLD7.cjs");
36
36
  var import_chunk_NHZRKHZO = require("./chunk-NHZRKHZO.cjs");
37
37
  var import_chunk_JDC43A3I = require("./chunk-JDC43A3I.cjs");
38
38
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
39
- (0, import_chunk_7GXXJDR3.init_sdk_util)();
39
+ (0, import_chunk_G6WICLD7.init_sdk_util)();
40
40
  // Annotate the CommonJS export names for ESM import in node:
41
41
  0 && (module.exports = {
42
42
  SectionKinds,
@@ -10,7 +10,7 @@ export { visitReferences, visitorNode } from "./visitor";
10
10
  export { hasProperty, traverseAst, visit_resources };
11
11
  export declare function parseSdkVersion(version: string | undefined): number;
12
12
  export declare function checkCompilerVersion(version: string, sdkVer: number): boolean | undefined;
13
- export declare function pushRootNode(stack: ProgramStateStack, root: RootStateNode): void;
13
+ export declare function pushRootNode(state: ProgramStateAnalysis, stack: ProgramStateStack, root: RootStateNode): void;
14
14
  export declare function popRootNode(stack: ProgramStateStack, root: RootStateNode): void;
15
15
  export declare function getApiMapping(state?: ProgramState, resourcesMap?: Record<string, JungleResourceMap>, manifestXML?: xmlUtil.Document): Promise<ProgramStateNode>;
16
16
  export declare function isStateNode(node: {
@@ -19,6 +19,7 @@ export declare function isStateNode(node: {
19
19
  export declare function variableDeclarationName(node: mctree.TypedIdentifier | mctree.InstanceofIdentifier): string;
20
20
  type DeclKind = "decls" | "type_decls";
21
21
  export declare function sameLookupResult(a: LookupDefinition[], b: LookupDefinition[]): boolean;
22
+ export declare function declKey(decl: StateNodeDecl): string | mctree.Identifier | mctree.Program | mctree.VariableDeclarator | mctree.EnumStringMember | mctree.BlockStatement | mctree.ForStatement | mctree.ClassDeclaration | mctree.EnumDeclaration | mctree.FunctionDeclaration | mctree.TypedefDeclaration | mctree.AsIdentifier | undefined;
22
23
  export declare function lookupResultContains(a: LookupDefinition[], b: LookupDefinition[]): boolean;
23
24
  export declare function isLookupCandidate(node: mctree.MemberExpression): false | mctree.Identifier;
24
25
  export declare function lookupNext(state: ProgramStateLive, results: LookupDefinition[], decls: DeclKind, property: mctree.Identifier): LookupDefinition[] | null;
@@ -136,6 +136,7 @@ export type ByNameStateNodeDecls = ModuleStateNode | ClassStateNode | FunctionSt
136
136
  export type ProgramState = {
137
137
  allFunctions?: Record<string, FunctionStateNode[]>;
138
138
  allClasses?: ClassStateNode[];
139
+ nestedClasses?: Record<string, ClassStateNode[]>;
139
140
  allModules?: Set<ModuleStateNode>;
140
141
  invokeInfo?: FunctionInfo;
141
142
  allDeclarations?: Record<string, ByNameStateNodeDecls[]>;
@@ -190,7 +191,7 @@ export type Finalized<T, Keys extends keyof T> = T & {
190
191
  [key in Keys]-?: NonNullable<T[key]>;
191
192
  };
192
193
  export type ProgramStateLive = Finalized<ProgramState, "stack" | "top" | "lookup" | "lookupValue" | "lookupType" | "lookupNonlocal" | "stackClone" | "traverse" | "index" | "constants" | "removeNodeComments" | "inType" | "nextExposed" | "lookupRules">;
193
- export type ProgramStateAnalysis = Finalized<ProgramStateLive, "allClasses" | "allModules" | "allFunctions" | "fnMap" | "allDeclarations" | "invokeInfo">;
194
+ export type ProgramStateAnalysis = Finalized<ProgramStateLive, "allClasses" | "nestedClasses" | "allModules" | "allFunctions" | "fnMap" | "allDeclarations" | "invokeInfo">;
194
195
  export type ProgramStateOptimizer = Finalized<ProgramStateAnalysis, "localsStack" | "exposed" | "calledFunctions" | "usedByName">;
195
196
  export type ExcludeAnnotationsMap = {
196
197
  [key: string]: boolean;
@@ -211,4 +211,8 @@ export declare function forEachUnionComponent(v: ExactOrUnion, bits: TypeTag, fn
211
211
  export declare function getUnionComponent<T extends ExactTypeTags>(v: ExactOrUnion, tag: T): ExactData<T> | null;
212
212
  export declare function setUnionComponent<T extends ExactTypeTags>(v: ExactOrUnion, tag: T, c: ExactData<T>): void;
213
213
  export declare function getStateNodeDeclsFromType(state: ProgramStateAnalysis, object: ExactOrUnion): StateNode[];
214
+ export declare function getStateNodeDeclsWithExactFromType(state: ProgramStateAnalysis, object: ExactOrUnion): {
215
+ sn: StateNode;
216
+ exact: boolean;
217
+ }[];
214
218
  export {};
@@ -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_7GXXJDR3 = require("./chunk-7GXXJDR3.cjs");
24
+ var import_chunk_G6WICLD7 = require("./chunk-G6WICLD7.cjs");
25
25
  var import_chunk_NHZRKHZO = require("./chunk-NHZRKHZO.cjs");
26
26
  var import_chunk_JDC43A3I = require("./chunk-JDC43A3I.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_7GXXJDR3.init_worker_task)();
31
+ (0, import_chunk_G6WICLD7.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_7GXXJDR3.performTask)(task));
34
+ return import_node_worker_threads.parentPort.postMessage(await (0, import_chunk_G6WICLD7.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.75",
4
+ "version": "1.1.77",
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",