Skip to content

Commit

Permalink
Merge pull request #52 from fczuardi/issue_51
Browse files Browse the repository at this point in the history
change the referencer to support import as described in the ESTree spec (fixes #51)
  • Loading branch information
Constellation committed Mar 10, 2015
2 parents 19a2e45 + 8809f60 commit 0af92da
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);
node.local = (node.local || node.id);
if (node.local) {
this.visitImport(node.local, node);
}
}

ImportDefaultSpecifier(node) {
this.visitImport(node.id, node);
node.local = (node.local || node.id);
this.visitImport(node.local, node);
}

ImportSpecifier(node) {
node.local = (node.local || node.id);
if (node.name) {
this.visitImport(node.name, node);
} else {
this.visitImport(node.id, node);
this.visitImport(node.local, 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 0af92da

Please sign in to comment.