@samitouri / QOS-React-2 / commits / e6c93f9246

Add optional harmony support to browser transform

This mirrors the react-tools API; it doesn't include support (yet) for transforming `<script type="text/jsx">` blocks with the ES6 transforms, mostly because I don't have a good API in mind there. Test Plan: Ran JSXTransformer.transform("var two = () => 2;", {harmony: true}).code in Chrome's dev console and got back some ES5 code.

Ben Alpert committed Mar 28, 2014 at 18:26 UTC e6c93f9246f2801e200864a74aec145410f13803
1 file changed +12 -5
vendor/browser-transforms.js
+12 -5
@@ -22,7 +22,7 @@ var headEl;
22
23 var buffer = require('buffer');
24 var transform = require('jstransform').transform;
25 -var visitors = require('./fbtransform/visitors').transformVisitors;
25 +var visitors = require('./fbtransform/visitors');
26 var docblock = require('jstransform/src/docblock');
27
28 // The source-map library relies on Object.defineProperty, but IE8 doesn't
@@ -31,16 +31,23 @@ var docblock = require('jstransform/src/docblock');
31 // the source map in that case.
32 var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__');
33
34 -function transformReact(source) {
35 - return transform(visitors.react, source, {
34 +function transformReact(source, options) {
35 + var visitorList;
36 + if (options && options.harmony) {
37 + visitorList = visitors.getAllVisitors();
38 + } else {
39 + visitorList = visitors.transformVisitors.react;
40 + }
41 +
42 + return transform(visitorList, source, {
43 sourceMap: supportsAccessors
44 });
45 }
46
47 exports.transform = transformReact;
48
42 -exports.exec = function(code) {
43 - return eval(transformReact(code).code);
49 +exports.exec = function(code, options) {
50 + return eval(transformReact(code, options).code);
51 };
52
53 var inlineScriptCount = 0;