Skip to content

Commit

Permalink
Better JSX support via precinct module
Browse files Browse the repository at this point in the history
Issue pahen#61
  • Loading branch information
Dean Radcliffe committed May 3, 2016
1 parent edc6059 commit 319b8e8
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"jquery" : false,
"couch" : false,
"es5" : false,
"esnext": true,
"node" : true,
"rhino" : false,
"prototypejs" : false,
Expand Down Expand Up @@ -46,4 +47,4 @@
"describe",
"it"
]
}
}
4 changes: 1 addition & 3 deletions lib/parse/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ Base.prototype.getFileSource = function (filename) {
header: false,
bare: true
});
} else if (filename.match(this.jsxExtRegEx)) {
src = jsx.transform(src);
}

return src;
Expand All @@ -185,4 +183,4 @@ Base.prototype.sortDependencies = function () {
*/
Base.prototype.replaceBackslashInPath = function (path) {
return path.replace(/\\/g, '/');
};
};
6 changes: 3 additions & 3 deletions lib/parse/es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
var fs = require('fs'),
path = require('path'),
util = require('util'),
detective = require('detective-es6'),
precinct = require('precinct'),
colors = require('colors'),
Base = require('./base');

Expand Down Expand Up @@ -39,7 +39,7 @@ ES6.prototype.parseFile = function (filename) {
this.emit('parseFile', fileData);

if (/import.*from/m.test(fileData.src)) {
detective(fileData.src).map(function (id) {
precinct(fileData.src).map(function (id) {
var depFilename = this.resolve(path.dirname(fileData.filename), id);
if (depFilename) {
return this.normalize(depFilename);
Expand All @@ -61,4 +61,4 @@ ES6.prototype.parseFile = function (filename) {
}

return [];
};
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"detective": "^4.2.0",
"detective-es6": "1.1.2",
"graphviz": "0.0.8",
"precinct": "^2.5.1",
"react-tools": "^0.13.3",
"resolve": "^1.1.6",
"uglify-js": "^1.3.5",
Expand Down
1 change: 1 addition & 0 deletions test/files/es6/jsx/basic.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import other from './other';

export default React.createClass({
render: function() {
Expand Down
1 change: 1 addition & 0 deletions test/files/es6/jsx/other.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'other';
9 changes: 6 additions & 3 deletions test/jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ describe('JSX Basics', ()=>{
it('can detect imports', ()=>{
madge([__dirname + '/files/es6/jsx/basic.jsx'], {
format: 'es6'
}).obj().should.eql({basic: ['react']})
})
})
}).obj().should.eql({basic: [
'../../../../other',
'../../../../react'
]});
});
});

0 comments on commit 319b8e8

Please sign in to comment.