incorrect handling of returns nested in switch cases (#3618)
This commit is contained in:
parent
183d9570f9
commit
0d1e1ee10c
@ -684,6 +684,7 @@ class BlockScoping {
|
|||||||
single.consequent[0]
|
single.consequent[0]
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
|
if (this.loop) {
|
||||||
// https://github.com/babel/babel/issues/998
|
// https://github.com/babel/babel/issues/998
|
||||||
for (let i = 0; i < cases.length; i++) {
|
for (let i = 0; i < cases.length; i++) {
|
||||||
let caseConsequent = cases[i].consequent[0];
|
let caseConsequent = cases[i].consequent[0];
|
||||||
@ -691,6 +692,7 @@ class BlockScoping {
|
|||||||
caseConsequent.label = this.loopLabel = this.loopLabel || this.scope.generateUidIdentifier("loop");
|
caseConsequent.label = this.loopLabel = this.loopLabel || this.scope.generateUidIdentifier("loop");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
body.push(t.switchStatement(ret, cases));
|
body.push(t.switchStatement(ret, cases));
|
||||||
}
|
}
|
||||||
|
|||||||
16
packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/superswitch/actual.js
vendored
Normal file
16
packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/superswitch/actual.js
vendored
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user