Нет описания

resolve-block-seq.js 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. 'use strict';
  2. var YAMLSeq = require('../nodes/YAMLSeq.js');
  3. var resolveProps = require('./resolve-props.js');
  4. var utilFlowIndentCheck = require('./util-flow-indent-check.js');
  5. function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError) {
  6. const seq = new YAMLSeq.YAMLSeq(ctx.schema);
  7. if (ctx.atRoot)
  8. ctx.atRoot = false;
  9. let offset = bs.offset;
  10. let commentEnd = null;
  11. for (const { start, value } of bs.items) {
  12. const props = resolveProps.resolveProps(start, {
  13. indicator: 'seq-item-ind',
  14. next: value,
  15. offset,
  16. onError,
  17. startOnNewline: true
  18. });
  19. if (!props.found) {
  20. if (props.anchor || props.tag || value) {
  21. if (value && value.type === 'block-seq')
  22. onError(props.end, 'BAD_INDENT', 'All sequence items must start at the same column');
  23. else
  24. onError(offset, 'MISSING_CHAR', 'Sequence item without - indicator');
  25. }
  26. else {
  27. commentEnd = props.end;
  28. if (props.comment)
  29. seq.comment = props.comment;
  30. continue;
  31. }
  32. }
  33. const node = value
  34. ? composeNode(ctx, value, props, onError)
  35. : composeEmptyNode(ctx, props.end, start, null, props, onError);
  36. if (ctx.schema.compat)
  37. utilFlowIndentCheck.flowIndentCheck(bs.indent, value, onError);
  38. offset = node.range[2];
  39. seq.items.push(node);
  40. }
  41. seq.range = [bs.offset, offset, commentEnd ?? offset];
  42. return seq;
  43. }
  44. exports.resolveBlockSeq = resolveBlockSeq;