toArray.js 579 B

123456789101112131415161718
  1. import { isFragment } from '../../_util/props-util';
  2. export default function toArray(children) {
  3. var option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  4. var ret = [];
  5. children.forEach(function (child) {
  6. if ((child === undefined || child === null) && !option.keepEmpty) {
  7. return;
  8. }
  9. if (Array.isArray(child)) {
  10. ret = ret.concat(toArray(child));
  11. } else if (isFragment(child) && child.props) {
  12. ret = ret.concat(toArray(child.props.children, option));
  13. } else {
  14. ret.push(child);
  15. }
  16. });
  17. return ret;
  18. }