@markw65/monkeyc-optimizer 1.1.96 → 1.1.97

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.97
6
+
7
+ - Fix [$ has :UNDEFINED error (#79)](https://github.com/markw65/monkeyc-optimizer/issues/79#top)
8
+ - Fix ["Generate Optimized Project" issue due to inlining code into another class (#76)](https://github.com/markw65/monkeyc-optimizer/issues/76#top)
9
+ - Fix ["Generate Optimized Project" produces code with syntax error (#77)](https://github.com/markw65/monkeyc-optimizer/issues/77#top)
10
+
5
11
  ### 1.1.96
6
12
 
7
13
  - Update to [@markw65/prettier-plugin-monkeyc@1.0.66](https://github.com/markw65/prettier-plugin-monkeyc/blob/main/CHANGELOG.md#1066)
package/build/api.cjs CHANGED
@@ -18,52 +18,52 @@ 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_4C4RQPFP.checkCompilerVersion,
22
- clearDiagnostics: () => import_chunk_4C4RQPFP.clearDiagnostics,
23
- collectNamespaces: () => import_chunk_4C4RQPFP.collectNamespaces,
24
- createDocumentationMap: () => import_chunk_4C4RQPFP.createDocumentationMap,
25
- declKey: () => import_chunk_4C4RQPFP.declKey,
26
- diagnostic: () => import_chunk_4C4RQPFP.diagnostic,
27
- diagnosticHelper: () => import_chunk_4C4RQPFP.diagnosticHelper,
28
- findNamesInScope: () => import_chunk_4C4RQPFP.findNamesInScope,
29
- findUsingForNode: () => import_chunk_4C4RQPFP.findUsingForNode,
30
- formatAst: () => import_chunk_4C4RQPFP.formatAst,
31
- formatAstLongLines: () => import_chunk_4C4RQPFP.formatAstLongLines,
32
- formatScopedName: () => import_chunk_4C4RQPFP.formatScopedName,
33
- getApiFunctionInfo: () => import_chunk_4C4RQPFP.getApiFunctionInfo,
34
- getApiMapping: () => import_chunk_4C4RQPFP.getApiMapping,
35
- getSuperClasses: () => import_chunk_4C4RQPFP.getSuperClasses,
36
- handleImportUsing: () => import_chunk_4C4RQPFP.handleImportUsing,
21
+ checkCompilerVersion: () => import_chunk_WP3SDGBT.checkCompilerVersion,
22
+ clearDiagnostics: () => import_chunk_WP3SDGBT.clearDiagnostics,
23
+ collectNamespaces: () => import_chunk_WP3SDGBT.collectNamespaces,
24
+ createDocumentationMap: () => import_chunk_WP3SDGBT.createDocumentationMap,
25
+ declKey: () => import_chunk_WP3SDGBT.declKey,
26
+ diagnostic: () => import_chunk_WP3SDGBT.diagnostic,
27
+ diagnosticHelper: () => import_chunk_WP3SDGBT.diagnosticHelper,
28
+ findNamesInScope: () => import_chunk_WP3SDGBT.findNamesInScope,
29
+ findUsingForNode: () => import_chunk_WP3SDGBT.findUsingForNode,
30
+ formatAst: () => import_chunk_WP3SDGBT.formatAst,
31
+ formatAstLongLines: () => import_chunk_WP3SDGBT.formatAstLongLines,
32
+ formatScopedName: () => import_chunk_WP3SDGBT.formatScopedName,
33
+ getApiFunctionInfo: () => import_chunk_WP3SDGBT.getApiFunctionInfo,
34
+ getApiMapping: () => import_chunk_WP3SDGBT.getApiMapping,
35
+ getSuperClasses: () => import_chunk_WP3SDGBT.getSuperClasses,
36
+ handleImportUsing: () => import_chunk_WP3SDGBT.handleImportUsing,
37
37
  hasProperty: () => import_chunk_UBAYZSM3.hasProperty,
38
- isClassVariable: () => import_chunk_4C4RQPFP.isClassVariable,
39
- isLocal: () => import_chunk_4C4RQPFP.isLocal,
40
- isLookupCandidate: () => import_chunk_4C4RQPFP.isLookupCandidate,
41
- isStateNode: () => import_chunk_4C4RQPFP.isStateNode,
42
- lookupByFullName: () => import_chunk_4C4RQPFP.lookupByFullName,
43
- lookupNext: () => import_chunk_4C4RQPFP.lookupNext,
44
- lookupResultContains: () => import_chunk_4C4RQPFP.lookupResultContains,
45
- lookupWithType: () => import_chunk_4C4RQPFP.lookupWithType,
46
- makeToyboxLink: () => import_chunk_4C4RQPFP.makeToyboxLink,
47
- mapVarDeclsByType: () => import_chunk_4C4RQPFP.mapVarDeclsByType,
48
- markInvokeClassMethod: () => import_chunk_4C4RQPFP.markInvokeClassMethod,
49
- parseSdkVersion: () => import_chunk_4C4RQPFP.parseSdkVersion,
50
- popRootNode: () => import_chunk_4C4RQPFP.popRootNode,
51
- pushRootNode: () => import_chunk_4C4RQPFP.pushRootNode,
52
- resolveDiagnostics: () => import_chunk_4C4RQPFP.resolveDiagnostics,
53
- resolveDiagnosticsMap: () => import_chunk_4C4RQPFP.resolveDiagnosticsMap,
54
- sameLookupResult: () => import_chunk_4C4RQPFP.sameLookupResult,
38
+ isClassVariable: () => import_chunk_WP3SDGBT.isClassVariable,
39
+ isLocal: () => import_chunk_WP3SDGBT.isLocal,
40
+ isLookupCandidate: () => import_chunk_WP3SDGBT.isLookupCandidate,
41
+ isStateNode: () => import_chunk_WP3SDGBT.isStateNode,
42
+ lookupByFullName: () => import_chunk_WP3SDGBT.lookupByFullName,
43
+ lookupNext: () => import_chunk_WP3SDGBT.lookupNext,
44
+ lookupResultContains: () => import_chunk_WP3SDGBT.lookupResultContains,
45
+ lookupWithType: () => import_chunk_WP3SDGBT.lookupWithType,
46
+ makeToyboxLink: () => import_chunk_WP3SDGBT.makeToyboxLink,
47
+ mapVarDeclsByType: () => import_chunk_WP3SDGBT.mapVarDeclsByType,
48
+ markInvokeClassMethod: () => import_chunk_WP3SDGBT.markInvokeClassMethod,
49
+ parseSdkVersion: () => import_chunk_WP3SDGBT.parseSdkVersion,
50
+ popRootNode: () => import_chunk_WP3SDGBT.popRootNode,
51
+ pushRootNode: () => import_chunk_WP3SDGBT.pushRootNode,
52
+ resolveDiagnostics: () => import_chunk_WP3SDGBT.resolveDiagnostics,
53
+ resolveDiagnosticsMap: () => import_chunk_WP3SDGBT.resolveDiagnosticsMap,
54
+ sameLookupResult: () => import_chunk_WP3SDGBT.sameLookupResult,
55
55
  traverseAst: () => import_chunk_UBAYZSM3.traverseAst,
56
- variableDeclarationName: () => import_chunk_4C4RQPFP.variableDeclarationName,
57
- visitReferences: () => import_chunk_4C4RQPFP.visitReferences,
58
- visit_resources: () => import_chunk_4C4RQPFP.visit_resources,
59
- visitorNode: () => import_chunk_4C4RQPFP.visitorNode
56
+ variableDeclarationName: () => import_chunk_WP3SDGBT.variableDeclarationName,
57
+ visitReferences: () => import_chunk_WP3SDGBT.visitReferences,
58
+ visit_resources: () => import_chunk_WP3SDGBT.visit_resources,
59
+ visitorNode: () => import_chunk_WP3SDGBT.visitorNode
60
60
  });
61
61
  module.exports = __toCommonJS(api_exports);
62
- var import_chunk_4C4RQPFP = require("./chunk-4C4RQPFP.cjs");
62
+ var import_chunk_WP3SDGBT = require("./chunk-WP3SDGBT.cjs");
63
63
  var import_chunk_IJS7AYMN = require("./chunk-IJS7AYMN.cjs");
64
64
  var import_chunk_UBAYZSM3 = require("./chunk-UBAYZSM3.cjs");
65
65
  var import_chunk_VS2QQHAK = require("./chunk-VS2QQHAK.cjs");
66
- (0, import_chunk_4C4RQPFP.init_api)();
66
+ (0, import_chunk_WP3SDGBT.init_api)();
67
67
  // Annotate the CommonJS export names for ESM import in node:
68
68
  0 && (module.exports = {
69
69
  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_4C4RQPFP_exports = {};
30
- __export(chunk_4C4RQPFP_exports, {
29
+ var chunk_WP3SDGBT_exports = {};
30
+ __export(chunk_WP3SDGBT_exports, {
31
31
  EnumTagsConst: () => EnumTagsConst,
32
32
  LastTypeTag: () => LastTypeTag,
33
33
  ObjectLikeTagsConst: () => ObjectLikeTagsConst,
@@ -140,7 +140,7 @@ __export(chunk_4C4RQPFP_exports, {
140
140
  visitorNode: () => visitorNode,
141
141
  xml_util_exports: () => xml_util_exports
142
142
  });
143
- module.exports = __toCommonJS(chunk_4C4RQPFP_exports);
143
+ module.exports = __toCommonJS(chunk_WP3SDGBT_exports);
144
144
  var import_chunk_IJS7AYMN = require("./chunk-IJS7AYMN.cjs");
145
145
  var import_chunk_UBAYZSM3 = require("./chunk-UBAYZSM3.cjs");
146
146
  var import_chunk_VS2QQHAK = require("./chunk-VS2QQHAK.cjs");
@@ -4351,11 +4351,97 @@ function processInlineBody(state, func, call, root, params) {
4351
4351
  }
4352
4352
  const replacement = fixNodeScope(state, node, lookupStack);
4353
4353
  if (!replacement) {
4354
- failed = true;
4354
+ if (!failed) {
4355
+ inlineDiagnostic(state, func, call, null);
4356
+ failed = true;
4357
+ }
4355
4358
  inlineDiagnostic(state, func, call, `Failed to resolve '${node.name}'`);
4356
4359
  }
4357
4360
  return replacement;
4358
4361
  };
4362
+ const fixupScopedType = (node) => {
4363
+ if (node.type === "Identifier") {
4364
+ const save = state.inType;
4365
+ state.inType = 1;
4366
+ const replacement = fixNodeScope(state, node, lookupStack);
4367
+ state.inType = save;
4368
+ if (!replacement) {
4369
+ if (!failed) {
4370
+ inlineDiagnostic(state, func, call, null);
4371
+ failed = true;
4372
+ }
4373
+ inlineDiagnostic(
4374
+ state,
4375
+ func,
4376
+ call,
4377
+ `Failed to resolve '${node.name}'`
4378
+ );
4379
+ }
4380
+ return replacement;
4381
+ }
4382
+ const object = fixupScopedType(node.object);
4383
+ return {
4384
+ ...node,
4385
+ object
4386
+ };
4387
+ };
4388
+ const fixupType = (node) => {
4389
+ if (typeof node === "string") {
4390
+ return node;
4391
+ }
4392
+ const { type } = node;
4393
+ switch (type) {
4394
+ case "TypeSpecList":
4395
+ return {
4396
+ ...node,
4397
+ ts: node.ts.map((spec) => fixupType(spec))
4398
+ };
4399
+ case "ArrayExpression":
4400
+ return {
4401
+ ...node,
4402
+ elements: node.elements.map(
4403
+ (e) => fixupType(e)
4404
+ )
4405
+ };
4406
+ case "ObjectExpression":
4407
+ return {
4408
+ ...node,
4409
+ properties: node.properties.map((property) => {
4410
+ const prop = property;
4411
+ return { ...prop, right: fixupType(prop.right) };
4412
+ })
4413
+ };
4414
+ case "TypeSpecPart": {
4415
+ const name = typeof node.name === "string" ? node.name : fixupScopedType(node.name);
4416
+ if (node.body) {
4417
+ return { ...node, name };
4418
+ }
4419
+ if (node.callspec) {
4420
+ return {
4421
+ ...node,
4422
+ callspec: {
4423
+ ...node.callspec,
4424
+ params: node.callspec.params.map(
4425
+ (p) => p.type === "BinaryExpression" ? { ...p, right: fixupType(p.right) } : p
4426
+ ),
4427
+ returnType: {
4428
+ ...node.callspec.returnType,
4429
+ argument: fixupType(node.callspec.returnType.argument)
4430
+ }
4431
+ }
4432
+ };
4433
+ }
4434
+ return node.generics ? {
4435
+ ...node,
4436
+ name,
4437
+ generics: node.generics.map((ts) => fixupType(ts))
4438
+ } : { ...node, name };
4439
+ break;
4440
+ }
4441
+ default:
4442
+ unhandledType(type);
4443
+ }
4444
+ };
4359
4445
  state.post = function(node) {
4360
4446
  if (failed) return post.call(this, node);
4361
4447
  let replacement = null;
@@ -4379,6 +4465,11 @@ function processInlineBody(state, func, call, root, params) {
4379
4465
  case "Identifier":
4380
4466
  replacement = fixId(node);
4381
4467
  break;
4468
+ case "BinaryExpression":
4469
+ if (node.operator === "as") {
4470
+ node.right = fixupType(node.right);
4471
+ }
4472
+ break;
4382
4473
  }
4383
4474
  const ret2 = post.call(this, replacement || node);
4384
4475
  return ret2 === false || ret2 ? ret2 : replacement;
@@ -4749,7 +4840,7 @@ function applyTypeIfNeeded(node) {
4749
4840
  return node;
4750
4841
  }
4751
4842
  function fixNodeScope(state, lookupNode, nodeStack) {
4752
- if (lookupNode.type === "Identifier") {
4843
+ if (lookupNode.type === "Identifier" && !state.inType) {
4753
4844
  const locals = state.localsStack[state.localsStack.length - 1];
4754
4845
  const { map: map2 } = locals;
4755
4846
  if (!map2) throw new Error("No local variable map!");
@@ -4861,6 +4952,7 @@ var init_inliner = (0, import_chunk_VS2QQHAK.__esm)({
4861
4952
  init_function_info();
4862
4953
  init_optimizer_types();
4863
4954
  init_variable_renamer();
4955
+ init_data_flow();
4864
4956
  }
4865
4957
  });
4866
4958
  function pragmaChecker(state, ast, diagnostics) {
@@ -12934,9 +13026,10 @@ function propagateTypes(state, root, graph, optimizeEquivalencies, copyPropStore
12934
13026
  }
12935
13027
  if (copyPropStores) {
12936
13028
  copyPropStores.forEach(({ ref, ant }, node) => {
13029
+ const result = nodeCopyProp.get(node) !== ref ? "Failed" : "Success";
12937
13030
  (0, import_chunk_IJS7AYMN.log)(
12938
13031
  formatAstLongLines(node).then(
12939
- (nodeStr) => `copy-prop-store: ${nodeStr}${ant ? "!" : ""} => ${nodeCopyProp.get(node) !== ref ? "Failed" : "Success"}`
13032
+ (nodeStr) => `copy-prop-store: ${nodeStr}${ant ? "!" : ""} => ${result}`
12940
13033
  )
12941
13034
  );
12942
13035
  });
@@ -14271,7 +14364,7 @@ var init_pre = (0, import_chunk_VS2QQHAK.__esm)({
14271
14364
  LocalRefCost = 2;
14272
14365
  }
14273
14366
  });
14274
- function minimizeModules(ast, state) {
14367
+ async function minimizeModules(ast, state) {
14275
14368
  const { pre, post } = state;
14276
14369
  try {
14277
14370
  const replacementMap = /* @__PURE__ */ new Map();
@@ -14350,7 +14443,7 @@ function minimizeModules(ast, state) {
14350
14443
  return null;
14351
14444
  };
14352
14445
  delete state.post;
14353
- collectNamespaces(ast, state);
14446
+ await collectNamespaces(ast, state);
14354
14447
  const mappedNames = /* @__PURE__ */ new Map();
14355
14448
  replacementMap.forEach((value2, key) => {
14356
14449
  let name;
@@ -14623,11 +14716,15 @@ function beforeEvaluate(istate, node) {
14623
14716
  case "BinaryExpression":
14624
14717
  if (node.operator === "has" && node.right.type === "UnaryExpression" && node.right.operator === ":") {
14625
14718
  const [left, right] = istate.stack.slice(-2);
14626
- if (left.embeddedEffects || right.embeddedEffects || !hasValue(left.value) || !hasValue(right.value) || !(left.value.type & (4096 | 16384))) {
14719
+ if (left.embeddedEffects || right.embeddedEffects || !hasValue(right.value) || !(left.value.type & (4096 | 16384))) {
14720
+ break;
14721
+ }
14722
+ const leftValues = hasValue(left.value) ? left.value.value : left.value.type === 4096 && node.left.type === "Identifier" && node.left.name === "$" ? istate.state.stack[0].sn : null;
14723
+ if (!leftValues) {
14627
14724
  break;
14628
14725
  }
14629
14726
  const id = node.right.argument;
14630
- if ((0, import_chunk_IJS7AYMN.every)(left.value.value, (m) => {
14727
+ if ((0, import_chunk_IJS7AYMN.every)(leftValues, (m) => {
14631
14728
  if ((0, import_chunk_UBAYZSM3.hasProperty)(m.decls, id.name)) return false;
14632
14729
  return istate.state.lookup({
14633
14730
  type: "MemberExpression",
@@ -14779,6 +14876,9 @@ function afterEvaluate(istate, node) {
14779
14876
  if (!top.embeddedEffects && hasValue(top.value)) {
14780
14877
  const rep = mcExprFromType(top.value);
14781
14878
  if (rep) {
14879
+ if (rep.type !== "BinaryExpression" || node.type !== "BinaryExpression" || node.operator !== "as" || node.left.type !== "Literal") {
14880
+ istate.rerun = true;
14881
+ }
14782
14882
  top.node = rep;
14783
14883
  return (0, import_chunk_UBAYZSM3.withLoc)(rep, node, node);
14784
14884
  }
@@ -15453,16 +15553,16 @@ async function analyze(fnMap, resourcesMap, manifestXML, config, allowParseError
15453
15553
  markApi = false;
15454
15554
  const state = preState;
15455
15555
  await getFileASTs(fnMap);
15456
- Object.values(fnMap).forEach((value2) => {
15556
+ for (const value2 of Object.values(fnMap)) {
15457
15557
  const { ast, parserError } = value2;
15458
15558
  if (!ast) {
15459
- if (allowParseErrors) return;
15559
+ if (allowParseErrors) continue;
15460
15560
  throw parserError || new Error(`Failed to parse ${value2.name}`);
15461
15561
  }
15462
15562
  hasTests = false;
15463
- collectNamespaces(ast, state);
15563
+ await collectNamespaces(ast, state);
15464
15564
  value2.hasTests = hasTests;
15465
- });
15565
+ }
15466
15566
  delete state.shouldExclude;
15467
15567
  delete state.pre;
15468
15568
  collectDeclarationsByName(state);
@@ -15471,60 +15571,60 @@ async function analyze(fnMap, resourcesMap, manifestXML, config, allowParseError
15471
15571
  state.nextExposed = {};
15472
15572
  return state;
15473
15573
  }
15474
- function reportMissingSymbols(state, config) {
15574
+ async function reportMissingSymbols(state, config) {
15475
15575
  const diagnosticType = config?.checkInvalidSymbols !== "OFF" ? config?.checkInvalidSymbols || "WARNING" : null;
15476
15576
  const compiler2DiagnosticType = config?.checkCompilerLookupRules !== "OFF" ? config?.checkCompilerLookupRules || "WARNING" : null;
15477
15577
  if (diagnosticType && !config?.compilerOptions?.includes("--Eno-invalid-symbol")) {
15478
15578
  const checkTypes = config?.checkTypes?.toLowerCase() !== "off";
15479
- const report = (ast) => {
15480
- visitReferences(state, ast, null, false, (node, results, error) => {
15481
- if (node.type === "BinaryExpression" && node.operator === "has") {
15482
- return void 0;
15483
- }
15484
- if (!error) {
15485
- if (state.sdkVersion === 4001006 && compiler2DiagnosticType && node.type === "MemberExpression" && (node.object.type === "Identifier" || node.object.type === "MemberExpression") && results.some((result) => {
15486
- const parent = result.parent;
15487
- if (!parent || parent.type !== "ClassDeclaration") {
15488
- return false;
15489
- }
15490
- return result.results.some((sn) => {
15491
- switch (sn.type) {
15492
- case "VariableDeclarator":
15493
- case "FunctionDeclaration":
15494
- return sn.attributes & (4 | 2);
15495
- }
15496
- return false;
15497
- });
15498
- })) {
15499
- diagnostic(
15500
- state,
15501
- node,
15502
- formatAstLongLines(node).then(
15503
- (nodeStr) => `The expression ${nodeStr} will fail at runtime using sdk-4.1.6`
15504
- ),
15505
- compiler2DiagnosticType
15506
- );
15579
+ const report = (ast) => visitReferences(state, ast, null, false, (node, results, error) => {
15580
+ if (node.type === "BinaryExpression" && node.operator === "has") {
15581
+ return void 0;
15582
+ }
15583
+ if (!error) {
15584
+ if (state.sdkVersion === 4001006 && compiler2DiagnosticType && node.type === "MemberExpression" && (node.object.type === "Identifier" || node.object.type === "MemberExpression") && results.some((result) => {
15585
+ const parent = result.parent;
15586
+ if (!parent || parent.type !== "ClassDeclaration") {
15587
+ return false;
15507
15588
  }
15508
- return void 0;
15589
+ return result.results.some((sn) => {
15590
+ switch (sn.type) {
15591
+ case "VariableDeclarator":
15592
+ case "FunctionDeclaration":
15593
+ return sn.attributes & (4 | 2);
15594
+ }
15595
+ return false;
15596
+ });
15597
+ })) {
15598
+ diagnostic(
15599
+ state,
15600
+ node,
15601
+ formatAstLongLines(node).then(
15602
+ (nodeStr) => `The expression ${nodeStr} will fail at runtime using sdk-4.1.6`
15603
+ ),
15604
+ compiler2DiagnosticType
15605
+ );
15509
15606
  }
15510
- if (state.inType) {
15511
- if (!checkTypes || node.type === "Identifier" && node.name.match(/^Void|Null$/)) {
15512
- return void 0;
15513
- }
15607
+ return void 0;
15608
+ }
15609
+ if (state.inType) {
15610
+ if (!checkTypes || node.type === "Identifier" && node.name.match(/^Void|Null$/)) {
15611
+ return void 0;
15514
15612
  }
15515
- diagnostic(
15516
- state,
15517
- node,
15518
- formatAstLongLines(node).then(
15519
- (nodeStr) => `Undefined symbol ${nodeStr}`
15520
- ),
15521
- diagnosticType
15522
- );
15523
- return false;
15524
- });
15525
- };
15526
- Object.values(state.fnMap).forEach((v) => v.ast && report(v.ast));
15527
- state.rezAst && report(state.rezAst);
15613
+ }
15614
+ diagnostic(
15615
+ state,
15616
+ node,
15617
+ formatAstLongLines(node).then(
15618
+ (nodeStr) => `Undefined symbol ${nodeStr}`
15619
+ ),
15620
+ diagnosticType
15621
+ );
15622
+ return false;
15623
+ });
15624
+ for (const v of Object.values(state.fnMap)) {
15625
+ v.ast && await report(v.ast);
15626
+ }
15627
+ state.rezAst && await report(state.rezAst);
15528
15628
  }
15529
15629
  }
15530
15630
  function optimizeNode(istate, node) {
@@ -15919,6 +16019,10 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
15919
16019
  this.currentFunction.info = this.currentFunction.next_info || false;
15920
16020
  delete this.currentFunction.next_info;
15921
16021
  delete this.currentFunction;
16022
+ if (istate.rerun) {
16023
+ again = true;
16024
+ delete istate.rerun;
16025
+ }
15922
16026
  if (istate.stack.length) {
15923
16027
  throw new Error("Stack was not empty");
15924
16028
  }
@@ -16086,50 +16190,47 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
16086
16190
  }
16087
16191
  return null;
16088
16192
  };
16089
- Object.values(fnMap).forEach((f) => {
16090
- collectNamespaces(f.ast, state);
16091
- });
16193
+ for (const f of Object.values(fnMap)) {
16194
+ await collectNamespaces(f.ast, state);
16195
+ }
16092
16196
  let Changes;
16093
16197
  ((Changes2) => {
16094
16198
  Changes2[Changes2["None"] = 0] = "None";
16095
16199
  Changes2[Changes2["Some"] = 1] = "Some";
16096
16200
  Changes2[Changes2["Force"] = 2] = "Force";
16097
16201
  })(Changes || (Changes = {}));
16098
- const cleanupAll = (state2) => {
16202
+ const cleanupAll = async (state2) => {
16099
16203
  const usedDecls = findRezRefs(state2);
16100
16204
  const pre = state2.pre;
16101
16205
  const post = state2.post;
16102
16206
  try {
16103
16207
  delete state2.pre;
16104
- return Object.values(fnMap).reduce(
16105
- (changes, f) => {
16106
- state2.post = function(node) {
16107
- if (usedDecls.has(node)) {
16108
- return null;
16109
- }
16110
- const ret = cleanup(this, node, f.ast, usedDecls);
16111
- if (ret === false) {
16208
+ let changes = 0;
16209
+ for (const f of Object.values(fnMap)) {
16210
+ state2.post = function(node) {
16211
+ if (usedDecls.has(node)) {
16212
+ return null;
16213
+ }
16214
+ const ret = cleanup(this, node, f.ast, usedDecls);
16215
+ if (ret === false) {
16216
+ changes |= 1;
16217
+ this.removeNodeComments(node, f.ast);
16218
+ clearDiagnostics(this, node);
16219
+ } else if (ret) {
16220
+ if (node.type === "EnumDeclaration" && ret.type === "TypedefDeclaration") {
16221
+ changes |= 2;
16222
+ } else {
16112
16223
  changes |= 1;
16113
- this.removeNodeComments(node, f.ast);
16114
- clearDiagnostics(this, node);
16115
- } else if (ret) {
16116
- if (node.type === "EnumDeclaration" && ret.type === "TypedefDeclaration") {
16117
- changes |= 2;
16118
- } else {
16119
- changes |= 1;
16120
- }
16121
16224
  }
16122
- return ret;
16123
- };
16124
- collectNamespaces(f.ast, state2);
16125
- if (changes & 2) {
16126
- state2.allCached?.forEach((t) => delete t.resolvedType);
16127
16225
  }
16128
- return changes;
16129
- },
16130
- 0
16131
- /* None */
16132
- );
16226
+ return ret;
16227
+ };
16228
+ await collectNamespaces(f.ast, state2);
16229
+ if (changes & 2) {
16230
+ state2.allCached?.forEach((t) => delete t.resolvedType);
16231
+ }
16232
+ }
16233
+ return changes;
16133
16234
  } finally {
16134
16235
  state2.pre = pre;
16135
16236
  state2.post = post;
@@ -16140,12 +16241,12 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
16140
16241
  state.calledFunctions = {};
16141
16242
  state.exposed = state.nextExposed;
16142
16243
  state.nextExposed = {};
16143
- Object.values(fnMap).forEach((f) => {
16144
- collectNamespaces(f.ast, state);
16145
- });
16244
+ for (const f of Object.values(fnMap)) {
16245
+ await collectNamespaces(f.ast, state);
16246
+ }
16146
16247
  state.exposed = state.nextExposed;
16147
16248
  state.nextExposed = {};
16148
- const changes = cleanupAll(state);
16249
+ const changes = await cleanupAll(state);
16149
16250
  if (changes & 2 || changes & 1 && state.config?.iterateOptimizer) {
16150
16251
  continue;
16151
16252
  }
@@ -16154,9 +16255,9 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
16154
16255
  delete state.pre;
16155
16256
  delete state.post;
16156
16257
  if (state.config?.minimizeModules ?? true) {
16157
- Object.values(fnMap).forEach((f) => {
16158
- minimizeModules(f.ast, state);
16159
- });
16258
+ for (const f of Object.values(fnMap)) {
16259
+ await minimizeModules(f.ast, state);
16260
+ }
16160
16261
  }
16161
16262
  await Object.values(state.allFunctions).reduce(
16162
16263
  (promise, fns) => fns.reduce(
@@ -16165,9 +16266,9 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
16165
16266
  ),
16166
16267
  Promise.resolve()
16167
16268
  );
16168
- cleanupAll(state);
16269
+ await cleanupAll(state);
16169
16270
  config.checkCompilerLookupRules = checkLookupRules;
16170
- reportMissingSymbols(state, config);
16271
+ await reportMissingSymbols(state, config);
16171
16272
  Object.values(fnMap).forEach(
16172
16273
  ({ ast }) => ast && reportFailedInlining(state, ast)
16173
16274
  );
@@ -16325,10 +16426,16 @@ function cleanup(state, node, ast, usedNodes) {
16325
16426
  }
16326
16427
  return typedefDecl;
16327
16428
  }
16328
- case "VariableDeclarator": {
16329
- const name = variableDeclarationName(node.id);
16330
- return !(0, import_chunk_UBAYZSM3.hasProperty)(state.index, name) || (0, import_chunk_UBAYZSM3.hasProperty)(state.exposed, name) || (0, import_chunk_UBAYZSM3.hasProperty)(state.usedByName, name) ? null : false;
16331
- }
16429
+ case "VariableDeclarator":
16430
+ if (state.stack.at(-1)?.sn.type !== "BlockStatement") {
16431
+ const name = variableDeclarationName(node.id);
16432
+ return !(0, import_chunk_UBAYZSM3.hasProperty)(state.index, name) || (0, import_chunk_UBAYZSM3.hasProperty)(state.exposed, name) || (0, import_chunk_UBAYZSM3.hasProperty)(state.usedByName, name) || !state.index[name].find(
16433
+ (sn) => sn.decls?.[name]?.find(
16434
+ (sn2) => sn2.type === "VariableDeclarator" && sn2.node === node
16435
+ )
16436
+ ) ? null : false;
16437
+ }
16438
+ break;
16332
16439
  case "VariableDeclaration": {
16333
16440
  if (!node.declarations.length) {
16334
16441
  return false;
@@ -17102,7 +17209,7 @@ function visitorNode(node) {
17102
17209
  }
17103
17210
  return node;
17104
17211
  }
17105
- function visitReferences(state, ast, name, defn, callback, includeDefs = false, filter = null, typeMap = null, findSingleDefinition = false) {
17212
+ async function visitReferences(state, ast, name, defn, callback, includeDefs = false, filter = null, typeMap = null, findSingleDefinition = false) {
17106
17213
  const lookup2 = (node, nonLocal = false) => lookupWithType(state, node, typeMap, nonLocal);
17107
17214
  const checkResults = ([name2, results], node) => {
17108
17215
  if (name2 && results) {
@@ -17232,6 +17339,11 @@ function visitReferences(state, ast, name, defn, callback, includeDefs = false,
17232
17339
  }
17233
17340
  break;
17234
17341
  }
17342
+ case "TypeSpecPart":
17343
+ if (node.callspec) {
17344
+ return ["callspec"];
17345
+ }
17346
+ break;
17235
17347
  case "MethodDefinition": {
17236
17348
  if (!this.inType) {
17237
17349
  throw new Error("Method definition outside of type!");
@@ -17300,7 +17412,7 @@ function visitReferences(state, ast, name, defn, callback, includeDefs = false,
17300
17412
  return null;
17301
17413
  };
17302
17414
  delete state.post;
17303
- collectNamespaces(ast, state);
17415
+ return collectNamespaces(ast, state);
17304
17416
  } finally {
17305
17417
  state.pre = pre;
17306
17418
  state.post = post;
@@ -17378,9 +17490,9 @@ async function getApiMapping(state, resourcesMap, manifestXML) {
17378
17490
  state.manifestXML = manifestXML;
17379
17491
  }
17380
17492
  }
17381
- const result = collectNamespaces(ast, state);
17493
+ const result = await collectNamespaces(ast, state);
17382
17494
  if (state && state.rezAst) {
17383
- collectNamespaces(state.rezAst, state);
17495
+ await collectNamespaces(state.rezAst, state);
17384
17496
  }
17385
17497
  negativeFixups.forEach((fixup) => {
17386
17498
  const vs = fixup.split(".").reduce((state2, part) => {
@@ -18190,7 +18302,7 @@ function stateFuncs() {
18190
18302
  }
18191
18303
  };
18192
18304
  }
18193
- function collectNamespaces(ast, stateIn) {
18305
+ async function collectNamespaces(ast, stateIn) {
18194
18306
  const state = stateIn || {};
18195
18307
  if (!state.nextExposed) state.nextExposed = {};
18196
18308
  if (!state.index) state.index = {};
@@ -18228,6 +18340,7 @@ function collectNamespaces(ast, stateIn) {
18228
18340
  }
18229
18341
  state.inType = 0;
18230
18342
  state.traverse(ast);
18343
+ await import_chunk_IJS7AYMN.logPromise;
18231
18344
  if (state.inType) {
18232
18345
  throw new Error(`inType was non-zero on exit: ${state.inType}`);
18233
18346
  }
@@ -26897,24 +27010,31 @@ function getConfig(options) {
26897
27010
  const defaults = buildConfigDescription.flatMap(
26898
27011
  (desc) => Object.entries(desc.properties)
26899
27012
  );
26900
- return defaults.reduce((promise, [key, info]) => {
26901
- if (key in config) return promise;
26902
- return promise.then(
26903
- (v) => v || getVSCodeSettings(`${appSupport}/Code/User/settings.json`).then(
26904
- (globals) => getCodeWorkspaceSettings(config.workspace).then(
26905
- (workspace) => getVSCodeSettings(
26906
- `${config.workspace ?? "."}/.vscode/settings.json`
26907
- ).then((locals) => ({ ...globals, ...workspace, ...locals }))
27013
+ return defaults.reduce(
27014
+ (promise, [key, info]) => {
27015
+ if (key in config) return promise;
27016
+ return promise.then(
27017
+ (v) => v || getVSCodeSettings(`${appSupport}/Code/User/settings.json`).then(
27018
+ (globals) => getCodeWorkspaceSettings(config.workspace).then(
27019
+ (workspace) => getVSCodeSettings(
27020
+ `${config.workspace ?? "."}/.vscode/settings.json`
27021
+ ).then((locals) => ({
27022
+ ...globals,
27023
+ ...workspace,
27024
+ ...locals
27025
+ }))
27026
+ )
26908
27027
  )
26909
- )
26910
- ).then((settings) => {
26911
- const value2 = settings[`prettierMonkeyC.${key}`] ?? settings[`monkeyC.${key}`] ?? info.default;
26912
- if (value2 !== void 0) {
26913
- config[key] = value2;
26914
- }
26915
- return settings;
26916
- });
26917
- }, Promise.resolve(options.ignore_settings_files ? {} : null)).then((settings) => {
27028
+ ).then((settings) => {
27029
+ const value2 = settings[`prettierMonkeyC.${key}`] ?? settings[`monkeyC.${key}`] ?? info.default;
27030
+ if (value2 !== void 0) {
27031
+ config[key] = value2;
27032
+ }
27033
+ return settings;
27034
+ });
27035
+ },
27036
+ Promise.resolve(options.ignore_settings_files ? {} : null)
27037
+ ).then((settings) => {
26918
27038
  if (settings && (!config.strictTypeCheck || config.strictTypeCheck === "Default") && (settings["monkeyC.typeCheckLevel"]?.toString().toLowerCase() === "strict" || settings["prettierMonkeyC.typeCheckLevel"]?.toString().toLowerCase() === "strict")) {
26919
27039
  config.strictTypeCheck = "On";
26920
27040
  }
@@ -27172,12 +27292,15 @@ async function generateOptimizedProject(options) {
27172
27292
  const nextAvailableDefault = () => {
27173
27293
  if (!availableDefaults) {
27174
27294
  availableDefaults = Object.keys(
27175
- Object.values(devices).reduce((m, d) => {
27176
- m[d.deviceFamily] = true;
27177
- const match = d.deviceFamily.match(/^(\w+)-\d+x\d+/);
27178
- if (match) m[match[1]] = true;
27179
- return m;
27180
- }, {})
27295
+ Object.values(devices).reduce(
27296
+ (m, d) => {
27297
+ m[d.deviceFamily] = true;
27298
+ const match = d.deviceFamily.match(/^(\w+)-\d+x\d+/);
27299
+ if (match) m[match[1]] = true;
27300
+ return m;
27301
+ },
27302
+ {}
27303
+ )
27181
27304
  ).sort();
27182
27305
  availableDefaults.unshift("base");
27183
27306
  }
@@ -27443,7 +27566,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
27443
27566
  const opt_time = await (0, import_chunk_IJS7AYMN.first_modified)(
27444
27567
  Object.values(fnMap).map((v) => v.output)
27445
27568
  );
27446
- if (source_time < opt_time && 1772064318337 < opt_time) {
27569
+ if (source_time < opt_time && 1773622846769 < opt_time) {
27447
27570
  return {
27448
27571
  hasTests,
27449
27572
  diagnostics: prevDiagnostics,
@@ -27481,7 +27604,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
27481
27604
  hasTests: hasTests2,
27482
27605
  diagnostics,
27483
27606
  sdkVersion,
27484
- optimizerVersion: "1.1.96",
27607
+ optimizerVersion: "1.1.97",
27485
27608
  ...Object.fromEntries(
27486
27609
  configOptionsToCheck.map((option) => [option, config[option]])
27487
27610
  )
@@ -27543,18 +27666,21 @@ async function getProjectAnalysisHelper(targets, analysis, manifestXML, options)
27543
27666
  )
27544
27667
  )
27545
27668
  ).then(
27546
- (results) => results.reduce((cur, result) => {
27547
- if (!cur) return result;
27548
- Object.entries(result.fnMap).forEach(([key, value2]) => {
27549
- if (cur.fnMap[key]) {
27550
- cur.fnMap[key + "::" + value2.barrel] = value2;
27551
- } else {
27552
- cur.fnMap[key] = value2;
27553
- }
27554
- });
27555
- cur.paths.push(...result.paths);
27556
- return cur;
27557
- }, null)
27669
+ (results) => results.reduce(
27670
+ (cur, result) => {
27671
+ if (!cur) return result;
27672
+ Object.entries(result.fnMap).forEach(([key, value2]) => {
27673
+ if (cur.fnMap[key]) {
27674
+ cur.fnMap[key + "::" + value2.barrel] = value2;
27675
+ } else {
27676
+ cur.fnMap[key] = value2;
27677
+ }
27678
+ });
27679
+ cur.paths.push(...result.paths);
27680
+ return cur;
27681
+ },
27682
+ null
27683
+ )
27558
27684
  ).then(
27559
27685
  (result) => result ?? Promise.reject(
27560
27686
  new Error(
@@ -27597,7 +27723,7 @@ async function getProjectAnalysisHelper(targets, analysis, manifestXML, options)
27597
27723
  async function getFnMapAnalysis(fnMap, resourcesMap, manifestXML, options) {
27598
27724
  const state = await analyze(fnMap, resourcesMap, manifestXML, options, true);
27599
27725
  if (Object.values(fnMap).every(({ ast }) => ast != null)) {
27600
- reportMissingSymbols(state, options);
27726
+ await reportMissingSymbols(state, options);
27601
27727
  }
27602
27728
  const typeMap = await analyze_module_types(state);
27603
27729
  const diagnostics = state.diagnostics && await resolveDiagnosticsMap(state.diagnostics);
@@ -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_4C4RQPFP.StateNodeAttributes,
22
- buildConfigDescription: () => import_chunk_4C4RQPFP.buildConfigDescription,
23
- buildOptimizedProject: () => import_chunk_4C4RQPFP.buildOptimizedProject,
21
+ StateNodeAttributes: () => import_chunk_WP3SDGBT.StateNodeAttributes,
22
+ buildConfigDescription: () => import_chunk_WP3SDGBT.buildConfigDescription,
23
+ buildOptimizedProject: () => import_chunk_WP3SDGBT.buildOptimizedProject,
24
24
  copyRecursiveAsNeeded: () => import_chunk_IJS7AYMN.copyRecursiveAsNeeded,
25
- defaultConfig: () => import_chunk_4C4RQPFP.defaultConfig,
26
- display: () => import_chunk_4C4RQPFP.display,
27
- generateOneConfig: () => import_chunk_4C4RQPFP.generateOneConfig,
28
- generateOptimizedProject: () => import_chunk_4C4RQPFP.generateOptimizedProject,
29
- getConfig: () => import_chunk_4C4RQPFP.getConfig,
30
- getFnMapAnalysis: () => import_chunk_4C4RQPFP.getFnMapAnalysis,
31
- getProjectAnalysis: () => import_chunk_4C4RQPFP.getProjectAnalysis,
32
- get_jungle: () => import_chunk_4C4RQPFP.get_jungle,
33
- isErrorWithLocation: () => import_chunk_4C4RQPFP.isErrorWithLocation,
34
- launchSimulator: () => import_chunk_4C4RQPFP.launchSimulator,
35
- manifestProducts: () => import_chunk_4C4RQPFP.manifestProducts,
36
- mctree: () => import_chunk_4C4RQPFP.mctree,
37
- simulateProgram: () => import_chunk_4C4RQPFP.simulateProgram
25
+ defaultConfig: () => import_chunk_WP3SDGBT.defaultConfig,
26
+ display: () => import_chunk_WP3SDGBT.display,
27
+ generateOneConfig: () => import_chunk_WP3SDGBT.generateOneConfig,
28
+ generateOptimizedProject: () => import_chunk_WP3SDGBT.generateOptimizedProject,
29
+ getConfig: () => import_chunk_WP3SDGBT.getConfig,
30
+ getFnMapAnalysis: () => import_chunk_WP3SDGBT.getFnMapAnalysis,
31
+ getProjectAnalysis: () => import_chunk_WP3SDGBT.getProjectAnalysis,
32
+ get_jungle: () => import_chunk_WP3SDGBT.get_jungle,
33
+ isErrorWithLocation: () => import_chunk_WP3SDGBT.isErrorWithLocation,
34
+ launchSimulator: () => import_chunk_WP3SDGBT.launchSimulator,
35
+ manifestProducts: () => import_chunk_WP3SDGBT.manifestProducts,
36
+ mctree: () => import_chunk_WP3SDGBT.mctree,
37
+ simulateProgram: () => import_chunk_WP3SDGBT.simulateProgram
38
38
  });
39
39
  module.exports = __toCommonJS(optimizer_exports);
40
- var import_chunk_4C4RQPFP = require("./chunk-4C4RQPFP.cjs");
40
+ var import_chunk_WP3SDGBT = require("./chunk-WP3SDGBT.cjs");
41
41
  var import_chunk_IJS7AYMN = require("./chunk-IJS7AYMN.cjs");
42
42
  var import_chunk_UBAYZSM3 = require("./chunk-UBAYZSM3.cjs");
43
43
  var import_chunk_VS2QQHAK = require("./chunk-VS2QQHAK.cjs");
44
- (0, import_chunk_4C4RQPFP.init_optimizer)();
44
+ (0, import_chunk_WP3SDGBT.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_4C4RQPFP.SectionKinds,
22
- appSupport: () => import_chunk_4C4RQPFP.appSupport,
23
- connectiq: () => import_chunk_4C4RQPFP.connectiq,
24
- getDeviceInfo: () => import_chunk_4C4RQPFP.getDeviceInfo,
25
- getFunctionDocumentation: () => import_chunk_4C4RQPFP.getFunctionDocumentation,
26
- getLanguages: () => import_chunk_4C4RQPFP.getLanguages,
27
- getSdkPath: () => import_chunk_4C4RQPFP.getSdkPath,
28
- isWin: () => import_chunk_4C4RQPFP.isWin,
29
- optimizeProgram: () => import_chunk_4C4RQPFP.optimizeProgram,
30
- readPrg: () => import_chunk_4C4RQPFP.readPrg,
31
- readPrgWithOffsets: () => import_chunk_4C4RQPFP.readPrgWithOffsets,
32
- xmlUtil: () => import_chunk_4C4RQPFP.xml_util_exports
21
+ SectionKinds: () => import_chunk_WP3SDGBT.SectionKinds,
22
+ appSupport: () => import_chunk_WP3SDGBT.appSupport,
23
+ connectiq: () => import_chunk_WP3SDGBT.connectiq,
24
+ getDeviceInfo: () => import_chunk_WP3SDGBT.getDeviceInfo,
25
+ getFunctionDocumentation: () => import_chunk_WP3SDGBT.getFunctionDocumentation,
26
+ getLanguages: () => import_chunk_WP3SDGBT.getLanguages,
27
+ getSdkPath: () => import_chunk_WP3SDGBT.getSdkPath,
28
+ isWin: () => import_chunk_WP3SDGBT.isWin,
29
+ optimizeProgram: () => import_chunk_WP3SDGBT.optimizeProgram,
30
+ readPrg: () => import_chunk_WP3SDGBT.readPrg,
31
+ readPrgWithOffsets: () => import_chunk_WP3SDGBT.readPrgWithOffsets,
32
+ xmlUtil: () => import_chunk_WP3SDGBT.xml_util_exports
33
33
  });
34
34
  module.exports = __toCommonJS(sdk_util_exports);
35
- var import_chunk_4C4RQPFP = require("./chunk-4C4RQPFP.cjs");
35
+ var import_chunk_WP3SDGBT = require("./chunk-WP3SDGBT.cjs");
36
36
  var import_chunk_IJS7AYMN = require("./chunk-IJS7AYMN.cjs");
37
37
  var import_chunk_UBAYZSM3 = require("./chunk-UBAYZSM3.cjs");
38
38
  var import_chunk_VS2QQHAK = require("./chunk-VS2QQHAK.cjs");
39
- (0, import_chunk_4C4RQPFP.init_sdk_util)();
39
+ (0, import_chunk_WP3SDGBT.init_sdk_util)();
40
40
  // Annotate the CommonJS export names for ESM import in node:
41
41
  0 && (module.exports = {
42
42
  SectionKinds,
@@ -25,13 +25,13 @@ export declare function isLookupCandidate(node: mctree.MemberExpression): false
25
25
  export declare function lookupNext(state: ProgramStateLive, results: LookupDefinition[], decls: DeclKind, property: mctree.Identifier): LookupDefinition[] | null;
26
26
  export declare function lookupWithType(state: ProgramStateAnalysis, node: mctree.Node, typeMap: TypeMap | undefined | null, nonLocal?: boolean, stack?: ProgramStateStack | null): LookupResult;
27
27
  export declare function handleImportUsing(state: ProgramStateLive, node: mctree.Using | mctree.ImportModule): void;
28
- export declare function collectNamespaces(ast: mctree.Program, stateIn?: ProgramState): ProgramStateNode;
28
+ export declare function collectNamespaces(ast: mctree.Program, stateIn?: ProgramState): Promise<ProgramStateNode>;
29
29
  export declare function formatAst(node: mctree.Node, monkeyCSource?: string | null, options?: Record<string, unknown> | null): Promise<string>;
30
30
  export declare function findNamesInScope(declStack: StateNode[][], pattern: string | RegExp): (readonly [StateNodeDecl, {
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 | TypedefStateNode | VariableStateNode | EnumStateNode | import("./optimizer-types").BlockStateNode)[];
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 | import("./optimizer-types").BlockStateNode | TypedefStateNode | VariableStateNode | 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: {
@@ -5,7 +5,7 @@ import { xmlUtil } from "./sdk-util";
5
5
  export declare function getFileSources(fnMap: FilesToOptimizeMap): Promise<void>;
6
6
  export declare function getFileASTs(fnMap: FilesToOptimizeMap): Promise<boolean>;
7
7
  export declare function analyze(fnMap: FilesToOptimizeMap, resourcesMap: Record<string, JungleResourceMap>, manifestXML: xmlUtil.Document | undefined, config: BuildConfig, allowParseErrors?: boolean): Promise<ProgramStateAnalysis>;
8
- export declare function reportMissingSymbols(state: ProgramStateAnalysis, config?: BuildConfig): void;
8
+ export declare function reportMissingSymbols(state: ProgramStateAnalysis, config?: BuildConfig): Promise<void>;
9
9
  export declare function getLiteralFromDecls(lookupDefns: LookupDefinition[]): mctree.Literal | mctree.AsExpression | null;
10
10
  export declare function optimizeMonkeyC(fnMap: FilesToOptimizeMap, resourcesMap: Record<string, JungleResourceMap>, manifestXML: xmlUtil.Document, config: BuildConfig): Promise<{
11
11
  diagnostics: Record<string, Diagnostic[]> | undefined;
@@ -179,7 +179,7 @@ export type ProgramState = {
179
179
  };
180
180
  }[];
181
181
  index?: {
182
- [key: string]: unknown[];
182
+ [key: string]: StateNode[];
183
183
  };
184
184
  constants?: {
185
185
  [key: string]: mctree.Literal;
@@ -27,6 +27,7 @@ export type InterpState = {
27
27
  checkTypes?: DiagnosticType;
28
28
  dependencies?: DependencyMap;
29
29
  frpushType?: ExactOrUnion;
30
+ rerun?: true;
30
31
  };
31
32
  export declare function popIstate(istate: InterpState, node: mctree.Node): InterpStackElem;
32
33
  export declare function tryPop(istate: InterpState, node: InterpStackElem["node"]): InterpStackElem;
@@ -1,3 +1,3 @@
1
1
  import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
2
  import { ProgramStateAnalysis } from "../optimizer-types";
3
- export declare function minimizeModules(ast: mctree.Program, state: ProgramStateAnalysis): void;
3
+ export declare function minimizeModules(ast: mctree.Program, state: ProgramStateAnalysis): Promise<void>;
@@ -2,4 +2,4 @@ import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
2
  import { LookupDefinition, ProgramStateAnalysis } from "./optimizer-types";
3
3
  import { TypeMap } from "./type-flow/interp";
4
4
  export declare function visitorNode(node: mctree.Node): mctree.Node;
5
- export declare function visitReferences(state: ProgramStateAnalysis, ast: mctree.Program, name: string | null, defn: LookupDefinition[] | null | false, callback: (node: mctree.Node, results: LookupDefinition[], error: boolean) => undefined | false, includeDefs?: boolean, filter?: ((node: mctree.Node) => boolean) | null, typeMap?: TypeMap | null, findSingleDefinition?: boolean): void;
5
+ export declare function visitReferences(state: ProgramStateAnalysis, ast: mctree.Program, name: string | null, defn: LookupDefinition[] | null | false, callback: (node: mctree.Node, results: LookupDefinition[], error: boolean) => undefined | false, includeDefs?: boolean, filter?: ((node: mctree.Node) => boolean) | null, typeMap?: TypeMap | null, findSingleDefinition?: boolean): Promise<import("./optimizer-types").ProgramStateNode>;
@@ -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_4C4RQPFP = require("./chunk-4C4RQPFP.cjs");
24
+ var import_chunk_WP3SDGBT = require("./chunk-WP3SDGBT.cjs");
25
25
  var import_chunk_IJS7AYMN = require("./chunk-IJS7AYMN.cjs");
26
26
  var import_chunk_UBAYZSM3 = require("./chunk-UBAYZSM3.cjs");
27
27
  var import_chunk_VS2QQHAK = require("./chunk-VS2QQHAK.cjs");
28
28
  var import_node_worker_threads = require("node:worker_threads");
29
29
  var require_worker_thread = (0, import_chunk_VS2QQHAK.__commonJS)({
30
30
  "src/worker-thread.ts"() {
31
- (0, import_chunk_4C4RQPFP.init_worker_task)();
31
+ (0, import_chunk_WP3SDGBT.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_4C4RQPFP.performTask)(task));
34
+ return import_node_worker_threads.parentPort.postMessage(await (0, import_chunk_WP3SDGBT.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.96",
4
+ "version": "1.1.97",
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",