diff --git a/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/issue-5979/actual.js b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/issue-5979/actual.js new file mode 100644 index 0000000000..301ed2e804 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/issue-5979/actual.js @@ -0,0 +1 @@ +try {} catch (a) { let a } diff --git a/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/issue-5979/options.json b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/issue-5979/options.json new file mode 100644 index 0000000000..ca26076ba7 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/issue-5979/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Duplicate declaration \"a\"" +} diff --git a/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/issue-T7525/actual.js b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/issue-T7525/actual.js index 594252c54d..2e78b6cffe 100644 --- a/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/issue-T7525/actual.js +++ b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/issue-T7525/actual.js @@ -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; -} \ No newline at end of file diff --git a/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/issue-T7525/expected.js b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/issue-T7525/expected.js index 4d9327a55f..f82e5391ed 100644 --- a/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/issue-T7525/expected.js +++ b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/issue-T7525/expected.js @@ -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; -} diff --git a/packages/babel-types/src/definitions/core.js b/packages/babel-types/src/definitions/core.js index 93157cc7ed..1f8f165812 100644 --- a/packages/babel-types/src/definitions/core.js +++ b/packages/babel-types/src/definitions/core.js @@ -154,7 +154,7 @@ defineType("CatchClause", { validate: assertNodeType("BlockStatement"), }, }, - aliases: ["Scopable"], + aliases: ["Scopable", "BlockParent"], }); defineType("ConditionalExpression", { diff --git a/packages/babel-types/src/validators.js b/packages/babel-types/src/validators.js index 14741ad4b7..81497ae367 100644 --- a/packages/babel-types/src/validators.js +++ b/packages/babel-types/src/validators.js @@ -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); }