@markw65/monkeyc-optimizer 1.0.12 → 1.0.15

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.
@@ -7215,8 +7215,14 @@ async function getDeviceInfo() {
7215
7215
  }
7216
7216
  return Promise.all(files.map((file) => {
7217
7217
  return promises_namespaceObject.readFile(file).then((data) => {
7218
- const { deviceId, appTypes, deviceFamily } = JSON.parse(data.toString());
7219
- return [deviceId, { appTypes, deviceFamily }];
7218
+ const { deviceId, appTypes, deviceFamily, displayName, partNumbers } = JSON.parse(data.toString());
7219
+ const languages = Object.fromEntries(partNumbers
7220
+ .map((part) => part.languages.map((lang) => [lang.code, true]))
7221
+ .flat(1));
7222
+ return [
7223
+ deviceId,
7224
+ { appTypes, deviceFamily, displayName, languages },
7225
+ ];
7220
7226
  });
7221
7227
  })).then((info) => {
7222
7228
  return Object.fromEntries(info);
@@ -1,8 +1,9 @@
1
1
  import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
2
  export declare function getApiMapping(state?: ProgramState): Promise<ProgramStateNode | null>;
3
- export declare function hasProperty(obj: unknown, prop: string): any;
3
+ export declare function hasProperty<T extends null extends T ? unknown : undefined extends T ? unknown : never>(obj: T, prop: string): obj is NonNullable<T>;
4
+ export declare function hasProperty<T>(obj: T, prop: string): boolean;
4
5
  export declare function isStateNode(node: StateNodeDecl): node is StateNode;
5
6
  export declare function variableDeclarationName(node: mctree.TypedIdentifier): string;
6
- export declare function collectNamespaces(ast: mctree.Program, state: ProgramState): ProgramStateNode;
7
- export declare function traverseAst(node: mctree.Node, pre?: (node: mctree.Node) => void | null | false | (keyof mctree.NodeAll)[], post?: (node: mctree.Node) => void | null | false | mctree.Node): false | void | null | mctree.Node;
8
- export declare function formatAst(node: mctree.Node, monkeyCSource?: string): string;
7
+ export declare function collectNamespaces(ast: mctree.Program, stateIn?: ProgramState): ProgramStateNode;
8
+ export declare function traverseAst(node: mctree.Node, pre?: null | ((node: mctree.Node) => void | null | false | (keyof mctree.NodeAll)[]), post?: (node: mctree.Node) => void | null | false | mctree.Node): false | void | null | mctree.Node;
9
+ export declare function formatAst(node: mctree.Node, monkeyCSource?: string | null): string;
@@ -1,6 +1,6 @@
1
- export declare function build_project(product: string, options: BuildConfig, lineCallback?: (line: string) => void): Promise<{
1
+ export declare function build_project(product: string | null, options: BuildConfig, lineCallback?: (line: string) => void): Promise<{
2
2
  exe: string;
3
3
  args: string[];
4
4
  program: string;
5
- product: string;
5
+ product: string | null;
6
6
  }>;
@@ -6,7 +6,7 @@ export declare type Target = {
6
6
  group?: {
7
7
  optimizerConfig: JungleQualifier;
8
8
  dir?: string;
9
- key?: string;
9
+ key: string;
10
10
  };
11
11
  };
12
12
  declare type LangResourcePaths = {
@@ -56,8 +56,8 @@ export declare type ManifestXML = {
56
56
  $: {
57
57
  "xmlns:iq": string;
58
58
  };
59
- "iq:application": Array<iqApplication>;
60
- "iq:barrel": Array<iqBarrel>;
59
+ "iq:application"?: Array<iqApplication>;
60
+ "iq:barrel"?: Array<iqBarrel>;
61
61
  };
62
62
  };
63
63
  export declare function readManifest(manifest: string): Promise<ManifestXML>;
@@ -66,6 +66,6 @@ export declare function manifestProducts(manifest: ManifestXML): string[];
66
66
  export declare function manifestBarrels(manifest: ManifestXML): string[];
67
67
  export declare function manifestDropBarrels(manifest: ManifestXML): void;
68
68
  export declare function manifestBarrelName(manifestName: string, manifest: ManifestXML): string;
69
- export declare function manifestAnnotations(manifest: ManifestXML): string[];
69
+ export declare function manifestAnnotations(manifest: ManifestXML): string[] | undefined;
70
70
  export declare function checkManifest(manifest: ManifestXML, products: string[]): Promise<boolean>;
71
71
  export {};
@@ -1,7 +1,7 @@
1
1
  import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
2
  export declare function getFileSources(fnMap: FilesToOptimizeMap): Promise<void>;
3
3
  export declare function getFileASTs(fnMap: FilesToOptimizeMap): Promise<boolean>;
4
- export declare function analyze(fnMap: FilesToOptimizeMap): Promise<ProgramState>;
5
- export declare function getLiteralFromDecls(decls: StateNodeDecl[]): mctree.AsExpression | mctree.Literal;
6
- export declare function getLiteralNode(node: mctree.Node): null | mctree.Literal | mctree.AsExpression;
4
+ export declare function analyze(fnMap: FilesToOptimizeMap): Promise<ProgramStateAnalysis>;
5
+ export declare function getLiteralFromDecls(decls: StateNodeDecl[]): null;
6
+ export declare function getLiteralNode(node: mctree.Node | null | undefined): null | mctree.Literal | mctree.AsExpression;
7
7
  export declare function optimizeMonkeyC(fnMap: FilesToOptimizeMap): Promise<void>;
@@ -1,12 +1,17 @@
1
- import { get_jungle, Target, ResolvedJungle } from "./jungles";
1
+ import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
+ import { get_jungle, ResolvedJungle, Target } from "./jungles";
2
3
  import { launchSimulator, simulateProgram } from "./launch";
4
+ import { manifestProducts } from "./manifest";
3
5
  import { copyRecursiveAsNeeded } from "./util";
4
- import { mctree } from "@markw65/prettier-plugin-monkeyc";
5
- export { copyRecursiveAsNeeded, launchSimulator, simulateProgram, get_jungle, ResolvedJungle, mctree, };
6
+ export { copyRecursiveAsNeeded, get_jungle, launchSimulator, manifestProducts, mctree, ResolvedJungle, simulateProgram, };
6
7
  export declare const defaultConfig: {
7
8
  outputPath: string;
8
9
  workspace: string;
9
10
  };
11
+ export interface ErrorWithLocation extends Error {
12
+ location?: NonNullable<mctree.Node["loc"]>;
13
+ }
14
+ export declare function isErrorWithLocation(e: Error): e is ErrorWithLocation;
10
15
  declare global {
11
16
  type BuildConfig = {
12
17
  workspace?: string;
@@ -38,58 +43,65 @@ declare global {
38
43
  type StateNodeDecls = {
39
44
  [key: string]: StateNodeDecl[];
40
45
  };
41
- type ProgramStateNode = {
46
+ interface BaseStateNode {
47
+ type: string;
48
+ node: mctree.Node | null | undefined;
49
+ name: string | null | undefined;
50
+ fullName: string | null | undefined;
51
+ decls?: StateNodeDecls | undefined;
52
+ type_decls?: StateNodeDecls | undefined;
53
+ stack?: ProgramStateStack | undefined;
54
+ }
55
+ interface ProgramStateNode extends BaseStateNode {
42
56
  type: "Program";
43
57
  node: null | undefined;
44
58
  name: "$";
45
59
  fullName: "$";
46
- decls?: StateNodeDecls;
47
- stack?: null | undefined;
48
- };
49
- type ModuleStateNode = {
60
+ stack?: undefined;
61
+ }
62
+ interface ModuleStateNode extends BaseStateNode {
50
63
  type: "ModuleDeclaration";
64
+ node: mctree.ModuleDeclaration;
51
65
  name: string;
52
66
  fullName: string;
53
- node: mctree.ModuleDeclaration;
54
- stack?: ProgramStateStack;
55
- decls?: StateNodeDecls;
56
- };
57
- type ClassStateNode = {
67
+ }
68
+ interface ClassStateNode extends BaseStateNode {
58
69
  type: "ClassDeclaration";
70
+ node: mctree.ClassDeclaration;
59
71
  name: string;
60
72
  fullName: string;
61
- node: mctree.ClassDeclaration;
62
- decls?: StateNodeDecls;
63
- stack?: ProgramStateStack;
64
- superClass: ClassStateNode[] | true;
65
- };
66
- type FunctionStateNode = {
73
+ superClass?: ClassStateNode[] | true;
74
+ }
75
+ interface FunctionStateNode extends BaseStateNode {
67
76
  type: "FunctionDeclaration";
77
+ node: mctree.FunctionDeclaration;
68
78
  name: string;
69
79
  fullName: string;
70
- node: mctree.FunctionDeclaration;
71
80
  stack?: ProgramStateStack;
72
81
  decls?: undefined;
73
- };
74
- type BlockStateNode = {
82
+ }
83
+ interface BlockStateNode extends BaseStateNode {
75
84
  type: "BlockStatement";
76
- name?: null | undefined;
77
- fullName?: null | undefined;
85
+ name: undefined;
86
+ fullName: undefined;
78
87
  node: mctree.BlockStatement;
79
- decls?: StateNodeDecls;
80
- stack?: null | undefined;
81
- };
88
+ stack?: undefined;
89
+ }
82
90
  type StateNode = ProgramStateNode | FunctionStateNode | BlockStateNode | ClassStateNode | ModuleStateNode;
83
91
  type ProgramStateStack = StateNode[];
84
92
  export type ProgramState = {
85
93
  allFunctions?: FunctionStateNode[];
86
94
  allClasses?: ClassStateNode[];
87
95
  stack?: ProgramStateStack;
88
- shouldExclude?: (node: any) => any;
89
- pre?: (node: mctree.Node) => null | false | (keyof mctree.NodeAll)[];
90
- post?: (node: mctree.Node) => null | false | mctree.Node;
91
- lookup?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => [string, StateNodeDecl[], ProgramStateStack];
92
- traverse?: (node: mctree.Node) => void | boolean | mctree.Node;
96
+ removeNodeComments?: (node: mctree.Node, ast: mctree.Program) => void;
97
+ shouldExclude?: (node: mctree.Node) => boolean;
98
+ pre?: (node: mctree.Node, state: ProgramStateLive) => null | false | (keyof mctree.NodeAll)[];
99
+ post?: (node: mctree.Node, state: ProgramStateLive) => null | false | mctree.Node;
100
+ lookup?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => [string, StateNodeDecl[], ProgramStateStack] | [null, null, null];
101
+ lookupValue?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => [string, StateNodeDecl[], ProgramStateStack] | [null, null, null];
102
+ lookupType?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => [string, StateNodeDecl[], ProgramStateStack] | [null, null, null];
103
+ traverse?: (node: mctree.Node) => void | null | false | mctree.Node;
104
+ inType?: boolean;
93
105
  exposed?: {
94
106
  [key: string]: true;
95
107
  };
@@ -112,6 +124,12 @@ declare global {
112
124
  [key: string]: mctree.Literal;
113
125
  };
114
126
  };
127
+ type Finalized<T, Keys extends keyof T> = T & {
128
+ [key in Keys]-?: NonNullable<T[key]>;
129
+ };
130
+ export type ProgramStateLive = Finalized<ProgramState, "stack" | "lookup" | "lookupValue" | "lookupType" | "traverse" | "index" | "constants" | "removeNodeComments" | "inType">;
131
+ export type ProgramStateAnalysis = Finalized<ProgramStateLive, "allClasses" | "allFunctions">;
132
+ export type ProgramStateOptimizer = Finalized<ProgramStateAnalysis, "localsStack" | "exposed" | "calledFunctions">;
115
133
  type ExcludeAnnotationsMap = {
116
134
  [key: string]: boolean;
117
135
  };
@@ -137,20 +155,17 @@ export declare function buildOptimizedProject(product: string | null, options: B
137
155
  exe: string;
138
156
  args: string[];
139
157
  program: string;
140
- product: string;
141
- hasTests: boolean;
158
+ product: string | null;
159
+ hasTests: boolean | undefined;
142
160
  }>;
143
- /**
144
- *
145
- * @param {BuildConfig} options
146
- * @returns
147
- */
148
161
  export declare function generateOptimizedProject(options: BuildConfig): Promise<{
149
- jungleFiles: string;
162
+ jungleFiles: string | undefined;
150
163
  program: string;
164
+ xml?: undefined;
151
165
  hasTests?: undefined;
152
166
  } | {
153
167
  jungleFiles: string;
168
+ xml: import("./manifest").ManifestXML;
154
169
  program: string;
155
170
  hasTests: boolean;
156
171
  }>;
@@ -166,7 +181,7 @@ declare type RequiredNonNull<T> = {
166
181
  export declare type Analysis = {
167
182
  fnMap: RequiredNonNull<FilesToOptimizeMap>;
168
183
  paths: string[];
169
- state: ProgramState;
184
+ state: ProgramStateAnalysis;
170
185
  };
171
186
  export declare function getProjectAnalysis(targets: Target[], analysis: PreAnalysis | null, options: BuildConfig): Promise<Analysis | PreAnalysis>;
172
187
  /**
@@ -2,13 +2,16 @@ export declare const isWin: boolean;
2
2
  export declare const appSupport: string;
3
3
  export declare const connectiq: string;
4
4
  export declare function getSdkPath(): Promise<string>;
5
- export declare function getDeviceInfo(): Promise<{
5
+ export declare type DeviceInfo = {
6
6
  [key: string]: {
7
7
  appTypes: {
8
8
  memoryLimit: number;
9
9
  type: string;
10
10
  }[];
11
11
  deviceFamily: string;
12
+ displayName: string;
13
+ languages: Record<string, true>;
12
14
  };
13
- }>;
15
+ };
16
+ export declare function getDeviceInfo(): Promise<DeviceInfo>;
14
17
  export declare function getLanguages(): Promise<any>;
@@ -1,6 +1,5 @@
1
- export declare function globa(pattern: string, options?: {
2
- [key: string]: unknown;
3
- }): Promise<Array<string>>;
1
+ import * as glob from "glob";
2
+ export declare function globa(pattern: string, options?: glob.IOptions): Promise<Array<string>>;
4
3
  export declare function last_modified(inputs: string[]): Promise<number>;
5
4
  export declare function first_modified(inputs: string[]): Promise<number>;
6
5
  export declare function pushUnique<T>(arr: T[], value: T): void;
package/build/util.cjs CHANGED
@@ -1303,6 +1303,8 @@ function setopts (self, pattern, options) {
1303
1303
  // Note that they are not supported in Glob itself anyway.
1304
1304
  options.nonegate = true
1305
1305
  options.nocomment = true
1306
+ // always treat \ in patterns as escapes, not path separators
1307
+ options.allowWindowsEscape = false
1306
1308
 
1307
1309
  self.minimatch = new Minimatch(pattern, options)
1308
1310
  self.options = self.minimatch.options
@@ -1778,7 +1780,10 @@ Glob.prototype._process = function (pattern, index, inGlobStar, cb) {
1778
1780
  var read
1779
1781
  if (prefix === null)
1780
1782
  read = '.'
1781
- else if (isAbsolute(prefix) || isAbsolute(pattern.join('/'))) {
1783
+ else if (isAbsolute(prefix) ||
1784
+ isAbsolute(pattern.map(function (p) {
1785
+ return typeof p === 'string' ? p : '[*]'
1786
+ }).join('/'))) {
1782
1787
  if (!prefix || !isAbsolute(prefix))
1783
1788
  prefix = '/' + prefix
1784
1789
  read = prefix
@@ -2278,7 +2283,7 @@ function GlobSync (pattern, options) {
2278
2283
  }
2279
2284
 
2280
2285
  GlobSync.prototype._finish = function () {
2281
- assert(this instanceof GlobSync)
2286
+ assert.ok(this instanceof GlobSync)
2282
2287
  if (this.realpath) {
2283
2288
  var self = this
2284
2289
  this.matches.forEach(function (matchset, index) {
@@ -2302,7 +2307,7 @@ GlobSync.prototype._finish = function () {
2302
2307
 
2303
2308
 
2304
2309
  GlobSync.prototype._process = function (pattern, index, inGlobStar) {
2305
- assert(this instanceof GlobSync)
2310
+ assert.ok(this instanceof GlobSync)
2306
2311
 
2307
2312
  // Get the first [n] parts of pattern that are all strings.
2308
2313
  var n = 0
@@ -2339,7 +2344,10 @@ GlobSync.prototype._process = function (pattern, index, inGlobStar) {
2339
2344
  var read
2340
2345
  if (prefix === null)
2341
2346
  read = '.'
2342
- else if (isAbsolute(prefix) || isAbsolute(pattern.join('/'))) {
2347
+ else if (isAbsolute(prefix) ||
2348
+ isAbsolute(pattern.map(function (p) {
2349
+ return typeof p === 'string' ? p : '[*]'
2350
+ }).join('/'))) {
2343
2351
  if (!prefix || !isAbsolute(prefix))
2344
2352
  prefix = '/' + prefix
2345
2353
  read = prefix
@@ -3940,18 +3948,6 @@ module.exports = require("util");
3940
3948
  /******/ }
3941
3949
  /******/
3942
3950
  /************************************************************************/
3943
- /******/ /* webpack/runtime/compat get default export */
3944
- /******/ (() => {
3945
- /******/ // getDefaultExport function for compatibility with non-harmony modules
3946
- /******/ __webpack_require__.n = (module) => {
3947
- /******/ var getter = module && module.__esModule ?
3948
- /******/ () => (module['default']) :
3949
- /******/ () => (module);
3950
- /******/ __webpack_require__.d(getter, { a: getter });
3951
- /******/ return getter;
3952
- /******/ };
3953
- /******/ })();
3954
- /******/
3955
3951
  /******/ /* webpack/runtime/define property getters */
3956
3952
  /******/ (() => {
3957
3953
  /******/ // define getter functions for harmony exports
@@ -4020,7 +4016,6 @@ var external_fs_ = __webpack_require__(6231);
4020
4016
  const promises_namespaceObject = require("fs/promises");
4021
4017
  // EXTERNAL MODULE: ./node_modules/glob/glob.js
4022
4018
  var glob = __webpack_require__(2884);
4023
- var glob_default = /*#__PURE__*/__webpack_require__.n(glob);
4024
4019
  // EXTERNAL MODULE: external "path"
4025
4020
  var external_path_ = __webpack_require__(1423);
4026
4021
  ;// CONCATENATED MODULE: external "readline"
@@ -4038,7 +4033,7 @@ const external_readline_namespaceObject = require("readline");
4038
4033
  __webpack_require__.g["lastModifiedSource" + ""] = 0;
4039
4034
  function globa(pattern, options) {
4040
4035
  return new Promise((resolve, reject) => {
4041
- glob_default().glob(pattern, options, (er, files) => {
4036
+ glob.glob(pattern, options || {}, (er, files) => {
4042
4037
  if (er) {
4043
4038
  reject(files);
4044
4039
  }
package/package.json CHANGED
@@ -1,13 +1,19 @@
1
1
  {
2
2
  "name": "@markw65/monkeyc-optimizer",
3
3
  "type": "module",
4
- "version": "1.0.12",
4
+ "version": "1.0.15",
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",
8
8
  "exports": {
9
- ".": "./build/optimizer.cjs",
10
- "./*.js": "./build/*.cjs"
9
+ ".": {
10
+ "types": "./build/src/optimizer.d.ts",
11
+ "default": "./build/optimizer.cjs"
12
+ },
13
+ "./*.js": {
14
+ "types": "./build/src/*.d.ts",
15
+ "default": "./build/*.cjs"
16
+ }
11
17
  },
12
18
  "scripts": {
13
19
  "watch": "webpack --mode development --watch",
@@ -27,7 +33,7 @@
27
33
  "author": "markw65",
28
34
  "license": "MIT",
29
35
  "dependencies": {
30
- "@markw65/prettier-plugin-monkeyc": "^1.0.19"
36
+ "@markw65/prettier-plugin-monkeyc": "^1.0.21"
31
37
  },
32
38
  "devDependencies": {
33
39
  "@types/glob": "^7.2.0",