Permalink
Browse files

Improve transform speed by 8.5%

Reviewed By: jeanlauliac

Differential Revision: D5443966

fbshipit-source-id: 06a151f44b7b9f8307be2ea47ce35deb3663869f
  • Loading branch information...
cpojer authored and facebook-github-bot committed Jul 21, 2017
1 parent 365aea3 commit 4caf79471b144a6a8098730c226e90fb5ae8b9c6
Showing with 74 additions and 46 deletions.
  1. +0 −16 babel-preset/configs/internal.js
  2. +74 −30 babel-preset/configs/main.js

This file was deleted.

Oops, something went wrong.
@@ -5,55 +5,99 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @format
*/
'use strict';
var resolvePlugins = require('../lib/resolvePlugins');
var base = {
comments: false,
compact: true,
plugins: resolvePlugins([
'syntax-async-functions',
const getPreset = (src, options) => {
const plugins = [];
const isNull = src === null || src === undefined;
const hasClass = isNull || src.indexOf('class') !== -1;
const hasForOf =
isNull || (src.indexOf('for') !== -1 && src.indexOf('of') !== -1);
plugins.push(
'syntax-class-properties',
'syntax-trailing-function-commas',
'transform-class-properties',
'transform-es2015-function-name',
'transform-es2015-arrow-functions',
'transform-es2015-block-scoping',
'transform-es2015-classes',
'transform-es2015-computed-properties',
'check-es2015-constants',
'transform-es2015-destructuring',
['transform-es2015-modules-commonjs', { strict: false, allowTopLevelThis: true }],
'transform-es2015-function-name',
'transform-es2015-literals',
'transform-es2015-parameters',
'transform-es2015-shorthand-properties',
'transform-es2015-spread',
'transform-es2015-template-literals',
'transform-es2015-literals',
'transform-flow-strip-types',
'transform-object-assign',
'transform-object-rest-spread',
'transform-react-display-name',
'transform-react-jsx',
'transform-regenerator',
['transform-es2015-for-of', { loose: true }],
require('../transforms/transform-regenerator-runtime-insertion'),
require('../transforms/transform-symbol-member'),
]),
};
[
'transform-es2015-modules-commonjs',
{strict: false, allowTopLevelThis: true},
],
);
if (isNull || src.indexOf('async') !== -1 || src.indexOf('await') !== -1) {
plugins.push('syntax-async-functions');
}
if (hasClass) {
plugins.push('transform-es2015-classes');
}
if (isNull || src.indexOf('=>') !== -1) {
plugins.push('transform-es2015-arrow-functions');
}
if (isNull || src.indexOf('const') !== -1) {
plugins.push('check-es2015-constants');
}
if (isNull || hasClass || src.indexOf('...') !== -1) {
plugins.push('transform-es2015-spread');
plugins.push('transform-object-rest-spread');
}
if (isNull || src.indexOf('`') !== -1) {
plugins.push('transform-es2015-template-literals');
}
if (isNull || src.indexOf('Object.assign') !== -1) {
plugins.push('transform-object-assign');
}
if (hasForOf) {
plugins.push(['transform-es2015-for-of', {loose: true}]);
}
if (hasForOf || src.indexOf('Symbol') !== -1) {
plugins.push(require('../transforms/transform-symbol-member'));
}
if (
isNull ||
src.indexOf('React.createClass') !== -1 ||
src.indexOf('createReactClass') !== -1
) {
plugins.push('transform-react-display-name');
}
var devTools = Object.assign({}, base);
devTools.plugins = devTools.plugins.concat(
resolvePlugins(['transform-react-jsx-source'])
);
if (options && options.dev) {
plugins.push('transform-react-jsx-source');
}
return {
comments: false,
compact: true,
plugins: resolvePlugins(plugins),
};
};
module.exports = function(options) {
var withDevTools = options.withDevTools;
if (withDevTools == null) {
var env = process.env.BABEL_ENV || process.env.NODE_ENV;
withDevTools = !env || env === 'development';
const base = getPreset(null);
const devTools = getPreset(null, {dev: true});
module.exports = options => {
if (options.withDevTools == null) {
const env = process.env.BABEL_ENV || process.env.NODE_ENV;
if (!env || env === 'development') {
return devTools;
}
}
return withDevTools ? devTools : base;
return base;
};
module.exports.getPreset = getPreset;

1 comment on commit 4caf794

@orta

This comment has been minimized.

Show comment
Hide comment
@orta

orta Jul 21, 2017

Contributor

💯 impressive

Contributor

orta commented on 4caf794 Jul 21, 2017

💯 impressive

Please sign in to comment.