'use strict';

var visitors = require('./vendor/fbtransform/visitors');
var transform = require('jstransform').transform;

module.exports = {
  transform: function(code, options) {
    var visitorList;
    if (options && options.harmony) {
      visitorList = visitors.getAllVisitors();
    } else {
      visitorList = visitors.transformVisitors.react;
    }
    return transform(visitorList, code).code;
  }
};

'use strict';

var visitors = require('./vendor/fbtransform/visitors');
var transform = require('jstransform').transform;
var Buffer = require('buffer').Buffer;

module.exports = {
  React: React,
  transform: function(input, options) {
    options = options || {};
    var result = transform(visitors.react, input, options);
    var output = result.code;
    if (options.sourceMap) {
      var map = inlineSourceMap(
        result.sourceMap,
        input,
        options.sourceFilename
      );
      output += '\n' + map;
    }
    return output;
  }
};

function inlineSourceMap(sourceMap, sourceCode, sourceFilename) {
  var json = sourceMap.toJSON();
  json.sources = [ sourceFilename ];
  json.sourcesContent = [ sourceCode ];
  var base64 = Buffer(JSON.stringify(json)).toString('base64');
  return '//# sourceMappingURL=data:application/json;base64,' +
         base64;
}

Add sourceMap option to react-tools transform
Add sourceMap option to react-tools transform

Allow tools like grunt-react to include inline source maps in the
generated JavaScript. Browserify can then combine these source maps when
bundling everything together.

Usage:

```
var transform = require('react-tools').transform;
var output = transform(jsxContent, {
  sourceMap: true,
  sourceFilename: 'source.jsx'
});
```

The `output` will have an inline source map comment appended.
