diff --git a/packages/babel-plugin-transform-es2015-block-scoping/src/index.js b/packages/babel-plugin-transform-es2015-block-scoping/src/index.js index 6f21235196..eb27618ae3 100644 --- a/packages/babel-plugin-transform-es2015-block-scoping/src/index.js +++ b/packages/babel-plugin-transform-es2015-block-scoping/src/index.js @@ -524,7 +524,11 @@ class BlockScoping { // for (let i = 0; i < declarators.length; i++) { let declar = declarators[i]; - let keys = t.getBindingIdentifiers(declar); + // Passing true as the third argument causes t.getBindingIdentifiers + // to return only the *outer* binding identifiers of this + // declaration, rather than (for example) mistakenly including the + // parameters of a function declaration. Fixes #4880. + let keys = t.getBindingIdentifiers(declar, false, true); extend(this.letReferences, keys); this.hasLetReferences = true; } diff --git a/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/function-in-catch/actual.js b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/function-in-catch/actual.js new file mode 100644 index 0000000000..c38a4caa3a --- /dev/null +++ b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/function-in-catch/actual.js @@ -0,0 +1,7 @@ +try { + foo(); +} catch (x) { + function harmless(x) { + return x; + } +} diff --git a/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/function-in-catch/expected.js b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/function-in-catch/expected.js new file mode 100644 index 0000000000..9403930476 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-block-scoping/test/fixtures/general/function-in-catch/expected.js @@ -0,0 +1,7 @@ +try { + foo(); +} catch (x) { + var harmless = function (x) { + return x; + }; +}