group-cst-flow-collection-items.js 794 B

1234567891011121314151617181920212223
  1. "use strict";
  2. exports.__esModule = true;
  3. var create_slicer_1 = require("./create-slicer");
  4. function groupCstFlowCollectionItems(cstItems) {
  5. var groups = [];
  6. var sliceCstItems = create_slicer_1.createSlicer(cstItems, 1); // exclude `{` or `[`
  7. var hasItem = false;
  8. for (var i = 1; i < cstItems.length - 1; i++) {
  9. var cstItem = cstItems[i];
  10. if ("char" in cstItem && cstItem.char === ",") {
  11. groups.push(sliceCstItems(i));
  12. sliceCstItems(i + 1); // exclude `,`
  13. hasItem = false;
  14. continue;
  15. }
  16. hasItem = true;
  17. }
  18. if (hasItem) {
  19. groups.push(sliceCstItems(cstItems.length - 1)); // exclude `}` or `]`
  20. }
  21. return groups;
  22. }
  23. exports.groupCstFlowCollectionItems = groupCstFlowCollectionItems;