@markw65/monkeyc-optimizer 1.1.47 → 1.1.49

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,10 +2,21 @@
2
2
 
3
3
  All notable changes to the "monkeyc-optimizer" package will be documented in this file.
4
4
 
5
+ ### 1.1.49
6
+
7
+ - Fix a bug in cleanupUnusedVars that could cause the wrong variable to be removed
8
+ - Allow variables mixed with literals in jungle files
9
+ - Allow Char as operands to relational operators
10
+ - Include Null in dictionary return type
11
+
12
+ ### 1.1.48
13
+
14
+ - Adds a `--char-info-as-array` option to `cft-font-info`. When this option is set, charInfo is an array of arrays, rather than an array of objects, and there is a (single) `charInfoNames` array, giving the names of the elements of the charInfo sub-arrays. This is to save space - the charInfo array only contains the data, rather than (potentially) thousands of copies of the field names.
15
+
5
16
  ### 1.1.47
6
17
 
7
18
  - Adds glyphAscent and glyphDescent to the font info produced by `cft-font-info`
8
- - Adds a --chars option to `cft-font-info` to select the chars you want included. This can save time, and greatly reduce the amount of output produced.
19
+ - Adds a `--chars` option to `cft-font-info` to select the chars you want included. This can save time, and greatly reduce the amount of output produced.
9
20
 
10
21
  ### 1.1.46
11
22
 
@@ -2,12 +2,13 @@
2
2
 
3
3
  const cft = require("../build/cftinfo.cjs");
4
4
  const sdkUtil = require("../build/sdk-util.cjs");
5
- const { globa } = require("../build/util.cjs");
5
+ const { globa, promiseAll } = require("../build/util.cjs");
6
6
  const path = require("node:path");
7
7
 
8
8
  const fonts = new Set();
9
9
  const otherArgs = [];
10
10
  let charsWanted;
11
+ let charInfoAsArray;
11
12
 
12
13
  function error(e) {
13
14
  throw new Error(e);
@@ -34,6 +35,9 @@ const prev = process.argv.slice(2).reduce((key, value) => {
34
35
  if (value == null) return key;
35
36
  charsWanted = (charsWanted ?? "") + value;
36
37
  break;
38
+ case "char-info-as-array":
39
+ charInfoAsArray = !value || /^(true|1)$/i.test(value);
40
+ break;
37
41
  default:
38
42
  error(`Unknown argument: --${key}`);
39
43
  }
@@ -71,28 +75,41 @@ Promise.all(
71
75
  )
72
76
  );
73
77
  })
74
- )
75
- .then((results) =>
76
- Promise.all(
77
- Array.from(fonts).map((font) =>
78
- cft.getCFTFontInfo(font, charsWanted).catch(() => null)
78
+ ).then((results) => {
79
+ console.log("{");
80
+ let last = -1;
81
+ let active = [];
82
+ const fontArray = Array.from(fonts).sort();
83
+ return promiseAll(
84
+ (i) =>
85
+ fontArray[i] &&
86
+ cft
87
+ .getCFTFontInfo(fontArray[i], { chars: charsWanted, charInfoAsArray })
88
+ .then(({ name, ...rest }) => `"${name}":${JSON.stringify(rest)},`)
89
+ .catch(() => null)
90
+ .then((line) => {
91
+ active[i] = line;
92
+ while (active[last + 1] !== undefined) {
93
+ const a = active[++last];
94
+ if (a != null) {
95
+ console.log(a);
96
+ }
97
+ delete active[last];
98
+ }
99
+ })
100
+ )
101
+ .then(() => active.forEach((line) => line && console.log(line)))
102
+ .then(() =>
103
+ console.log(
104
+ `"devices":${JSON.stringify(
105
+ Object.fromEntries(
106
+ results
107
+ .flat()
108
+ .filter((result) => result != null)
109
+ .map(({ device, ...rest }) => [device, rest])
110
+ )
111
+ )}`
79
112
  )
80
113
  )
81
- .then((fonts) =>
82
- Object.fromEntries(
83
- fonts
84
- .filter((font) => font != null)
85
- .map(({ name, ...rest }) => [name, rest])
86
- )
87
- )
88
- .then((fonts) => ({
89
- fonts,
90
- devices: Object.fromEntries(
91
- results
92
- .flat()
93
- .filter((result) => result != null)
94
- .map(({ device, ...rest }) => [device, rest])
95
- ),
96
- }))
97
- )
98
- .then((results) => console.log(JSON.stringify(results)));
114
+ .then(() => console.log("}"));
115
+ });
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_2ATRIWWT.checkCompilerVersion,
22
- collectNamespaces: () => import_chunk_2ATRIWWT.collectNamespaces,
23
- createDocumentationMap: () => import_chunk_2ATRIWWT.createDocumentationMap,
24
- diagnostic: () => import_chunk_2ATRIWWT.diagnostic,
25
- diagnosticHelper: () => import_chunk_2ATRIWWT.diagnosticHelper,
26
- findNamesInScope: () => import_chunk_2ATRIWWT.findNamesInScope,
27
- findUsingForNode: () => import_chunk_2ATRIWWT.findUsingForNode,
28
- formatAst: () => import_chunk_2ATRIWWT.formatAst,
29
- formatAstLongLines: () => import_chunk_2ATRIWWT.formatAstLongLines,
30
- formatScopedName: () => import_chunk_2ATRIWWT.formatScopedName,
31
- getApiFunctionInfo: () => import_chunk_2ATRIWWT.getApiFunctionInfo,
32
- getApiMapping: () => import_chunk_2ATRIWWT.getApiMapping,
33
- getSuperClasses: () => import_chunk_2ATRIWWT.getSuperClasses,
21
+ checkCompilerVersion: () => import_chunk_DZ7YMTUE.checkCompilerVersion,
22
+ collectNamespaces: () => import_chunk_DZ7YMTUE.collectNamespaces,
23
+ createDocumentationMap: () => import_chunk_DZ7YMTUE.createDocumentationMap,
24
+ diagnostic: () => import_chunk_DZ7YMTUE.diagnostic,
25
+ diagnosticHelper: () => import_chunk_DZ7YMTUE.diagnosticHelper,
26
+ findNamesInScope: () => import_chunk_DZ7YMTUE.findNamesInScope,
27
+ findUsingForNode: () => import_chunk_DZ7YMTUE.findUsingForNode,
28
+ formatAst: () => import_chunk_DZ7YMTUE.formatAst,
29
+ formatAstLongLines: () => import_chunk_DZ7YMTUE.formatAstLongLines,
30
+ formatScopedName: () => import_chunk_DZ7YMTUE.formatScopedName,
31
+ getApiFunctionInfo: () => import_chunk_DZ7YMTUE.getApiFunctionInfo,
32
+ getApiMapping: () => import_chunk_DZ7YMTUE.getApiMapping,
33
+ getSuperClasses: () => import_chunk_DZ7YMTUE.getSuperClasses,
34
34
  hasProperty: () => import_chunk_MBTLUWXR.hasProperty,
35
- isClassVariable: () => import_chunk_2ATRIWWT.isClassVariable,
36
- isLocal: () => import_chunk_2ATRIWWT.isLocal,
37
- isLookupCandidate: () => import_chunk_2ATRIWWT.isLookupCandidate,
38
- isStateNode: () => import_chunk_2ATRIWWT.isStateNode,
39
- lookupByFullName: () => import_chunk_2ATRIWWT.lookupByFullName,
40
- lookupNext: () => import_chunk_2ATRIWWT.lookupNext,
41
- lookupResultContains: () => import_chunk_2ATRIWWT.lookupResultContains,
42
- lookupWithType: () => import_chunk_2ATRIWWT.lookupWithType,
43
- makeToyboxLink: () => import_chunk_2ATRIWWT.makeToyboxLink,
44
- mapVarDeclsByType: () => import_chunk_2ATRIWWT.mapVarDeclsByType,
45
- markInvokeClassMethod: () => import_chunk_2ATRIWWT.markInvokeClassMethod,
46
- parseSdkVersion: () => import_chunk_2ATRIWWT.parseSdkVersion,
47
- resolveDiagnostics: () => import_chunk_2ATRIWWT.resolveDiagnostics,
48
- resolveDiagnosticsMap: () => import_chunk_2ATRIWWT.resolveDiagnosticsMap,
49
- sameLookupResult: () => import_chunk_2ATRIWWT.sameLookupResult,
35
+ isClassVariable: () => import_chunk_DZ7YMTUE.isClassVariable,
36
+ isLocal: () => import_chunk_DZ7YMTUE.isLocal,
37
+ isLookupCandidate: () => import_chunk_DZ7YMTUE.isLookupCandidate,
38
+ isStateNode: () => import_chunk_DZ7YMTUE.isStateNode,
39
+ lookupByFullName: () => import_chunk_DZ7YMTUE.lookupByFullName,
40
+ lookupNext: () => import_chunk_DZ7YMTUE.lookupNext,
41
+ lookupResultContains: () => import_chunk_DZ7YMTUE.lookupResultContains,
42
+ lookupWithType: () => import_chunk_DZ7YMTUE.lookupWithType,
43
+ makeToyboxLink: () => import_chunk_DZ7YMTUE.makeToyboxLink,
44
+ mapVarDeclsByType: () => import_chunk_DZ7YMTUE.mapVarDeclsByType,
45
+ markInvokeClassMethod: () => import_chunk_DZ7YMTUE.markInvokeClassMethod,
46
+ parseSdkVersion: () => import_chunk_DZ7YMTUE.parseSdkVersion,
47
+ resolveDiagnostics: () => import_chunk_DZ7YMTUE.resolveDiagnostics,
48
+ resolveDiagnosticsMap: () => import_chunk_DZ7YMTUE.resolveDiagnosticsMap,
49
+ sameLookupResult: () => import_chunk_DZ7YMTUE.sameLookupResult,
50
50
  traverseAst: () => import_chunk_MBTLUWXR.traverseAst,
51
- variableDeclarationName: () => import_chunk_2ATRIWWT.variableDeclarationName,
52
- visitReferences: () => import_chunk_2ATRIWWT.visitReferences,
53
- visit_resources: () => import_chunk_2ATRIWWT.visit_resources,
54
- visitorNode: () => import_chunk_2ATRIWWT.visitorNode
51
+ variableDeclarationName: () => import_chunk_DZ7YMTUE.variableDeclarationName,
52
+ visitReferences: () => import_chunk_DZ7YMTUE.visitReferences,
53
+ visit_resources: () => import_chunk_DZ7YMTUE.visit_resources,
54
+ visitorNode: () => import_chunk_DZ7YMTUE.visitorNode
55
55
  });
56
56
  module.exports = __toCommonJS(api_exports);
57
- var import_chunk_2ATRIWWT = require("./chunk-2ATRIWWT.cjs");
57
+ var import_chunk_DZ7YMTUE = require("./chunk-DZ7YMTUE.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_2ATRIWWT.init_api)();
61
+ (0, import_chunk_DZ7YMTUE.init_api)();
62
62
  // Annotate the CommonJS export names for ESM import in node:
63
63
  0 && (module.exports = {
64
64
  checkCompilerVersion,
package/build/cftinfo.cjs CHANGED
@@ -40,7 +40,7 @@ var fs = __toESM(require("node:fs/promises"));
40
40
  var path = __toESM(require("node:path"));
41
41
  var zlib = __toESM(require("node:zlib"));
42
42
  (0, import_chunk_MBTLUWXR.init_ast)();
43
- async function getCFTFontInfoFromBuffer(name, data, chars) {
43
+ async function getCFTFontInfoFromBuffer(name, data, options) {
44
44
  const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
45
45
  const glyphFlags = view.getUint8(3);
46
46
  const cmapOffset = view.getUint32(8);
@@ -49,7 +49,8 @@ async function getCFTFontInfoFromBuffer(name, data, chars) {
49
49
  const height = view.getUint16(22);
50
50
  const ascent = view.getUint16(24);
51
51
  const internalLeading = view.getUint16(26);
52
- const charFilter = chars ? new Set(chars.split("").map((ch) => ch.charCodeAt(0))) : null;
52
+ const { chars, charInfoAsArray } = typeof options === "string" ? { chars: options } : options ?? {};
53
+ const charFilter = chars != null ? new Set(chars.split("").map((ch) => ch.charCodeAt(0))) : null;
53
54
  const cmapNGroups = view.getUint32(cmapOffset + 12);
54
55
  const charInfo = [];
55
56
  const maybeCompressed = view.getUint16(0) === 40;
@@ -85,6 +86,16 @@ async function getCFTFontInfoFromBuffer(name, data, chars) {
85
86
  });
86
87
  }
87
88
  }
89
+ if (charInfoAsArray && charInfo.length) {
90
+ return {
91
+ name,
92
+ height,
93
+ ascent,
94
+ internalLeading,
95
+ charInfo: charInfo.map((info) => Object.values(info)),
96
+ charInfoNames: Object.keys(charInfo[0])
97
+ };
98
+ }
88
99
  return {
89
100
  name,
90
101
  height,
@@ -169,8 +180,10 @@ async function getGlyphData(view, offset, maybeCompressed) {
169
180
  );
170
181
  }
171
182
  function getGlyphAscentDescent(glyphData, glyphOffset, width, height, ascent, align, flags) {
172
- const rle = (glyphOffset & 8388608) !== 0;
173
- glyphOffset &= 8388607;
183
+ const rle = (flags & 2) !== 0;
184
+ if (rle) {
185
+ glyphOffset &= 8388607;
186
+ }
174
187
  const pixelsPerByte = flags & 4 ? 4 : 8;
175
188
  const bytesToCount = Math.ceil(width / pixelsPerByte);
176
189
  const byteWidth = Math.ceil(bytesToCount / align) * align;