fix for-in/of regression with let or const loop variable (#2840)
fixes #2835
This commit is contained in:
@@ -1759,7 +1759,7 @@ merge(Compressor.prototype, {
|
|||||||
var stat = null;
|
var stat = null;
|
||||||
for (var i = 0, len = block.body.length; i < len; i++) {
|
for (var i = 0, len = block.body.length; i < len; i++) {
|
||||||
var line = block.body[i];
|
var line = block.body[i];
|
||||||
if (line instanceof AST_Definitions && declarations_only(line)) {
|
if (line instanceof AST_Var && declarations_only(line)) {
|
||||||
decls.push(line);
|
decls.push(line);
|
||||||
} else if (stat) {
|
} else if (stat) {
|
||||||
return false;
|
return false;
|
||||||
@@ -1803,7 +1803,9 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (stat instanceof AST_ForIn) {
|
} else if (stat instanceof AST_ForIn) {
|
||||||
stat.object = cons_seq(stat.object);
|
if (!(stat.init instanceof AST_Const) && !(stat.init instanceof AST_Let)) {
|
||||||
|
stat.object = cons_seq(stat.object);
|
||||||
|
}
|
||||||
} else if (stat instanceof AST_If) {
|
} else if (stat instanceof AST_If) {
|
||||||
stat.condition = cons_seq(stat.condition);
|
stat.condition = cons_seq(stat.condition);
|
||||||
} else if (stat instanceof AST_Switch) {
|
} else if (stat instanceof AST_Switch) {
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ same_variable_in_multiple_for_loop: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
|
node_version: ">=6"
|
||||||
}
|
}
|
||||||
|
|
||||||
same_variable_in_multiple_forOf: {
|
same_variable_in_multiple_forOf: {
|
||||||
@@ -79,7 +80,7 @@ same_variable_in_multiple_forOf: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
reminify: false // FIXME - regression https://github.com/mishoo/UglifyJS2/issues/2835
|
node_version: ">=6"
|
||||||
}
|
}
|
||||||
|
|
||||||
same_variable_in_multiple_forIn: {
|
same_variable_in_multiple_forIn: {
|
||||||
@@ -121,7 +122,7 @@ same_variable_in_multiple_forIn: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
reminify: false // FIXME - regression https://github.com/mishoo/UglifyJS2/issues/2835
|
node_version: ">=6"
|
||||||
}
|
}
|
||||||
|
|
||||||
different_variable_in_multiple_for_loop: {
|
different_variable_in_multiple_for_loop: {
|
||||||
@@ -164,6 +165,7 @@ different_variable_in_multiple_for_loop: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
|
node_version: ">=6"
|
||||||
}
|
}
|
||||||
|
|
||||||
different_variable_in_multiple_forOf: {
|
different_variable_in_multiple_forOf: {
|
||||||
@@ -205,6 +207,7 @@ different_variable_in_multiple_forOf: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
|
node_version: ">=6"
|
||||||
}
|
}
|
||||||
|
|
||||||
different_variable_in_multiple_forIn: {
|
different_variable_in_multiple_forIn: {
|
||||||
@@ -246,6 +249,175 @@ different_variable_in_multiple_forIn: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
|
same_variable_in_multiple_forOf_sequences_let: {
|
||||||
|
options = {
|
||||||
|
hoist_funs: true,
|
||||||
|
dead_code: true,
|
||||||
|
conditionals: true,
|
||||||
|
comparisons: true,
|
||||||
|
evaluate: true,
|
||||||
|
booleans: true,
|
||||||
|
loops: true,
|
||||||
|
unused: true,
|
||||||
|
keep_fargs: true,
|
||||||
|
if_return: true,
|
||||||
|
join_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
collapse_vars: true,
|
||||||
|
}
|
||||||
|
mangle = {}
|
||||||
|
input: {
|
||||||
|
var test = [ "a", "b", "c" ];
|
||||||
|
for (let tmp of test) {
|
||||||
|
console.log(tmp);
|
||||||
|
let dd;
|
||||||
|
dd = [ "e", "f", "g" ];
|
||||||
|
for (let tmp of dd) {
|
||||||
|
console.log(tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var test = [ "a", "b", "c" ];
|
||||||
|
for (let o of test) {
|
||||||
|
let e;
|
||||||
|
console.log(o), e = [ "e", "f", "g" ];
|
||||||
|
for (let o of e)
|
||||||
|
console.log(o);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
|
same_variable_in_multiple_forOf_sequences_const: {
|
||||||
|
options = {
|
||||||
|
hoist_funs: true,
|
||||||
|
dead_code: true,
|
||||||
|
conditionals: true,
|
||||||
|
comparisons: true,
|
||||||
|
evaluate: true,
|
||||||
|
booleans: true,
|
||||||
|
loops: true,
|
||||||
|
unused: true,
|
||||||
|
keep_fargs: true,
|
||||||
|
if_return: true,
|
||||||
|
join_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
collapse_vars: true,
|
||||||
|
}
|
||||||
|
mangle = {}
|
||||||
|
input: {
|
||||||
|
var test = [ "a", "b", "c" ];
|
||||||
|
for (const tmp of test) {
|
||||||
|
console.log(tmp);
|
||||||
|
let dd;
|
||||||
|
dd = [ "e", "f", "g" ];
|
||||||
|
for (const tmp of dd) {
|
||||||
|
console.log(tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var test = [ "a", "b", "c" ];
|
||||||
|
for (const o of test) {
|
||||||
|
let t;
|
||||||
|
console.log(o), t = [ "e", "f", "g" ];
|
||||||
|
for (const o of t)
|
||||||
|
console.log(o);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
|
same_variable_in_multiple_forIn_sequences_let: {
|
||||||
|
options = {
|
||||||
|
hoist_funs: true,
|
||||||
|
dead_code: true,
|
||||||
|
conditionals: true,
|
||||||
|
comparisons: true,
|
||||||
|
evaluate: true,
|
||||||
|
booleans: true,
|
||||||
|
loops: true,
|
||||||
|
unused: false,
|
||||||
|
keep_fargs: true,
|
||||||
|
if_return: true,
|
||||||
|
join_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
collapse_vars: true,
|
||||||
|
}
|
||||||
|
mangle = {}
|
||||||
|
input: {
|
||||||
|
var test = [ "a", "b", "c" ];
|
||||||
|
for (let tmp in test) {
|
||||||
|
console.log(tmp);
|
||||||
|
let dd;
|
||||||
|
dd = [ "e", "f", "g" ];
|
||||||
|
for (let tmp in test) {
|
||||||
|
console.log(tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var test = [ "a", "b", "c" ];
|
||||||
|
for (let e in test) {
|
||||||
|
let t;
|
||||||
|
console.log(e), t = [ "e", "f", "g" ];
|
||||||
|
for (let e in test)
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
|
same_variable_in_multiple_forIn_sequences_const: {
|
||||||
|
options = {
|
||||||
|
hoist_funs: true,
|
||||||
|
dead_code: true,
|
||||||
|
conditionals: true,
|
||||||
|
comparisons: true,
|
||||||
|
evaluate: true,
|
||||||
|
booleans: true,
|
||||||
|
loops: true,
|
||||||
|
unused: false,
|
||||||
|
keep_fargs: true,
|
||||||
|
if_return: true,
|
||||||
|
join_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
collapse_vars: true,
|
||||||
|
}
|
||||||
|
mangle = {}
|
||||||
|
input: {
|
||||||
|
var test = [ "a", "b", "c" ];
|
||||||
|
for (const tmp in test) {
|
||||||
|
console.log(tmp);
|
||||||
|
let dd;
|
||||||
|
dd = [ "e", "f", "g" ];
|
||||||
|
for (const tmp in test) {
|
||||||
|
console.log(tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var test = [ "a", "b", "c" ];
|
||||||
|
for (const o in test) {
|
||||||
|
let t;
|
||||||
|
console.log(o), t = [ "e", "f", "g" ];
|
||||||
|
for (const o in test)
|
||||||
|
console.log(o);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
node_version: ">=6"
|
||||||
}
|
}
|
||||||
|
|
||||||
more_variable_in_multiple_for: {
|
more_variable_in_multiple_for: {
|
||||||
@@ -283,4 +455,5 @@ more_variable_in_multiple_for: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
|
node_version: ">=6"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user