-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use ESTree-based optimizer for core JS passes, to support ES6+ inputs (…
…#7973) Fixes #6000 The key change here is to rewrite the JS optimizer passes that run in a normal `-O3` etc. build from the Uglify1 AST to ESTree. With ESTree we can use modern parsers etc. so that we support ES6+ inputs to js libraries, pre-jses, EM_ASM, etc. Aside from that rewrite, the other changes are less critical and can be altered later. Specifically, this uses acorn for parsing and terser for outputting, but we could switch to anything using ESTree very easily. Acorn is nice for parsing since it's small and standalone. For outputting I experimented with astring, which is small and nice, and escodegen, which looks very robust, but neither could output compact-enough JS to not regress our JS code sizes. This is not truly critical since for minimal code size people should use closure anyhow, however, it's nice for default builds to be small (and we don't run closure by default), and I didn't want to regress anything. Using the terser outputter achieves that. (Since it uses the Uglify2 AST internally, this means using their tool to convert ESTree to Uglify2.) They may be some minor code size changes with this PR, just because we use a different outputter now, but nothing major in either direction. Most changes seem positive actually. Sizes after closure are unchanged. This uses almost unmodified versions of acorn and terser, but they are stripped down to what we need, and I had to make two modifications, see these PRs: [acornjs/acorn#793](acornjs/acorn#793) (quote the error on parse exceptions) and [mishoo/UglifyJS#3323](mishoo/UglifyJS#3323) (preserve quoted properties). This may very slightly regress compile times when using those passes, as Uglify1 was just very fast. However, the change should be very small. This does _not_ rewrite every single JS optimizer pass. In particular the asm.js passes don't need to support ES6, and so don't need to be rewritten. There are also optional passes that do not run by default, that we can convert later depending on priority.
- Loading branch information
Showing
25 changed files
with
17,441 additions
and
601 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
for (var i in x) {} | ||
|
||
for (var j = 0; ;) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
for (var i in x) {} | ||
for (var j = 0;;) {} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
function hasOwnProperty(obj, prop) { | ||
return Object.prototype.hasOwnProperty.call(obj, prop); | ||
} | ||
|
||
if (hasOwnProperty({}, "prop_name")) { | ||
console.log("yeah"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,40 @@ | ||
var name; | ||
|
||
var asmLibraryArg = { | ||
"save1": 1, | ||
"save2": 2 | ||
}; | ||
|
||
var expD1 = Module["expD1"] = asm["expD1"]; | ||
|
||
var expD2 = Module["expD2"] = asm["expD2"]; | ||
|
||
var expD3 = Module["expD3"] = asm["expD3"]; | ||
var expD4 = undefined; | ||
var expI1 = Module["expI1"] = (function() { | ||
|
||
var expD4; | ||
|
||
var expI1 = Module["expI1"] = function() { | ||
return Module["asm"]["expI1"].apply(null, arguments); | ||
}); | ||
var expI2 = Module["expI2"] = (function() { | ||
}; | ||
|
||
var expI2 = Module["expI2"] = function() { | ||
return Module["asm"]["expI2"].apply(null, arguments); | ||
}); | ||
var expI3 = Module["expI3"] = (function() { | ||
}; | ||
|
||
var expI3 = Module["expI3"] = function() { | ||
return Module["asm"]["expI3"].apply(null, arguments); | ||
}); | ||
var expI4 = undefined; | ||
}; | ||
|
||
var expI4; | ||
|
||
expD1; | ||
|
||
Module["expD2"]; | ||
|
||
asm["expD3"]; | ||
|
||
expI1; | ||
|
||
Module["expI2"]; | ||
asm["expI3"]; | ||
|
||
asm["expI3"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.