Permalink
Browse files

[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
  • Loading branch information...
amasad committed May 22, 2015
1 parent 5bad316 commit 56d6ee3f0fadeb66aeb6cf9156c723759f48f617
Showing with 30 additions and 40 deletions.
  1. +30 −40 packager/transformer.js
View
@@ -10,40 +10,37 @@
*/
'use strict';
var jstransform = require('jstransform').transform;
var babel = require('babel');
var reactVisitors =
require('react-tools/vendor/fbtransform/visitors').getAllVisitors();
var staticTypeSyntax =
require('jstransform/visitors/type-syntax').visitorList;
var trailingCommaVisitors =
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',
function transform(srcTxt, filename, options) {
var result = babel.transform(srcTxt, {
retainLines: true,
compact: true,
comments: false,
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) {
@@ -54,15 +51,8 @@ module.exports = function(data, callback) {
data.filename
);
} catch (e) {
return callback(null, {
error: {
lineNumber: e.lineNumber,
column: e.column,
message: e.message,
stack: e.stack,
description: e.description
}
});
callback(e);
return;
}
callback(null, result);

1 comment on commit 56d6ee3

@nmn

This comment has been minimized.

Show comment
Hide comment
@nmn

nmn May 30, 2015

flow remains useless with most of ES6 and ES7, so don't use any new features if you want to typecheck.

nmn commented on 56d6ee3 May 30, 2015

flow remains useless with most of ES6 and ES7, so don't use any new features if you want to typecheck.

Please sign in to comment.