@samitouri / QOS-React-2 / commits / 79fc73e674

check entry type iterables

check that the value is a node for map iterables

Antonio Ruberto committed Jun 24, 2015 at 15:17 UTC 79fc73e6742d0548d6d6af56e95074707d8189f1
2 files changed +29 -2
src/isomorphic/classic/types/ReactPropTypes.js
+12 -2
@@ -349,14 +349,24 @@ function isNode(propValue) {
349
350 var iteratorFn = getIteratorFn(propValue);
351 if (iteratorFn) {
352 + var iterator = iteratorFn.call(propValue);
353 + var step;
354 if (iteratorFn !== propValue.entries) {
353 - var iterator = iteratorFn.call(propValue);
354 - var step;
355 while (!(step = iterator.next()).done) {
356 if (!isNode(step.value)) {
357 return false;
358 }
359 }
360 + } else {
361 + // Iterator will provide entry [k,v] tuples rather than values.
362 + while (!(step = iterator.next()).done) {
363 + var entry = step.value;
364 + if (entry) {
365 + if (!isNode(entry[1])) {
366 + return false;
367 + }
368 + }
369 + }
370 }
371 } else {
372 propValue = ReactFragment.extractIfFragment(propValue);
src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js
+17
@@ -421,6 +421,23 @@ describe('ReactPropTypes', function() {
421 typeCheckPass(PropTypes.node, iterable);
422 });
423
424 + it('should not warn for entry iterables', function() {
425 + var iterable = {
426 + '@@iterator': function() {
427 + var i = 0;
428 + return {
429 + next: function() {
430 + var done = ++i > 2;
431 + return {value: done ? undefined : ['#' + i, <MyComponent />], done: done};
432 + },
433 + };
434 + },
435 + };
436 + iterable.entries = iterable['@@iterator'];
437 +
438 + typeCheckPass(PropTypes.node, iterable);
439 + });
440 +
441 it('should not warn for null/undefined if not required', function() {
442 typeCheckPass(PropTypes.node, null);
443 typeCheckPass(PropTypes.node, undefined);