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
package/dist/parse/parser.js
CHANGED
|
@@ -9,7 +9,7 @@ function includesToken(list, type) {
|
|
|
9
9
|
return true;
|
|
10
10
|
return false;
|
|
11
11
|
}
|
|
12
|
-
function
|
|
12
|
+
function findNonEmptyIndex(list) {
|
|
13
13
|
for (let i = 0; i < list.length; ++i) {
|
|
14
14
|
switch (list[i].type) {
|
|
15
15
|
case 'space':
|
|
@@ -17,13 +17,13 @@ function includesNonEmpty(list) {
|
|
|
17
17
|
case 'newline':
|
|
18
18
|
break;
|
|
19
19
|
default:
|
|
20
|
-
return
|
|
20
|
+
return i;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
return
|
|
23
|
+
return -1;
|
|
24
24
|
}
|
|
25
25
|
function isFlowToken(token) {
|
|
26
|
-
switch (token
|
|
26
|
+
switch (token?.type) {
|
|
27
27
|
case 'alias':
|
|
28
28
|
case 'scalar':
|
|
29
29
|
case 'single-quoted-scalar':
|
|
@@ -35,13 +35,12 @@ function isFlowToken(token) {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
function getPrevProps(parent) {
|
|
38
|
-
var _a;
|
|
39
38
|
switch (parent.type) {
|
|
40
39
|
case 'document':
|
|
41
40
|
return parent.start;
|
|
42
41
|
case 'block-map': {
|
|
43
42
|
const it = parent.items[parent.items.length - 1];
|
|
44
|
-
return
|
|
43
|
+
return it.sep ?? it.start;
|
|
45
44
|
}
|
|
46
45
|
case 'block-seq':
|
|
47
46
|
return parent.items[parent.items.length - 1].start;
|
|
@@ -52,7 +51,6 @@ function getPrevProps(parent) {
|
|
|
52
51
|
}
|
|
53
52
|
/** Note: May modify input array */
|
|
54
53
|
function getFirstKeyStartProps(prev) {
|
|
55
|
-
var _a;
|
|
56
54
|
if (prev.length === 0)
|
|
57
55
|
return [];
|
|
58
56
|
let i = prev.length;
|
|
@@ -66,7 +64,7 @@ function getFirstKeyStartProps(prev) {
|
|
|
66
64
|
break loop;
|
|
67
65
|
}
|
|
68
66
|
}
|
|
69
|
-
while (
|
|
67
|
+
while (prev[++i]?.type === 'space') {
|
|
70
68
|
/* loop */
|
|
71
69
|
}
|
|
72
70
|
return prev.splice(i, prev.length);
|
|
@@ -270,7 +268,7 @@ class Parser {
|
|
|
270
268
|
return this.stack[this.stack.length - n];
|
|
271
269
|
}
|
|
272
270
|
*pop(error) {
|
|
273
|
-
const token = error
|
|
271
|
+
const token = error ?? this.stack.pop();
|
|
274
272
|
/* istanbul ignore if should not happen */
|
|
275
273
|
if (!token) {
|
|
276
274
|
const message = 'Tried to pop an empty stack';
|
|
@@ -347,7 +345,7 @@ class Parser {
|
|
|
347
345
|
!last.sep &&
|
|
348
346
|
!last.value &&
|
|
349
347
|
last.start.length > 0 &&
|
|
350
|
-
|
|
348
|
+
findNonEmptyIndex(last.start) === -1 &&
|
|
351
349
|
(token.indent === 0 ||
|
|
352
350
|
last.start.every(st => st.type !== 'comment' || st.indent < token.indent))) {
|
|
353
351
|
if (top.type === 'document')
|
|
@@ -395,7 +393,7 @@ class Parser {
|
|
|
395
393
|
return yield* this.lineEnd(doc);
|
|
396
394
|
switch (this.type) {
|
|
397
395
|
case 'doc-start': {
|
|
398
|
-
if (
|
|
396
|
+
if (findNonEmptyIndex(doc.start) !== -1) {
|
|
399
397
|
yield* this.pop();
|
|
400
398
|
yield* this.step();
|
|
401
399
|
}
|
|
@@ -475,7 +473,6 @@ class Parser {
|
|
|
475
473
|
}
|
|
476
474
|
}
|
|
477
475
|
*blockMap(map) {
|
|
478
|
-
var _a;
|
|
479
476
|
const it = map.items[map.items.length - 1];
|
|
480
477
|
// it.sep is true-ish if pair already has key or : separator
|
|
481
478
|
switch (this.type) {
|
|
@@ -484,26 +481,30 @@ class Parser {
|
|
|
484
481
|
if (it.value) {
|
|
485
482
|
const end = 'end' in it.value ? it.value.end : undefined;
|
|
486
483
|
const last = Array.isArray(end) ? end[end.length - 1] : undefined;
|
|
487
|
-
if (
|
|
488
|
-
end
|
|
484
|
+
if (last?.type === 'comment')
|
|
485
|
+
end?.push(this.sourceToken);
|
|
489
486
|
else
|
|
490
487
|
map.items.push({ start: [this.sourceToken] });
|
|
491
488
|
}
|
|
492
|
-
else if (it.sep)
|
|
489
|
+
else if (it.sep) {
|
|
493
490
|
it.sep.push(this.sourceToken);
|
|
494
|
-
|
|
491
|
+
}
|
|
492
|
+
else {
|
|
495
493
|
it.start.push(this.sourceToken);
|
|
494
|
+
}
|
|
496
495
|
return;
|
|
497
496
|
case 'space':
|
|
498
497
|
case 'comment':
|
|
499
|
-
if (it.value)
|
|
498
|
+
if (it.value) {
|
|
500
499
|
map.items.push({ start: [this.sourceToken] });
|
|
501
|
-
|
|
500
|
+
}
|
|
501
|
+
else if (it.sep) {
|
|
502
502
|
it.sep.push(this.sourceToken);
|
|
503
|
+
}
|
|
503
504
|
else {
|
|
504
505
|
if (this.atIndentedComment(it.start, map.indent)) {
|
|
505
506
|
const prev = map.items[map.items.length - 2];
|
|
506
|
-
const end =
|
|
507
|
+
const end = prev?.value?.end;
|
|
507
508
|
if (Array.isArray(end)) {
|
|
508
509
|
Array.prototype.push.apply(end, it.start);
|
|
509
510
|
end.push(this.sourceToken);
|
|
@@ -516,9 +517,7 @@ class Parser {
|
|
|
516
517
|
return;
|
|
517
518
|
}
|
|
518
519
|
if (this.indent >= map.indent) {
|
|
519
|
-
const atNextItem = !this.onKeyLine &&
|
|
520
|
-
this.indent === map.indent &&
|
|
521
|
-
(it.sep || includesNonEmpty(it.start));
|
|
520
|
+
const atNextItem = !this.onKeyLine && this.indent === map.indent && it.sep;
|
|
522
521
|
// For empty nodes, assign newline-separated not indented empty tokens to following node
|
|
523
522
|
let start = [];
|
|
524
523
|
if (atNextItem && it.sep && !it.value) {
|
|
@@ -682,15 +681,14 @@ class Parser {
|
|
|
682
681
|
yield* this.step();
|
|
683
682
|
}
|
|
684
683
|
*blockSequence(seq) {
|
|
685
|
-
var _a;
|
|
686
684
|
const it = seq.items[seq.items.length - 1];
|
|
687
685
|
switch (this.type) {
|
|
688
686
|
case 'newline':
|
|
689
687
|
if (it.value) {
|
|
690
688
|
const end = 'end' in it.value ? it.value.end : undefined;
|
|
691
689
|
const last = Array.isArray(end) ? end[end.length - 1] : undefined;
|
|
692
|
-
if (
|
|
693
|
-
end
|
|
690
|
+
if (last?.type === 'comment')
|
|
691
|
+
end?.push(this.sourceToken);
|
|
694
692
|
else
|
|
695
693
|
seq.items.push({ start: [this.sourceToken] });
|
|
696
694
|
}
|
|
@@ -704,7 +702,7 @@ class Parser {
|
|
|
704
702
|
else {
|
|
705
703
|
if (this.atIndentedComment(it.start, seq.indent)) {
|
|
706
704
|
const prev = seq.items[seq.items.length - 2];
|
|
707
|
-
const end =
|
|
705
|
+
const end = prev?.value?.end;
|
|
708
706
|
if (Array.isArray(end)) {
|
|
709
707
|
Array.prototype.push.apply(end, it.start);
|
|
710
708
|
end.push(this.sourceToken);
|
package/dist/public-api.js
CHANGED
|
@@ -23,7 +23,7 @@ function parseOptions(options) {
|
|
|
23
23
|
*/
|
|
24
24
|
function parseAllDocuments(source, options = {}) {
|
|
25
25
|
const { lineCounter, prettyErrors } = parseOptions(options);
|
|
26
|
-
const parser$1 = new parser.Parser(lineCounter
|
|
26
|
+
const parser$1 = new parser.Parser(lineCounter?.addNewLine);
|
|
27
27
|
const composer$1 = new composer.Composer(options);
|
|
28
28
|
const docs = Array.from(composer$1.compose(parser$1.parse(source)));
|
|
29
29
|
if (prettyErrors && lineCounter)
|
|
@@ -38,7 +38,7 @@ function parseAllDocuments(source, options = {}) {
|
|
|
38
38
|
/** Parse an input string into a single YAML.Document */
|
|
39
39
|
function parseDocument(source, options = {}) {
|
|
40
40
|
const { lineCounter, prettyErrors } = parseOptions(options);
|
|
41
|
-
const parser$1 = new parser.Parser(lineCounter
|
|
41
|
+
const parser$1 = new parser.Parser(lineCounter?.addNewLine);
|
|
42
42
|
const composer$1 = new composer.Composer(options);
|
|
43
43
|
// `doc` is always set by compose.end(true) at the very latest
|
|
44
44
|
let doc = null;
|
|
@@ -77,7 +77,6 @@ function parse(src, reviver, options) {
|
|
|
77
77
|
return doc.toJS(Object.assign({ reviver: _reviver }, options));
|
|
78
78
|
}
|
|
79
79
|
function stringify(value, replacer, options) {
|
|
80
|
-
var _a;
|
|
81
80
|
let _replacer = null;
|
|
82
81
|
if (typeof replacer === 'function' || Array.isArray(replacer)) {
|
|
83
82
|
_replacer = replacer;
|
|
@@ -92,7 +91,7 @@ function stringify(value, replacer, options) {
|
|
|
92
91
|
options = indent < 1 ? undefined : indent > 8 ? { indent: 8 } : { indent };
|
|
93
92
|
}
|
|
94
93
|
if (value === undefined) {
|
|
95
|
-
const { keepUndefined } =
|
|
94
|
+
const { keepUndefined } = options ?? replacer ?? {};
|
|
96
95
|
if (!keepUndefined)
|
|
97
96
|
return undefined;
|
|
98
97
|
}
|
package/dist/schema/Schema.d.ts
CHANGED
|
@@ -10,9 +10,9 @@ export declare class Schema {
|
|
|
10
10
|
sortMapEntries: ((a: Pair, b: Pair) => number) | null;
|
|
11
11
|
tags: Array<CollectionTag | ScalarTag>;
|
|
12
12
|
toStringOptions: Readonly<ToStringOptions> | null;
|
|
13
|
-
[MAP]: CollectionTag;
|
|
14
|
-
[SCALAR]: ScalarTag;
|
|
15
|
-
[SEQ]: CollectionTag;
|
|
13
|
+
readonly [MAP]: CollectionTag;
|
|
14
|
+
readonly [SCALAR]: ScalarTag;
|
|
15
|
+
readonly [SEQ]: CollectionTag;
|
|
16
16
|
constructor({ compat, customTags, merge, resolveKnownTags, schema, sortMapEntries, toStringDefaults }: SchemaOptions);
|
|
17
17
|
clone(): Schema;
|
|
18
18
|
}
|
package/dist/schema/Schema.js
CHANGED
|
@@ -18,7 +18,7 @@ class Schema {
|
|
|
18
18
|
this.name = (typeof schema === 'string' && schema) || 'core';
|
|
19
19
|
this.knownTags = resolveKnownTags ? tags.coreKnownTags : {};
|
|
20
20
|
this.tags = tags.getTags(customTags, this.name);
|
|
21
|
-
this.toStringOptions = toStringDefaults
|
|
21
|
+
this.toStringOptions = toStringDefaults ?? null;
|
|
22
22
|
Object.defineProperty(this, Node.MAP, { value: map.map });
|
|
23
23
|
Object.defineProperty(this, Node.SCALAR, { value: string.string });
|
|
24
24
|
Object.defineProperty(this, Node.SEQ, { value: seq.seq });
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
declare type JsonSchema = boolean | ArraySchema | ObjectSchema | NumberSchema | StringSchema;
|
|
2
|
+
declare type JsonType = 'array' | 'object' | 'string' | 'number' | 'integer' | 'boolean' | 'null';
|
|
3
|
+
interface CommonSchema {
|
|
4
|
+
type?: JsonType | JsonType[];
|
|
5
|
+
const?: unknown;
|
|
6
|
+
enum?: unknown[];
|
|
7
|
+
format?: string;
|
|
8
|
+
allOf?: JsonSchema[];
|
|
9
|
+
anyOf?: JsonSchema[];
|
|
10
|
+
oneOf?: JsonSchema[];
|
|
11
|
+
not?: JsonSchema;
|
|
12
|
+
if?: JsonSchema;
|
|
13
|
+
then?: JsonSchema;
|
|
14
|
+
else?: JsonSchema;
|
|
15
|
+
$id?: string;
|
|
16
|
+
$defs?: Record<string, JsonSchema>;
|
|
17
|
+
$anchor?: string;
|
|
18
|
+
$dynamicAnchor?: string;
|
|
19
|
+
$ref?: string;
|
|
20
|
+
$dynamicRef?: string;
|
|
21
|
+
$schema?: string;
|
|
22
|
+
$vocabulary?: Record<string, boolean>;
|
|
23
|
+
$comment?: string;
|
|
24
|
+
default?: unknown;
|
|
25
|
+
deprecated?: boolean;
|
|
26
|
+
readOnly?: boolean;
|
|
27
|
+
writeOnly?: boolean;
|
|
28
|
+
title?: string;
|
|
29
|
+
description?: string;
|
|
30
|
+
examples?: unknown[];
|
|
31
|
+
}
|
|
32
|
+
interface ArraySchema extends CommonSchema {
|
|
33
|
+
prefixItems?: JsonSchema[];
|
|
34
|
+
items?: JsonSchema;
|
|
35
|
+
contains?: JsonSchema;
|
|
36
|
+
unevaluatedItems?: JsonSchema;
|
|
37
|
+
maxItems?: number;
|
|
38
|
+
minItems?: number;
|
|
39
|
+
uniqueItems?: boolean;
|
|
40
|
+
maxContains?: number;
|
|
41
|
+
minContains?: number;
|
|
42
|
+
}
|
|
43
|
+
interface ObjectSchema extends CommonSchema {
|
|
44
|
+
properties?: Record<string, JsonSchema>;
|
|
45
|
+
patternProperties?: Record<string, JsonSchema>;
|
|
46
|
+
additionalProperties?: JsonSchema;
|
|
47
|
+
propertyNames?: JsonSchema;
|
|
48
|
+
unevaluatedProperties?: JsonSchema;
|
|
49
|
+
maxProperties?: number;
|
|
50
|
+
minProperties?: number;
|
|
51
|
+
required?: string[];
|
|
52
|
+
dependentRequired?: Record<string, string[]>;
|
|
53
|
+
dependentSchemas?: Record<string, JsonSchema>;
|
|
54
|
+
}
|
|
55
|
+
interface StringSchema extends CommonSchema {
|
|
56
|
+
maxLength?: number;
|
|
57
|
+
minLength?: number;
|
|
58
|
+
patter?: string;
|
|
59
|
+
contentEncoding?: string;
|
|
60
|
+
contentMediaType?: string;
|
|
61
|
+
contentSchema?: JsonSchema;
|
|
62
|
+
}
|
|
63
|
+
interface NumberSchema extends CommonSchema {
|
|
64
|
+
multipleOf?: number;
|
|
65
|
+
maximum?: number;
|
|
66
|
+
exclusiveMaximum?: number;
|
|
67
|
+
minimum?: number;
|
|
68
|
+
exclusiveMinimum?: number;
|
|
69
|
+
}
|
|
@@ -8,9 +8,13 @@ export declare class YAMLOMap extends YAMLSeq {
|
|
|
8
8
|
key: any;
|
|
9
9
|
value: any;
|
|
10
10
|
}, overwrite?: boolean | undefined) => void;
|
|
11
|
-
delete: (key:
|
|
12
|
-
get:
|
|
13
|
-
|
|
11
|
+
delete: (key: unknown) => boolean;
|
|
12
|
+
get: {
|
|
13
|
+
(key: unknown, keepScalar: true): import("../../index.js").Scalar<any> | undefined;
|
|
14
|
+
(key: unknown, keepScalar?: false | undefined): any;
|
|
15
|
+
(key: unknown, keepScalar?: boolean | undefined): any;
|
|
16
|
+
};
|
|
17
|
+
has: (key: unknown) => boolean;
|
|
14
18
|
set: (key: any, value: any) => void;
|
|
15
19
|
/**
|
|
16
20
|
* If `ctx` is given, the return type is actually `Map<unknown, unknown>`,
|
|
@@ -24,7 +24,7 @@ class YAMLOMap extends YAMLSeq.YAMLSeq {
|
|
|
24
24
|
if (!ctx)
|
|
25
25
|
return super.toJSON(_);
|
|
26
26
|
const map = new Map();
|
|
27
|
-
if (ctx
|
|
27
|
+
if (ctx?.onCreate)
|
|
28
28
|
ctx.onCreate(map);
|
|
29
29
|
for (const pair of this.items) {
|
|
30
30
|
let key, value;
|
|
@@ -6,7 +6,6 @@ var Scalar = require('../../nodes/Scalar.js');
|
|
|
6
6
|
var YAMLSeq = require('../../nodes/YAMLSeq.js');
|
|
7
7
|
|
|
8
8
|
function resolvePairs(seq, onError) {
|
|
9
|
-
var _a;
|
|
10
9
|
if (Node.isSeq(seq)) {
|
|
11
10
|
for (let i = 0; i < seq.items.length; ++i) {
|
|
12
11
|
let item = seq.items[i];
|
|
@@ -21,7 +20,7 @@ function resolvePairs(seq, onError) {
|
|
|
21
20
|
? `${item.commentBefore}\n${pair.key.commentBefore}`
|
|
22
21
|
: item.commentBefore;
|
|
23
22
|
if (item.comment) {
|
|
24
|
-
const cn =
|
|
23
|
+
const cn = pair.value ?? pair.key;
|
|
25
24
|
cn.comment = cn.comment
|
|
26
25
|
? `${item.comment}\n${cn.comment}`
|
|
27
26
|
: item.comment;
|
|
@@ -12,9 +12,13 @@ export declare class YAMLSet<T = unknown> extends YAMLMap<T, Scalar<null> | null
|
|
|
12
12
|
key: T;
|
|
13
13
|
value: Scalar<null> | null;
|
|
14
14
|
}): void;
|
|
15
|
-
|
|
15
|
+
/**
|
|
16
|
+
* If `keepPair` is `true`, returns the Pair matching `key`.
|
|
17
|
+
* Otherwise, returns the value of that Pair's key.
|
|
18
|
+
*/
|
|
19
|
+
get(key: unknown, keepPair?: boolean): any;
|
|
16
20
|
set(key: T, value: boolean): void;
|
|
17
|
-
/** Will throw; `value` must be boolean */
|
|
21
|
+
/** @deprecated Will throw; `value` must be boolean */
|
|
18
22
|
set(key: T, value: null): void;
|
|
19
23
|
toJSON(_?: unknown, ctx?: ToJSContext): any;
|
|
20
24
|
toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
|
|
@@ -24,6 +24,10 @@ class YAMLSet extends YAMLMap.YAMLMap {
|
|
|
24
24
|
if (!prev)
|
|
25
25
|
this.items.push(pair);
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* If `keepPair` is `true`, returns the Pair matching `key`.
|
|
29
|
+
* Otherwise, returns the value of that Pair's key.
|
|
30
|
+
*/
|
|
27
31
|
get(key, keepPair) {
|
|
28
32
|
const pair = YAMLMap.findPair(this.items, key);
|
|
29
33
|
return !keepPair && Node.isPair(pair)
|
|
@@ -45,26 +45,25 @@ function createStringifyContext(doc, options) {
|
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
function getTagObject(tags, item) {
|
|
48
|
-
var _a, _b, _c, _d;
|
|
49
48
|
if (item.tag) {
|
|
50
49
|
const match = tags.filter(t => t.tag === item.tag);
|
|
51
50
|
if (match.length > 0)
|
|
52
|
-
return
|
|
51
|
+
return match.find(t => t.format === item.format) ?? match[0];
|
|
53
52
|
}
|
|
54
53
|
let tagObj = undefined;
|
|
55
54
|
let obj;
|
|
56
55
|
if (Node.isScalar(item)) {
|
|
57
56
|
obj = item.value;
|
|
58
|
-
const match = tags.filter(t =>
|
|
57
|
+
const match = tags.filter(t => t.identify?.(obj));
|
|
59
58
|
tagObj =
|
|
60
|
-
|
|
59
|
+
match.find(t => t.format === item.format) ?? match.find(t => !t.format);
|
|
61
60
|
}
|
|
62
61
|
else {
|
|
63
62
|
obj = item;
|
|
64
63
|
tagObj = tags.find(t => t.nodeClass && obj instanceof t.nodeClass);
|
|
65
64
|
}
|
|
66
65
|
if (!tagObj) {
|
|
67
|
-
const name =
|
|
66
|
+
const name = obj?.constructor?.name ?? typeof obj;
|
|
68
67
|
throw new Error(`Tag not resolved for ${name} value`);
|
|
69
68
|
}
|
|
70
69
|
return tagObj;
|
|
@@ -85,13 +84,12 @@ function stringifyProps(node, tagObj, { anchors: anchors$1, doc }) {
|
|
|
85
84
|
return props.join(' ');
|
|
86
85
|
}
|
|
87
86
|
function stringify(item, ctx, onComment, onChompKeep) {
|
|
88
|
-
var _a, _b;
|
|
89
87
|
if (Node.isPair(item))
|
|
90
88
|
return item.toString(ctx, onComment, onChompKeep);
|
|
91
89
|
if (Node.isAlias(item)) {
|
|
92
90
|
if (ctx.doc.directives)
|
|
93
91
|
return item.toString(ctx);
|
|
94
|
-
if (
|
|
92
|
+
if (ctx.resolvedAliases?.has(item)) {
|
|
95
93
|
throw new TypeError(`Cannot stringify circular structure without alias nodes`);
|
|
96
94
|
}
|
|
97
95
|
else {
|
|
@@ -110,7 +108,7 @@ function stringify(item, ctx, onComment, onChompKeep) {
|
|
|
110
108
|
tagObj = getTagObject(ctx.doc.schema.tags, node);
|
|
111
109
|
const props = stringifyProps(node, tagObj, ctx);
|
|
112
110
|
if (props.length > 0)
|
|
113
|
-
ctx.indentAtStart = (
|
|
111
|
+
ctx.indentAtStart = (ctx.indentAtStart ?? 0) + props.length + 1;
|
|
114
112
|
const str = typeof tagObj.stringify === 'function'
|
|
115
113
|
? tagObj.stringify(node, ctx, onComment, onChompKeep)
|
|
116
114
|
: Node.isScalar(node)
|
|
@@ -6,8 +6,7 @@ var stringify = require('./stringify.js');
|
|
|
6
6
|
var stringifyComment = require('./stringifyComment.js');
|
|
7
7
|
|
|
8
8
|
function stringifyCollection(collection, ctx, options) {
|
|
9
|
-
|
|
10
|
-
const flow = (_a = ctx.inFlow) !== null && _a !== void 0 ? _a : collection.flow;
|
|
9
|
+
const flow = ctx.inFlow ?? collection.flow;
|
|
11
10
|
const stringify = flow ? stringifyFlowCollection : stringifyBlockCollection;
|
|
12
11
|
return stringify(collection, ctx, options);
|
|
13
12
|
}
|
|
@@ -5,7 +5,6 @@ var stringify = require('./stringify.js');
|
|
|
5
5
|
var stringifyComment = require('./stringifyComment.js');
|
|
6
6
|
|
|
7
7
|
function stringifyDocument(doc, options) {
|
|
8
|
-
var _a;
|
|
9
8
|
const lines = [];
|
|
10
9
|
let hasDirectives = options.directives === true;
|
|
11
10
|
if (options.directives !== false && doc.directives) {
|
|
@@ -57,7 +56,7 @@ function stringifyDocument(doc, options) {
|
|
|
57
56
|
else {
|
|
58
57
|
lines.push(stringify.stringify(doc.contents, ctx));
|
|
59
58
|
}
|
|
60
|
-
if (
|
|
59
|
+
if (doc.directives?.docEnd) {
|
|
61
60
|
if (doc.comment) {
|
|
62
61
|
const cs = commentString(doc.comment);
|
|
63
62
|
if (cs.includes('\n')) {
|
|
@@ -265,9 +265,9 @@ function plainString(item, ctx, onComment, onChompKeep) {
|
|
|
265
265
|
// booleans get parsed with those types in v1.2 (e.g. '42', 'true' & '0.9e-3'),
|
|
266
266
|
// and others in v1.1.
|
|
267
267
|
if (actualString) {
|
|
268
|
-
const test = (tag) =>
|
|
268
|
+
const test = (tag) => tag.default && tag.tag !== 'tag:yaml.org,2002:str' && tag.test?.test(str);
|
|
269
269
|
const { compat, tags } = ctx.doc.schema;
|
|
270
|
-
if (tags.some(test) ||
|
|
270
|
+
if (tags.some(test) || compat?.some(test))
|
|
271
271
|
return quotedString(value, ctx);
|
|
272
272
|
}
|
|
273
273
|
return implicitKey
|
package/dist/test-events.js
CHANGED
|
@@ -25,7 +25,6 @@ function anchorExists(doc, anchor) {
|
|
|
25
25
|
}
|
|
26
26
|
// test harness for yaml-test-suite event tests
|
|
27
27
|
function testEvents(src) {
|
|
28
|
-
var _a;
|
|
29
28
|
const docs = publicApi.parseAllDocuments(src);
|
|
30
29
|
const errDoc = docs.find(doc => doc.errors.length > 0);
|
|
31
30
|
const error = errDoc ? errDoc.errors[0].message : null;
|
|
@@ -49,7 +48,7 @@ function testEvents(src) {
|
|
|
49
48
|
!doc.contents.tag)
|
|
50
49
|
continue;
|
|
51
50
|
events.push(docStart);
|
|
52
|
-
addEvents(events, doc,
|
|
51
|
+
addEvents(events, doc, error?.pos[0] ?? -1, root);
|
|
53
52
|
let docEnd = '-DOC';
|
|
54
53
|
if (doc.directives.docEnd)
|
|
55
54
|
docEnd += ' ...';
|
|
@@ -57,7 +56,7 @@ function testEvents(src) {
|
|
|
57
56
|
}
|
|
58
57
|
}
|
|
59
58
|
catch (e) {
|
|
60
|
-
return { events, error: error
|
|
59
|
+
return { events, error: error ?? e };
|
|
61
60
|
}
|
|
62
61
|
events.push('-STR');
|
|
63
62
|
return { events, error };
|
package/dist/visit.js
CHANGED
|
@@ -198,19 +198,18 @@ function initVisitor(visitor) {
|
|
|
198
198
|
return visitor;
|
|
199
199
|
}
|
|
200
200
|
function callVisitor(key, node, visitor, path) {
|
|
201
|
-
var _a, _b, _c, _d, _e;
|
|
202
201
|
if (typeof visitor === 'function')
|
|
203
202
|
return visitor(key, node, path);
|
|
204
203
|
if (Node.isMap(node))
|
|
205
|
-
return
|
|
204
|
+
return visitor.Map?.(key, node, path);
|
|
206
205
|
if (Node.isSeq(node))
|
|
207
|
-
return
|
|
206
|
+
return visitor.Seq?.(key, node, path);
|
|
208
207
|
if (Node.isPair(node))
|
|
209
|
-
return
|
|
208
|
+
return visitor.Pair?.(key, node, path);
|
|
210
209
|
if (Node.isScalar(node))
|
|
211
|
-
return
|
|
210
|
+
return visitor.Scalar?.(key, node, path);
|
|
212
211
|
if (Node.isAlias(node))
|
|
213
|
-
return
|
|
212
|
+
return visitor.Alias?.(key, node, path);
|
|
214
213
|
return undefined;
|
|
215
214
|
}
|
|
216
215
|
function replaceNode(key, path, node) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yaml",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"author": "Eemeli Aro <eemeli@gmail.com>",
|
|
6
6
|
"repository": "github:eemeli/yaml",
|
|
@@ -76,12 +76,12 @@
|
|
|
76
76
|
"@types/node": "^12.20.47",
|
|
77
77
|
"@typescript-eslint/eslint-plugin": "^5.3.1",
|
|
78
78
|
"@typescript-eslint/parser": "^5.3.1",
|
|
79
|
-
"babel-jest": "^
|
|
79
|
+
"babel-jest": "^28.1.0",
|
|
80
80
|
"cross-env": "^7.0.3",
|
|
81
81
|
"eslint": "^8.2.0",
|
|
82
82
|
"eslint-config-prettier": "^8.1.0",
|
|
83
83
|
"fast-check": "^2.12.0",
|
|
84
|
-
"jest": "^
|
|
84
|
+
"jest": "^28.1.0",
|
|
85
85
|
"jest-ts-webcompat-resolver": "^1.0.0",
|
|
86
86
|
"prettier": "^2.2.1",
|
|
87
87
|
"rollup": "^2.38.2",
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/*! *****************************************************************************
|
|
4
|
-
Copyright (c) Microsoft Corporation.
|
|
5
|
-
|
|
6
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
7
|
-
purpose with or without fee is hereby granted.
|
|
8
|
-
|
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
-
***************************************************************************** */
|
|
17
|
-
/* global Reflect, Promise */
|
|
18
|
-
|
|
19
|
-
var extendStatics = function(d, b) {
|
|
20
|
-
extendStatics = Object.setPrototypeOf ||
|
|
21
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
22
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
23
|
-
return extendStatics(d, b);
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
function __extends(d, b) {
|
|
27
|
-
if (typeof b !== "function" && b !== null)
|
|
28
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
29
|
-
extendStatics(d, b);
|
|
30
|
-
function __() { this.constructor = d; }
|
|
31
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function __generator(thisArg, body) {
|
|
35
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
36
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
37
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
38
|
-
function step(op) {
|
|
39
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
40
|
-
while (_) try {
|
|
41
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
42
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
43
|
-
switch (op[0]) {
|
|
44
|
-
case 0: case 1: t = op; break;
|
|
45
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
46
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
47
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
48
|
-
default:
|
|
49
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
50
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
51
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
52
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
53
|
-
if (t[2]) _.ops.pop();
|
|
54
|
-
_.trys.pop(); continue;
|
|
55
|
-
}
|
|
56
|
-
op = body.call(thisArg, _);
|
|
57
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
58
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function __values(o) {
|
|
63
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
64
|
-
if (m) return m.call(o);
|
|
65
|
-
if (o && typeof o.length === "number") return {
|
|
66
|
-
next: function () {
|
|
67
|
-
if (o && i >= o.length) o = void 0;
|
|
68
|
-
return { value: o && o[i++], done: !o };
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
exports.__extends = __extends;
|
|
75
|
-
exports.__generator = __generator;
|
|
76
|
-
exports.__values = __values;
|