mirror of
https://github.com/facebook/react.git
synced 2026-11-18 20:15:56 +00:00
check entry type iterables
check that the value is a node for map iterables
This commit is contained in:
1 parent
8e72956430
commit
79fc73e674
2 files changed
+29
-2
No files matched your search
@@ -349,14 +349,24 @@ function isNode(propValue) {
|
||||
|
||||
var iteratorFn = getIteratorFn(propValue);
|
||||
if (iteratorFn) {
|
||||
var iterator = iteratorFn.call(propValue);
|
||||
var step;
|
||||
if (iteratorFn !== propValue.entries) {
|
||||
var iterator = iteratorFn.call(propValue);
|
||||
var step;
|
||||
while (!(step = iterator.next()).done) {
|
||||
if (!isNode(step.value)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Iterator will provide entry [k,v] tuples rather than values.
|
||||
while (!(step = iterator.next()).done) {
|
||||
var entry = step.value;
|
||||
if (entry) {
|
||||
if (!isNode(entry[1])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
propValue = ReactFragment.extractIfFragment(propValue);
|
||||
|
||||
@@ -421,6 +421,23 @@ describe('ReactPropTypes', function() {
|
||||
typeCheckPass(PropTypes.node, iterable);
|
||||
});
|
||||
|
||||
it('should not warn for entry iterables', function() {
|
||||
var iterable = {
|
||||
'@@iterator': function() {
|
||||
var i = 0;
|
||||
return {
|
||||
next: function() {
|
||||
var done = ++i > 2;
|
||||
return {value: done ? undefined : ['#' + i, <MyComponent />], done: done};
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
iterable.entries = iterable['@@iterator'];
|
||||
|
||||
typeCheckPass(PropTypes.node, iterable);
|
||||
});
|
||||
|
||||
it('should not warn for null/undefined if not required', function() {
|
||||
typeCheckPass(PropTypes.node, null);
|
||||
typeCheckPass(PropTypes.node, undefined);
|
||||
|
||||
Reference in new issue
Block a user