Use Object.assign directly and inject object-assign at compile

This commit is contained in:
Paul O’Shannessy
2016-04-04 09:53:25 -07:00
parent b0d1e16271
commit 1573baaee8
45 changed files with 123 additions and 150 deletions
@@ -0,0 +1,40 @@
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* 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.
*/
'use strict';
module.exports = function autoImporter(babel) {
const t = babel.types;
return {
pre: function() {
// map from module to generated identifier
this.id = null;
},
visitor: {
CallExpression: function(path, file) {
if (path.get('callee').matchesPattern('Object.assign')) {
// generate identifier and require if it hasn't been already
if (!this.id) {
this.id = path.scope.generateUidIdentifier('assign');
path.scope.getProgramParent().push({
id: this.id,
init: t.callExpression(
t.identifier('require'),
[t.stringLiteral('object-assign')]
),
});
}
path.node.callee = this.id;
}
},
},
};
};
+9 -1
View File
@@ -27,7 +27,15 @@ var pathToBabelrc = path.join(__dirname, '..', '..', '.babelrc');
// TODO: make sure this stays in sync with gulpfile
var babelOptions = {
plugins: [
[babelPluginModules, { map: moduleMap }],
[babelPluginModules, {
map: Object.assign(
{},
moduleMap,
{
'object-assign': 'object-assign',
}
),
}],
],
retainLines: true,
};