@markw65/monkeyc-optimizer 1.1.82 → 1.1.83

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,12 @@
2
2
 
3
3
  All notable changes to the "monkeyc-optimizer" package will be documented in this file.
4
4
 
5
+ ### 1.1.83
6
+
7
+ - Rewrite enums to handle arbitrary unions (Fixes #48)
8
+ - Clear typedef cache when an enum is converted to a typedef
9
+ - Support barrel qualifiers in personality references (Fixes #54)
10
+
5
11
  ### 1.1.82
6
12
 
7
13
  - Fix type for resource ids that contain refs (Fixes #53)
package/build/api.cjs CHANGED
@@ -18,51 +18,51 @@ 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_TLXMWGYI.checkCompilerVersion,
22
- collectNamespaces: () => import_chunk_TLXMWGYI.collectNamespaces,
23
- createDocumentationMap: () => import_chunk_TLXMWGYI.createDocumentationMap,
24
- declKey: () => import_chunk_TLXMWGYI.declKey,
25
- diagnostic: () => import_chunk_TLXMWGYI.diagnostic,
26
- diagnosticHelper: () => import_chunk_TLXMWGYI.diagnosticHelper,
27
- findNamesInScope: () => import_chunk_TLXMWGYI.findNamesInScope,
28
- findUsingForNode: () => import_chunk_TLXMWGYI.findUsingForNode,
29
- formatAst: () => import_chunk_TLXMWGYI.formatAst,
30
- formatAstLongLines: () => import_chunk_TLXMWGYI.formatAstLongLines,
31
- formatScopedName: () => import_chunk_TLXMWGYI.formatScopedName,
32
- getApiFunctionInfo: () => import_chunk_TLXMWGYI.getApiFunctionInfo,
33
- getApiMapping: () => import_chunk_TLXMWGYI.getApiMapping,
34
- getSuperClasses: () => import_chunk_TLXMWGYI.getSuperClasses,
35
- handleImportUsing: () => import_chunk_TLXMWGYI.handleImportUsing,
21
+ checkCompilerVersion: () => import_chunk_UNU55JJ3.checkCompilerVersion,
22
+ collectNamespaces: () => import_chunk_UNU55JJ3.collectNamespaces,
23
+ createDocumentationMap: () => import_chunk_UNU55JJ3.createDocumentationMap,
24
+ declKey: () => import_chunk_UNU55JJ3.declKey,
25
+ diagnostic: () => import_chunk_UNU55JJ3.diagnostic,
26
+ diagnosticHelper: () => import_chunk_UNU55JJ3.diagnosticHelper,
27
+ findNamesInScope: () => import_chunk_UNU55JJ3.findNamesInScope,
28
+ findUsingForNode: () => import_chunk_UNU55JJ3.findUsingForNode,
29
+ formatAst: () => import_chunk_UNU55JJ3.formatAst,
30
+ formatAstLongLines: () => import_chunk_UNU55JJ3.formatAstLongLines,
31
+ formatScopedName: () => import_chunk_UNU55JJ3.formatScopedName,
32
+ getApiFunctionInfo: () => import_chunk_UNU55JJ3.getApiFunctionInfo,
33
+ getApiMapping: () => import_chunk_UNU55JJ3.getApiMapping,
34
+ getSuperClasses: () => import_chunk_UNU55JJ3.getSuperClasses,
35
+ handleImportUsing: () => import_chunk_UNU55JJ3.handleImportUsing,
36
36
  hasProperty: () => import_chunk_JDC43A3I.hasProperty,
37
- isClassVariable: () => import_chunk_TLXMWGYI.isClassVariable,
38
- isLocal: () => import_chunk_TLXMWGYI.isLocal,
39
- isLookupCandidate: () => import_chunk_TLXMWGYI.isLookupCandidate,
40
- isStateNode: () => import_chunk_TLXMWGYI.isStateNode,
41
- lookupByFullName: () => import_chunk_TLXMWGYI.lookupByFullName,
42
- lookupNext: () => import_chunk_TLXMWGYI.lookupNext,
43
- lookupResultContains: () => import_chunk_TLXMWGYI.lookupResultContains,
44
- lookupWithType: () => import_chunk_TLXMWGYI.lookupWithType,
45
- makeToyboxLink: () => import_chunk_TLXMWGYI.makeToyboxLink,
46
- mapVarDeclsByType: () => import_chunk_TLXMWGYI.mapVarDeclsByType,
47
- markInvokeClassMethod: () => import_chunk_TLXMWGYI.markInvokeClassMethod,
48
- parseSdkVersion: () => import_chunk_TLXMWGYI.parseSdkVersion,
49
- popRootNode: () => import_chunk_TLXMWGYI.popRootNode,
50
- pushRootNode: () => import_chunk_TLXMWGYI.pushRootNode,
51
- resolveDiagnostics: () => import_chunk_TLXMWGYI.resolveDiagnostics,
52
- resolveDiagnosticsMap: () => import_chunk_TLXMWGYI.resolveDiagnosticsMap,
53
- sameLookupResult: () => import_chunk_TLXMWGYI.sameLookupResult,
37
+ isClassVariable: () => import_chunk_UNU55JJ3.isClassVariable,
38
+ isLocal: () => import_chunk_UNU55JJ3.isLocal,
39
+ isLookupCandidate: () => import_chunk_UNU55JJ3.isLookupCandidate,
40
+ isStateNode: () => import_chunk_UNU55JJ3.isStateNode,
41
+ lookupByFullName: () => import_chunk_UNU55JJ3.lookupByFullName,
42
+ lookupNext: () => import_chunk_UNU55JJ3.lookupNext,
43
+ lookupResultContains: () => import_chunk_UNU55JJ3.lookupResultContains,
44
+ lookupWithType: () => import_chunk_UNU55JJ3.lookupWithType,
45
+ makeToyboxLink: () => import_chunk_UNU55JJ3.makeToyboxLink,
46
+ mapVarDeclsByType: () => import_chunk_UNU55JJ3.mapVarDeclsByType,
47
+ markInvokeClassMethod: () => import_chunk_UNU55JJ3.markInvokeClassMethod,
48
+ parseSdkVersion: () => import_chunk_UNU55JJ3.parseSdkVersion,
49
+ popRootNode: () => import_chunk_UNU55JJ3.popRootNode,
50
+ pushRootNode: () => import_chunk_UNU55JJ3.pushRootNode,
51
+ resolveDiagnostics: () => import_chunk_UNU55JJ3.resolveDiagnostics,
52
+ resolveDiagnosticsMap: () => import_chunk_UNU55JJ3.resolveDiagnosticsMap,
53
+ sameLookupResult: () => import_chunk_UNU55JJ3.sameLookupResult,
54
54
  traverseAst: () => import_chunk_JDC43A3I.traverseAst,
55
- variableDeclarationName: () => import_chunk_TLXMWGYI.variableDeclarationName,
56
- visitReferences: () => import_chunk_TLXMWGYI.visitReferences,
57
- visit_resources: () => import_chunk_TLXMWGYI.visit_resources,
58
- visitorNode: () => import_chunk_TLXMWGYI.visitorNode
55
+ variableDeclarationName: () => import_chunk_UNU55JJ3.variableDeclarationName,
56
+ visitReferences: () => import_chunk_UNU55JJ3.visitReferences,
57
+ visit_resources: () => import_chunk_UNU55JJ3.visit_resources,
58
+ visitorNode: () => import_chunk_UNU55JJ3.visitorNode
59
59
  });
60
60
  module.exports = __toCommonJS(api_exports);
61
- var import_chunk_TLXMWGYI = require("./chunk-TLXMWGYI.cjs");
61
+ var import_chunk_UNU55JJ3 = require("./chunk-UNU55JJ3.cjs");
62
62
  var import_chunk_X7QCZR3F = require("./chunk-X7QCZR3F.cjs");
63
63
  var import_chunk_JDC43A3I = require("./chunk-JDC43A3I.cjs");
64
64
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
65
- (0, import_chunk_TLXMWGYI.init_api)();
65
+ (0, import_chunk_UNU55JJ3.init_api)();
66
66
  // Annotate the CommonJS export names for ESM import in node:
67
67
  0 && (module.exports = {
68
68
  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_TLXMWGYI_exports = {};
30
- __export(chunk_TLXMWGYI_exports, {
29
+ var chunk_UNU55JJ3_exports = {};
30
+ __export(chunk_UNU55JJ3_exports, {
31
31
  EnumTagsConst: () => EnumTagsConst,
32
32
  LastTypeTag: () => LastTypeTag,
33
33
  ObjectLikeTagsConst: () => ObjectLikeTagsConst,
@@ -139,7 +139,7 @@ __export(chunk_TLXMWGYI_exports, {
139
139
  visitorNode: () => visitorNode,
140
140
  xml_util_exports: () => xml_util_exports
141
141
  });
142
- module.exports = __toCommonJS(chunk_TLXMWGYI_exports);
142
+ module.exports = __toCommonJS(chunk_UNU55JJ3_exports);
143
143
  var import_chunk_X7QCZR3F = require("./chunk-X7QCZR3F.cjs");
144
144
  var import_chunk_JDC43A3I = require("./chunk-JDC43A3I.cjs");
145
145
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
@@ -7897,28 +7897,33 @@ function mergeSingle(pair, widenDepth) {
7897
7897
  case 65536: {
7898
7898
  const toE = pair.avalue;
7899
7899
  const fromE = pair.bvalue;
7900
- if (toE.enum !== fromE.enum) {
7901
- if (toE.value && fromE.value) {
7902
- const result = cloneType(toE.value);
7903
- unionHelper(result, fromE.value, widenDepth + 1);
7904
- const e = { value: result };
7905
- return [e, true];
7900
+ let changed = false;
7901
+ let resultEnum = toE.enum;
7902
+ const s = new Set(
7903
+ Array.isArray(toE.enum) ? toE.enum : [toE.enum]
7904
+ );
7905
+ const size = s.size;
7906
+ (0, import_chunk_X7QCZR3F.forEach)(fromE.enum, (e) => s.add(e));
7907
+ if (size !== s.size) {
7908
+ resultEnum = Array.from(s);
7909
+ changed = true;
7910
+ }
7911
+ let resultValue = toE.value;
7912
+ if (resultValue) {
7913
+ if (fromE.value) {
7914
+ resultValue = cloneType(resultValue);
7915
+ if (unionHelper(resultValue, fromE.value, widenDepth + 1)) {
7916
+ changed = true;
7917
+ }
7918
+ } else {
7919
+ resultValue = void 0;
7920
+ changed = true;
7906
7921
  }
7907
- return [null, true];
7908
7922
  }
7909
- if (!toE.value) {
7923
+ if (!changed) {
7910
7924
  return [toE, false];
7911
7925
  }
7912
- if (!fromE.value) {
7913
- delete toE.value;
7914
- return [toE, true];
7915
- }
7916
- const toValue = tryUnion(toE.value, fromE.value);
7917
- if (toValue) {
7918
- const e = { enum: toE.enum, value: toValue };
7919
- return [e, true];
7920
- }
7921
- return [toE, false];
7926
+ return resultValue ? [{ enum: resultEnum, value: resultValue }, changed] : [{ enum: resultEnum }, changed];
7922
7927
  }
7923
7928
  default:
7924
7929
  unhandledType(pair);
@@ -8063,10 +8068,7 @@ function intersectEnum(t, e) {
8063
8068
  /* Enum */
8064
8069
  );
8065
8070
  const e2 = cloneType(e);
8066
- const i = intersection(
8067
- t,
8068
- !enumData ? { type: EnumTagsConst } : enumData.value ? enumData.value : enumData.enum?.resolvedType || { type: EnumTagsConst }
8069
- );
8071
+ const i = intersection(t, typeFromEnumValue(enumData));
8070
8072
  if (e2.value != null) {
8071
8073
  clearValuesUnder(e2, 65536, true);
8072
8074
  } else {
@@ -8295,19 +8297,21 @@ function intersectionValue(pair) {
8295
8297
  return klass.type !== 16384 || klass.value == null ? null : obj ? { klass, obj } : { klass };
8296
8298
  }
8297
8299
  case 65536: {
8298
- if (pair.avalue.enum !== pair.bvalue.enum && pair.avalue.enum && pair.bvalue.enum) {
8299
- return null;
8300
- }
8301
- const enumDecl = pair.avalue.enum || pair.bvalue.enum;
8302
- if (pair.avalue.value != null) {
8303
- if (pair.bvalue.value != null) {
8304
- const value2 = intersection(pair.avalue.value, pair.bvalue.value);
8305
- const e = { enum: enumDecl, value: value2 };
8306
- return e;
8300
+ let enumDecl;
8301
+ if (Array.isArray(pair.avalue.enum)) {
8302
+ const s = new Set(pair.avalue.enum);
8303
+ const enums = [];
8304
+ (0, import_chunk_X7QCZR3F.forEach)(pair.bvalue.enum, (b) => s.has(b) && enums.push(b));
8305
+ if (enums.length) {
8306
+ enumDecl = enums.length === 1 ? enums[0] : enums;
8307
8307
  }
8308
- return pair.avalue.value;
8308
+ } else {
8309
+ (0, import_chunk_X7QCZR3F.some)(pair.bvalue.enum, (b) => b === pair.avalue.enum) && (enumDecl = pair.bvalue.enum);
8309
8310
  }
8310
- return pair.bvalue;
8311
+ if (!enumDecl)
8312
+ return null;
8313
+ const enumValue = pair.avalue.value != null ? pair.bvalue.value != null ? intersection(pair.avalue.value, pair.bvalue.value) : pair.avalue.value : pair.bvalue.value;
8314
+ return { enum: enumDecl, value: enumValue };
8311
8315
  }
8312
8316
  default:
8313
8317
  unhandledType(pair);
@@ -8339,12 +8343,7 @@ function fixupEnum(a, b_restricted, b) {
8339
8343
  65536
8340
8344
  /* Enum */
8341
8345
  );
8342
- const br = restrictByEquality(
8343
- a,
8344
- bvalue && (bvalue.value || bvalue.enum?.resolvedType) || {
8345
- type: EnumTagsConst
8346
- }
8347
- );
8346
+ const br = restrictByEquality(a, typeFromEnumValue(bvalue));
8348
8347
  if (br.type) {
8349
8348
  b_restricted = cloneType(b_restricted);
8350
8349
  unionInto(
@@ -8512,12 +8511,7 @@ function restrictExactTypesByEquality(a, b) {
8512
8511
  case 131072:
8513
8512
  return intersection(a, b);
8514
8513
  case 65536: {
8515
- return restrictByEquality(
8516
- a.value && (a.value.value || a.value.enum?.resolvedType) || {
8517
- type: EnumTagsConst
8518
- },
8519
- b
8520
- );
8514
+ return restrictByEquality(typeFromEnumValue(a.value), b);
8521
8515
  }
8522
8516
  case 262144:
8523
8517
  return restrictByEquality(
@@ -8608,12 +8602,7 @@ function subtypeOf(a, b) {
8608
8602
  65536
8609
8603
  /* Enum */
8610
8604
  );
8611
- if (!subtypeOf(
8612
- value2 != null && (value2.value || value2.enum?.resolvedType) || {
8613
- type: EnumTagsConst
8614
- },
8615
- b
8616
- )) {
8605
+ if (!subtypeOf(typeFromEnumValue(value2), b)) {
8617
8606
  return false;
8618
8607
  }
8619
8608
  if (a.type === 65536)
@@ -8740,7 +8729,12 @@ function subtypeOfValue(pair) {
8740
8729
  case 65536: {
8741
8730
  const aenum = pair.avalue;
8742
8731
  const benum = pair.bvalue;
8743
- return aenum.enum === benum.enum && (!aenum.value || !benum.value || subtypeOf(aenum.value, benum.value));
8732
+ if (benum.value) {
8733
+ if (!aenum.value || !subtypeOf(aenum.value, benum.value)) {
8734
+ return false;
8735
+ }
8736
+ }
8737
+ return (0, import_chunk_X7QCZR3F.every)(aenum.enum, (ea) => (0, import_chunk_X7QCZR3F.some)(benum.enum, (eb) => ea === eb));
8744
8738
  }
8745
8739
  default:
8746
8740
  unhandledType(pair);
@@ -10476,12 +10470,7 @@ function deEnumerate(t) {
10476
10470
  );
10477
10471
  t = cloneType(t);
10478
10472
  clearValuesUnder(t, 65536, true);
10479
- unionInto(
10480
- t,
10481
- data && (data.value || data.enum?.resolvedType) || {
10482
- type: EnumTagsConst
10483
- }
10484
- );
10473
+ unionInto(t, typeFromEnumValue(data));
10485
10474
  }
10486
10475
  return t;
10487
10476
  }
@@ -12024,11 +12013,8 @@ function mcExprFromType(type) {
12024
12013
  if (type.value.value && hasValue(type.value.value)) {
12025
12014
  const left = mcExprFromType(type.value.value);
12026
12015
  if (left) {
12027
- if (!type.value.enum) {
12028
- return left;
12029
- }
12030
- const enumStr = type.value.enum.fullName.slice(2);
12031
- if (enumStr === "Toybox.Graphics.ColorValue" && left.type === "Literal" && typeof left.value === "number" && left.value >= 0 && left.value <= 16777215 && /^\d+$/.test(left.raw)) {
12016
+ const enumStrs = (0, import_chunk_X7QCZR3F.map)(type.value.enum, (e) => e.fullName.slice(2));
12017
+ if (enumStrs.length === 1 && enumStrs[0] === "Toybox.Graphics.ColorValue" && left.type === "Literal" && typeof left.value === "number" && left.value >= 0 && left.value <= 16777215 && /^\d+$/.test(left.raw)) {
12032
12018
  left.raw = "0x" + `00000${left.value.toString(16)}`.slice(-6);
12033
12019
  }
12034
12020
  return {
@@ -12037,7 +12023,7 @@ function mcExprFromType(type) {
12037
12023
  left,
12038
12024
  right: {
12039
12025
  type: "TypeSpecList",
12040
- ts: [type.value.enum.fullName.slice(2)]
12026
+ ts: enumStrs
12041
12027
  }
12042
12028
  };
12043
12029
  }
@@ -12191,7 +12177,8 @@ function display(type) {
12191
12177
  }
12192
12178
  case 65536: {
12193
12179
  const v = tv.value;
12194
- return v.enum != null ? v.value != null ? `${display(v.value)} as ${v.enum.fullName.slice(2)}` : v.enum.fullName.slice(2) : v.value != null ? `enum<${display(v.value)}>` : `enum`;
12180
+ const name = v.enum ? (0, import_chunk_X7QCZR3F.map)(v.enum, (e) => e.fullName.slice(2)).join(" or ") : "";
12181
+ return v.value != null ? `${display(v.value)} as ${name}` : name;
12195
12182
  }
12196
12183
  case 131072:
12197
12184
  return `:${tv.value}`;
@@ -12414,6 +12401,18 @@ function checkArrayCovariance(arg, param) {
12414
12401
  function safeReferenceArg(arg) {
12415
12402
  return arg.type === "ArrayExpression" || arg.type === "ObjectExpression" || arg.type === "NewExpression";
12416
12403
  }
12404
+ function typeFromEnumValue(arg) {
12405
+ return arg?.value ?? (arg && reducedType(
12406
+ (0, import_chunk_X7QCZR3F.map)(
12407
+ arg.enum,
12408
+ (e) => e.resolvedType ?? {
12409
+ type: EnumTagsConst
12410
+ }
12411
+ )
12412
+ )) ?? {
12413
+ type: EnumTagsConst
12414
+ };
12415
+ }
12417
12416
  var LastTypeTag, SingletonTypeTagsConst, UnionDataTypeTagsConst, ValueTypeTagsConst, ObjectLikeTagsConst, EnumTagsConst, TruthyTypes;
12418
12417
  var init_types = (0, import_chunk_ABYVSU2C.__esm)({
12419
12418
  "src/type-flow/types.ts"() {
@@ -12591,7 +12590,10 @@ function couldBeValue(pair, shallow) {
12591
12590
  return couldBe(pair.avalue.klass, pair.bvalue.klass) && (shallow || couldBeObj(pair.avalue.obj, pair.bvalue.obj));
12592
12591
  }
12593
12592
  case 65536: {
12594
- return pair.avalue.enum === pair.bvalue.enum && (!pair.avalue.value || !pair.bvalue.value || couldBe(pair.avalue.value, pair.bvalue.value));
12593
+ return (!pair.avalue.value || !pair.bvalue.value || couldBe(pair.avalue.value, pair.bvalue.value)) && (0, import_chunk_X7QCZR3F.some)(
12594
+ pair.avalue.enum,
12595
+ (sna) => (0, import_chunk_X7QCZR3F.some)(pair.bvalue.enum, (snb) => sna === snb)
12596
+ );
12595
12597
  }
12596
12598
  default:
12597
12599
  unhandledType(pair);
@@ -17182,6 +17184,7 @@ async function analyze(fnMap, resourcesMap, manifestXML, config, allowParseError
17182
17184
  allClasses: [],
17183
17185
  nestedClasses: {},
17184
17186
  allModules: /* @__PURE__ */ new Set(),
17187
+ allTypedefs: /* @__PURE__ */ new Set(),
17185
17188
  shouldExclude(node) {
17186
17189
  if ("attrs" in node && node.attrs && "attributes" in node.attrs && node.attrs.attributes && node.loc?.source) {
17187
17190
  const excludeAnnotations = fnMap[node.loc.source].excludeAnnotations;
@@ -17874,7 +17877,7 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
17874
17877
  changes |= 1;
17875
17878
  this.removeNodeComments(node, f.ast);
17876
17879
  } else if (ret) {
17877
- if (node.type === "EnumDeclaration" && ret.type === "TypedefDeclaration" && ret.ts.argument.ts.length > 1) {
17880
+ if (node.type === "EnumDeclaration" && ret.type === "TypedefDeclaration") {
17878
17881
  changes |= 2;
17879
17882
  } else {
17880
17883
  changes |= 1;
@@ -17883,6 +17886,9 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
17883
17886
  return ret;
17884
17887
  };
17885
17888
  collectNamespaces(f.ast, state2);
17889
+ if (changes & 2) {
17890
+ state2.allTypedefs?.forEach((t) => delete t.resolvedType);
17891
+ }
17886
17892
  return changes;
17887
17893
  },
17888
17894
  0
@@ -18074,14 +18080,10 @@ function cleanup(state, node, ast, usedNodes) {
18074
18080
  (d) => d.type === "EnumDeclaration" && d.node === node
18075
18081
  );
18076
18082
  if (i >= 0) {
18077
- const old = decls[i];
18078
- const rep = {
18079
- ...old,
18080
- type: "TypedefDeclaration",
18081
- node: typedefDecl
18082
- };
18083
+ const rep = decls[i];
18084
+ rep.type = "TypedefDeclaration";
18085
+ rep.node = typedefDecl;
18083
18086
  delete rep.resolvedType;
18084
- decls.splice(i, 1, rep);
18085
18087
  }
18086
18088
  }
18087
18089
  return typedefDecl;
@@ -18541,8 +18543,11 @@ function visit_resource_refs(state, doc, e, barrelNames) {
18541
18543
  loc.start.offset -= name.length;
18542
18544
  }
18543
18545
  } else {
18544
- const base = (0, import_chunk_JDC43A3I.makeScopedName)(`Rez.Styles`);
18545
- const idLoc = (0, import_chunk_JDC43A3I.adjustLoc)(loc, 0, 0);
18546
+ const colonPos = name.indexOf(":");
18547
+ const barrel = colonPos < 0 ? "" : name.slice(0, colonPos) + ".";
18548
+ name = name.slice(colonPos + 1);
18549
+ const base = (0, import_chunk_JDC43A3I.makeScopedName)(`${barrel}Rez.Styles`);
18550
+ const idLoc = (0, import_chunk_JDC43A3I.adjustLoc)(loc, colonPos + 1, 0);
18546
18551
  idLoc.end = { ...idLoc.start };
18547
18552
  idLoc.end.column += name.length;
18548
18553
  idLoc.end.offset += name.length;
@@ -19823,6 +19828,8 @@ function stateFuncs() {
19823
19828
  parent.type_decls[name].push(decl);
19824
19829
  if (decl.type === "EnumDeclaration") {
19825
19830
  currentEnum = decl;
19831
+ } else {
19832
+ this.allTypedefs?.add(decl);
19826
19833
  }
19827
19834
  break;
19828
19835
  }
@@ -30406,7 +30413,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
30406
30413
  const opt_time = await (0, import_chunk_X7QCZR3F.first_modified)(
30407
30414
  Object.values(fnMap).map((v) => v.output)
30408
30415
  );
30409
- if (source_time < opt_time && 1732486572981 < opt_time) {
30416
+ if (source_time < opt_time && 1732680967178 < opt_time) {
30410
30417
  return {
30411
30418
  hasTests,
30412
30419
  diagnostics: prevDiagnostics,
@@ -30444,7 +30451,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
30444
30451
  hasTests: hasTests2,
30445
30452
  diagnostics,
30446
30453
  sdkVersion,
30447
- optimizerVersion: "1.1.82",
30454
+ optimizerVersion: "1.1.83",
30448
30455
  ...Object.fromEntries(
30449
30456
  configOptionsToCheck.map((option) => [option, config[option]])
30450
30457
  )
@@ -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_TLXMWGYI.StateNodeAttributes,
22
- buildConfigDescription: () => import_chunk_TLXMWGYI.buildConfigDescription,
23
- buildOptimizedProject: () => import_chunk_TLXMWGYI.buildOptimizedProject,
21
+ StateNodeAttributes: () => import_chunk_UNU55JJ3.StateNodeAttributes,
22
+ buildConfigDescription: () => import_chunk_UNU55JJ3.buildConfigDescription,
23
+ buildOptimizedProject: () => import_chunk_UNU55JJ3.buildOptimizedProject,
24
24
  copyRecursiveAsNeeded: () => import_chunk_X7QCZR3F.copyRecursiveAsNeeded,
25
- defaultConfig: () => import_chunk_TLXMWGYI.defaultConfig,
26
- display: () => import_chunk_TLXMWGYI.display,
27
- generateOneConfig: () => import_chunk_TLXMWGYI.generateOneConfig,
28
- generateOptimizedProject: () => import_chunk_TLXMWGYI.generateOptimizedProject,
29
- getConfig: () => import_chunk_TLXMWGYI.getConfig,
30
- getFnMapAnalysis: () => import_chunk_TLXMWGYI.getFnMapAnalysis,
31
- getProjectAnalysis: () => import_chunk_TLXMWGYI.getProjectAnalysis,
32
- get_jungle: () => import_chunk_TLXMWGYI.get_jungle,
33
- isErrorWithLocation: () => import_chunk_TLXMWGYI.isErrorWithLocation,
34
- launchSimulator: () => import_chunk_TLXMWGYI.launchSimulator,
35
- manifestProducts: () => import_chunk_TLXMWGYI.manifestProducts,
36
- mctree: () => import_chunk_TLXMWGYI.mctree,
37
- simulateProgram: () => import_chunk_TLXMWGYI.simulateProgram
25
+ defaultConfig: () => import_chunk_UNU55JJ3.defaultConfig,
26
+ display: () => import_chunk_UNU55JJ3.display,
27
+ generateOneConfig: () => import_chunk_UNU55JJ3.generateOneConfig,
28
+ generateOptimizedProject: () => import_chunk_UNU55JJ3.generateOptimizedProject,
29
+ getConfig: () => import_chunk_UNU55JJ3.getConfig,
30
+ getFnMapAnalysis: () => import_chunk_UNU55JJ3.getFnMapAnalysis,
31
+ getProjectAnalysis: () => import_chunk_UNU55JJ3.getProjectAnalysis,
32
+ get_jungle: () => import_chunk_UNU55JJ3.get_jungle,
33
+ isErrorWithLocation: () => import_chunk_UNU55JJ3.isErrorWithLocation,
34
+ launchSimulator: () => import_chunk_UNU55JJ3.launchSimulator,
35
+ manifestProducts: () => import_chunk_UNU55JJ3.manifestProducts,
36
+ mctree: () => import_chunk_UNU55JJ3.mctree,
37
+ simulateProgram: () => import_chunk_UNU55JJ3.simulateProgram
38
38
  });
39
39
  module.exports = __toCommonJS(optimizer_exports);
40
- var import_chunk_TLXMWGYI = require("./chunk-TLXMWGYI.cjs");
40
+ var import_chunk_UNU55JJ3 = require("./chunk-UNU55JJ3.cjs");
41
41
  var import_chunk_X7QCZR3F = require("./chunk-X7QCZR3F.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_TLXMWGYI.init_optimizer)();
44
+ (0, import_chunk_UNU55JJ3.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_TLXMWGYI.SectionKinds,
22
- appSupport: () => import_chunk_TLXMWGYI.appSupport,
23
- connectiq: () => import_chunk_TLXMWGYI.connectiq,
24
- getDeviceInfo: () => import_chunk_TLXMWGYI.getDeviceInfo,
25
- getFunctionDocumentation: () => import_chunk_TLXMWGYI.getFunctionDocumentation,
26
- getLanguages: () => import_chunk_TLXMWGYI.getLanguages,
27
- getSdkPath: () => import_chunk_TLXMWGYI.getSdkPath,
28
- isWin: () => import_chunk_TLXMWGYI.isWin,
29
- optimizeProgram: () => import_chunk_TLXMWGYI.optimizeProgram,
30
- readPrg: () => import_chunk_TLXMWGYI.readPrg,
31
- readPrgWithOffsets: () => import_chunk_TLXMWGYI.readPrgWithOffsets,
32
- xmlUtil: () => import_chunk_TLXMWGYI.xml_util_exports
21
+ SectionKinds: () => import_chunk_UNU55JJ3.SectionKinds,
22
+ appSupport: () => import_chunk_UNU55JJ3.appSupport,
23
+ connectiq: () => import_chunk_UNU55JJ3.connectiq,
24
+ getDeviceInfo: () => import_chunk_UNU55JJ3.getDeviceInfo,
25
+ getFunctionDocumentation: () => import_chunk_UNU55JJ3.getFunctionDocumentation,
26
+ getLanguages: () => import_chunk_UNU55JJ3.getLanguages,
27
+ getSdkPath: () => import_chunk_UNU55JJ3.getSdkPath,
28
+ isWin: () => import_chunk_UNU55JJ3.isWin,
29
+ optimizeProgram: () => import_chunk_UNU55JJ3.optimizeProgram,
30
+ readPrg: () => import_chunk_UNU55JJ3.readPrg,
31
+ readPrgWithOffsets: () => import_chunk_UNU55JJ3.readPrgWithOffsets,
32
+ xmlUtil: () => import_chunk_UNU55JJ3.xml_util_exports
33
33
  });
34
34
  module.exports = __toCommonJS(sdk_util_exports);
35
- var import_chunk_TLXMWGYI = require("./chunk-TLXMWGYI.cjs");
35
+ var import_chunk_UNU55JJ3 = require("./chunk-UNU55JJ3.cjs");
36
36
  var import_chunk_X7QCZR3F = require("./chunk-X7QCZR3F.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_TLXMWGYI.init_sdk_util)();
39
+ (0, import_chunk_UNU55JJ3.init_sdk_util)();
40
40
  // Annotate the CommonJS export names for ESM import in node:
41
41
  0 && (module.exports = {
42
42
  SectionKinds,
@@ -31,7 +31,7 @@ export declare function findNamesInScope(declStack: StateNode[][], pattern: stri
31
31
  readonly parent: StateNode;
32
32
  readonly depth: number;
33
33
  }])[];
34
- export declare function mapVarDeclsByType(state: ProgramStateAnalysis, decls: StateNodeDecl[], node: mctree.Node, typeMap: TypeMap | null | undefined): (mctree.Identifier | mctree.EnumStringMember | mctree.AsIdentifier | ProgramStateNode | FunctionStateNode | ModuleStateNode | ClassStateNode | VariableStateNode | import("./optimizer-types").BlockStateNode | TypedefStateNode | EnumStateNode)[];
34
+ export declare function mapVarDeclsByType(state: ProgramStateAnalysis, decls: StateNodeDecl[], node: mctree.Node, typeMap: TypeMap | null | undefined): (mctree.Identifier | mctree.EnumStringMember | mctree.AsIdentifier | ProgramStateNode | FunctionStateNode | ModuleStateNode | ClassStateNode | TypedefStateNode | VariableStateNode | import("./optimizer-types").BlockStateNode | EnumStateNode)[];
35
35
  export declare function formatScopedName(node: mctree.ScopedName | mctree.ThisExpression): string;
36
36
  export declare function formatAstLongLines(node: mctree.Node): Promise<string>;
37
37
  export declare function createDocumentationMap(functionDocumentation: {
@@ -138,6 +138,7 @@ export type ProgramState = {
138
138
  allClasses?: ClassStateNode[];
139
139
  nestedClasses?: Record<string, ClassStateNode[]>;
140
140
  allModules?: Set<ModuleStateNode>;
141
+ allTypedefs?: Set<TypedefStateNode>;
141
142
  invokeInfo?: FunctionInfo;
142
143
  allDeclarations?: Record<string, ByNameStateNodeDecls[]>;
143
144
  fnMap?: FilesToOptimizeMap;
@@ -191,7 +192,7 @@ export type Finalized<T, Keys extends keyof T> = T & {
191
192
  [key in Keys]-?: NonNullable<T[key]>;
192
193
  };
193
194
  export type ProgramStateLive = Finalized<ProgramState, "stack" | "top" | "lookup" | "lookupValue" | "lookupType" | "lookupNonlocal" | "stackClone" | "traverse" | "index" | "constants" | "removeNodeComments" | "inType" | "nextExposed" | "lookupRules">;
194
- export type ProgramStateAnalysis = Finalized<ProgramStateLive, "allClasses" | "nestedClasses" | "allModules" | "allFunctions" | "fnMap" | "allDeclarations" | "invokeInfo">;
195
+ export type ProgramStateAnalysis = Finalized<ProgramStateLive, "allClasses" | "nestedClasses" | "allModules" | "allTypedefs" | "allFunctions" | "fnMap" | "allDeclarations" | "invokeInfo">;
195
196
  export type ProgramStateOptimizer = Finalized<ProgramStateAnalysis, "localsStack" | "exposed" | "calledFunctions" | "usedByName">;
196
197
  export type ExcludeAnnotationsMap = {
197
198
  [key: string]: boolean;
@@ -144,11 +144,8 @@ export interface ObjectType extends AbstractValue {
144
144
  export interface EnumType extends AbstractValue {
145
145
  type: TypeTag.Enum;
146
146
  value?: {
147
- enum: EnumStateNode;
147
+ enum: EnumStateNode | EnumStateNode[];
148
148
  value?: ExactOrUnion | undefined;
149
- } | {
150
- enum?: undefined;
151
- value: ExactOrUnion;
152
149
  } | undefined;
153
150
  }
154
151
  export interface SymbolType extends AbstractValue {
@@ -222,4 +219,5 @@ export declare function tupleReduce(v: Array<ExactOrUnion | ExactOrUnion[]>): Un
222
219
  export declare function reducedArrayType(t: Set<ExactOrUnion[] | ExactOrUnion> | ExactOrUnion[] | ExactOrUnion): ExactOrUnion;
223
220
  export declare function checkArrayCovariance(arg: NonNullable<ArrayType["value"]>, param: NonNullable<ArrayType["value"]>): boolean;
224
221
  export declare function safeReferenceArg(arg: mctree.Expression): boolean;
222
+ export declare function typeFromEnumValue(arg: EnumType["value"] | null): UnionType | NumberType | LongType | FloatType | DoubleType | CharType | StringType | ArrayType | DictionaryType | MethodType | ModuleType | FunctionType | ClassType | ObjectType | EnumType | SymbolType | TypedefType;
225
223
  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_TLXMWGYI = require("./chunk-TLXMWGYI.cjs");
24
+ var import_chunk_UNU55JJ3 = require("./chunk-UNU55JJ3.cjs");
25
25
  var import_chunk_X7QCZR3F = require("./chunk-X7QCZR3F.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_TLXMWGYI.init_worker_task)();
31
+ (0, import_chunk_UNU55JJ3.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_TLXMWGYI.performTask)(task));
34
+ return import_node_worker_threads.parentPort.postMessage(await (0, import_chunk_UNU55JJ3.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.82",
4
+ "version": "1.1.83",
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",