diff --git a/src/referencer.js b/src/referencer.js index 7b592ce..5760c6e 100644 --- a/src/referencer.js +++ b/src/referencer.js @@ -83,6 +83,7 @@ function isPattern(node) { // Importing ImportDeclaration. // http://people.mozilla.org/~jorendorff/es6-draft.html#sec-moduledeclarationinstantiation +// https://github.com/estree/estree/blob/master/es6.md#importdeclaration // FIXME: Now, we don't create module environment, because the context is // implementation dependent. @@ -108,20 +109,23 @@ class Importer extends esrecurse.Visitor { } ImportNamespaceSpecifier(node) { - if (node.id) { - this.visitImport(node.id, node); + var nodeLocal = (node.local || node.id); + if (nodeLocal) { + this.visitImport(nodeLocal, node); } } ImportDefaultSpecifier(node) { - this.visitImport(node.id, node); + var nodeLocal = (node.local || node.id); + this.visitImport(nodeLocal, node); } ImportSpecifier(node) { + var nodeLocal = (node.local || node.id); if (node.name) { this.visitImport(node.name, node); } else { - this.visitImport(node.id, node); + this.visitImport(nodeLocal, node); } } } diff --git a/test/es6-import.coffee b/test/es6-import.coffee index 11d8a6b..5a178d5 100644 --- a/test/es6-import.coffee +++ b/test/es6-import.coffee @@ -22,13 +22,13 @@ # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. expect = require('chai').expect -harmony = require '../third_party/esprima' +harmony = require '../third_party/espree' escope = require '..' describe 'import declaration', -> # http://people.mozilla.org/~jorendorff/es6-draft.html#sec-static-and-runtme-semantics-module-records it 'should import names from source', -> - ast = harmony.parse """ + ast = harmony """ import v from "mod"; """, sourceType: 'module' @@ -48,7 +48,7 @@ describe 'import declaration', -> expect(scope.references).to.have.length 0 it 'should import namespaces', -> - ast = harmony.parse """ + ast = harmony """ import * as ns from "mod"; """, sourceType: 'module' @@ -68,7 +68,7 @@ describe 'import declaration', -> expect(scope.references).to.have.length 0 it 'should import insided names#1', -> - ast = harmony.parse """ + ast = harmony """ import {x} from "mod"; """, sourceType: 'module' @@ -88,7 +88,7 @@ describe 'import declaration', -> expect(scope.references).to.have.length 0 it 'should import insided names#2', -> - ast = harmony.parse """ + ast = harmony """ import {x as v} from "mod"; """, sourceType: 'module'