enhance if_return & inline (#5538)
This commit is contained in:
@@ -1073,7 +1073,7 @@ issue_5414_2: {
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5416: {
|
||||
issue_5416_1: {
|
||||
options = {
|
||||
dead_code: true,
|
||||
evaluate: true,
|
||||
@@ -1095,10 +1095,11 @@ issue_5416: {
|
||||
expect: {
|
||||
var f = () => {
|
||||
{
|
||||
arguments = void 0;
|
||||
console;
|
||||
arguments = void 0,
|
||||
console.log(arguments);
|
||||
var arguments;
|
||||
return;
|
||||
}
|
||||
};
|
||||
f();
|
||||
@@ -1107,6 +1108,97 @@ issue_5416: {
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5416_2: {
|
||||
options = {
|
||||
dead_code: true,
|
||||
evaluate: true,
|
||||
inline: true,
|
||||
loops: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var f = () => {
|
||||
while ((() => {
|
||||
console;
|
||||
var a = function g(arguments) {
|
||||
while (console.log(arguments));
|
||||
}();
|
||||
})());
|
||||
};
|
||||
f();
|
||||
}
|
||||
expect: {
|
||||
var f = () => {
|
||||
{
|
||||
console;
|
||||
var arguments = void 0;
|
||||
for (; console.log(arguments););
|
||||
return;
|
||||
}
|
||||
};
|
||||
f();
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5416_3: {
|
||||
options = {
|
||||
inline: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var f = () => {
|
||||
(() => {
|
||||
var a = function g(arguments) {
|
||||
console.log(arguments);
|
||||
}();
|
||||
})();
|
||||
};
|
||||
f();
|
||||
}
|
||||
expect: {
|
||||
var f = () => {
|
||||
arguments = void 0,
|
||||
console.log(arguments);
|
||||
var arguments;
|
||||
};
|
||||
f();
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5416_4: {
|
||||
options = {
|
||||
arrows: true,
|
||||
inline: true,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var f = () => {
|
||||
(() => {
|
||||
var a = function g(arguments) {
|
||||
while (console.log(arguments));
|
||||
}();
|
||||
})();
|
||||
};
|
||||
f();
|
||||
}
|
||||
expect: {
|
||||
var f = () => {
|
||||
var arguments = void 0;
|
||||
while (console.log(arguments));
|
||||
return;
|
||||
};
|
||||
f();
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5495: {
|
||||
input: {
|
||||
console.log((() => {
|
||||
|
||||
@@ -1731,7 +1731,7 @@ issue_3576: {
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_3668: {
|
||||
issue_3668_1: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
if_return: true,
|
||||
@@ -1748,6 +1748,38 @@ issue_3668: {
|
||||
}
|
||||
console.log(f());
|
||||
}
|
||||
expect: {
|
||||
function f() {
|
||||
try {
|
||||
var undefined = typeof f;
|
||||
if (!f) return undefined;
|
||||
} catch (e) {
|
||||
return "FAIL";
|
||||
}
|
||||
}
|
||||
console.log(f());
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
}
|
||||
|
||||
issue_3668_2: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
try {
|
||||
var undefined = typeof f;
|
||||
if (!f) return undefined;
|
||||
return;
|
||||
} catch (e) {
|
||||
return "FAIL";
|
||||
}
|
||||
FAIL;
|
||||
}
|
||||
console.log(f());
|
||||
}
|
||||
expect: {
|
||||
function f() {
|
||||
try {
|
||||
@@ -1756,6 +1788,7 @@ issue_3668: {
|
||||
} catch (e) {
|
||||
return "FAIL";
|
||||
}
|
||||
FAIL;
|
||||
}
|
||||
console.log(f());
|
||||
}
|
||||
|
||||
@@ -1017,3 +1017,302 @@ issue_5523: {
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
}
|
||||
|
||||
drop_catch: {
|
||||
options = {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
try {
|
||||
throw 42;
|
||||
} catch (e) {
|
||||
return console.log("foo"), "bar";
|
||||
} finally {
|
||||
console.log("baz");
|
||||
}
|
||||
return "bar";
|
||||
}
|
||||
console.log(f());
|
||||
}
|
||||
expect: {
|
||||
function f() {
|
||||
try {
|
||||
throw 42;
|
||||
} catch (e) {
|
||||
console.log("foo");
|
||||
} finally {
|
||||
console.log("baz");
|
||||
}
|
||||
return "bar";
|
||||
}
|
||||
console.log(f());
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"baz",
|
||||
"bar",
|
||||
]
|
||||
}
|
||||
|
||||
retain_catch: {
|
||||
options = {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
try {
|
||||
throw 42;
|
||||
} catch (e) {
|
||||
return console.log("foo");
|
||||
} finally {
|
||||
console.log("bar");
|
||||
}
|
||||
return console.log("foo");
|
||||
}
|
||||
f();
|
||||
}
|
||||
expect: {
|
||||
function f() {
|
||||
try {
|
||||
throw 42;
|
||||
} catch (e) {
|
||||
return console.log("foo");
|
||||
} finally {
|
||||
console.log("bar");
|
||||
}
|
||||
return console.log("foo");
|
||||
}
|
||||
f();
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
]
|
||||
}
|
||||
|
||||
retain_finally: {
|
||||
options = {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
try {
|
||||
return console.log("foo"), FAIL;
|
||||
} catch (e) {
|
||||
return console.log("bar"), "FAIL";
|
||||
} finally {
|
||||
return console.log("baz"), console.log("moo");
|
||||
}
|
||||
return console.log("moo");
|
||||
}
|
||||
console.log(f());
|
||||
}
|
||||
expect: {
|
||||
function f() {
|
||||
try {
|
||||
return console.log("foo"), FAIL;
|
||||
} catch (e) {
|
||||
return console.log("bar"), "FAIL";
|
||||
} finally {
|
||||
return console.log("baz"), console.log("moo");
|
||||
}
|
||||
return console.log("moo");
|
||||
}
|
||||
console.log(f());
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
"baz",
|
||||
"moo",
|
||||
"undefined",
|
||||
]
|
||||
}
|
||||
|
||||
drop_try: {
|
||||
options = {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
try {
|
||||
return console.log("foo"), "bar";
|
||||
} finally {
|
||||
console.log("baz");
|
||||
}
|
||||
return "bar";
|
||||
}
|
||||
console.log(f());
|
||||
}
|
||||
expect: {
|
||||
function f() {
|
||||
try {
|
||||
console.log("foo");
|
||||
} finally {
|
||||
console.log("baz");
|
||||
}
|
||||
return "bar";
|
||||
}
|
||||
console.log(f());
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"baz",
|
||||
"bar",
|
||||
]
|
||||
}
|
||||
|
||||
retain_try: {
|
||||
options = {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
try {
|
||||
return console.log("foo");
|
||||
} finally {
|
||||
console.log("bar");
|
||||
}
|
||||
return console.log("foo");
|
||||
}
|
||||
f();
|
||||
}
|
||||
expect: {
|
||||
function f() {
|
||||
try {
|
||||
return console.log("foo");
|
||||
} finally {
|
||||
console.log("bar");
|
||||
}
|
||||
return console.log("foo");
|
||||
}
|
||||
f();
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
]
|
||||
}
|
||||
|
||||
drop_try_catch: {
|
||||
options = {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
function f(a) {
|
||||
try {
|
||||
if (a())
|
||||
return console.log("foo"), console.log("baz");
|
||||
} catch (e) {
|
||||
return console.log("bar"), console.log("baz");
|
||||
}
|
||||
return console.log("baz");
|
||||
}
|
||||
f(function() {
|
||||
return 42;
|
||||
});
|
||||
f(function() {});
|
||||
f();
|
||||
}
|
||||
expect: {
|
||||
function f(a) {
|
||||
try {
|
||||
if (a())
|
||||
console.log("foo");
|
||||
} catch (e) {
|
||||
console.log("bar");
|
||||
}
|
||||
return console.log("baz");
|
||||
}
|
||||
f(function() {
|
||||
return 42;
|
||||
});
|
||||
f(function() {});
|
||||
f();
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"baz",
|
||||
"baz",
|
||||
"bar",
|
||||
"baz",
|
||||
]
|
||||
}
|
||||
|
||||
empty_try: {
|
||||
options = {
|
||||
if_return: true,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function() {
|
||||
return f;
|
||||
function f() {
|
||||
try {} finally {}
|
||||
return "PASS";
|
||||
}
|
||||
}()());
|
||||
}
|
||||
expect: {
|
||||
console.log(function() {
|
||||
return function() {
|
||||
try {} finally {}
|
||||
return "PASS";
|
||||
};
|
||||
}()());
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
sequence_void_1: {
|
||||
options = {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
{
|
||||
if (console)
|
||||
return console, void console.log("PASS");
|
||||
return;
|
||||
}
|
||||
}
|
||||
f();
|
||||
}
|
||||
expect: {
|
||||
function f() {
|
||||
if (console)
|
||||
return console, void console.log("PASS");
|
||||
}
|
||||
f();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
sequence_void_2: {
|
||||
options = {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
{
|
||||
if (console)
|
||||
return console, void console.log("PASS");
|
||||
return;
|
||||
}
|
||||
FAIL;
|
||||
}
|
||||
f();
|
||||
}
|
||||
expect: {
|
||||
function f() {
|
||||
if (console)
|
||||
console, void console.log("PASS");
|
||||
return;
|
||||
FAIL;
|
||||
}
|
||||
f();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
@@ -1659,7 +1659,7 @@ issue_4438: {
|
||||
function f() {
|
||||
if (console) {
|
||||
let a = console.log;
|
||||
void a("PASS");
|
||||
a("PASS");
|
||||
}
|
||||
}
|
||||
f();
|
||||
|
||||
@@ -1183,6 +1183,35 @@ issue_4641_2: {
|
||||
node_version: ">=10"
|
||||
}
|
||||
|
||||
issue_4641_3: {
|
||||
options = {
|
||||
if_return: true,
|
||||
}
|
||||
input: {
|
||||
console.log(typeof async function*() {
|
||||
try {
|
||||
return void "FAIL";
|
||||
} finally {
|
||||
console.log("PASS");
|
||||
}
|
||||
}().next().then);
|
||||
}
|
||||
expect: {
|
||||
console.log(typeof async function*() {
|
||||
try {
|
||||
return void "FAIL";
|
||||
} finally {
|
||||
console.log("PASS");
|
||||
}
|
||||
}().next().then);
|
||||
}
|
||||
expect_stdout: [
|
||||
"function",
|
||||
"PASS",
|
||||
]
|
||||
node_version: ">=10"
|
||||
}
|
||||
|
||||
issue_4769_1: {
|
||||
options = {
|
||||
side_effects: true,
|
||||
|
||||
Reference in New Issue
Block a user