Merge pull request #3526 from loganfsmyth/fix-switch-error
Fix an issue with the switch handing from PR #3490.
This commit is contained in:
commit
57328c1fbd
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
function fn() {
|
||||
switch (true) {
|
||||
default:
|
||||
let foo = 4;
|
||||
if (true) {
|
||||
let bar = () => foo;
|
||||
console.log(bar());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
function fn() {
|
||||
(function () {
|
||||
switch (true) {
|
||||
default:
|
||||
var foo = 4;
|
||||
if (true) {
|
||||
var bar = function () {
|
||||
return foo;
|
||||
};
|
||||
console.log(bar());
|
||||
}
|
||||
}
|
||||
})();
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user