Skip to content

Commit

Permalink
enhance inline
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl committed Dec 30, 2021
1 parent 80d5f23 commit 366bf80
Show file tree
Hide file tree
Showing 9 changed files with 247 additions and 146 deletions.
200 changes: 126 additions & 74 deletions lib/compress.js

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions test/compress/classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1646,10 +1646,8 @@ issue_4962_1: {
})(function g() {});
}
expect: {
(function g() {}),
void function() {
while (console.log(typeof g));
}();
(function g() {});
while (console.log(typeof g));
}
expect_stdout: "undefined"
node_version: ">=12"
Expand Down
20 changes: 8 additions & 12 deletions test/compress/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -838,12 +838,10 @@ issue_4202: {
expect: {
{
const o = {};
(function() {
function f() {
o.p = 42;
}
f(f);
})();
function f() {
o.p = 42;
}
f(f);
console.log(o.p++);
}
}
Expand Down Expand Up @@ -1287,12 +1285,10 @@ issue_4261_2: {
expect: {
{
const a = 42;
(function() {
function g() {
while (void console.log(a));
}
while (g());
})();
function g() {
while (void console.log(a));
}
while (g());
}
}
expect_stdout: "42"
Expand Down
12 changes: 5 additions & 7 deletions test/compress/default-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -2027,13 +2027,11 @@ issue_5222: {
f();
}
expect: {
(function() {
do {
a = void 0,
[ a ] = [];
} while (console.log("PASS"));
var a;
})();
do {
a = void 0,
[ a ] = [];
} while (console.log("PASS"));
var a;
}
expect_stdout: "PASS"
node_version: ">=6"
Expand Down
89 changes: 54 additions & 35 deletions test/compress/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -820,16 +820,14 @@ issue_2604_1: {
}
expect: {
var a = "FAIL";
(function() {
try {
throw 1;
} catch (b) {
(function(b) {
b && b();
})();
b && (a = "PASS");
}
})();
try {
throw 1;
} catch (b) {
(function(b) {
b && b();
})();
b && (a = "PASS");
}
console.log(a);
}
expect_stdout: "PASS"
Expand Down Expand Up @@ -862,13 +860,11 @@ issue_2604_2: {
}
expect: {
var a = "FAIL";
(function() {
try {
throw 1;
} catch (o) {
o && (a = "PASS");
}
})();
try {
throw 1;
} catch (o) {
o && (a = "PASS");
}
console.log(a);
}
expect_stdout: "PASS"
Expand Down Expand Up @@ -1384,7 +1380,7 @@ issue_2630_3: {
issue_2630_4: {
options = {
collapse_vars: true,
inline: true,
inline: 3,
reduce_vars: true,
side_effects: true,
unused: true,
Expand Down Expand Up @@ -1412,6 +1408,35 @@ issue_2630_4: {
}

issue_2630_5: {
options = {
collapse_vars: true,
inline: true,
passes: 2,
reduce_vars: true,
side_effects: true,
unused: true,
}
input: {
var x = 3, a = 1, b = 2;
(function() {
(function f1() {
while (--x >= 0 && f2());
}());
function f2() {
a++ + (b += a);
}
})();
console.log(a);
}
expect: {
var x = 3, a = 1, b = 2;
while (--x >= 0 && void (b += ++a));
console.log(a);
}
expect_stdout: "2"
}

issue_2630_6: {
options = {
assignments: true,
collapse_vars: true,
Expand Down Expand Up @@ -4981,10 +5006,9 @@ issue_3833_2: {
f();
}
expect: {
(function(a) {
while (a);
console.log("PASS");
})();
var a = void 0;
while (a);
console.log("PASS");
}
expect_stdout: "PASS"
}
Expand Down Expand Up @@ -5605,13 +5629,11 @@ issue_4261: {
try {
throw 42;
} catch (e) {
(function() {
function g() {
// `ReferenceError: e is not defined` on Node.js v0.10
while (void e.p);
}
while (console.log(g()));
})();
function g() {
// `ReferenceError: e is not defined` on Node.js v0.10
while (void e.p);
}
while (console.log(g()));
}
}
expect_stdout: "undefined"
Expand Down Expand Up @@ -5975,9 +5997,8 @@ issue_4659_3: {
function f() {
return a++;
}
(function() {
while (!console);
})(f && a++);
f && a++;
while (!console);
(function() {
var a = console && a;
})();
Expand Down Expand Up @@ -7122,9 +7143,7 @@ issue_5237: {
}
expect: {
function f() {
(function() {
while (console.log(0/0));
})();
while (console.log(0/0));
var NaN = console && console.log(NaN);
return;
}
Expand Down
44 changes: 44 additions & 0 deletions test/compress/join_vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,50 @@ inlined_assignments: {
expect_stdout: "PASS"
}

inilne_for: {
options = {
inline: true,
join_vars: true,
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
var a = function() {
for (; console.log("PASS"););
};
a();
}
expect: {
for (; console.log("PASS"););
}
expect_stdout: "PASS"
}

inilne_var: {
options = {
inline: true,
join_vars: true,
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
A = "PASS";
var a = function() {
var b = A;
for (b in console.log(b));
};
a();
}
expect: {
A = "PASS";
var b = A;
for (b in console.log(b));
}
expect_stdout: "PASS"
}

typescript_enum: {
rename = true
options = {
Expand Down
10 changes: 4 additions & 6 deletions test/compress/let.js
Original file line number Diff line number Diff line change
Expand Up @@ -1054,12 +1054,10 @@ issue_4202: {
"use strict";
{
let o = {};
(function() {
function f() {
o.p = 42;
}
f(f);
})();
function f() {
o.p = 42;
}
f(f);
console.log(o.p++);
}
}
Expand Down
6 changes: 2 additions & 4 deletions test/compress/reduce_vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ reduce_vars: {
}
expect: {
var A = 1;
(function() {
console.log(-3);
console.log(A - 5);
})();
console.log(-3);
console.log(A - 5);
(function f1() {
var a = 2;
console.log(a - 5);
Expand Down
6 changes: 2 additions & 4 deletions test/compress/spreads.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,8 @@ do_inline_3: {
})();
}
expect: {
(function() {
var [] = [ ..."" ];
while (console.log("PASS"));
})();
var [] = [ ..."" ];
while (console.log("PASS"));
}
expect_stdout: "PASS"
node_version: ">=6"
Expand Down

0 comments on commit 366bf80

Please sign in to comment.