Register import bindings to the specifier instead of the declaration - fixes #2122
This commit is contained in:
parent
b91b4a4dc0
commit
75d78623f7
@ -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;
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user