react 16.0.0-alpha.6 → 16.0.0-alpha.7
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/cjs/react.development.js +3268 -0
- package/cjs/react.production.min.js +1 -0
- package/index.js +7 -0
- package/package.json +7 -8
- package/{dist/react.js → umd/react.development.js} +2806 -3216
- package/umd/react.production.min.js +4 -0
- package/dist/react.min.js +0 -17
- package/lib/KeyEscapeUtils.js +0 -58
- package/lib/PooledClass.js +0 -111
- package/lib/React.js +0 -84
- package/lib/ReactBaseClasses.js +0 -136
- package/lib/ReactChildren.js +0 -190
- package/lib/ReactClass.js +0 -698
- package/lib/ReactComponentTreeHook.js +0 -342
- package/lib/ReactComponentTreeHookUMDShim.js +0 -17
- package/lib/ReactCurrentOwner.js +0 -28
- package/lib/ReactCurrentOwnerUMDShim.js +0 -17
- package/lib/ReactDOMFactories.js +0 -169
- package/lib/ReactDebugCurrentFrame.js +0 -55
- package/lib/ReactElement.js +0 -340
- package/lib/ReactElementSymbol.js +0 -19
- package/lib/ReactElementType.js +0 -12
- package/lib/ReactElementValidator.js +0 -276
- package/lib/ReactFiberComponentTreeHook.js +0 -62
- package/lib/ReactNoopUpdateQueue.js +0 -90
- package/lib/ReactPropTypes.js +0 -458
- package/lib/ReactPropTypesSecret.js +0 -16
- package/lib/ReactTypeOfWork.js +0 -26
- package/lib/ReactUMDEntry.js +0 -31
- package/lib/ReactUMDShim.js +0 -15
- package/lib/ReactVersion.js +0 -13
- package/lib/canDefineProperty.js +0 -25
- package/lib/checkPropTypes.js +0 -64
- package/lib/checkReactTypeSpec.js +0 -22
- package/lib/deprecated.js +0 -56
- package/lib/flattenChildren.js +0 -75
- package/lib/getComponentName.js +0 -35
- package/lib/getIteratorFn.js +0 -40
- package/lib/getNextDebugID.js +0 -20
- package/lib/onlyChild.js +0 -37
- package/lib/reactProdInvariant.js +0 -38
- package/lib/traverseAllChildren.js +0 -164
- package/react.js +0 -3
|
@@ -1,55 +0,0 @@
|
|
|
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
|
-
|
|
12
|
-
'use strict';
|
|
13
|
-
|
|
14
|
-
var ReactDebugCurrentFrame = {};
|
|
15
|
-
|
|
16
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
17
|
-
var _require = require('./ReactComponentTreeHook'),
|
|
18
|
-
getStackAddendumByID = _require.getStackAddendumByID,
|
|
19
|
-
getCurrentStackAddendum = _require.getCurrentStackAddendum;
|
|
20
|
-
|
|
21
|
-
var _require2 = require('./ReactFiberComponentTreeHook'),
|
|
22
|
-
getStackAddendumByWorkInProgressFiber = _require2.getStackAddendumByWorkInProgressFiber;
|
|
23
|
-
|
|
24
|
-
// Component that is being worked on
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
ReactDebugCurrentFrame.current = null;
|
|
28
|
-
|
|
29
|
-
// Element that is being cloned or created
|
|
30
|
-
ReactDebugCurrentFrame.element = null;
|
|
31
|
-
|
|
32
|
-
ReactDebugCurrentFrame.getStackAddendum = function () {
|
|
33
|
-
var stack = null;
|
|
34
|
-
var current = ReactDebugCurrentFrame.current;
|
|
35
|
-
var element = ReactDebugCurrentFrame.element;
|
|
36
|
-
if (current !== null) {
|
|
37
|
-
if (typeof current === 'number') {
|
|
38
|
-
// DebugID from Stack.
|
|
39
|
-
var debugID = current;
|
|
40
|
-
stack = getStackAddendumByID(debugID);
|
|
41
|
-
} else if (typeof current.tag === 'number') {
|
|
42
|
-
// This is a Fiber.
|
|
43
|
-
// The stack will only be correct if this is a work in progress
|
|
44
|
-
// version and we're calling it during reconciliation.
|
|
45
|
-
var workInProgress = current;
|
|
46
|
-
stack = getStackAddendumByWorkInProgressFiber(workInProgress);
|
|
47
|
-
}
|
|
48
|
-
} else if (element !== null) {
|
|
49
|
-
stack = getCurrentStackAddendum(element);
|
|
50
|
-
}
|
|
51
|
-
return stack;
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
module.exports = ReactDebugCurrentFrame;
|
package/lib/ReactElement.js
DELETED
|
@@ -1,340 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2014-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 _assign = require('object-assign');
|
|
14
|
-
|
|
15
|
-
var ReactCurrentOwner = require('./ReactCurrentOwner');
|
|
16
|
-
|
|
17
|
-
var warning = require('fbjs/lib/warning');
|
|
18
|
-
var canDefineProperty = require('./canDefineProperty');
|
|
19
|
-
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
20
|
-
|
|
21
|
-
var REACT_ELEMENT_TYPE = require('./ReactElementSymbol');
|
|
22
|
-
|
|
23
|
-
var RESERVED_PROPS = {
|
|
24
|
-
key: true,
|
|
25
|
-
ref: true,
|
|
26
|
-
__self: true,
|
|
27
|
-
__source: true
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
var specialPropKeyWarningShown, specialPropRefWarningShown;
|
|
31
|
-
|
|
32
|
-
function hasValidRef(config) {
|
|
33
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
34
|
-
if (hasOwnProperty.call(config, 'ref')) {
|
|
35
|
-
var getter = Object.getOwnPropertyDescriptor(config, 'ref').get;
|
|
36
|
-
if (getter && getter.isReactWarning) {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return config.ref !== undefined;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function hasValidKey(config) {
|
|
45
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
46
|
-
if (hasOwnProperty.call(config, 'key')) {
|
|
47
|
-
var getter = Object.getOwnPropertyDescriptor(config, 'key').get;
|
|
48
|
-
if (getter && getter.isReactWarning) {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return config.key !== undefined;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function defineKeyPropWarningGetter(props, displayName) {
|
|
57
|
-
var warnAboutAccessingKey = function () {
|
|
58
|
-
if (!specialPropKeyWarningShown) {
|
|
59
|
-
specialPropKeyWarningShown = true;
|
|
60
|
-
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;
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
warnAboutAccessingKey.isReactWarning = true;
|
|
64
|
-
Object.defineProperty(props, 'key', {
|
|
65
|
-
get: warnAboutAccessingKey,
|
|
66
|
-
configurable: true
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function defineRefPropWarningGetter(props, displayName) {
|
|
71
|
-
var warnAboutAccessingRef = function () {
|
|
72
|
-
if (!specialPropRefWarningShown) {
|
|
73
|
-
specialPropRefWarningShown = true;
|
|
74
|
-
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;
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
warnAboutAccessingRef.isReactWarning = true;
|
|
78
|
-
Object.defineProperty(props, 'ref', {
|
|
79
|
-
get: warnAboutAccessingRef,
|
|
80
|
-
configurable: true
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Factory method to create a new React element. This no longer adheres to
|
|
86
|
-
* the class pattern, so do not use new to call it. Also, no instanceof check
|
|
87
|
-
* will work. Instead test $$typeof field against Symbol.for('react.element') to check
|
|
88
|
-
* if something is a React Element.
|
|
89
|
-
*
|
|
90
|
-
* @param {*} type
|
|
91
|
-
* @param {*} key
|
|
92
|
-
* @param {string|object} ref
|
|
93
|
-
* @param {*} self A *temporary* helper to detect places where `this` is
|
|
94
|
-
* different from the `owner` when React.createElement is called, so that we
|
|
95
|
-
* can warn. We want to get rid of owner and replace string `ref`s with arrow
|
|
96
|
-
* functions, and as long as `this` and owner are the same, there will be no
|
|
97
|
-
* change in behavior.
|
|
98
|
-
* @param {*} source An annotation object (added by a transpiler or otherwise)
|
|
99
|
-
* indicating filename, line number, and/or other information.
|
|
100
|
-
* @param {*} owner
|
|
101
|
-
* @param {*} props
|
|
102
|
-
* @internal
|
|
103
|
-
*/
|
|
104
|
-
var ReactElement = function (type, key, ref, self, source, owner, props) {
|
|
105
|
-
var element = {
|
|
106
|
-
// This tag allow us to uniquely identify this as a React Element
|
|
107
|
-
$$typeof: REACT_ELEMENT_TYPE,
|
|
108
|
-
|
|
109
|
-
// Built-in properties that belong on the element
|
|
110
|
-
type: type,
|
|
111
|
-
key: key,
|
|
112
|
-
ref: ref,
|
|
113
|
-
props: props,
|
|
114
|
-
|
|
115
|
-
// Record the component responsible for creating this element.
|
|
116
|
-
_owner: owner
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
120
|
-
// The validation flag is currently mutative. We put it on
|
|
121
|
-
// an external backing store so that we can freeze the whole object.
|
|
122
|
-
// This can be replaced with a WeakMap once they are implemented in
|
|
123
|
-
// commonly used development environments.
|
|
124
|
-
element._store = {};
|
|
125
|
-
|
|
126
|
-
// To make comparing ReactElements easier for testing purposes, we make
|
|
127
|
-
// the validation flag non-enumerable (where possible, which should
|
|
128
|
-
// include every environment we run tests in), so the test framework
|
|
129
|
-
// ignores it.
|
|
130
|
-
if (canDefineProperty) {
|
|
131
|
-
Object.defineProperty(element._store, 'validated', {
|
|
132
|
-
configurable: false,
|
|
133
|
-
enumerable: false,
|
|
134
|
-
writable: true,
|
|
135
|
-
value: false
|
|
136
|
-
});
|
|
137
|
-
// self and source are DEV only properties.
|
|
138
|
-
Object.defineProperty(element, '_self', {
|
|
139
|
-
configurable: false,
|
|
140
|
-
enumerable: false,
|
|
141
|
-
writable: false,
|
|
142
|
-
value: self
|
|
143
|
-
});
|
|
144
|
-
// Two elements created in two different places should be considered
|
|
145
|
-
// equal for testing purposes and therefore we hide it from enumeration.
|
|
146
|
-
Object.defineProperty(element, '_source', {
|
|
147
|
-
configurable: false,
|
|
148
|
-
enumerable: false,
|
|
149
|
-
writable: false,
|
|
150
|
-
value: source
|
|
151
|
-
});
|
|
152
|
-
} else {
|
|
153
|
-
element._store.validated = false;
|
|
154
|
-
element._self = self;
|
|
155
|
-
element._source = source;
|
|
156
|
-
}
|
|
157
|
-
if (Object.freeze) {
|
|
158
|
-
Object.freeze(element.props);
|
|
159
|
-
Object.freeze(element);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return element;
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Create and return a new ReactElement of the given type.
|
|
168
|
-
* See https://facebook.github.io/react/docs/react-api.html#createelement
|
|
169
|
-
*/
|
|
170
|
-
ReactElement.createElement = function (type, config, children) {
|
|
171
|
-
var propName;
|
|
172
|
-
|
|
173
|
-
// Reserved names are extracted
|
|
174
|
-
var props = {};
|
|
175
|
-
|
|
176
|
-
var key = null;
|
|
177
|
-
var ref = null;
|
|
178
|
-
var self = null;
|
|
179
|
-
var source = null;
|
|
180
|
-
|
|
181
|
-
if (config != null) {
|
|
182
|
-
if (hasValidRef(config)) {
|
|
183
|
-
ref = config.ref;
|
|
184
|
-
}
|
|
185
|
-
if (hasValidKey(config)) {
|
|
186
|
-
key = '' + config.key;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
self = config.__self === undefined ? null : config.__self;
|
|
190
|
-
source = config.__source === undefined ? null : config.__source;
|
|
191
|
-
// Remaining properties are added to a new props object
|
|
192
|
-
for (propName in config) {
|
|
193
|
-
if (hasOwnProperty.call(config, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
|
|
194
|
-
props[propName] = config[propName];
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// Children can be more than one argument, and those are transferred onto
|
|
200
|
-
// the newly allocated props object.
|
|
201
|
-
var childrenLength = arguments.length - 2;
|
|
202
|
-
if (childrenLength === 1) {
|
|
203
|
-
props.children = children;
|
|
204
|
-
} else if (childrenLength > 1) {
|
|
205
|
-
var childArray = Array(childrenLength);
|
|
206
|
-
for (var i = 0; i < childrenLength; i++) {
|
|
207
|
-
childArray[i] = arguments[i + 2];
|
|
208
|
-
}
|
|
209
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
210
|
-
if (Object.freeze) {
|
|
211
|
-
Object.freeze(childArray);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
props.children = childArray;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// Resolve default props
|
|
218
|
-
if (type && type.defaultProps) {
|
|
219
|
-
var defaultProps = type.defaultProps;
|
|
220
|
-
for (propName in defaultProps) {
|
|
221
|
-
if (props[propName] === undefined) {
|
|
222
|
-
props[propName] = defaultProps[propName];
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
227
|
-
if (key || ref) {
|
|
228
|
-
if (typeof props.$$typeof === 'undefined' || props.$$typeof !== REACT_ELEMENT_TYPE) {
|
|
229
|
-
var displayName = typeof type === 'function' ? type.displayName || type.name || 'Unknown' : type;
|
|
230
|
-
if (key) {
|
|
231
|
-
defineKeyPropWarningGetter(props, displayName);
|
|
232
|
-
}
|
|
233
|
-
if (ref) {
|
|
234
|
-
defineRefPropWarningGetter(props, displayName);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
return ReactElement(type, key, ref, self, source, ReactCurrentOwner.current, props);
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Return a function that produces ReactElements of a given type.
|
|
244
|
-
* See https://facebook.github.io/react/docs/react-api.html#createfactory
|
|
245
|
-
*/
|
|
246
|
-
ReactElement.createFactory = function (type) {
|
|
247
|
-
var factory = ReactElement.createElement.bind(null, type);
|
|
248
|
-
// Expose the type on the factory and the prototype so that it can be
|
|
249
|
-
// easily accessed on elements. E.g. `<Foo />.type === Foo`.
|
|
250
|
-
// This should not be named `constructor` since this may not be the function
|
|
251
|
-
// that created the element, and it may not even be a constructor.
|
|
252
|
-
// Legacy hook TODO: Warn if this is accessed
|
|
253
|
-
factory.type = type;
|
|
254
|
-
return factory;
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
ReactElement.cloneAndReplaceKey = function (oldElement, newKey) {
|
|
258
|
-
var newElement = ReactElement(oldElement.type, newKey, oldElement.ref, oldElement._self, oldElement._source, oldElement._owner, oldElement.props);
|
|
259
|
-
|
|
260
|
-
return newElement;
|
|
261
|
-
};
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* Clone and return a new ReactElement using element as the starting point.
|
|
265
|
-
* See https://facebook.github.io/react/docs/react-api.html#cloneelement
|
|
266
|
-
*/
|
|
267
|
-
ReactElement.cloneElement = function (element, config, children) {
|
|
268
|
-
var propName;
|
|
269
|
-
|
|
270
|
-
// Original props are copied
|
|
271
|
-
var props = _assign({}, element.props);
|
|
272
|
-
|
|
273
|
-
// Reserved names are extracted
|
|
274
|
-
var key = element.key;
|
|
275
|
-
var ref = element.ref;
|
|
276
|
-
// Self is preserved since the owner is preserved.
|
|
277
|
-
var self = element._self;
|
|
278
|
-
// Source is preserved since cloneElement is unlikely to be targeted by a
|
|
279
|
-
// transpiler, and the original source is probably a better indicator of the
|
|
280
|
-
// true owner.
|
|
281
|
-
var source = element._source;
|
|
282
|
-
|
|
283
|
-
// Owner will be preserved, unless ref is overridden
|
|
284
|
-
var owner = element._owner;
|
|
285
|
-
|
|
286
|
-
if (config != null) {
|
|
287
|
-
if (hasValidRef(config)) {
|
|
288
|
-
// Silently steal the ref from the parent.
|
|
289
|
-
ref = config.ref;
|
|
290
|
-
owner = ReactCurrentOwner.current;
|
|
291
|
-
}
|
|
292
|
-
if (hasValidKey(config)) {
|
|
293
|
-
key = '' + config.key;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
// Remaining properties override existing props
|
|
297
|
-
var defaultProps;
|
|
298
|
-
if (element.type && element.type.defaultProps) {
|
|
299
|
-
defaultProps = element.type.defaultProps;
|
|
300
|
-
}
|
|
301
|
-
for (propName in config) {
|
|
302
|
-
if (hasOwnProperty.call(config, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
|
|
303
|
-
if (config[propName] === undefined && defaultProps !== undefined) {
|
|
304
|
-
// Resolve default props
|
|
305
|
-
props[propName] = defaultProps[propName];
|
|
306
|
-
} else {
|
|
307
|
-
props[propName] = config[propName];
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
// Children can be more than one argument, and those are transferred onto
|
|
314
|
-
// the newly allocated props object.
|
|
315
|
-
var childrenLength = arguments.length - 2;
|
|
316
|
-
if (childrenLength === 1) {
|
|
317
|
-
props.children = children;
|
|
318
|
-
} else if (childrenLength > 1) {
|
|
319
|
-
var childArray = Array(childrenLength);
|
|
320
|
-
for (var i = 0; i < childrenLength; i++) {
|
|
321
|
-
childArray[i] = arguments[i + 2];
|
|
322
|
-
}
|
|
323
|
-
props.children = childArray;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
return ReactElement(element.type, key, ref, self, source, owner, props);
|
|
327
|
-
};
|
|
328
|
-
|
|
329
|
-
/**
|
|
330
|
-
* Verifies the object is a ReactElement.
|
|
331
|
-
* See https://facebook.github.io/react/docs/react-api.html#isvalidelement
|
|
332
|
-
* @param {?object} object
|
|
333
|
-
* @return {boolean} True if `object` is a valid component.
|
|
334
|
-
* @final
|
|
335
|
-
*/
|
|
336
|
-
ReactElement.isValidElement = function (object) {
|
|
337
|
-
return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
module.exports = ReactElement;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2014-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
|
-
// The Symbol used to tag the ReactElement type. If there is no native Symbol
|
|
15
|
-
// nor polyfill, then a plain number is used for performance.
|
|
16
|
-
|
|
17
|
-
var REACT_ELEMENT_TYPE = typeof Symbol === 'function' && Symbol['for'] && Symbol['for']('react.element') || 0xeac7;
|
|
18
|
-
|
|
19
|
-
module.exports = REACT_ELEMENT_TYPE;
|
package/lib/ReactElementType.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
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';
|
|
@@ -1,276 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2014-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
|
-
* ReactElementValidator provides a wrapper around a element factory
|
|
13
|
-
* which validates the props passed to the element. This is intended to be
|
|
14
|
-
* used only in DEV and could be replaced by a static type checker for languages
|
|
15
|
-
* that support it.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
'use strict';
|
|
19
|
-
|
|
20
|
-
var ReactCurrentOwner = require('./ReactCurrentOwner');
|
|
21
|
-
var ReactElement = require('./ReactElement');
|
|
22
|
-
|
|
23
|
-
var checkReactTypeSpec = require('./checkReactTypeSpec');
|
|
24
|
-
|
|
25
|
-
var canDefineProperty = require('./canDefineProperty');
|
|
26
|
-
var getComponentName = require('./getComponentName');
|
|
27
|
-
var getIteratorFn = require('./getIteratorFn');
|
|
28
|
-
|
|
29
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
30
|
-
var warning = require('fbjs/lib/warning');
|
|
31
|
-
var ReactDebugCurrentFrame = require('./ReactDebugCurrentFrame');
|
|
32
|
-
|
|
33
|
-
var _require = require('./ReactComponentTreeHook'),
|
|
34
|
-
getCurrentStackAddendum = _require.getCurrentStackAddendum;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function getDeclarationErrorAddendum() {
|
|
38
|
-
if (ReactCurrentOwner.current) {
|
|
39
|
-
var name = getComponentName(ReactCurrentOwner.current);
|
|
40
|
-
if (name) {
|
|
41
|
-
return '\n\nCheck the render method of `' + name + '`.';
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return '';
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function getSourceInfoErrorAddendum(elementProps) {
|
|
48
|
-
if (elementProps !== null && elementProps !== undefined && elementProps.__source !== undefined) {
|
|
49
|
-
var source = elementProps.__source;
|
|
50
|
-
var fileName = source.fileName.replace(/^.*[\\\/]/, '');
|
|
51
|
-
var lineNumber = source.lineNumber;
|
|
52
|
-
return '\n\nCheck your code at ' + fileName + ':' + lineNumber + '.';
|
|
53
|
-
}
|
|
54
|
-
return '';
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Warn if there's no key explicitly set on dynamic arrays of children or
|
|
59
|
-
* object keys are not valid. This allows us to keep track of children between
|
|
60
|
-
* updates.
|
|
61
|
-
*/
|
|
62
|
-
var ownerHasKeyUseWarning = {};
|
|
63
|
-
|
|
64
|
-
function getCurrentComponentErrorInfo(parentType) {
|
|
65
|
-
var info = getDeclarationErrorAddendum();
|
|
66
|
-
|
|
67
|
-
if (!info) {
|
|
68
|
-
var parentName = typeof parentType === 'string' ? parentType : parentType.displayName || parentType.name;
|
|
69
|
-
if (parentName) {
|
|
70
|
-
info = '\n\nCheck the top-level render call using <' + parentName + '>.';
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return info;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Warn if the element doesn't have an explicit key assigned to it.
|
|
78
|
-
* This element is in an array. The array could grow and shrink or be
|
|
79
|
-
* reordered. All children that haven't already been validated are required to
|
|
80
|
-
* have a "key" property assigned to it. Error statuses are cached so a warning
|
|
81
|
-
* will only be shown once.
|
|
82
|
-
*
|
|
83
|
-
* @internal
|
|
84
|
-
* @param {ReactElement} element Element that requires a key.
|
|
85
|
-
* @param {*} parentType element's parent's type.
|
|
86
|
-
*/
|
|
87
|
-
function validateExplicitKey(element, parentType) {
|
|
88
|
-
if (!element._store || element._store.validated || element.key != null) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
element._store.validated = true;
|
|
92
|
-
|
|
93
|
-
var memoizer = ownerHasKeyUseWarning.uniqueKey || (ownerHasKeyUseWarning.uniqueKey = {});
|
|
94
|
-
|
|
95
|
-
var currentComponentErrorInfo = getCurrentComponentErrorInfo(parentType);
|
|
96
|
-
if (memoizer[currentComponentErrorInfo]) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
memoizer[currentComponentErrorInfo] = true;
|
|
100
|
-
|
|
101
|
-
// Usually the current owner is the offender, but if it accepts children as a
|
|
102
|
-
// property, it may be the creator of the child that's responsible for
|
|
103
|
-
// assigning it a key.
|
|
104
|
-
var childOwner = '';
|
|
105
|
-
if (element && element._owner && element._owner !== ReactCurrentOwner.current) {
|
|
106
|
-
// Give the component that originally created this child.
|
|
107
|
-
childOwner = ' It was passed a child from ' + getComponentName(element._owner) + '.';
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
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, getCurrentStackAddendum(element)) : void 0;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Ensure that every element either is passed in a static location, in an
|
|
115
|
-
* array with an explicit keys property defined, or in an object literal
|
|
116
|
-
* with valid key property.
|
|
117
|
-
*
|
|
118
|
-
* @internal
|
|
119
|
-
* @param {ReactNode} node Statically passed child of any type.
|
|
120
|
-
* @param {*} parentType node's parent's type.
|
|
121
|
-
*/
|
|
122
|
-
function validateChildKeys(node, parentType) {
|
|
123
|
-
if (typeof node !== 'object') {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
if (Array.isArray(node)) {
|
|
127
|
-
for (var i = 0; i < node.length; i++) {
|
|
128
|
-
var child = node[i];
|
|
129
|
-
if (ReactElement.isValidElement(child)) {
|
|
130
|
-
validateExplicitKey(child, parentType);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
} else if (ReactElement.isValidElement(node)) {
|
|
134
|
-
// This element was passed in a valid location.
|
|
135
|
-
if (node._store) {
|
|
136
|
-
node._store.validated = true;
|
|
137
|
-
}
|
|
138
|
-
} else if (node) {
|
|
139
|
-
var iteratorFn = getIteratorFn(node);
|
|
140
|
-
// Entry iterators provide implicit keys.
|
|
141
|
-
if (iteratorFn) {
|
|
142
|
-
if (iteratorFn !== node.entries) {
|
|
143
|
-
var iterator = iteratorFn.call(node);
|
|
144
|
-
var step;
|
|
145
|
-
while (!(step = iterator.next()).done) {
|
|
146
|
-
if (ReactElement.isValidElement(step.value)) {
|
|
147
|
-
validateExplicitKey(step.value, parentType);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Given an element, validate that its props follow the propTypes definition,
|
|
157
|
-
* provided by the type.
|
|
158
|
-
*
|
|
159
|
-
* @param {ReactElement} element
|
|
160
|
-
*/
|
|
161
|
-
function validatePropTypes(element) {
|
|
162
|
-
var componentClass = element.type;
|
|
163
|
-
if (typeof componentClass !== 'function') {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
var name = componentClass.displayName || componentClass.name;
|
|
167
|
-
|
|
168
|
-
// ReactNative `View.propTypes` have been deprecated in favor of `ViewPropTypes`.
|
|
169
|
-
// In their place a temporary getter has been added with a deprecated warning message.
|
|
170
|
-
// Avoid triggering that warning during validation using the temporary workaround, __propTypesSecretDontUseThesePlease.
|
|
171
|
-
// TODO (bvaughn) Revert this particular change any time after April 1 ReactNative RC is tagged.
|
|
172
|
-
var propTypes = typeof componentClass.__propTypesSecretDontUseThesePlease === 'object' ? componentClass.__propTypesSecretDontUseThesePlease : componentClass.propTypes;
|
|
173
|
-
|
|
174
|
-
if (propTypes) {
|
|
175
|
-
checkReactTypeSpec(propTypes, element.props, 'prop', name);
|
|
176
|
-
}
|
|
177
|
-
if (typeof componentClass.getDefaultProps === 'function') {
|
|
178
|
-
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;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
var ReactElementValidator = {
|
|
183
|
-
createElement: function (type, props, children) {
|
|
184
|
-
var validType = typeof type === 'string' || typeof type === 'function';
|
|
185
|
-
// We warn in this case but don't throw. We expect the element creation to
|
|
186
|
-
// succeed and there will likely be errors in render.
|
|
187
|
-
if (!validType) {
|
|
188
|
-
var info = '';
|
|
189
|
-
if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) {
|
|
190
|
-
info += ' You likely forgot to export your component from the file ' + "it's defined in.";
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
var sourceInfo = getSourceInfoErrorAddendum(props);
|
|
194
|
-
if (sourceInfo) {
|
|
195
|
-
info += sourceInfo;
|
|
196
|
-
} else {
|
|
197
|
-
info += getDeclarationErrorAddendum();
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
info += getCurrentStackAddendum();
|
|
201
|
-
|
|
202
|
-
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;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
var element = ReactElement.createElement.apply(this, arguments);
|
|
206
|
-
|
|
207
|
-
// The result can be nullish if a mock or a custom function is used.
|
|
208
|
-
// TODO: Drop this when these are no longer allowed as the type argument.
|
|
209
|
-
if (element == null) {
|
|
210
|
-
return element;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
214
|
-
ReactDebugCurrentFrame.element = element;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// Skip key warning if the type isn't valid since our key validation logic
|
|
218
|
-
// doesn't expect a non-string/function type and can throw confusing errors.
|
|
219
|
-
// We don't want exception behavior to differ between dev and prod.
|
|
220
|
-
// (Rendering will throw with a helpful message and as soon as the type is
|
|
221
|
-
// fixed, the key warnings will appear.)
|
|
222
|
-
if (validType) {
|
|
223
|
-
for (var i = 2; i < arguments.length; i++) {
|
|
224
|
-
validateChildKeys(arguments[i], type);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
validatePropTypes(element);
|
|
229
|
-
|
|
230
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
231
|
-
ReactDebugCurrentFrame.element = null;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
return element;
|
|
235
|
-
},
|
|
236
|
-
|
|
237
|
-
createFactory: function (type) {
|
|
238
|
-
var validatedFactory = ReactElementValidator.createElement.bind(null, type);
|
|
239
|
-
// Legacy hook TODO: Warn if this is accessed
|
|
240
|
-
validatedFactory.type = type;
|
|
241
|
-
|
|
242
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
243
|
-
if (canDefineProperty) {
|
|
244
|
-
Object.defineProperty(validatedFactory, 'type', {
|
|
245
|
-
enumerable: false,
|
|
246
|
-
get: function () {
|
|
247
|
-
process.env.NODE_ENV !== 'production' ? warning(false, 'Factory.type is deprecated. Access the class directly ' + 'before passing it to createFactory.') : void 0;
|
|
248
|
-
Object.defineProperty(this, 'type', {
|
|
249
|
-
value: type
|
|
250
|
-
});
|
|
251
|
-
return type;
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
return validatedFactory;
|
|
258
|
-
},
|
|
259
|
-
|
|
260
|
-
cloneElement: function (element, props, children) {
|
|
261
|
-
var newElement = ReactElement.cloneElement.apply(this, arguments);
|
|
262
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
263
|
-
ReactDebugCurrentFrame.element = newElement;
|
|
264
|
-
}
|
|
265
|
-
for (var i = 2; i < arguments.length; i++) {
|
|
266
|
-
validateChildKeys(arguments[i], newElement.type);
|
|
267
|
-
}
|
|
268
|
-
validatePropTypes(newElement);
|
|
269
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
270
|
-
ReactDebugCurrentFrame.element = null;
|
|
271
|
-
}
|
|
272
|
-
return newElement;
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
|
|
276
|
-
module.exports = ReactElementValidator;
|