Skip to content

Commit

Permalink
Support for es6 re-export syntax (#91)
Browse files Browse the repository at this point in the history
* Add support for re-export syntax

e.g.:

export { a } from './a'k
export a from './a'
export * as a from './a'

* update npm-shrinkwrap.json

* should should -> should, ^1.1.5 -> 1.1.5
  • Loading branch information
olalonde authored and pahen committed Jun 28, 2016
1 parent 24ba180 commit 5deb37f
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 41 deletions.
2 changes: 1 addition & 1 deletion lib/parse/es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ ES6.prototype.parseFile = function (filename) {

this.emit('parseFile', fileData);

if (/import.*from/m.test(fileData.src)) {
if (/import.*from/m.test(fileData.src) || /export.*from/m.test(fileData.src)) {
detective(fileData.src).map(function (id) {
var depFilename = this.resolve(path.dirname(fileData.filename), id);
if (depFilename) {
Expand Down
111 changes: 73 additions & 38 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"commander": "^2.8.1",
"commondir": "^1.0.1",
"detective": "^4.2.0",
"detective-es6": "1.1.4",
"detective-es6": "1.1.5",
"graphviz": "0.0.8",
"react-tools": "^0.13.3",
"resolve": "^1.1.6",
Expand Down
8 changes: 7 additions & 1 deletion test/es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@ describe('module format (ES6)', function () {
}).obj().should.eql({ 'jsx': [ 'absolute/b' ] });
});

it('should should find imports on files with ES7', function() {
it('should find imports on files with ES7', function() {
madge([__dirname + '/files/es6/async.js'], {
format: 'es6'
}).obj().should.eql({ 'async': [ 'absolute/b' ] });
});

it('should support export x from "./file"', function() {
madge([__dirname + '/files/es6/re-export'], {
format: 'es6'
}).obj().should.eql({ 'a': [], 'b-default': ['a'], 'b-named': ['a'], 'b-star': ['a'], 'c': ['b-default', 'b-named', 'b-star'] });
});
});
2 changes: 2 additions & 0 deletions test/files/es6/re-export/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export default 'default export value';
export const named = 'named';
1 change: 1 addition & 0 deletions test/files/es6/re-export/b-default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export someDefault from './a'
1 change: 1 addition & 0 deletions test/files/es6/re-export/b-named.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { named } from './a';
1 change: 1 addition & 0 deletions test/files/es6/re-export/b-star.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './a'
3 changes: 3 additions & 0 deletions test/files/es6/re-export/c.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { named } from './b-named'
import { someDefault } from './b-default'
import star from './b-star'

0 comments on commit 5deb37f

Please sign in to comment.