yaml 2.0.1 → 2.1.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/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 +5 -6
- 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 +2 -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 +10 -14
- 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 +5 -6
- 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.js +2 -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 +14 -10
- 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 +10 -14
- package/dist/public-api.js +3 -4
- 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
|
@@ -16,7 +16,7 @@ class Schema {
|
|
|
16
16
|
this.name = (typeof schema === 'string' && schema) || 'core';
|
|
17
17
|
this.knownTags = resolveKnownTags ? coreKnownTags : {};
|
|
18
18
|
this.tags = getTags(customTags, this.name);
|
|
19
|
-
this.toStringOptions = toStringDefaults
|
|
19
|
+
this.toStringOptions = toStringDefaults ?? null;
|
|
20
20
|
Object.defineProperty(this, MAP, { value: map });
|
|
21
21
|
Object.defineProperty(this, SCALAR, { value: string });
|
|
22
22
|
Object.defineProperty(this, SEQ, { value: seq });
|
|
@@ -22,7 +22,7 @@ class YAMLOMap extends YAMLSeq {
|
|
|
22
22
|
if (!ctx)
|
|
23
23
|
return super.toJSON(_);
|
|
24
24
|
const map = new Map();
|
|
25
|
-
if (ctx
|
|
25
|
+
if (ctx?.onCreate)
|
|
26
26
|
ctx.onCreate(map);
|
|
27
27
|
for (const pair of this.items) {
|
|
28
28
|
let key, value;
|
|
@@ -4,7 +4,6 @@ import { Scalar } from '../../nodes/Scalar.js';
|
|
|
4
4
|
import { YAMLSeq } from '../../nodes/YAMLSeq.js';
|
|
5
5
|
|
|
6
6
|
function resolvePairs(seq, onError) {
|
|
7
|
-
var _a;
|
|
8
7
|
if (isSeq(seq)) {
|
|
9
8
|
for (let i = 0; i < seq.items.length; ++i) {
|
|
10
9
|
let item = seq.items[i];
|
|
@@ -19,7 +18,7 @@ function resolvePairs(seq, onError) {
|
|
|
19
18
|
? `${item.commentBefore}\n${pair.key.commentBefore}`
|
|
20
19
|
: item.commentBefore;
|
|
21
20
|
if (item.comment) {
|
|
22
|
-
const cn =
|
|
21
|
+
const cn = pair.value ?? pair.key;
|
|
23
22
|
cn.comment = cn.comment
|
|
24
23
|
? `${item.comment}\n${cn.comment}`
|
|
25
24
|
: item.comment;
|
|
@@ -22,6 +22,10 @@ class YAMLSet extends YAMLMap {
|
|
|
22
22
|
if (!prev)
|
|
23
23
|
this.items.push(pair);
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* If `keepPair` is `true`, returns the Pair matching `key`.
|
|
27
|
+
* Otherwise, returns the value of that Pair's key.
|
|
28
|
+
*/
|
|
25
29
|
get(key, keepPair) {
|
|
26
30
|
const pair = findPair(this.items, key);
|
|
27
31
|
return !keepPair && isPair(pair)
|
|
@@ -43,26 +43,25 @@ function createStringifyContext(doc, options) {
|
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
function getTagObject(tags, item) {
|
|
46
|
-
var _a, _b, _c, _d;
|
|
47
46
|
if (item.tag) {
|
|
48
47
|
const match = tags.filter(t => t.tag === item.tag);
|
|
49
48
|
if (match.length > 0)
|
|
50
|
-
return
|
|
49
|
+
return match.find(t => t.format === item.format) ?? match[0];
|
|
51
50
|
}
|
|
52
51
|
let tagObj = undefined;
|
|
53
52
|
let obj;
|
|
54
53
|
if (isScalar(item)) {
|
|
55
54
|
obj = item.value;
|
|
56
|
-
const match = tags.filter(t =>
|
|
55
|
+
const match = tags.filter(t => t.identify?.(obj));
|
|
57
56
|
tagObj =
|
|
58
|
-
|
|
57
|
+
match.find(t => t.format === item.format) ?? match.find(t => !t.format);
|
|
59
58
|
}
|
|
60
59
|
else {
|
|
61
60
|
obj = item;
|
|
62
61
|
tagObj = tags.find(t => t.nodeClass && obj instanceof t.nodeClass);
|
|
63
62
|
}
|
|
64
63
|
if (!tagObj) {
|
|
65
|
-
const name =
|
|
64
|
+
const name = obj?.constructor?.name ?? typeof obj;
|
|
66
65
|
throw new Error(`Tag not resolved for ${name} value`);
|
|
67
66
|
}
|
|
68
67
|
return tagObj;
|
|
@@ -83,13 +82,12 @@ function stringifyProps(node, tagObj, { anchors, doc }) {
|
|
|
83
82
|
return props.join(' ');
|
|
84
83
|
}
|
|
85
84
|
function stringify(item, ctx, onComment, onChompKeep) {
|
|
86
|
-
var _a, _b;
|
|
87
85
|
if (isPair(item))
|
|
88
86
|
return item.toString(ctx, onComment, onChompKeep);
|
|
89
87
|
if (isAlias(item)) {
|
|
90
88
|
if (ctx.doc.directives)
|
|
91
89
|
return item.toString(ctx);
|
|
92
|
-
if (
|
|
90
|
+
if (ctx.resolvedAliases?.has(item)) {
|
|
93
91
|
throw new TypeError(`Cannot stringify circular structure without alias nodes`);
|
|
94
92
|
}
|
|
95
93
|
else {
|
|
@@ -108,7 +106,7 @@ function stringify(item, ctx, onComment, onChompKeep) {
|
|
|
108
106
|
tagObj = getTagObject(ctx.doc.schema.tags, node);
|
|
109
107
|
const props = stringifyProps(node, tagObj, ctx);
|
|
110
108
|
if (props.length > 0)
|
|
111
|
-
ctx.indentAtStart = (
|
|
109
|
+
ctx.indentAtStart = (ctx.indentAtStart ?? 0) + props.length + 1;
|
|
112
110
|
const str = typeof tagObj.stringify === 'function'
|
|
113
111
|
? tagObj.stringify(node, ctx, onComment, onChompKeep)
|
|
114
112
|
: isScalar(node)
|
|
@@ -4,8 +4,7 @@ import { stringify } from './stringify.js';
|
|
|
4
4
|
import { lineComment, indentComment } from './stringifyComment.js';
|
|
5
5
|
|
|
6
6
|
function stringifyCollection(collection, ctx, options) {
|
|
7
|
-
|
|
8
|
-
const flow = (_a = ctx.inFlow) !== null && _a !== void 0 ? _a : collection.flow;
|
|
7
|
+
const flow = ctx.inFlow ?? collection.flow;
|
|
9
8
|
const stringify = flow ? stringifyFlowCollection : stringifyBlockCollection;
|
|
10
9
|
return stringify(collection, ctx, options);
|
|
11
10
|
}
|
|
@@ -3,7 +3,6 @@ import { createStringifyContext, stringify } from './stringify.js';
|
|
|
3
3
|
import { indentComment, lineComment } from './stringifyComment.js';
|
|
4
4
|
|
|
5
5
|
function stringifyDocument(doc, options) {
|
|
6
|
-
var _a;
|
|
7
6
|
const lines = [];
|
|
8
7
|
let hasDirectives = options.directives === true;
|
|
9
8
|
if (options.directives !== false && doc.directives) {
|
|
@@ -55,7 +54,7 @@ function stringifyDocument(doc, options) {
|
|
|
55
54
|
else {
|
|
56
55
|
lines.push(stringify(doc.contents, ctx));
|
|
57
56
|
}
|
|
58
|
-
if (
|
|
57
|
+
if (doc.directives?.docEnd) {
|
|
59
58
|
if (doc.comment) {
|
|
60
59
|
const cs = commentString(doc.comment);
|
|
61
60
|
if (cs.includes('\n')) {
|
|
@@ -263,9 +263,9 @@ function plainString(item, ctx, onComment, onChompKeep) {
|
|
|
263
263
|
// booleans get parsed with those types in v1.2 (e.g. '42', 'true' & '0.9e-3'),
|
|
264
264
|
// and others in v1.1.
|
|
265
265
|
if (actualString) {
|
|
266
|
-
const test = (tag) =>
|
|
266
|
+
const test = (tag) => tag.default && tag.tag !== 'tag:yaml.org,2002:str' && tag.test?.test(str);
|
|
267
267
|
const { compat, tags } = ctx.doc.schema;
|
|
268
|
-
if (tags.some(test) ||
|
|
268
|
+
if (tags.some(test) || compat?.some(test))
|
|
269
269
|
return quotedString(value, ctx);
|
|
270
270
|
}
|
|
271
271
|
return implicitKey
|
package/browser/dist/visit.js
CHANGED
|
@@ -196,19 +196,18 @@ function initVisitor(visitor) {
|
|
|
196
196
|
return visitor;
|
|
197
197
|
}
|
|
198
198
|
function callVisitor(key, node, visitor, path) {
|
|
199
|
-
var _a, _b, _c, _d, _e;
|
|
200
199
|
if (typeof visitor === 'function')
|
|
201
200
|
return visitor(key, node, path);
|
|
202
201
|
if (isMap(node))
|
|
203
|
-
return
|
|
202
|
+
return visitor.Map?.(key, node, path);
|
|
204
203
|
if (isSeq(node))
|
|
205
|
-
return
|
|
204
|
+
return visitor.Seq?.(key, node, path);
|
|
206
205
|
if (isPair(node))
|
|
207
|
-
return
|
|
206
|
+
return visitor.Pair?.(key, node, path);
|
|
208
207
|
if (isScalar(node))
|
|
209
|
-
return
|
|
208
|
+
return visitor.Scalar?.(key, node, path);
|
|
210
209
|
if (isAlias(node))
|
|
211
|
-
return
|
|
210
|
+
return visitor.Alias?.(key, node, path);
|
|
212
211
|
return undefined;
|
|
213
212
|
}
|
|
214
213
|
function replaceNode(key, path, node) {
|
|
@@ -53,7 +53,7 @@ function composeCollection(CN, ctx, token, tagToken, onError) {
|
|
|
53
53
|
: new Scalar.Scalar(res);
|
|
54
54
|
node.range = coll.range;
|
|
55
55
|
node.tag = tagName;
|
|
56
|
-
if (tag
|
|
56
|
+
if (tag?.format)
|
|
57
57
|
node.format = tag.format;
|
|
58
58
|
return node;
|
|
59
59
|
}
|
|
@@ -6,7 +6,7 @@ var resolveEnd = require('./resolve-end.js');
|
|
|
6
6
|
var resolveProps = require('./resolve-props.js');
|
|
7
7
|
|
|
8
8
|
function composeDoc(options, directives, { offset, start, value, end }, onError) {
|
|
9
|
-
const opts = Object.assign({ directives }, options);
|
|
9
|
+
const opts = Object.assign({ _directives: directives }, options);
|
|
10
10
|
const doc = new Document.Document(undefined, opts);
|
|
11
11
|
const ctx = {
|
|
12
12
|
atRoot: true,
|
|
@@ -16,7 +16,7 @@ function composeDoc(options, directives, { offset, start, value, end }, onError)
|
|
|
16
16
|
};
|
|
17
17
|
const props = resolveProps.resolveProps(start, {
|
|
18
18
|
indicator: 'doc-start',
|
|
19
|
-
next: value
|
|
19
|
+
next: value ?? end?.[0],
|
|
20
20
|
offset,
|
|
21
21
|
onError,
|
|
22
22
|
startOnNewline: true
|
|
@@ -19,12 +19,12 @@ function composeScalar(ctx, token, tagToken, onError) {
|
|
|
19
19
|
: ctx.schema[Node.SCALAR];
|
|
20
20
|
let scalar;
|
|
21
21
|
try {
|
|
22
|
-
const res = tag.resolve(value, msg => onError(tagToken
|
|
22
|
+
const res = tag.resolve(value, msg => onError(tagToken ?? token, 'TAG_RESOLVE_FAILED', msg), ctx.options);
|
|
23
23
|
scalar = Node.isScalar(res) ? res : new Scalar.Scalar(res);
|
|
24
24
|
}
|
|
25
25
|
catch (error) {
|
|
26
26
|
const msg = error instanceof Error ? error.message : String(error);
|
|
27
|
-
onError(tagToken
|
|
27
|
+
onError(tagToken ?? token, 'TAG_RESOLVE_FAILED', msg);
|
|
28
28
|
scalar = new Scalar.Scalar(value);
|
|
29
29
|
}
|
|
30
30
|
scalar.range = range;
|
|
@@ -40,7 +40,6 @@ function composeScalar(ctx, token, tagToken, onError) {
|
|
|
40
40
|
return scalar;
|
|
41
41
|
}
|
|
42
42
|
function findScalarTagByName(schema, value, tagName, tagToken, onError) {
|
|
43
|
-
var _a;
|
|
44
43
|
if (tagName === '!')
|
|
45
44
|
return schema[Node.SCALAR]; // non-specific tag
|
|
46
45
|
const matchWithTest = [];
|
|
@@ -53,7 +52,7 @@ function findScalarTagByName(schema, value, tagName, tagToken, onError) {
|
|
|
53
52
|
}
|
|
54
53
|
}
|
|
55
54
|
for (const tag of matchWithTest)
|
|
56
|
-
if (
|
|
55
|
+
if (tag.test?.test(value))
|
|
57
56
|
return tag;
|
|
58
57
|
const kt = schema.knownTags[tagName];
|
|
59
58
|
if (kt && !kt.collection) {
|
|
@@ -66,10 +65,10 @@ function findScalarTagByName(schema, value, tagName, tagToken, onError) {
|
|
|
66
65
|
return schema[Node.SCALAR];
|
|
67
66
|
}
|
|
68
67
|
function findScalarTagByTest({ directives, schema }, value, token, onError) {
|
|
69
|
-
|
|
70
|
-
const tag = schema.tags.find(tag => { var _a; return tag.default && ((_a = tag.test) === null || _a === void 0 ? void 0 : _a.test(value)); }) || schema[Node.SCALAR];
|
|
68
|
+
const tag = schema.tags.find(tag => tag.default && tag.test?.test(value)) || schema[Node.SCALAR];
|
|
71
69
|
if (schema.compat) {
|
|
72
|
-
const compat =
|
|
70
|
+
const compat = schema.compat.find(tag => tag.default && tag.test?.test(value)) ??
|
|
71
|
+
schema[Node.SCALAR];
|
|
73
72
|
if (tag.tag !== compat.tag) {
|
|
74
73
|
const ts = directives.tagString(tag.tag);
|
|
75
74
|
const cs = directives.tagString(compat.tag);
|
package/dist/compose/composer.js
CHANGED
|
@@ -16,7 +16,6 @@ function getErrorPos(src) {
|
|
|
16
16
|
return [offset, offset + (typeof source === 'string' ? source.length : 1)];
|
|
17
17
|
}
|
|
18
18
|
function parsePrelude(prelude) {
|
|
19
|
-
var _a;
|
|
20
19
|
let comment = '';
|
|
21
20
|
let atComment = false;
|
|
22
21
|
let afterEmptyLine = false;
|
|
@@ -31,7 +30,7 @@ function parsePrelude(prelude) {
|
|
|
31
30
|
afterEmptyLine = false;
|
|
32
31
|
break;
|
|
33
32
|
case '%':
|
|
34
|
-
if (
|
|
33
|
+
if (prelude[i + 1]?.[0] !== '#')
|
|
35
34
|
i += 1;
|
|
36
35
|
atComment = false;
|
|
37
36
|
break;
|
|
@@ -208,7 +207,7 @@ class Composer {
|
|
|
208
207
|
this.doc = null;
|
|
209
208
|
}
|
|
210
209
|
else if (forceDoc) {
|
|
211
|
-
const opts = Object.assign({
|
|
210
|
+
const opts = Object.assign({ _directives: this.directives }, this.options);
|
|
212
211
|
const doc = new Document.Document(undefined, opts);
|
|
213
212
|
if (this.atDirectives)
|
|
214
213
|
this.onError(endOffset, 'MISSING_CHAR', 'Missing directives-end indicator line');
|
|
@@ -9,7 +9,6 @@ var utilMapIncludes = require('./util-map-includes.js');
|
|
|
9
9
|
|
|
10
10
|
const startColMsg = 'All mapping items must start at the same column';
|
|
11
11
|
function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
|
|
12
|
-
var _a;
|
|
13
12
|
const map = new YAMLMap.YAMLMap(ctx.schema);
|
|
14
13
|
if (ctx.atRoot)
|
|
15
14
|
ctx.atRoot = false;
|
|
@@ -19,7 +18,7 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
|
|
|
19
18
|
// key properties
|
|
20
19
|
const keyProps = resolveProps.resolveProps(start, {
|
|
21
20
|
indicator: 'explicit-key-ind',
|
|
22
|
-
next: key
|
|
21
|
+
next: key ?? sep?.[0],
|
|
23
22
|
offset,
|
|
24
23
|
onError,
|
|
25
24
|
startOnNewline: true
|
|
@@ -43,10 +42,10 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
|
|
|
43
42
|
continue;
|
|
44
43
|
}
|
|
45
44
|
if (keyProps.hasNewlineAfterProp || utilContainsNewline.containsNewline(key)) {
|
|
46
|
-
onError(key
|
|
45
|
+
onError(key ?? start[start.length - 1], 'MULTILINE_IMPLICIT_KEY', 'Implicit keys need to be on a single line');
|
|
47
46
|
}
|
|
48
47
|
}
|
|
49
|
-
else if (
|
|
48
|
+
else if (keyProps.found?.indent !== bm.indent) {
|
|
50
49
|
onError(offset, 'BAD_INDENT', startColMsg);
|
|
51
50
|
}
|
|
52
51
|
// key value
|
|
@@ -59,7 +58,7 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
|
|
|
59
58
|
if (utilMapIncludes.mapIncludes(ctx, map.items, keyNode))
|
|
60
59
|
onError(keyStart, 'DUPLICATE_KEY', 'Map keys must be unique');
|
|
61
60
|
// value properties
|
|
62
|
-
const valueProps = resolveProps.resolveProps(sep
|
|
61
|
+
const valueProps = resolveProps.resolveProps(sep ?? [], {
|
|
63
62
|
indicator: 'map-value-ind',
|
|
64
63
|
next: value,
|
|
65
64
|
offset: keyNode.range[2],
|
|
@@ -69,7 +68,7 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
|
|
|
69
68
|
offset = valueProps.end;
|
|
70
69
|
if (valueProps.found) {
|
|
71
70
|
if (implicitKey) {
|
|
72
|
-
if (
|
|
71
|
+
if (value?.type === 'block-map' && !valueProps.hasNewline)
|
|
73
72
|
onError(offset, 'BLOCK_AS_IMPLICIT_KEY', 'Nested mappings are not allowed in compact mappings');
|
|
74
73
|
if (ctx.options.strict &&
|
|
75
74
|
keyProps.start < valueProps.found.offset - 1024)
|
|
@@ -184,7 +184,7 @@ function splitLines(source) {
|
|
|
184
184
|
const split = source.split(/\n( *)/);
|
|
185
185
|
const first = split[0];
|
|
186
186
|
const m = first.match(/^( *)/);
|
|
187
|
-
const line0 =
|
|
187
|
+
const line0 = m?.[1]
|
|
188
188
|
? [m[1], first.slice(m[1].length)]
|
|
189
189
|
: ['', first];
|
|
190
190
|
const lines = [line0];
|
|
@@ -12,7 +12,6 @@ var utilMapIncludes = require('./util-map-includes.js');
|
|
|
12
12
|
const blockMsg = 'Block collections are not allowed within flow collections';
|
|
13
13
|
const isBlock = (token) => token && (token.type === 'block-map' || token.type === 'block-seq');
|
|
14
14
|
function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onError) {
|
|
15
|
-
var _a;
|
|
16
15
|
const isMap = fc.start.source === '{';
|
|
17
16
|
const fcName = isMap ? 'flow map' : 'flow sequence';
|
|
18
17
|
const coll = isMap
|
|
@@ -29,7 +28,7 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
|
|
|
29
28
|
const props = resolveProps.resolveProps(start, {
|
|
30
29
|
flow: fcName,
|
|
31
30
|
indicator: 'explicit-key-ind',
|
|
32
|
-
next: key
|
|
31
|
+
next: key ?? sep?.[0],
|
|
33
32
|
offset,
|
|
34
33
|
onError,
|
|
35
34
|
startOnNewline: false
|
|
@@ -77,7 +76,7 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
|
|
|
77
76
|
if (prevItemComment) {
|
|
78
77
|
let prev = coll.items[coll.items.length - 1];
|
|
79
78
|
if (Node.isPair(prev))
|
|
80
|
-
prev =
|
|
79
|
+
prev = prev.value ?? prev.key;
|
|
81
80
|
if (prev.comment)
|
|
82
81
|
prev.comment += '\n' + prevItemComment;
|
|
83
82
|
else
|
|
@@ -107,7 +106,7 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
|
|
|
107
106
|
if (isBlock(key))
|
|
108
107
|
onError(keyNode.range, 'BLOCK_IN_FLOW', blockMsg);
|
|
109
108
|
// value properties
|
|
110
|
-
const valueProps = resolveProps.resolveProps(sep
|
|
109
|
+
const valueProps = resolveProps.resolveProps(sep ?? [], {
|
|
111
110
|
flow: fcName,
|
|
112
111
|
indicator: 'map-value-ind',
|
|
113
112
|
next: value,
|
|
@@ -74,7 +74,6 @@ function singleQuotedValue(source, onError) {
|
|
|
74
74
|
return foldLines(source.slice(1, -1)).replace(/''/g, "'");
|
|
75
75
|
}
|
|
76
76
|
function foldLines(source) {
|
|
77
|
-
var _a;
|
|
78
77
|
/**
|
|
79
78
|
* The negative lookbehind here and in the `re` RegExp is to
|
|
80
79
|
* prevent causing a polynomial search time in certain cases.
|
|
@@ -114,7 +113,7 @@ function foldLines(source) {
|
|
|
114
113
|
const last = /[ \t]*(.*)/sy;
|
|
115
114
|
last.lastIndex = pos;
|
|
116
115
|
match = last.exec(source);
|
|
117
|
-
return res + sep + (
|
|
116
|
+
return res + sep + (match?.[1] ?? '');
|
|
118
117
|
}
|
|
119
118
|
function doubleQuotedValue(source, onError) {
|
|
120
119
|
let res = '';
|
|
@@ -89,7 +89,7 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
|
|
|
89
89
|
if (anchor || tag)
|
|
90
90
|
onError(token, 'BAD_PROP_ORDER', `Anchors and tags must be after the ${token.source} indicator`);
|
|
91
91
|
if (found)
|
|
92
|
-
onError(token, 'UNEXPECTED_TOKEN', `Unexpected ${token.source} in ${flow
|
|
92
|
+
onError(token, 'UNEXPECTED_TOKEN', `Unexpected ${token.source} in ${flow ?? 'collection'}`);
|
|
93
93
|
found = token;
|
|
94
94
|
atNewline = false;
|
|
95
95
|
hasSpace = false;
|
|
@@ -129,7 +129,7 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
|
|
|
129
129
|
anchor,
|
|
130
130
|
tag,
|
|
131
131
|
end,
|
|
132
|
-
start: start
|
|
132
|
+
start: start ?? end
|
|
133
133
|
};
|
|
134
134
|
}
|
|
135
135
|
|
|
@@ -16,7 +16,7 @@ function emptyScalarPosition(offset, before, pos) {
|
|
|
16
16
|
// Technically, an empty scalar is immediately after the last non-empty
|
|
17
17
|
// node, but it's more useful to place it after any whitespace.
|
|
18
18
|
st = before[++i];
|
|
19
|
-
while (
|
|
19
|
+
while (st?.type === 'space') {
|
|
20
20
|
offset += st.source.length;
|
|
21
21
|
st = before[++i];
|
|
22
22
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var utilContainsNewline = require('./util-contains-newline.js');
|
|
4
4
|
|
|
5
5
|
function flowIndentCheck(indent, fc, onError) {
|
|
6
|
-
if (
|
|
6
|
+
if (fc?.type === 'flow-collection') {
|
|
7
7
|
const end = fc.end[0];
|
|
8
8
|
if (end.indent === indent &&
|
|
9
9
|
(end.source === ']' || end.source === '}') &&
|
package/dist/doc/Document.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { YAMLError, YAMLWarning } from '../errors.js';
|
|
2
2
|
import { Alias } from '../nodes/Alias.js';
|
|
3
|
-
import { Node, NODE_TYPE, ParsedNode, Range } from '../nodes/Node.js';
|
|
3
|
+
import { Node, NodeType, NODE_TYPE, ParsedNode, Range } from '../nodes/Node.js';
|
|
4
4
|
import { Pair } from '../nodes/Pair.js';
|
|
5
5
|
import type { Scalar } from '../nodes/Scalar.js';
|
|
6
6
|
import type { YAMLMap } from '../nodes/YAMLMap.js';
|
|
@@ -15,7 +15,7 @@ export declare namespace Document {
|
|
|
15
15
|
range: Range;
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
export declare class Document<T =
|
|
18
|
+
export declare class Document<T extends Node = Node> {
|
|
19
19
|
readonly [NODE_TYPE]: symbol;
|
|
20
20
|
/** A comment before this Document */
|
|
21
21
|
commentBefore: string | null;
|
|
@@ -26,7 +26,7 @@ export declare class Document<T = unknown> {
|
|
|
26
26
|
directives?: Directives;
|
|
27
27
|
/** Errors encountered during parsing. */
|
|
28
28
|
errors: YAMLError[];
|
|
29
|
-
options: Required<Omit<ParseOptions & DocumentOptions, '
|
|
29
|
+
options: Required<Omit<ParseOptions & DocumentOptions, '_directives' | 'lineCounter' | 'version'>>;
|
|
30
30
|
/**
|
|
31
31
|
* The `[start, value-end, node-end]` character offsets for the part of the
|
|
32
32
|
* source parsed into this document (undefined if not parsed). The `value-end`
|
|
@@ -68,8 +68,8 @@ export declare class Document<T = unknown> {
|
|
|
68
68
|
* Convert any value into a `Node` using the current schema, recursively
|
|
69
69
|
* turning objects into collections.
|
|
70
70
|
*/
|
|
71
|
-
createNode(value:
|
|
72
|
-
createNode(value:
|
|
71
|
+
createNode<T = unknown>(value: T, options?: CreateNodeOptions): NodeType<T>;
|
|
72
|
+
createNode<T = unknown>(value: T, replacer: Replacer | CreateNodeOptions | null, options?: CreateNodeOptions): NodeType<T>;
|
|
73
73
|
/**
|
|
74
74
|
* Convert a key and a value into a `Pair` using the current schema,
|
|
75
75
|
* recursively wrapping all values as `Scalar` or `Collection` nodes.
|
|
@@ -79,12 +79,12 @@ export declare class Document<T = unknown> {
|
|
|
79
79
|
* Removes a value from the document.
|
|
80
80
|
* @returns `true` if the item was found and removed.
|
|
81
81
|
*/
|
|
82
|
-
delete(key:
|
|
82
|
+
delete(key: unknown): boolean;
|
|
83
83
|
/**
|
|
84
84
|
* Removes a value from the document.
|
|
85
85
|
* @returns `true` if the item was found and removed.
|
|
86
86
|
*/
|
|
87
|
-
deleteIn(path: Iterable<unknown>): boolean;
|
|
87
|
+
deleteIn(path: Iterable<unknown> | null): boolean;
|
|
88
88
|
/**
|
|
89
89
|
* Returns item at `key`, or `undefined` if not found. By default unwraps
|
|
90
90
|
* scalar values from their surrounding node; to disable set `keepScalar` to
|
|
@@ -96,7 +96,7 @@ export declare class Document<T = unknown> {
|
|
|
96
96
|
* scalar values from their surrounding node; to disable set `keepScalar` to
|
|
97
97
|
* `true` (collections are always returned intact).
|
|
98
98
|
*/
|
|
99
|
-
getIn(path: Iterable<unknown
|
|
99
|
+
getIn(path: Iterable<unknown> | null, keepScalar?: boolean): unknown;
|
|
100
100
|
/**
|
|
101
101
|
* Checks if the document includes a value with the key `key`.
|
|
102
102
|
*/
|
|
@@ -104,7 +104,7 @@ export declare class Document<T = unknown> {
|
|
|
104
104
|
/**
|
|
105
105
|
* Checks if the document includes a value at `path`.
|
|
106
106
|
*/
|
|
107
|
-
hasIn(path: Iterable<unknown>): boolean;
|
|
107
|
+
hasIn(path: Iterable<unknown> | null): boolean;
|
|
108
108
|
/**
|
|
109
109
|
* Sets a value in this document. For `!!set`, `value` needs to be a
|
|
110
110
|
* boolean to add/remove the item from the set.
|
|
@@ -114,7 +114,7 @@ export declare class Document<T = unknown> {
|
|
|
114
114
|
* Sets a value in this document. For `!!set`, `value` needs to be a
|
|
115
115
|
* boolean to add/remove the item from the set.
|
|
116
116
|
*/
|
|
117
|
-
setIn(path: Iterable<unknown
|
|
117
|
+
setIn(path: Iterable<unknown> | null, value: unknown): void;
|
|
118
118
|
/**
|
|
119
119
|
* Change the YAML version and schema used by the document.
|
|
120
120
|
* A `null` version disables support for directives, explicit tags, anchors, and aliases.
|
package/dist/doc/Document.js
CHANGED
|
@@ -43,8 +43,8 @@ class Document {
|
|
|
43
43
|
}, options);
|
|
44
44
|
this.options = opt;
|
|
45
45
|
let { version } = opt;
|
|
46
|
-
if (options
|
|
47
|
-
this.directives = options.
|
|
46
|
+
if (options?._directives) {
|
|
47
|
+
this.directives = options._directives.atDocument();
|
|
48
48
|
if (this.directives.yaml.explicit)
|
|
49
49
|
version = this.directives.yaml.version;
|
|
50
50
|
}
|
|
@@ -126,13 +126,13 @@ class Document {
|
|
|
126
126
|
options = replacer;
|
|
127
127
|
replacer = undefined;
|
|
128
128
|
}
|
|
129
|
-
const { aliasDuplicateObjects, anchorPrefix, flow, keepUndefined, onTagObj, tag } = options
|
|
129
|
+
const { aliasDuplicateObjects, anchorPrefix, flow, keepUndefined, onTagObj, tag } = options ?? {};
|
|
130
130
|
const { onAnchor, setAnchors, sourceObjects } = anchors.createNodeAnchors(this,
|
|
131
131
|
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
132
132
|
anchorPrefix || 'a');
|
|
133
133
|
const ctx = {
|
|
134
|
-
aliasDuplicateObjects: aliasDuplicateObjects
|
|
135
|
-
keepUndefined: keepUndefined
|
|
134
|
+
aliasDuplicateObjects: aliasDuplicateObjects ?? true,
|
|
135
|
+
keepUndefined: keepUndefined ?? false,
|
|
136
136
|
onAnchor,
|
|
137
137
|
onTagObj,
|
|
138
138
|
replacer: _replacer,
|
|
@@ -296,7 +296,7 @@ class Document {
|
|
|
296
296
|
maxAliasCount: typeof maxAliasCount === 'number' ? maxAliasCount : 100,
|
|
297
297
|
stringify: stringify.stringify
|
|
298
298
|
};
|
|
299
|
-
const res = toJS.toJS(this.contents, jsonArg
|
|
299
|
+
const res = toJS.toJS(this.contents, jsonArg ?? '', ctx);
|
|
300
300
|
if (typeof onAnchor === 'function')
|
|
301
301
|
for (const { count, res } of ctx.anchors.values())
|
|
302
302
|
onAnchor(res, count);
|
package/dist/doc/anchors.d.ts
CHANGED
package/dist/doc/createNode.js
CHANGED
|
@@ -6,24 +6,22 @@ var Scalar = require('../nodes/Scalar.js');
|
|
|
6
6
|
|
|
7
7
|
const defaultTagPrefix = 'tag:yaml.org,2002:';
|
|
8
8
|
function findTagObject(value, tagName, tags) {
|
|
9
|
-
var _a;
|
|
10
9
|
if (tagName) {
|
|
11
10
|
const match = tags.filter(t => t.tag === tagName);
|
|
12
|
-
const tagObj =
|
|
11
|
+
const tagObj = match.find(t => !t.format) ?? match[0];
|
|
13
12
|
if (!tagObj)
|
|
14
13
|
throw new Error(`Tag ${tagName} not found`);
|
|
15
14
|
return tagObj;
|
|
16
15
|
}
|
|
17
|
-
return tags.find(t =>
|
|
16
|
+
return tags.find(t => t.identify?.(value) && !t.format);
|
|
18
17
|
}
|
|
19
18
|
function createNode(value, tagName, ctx) {
|
|
20
|
-
var _a, _b;
|
|
21
19
|
if (Node.isDocument(value))
|
|
22
20
|
value = value.contents;
|
|
23
21
|
if (Node.isNode(value))
|
|
24
22
|
return value;
|
|
25
23
|
if (Node.isPair(value)) {
|
|
26
|
-
const map =
|
|
24
|
+
const map = ctx.schema[Node.MAP].createNode?.(ctx.schema, null, ctx);
|
|
27
25
|
map.items.push(value);
|
|
28
26
|
return map;
|
|
29
27
|
}
|
|
@@ -51,7 +49,7 @@ function createNode(value, tagName, ctx) {
|
|
|
51
49
|
sourceObjects.set(value, ref);
|
|
52
50
|
}
|
|
53
51
|
}
|
|
54
|
-
if (tagName
|
|
52
|
+
if (tagName?.startsWith('!!'))
|
|
55
53
|
tagName = defaultTagPrefix + tagName.slice(2);
|
|
56
54
|
let tagObj = findTagObject(value, tagName, schema.tags);
|
|
57
55
|
if (!tagObj) {
|
|
@@ -76,7 +74,7 @@ function createNode(value, tagName, ctx) {
|
|
|
76
74
|
onTagObj(tagObj);
|
|
77
75
|
delete ctx.onTagObj;
|
|
78
76
|
}
|
|
79
|
-
const node =
|
|
77
|
+
const node = tagObj?.createNode
|
|
80
78
|
? tagObj.createNode(ctx.schema, value, ctx)
|
|
81
79
|
: new Scalar.Scalar(value);
|
|
82
80
|
if (tagName)
|
package/dist/index.d.ts
CHANGED
|
@@ -16,4 +16,6 @@ export { Parser } from './parse/parser.js';
|
|
|
16
16
|
export { EmptyStream, parse, parseAllDocuments, parseDocument, stringify } from './public-api.js';
|
|
17
17
|
export type { TagId, Tags } from './schema/tags';
|
|
18
18
|
export type { CollectionTag, ScalarTag } from './schema/types';
|
|
19
|
+
export type { YAMLOMap } from './schema/yaml-1.1/omap';
|
|
20
|
+
export type { YAMLSet } from './schema/yaml-1.1/set';
|
|
19
21
|
export { asyncVisitor, asyncVisitorFn, visit, visitAsync, visitor, visitorFn } from './visit.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Schema } from '../schema/Schema.js';
|
|
2
2
|
import { NodeBase, NODE_TYPE } from './Node.js';
|
|
3
|
-
export declare function collectionFromPath(schema: Schema, path: unknown[], value: unknown): import("./Node.js").Node
|
|
4
|
-
export declare const isEmptyPath: (path: Iterable<unknown> | null | undefined) =>
|
|
3
|
+
export declare function collectionFromPath(schema: Schema, path: unknown[], value: unknown): import("./Node.js").Node<unknown>;
|
|
4
|
+
export declare const isEmptyPath: (path: Iterable<unknown> | null | undefined) => path is null | undefined;
|
|
5
5
|
export declare abstract class Collection extends NodeBase {
|
|
6
6
|
static maxFlowStringSingleLineLength: number;
|
|
7
7
|
schema: Schema | undefined;
|
package/dist/nodes/Collection.js
CHANGED
|
@@ -26,7 +26,8 @@ function collectionFromPath(schema, path, value) {
|
|
|
26
26
|
sourceObjects: new Map()
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
|
-
//
|
|
29
|
+
// Type guard is intentionally a little wrong so as to be more useful,
|
|
30
|
+
// as it does not cover untypable empty non-string iterables (e.g. []).
|
|
30
31
|
const isEmptyPath = (path) => path == null ||
|
|
31
32
|
(typeof path === 'object' && !!path[Symbol.iterator]().next().done);
|
|
32
33
|
class Collection extends Node.NodeBase {
|