-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Rewrite MinifyLocals from Uglify to Acorn. NFC #13621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Is this part of #12410? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
I only briefly glanced over the actual algorithm, assuming that its its a roughly 1-to-1 with the existing code.
tools/acorn-optimizer.js
Outdated
@@ -1444,9 +1606,11 @@ var registry = { | |||
applyDCEGraphRemovals: applyDCEGraphRemovals, | |||
minifyWhitespace: function() { minifyWhitespace = true }, | |||
noPrint: function() { noPrint = true }, | |||
last: function() {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The python code uses "last" as a marker for knowing that nothing will run next. The acorn code doesn't actually need it, as you can see here, but adding this lets the existing python driver code work unmodified. Basically this makes the new pass implement the exact same API surface as the old pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(A refactoring on the python side could remove it, i'll add a TODO)
tools/acorn-optimizer.js
Outdated
var minifiedNames = []; | ||
var minifiedState = [0]; | ||
|
||
function ensureMinifiedNames(n) { // make sure the nth index in minifiedNames exists. done 100% deterministically |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you put the comment on its own line (before the function I guess?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
It could be perhaps as part of a larger refactoring. But the Acorn code uses Terser for its output, so removing Uglify would not affect our usage of Terser. |
Awesome, thanks for the heads up! |
Basically a simple rewrite from one AST to another, but also using slightly
more modern JS while doing so (
Set
,Map
). Some parts differ though asthe ASTs are not compatible, so the algorithm is not 100% identical, but the
results should be.
Test changes are just minor whitespace, caused by the different whitespace
style that Uglify used to emit vs the new one.
Verified on
wasm2js2, 3, s, z
which we do not run on CI here.After this we have just one remaining pass using Uglify, MinifyGlobals, after
which we can remove it entirely.
cc @walkingeyerobot