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