-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Transformers (source & browserify)
- Loading branch information
1 parent
3912af9
commit 3d30ae6
Showing
6 changed files
with
111 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Module Dependencies | ||
*/ | ||
|
||
var path = require('path') | ||
var tools = path.dirname(require.resolve('react-tools')) | ||
var visitors = require(path.join(tools, 'vendor/fbtransform/visitors')).transformVisitors; | ||
var transform = require(path.join(tools, 'vendor/fbtransform/lib/transform')).transform; | ||
var through = require('through') | ||
|
||
/** | ||
* Exports | ||
*/ | ||
|
||
var Transformers = {}; | ||
|
||
Transformers.source = function(source) { | ||
return transform(visitors.react, source).code; | ||
}; | ||
|
||
Transformers.browserify = function(file) { | ||
var source = ''; | ||
|
||
return through(function(data) { | ||
source += data; | ||
}, function() { | ||
this.queue(Transformers.source(source)); | ||
this.queue(null); | ||
}); | ||
}; | ||
|
||
module.exports = Transformers; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* Module Dependencies | ||
*/ | ||
|
||
var Transformers = require('./lib/transformers.js'); | ||
|
||
/** | ||
* Exports | ||
*/ | ||
|
||
module.exports = Transformers; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
var Transformers = require('../lib/transformers'); | ||
var fs = require('fs'); | ||
|
||
exports.transformers = { | ||
setUp: function(done) { | ||
done(); | ||
}, | ||
source_js: function(test) { | ||
test.expect(1); | ||
|
||
var source = fs.readFileSync('tmp/default_options/js/fixture.js').toString(); | ||
var actual = Transformers.source(source); | ||
var expected = fs.readFileSync('tmp/default_options/js/fixture.js').toString(); | ||
|
||
test.equal(actual, expected, 'should leave vanilla JS alone'); | ||
test.done(); | ||
}, | ||
source_jsx: function(test) { | ||
test.expect(1); | ||
|
||
var source = fs.readFileSync('tmp/default_options/js/fixture-jsx.js').toString(); | ||
var actual = Transformers.source(source); | ||
var expected = fs.readFileSync('test/expected/default_options').toString(); | ||
|
||
test.equal(actual, expected, 'should convert JSX into JS'); | ||
test.done(); | ||
} | ||
}; |