From ca0c409b6f178cf890f5ed95250ed3e79ab67634 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20O=E2=80=99Shannessy?= Date: Thu, 7 Apr 2016 17:30:44 -0700 Subject: [PATCH] Merge pull request #6444 from zpao/re__spreadwarn Add back React.__spread and make it warn (cherry picked from commit 516c1d809ea56dbd109f54712efea6923ac76ee6) --- .../babel/transform-object-assign-require.js | 34 +++++++++++++------ src/isomorphic/React.js | 21 ++++++++++++ 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/scripts/babel/transform-object-assign-require.js b/scripts/babel/transform-object-assign-require.js index 649a377005c9b..36d32241337a7 100644 --- a/scripts/babel/transform-object-assign-require.js +++ b/scripts/babel/transform-object-assign-require.js @@ -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 @@ -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); } }, }, diff --git a/src/isomorphic/React.js b/src/isomorphic/React.js index 551e0a608bb23..1461cf8a590c7 100644 --- a/src/isomorphic/React.js +++ b/src/isomorphic/React.js @@ -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; @@ -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 @@ -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;