Skip to content

Commit

Permalink
feat(es/minifier): Drop new token if possible (#4932)
Browse files Browse the repository at this point in the history
  • Loading branch information
magic-akari committed Jun 11, 2022
1 parent 565f06f commit 5940894
Show file tree
Hide file tree
Showing 106 changed files with 1,024 additions and 951 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ for (const i of [
1,
2,
3
])if (2 === i) throw new Error('ERR');
])if (2 === i) throw Error('ERR');
console.log(i);
} catch (err) {
console.log('E %s %s', i, err);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ try {
1,
2,
3
][Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = !0)if (_step1.value, 2 === i) throw new Error("ERR");
][Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = !0)if (_step1.value, 2 === i) throw Error("ERR");
} catch (err) {
_didIteratorError1 = !0, _iteratorError1 = err;
} finally{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var A;
!function(A1) {
var beez;
A1.beez2 = new Array(), A1.beez = beez;
A1.beez2 = Array(), A1.beez = beez;
}(A || (A = {}));
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import _class_call_check from "@swc/helpers/lib/_class_call_check.js";
"use strict";
_class_call_check(this, B);
};
A1.beez2 = new Array(), A1.beez = beez;
A1.beez2 = Array(), A1.beez = beez;
}(A || (A = {}));
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Wagon.circle = function(wagons) {
};
var db = new class extends Wagon {
load(files, format) {
if ("xmlolololol" === format) throw new Error("please do not use XML. It was a joke.");
if ("xmlolololol" === format) throw Error("please do not use XML. It was a joke.");
super.speed(), super.weight();
}
constructor(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var Sql = function(Wagon1) {
return _class_call_check(this, Sql), (_this = _super.call(this)).foonly = 12, _this;
}
return Sql.prototype.load = function(files, format) {
if ("xmlolololol" === format) throw new Error("please do not use XML. It was a joke.");
if ("xmlolololol" === format) throw Error("please do not use XML. It was a joke.");
_get(_get_prototype_of(Sql.prototype), "speed", this).call(this), _get(_get_prototype_of(Sql.prototype), "weight", this).call(this);
}, Sql;
}(Wagon), db = new Sql();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import _async_to_generator from "@swc/helpers/lib/_async_to_generator.js";
let maybeNumber;
maybeNumber = 1, ++maybeNumber, maybeNumber++;
let test;
if (!test) throw new Error('Test is not defined');
if (!test) throw Error('Test is not defined');
test.slice(1);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var maybeNumber, test;
import _async_to_generator from "@swc/helpers/lib/_async_to_generator.js";
import regeneratorRuntime from "regenerator-runtime";
if (maybeNumber = 1, ++maybeNumber, maybeNumber++, !test) throw new Error("Test is not defined");
if (maybeNumber = 1, ++maybeNumber, maybeNumber++, !test) throw Error("Test is not defined");
test.slice(1);
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ function f15(x) {
f15({
value: 10
}), f15({
error: new Error("boom")
error: Error("boom")
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ function f15(x) {
f15({
value: 10
}), f15({
error: new Error("boom")
error: Error("boom")
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function assertNever(x, msg) {
throw new Error("Unexpected " + msg);
throw Error("Unexpected " + msg);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function assertNever(x, msg) {
throw new Error("Unexpected " + msg);
throw Error("Unexpected " + msg);
}

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.

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
!function(x) {
return x;
}(()=>{}, 1), new Function();
}(()=>{}, 1), Function();
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ var C = function() {
"use strict";
_class_call_check(this, C2);
};
new Function();
Function();
Original file line number Diff line number Diff line change
@@ -1 +1 @@
new Function();
Function();
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var C = function() {
"use strict";
_class_call_check(this, C);
};
new Function();
Function();
var C2 = function() {
"use strict";
_class_call_check(this, C2);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export function Vec(len) {
this.storage = new Array(len);
this.storage = Array(len);
}
Vec.prototype = {
dot (other) {
if (other.storage.length !== this.storage.length) throw new Error("Dot product only applicable for vectors of equal length");
if (other.storage.length !== this.storage.length) throw Error("Dot product only applicable for vectors of equal length");
let sum = 0;
for(let i = 0; i < this.storage.length; i++)sum += this.storage[i] * other.storage[i];
return sum;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import _instanceof from "@swc/helpers/lib/_instanceof.js";
export function Vec(len) {
this.storage = new Array(len);
this.storage = Array(len);
}
Vec.prototype = {
dot: function(other) {
if (other.storage.length !== this.storage.length) throw new Error("Dot product only applicable for vectors of equal length");
if (other.storage.length !== this.storage.length) throw Error("Dot product only applicable for vectors of equal length");
for(var sum = 0, i = 0; i < this.storage.length; i++)sum += this.storage[i] * other.storage[i];
return sum;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var Test = function() {
}
var _proto = Test.prototype;
return _proto.fail = function(message) {
throw new Error(message);
throw Error(message);
}, _proto.f1 = function(x) {
void 0 === x && this.fail("undefined argument"), x.length;
}, _proto.f2 = function(x) {
Expand Down Expand Up @@ -53,7 +53,7 @@ var MyThrowable = function() {
_class_call_check(this, MyThrowable);
}
return MyThrowable.prototype.throw = function() {
throw new Error();
throw Error();
}, MyThrowable;
}(), SuperThrowable = function(MyThrowable) {
"use strict";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function error(message) {
throw new Error(message);
throw Error(message);
}
(function(cb) {
cb();
Expand All @@ -8,7 +8,7 @@ function error(message) {
}(()=>error("Something failed")), function(cb) {
cb();
}(()=>{
throw new Error();
throw Error();
}), function(cb) {
cb();
}(()=>error("Error callback"));
8 changes: 4 additions & 4 deletions crates/swc/tests/tsc-references/neverType_es5.2.minified.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import _class_call_check from "@swc/helpers/lib/_class_call_check.js";
function error(message) {
throw new Error(message);
throw Error(message);
}
var C = function() {
"use strict";
Expand All @@ -9,11 +9,11 @@ var C = function() {
}
var _proto = C.prototype;
return _proto.void1 = function() {
throw new Error();
throw Error();
}, _proto.void2 = function() {
for(;;);
}, _proto.never1 = function() {
throw new Error();
throw Error();
}, _proto.never2 = function() {
for(;;);
}, C;
Expand All @@ -29,7 +29,7 @@ var C = function() {
}), function(cb) {
cb();
}(function() {
throw new Error();
throw Error();
}), function(cb) {
cb();
}(function() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
runTestCase(function() {
var a = new Array(!1, void 0, null, "0", {
var a = Array(!1, void 0, null, "0", {
toString: function() {
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
runTestCase(function() {
var a = new Array(!1, void 0, null, "0", {
var a = Array(!1, void 0, null, "0", {
toString: function() {
return 0;
}
Expand Down
Empty file.
Empty file.

1 comment on commit 5940894

@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: 5940894 Previous: b041f29 Ratio
es/full/minify/libraries/antd 1676662222 ns/iter (± 60331285) 1801856233 ns/iter (± 67535184) 0.93
es/full/minify/libraries/d3 414726747 ns/iter (± 12893612) 449663924 ns/iter (± 3775355) 0.92
es/full/minify/libraries/echarts 2094202284 ns/iter (± 21275825) 2319792247 ns/iter (± 44284565) 0.90
es/full/minify/libraries/jquery 89699402 ns/iter (± 655131) 98193511 ns/iter (± 2413158) 0.91
es/full/minify/libraries/lodash 127431103 ns/iter (± 1441904) 135908126 ns/iter (± 1407229) 0.94
es/full/minify/libraries/moment 52566742 ns/iter (± 190958) 57053307 ns/iter (± 1174923) 0.92
es/full/minify/libraries/react 17291269 ns/iter (± 70553) 18215146 ns/iter (± 358057) 0.95
es/full/minify/libraries/terser 428031610 ns/iter (± 8306546) 504202583 ns/iter (± 8284465) 0.85
es/full/minify/libraries/three 521521700 ns/iter (± 13682508) 624186581 ns/iter (± 23548179) 0.84
es/full/minify/libraries/typescript 3924215095 ns/iter (± 13891072) 4262301967 ns/iter (± 25221516) 0.92
es/full/minify/libraries/victory 693154806 ns/iter (± 22106244) 762201324 ns/iter (± 15040280) 0.91
es/full/minify/libraries/vue 140171552 ns/iter (± 2706907) 148445357 ns/iter (± 1762410) 0.94
es/full/codegen/es3 34501 ns/iter (± 281) 36204 ns/iter (± 1580) 0.95
es/full/codegen/es5 34428 ns/iter (± 177) 35508 ns/iter (± 1234) 0.97
es/full/codegen/es2015 34495 ns/iter (± 173) 34715 ns/iter (± 1428) 0.99
es/full/codegen/es2016 34511 ns/iter (± 174) 34082 ns/iter (± 1371) 1.01
es/full/codegen/es2017 34502 ns/iter (± 171) 34651 ns/iter (± 1586) 1.00
es/full/codegen/es2018 34467 ns/iter (± 209) 35408 ns/iter (± 1679) 0.97
es/full/codegen/es2019 34484 ns/iter (± 150) 34974 ns/iter (± 1303) 0.99
es/full/codegen/es2020 34442 ns/iter (± 159) 34432 ns/iter (± 1374) 1.00
es/full/all/es3 192990777 ns/iter (± 1032950) 208220769 ns/iter (± 3963579) 0.93
es/full/all/es5 181635090 ns/iter (± 937729) 197687643 ns/iter (± 4165791) 0.92
es/full/all/es2015 145088478 ns/iter (± 922859) 158034904 ns/iter (± 3878207) 0.92
es/full/all/es2016 143935174 ns/iter (± 1148431) 156554170 ns/iter (± 3243915) 0.92
es/full/all/es2017 143742248 ns/iter (± 960747) 153853669 ns/iter (± 3870914) 0.93
es/full/all/es2018 141956883 ns/iter (± 1036337) 152434401 ns/iter (± 4092637) 0.93
es/full/all/es2019 140383230 ns/iter (± 819181) 151666129 ns/iter (± 3539084) 0.93
es/full/all/es2020 136467606 ns/iter (± 1111032) 146675726 ns/iter (± 3248459) 0.93
es/full/parser 583926 ns/iter (± 54544) 607017 ns/iter (± 55977) 0.96
es/full/base/fixer 27914 ns/iter (± 185) 29157 ns/iter (± 1279) 0.96
es/full/base/resolver_and_hygiene 140415 ns/iter (± 1650) 143821 ns/iter (± 7008) 0.98
serialization of ast node 181 ns/iter (± 1) 185 ns/iter (± 6) 0.98
serialization of serde 181 ns/iter (± 0) 192 ns/iter (± 7) 0.94

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

Please sign in to comment.