fix collisions for getBindingIdentifiers

This commit is contained in:
Sebastian McKenzie 2015-06-29 22:04:17 +01:00
parent 2d289150d1
commit 541309c4bb
3 changed files with 31 additions and 24 deletions

View File

@ -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);
}

View File

@ -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
});
}
}

View File

@ -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);