diff --git a/src/babel/transformation/transformers/es6/block-scoping.js b/src/babel/transformation/transformers/es6/block-scoping.js index 943f7716a0..39d43664d7 100644 --- a/src/babel/transformation/transformers/es6/block-scoping.js +++ b/src/babel/transformation/transformers/es6/block-scoping.js @@ -327,7 +327,7 @@ class BlockScoping { for (var name in outsideRefs) { var id = outsideRefs[name]; - if (this.scope.hasGlobal(id.name)) { + if (this.scope.hasGlobal(id.name) || this.scope.parentHasBinding(id.name)) { delete outsideRefs[id.name]; delete this.letReferences[id.name]; diff --git a/test/fixtures/transformation/es6-block-scoping/wrap-closure-shadow-variables/actual.js b/test/fixtures/transformation/es6-block-scoping/wrap-closure-shadow-variables/actual.js new file mode 100644 index 0000000000..33af2765a9 --- /dev/null +++ b/test/fixtures/transformation/es6-block-scoping/wrap-closure-shadow-variables/actual.js @@ -0,0 +1,5 @@ +let a = 1; +for (let a = 1; a < 100; a++) { + items.forEach(item => a); +} +console.log(a); diff --git a/test/fixtures/transformation/es6-block-scoping/wrap-closure-shadow-variables/expected.js b/test/fixtures/transformation/es6-block-scoping/wrap-closure-shadow-variables/expected.js new file mode 100644 index 0000000000..a2a9b24b01 --- /dev/null +++ b/test/fixtures/transformation/es6-block-scoping/wrap-closure-shadow-variables/expected.js @@ -0,0 +1,11 @@ +"use strict"; + +var a = 1; +for (var _a = 1; _a < 100; _a++) { + (function (_a) { + items.forEach(function (item) { + return _a; + }); + })(_a); +} +console.log(a);