Skip to content

Commit

Permalink
fix(es/minifier): calc function body cost when inline function
Browse files Browse the repository at this point in the history
  • Loading branch information
Austaras authored and kdy1 committed Oct 15, 2022
1 parent 608aa94 commit 18f2762
Show file tree
Hide file tree
Showing 66 changed files with 1,234 additions and 1,517 deletions.
9 changes: 2 additions & 7 deletions crates/swc/tests/tsc-references/ES5For-of10.2.minified.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
//// [ES5For-of10.ts]
function foo() {
return {
x: 0
};
}
for(var _i = 0, _iter = []; _i < _iter.length; _i++){
foo().x = _iter[_i];
for(var _i1 = 0, _iter1 = []; _i1 < _iter1.length; _i1++)foo().x = _iter1[_i1], foo().x;
_iter[_i];
for(var _i1 = 0, _iter1 = []; _i1 < _iter1.length; _i1++)_iter1[_i1];
}
7 changes: 1 addition & 6 deletions crates/swc/tests/tsc-references/ES5For-of34.2.minified.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
//// [ES5For-of34.ts]
function foo() {
return {
x: 0
};
}
for(var _i = 0, _iter = [
"a",
"b",
"c"
]; _i < _iter.length; _i++)foo().x = _iter[_i], foo().x;
]; _i < _iter.length; _i++)_iter[_i];
7 changes: 1 addition & 6 deletions crates/swc/tests/tsc-references/ES5For-of8.2.minified.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
//// [ES5For-of8.ts]
function foo() {
return {
x: 0
};
}
for(var _i = 0, _iter = [
"a",
"b",
"c"
]; _i < _iter.length; _i++)foo().x = _iter[_i], foo().x;
]; _i < _iter.length; _i++)_iter[_i];
9 changes: 2 additions & 7 deletions crates/swc/tests/tsc-references/ES5For-of9.2.minified.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
//// [ES5For-of9.ts]
function foo() {
return {
x: 0
};
}
for(var _i = 0, _iter = []; _i < _iter.length; _i++){
foo().x = _iter[_i];
for(var _i1 = 0, _iter1 = []; _i1 < _iter1.length; _i1++)foo().x = _iter1[_i1], foo().x;
_iter[_i];
for(var _i1 = 0, _iter1 = []; _i1 < _iter1.length; _i1++)_iter1[_i1];
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
//// [bitwiseNotOperatorWithStringType.ts]
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
function foo() {
return "abc";
}
var STRING, M, A = function() {
"use strict";
function A() {
Expand All @@ -17,4 +14,4 @@ var STRING, M, A = function() {
M.n = n;
}(M || (M = {}));
var objA = new A();
objA.a, M.n, foo(), A.foo(), STRING.charAt(0), foo(), objA.a, M.n;
objA.a, M.n, A.foo(), STRING.charAt(0), objA.a, M.n;
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,4 @@ var A = function A() {
}
return B;
}(A);
function NewA(Factory) {
return new A;
}
function NewB(Factory) {
return new B;
}
NewA(A), NewA(B), NewB(A), NewB(B);
new A, new A, new B, new B;
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import _to_consumable_array from "@swc/helpers/src/_to_consumable_array.mjs";
var _undefined = _sliced_to_array(void 0, 2);
_undefined[0], _undefined[1];
var _undefined1 = _sliced_to_array(void 0, 2);
function foo() {
return [
1,
2,
3
];
}
_undefined1[0], _undefined1[1];
var ref = _sliced_to_array(foo(), 2);
ref[0], ref[1], _to_array(foo()).slice(0);
var ref = _sliced_to_array([
1,
2,
3
], 2);
ref[0], ref[1], _to_array([
1,
2,
3
]).slice(0);
var ref1 = _sliced_to_array(_to_consumable_array([
1,
2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import _to_consumable_array from "@swc/helpers/src/_to_consumable_array.mjs";
var _undefined = _sliced_to_array(void 0, 2);
_undefined[0], _undefined[1];
var _undefined1 = _sliced_to_array(void 0, 2);
function foo() {
return [
1,
2,
3
];
}
_undefined1[0], _undefined1[1];
var ref = _sliced_to_array(foo(), 2);
ref[0], ref[1], _to_array(foo()).slice(0);
var ref = _sliced_to_array([
1,
2,
3
], 2);
ref[0], ref[1], _to_array([
1,
2,
3
]).slice(0);
var ref1 = _sliced_to_array(_to_consumable_array([
1,
2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ var [a0, a1] = void 0, [a2 = !1, a3 = 1] = void 0, [b0, b1, b2] = [
1,
2,
"string"
];
function foo() {
return [
1,
2,
3
];
}
var [b6, b7] = foo(), [...b8] = foo(), [c0, c1] = [
], [b6, b7] = [
1,
2,
3
], [...b8] = [
1,
2,
3
], [c0, c1] = [
1,
2,
3
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
//// [destructuringWithLiteralInitializers.ts]
import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs";
function f2(param) {
param.x, param.y;
}
function f3(param) {
param.x, param.y;
}
function f4() {
var ref = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {
x: 0,
Expand Down Expand Up @@ -51,16 +45,28 @@ function g5() {
}({
x: 1,
y: 1
}), f2({
}), function(param) {
param.x, param.y;
}({
x: 1
}), f2({
}), function(param) {
param.x, param.y;
}({
x: 1,
y: 1
}), f3({}), f3({
}), function(param) {
param.x, param.y;
}({}), function(param) {
param.x, param.y;
}({
x: 1
}), f3({
}), function(param) {
param.x, param.y;
}({
y: 1
}), f3({
}), function(param) {
param.x, param.y;
}({
x: 1,
y: 1
}), f4(), f4({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
import _inherits from "@swc/helpers/src/_inherits.mjs";
import _create_super from "@swc/helpers/src/_create_super.mjs";
function rec1() {
return rec2();
}
function rec2() {
return rec1();
}
function rec3() {
return rec4();
return rec2();
}
function rec4() {
return rec3();
return rec4();
}
rec1(), rec2(), rec3(), rec4();
rec2(), rec2(), rec4(), rec4();
var Base = function Base() {
"use strict";
_class_call_check(this, Base);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
//// [genericCallWithFunctionTypedArguments.ts]
function foo(x) {
return x(null);
}
foo(function(x) {
return "";
}), foo(function(x) {
return "";
}), foo(function(x) {
return "";
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@ var i, i2, a;
function foo(x) {
return new x(null);
}
function foo2(x, cb) {
return new cb(x);
}
foo(i), foo(i), foo(i2), foo(a), foo2(1, i2), foo2(1, a), foo2(1, i), foo2("", i2), new i(null), new a(null), new i2(1), new i2("");
foo(i), foo(i), foo(i2), foo(a), new i2(1), new a(1), new i(1), new i2(""), new i(null), new a(null), new i2(1), new i2("");
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,19 @@ var i, Base = function Base() {
}
return Derived2;
}(Base);
function f(a) {
return [
a.x,
a.y
];
}
function f2(a) {
return function(x) {
return a.y;
};
}
f({
!function(a) {
a.x, a.y;
}({
x: new Derived(),
y: new Derived2()
}), f({
}), function(a) {
a.x, a.y;
}({
x: new Base(),
y: new Derived2()
}), f2({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,4 @@ var Base = function Base() {
}
return Derived;
}(Base);
function f3(x, y) {
return y(null);
}
new Base(), new Derived(), new Derived(), new Derived(), f3(new Base(), function(x) {
return x;
}), f3(new Derived(), function(x) {
return x;
}), f3(null, null), f3(null, function(x) {
return x;
});
new Base(), new Derived(), new Derived(), new Derived(), new Base(), new Derived(), (null)(null);
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
import _inherits from "@swc/helpers/src/_inherits.mjs";
import _create_super from "@swc/helpers/src/_create_super.mjs";
var Base = function Base() {
var y, y1, Base = function Base() {
"use strict";
_class_call_check(this, Base);
}, Derived = function(Base) {
Expand All @@ -22,13 +22,8 @@ var Base = function Base() {
}
return Derived2;
}(Base);
function f3(y, x) {
return y(null);
}
new Derived(), new Derived2(), new Derived(), new Derived2(), new Derived(), new Derived2(), f3(function(x) {
new Derived(), new Derived2(), new Derived(), new Derived2(), new Derived(), new Derived2(), y = function(x) {
return x;
}, new Base()), f3(function(x) {
}, new Base(), y(null), y1 = function(x) {
return x;
}, new Derived()), f3(function(x) {
return x;
}, null);
}, new Derived(), y1(null);
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
//// [iteratorSpreadInCall11.ts]
function foo(...s) {
return s[0];
}
class SymbolIterator {
next() {
return {
Expand All @@ -13,4 +10,6 @@ class SymbolIterator {
return this;
}
}
foo(...new SymbolIterator);
!function(...s) {
s[0];
}(...new SymbolIterator);
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
//// [iteratorSpreadInCall7.ts]
function foo(...s) {
return s[0];
}
class SymbolIterator {
next() {
return {
Expand All @@ -24,4 +21,6 @@ class _StringIterator {
return this;
}
}
foo(...new SymbolIterator, ...new _StringIterator);
!function(...s) {
s[0];
}(...new SymbolIterator, ...new _StringIterator);
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
//// [logicalAssignment10.ts]
var _obj, _ref, _ref1, _ref2, ref, ref1, count = 0, obj = {};
function incr() {
return ++count;
}
null !== (ref = (_obj = obj)[_ref = incr()]) && void 0 !== ref || (_obj[_ref] = incr()), null !== (ref1 = (_ref1 = ({
null !== (ref = (_obj = obj)[_ref = ++count]) && void 0 !== ref || (_obj[_ref] = ++count), null !== (ref1 = (_ref1 = ({
obj
}).obj)[_ref2 = incr()]) && void 0 !== ref1 || (_ref1[_ref2] = incr());
}).obj)[_ref2 = ++count]) && void 0 !== ref1 || (_ref1[_ref2] = ++count);
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
//// [logicalAssignment10.ts]
var _obj, _ref, _ref1, _ref2, count = 0, obj = {};
function incr() {
return ++count;
}
(_obj = obj)[_ref = incr()], _obj[_ref] = incr(), (_ref1 = ({
(_obj = obj)[_ref = ++count], _obj[_ref] = ++count, (_ref1 = ({
obj
}).obj)[_ref2 = incr()], _ref1[_ref2] = incr();
}).obj)[_ref2 = ++count], _ref1[_ref2] = ++count;
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
//// [logicalAssignment10.ts]
var count = 0, obj = {};
function incr() {
return ++count;
}
const oobj = {
obj
};
obj[incr()] ??= incr(), oobj.obj[incr()] ??= incr();
obj[++count] ??= ++count, oobj.obj[++count] ??= ++count;
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
//// [logicalAssignment10.ts]
var count = 0, obj = {};
function incr() {
return ++count;
}
const oobj = {
obj
};
obj[incr()] ??= incr(), oobj.obj[incr()] ??= incr();
obj[++count] ??= ++count, oobj.obj[++count] ??= ++count;

0 comments on commit 18f2762

Please sign in to comment.