Skip discriminant when renaming starting from SwitchStatement (#12530)

This commit is contained in:
Zen 2020-12-22 10:10:43 +08:00 committed by GitHub
parent 814212f0be
commit e08f68bf61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 1 deletions

View File

@ -0,0 +1,20 @@
window.test = () => {
const e = "TEST";
switch (e) {
case "TEST":
const e = [];
e.push('111');
alert(e);
break;
default: alert('666'); break;
}
};
window.test = () => {
const e = "TEST";
switch (e) {
case "TEST":
const e = [];
switch(e) {}
}
};

View File

@ -0,0 +1,29 @@
window.test = function () {
var e = "TEST";
switch (e) {
case "TEST":
var _e = [];
_e.push('111');
alert(_e);
break;
default:
alert('666');
break;
}
};
window.test = function () {
var e = "TEST";
switch (e) {
case "TEST":
var _e2 = [];
switch (_e2) {}
}
};

View File

@ -119,7 +119,15 @@ export default class Renamer {
}
}
scope.traverse(block || scope.block, renameVisitor, this);
const blockToTraverse = block || scope.block;
if (blockToTraverse?.type === "SwitchStatement") {
// discriminant is not part of current scope, should be skipped.
blockToTraverse.cases.forEach(c => {
scope.traverse(c, renameVisitor, this);
});
} else {
scope.traverse(blockToTraverse, renameVisitor, this);
}
if (!block) {
scope.removeOwnBinding(oldName);