mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Use Object.assign directly and inject object-assign at compile
This commit is contained in:
@@ -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;
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user