From 4b297907d1f4d308aeceaca7809ff0aecb9235cf Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Fri, 25 Aug 2017 19:23:11 -0400 Subject: [PATCH] Move fix into #checkBlockScopedCollisions --- packages/babel-traverse/src/scope/index.js | 8 ++++---- .../regression/constant-shadows-function-name/actual.js | 8 ++++++++ .../regression/constant-shadows-function-name/expected.js | 7 +++++++ 3 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 packages/babel-traverse/test/fixtures/regression/constant-shadows-function-name/actual.js create mode 100644 packages/babel-traverse/test/fixtures/regression/constant-shadows-function-name/expected.js diff --git a/packages/babel-traverse/src/scope/index.js b/packages/babel-traverse/src/scope/index.js index f9c1ab22e2..8e5950bf28 100644 --- a/packages/babel-traverse/src/scope/index.js +++ b/packages/babel-traverse/src/scope/index.js @@ -346,6 +346,10 @@ export default class Scope { // ignore parameters if (kind === "param") return; + // Ignore existing binding if it's the name of the current function or + // class expression + if (local.kind === "local") return; + // ignore hoisted functions if there's also a local let if (kind === "hoisted" && local.kind === "let") return; @@ -520,10 +524,6 @@ export default class Scope { for (const id of (ids[name]: Array)) { let local = this.getOwnBinding(name); - // Ignore existing binding if it's the name of the current function or class - // expression - if (local && local.kind === "local") local = null; - if (local) { // same identifier so continue safely as we're likely trying to register it // multiple times diff --git a/packages/babel-traverse/test/fixtures/regression/constant-shadows-function-name/actual.js b/packages/babel-traverse/test/fixtures/regression/constant-shadows-function-name/actual.js new file mode 100644 index 0000000000..f56e906e25 --- /dev/null +++ b/packages/babel-traverse/test/fixtures/regression/constant-shadows-function-name/actual.js @@ -0,0 +1,8 @@ +let obj = { + foo: function foo() { + let foo = true; + console.log('foo ran'); + } +}; + +obj.foo(); diff --git a/packages/babel-traverse/test/fixtures/regression/constant-shadows-function-name/expected.js b/packages/babel-traverse/test/fixtures/regression/constant-shadows-function-name/expected.js new file mode 100644 index 0000000000..1a47048c09 --- /dev/null +++ b/packages/babel-traverse/test/fixtures/regression/constant-shadows-function-name/expected.js @@ -0,0 +1,7 @@ +let obj = { + foo: function foo() { + let foo = true; + console.log('foo ran'); + } +}; +obj.foo();