diff --git a/packages/babel/src/traversal/path/introspection.js b/packages/babel/src/traversal/path/introspection.js index 804e06d9d1..0adafb130b 100644 --- a/packages/babel/src/traversal/path/introspection.js +++ b/packages/babel/src/traversal/path/introspection.js @@ -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; diff --git a/packages/babel/src/traversal/scope/index.js b/packages/babel/src/traversal/scope/index.js index 2c91c5ed14..884bbde849 100644 --- a/packages/babel/src/traversal/scope/index.js +++ b/packages/babel/src/traversal/scope/index.js @@ -537,8 +537,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); }