yaml 2.0.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/dist/compose/compose-collection.js +1 -1
- package/browser/dist/compose/compose-doc.js +2 -2
- package/browser/dist/compose/compose-scalar.js +6 -7
- package/browser/dist/compose/composer.js +2 -3
- package/browser/dist/compose/resolve-block-map.js +8 -8
- package/browser/dist/compose/resolve-block-scalar.js +1 -1
- package/browser/dist/compose/resolve-flow-collection.js +3 -4
- package/browser/dist/compose/resolve-flow-scalar.js +1 -2
- package/browser/dist/compose/resolve-props.js +6 -2
- package/browser/dist/compose/util-empty-scalar-position.js +1 -1
- package/browser/dist/compose/util-flow-indent-check.js +1 -1
- package/browser/dist/doc/Document.js +6 -6
- package/browser/dist/doc/createNode.js +5 -7
- package/browser/dist/nodes/Collection.js +2 -1
- package/browser/dist/nodes/Pair.js +2 -2
- package/browser/dist/nodes/Scalar.js +1 -1
- package/browser/dist/nodes/YAMLMap.js +6 -7
- package/browser/dist/nodes/YAMLSeq.js +1 -9
- package/browser/dist/nodes/addPairToJSMap.js +1 -1
- package/browser/dist/nodes/toJS.js +1 -1
- package/browser/dist/parse/cst-scalar.js +1 -2
- package/browser/dist/parse/cst-visit.js +2 -2
- package/browser/dist/parse/lexer.js +1 -2
- package/browser/dist/parse/parser.js +24 -26
- package/browser/dist/public-api.js +3 -4
- package/browser/dist/schema/Schema.js +1 -1
- package/browser/dist/schema/yaml-1.1/omap.js +1 -1
- package/browser/dist/schema/yaml-1.1/pairs.js +1 -2
- package/browser/dist/schema/yaml-1.1/set.js +4 -0
- package/browser/dist/stringify/stringify.js +6 -8
- package/browser/dist/stringify/stringifyCollection.js +1 -2
- package/browser/dist/stringify/stringifyDocument.js +1 -2
- package/browser/dist/stringify/stringifyString.js +2 -2
- package/browser/dist/visit.js +5 -6
- package/dist/compose/compose-collection.js +1 -1
- package/dist/compose/compose-doc.js +2 -2
- package/dist/compose/compose-scalar.js +6 -7
- package/dist/compose/composer.js +2 -3
- package/dist/compose/resolve-block-map.js +8 -8
- package/dist/compose/resolve-block-scalar.js +1 -1
- package/dist/compose/resolve-flow-collection.js +3 -4
- package/dist/compose/resolve-flow-scalar.js +1 -2
- package/dist/compose/resolve-props.d.ts +1 -0
- package/dist/compose/resolve-props.js +6 -2
- package/dist/compose/util-empty-scalar-position.js +1 -1
- package/dist/compose/util-flow-indent-check.js +1 -1
- package/dist/doc/Document.d.ts +10 -10
- package/dist/doc/Document.js +6 -6
- package/dist/doc/anchors.d.ts +1 -1
- package/dist/doc/createNode.js +5 -7
- package/dist/index.d.ts +2 -0
- package/dist/nodes/Collection.d.ts +2 -2
- package/dist/nodes/Collection.js +2 -1
- package/dist/nodes/Node.d.ts +15 -9
- package/dist/nodes/Pair.d.ts +1 -1
- package/dist/nodes/Pair.js +2 -2
- package/dist/nodes/Scalar.js +1 -1
- package/dist/nodes/YAMLMap.d.ts +6 -3
- package/dist/nodes/YAMLMap.js +6 -7
- package/dist/nodes/YAMLSeq.d.ts +4 -1
- package/dist/nodes/YAMLSeq.js +1 -9
- package/dist/nodes/addPairToJSMap.js +1 -1
- package/dist/nodes/toJS.js +1 -1
- package/dist/options.d.ts +2 -1
- package/dist/parse/cst-scalar.js +1 -2
- package/dist/parse/cst-visit.js +2 -2
- package/dist/parse/lexer.js +1 -2
- package/dist/parse/parser.js +24 -26
- package/dist/public-api.js +3 -4
- package/dist/schema/Schema.d.ts +3 -3
- package/dist/schema/Schema.js +1 -1
- package/dist/schema/json-schema.d.ts +69 -0
- package/dist/schema/yaml-1.1/omap.d.ts +7 -3
- package/dist/schema/yaml-1.1/omap.js +1 -1
- package/dist/schema/yaml-1.1/pairs.js +1 -2
- package/dist/schema/yaml-1.1/set.d.ts +6 -2
- package/dist/schema/yaml-1.1/set.js +4 -0
- package/dist/stringify/stringify.js +6 -8
- package/dist/stringify/stringifyCollection.js +1 -2
- package/dist/stringify/stringifyDocument.js +1 -2
- package/dist/stringify/stringifyString.js +2 -2
- package/dist/test-events.js +2 -3
- package/dist/visit.js +5 -6
- package/package.json +3 -3
- package/dist/node_modules/tslib/tslib.es6.js +0 -76
|
@@ -7,7 +7,7 @@ function includesToken(list, type) {
|
|
|
7
7
|
return true;
|
|
8
8
|
return false;
|
|
9
9
|
}
|
|
10
|
-
function
|
|
10
|
+
function findNonEmptyIndex(list) {
|
|
11
11
|
for (let i = 0; i < list.length; ++i) {
|
|
12
12
|
switch (list[i].type) {
|
|
13
13
|
case 'space':
|
|
@@ -15,13 +15,13 @@ function includesNonEmpty(list) {
|
|
|
15
15
|
case 'newline':
|
|
16
16
|
break;
|
|
17
17
|
default:
|
|
18
|
-
return
|
|
18
|
+
return i;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
return
|
|
21
|
+
return -1;
|
|
22
22
|
}
|
|
23
23
|
function isFlowToken(token) {
|
|
24
|
-
switch (token
|
|
24
|
+
switch (token?.type) {
|
|
25
25
|
case 'alias':
|
|
26
26
|
case 'scalar':
|
|
27
27
|
case 'single-quoted-scalar':
|
|
@@ -33,13 +33,12 @@ function isFlowToken(token) {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
function getPrevProps(parent) {
|
|
36
|
-
var _a;
|
|
37
36
|
switch (parent.type) {
|
|
38
37
|
case 'document':
|
|
39
38
|
return parent.start;
|
|
40
39
|
case 'block-map': {
|
|
41
40
|
const it = parent.items[parent.items.length - 1];
|
|
42
|
-
return
|
|
41
|
+
return it.sep ?? it.start;
|
|
43
42
|
}
|
|
44
43
|
case 'block-seq':
|
|
45
44
|
return parent.items[parent.items.length - 1].start;
|
|
@@ -50,7 +49,6 @@ function getPrevProps(parent) {
|
|
|
50
49
|
}
|
|
51
50
|
/** Note: May modify input array */
|
|
52
51
|
function getFirstKeyStartProps(prev) {
|
|
53
|
-
var _a;
|
|
54
52
|
if (prev.length === 0)
|
|
55
53
|
return [];
|
|
56
54
|
let i = prev.length;
|
|
@@ -64,7 +62,7 @@ function getFirstKeyStartProps(prev) {
|
|
|
64
62
|
break loop;
|
|
65
63
|
}
|
|
66
64
|
}
|
|
67
|
-
while (
|
|
65
|
+
while (prev[++i]?.type === 'space') {
|
|
68
66
|
/* loop */
|
|
69
67
|
}
|
|
70
68
|
return prev.splice(i, prev.length);
|
|
@@ -266,7 +264,7 @@ class Parser {
|
|
|
266
264
|
return this.stack[this.stack.length - n];
|
|
267
265
|
}
|
|
268
266
|
*pop(error) {
|
|
269
|
-
const token = error
|
|
267
|
+
const token = error ?? this.stack.pop();
|
|
270
268
|
/* istanbul ignore if should not happen */
|
|
271
269
|
if (!token) {
|
|
272
270
|
const message = 'Tried to pop an empty stack';
|
|
@@ -343,7 +341,7 @@ class Parser {
|
|
|
343
341
|
!last.sep &&
|
|
344
342
|
!last.value &&
|
|
345
343
|
last.start.length > 0 &&
|
|
346
|
-
|
|
344
|
+
findNonEmptyIndex(last.start) === -1 &&
|
|
347
345
|
(token.indent === 0 ||
|
|
348
346
|
last.start.every(st => st.type !== 'comment' || st.indent < token.indent))) {
|
|
349
347
|
if (top.type === 'document')
|
|
@@ -391,7 +389,7 @@ class Parser {
|
|
|
391
389
|
return yield* this.lineEnd(doc);
|
|
392
390
|
switch (this.type) {
|
|
393
391
|
case 'doc-start': {
|
|
394
|
-
if (
|
|
392
|
+
if (findNonEmptyIndex(doc.start) !== -1) {
|
|
395
393
|
yield* this.pop();
|
|
396
394
|
yield* this.step();
|
|
397
395
|
}
|
|
@@ -471,7 +469,6 @@ class Parser {
|
|
|
471
469
|
}
|
|
472
470
|
}
|
|
473
471
|
*blockMap(map) {
|
|
474
|
-
var _a;
|
|
475
472
|
const it = map.items[map.items.length - 1];
|
|
476
473
|
// it.sep is true-ish if pair already has key or : separator
|
|
477
474
|
switch (this.type) {
|
|
@@ -480,26 +477,30 @@ class Parser {
|
|
|
480
477
|
if (it.value) {
|
|
481
478
|
const end = 'end' in it.value ? it.value.end : undefined;
|
|
482
479
|
const last = Array.isArray(end) ? end[end.length - 1] : undefined;
|
|
483
|
-
if (
|
|
484
|
-
end
|
|
480
|
+
if (last?.type === 'comment')
|
|
481
|
+
end?.push(this.sourceToken);
|
|
485
482
|
else
|
|
486
483
|
map.items.push({ start: [this.sourceToken] });
|
|
487
484
|
}
|
|
488
|
-
else if (it.sep)
|
|
485
|
+
else if (it.sep) {
|
|
489
486
|
it.sep.push(this.sourceToken);
|
|
490
|
-
|
|
487
|
+
}
|
|
488
|
+
else {
|
|
491
489
|
it.start.push(this.sourceToken);
|
|
490
|
+
}
|
|
492
491
|
return;
|
|
493
492
|
case 'space':
|
|
494
493
|
case 'comment':
|
|
495
|
-
if (it.value)
|
|
494
|
+
if (it.value) {
|
|
496
495
|
map.items.push({ start: [this.sourceToken] });
|
|
497
|
-
|
|
496
|
+
}
|
|
497
|
+
else if (it.sep) {
|
|
498
498
|
it.sep.push(this.sourceToken);
|
|
499
|
+
}
|
|
499
500
|
else {
|
|
500
501
|
if (this.atIndentedComment(it.start, map.indent)) {
|
|
501
502
|
const prev = map.items[map.items.length - 2];
|
|
502
|
-
const end =
|
|
503
|
+
const end = prev?.value?.end;
|
|
503
504
|
if (Array.isArray(end)) {
|
|
504
505
|
Array.prototype.push.apply(end, it.start);
|
|
505
506
|
end.push(this.sourceToken);
|
|
@@ -512,9 +513,7 @@ class Parser {
|
|
|
512
513
|
return;
|
|
513
514
|
}
|
|
514
515
|
if (this.indent >= map.indent) {
|
|
515
|
-
const atNextItem = !this.onKeyLine &&
|
|
516
|
-
this.indent === map.indent &&
|
|
517
|
-
(it.sep || includesNonEmpty(it.start));
|
|
516
|
+
const atNextItem = !this.onKeyLine && this.indent === map.indent && it.sep;
|
|
518
517
|
// For empty nodes, assign newline-separated not indented empty tokens to following node
|
|
519
518
|
let start = [];
|
|
520
519
|
if (atNextItem && it.sep && !it.value) {
|
|
@@ -678,15 +677,14 @@ class Parser {
|
|
|
678
677
|
yield* this.step();
|
|
679
678
|
}
|
|
680
679
|
*blockSequence(seq) {
|
|
681
|
-
var _a;
|
|
682
680
|
const it = seq.items[seq.items.length - 1];
|
|
683
681
|
switch (this.type) {
|
|
684
682
|
case 'newline':
|
|
685
683
|
if (it.value) {
|
|
686
684
|
const end = 'end' in it.value ? it.value.end : undefined;
|
|
687
685
|
const last = Array.isArray(end) ? end[end.length - 1] : undefined;
|
|
688
|
-
if (
|
|
689
|
-
end
|
|
686
|
+
if (last?.type === 'comment')
|
|
687
|
+
end?.push(this.sourceToken);
|
|
690
688
|
else
|
|
691
689
|
seq.items.push({ start: [this.sourceToken] });
|
|
692
690
|
}
|
|
@@ -700,7 +698,7 @@ class Parser {
|
|
|
700
698
|
else {
|
|
701
699
|
if (this.atIndentedComment(it.start, seq.indent)) {
|
|
702
700
|
const prev = seq.items[seq.items.length - 2];
|
|
703
|
-
const end =
|
|
701
|
+
const end = prev?.value?.end;
|
|
704
702
|
if (Array.isArray(end)) {
|
|
705
703
|
Array.prototype.push.apply(end, it.start);
|
|
706
704
|
end.push(this.sourceToken);
|
|
@@ -21,7 +21,7 @@ function parseOptions(options) {
|
|
|
21
21
|
*/
|
|
22
22
|
function parseAllDocuments(source, options = {}) {
|
|
23
23
|
const { lineCounter, prettyErrors } = parseOptions(options);
|
|
24
|
-
const parser = new Parser(lineCounter
|
|
24
|
+
const parser = new Parser(lineCounter?.addNewLine);
|
|
25
25
|
const composer = new Composer(options);
|
|
26
26
|
const docs = Array.from(composer.compose(parser.parse(source)));
|
|
27
27
|
if (prettyErrors && lineCounter)
|
|
@@ -36,7 +36,7 @@ function parseAllDocuments(source, options = {}) {
|
|
|
36
36
|
/** Parse an input string into a single YAML.Document */
|
|
37
37
|
function parseDocument(source, options = {}) {
|
|
38
38
|
const { lineCounter, prettyErrors } = parseOptions(options);
|
|
39
|
-
const parser = new Parser(lineCounter
|
|
39
|
+
const parser = new Parser(lineCounter?.addNewLine);
|
|
40
40
|
const composer = new Composer(options);
|
|
41
41
|
// `doc` is always set by compose.end(true) at the very latest
|
|
42
42
|
let doc = null;
|
|
@@ -75,7 +75,6 @@ function parse(src, reviver, options) {
|
|
|
75
75
|
return doc.toJS(Object.assign({ reviver: _reviver }, options));
|
|
76
76
|
}
|
|
77
77
|
function stringify(value, replacer, options) {
|
|
78
|
-
var _a;
|
|
79
78
|
let _replacer = null;
|
|
80
79
|
if (typeof replacer === 'function' || Array.isArray(replacer)) {
|
|
81
80
|
_replacer = replacer;
|
|
@@ -90,7 +89,7 @@ function stringify(value, replacer, options) {
|
|
|
90
89
|
options = indent < 1 ? undefined : indent > 8 ? { indent: 8 } : { indent };
|
|
91
90
|
}
|
|
92
91
|
if (value === undefined) {
|
|
93
|
-
const { keepUndefined } =
|
|
92
|
+
const { keepUndefined } = options ?? replacer ?? {};
|
|
94
93
|
if (!keepUndefined)
|
|
95
94
|
return undefined;
|
|
96
95
|
}
|
|
@@ -16,7 +16,7 @@ class Schema {
|
|
|
16
16
|
this.name = (typeof schema === 'string' && schema) || 'core';
|
|
17
17
|
this.knownTags = resolveKnownTags ? coreKnownTags : {};
|
|
18
18
|
this.tags = getTags(customTags, this.name);
|
|
19
|
-
this.toStringOptions = toStringDefaults
|
|
19
|
+
this.toStringOptions = toStringDefaults ?? null;
|
|
20
20
|
Object.defineProperty(this, MAP, { value: map });
|
|
21
21
|
Object.defineProperty(this, SCALAR, { value: string });
|
|
22
22
|
Object.defineProperty(this, SEQ, { value: seq });
|
|
@@ -22,7 +22,7 @@ class YAMLOMap extends YAMLSeq {
|
|
|
22
22
|
if (!ctx)
|
|
23
23
|
return super.toJSON(_);
|
|
24
24
|
const map = new Map();
|
|
25
|
-
if (ctx
|
|
25
|
+
if (ctx?.onCreate)
|
|
26
26
|
ctx.onCreate(map);
|
|
27
27
|
for (const pair of this.items) {
|
|
28
28
|
let key, value;
|
|
@@ -4,7 +4,6 @@ import { Scalar } from '../../nodes/Scalar.js';
|
|
|
4
4
|
import { YAMLSeq } from '../../nodes/YAMLSeq.js';
|
|
5
5
|
|
|
6
6
|
function resolvePairs(seq, onError) {
|
|
7
|
-
var _a;
|
|
8
7
|
if (isSeq(seq)) {
|
|
9
8
|
for (let i = 0; i < seq.items.length; ++i) {
|
|
10
9
|
let item = seq.items[i];
|
|
@@ -19,7 +18,7 @@ function resolvePairs(seq, onError) {
|
|
|
19
18
|
? `${item.commentBefore}\n${pair.key.commentBefore}`
|
|
20
19
|
: item.commentBefore;
|
|
21
20
|
if (item.comment) {
|
|
22
|
-
const cn =
|
|
21
|
+
const cn = pair.value ?? pair.key;
|
|
23
22
|
cn.comment = cn.comment
|
|
24
23
|
? `${item.comment}\n${cn.comment}`
|
|
25
24
|
: item.comment;
|
|
@@ -22,6 +22,10 @@ class YAMLSet extends YAMLMap {
|
|
|
22
22
|
if (!prev)
|
|
23
23
|
this.items.push(pair);
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* If `keepPair` is `true`, returns the Pair matching `key`.
|
|
27
|
+
* Otherwise, returns the value of that Pair's key.
|
|
28
|
+
*/
|
|
25
29
|
get(key, keepPair) {
|
|
26
30
|
const pair = findPair(this.items, key);
|
|
27
31
|
return !keepPair && isPair(pair)
|
|
@@ -43,26 +43,25 @@ function createStringifyContext(doc, options) {
|
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
function getTagObject(tags, item) {
|
|
46
|
-
var _a, _b, _c, _d;
|
|
47
46
|
if (item.tag) {
|
|
48
47
|
const match = tags.filter(t => t.tag === item.tag);
|
|
49
48
|
if (match.length > 0)
|
|
50
|
-
return
|
|
49
|
+
return match.find(t => t.format === item.format) ?? match[0];
|
|
51
50
|
}
|
|
52
51
|
let tagObj = undefined;
|
|
53
52
|
let obj;
|
|
54
53
|
if (isScalar(item)) {
|
|
55
54
|
obj = item.value;
|
|
56
|
-
const match = tags.filter(t =>
|
|
55
|
+
const match = tags.filter(t => t.identify?.(obj));
|
|
57
56
|
tagObj =
|
|
58
|
-
|
|
57
|
+
match.find(t => t.format === item.format) ?? match.find(t => !t.format);
|
|
59
58
|
}
|
|
60
59
|
else {
|
|
61
60
|
obj = item;
|
|
62
61
|
tagObj = tags.find(t => t.nodeClass && obj instanceof t.nodeClass);
|
|
63
62
|
}
|
|
64
63
|
if (!tagObj) {
|
|
65
|
-
const name =
|
|
64
|
+
const name = obj?.constructor?.name ?? typeof obj;
|
|
66
65
|
throw new Error(`Tag not resolved for ${name} value`);
|
|
67
66
|
}
|
|
68
67
|
return tagObj;
|
|
@@ -83,13 +82,12 @@ function stringifyProps(node, tagObj, { anchors, doc }) {
|
|
|
83
82
|
return props.join(' ');
|
|
84
83
|
}
|
|
85
84
|
function stringify(item, ctx, onComment, onChompKeep) {
|
|
86
|
-
var _a, _b;
|
|
87
85
|
if (isPair(item))
|
|
88
86
|
return item.toString(ctx, onComment, onChompKeep);
|
|
89
87
|
if (isAlias(item)) {
|
|
90
88
|
if (ctx.doc.directives)
|
|
91
89
|
return item.toString(ctx);
|
|
92
|
-
if (
|
|
90
|
+
if (ctx.resolvedAliases?.has(item)) {
|
|
93
91
|
throw new TypeError(`Cannot stringify circular structure without alias nodes`);
|
|
94
92
|
}
|
|
95
93
|
else {
|
|
@@ -108,7 +106,7 @@ function stringify(item, ctx, onComment, onChompKeep) {
|
|
|
108
106
|
tagObj = getTagObject(ctx.doc.schema.tags, node);
|
|
109
107
|
const props = stringifyProps(node, tagObj, ctx);
|
|
110
108
|
if (props.length > 0)
|
|
111
|
-
ctx.indentAtStart = (
|
|
109
|
+
ctx.indentAtStart = (ctx.indentAtStart ?? 0) + props.length + 1;
|
|
112
110
|
const str = typeof tagObj.stringify === 'function'
|
|
113
111
|
? tagObj.stringify(node, ctx, onComment, onChompKeep)
|
|
114
112
|
: isScalar(node)
|
|
@@ -4,8 +4,7 @@ import { stringify } from './stringify.js';
|
|
|
4
4
|
import { lineComment, indentComment } from './stringifyComment.js';
|
|
5
5
|
|
|
6
6
|
function stringifyCollection(collection, ctx, options) {
|
|
7
|
-
|
|
8
|
-
const flow = (_a = ctx.inFlow) !== null && _a !== void 0 ? _a : collection.flow;
|
|
7
|
+
const flow = ctx.inFlow ?? collection.flow;
|
|
9
8
|
const stringify = flow ? stringifyFlowCollection : stringifyBlockCollection;
|
|
10
9
|
return stringify(collection, ctx, options);
|
|
11
10
|
}
|
|
@@ -3,7 +3,6 @@ import { createStringifyContext, stringify } from './stringify.js';
|
|
|
3
3
|
import { indentComment, lineComment } from './stringifyComment.js';
|
|
4
4
|
|
|
5
5
|
function stringifyDocument(doc, options) {
|
|
6
|
-
var _a;
|
|
7
6
|
const lines = [];
|
|
8
7
|
let hasDirectives = options.directives === true;
|
|
9
8
|
if (options.directives !== false && doc.directives) {
|
|
@@ -55,7 +54,7 @@ function stringifyDocument(doc, options) {
|
|
|
55
54
|
else {
|
|
56
55
|
lines.push(stringify(doc.contents, ctx));
|
|
57
56
|
}
|
|
58
|
-
if (
|
|
57
|
+
if (doc.directives?.docEnd) {
|
|
59
58
|
if (doc.comment) {
|
|
60
59
|
const cs = commentString(doc.comment);
|
|
61
60
|
if (cs.includes('\n')) {
|
|
@@ -263,9 +263,9 @@ function plainString(item, ctx, onComment, onChompKeep) {
|
|
|
263
263
|
// booleans get parsed with those types in v1.2 (e.g. '42', 'true' & '0.9e-3'),
|
|
264
264
|
// and others in v1.1.
|
|
265
265
|
if (actualString) {
|
|
266
|
-
const test = (tag) =>
|
|
266
|
+
const test = (tag) => tag.default && tag.tag !== 'tag:yaml.org,2002:str' && tag.test?.test(str);
|
|
267
267
|
const { compat, tags } = ctx.doc.schema;
|
|
268
|
-
if (tags.some(test) ||
|
|
268
|
+
if (tags.some(test) || compat?.some(test))
|
|
269
269
|
return quotedString(value, ctx);
|
|
270
270
|
}
|
|
271
271
|
return implicitKey
|
package/browser/dist/visit.js
CHANGED
|
@@ -196,19 +196,18 @@ function initVisitor(visitor) {
|
|
|
196
196
|
return visitor;
|
|
197
197
|
}
|
|
198
198
|
function callVisitor(key, node, visitor, path) {
|
|
199
|
-
var _a, _b, _c, _d, _e;
|
|
200
199
|
if (typeof visitor === 'function')
|
|
201
200
|
return visitor(key, node, path);
|
|
202
201
|
if (isMap(node))
|
|
203
|
-
return
|
|
202
|
+
return visitor.Map?.(key, node, path);
|
|
204
203
|
if (isSeq(node))
|
|
205
|
-
return
|
|
204
|
+
return visitor.Seq?.(key, node, path);
|
|
206
205
|
if (isPair(node))
|
|
207
|
-
return
|
|
206
|
+
return visitor.Pair?.(key, node, path);
|
|
208
207
|
if (isScalar(node))
|
|
209
|
-
return
|
|
208
|
+
return visitor.Scalar?.(key, node, path);
|
|
210
209
|
if (isAlias(node))
|
|
211
|
-
return
|
|
210
|
+
return visitor.Alias?.(key, node, path);
|
|
212
211
|
return undefined;
|
|
213
212
|
}
|
|
214
213
|
function replaceNode(key, path, node) {
|
|
@@ -53,7 +53,7 @@ function composeCollection(CN, ctx, token, tagToken, onError) {
|
|
|
53
53
|
: new Scalar.Scalar(res);
|
|
54
54
|
node.range = coll.range;
|
|
55
55
|
node.tag = tagName;
|
|
56
|
-
if (tag
|
|
56
|
+
if (tag?.format)
|
|
57
57
|
node.format = tag.format;
|
|
58
58
|
return node;
|
|
59
59
|
}
|
|
@@ -6,7 +6,7 @@ var resolveEnd = require('./resolve-end.js');
|
|
|
6
6
|
var resolveProps = require('./resolve-props.js');
|
|
7
7
|
|
|
8
8
|
function composeDoc(options, directives, { offset, start, value, end }, onError) {
|
|
9
|
-
const opts = Object.assign({ directives }, options);
|
|
9
|
+
const opts = Object.assign({ _directives: directives }, options);
|
|
10
10
|
const doc = new Document.Document(undefined, opts);
|
|
11
11
|
const ctx = {
|
|
12
12
|
atRoot: true,
|
|
@@ -16,7 +16,7 @@ function composeDoc(options, directives, { offset, start, value, end }, onError)
|
|
|
16
16
|
};
|
|
17
17
|
const props = resolveProps.resolveProps(start, {
|
|
18
18
|
indicator: 'doc-start',
|
|
19
|
-
next: value
|
|
19
|
+
next: value ?? end?.[0],
|
|
20
20
|
offset,
|
|
21
21
|
onError,
|
|
22
22
|
startOnNewline: true
|
|
@@ -19,12 +19,12 @@ function composeScalar(ctx, token, tagToken, onError) {
|
|
|
19
19
|
: ctx.schema[Node.SCALAR];
|
|
20
20
|
let scalar;
|
|
21
21
|
try {
|
|
22
|
-
const res = tag.resolve(value, msg => onError(tagToken
|
|
22
|
+
const res = tag.resolve(value, msg => onError(tagToken ?? token, 'TAG_RESOLVE_FAILED', msg), ctx.options);
|
|
23
23
|
scalar = Node.isScalar(res) ? res : new Scalar.Scalar(res);
|
|
24
24
|
}
|
|
25
25
|
catch (error) {
|
|
26
26
|
const msg = error instanceof Error ? error.message : String(error);
|
|
27
|
-
onError(tagToken
|
|
27
|
+
onError(tagToken ?? token, 'TAG_RESOLVE_FAILED', msg);
|
|
28
28
|
scalar = new Scalar.Scalar(value);
|
|
29
29
|
}
|
|
30
30
|
scalar.range = range;
|
|
@@ -40,7 +40,6 @@ function composeScalar(ctx, token, tagToken, onError) {
|
|
|
40
40
|
return scalar;
|
|
41
41
|
}
|
|
42
42
|
function findScalarTagByName(schema, value, tagName, tagToken, onError) {
|
|
43
|
-
var _a;
|
|
44
43
|
if (tagName === '!')
|
|
45
44
|
return schema[Node.SCALAR]; // non-specific tag
|
|
46
45
|
const matchWithTest = [];
|
|
@@ -53,7 +52,7 @@ function findScalarTagByName(schema, value, tagName, tagToken, onError) {
|
|
|
53
52
|
}
|
|
54
53
|
}
|
|
55
54
|
for (const tag of matchWithTest)
|
|
56
|
-
if (
|
|
55
|
+
if (tag.test?.test(value))
|
|
57
56
|
return tag;
|
|
58
57
|
const kt = schema.knownTags[tagName];
|
|
59
58
|
if (kt && !kt.collection) {
|
|
@@ -66,10 +65,10 @@ function findScalarTagByName(schema, value, tagName, tagToken, onError) {
|
|
|
66
65
|
return schema[Node.SCALAR];
|
|
67
66
|
}
|
|
68
67
|
function findScalarTagByTest({ directives, schema }, value, token, onError) {
|
|
69
|
-
|
|
70
|
-
const tag = schema.tags.find(tag => { var _a; return tag.default && ((_a = tag.test) === null || _a === void 0 ? void 0 : _a.test(value)); }) || schema[Node.SCALAR];
|
|
68
|
+
const tag = schema.tags.find(tag => tag.default && tag.test?.test(value)) || schema[Node.SCALAR];
|
|
71
69
|
if (schema.compat) {
|
|
72
|
-
const compat =
|
|
70
|
+
const compat = schema.compat.find(tag => tag.default && tag.test?.test(value)) ??
|
|
71
|
+
schema[Node.SCALAR];
|
|
73
72
|
if (tag.tag !== compat.tag) {
|
|
74
73
|
const ts = directives.tagString(tag.tag);
|
|
75
74
|
const cs = directives.tagString(compat.tag);
|
package/dist/compose/composer.js
CHANGED
|
@@ -16,7 +16,6 @@ function getErrorPos(src) {
|
|
|
16
16
|
return [offset, offset + (typeof source === 'string' ? source.length : 1)];
|
|
17
17
|
}
|
|
18
18
|
function parsePrelude(prelude) {
|
|
19
|
-
var _a;
|
|
20
19
|
let comment = '';
|
|
21
20
|
let atComment = false;
|
|
22
21
|
let afterEmptyLine = false;
|
|
@@ -31,7 +30,7 @@ function parsePrelude(prelude) {
|
|
|
31
30
|
afterEmptyLine = false;
|
|
32
31
|
break;
|
|
33
32
|
case '%':
|
|
34
|
-
if (
|
|
33
|
+
if (prelude[i + 1]?.[0] !== '#')
|
|
35
34
|
i += 1;
|
|
36
35
|
atComment = false;
|
|
37
36
|
break;
|
|
@@ -208,7 +207,7 @@ class Composer {
|
|
|
208
207
|
this.doc = null;
|
|
209
208
|
}
|
|
210
209
|
else if (forceDoc) {
|
|
211
|
-
const opts = Object.assign({
|
|
210
|
+
const opts = Object.assign({ _directives: this.directives }, this.options);
|
|
212
211
|
const doc = new Document.Document(undefined, opts);
|
|
213
212
|
if (this.atDirectives)
|
|
214
213
|
this.onError(endOffset, 'MISSING_CHAR', 'Missing directives-end indicator line');
|
|
@@ -9,7 +9,6 @@ var utilMapIncludes = require('./util-map-includes.js');
|
|
|
9
9
|
|
|
10
10
|
const startColMsg = 'All mapping items must start at the same column';
|
|
11
11
|
function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
|
|
12
|
-
var _a;
|
|
13
12
|
const map = new YAMLMap.YAMLMap(ctx.schema);
|
|
14
13
|
if (ctx.atRoot)
|
|
15
14
|
ctx.atRoot = false;
|
|
@@ -19,7 +18,7 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
|
|
|
19
18
|
// key properties
|
|
20
19
|
const keyProps = resolveProps.resolveProps(start, {
|
|
21
20
|
indicator: 'explicit-key-ind',
|
|
22
|
-
next: key
|
|
21
|
+
next: key ?? sep?.[0],
|
|
23
22
|
offset,
|
|
24
23
|
onError,
|
|
25
24
|
startOnNewline: true
|
|
@@ -42,12 +41,13 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
|
|
|
42
41
|
}
|
|
43
42
|
continue;
|
|
44
43
|
}
|
|
44
|
+
if (keyProps.hasNewlineAfterProp || utilContainsNewline.containsNewline(key)) {
|
|
45
|
+
onError(key ?? start[start.length - 1], 'MULTILINE_IMPLICIT_KEY', 'Implicit keys need to be on a single line');
|
|
46
|
+
}
|
|
45
47
|
}
|
|
46
|
-
else if (
|
|
48
|
+
else if (keyProps.found?.indent !== bm.indent) {
|
|
47
49
|
onError(offset, 'BAD_INDENT', startColMsg);
|
|
48
|
-
|
|
49
|
-
onError(key, // checked by containsNewline()
|
|
50
|
-
'MULTILINE_IMPLICIT_KEY', 'Implicit keys need to be on a single line');
|
|
50
|
+
}
|
|
51
51
|
// key value
|
|
52
52
|
const keyStart = keyProps.end;
|
|
53
53
|
const keyNode = key
|
|
@@ -58,7 +58,7 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
|
|
|
58
58
|
if (utilMapIncludes.mapIncludes(ctx, map.items, keyNode))
|
|
59
59
|
onError(keyStart, 'DUPLICATE_KEY', 'Map keys must be unique');
|
|
60
60
|
// value properties
|
|
61
|
-
const valueProps = resolveProps.resolveProps(sep
|
|
61
|
+
const valueProps = resolveProps.resolveProps(sep ?? [], {
|
|
62
62
|
indicator: 'map-value-ind',
|
|
63
63
|
next: value,
|
|
64
64
|
offset: keyNode.range[2],
|
|
@@ -68,7 +68,7 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
|
|
|
68
68
|
offset = valueProps.end;
|
|
69
69
|
if (valueProps.found) {
|
|
70
70
|
if (implicitKey) {
|
|
71
|
-
if (
|
|
71
|
+
if (value?.type === 'block-map' && !valueProps.hasNewline)
|
|
72
72
|
onError(offset, 'BLOCK_AS_IMPLICIT_KEY', 'Nested mappings are not allowed in compact mappings');
|
|
73
73
|
if (ctx.options.strict &&
|
|
74
74
|
keyProps.start < valueProps.found.offset - 1024)
|
|
@@ -184,7 +184,7 @@ function splitLines(source) {
|
|
|
184
184
|
const split = source.split(/\n( *)/);
|
|
185
185
|
const first = split[0];
|
|
186
186
|
const m = first.match(/^( *)/);
|
|
187
|
-
const line0 =
|
|
187
|
+
const line0 = m?.[1]
|
|
188
188
|
? [m[1], first.slice(m[1].length)]
|
|
189
189
|
: ['', first];
|
|
190
190
|
const lines = [line0];
|
|
@@ -12,7 +12,6 @@ var utilMapIncludes = require('./util-map-includes.js');
|
|
|
12
12
|
const blockMsg = 'Block collections are not allowed within flow collections';
|
|
13
13
|
const isBlock = (token) => token && (token.type === 'block-map' || token.type === 'block-seq');
|
|
14
14
|
function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onError) {
|
|
15
|
-
var _a;
|
|
16
15
|
const isMap = fc.start.source === '{';
|
|
17
16
|
const fcName = isMap ? 'flow map' : 'flow sequence';
|
|
18
17
|
const coll = isMap
|
|
@@ -29,7 +28,7 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
|
|
|
29
28
|
const props = resolveProps.resolveProps(start, {
|
|
30
29
|
flow: fcName,
|
|
31
30
|
indicator: 'explicit-key-ind',
|
|
32
|
-
next: key
|
|
31
|
+
next: key ?? sep?.[0],
|
|
33
32
|
offset,
|
|
34
33
|
onError,
|
|
35
34
|
startOnNewline: false
|
|
@@ -77,7 +76,7 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
|
|
|
77
76
|
if (prevItemComment) {
|
|
78
77
|
let prev = coll.items[coll.items.length - 1];
|
|
79
78
|
if (Node.isPair(prev))
|
|
80
|
-
prev =
|
|
79
|
+
prev = prev.value ?? prev.key;
|
|
81
80
|
if (prev.comment)
|
|
82
81
|
prev.comment += '\n' + prevItemComment;
|
|
83
82
|
else
|
|
@@ -107,7 +106,7 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
|
|
|
107
106
|
if (isBlock(key))
|
|
108
107
|
onError(keyNode.range, 'BLOCK_IN_FLOW', blockMsg);
|
|
109
108
|
// value properties
|
|
110
|
-
const valueProps = resolveProps.resolveProps(sep
|
|
109
|
+
const valueProps = resolveProps.resolveProps(sep ?? [], {
|
|
111
110
|
flow: fcName,
|
|
112
111
|
indicator: 'map-value-ind',
|
|
113
112
|
next: value,
|
|
@@ -74,7 +74,6 @@ function singleQuotedValue(source, onError) {
|
|
|
74
74
|
return foldLines(source.slice(1, -1)).replace(/''/g, "'");
|
|
75
75
|
}
|
|
76
76
|
function foldLines(source) {
|
|
77
|
-
var _a;
|
|
78
77
|
/**
|
|
79
78
|
* The negative lookbehind here and in the `re` RegExp is to
|
|
80
79
|
* prevent causing a polynomial search time in certain cases.
|
|
@@ -114,7 +113,7 @@ function foldLines(source) {
|
|
|
114
113
|
const last = /[ \t]*(.*)/sy;
|
|
115
114
|
last.lastIndex = pos;
|
|
116
115
|
match = last.exec(source);
|
|
117
|
-
return res + sep + (
|
|
116
|
+
return res + sep + (match?.[1] ?? '');
|
|
118
117
|
}
|
|
119
118
|
function doubleQuotedValue(source, onError) {
|
|
120
119
|
let res = '';
|
|
@@ -7,6 +7,7 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
|
|
|
7
7
|
let comment = '';
|
|
8
8
|
let commentSep = '';
|
|
9
9
|
let hasNewline = false;
|
|
10
|
+
let hasNewlineAfterProp = false;
|
|
10
11
|
let reqSpace = false;
|
|
11
12
|
let anchor = null;
|
|
12
13
|
let tag = null;
|
|
@@ -56,6 +57,8 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
|
|
|
56
57
|
commentSep += token.source;
|
|
57
58
|
atNewline = true;
|
|
58
59
|
hasNewline = true;
|
|
60
|
+
if (anchor || tag)
|
|
61
|
+
hasNewlineAfterProp = true;
|
|
59
62
|
hasSpace = true;
|
|
60
63
|
break;
|
|
61
64
|
case 'anchor':
|
|
@@ -86,7 +89,7 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
|
|
|
86
89
|
if (anchor || tag)
|
|
87
90
|
onError(token, 'BAD_PROP_ORDER', `Anchors and tags must be after the ${token.source} indicator`);
|
|
88
91
|
if (found)
|
|
89
|
-
onError(token, 'UNEXPECTED_TOKEN', `Unexpected ${token.source} in ${flow
|
|
92
|
+
onError(token, 'UNEXPECTED_TOKEN', `Unexpected ${token.source} in ${flow ?? 'collection'}`);
|
|
90
93
|
found = token;
|
|
91
94
|
atNewline = false;
|
|
92
95
|
hasSpace = false;
|
|
@@ -122,10 +125,11 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
|
|
|
122
125
|
spaceBefore,
|
|
123
126
|
comment,
|
|
124
127
|
hasNewline,
|
|
128
|
+
hasNewlineAfterProp,
|
|
125
129
|
anchor,
|
|
126
130
|
tag,
|
|
127
131
|
end,
|
|
128
|
-
start: start
|
|
132
|
+
start: start ?? end
|
|
129
133
|
};
|
|
130
134
|
}
|
|
131
135
|
|
|
@@ -16,7 +16,7 @@ function emptyScalarPosition(offset, before, pos) {
|
|
|
16
16
|
// Technically, an empty scalar is immediately after the last non-empty
|
|
17
17
|
// node, but it's more useful to place it after any whitespace.
|
|
18
18
|
st = before[++i];
|
|
19
|
-
while (
|
|
19
|
+
while (st?.type === 'space') {
|
|
20
20
|
offset += st.source.length;
|
|
21
21
|
st = before[++i];
|
|
22
22
|
}
|