@markw65/monkeyc-optimizer 1.0.9 → 1.0.10
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 +8 -0
- package/build/api.cjs +26 -26
- package/build/optimizer.cjs +3364 -200
- package/build/sdk-util.cjs +3 -3
- package/build/util.cjs +0 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -92,3 +92,11 @@ More fixes found via open source projects.
|
|
|
92
92
|
- LiteralIntegerRe should be case insensitive
|
|
93
93
|
- Proper fix for promiseAll
|
|
94
94
|
- Auto-include barrels.jungle when its present
|
|
95
|
+
|
|
96
|
+
### 1.0.10
|
|
97
|
+
|
|
98
|
+
- Add --execute option to test.js to run the projects after building them
|
|
99
|
+
- Add support for optimizing barrels
|
|
100
|
+
- Add some typing via jsdoc, and turn on ts validation in vscode
|
|
101
|
+
- Bump to @markw65/prettier-plugin-monkeyc:1.0.16 so ts recognizes its exports
|
|
102
|
+
- Add [garmin/connectiq-apps](https://github.com/garmin/connectiq-apps) and fix some minor issues it revealed
|
package/build/api.cjs
CHANGED
|
@@ -112,12 +112,8 @@ function collectClassInfo(state) {
|
|
|
112
112
|
});
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
async function analyze(
|
|
116
|
-
|
|
117
|
-
buildConfig && buildConfig.excludeAnnotations
|
|
118
|
-
? Object.fromEntries(buildConfig.excludeAnnotations.map((a) => [a, true]))
|
|
119
|
-
: {};
|
|
120
|
-
|
|
115
|
+
async function analyze(fnMap) {
|
|
116
|
+
let excludeAnnotations;
|
|
121
117
|
const allImports = [];
|
|
122
118
|
const state = {
|
|
123
119
|
allFunctions: [],
|
|
@@ -125,11 +121,11 @@ async function analyze(fileNames, buildConfig) {
|
|
|
125
121
|
shouldExclude(node) {
|
|
126
122
|
if (node.attrs && node.attrs.attrs) {
|
|
127
123
|
if (
|
|
128
|
-
node.attrs.attrs.
|
|
124
|
+
node.attrs.attrs.some((attr) => {
|
|
129
125
|
if (attr.type != "UnaryExpression") return false;
|
|
130
126
|
if (attr.argument.type != "Identifier") return false;
|
|
131
127
|
return hasProperty(excludeAnnotations, attr.argument.name);
|
|
132
|
-
})
|
|
128
|
+
})
|
|
133
129
|
) {
|
|
134
130
|
return true;
|
|
135
131
|
}
|
|
@@ -172,25 +168,29 @@ async function analyze(fileNames, buildConfig) {
|
|
|
172
168
|
};
|
|
173
169
|
markApi(state.stack[0]);
|
|
174
170
|
|
|
171
|
+
const getAst = (source, monkeyCSource, exclude) => {
|
|
172
|
+
excludeAnnotations = exclude;
|
|
173
|
+
const ast = MonkeyC.parsers.monkeyc.parse(monkeyCSource, {
|
|
174
|
+
grammarSource: source,
|
|
175
|
+
});
|
|
176
|
+
ast.source = source;
|
|
177
|
+
ast.monkeyCSource = monkeyCSource;
|
|
178
|
+
collectNamespaces(ast, state);
|
|
179
|
+
return ast;
|
|
180
|
+
};
|
|
175
181
|
const files = await Promise.all(
|
|
176
|
-
|
|
177
|
-
name
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
+
Object.entries(fnMap).map(([name, { excludeAnnotations }]) =>
|
|
183
|
+
fs.readFile(name).then((data) => ({
|
|
184
|
+
name,
|
|
185
|
+
ast: getAst(
|
|
186
|
+
name,
|
|
187
|
+
data.toString().replace(/\r\n/g, "\n"),
|
|
188
|
+
excludeAnnotations
|
|
189
|
+
),
|
|
190
|
+
}))
|
|
191
|
+
)
|
|
182
192
|
);
|
|
183
193
|
|
|
184
|
-
files.forEach((f) => {
|
|
185
|
-
f.ast = MonkeyC.parsers.monkeyc.parse(f.monkeyCSource, {
|
|
186
|
-
grammarSource: f.name,
|
|
187
|
-
});
|
|
188
|
-
f.ast.source = f.name;
|
|
189
|
-
f.ast.monkeyCSource = f.monkeyCSource;
|
|
190
|
-
delete f.monkeyCSource;
|
|
191
|
-
collectNamespaces(f.ast, state);
|
|
192
|
-
});
|
|
193
|
-
|
|
194
194
|
delete state.shouldExclude;
|
|
195
195
|
delete state.post;
|
|
196
196
|
|
|
@@ -411,8 +411,8 @@ function evaluateFunction(func, args) {
|
|
|
411
411
|
}
|
|
412
412
|
}
|
|
413
413
|
|
|
414
|
-
async function optimizeMonkeyC(
|
|
415
|
-
const { files, state } = await analyze(
|
|
414
|
+
async function optimizeMonkeyC(fnMap) {
|
|
415
|
+
const { files, state } = await analyze(fnMap);
|
|
416
416
|
const replace = (node, obj) => {
|
|
417
417
|
for (const k of Object.keys(node)) {
|
|
418
418
|
delete node[k];
|