Register import bindings to the specifier instead of the declaration - fixes #2122

This commit is contained in:
Martin Muñoz 2015-07-30 04:42:50 -04:00
parent b91b4a4dc0
commit 75d78623f7
2 changed files with 18 additions and 14 deletions

View File

@ -171,27 +171,26 @@ export function referencesImport(moduleSource, importName) {
if (!binding || binding.kind !== "module") return false;
var path = binding.path;
if (!path.isImportDeclaration()) return false;
var parent = path.parentPath;
if (!parent.isImportDeclaration()) return false;
// check moduleSource
if (path.node.source.value === moduleSource) {
if (parent.node.source.value === moduleSource) {
if (!importName) return true;
} else {
return false;
}
for (var specifier of (path.node.specifiers: Array)) {
if (t.isSpecifierDefault(specifier) && importName === "default") {
return true;
}
if (path.isImportDefaultSpecifier() && importName === "default") {
return true;
}
if (t.isImportNamespaceSpecifier(specifier) && importName === "*") {
return true;
}
if (path.isImportNamespaceSpecifier() && importName === "*") {
return true;
}
if (t.isImportSpecifier(specifier) && specifier.imported.name === importName) {
return true;
}
if (path.isImportSpecifier() && path.node.imported.name === importName) {
return true;
}
return false;

View File

@ -540,8 +540,13 @@ export default class Scope {
}
} else if (path.isClassDeclaration()) {
this.registerBinding("let", path);
} else if (path.isImportDeclaration() || path.isExportDeclaration()) {
this.registerBinding("module", path);
} else if (path.isImportDeclaration()) {
var specifiers = path.get("specifiers");
for (var specifier of (specifiers: Array)) {
this.registerBinding("module", specifier);
}
} else if (path.isExportDeclaration()) {
this.registerBinding("module", path.get("declaration"));
} else {
this.registerBinding("unknown", path);
}