From f02d87bdb55ebd84943c5da5d6de92e3488fa2bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20O=E2=80=99Shannessy?= Date: Thu, 7 Apr 2016 16:16:37 -0700 Subject: [PATCH 1/2] Revert "Merge pull request #6431 from sebmarkbage/killspread" This reverts commit a37e4e94fcae9424094378349dc11bafe1e47973, reversing changes made to 411951d5b8a4a467adc213d4533c87a7c3b06bf8. --- src/isomorphic/React.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/isomorphic/React.js b/src/isomorphic/React.js index 551e0a608bb23..37109d6ea13f0 100644 --- a/src/isomorphic/React.js +++ b/src/isomorphic/React.js @@ -65,6 +65,9 @@ var React = { DOM: ReactDOMFactories, version: ReactVersion, + + // Hook for JSX spread, don't use this for anything else. + __spread: Object.assign, }; module.exports = React; From fc1cfb6225f5c3af6843515363db63ed3dcbb824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20O=E2=80=99Shannessy?= Date: Thu, 7 Apr 2016 16:24:20 -0700 Subject: [PATCH 2/2] Make React.__spread warn --- .../babel/transform-object-assign-require.js | 34 +++++++++++++------ src/isomorphic/React.js | 22 ++++++++++-- 2 files changed, 43 insertions(+), 13 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 37109d6ea13f0..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 @@ -66,8 +84,8 @@ var React = { version: ReactVersion, - // Hook for JSX spread, don't use this for anything else. - __spread: Object.assign, + // Deprecated hook for JSX spread, don't use this for anything. + __spread: __spread, }; module.exports = React;