Merge pull request #3526 from loganfsmyth/fix-switch-error

Fix an issue with the switch handing from PR #3490.
This commit is contained in:
Logan Smyth 2016-06-11 00:32:37 -07:00 committed by GitHub
commit 57328c1fbd
3 changed files with 32 additions and 5 deletions

View File

@ -435,16 +435,15 @@ class BlockScoping {
let params = values(outsideRefs);
let args = values(outsideRefs);
// build the closure that we're going to wrap the block with
let fn = t.functionExpression(null, params, t.blockStatement(block.body));
const isSwitch = this.blockPath.isSwitchStatement();
// build the closure that we're going to wrap the block with, possible wrapping switch(){}
let fn = t.functionExpression(null, params, t.blockStatement(isSwitch ? [block] : block.body));
fn.shadow = true;
// continuation
this.addContinuations(fn);
// replace the current block body with the one we're going to build
block.body = this.body;
let ref = fn;
if (this.loop) {
@ -473,6 +472,10 @@ class BlockScoping {
}
this.buildClosure(ret, call);
// replace the current block body with the one we're going to build
if (isSwitch) this.blockPath.replaceWithMultiple(this.body);
else block.body = this.body;
}
/**

View File

@ -0,0 +1,10 @@
function fn() {
switch (true) {
default:
let foo = 4;
if (true) {
let bar = () => foo;
console.log(bar());
}
}
}

View File

@ -0,0 +1,14 @@
function fn() {
(function () {
switch (true) {
default:
var foo = 4;
if (true) {
var bar = function () {
return foo;
};
console.log(bar());
}
}
})();
}