Skip to content

Commit

Permalink
change the referencer to support import declarations as described in …
Browse files Browse the repository at this point in the history
…the ESTree spec (fixes estools#51)
  • Loading branch information
fczuardi committed Mar 9, 2015
1 parent 19a2e45 commit 2360f83
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
12 changes: 8 additions & 4 deletions src/referencer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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);
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions test/es6-import.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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'

Expand All @@ -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'

Expand All @@ -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'

Expand Down

0 comments on commit 2360f83

Please sign in to comment.