UNPKG

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