source: node_modules/yaml/dist/compose/compose-doc.js@ d24f17c

main
Last change on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.5 KB
Line 
1'use strict';
2
3var Document = require('../doc/Document.js');
4var composeNode = require('./compose-node.js');
5var resolveEnd = require('./resolve-end.js');
6var resolveProps = require('./resolve-props.js');
7
8function composeDoc(options, directives, { offset, start, value, end }, onError) {
9 const opts = Object.assign({ _directives: directives }, options);
10 const doc = new Document.Document(undefined, opts);
11 const ctx = {
12 atRoot: true,
13 directives: doc.directives,
14 options: doc.options,
15 schema: doc.schema
16 };
17 const props = resolveProps.resolveProps(start, {
18 indicator: 'doc-start',
19 next: value ?? end?.[0],
20 offset,
21 onError,
22 startOnNewline: true
23 });
24 if (props.found) {
25 doc.directives.docStart = true;
26 if (value &&
27 (value.type === 'block-map' || value.type === 'block-seq') &&
28 !props.hasNewline)
29 onError(props.end, 'MISSING_CHAR', 'Block collection cannot start on same line with directives-end marker');
30 }
31 // @ts-expect-error If Contents is set, let's trust the user
32 doc.contents = value
33 ? composeNode.composeNode(ctx, value, props, onError)
34 : composeNode.composeEmptyNode(ctx, props.end, start, null, props, onError);
35 const contentEnd = doc.contents.range[2];
36 const re = resolveEnd.resolveEnd(end, contentEnd, false, onError);
37 if (re.comment)
38 doc.comment = re.comment;
39 doc.range = [offset, contentEnd, re.offset];
40 return doc;
41}
42
43exports.composeDoc = composeDoc;
Note: See TracBrowser for help on using the repository browser.