react 15.1.0 → 15.2.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/dist/react-with-addons.js +2034 -1313
  2. package/dist/react-with-addons.min.js +7 -6
  3. package/dist/react.js +1832 -1244
  4. package/dist/react.min.js +6 -6
  5. package/lib/CSSPropertyOperations.js +1 -1
  6. package/lib/CallbackQueue.js +3 -2
  7. package/lib/DOMChildrenOperations.js +9 -9
  8. package/lib/DOMLazyTree.js +3 -2
  9. package/lib/DOMProperty.js +6 -4
  10. package/lib/DOMPropertyOperations.js +17 -3
  11. package/lib/Danger.js +10 -8
  12. package/lib/DisabledInputUtils.js +5 -5
  13. package/lib/EventPluginHub.js +8 -2
  14. package/lib/EventPluginRegistry.js +13 -7
  15. package/lib/EventPluginUtils.js +3 -1
  16. package/lib/HTMLDOMPropertyConfig.js +1 -2
  17. package/lib/LinkedValueUtils.js +5 -3
  18. package/lib/NativeMethodsMixin.js +6 -4
  19. package/lib/PooledClass.js +3 -1
  20. package/lib/React.js +1 -1
  21. package/lib/ReactCSSTransitionGroupChild.js +15 -8
  22. package/lib/ReactChildReconciler.js +15 -6
  23. package/lib/ReactClass.js +14 -13
  24. package/lib/ReactComponent.js +3 -6
  25. package/lib/ReactComponentEnvironment.js +3 -1
  26. package/lib/ReactComponentTreeDevtool.js +94 -16
  27. package/lib/ReactComponentTreeTestUtils.js +87 -0
  28. package/lib/ReactCompositeComponent.js +66 -106
  29. package/lib/ReactDOM.js +2 -2
  30. package/lib/ReactDOMButton.js +2 -2
  31. package/lib/ReactDOMComponent.js +130 -76
  32. package/lib/ReactDOMComponentTree.js +23 -21
  33. package/lib/ReactDOMDebugTool.js +7 -1
  34. package/lib/ReactDOMEmptyComponent.js +9 -9
  35. package/lib/ReactDOMFactories.js +1 -1
  36. package/lib/ReactDOMInput.js +52 -16
  37. package/lib/ReactDOMOption.js +40 -26
  38. package/lib/ReactDOMSelect.js +3 -3
  39. package/lib/ReactDOMTextComponent.js +21 -20
  40. package/lib/ReactDOMTextarea.js +59 -32
  41. package/lib/ReactDOMTreeTraversal.js +18 -16
  42. package/lib/ReactDOMUnknownPropertyDevtool.js +41 -15
  43. package/lib/ReactDebugTool.js +88 -27
  44. package/lib/ReactDefaultInjection.js +2 -2
  45. package/lib/ReactElement.js +64 -25
  46. package/lib/ReactElementValidator.js +26 -81
  47. package/lib/ReactEventListener.js +2 -2
  48. package/lib/ReactFragment.js +3 -1
  49. package/lib/{ReactNativeComponent.js → ReactHostComponent.js} +10 -29
  50. package/lib/{ReactNativeOperationHistoryDevtool.js → ReactHostOperationHistoryDevtool.js} +5 -5
  51. package/lib/ReactInjection.js +2 -2
  52. package/lib/ReactInstanceHandles.js +8 -6
  53. package/lib/ReactMount.js +24 -16
  54. package/lib/ReactMultiChild.js +31 -9
  55. package/lib/ReactNativeAttributePayload.js +5 -2
  56. package/lib/ReactNativeBaseComponent.js +7 -7
  57. package/lib/ReactNativeBridgeEventPlugin.js +1 -1
  58. package/lib/ReactNativeComponentTree.js +8 -6
  59. package/lib/ReactNativeDOMIDOperations.js +1 -2
  60. package/lib/ReactNativeDefaultInjection.js +9 -7
  61. package/lib/ReactNativeGlobalResponderHandler.js +1 -1
  62. package/lib/ReactNativeMount.js +1 -1
  63. package/lib/ReactNativeTagHandles.js +3 -1
  64. package/lib/ReactNativeTextComponent.js +10 -9
  65. package/lib/ReactNativeTreeTraversal.js +11 -11
  66. package/lib/ReactNodeTypes.js +5 -3
  67. package/lib/ReactNoop.js +76 -0
  68. package/lib/ReactOwner.js +4 -2
  69. package/lib/ReactPerf.js +83 -7
  70. package/lib/ReactPropTypes.js +23 -0
  71. package/lib/ReactReconcileTransaction.js +1 -1
  72. package/lib/ReactReconciler.js +12 -7
  73. package/lib/ReactServerRendering.js +4 -2
  74. package/lib/ReactSimpleEmptyComponent.js +4 -4
  75. package/lib/ReactTestMount.js +126 -0
  76. package/lib/ReactTestReconcileTransaction.js +100 -0
  77. package/lib/ReactTestRenderer.js +133 -0
  78. package/lib/ReactTestUtils.js +17 -10
  79. package/lib/ReactTransitionChildMapping.js +7 -1
  80. package/lib/ReactTransitionGroup.js +40 -6
  81. package/lib/ReactUpdateQueue.js +9 -1
  82. package/lib/ReactUpdates.js +9 -8
  83. package/lib/ReactVersion.js +1 -1
  84. package/lib/ResponderEventPlugin.js +8 -6
  85. package/lib/ResponderTouchHistoryStore.js +6 -4
  86. package/lib/SimpleEventPlugin.js +3 -1
  87. package/lib/SyntheticEvent.js +2 -3
  88. package/lib/SyntheticUIEvent.js +1 -1
  89. package/lib/Transaction.js +4 -2
  90. package/lib/accumulate.js +3 -1
  91. package/lib/accumulateInto.js +3 -1
  92. package/lib/checkReactTypeSpec.js +71 -0
  93. package/lib/createReactNativeComponentClass.js +2 -2
  94. package/lib/dangerousStyleValue.js +3 -1
  95. package/lib/escapeTextContentForBrowser.js +96 -12
  96. package/lib/findDOMNode.js +6 -4
  97. package/lib/findNodeHandle.js +5 -3
  98. package/lib/flattenChildren.js +13 -4
  99. package/lib/{getNativeComponentFromComposite.js → getHostComponentFromComposite.js} +4 -4
  100. package/lib/instantiateReactComponent.js +13 -12
  101. package/lib/onlyChild.js +3 -1
  102. package/lib/reactComponentExpect.js +3 -3
  103. package/lib/reactProdInvariant.js +38 -0
  104. package/lib/setInnerHTML.js +17 -1
  105. package/lib/setTextContent.js +8 -0
  106. package/lib/traverseAllChildren.js +3 -1
  107. package/lib/update.js +12 -11
  108. package/package.json +2 -2
  109. package/lib/MetaMatchers.js +0 -118
@@ -27,7 +27,7 @@ function emitEvent(handlerFunctionName, arg1, arg2, arg3, arg4, arg5) {
27
27
  handler[handlerFunctionName](arg1, arg2, arg3, arg4, arg5);
28
28
  }
29
29
  } catch (e) {
30
- process.env.NODE_ENV !== 'production' ? warning(!handlerDoesThrowForEvent[handlerFunctionName], 'exception thrown by devtool while handling %s: %s', handlerFunctionName, e.message) : void 0;
30
+ process.env.NODE_ENV !== 'production' ? warning(handlerDoesThrowForEvent[handlerFunctionName], 'exception thrown by devtool while handling %s: %s', handlerFunctionName, e + '\n' + e.stack) : void 0;
31
31
  handlerDoesThrowForEvent[handlerFunctionName] = true;
32
32
  }
33
33
  });
@@ -36,16 +36,18 @@ function emitEvent(handlerFunctionName, arg1, arg2, arg3, arg4, arg5) {
36
36
 
37
37
  var isProfiling = false;
38
38
  var flushHistory = [];
39
+ var lifeCycleTimerStack = [];
39
40
  var currentFlushNesting = 0;
40
41
  var currentFlushMeasurements = null;
41
42
  var currentFlushStartTime = null;
42
43
  var currentTimerDebugID = null;
43
44
  var currentTimerStartTime = null;
45
+ var currentTimerNestedFlushDuration = null;
44
46
  var currentTimerType = null;
45
47
 
46
48
  function clearHistory() {
47
49
  ReactComponentTreeDevtool.purgeUnmountedComponents();
48
- ReactNativeOperationHistoryDevtool.clearHistory();
50
+ ReactHostOperationHistoryDevtool.clearHistory();
49
51
  }
50
52
 
51
53
  function getTreeSnapshot(registeredIDs) {
@@ -69,7 +71,7 @@ function resetMeasurements() {
69
71
  if (process.env.NODE_ENV !== 'production') {
70
72
  var previousStartTime = currentFlushStartTime;
71
73
  var previousMeasurements = currentFlushMeasurements || [];
72
- var previousOperations = ReactNativeOperationHistoryDevtool.getHistory();
74
+ var previousOperations = ReactHostOperationHistoryDevtool.getHistory();
73
75
 
74
76
  if (!isProfiling || currentFlushNesting === 0) {
75
77
  currentFlushStartTime = null;
@@ -98,6 +100,62 @@ function checkDebugID(debugID) {
98
100
  process.env.NODE_ENV !== 'production' ? warning(debugID, 'ReactDebugTool: debugID may not be empty.') : void 0;
99
101
  }
100
102
 
103
+ function beginLifeCycleTimer(debugID, timerType) {
104
+ if (!isProfiling || currentFlushNesting === 0) {
105
+ return;
106
+ }
107
+ process.env.NODE_ENV !== 'production' ? warning(!currentTimerType, 'There is an internal error in the React performance measurement code. ' + 'Did not expect %s timer to start while %s timer is still in ' + 'progress for %s instance.', timerType, currentTimerType || 'no', debugID === currentTimerDebugID ? 'the same' : 'another') : void 0;
108
+ currentTimerStartTime = performanceNow();
109
+ currentTimerNestedFlushDuration = 0;
110
+ currentTimerDebugID = debugID;
111
+ currentTimerType = timerType;
112
+ }
113
+
114
+ function endLifeCycleTimer(debugID, timerType) {
115
+ if (!isProfiling || currentFlushNesting === 0) {
116
+ return;
117
+ }
118
+ process.env.NODE_ENV !== 'production' ? warning(currentTimerType === timerType, 'There is an internal error in the React performance measurement code. ' + 'We did not expect %s timer to stop while %s timer is still in ' + 'progress for %s instance. Please report this as a bug in React.', timerType, currentTimerType || 'no', debugID === currentTimerDebugID ? 'the same' : 'another') : void 0;
119
+ currentFlushMeasurements.push({
120
+ timerType: timerType,
121
+ instanceID: debugID,
122
+ duration: performanceNow() - currentTimerStartTime - currentTimerNestedFlushDuration
123
+ });
124
+ currentTimerStartTime = null;
125
+ currentTimerNestedFlushDuration = null;
126
+ currentTimerDebugID = null;
127
+ currentTimerType = null;
128
+ }
129
+
130
+ function pauseCurrentLifeCycleTimer() {
131
+ var currentTimer = {
132
+ startTime: currentTimerStartTime,
133
+ nestedFlushStartTime: performanceNow(),
134
+ debugID: currentTimerDebugID,
135
+ timerType: currentTimerType
136
+ };
137
+ lifeCycleTimerStack.push(currentTimer);
138
+ currentTimerStartTime = null;
139
+ currentTimerNestedFlushDuration = null;
140
+ currentTimerDebugID = null;
141
+ currentTimerType = null;
142
+ }
143
+
144
+ function resumeCurrentLifeCycleTimer() {
145
+ var _lifeCycleTimerStack$ = lifeCycleTimerStack.pop();
146
+
147
+ var startTime = _lifeCycleTimerStack$.startTime;
148
+ var nestedFlushStartTime = _lifeCycleTimerStack$.nestedFlushStartTime;
149
+ var debugID = _lifeCycleTimerStack$.debugID;
150
+ var timerType = _lifeCycleTimerStack$.timerType;
151
+
152
+ var nestedFlushDuration = performanceNow() - nestedFlushStartTime;
153
+ currentTimerStartTime = startTime;
154
+ currentTimerNestedFlushDuration += nestedFlushDuration;
155
+ currentTimerDebugID = debugID;
156
+ currentTimerType = timerType;
157
+ }
158
+
101
159
  var ReactDebugTool = {
102
160
  addDevtool: function (devtool) {
103
161
  eventHandlers.push(devtool);
@@ -110,6 +168,9 @@ var ReactDebugTool = {
110
168
  }
111
169
  }
112
170
  },
171
+ isProfiling: function () {
172
+ return isProfiling;
173
+ },
113
174
  beginProfiling: function () {
114
175
  if (process.env.NODE_ENV !== 'production') {
115
176
  if (isProfiling) {
@@ -132,14 +193,13 @@ var ReactDebugTool = {
132
193
  }
133
194
  },
134
195
  getFlushHistory: function () {
135
- if (process.env.NODE_ENV !== 'production') {
136
- return flushHistory;
137
- }
196
+ return flushHistory;
138
197
  },
139
198
  onBeginFlush: function () {
140
199
  if (process.env.NODE_ENV !== 'production') {
141
200
  currentFlushNesting++;
142
201
  resetMeasurements();
202
+ pauseCurrentLifeCycleTimer();
143
203
  }
144
204
  emitEvent('onBeginFlush');
145
205
  },
@@ -147,6 +207,7 @@ var ReactDebugTool = {
147
207
  if (process.env.NODE_ENV !== 'production') {
148
208
  resetMeasurements();
149
209
  currentFlushNesting--;
210
+ resumeCurrentLifeCycleTimer();
150
211
  }
151
212
  emitEvent('onEndFlush');
152
213
  },
@@ -154,28 +215,13 @@ var ReactDebugTool = {
154
215
  checkDebugID(debugID);
155
216
  emitEvent('onBeginLifeCycleTimer', debugID, timerType);
156
217
  if (process.env.NODE_ENV !== 'production') {
157
- if (isProfiling && currentFlushNesting > 0) {
158
- process.env.NODE_ENV !== 'production' ? warning(!currentTimerType, 'There is an internal error in the React performance measurement code. ' + 'Did not expect %s timer to start while %s timer is still in ' + 'progress for %s instance.', timerType, currentTimerType || 'no', debugID === currentTimerDebugID ? 'the same' : 'another') : void 0;
159
- currentTimerStartTime = performanceNow();
160
- currentTimerDebugID = debugID;
161
- currentTimerType = timerType;
162
- }
218
+ beginLifeCycleTimer(debugID, timerType);
163
219
  }
164
220
  },
165
221
  onEndLifeCycleTimer: function (debugID, timerType) {
166
222
  checkDebugID(debugID);
167
223
  if (process.env.NODE_ENV !== 'production') {
168
- if (isProfiling && currentFlushNesting > 0) {
169
- process.env.NODE_ENV !== 'production' ? warning(currentTimerType === timerType, 'There is an internal error in the React performance measurement code. ' + 'We did not expect %s timer to stop while %s timer is still in ' + 'progress for %s instance. Please report this as a bug in React.', timerType, currentTimerType || 'no', debugID === currentTimerDebugID ? 'the same' : 'another') : void 0;
170
- currentFlushMeasurements.push({
171
- timerType: timerType,
172
- instanceID: debugID,
173
- duration: performanceNow() - currentTimerStartTime
174
- });
175
- currentTimerStartTime = null;
176
- currentTimerDebugID = null;
177
- currentTimerType = null;
178
- }
224
+ endLifeCycleTimer(debugID, timerType);
179
225
  }
180
226
  emitEvent('onEndLifeCycleTimer', debugID, timerType);
181
227
  },
@@ -193,9 +239,9 @@ var ReactDebugTool = {
193
239
  onEndProcessingChildContext: function () {
194
240
  emitEvent('onEndProcessingChildContext');
195
241
  },
196
- onNativeOperation: function (debugID, type, payload) {
242
+ onHostOperation: function (debugID, type, payload) {
197
243
  checkDebugID(debugID);
198
- emitEvent('onNativeOperation', debugID, type, payload);
244
+ emitEvent('onHostOperation', debugID, type, payload);
199
245
  },
200
246
  onSetState: function () {
201
247
  emitEvent('onSetState');
@@ -212,6 +258,10 @@ var ReactDebugTool = {
212
258
  checkDebugID(debugID);
213
259
  emitEvent('onSetOwner', debugID, ownerDebugID);
214
260
  },
261
+ onSetParent: function (debugID, parentDebugID) {
262
+ checkDebugID(debugID);
263
+ emitEvent('onSetParent', debugID, parentDebugID);
264
+ },
215
265
  onSetText: function (debugID, text) {
216
266
  checkDebugID(debugID);
217
267
  emitEvent('onSetText', debugID, text);
@@ -220,10 +270,18 @@ var ReactDebugTool = {
220
270
  checkDebugID(debugID);
221
271
  emitEvent('onMountRootComponent', debugID);
222
272
  },
273
+ onBeforeMountComponent: function (debugID, element) {
274
+ checkDebugID(debugID);
275
+ emitEvent('onBeforeMountComponent', debugID, element);
276
+ },
223
277
  onMountComponent: function (debugID) {
224
278
  checkDebugID(debugID);
225
279
  emitEvent('onMountComponent', debugID);
226
280
  },
281
+ onBeforeUpdateComponent: function (debugID, element) {
282
+ checkDebugID(debugID);
283
+ emitEvent('onBeforeUpdateComponent', debugID, element);
284
+ },
227
285
  onUpdateComponent: function (debugID) {
228
286
  checkDebugID(debugID);
229
287
  emitEvent('onUpdateComponent', debugID);
@@ -231,16 +289,19 @@ var ReactDebugTool = {
231
289
  onUnmountComponent: function (debugID) {
232
290
  checkDebugID(debugID);
233
291
  emitEvent('onUnmountComponent', debugID);
292
+ },
293
+ onTestEvent: function () {
294
+ emitEvent('onTestEvent');
234
295
  }
235
296
  };
236
297
 
237
298
  if (process.env.NODE_ENV !== 'production') {
238
299
  var ReactInvalidSetStateWarningDevTool = require('./ReactInvalidSetStateWarningDevTool');
239
- var ReactNativeOperationHistoryDevtool = require('./ReactNativeOperationHistoryDevtool');
300
+ var ReactHostOperationHistoryDevtool = require('./ReactHostOperationHistoryDevtool');
240
301
  var ReactComponentTreeDevtool = require('./ReactComponentTreeDevtool');
241
302
  ReactDebugTool.addDevtool(ReactInvalidSetStateWarningDevTool);
242
303
  ReactDebugTool.addDevtool(ReactComponentTreeDevtool);
243
- ReactDebugTool.addDevtool(ReactNativeOperationHistoryDevtool);
304
+ ReactDebugTool.addDevtool(ReactHostOperationHistoryDevtool);
244
305
  var url = ExecutionEnvironment.canUseDOM && window.location.href || '';
245
306
  if (/[?&]react_perf\b/.test(url)) {
246
307
  ReactDebugTool.beginProfiling();
@@ -62,9 +62,9 @@ function inject() {
62
62
  BeforeInputEventPlugin: BeforeInputEventPlugin
63
63
  });
64
64
 
65
- ReactInjection.NativeComponent.injectGenericComponentClass(ReactDOMComponent);
65
+ ReactInjection.HostComponent.injectGenericComponentClass(ReactDOMComponent);
66
66
 
67
- ReactInjection.NativeComponent.injectTextComponentClass(ReactDOMTextComponent);
67
+ ReactInjection.HostComponent.injectTextComponentClass(ReactDOMTextComponent);
68
68
 
69
69
  ReactInjection.DOMProperty.injectDOMPropertyConfig(HTMLDOMPropertyConfig);
70
70
  ReactInjection.DOMProperty.injectDOMPropertyConfig(SVGDOMPropertyConfig);
@@ -17,6 +17,7 @@ var ReactCurrentOwner = require('./ReactCurrentOwner');
17
17
 
18
18
  var warning = require('fbjs/lib/warning');
19
19
  var canDefineProperty = require('./canDefineProperty');
20
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
20
21
 
21
22
  // The Symbol used to tag the ReactElement type. If there is no native Symbol
22
23
  // nor polyfill, then a plain number is used for performance.
@@ -31,6 +32,30 @@ var RESERVED_PROPS = {
31
32
 
32
33
  var specialPropKeyWarningShown, specialPropRefWarningShown;
33
34
 
35
+ function hasValidRef(config) {
36
+ if (process.env.NODE_ENV !== 'production') {
37
+ if (hasOwnProperty.call(config, 'ref')) {
38
+ var getter = Object.getOwnPropertyDescriptor(config, 'ref').get;
39
+ if (getter && getter.isReactWarning) {
40
+ return false;
41
+ }
42
+ }
43
+ }
44
+ return config.ref !== undefined;
45
+ }
46
+
47
+ function hasValidKey(config) {
48
+ if (process.env.NODE_ENV !== 'production') {
49
+ if (hasOwnProperty.call(config, 'key')) {
50
+ var getter = Object.getOwnPropertyDescriptor(config, 'key').get;
51
+ if (getter && getter.isReactWarning) {
52
+ return false;
53
+ }
54
+ }
55
+ }
56
+ return config.key !== undefined;
57
+ }
58
+
34
59
  /**
35
60
  * Factory method to create a new React element. This no longer adheres to
36
61
  * the class pattern, so do not use new to call it. Also, no instanceof check
@@ -135,17 +160,20 @@ ReactElement.createElement = function (type, config, children) {
135
160
  config.__proto__ == null || config.__proto__ === Object.prototype,
136
161
  /* eslint-enable no-proto */
137
162
  'React.createElement(...): Expected props argument to be a plain object. ' + 'Properties defined in its prototype chain will be ignored.') : void 0;
138
- ref = !config.hasOwnProperty('ref') || Object.getOwnPropertyDescriptor(config, 'ref').get ? null : config.ref;
139
- key = !config.hasOwnProperty('key') || Object.getOwnPropertyDescriptor(config, 'key').get ? null : '' + config.key;
140
- } else {
141
- ref = config.ref === undefined ? null : config.ref;
142
- key = config.key === undefined ? null : '' + config.key;
143
163
  }
164
+
165
+ if (hasValidRef(config)) {
166
+ ref = config.ref;
167
+ }
168
+ if (hasValidKey(config)) {
169
+ key = '' + config.key;
170
+ }
171
+
144
172
  self = config.__self === undefined ? null : config.__self;
145
173
  source = config.__source === undefined ? null : config.__source;
146
174
  // Remaining properties are added to a new props object
147
175
  for (propName in config) {
148
- if (config.hasOwnProperty(propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
176
+ if (hasOwnProperty.call(config, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
149
177
  props[propName] = config[propName];
150
178
  }
151
179
  }
@@ -174,30 +202,37 @@ ReactElement.createElement = function (type, config, children) {
174
202
  }
175
203
  }
176
204
  if (process.env.NODE_ENV !== 'production') {
177
- // Create dummy `key` and `ref` property to `props` to warn users
178
- // against its use
205
+ var displayName = typeof type === 'function' ? type.displayName || type.name || 'Unknown' : type;
206
+
207
+ // Create dummy `key` and `ref` property to `props` to warn users against its use
208
+ var warnAboutAccessingKey = function () {
209
+ if (!specialPropKeyWarningShown) {
210
+ specialPropKeyWarningShown = true;
211
+ process.env.NODE_ENV !== 'production' ? warning(false, '%s: `key` is not a prop. Trying to access it will result ' + 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://fb.me/react-special-props)', displayName) : void 0;
212
+ }
213
+ return undefined;
214
+ };
215
+ warnAboutAccessingKey.isReactWarning = true;
216
+
217
+ var warnAboutAccessingRef = function () {
218
+ if (!specialPropRefWarningShown) {
219
+ specialPropRefWarningShown = true;
220
+ process.env.NODE_ENV !== 'production' ? warning(false, '%s: `ref` is not a prop. Trying to access it will result ' + 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://fb.me/react-special-props)', displayName) : void 0;
221
+ }
222
+ return undefined;
223
+ };
224
+ warnAboutAccessingRef.isReactWarning = true;
225
+
179
226
  if (typeof props.$$typeof === 'undefined' || props.$$typeof !== REACT_ELEMENT_TYPE) {
180
227
  if (!props.hasOwnProperty('key')) {
181
228
  Object.defineProperty(props, 'key', {
182
- get: function () {
183
- if (!specialPropKeyWarningShown) {
184
- specialPropKeyWarningShown = true;
185
- process.env.NODE_ENV !== 'production' ? warning(false, '%s: `key` is not a prop. Trying to access it will result ' + 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://fb.me/react-special-props)', typeof type === 'function' && 'displayName' in type ? type.displayName : 'Element') : void 0;
186
- }
187
- return undefined;
188
- },
229
+ get: warnAboutAccessingKey,
189
230
  configurable: true
190
231
  });
191
232
  }
192
233
  if (!props.hasOwnProperty('ref')) {
193
234
  Object.defineProperty(props, 'ref', {
194
- get: function () {
195
- if (!specialPropRefWarningShown) {
196
- specialPropRefWarningShown = true;
197
- process.env.NODE_ENV !== 'production' ? warning(false, '%s: `ref` is not a prop. Trying to access it will result ' + 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://fb.me/react-special-props)', typeof type === 'function' && 'displayName' in type ? type.displayName : 'Element') : void 0;
198
- }
199
- return undefined;
200
- },
235
+ get: warnAboutAccessingRef,
201
236
  configurable: true
202
237
  });
203
238
  }
@@ -258,21 +293,23 @@ ReactElement.cloneElement = function (element, config, children) {
258
293
  /* eslint-enable no-proto */
259
294
  'React.cloneElement(...): Expected props argument to be a plain object. ' + 'Properties defined in its prototype chain will be ignored.') : void 0;
260
295
  }
261
- if (config.ref !== undefined) {
296
+
297
+ if (hasValidRef(config)) {
262
298
  // Silently steal the ref from the parent.
263
299
  ref = config.ref;
264
300
  owner = ReactCurrentOwner.current;
265
301
  }
266
- if (config.key !== undefined) {
302
+ if (hasValidKey(config)) {
267
303
  key = '' + config.key;
268
304
  }
305
+
269
306
  // Remaining properties override existing props
270
307
  var defaultProps;
271
308
  if (element.type && element.type.defaultProps) {
272
309
  defaultProps = element.type.defaultProps;
273
310
  }
274
311
  for (propName in config) {
275
- if (config.hasOwnProperty(propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
312
+ if (hasOwnProperty.call(config, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
276
313
  if (config[propName] === undefined && defaultProps !== undefined) {
277
314
  // Resolve default props
278
315
  props[propName] = defaultProps[propName];
@@ -310,4 +347,6 @@ ReactElement.isValidElement = function (object) {
310
347
  return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
311
348
  };
312
349
 
350
+ ReactElement.REACT_ELEMENT_TYPE = REACT_ELEMENT_TYPE;
351
+
313
352
  module.exports = ReactElement;
@@ -18,14 +18,15 @@
18
18
 
19
19
  'use strict';
20
20
 
21
+ var ReactCurrentOwner = require('./ReactCurrentOwner');
22
+ var ReactComponentTreeDevtool = require('./ReactComponentTreeDevtool');
21
23
  var ReactElement = require('./ReactElement');
22
24
  var ReactPropTypeLocations = require('./ReactPropTypeLocations');
23
- var ReactPropTypeLocationNames = require('./ReactPropTypeLocationNames');
24
- var ReactCurrentOwner = require('./ReactCurrentOwner');
25
+
26
+ var checkReactTypeSpec = require('./checkReactTypeSpec');
25
27
 
26
28
  var canDefineProperty = require('./canDefineProperty');
27
29
  var getIteratorFn = require('./getIteratorFn');
28
- var invariant = require('fbjs/lib/invariant');
29
30
  var warning = require('fbjs/lib/warning');
30
31
 
31
32
  function getDeclarationErrorAddendum() {
@@ -45,13 +46,24 @@ function getDeclarationErrorAddendum() {
45
46
  */
46
47
  var ownerHasKeyUseWarning = {};
47
48
 
48
- var loggedTypeFailures = {};
49
+ function getCurrentComponentErrorInfo(parentType) {
50
+ var info = getDeclarationErrorAddendum();
51
+
52
+ if (!info) {
53
+ var parentName = typeof parentType === 'string' ? parentType : parentType.displayName || parentType.name;
54
+ if (parentName) {
55
+ info = ' Check the top-level render call using <' + parentName + '>.';
56
+ }
57
+ }
58
+ return info;
59
+ }
49
60
 
50
61
  /**
51
62
  * Warn if the element doesn't have an explicit key assigned to it.
52
63
  * This element is in an array. The array could grow and shrink or be
53
64
  * reordered. All children that haven't already been validated are required to
54
- * have a "key" property assigned to it.
65
+ * have a "key" property assigned to it. Error statuses are cached so a warning
66
+ * will only be shown once.
55
67
  *
56
68
  * @internal
57
69
  * @param {ReactElement} element Element that requires a key.
@@ -63,54 +75,24 @@ function validateExplicitKey(element, parentType) {
63
75
  }
64
76
  element._store.validated = true;
65
77
 
66
- var addenda = getAddendaForKeyUse('uniqueKey', element, parentType);
67
- if (addenda === null) {
68
- // we already showed the warning
69
- return;
70
- }
71
- process.env.NODE_ENV !== 'production' ? warning(false, 'Each child in an array or iterator should have a unique "key" prop.' + '%s%s%s', addenda.parentOrOwner || '', addenda.childOwner || '', addenda.url || '') : void 0;
72
- }
73
-
74
- /**
75
- * Shared warning and monitoring code for the key warnings.
76
- *
77
- * @internal
78
- * @param {string} messageType A key used for de-duping warnings.
79
- * @param {ReactElement} element Component that requires a key.
80
- * @param {*} parentType element's parent's type.
81
- * @returns {?object} A set of addenda to use in the warning message, or null
82
- * if the warning has already been shown before (and shouldn't be shown again).
83
- */
84
- function getAddendaForKeyUse(messageType, element, parentType) {
85
- var addendum = getDeclarationErrorAddendum();
86
- if (!addendum) {
87
- var parentName = typeof parentType === 'string' ? parentType : parentType.displayName || parentType.name;
88
- if (parentName) {
89
- addendum = ' Check the top-level render call using <' + parentName + '>.';
90
- }
91
- }
78
+ var memoizer = ownerHasKeyUseWarning.uniqueKey || (ownerHasKeyUseWarning.uniqueKey = {});
92
79
 
93
- var memoizer = ownerHasKeyUseWarning[messageType] || (ownerHasKeyUseWarning[messageType] = {});
94
- if (memoizer[addendum]) {
95
- return null;
80
+ var currentComponentErrorInfo = getCurrentComponentErrorInfo(parentType);
81
+ if (memoizer[currentComponentErrorInfo]) {
82
+ return;
96
83
  }
97
- memoizer[addendum] = true;
98
-
99
- var addenda = {
100
- parentOrOwner: addendum,
101
- url: ' See https://fb.me/react-warning-keys for more information.',
102
- childOwner: null
103
- };
84
+ memoizer[currentComponentErrorInfo] = true;
104
85
 
105
86
  // Usually the current owner is the offender, but if it accepts children as a
106
87
  // property, it may be the creator of the child that's responsible for
107
88
  // assigning it a key.
89
+ var childOwner = '';
108
90
  if (element && element._owner && element._owner !== ReactCurrentOwner.current) {
109
91
  // Give the component that originally created this child.
110
- addenda.childOwner = ' It was passed a child from ' + element._owner.getName() + '.';
92
+ childOwner = ' It was passed a child from ' + element._owner.getName() + '.';
111
93
  }
112
94
 
113
- return addenda;
95
+ process.env.NODE_ENV !== 'production' ? warning(false, 'Each child in an array or iterator should have a unique "key" prop.' + '%s%s See https://fb.me/react-warning-keys for more information.%s', currentComponentErrorInfo, childOwner, ReactComponentTreeDevtool.getCurrentStackAddendum(element)) : void 0;
114
96
  }
115
97
 
116
98
  /**
@@ -155,43 +137,6 @@ function validateChildKeys(node, parentType) {
155
137
  }
156
138
  }
157
139
 
158
- /**
159
- * Assert that the props are valid
160
- *
161
- * @param {string} componentName Name of the component for error messages.
162
- * @param {object} propTypes Map of prop name to a ReactPropType
163
- * @param {object} props
164
- * @param {string} location e.g. "prop", "context", "child context"
165
- * @private
166
- */
167
- function checkPropTypes(componentName, propTypes, props, location) {
168
- for (var propName in propTypes) {
169
- if (propTypes.hasOwnProperty(propName)) {
170
- var error;
171
- // Prop type validation may throw. In case they do, we don't want to
172
- // fail the render phase where it didn't fail before. So we log it.
173
- // After these have been cleaned up, we'll let them throw.
174
- try {
175
- // This is intentionally an invariant that gets caught. It's the same
176
- // behavior as without this statement except with a better message.
177
- !(typeof propTypes[propName] === 'function') ? process.env.NODE_ENV !== 'production' ? invariant(false, '%s: %s type `%s` is invalid; it must be a function, usually from ' + 'React.PropTypes.', componentName || 'React class', ReactPropTypeLocationNames[location], propName) : invariant(false) : void 0;
178
- error = propTypes[propName](props, propName, componentName, location);
179
- } catch (ex) {
180
- error = ex;
181
- }
182
- process.env.NODE_ENV !== 'production' ? warning(!error || error instanceof Error, '%s: type specification of %s `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', ReactPropTypeLocationNames[location], propName, typeof error) : void 0;
183
- if (error instanceof Error && !(error.message in loggedTypeFailures)) {
184
- // Only monitor this failure once because there tends to be a lot of the
185
- // same error.
186
- loggedTypeFailures[error.message] = true;
187
-
188
- var addendum = getDeclarationErrorAddendum();
189
- process.env.NODE_ENV !== 'production' ? warning(false, 'Failed propType: %s%s', error.message, addendum) : void 0;
190
- }
191
- }
192
- }
193
- }
194
-
195
140
  /**
196
141
  * Given an element, validate that its props follow the propTypes definition,
197
142
  * provided by the type.
@@ -205,7 +150,7 @@ function validatePropTypes(element) {
205
150
  }
206
151
  var name = componentClass.displayName || componentClass.name;
207
152
  if (componentClass.propTypes) {
208
- checkPropTypes(name, componentClass.propTypes, element.props, ReactPropTypeLocations.prop);
153
+ checkReactTypeSpec(componentClass.propTypes, element.props, ReactPropTypeLocations.prop, name, element, null);
209
154
  }
210
155
  if (typeof componentClass.getDefaultProps === 'function') {
211
156
  process.env.NODE_ENV !== 'production' ? warning(componentClass.getDefaultProps.isReactClassApproved, 'getDefaultProps is only used on classic React.createClass ' + 'definitions. Use a static property named `defaultProps` instead.') : void 0;