Skip to content

Commit

Permalink
fix(es/minifier): Don't inline a callable expression if it's used as …
Browse files Browse the repository at this point in the history
…a reference (#5118)
  • Loading branch information
kdy1 committed Jul 6, 2022
1 parent 9f64f5d commit 0e4a03c
Show file tree
Hide file tree
Showing 70 changed files with 90,321 additions and 2,147 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var a;
var a, b = function() {};
module.exports = ((a = function() {
"use strict";
function a() {}
return a.prototype.it = function() {
this.bb = new a.MyA();
}, a;
}()).MyA = function() {}, a);
}()).MyA = b, a);
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ var clodule = function() {
}
return clodule.fn = function(id) {}, clodule;
}();
(clodule || (clodule = {})).fn = function(x, y) {
return x;
};
!function(clodule) {
var fn = function(x, y) {
return x;
};
clodule.fn = fn;
}(clodule || (clodule = {}));
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ var clodule = function() {
}
return clodule.fn = function(id) {}, clodule;
}();
(clodule || (clodule = {})).fn = function(x, y) {
return x;
};
!function(clodule) {
var fn = function(x, y) {
return x;
};
clodule.fn = fn;
}(clodule || (clodule = {}));
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ var A, Point = function() {
};
}, Point;
}();
(Point || (Point = {})).Origin = function() {
return null;
}, function(A) {
!function(Point) {
var Origin = function() {
return null;
};
Point.Origin = Origin;
}(Point || (Point = {})), function(A) {
var Point = function() {
"use strict";
function Point(x, y) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
var A;
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
!function(A) {
var Point = function() {
var fromOrigin = function(p) {
return new Line({
x: 0,
y: 0
}, p);
}, Point = function() {
"use strict";
_class_call_check(this, Point);
};
A.Point = Point;
var Line = function(start, end) {
var Line = function Line(start, end) {
"use strict";
_class_call_check(this, Line), this.start = start, this.end = end;
};
A.Line = Line, A.fromOrigin = function(p) {
return new Line({
x: 0,
y: 0
}, p);
};
A.Line = Line, A.fromOrigin = fromOrigin;
}(A || (A = {}));
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
var A;
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
!function(A) {
var Point = function() {
"use strict";
_class_call_check(this, Point);
}, Line = function(start, end) {
"use strict";
_class_call_check(this, Line), this.start = start, this.end = end;
};
A.Line = Line, A.fromOrigin = function(p) {
var fromOrigin = function(p) {
return new Line({
x: 0,
y: 0
}, p);
}, Point = function() {
"use strict";
_class_call_check(this, Point);
}, Line = function Line(start, end) {
"use strict";
_class_call_check(this, Line), this.start = start, this.end = end;
};
A.Line = Line, A.fromOrigin = fromOrigin;
}(A || (A = {}));
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
var A;
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
!function(A) {
var Point = function() {
var fromOrigin = function(p) {
return new Line({
x: 0,
y: 0
}, p);
}, Point = function() {
"use strict";
_class_call_check(this, Point);
};
A.Point = Point;
var Line = function(start, end) {
var Line = function Line(start, end) {
"use strict";
_class_call_check(this, Line), this.start = start, this.end = end;
};
A.fromOrigin = function(p) {
return new Line({
x: 0,
y: 0
}, p);
};
A.fromOrigin = fromOrigin;
}(A || (A = {}));
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
var A, B;
(A || (A = {})).Point = function() {
return {
x: 0,
y: 0
!function(A) {
var Point = function() {
return {
x: 0,
y: 0
};
};
}, function(A) {
A.Point = Point;
}(A || (A = {})), function(A) {
(A.Point || (A.Point = {})).Origin = {
x: 0,
y: 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
var A, B;
(A || (A = {})).Point = function() {
return {
x: 0,
y: 0
!function(A) {
var Point = function() {
return {
x: 0,
y: 0
};
};
}, function(B) {
A.Point = Point;
}(A || (A = {})), function(B) {
(B.Point || (B.Point = {})).Origin = {
x: 0,
y: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ var A, B;
x: 0,
y: 0
};
}(A || (A = {})), (A || (A = {})).Point = function() {
return {
x: 0,
y: 0
}(A || (A = {})), function(A) {
var Point = function() {
return {
x: 0,
y: 0
};
};
}, function(B) {
A.Point = Point;
}(A || (A = {})), function(B) {
var Point = function() {
return {
x: 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
var A;
!function(A) {
A.fn = function(s) {
var fn = function(s) {
return !0;
}, A.fng = function(s) {
}, fng = function(s) {
return null;
};
A.fn = fn, A.fng = fng;
}(A || (A = {})), A.fn, A.fng, A.fn2, A.fng2;
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
var donkey = function(ast) {
return ast;
};
function funky(declaration) {
return !1;
}
module.exports = function(ast) {
return ast;
}, module.exports.funky = funky;
module.exports = donkey, module.exports.funky = funky;
var funky = require("./commonJSAliasedExport").funky;
funky(1);
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ var M, C = function() {
_class_call_check(this, D);
};
!function(M) {
var A = function() {
var F2 = function(x) {
return x.toString();
}, A = function() {
"use strict";
_class_call_check(this, A);
};
M.A = A, M.F2 = function(x) {
return x.toString();
};
M.A = A, M.F2 = F2;
}(M || (M = {})), new C(), new C(), new D(), new C(), new M.A();
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ var M, N, C = function() {
_class_call_check(this, D);
};
!function(M) {
var A = function() {
var _$F2 = function(x) {
return x.toString();
}, A = function() {
"use strict";
_class_call_check(this, A);
};
M.A = A, M.F2 = function(x) {
return x.toString();
};
M.A = A, M.F2 = _$F2;
}(M || (M = {})), function(N) {
var A = function() {
var _$F2 = function(x) {
return x.toString();
}, A = function() {
"use strict";
_class_call_check(this, A);
};
N.A = A, N.F2 = function(x) {
return x.toString();
};
N.A = A, N.F2 = _$F2;
}(N || (N = {})), new D(), new D(), new C(), new C(), new N.A();
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ var M, C = function() {
_class_call_check(this, D);
};
!function(M) {
var A = function() {
var F2 = function(x) {
return x.toString();
}, A = function() {
"use strict";
_class_call_check(this, A);
};
M.A = A, M.F2 = function(x) {
return x.toString();
};
M.A = A, M.F2 = F2;
}(M || (M = {})), new C(), new C(), new D(), new M.A(), M.F2;
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
!function(Foo) {
Foo.a = function() {
var a = function() {
return 5;
}, Foo.b = !0;
};
Foo.a = a, Foo.b = !0;
}(Foo || (Foo = {})), function(Foo) {
Foo.c = function(a) {
var c = function(a) {
return a;
}, (Foo.Test || (Foo.Test = {})).answer = 42;
};
Foo.c = c, (Foo.Test || (Foo.Test = {})).answer = 42;
}(Foo || (Foo = {}));
var Foo, foo = require("./foo_0");
foo.a(), foo.b && (foo.Test.answer = foo.c(42)), module.exports = Foo;
Expand Down
14 changes: 9 additions & 5 deletions crates/swc/tests/tsc-references/exportCodeGen_es5.2.minified.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
var A, B, C, D, E, F;
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
(A || (A = {})).x = 12, B || (B = {}), C || (C = {}), (D || (D = {})).yes = function() {
return !0;
}, function(E) {
(Color = E.Color || (E.Color = {}))[Color.Red = 0] = "Red", E.fn = function() {};
var Color, C = function() {
(A || (A = {})).x = 12, B || (B = {}), C || (C = {}), function(D) {
var yes = function() {
return !0;
};
D.yes = yes;
}(D || (D = {})), function(E) {
var Color, fn = function() {};
(Color = E.Color || (E.Color = {}))[Color.Red = 0] = "Red", E.fn = fn;
var C = function() {
"use strict";
_class_call_check(this, C);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ var M, C = function() {
_class_call_check(this, D);
};
for(!function(M) {
var A = function() {
var F2 = function(x) {
return x.toString();
}, A = function() {
"use strict";
_class_call_check(this, A);
};
M.A = A, M.F2 = function(x) {
return x.toString();
};
M.A = A, M.F2 = F2;
}(M || (M = {}));;);
for(;;);
for(;;);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ var M, C = function() {
_class_call_check(this, D);
};
for(!function(M) {
var A = function() {
var F2 = function(x) {
return x.toString();
}, A = function() {
"use strict";
_class_call_check(this, A);
};
M.A = A, M.F2 = function(x) {
return x.toString();
};
M.A = A, M.F2 = F2;
}(M || (M = {}));;);
for(;;);
for(;;);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ var M, N, C = function() {
_class_call_check(this, D);
};
for(!function(M) {
var A = function() {
var F2 = function(x) {
return x.toString();
}, A = function() {
"use strict";
_class_call_check(this, A);
};
M.A = A, M.F2 = function(x) {
return x.toString();
};
M.A = A, M.F2 = F2;
}(M || (M = {})), function(N) {
var A = function() {
var F2 = function(x) {
return x.toString();
}, A = function() {
"use strict";
_class_call_check(this, A);
};
N.A = A, N.F2 = function(x) {
return x.toString();
};
N.A = A, N.F2 = F2;
}(N || (N = {}));;);
for(;;);
for(;;);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
var C, D, E;
C || (C = {}), D || (D = {}), (E || (E = {})).xDist = function(x) {
return 0 - x.x;
};
C || (C = {}), D || (D = {}), function(E) {
var xDist = function(x) {
return 0 - x.x;
};
E.xDist = xDist;
}(E || (E = {}));

1 comment on commit 0e4a03c

@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: 0e4a03c Previous: f952a61 Ratio
es/full/minify/libraries/antd 1772791159 ns/iter (± 78467817) 1786169866 ns/iter (± 114204135) 0.99
es/full/minify/libraries/d3 466364990 ns/iter (± 51301912) 446747396 ns/iter (± 37105310) 1.04
es/full/minify/libraries/echarts 1816227662 ns/iter (± 217842083) 1771580421 ns/iter (± 154631986) 1.03
es/full/minify/libraries/jquery 129542528 ns/iter (± 47596669) 109026497 ns/iter (± 12684919) 1.19
es/full/minify/libraries/lodash 160789279 ns/iter (± 7215569) 144098234 ns/iter (± 24390314) 1.12
es/full/minify/libraries/moment 69011659 ns/iter (± 3230079) 63348313 ns/iter (± 2143507) 1.09
es/full/minify/libraries/react 20433374 ns/iter (± 2123365) 20510033 ns/iter (± 4704088) 1.00
es/full/minify/libraries/terser 646052205 ns/iter (± 11160829) 649541915 ns/iter (± 43724176) 0.99
es/full/minify/libraries/three 596606779 ns/iter (± 87425911) 612941308 ns/iter (± 98882614) 0.97
es/full/minify/libraries/typescript 3783381764 ns/iter (± 377411365) 3806066704 ns/iter (± 253310375) 0.99
es/full/minify/libraries/victory 765078488 ns/iter (± 46436322) 782409336 ns/iter (± 93927600) 0.98
es/full/minify/libraries/vue 157639120 ns/iter (± 13193365) 169646197 ns/iter (± 3503812) 0.93
es/full/codegen/es3 32674 ns/iter (± 700) 33785 ns/iter (± 3313) 0.97
es/full/codegen/es5 32421 ns/iter (± 808) 33206 ns/iter (± 1961) 0.98
es/full/codegen/es2015 32668 ns/iter (± 6188) 33757 ns/iter (± 1810) 0.97
es/full/codegen/es2016 32498 ns/iter (± 1061) 32308 ns/iter (± 440) 1.01
es/full/codegen/es2017 32438 ns/iter (± 1815) 32349 ns/iter (± 631) 1.00
es/full/codegen/es2018 32522 ns/iter (± 4958) 32363 ns/iter (± 1679) 1.00
es/full/codegen/es2019 32714 ns/iter (± 921) 32393 ns/iter (± 2240) 1.01
es/full/codegen/es2020 32345 ns/iter (± 600) 32562 ns/iter (± 1168) 0.99
es/full/all/es3 208943121 ns/iter (± 28156658) 211461222 ns/iter (± 15372153) 0.99
es/full/all/es5 190442358 ns/iter (± 56673963) 199556462 ns/iter (± 13351772) 0.95
es/full/all/es2015 167122727 ns/iter (± 46598022) 153561301 ns/iter (± 11863103) 1.09
es/full/all/es2016 163782319 ns/iter (± 40752940) 147012169 ns/iter (± 16109374) 1.11
es/full/all/es2017 165281731 ns/iter (± 23282599) 149891256 ns/iter (± 11582520) 1.10
es/full/all/es2018 165276077 ns/iter (± 31520258) 145951194 ns/iter (± 13584130) 1.13
es/full/all/es2019 163802190 ns/iter (± 36834062) 153206771 ns/iter (± 13002580) 1.07
es/full/all/es2020 148630830 ns/iter (± 28040043) 145877834 ns/iter (± 13970615) 1.02
es/full/parser 728682 ns/iter (± 23592) 718437 ns/iter (± 33157) 1.01
es/full/base/fixer 29644 ns/iter (± 1111) 29593 ns/iter (± 8246) 1.00
es/full/base/resolver_and_hygiene 90341 ns/iter (± 3965) 88694 ns/iter (± 8881) 1.02
serialization of ast node 217 ns/iter (± 4) 217 ns/iter (± 10) 1
serialization of serde 230 ns/iter (± 14) 228 ns/iter (± 5) 1.01

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

Please sign in to comment.