Fix scope of catch block (#5980)

* Fix scope of catch block

* Throw error on Duplicate variable declaration

* Update test
This commit is contained in:
Boopathi Rajaa
2017-08-08 22:26:29 +02:00
committed by Justin Ridgewell
parent 009d7f0b76
commit ab76cb6b53
6 changed files with 9 additions and 13 deletions

View File

@@ -0,0 +1 @@
try {} catch (a) { let a }

View File

@@ -0,0 +1,3 @@
{
"throws": "Duplicate declaration \"a\""
}

View File

@@ -8,9 +8,3 @@ for (let a in [1, 2, 3]) {
let a = 3;
console.log(a);
}
try {
throw new Error();
} catch(a) {
let a = 4;
}

View File

@@ -8,9 +8,3 @@ for (var _a2 in [1, 2, 3]) {
var _a3 = 3;
console.log(_a3);
}
try {
throw new Error();
} catch (_a4) {
var _a5 = 4;
}

View File

@@ -154,7 +154,7 @@ defineType("CatchClause", {
validate: assertNodeType("BlockStatement"),
},
},
aliases: ["Scopable"],
aliases: ["Scopable", "BlockParent"],
});
defineType("ConditionalExpression", {

View File

@@ -231,6 +231,10 @@ export function isScope(node: Object, parent: Object): boolean {
return false;
}
if (t.isBlockStatement(node) && t.isCatchClause(parent, { body: node })) {
return false;
}
return t.isScopable(node);
}