@@ -4592,6 +4592,9 @@ merge(Compressor.prototype, {
|
|||||||
&& !fn.uses_arguments
|
&& !fn.uses_arguments
|
||||||
&& !fn.uses_eval
|
&& !fn.uses_eval
|
||||||
&& !(fn.name && fn instanceof AST_Function)
|
&& !(fn.name && fn instanceof AST_Function)
|
||||||
|
&& (!(compressor.find_parent(AST_Lambda) instanceof AST_Arrow)
|
||||||
|
|| fn.argnames.length == 0
|
||||||
|
&& (fn.body instanceof AST_Node || fn.body.length == 1))
|
||||||
&& (value = can_flatten_body(stat))
|
&& (value = can_flatten_body(stat))
|
||||||
&& (exp === fn
|
&& (exp === fn
|
||||||
|| compressor.option("unused")
|
|| compressor.option("unused")
|
||||||
|
|||||||
@@ -1516,9 +1516,11 @@ issue_2647_2: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
(function() {
|
(function() {
|
||||||
console.log((() => (x = "pass", x.toUpperCase()))());
|
function foo(x) {
|
||||||
var x;
|
return x.toUpperCase();
|
||||||
})();
|
}
|
||||||
|
console.log((() => foo("pass"))());
|
||||||
|
}());
|
||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
node_version: ">=4"
|
node_version: ">=4"
|
||||||
|
|||||||
@@ -1470,3 +1470,134 @@ inline_arrow_using_arguments: {
|
|||||||
]
|
]
|
||||||
node_version: ">=6"
|
node_version: ">=6"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2874_1: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
evaluate: true,
|
||||||
|
inline: 3,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
function foo() {
|
||||||
|
let letters = ["A", "B", "C"];
|
||||||
|
let result = [2, 1, 0].map(key => bar(letters[key] + key));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
function bar(value) {
|
||||||
|
return () => console.log(value);
|
||||||
|
}
|
||||||
|
foo().map(fn => fn());
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
(function() {
|
||||||
|
let letters = [ "A", "B", "C" ];
|
||||||
|
return [ 2, 1, 0 ].map(key => (function(value) {
|
||||||
|
return () => console.log(value);
|
||||||
|
})(letters[key] + key));
|
||||||
|
})().map(fn => fn());
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"C2",
|
||||||
|
"B1",
|
||||||
|
"A0",
|
||||||
|
]
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2874_2: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
evaluate: true,
|
||||||
|
inline: 3,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
let keys = [];
|
||||||
|
function foo() {
|
||||||
|
var result = [2, 1, 0].map(value => {
|
||||||
|
keys.push(value);
|
||||||
|
return bar();
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
function bar() {
|
||||||
|
var letters = ["A", "B", "C"], key = keys.shift();
|
||||||
|
return () => console.log(letters[key] + key);
|
||||||
|
}
|
||||||
|
foo().map(fn => fn());
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
let keys = [];
|
||||||
|
[ 2, 1, 0 ].map(value => {
|
||||||
|
return keys.push(value), function() {
|
||||||
|
var letters = [ "A", "B", "C" ], key = keys.shift();
|
||||||
|
return () => console.log(letters[key] + key);
|
||||||
|
}();
|
||||||
|
}).map(fn => fn());
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"C2",
|
||||||
|
"B1",
|
||||||
|
"A0",
|
||||||
|
]
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2874_3: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
evaluate: true,
|
||||||
|
inline: 3,
|
||||||
|
reduce_funcs: false,
|
||||||
|
reduce_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
return x + y;
|
||||||
|
}
|
||||||
|
let x, y;
|
||||||
|
let a = (z) => {
|
||||||
|
x = "A";
|
||||||
|
y = z;
|
||||||
|
console.log(f());
|
||||||
|
}
|
||||||
|
a(1);
|
||||||
|
a(2);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
let x, y;
|
||||||
|
let a = z => {
|
||||||
|
x = "A",
|
||||||
|
y = z,
|
||||||
|
console.log(x + y);
|
||||||
|
};
|
||||||
|
a(1),
|
||||||
|
a(2);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"A1",
|
||||||
|
"A2",
|
||||||
|
]
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user