Skip to content

Commit

Permalink
fix(es/minifier): Don't create top level variables (#2985)
Browse files Browse the repository at this point in the history
swc_ecma_minifier:
 - Add `module` to `TerserCompressorOptions`.
 - Don't create top level variables while inlining if `module` is false.
 - Drop more unused parameters.
  • Loading branch information
kdy1 authored Dec 7, 2021
1 parent 20179a6 commit 4a7937d
Show file tree
Hide file tree
Showing 18 changed files with 116 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var _class, _class1, C = function() {
"use strict";
_classCallCheck(this, C);
};
!function(param) {
!function() {
(void 0)[((_class = (function(C) {
"use strict";
_inherits(_class, C);
Expand All @@ -59,7 +59,7 @@ var _class, _class1, C = function() {
}
return _class;
})(C)).x = 1, _class).x];
}(), (function(param) {
}(), (function() {
(void 0)[((_class1 = (function(C) {
"use strict";
_inherits(_class, C);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var _class, _class1, C = function() {
"use strict";
_classCallCheck(this, C);
};
!function(param) {
!function() {
(void 0)[((_class = (function(C) {
"use strict";
_inherits(_class, C);
Expand All @@ -59,7 +59,7 @@ var _class, _class1, C = function() {
}
return _class;
})(C)).x = 1, _class).x];
}(), (function(param) {
}(), (function() {
(void 0)[((_class1 = (function(C) {
"use strict";
_inherits(_class, C);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var ref, ref1, a = function() {
};
(void 0)[null === (ref = a()) || void 0 === ref ? void 0 : ref.d], (function(param) {
(void 0)[null === (ref = a()) || void 0 === ref ? void 0 : ref.d], (function() {
(void 0)[null === (ref1 = a()) || void 0 === ref1 ? void 0 : ref1.d], arguments.length > 1 && void 0 !== arguments[1] && arguments[1];
})();
4 changes: 2 additions & 2 deletions crates/swc/tests/tsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ fn matrix() -> Vec<(String, Options)> {
target: Some(target),
minify: if minify {
Some(from_json(
"{ \"compress\": { \"toplevel\": true }, \"mangle\": false, \
\"toplevel\": true }",
"{ \"compress\": { \"toplevel\": true, \"module\": true }, \
\"mangle\": false, \"toplevel\": true }",
))
} else {
None
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

1 comment on commit 4a7937d

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 4a7937d Previous: 20179a6 Ratio
full_es2015 178802365 ns/iter (± 23829187) 199088704 ns/iter (± 9180703) 0.90
full_es2016 130265879 ns/iter (± 5906385) 160859778 ns/iter (± 9304873) 0.81
full_es2017 134607173 ns/iter (± 6333929) 163965339 ns/iter (± 9148249) 0.82
full_es2018 133966569 ns/iter (± 18862215) 161658185 ns/iter (± 7509668) 0.83
full_es2019 144900840 ns/iter (± 15480644) 160893500 ns/iter (± 6929672) 0.90
full_es2020 132830156 ns/iter (± 5530700) 158717903 ns/iter (± 7813790) 0.84
full_es3 187275288 ns/iter (± 368016048) 224986255 ns/iter (± 18253156) 0.83
full_es5 174605896 ns/iter (± 20435477) 209176289 ns/iter (± 11881676) 0.83
parser 615596 ns/iter (± 26625) 744947 ns/iter (± 66199) 0.83

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.