incorrect handling of returns nested in switch cases (#3618)

This commit is contained in:
Adam Leventhal 2016-08-18 07:14:07 -07:00 committed by Henry Zhu
parent 183d9570f9
commit 0d1e1ee10c
3 changed files with 52 additions and 5 deletions

View File

@ -684,11 +684,13 @@ class BlockScoping {
single.consequent[0]
));
} else {
// https://github.com/babel/babel/issues/998
for (let i = 0; i < cases.length; i++) {
let caseConsequent = cases[i].consequent[0];
if (t.isBreakStatement(caseConsequent) && !caseConsequent.label) {
caseConsequent.label = this.loopLabel = this.loopLabel || this.scope.generateUidIdentifier("loop");
if (this.loop) {
// https://github.com/babel/babel/issues/998
for (let i = 0; i < cases.length; i++) {
let caseConsequent = cases[i].consequent[0];
if (t.isBreakStatement(caseConsequent) && !caseConsequent.label) {
caseConsequent.label = this.loopLabel = this.loopLabel || this.scope.generateUidIdentifier("loop");
}
}
}

View File

@ -0,0 +1,16 @@
function foo() {
switch (2) {
case 0: {
if (true) {
return;
}
const stuff = new Map();
const data = 0;
stuff.forEach(() => {
const d = data;
});
break;
}
}
}

View File

@ -0,0 +1,29 @@
function foo() {
switch (2) {
case 0:
{
var _ret = function () {
if (true) {
return {
v: void 0
};
}
var stuff = new Map();
var data = 0;
stuff.forEach(function () {
var d = data;
});
return "break";
}();
switch (_ret) {
case "break":
break;
default:
if (typeof _ret === "object") return _ret.v;
}
}
}
}