From 3f38a836008323ee21f67fdbec123ac68f638537 Mon Sep 17 00:00:00 2001 From: Logan Smyth Date: Wed, 1 Jul 2015 22:06:05 -0700 Subject: [PATCH] Properly regenerate scope for replaced nodes - fixes #1773 --- src/babel/traversal/scope/index.js | 2 +- .../transformation/es6.classes/constructor/actual.js | 9 +++++++++ .../es6.classes/constructor/expected.js | 11 ++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/babel/traversal/scope/index.js b/src/babel/traversal/scope/index.js index 158c85388a..646666738c 100644 --- a/src/babel/traversal/scope/index.js +++ b/src/babel/traversal/scope/index.js @@ -146,7 +146,7 @@ export default class Scope { } var cached = path.getData("scope"); - if (cached && cached.parent === parent) { + if (cached && cached.parent === parent && cached.block === path.node) { return cached; } else { path.setData("scope", this); diff --git a/test/core/fixtures/transformation/es6.classes/constructor/actual.js b/test/core/fixtures/transformation/es6.classes/constructor/actual.js index c968e6c108..33c274123a 100644 --- a/test/core/fixtures/transformation/es6.classes/constructor/actual.js +++ b/test/core/fixtures/transformation/es6.classes/constructor/actual.js @@ -10,3 +10,12 @@ class Foo extends Bar { this.state = "test"; } } + +class ConstructorScoping { + constructor(){ + let bar; + { + let bar; + } + } +} diff --git a/test/core/fixtures/transformation/es6.classes/constructor/expected.js b/test/core/fixtures/transformation/es6.classes/constructor/expected.js index 7169ce082f..9aefa96a1c 100644 --- a/test/core/fixtures/transformation/es6.classes/constructor/expected.js +++ b/test/core/fixtures/transformation/es6.classes/constructor/expected.js @@ -16,4 +16,13 @@ var Foo = (function (_Bar) { babelHelpers.inherits(Foo, _Bar); return Foo; -})(Bar); \ No newline at end of file +})(Bar); + +var ConstructorScoping = function ConstructorScoping() { + babelHelpers.classCallCheck(this, ConstructorScoping); + + var bar = undefined; + { + var _bar = undefined; + } +};