fix scope assignment to switch expressions (#5826)
fixes #5787 fixes #5792
This commit is contained in:
@@ -178,6 +178,13 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
|||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (node instanceof AST_Switch) {
|
||||||
|
node.expression.walk(tw);
|
||||||
|
walk_scope(function() {
|
||||||
|
walk_body(node, tw);
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (node instanceof AST_SwitchBranch) {
|
if (node instanceof AST_SwitchBranch) {
|
||||||
node.init_vars(scope);
|
node.init_vars(scope);
|
||||||
descend();
|
descend();
|
||||||
|
|||||||
@@ -2204,3 +2204,30 @@ issue_5660: {
|
|||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_5787: {
|
||||||
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
const a = 42;
|
||||||
|
switch (a) {
|
||||||
|
case 42:
|
||||||
|
const a = "PASS";
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
const a = 42;
|
||||||
|
switch (a) {
|
||||||
|
case 42:
|
||||||
|
const a = "PASS";
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|||||||
@@ -2537,3 +2537,32 @@ issue_5759: {
|
|||||||
]
|
]
|
||||||
node_version: ">=4"
|
node_version: ">=4"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_5787: {
|
||||||
|
options = {
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
let a = 42;
|
||||||
|
switch (a) {
|
||||||
|
case 42:
|
||||||
|
// Node.js v4 (vm): SyntaxError: Identifier 'a' has already been declared
|
||||||
|
let a = "PASS";
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
let a = 42;
|
||||||
|
switch (a) {
|
||||||
|
case 42:
|
||||||
|
let a = "PASS";
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|||||||
@@ -739,3 +739,55 @@ issue_3480_ie8_toplevel: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_5787_1: {
|
||||||
|
rename = true
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
const a = 42;
|
||||||
|
switch (a) {
|
||||||
|
case 42:
|
||||||
|
const a = "PASS";
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
const a = 42;
|
||||||
|
switch (a) {
|
||||||
|
case 42:
|
||||||
|
const a = "PASS";
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_5787_2: {
|
||||||
|
rename = true
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
let a = 42;
|
||||||
|
switch (a) {
|
||||||
|
case 42:
|
||||||
|
// Node.js v4 (vm): SyntaxError: Identifier 'a' has already been declared
|
||||||
|
let a = "PASS";
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
let a = 42;
|
||||||
|
switch (a) {
|
||||||
|
case 42:
|
||||||
|
let b = "PASS";
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user