Skip to content

Commit

Permalink
Fully support ES6 export declaration with estree spec
Browse files Browse the repository at this point in the history
Already tested with test/es6-export.coffee.
Ref #51
  • Loading branch information
Constellation committed Mar 10, 2015
1 parent 50978c1 commit dcb3231
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"dependencies": {
"es6-map": "^0.1.1",
"es6-weak-map": "^0.1.2",
"esrecurse": "^1.2.0",
"estraverse": "^1.9.1"
"esrecurse": "^2.0.0",
"estraverse": "^2.0.0"
},
"devDependencies": {
"browserify": "^9.0.3",
Expand Down
13 changes: 11 additions & 2 deletions src/referencer.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ export default class Referencer extends esrecurse.Visitor {
importer.visit(node);
}

ExportDeclaration(node) {
visitExportDeclaration(node) {
if (node.source) {
return;
}
Expand All @@ -571,8 +571,17 @@ export default class Referencer extends esrecurse.Visitor {
this.visitChildren(node);
}

ExportDeclaration(node) {
this.visitExportDeclaration(node);
}

ExportNamedDeclaration(node) {
this.visitExportDeclaration(node);
}

ExportSpecifier(node) {
this.visit(node.id);
let local = (node.id || node.local);
this.visit(local);
}
}

Expand Down
21 changes: 11 additions & 10 deletions test/es6-export.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'
espree = require '../third_party/espree'
escope = require '..'

describe 'export declaration', ->
# http://people.mozilla.org/~jorendorff/es6-draft.html#sec-static-and-runtme-semantics-module-records
it 'should create vairable bindings', ->
ast = harmony.parse """
ast = espree """
export var v;
""", sourceType: 'module'

Expand All @@ -47,7 +47,7 @@ describe 'export declaration', ->
expect(scope.references).to.have.length 0

it 'should create function declaration bindings', ->
ast = harmony.parse """
ast = espree """
export default function f(){};
""", sourceType: 'module'

Expand All @@ -73,7 +73,7 @@ describe 'export declaration', ->


it 'should export function expression', ->
ast = harmony.parse """
ast = espree """
export default function(){};
""", sourceType: 'module'

Expand All @@ -96,7 +96,7 @@ describe 'export declaration', ->
expect(scope.references).to.have.length 0

it 'should export literal', ->
ast = harmony.parse """
ast = espree """
export default 42;
""", sourceType: 'module'

Expand All @@ -113,7 +113,7 @@ describe 'export declaration', ->
expect(scope.references).to.have.length 0

it 'should refer exported references#1', ->
ast = harmony.parse """
ast = espree """
export {x};
""", sourceType: 'module'

Expand All @@ -131,7 +131,7 @@ describe 'export declaration', ->
expect(scope.references[0].identifier.name).to.be.equal 'x'

it 'should refer exported references#2', ->
ast = harmony.parse """
ast = espree """
export {v as x};
""", sourceType: 'module'

Expand All @@ -149,7 +149,7 @@ describe 'export declaration', ->
expect(scope.references[0].identifier.name).to.be.equal 'v'

it 'should not refer exported references from other source#1', ->
ast = harmony.parse """
ast = espree """
export {x} from "mod";
""", sourceType: 'module'

Expand All @@ -163,10 +163,11 @@ describe 'export declaration', ->
scope = scopeManager.scopes[1]
expect(scope.type).to.be.equal 'module'
expect(scope.variables).to.have.length 0
console.log(scope.references)
expect(scope.references).to.have.length 0

it 'should not refer exported references from other source#2', ->
ast = harmony.parse """
ast = espree """
export {v as x} from "mod";
""", sourceType: 'module'

Expand All @@ -183,7 +184,7 @@ describe 'export declaration', ->
expect(scope.references).to.have.length 0

it 'should not refer exported references from other source#3', ->
ast = harmony.parse """
ast = espree """
export * from "mod";
""", sourceType: 'module'

Expand Down

0 comments on commit dcb3231

Please sign in to comment.