[react-native] Replace jstransform with Babel in the OSS repo

Summary:
@public
Replaces jstransform with Babel. Additionally, stops (using the deprecated) passing an error property
back from the transformer, and instead passes an error in the first argument. This is because we were
able to update node-worker-farm to handle custom properties on errors.

Test Plan:
1. Export the oss project
2. npm install
3. Start the movies app
4. Make sure it works
5. Add a syntax error
6. Make sure the message is correct
This commit is contained in:
Amjad Masad 2015-05-22 12:16:15 -07:00
Родитель 5bad316678
Коммит 56d6ee3f0f
1 изменённых файлов: 30 добавлений и 40 удалений

Просмотреть файл

@ -10,40 +10,37 @@
*/ */
'use strict'; 'use strict';
var jstransform = require('jstransform').transform; var babel = require('babel');
var reactVisitors = function transform(srcTxt, filename, options) {
require('react-tools/vendor/fbtransform/visitors').getAllVisitors(); var result = babel.transform(srcTxt, {
var staticTypeSyntax = retainLines: true,
require('jstransform/visitors/type-syntax').visitorList; compact: true,
var trailingCommaVisitors = comments: false,
require('jstransform/visitors/es7-trailing-comma-visitors.js').visitorList;
// Note that reactVisitors now handles ES6 classes, rest parameters, arrow
// functions, template strings, and object short notation.
var visitorList = reactVisitors.concat(trailingCommaVisitors);
function transform(srcTxt, filename) {
var options = {
es3: true,
sourceType: 'nonStrictModule',
filename: filename, filename: filename,
whitelist: [
'es6.arrowFunctions',
'es6.blockScoping',
'es6.classes',
'es6.destructuring',
'es6.parameters.rest',
'es6.properties.computed',
'es6.properties.shorthand',
'es6.spread',
'es6.templateLiterals',
'es7.trailingFunctionCommas',
'es7.objectRestSpread',
'flow',
'react',
],
sourceFileName: filename,
sourceMaps: false,
extra: options || {},
});
return {
code: result.code,
}; };
// These tranforms mostly just erase type annotations and static typing
// related statements, but they were conflicting with other tranforms.
// Running them first solves that problem
var staticTypeSyntaxResult = jstransform(
staticTypeSyntax,
srcTxt,
options
);
return jstransform(
visitorList,
staticTypeSyntaxResult.code,
options
);
} }
module.exports = function(data, callback) { module.exports = function(data, callback) {
@ -54,15 +51,8 @@ module.exports = function(data, callback) {
data.filename data.filename
); );
} catch (e) { } catch (e) {
return callback(null, { callback(e);
error: { return;
lineNumber: e.lineNumber,
column: e.column,
message: e.message,
stack: e.stack,
description: e.description
}
});
} }
callback(null, result); callback(null, result);