@markw65/monkeyc-optimizer 1.0.42 → 1.0.43

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/README.md CHANGED
@@ -507,3 +507,14 @@ Bug Fixes
507
507
 
508
508
  - New features
509
509
  - Resource files, and manifest.xml generate definitions and references so that prettier-extension-monkeyc can provide Goto Ref/Def between monkeyc, resource, and manifest files.
510
+
511
+ ### 1.0.43
512
+
513
+ - Update to [@markw65/prettier-plugin-monkeyc@1.0.39](https://github.com/markw65/prettier-plugin-monkeyc#1039)
514
+
515
+ - Fixes issues parsing/printing/optimizing NaN
516
+
517
+ - Fix issues with windows paths introduced in 1.0.42
518
+ - Add Symbols (`:name`) to the list of things the inliner knows are constants
519
+ - Propagate `:typecheck(false)` to the caller when inlining
520
+ - Fix an issue with bogus undefined symbols being reported against manifest.xml in some projects that use barrels.
package/build/api.cjs CHANGED
@@ -466,7 +466,13 @@ function ast_withLoc(node, start, end) {
466
466
  node.end = start.end;
467
467
  node.loc = { ...(node.loc || start.loc), start: start.loc.start };
468
468
  }
469
- if (end && end.loc) {
469
+ if (end === false) {
470
+ if (node.loc) {
471
+ node.loc.end = node.loc.start;
472
+ node.end = node.start;
473
+ }
474
+ }
475
+ else if (end && end.loc) {
470
476
  node.end = end.end;
471
477
  node.loc = { ...(node.loc || end.loc), end: end.loc.end };
472
478
  }
@@ -829,6 +835,12 @@ function getArgSafety(state, func, args, requireAll) {
829
835
  let allSafe = true;
830
836
  if (!args.every((arg, i) => {
831
837
  switch (arg.type) {
838
+ case "UnaryExpression":
839
+ if (arg.operator === ":") {
840
+ safeArgs.push(true);
841
+ return true;
842
+ }
843
+ break;
832
844
  case "Literal":
833
845
  safeArgs.push(true);
834
846
  return true;
@@ -1408,7 +1420,16 @@ function inlineWithArgs(state, func, call, context) {
1408
1420
  withLocDeep(body, context, context, true);
1409
1421
  return body;
1410
1422
  }
1411
- function inliner_inlineFunction(state, func, call, context) {
1423
+ function isTypecheckArg(node, arg) {
1424
+ return (node.type === "CallExpression" &&
1425
+ node.callee.type === "Identifier" &&
1426
+ node.callee.name === ":typecheck" &&
1427
+ (arg === null ||
1428
+ (node.arguments.length === 1 &&
1429
+ node.arguments[0].type === "Literal" &&
1430
+ node.arguments[0].value === arg)));
1431
+ }
1432
+ function inlineFunctionHelper(state, func, call, context) {
1412
1433
  if (context) {
1413
1434
  return inlineWithArgs(state, func, call, context);
1414
1435
  }
@@ -1419,6 +1440,33 @@ function inliner_inlineFunction(state, func, call, context) {
1419
1440
  state.localsStack[state.localsStack.length - 1].map = map;
1420
1441
  return ret && withLocDeep(ret, call, call, true);
1421
1442
  }
1443
+ function inliner_inlineFunction(state, func, call, context) {
1444
+ const ret = inlineFunctionHelper(state, func, call, context);
1445
+ if (!ret)
1446
+ return ret;
1447
+ const typecheckFalse = func.node.attrs?.attributes?.elements.find((attr) => isTypecheckArg(attr, false));
1448
+ if (!typecheckFalse) {
1449
+ return ret;
1450
+ }
1451
+ const callerSn = state.stack.find((sn) => sn.type === "FunctionDeclaration");
1452
+ if (!callerSn) {
1453
+ return ret;
1454
+ }
1455
+ const caller = callerSn.node;
1456
+ if (!caller.attrs) {
1457
+ caller.attrs = withLoc({
1458
+ type: "AttributeList",
1459
+ }, caller, false);
1460
+ }
1461
+ if (!caller.attrs.attributes) {
1462
+ caller.attrs.attributes = withLoc({ type: "Attributes", elements: [] }, caller.attrs, false);
1463
+ }
1464
+ if (caller.attrs.attributes.elements.find((attr) => isTypecheckArg(attr, null))) {
1465
+ return ret;
1466
+ }
1467
+ caller.attrs.attributes.elements.unshift(withLocDeep({ ...typecheckFalse }, caller.attrs, false));
1468
+ return ret;
1469
+ }
1422
1470
  function applyTypeIfNeeded(node) {
1423
1471
  if ("enumType" in node && node.enumType) {
1424
1472
  node = {
@@ -4748,7 +4796,9 @@ function add_resources_to_ast(ast, resources, manifestXML) {
4748
4796
  body.push(rez);
4749
4797
  const hiddenRez = makeModule("*Rez*");
4750
4798
  rez.body.body.push(hiddenRez);
4751
- if (manifestXML && manifestXML.body instanceof external_sdk_util_cjs_namespaceObject.xmlUtil.Nodes) {
4799
+ if (barrel === "" &&
4800
+ manifestXML &&
4801
+ manifestXML.body instanceof external_sdk_util_cjs_namespaceObject.xmlUtil.Nodes) {
4752
4802
  manifestXML.body
4753
4803
  .children("iq:application")
4754
4804
  .elements.forEach((e) => add_one_resource(rez, e));
@@ -4731,7 +4731,13 @@ function withLoc(node, start, end) {
4731
4731
  node.end = start.end;
4732
4732
  node.loc = { ...(node.loc || start.loc), start: start.loc.start };
4733
4733
  }
4734
- if (end && end.loc) {
4734
+ if (end === false) {
4735
+ if (node.loc) {
4736
+ node.loc.end = node.loc.start;
4737
+ node.end = node.start;
4738
+ }
4739
+ }
4740
+ else if (end && end.loc) {
4735
4741
  node.end = end.end;
4736
4742
  node.loc = { ...(node.loc || end.loc), end: end.loc.end };
4737
4743
  }
@@ -5092,6 +5098,12 @@ function getArgSafety(state, func, args, requireAll) {
5092
5098
  let allSafe = true;
5093
5099
  if (!args.every((arg, i) => {
5094
5100
  switch (arg.type) {
5101
+ case "UnaryExpression":
5102
+ if (arg.operator === ":") {
5103
+ safeArgs.push(true);
5104
+ return true;
5105
+ }
5106
+ break;
5095
5107
  case "Literal":
5096
5108
  safeArgs.push(true);
5097
5109
  return true;
@@ -5671,7 +5683,16 @@ function inlineWithArgs(state, func, call, context) {
5671
5683
  withLocDeep(body, context, context, true);
5672
5684
  return body;
5673
5685
  }
5674
- function inlineFunction(state, func, call, context) {
5686
+ function isTypecheckArg(node, arg) {
5687
+ return (node.type === "CallExpression" &&
5688
+ node.callee.type === "Identifier" &&
5689
+ node.callee.name === ":typecheck" &&
5690
+ (arg === null ||
5691
+ (node.arguments.length === 1 &&
5692
+ node.arguments[0].type === "Literal" &&
5693
+ node.arguments[0].value === arg)));
5694
+ }
5695
+ function inlineFunctionHelper(state, func, call, context) {
5675
5696
  if (context) {
5676
5697
  return inlineWithArgs(state, func, call, context);
5677
5698
  }
@@ -5682,6 +5703,33 @@ function inlineFunction(state, func, call, context) {
5682
5703
  state.localsStack[state.localsStack.length - 1].map = map;
5683
5704
  return ret && withLocDeep(ret, call, call, true);
5684
5705
  }
5706
+ function inlineFunction(state, func, call, context) {
5707
+ const ret = inlineFunctionHelper(state, func, call, context);
5708
+ if (!ret)
5709
+ return ret;
5710
+ const typecheckFalse = func.node.attrs?.attributes?.elements.find((attr) => isTypecheckArg(attr, false));
5711
+ if (!typecheckFalse) {
5712
+ return ret;
5713
+ }
5714
+ const callerSn = state.stack.find((sn) => sn.type === "FunctionDeclaration");
5715
+ if (!callerSn) {
5716
+ return ret;
5717
+ }
5718
+ const caller = callerSn.node;
5719
+ if (!caller.attrs) {
5720
+ caller.attrs = withLoc({
5721
+ type: "AttributeList",
5722
+ }, caller, false);
5723
+ }
5724
+ if (!caller.attrs.attributes) {
5725
+ caller.attrs.attributes = withLoc({ type: "Attributes", elements: [] }, caller.attrs, false);
5726
+ }
5727
+ if (caller.attrs.attributes.elements.find((attr) => isTypecheckArg(attr, null))) {
5728
+ return ret;
5729
+ }
5730
+ caller.attrs.attributes.elements.unshift(withLocDeep({ ...typecheckFalse }, caller.attrs, false));
5731
+ return ret;
5732
+ }
5685
5733
  function applyTypeIfNeeded(node) {
5686
5734
  if ("enumType" in node && node.enumType) {
5687
5735
  node = {
@@ -9218,7 +9266,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
9218
9266
  // the oldest optimized file, we don't need to regenerate
9219
9267
  const source_time = await (0,external_util_cjs_namespaceObject.last_modified)(Object.keys(fnMap).concat(dependencyFiles));
9220
9268
  const opt_time = await (0,external_util_cjs_namespaceObject.first_modified)(Object.values(fnMap).map((v) => v.output));
9221
- if (source_time < opt_time && 1670349312602 < opt_time) {
9269
+ if (source_time < opt_time && 1670458646779 < opt_time) {
9222
9270
  return { hasTests, diagnostics: prevDiagnostics };
9223
9271
  }
9224
9272
  }
@@ -9245,7 +9293,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
9245
9293
  return promises_namespaceObject.writeFile(external_path_.join(output, "build-info.json"), JSON.stringify({
9246
9294
  hasTests,
9247
9295
  diagnostics,
9248
- optimizerVersion: "1.0.42",
9296
+ optimizerVersion: "1.0.43",
9249
9297
  ...Object.fromEntries(configOptionsToCheck.map((option) => [option, config[option]])),
9250
9298
  }))
9251
9299
  .then(() => ({ hasTests, diagnostics }));
@@ -176,7 +176,7 @@ function makeAttribute(name, value) {
176
176
  function parseXml(content, fileName = null) {
177
177
  try {
178
178
  const [prolog, body, misc] = peg$parse(content, {
179
- grammarSource: fileName || "unknown",
179
+ grammarSource: (fileName || "unknown").replace(/\\/g, "/"),
180
180
  });
181
181
  return new Document(prolog, new Nodes(body), misc, content);
182
182
  }
@@ -5,8 +5,8 @@ export declare function isExpression(node: mctree.Node): node is mctree.Expressi
5
5
  export declare function mayThrow(node: mctree.Node): boolean;
6
6
  export declare function hasProperty<T extends null extends T ? unknown : undefined extends T ? unknown : never>(obj: T, prop: string): obj is NonNullable<T>;
7
7
  export declare function hasProperty<T>(obj: T, prop: string): boolean;
8
- export declare function withLoc<T extends mctree.Node>(node: T, start: mctree.Node | null, end?: mctree.Node | undefined): T;
9
- export declare function withLocDeep<T extends mctree.Node>(node: T, start: mctree.Node | null, end?: mctree.Node | undefined, inplace?: boolean): T;
8
+ export declare function withLoc<T extends mctree.Node>(node: T, start: mctree.Node | null, end?: mctree.Node | undefined | false): T;
9
+ export declare function withLocDeep<T extends mctree.Node>(node: T, start: mctree.Node | null, end?: mctree.Node | undefined | false, inplace?: boolean): T;
10
10
  export declare function cloneDeep<T extends mctree.Node>(node: T): T;
11
11
  interface NumberLiteral extends mctree.Literal {
12
12
  value: number;
@@ -32,6 +32,7 @@ export declare type BuildConfig = {
32
32
  sizeBasedPRE?: boolean | string;
33
33
  prettier?: Record<string, unknown>;
34
34
  extensionVersion?: string;
35
+ useLocalOptimizer?: boolean;
35
36
  };
36
37
  export declare type StateNodeDecl = StateNode | mctree.EnumStringMember | mctree.TypedIdentifier | mctree.EnumDeclaration;
37
38
  export declare type StateNodeDecls = {
package/build/util.cjs CHANGED
@@ -7756,7 +7756,7 @@ function globa(pattern, options) {
7756
7756
  }
7757
7757
  function globSome(pattern, predicate, options) {
7758
7758
  return new Promise((resolve, _reject) => {
7759
- const stream = out.stream(pattern, options || {});
7759
+ const stream = out.stream(pattern.replace(/\\/g, "/"), options || {});
7760
7760
  let result = false;
7761
7761
  const resolver = () => {
7762
7762
  resolve(result);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@markw65/monkeyc-optimizer",
3
3
  "type": "module",
4
- "version": "1.0.42",
4
+ "version": "1.0.43",
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",
@@ -38,7 +38,7 @@
38
38
  "author": "markw65",
39
39
  "license": "MIT",
40
40
  "dependencies": {
41
- "@markw65/prettier-plugin-monkeyc": "^1.0.38"
41
+ "@markw65/prettier-plugin-monkeyc": "^1.0.39"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/glob": "^8.0.0",