-
-
Notifications
You must be signed in to change notification settings - Fork 288
Description
Creating this issue so someone with more closure compiler experience might be able to help. Or gather information we have.
The issue is to keep devices code readable and maintainable, registers and constant values should not go directly into the code, but kept in separate objects like var C = { ... }
. Looks like previously Closure Compiler inlined these constant, but now it doesn't. And if you define long & readable constant names, that can use up quite some variables.
Might worth investigating, and possibly pulling in a specific version, if we can find one that does more aggressive inlining.
Advanced mode I think is pretty much out of question for modules, because it removes and renames too much. Did some fiddling with annotations and advanced optimizations, but no luck. Might work for final application, but didn't try that.
Example
An example using the BME280 as base. The constant is inlined. One thing I noticed is if I add another const, and use it in the constructor, C
is no longer inlined. Even if you explicitly tell the compiler it's const
.
/** @const */
const C = {/** @const */BME280_ADDRESS: 0x76, /** @const */BLA: 123}
...
// in ctor:
const t_sb = 5+C.BLA; //The funny thing is, you can calculate this value at "compile time"
// minified (˙C` is renamed to `g`):
a=5+g.BLA<<5|0;
But if I use the same constant in the exports.connect function it's inlined. Even without explicitly telling the compiler that it's a constant:
var C = {BME280_ADDRESS: 0x76, BLA: 123}
...
// in exports.connect
i2c.writeTo(addr, reg+C.BLA);
// minified (123 is inlined):
a.writeTo(b,c+123)
No idea why does it work this way..