yaml 2.0.0-9 → 2.0.0
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/README.md +1 -1
- package/browser/dist/compose/compose-doc.js +3 -2
- package/browser/dist/compose/compose-node.js +13 -4
- package/browser/dist/compose/compose-scalar.js +16 -10
- package/browser/dist/compose/composer.js +6 -7
- package/browser/dist/compose/resolve-block-map.js +9 -2
- package/browser/dist/compose/resolve-block-scalar.js +12 -3
- package/browser/dist/compose/resolve-block-seq.js +5 -0
- package/browser/dist/compose/resolve-flow-collection.js +14 -5
- package/browser/dist/compose/resolve-flow-scalar.js +2 -1
- package/browser/dist/compose/resolve-props.js +4 -0
- package/browser/dist/compose/util-flow-indent-check.js +15 -0
- package/browser/dist/doc/Document.js +49 -16
- package/browser/dist/doc/anchors.js +2 -2
- package/browser/dist/doc/createNode.js +7 -4
- package/browser/dist/doc/directives.js +7 -4
- package/browser/dist/index.js +1 -2
- package/browser/dist/nodes/Pair.js +2 -2
- package/browser/dist/nodes/Scalar.js +1 -1
- package/browser/dist/nodes/YAMLMap.js +6 -5
- package/browser/dist/nodes/YAMLSeq.js +2 -2
- package/browser/dist/nodes/addPairToJSMap.js +1 -1
- package/browser/dist/nodes/toJS.js +3 -1
- package/browser/dist/parse/cst-visit.js +2 -2
- package/browser/dist/parse/lexer.js +21 -8
- package/browser/dist/parse/parser.js +121 -45
- package/browser/dist/public-api.js +4 -5
- package/browser/dist/schema/Schema.js +14 -4
- package/browser/dist/schema/common/null.js +3 -1
- package/browser/dist/schema/core/float.js +4 -1
- package/browser/dist/schema/tags.js +9 -9
- package/browser/dist/schema/yaml-1.1/float.js +4 -1
- package/browser/dist/schema/yaml-1.1/omap.js +1 -1
- package/browser/dist/schema/yaml-1.1/pairs.js +2 -1
- package/browser/dist/stringify/stringify.js +51 -22
- package/browser/dist/stringify/stringifyCollection.js +115 -85
- package/browser/dist/stringify/stringifyComment.js +18 -12
- package/browser/dist/stringify/stringifyDocument.js +37 -15
- package/browser/dist/stringify/stringifyPair.js +34 -20
- package/browser/dist/stringify/stringifyString.js +8 -11
- package/browser/dist/visit.js +150 -62
- package/dist/compose/compose-doc.js +3 -2
- package/dist/compose/compose-node.d.ts +1 -0
- package/dist/compose/compose-node.js +13 -4
- package/dist/compose/compose-scalar.js +15 -9
- package/dist/compose/composer.d.ts +1 -1
- package/dist/compose/composer.js +8 -9
- package/dist/compose/resolve-block-map.js +9 -2
- package/dist/compose/resolve-block-scalar.js +12 -3
- package/dist/compose/resolve-block-seq.js +5 -0
- package/dist/compose/resolve-flow-collection.js +14 -5
- package/dist/compose/resolve-flow-scalar.js +2 -1
- package/dist/compose/resolve-props.d.ts +1 -1
- package/dist/compose/resolve-props.js +4 -0
- package/dist/compose/util-flow-indent-check.d.ts +3 -0
- package/dist/compose/util-flow-indent-check.js +17 -0
- package/dist/doc/Document.d.ts +7 -4
- package/dist/doc/Document.js +56 -23
- package/dist/doc/anchors.d.ts +2 -2
- package/dist/doc/anchors.js +2 -2
- package/dist/doc/createNode.d.ts +1 -1
- package/dist/doc/createNode.js +7 -4
- package/dist/doc/directives.d.ts +4 -2
- package/dist/doc/directives.js +7 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -2
- package/dist/nodes/Pair.js +2 -2
- package/dist/nodes/Scalar.js +1 -1
- package/dist/nodes/YAMLMap.d.ts +3 -1
- package/dist/nodes/YAMLMap.js +6 -5
- package/dist/nodes/YAMLSeq.js +2 -2
- package/dist/nodes/addPairToJSMap.js +1 -1
- package/dist/nodes/toJS.js +3 -1
- package/dist/options.d.ts +42 -12
- package/dist/parse/cst-visit.js +2 -2
- package/dist/parse/lexer.js +21 -8
- package/dist/parse/parser.js +121 -45
- package/dist/public-api.js +4 -5
- package/dist/schema/Schema.d.ts +5 -4
- package/dist/schema/Schema.js +13 -3
- package/dist/schema/common/null.js +3 -1
- package/dist/schema/core/float.js +4 -1
- package/dist/schema/tags.d.ts +1 -2
- package/dist/schema/tags.js +9 -9
- package/dist/schema/yaml-1.1/float.js +4 -1
- package/dist/schema/yaml-1.1/omap.js +1 -1
- package/dist/schema/yaml-1.1/pairs.js +2 -1
- package/dist/stringify/stringify.d.ts +5 -3
- package/dist/stringify/stringify.js +51 -22
- package/dist/stringify/stringifyCollection.d.ts +2 -6
- package/dist/stringify/stringifyCollection.js +114 -84
- package/dist/stringify/stringifyComment.d.ts +10 -2
- package/dist/stringify/stringifyComment.js +19 -12
- package/dist/stringify/stringifyDocument.js +36 -14
- package/dist/stringify/stringifyPair.js +33 -19
- package/dist/stringify/stringifyString.js +8 -11
- package/dist/test-events.js +13 -12
- package/dist/visit.d.ts +49 -10
- package/dist/visit.js +149 -60
- package/package.json +9 -8
- package/browser/dist/options.js +0 -18
- package/dist/options.js +0 -20
|
@@ -8,7 +8,7 @@ class Scalar extends NodeBase {
|
|
|
8
8
|
this.value = value;
|
|
9
9
|
}
|
|
10
10
|
toJSON(arg, ctx) {
|
|
11
|
-
return ctx
|
|
11
|
+
return (ctx === null || ctx === void 0 ? void 0 : ctx.keep) ? this.value : toJS(this.value, arg, ctx);
|
|
12
12
|
}
|
|
13
13
|
toString() {
|
|
14
14
|
return String(this.value);
|
|
@@ -32,6 +32,7 @@ class YAMLMap extends Collection {
|
|
|
32
32
|
* collection will throw. Otherwise, overwrites the previous value.
|
|
33
33
|
*/
|
|
34
34
|
add(pair, overwrite) {
|
|
35
|
+
var _a;
|
|
35
36
|
let _pair;
|
|
36
37
|
if (isPair(pair))
|
|
37
38
|
_pair = pair;
|
|
@@ -42,7 +43,7 @@ class YAMLMap extends Collection {
|
|
|
42
43
|
else
|
|
43
44
|
_pair = new Pair(pair.key, pair.value);
|
|
44
45
|
const prev = findPair(this.items, _pair.key);
|
|
45
|
-
const sortEntries = this.schema
|
|
46
|
+
const sortEntries = (_a = this.schema) === null || _a === void 0 ? void 0 : _a.sortMapEntries;
|
|
46
47
|
if (prev) {
|
|
47
48
|
if (!overwrite)
|
|
48
49
|
throw new Error(`Key ${_pair.key} already set`);
|
|
@@ -72,7 +73,7 @@ class YAMLMap extends Collection {
|
|
|
72
73
|
}
|
|
73
74
|
get(key, keepScalar) {
|
|
74
75
|
const it = findPair(this.items, key);
|
|
75
|
-
const node = it
|
|
76
|
+
const node = it === null || it === void 0 ? void 0 : it.value;
|
|
76
77
|
return !keepScalar && isScalar(node) ? node.value : node;
|
|
77
78
|
}
|
|
78
79
|
has(key) {
|
|
@@ -87,8 +88,8 @@ class YAMLMap extends Collection {
|
|
|
87
88
|
* @returns Instance of Type, Map, or Object
|
|
88
89
|
*/
|
|
89
90
|
toJSON(_, ctx, Type) {
|
|
90
|
-
const map = Type ? new Type() : ctx
|
|
91
|
-
if (ctx
|
|
91
|
+
const map = Type ? new Type() : (ctx === null || ctx === void 0 ? void 0 : ctx.mapAsMap) ? new Map() : {};
|
|
92
|
+
if (ctx === null || ctx === void 0 ? void 0 : ctx.onCreate)
|
|
92
93
|
ctx.onCreate(map);
|
|
93
94
|
for (const item of this.items)
|
|
94
95
|
addPairToJSMap(ctx, map, item);
|
|
@@ -104,7 +105,7 @@ class YAMLMap extends Collection {
|
|
|
104
105
|
if (!ctx.allNullValues && this.hasAllNullValues(false))
|
|
105
106
|
ctx = Object.assign({}, ctx, { allNullValues: true });
|
|
106
107
|
return stringifyCollection(this, ctx, {
|
|
107
|
-
|
|
108
|
+
blockItemPrefix: '',
|
|
108
109
|
flowChars: { start: '{', end: '}' },
|
|
109
110
|
itemIndent: ctx.indent || '',
|
|
110
111
|
onChompKeep,
|
|
@@ -74,7 +74,7 @@ class YAMLSeq extends Collection {
|
|
|
74
74
|
}
|
|
75
75
|
toJSON(_, ctx) {
|
|
76
76
|
const seq = [];
|
|
77
|
-
if (ctx
|
|
77
|
+
if (ctx === null || ctx === void 0 ? void 0 : ctx.onCreate)
|
|
78
78
|
ctx.onCreate(seq);
|
|
79
79
|
let i = 0;
|
|
80
80
|
for (const item of this.items)
|
|
@@ -85,7 +85,7 @@ class YAMLSeq extends Collection {
|
|
|
85
85
|
if (!ctx)
|
|
86
86
|
return JSON.stringify(this);
|
|
87
87
|
return stringifyCollection(this, ctx, {
|
|
88
|
-
|
|
88
|
+
blockItemPrefix: '- ',
|
|
89
89
|
flowChars: { start: '[', end: ']' },
|
|
90
90
|
itemIndent: (ctx.indent || '') + ' ',
|
|
91
91
|
onChompKeep,
|
|
@@ -6,7 +6,7 @@ import { toJS } from './toJS.js';
|
|
|
6
6
|
|
|
7
7
|
const MERGE_KEY = '<<';
|
|
8
8
|
function addPairToJSMap(ctx, map, { key, value }) {
|
|
9
|
-
if (ctx
|
|
9
|
+
if ((ctx === null || ctx === void 0 ? void 0 : ctx.doc.schema.merge) && isMergeKey(key)) {
|
|
10
10
|
value = isAlias(value) ? value.resolve(ctx.doc) : value;
|
|
11
11
|
if (isSeq(value))
|
|
12
12
|
for (const it of value.items)
|
|
@@ -11,9 +11,11 @@ import { hasAnchor } from './Node.js';
|
|
|
11
11
|
* stringification.
|
|
12
12
|
*/
|
|
13
13
|
function toJS(value, arg, ctx) {
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
14
15
|
if (Array.isArray(value))
|
|
15
16
|
return value.map((v, i) => toJS(v, String(i), ctx));
|
|
16
17
|
if (value && typeof value.toJSON === 'function') {
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
17
19
|
if (!ctx || !hasAnchor(value))
|
|
18
20
|
return value.toJSON(arg, ctx);
|
|
19
21
|
const data = { aliasCount: 0, count: 1, res: undefined };
|
|
@@ -27,7 +29,7 @@ function toJS(value, arg, ctx) {
|
|
|
27
29
|
ctx.onCreate(res);
|
|
28
30
|
return res;
|
|
29
31
|
}
|
|
30
|
-
if (typeof value === 'bigint' && !(ctx
|
|
32
|
+
if (typeof value === 'bigint' && !(ctx === null || ctx === void 0 ? void 0 : ctx.keep))
|
|
31
33
|
return Number(value);
|
|
32
34
|
return value;
|
|
33
35
|
}
|
|
@@ -47,7 +47,7 @@ visit.REMOVE = REMOVE;
|
|
|
47
47
|
visit.itemAtPath = (cst, path) => {
|
|
48
48
|
let item = cst;
|
|
49
49
|
for (const [field, index] of path) {
|
|
50
|
-
const tok = item
|
|
50
|
+
const tok = item === null || item === void 0 ? void 0 : item[field];
|
|
51
51
|
if (tok && 'items' in tok) {
|
|
52
52
|
item = tok.items[index];
|
|
53
53
|
}
|
|
@@ -64,7 +64,7 @@ visit.itemAtPath = (cst, path) => {
|
|
|
64
64
|
visit.parentCollection = (cst, path) => {
|
|
65
65
|
const parent = visit.itemAtPath(cst, path.slice(0, -1));
|
|
66
66
|
const field = path[path.length - 1][0];
|
|
67
|
-
const coll = parent
|
|
67
|
+
const coll = parent === null || parent === void 0 ? void 0 : parent[field];
|
|
68
68
|
if (coll && 'items' in coll)
|
|
69
69
|
return coll;
|
|
70
70
|
throw new Error('Parent collection not found');
|
|
@@ -148,12 +148,13 @@ class Lexer {
|
|
|
148
148
|
* @returns A generator of lexical tokens
|
|
149
149
|
*/
|
|
150
150
|
*lex(source, incomplete = false) {
|
|
151
|
+
var _a;
|
|
151
152
|
if (source) {
|
|
152
153
|
this.buffer = this.buffer ? this.buffer + source : source;
|
|
153
154
|
this.lineEndPos = null;
|
|
154
155
|
}
|
|
155
156
|
this.atEnd = !incomplete;
|
|
156
|
-
let next = this.next
|
|
157
|
+
let next = (_a = this.next) !== null && _a !== void 0 ? _a : 'stream';
|
|
157
158
|
while (next && (incomplete || this.hasChars(1)))
|
|
158
159
|
next = yield* this.parseNext(next);
|
|
159
160
|
}
|
|
@@ -357,9 +358,14 @@ class Lexer {
|
|
|
357
358
|
let indent = -1;
|
|
358
359
|
do {
|
|
359
360
|
nl = yield* this.pushNewline();
|
|
360
|
-
|
|
361
|
-
|
|
361
|
+
if (nl > 0) {
|
|
362
|
+
sp = yield* this.pushSpaces(false);
|
|
362
363
|
this.indentValue = indent = sp;
|
|
364
|
+
}
|
|
365
|
+
else {
|
|
366
|
+
sp = 0;
|
|
367
|
+
}
|
|
368
|
+
sp += yield* this.pushSpaces(true);
|
|
363
369
|
} while (nl + sp > 0);
|
|
364
370
|
const line = this.getLine();
|
|
365
371
|
if (line === null)
|
|
@@ -416,6 +422,7 @@ class Lexer {
|
|
|
416
422
|
case ':': {
|
|
417
423
|
const next = this.charAt(1);
|
|
418
424
|
if (this.flowKey || isEmpty(next) || next === ',') {
|
|
425
|
+
this.flowKey = false;
|
|
419
426
|
yield* this.pushCount(1);
|
|
420
427
|
yield* this.pushSpaces(true);
|
|
421
428
|
return 'flow';
|
|
@@ -532,9 +539,10 @@ class Lexer {
|
|
|
532
539
|
let ch = this.buffer[i];
|
|
533
540
|
if (ch === '\r')
|
|
534
541
|
ch = this.buffer[--i];
|
|
542
|
+
const lastChar = i; // Drop the line if last char not more indented
|
|
535
543
|
while (ch === ' ' || ch === '\t')
|
|
536
544
|
ch = this.buffer[--i];
|
|
537
|
-
if (ch === '\n' && i >= this.pos)
|
|
545
|
+
if (ch === '\n' && i >= this.pos && i + 1 + indent > lastChar)
|
|
538
546
|
nl = i;
|
|
539
547
|
else
|
|
540
548
|
break;
|
|
@@ -617,16 +625,21 @@ class Lexer {
|
|
|
617
625
|
return ((yield* this.pushUntil(isNotAnchorChar)) +
|
|
618
626
|
(yield* this.pushSpaces(true)) +
|
|
619
627
|
(yield* this.pushIndicators()));
|
|
620
|
-
case ':':
|
|
621
|
-
case '?': // this is an error outside flow collections
|
|
622
628
|
case '-': // this is an error
|
|
623
|
-
|
|
624
|
-
|
|
629
|
+
case '?': // this is an error outside flow collections
|
|
630
|
+
case ':': {
|
|
631
|
+
const inFlow = this.flowLevel > 0;
|
|
632
|
+
const ch1 = this.charAt(1);
|
|
633
|
+
if (isEmpty(ch1) || (inFlow && invalidFlowScalarChars.includes(ch1))) {
|
|
634
|
+
if (!inFlow)
|
|
625
635
|
this.indentNext = this.indentValue + 1;
|
|
636
|
+
else if (this.flowKey)
|
|
637
|
+
this.flowKey = false;
|
|
626
638
|
return ((yield* this.pushCount(1)) +
|
|
627
639
|
(yield* this.pushSpaces(true)) +
|
|
628
640
|
(yield* this.pushIndicators()));
|
|
629
641
|
}
|
|
642
|
+
}
|
|
630
643
|
}
|
|
631
644
|
return 0;
|
|
632
645
|
}
|
|
@@ -33,12 +33,13 @@ function isFlowToken(token) {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
function getPrevProps(parent) {
|
|
36
|
+
var _a;
|
|
36
37
|
switch (parent.type) {
|
|
37
38
|
case 'document':
|
|
38
39
|
return parent.start;
|
|
39
40
|
case 'block-map': {
|
|
40
41
|
const it = parent.items[parent.items.length - 1];
|
|
41
|
-
return it.sep
|
|
42
|
+
return (_a = it.sep) !== null && _a !== void 0 ? _a : it.start;
|
|
42
43
|
}
|
|
43
44
|
case 'block-seq':
|
|
44
45
|
return parent.items[parent.items.length - 1].start;
|
|
@@ -203,6 +204,7 @@ class Parser {
|
|
|
203
204
|
this.indent += source.length;
|
|
204
205
|
break;
|
|
205
206
|
case 'doc-mode':
|
|
207
|
+
case 'flow-error-end':
|
|
206
208
|
return;
|
|
207
209
|
default:
|
|
208
210
|
this.atNewLine = false;
|
|
@@ -264,7 +266,7 @@ class Parser {
|
|
|
264
266
|
return this.stack[this.stack.length - n];
|
|
265
267
|
}
|
|
266
268
|
*pop(error) {
|
|
267
|
-
const token = error
|
|
269
|
+
const token = error !== null && error !== void 0 ? error : this.stack.pop();
|
|
268
270
|
/* istanbul ignore if should not happen */
|
|
269
271
|
if (!token) {
|
|
270
272
|
const message = 'Tried to pop an empty stack';
|
|
@@ -275,9 +277,14 @@ class Parser {
|
|
|
275
277
|
}
|
|
276
278
|
else {
|
|
277
279
|
const top = this.peek(1);
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
token.indent = 'indent' in top ? top.indent :
|
|
280
|
+
if (token.type === 'block-scalar') {
|
|
281
|
+
// Block scalars use their parent rather than header indent
|
|
282
|
+
token.indent = 'indent' in top ? top.indent : 0;
|
|
283
|
+
}
|
|
284
|
+
else if (token.type === 'flow-collection' && top.type === 'document') {
|
|
285
|
+
// Ignore all indent for top-level flow collections
|
|
286
|
+
token.indent = 0;
|
|
287
|
+
}
|
|
281
288
|
if (token.type === 'flow-collection')
|
|
282
289
|
fixFlowSeqItems(token);
|
|
283
290
|
switch (top.type) {
|
|
@@ -508,63 +515,131 @@ class Parser {
|
|
|
508
515
|
const atNextItem = !this.onKeyLine &&
|
|
509
516
|
this.indent === map.indent &&
|
|
510
517
|
(it.sep || includesNonEmpty(it.start));
|
|
518
|
+
// For empty nodes, assign newline-separated not indented empty tokens to following node
|
|
519
|
+
let start = [];
|
|
520
|
+
if (atNextItem && it.sep && !it.value) {
|
|
521
|
+
const nl = [];
|
|
522
|
+
for (let i = 0; i < it.sep.length; ++i) {
|
|
523
|
+
const st = it.sep[i];
|
|
524
|
+
switch (st.type) {
|
|
525
|
+
case 'newline':
|
|
526
|
+
nl.push(i);
|
|
527
|
+
break;
|
|
528
|
+
case 'space':
|
|
529
|
+
break;
|
|
530
|
+
case 'comment':
|
|
531
|
+
if (st.indent > map.indent)
|
|
532
|
+
nl.length = 0;
|
|
533
|
+
break;
|
|
534
|
+
default:
|
|
535
|
+
nl.length = 0;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
if (nl.length >= 2)
|
|
539
|
+
start = it.sep.splice(nl[1]);
|
|
540
|
+
}
|
|
511
541
|
switch (this.type) {
|
|
512
542
|
case 'anchor':
|
|
513
543
|
case 'tag':
|
|
514
544
|
if (atNextItem || it.value) {
|
|
515
|
-
|
|
545
|
+
start.push(this.sourceToken);
|
|
546
|
+
map.items.push({ start });
|
|
516
547
|
this.onKeyLine = true;
|
|
517
548
|
}
|
|
518
|
-
else if (it.sep)
|
|
549
|
+
else if (it.sep) {
|
|
519
550
|
it.sep.push(this.sourceToken);
|
|
520
|
-
|
|
551
|
+
}
|
|
552
|
+
else {
|
|
521
553
|
it.start.push(this.sourceToken);
|
|
554
|
+
}
|
|
522
555
|
return;
|
|
523
556
|
case 'explicit-key-ind':
|
|
524
|
-
if (!it.sep && !includesToken(it.start, 'explicit-key-ind'))
|
|
557
|
+
if (!it.sep && !includesToken(it.start, 'explicit-key-ind')) {
|
|
525
558
|
it.start.push(this.sourceToken);
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
559
|
+
}
|
|
560
|
+
else if (atNextItem || it.value) {
|
|
561
|
+
start.push(this.sourceToken);
|
|
562
|
+
map.items.push({ start });
|
|
563
|
+
}
|
|
564
|
+
else {
|
|
529
565
|
this.stack.push({
|
|
530
566
|
type: 'block-map',
|
|
531
567
|
offset: this.offset,
|
|
532
568
|
indent: this.indent,
|
|
533
569
|
items: [{ start: [this.sourceToken] }]
|
|
534
570
|
});
|
|
571
|
+
}
|
|
535
572
|
this.onKeyLine = true;
|
|
536
573
|
return;
|
|
537
574
|
case 'map-value-ind':
|
|
538
|
-
if (
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
575
|
+
if (includesToken(it.start, 'explicit-key-ind')) {
|
|
576
|
+
if (!it.sep) {
|
|
577
|
+
if (includesToken(it.start, 'newline')) {
|
|
578
|
+
Object.assign(it, { key: null, sep: [this.sourceToken] });
|
|
579
|
+
}
|
|
580
|
+
else {
|
|
581
|
+
const start = getFirstKeyStartProps(it.start);
|
|
582
|
+
this.stack.push({
|
|
583
|
+
type: 'block-map',
|
|
584
|
+
offset: this.offset,
|
|
585
|
+
indent: this.indent,
|
|
586
|
+
items: [{ start, key: null, sep: [this.sourceToken] }]
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
else if (it.value) {
|
|
591
|
+
map.items.push({ start: [], key: null, sep: [this.sourceToken] });
|
|
592
|
+
}
|
|
593
|
+
else if (includesToken(it.sep, 'map-value-ind')) {
|
|
594
|
+
this.stack.push({
|
|
595
|
+
type: 'block-map',
|
|
596
|
+
offset: this.offset,
|
|
597
|
+
indent: this.indent,
|
|
598
|
+
items: [{ start, key: null, sep: [this.sourceToken] }]
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
else if (isFlowToken(it.key) &&
|
|
602
|
+
!includesToken(it.sep, 'newline')) {
|
|
603
|
+
const start = getFirstKeyStartProps(it.start);
|
|
604
|
+
const key = it.key;
|
|
605
|
+
const sep = it.sep;
|
|
606
|
+
sep.push(this.sourceToken);
|
|
607
|
+
// @ts-expect-error type guard is wrong here
|
|
608
|
+
delete it.key, delete it.sep;
|
|
609
|
+
this.stack.push({
|
|
610
|
+
type: 'block-map',
|
|
611
|
+
offset: this.offset,
|
|
612
|
+
indent: this.indent,
|
|
613
|
+
items: [{ start, key, sep }]
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
else if (start.length > 0) {
|
|
617
|
+
// Not actually at next item
|
|
618
|
+
it.sep = it.sep.concat(start, this.sourceToken);
|
|
619
|
+
}
|
|
620
|
+
else {
|
|
621
|
+
it.sep.push(this.sourceToken);
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
else {
|
|
625
|
+
if (!it.sep) {
|
|
626
|
+
Object.assign(it, { key: null, sep: [this.sourceToken] });
|
|
627
|
+
}
|
|
628
|
+
else if (it.value || atNextItem) {
|
|
629
|
+
map.items.push({ start, key: null, sep: [this.sourceToken] });
|
|
630
|
+
}
|
|
631
|
+
else if (includesToken(it.sep, 'map-value-ind')) {
|
|
632
|
+
this.stack.push({
|
|
633
|
+
type: 'block-map',
|
|
634
|
+
offset: this.offset,
|
|
635
|
+
indent: this.indent,
|
|
636
|
+
items: [{ start: [], key: null, sep: [this.sourceToken] }]
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
else {
|
|
640
|
+
it.sep.push(this.sourceToken);
|
|
641
|
+
}
|
|
565
642
|
}
|
|
566
|
-
else
|
|
567
|
-
it.sep.push(this.sourceToken);
|
|
568
643
|
this.onKeyLine = true;
|
|
569
644
|
return;
|
|
570
645
|
case 'alias':
|
|
@@ -573,7 +648,7 @@ class Parser {
|
|
|
573
648
|
case 'double-quoted-scalar': {
|
|
574
649
|
const fs = this.flowScalar(this.type);
|
|
575
650
|
if (atNextItem || it.value) {
|
|
576
|
-
map.items.push({ start
|
|
651
|
+
map.items.push({ start, key: fs, sep: [] });
|
|
577
652
|
this.onKeyLine = true;
|
|
578
653
|
}
|
|
579
654
|
else if (it.sep) {
|
|
@@ -590,8 +665,9 @@ class Parser {
|
|
|
590
665
|
if (bv) {
|
|
591
666
|
if (atNextItem &&
|
|
592
667
|
bv.type !== 'block-seq' &&
|
|
593
|
-
includesToken(it.start, 'explicit-key-ind'))
|
|
594
|
-
map.items.push({ start
|
|
668
|
+
includesToken(it.start, 'explicit-key-ind')) {
|
|
669
|
+
map.items.push({ start });
|
|
670
|
+
}
|
|
595
671
|
this.stack.push(bv);
|
|
596
672
|
return;
|
|
597
673
|
}
|
|
@@ -728,7 +804,7 @@ class Parser {
|
|
|
728
804
|
else {
|
|
729
805
|
const parent = this.peek(2);
|
|
730
806
|
if (parent.type === 'block-map' &&
|
|
731
|
-
(this.type === 'map-value-ind' ||
|
|
807
|
+
((this.type === 'map-value-ind' && parent.indent === fc.indent) ||
|
|
732
808
|
(this.type === 'newline' &&
|
|
733
809
|
!parent.items[parent.items.length - 1].sep))) {
|
|
734
810
|
yield* this.pop();
|
|
@@ -6,10 +6,8 @@ import { LineCounter } from './parse/line-counter.js';
|
|
|
6
6
|
import { Parser } from './parse/parser.js';
|
|
7
7
|
|
|
8
8
|
function parseOptions(options) {
|
|
9
|
-
const prettyErrors =
|
|
10
|
-
const lineCounter =
|
|
11
|
-
(prettyErrors && new LineCounter()) ||
|
|
12
|
-
null;
|
|
9
|
+
const prettyErrors = options.prettyErrors !== false;
|
|
10
|
+
const lineCounter = options.lineCounter || (prettyErrors && new LineCounter()) || null;
|
|
13
11
|
return { lineCounter, prettyErrors };
|
|
14
12
|
}
|
|
15
13
|
/**
|
|
@@ -77,6 +75,7 @@ function parse(src, reviver, options) {
|
|
|
77
75
|
return doc.toJS(Object.assign({ reviver: _reviver }, options));
|
|
78
76
|
}
|
|
79
77
|
function stringify(value, replacer, options) {
|
|
78
|
+
var _a;
|
|
80
79
|
let _replacer = null;
|
|
81
80
|
if (typeof replacer === 'function' || Array.isArray(replacer)) {
|
|
82
81
|
_replacer = replacer;
|
|
@@ -91,7 +90,7 @@ function stringify(value, replacer, options) {
|
|
|
91
90
|
options = indent < 1 ? undefined : indent > 8 ? { indent: 8 } : { indent };
|
|
92
91
|
}
|
|
93
92
|
if (value === undefined) {
|
|
94
|
-
const { keepUndefined } = options
|
|
93
|
+
const { keepUndefined } = (_a = options !== null && options !== void 0 ? options : replacer) !== null && _a !== void 0 ? _a : {};
|
|
95
94
|
if (!keepUndefined)
|
|
96
95
|
return undefined;
|
|
97
96
|
}
|
|
@@ -2,21 +2,31 @@ import { MAP, SCALAR, SEQ } from '../nodes/Node.js';
|
|
|
2
2
|
import { map } from './common/map.js';
|
|
3
3
|
import { seq } from './common/seq.js';
|
|
4
4
|
import { string } from './common/string.js';
|
|
5
|
-
import {
|
|
5
|
+
import { getTags, coreKnownTags } from './tags.js';
|
|
6
6
|
|
|
7
7
|
const sortMapEntriesByKey = (a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0;
|
|
8
8
|
class Schema {
|
|
9
|
-
constructor({ customTags, merge, resolveKnownTags, schema, sortMapEntries }) {
|
|
9
|
+
constructor({ compat, customTags, merge, resolveKnownTags, schema, sortMapEntries, toStringDefaults }) {
|
|
10
|
+
this.compat = Array.isArray(compat)
|
|
11
|
+
? getTags(compat, 'compat')
|
|
12
|
+
: compat
|
|
13
|
+
? getTags(null, compat)
|
|
14
|
+
: null;
|
|
10
15
|
this.merge = !!merge;
|
|
11
|
-
this.name = schema || 'core';
|
|
16
|
+
this.name = (typeof schema === 'string' && schema) || 'core';
|
|
12
17
|
this.knownTags = resolveKnownTags ? coreKnownTags : {};
|
|
13
18
|
this.tags = getTags(customTags, this.name);
|
|
19
|
+
this.toStringOptions = toStringDefaults !== null && toStringDefaults !== void 0 ? toStringDefaults : null;
|
|
14
20
|
Object.defineProperty(this, MAP, { value: map });
|
|
15
21
|
Object.defineProperty(this, SCALAR, { value: string });
|
|
16
22
|
Object.defineProperty(this, SEQ, { value: seq });
|
|
17
23
|
// Used by createMap()
|
|
18
24
|
this.sortMapEntries =
|
|
19
|
-
sortMapEntries ===
|
|
25
|
+
typeof sortMapEntries === 'function'
|
|
26
|
+
? sortMapEntries
|
|
27
|
+
: sortMapEntries === true
|
|
28
|
+
? sortMapEntriesByKey
|
|
29
|
+
: null;
|
|
20
30
|
}
|
|
21
31
|
clone() {
|
|
22
32
|
const copy = Object.create(Schema.prototype, Object.getOwnPropertyDescriptors(this));
|
|
@@ -7,7 +7,9 @@ const nullTag = {
|
|
|
7
7
|
tag: 'tag:yaml.org,2002:null',
|
|
8
8
|
test: /^(?:~|[Nn]ull|NULL)?$/,
|
|
9
9
|
resolve: () => new Scalar(null),
|
|
10
|
-
stringify: ({ source }, ctx) => source && nullTag.test.test(source)
|
|
10
|
+
stringify: ({ source }, ctx) => typeof source === 'string' && nullTag.test.test(source)
|
|
11
|
+
? source
|
|
12
|
+
: ctx.options.nullStr
|
|
11
13
|
};
|
|
12
14
|
|
|
13
15
|
export { nullTag };
|
|
@@ -20,7 +20,10 @@ const floatExp = {
|
|
|
20
20
|
format: 'EXP',
|
|
21
21
|
test: /^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,
|
|
22
22
|
resolve: str => parseFloat(str),
|
|
23
|
-
stringify
|
|
23
|
+
stringify(node) {
|
|
24
|
+
const num = Number(node.value);
|
|
25
|
+
return isFinite(num) ? num.toExponential() : stringifyNumber(node);
|
|
26
|
+
}
|
|
24
27
|
};
|
|
25
28
|
const float = {
|
|
26
29
|
identify: value => typeof value === 'number',
|
|
@@ -14,13 +14,13 @@ import { schema as schema$2 } from './yaml-1.1/schema.js';
|
|
|
14
14
|
import { set } from './yaml-1.1/set.js';
|
|
15
15
|
import { floatTime, intTime, timestamp } from './yaml-1.1/timestamp.js';
|
|
16
16
|
|
|
17
|
-
const schemas =
|
|
18
|
-
core
|
|
19
|
-
failsafe
|
|
20
|
-
json
|
|
21
|
-
yaml11
|
|
22
|
-
'yaml-1.1'
|
|
23
|
-
|
|
17
|
+
const schemas = new Map([
|
|
18
|
+
['core', schema],
|
|
19
|
+
['failsafe', [map, seq, string]],
|
|
20
|
+
['json', schema$1],
|
|
21
|
+
['yaml11', schema$2],
|
|
22
|
+
['yaml-1.1', schema$2]
|
|
23
|
+
]);
|
|
24
24
|
const tagsByName = {
|
|
25
25
|
binary,
|
|
26
26
|
bool: boolTag,
|
|
@@ -48,12 +48,12 @@ const coreKnownTags = {
|
|
|
48
48
|
'tag:yaml.org,2002:timestamp': timestamp
|
|
49
49
|
};
|
|
50
50
|
function getTags(customTags, schemaName) {
|
|
51
|
-
let tags = schemas
|
|
51
|
+
let tags = schemas.get(schemaName);
|
|
52
52
|
if (!tags) {
|
|
53
53
|
if (Array.isArray(customTags))
|
|
54
54
|
tags = [];
|
|
55
55
|
else {
|
|
56
|
-
const keys =
|
|
56
|
+
const keys = Array.from(schemas.keys())
|
|
57
57
|
.filter(key => key !== 'yaml11')
|
|
58
58
|
.map(key => JSON.stringify(key))
|
|
59
59
|
.join(', ');
|
|
@@ -20,7 +20,10 @@ const floatExp = {
|
|
|
20
20
|
format: 'EXP',
|
|
21
21
|
test: /^[-+]?(?:[0-9][0-9_]*)?(?:\.[0-9_]*)?[eE][-+]?[0-9]+$/,
|
|
22
22
|
resolve: (str) => parseFloat(str.replace(/_/g, '')),
|
|
23
|
-
stringify
|
|
23
|
+
stringify(node) {
|
|
24
|
+
const num = Number(node.value);
|
|
25
|
+
return isFinite(num) ? num.toExponential() : stringifyNumber(node);
|
|
26
|
+
}
|
|
24
27
|
};
|
|
25
28
|
const float = {
|
|
26
29
|
identify: value => typeof value === 'number',
|
|
@@ -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 === null || ctx === void 0 ? void 0 : ctx.onCreate)
|
|
26
26
|
ctx.onCreate(map);
|
|
27
27
|
for (const pair of this.items) {
|
|
28
28
|
let key, value;
|
|
@@ -4,6 +4,7 @@ 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;
|
|
7
8
|
if (isSeq(seq)) {
|
|
8
9
|
for (let i = 0; i < seq.items.length; ++i) {
|
|
9
10
|
let item = seq.items[i];
|
|
@@ -18,7 +19,7 @@ function resolvePairs(seq, onError) {
|
|
|
18
19
|
? `${item.commentBefore}\n${pair.key.commentBefore}`
|
|
19
20
|
: item.commentBefore;
|
|
20
21
|
if (item.comment) {
|
|
21
|
-
const cn = pair.value
|
|
22
|
+
const cn = (_a = pair.value) !== null && _a !== void 0 ? _a : pair.key;
|
|
22
23
|
cn.comment = cn.comment
|
|
23
24
|
? `${item.comment}\n${cn.comment}`
|
|
24
25
|
: item.comment;
|