react 15.6.0 → 16.0.0-alpha

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 (38) hide show
  1. package/README.md +7 -0
  2. package/dist/react-with-addons.js +3813 -4283
  3. package/dist/react-with-addons.min.js +2 -3
  4. package/dist/react.js +2882 -3136
  5. package/dist/react.min.js +2 -2
  6. package/lib/React.js +15 -58
  7. package/lib/ReactCSSTransitionGroup.js +4 -6
  8. package/lib/ReactCSSTransitionGroupChild.js +113 -131
  9. package/lib/ReactChildren.js +4 -4
  10. package/lib/ReactClass.js +703 -0
  11. package/lib/{ReactBaseClasses.js → ReactComponent.js} +6 -37
  12. package/lib/ReactComponentTreeHook.js +58 -55
  13. package/lib/ReactCurrentOwner.js +2 -0
  14. package/lib/ReactDOMFactories.js +1 -0
  15. package/lib/ReactElement.js +4 -4
  16. package/lib/ReactElementValidator.js +8 -9
  17. package/lib/ReactNoopUpdateQueue.js +10 -13
  18. package/lib/ReactPropTypes.js +442 -4
  19. package/lib/ReactPureComponent.js +41 -0
  20. package/lib/ReactTransitionGroup.js +3 -9
  21. package/lib/ReactTypeOfWork.js +26 -0
  22. package/lib/ReactUMDEntry.js +3 -4
  23. package/lib/ReactVersion.js +1 -1
  24. package/lib/ReactWithAddons.js +0 -2
  25. package/lib/ReactWithAddonsUMDEntry.js +3 -4
  26. package/lib/checkReactTypeSpec.js +17 -6
  27. package/lib/deprecated.js +3 -3
  28. package/lib/getComponentName.js +37 -0
  29. package/lib/onlyChild.js +1 -1
  30. package/lib/traverseAllChildren.js +1 -1
  31. package/package.json +3 -5
  32. package/lib/LinkedStateMixin.js +0 -34
  33. package/lib/ReactComponentTreeDevtool.js +0 -14
  34. package/lib/ReactLink.js +0 -50
  35. package/lib/ReactPropTypesSecret.js +0 -16
  36. package/lib/createClass.js +0 -22
  37. package/lib/getNextDebugIDUMDShim.js +0 -17
  38. package/lib/lowPriorityWarning.js +0 -64
@@ -10,15 +10,14 @@
10
10
 
11
11
  'use strict';
12
12
 
13
- var _prodInvariant = require('./reactProdInvariant'),
14
- _assign = require('object-assign');
13
+ var _prodInvariant = require('./reactProdInvariant');
15
14
 
16
15
  var ReactNoopUpdateQueue = require('./ReactNoopUpdateQueue');
17
16
 
18
17
  var canDefineProperty = require('./canDefineProperty');
19
18
  var emptyObject = require('fbjs/lib/emptyObject');
20
19
  var invariant = require('fbjs/lib/invariant');
21
- var lowPriorityWarning = require('./lowPriorityWarning');
20
+ var warning = require('fbjs/lib/warning');
22
21
 
23
22
  /**
24
23
  * Base class helpers for the updating state of a component.
@@ -61,10 +60,7 @@ ReactComponent.prototype.isReactComponent = {};
61
60
  */
62
61
  ReactComponent.prototype.setState = function (partialState, callback) {
63
62
  !(typeof partialState === 'object' || typeof partialState === 'function' || partialState == null) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'setState(...): takes an object of state variables to update or a function which returns an object of state variables.') : _prodInvariant('85') : void 0;
64
- this.updater.enqueueSetState(this, partialState);
65
- if (callback) {
66
- this.updater.enqueueCallback(this, callback, 'setState');
67
- }
63
+ this.updater.enqueueSetState(this, partialState, callback, 'setState');
68
64
  };
69
65
 
70
66
  /**
@@ -82,10 +78,7 @@ ReactComponent.prototype.setState = function (partialState, callback) {
82
78
  * @protected
83
79
  */
84
80
  ReactComponent.prototype.forceUpdate = function (callback) {
85
- this.updater.enqueueForceUpdate(this);
86
- if (callback) {
87
- this.updater.enqueueCallback(this, callback, 'forceUpdate');
88
- }
81
+ this.updater.enqueueForceUpdate(this, callback, 'forceUpdate');
89
82
  };
90
83
 
91
84
  /**
@@ -102,7 +95,7 @@ if (process.env.NODE_ENV !== 'production') {
102
95
  if (canDefineProperty) {
103
96
  Object.defineProperty(ReactComponent.prototype, methodName, {
104
97
  get: function () {
105
- lowPriorityWarning(false, '%s(...) is deprecated in plain JavaScript React classes. %s', info[0], info[1]);
98
+ process.env.NODE_ENV !== 'production' ? warning(false, '%s(...) is deprecated in plain JavaScript React classes. %s', info[0], info[1]) : void 0;
106
99
  return undefined;
107
100
  }
108
101
  });
@@ -115,28 +108,4 @@ if (process.env.NODE_ENV !== 'production') {
115
108
  }
116
109
  }
117
110
 
118
- /**
119
- * Base class helpers for the updating state of a component.
120
- */
121
- function ReactPureComponent(props, context, updater) {
122
- // Duplicated from ReactComponent.
123
- this.props = props;
124
- this.context = context;
125
- this.refs = emptyObject;
126
- // We initialize the default updater but the real one gets injected by the
127
- // renderer.
128
- this.updater = updater || ReactNoopUpdateQueue;
129
- }
130
-
131
- function ComponentDummy() {}
132
- ComponentDummy.prototype = ReactComponent.prototype;
133
- ReactPureComponent.prototype = new ComponentDummy();
134
- ReactPureComponent.prototype.constructor = ReactPureComponent;
135
- // Avoid an extra prototype jump for these methods.
136
- _assign(ReactPureComponent.prototype, ReactComponent.prototype);
137
- ReactPureComponent.prototype.isPureReactComponent = true;
138
-
139
- module.exports = {
140
- Component: ReactComponent,
141
- PureComponent: ReactPureComponent
142
- };
111
+ module.exports = ReactComponent;
@@ -14,7 +14,14 @@
14
14
  var _prodInvariant = require('./reactProdInvariant');
15
15
 
16
16
  var ReactCurrentOwner = require('./ReactCurrentOwner');
17
+ var ReactTypeOfWork = require('./ReactTypeOfWork');
18
+ var IndeterminateComponent = ReactTypeOfWork.IndeterminateComponent,
19
+ FunctionalComponent = ReactTypeOfWork.FunctionalComponent,
20
+ ClassComponent = ReactTypeOfWork.ClassComponent,
21
+ HostComponent = ReactTypeOfWork.HostComponent;
17
22
 
23
+
24
+ var getComponentName = require('./getComponentName');
18
25
  var invariant = require('fbjs/lib/invariant');
19
26
  var warning = require('fbjs/lib/warning');
20
27
 
@@ -24,11 +31,11 @@ function isNative(fn) {
24
31
  var hasOwnProperty = Object.prototype.hasOwnProperty;
25
32
  var reIsNative = RegExp('^' + funcToString
26
33
  // Take an example native function source for comparison
27
- .call(hasOwnProperty
34
+ .call(hasOwnProperty)
28
35
  // Strip regex characters so we can use it for regex
29
- ).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&'
36
+ .replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
30
37
  // Remove hasOwnProperty from the template to make it generic
31
- ).replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$');
38
+ .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$');
32
39
  try {
33
40
  var source = funcToString.call(fn);
34
41
  return reIsNative.test(source);
@@ -165,10 +172,29 @@ function describeID(id) {
165
172
  return describeComponentFrame(name, element && element._source, ownerName);
166
173
  }
167
174
 
175
+ function describeFiber(fiber) {
176
+ switch (fiber.tag) {
177
+ case IndeterminateComponent:
178
+ case FunctionalComponent:
179
+ case ClassComponent:
180
+ case HostComponent:
181
+ var owner = fiber._debugOwner;
182
+ var source = fiber._debugSource;
183
+ var name = getComponentName(fiber);
184
+ var ownerName = null;
185
+ if (owner) {
186
+ ownerName = getComponentName(owner);
187
+ }
188
+ return describeComponentFrame(name, source, ownerName);
189
+ default:
190
+ return '';
191
+ }
192
+ }
193
+
168
194
  var ReactComponentTreeHook = {
169
195
  onSetChildren: function (id, nextChildIDs) {
170
196
  var item = getItem(id);
171
- !item ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Item must have been set') : _prodInvariant('144') : void 0;
197
+ invariant(item, 'Item must have been set');
172
198
  item.childIDs = nextChildIDs;
173
199
 
174
200
  for (var i = 0; i < nextChildIDs.length; i++) {
@@ -208,7 +234,7 @@ var ReactComponentTreeHook = {
208
234
  },
209
235
  onMountComponent: function (id) {
210
236
  var item = getItem(id);
211
- !item ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Item must have been set') : _prodInvariant('144') : void 0;
237
+ invariant(item, 'Item must have been set');
212
238
  item.isMounted = true;
213
239
  var isRoot = item.parentID === 0;
214
240
  if (isRoot) {
@@ -261,13 +287,20 @@ var ReactComponentTreeHook = {
261
287
  if (topElement) {
262
288
  var name = getDisplayName(topElement);
263
289
  var owner = topElement._owner;
264
- info += describeComponentFrame(name, topElement._source, owner && owner.getName());
290
+ info += describeComponentFrame(name, topElement._source, owner && getComponentName(owner));
265
291
  }
266
292
 
267
293
  var currentOwner = ReactCurrentOwner.current;
268
- var id = currentOwner && currentOwner._debugID;
269
-
270
- info += ReactComponentTreeHook.getStackAddendumByID(id);
294
+ if (currentOwner) {
295
+ if (typeof currentOwner.tag === 'number') {
296
+ var workInProgress = currentOwner;
297
+ // Safe because if current owner exists, we are reconciling,
298
+ // and it is guaranteed to be the work-in-progress version.
299
+ info += ReactComponentTreeHook.getStackAddendumByWorkInProgressFiber(workInProgress);
300
+ } else if (typeof currentOwner._debugID === 'number') {
301
+ info += ReactComponentTreeHook.getStackAddendumByID(currentOwner._debugID);
302
+ }
303
+ }
271
304
  return info;
272
305
  },
273
306
  getStackAddendumByID: function (id) {
@@ -278,6 +311,21 @@ var ReactComponentTreeHook = {
278
311
  }
279
312
  return info;
280
313
  },
314
+
315
+
316
+ // This function can only be called with a work-in-progress fiber and
317
+ // only during begin or complete phase. Do not call it under any other
318
+ // circumstances.
319
+ getStackAddendumByWorkInProgressFiber: function (workInProgress) {
320
+ var info = '';
321
+ var node = workInProgress;
322
+ do {
323
+ info += describeFiber(node);
324
+ // Otherwise this return pointer might point to the wrong tree:
325
+ node = node['return'];
326
+ } while (node);
327
+ return info;
328
+ },
281
329
  getChildIDs: function (id) {
282
330
  var item = getItem(id);
283
331
  return item ? item.childIDs : [];
@@ -327,52 +375,7 @@ var ReactComponentTreeHook = {
327
375
 
328
376
 
329
377
  getRootIDs: getRootIDs,
330
- getRegisteredIDs: getItemIDs,
331
-
332
- pushNonStandardWarningStack: function (isCreatingElement, currentSource) {
333
- if (typeof console.reactStack !== 'function') {
334
- return;
335
- }
336
-
337
- var stack = [];
338
- var currentOwner = ReactCurrentOwner.current;
339
- var id = currentOwner && currentOwner._debugID;
340
-
341
- try {
342
- if (isCreatingElement) {
343
- stack.push({
344
- name: id ? ReactComponentTreeHook.getDisplayName(id) : null,
345
- fileName: currentSource ? currentSource.fileName : null,
346
- lineNumber: currentSource ? currentSource.lineNumber : null
347
- });
348
- }
349
-
350
- while (id) {
351
- var element = ReactComponentTreeHook.getElement(id);
352
- var parentID = ReactComponentTreeHook.getParentID(id);
353
- var ownerID = ReactComponentTreeHook.getOwnerID(id);
354
- var ownerName = ownerID ? ReactComponentTreeHook.getDisplayName(ownerID) : null;
355
- var source = element && element._source;
356
- stack.push({
357
- name: ownerName,
358
- fileName: source ? source.fileName : null,
359
- lineNumber: source ? source.lineNumber : null
360
- });
361
- id = parentID;
362
- }
363
- } catch (err) {
364
- // Internal state is messed up.
365
- // Stop building the stack (it's just a nice to have).
366
- }
367
-
368
- console.reactStack(stack);
369
- },
370
- popNonStandardWarningStack: function () {
371
- if (typeof console.reactStackEnd !== 'function') {
372
- return;
373
- }
374
- console.reactStackEnd();
375
- }
378
+ getRegisteredIDs: getItemIDs
376
379
  };
377
380
 
378
381
  module.exports = ReactComponentTreeHook;
@@ -18,11 +18,13 @@
18
18
  * currently being constructed.
19
19
  */
20
20
  var ReactCurrentOwner = {
21
+
21
22
  /**
22
23
  * @internal
23
24
  * @type {ReactComponent}
24
25
  */
25
26
  current: null
27
+
26
28
  };
27
29
 
28
30
  module.exports = ReactCurrentOwner;
@@ -25,6 +25,7 @@ if (process.env.NODE_ENV !== 'production') {
25
25
 
26
26
  /**
27
27
  * Creates a mapping from supported HTML tags to `ReactDOMComponent` classes.
28
+ * This is also accessible via `React.DOM`.
28
29
  *
29
30
  * @public
30
31
  */
@@ -165,7 +165,7 @@ var ReactElement = function (type, key, ref, self, source, owner, props) {
165
165
 
166
166
  /**
167
167
  * Create and return a new ReactElement of the given type.
168
- * See https://facebook.github.io/react/docs/top-level-api.html#react.createelement
168
+ * See https://facebook.github.io/react/docs/react-api.html#createelement
169
169
  */
170
170
  ReactElement.createElement = function (type, config, children) {
171
171
  var propName;
@@ -241,7 +241,7 @@ ReactElement.createElement = function (type, config, children) {
241
241
 
242
242
  /**
243
243
  * Return a function that produces ReactElements of a given type.
244
- * See https://facebook.github.io/react/docs/top-level-api.html#react.createfactory
244
+ * See https://facebook.github.io/react/docs/react-api.html#createfactory
245
245
  */
246
246
  ReactElement.createFactory = function (type) {
247
247
  var factory = ReactElement.createElement.bind(null, type);
@@ -262,7 +262,7 @@ ReactElement.cloneAndReplaceKey = function (oldElement, newKey) {
262
262
 
263
263
  /**
264
264
  * Clone and return a new ReactElement using element as the starting point.
265
- * See https://facebook.github.io/react/docs/top-level-api.html#react.cloneelement
265
+ * See https://facebook.github.io/react/docs/react-api.html#cloneelement
266
266
  */
267
267
  ReactElement.cloneElement = function (element, config, children) {
268
268
  var propName;
@@ -328,7 +328,7 @@ ReactElement.cloneElement = function (element, config, children) {
328
328
 
329
329
  /**
330
330
  * Verifies the object is a ReactElement.
331
- * See https://facebook.github.io/react/docs/top-level-api.html#react.isvalidelement
331
+ * See https://facebook.github.io/react/docs/react-api.html#isvalidelement
332
332
  * @param {?object} object
333
333
  * @return {boolean} True if `object` is a valid component.
334
334
  * @final
@@ -24,13 +24,13 @@ var ReactElement = require('./ReactElement');
24
24
  var checkReactTypeSpec = require('./checkReactTypeSpec');
25
25
 
26
26
  var canDefineProperty = require('./canDefineProperty');
27
+ var getComponentName = require('./getComponentName');
27
28
  var getIteratorFn = require('./getIteratorFn');
28
29
  var warning = require('fbjs/lib/warning');
29
- var lowPriorityWarning = require('./lowPriorityWarning');
30
30
 
31
31
  function getDeclarationErrorAddendum() {
32
32
  if (ReactCurrentOwner.current) {
33
- var name = ReactCurrentOwner.current.getName();
33
+ var name = getComponentName(ReactCurrentOwner.current);
34
34
  if (name) {
35
35
  return ' Check the render method of `' + name + '`.';
36
36
  }
@@ -98,7 +98,7 @@ function validateExplicitKey(element, parentType) {
98
98
  var childOwner = '';
99
99
  if (element && element._owner && element._owner !== ReactCurrentOwner.current) {
100
100
  // Give the component that originally created this child.
101
- childOwner = ' It was passed a child from ' + element._owner.getName() + '.';
101
+ childOwner = ' It was passed a child from ' + getComponentName(element._owner) + '.';
102
102
  }
103
103
 
104
104
  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, ReactComponentTreeHook.getCurrentStackAddendum(element)) : void 0;
@@ -167,15 +167,16 @@ function validatePropTypes(element) {
167
167
  }
168
168
 
169
169
  var ReactElementValidator = {
170
+
170
171
  createElement: function (type, props, children) {
171
- var validType = typeof type === 'string' || typeof type === 'function';
172
+ var validType = typeof type === 'string' || typeof type === 'function' || type !== null && typeof type === 'object' && typeof type.tag === 'number';
172
173
  // We warn in this case but don't throw. We expect the element creation to
173
174
  // succeed and there will likely be errors in render.
174
175
  if (!validType) {
175
176
  if (typeof type !== 'function' && typeof type !== 'string') {
176
177
  var info = '';
177
178
  if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) {
178
- info += ' You likely forgot to export your component from the file ' + "it's defined in.";
179
+ info += ' You likely forgot to export your component from the file ' + 'it\'s defined in.';
179
180
  }
180
181
 
181
182
  var sourceInfo = getSourceInfoErrorAddendum(props);
@@ -187,10 +188,7 @@ var ReactElementValidator = {
187
188
 
188
189
  info += ReactComponentTreeHook.getCurrentStackAddendum();
189
190
 
190
- var currentSource = props !== null && props !== undefined && props.__source !== undefined ? props.__source : null;
191
- ReactComponentTreeHook.pushNonStandardWarningStack(true, currentSource);
192
191
  process.env.NODE_ENV !== 'production' ? warning(false, 'React.createElement: type is invalid -- expected a string (for ' + 'built-in components) or a class/function (for composite ' + 'components) but got: %s.%s', type == null ? type : typeof type, info) : void 0;
193
- ReactComponentTreeHook.popNonStandardWarningStack();
194
192
  }
195
193
  }
196
194
 
@@ -228,7 +226,7 @@ var ReactElementValidator = {
228
226
  Object.defineProperty(validatedFactory, 'type', {
229
227
  enumerable: false,
230
228
  get: function () {
231
- lowPriorityWarning(false, 'Factory.type is deprecated. Access the class directly ' + 'before passing it to createFactory.');
229
+ process.env.NODE_ENV !== 'production' ? warning(false, 'Factory.type is deprecated. Access the class directly ' + 'before passing it to createFactory.') : void 0;
232
230
  Object.defineProperty(this, 'type', {
233
231
  value: type
234
232
  });
@@ -249,6 +247,7 @@ var ReactElementValidator = {
249
247
  validatePropTypes(newElement);
250
248
  return newElement;
251
249
  }
250
+
252
251
  };
253
252
 
254
253
  module.exports = ReactElementValidator;
@@ -23,6 +23,7 @@ function warnNoop(publicInstance, callerName) {
23
23
  * This is the abstract API for an update queue.
24
24
  */
25
25
  var ReactNoopUpdateQueue = {
26
+
26
27
  /**
27
28
  * Checks whether or not this composite component is mounted.
28
29
  * @param {ReactClass} publicInstance The instance we want to test.
@@ -34,16 +35,6 @@ var ReactNoopUpdateQueue = {
34
35
  return false;
35
36
  },
36
37
 
37
- /**
38
- * Enqueue a callback that will be executed after all the pending updates
39
- * have processed.
40
- *
41
- * @param {ReactClass} publicInstance The instance to use as `this` context.
42
- * @param {?function} callback Called after state is updated.
43
- * @internal
44
- */
45
- enqueueCallback: function (publicInstance, callback) {},
46
-
47
38
  /**
48
39
  * Forces an update. This should only be invoked when it is known with
49
40
  * certainty that we are **not** in a DOM transaction.
@@ -55,9 +46,11 @@ var ReactNoopUpdateQueue = {
55
46
  * `componentWillUpdate` and `componentDidUpdate`.
56
47
  *
57
48
  * @param {ReactClass} publicInstance The instance that should rerender.
49
+ * @param {?function} callback Called after component is updated.
50
+ * @param {?string} Name of the calling function in the public API.
58
51
  * @internal
59
52
  */
60
- enqueueForceUpdate: function (publicInstance) {
53
+ enqueueForceUpdate: function (publicInstance, callback, callerName) {
61
54
  warnNoop(publicInstance, 'forceUpdate');
62
55
  },
63
56
 
@@ -70,9 +63,11 @@ var ReactNoopUpdateQueue = {
70
63
  *
71
64
  * @param {ReactClass} publicInstance The instance that should rerender.
72
65
  * @param {object} completeState Next state.
66
+ * @param {?function} callback Called after component is updated.
67
+ * @param {?string} Name of the calling function in the public API.
73
68
  * @internal
74
69
  */
75
- enqueueReplaceState: function (publicInstance, completeState) {
70
+ enqueueReplaceState: function (publicInstance, completeState, callback, callerName) {
76
71
  warnNoop(publicInstance, 'replaceState');
77
72
  },
78
73
 
@@ -84,9 +79,11 @@ var ReactNoopUpdateQueue = {
84
79
  *
85
80
  * @param {ReactClass} publicInstance The instance that should rerender.
86
81
  * @param {object} partialState Next partial state to be merged with state.
82
+ * @param {?function} callback Called after component is updated.
83
+ * @param {?string} Name of the calling function in the public API.
87
84
  * @internal
88
85
  */
89
- enqueueSetState: function (publicInstance, partialState) {
86
+ enqueueSetState: function (publicInstance, partialState, callback, callerName) {
90
87
  warnNoop(publicInstance, 'setState');
91
88
  }
92
89
  };
@@ -10,9 +10,447 @@
10
10
 
11
11
  'use strict';
12
12
 
13
- var _require = require('./ReactElement'),
14
- isValidElement = _require.isValidElement;
13
+ var _prodInvariant = require('./reactProdInvariant');
15
14
 
16
- var factory = require('prop-types/factory');
15
+ var ReactElement = require('./ReactElement');
16
+ var ReactPropTypeLocationNames = require('./ReactPropTypeLocationNames');
17
17
 
18
- module.exports = factory(isValidElement);
18
+ var emptyFunction = require('fbjs/lib/emptyFunction');
19
+ var getIteratorFn = require('./getIteratorFn');
20
+ var invariant = require('fbjs/lib/invariant');
21
+ var warning = require('fbjs/lib/warning');
22
+
23
+ /**
24
+ * Collection of methods that allow declaration and validation of props that are
25
+ * supplied to React components. Example usage:
26
+ *
27
+ * var Props = require('ReactPropTypes');
28
+ * var MyArticle = React.createClass({
29
+ * propTypes: {
30
+ * // An optional string prop named "description".
31
+ * description: Props.string,
32
+ *
33
+ * // A required enum prop named "category".
34
+ * category: Props.oneOf(['News','Photos']).isRequired,
35
+ *
36
+ * // A prop named "dialog" that requires an instance of Dialog.
37
+ * dialog: Props.instanceOf(Dialog).isRequired
38
+ * },
39
+ * render: function() { ... }
40
+ * });
41
+ *
42
+ * A more formal specification of how these methods are used:
43
+ *
44
+ * type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...)
45
+ * decl := ReactPropTypes.{type}(.isRequired)?
46
+ *
47
+ * Each and every declaration produces a function with the same signature. This
48
+ * allows the creation of custom validation functions. For example:
49
+ *
50
+ * var MyLink = React.createClass({
51
+ * propTypes: {
52
+ * // An optional string or URI prop named "href".
53
+ * href: function(props, propName, componentName) {
54
+ * var propValue = props[propName];
55
+ * if (propValue != null && typeof propValue !== 'string' &&
56
+ * !(propValue instanceof URI)) {
57
+ * return new Error(
58
+ * 'Expected a string or an URI for ' + propName + ' in ' +
59
+ * componentName
60
+ * );
61
+ * }
62
+ * }
63
+ * },
64
+ * render: function() {...}
65
+ * });
66
+ *
67
+ * @internal
68
+ */
69
+
70
+ var ANONYMOUS = '<<anonymous>>';
71
+
72
+ var ReactPropTypes;
73
+
74
+ if (process.env.NODE_ENV !== 'production') {
75
+ // Keep in sync with production version below
76
+ ReactPropTypes = {
77
+ array: createPrimitiveTypeChecker('array'),
78
+ bool: createPrimitiveTypeChecker('boolean'),
79
+ func: createPrimitiveTypeChecker('function'),
80
+ number: createPrimitiveTypeChecker('number'),
81
+ object: createPrimitiveTypeChecker('object'),
82
+ string: createPrimitiveTypeChecker('string'),
83
+ symbol: createPrimitiveTypeChecker('symbol'),
84
+
85
+ any: createAnyTypeChecker(),
86
+ arrayOf: createArrayOfTypeChecker,
87
+ element: createElementTypeChecker(),
88
+ instanceOf: createInstanceTypeChecker,
89
+ node: createNodeChecker(),
90
+ objectOf: createObjectOfTypeChecker,
91
+ oneOf: createEnumTypeChecker,
92
+ oneOfType: createUnionTypeChecker,
93
+ shape: createShapeTypeChecker
94
+ };
95
+ } else {
96
+ var productionTypeChecker = function () {
97
+ invariant(false, 'React.PropTypes type checking code is stripped in production.');
98
+ };
99
+ productionTypeChecker.isRequired = productionTypeChecker;
100
+ var getProductionTypeChecker = function () {
101
+ return productionTypeChecker;
102
+ };
103
+ // Keep in sync with development version above
104
+ ReactPropTypes = {
105
+ array: productionTypeChecker,
106
+ bool: productionTypeChecker,
107
+ func: productionTypeChecker,
108
+ number: productionTypeChecker,
109
+ object: productionTypeChecker,
110
+ string: productionTypeChecker,
111
+ symbol: productionTypeChecker,
112
+
113
+ any: productionTypeChecker,
114
+ arrayOf: getProductionTypeChecker,
115
+ element: productionTypeChecker,
116
+ instanceOf: getProductionTypeChecker,
117
+ node: productionTypeChecker,
118
+ objectOf: getProductionTypeChecker,
119
+ oneOf: getProductionTypeChecker,
120
+ oneOfType: getProductionTypeChecker,
121
+ shape: getProductionTypeChecker
122
+ };
123
+ }
124
+
125
+ /**
126
+ * inlined Object.is polyfill to avoid requiring consumers ship their own
127
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
128
+ */
129
+ /*eslint-disable no-self-compare*/
130
+ function is(x, y) {
131
+ // SameValue algorithm
132
+ if (x === y) {
133
+ // Steps 1-5, 7-10
134
+ // Steps 6.b-6.e: +0 != -0
135
+ return x !== 0 || 1 / x === 1 / y;
136
+ } else {
137
+ // Step 6.a: NaN == NaN
138
+ return x !== x && y !== y;
139
+ }
140
+ }
141
+ /*eslint-enable no-self-compare*/
142
+
143
+ /**
144
+ * We use an Error-like object for backward compatibility as people may call
145
+ * PropTypes directly and inspect their output. However we don't use real
146
+ * Errors anymore. We don't inspect their stack anyway, and creating them
147
+ * is prohibitively expensive if they are created too often, such as what
148
+ * happens in oneOfType() for any type before the one that matched.
149
+ */
150
+ function PropTypeError(message) {
151
+ this.message = message;
152
+ this.stack = '';
153
+ }
154
+ // Make `instanceof Error` still work for returned errors.
155
+ PropTypeError.prototype = Error.prototype;
156
+
157
+ function createChainableTypeChecker(validate) {
158
+ function checkType(isRequired, props, propName, componentName, location, propFullName) {
159
+ componentName = componentName || ANONYMOUS;
160
+ propFullName = propFullName || propName;
161
+ if (props[propName] == null) {
162
+ var locationName = ReactPropTypeLocationNames[location];
163
+ if (isRequired) {
164
+ if (props[propName] === null) {
165
+ return new PropTypeError('The ' + locationName + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.'));
166
+ }
167
+ return new PropTypeError('The ' + locationName + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.'));
168
+ }
169
+ return null;
170
+ } else {
171
+ return validate(props, propName, componentName, location, propFullName);
172
+ }
173
+ }
174
+
175
+ var chainedCheckType = checkType.bind(null, false);
176
+ chainedCheckType.isRequired = checkType.bind(null, true);
177
+
178
+ return chainedCheckType;
179
+ }
180
+
181
+ function createPrimitiveTypeChecker(expectedType) {
182
+ function validate(props, propName, componentName, location, propFullName) {
183
+ var propValue = props[propName];
184
+ var propType = getPropType(propValue);
185
+ if (propType !== expectedType) {
186
+ var locationName = ReactPropTypeLocationNames[location];
187
+ // `propValue` being instance of, say, date/regexp, pass the 'object'
188
+ // check, but we can offer a more precise error message here rather than
189
+ // 'of type `object`'.
190
+ var preciseType = getPreciseType(propValue);
191
+
192
+ return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.'));
193
+ }
194
+ return null;
195
+ }
196
+ return createChainableTypeChecker(validate);
197
+ }
198
+
199
+ function createAnyTypeChecker() {
200
+ return createChainableTypeChecker(emptyFunction.thatReturns(null));
201
+ }
202
+
203
+ function createArrayOfTypeChecker(typeChecker) {
204
+ function validate(props, propName, componentName, location, propFullName) {
205
+ if (typeof typeChecker !== 'function') {
206
+ return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.');
207
+ }
208
+ var propValue = props[propName];
209
+ if (!Array.isArray(propValue)) {
210
+ var locationName = ReactPropTypeLocationNames[location];
211
+ var propType = getPropType(propValue);
212
+ return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.'));
213
+ }
214
+ for (var i = 0; i < propValue.length; i++) {
215
+ var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']');
216
+ if (error instanceof Error) {
217
+ return error;
218
+ }
219
+ }
220
+ return null;
221
+ }
222
+ return createChainableTypeChecker(validate);
223
+ }
224
+
225
+ function createElementTypeChecker() {
226
+ function validate(props, propName, componentName, location, propFullName) {
227
+ var propValue = props[propName];
228
+ if (!ReactElement.isValidElement(propValue)) {
229
+ var locationName = ReactPropTypeLocationNames[location];
230
+ var propType = getPropType(propValue);
231
+ return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.'));
232
+ }
233
+ return null;
234
+ }
235
+ return createChainableTypeChecker(validate);
236
+ }
237
+
238
+ function createInstanceTypeChecker(expectedClass) {
239
+ function validate(props, propName, componentName, location, propFullName) {
240
+ if (!(props[propName] instanceof expectedClass)) {
241
+ var locationName = ReactPropTypeLocationNames[location];
242
+ var expectedClassName = expectedClass.name || ANONYMOUS;
243
+ var actualClassName = getClassName(props[propName]);
244
+ return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.'));
245
+ }
246
+ return null;
247
+ }
248
+ return createChainableTypeChecker(validate);
249
+ }
250
+
251
+ function createEnumTypeChecker(expectedValues) {
252
+ if (!Array.isArray(expectedValues)) {
253
+ process.env.NODE_ENV !== 'production' ? warning(false, 'Invalid argument supplied to oneOf, expected an instance of array.') : void 0;
254
+ return emptyFunction.thatReturnsNull;
255
+ }
256
+
257
+ function validate(props, propName, componentName, location, propFullName) {
258
+ var propValue = props[propName];
259
+ for (var i = 0; i < expectedValues.length; i++) {
260
+ if (is(propValue, expectedValues[i])) {
261
+ return null;
262
+ }
263
+ }
264
+
265
+ var locationName = ReactPropTypeLocationNames[location];
266
+ var valuesString = JSON.stringify(expectedValues);
267
+ return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of value `' + propValue + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.'));
268
+ }
269
+ return createChainableTypeChecker(validate);
270
+ }
271
+
272
+ function createObjectOfTypeChecker(typeChecker) {
273
+ function validate(props, propName, componentName, location, propFullName) {
274
+ if (typeof typeChecker !== 'function') {
275
+ return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.');
276
+ }
277
+ var propValue = props[propName];
278
+ var propType = getPropType(propValue);
279
+ if (propType !== 'object') {
280
+ var locationName = ReactPropTypeLocationNames[location];
281
+ return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.'));
282
+ }
283
+ for (var key in propValue) {
284
+ if (propValue.hasOwnProperty(key)) {
285
+ var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key);
286
+ if (error instanceof Error) {
287
+ return error;
288
+ }
289
+ }
290
+ }
291
+ return null;
292
+ }
293
+ return createChainableTypeChecker(validate);
294
+ }
295
+
296
+ function createUnionTypeChecker(arrayOfTypeCheckers) {
297
+ if (!Array.isArray(arrayOfTypeCheckers)) {
298
+ process.env.NODE_ENV !== 'production' ? warning(false, 'Invalid argument supplied to oneOfType, expected an instance of array.') : void 0;
299
+ return emptyFunction.thatReturnsNull;
300
+ }
301
+
302
+ function validate(props, propName, componentName, location, propFullName) {
303
+ for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
304
+ var checker = arrayOfTypeCheckers[i];
305
+ if (checker(props, propName, componentName, location, propFullName) == null) {
306
+ return null;
307
+ }
308
+ }
309
+
310
+ var locationName = ReactPropTypeLocationNames[location];
311
+ return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.'));
312
+ }
313
+ return createChainableTypeChecker(validate);
314
+ }
315
+
316
+ function createNodeChecker() {
317
+ function validate(props, propName, componentName, location, propFullName) {
318
+ if (!isNode(props[propName])) {
319
+ var locationName = ReactPropTypeLocationNames[location];
320
+ return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.'));
321
+ }
322
+ return null;
323
+ }
324
+ return createChainableTypeChecker(validate);
325
+ }
326
+
327
+ function createShapeTypeChecker(shapeTypes) {
328
+ function validate(props, propName, componentName, location, propFullName) {
329
+ var propValue = props[propName];
330
+ var propType = getPropType(propValue);
331
+ if (propType !== 'object') {
332
+ var locationName = ReactPropTypeLocationNames[location];
333
+ return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
334
+ }
335
+ for (var key in shapeTypes) {
336
+ var checker = shapeTypes[key];
337
+ if (!checker) {
338
+ continue;
339
+ }
340
+ var error = checker(propValue, key, componentName, location, propFullName + '.' + key);
341
+ if (error) {
342
+ return error;
343
+ }
344
+ }
345
+ return null;
346
+ }
347
+ return createChainableTypeChecker(validate);
348
+ }
349
+
350
+ function isNode(propValue) {
351
+ switch (typeof propValue) {
352
+ case 'number':
353
+ case 'string':
354
+ case 'undefined':
355
+ return true;
356
+ case 'boolean':
357
+ return !propValue;
358
+ case 'object':
359
+ if (Array.isArray(propValue)) {
360
+ return propValue.every(isNode);
361
+ }
362
+ if (propValue === null || ReactElement.isValidElement(propValue)) {
363
+ return true;
364
+ }
365
+
366
+ var iteratorFn = getIteratorFn(propValue);
367
+ if (iteratorFn) {
368
+ var iterator = iteratorFn.call(propValue);
369
+ var step;
370
+ if (iteratorFn !== propValue.entries) {
371
+ while (!(step = iterator.next()).done) {
372
+ if (!isNode(step.value)) {
373
+ return false;
374
+ }
375
+ }
376
+ } else {
377
+ // Iterator will provide entry [k,v] tuples rather than values.
378
+ while (!(step = iterator.next()).done) {
379
+ var entry = step.value;
380
+ if (entry) {
381
+ if (!isNode(entry[1])) {
382
+ return false;
383
+ }
384
+ }
385
+ }
386
+ }
387
+ } else {
388
+ return false;
389
+ }
390
+
391
+ return true;
392
+ default:
393
+ return false;
394
+ }
395
+ }
396
+
397
+ function isSymbol(propType, propValue) {
398
+ // Native Symbol.
399
+ if (propType === 'symbol') {
400
+ return true;
401
+ }
402
+
403
+ // 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol'
404
+ if (propValue['@@toStringTag'] === 'Symbol') {
405
+ return true;
406
+ }
407
+
408
+ // Fallback for non-spec compliant Symbols which are polyfilled.
409
+ if (typeof Symbol === 'function' && propValue instanceof Symbol) {
410
+ return true;
411
+ }
412
+
413
+ return false;
414
+ }
415
+
416
+ // Equivalent of `typeof` but with special handling for array and regexp.
417
+ function getPropType(propValue) {
418
+ var propType = typeof propValue;
419
+ if (Array.isArray(propValue)) {
420
+ return 'array';
421
+ }
422
+ if (propValue instanceof RegExp) {
423
+ // Old webkits (at least until Android 4.0) return 'function' rather than
424
+ // 'object' for typeof a RegExp. We'll normalize this here so that /bla/
425
+ // passes PropTypes.object.
426
+ return 'object';
427
+ }
428
+ if (isSymbol(propType, propValue)) {
429
+ return 'symbol';
430
+ }
431
+ return propType;
432
+ }
433
+
434
+ // This handles more types than `getPropType`. Only used for error messages.
435
+ // See `createPrimitiveTypeChecker`.
436
+ function getPreciseType(propValue) {
437
+ var propType = getPropType(propValue);
438
+ if (propType === 'object') {
439
+ if (propValue instanceof Date) {
440
+ return 'date';
441
+ } else if (propValue instanceof RegExp) {
442
+ return 'regexp';
443
+ }
444
+ }
445
+ return propType;
446
+ }
447
+
448
+ // Returns class name of the object, if any.
449
+ function getClassName(propValue) {
450
+ if (!propValue.constructor || !propValue.constructor.name) {
451
+ return ANONYMOUS;
452
+ }
453
+ return propValue.constructor.name;
454
+ }
455
+
456
+ module.exports = ReactPropTypes;