diff --git a/src/babel/traversal/path/family.js b/src/babel/traversal/path/family.js index 8e91a40128..f13780528c 100644 --- a/src/babel/traversal/path/family.js +++ b/src/babel/traversal/path/family.js @@ -142,6 +142,6 @@ export function _getPattern(parts) { * Description */ -export function getBindingIdentifiers() { - return t.getBindingIdentifiers(this.node); +export function getBindingIdentifiers(duplicates?) { + return t.getBindingIdentifiers(this.node, duplicates); } diff --git a/src/babel/traversal/scope/index.js b/src/babel/traversal/scope/index.js index d93da2995d..5d65323e1d 100644 --- a/src/babel/traversal/scope/index.js +++ b/src/babel/traversal/scope/index.js @@ -491,32 +491,34 @@ export default class Scope { } var parent = this.getProgramParent(); - var ids = path.getBindingIdentifiers(); + var ids = path.getBindingIdentifiers(true); for (var name in ids) { - var id = ids[name]; + for (var id of (ids[name]: Array)) { + console.log(); - var local = this.getOwnBinding(name); - if (local) { - // don't ever let a type alias shadow a local binding - if (kind === "type") continue; + var local = this.getOwnBinding(name); + if (local) { + // don't ever let a type alias shadow a local binding + if (kind === "type") continue; - // same identifier so continue safely as we're likely trying to register it - // multiple times - if (local.identifier === id) continue; + // same identifier so continue safely as we're likely trying to register it + // multiple times + if (local.identifier === id) continue; - this.checkBlockScopedCollisions(local, kind, name, id); + this.checkBlockScopedCollisions(local, kind, name, id); + } + + parent.references[name] = true; + + this.bindings[name] = new Binding({ + identifier: id, + existing: local, + scope: this, + path: path, + kind: kind + }); } - - parent.references[name] = true; - - this.bindings[name] = new Binding({ - identifier: id, - existing: local, - scope: this, - path: path, - kind: kind - }); } } diff --git a/src/babel/types/retrievers.js b/src/babel/types/retrievers.js index 174d15d6de..64eb1bdf60 100644 --- a/src/babel/types/retrievers.js +++ b/src/babel/types/retrievers.js @@ -5,7 +5,7 @@ import * as t from "./index"; * Return a list of binding identifiers associated with the input `node`. */ -export function getBindingIdentifiers(node: Object): Object { +export function getBindingIdentifiers(node: Object, duplicates?): Object { var search = [].concat(node); var ids = object(); @@ -16,7 +16,12 @@ export function getBindingIdentifiers(node: Object): Object { var key = t.getBindingIdentifiers.keys[id.type]; if (t.isIdentifier(id)) { - ids[id.name] = id; + if (duplicates) { + var _ids = ids[id.name] = ids[id.name] || []; + _ids.push(id); + } else { + ids[id.name] = id; + } } else if (t.isExportDeclaration(id)) { if (t.isDeclaration(node.declaration)) { search.push(node.declaration);