toArray.js 678 B

123456789101112131415161718192021222324
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = toArray;
  6. var _propsUtil = require("../../_util/props-util");
  7. function toArray(children) {
  8. let option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  9. let ret = [];
  10. children.forEach(child => {
  11. if ((child === undefined || child === null) && !option.keepEmpty) {
  12. return;
  13. }
  14. if (Array.isArray(child)) {
  15. ret = ret.concat(toArray(child));
  16. } else if ((0, _propsUtil.isFragment)(child) && child.props) {
  17. ret = ret.concat(toArray(child.props.children, option));
  18. } else {
  19. ret.push(child);
  20. }
  21. });
  22. return ret;
  23. }