fix collisions for getBindingIdentifiers
This commit is contained in:
parent
2d289150d1
commit
541309c4bb
@ -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);
|
||||
}
|
||||
|
||||
@ -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
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user