-
• #2
redeclaring a variable existing in an outside scope sure seems fishy.
Yes... The problem I have is esprima seems more or less unmaintained now - and it's hard to find a decent minifier that can be bundled up and run in the browser and node.js.
Someone attempted using rollup at one point. but as I remember it was huge and ended up being a bit of a mess to use.
Does the minifier actually know that Bangle.load can call g.whatever()?
Oh, I misunderstood.
That shouldn't actually be a problem. Or was it generating a new global variable of that name?
If you do:
function boom() { g.reset(); } function hello() { var g = "blah"; boom(); }
or:
function boom() { g.reset(); } { let g = "blah"; boom(); }
Then there should be no problem - the function that uses
g
will only do it from the global scope, not the local one -
• #3
Regarding another minifier than esprima, have you tried uglifyjs? It is build for Node.js and there are projects using it wrapped for a browser like https://github.com/Skalman/UglifyJS-online. I know close to nothing about the whole NPM/Node world, it's just what I had seen used for minification sometime before.
As for the minification problem in iconlaunch, I currently can not reproduce that because of changes I have done to iconlaunch since then. Probably because the problematic code now just uses other variable names after minification. I will have an eye on that and try to build a minimum sample if I see it happening again.
-
• #4
I can't remember exactly... but it looks from the commit history like we never put uglifyjs in publicly - so may it's an option...
-
• #5
Just a note on another minifier problem:
Classes defined in the script seem to be removed by the minifier. Wrapping the script in a scope apparently works around this. At least it does for2047pp
. https://github.com/espruino/BangleApps/pull/2500
Continuation of: original post
I tried this and got 5-10% faster time to first complete draw by pretokenization alone. Additionally using minification got about 5% on top of that. So pretty worthwhile I think.
That could well be. I could not find similar problem descriptions, but redeclaring a variable existing in an outside scope sure seems fishy.
Edit: I have tried running the closure compiler on the same code and it creates
for (var n of a.getPoints())
insteadI don't know. Does the minifier actually know that
Bangle.load
can callg.whatever()
? This is probably a quite seldom problem, since you need to have code using enough variables that the minifier gets to "g" as a variable name. Maybe it would be enough to prohibit the minifier from using "g" as a name?