inline requires + preprocessor updates

Reviewed By: @DmitrySoshnikov

Differential Revision: D2455903
This commit is contained in:
Christoph Pojer 2015-09-19 15:20:25 -07:00 committed by facebook-github-bot-3
parent 9e37caebbb
commit 358b49597b
1 changed files with 16 additions and 13 deletions

View File

@ -10,20 +10,26 @@
*/ */
'use strict'; 'use strict';
var babel = require('babel-core'); const babel = require('babel-core');
const inlineRequires = require('fbjs-scripts/babel/inline-requires');
function transform(srcTxt, filename, options) { function transform(src, filename, options) {
var plugins = []; const plugins = [];
if (process.env.NODE_ENV === 'production') { if (process.env.NODE_ENV === 'production') {
plugins = plugins.concat(['node-env-inline', 'dunderscore-dev-inline']); plugins.push('node-env-inline', 'dunderscore-dev-inline');
} else if (process.env.NODE_ENV === 'test') {
plugins.push({
position: 'after',
transformer: inlineRequires,
});
} }
var result = babel.transform(srcTxt, { const result = babel.transform(src, {
retainLines: true, retainLines: true,
compact: true, compact: true,
comments: false, comments: false,
filename: filename, filename,
whitelist: [ whitelist: [
'es6.arrowFunctions', 'es6.arrowFunctions',
'es6.blockScoping', 'es6.blockScoping',
@ -42,24 +48,21 @@ function transform(srcTxt, filename, options) {
'react.displayName', 'react.displayName',
'regenerator', 'regenerator',
], ],
plugins: plugins, plugins,
sourceFileName: filename, sourceFileName: filename,
sourceMaps: false, sourceMaps: false,
extra: options || {}, extra: options || {},
}); });
return { return {
code: result.code, code: result.code
}; };
} }
module.exports = function(data, callback) { module.exports = function(data, callback) {
var result; let result;
try { try {
result = transform( result = transform(data.sourceCode, data.filename);
data.sourceCode,
data.filename
);
} catch (e) { } catch (e) {
callback(e); callback(e);
return; return;