react 16.0.0-alpha → 16.0.0-alpha.4
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.
- package/dist/react-with-addons.js +595 -536
- package/dist/react-with-addons.min.js +7 -2
- package/dist/react.js +547 -486
- package/dist/react.min.js +7 -2
- package/lib/React.js +17 -19
- package/lib/ReactAddonsDOMDependencies.js +1 -1
- package/lib/{ReactComponent.js → ReactBaseClasses.js} +27 -2
- package/lib/ReactClass.js +9 -9
- package/lib/ReactComponentTreeHook.js +8 -47
- package/lib/ReactDebugCurrentFrame.js +55 -0
- package/lib/ReactElementValidator.js +40 -22
- package/lib/ReactFiberComponentTreeHook.js +62 -0
- package/lib/ReactNoopUpdateQueue.js +1 -1
- package/lib/ReactPropTypes.js +33 -31
- package/lib/{ReactPropTypeLocations.js → ReactPropTypesSecret.js} +5 -1
- package/lib/ReactVersion.js +1 -1
- package/lib/checkPropTypes.js +64 -0
- package/lib/checkReactTypeSpec.js +5 -80
- package/lib/getComponentName.js +14 -16
- package/lib/traverseAllChildren.js +16 -27
- package/lib/update.js +2 -2
- package/package.json +2 -2
- package/lib/ReactPropTypeLocationNames.js +0 -24
- package/lib/ReactPureComponent.js +0 -41
- package/lib/ReactStateSetters.js +0 -103
- package/lib/sliceChildren.js +0 -33
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2016-present, 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
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
var ReactTypeOfWork = require('./ReactTypeOfWork');
|
|
15
|
+
var IndeterminateComponent = ReactTypeOfWork.IndeterminateComponent,
|
|
16
|
+
FunctionalComponent = ReactTypeOfWork.FunctionalComponent,
|
|
17
|
+
ClassComponent = ReactTypeOfWork.ClassComponent,
|
|
18
|
+
HostComponent = ReactTypeOfWork.HostComponent;
|
|
19
|
+
|
|
20
|
+
var getComponentName = require('./getComponentName');
|
|
21
|
+
|
|
22
|
+
function describeComponentFrame(name, source, ownerName) {
|
|
23
|
+
return '\n in ' + (name || 'Unknown') + (source ? ' (at ' + source.fileName.replace(/^.*[\\\/]/, '') + ':' + source.lineNumber + ')' : ownerName ? ' (created by ' + ownerName + ')' : '');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function describeFiber(fiber) {
|
|
27
|
+
switch (fiber.tag) {
|
|
28
|
+
case IndeterminateComponent:
|
|
29
|
+
case FunctionalComponent:
|
|
30
|
+
case ClassComponent:
|
|
31
|
+
case HostComponent:
|
|
32
|
+
var owner = fiber._debugOwner;
|
|
33
|
+
var source = fiber._debugSource;
|
|
34
|
+
var name = getComponentName(fiber);
|
|
35
|
+
var ownerName = null;
|
|
36
|
+
if (owner) {
|
|
37
|
+
ownerName = getComponentName(owner);
|
|
38
|
+
}
|
|
39
|
+
return describeComponentFrame(name, source, ownerName);
|
|
40
|
+
default:
|
|
41
|
+
return '';
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// This function can only be called with a work-in-progress fiber and
|
|
46
|
+
// only during begin or complete phase. Do not call it under any other
|
|
47
|
+
// circumstances.
|
|
48
|
+
function getStackAddendumByWorkInProgressFiber(workInProgress) {
|
|
49
|
+
var info = '';
|
|
50
|
+
var node = workInProgress;
|
|
51
|
+
do {
|
|
52
|
+
info += describeFiber(node);
|
|
53
|
+
// Otherwise this return pointer might point to the wrong tree:
|
|
54
|
+
node = node['return'];
|
|
55
|
+
} while (node);
|
|
56
|
+
return info;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
module.exports = {
|
|
60
|
+
getStackAddendumByWorkInProgressFiber: getStackAddendumByWorkInProgressFiber,
|
|
61
|
+
describeComponentFrame: describeComponentFrame
|
|
62
|
+
};
|
|
@@ -15,7 +15,7 @@ var warning = require('fbjs/lib/warning');
|
|
|
15
15
|
function warnNoop(publicInstance, callerName) {
|
|
16
16
|
if (process.env.NODE_ENV !== 'production') {
|
|
17
17
|
var constructor = publicInstance.constructor;
|
|
18
|
-
process.env.NODE_ENV !== 'production' ? warning(false, '%s(...): Can only update a mounted or mounting component. ' + 'This usually means you called %s() on an unmounted component. ' + 'This is a no-op
|
|
18
|
+
process.env.NODE_ENV !== 'production' ? warning(false, '%s(...): Can only update a mounted or mounting component. ' + 'This usually means you called %s() on an unmounted component. ' + 'This is a no-op.\n\nPlease check the code for the %s component.', callerName, callerName, constructor && (constructor.displayName || constructor.name) || 'ReactClass') : void 0;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
package/lib/ReactPropTypes.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
var _prodInvariant = require('./reactProdInvariant');
|
|
14
14
|
|
|
15
15
|
var ReactElement = require('./ReactElement');
|
|
16
|
-
var
|
|
16
|
+
var ReactPropTypesSecret = require('./ReactPropTypesSecret');
|
|
17
17
|
|
|
18
18
|
var emptyFunction = require('fbjs/lib/emptyFunction');
|
|
19
19
|
var getIteratorFn = require('./getIteratorFn');
|
|
@@ -94,7 +94,7 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
94
94
|
};
|
|
95
95
|
} else {
|
|
96
96
|
var productionTypeChecker = function () {
|
|
97
|
-
invariant(false, 'React.PropTypes type checking code is stripped in production.');
|
|
97
|
+
!false ? process.env.NODE_ENV !== 'production' ? invariant(false, 'React.PropTypes type checking code is stripped in production.') : _prodInvariant('144') : void 0;
|
|
98
98
|
};
|
|
99
99
|
productionTypeChecker.isRequired = productionTypeChecker;
|
|
100
100
|
var getProductionTypeChecker = function () {
|
|
@@ -142,7 +142,7 @@ function is(x, y) {
|
|
|
142
142
|
|
|
143
143
|
/**
|
|
144
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
|
|
145
|
+
* PropTypes directly and inspect their output. However, we don't use real
|
|
146
146
|
* Errors anymore. We don't inspect their stack anyway, and creating them
|
|
147
147
|
* is prohibitively expensive if they are created too often, such as what
|
|
148
148
|
* happens in oneOfType() for any type before the one that matched.
|
|
@@ -155,16 +155,27 @@ function PropTypeError(message) {
|
|
|
155
155
|
PropTypeError.prototype = Error.prototype;
|
|
156
156
|
|
|
157
157
|
function createChainableTypeChecker(validate) {
|
|
158
|
-
|
|
158
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
159
|
+
var manualPropTypeCallCache = {};
|
|
160
|
+
}
|
|
161
|
+
function checkType(isRequired, props, propName, componentName, location, propFullName, secret) {
|
|
159
162
|
componentName = componentName || ANONYMOUS;
|
|
160
163
|
propFullName = propFullName || propName;
|
|
164
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
165
|
+
if (secret !== ReactPropTypesSecret && typeof console !== 'undefined') {
|
|
166
|
+
var cacheKey = componentName + ':' + propName;
|
|
167
|
+
if (!manualPropTypeCallCache[cacheKey]) {
|
|
168
|
+
process.env.NODE_ENV !== 'production' ? warning(false, 'You are manually calling a React.PropTypes validation ' + 'function for the `%s` prop on `%s`. This is deprecated ' + 'and will not work in production with the next major version. ' + 'You may be seeing this warning due to a third-party PropTypes ' + 'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.', propFullName, componentName) : void 0;
|
|
169
|
+
manualPropTypeCallCache[cacheKey] = true;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
161
173
|
if (props[propName] == null) {
|
|
162
|
-
var locationName = ReactPropTypeLocationNames[location];
|
|
163
174
|
if (isRequired) {
|
|
164
175
|
if (props[propName] === null) {
|
|
165
|
-
return new PropTypeError('The ' +
|
|
176
|
+
return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.'));
|
|
166
177
|
}
|
|
167
|
-
return new PropTypeError('The ' +
|
|
178
|
+
return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.'));
|
|
168
179
|
}
|
|
169
180
|
return null;
|
|
170
181
|
} else {
|
|
@@ -179,17 +190,16 @@ function createChainableTypeChecker(validate) {
|
|
|
179
190
|
}
|
|
180
191
|
|
|
181
192
|
function createPrimitiveTypeChecker(expectedType) {
|
|
182
|
-
function validate(props, propName, componentName, location, propFullName) {
|
|
193
|
+
function validate(props, propName, componentName, location, propFullName, secret) {
|
|
183
194
|
var propValue = props[propName];
|
|
184
195
|
var propType = getPropType(propValue);
|
|
185
196
|
if (propType !== expectedType) {
|
|
186
|
-
var locationName = ReactPropTypeLocationNames[location];
|
|
187
197
|
// `propValue` being instance of, say, date/regexp, pass the 'object'
|
|
188
198
|
// check, but we can offer a more precise error message here rather than
|
|
189
199
|
// 'of type `object`'.
|
|
190
200
|
var preciseType = getPreciseType(propValue);
|
|
191
201
|
|
|
192
|
-
return new PropTypeError('Invalid ' +
|
|
202
|
+
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.'));
|
|
193
203
|
}
|
|
194
204
|
return null;
|
|
195
205
|
}
|
|
@@ -197,7 +207,7 @@ function createPrimitiveTypeChecker(expectedType) {
|
|
|
197
207
|
}
|
|
198
208
|
|
|
199
209
|
function createAnyTypeChecker() {
|
|
200
|
-
return createChainableTypeChecker(emptyFunction.
|
|
210
|
+
return createChainableTypeChecker(emptyFunction.thatReturnsNull);
|
|
201
211
|
}
|
|
202
212
|
|
|
203
213
|
function createArrayOfTypeChecker(typeChecker) {
|
|
@@ -207,12 +217,11 @@ function createArrayOfTypeChecker(typeChecker) {
|
|
|
207
217
|
}
|
|
208
218
|
var propValue = props[propName];
|
|
209
219
|
if (!Array.isArray(propValue)) {
|
|
210
|
-
var locationName = ReactPropTypeLocationNames[location];
|
|
211
220
|
var propType = getPropType(propValue);
|
|
212
|
-
return new PropTypeError('Invalid ' +
|
|
221
|
+
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.'));
|
|
213
222
|
}
|
|
214
223
|
for (var i = 0; i < propValue.length; i++) {
|
|
215
|
-
var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']');
|
|
224
|
+
var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret);
|
|
216
225
|
if (error instanceof Error) {
|
|
217
226
|
return error;
|
|
218
227
|
}
|
|
@@ -226,9 +235,8 @@ function createElementTypeChecker() {
|
|
|
226
235
|
function validate(props, propName, componentName, location, propFullName) {
|
|
227
236
|
var propValue = props[propName];
|
|
228
237
|
if (!ReactElement.isValidElement(propValue)) {
|
|
229
|
-
var locationName = ReactPropTypeLocationNames[location];
|
|
230
238
|
var propType = getPropType(propValue);
|
|
231
|
-
return new PropTypeError('Invalid ' +
|
|
239
|
+
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.'));
|
|
232
240
|
}
|
|
233
241
|
return null;
|
|
234
242
|
}
|
|
@@ -238,10 +246,9 @@ function createElementTypeChecker() {
|
|
|
238
246
|
function createInstanceTypeChecker(expectedClass) {
|
|
239
247
|
function validate(props, propName, componentName, location, propFullName) {
|
|
240
248
|
if (!(props[propName] instanceof expectedClass)) {
|
|
241
|
-
var locationName = ReactPropTypeLocationNames[location];
|
|
242
249
|
var expectedClassName = expectedClass.name || ANONYMOUS;
|
|
243
250
|
var actualClassName = getClassName(props[propName]);
|
|
244
|
-
return new PropTypeError('Invalid ' +
|
|
251
|
+
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.'));
|
|
245
252
|
}
|
|
246
253
|
return null;
|
|
247
254
|
}
|
|
@@ -262,9 +269,8 @@ function createEnumTypeChecker(expectedValues) {
|
|
|
262
269
|
}
|
|
263
270
|
}
|
|
264
271
|
|
|
265
|
-
var locationName = ReactPropTypeLocationNames[location];
|
|
266
272
|
var valuesString = JSON.stringify(expectedValues);
|
|
267
|
-
return new PropTypeError('Invalid ' +
|
|
273
|
+
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + propValue + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.'));
|
|
268
274
|
}
|
|
269
275
|
return createChainableTypeChecker(validate);
|
|
270
276
|
}
|
|
@@ -277,12 +283,11 @@ function createObjectOfTypeChecker(typeChecker) {
|
|
|
277
283
|
var propValue = props[propName];
|
|
278
284
|
var propType = getPropType(propValue);
|
|
279
285
|
if (propType !== 'object') {
|
|
280
|
-
|
|
281
|
-
return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.'));
|
|
286
|
+
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.'));
|
|
282
287
|
}
|
|
283
288
|
for (var key in propValue) {
|
|
284
289
|
if (propValue.hasOwnProperty(key)) {
|
|
285
|
-
var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key);
|
|
290
|
+
var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
|
|
286
291
|
if (error instanceof Error) {
|
|
287
292
|
return error;
|
|
288
293
|
}
|
|
@@ -302,13 +307,12 @@ function createUnionTypeChecker(arrayOfTypeCheckers) {
|
|
|
302
307
|
function validate(props, propName, componentName, location, propFullName) {
|
|
303
308
|
for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
|
|
304
309
|
var checker = arrayOfTypeCheckers[i];
|
|
305
|
-
if (checker(props, propName, componentName, location, propFullName) == null) {
|
|
310
|
+
if (checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret) == null) {
|
|
306
311
|
return null;
|
|
307
312
|
}
|
|
308
313
|
}
|
|
309
314
|
|
|
310
|
-
|
|
311
|
-
return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.'));
|
|
315
|
+
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.'));
|
|
312
316
|
}
|
|
313
317
|
return createChainableTypeChecker(validate);
|
|
314
318
|
}
|
|
@@ -316,8 +320,7 @@ function createUnionTypeChecker(arrayOfTypeCheckers) {
|
|
|
316
320
|
function createNodeChecker() {
|
|
317
321
|
function validate(props, propName, componentName, location, propFullName) {
|
|
318
322
|
if (!isNode(props[propName])) {
|
|
319
|
-
|
|
320
|
-
return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.'));
|
|
323
|
+
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.'));
|
|
321
324
|
}
|
|
322
325
|
return null;
|
|
323
326
|
}
|
|
@@ -329,15 +332,14 @@ function createShapeTypeChecker(shapeTypes) {
|
|
|
329
332
|
var propValue = props[propName];
|
|
330
333
|
var propType = getPropType(propValue);
|
|
331
334
|
if (propType !== 'object') {
|
|
332
|
-
|
|
333
|
-
return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
|
|
335
|
+
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
|
|
334
336
|
}
|
|
335
337
|
for (var key in shapeTypes) {
|
|
336
338
|
var checker = shapeTypes[key];
|
|
337
339
|
if (!checker) {
|
|
338
340
|
continue;
|
|
339
341
|
}
|
|
340
|
-
var error = checker(propValue, key, componentName, location, propFullName + '.' + key);
|
|
342
|
+
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
|
|
341
343
|
if (error) {
|
|
342
344
|
return error;
|
|
343
345
|
}
|
package/lib/ReactVersion.js
CHANGED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2013-present, 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
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
var _prodInvariant = require('./reactProdInvariant');
|
|
14
|
+
|
|
15
|
+
var ReactPropTypesSecret = require('./ReactPropTypesSecret');
|
|
16
|
+
|
|
17
|
+
var invariant = require('fbjs/lib/invariant');
|
|
18
|
+
var warning = require('fbjs/lib/warning');
|
|
19
|
+
|
|
20
|
+
var loggedTypeFailures = {};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Assert that the values match with the type specs.
|
|
24
|
+
* Error messages are memorized and will only be shown once.
|
|
25
|
+
*
|
|
26
|
+
* @param {object} typeSpecs Map of name to a ReactPropType
|
|
27
|
+
* @param {object} values Runtime values that need to be type-checked
|
|
28
|
+
* @param {string} location e.g. "prop", "context", "child context"
|
|
29
|
+
* @param {string} componentName Name of the component for error messages.
|
|
30
|
+
* @param {?Function} getStack Returns the component stack.
|
|
31
|
+
* @private
|
|
32
|
+
*/
|
|
33
|
+
function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
|
|
34
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
35
|
+
for (var typeSpecName in typeSpecs) {
|
|
36
|
+
if (typeSpecs.hasOwnProperty(typeSpecName)) {
|
|
37
|
+
var error;
|
|
38
|
+
// Prop type validation may throw. In case they do, we don't want to
|
|
39
|
+
// fail the render phase where it didn't fail before. So we log it.
|
|
40
|
+
// After these have been cleaned up, we'll let them throw.
|
|
41
|
+
try {
|
|
42
|
+
// This is intentionally an invariant that gets caught. It's the same
|
|
43
|
+
// behavior as without this statement except with a better message.
|
|
44
|
+
!(typeof typeSpecs[typeSpecName] === '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', location, typeSpecName) : _prodInvariant('84', componentName || 'React class', location, typeSpecName) : void 0;
|
|
45
|
+
error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
|
|
46
|
+
} catch (ex) {
|
|
47
|
+
error = ex;
|
|
48
|
+
}
|
|
49
|
+
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', location, typeSpecName, typeof error) : void 0;
|
|
50
|
+
if (error instanceof Error && !(error.message in loggedTypeFailures)) {
|
|
51
|
+
// Only monitor this failure once because there tends to be a lot of the
|
|
52
|
+
// same error.
|
|
53
|
+
loggedTypeFailures[error.message] = true;
|
|
54
|
+
|
|
55
|
+
var stack = getStack ? getStack() : '';
|
|
56
|
+
|
|
57
|
+
process.env.NODE_ENV !== 'production' ? warning(false, 'Failed %s type: %s%s', location, error.message, stack != null ? stack : '') : void 0;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = checkPropTypes;
|
|
@@ -10,88 +10,13 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var checkPropTypes = require('./checkPropTypes');
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var _require = require('./ReactDebugCurrentFrame'),
|
|
16
|
+
getStackAddendum = _require.getStackAddendum;
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var ReactComponentTreeHook;
|
|
21
|
-
|
|
22
|
-
if (typeof process !== 'undefined' && process.env && process.env.NODE_ENV === 'test') {
|
|
23
|
-
// Temporary hack.
|
|
24
|
-
// Inline requires don't work well with Jest:
|
|
25
|
-
// https://github.com/facebook/react/issues/7240
|
|
26
|
-
// Remove the inline requires when we don't need them anymore:
|
|
27
|
-
// https://github.com/facebook/react/pull/7178
|
|
28
|
-
ReactComponentTreeHook = require('./ReactComponentTreeHook');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
var loggedTypeFailures = {};
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Assert that the values match with the type specs.
|
|
35
|
-
* Error messages are memorized and will only be shown once.
|
|
36
|
-
*
|
|
37
|
-
* @param {object} typeSpecs Map of name to a ReactPropType
|
|
38
|
-
* @param {object} values Runtime values that need to be type-checked
|
|
39
|
-
* @param {string} location e.g. "prop", "context", "child context"
|
|
40
|
-
* @param {string} componentName Name of the component for error messages.
|
|
41
|
-
* @param {?object} element The React element that is being type-checked
|
|
42
|
-
* @param {?number} workInProgressOrDebugID The React component instance that is being type-checked
|
|
43
|
-
* @private
|
|
44
|
-
*/
|
|
45
|
-
function checkReactTypeSpec(typeSpecs, values, location, componentName, element,
|
|
46
|
-
// It is only safe to pass fiber if it is the work-in-progress version, and
|
|
47
|
-
workInProgressOrDebugID) {
|
|
48
|
-
for (var typeSpecName in typeSpecs) {
|
|
49
|
-
if (typeSpecs.hasOwnProperty(typeSpecName)) {
|
|
50
|
-
var error;
|
|
51
|
-
// Prop type validation may throw. In case they do, we don't want to
|
|
52
|
-
// fail the render phase where it didn't fail before. So we log it.
|
|
53
|
-
// After these have been cleaned up, we'll let them throw.
|
|
54
|
-
try {
|
|
55
|
-
// This is intentionally an invariant that gets caught. It's the same
|
|
56
|
-
// behavior as without this statement except with a better message.
|
|
57
|
-
!(typeof typeSpecs[typeSpecName] === '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], typeSpecName) : _prodInvariant('84', componentName || 'React class', ReactPropTypeLocationNames[location], typeSpecName) : void 0;
|
|
58
|
-
error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location);
|
|
59
|
-
} catch (ex) {
|
|
60
|
-
error = ex;
|
|
61
|
-
}
|
|
62
|
-
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], typeSpecName, typeof error) : void 0;
|
|
63
|
-
if (error instanceof Error && !(error.message in loggedTypeFailures)) {
|
|
64
|
-
// Only monitor this failure once because there tends to be a lot of the
|
|
65
|
-
// same error.
|
|
66
|
-
loggedTypeFailures[error.message] = true;
|
|
67
|
-
|
|
68
|
-
var componentStackInfo = '';
|
|
69
|
-
|
|
70
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
71
|
-
if (!ReactComponentTreeHook) {
|
|
72
|
-
ReactComponentTreeHook = require('./ReactComponentTreeHook');
|
|
73
|
-
}
|
|
74
|
-
if (workInProgressOrDebugID != null) {
|
|
75
|
-
if (typeof workInProgressOrDebugID === 'number') {
|
|
76
|
-
// DebugID from Stack.
|
|
77
|
-
var debugID = workInProgressOrDebugID;
|
|
78
|
-
componentStackInfo = ReactComponentTreeHook.getStackAddendumByID(debugID);
|
|
79
|
-
} else if (typeof workInProgressOrDebugID.tag === 'number') {
|
|
80
|
-
// This is a Fiber.
|
|
81
|
-
// The stack will only be correct if this is a work in progress
|
|
82
|
-
// version and we're calling it during reconciliation.
|
|
83
|
-
var workInProgress = workInProgressOrDebugID;
|
|
84
|
-
componentStackInfo = ReactComponentTreeHook.getStackAddendumByWorkInProgressFiber(workInProgress);
|
|
85
|
-
}
|
|
86
|
-
} else if (element !== null) {
|
|
87
|
-
componentStackInfo = ReactComponentTreeHook.getCurrentStackAddendum(element);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
process.env.NODE_ENV !== 'production' ? warning(false, 'Failed %s type: %s%s', location, error.message, componentStackInfo) : void 0;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
18
|
+
function checkReactTypeSpec(typeSpecs, values, location, componentName) {
|
|
19
|
+
checkPropTypes(typeSpecs, values, location, componentName, getStackAddendum);
|
|
95
20
|
}
|
|
96
21
|
|
|
97
22
|
module.exports = checkReactTypeSpec;
|
package/lib/getComponentName.js
CHANGED
|
@@ -12,23 +12,21 @@
|
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
14
|
function getComponentName(instanceOrFiber) {
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
var type = fiber.type;
|
|
15
|
+
if (typeof instanceOrFiber.getName === 'function') {
|
|
16
|
+
// Stack reconciler
|
|
17
|
+
var instance = instanceOrFiber;
|
|
18
|
+
return instance.getName();
|
|
19
|
+
}
|
|
20
|
+
if (typeof instanceOrFiber.tag === 'number') {
|
|
21
|
+
// Fiber reconciler
|
|
22
|
+
var fiber = instanceOrFiber;
|
|
23
|
+
var type = fiber.type;
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
25
|
+
if (typeof type === 'string') {
|
|
26
|
+
return type;
|
|
27
|
+
}
|
|
28
|
+
if (typeof type === 'function') {
|
|
29
|
+
return type.displayName || type.name;
|
|
32
30
|
}
|
|
33
31
|
}
|
|
34
32
|
return null;
|