Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add back React.__spread and make it warn #6444

Merged
merged 2 commits into from
Apr 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions scripts/babel/transform-object-assign-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@
module.exports = function autoImporter(babel) {
const t = babel.types;

function getAssignIdent(path, file, state) {
if (!state.id) {
state.id = path.scope.generateUidIdentifier('assign');
path.scope.getProgramParent().push({
id: state.id,
init: t.callExpression(
t.identifier('require'),
[t.stringLiteral('object-assign')]
),
});
}
return state.id;
}

return {
pre: function() {
// map from module to generated identifier
Expand All @@ -22,17 +36,15 @@ module.exports = function autoImporter(babel) {
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;
var id = getAssignIdent(path, file, this);
path.node.callee = id;
}
},

MemberExpression: function(path, file) {
if (path.matchesPattern('Object.assign')) {
var id = getAssignIdent(path, file, this);
path.replaceWith(id);
}
},
},
Expand Down
21 changes: 21 additions & 0 deletions src/isomorphic/React.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var ReactPropTypes = require('ReactPropTypes');
var ReactVersion = require('ReactVersion');

var onlyChild = require('onlyChild');
var warning = require('warning');

var createElement = ReactElement.createElement;
var createFactory = ReactElement.createFactory;
Expand All @@ -32,6 +33,23 @@ if (__DEV__) {
cloneElement = ReactElementValidator.cloneElement;
}

var __spread = Object.assign;

if (__DEV__) {
var warned = false;
__spread = function() {
warning(
warned,
'React.__spread is deprecated and should not be used. Use ' +
'Object.assign directly or another helper function with similar ' +
'semantics. You may be seeing this warning due to your compiler. ' +
'See https://fb.me/react-spread-deprecation for more details.'
);
warned = true;
return Object.assign.apply(null, arguments);
};
}

var React = {

// Modern
Expand Down Expand Up @@ -65,6 +83,9 @@ var React = {
DOM: ReactDOMFactories,

version: ReactVersion,

// Deprecated hook for JSX spread, don't use this for anything.
__spread: __spread,
};

module.exports = React;