Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update React-tools to support transform as object #1783

Merged
merged 4 commits into from
Jul 11, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 21 additions & 8 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,35 @@ var Buffer = require('buffer').Buffer;

module.exports = {
transform: function(input, options) {
options = options || {};
var visitorList = getVisitors(options.harmony);
var result = transform(visitorList, input, options);
var output = result.code;
if (options.sourceMap) {
var output = innerTransform(input, options);
var result = output.code;
if (options && options.sourceMap) {
var map = inlineSourceMap(
result.sourceMap,
output.sourceMap,
input,
options.sourceFilename
);
output += '\n' + map;
result += '\n' + map;
}
return output;
return result;
},
transformWithDetails: function(input, options) {
var output = innerTransform(input, options);
var result = {};
result.code = output.code;
if (options && options.sourceMap) {
result.sourceMap = output.sourceMap.toJSON();
}
return result;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transform has all of this code. Let's reuse - transform can call transformAsObject then do it's additional sourcemap inline.

Also, I'm not wild about transformAsObject as a name, but don't know what else I would call it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya I wasn't wild about transformAsObject as object but since transform was taken and we can't really change the existing transform to transformResult or something similar, that was what I came up with. Happy to change if we can come up with anything better.

}
};

function innerTransform(input, options) {
options = options || {};
var visitorList = getVisitors(options.harmony);
return transform(visitorList, input, options);
}

function getVisitors(harmony) {
if (harmony) {
return visitors.getAllVisitors();
Expand Down