@markw65/monkeyc-optimizer 1.1.57 → 1.1.58

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  All notable changes to the "monkeyc-optimizer" package will be documented in this file.
4
4
 
5
+ ### 1.1.58
6
+
7
+ - Update to [@markw65/prettier-plugin-monkeyc@1.0.57](https://github.com/markw65/prettier-plugin-monkeyc/blob/main/CHANGELOG.md#1057)
8
+ - Just updates exported types. No change in functionality
9
+ - Properly quote paths in the generated jungle
10
+ - Take account of all references from resource files
11
+ - Include Null in the types of uninitialized variables in their initialize method
12
+
5
13
  ### 1.1.57
6
14
 
7
15
  - Include ConditionalExpression and LogicalExpression in evaluateFunction
package/build/api.cjs CHANGED
@@ -18,47 +18,47 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var api_exports = {};
20
20
  __export(api_exports, {
21
- checkCompilerVersion: () => import_chunk_PUEG4GNZ.checkCompilerVersion,
22
- collectNamespaces: () => import_chunk_PUEG4GNZ.collectNamespaces,
23
- createDocumentationMap: () => import_chunk_PUEG4GNZ.createDocumentationMap,
24
- diagnostic: () => import_chunk_PUEG4GNZ.diagnostic,
25
- diagnosticHelper: () => import_chunk_PUEG4GNZ.diagnosticHelper,
26
- findNamesInScope: () => import_chunk_PUEG4GNZ.findNamesInScope,
27
- findUsingForNode: () => import_chunk_PUEG4GNZ.findUsingForNode,
28
- formatAst: () => import_chunk_PUEG4GNZ.formatAst,
29
- formatAstLongLines: () => import_chunk_PUEG4GNZ.formatAstLongLines,
30
- formatScopedName: () => import_chunk_PUEG4GNZ.formatScopedName,
31
- getApiFunctionInfo: () => import_chunk_PUEG4GNZ.getApiFunctionInfo,
32
- getApiMapping: () => import_chunk_PUEG4GNZ.getApiMapping,
33
- getSuperClasses: () => import_chunk_PUEG4GNZ.getSuperClasses,
21
+ checkCompilerVersion: () => import_chunk_XC5IVRTO.checkCompilerVersion,
22
+ collectNamespaces: () => import_chunk_XC5IVRTO.collectNamespaces,
23
+ createDocumentationMap: () => import_chunk_XC5IVRTO.createDocumentationMap,
24
+ diagnostic: () => import_chunk_XC5IVRTO.diagnostic,
25
+ diagnosticHelper: () => import_chunk_XC5IVRTO.diagnosticHelper,
26
+ findNamesInScope: () => import_chunk_XC5IVRTO.findNamesInScope,
27
+ findUsingForNode: () => import_chunk_XC5IVRTO.findUsingForNode,
28
+ formatAst: () => import_chunk_XC5IVRTO.formatAst,
29
+ formatAstLongLines: () => import_chunk_XC5IVRTO.formatAstLongLines,
30
+ formatScopedName: () => import_chunk_XC5IVRTO.formatScopedName,
31
+ getApiFunctionInfo: () => import_chunk_XC5IVRTO.getApiFunctionInfo,
32
+ getApiMapping: () => import_chunk_XC5IVRTO.getApiMapping,
33
+ getSuperClasses: () => import_chunk_XC5IVRTO.getSuperClasses,
34
34
  hasProperty: () => import_chunk_MBTLUWXR.hasProperty,
35
- isClassVariable: () => import_chunk_PUEG4GNZ.isClassVariable,
36
- isLocal: () => import_chunk_PUEG4GNZ.isLocal,
37
- isLookupCandidate: () => import_chunk_PUEG4GNZ.isLookupCandidate,
38
- isStateNode: () => import_chunk_PUEG4GNZ.isStateNode,
39
- lookupByFullName: () => import_chunk_PUEG4GNZ.lookupByFullName,
40
- lookupNext: () => import_chunk_PUEG4GNZ.lookupNext,
41
- lookupResultContains: () => import_chunk_PUEG4GNZ.lookupResultContains,
42
- lookupWithType: () => import_chunk_PUEG4GNZ.lookupWithType,
43
- makeToyboxLink: () => import_chunk_PUEG4GNZ.makeToyboxLink,
44
- mapVarDeclsByType: () => import_chunk_PUEG4GNZ.mapVarDeclsByType,
45
- markInvokeClassMethod: () => import_chunk_PUEG4GNZ.markInvokeClassMethod,
46
- parseSdkVersion: () => import_chunk_PUEG4GNZ.parseSdkVersion,
47
- resolveDiagnostics: () => import_chunk_PUEG4GNZ.resolveDiagnostics,
48
- resolveDiagnosticsMap: () => import_chunk_PUEG4GNZ.resolveDiagnosticsMap,
49
- sameLookupResult: () => import_chunk_PUEG4GNZ.sameLookupResult,
35
+ isClassVariable: () => import_chunk_XC5IVRTO.isClassVariable,
36
+ isLocal: () => import_chunk_XC5IVRTO.isLocal,
37
+ isLookupCandidate: () => import_chunk_XC5IVRTO.isLookupCandidate,
38
+ isStateNode: () => import_chunk_XC5IVRTO.isStateNode,
39
+ lookupByFullName: () => import_chunk_XC5IVRTO.lookupByFullName,
40
+ lookupNext: () => import_chunk_XC5IVRTO.lookupNext,
41
+ lookupResultContains: () => import_chunk_XC5IVRTO.lookupResultContains,
42
+ lookupWithType: () => import_chunk_XC5IVRTO.lookupWithType,
43
+ makeToyboxLink: () => import_chunk_XC5IVRTO.makeToyboxLink,
44
+ mapVarDeclsByType: () => import_chunk_XC5IVRTO.mapVarDeclsByType,
45
+ markInvokeClassMethod: () => import_chunk_XC5IVRTO.markInvokeClassMethod,
46
+ parseSdkVersion: () => import_chunk_XC5IVRTO.parseSdkVersion,
47
+ resolveDiagnostics: () => import_chunk_XC5IVRTO.resolveDiagnostics,
48
+ resolveDiagnosticsMap: () => import_chunk_XC5IVRTO.resolveDiagnosticsMap,
49
+ sameLookupResult: () => import_chunk_XC5IVRTO.sameLookupResult,
50
50
  traverseAst: () => import_chunk_MBTLUWXR.traverseAst,
51
- variableDeclarationName: () => import_chunk_PUEG4GNZ.variableDeclarationName,
52
- visitReferences: () => import_chunk_PUEG4GNZ.visitReferences,
53
- visit_resources: () => import_chunk_PUEG4GNZ.visit_resources,
54
- visitorNode: () => import_chunk_PUEG4GNZ.visitorNode
51
+ variableDeclarationName: () => import_chunk_XC5IVRTO.variableDeclarationName,
52
+ visitReferences: () => import_chunk_XC5IVRTO.visitReferences,
53
+ visit_resources: () => import_chunk_XC5IVRTO.visit_resources,
54
+ visitorNode: () => import_chunk_XC5IVRTO.visitorNode
55
55
  });
56
56
  module.exports = __toCommonJS(api_exports);
57
- var import_chunk_PUEG4GNZ = require("./chunk-PUEG4GNZ.cjs");
57
+ var import_chunk_XC5IVRTO = require("./chunk-XC5IVRTO.cjs");
58
58
  var import_chunk_SG7ODKRM = require("./chunk-SG7ODKRM.cjs");
59
59
  var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.cjs");
60
60
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
61
- (0, import_chunk_PUEG4GNZ.init_api)();
61
+ (0, import_chunk_XC5IVRTO.init_api)();
62
62
  // Annotate the CommonJS export names for ESM import in node:
63
63
  0 && (module.exports = {
64
64
  checkCompilerVersion,
@@ -26,8 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var chunk_PUEG4GNZ_exports = {};
30
- __export(chunk_PUEG4GNZ_exports, {
29
+ var chunk_XC5IVRTO_exports = {};
30
+ __export(chunk_XC5IVRTO_exports, {
31
31
  EnumTagsConst: () => EnumTagsConst,
32
32
  LastTypeTag: () => LastTypeTag,
33
33
  ObjectLikeTagsConst: () => ObjectLikeTagsConst,
@@ -133,7 +133,7 @@ __export(chunk_PUEG4GNZ_exports, {
133
133
  visitorNode: () => visitorNode,
134
134
  xml_util_exports: () => xml_util_exports
135
135
  });
136
- module.exports = __toCommonJS(chunk_PUEG4GNZ_exports);
136
+ module.exports = __toCommonJS(chunk_XC5IVRTO_exports);
137
137
  var import_chunk_SG7ODKRM = require("./chunk-SG7ODKRM.cjs");
138
138
  var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.cjs");
139
139
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
@@ -12789,12 +12789,12 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
12789
12789
  const order = getPostOrder(graph).reverse();
12790
12790
  const queue = new DataflowQueue();
12791
12791
  let selfClassDecl = null;
12792
- if (!(func.attributes & 8)) {
12793
- const klass = func.stack?.[func.stack?.length - 1].sn;
12794
- if (klass && klass.type === "ClassDeclaration") {
12795
- selfClassDecl = klass;
12796
- }
12792
+ const isStatic = !!(func.attributes & 8);
12793
+ const klass = func.stack?.[func.stack?.length - 1].sn;
12794
+ if (klass && klass.type === "ClassDeclaration") {
12795
+ selfClassDecl = klass;
12797
12796
  }
12797
+ const isInitialize = selfClassDecl && func.name === "initialize";
12798
12798
  order.forEach((block, i) => {
12799
12799
  block.order = i;
12800
12800
  });
@@ -12994,7 +12994,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
12994
12994
  );
12995
12995
  }
12996
12996
  }
12997
- if (selfClassDecl) {
12997
+ if (!isStatic && selfClassDecl) {
12998
12998
  const baseObj = getObjectValue(baseElem.type);
12999
12999
  if (baseObj && baseObj.klass.type === 16384 && (0, import_chunk_SG7ODKRM.some)(
13000
13000
  baseObj.klass.value,
@@ -13055,6 +13055,9 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
13055
13055
  cur,
13056
13056
  decl.type === "Literal" ? typeFromLiteral(decl) : typeFromTypeStateNode(state, decl, true)
13057
13057
  );
13058
+ if (isInitialize && decl.type === "VariableDeclarator" && !decl.node.init && decl.node.kind === "var" && decl.stack[decl.stack.length - 1].sn === selfClassDecl) {
13059
+ cur.type |= 1;
13060
+ }
13058
13061
  return cur;
13059
13062
  },
13060
13063
  {
@@ -17057,19 +17060,25 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
17057
17060
  Object.values(fnMap).forEach((f) => {
17058
17061
  collectNamespaces(f.ast, state);
17059
17062
  });
17060
- const cleanupAll = () => Object.values(fnMap).reduce((changes, f) => {
17061
- (0, import_chunk_MBTLUWXR.traverseAst)(f.ast, void 0, (node) => {
17062
- const ret = cleanup(state, node, f.ast);
17063
- if (ret === false) {
17064
- changes = true;
17065
- state.removeNodeComments(node, f.ast);
17066
- } else if (ret) {
17067
- changes = true;
17068
- }
17069
- return ret;
17070
- });
17071
- return changes;
17072
- }, false);
17063
+ const cleanupAll = () => {
17064
+ const usedDecls = findRezRefs(state);
17065
+ return Object.values(fnMap).reduce((changes, f) => {
17066
+ (0, import_chunk_MBTLUWXR.traverseAst)(f.ast, void 0, (node) => {
17067
+ if (usedDecls.has(node)) {
17068
+ return null;
17069
+ }
17070
+ const ret = cleanup(state, node, f.ast, usedDecls);
17071
+ if (ret === false) {
17072
+ changes = true;
17073
+ state.removeNodeComments(node, f.ast);
17074
+ } else if (ret) {
17075
+ changes = true;
17076
+ }
17077
+ return ret;
17078
+ });
17079
+ return changes;
17080
+ }, false);
17081
+ };
17073
17082
  do {
17074
17083
  state.usedByName = {};
17075
17084
  state.calledFunctions = {};
@@ -17080,7 +17089,9 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
17080
17089
  });
17081
17090
  state.exposed = state.nextExposed;
17082
17091
  state.nextExposed = {};
17083
- } while (cleanupAll() && state.config?.iterateOptimizer);
17092
+ if (!cleanupAll())
17093
+ break;
17094
+ } while (state.config?.iterateOptimizer);
17084
17095
  delete state.pre;
17085
17096
  delete state.post;
17086
17097
  if (state.config?.minimizeModules ?? true) {
@@ -17129,6 +17140,53 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
17129
17140
  sdkVersion: state.sdkVersion
17130
17141
  };
17131
17142
  }
17143
+ function findRezRefs(state) {
17144
+ const usedDecls = /* @__PURE__ */ new Set();
17145
+ state.rezAst && visitReferences(
17146
+ state,
17147
+ state.rezAst,
17148
+ null,
17149
+ false,
17150
+ (node, results, error) => {
17151
+ if (error)
17152
+ return;
17153
+ results.forEach(
17154
+ (result) => result.results.forEach((sn) => {
17155
+ switch (sn.type) {
17156
+ case "ModuleDeclaration":
17157
+ case "Program":
17158
+ case "BlockStatement":
17159
+ return;
17160
+ case "Identifier":
17161
+ case "BinaryExpression":
17162
+ return;
17163
+ case "EnumStringMember":
17164
+ if (sn.system)
17165
+ return;
17166
+ usedDecls.add(sn);
17167
+ break;
17168
+ case "ClassDeclaration":
17169
+ case "FunctionDeclaration":
17170
+ case "EnumDeclaration":
17171
+ case "TypedefDeclaration":
17172
+ if (sn.node.attrs?.system)
17173
+ return;
17174
+ case "VariableDeclarator":
17175
+ if (sn.fullName.startsWith("$.Toybox") || sn.fullName.startsWith("$.Rez")) {
17176
+ return;
17177
+ }
17178
+ usedDecls.add(sn.node);
17179
+ break;
17180
+ default:
17181
+ unhandledType(sn);
17182
+ }
17183
+ })
17184
+ );
17185
+ return void 0;
17186
+ }
17187
+ );
17188
+ return usedDecls;
17189
+ }
17132
17190
  function maybeCalled(state, func) {
17133
17191
  if (!func.body) {
17134
17192
  return true;
@@ -17149,13 +17207,15 @@ function maybeCalled(state, func) {
17149
17207
  }
17150
17208
  return false;
17151
17209
  }
17152
- function cleanup(state, node, ast) {
17210
+ function cleanup(state, node, ast, usedNodes) {
17153
17211
  switch (node.type) {
17154
17212
  case "ThisExpression":
17155
17213
  node.text = "self";
17156
17214
  break;
17157
17215
  case "EnumStringBody":
17158
17216
  if (node.members.every((m) => {
17217
+ if (usedNodes.has(m))
17218
+ return false;
17159
17219
  const name = "name" in m ? m.name : m.id.name;
17160
17220
  return (0, import_chunk_MBTLUWXR.hasProperty)(state.index, name) && !(0, import_chunk_MBTLUWXR.hasProperty)(state.exposed, name) && !(0, import_chunk_MBTLUWXR.hasProperty)(state.usedByName, name);
17161
17221
  })) {
@@ -17303,6 +17363,7 @@ var init_mc_rewrite = (0, import_chunk_ABYVSU2C.__esm)({
17303
17363
  init_unused_exprs();
17304
17364
  (0, import_chunk_SG7ODKRM.init_util)();
17305
17365
  init_variable_renamer();
17366
+ init_data_flow();
17306
17367
  }
17307
17368
  });
17308
17369
  var negativeFixups;
@@ -17975,126 +18036,132 @@ function visitReferences(state, ast, name, defn, callback, includeDefs = false,
17975
18036
  }
17976
18037
  checkResults([id.name, [{ parent: parent.sn, results }]], id);
17977
18038
  };
17978
- state.pre = (node) => {
17979
- if (filter && !filter(node))
17980
- return [];
17981
- switch (node.type) {
17982
- case "AttributeList":
18039
+ const { pre, post } = state;
18040
+ try {
18041
+ state.pre = (node) => {
18042
+ if (filter && !filter(node))
17983
18043
  return [];
17984
- case "UnaryExpression":
17985
- if (node.operator === ":")
18044
+ switch (node.type) {
18045
+ case "AttributeList":
17986
18046
  return [];
17987
- break;
17988
- case "BinaryExpression":
17989
- if (node.operator === "has") {
17990
- if (node.right.type === "UnaryExpression" && node.right.operator === ":") {
17991
- if (!name || node.right.argument.name === name) {
17992
- return checkResults(
17993
- lookup2({
17994
- type: "MemberExpression",
17995
- object: node.left,
17996
- property: node.right.argument,
17997
- computed: false
17998
- }),
17999
- node
18000
- );
18047
+ case "UnaryExpression":
18048
+ if (node.operator === ":")
18049
+ return [];
18050
+ break;
18051
+ case "BinaryExpression":
18052
+ if (node.operator === "has") {
18053
+ if (node.right.type === "UnaryExpression" && node.right.operator === ":") {
18054
+ if (!name || node.right.argument.name === name) {
18055
+ return checkResults(
18056
+ lookup2({
18057
+ type: "MemberExpression",
18058
+ object: node.left,
18059
+ property: node.right.argument,
18060
+ computed: false
18061
+ }),
18062
+ node
18063
+ );
18064
+ }
18001
18065
  }
18002
18066
  }
18003
- }
18004
- break;
18005
- case "CallExpression":
18006
- if (node.callee.type === "Identifier") {
18007
- if ((!name || node.callee.name === name) && (!filter || filter(node.callee))) {
18008
- checkResults(lookup2(node.callee, true), node.callee);
18067
+ break;
18068
+ case "CallExpression":
18069
+ if (node.callee.type === "Identifier") {
18070
+ if ((!name || node.callee.name === name) && (!filter || filter(node.callee))) {
18071
+ checkResults(lookup2(node.callee, true), node.callee);
18072
+ }
18073
+ return ["arguments"];
18009
18074
  }
18010
- return ["arguments"];
18011
- }
18012
- break;
18013
- case "Identifier":
18014
- if (!name || node.name === name) {
18015
- return checkResults(lookup2(node), node);
18016
- }
18017
- break;
18018
- case "MemberExpression": {
18019
- const property = isLookupCandidate(node);
18020
- if (property) {
18021
- if (!name || property.name === name) {
18022
- return checkResults(lookup2(node), node) || ["object"];
18075
+ break;
18076
+ case "Identifier":
18077
+ if (!name || node.name === name) {
18078
+ return checkResults(lookup2(node), node);
18023
18079
  }
18024
- return ["object"];
18025
- }
18026
- break;
18027
- }
18028
- case "MethodDefinition": {
18029
- if (!state.inType) {
18030
- throw new Error("Method definition outside of type!");
18031
- }
18032
- if (node.params) {
18033
- node.params.forEach((param) => {
18034
- if (param.type === "BinaryExpression") {
18035
- state.traverse(param.right);
18080
+ break;
18081
+ case "MemberExpression": {
18082
+ const property = isLookupCandidate(node);
18083
+ if (property) {
18084
+ if (!name || property.name === name) {
18085
+ return checkResults(lookup2(node), node) || ["object"];
18036
18086
  }
18037
- });
18038
- }
18039
- return ["returnType"];
18040
- }
18041
- case "ModuleDeclaration":
18042
- if (includeDefs) {
18043
- visitDef(node.id);
18044
- }
18045
- return ["body"];
18046
- case "ClassDeclaration":
18047
- if (includeDefs) {
18048
- visitDef(node.id, node);
18049
- }
18050
- return ["body", "superClass"];
18051
- case "FunctionDeclaration":
18052
- if (includeDefs) {
18053
- visitDef(node.id, node);
18054
- }
18055
- return ["params", "returnType", "body"];
18056
- case "TypedefDeclaration":
18057
- if (includeDefs) {
18058
- visitDef(node.id, node, "type_decls");
18059
- }
18060
- return ["ts"];
18061
- case "VariableDeclarator":
18062
- if (includeDefs) {
18063
- visitDef(node.id, node);
18087
+ return ["object"];
18088
+ }
18089
+ break;
18064
18090
  }
18065
- if (node.id.type === "BinaryExpression") {
18066
- state.traverse(node.id.right);
18091
+ case "MethodDefinition": {
18092
+ if (!state.inType) {
18093
+ throw new Error("Method definition outside of type!");
18094
+ }
18095
+ if (node.params) {
18096
+ node.params.forEach((param) => {
18097
+ if (param.type === "BinaryExpression") {
18098
+ state.traverse(param.right);
18099
+ }
18100
+ });
18101
+ }
18102
+ return ["returnType"];
18067
18103
  }
18068
- return ["init"];
18069
- case "EnumDeclaration":
18070
- if (includeDefs) {
18071
- if (node.id) {
18104
+ case "ModuleDeclaration":
18105
+ if (includeDefs) {
18106
+ visitDef(node.id);
18107
+ }
18108
+ return ["body"];
18109
+ case "ClassDeclaration":
18110
+ if (includeDefs) {
18111
+ visitDef(node.id, node);
18112
+ }
18113
+ return ["body", "superClass"];
18114
+ case "FunctionDeclaration":
18115
+ if (includeDefs) {
18116
+ visitDef(node.id, node);
18117
+ }
18118
+ return ["params", "returnType", "body"];
18119
+ case "TypedefDeclaration":
18120
+ if (includeDefs) {
18072
18121
  visitDef(node.id, node, "type_decls");
18073
18122
  }
18123
+ return ["ts"];
18124
+ case "VariableDeclarator":
18125
+ if (includeDefs) {
18126
+ visitDef(node.id, node);
18127
+ }
18128
+ if (node.id.type === "BinaryExpression") {
18129
+ state.traverse(node.id.right);
18130
+ }
18131
+ return ["init"];
18132
+ case "EnumDeclaration":
18133
+ if (includeDefs) {
18134
+ if (node.id) {
18135
+ visitDef(node.id, node, "type_decls");
18136
+ }
18137
+ break;
18138
+ }
18139
+ return [];
18140
+ case "EnumStringMember": {
18141
+ if (!filter || filter(node.id)) {
18142
+ checkResults(
18143
+ [node.id.name, [{ parent: state.top().sn, results: [node] }]],
18144
+ node
18145
+ );
18146
+ }
18074
18147
  break;
18075
18148
  }
18076
- return [];
18077
- case "EnumStringMember": {
18078
- if (!filter || filter(node.id)) {
18079
- checkResults(
18080
- [node.id.name, [{ parent: state.top().sn, results: [node] }]],
18081
- node
18082
- );
18083
- }
18084
- break;
18149
+ case "CatchClause":
18150
+ if (includeDefs)
18151
+ break;
18152
+ if (node.param && node.param.type !== "Identifier") {
18153
+ state.traverse(node.param.right);
18154
+ }
18155
+ return ["body"];
18085
18156
  }
18086
- case "CatchClause":
18087
- if (includeDefs)
18088
- break;
18089
- if (node.param && node.param.type !== "Identifier") {
18090
- state.traverse(node.param.right);
18091
- }
18092
- return ["body"];
18093
- }
18094
- return null;
18095
- };
18096
- collectNamespaces(ast, state);
18097
- delete state.pre;
18157
+ return null;
18158
+ };
18159
+ delete state.post;
18160
+ collectNamespaces(ast, state);
18161
+ } finally {
18162
+ state.pre = pre;
18163
+ state.post = post;
18164
+ }
18098
18165
  }
18099
18166
  var init_visitor = (0, import_chunk_ABYVSU2C.__esm)({
18100
18167
  "src/visitor.ts"() {
@@ -28729,7 +28796,14 @@ async function generateOptimizedProject(options) {
28729
28796
  const jungle_dir = path4.resolve(workspace, config.outputPath);
28730
28797
  await fs6.mkdir(jungle_dir, { recursive: true });
28731
28798
  const relative_path = (s) => path4.relative(jungle_dir, s);
28732
- let relative_manifest = relative_path(manifest);
28799
+ const quoted_relative_path = (s) => {
28800
+ const rel = relative_path(s);
28801
+ if (/[^-*._$/\\\w]/.test(rel)) {
28802
+ return `"${rel}"`;
28803
+ }
28804
+ return rel;
28805
+ };
28806
+ let relative_manifest = quoted_relative_path(manifest);
28733
28807
  const manifestOk = (!config.checkManifest || await checkManifest(
28734
28808
  xml,
28735
28809
  targets.map((t) => t.product)
@@ -28875,8 +28949,8 @@ async function generateOptimizedProject(options) {
28875
28949
  ).join(";")}`
28876
28950
  );
28877
28951
  }
28878
- process_field(prefix, qualifier, "resourcePath", relative_path);
28879
- process_field(prefix, qualifier, "personality", relative_path);
28952
+ process_field(prefix, qualifier, "resourcePath", quoted_relative_path);
28953
+ process_field(prefix, qualifier, "personality", quoted_relative_path);
28880
28954
  process_field(prefix, qualifier, "excludeAnnotations");
28881
28955
  const qLang = qualifier.lang;
28882
28956
  if (qLang) {
@@ -28885,7 +28959,7 @@ async function generateOptimizedProject(options) {
28885
28959
  if ((0, import_chunk_MBTLUWXR.hasProperty)(devLang, key) || !(0, import_chunk_MBTLUWXR.hasProperty)(languagesToInclude, key)) {
28886
28960
  return null;
28887
28961
  }
28888
- const mapped = map_field(qLang, key, relative_path);
28962
+ const mapped = map_field(qLang, key, quoted_relative_path);
28889
28963
  if (!mapped)
28890
28964
  return null;
28891
28965
  return [key, mapped];
@@ -29068,7 +29142,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
29068
29142
  const opt_time = await (0, import_chunk_SG7ODKRM.first_modified)(
29069
29143
  Object.values(fnMap).map((v) => v.output)
29070
29144
  );
29071
- if (source_time < opt_time && 1713624391103 < opt_time) {
29145
+ if (source_time < opt_time && 1713815963058 < opt_time) {
29072
29146
  return {
29073
29147
  hasTests,
29074
29148
  diagnostics: prevDiagnostics,
@@ -29107,7 +29181,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
29107
29181
  hasTests: hasTests2,
29108
29182
  diagnostics,
29109
29183
  sdkVersion,
29110
- optimizerVersion: "1.1.57",
29184
+ optimizerVersion: "1.1.58",
29111
29185
  ...Object.fromEntries(
29112
29186
  configOptionsToCheck.map((option) => [option, config[option]])
29113
29187
  )
@@ -18,28 +18,28 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var optimizer_exports = {};
20
20
  __export(optimizer_exports, {
21
- StateNodeAttributes: () => import_chunk_PUEG4GNZ.StateNodeAttributes,
22
- buildOptimizedProject: () => import_chunk_PUEG4GNZ.buildOptimizedProject,
21
+ StateNodeAttributes: () => import_chunk_XC5IVRTO.StateNodeAttributes,
22
+ buildOptimizedProject: () => import_chunk_XC5IVRTO.buildOptimizedProject,
23
23
  copyRecursiveAsNeeded: () => import_chunk_SG7ODKRM.copyRecursiveAsNeeded,
24
- defaultConfig: () => import_chunk_PUEG4GNZ.defaultConfig,
25
- display: () => import_chunk_PUEG4GNZ.display,
26
- generateOneConfig: () => import_chunk_PUEG4GNZ.generateOneConfig,
27
- generateOptimizedProject: () => import_chunk_PUEG4GNZ.generateOptimizedProject,
28
- getConfig: () => import_chunk_PUEG4GNZ.getConfig,
29
- getProjectAnalysis: () => import_chunk_PUEG4GNZ.getProjectAnalysis,
30
- get_jungle: () => import_chunk_PUEG4GNZ.get_jungle,
31
- isErrorWithLocation: () => import_chunk_PUEG4GNZ.isErrorWithLocation,
32
- launchSimulator: () => import_chunk_PUEG4GNZ.launchSimulator,
33
- manifestProducts: () => import_chunk_PUEG4GNZ.manifestProducts,
34
- mctree: () => import_chunk_PUEG4GNZ.mctree,
35
- simulateProgram: () => import_chunk_PUEG4GNZ.simulateProgram
24
+ defaultConfig: () => import_chunk_XC5IVRTO.defaultConfig,
25
+ display: () => import_chunk_XC5IVRTO.display,
26
+ generateOneConfig: () => import_chunk_XC5IVRTO.generateOneConfig,
27
+ generateOptimizedProject: () => import_chunk_XC5IVRTO.generateOptimizedProject,
28
+ getConfig: () => import_chunk_XC5IVRTO.getConfig,
29
+ getProjectAnalysis: () => import_chunk_XC5IVRTO.getProjectAnalysis,
30
+ get_jungle: () => import_chunk_XC5IVRTO.get_jungle,
31
+ isErrorWithLocation: () => import_chunk_XC5IVRTO.isErrorWithLocation,
32
+ launchSimulator: () => import_chunk_XC5IVRTO.launchSimulator,
33
+ manifestProducts: () => import_chunk_XC5IVRTO.manifestProducts,
34
+ mctree: () => import_chunk_XC5IVRTO.mctree,
35
+ simulateProgram: () => import_chunk_XC5IVRTO.simulateProgram
36
36
  });
37
37
  module.exports = __toCommonJS(optimizer_exports);
38
- var import_chunk_PUEG4GNZ = require("./chunk-PUEG4GNZ.cjs");
38
+ var import_chunk_XC5IVRTO = require("./chunk-XC5IVRTO.cjs");
39
39
  var import_chunk_SG7ODKRM = require("./chunk-SG7ODKRM.cjs");
40
40
  var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.cjs");
41
41
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
42
- (0, import_chunk_PUEG4GNZ.init_optimizer)();
42
+ (0, import_chunk_XC5IVRTO.init_optimizer)();
43
43
  // Annotate the CommonJS export names for ESM import in node:
44
44
  0 && (module.exports = {
45
45
  StateNodeAttributes,
@@ -18,25 +18,25 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var sdk_util_exports = {};
20
20
  __export(sdk_util_exports, {
21
- SectionKinds: () => import_chunk_PUEG4GNZ.SectionKinds,
22
- appSupport: () => import_chunk_PUEG4GNZ.appSupport,
23
- connectiq: () => import_chunk_PUEG4GNZ.connectiq,
24
- getDeviceInfo: () => import_chunk_PUEG4GNZ.getDeviceInfo,
25
- getFunctionDocumentation: () => import_chunk_PUEG4GNZ.getFunctionDocumentation,
26
- getLanguages: () => import_chunk_PUEG4GNZ.getLanguages,
27
- getSdkPath: () => import_chunk_PUEG4GNZ.getSdkPath,
28
- isWin: () => import_chunk_PUEG4GNZ.isWin,
29
- optimizeProgram: () => import_chunk_PUEG4GNZ.optimizeProgram,
30
- readPrg: () => import_chunk_PUEG4GNZ.readPrg,
31
- readPrgWithOffsets: () => import_chunk_PUEG4GNZ.readPrgWithOffsets,
32
- xmlUtil: () => import_chunk_PUEG4GNZ.xml_util_exports
21
+ SectionKinds: () => import_chunk_XC5IVRTO.SectionKinds,
22
+ appSupport: () => import_chunk_XC5IVRTO.appSupport,
23
+ connectiq: () => import_chunk_XC5IVRTO.connectiq,
24
+ getDeviceInfo: () => import_chunk_XC5IVRTO.getDeviceInfo,
25
+ getFunctionDocumentation: () => import_chunk_XC5IVRTO.getFunctionDocumentation,
26
+ getLanguages: () => import_chunk_XC5IVRTO.getLanguages,
27
+ getSdkPath: () => import_chunk_XC5IVRTO.getSdkPath,
28
+ isWin: () => import_chunk_XC5IVRTO.isWin,
29
+ optimizeProgram: () => import_chunk_XC5IVRTO.optimizeProgram,
30
+ readPrg: () => import_chunk_XC5IVRTO.readPrg,
31
+ readPrgWithOffsets: () => import_chunk_XC5IVRTO.readPrgWithOffsets,
32
+ xmlUtil: () => import_chunk_XC5IVRTO.xml_util_exports
33
33
  });
34
34
  module.exports = __toCommonJS(sdk_util_exports);
35
- var import_chunk_PUEG4GNZ = require("./chunk-PUEG4GNZ.cjs");
35
+ var import_chunk_XC5IVRTO = require("./chunk-XC5IVRTO.cjs");
36
36
  var import_chunk_SG7ODKRM = require("./chunk-SG7ODKRM.cjs");
37
37
  var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.cjs");
38
38
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
39
- (0, import_chunk_PUEG4GNZ.init_sdk_util)();
39
+ (0, import_chunk_XC5IVRTO.init_sdk_util)();
40
40
  // Annotate the CommonJS export names for ESM import in node:
41
41
  0 && (module.exports = {
42
42
  SectionKinds,
@@ -21,17 +21,17 @@ __export(worker_thread_exports, {
21
21
  default: () => worker_thread_default
22
22
  });
23
23
  module.exports = __toCommonJS(worker_thread_exports);
24
- var import_chunk_PUEG4GNZ = require("./chunk-PUEG4GNZ.cjs");
24
+ var import_chunk_XC5IVRTO = require("./chunk-XC5IVRTO.cjs");
25
25
  var import_chunk_SG7ODKRM = require("./chunk-SG7ODKRM.cjs");
26
26
  var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.cjs");
27
27
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
28
28
  var import_node_worker_threads = require("node:worker_threads");
29
29
  var require_worker_thread = (0, import_chunk_ABYVSU2C.__commonJS)({
30
30
  "src/worker-thread.ts"() {
31
- (0, import_chunk_PUEG4GNZ.init_worker_task)();
31
+ (0, import_chunk_XC5IVRTO.init_worker_task)();
32
32
  if (import_node_worker_threads.parentPort) {
33
33
  import_node_worker_threads.parentPort.on("message", async (task) => {
34
- return import_node_worker_threads.parentPort.postMessage(await (0, import_chunk_PUEG4GNZ.performTask)(task));
34
+ return import_node_worker_threads.parentPort.postMessage(await (0, import_chunk_XC5IVRTO.performTask)(task));
35
35
  });
36
36
  }
37
37
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@markw65/monkeyc-optimizer",
3
3
  "type": "commonjs",
4
- "version": "1.1.57",
4
+ "version": "1.1.58",
5
5
  "description": "Source to source optimizer for Garmin Monkey C code",
6
6
  "main": "build/optimizer.cjs",
7
7
  "types": "build/src/optimizer.d.ts",
@@ -52,7 +52,7 @@
52
52
  "author": "markw65",
53
53
  "license": "MIT",
54
54
  "dependencies": {
55
- "@markw65/prettier-plugin-monkeyc": "^1.0.56"
55
+ "@markw65/prettier-plugin-monkeyc": "^1.0.57"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@markw65/peggy-optimizer": "^1.0.1",