@markw65/monkeyc-optimizer 1.0.13 → 1.0.16

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, displayName } = JSON.parse(data.toString());
7219
- return [deviceId, { appTypes, deviceFamily, displayName }];
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);
@@ -0,0 +1,4 @@
1
+ import { mctree } from "@markw65/prettier-plugin-monkeyc";
2
+ export declare function shouldInline(state: ProgramStateAnalysis, func: FunctionStateNode, args: mctree.Node[]): boolean | undefined;
3
+ export declare function inlineFunction(state: ProgramStateAnalysis, func: FunctionStateNode, call: mctree.CallExpression): any;
4
+ export declare function applyTypeIfNeeded(node: mctree.Node): mctree.Node;
@@ -34,67 +34,89 @@ declare global {
34
34
  ignoredAnnotations?: string;
35
35
  ignoredSourcePaths?: string;
36
36
  returnCommand?: boolean;
37
+ checkBuildPragmas?: boolean;
37
38
  _cache?: {
38
39
  barrels?: Record<string, ResolvedJungle>;
39
40
  barrelMap?: Record<string, Record<string, ResolvedJungle>>;
40
41
  };
41
42
  };
42
- type StateNodeDecl = StateNode | mctree.EnumStringMember | mctree.TypedIdentifier | mctree.EnumDeclaration | mctree.TypedefDeclaration | mctree.VariableDeclarator;
43
+ type StateNodeDecl = StateNode | mctree.EnumStringMember | mctree.TypedIdentifier | mctree.EnumDeclaration;
43
44
  type StateNodeDecls = {
44
45
  [key: string]: StateNodeDecl[];
45
46
  };
46
- type ProgramStateNode = {
47
+ interface BaseStateNode {
48
+ type: string;
49
+ node: mctree.Node | null | undefined;
50
+ name: string | null | undefined;
51
+ fullName: string | null | undefined;
52
+ decls?: StateNodeDecls | undefined;
53
+ type_decls?: StateNodeDecls | undefined;
54
+ stack?: ProgramStateStack | undefined;
55
+ }
56
+ interface ProgramStateNode extends BaseStateNode {
47
57
  type: "Program";
48
58
  node: null | undefined;
49
59
  name: "$";
50
60
  fullName: "$";
51
- decls?: StateNodeDecls;
52
- stack?: null | undefined;
53
- };
54
- type ModuleStateNode = {
61
+ stack?: undefined;
62
+ }
63
+ interface ModuleStateNode extends BaseStateNode {
55
64
  type: "ModuleDeclaration";
65
+ node: mctree.ModuleDeclaration;
56
66
  name: string;
57
67
  fullName: string;
58
- node: mctree.ModuleDeclaration;
59
- stack?: ProgramStateStack;
60
- decls?: StateNodeDecls;
61
- };
62
- type ClassStateNode = {
68
+ }
69
+ interface ClassStateNode extends BaseStateNode {
63
70
  type: "ClassDeclaration";
71
+ node: mctree.ClassDeclaration;
64
72
  name: string;
65
73
  fullName: string;
66
- node: mctree.ClassDeclaration;
67
- decls?: StateNodeDecls;
68
- stack?: ProgramStateStack;
69
- superClass: ClassStateNode[] | true;
70
- };
71
- type FunctionStateNode = {
74
+ superClass?: ClassStateNode[] | true;
75
+ }
76
+ interface FunctionStateNode extends BaseStateNode {
72
77
  type: "FunctionDeclaration";
78
+ node: mctree.FunctionDeclaration;
73
79
  name: string;
74
80
  fullName: string;
75
- node: mctree.FunctionDeclaration;
76
81
  stack?: ProgramStateStack;
77
82
  decls?: undefined;
78
- };
79
- type BlockStateNode = {
83
+ }
84
+ interface BlockStateNode extends BaseStateNode {
80
85
  type: "BlockStatement";
81
- name?: null | undefined;
82
- fullName?: null | undefined;
86
+ name: undefined;
87
+ fullName: undefined;
83
88
  node: mctree.BlockStatement;
84
- decls?: StateNodeDecls;
85
- stack?: null | undefined;
86
- };
87
- type StateNode = ProgramStateNode | FunctionStateNode | BlockStateNode | ClassStateNode | ModuleStateNode;
89
+ stack?: undefined;
90
+ }
91
+ interface TypedefStateNode extends BaseStateNode {
92
+ type: "TypedefDeclaration";
93
+ node: mctree.TypedefDeclaration;
94
+ name: string;
95
+ fullName: string;
96
+ }
97
+ interface VariableStateNode extends BaseStateNode {
98
+ type: "VariableDeclarator";
99
+ node: mctree.VariableDeclarator;
100
+ name: string;
101
+ fullName: string;
102
+ stack: ProgramStateStack;
103
+ }
104
+ type StateNode = ProgramStateNode | FunctionStateNode | BlockStateNode | ClassStateNode | ModuleStateNode | TypedefStateNode | VariableStateNode;
88
105
  type ProgramStateStack = StateNode[];
89
106
  export type ProgramState = {
90
107
  allFunctions?: FunctionStateNode[];
91
108
  allClasses?: ClassStateNode[];
109
+ fnMap?: FilesToOptimizeMap;
92
110
  stack?: ProgramStateStack;
93
- shouldExclude?: (node: any) => any;
111
+ removeNodeComments?: (node: mctree.Node, ast: mctree.Program) => void;
112
+ shouldExclude?: (node: mctree.Node) => boolean;
94
113
  pre?: (node: mctree.Node, state: ProgramStateLive) => null | false | (keyof mctree.NodeAll)[];
95
114
  post?: (node: mctree.Node, state: ProgramStateLive) => null | false | mctree.Node;
96
115
  lookup?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => [string, StateNodeDecl[], ProgramStateStack] | [null, null, null];
116
+ lookupValue?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => [string, StateNodeDecl[], ProgramStateStack] | [null, null, null];
117
+ lookupType?: (node: mctree.Node, name?: string | null, stack?: ProgramStateStack) => [string, StateNodeDecl[], ProgramStateStack] | [null, null, null];
97
118
  traverse?: (node: mctree.Node) => void | null | false | mctree.Node;
119
+ inType?: boolean;
98
120
  exposed?: {
99
121
  [key: string]: true;
100
122
  };
@@ -120,8 +142,8 @@ declare global {
120
142
  type Finalized<T, Keys extends keyof T> = T & {
121
143
  [key in Keys]-?: NonNullable<T[key]>;
122
144
  };
123
- export type ProgramStateLive = Finalized<ProgramState, "stack" | "lookup" | "traverse" | "index" | "constants">;
124
- export type ProgramStateAnalysis = Finalized<ProgramStateLive, "allClasses" | "allFunctions">;
145
+ export type ProgramStateLive = Finalized<ProgramState, "stack" | "lookup" | "lookupValue" | "lookupType" | "traverse" | "index" | "constants" | "removeNodeComments" | "inType">;
146
+ export type ProgramStateAnalysis = Finalized<ProgramStateLive, "allClasses" | "allFunctions" | "fnMap">;
125
147
  export type ProgramStateOptimizer = Finalized<ProgramStateAnalysis, "localsStack" | "exposed" | "calledFunctions">;
126
148
  type ExcludeAnnotationsMap = {
127
149
  [key: string]: boolean;
@@ -174,7 +196,7 @@ declare type RequiredNonNull<T> = {
174
196
  export declare type Analysis = {
175
197
  fnMap: RequiredNonNull<FilesToOptimizeMap>;
176
198
  paths: string[];
177
- state: ProgramState;
199
+ state: ProgramStateAnalysis;
178
200
  };
179
201
  export declare function getProjectAnalysis(targets: Target[], analysis: PreAnalysis | null, options: BuildConfig): Promise<Analysis | PreAnalysis>;
180
202
  /**
@@ -2,7 +2,7 @@ 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;
@@ -10,6 +10,8 @@ export declare function getDeviceInfo(): Promise<{
10
10
  }[];
11
11
  deviceFamily: string;
12
12
  displayName: string;
13
+ languages: Record<string, true>;
13
14
  };
14
- }>;
15
+ };
16
+ export declare function getDeviceInfo(): Promise<DeviceInfo>;
15
17
  export declare function getLanguages(): Promise<any>;
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
package/package.json CHANGED
@@ -1,21 +1,28 @@
1
1
  {
2
2
  "name": "@markw65/monkeyc-optimizer",
3
3
  "type": "module",
4
- "version": "1.0.13",
4
+ "version": "1.0.16",
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",
14
20
  "build-debug": "webpack --mode development",
15
21
  "build-release": "webpack --mode production",
16
22
  "prepack": "webpack --mode production",
17
- "test": "npm run test-remote",
18
- "test-remote": "node ./test/test.js --product=pick-one --github"
23
+ "test": "npm run test-inline && npm run test-remote",
24
+ "test-remote": "node ./test/test.js --product=pick-one --github",
25
+ "test-inline": "node test/test.js --run-tests --product=fenix5 --product=fr235 --jungle $(pwd)/test/OptimizerTests/monkey.jungle"
19
26
  },
20
27
  "files": [
21
28
  "build/optimizer.cjs",
@@ -27,7 +34,7 @@
27
34
  "author": "markw65",
28
35
  "license": "MIT",
29
36
  "dependencies": {
30
- "@markw65/prettier-plugin-monkeyc": "^1.0.20"
37
+ "@markw65/prettier-plugin-monkeyc": "^1.0.21"
31
38
  },
32
39
  "devDependencies": {
33
40
  "@types/glob": "^7.2.0",