yaml 2.0.0-10 → 2.0.0-5
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-doc.js +1 -2
- package/browser/dist/compose/compose-node.js +1 -10
- package/browser/dist/compose/compose-scalar.js +10 -17
- package/browser/dist/compose/composer.js +2 -3
- package/browser/dist/compose/resolve-block-map.js +5 -22
- package/browser/dist/compose/resolve-block-scalar.js +2 -2
- package/browser/dist/compose/resolve-block-seq.js +1 -6
- package/browser/dist/compose/resolve-end.js +2 -2
- package/browser/dist/compose/resolve-flow-collection.js +8 -24
- package/browser/dist/compose/resolve-flow-scalar.js +7 -19
- package/browser/dist/compose/resolve-props.js +7 -32
- package/browser/dist/doc/Document.js +12 -58
- package/browser/dist/doc/createNode.js +5 -11
- package/browser/dist/doc/directives.js +0 -5
- package/browser/dist/nodes/Collection.js +15 -28
- package/browser/dist/nodes/Node.js +0 -7
- package/browser/dist/nodes/Pair.js +1 -9
- package/browser/dist/nodes/YAMLMap.js +1 -1
- package/browser/dist/nodes/YAMLSeq.js +1 -1
- package/browser/dist/nodes/addPairToJSMap.js +3 -4
- package/browser/dist/options.js +0 -2
- package/browser/dist/parse/cst-scalar.js +6 -2
- package/browser/dist/parse/lexer.js +31 -67
- package/browser/dist/parse/parser.js +55 -62
- package/browser/dist/public-api.js +4 -2
- package/browser/dist/schema/Schema.js +3 -14
- package/browser/dist/schema/core/float.js +1 -4
- package/browser/dist/schema/tags.js +13 -17
- package/browser/dist/schema/yaml-1.1/float.js +1 -4
- package/browser/dist/stringify/addComment.js +11 -0
- package/browser/dist/stringify/stringify.js +17 -47
- package/browser/dist/stringify/stringifyCollection.js +72 -116
- package/browser/dist/stringify/stringifyDocument.js +9 -16
- package/browser/dist/stringify/stringifyPair.js +20 -29
- package/browser/dist/stringify/stringifyString.js +41 -39
- package/browser/dist/util.js +0 -3
- package/dist/compose/compose-doc.js +1 -2
- package/dist/compose/compose-node.d.ts +0 -1
- package/dist/compose/compose-node.js +1 -10
- package/dist/compose/compose-scalar.js +9 -16
- package/dist/compose/composer.js +2 -3
- package/dist/compose/resolve-block-map.d.ts +1 -2
- package/dist/compose/resolve-block-map.js +5 -22
- package/dist/compose/resolve-block-scalar.js +2 -2
- package/dist/compose/resolve-block-seq.js +1 -6
- package/dist/compose/resolve-end.js +2 -2
- package/dist/compose/resolve-flow-collection.js +8 -24
- package/dist/compose/resolve-flow-scalar.js +7 -19
- package/dist/compose/resolve-props.d.ts +4 -3
- package/dist/compose/resolve-props.js +7 -32
- package/dist/doc/Document.d.ts +5 -16
- package/dist/doc/Document.js +11 -57
- package/dist/doc/createNode.d.ts +1 -2
- package/dist/doc/createNode.js +4 -10
- package/dist/doc/directives.d.ts +0 -1
- package/dist/doc/directives.js +0 -5
- package/dist/errors.d.ts +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/nodes/Alias.d.ts +3 -7
- package/dist/nodes/Collection.d.ts +4 -10
- package/dist/nodes/Collection.js +14 -27
- package/dist/nodes/Node.d.ts +3 -10
- package/dist/nodes/Node.js +0 -7
- package/dist/nodes/Pair.d.ts +2 -7
- package/dist/nodes/Pair.js +0 -8
- package/dist/nodes/Scalar.d.ts +0 -2
- package/dist/nodes/YAMLMap.d.ts +0 -2
- package/dist/nodes/YAMLMap.js +1 -1
- package/dist/nodes/YAMLSeq.d.ts +0 -2
- package/dist/nodes/YAMLSeq.js +1 -1
- package/dist/nodes/addPairToJSMap.js +2 -3
- package/dist/options.d.ts +6 -81
- package/dist/options.js +0 -2
- package/dist/parse/cst-scalar.d.ts +0 -6
- package/dist/parse/cst-scalar.js +6 -2
- package/dist/parse/lexer.d.ts +1 -3
- package/dist/parse/lexer.js +31 -67
- package/dist/parse/parser.d.ts +0 -1
- package/dist/parse/parser.js +55 -62
- package/dist/public-api.js +4 -2
- package/dist/schema/Schema.d.ts +4 -6
- package/dist/schema/Schema.js +2 -13
- package/dist/schema/core/float.js +1 -4
- package/dist/schema/tags.d.ts +2 -1
- package/dist/schema/tags.js +13 -17
- package/dist/schema/yaml-1.1/float.js +1 -4
- package/dist/stringify/addComment.d.ts +2 -0
- package/dist/stringify/addComment.js +13 -0
- package/dist/stringify/stringify.d.ts +3 -5
- package/dist/stringify/stringify.js +17 -47
- package/dist/stringify/stringifyCollection.d.ts +7 -3
- package/dist/stringify/stringifyCollection.js +72 -116
- package/dist/stringify/stringifyDocument.js +9 -16
- package/dist/stringify/stringifyPair.js +20 -29
- package/dist/stringify/stringifyString.js +41 -39
- package/dist/test-events.d.ts +1 -1
- package/dist/test-events.js +2 -4
- package/dist/util.d.ts +0 -3
- package/dist/util.js +0 -6
- package/package.json +12 -14
- package/browser/dist/compose/util-flow-indent-check.js +0 -15
- package/browser/dist/compose/util-map-includes.js +0 -17
- package/browser/dist/node_modules/tslib/tslib.es6.js +0 -164
- package/browser/dist/stringify/stringifyComment.js +0 -18
- package/dist/compose/util-flow-indent-check.d.ts +0 -3
- package/dist/compose/util-flow-indent-check.js +0 -17
- package/dist/compose/util-map-includes.d.ts +0 -4
- package/dist/compose/util-map-includes.js +0 -19
- package/dist/node_modules/tslib/tslib.es6.js +0 -76
- package/dist/stringify/stringifyComment.d.ts +0 -10
- package/dist/stringify/stringifyComment.js +0 -22
- package/util.d.ts +0 -3
|
@@ -1,26 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
function resolveProps(tokens, { flow, indicator,
|
|
3
|
+
function resolveProps(tokens, { ctx, flow, indicator, offset, onError, startOnNewline }) {
|
|
4
4
|
let spaceBefore = false;
|
|
5
5
|
let atNewline = startOnNewline;
|
|
6
6
|
let hasSpace = startOnNewline;
|
|
7
7
|
let comment = '';
|
|
8
8
|
let commentSep = '';
|
|
9
9
|
let hasNewline = false;
|
|
10
|
-
let reqSpace = false;
|
|
11
10
|
let anchor = null;
|
|
12
11
|
let tag = null;
|
|
13
12
|
let comma = null;
|
|
14
13
|
let found = null;
|
|
15
14
|
let start = null;
|
|
16
15
|
for (const token of tokens) {
|
|
17
|
-
if (reqSpace) {
|
|
18
|
-
if (token.type !== 'space' &&
|
|
19
|
-
token.type !== 'newline' &&
|
|
20
|
-
token.type !== 'comma')
|
|
21
|
-
onError(token.offset, 'MISSING_CHAR', 'Tags and anchors must be separated from the next token by white space');
|
|
22
|
-
reqSpace = false;
|
|
23
|
-
}
|
|
24
16
|
switch (token.type) {
|
|
25
17
|
case 'space':
|
|
26
18
|
// At the doc level, tabs at line start may be parsed
|
|
@@ -34,29 +26,23 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
|
|
|
34
26
|
hasSpace = true;
|
|
35
27
|
break;
|
|
36
28
|
case 'comment': {
|
|
37
|
-
if (!hasSpace)
|
|
38
|
-
onError(token, '
|
|
39
|
-
const cb = token.source.substring(1)
|
|
29
|
+
if (ctx.options.strict && !hasSpace)
|
|
30
|
+
onError(token, 'COMMENT_SPACE', 'Comments must be separated from other tokens by white space characters');
|
|
31
|
+
const cb = token.source.substring(1);
|
|
40
32
|
if (!comment)
|
|
41
33
|
comment = cb;
|
|
42
34
|
else
|
|
43
35
|
comment += commentSep + cb;
|
|
44
36
|
commentSep = '';
|
|
45
|
-
atNewline = false;
|
|
46
37
|
break;
|
|
47
38
|
}
|
|
48
39
|
case 'newline':
|
|
49
|
-
if (atNewline)
|
|
50
|
-
|
|
51
|
-
comment += token.source;
|
|
52
|
-
else
|
|
53
|
-
spaceBefore = true;
|
|
54
|
-
}
|
|
55
|
-
else
|
|
56
|
-
commentSep += token.source;
|
|
40
|
+
if (atNewline && !comment)
|
|
41
|
+
spaceBefore = true;
|
|
57
42
|
atNewline = true;
|
|
58
43
|
hasNewline = true;
|
|
59
44
|
hasSpace = true;
|
|
45
|
+
commentSep += token.source;
|
|
60
46
|
break;
|
|
61
47
|
case 'anchor':
|
|
62
48
|
if (anchor)
|
|
@@ -66,7 +52,6 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
|
|
|
66
52
|
start = token.offset;
|
|
67
53
|
atNewline = false;
|
|
68
54
|
hasSpace = false;
|
|
69
|
-
reqSpace = true;
|
|
70
55
|
break;
|
|
71
56
|
case 'tag': {
|
|
72
57
|
if (tag)
|
|
@@ -76,15 +61,12 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
|
|
|
76
61
|
start = token.offset;
|
|
77
62
|
atNewline = false;
|
|
78
63
|
hasSpace = false;
|
|
79
|
-
reqSpace = true;
|
|
80
64
|
break;
|
|
81
65
|
}
|
|
82
66
|
case indicator:
|
|
83
67
|
// Could here handle preceding comments differently
|
|
84
68
|
if (anchor || tag)
|
|
85
69
|
onError(token, 'BAD_PROP_ORDER', `Anchors and tags must be after the ${token.source} indicator`);
|
|
86
|
-
if (found)
|
|
87
|
-
onError(token, 'UNEXPECTED_TOKEN', `Unexpected ${token.source} in ${flow || 'collection'}`);
|
|
88
70
|
found = token;
|
|
89
71
|
atNewline = false;
|
|
90
72
|
hasSpace = false;
|
|
@@ -107,13 +89,6 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
|
|
|
107
89
|
}
|
|
108
90
|
const last = tokens[tokens.length - 1];
|
|
109
91
|
const end = last ? last.offset + last.source.length : offset;
|
|
110
|
-
if (reqSpace &&
|
|
111
|
-
next &&
|
|
112
|
-
next.type !== 'space' &&
|
|
113
|
-
next.type !== 'newline' &&
|
|
114
|
-
next.type !== 'comma' &&
|
|
115
|
-
(next.type !== 'scalar' || next.source !== ''))
|
|
116
|
-
onError(next.offset, 'MISSING_CHAR', 'Tags and anchors must be separated from the next token by white space');
|
|
117
92
|
return {
|
|
118
93
|
comma,
|
|
119
94
|
found,
|
package/dist/doc/Document.d.ts
CHANGED
|
@@ -11,7 +11,6 @@ import { Directives } from './directives.js';
|
|
|
11
11
|
export declare type Replacer = any[] | ((key: any, value: any) => unknown);
|
|
12
12
|
export declare namespace Document {
|
|
13
13
|
interface Parsed<T extends ParsedNode = ParsedNode> extends Document<T> {
|
|
14
|
-
directives: Directives;
|
|
15
14
|
range: Range;
|
|
16
15
|
}
|
|
17
16
|
}
|
|
@@ -23,15 +22,13 @@ export declare class Document<T = unknown> {
|
|
|
23
22
|
comment: string | null;
|
|
24
23
|
/** The document contents. */
|
|
25
24
|
contents: T | null;
|
|
26
|
-
directives
|
|
25
|
+
directives: Directives;
|
|
27
26
|
/** Errors encountered during parsing. */
|
|
28
27
|
errors: YAMLError[];
|
|
29
28
|
options: Required<Omit<ParseOptions & DocumentOptions, 'lineCounter' | 'directives' | 'version'>>;
|
|
30
29
|
/**
|
|
31
|
-
* The
|
|
32
|
-
* source parsed into this document (undefined if not parsed).
|
|
33
|
-
* and `node-end` positions are themselves not included in their respective
|
|
34
|
-
* ranges.
|
|
30
|
+
* The [start, value-end, node-end] character offsets for the part of the
|
|
31
|
+
* source parsed into this document (undefined if not parsed).
|
|
35
32
|
*/
|
|
36
33
|
range?: Range;
|
|
37
34
|
/** The schema used with the document. Use `setSchema()` to change. */
|
|
@@ -44,12 +41,6 @@ export declare class Document<T = unknown> {
|
|
|
44
41
|
*/
|
|
45
42
|
constructor(value?: any, options?: DocumentOptions & SchemaOptions & ParseOptions & CreateNodeOptions);
|
|
46
43
|
constructor(value: any, replacer: null | Replacer, options?: DocumentOptions & SchemaOptions & ParseOptions & CreateNodeOptions);
|
|
47
|
-
/**
|
|
48
|
-
* Create a deep copy of this Document and its contents.
|
|
49
|
-
*
|
|
50
|
-
* Custom Node values that inherit from `Object` still refer to their original instances.
|
|
51
|
-
*/
|
|
52
|
-
clone(): Document<T>;
|
|
53
44
|
/** Adds a value to the document. */
|
|
54
45
|
add(value: any): void;
|
|
55
46
|
/** Adds a value to the document. */
|
|
@@ -117,12 +108,10 @@ export declare class Document<T = unknown> {
|
|
|
117
108
|
setIn(path: Iterable<unknown>, value: unknown): void;
|
|
118
109
|
/**
|
|
119
110
|
* Change the YAML version and schema used by the document.
|
|
120
|
-
* A `null` version disables support for directives, explicit tags, anchors, and aliases.
|
|
121
|
-
* It also requires the `schema` option to be given as a `Schema` instance value.
|
|
122
111
|
*
|
|
123
|
-
* Overrides all previously set schema options
|
|
112
|
+
* Overrides all previously set schema options
|
|
124
113
|
*/
|
|
125
|
-
setSchema(version: '1.1' | '1.2'
|
|
114
|
+
setSchema(version: '1.1' | '1.2', options?: SchemaOptions): void;
|
|
126
115
|
/** A plain JavaScript representation of the document `contents`. */
|
|
127
116
|
toJS(opt?: ToJSOptions & {
|
|
128
117
|
[ignored: string]: unknown;
|
package/dist/doc/Document.js
CHANGED
|
@@ -50,30 +50,6 @@ class Document {
|
|
|
50
50
|
this.contents = this.createNode(value, _replacer, options$1);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
/**
|
|
54
|
-
* Create a deep copy of this Document and its contents.
|
|
55
|
-
*
|
|
56
|
-
* Custom Node values that inherit from `Object` still refer to their original instances.
|
|
57
|
-
*/
|
|
58
|
-
clone() {
|
|
59
|
-
const copy = Object.create(Document.prototype, {
|
|
60
|
-
[Node.NODE_TYPE]: { value: Node.DOC }
|
|
61
|
-
});
|
|
62
|
-
copy.commentBefore = this.commentBefore;
|
|
63
|
-
copy.comment = this.comment;
|
|
64
|
-
copy.errors = this.errors.slice();
|
|
65
|
-
copy.warnings = this.warnings.slice();
|
|
66
|
-
copy.options = Object.assign({}, this.options);
|
|
67
|
-
if (this.directives)
|
|
68
|
-
copy.directives = this.directives.clone();
|
|
69
|
-
copy.schema = this.schema.clone();
|
|
70
|
-
copy.contents = Node.isNode(this.contents)
|
|
71
|
-
? this.contents.clone(copy.schema)
|
|
72
|
-
: this.contents;
|
|
73
|
-
if (this.range)
|
|
74
|
-
copy.range = this.range.slice();
|
|
75
|
-
return copy;
|
|
76
|
-
}
|
|
77
53
|
/** Adds a value to the document. */
|
|
78
54
|
add(value) {
|
|
79
55
|
if (assertCollection(this.contents))
|
|
@@ -118,10 +94,9 @@ class Document {
|
|
|
118
94
|
options = replacer;
|
|
119
95
|
replacer = undefined;
|
|
120
96
|
}
|
|
121
|
-
const {
|
|
97
|
+
const { anchorPrefix, flow, keepUndefined, onTagObj, tag } = options || {};
|
|
122
98
|
const { onAnchor, setAnchors, sourceObjects } = anchors.createNodeAnchors(this, anchorPrefix || 'a');
|
|
123
99
|
const ctx = {
|
|
124
|
-
aliasDuplicateObjects: aliasDuplicateObjects !== null && aliasDuplicateObjects !== void 0 ? aliasDuplicateObjects : true,
|
|
125
100
|
keepUndefined: keepUndefined !== null && keepUndefined !== void 0 ? keepUndefined : false,
|
|
126
101
|
onAnchor,
|
|
127
102
|
onTagObj,
|
|
@@ -232,47 +207,26 @@ class Document {
|
|
|
232
207
|
}
|
|
233
208
|
/**
|
|
234
209
|
* Change the YAML version and schema used by the document.
|
|
235
|
-
* A `null` version disables support for directives, explicit tags, anchors, and aliases.
|
|
236
|
-
* It also requires the `schema` option to be given as a `Schema` instance value.
|
|
237
210
|
*
|
|
238
|
-
* Overrides all previously set schema options
|
|
211
|
+
* Overrides all previously set schema options
|
|
239
212
|
*/
|
|
240
|
-
setSchema(version, options
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
let opt;
|
|
244
|
-
switch (version) {
|
|
213
|
+
setSchema(version, options) {
|
|
214
|
+
let _options;
|
|
215
|
+
switch (String(version)) {
|
|
245
216
|
case '1.1':
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
else
|
|
249
|
-
this.directives = new directives.Directives({ version: '1.1' });
|
|
250
|
-
opt = { merge: true, resolveKnownTags: false, schema: 'yaml-1.1' };
|
|
217
|
+
this.directives.yaml.version = '1.1';
|
|
218
|
+
_options = Object.assign({ merge: true, resolveKnownTags: false, schema: 'yaml-1.1' }, options);
|
|
251
219
|
break;
|
|
252
220
|
case '1.2':
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
else
|
|
256
|
-
this.directives = new directives.Directives({ version: '1.2' });
|
|
257
|
-
opt = { merge: false, resolveKnownTags: true, schema: 'core' };
|
|
258
|
-
break;
|
|
259
|
-
case null:
|
|
260
|
-
if (this.directives)
|
|
261
|
-
delete this.directives;
|
|
262
|
-
opt = null;
|
|
221
|
+
this.directives.yaml.version = '1.2';
|
|
222
|
+
_options = Object.assign({ merge: false, resolveKnownTags: true, schema: 'core' }, options);
|
|
263
223
|
break;
|
|
264
224
|
default: {
|
|
265
225
|
const sv = JSON.stringify(version);
|
|
266
|
-
throw new Error(`Expected '1.1'
|
|
226
|
+
throw new Error(`Expected '1.1' or '1.2' as version, but found: ${sv}`);
|
|
267
227
|
}
|
|
268
228
|
}
|
|
269
|
-
|
|
270
|
-
if (options.schema instanceof Object)
|
|
271
|
-
this.schema = options.schema;
|
|
272
|
-
else if (opt)
|
|
273
|
-
this.schema = new Schema.Schema(Object.assign(opt, options));
|
|
274
|
-
else
|
|
275
|
-
throw new Error(`With a null YAML version, the { schema: Schema } option is required`);
|
|
229
|
+
this.schema = new Schema.Schema(_options);
|
|
276
230
|
}
|
|
277
231
|
// json & jsonArg are only used from toJSON()
|
|
278
232
|
toJS({ json, jsonArg, mapAsMap, maxAliasCount, onAnchor, reviver } = {}) {
|
package/dist/doc/createNode.d.ts
CHANGED
|
@@ -3,8 +3,7 @@ import type { Schema } from '../schema/Schema.js';
|
|
|
3
3
|
import type { CollectionTag, ScalarTag } from '../schema/types.js';
|
|
4
4
|
import type { Replacer } from './Document.js';
|
|
5
5
|
export interface CreateNodeContext {
|
|
6
|
-
|
|
7
|
-
keepUndefined: boolean;
|
|
6
|
+
keepUndefined?: boolean;
|
|
8
7
|
onAnchor(source: unknown): string;
|
|
9
8
|
onTagObj?: (tagObj: ScalarTag | CollectionTag) => void;
|
|
10
9
|
sourceObjects: Map<unknown, {
|
package/dist/doc/createNode.js
CHANGED
|
@@ -17,8 +17,6 @@ function findTagObject(value, tagName, tags) {
|
|
|
17
17
|
}
|
|
18
18
|
function createNode(value, tagName, ctx) {
|
|
19
19
|
var _a, _b;
|
|
20
|
-
if (Node.isDocument(value))
|
|
21
|
-
value = value.contents;
|
|
22
20
|
if (Node.isNode(value))
|
|
23
21
|
return value;
|
|
24
22
|
if (Node.isPair(value)) {
|
|
@@ -34,11 +32,11 @@ function createNode(value, tagName, ctx) {
|
|
|
34
32
|
// https://tc39.es/ecma262/#sec-serializejsonproperty
|
|
35
33
|
value = value.valueOf();
|
|
36
34
|
}
|
|
37
|
-
const {
|
|
35
|
+
const { onAnchor, onTagObj, schema, sourceObjects } = ctx;
|
|
38
36
|
// Detect duplicate references to the same object & use Alias nodes for all
|
|
39
37
|
// after first. The `ref` wrapper allows for circular references to resolve.
|
|
40
38
|
let ref = undefined;
|
|
41
|
-
if (
|
|
39
|
+
if (value && typeof value === 'object') {
|
|
42
40
|
ref = sourceObjects.get(value);
|
|
43
41
|
if (ref) {
|
|
44
42
|
if (!ref.anchor)
|
|
@@ -56,12 +54,8 @@ function createNode(value, tagName, ctx) {
|
|
|
56
54
|
if (!tagObj) {
|
|
57
55
|
if (value && typeof value.toJSON === 'function')
|
|
58
56
|
value = value.toJSON();
|
|
59
|
-
if (!value || typeof value !== 'object')
|
|
60
|
-
|
|
61
|
-
if (ref)
|
|
62
|
-
ref.node = node;
|
|
63
|
-
return node;
|
|
64
|
-
}
|
|
57
|
+
if (!value || typeof value !== 'object')
|
|
58
|
+
return new Scalar.Scalar(value);
|
|
65
59
|
tagObj =
|
|
66
60
|
value instanceof Map
|
|
67
61
|
? schema[Node.MAP]
|
package/dist/doc/directives.d.ts
CHANGED
|
@@ -20,7 +20,6 @@ export declare class Directives {
|
|
|
20
20
|
*/
|
|
21
21
|
private atNextDocument?;
|
|
22
22
|
constructor(yaml?: Directives['yaml'], tags?: Directives['tags']);
|
|
23
|
-
clone(): Directives;
|
|
24
23
|
/**
|
|
25
24
|
* During parsing, get a Directives instance for the current document and
|
|
26
25
|
* update the stream state according to the current version's spec.
|
package/dist/doc/directives.js
CHANGED
|
@@ -22,11 +22,6 @@ class Directives {
|
|
|
22
22
|
this.yaml = Object.assign({}, Directives.defaultYaml, yaml);
|
|
23
23
|
this.tags = Object.assign({}, Directives.defaultTags, tags);
|
|
24
24
|
}
|
|
25
|
-
clone() {
|
|
26
|
-
const copy = new Directives(this.yaml, this.tags);
|
|
27
|
-
copy.marker = this.marker;
|
|
28
|
-
return copy;
|
|
29
|
-
}
|
|
30
25
|
/**
|
|
31
26
|
* During parsing, get a Directives instance for the current document and
|
|
32
27
|
* update the stream state according to the current version's spec.
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { LineCounter } from './parse/line-counter';
|
|
2
|
-
export declare type ErrorCode = 'ALIAS_PROPS' | '
|
|
2
|
+
export declare type ErrorCode = 'ALIAS_PROPS' | 'BAD_DIRECTIVE' | 'BAD_DQ_ESCAPE' | 'BAD_INDENT' | 'BAD_PROP_ORDER' | 'BAD_SCALAR_START' | 'BLOCK_AS_IMPLICIT_KEY' | 'BLOCK_IN_FLOW' | 'COMMENT_SPACE' | 'IMPOSSIBLE' | 'KEY_OVER_1024_CHARS' | 'MISSING_ANCHOR' | 'MISSING_CHAR' | 'MULTILINE_IMPLICIT_KEY' | 'MULTIPLE_ANCHORS' | 'MULTIPLE_DOCS' | 'MULTIPLE_TAGS' | 'TAB_AS_INDENT' | 'TAG_RESOLVE_FAILED' | 'UNEXPECTED_TOKEN';
|
|
3
3
|
export declare type LinePos = {
|
|
4
4
|
line: number;
|
|
5
5
|
col: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export { Composer } from './compose/composer.js';
|
|
2
2
|
export { Document } from './doc/Document.js';
|
|
3
3
|
export { Schema } from './schema/Schema.js';
|
|
4
|
-
export {
|
|
4
|
+
export { YAMLError, YAMLParseError, YAMLWarning } from './errors.js';
|
|
5
5
|
export { Alias } from './nodes/Alias.js';
|
|
6
|
-
export { isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq, Node, ParsedNode
|
|
6
|
+
export { isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq, Node, ParsedNode } from './nodes/Node.js';
|
|
7
7
|
export { Pair } from './nodes/Pair.js';
|
|
8
8
|
export { Scalar } from './nodes/Scalar.js';
|
|
9
9
|
export { YAMLMap } from './nodes/YAMLMap.js';
|
package/dist/nodes/Alias.d.ts
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
import type { Document } from '../doc/Document
|
|
2
|
-
import type { FlowScalar } from '../parse/cst.js';
|
|
1
|
+
import type { Document } from '../doc/Document';
|
|
3
2
|
import type { StringifyContext } from '../stringify/stringify.js';
|
|
4
3
|
import { NodeBase, Range } from './Node.js';
|
|
5
4
|
import type { Scalar } from './Scalar';
|
|
6
5
|
import type { ToJSContext } from './toJS.js';
|
|
7
|
-
import type { YAMLMap } from './YAMLMap
|
|
8
|
-
import type { YAMLSeq } from './YAMLSeq
|
|
6
|
+
import type { YAMLMap } from './YAMLMap';
|
|
7
|
+
import type { YAMLSeq } from './YAMLSeq';
|
|
9
8
|
export declare namespace Alias {
|
|
10
9
|
interface Parsed extends Alias {
|
|
11
10
|
range: Range;
|
|
12
|
-
srcToken?: FlowScalar & {
|
|
13
|
-
type: 'alias';
|
|
14
|
-
};
|
|
15
11
|
}
|
|
16
12
|
}
|
|
17
13
|
export declare class Alias extends NodeBase {
|
|
@@ -15,12 +15,6 @@ export declare abstract class Collection extends NodeBase {
|
|
|
15
15
|
*/
|
|
16
16
|
flow?: boolean;
|
|
17
17
|
constructor(type: symbol, schema?: Schema);
|
|
18
|
-
/**
|
|
19
|
-
* Create a copy of this collection.
|
|
20
|
-
*
|
|
21
|
-
* @param schema - If defined, overwrites the original's schema
|
|
22
|
-
*/
|
|
23
|
-
clone(schema?: Schema): Collection;
|
|
24
18
|
/** Adds a value to the collection. */
|
|
25
19
|
abstract add(value: unknown): void;
|
|
26
20
|
/**
|
|
@@ -53,21 +47,21 @@ export declare abstract class Collection extends NodeBase {
|
|
|
53
47
|
* Removes a value from the collection.
|
|
54
48
|
* @returns `true` if the item was found and removed.
|
|
55
49
|
*/
|
|
56
|
-
deleteIn(
|
|
50
|
+
deleteIn([key, ...rest]: Iterable<unknown>): boolean;
|
|
57
51
|
/**
|
|
58
52
|
* Returns item at `key`, or `undefined` if not found. By default unwraps
|
|
59
53
|
* scalar values from their surrounding node; to disable set `keepScalar` to
|
|
60
54
|
* `true` (collections are always returned intact).
|
|
61
55
|
*/
|
|
62
|
-
getIn(
|
|
56
|
+
getIn([key, ...rest]: Iterable<unknown>, keepScalar?: boolean): unknown;
|
|
63
57
|
hasAllNullValues(allowScalar?: boolean): boolean;
|
|
64
58
|
/**
|
|
65
59
|
* Checks if the collection includes a value with the key `key`.
|
|
66
60
|
*/
|
|
67
|
-
hasIn(
|
|
61
|
+
hasIn([key, ...rest]: Iterable<unknown>): boolean;
|
|
68
62
|
/**
|
|
69
63
|
* Sets a value in this collection. For `!!set`, `value` needs to be a
|
|
70
64
|
* boolean to add/remove the item from the set.
|
|
71
65
|
*/
|
|
72
|
-
setIn(
|
|
66
|
+
setIn([key, ...rest]: Iterable<unknown>, value: unknown): void;
|
|
73
67
|
}
|
package/dist/nodes/Collection.js
CHANGED
|
@@ -13,14 +13,19 @@ function collectionFromPath(schema, path, value) {
|
|
|
13
13
|
v = a;
|
|
14
14
|
}
|
|
15
15
|
else {
|
|
16
|
-
|
|
16
|
+
const o = {};
|
|
17
|
+
Object.defineProperty(o, typeof k === 'symbol' ? k : String(k), {
|
|
18
|
+
value: v,
|
|
19
|
+
writable: true,
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true
|
|
22
|
+
});
|
|
23
|
+
v = o;
|
|
17
24
|
}
|
|
18
25
|
}
|
|
19
26
|
return createNode.createNode(v, undefined, {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
onAnchor: () => {
|
|
23
|
-
throw new Error('This should not happen, please report a bug.');
|
|
27
|
+
onAnchor() {
|
|
28
|
+
throw new Error('Repeated objects are not supported here');
|
|
24
29
|
},
|
|
25
30
|
schema,
|
|
26
31
|
sourceObjects: new Map()
|
|
@@ -39,20 +44,6 @@ class Collection extends Node.NodeBase {
|
|
|
39
44
|
writable: true
|
|
40
45
|
});
|
|
41
46
|
}
|
|
42
|
-
/**
|
|
43
|
-
* Create a copy of this collection.
|
|
44
|
-
*
|
|
45
|
-
* @param schema - If defined, overwrites the original's schema
|
|
46
|
-
*/
|
|
47
|
-
clone(schema) {
|
|
48
|
-
const copy = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));
|
|
49
|
-
if (schema)
|
|
50
|
-
copy.schema = schema;
|
|
51
|
-
copy.items = copy.items.map(it => Node.isNode(it) || Node.isPair(it) ? it.clone(schema) : it);
|
|
52
|
-
if (this.range)
|
|
53
|
-
copy.range = this.range.slice();
|
|
54
|
-
return copy;
|
|
55
|
-
}
|
|
56
47
|
/**
|
|
57
48
|
* Adds a value to the collection. For `!!map` and `!!omap` the value must
|
|
58
49
|
* be a Pair instance or a `{ key, value }` object, which may not have a key
|
|
@@ -76,8 +67,7 @@ class Collection extends Node.NodeBase {
|
|
|
76
67
|
* Removes a value from the collection.
|
|
77
68
|
* @returns `true` if the item was found and removed.
|
|
78
69
|
*/
|
|
79
|
-
deleteIn(
|
|
80
|
-
const [key, ...rest] = path;
|
|
70
|
+
deleteIn([key, ...rest]) {
|
|
81
71
|
if (rest.length === 0)
|
|
82
72
|
return this.delete(key);
|
|
83
73
|
const node = this.get(key, true);
|
|
@@ -91,8 +81,7 @@ class Collection extends Node.NodeBase {
|
|
|
91
81
|
* scalar values from their surrounding node; to disable set `keepScalar` to
|
|
92
82
|
* `true` (collections are always returned intact).
|
|
93
83
|
*/
|
|
94
|
-
getIn(
|
|
95
|
-
const [key, ...rest] = path;
|
|
84
|
+
getIn([key, ...rest], keepScalar) {
|
|
96
85
|
const node = this.get(key, true);
|
|
97
86
|
if (rest.length === 0)
|
|
98
87
|
return !keepScalar && Node.isScalar(node) ? node.value : node;
|
|
@@ -116,8 +105,7 @@ class Collection extends Node.NodeBase {
|
|
|
116
105
|
/**
|
|
117
106
|
* Checks if the collection includes a value with the key `key`.
|
|
118
107
|
*/
|
|
119
|
-
hasIn(
|
|
120
|
-
const [key, ...rest] = path;
|
|
108
|
+
hasIn([key, ...rest]) {
|
|
121
109
|
if (rest.length === 0)
|
|
122
110
|
return this.has(key);
|
|
123
111
|
const node = this.get(key, true);
|
|
@@ -127,8 +115,7 @@ class Collection extends Node.NodeBase {
|
|
|
127
115
|
* Sets a value in this collection. For `!!set`, `value` needs to be a
|
|
128
116
|
* boolean to add/remove the item from the set.
|
|
129
117
|
*/
|
|
130
|
-
setIn(
|
|
131
|
-
const [key, ...rest] = path;
|
|
118
|
+
setIn([key, ...rest], value) {
|
|
132
119
|
if (rest.length === 0) {
|
|
133
120
|
this.set(key, value);
|
|
134
121
|
}
|
package/dist/nodes/Node.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Document } from '../doc/Document.js';
|
|
2
|
-
import { Token } from '../parse/cst.js';
|
|
3
2
|
import type { StringifyContext } from '../stringify/stringify.js';
|
|
4
3
|
import type { Alias } from './Alias.js';
|
|
5
4
|
import type { Pair } from './Pair.js';
|
|
@@ -24,7 +23,7 @@ export declare const isScalar: (node: any) => node is Scalar<unknown>;
|
|
|
24
23
|
export declare const isSeq: (node: any) => node is YAMLSeq<unknown>;
|
|
25
24
|
export declare function isCollection(node: any): node is YAMLMap | YAMLSeq;
|
|
26
25
|
export declare function isNode(node: any): node is Node;
|
|
27
|
-
export declare const hasAnchor: (node: unknown) => node is
|
|
26
|
+
export declare const hasAnchor: (node: unknown) => node is YAMLMap<unknown, unknown> | YAMLSeq<unknown> | Scalar<unknown>;
|
|
28
27
|
export declare abstract class NodeBase {
|
|
29
28
|
readonly [NODE_TYPE]: symbol;
|
|
30
29
|
/** A comment on or immediately after this */
|
|
@@ -32,22 +31,16 @@ export declare abstract class NodeBase {
|
|
|
32
31
|
/** A comment before this */
|
|
33
32
|
commentBefore?: string | null;
|
|
34
33
|
/**
|
|
35
|
-
* The
|
|
36
|
-
* source parsed into this node (undefined if not parsed).
|
|
37
|
-
* and `node-end` positions are themselves not included in their respective
|
|
38
|
-
* ranges.
|
|
34
|
+
* The [start, value-end, node-end] character offsets for the part of the
|
|
35
|
+
* source parsed into this node (undefined if not parsed).
|
|
39
36
|
*/
|
|
40
37
|
range?: Range | null;
|
|
41
38
|
/** A blank line before this node and its commentBefore */
|
|
42
39
|
spaceBefore?: boolean;
|
|
43
|
-
/** The CST token that was composed into this node. */
|
|
44
|
-
srcToken?: Token;
|
|
45
40
|
/** A fully qualified tag, if required */
|
|
46
41
|
tag?: string;
|
|
47
42
|
/** A plain JS representation of this node */
|
|
48
43
|
abstract toJSON(): any;
|
|
49
44
|
abstract toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
|
|
50
45
|
constructor(type: symbol);
|
|
51
|
-
/** Create a copy of this node. */
|
|
52
|
-
clone(): NodeBase;
|
|
53
46
|
}
|
package/dist/nodes/Node.js
CHANGED
|
@@ -38,13 +38,6 @@ class NodeBase {
|
|
|
38
38
|
constructor(type) {
|
|
39
39
|
Object.defineProperty(this, NODE_TYPE, { value: type });
|
|
40
40
|
}
|
|
41
|
-
/** Create a copy of this node. */
|
|
42
|
-
clone() {
|
|
43
|
-
const copy = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));
|
|
44
|
-
if (this.range)
|
|
45
|
-
copy.range = this.range.slice();
|
|
46
|
-
return copy;
|
|
47
|
-
}
|
|
48
41
|
}
|
|
49
42
|
|
|
50
43
|
exports.ALIAS = ALIAS;
|
package/dist/nodes/Pair.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { CreateNodeContext } from '../doc/createNode.js';
|
|
2
|
-
import
|
|
3
|
-
import type { Schema } from '../schema/Schema.js';
|
|
4
|
-
import type { StringifyContext } from '../stringify/stringify.js';
|
|
2
|
+
import { StringifyContext } from '../stringify/stringify.js';
|
|
5
3
|
import { addPairToJSMap } from './addPairToJSMap.js';
|
|
6
4
|
import { NODE_TYPE } from './Node.js';
|
|
7
|
-
import
|
|
5
|
+
import { ToJSContext } from './toJS.js';
|
|
8
6
|
export declare function createPair(key: unknown, value: unknown, ctx: CreateNodeContext): Pair<import("./Node.js").Node, import("./Alias.js").Alias | import("./Scalar.js").Scalar<unknown> | import("./YAMLMap.js").YAMLMap<unknown, unknown> | import("./YAMLSeq.js").YAMLSeq<unknown>>;
|
|
9
7
|
export declare class Pair<K = unknown, V = unknown> {
|
|
10
8
|
readonly [NODE_TYPE]: symbol;
|
|
@@ -12,10 +10,7 @@ export declare class Pair<K = unknown, V = unknown> {
|
|
|
12
10
|
key: K;
|
|
13
11
|
/** Always Node or null when parsed, but can be set to anything. */
|
|
14
12
|
value: V | null;
|
|
15
|
-
/** The CST token that was composed into this pair. */
|
|
16
|
-
srcToken?: CollectionItem;
|
|
17
13
|
constructor(key: K, value?: V | null);
|
|
18
|
-
clone(schema?: Schema): Pair<K, V>;
|
|
19
14
|
toJSON(_?: unknown, ctx?: ToJSContext): ReturnType<typeof addPairToJSMap>;
|
|
20
15
|
toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
|
|
21
16
|
}
|
package/dist/nodes/Pair.js
CHANGED
|
@@ -16,14 +16,6 @@ class Pair {
|
|
|
16
16
|
this.key = key;
|
|
17
17
|
this.value = value;
|
|
18
18
|
}
|
|
19
|
-
clone(schema) {
|
|
20
|
-
let { key, value } = this;
|
|
21
|
-
if (Node.isNode(key))
|
|
22
|
-
key = key.clone(schema);
|
|
23
|
-
if (Node.isNode(value))
|
|
24
|
-
value = value.clone(schema);
|
|
25
|
-
return new Pair(key, value);
|
|
26
|
-
}
|
|
27
19
|
toJSON(_, ctx) {
|
|
28
20
|
const pair = ctx && ctx.mapAsMap ? new Map() : {};
|
|
29
21
|
return addPairToJSMap.addPairToJSMap(ctx, pair, this);
|
package/dist/nodes/Scalar.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { BlockScalar, FlowScalar } from '../parse/cst.js';
|
|
2
1
|
import { NodeBase, Range } from './Node.js';
|
|
3
2
|
import { ToJSContext } from './toJS.js';
|
|
4
3
|
export declare const isScalarValue: (value: unknown) => boolean;
|
|
@@ -6,7 +5,6 @@ export declare namespace Scalar {
|
|
|
6
5
|
interface Parsed extends Scalar {
|
|
7
6
|
range: Range;
|
|
8
7
|
source: string;
|
|
9
|
-
srcToken?: FlowScalar | BlockScalar;
|
|
10
8
|
}
|
|
11
9
|
type BLOCK_FOLDED = 'BLOCK_FOLDED';
|
|
12
10
|
type BLOCK_LITERAL = 'BLOCK_LITERAL';
|
package/dist/nodes/YAMLMap.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { BlockMap, FlowCollection } from '../parse/cst.js';
|
|
2
1
|
import type { Schema } from '../schema/Schema.js';
|
|
3
2
|
import type { StringifyContext } from '../stringify/stringify.js';
|
|
4
3
|
import { Collection } from './Collection.js';
|
|
@@ -10,7 +9,6 @@ export declare namespace YAMLMap {
|
|
|
10
9
|
interface Parsed<K extends ParsedNode = ParsedNode, V extends ParsedNode | null = ParsedNode | null> extends YAMLMap<K, V> {
|
|
11
10
|
items: Pair<K, V>[];
|
|
12
11
|
range: Range;
|
|
13
|
-
srcToken?: BlockMap | FlowCollection;
|
|
14
12
|
}
|
|
15
13
|
}
|
|
16
14
|
export declare class YAMLMap<K = unknown, V = unknown> extends Collection {
|
package/dist/nodes/YAMLMap.js
CHANGED
|
@@ -106,7 +106,7 @@ class YAMLMap extends Collection.Collection {
|
|
|
106
106
|
if (!ctx.allNullValues && this.hasAllNullValues(false))
|
|
107
107
|
ctx = Object.assign({}, ctx, { allNullValues: true });
|
|
108
108
|
return stringifyCollection.stringifyCollection(this, ctx, {
|
|
109
|
-
|
|
109
|
+
blockItem: n => n.str,
|
|
110
110
|
flowChars: { start: '{', end: '}' },
|
|
111
111
|
itemIndent: ctx.indent || '',
|
|
112
112
|
onChompKeep,
|
package/dist/nodes/YAMLSeq.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { BlockSequence, FlowCollection } from '../parse/cst.js';
|
|
2
1
|
import type { Schema } from '../schema/Schema.js';
|
|
3
2
|
import type { StringifyContext } from '../stringify/stringify.js';
|
|
4
3
|
import { Collection } from './Collection.js';
|
|
@@ -9,7 +8,6 @@ export declare namespace YAMLSeq {
|
|
|
9
8
|
interface Parsed<T extends ParsedNode | Pair<ParsedNode, ParsedNode | null> = ParsedNode> extends YAMLSeq<T> {
|
|
10
9
|
items: T[];
|
|
11
10
|
range: Range;
|
|
12
|
-
srcToken?: BlockSequence | FlowCollection;
|
|
13
11
|
}
|
|
14
12
|
}
|
|
15
13
|
export declare class YAMLSeq<T = unknown> extends Collection {
|
package/dist/nodes/YAMLSeq.js
CHANGED
|
@@ -87,7 +87,7 @@ class YAMLSeq extends Collection.Collection {
|
|
|
87
87
|
if (!ctx)
|
|
88
88
|
return JSON.stringify(this);
|
|
89
89
|
return stringifyCollection.stringifyCollection(this, ctx, {
|
|
90
|
-
|
|
90
|
+
blockItem: n => (n.comment ? n.str : `- ${n.str}`),
|
|
91
91
|
flowChars: { start: '[', end: ']' },
|
|
92
92
|
itemIndent: (ctx.indent || '') + ' ',
|
|
93
93
|
onChompKeep,
|