@samitouri / QOS-React-2 / commits / 8210beeef4

Hide Object.assign polyfill behind a module

Because the JS community's polyfilling infrastructure sucks and we'll have to fix it for them before we require this. JSX spread uses React.__spread (which might get special behavior for key/ref, not sure yet) This never uses the native implementation and throws for prototype chains. Once the native implementations are faster, we'll start using them.

Sebastian Markbage committed Oct 16, 2014 at 09:21 UTC 8210beeef4219d11b0a997f5a5abe7c348c01448
41 files changed +182 -128
jest/environment.js
-2
@@ -1,3 +1 @@
1 __DEV__ = true;
2 -
3 -require.requireActual('../src/vendor/polyfill/Object.es6.js');
src/addons/transitions/ReactCSSTransitionGroup.js
+3 -1
@@ -14,6 +14,8 @@
14
15 var React = require('React');
16
17 +var assign = require('Object.assign');
18 +
19 var ReactTransitionGroup = React.createFactory(
20 require('ReactTransitionGroup')
21 );
@@ -54,7 +56,7 @@ var ReactCSSTransitionGroup = React.createClass({
56 render: function() {
57 return (
58 ReactTransitionGroup(
57 - Object.assign({}, this.props, {childFactory: this._wrapChild})
59 + assign({}, this.props, {childFactory: this._wrapChild})
60 )
61 );
62 }
src/addons/transitions/ReactTransitionGroup.js
+2 -1
@@ -14,6 +14,7 @@
14 var React = require('React');
15 var ReactTransitionChildMapping = require('ReactTransitionChildMapping');
16
17 +var assign = require('Object.assign');
18 var cloneWithProps = require('cloneWithProps');
19 var emptyFunction = require('emptyFunction');
20
@@ -151,7 +152,7 @@ var ReactTransitionGroup = React.createClass({
152 // This entered again before it fully left. Add it again.
153 this.performEnter(key);
154 } else {
154 - var newChildren = Object.assign({}, this.state.children);
155 + var newChildren = assign({}, this.state.children);
156 delete newChildren[key];
157 this.setState({children: newChildren});
158 }
src/addons/update.js
+3 -2
@@ -11,6 +11,7 @@
11
12 "use strict";
13
14 +var assign = require('Object.assign');
15 var keyOf = require('keyOf');
16 var invariant = require('invariant');
17
@@ -18,7 +19,7 @@ function shallowCopy(x) {
19 if (Array.isArray(x)) {
20 return x.concat();
21 } else if (x && typeof x === 'object') {
21 - return Object.assign(new x.constructor(), x);
22 + return assign(new x.constructor(), x);
23 } else {
24 return x;
25 }
@@ -98,7 +99,7 @@ function update(value, spec) {
99 COMMAND_MERGE,
100 nextValue
101 );
101 - Object.assign(nextValue, spec[COMMAND_MERGE]);
102 + assign(nextValue, spec[COMMAND_MERGE]);
103 }
104
105 if (spec.hasOwnProperty(COMMAND_PUSH)) {
src/browser/ReactBrowserEventEmitter.js
+2 -1
@@ -18,6 +18,7 @@ var EventPluginRegistry = require('EventPluginRegistry');
18 var ReactEventEmitterMixin = require('ReactEventEmitterMixin');
19 var ViewportMetrics = require('ViewportMetrics');
20
21 +var assign = require('Object.assign');
22 var isEventSupported = require('isEventSupported');
23
24 /**
@@ -147,7 +148,7 @@ function getListeningForDocument(mountAt) {
148 *
149 * @internal
150 */
150 -var ReactBrowserEventEmitter = Object.assign({}, ReactEventEmitterMixin, {
151 +var ReactBrowserEventEmitter = assign({}, ReactEventEmitterMixin, {
152
153 /**
154 * Injectable event backend
src/browser/ReactPutListenerQueue.js
+3 -1
@@ -14,11 +14,13 @@
14 var PooledClass = require('PooledClass');
15 var ReactBrowserEventEmitter = require('ReactBrowserEventEmitter');
16
17 +var assign = require('Object.assign');
18 +
19 function ReactPutListenerQueue() {
20 this.listenersToPut = [];
21 }
22
21 -Object.assign(ReactPutListenerQueue.prototype, {
23 +assign(ReactPutListenerQueue.prototype, {
24 enqueuePutListener: function(rootNodeID, propKey, propValue) {
25 this.listenersToPut.push({
26 rootNodeID: rootNodeID,
src/browser/ReactReconcileTransaction.js
+3 -1
@@ -19,6 +19,8 @@ var ReactInputSelection = require('ReactInputSelection');
19 var ReactPutListenerQueue = require('ReactPutListenerQueue');
20 var Transaction = require('Transaction');
21
22 +var assign = require('Object.assign');
23 +
24 /**
25 * Ensures that, when possible, the selection range (currently selected text
26 * input) is not disturbed by performing the transaction.
@@ -165,7 +167,7 @@ var Mixin = {
167 };
168
169
168 -Object.assign(ReactReconcileTransaction.prototype, Transaction.Mixin, Mixin);
170 +assign(ReactReconcileTransaction.prototype, Transaction.Mixin, Mixin);
171
172 PooledClass.addPoolingTo(ReactReconcileTransaction);
173
src/browser/ReactTextComponent.js
+2 -1
@@ -16,6 +16,7 @@ var DOMPropertyOperations = require('DOMPropertyOperations');
16 var ReactComponent = require('ReactComponent');
17 var ReactElement = require('ReactElement');
18
19 +var assign = require('Object.assign');
20 var escapeTextForBrowser = require('escapeTextForBrowser');
21
22 /**
@@ -37,7 +38,7 @@ var ReactTextComponent = function(props) {
38 // This constructor and it's argument is currently used by mocks.
39 };
40
40 -Object.assign(ReactTextComponent.prototype, ReactComponent.Mixin, {
41 +assign(ReactTextComponent.prototype, ReactComponent.Mixin, {
42
43 /**
44 * Creates the markup for this text node. This node is not intended to have
src/browser/server/ReactServerRenderingTransaction.js
+2 -1
@@ -17,6 +17,7 @@ var CallbackQueue = require('CallbackQueue');
17 var ReactPutListenerQueue = require('ReactPutListenerQueue');
18 var Transaction = require('Transaction');
19
20 +var assign = require('Object.assign');
21 var emptyFunction = require('emptyFunction');
22
23 /**
@@ -99,7 +100,7 @@ var Mixin = {
100 };
101
102
102 -Object.assign(
103 +assign(
104 ReactServerRenderingTransaction.prototype,
105 Transaction.Mixin,
106 Mixin
src/browser/syntheticEvents/SyntheticEvent.js
+4 -3
@@ -14,6 +14,7 @@
14
15 var PooledClass = require('PooledClass');
16
17 +var assign = require('Object.assign');
18 var emptyFunction = require('emptyFunction');
19 var getEventTarget = require('getEventTarget');
20
@@ -82,7 +83,7 @@ function SyntheticEvent(dispatchConfig, dispatchMarker, nativeEvent) {
83 this.isPropagationStopped = emptyFunction.thatReturnsFalse;
84 }
85
85 -Object.assign(SyntheticEvent.prototype, {
86 +assign(SyntheticEvent.prototype, {
87
88 preventDefault: function() {
89 this.defaultPrevented = true;
@@ -140,11 +141,11 @@ SyntheticEvent.augmentClass = function(Class, Interface) {
141 var Super = this;
142
143 var prototype = Object.create(Super.prototype);
143 - Object.assign(prototype, Class.prototype);
144 + assign(prototype, Class.prototype);
145 Class.prototype = prototype;
146 Class.prototype.constructor = Class;
147
147 - Class.Interface = Object.assign({}, Super.Interface, Interface);
148 + Class.Interface = assign({}, Super.Interface, Interface);
149 Class.augmentClass = Super.augmentClass;
150
151 PooledClass.addPoolingTo(Class, PooledClass.threeArgumentPooler);
src/browser/ui/React.js
+4 -4
@@ -11,10 +11,6 @@
11
12 "use strict";
13
14 -// TODO: Move this elsewhere - it only exists in open source until a better
15 -// solution is found.
16 -require('Object.es6');
17 -
14 var DOMPropertyOperations = require('DOMPropertyOperations');
15 var EventPluginUtils = require('EventPluginUtils');
16 var ReactChildren = require('ReactChildren');
@@ -36,6 +32,7 @@ var ReactPropTypes = require('ReactPropTypes');
32 var ReactServerRendering = require('ReactServerRendering');
33 var ReactTextComponent = require('ReactTextComponent');
34
35 +var assign = require('Object.assign');
36 var deprecated = require('deprecated');
37 var onlyChild = require('onlyChild');
38
@@ -84,6 +81,9 @@ var React = {
81 isValidElement: ReactElement.isValidElement,
82 withContext: ReactContext.withContext,
83
84 + // Hook for JSX spread, don't use this for anything else.
85 + __spread: assign,
86 +
87 // Deprecations (remove for 0.13)
88 renderComponent: deprecated(
89 'React',
src/browser/ui/ReactDOMComponent.js
+4 -3
@@ -22,6 +22,7 @@ var ReactMount = require('ReactMount');
22 var ReactMultiChild = require('ReactMultiChild');
23 var ReactPerf = require('ReactPerf');
24
25 +var assign = require('Object.assign');
26 var escapeTextForBrowser = require('escapeTextForBrowser');
27 var invariant = require('invariant');
28 var isEventSupported = require('isEventSupported');
@@ -213,7 +214,7 @@ ReactDOMComponent.Mixin = {
214 } else {
215 if (propKey === STYLE) {
216 if (propValue) {
216 - propValue = props.style = Object.assign({}, props.style);
217 + propValue = props.style = assign({}, props.style);
218 }
219 propValue = CSSPropertyOperations.createMarkupForStyles(propValue);
220 }
@@ -362,7 +363,7 @@ ReactDOMComponent.Mixin = {
363 }
364 if (propKey === STYLE) {
365 if (nextProp) {
365 - nextProp = nextProps.style = Object.assign({}, nextProp);
366 + nextProp = nextProps.style = assign({}, nextProp);
367 }
368 if (lastProp) {
369 // Unset styles on `lastProp` but not on `nextProp`.
@@ -471,7 +472,7 @@ ReactDOMComponent.Mixin = {
472
473 };
474
474 -Object.assign(
475 +assign(
476 ReactDOMComponent.prototype,
477 ReactComponent.Mixin,
478 ReactDOMComponent.Mixin,
src/browser/ui/ReactEventListener.js
+2 -1
@@ -19,6 +19,7 @@ var ReactInstanceHandles = require('ReactInstanceHandles');
19 var ReactMount = require('ReactMount');
20 var ReactUpdates = require('ReactUpdates');
21
22 +var assign = require('Object.assign');
23 var getEventTarget = require('getEventTarget');
24 var getUnboundedScrollPosition = require('getUnboundedScrollPosition');
25
@@ -46,7 +47,7 @@ function TopLevelCallbackBookKeeping(topLevelType, nativeEvent) {
47 this.nativeEvent = nativeEvent;
48 this.ancestors = [];
49 }
49 -Object.assign(TopLevelCallbackBookKeeping.prototype, {
50 +assign(TopLevelCallbackBookKeeping.prototype, {
51 destructor: function() {
52 this.topLevelType = null;
53 this.nativeEvent = null;
src/browser/ui/__tests__/ReactDOMComponent-test.js
+6 -5
@@ -13,6 +13,7 @@
13
14 "use strict";
15
16 +var assign = require('Object.assign');
17 var mocks = require('mocks');
18
19 describe('ReactDOMComponent', function() {
@@ -223,7 +224,7 @@ describe('ReactDOMComponent', function() {
224 this.props = initialProps || {};
225 this._rootNodeID = 'test';
226 };
226 - Object.assign(NodeStub.prototype, ReactDOMComponent.Mixin);
227 + assign(NodeStub.prototype, ReactDOMComponent.Mixin);
228
229 genMarkup = function(props) {
230 var transaction = new ReactReconcileTransaction();
@@ -273,7 +274,7 @@ describe('ReactDOMComponent', function() {
274 this.props = initialProps || {};
275 this._rootNodeID = 'test';
276 };
276 - Object.assign(NodeStub.prototype, ReactDOMComponent.Mixin);
277 + assign(NodeStub.prototype, ReactDOMComponent.Mixin);
278
279 genMarkup = function(props) {
280 var transaction = new ReactReconcileTransaction();
@@ -310,9 +311,9 @@ describe('ReactDOMComponent', function() {
311 var StubNativeComponent = function(element) {
312 ReactComponent.Mixin.construct.call(this, element);
313 };
313 - Object.assign(StubNativeComponent.prototype, ReactComponent.Mixin);
314 - Object.assign(StubNativeComponent.prototype, ReactDOMComponent.Mixin);
315 - Object.assign(StubNativeComponent.prototype, ReactMultiChild.Mixin);
314 + assign(StubNativeComponent.prototype, ReactComponent.Mixin);
315 + assign(StubNativeComponent.prototype, ReactDOMComponent.Mixin);
316 + assign(StubNativeComponent.prototype, ReactMultiChild.Mixin);
317
318 mountComponent = function(props) {
319 var transaction = new ReactReconcileTransaction();
src/browser/ui/dom/components/ReactDOMInput.js
+2 -1
@@ -21,6 +21,7 @@ var ReactDOM = require('ReactDOM');
21 var ReactMount = require('ReactMount');
22 var ReactUpdates = require('ReactUpdates');
23
24 +var assign = require('Object.assign');
25 var invariant = require('invariant');
26
27 // Store a reference to the <input> `ReactDOMComponent`. TODO: use string
@@ -66,7 +67,7 @@ var ReactDOMInput = ReactCompositeComponent.createClass({
67
68 render: function() {
69 // Clone `this.props` so we don't mutate the input.
69 - var props = Object.assign({}, this.props);
70 + var props = assign({}, this.props);
71
72 props.defaultChecked = null;
73 props.defaultValue = null;
src/browser/ui/dom/components/ReactDOMSelect.js
+3 -1
@@ -19,6 +19,8 @@ var ReactElement = require('ReactElement');
19 var ReactDOM = require('ReactDOM');
20 var ReactUpdates = require('ReactUpdates');
21
22 +var assign = require('Object.assign');
23 +
24 // Store a reference to the <select> `ReactDOMComponent`. TODO: use string
25 var select = ReactElement.createFactory(ReactDOM.select.type);
26
@@ -129,7 +131,7 @@ var ReactDOMSelect = ReactCompositeComponent.createClass({
131
132 render: function() {
133 // Clone `this.props` so we don't mutate the input.
132 - var props = Object.assign({}, this.props);
134 + var props = assign({}, this.props);
135
136 props.onChange = this._handleChange;
137 props.value = null;
src/browser/ui/dom/components/ReactDOMTextarea.js
+2 -1
@@ -20,6 +20,7 @@ var ReactElement = require('ReactElement');
20 var ReactDOM = require('ReactDOM');
21 var ReactUpdates = require('ReactUpdates');
22
23 +var assign = require('Object.assign');
24 var invariant = require('invariant');
25
26 var warning = require('warning');
@@ -95,7 +96,7 @@ var ReactDOMTextarea = ReactCompositeComponent.createClass({
96
97 render: function() {
98 // Clone `this.props` so we don't mutate the input.
98 - var props = Object.assign({}, this.props);
99 + var props = assign({}, this.props);
100
101 invariant(
102 props.dangerouslySetInnerHTML == null,
src/core/ReactComponent.js
+3 -2
@@ -15,6 +15,7 @@ var ReactElement = require('ReactElement');
15 var ReactOwner = require('ReactOwner');
16 var ReactUpdates = require('ReactUpdates');
17
18 +var assign = require('Object.assign');
19 var invariant = require('invariant');
20 var keyMirror = require('keyMirror');
21
@@ -143,7 +144,7 @@ var ReactComponent = {
144 // element props.
145 var element = this._pendingElement || this._currentElement;
146 this.replaceProps(
146 - Object.assign({}, element.props, partialProps),
147 + assign({}, element.props, partialProps),
148 callback
149 );
150 },
@@ -192,7 +193,7 @@ var ReactComponent = {
193 var element = this._pendingElement || this._currentElement;
194 this._pendingElement = ReactElement.cloneAndReplaceProps(
195 element,
195 - Object.assign({}, element.props, partialProps)
196 + assign({}, element.props, partialProps)
197 );
198 ReactUpdates.enqueueUpdate(this, callback);
199 },
src/core/ReactCompositeComponent.js
+7 -6
@@ -26,6 +26,7 @@ var ReactPropTypeLocations = require('ReactPropTypeLocations');
26 var ReactPropTypeLocationNames = require('ReactPropTypeLocationNames');
27 var ReactUpdates = require('ReactUpdates');
28
29 +var assign = require('Object.assign');
30 var instantiateReactComponent = require('instantiateReactComponent');
31 var invariant = require('invariant');
32 var keyMirror = require('keyMirror');
@@ -340,7 +341,7 @@ var RESERVED_SPEC_KEYS = {
341 childContextTypes,
342 ReactPropTypeLocations.childContext
343 );
343 - Constructor.childContextTypes = Object.assign(
344 + Constructor.childContextTypes = assign(
345 {},
346 Constructor.childContextTypes,
347 childContextTypes
@@ -352,7 +353,7 @@ var RESERVED_SPEC_KEYS = {
353 contextTypes,
354 ReactPropTypeLocations.context
355 );
355 - Constructor.contextTypes = Object.assign(
356 + Constructor.contextTypes = assign(
357 {},
358 Constructor.contextTypes,
359 contextTypes
@@ -378,7 +379,7 @@ var RESERVED_SPEC_KEYS = {
379 propTypes,
380 ReactPropTypeLocations.prop
381 );
381 - Constructor.propTypes = Object.assign(
382 + Constructor.propTypes = assign(
383 {},
384 Constructor.propTypes,
385 propTypes
@@ -866,7 +867,7 @@ var ReactCompositeComponentMixin = {
867 }
868 // Merge with `_pendingState` if it exists, otherwise with existing state.
869 this.replaceState(
869 - Object.assign({}, this._pendingState || this.state, partialState),
870 + assign({}, this._pendingState || this.state, partialState),
871 callback
872 );
873 },
@@ -954,7 +955,7 @@ var ReactCompositeComponentMixin = {
955 name
956 );
957 }
957 - return Object.assign({}, currentContext, childContext);
958 + return assign({}, currentContext, childContext);
959 }
960 return currentContext;
961 },
@@ -1332,7 +1333,7 @@ var ReactCompositeComponentMixin = {
1333 };
1334
1335 var ReactCompositeComponentBase = function() {};
1335 -Object.assign(
1336 +assign(
1337 ReactCompositeComponentBase.prototype,
1338 ReactComponent.Mixin,
1339 ReactOwner.Mixin,
src/core/ReactContext.js
+3 -1
@@ -11,6 +11,8 @@
11
12 "use strict";
13
14 +var assign = require('Object.assign');
15 +
16 /**
17 * Keeps track of the current context.
18 *
@@ -44,7 +46,7 @@ var ReactContext = {
46 withContext: function(newContext, scopedCallback) {
47 var result;
48 var previousContext = ReactContext.current;
47 - ReactContext.current = Object.assign({}, previousContext, newContext);
49 + ReactContext.current = assign({}, previousContext, newContext);
50 try {
51 result = scopedCallback();
52 } finally {
src/core/ReactDefaultBatchingStrategy.js
+2 -1
@@ -14,6 +14,7 @@
14 var ReactUpdates = require('ReactUpdates');
15 var Transaction = require('Transaction');
16
17 +var assign = require('Object.assign');
18 var emptyFunction = require('emptyFunction');
19
20 var RESET_BATCHED_UPDATES = {
@@ -34,7 +35,7 @@ function ReactDefaultBatchingStrategyTransaction() {
35 this.reinitializeTransaction();
36 }
37
37 -Object.assign(
38 +assign(
39 ReactDefaultBatchingStrategyTransaction.prototype,
40 Transaction.Mixin,
41 {
src/core/ReactNativeComponent.js
+2 -1
@@ -11,6 +11,7 @@
11
12 "use strict";
13
14 +var assign = require('Object.assign');
15 var invariant = require('invariant');
16
17 var genericComponentClass = null;
@@ -26,7 +27,7 @@ var ReactNativeComponentInjection = {
27 // This accepts a keyed object with classes as values. Each key represents a
28 // tag. That particular tag will use this class instead of the generic one.
29 injectComponentClasses: function(componentClasses) {
29 - Object.assign(tagToComponentClass, componentClasses);
30 + assign(tagToComponentClass, componentClasses);
31 }
32 };
33
src/core/ReactPropTransferer.js
+3 -2
@@ -11,6 +11,7 @@
11
12 "use strict";
13
14 +var assign = require('Object.assign');
15 var emptyFunction = require('emptyFunction');
16 var invariant = require('invariant');
17 var joinClasses = require('joinClasses');
@@ -39,7 +40,7 @@ var transferStrategyMerge = createTransferStrategy(function(a, b) {
40 // `merge` overrides the first object's (`props[key]` above) keys using the
41 // second object's (`value`) keys. An object's style's existing `propA` would
42 // get overridden. Flip the order here.
42 - return Object.assign({}, b, a);
43 + return assign({}, b, a);
44 });
45
46 /**
@@ -105,7 +106,7 @@ var ReactPropTransferer = {
106 * @return {object} a new object containing both sets of props merged.
107 */
108 mergeProps: function(oldProps, newProps) {
108 - return transferInto(Object.assign({}, oldProps), newProps);
109 + return transferInto(assign({}, oldProps), newProps);
110 },
111
112 /**
src/core/ReactUpdates.js
+2 -1
@@ -17,6 +17,7 @@ var ReactCurrentOwner = require('ReactCurrentOwner');
17 var ReactPerf = require('ReactPerf');
18 var Transaction = require('Transaction');
19
20 +var assign = require('Object.assign');
21 var invariant = require('invariant');
22 var warning = require('warning');
23
@@ -72,7 +73,7 @@ function ReactUpdatesFlushTransaction() {
73 ReactUpdates.ReactReconcileTransaction.getPooled();
74 }
75
75 -Object.assign(
76 +assign(
77 ReactUpdatesFlushTransaction.prototype,
78 Transaction.Mixin, {
79 getTransactionWrappers: function() {
src/event/__tests__/EventPluginRegistry-test.js
+3 -1
@@ -11,6 +11,8 @@
11
12 "use strict";
13
14 +var assign = require('Object.assign');
15 +
16 describe('EventPluginRegistry', function() {
17 var EventPluginRegistry;
18 var createPlugin;
@@ -20,7 +22,7 @@ describe('EventPluginRegistry', function() {
22 EventPluginRegistry._resetEventPlugins();
23
24 createPlugin = function(properties) {
23 - return Object.assign({extractEvents: function() {}}, properties);
25 + return assign({extractEvents: function() {}}, properties);
26 };
27 });
28
src/test/ReactDefaultPerfAnalysis.js
+5 -3
@@ -9,6 +9,8 @@
9 * @providesModule ReactDefaultPerfAnalysis
10 */
11
12 +var assign = require('Object.assign');
13 +
14 // Don't try to save users less than 1.2ms (a number I made up)
15 var DONT_CARE_THRESHOLD = 1.2;
16 var DOM_OPERATION_TYPES = {
@@ -62,7 +64,7 @@ function getExclusiveSummary(measurements) {
64
65 for (var i = 0; i < measurements.length; i++) {
66 var measurement = measurements[i];
65 - var allIDs = Object.assign(
67 + var allIDs = assign(
68 {},
69 measurement.exclusive,
70 measurement.inclusive
@@ -114,7 +116,7 @@ function getInclusiveSummary(measurements, onlyClean) {
116
117 for (var i = 0; i < measurements.length; i++) {
118 var measurement = measurements[i];
117 - var allIDs = Object.assign(
119 + var allIDs = assign(
120 {},
121 measurement.exclusive,
122 measurement.inclusive
@@ -173,7 +175,7 @@ function getUnchangedComponents(measurement) {
175 // the amount of time it took to render the entire subtree.
176 var cleanComponents = {};
177 var dirtyLeafIDs = Object.keys(measurement.writes);
176 - var allIDs = Object.assign({}, measurement.exclusive, measurement.inclusive);
178 + var allIDs = assign({}, measurement.exclusive, measurement.inclusive);
179
180 for (var id in allIDs) {
181 var isDirty = false;
src/test/ReactTestUtils.js
+4 -2
@@ -22,6 +22,8 @@ var ReactTextComponent = require('ReactTextComponent');
22 var ReactUpdates = require('ReactUpdates');
23 var SyntheticEvent = require('SyntheticEvent');
24
25 +var assign = require('Object.assign');
26 +
27 var topLevelTypes = EventConstants.topLevelTypes;
28
29 function Event(suffix) {}
@@ -318,7 +320,7 @@ function makeSimulator(eventType) {
320 ReactMount.getID(node),
321 fakeNativeEvent
322 );
321 - Object.assign(event, eventData);
323 + assign(event, eventData);
324 EventPropagators.accumulateTwoPhaseDispatches(event);
325
326 ReactUpdates.batchedUpdates(function() {
@@ -374,7 +376,7 @@ buildSimulators();
376 function makeNativeSimulator(eventType) {
377 return function(domComponentOrNode, nativeEventData) {
378 var fakeNativeEvent = new Event(eventType);
377 - Object.assign(fakeNativeEvent, nativeEventData);
379 + assign(fakeNativeEvent, nativeEventData);
380 if (ReactTestUtils.isDOMComponent(domComponentOrNode)) {
381 ReactTestUtils.simulateNativeEventOnDOMComponent(
382 eventType,
src/test/reactComponentExpect.js
+3 -1
@@ -14,6 +14,8 @@
14
15 var ReactTestUtils = require('ReactTestUtils');
16
17 +var assign = require('Object.assign');
18 +
19 function reactComponentExpect(instance) {
20 if (instance instanceof reactComponentExpect) {
21 return instance;
@@ -29,7 +31,7 @@ function reactComponentExpect(instance) {
31 expect(ReactTestUtils.isElement(instance)).toBe(false);
32 }
33
32 -Object.assign(reactComponentExpect.prototype, {
34 +assign(reactComponentExpect.prototype, {
35 // Getters -------------------------------------------------------------------
36
37 /**
src/utils/CallbackQueue.js
+2 -1
@@ -13,6 +13,7 @@
13
14 var PooledClass = require('PooledClass');
15
16 +var assign = require('Object.assign');
17 var invariant = require('invariant');
18
19 /**
@@ -31,7 +32,7 @@ function CallbackQueue() {
32 this._contexts = null;
33 }
34
34 -Object.assign(CallbackQueue.prototype, {
35 +assign(CallbackQueue.prototype, {
36
37 /**
38 * Enqueues a callback to be invoked when `notifyAll` is invoked.
src/utils/LegacyImmutableObject.js
+5 -4
@@ -12,6 +12,7 @@
12
13 "use strict";
14
15 +var assign = require('Object.assign');
16 var invariant = require('invariant');
17 var isNode = require('isNode');
18 var mergeHelpers = require('mergeHelpers');
@@ -42,7 +43,7 @@ if (__DEV__) {
43 * @constructor
44 */
45 LegacyImmutableObject = function LegacyImmutableObject(initialProperties) {
45 - Object.assign(this, initialProperties);
46 + assign(this, initialProperties);
47 deepFreeze(this);
48 };
49
@@ -91,7 +92,7 @@ if (__DEV__) {
92 */
93 LegacyImmutableObject.set = function(immutableObject, put) {
94 assertLegacyImmutableObject(immutableObject);
94 - var totalNewFields = Object.assign({}, immutableObject, put);
95 + var totalNewFields = assign({}, immutableObject, put);
96 return new LegacyImmutableObject(totalNewFields);
97 };
98
@@ -103,7 +104,7 @@ if (__DEV__) {
104 * @constructor
105 */
106 LegacyImmutableObject = function LegacyImmutableObject(initialProperties) {
106 - Object.assign(this, initialProperties);
107 + assign(this, initialProperties);
108 };
109
110 /**
@@ -117,7 +118,7 @@ if (__DEV__) {
118 LegacyImmutableObject.set = function(immutableObject, put) {
119 assertLegacyImmutableObject(immutableObject);
120 var newMap = new LegacyImmutableObject(immutableObject);
120 - Object.assign(newMap, put);
121 + assign(newMap, put);
122 return newMap;
123 };
124 }
src/utils/OrderedMap.js
+2 -1
@@ -11,6 +11,7 @@
11
12 "use strict";
13
14 +var assign = require('Object.assign');
15 var invariant = require('invariant');
16
17 var PREFIX = 'key:';
@@ -475,7 +476,7 @@ var OrderedMapMethods = {
476 }
477 };
478
478 -Object.assign(OrderedMapImpl.prototype, OrderedMapMethods);
479 +assign(OrderedMapImpl.prototype, OrderedMapMethods);
480
481 var OrderedMap = {
482 from: function(orderedMap) {
src/utils/__tests__/Transaction-test.js
+8 -6
@@ -11,6 +11,8 @@
11
12 "use strict";
13
14 +var assign = require('Object.assign');
15 +
16 var Transaction;
17
18 var INIT_ERRORED = 'initErrored'; // Just a dummy value to check for.
@@ -44,7 +46,7 @@ describe('Transaction', function() {
46 this.secondCloseParam = INIT_ERRORED; // WILL be set to something else
47 this.lastCloseParam = INIT_ERRORED; // WON'T be set to something else
48 };
47 - Object.assign(TestTransaction.prototype, Transaction.Mixin);
49 + assign(TestTransaction.prototype, Transaction.Mixin);
50 TestTransaction.prototype.getTransactionWrappers = function() {
51 return [
52 {
@@ -93,7 +95,7 @@ describe('Transaction', function() {
95 this.secondCloseParam = INIT_ERRORED; // WILL be set to something else
96 this.lastCloseParam = INIT_ERRORED; // WILL be set to something else
97 };
96 - Object.assign(TestTransaction.prototype, Transaction.Mixin);
98 + assign(TestTransaction.prototype, Transaction.Mixin);
99 TestTransaction.prototype.getTransactionWrappers = function() {
100 return [
101 {
@@ -154,7 +156,7 @@ describe('Transaction', function() {
156 this.secondCloseParam = INIT_ERRORED; // WILL be set to something else
157 this.lastCloseParam = INIT_ERRORED; // WILL be set to something else
158 };
157 - Object.assign(TestTransaction.prototype, Transaction.Mixin);
159 + assign(TestTransaction.prototype, Transaction.Mixin);
160 // Now, none of the close/inits throw, but the operation we wrap will throw.
161 TestTransaction.prototype.getTransactionWrappers = function() {
162 return [
@@ -218,7 +220,7 @@ describe('Transaction', function() {
220 var TestTransaction = function() {
221 this.reinitializeTransaction();
222 };
221 - Object.assign(TestTransaction.prototype, Transaction.Mixin);
223 + assign(TestTransaction.prototype, Transaction.Mixin);
224 var exceptionMsg = 'This exception should throw.';
225 TestTransaction.prototype.getTransactionWrappers = function() {
226 return [
@@ -247,7 +249,7 @@ describe('Transaction', function() {
249 this.reinitializeTransaction();
250 this.firstCloseParam = INIT_ERRORED; // WILL be set to something else
251 };
250 - Object.assign(TestTransaction.prototype, Transaction.Mixin);
252 + assign(TestTransaction.prototype, Transaction.Mixin);
253 TestTransaction.prototype.getTransactionWrappers = function() {
254 return [
255 {
@@ -275,7 +277,7 @@ describe('Transaction', function() {
277 var NestedTransaction = function() {
278 this.reinitializeTransaction();
279 };
278 - Object.assign(NestedTransaction.prototype, Transaction.Mixin);
280 + assign(NestedTransaction.prototype, Transaction.Mixin);
281 NestedTransaction.prototype.getTransactionWrappers = function() {
282 return [{
283 initialize: function() {
src/utils/deprecated.js
+2 -1
@@ -9,6 +9,7 @@
9 * @providesModule deprecated
10 */
11
12 +var assign = require('Object.assign');
13 var warning = require('warning');
14
15 /**
@@ -37,7 +38,7 @@ function deprecated(namespace, oldName, newName, ctx, fn) {
38 newFn.displayName = `${namespace}_${oldName}`;
39 // We need to make sure all properties of the original fn are copied over.
40 // In particular, this is needed to support PropTypes
40 - return Object.assign(newFn, fn);
41 + return assign(newFn, fn);
42 }
43
44 return fn;
src/vendor/core/emptyFunction.js
+6 -8
@@ -22,13 +22,11 @@ function makeEmptyFunction(arg) {
22 */
23 function emptyFunction() {}
24
25 -Object.assign(emptyFunction, {
26 - thatReturns: makeEmptyFunction,
27 - thatReturnsFalse: makeEmptyFunction(false),
28 - thatReturnsTrue: makeEmptyFunction(true),
29 - thatReturnsNull: makeEmptyFunction(null),
30 - thatReturnsThis: function() { return this; },
31 - thatReturnsArgument: function(arg) { return arg; }
32 -});
25 +emptyFunction.thatReturns = makeEmptyFunction;
26 +emptyFunction.thatReturnsFalse = makeEmptyFunction(false);
27 +emptyFunction.thatReturnsTrue = makeEmptyFunction(true);
28 +emptyFunction.thatReturnsNull = makeEmptyFunction(null);
29 +emptyFunction.thatReturnsThis = function() { return this; };
30 +emptyFunction.thatReturnsArgument = function(arg) { return arg; };
31
32 module.exports = emptyFunction;
src/vendor/immutable/Immutable.js
+2 -1
@@ -9,6 +9,7 @@
9 * @providesModule Immutable
10 */
11
12 +var assign = require('Object.assign');
13 var invariant = require('invariant');
14 var isNode = require('isNode');
15 var keyOf = require('keyOf');
@@ -59,7 +60,7 @@ class Immutable {
60 static mergeAllPropertiesInto(destination, propertyObjects) {
61 var argLength = propertyObjects.length;
62 for (var i = 0; i < argLength; i++) {
62 - Object.assign(destination, propertyObjects[i]);
63 + assign(destination, propertyObjects[i]);
64 }
65 }
66
src/vendor/polyfill/Object.es6.js deleted
-45
@@ -1,45 +0,0 @@
1 -/**
2 - * Copyright 2014, Facebook, Inc.
3 - * All rights reserved.
4 - *
5 - * This source code is licensed under the BSD-style license found in the
6 - * LICENSE file in the root directory of this source tree. An additional grant
7 - * of patent rights can be found in the PATENTS file in the same directory.
8 - *
9 - * @providesModule Object.es6
10 - * @polyfill
11 - */
12 -
13 -// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.assign
14 -
15 -if (!Object.assign) {
16 - Object.assign = function(target, sources) {
17 - if (target == null) {
18 - throw new TypeError('Object.assign target cannot be null or undefined');
19 - }
20 -
21 - var to = Object(target);
22 - var hasOwnProperty = Object.prototype.hasOwnProperty;
23 -
24 - for (var nextIndex = 1; nextIndex < arguments.length; nextIndex++) {
25 - var nextSource = arguments[nextIndex];
26 - if (nextSource == null) {
27 - continue;
28 - }
29 -
30 - var from = Object(nextSource);
31 -
32 - // We don't currently support accessors nor proxies. Therefore this
33 - // copy cannot throw. If we ever supported this then we must handle
34 - // exceptions and side-effects.
35 -
36 - for (var key in from) {
37 - if (hasOwnProperty.call(from, key)) {
38 - to[key] = from[key];
39 - }
40 - }
41 - }
42 -
43 - return to;
44 - };
45 -}
src/vendor/stubs/Object.assign.js new
+57
@@ -0,0 +1,57 @@
1 +/**
2 + * Copyright 2014, Facebook, Inc.
3 + * All rights reserved.
4 + *
5 + * This source code is licensed under the BSD-style license found in the
6 + * LICENSE file in the root directory of this source tree. An additional grant
7 + * of patent rights can be found in the PATENTS file in the same directory.
8 + *
9 + * @providesModule Object.assign
10 + */
11 +
12 +// This is an optimized version that fails on hasOwnProperty checks
13 +// and non objects. It's not spec-compliant. It's a perf optimization.
14 +
15 +var hasOwnProperty = Object.prototype.hasOwnProperty;
16 +
17 +function assign(target, sources) {
18 + if (__DEV__) {
19 + if (target == null) {
20 + throw new TypeError('Object.assign target cannot be null or undefined');
21 + }
22 + if (typeof target !== 'object' && typeof target !== 'function') {
23 + throw new TypeError(
24 + 'In this environment the target of assign MUST be an object. ' +
25 + 'This error is a performance optimization and not spec compliant.'
26 + );
27 + }
28 + }
29 +
30 + for (var nextIndex = 1; nextIndex < arguments.length; nextIndex++) {
31 + var nextSource = arguments[nextIndex];
32 + if (nextSource == null) {
33 + continue;
34 + }
35 +
36 + // We don't currently support accessors nor proxies. Therefore this
37 + // copy cannot throw. If we ever supported this then we must handle
38 + // exceptions and side-effects.
39 +
40 + for (var key in nextSource) {
41 + if (__DEV__) {
42 + if (!hasOwnProperty.call(nextSource, key)) {
43 + throw new TypeError(
44 + 'One of the sources to assign has an enumerable key on the ' +
45 + 'prototype chain. This is an edge case that we do not support. ' +
46 + 'This error is a performance optimization and not spec compliant.'
47 + );
48 + }
49 + }
50 + target[key] = nextSource[key];
51 + }
52 + }
53 +
54 + return target;
55 +};
56 +
57 +module.exports = assign;
src/vendor_deprecated/core/merge.js
+3 -1
@@ -11,6 +11,8 @@
11
12 "use strict";
13
14 +var assign = require('Object.assign');
15 +
16 /**
17 * Shallow merges two structures into a return value, without mutating either.
18 *
@@ -19,7 +21,7 @@
21 * @return {object} The shallow extension of one by two.
22 */
23 var merge = function(one, two) {
22 - return Object.assign({}, one, two);
24 + return assign({}, one, two);
25 };
26
27 module.exports = merge;
src/vendor_deprecated/core/mergeInto.js
+3 -1
@@ -12,7 +12,9 @@
12
13 "use strict";
14
15 -module.exports = Object.assign;
15 +var assign = require('Object.assign');
16 +
17 +module.exports = assign;
18
19 // deprecation notice
20 console.warn(
vendor/fbtransform/transforms/__tests__/react-test.js
+7 -7
@@ -42,7 +42,7 @@ describe('react jsx', function() {
42 var Component = jest.genMockFunction();
43 var Child = jest.genMockFunction();
44 var objectAssignMock = jest.genMockFunction();
45 - Object.assign = objectAssignMock;
45 + React.__spread = objectAssignMock;
46 eval(transform(code).code);
47 return expect(objectAssignMock);
48 }
@@ -309,12 +309,12 @@ describe('react jsx', function() {
309 expect(() => transform(code)).toThrow();
310 });
311
312 - it('wraps props in Object.assign for spread attributes', function() {
312 + it('wraps props in React.__spread for spread attributes', function() {
313 var code =
314 '<Component { ... x } y\n' +
315 '={2 } z />';
316 var result =
317 - 'React.createElement(Component, Object.assign({}, x , {y: \n' +
317 + 'React.createElement(Component, React.__spread({}, x , {y: \n' +
318 '2, z: true}))';
319
320 expect(transform(code).code).toBe(result);
@@ -326,7 +326,7 @@ describe('react jsx', function() {
326 ' {...this.props}\n' +
327 ' sound="moo" />';
328 var result =
329 - 'React.createElement(Component, Object.assign({}, \n' +
329 + 'React.createElement(Component, React.__spread({}, \n' +
330 ' this.props, \n' +
331 ' {sound: "moo"}))';
332
@@ -340,7 +340,7 @@ describe('react jsx', function() {
340 expect(transform(code).code).toBe(result);
341 });
342
343 - it('does not call Object.assign when there are no spreads', function() {
343 + it('does not call React.__spread when there are no spreads', function() {
344 expectObjectAssign(
345 '<Component x={y} />'
346 ).not.toBeCalled();
@@ -376,13 +376,13 @@ describe('react jsx', function() {
376 ).toBeCalledWith({x: 1}, y);
377 });
378
379 - it('passes the same value multiple times to Object.assign', function() {
379 + it('passes the same value multiple times to React.__spread', function() {
380 expectObjectAssign(
381 '<Component x={1} y="2" {...z} {...z}><Child /></Component>'
382 ).toBeCalledWith({x: 1, y: "2"}, z, z);
383 });
384
385 - it('evaluates sequences before passing them to Object.assign', function() {
385 + it('evaluates sequences before passing them to React.__spread', function() {
386 expectObjectAssign(
387 '<Component x="1" {...(z = { y: 2 }, z)} z={3}>Text</Component>'
388 ).toBeCalledWith({x: "1"}, { y: 2 }, {z: 3});
vendor/fbtransform/transforms/react.js
+1 -1
@@ -89,7 +89,7 @@ function visitReactTag(traverse, object, path, state) {
89
90 // if we don't have any attributes, pass in null
91 if (hasAtLeastOneSpreadProperty) {
92 - utils.append('Object.assign({', state);
92 + utils.append('React.__spread({', state);
93 } else if (hasAttributes) {
94 utils.append('{', state);
95 } else {