Skip to content

Commit

Permalink
fix if_return on block-scoped variables (#2021)
Browse files Browse the repository at this point in the history
fixes #1317
  • Loading branch information
alexlamsl authored May 29, 2017
1 parent ee23a84 commit c2e471e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,9 @@ merge(Compressor.prototype, {
}

function can_merge_flow(ab) {
if (!ab) return false;
if (!ab || !all(ret, function(stat) {
return !(stat instanceof AST_Const || stat instanceof AST_Let);
})) return false;
var lct = ab instanceof AST_LoopControl ? compressor.loopcontrol_target(ab) : null;
return ab instanceof AST_Return && in_lambda && is_return_void(ab.value)
|| ab instanceof AST_Continue && self === loop_body(lct)
Expand Down
58 changes: 58 additions & 0 deletions test/compress/if_return.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,3 +326,61 @@ issue_512: {
}
}
}

issue_1317: {
options = {
if_return: true,
}
input: {
!function(a) {
if (a) return;
let b = 1;
function g() {
return b;
}
console.log(g());
}();
}
expect: {
!function(a) {
if (a) return;
let b = 1;
function g() {
return b;
}
console.log(g());
}();
}
expect_stdout: "1"
node_version: ">=6"
}

issue_1317_strict: {
options = {
if_return: true,
}
input: {
"use strict";
!function(a) {
if (a) return;
let b = 1;
function g() {
return b;
}
console.log(g());
}();
}
expect: {
"use strict";
!function(a) {
if (a) return;
let b = 1;
function g() {
return b;
}
console.log(g());
}();
}
expect_stdout: "1"
node_version: ">=4"
}

0 comments on commit c2e471e

Please sign in to comment.