yaml 2.0.0-7 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/browser/dist/compose/compose-doc.js +3 -2
- package/browser/dist/compose/compose-node.js +14 -3
- package/browser/dist/compose/compose-scalar.js +17 -10
- package/browser/dist/compose/composer.js +6 -7
- package/browser/dist/compose/resolve-block-map.js +19 -5
- package/browser/dist/compose/resolve-block-scalar.js +12 -3
- package/browser/dist/compose/resolve-block-seq.js +5 -0
- package/browser/dist/compose/resolve-flow-collection.js +18 -6
- package/browser/dist/compose/resolve-flow-scalar.js +9 -2
- package/browser/dist/compose/resolve-props.js +4 -0
- package/browser/dist/compose/util-flow-indent-check.js +15 -0
- package/browser/dist/doc/Document.js +73 -16
- package/browser/dist/doc/anchors.js +2 -2
- package/browser/dist/doc/createNode.js +12 -7
- package/browser/dist/doc/directives.js +11 -3
- package/browser/dist/index.js +1 -2
- package/browser/dist/node_modules/tslib/tslib.es6.js +164 -0
- package/browser/dist/nodes/Collection.js +28 -15
- package/browser/dist/nodes/Node.js +7 -0
- package/browser/dist/nodes/Pair.js +11 -3
- package/browser/dist/nodes/Scalar.js +1 -1
- package/browser/dist/nodes/YAMLMap.js +6 -5
- package/browser/dist/nodes/YAMLSeq.js +2 -2
- package/browser/dist/nodes/addPairToJSMap.js +3 -2
- package/browser/dist/nodes/toJS.js +3 -1
- package/browser/dist/parse/cst-scalar.js +2 -6
- package/browser/dist/parse/cst-visit.js +2 -2
- package/browser/dist/parse/lexer.js +50 -22
- package/browser/dist/parse/parser.js +121 -45
- package/browser/dist/public-api.js +4 -5
- package/browser/dist/schema/Schema.js +19 -4
- package/browser/dist/schema/common/null.js +3 -1
- package/browser/dist/schema/core/float.js +4 -1
- package/browser/dist/schema/tags.js +17 -13
- package/browser/dist/schema/yaml-1.1/float.js +4 -1
- package/browser/dist/schema/yaml-1.1/omap.js +1 -1
- package/browser/dist/schema/yaml-1.1/pairs.js +2 -1
- package/browser/dist/stringify/stringify.js +53 -23
- package/browser/dist/stringify/stringifyCollection.js +115 -85
- package/browser/dist/stringify/stringifyComment.js +18 -12
- package/browser/dist/stringify/stringifyDocument.js +37 -15
- package/browser/dist/stringify/stringifyPair.js +35 -21
- package/browser/dist/stringify/stringifyString.js +41 -43
- package/browser/dist/util.js +3 -0
- package/browser/dist/visit.js +150 -62
- package/dist/compose/compose-doc.js +3 -2
- package/dist/compose/compose-node.d.ts +1 -0
- package/dist/compose/compose-node.js +14 -3
- package/dist/compose/compose-scalar.js +16 -9
- package/dist/compose/composer.d.ts +1 -1
- package/dist/compose/composer.js +8 -9
- package/dist/compose/resolve-block-map.js +19 -5
- package/dist/compose/resolve-block-scalar.js +12 -3
- package/dist/compose/resolve-block-seq.js +5 -0
- package/dist/compose/resolve-flow-collection.js +18 -6
- package/dist/compose/resolve-flow-scalar.js +9 -2
- package/dist/compose/resolve-props.d.ts +1 -1
- package/dist/compose/resolve-props.js +4 -0
- package/dist/compose/util-flow-indent-check.d.ts +3 -0
- package/dist/compose/util-flow-indent-check.js +17 -0
- package/dist/doc/Document.d.ts +13 -4
- package/dist/doc/Document.js +79 -22
- package/dist/doc/anchors.d.ts +2 -2
- package/dist/doc/anchors.js +2 -2
- package/dist/doc/createNode.d.ts +3 -2
- package/dist/doc/createNode.js +11 -6
- package/dist/doc/directives.d.ts +5 -2
- package/dist/doc/directives.js +11 -3
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -2
- package/dist/node_modules/tslib/tslib.es6.js +76 -0
- package/dist/nodes/Alias.d.ts +7 -3
- package/dist/nodes/Collection.d.ts +10 -4
- package/dist/nodes/Collection.js +27 -14
- package/dist/nodes/Node.d.ts +6 -1
- package/dist/nodes/Node.js +7 -0
- package/dist/nodes/Pair.d.ts +7 -2
- package/dist/nodes/Pair.js +10 -2
- package/dist/nodes/Scalar.d.ts +2 -0
- package/dist/nodes/Scalar.js +1 -1
- package/dist/nodes/YAMLMap.d.ts +5 -1
- package/dist/nodes/YAMLMap.js +6 -5
- package/dist/nodes/YAMLSeq.d.ts +2 -0
- package/dist/nodes/YAMLSeq.js +2 -2
- package/dist/nodes/addPairToJSMap.js +2 -1
- package/dist/nodes/toJS.js +3 -1
- package/dist/options.d.ts +67 -15
- package/dist/parse/cst-scalar.d.ts +6 -0
- package/dist/parse/cst-scalar.js +2 -6
- package/dist/parse/cst-visit.js +2 -2
- package/dist/parse/lexer.d.ts +2 -0
- package/dist/parse/lexer.js +50 -22
- package/dist/parse/parser.js +121 -45
- package/dist/public-api.js +4 -5
- package/dist/schema/Schema.d.ts +6 -4
- package/dist/schema/Schema.js +18 -3
- package/dist/schema/common/null.js +3 -1
- package/dist/schema/core/float.js +4 -1
- package/dist/schema/tags.d.ts +1 -2
- package/dist/schema/tags.js +17 -13
- package/dist/schema/yaml-1.1/float.js +4 -1
- package/dist/schema/yaml-1.1/omap.js +1 -1
- package/dist/schema/yaml-1.1/pairs.js +2 -1
- package/dist/stringify/stringify.d.ts +5 -3
- package/dist/stringify/stringify.js +53 -23
- package/dist/stringify/stringifyCollection.d.ts +2 -6
- package/dist/stringify/stringifyCollection.js +114 -84
- package/dist/stringify/stringifyComment.d.ts +10 -2
- package/dist/stringify/stringifyComment.js +19 -12
- package/dist/stringify/stringifyDocument.js +36 -14
- package/dist/stringify/stringifyPair.js +34 -20
- package/dist/stringify/stringifyString.js +41 -43
- package/dist/test-events.d.ts +1 -1
- package/dist/test-events.js +13 -12
- package/dist/util.d.ts +3 -0
- package/dist/util.js +6 -0
- package/dist/visit.d.ts +49 -10
- package/dist/visit.js +149 -60
- package/package.json +12 -10
- package/util.d.ts +3 -0
- package/browser/dist/options.js +0 -17
- package/dist/options.js +0 -19
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import { Alias } from '../nodes/Alias.js';
|
|
2
|
-
import { isNode, isPair, MAP, SEQ } from '../nodes/Node.js';
|
|
2
|
+
import { isNode, isPair, MAP, SEQ, isDocument } from '../nodes/Node.js';
|
|
3
3
|
import { Scalar } from '../nodes/Scalar.js';
|
|
4
4
|
|
|
5
5
|
const defaultTagPrefix = 'tag:yaml.org,2002:';
|
|
6
6
|
function findTagObject(value, tagName, tags) {
|
|
7
|
+
var _a;
|
|
7
8
|
if (tagName) {
|
|
8
9
|
const match = tags.filter(t => t.tag === tagName);
|
|
9
|
-
const tagObj = match.find(t => !t.format)
|
|
10
|
+
const tagObj = (_a = match.find(t => !t.format)) !== null && _a !== void 0 ? _a : match[0];
|
|
10
11
|
if (!tagObj)
|
|
11
12
|
throw new Error(`Tag ${tagName} not found`);
|
|
12
13
|
return tagObj;
|
|
13
14
|
}
|
|
14
|
-
return tags.find(t => t.identify
|
|
15
|
+
return tags.find(t => { var _a; return ((_a = t.identify) === null || _a === void 0 ? void 0 : _a.call(t, value)) && !t.format; });
|
|
15
16
|
}
|
|
16
17
|
function createNode(value, tagName, ctx) {
|
|
17
18
|
var _a, _b;
|
|
19
|
+
if (isDocument(value))
|
|
20
|
+
value = value.contents;
|
|
18
21
|
if (isNode(value))
|
|
19
22
|
return value;
|
|
20
23
|
if (isPair(value)) {
|
|
@@ -30,11 +33,11 @@ function createNode(value, tagName, ctx) {
|
|
|
30
33
|
// https://tc39.es/ecma262/#sec-serializejsonproperty
|
|
31
34
|
value = value.valueOf();
|
|
32
35
|
}
|
|
33
|
-
const { onAnchor, onTagObj, schema, sourceObjects } = ctx;
|
|
36
|
+
const { aliasDuplicateObjects, onAnchor, onTagObj, schema, sourceObjects } = ctx;
|
|
34
37
|
// Detect duplicate references to the same object & use Alias nodes for all
|
|
35
38
|
// after first. The `ref` wrapper allows for circular references to resolve.
|
|
36
39
|
let ref = undefined;
|
|
37
|
-
if (value && typeof value === 'object') {
|
|
40
|
+
if (aliasDuplicateObjects && value && typeof value === 'object') {
|
|
38
41
|
ref = sourceObjects.get(value);
|
|
39
42
|
if (ref) {
|
|
40
43
|
if (!ref.anchor)
|
|
@@ -46,12 +49,14 @@ function createNode(value, tagName, ctx) {
|
|
|
46
49
|
sourceObjects.set(value, ref);
|
|
47
50
|
}
|
|
48
51
|
}
|
|
49
|
-
if (tagName
|
|
52
|
+
if (tagName === null || tagName === void 0 ? void 0 : tagName.startsWith('!!'))
|
|
50
53
|
tagName = defaultTagPrefix + tagName.slice(2);
|
|
51
54
|
let tagObj = findTagObject(value, tagName, schema.tags);
|
|
52
55
|
if (!tagObj) {
|
|
53
|
-
if (value && typeof value.toJSON === 'function')
|
|
56
|
+
if (value && typeof value.toJSON === 'function') {
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
54
58
|
value = value.toJSON();
|
|
59
|
+
}
|
|
55
60
|
if (!value || typeof value !== 'object') {
|
|
56
61
|
const node = new Scalar(value);
|
|
57
62
|
if (ref)
|
|
@@ -16,10 +16,17 @@ class Directives {
|
|
|
16
16
|
* The directives-end/doc-start marker `---`. If `null`, a marker may still be
|
|
17
17
|
* included in the document's stringified representation.
|
|
18
18
|
*/
|
|
19
|
-
this.
|
|
19
|
+
this.docStart = null;
|
|
20
|
+
/** The doc-end marker `...`. */
|
|
21
|
+
this.docEnd = false;
|
|
20
22
|
this.yaml = Object.assign({}, Directives.defaultYaml, yaml);
|
|
21
23
|
this.tags = Object.assign({}, Directives.defaultTags, tags);
|
|
22
24
|
}
|
|
25
|
+
clone() {
|
|
26
|
+
const copy = new Directives(this.yaml, this.tags);
|
|
27
|
+
copy.docStart = this.docStart;
|
|
28
|
+
return copy;
|
|
29
|
+
}
|
|
23
30
|
/**
|
|
24
31
|
* During parsing, get a Directives instance for the current document and
|
|
25
32
|
* update the stream state according to the current version's spec.
|
|
@@ -66,7 +73,7 @@ class Directives {
|
|
|
66
73
|
}
|
|
67
74
|
case '%YAML': {
|
|
68
75
|
this.yaml.explicit = true;
|
|
69
|
-
if (parts.length
|
|
76
|
+
if (parts.length !== 1) {
|
|
70
77
|
onError(0, '%YAML directive should contain exactly one part');
|
|
71
78
|
return false;
|
|
72
79
|
}
|
|
@@ -76,7 +83,8 @@ class Directives {
|
|
|
76
83
|
return true;
|
|
77
84
|
}
|
|
78
85
|
else {
|
|
79
|
-
|
|
86
|
+
const isValid = /^\d+\.\d+$/.test(version);
|
|
87
|
+
onError(6, `Unsupported YAML version ${version}`, isValid);
|
|
80
88
|
return false;
|
|
81
89
|
}
|
|
82
90
|
}
|
package/browser/dist/index.js
CHANGED
|
@@ -8,11 +8,10 @@ export { Pair } from './nodes/Pair.js';
|
|
|
8
8
|
export { Scalar } from './nodes/Scalar.js';
|
|
9
9
|
export { YAMLMap } from './nodes/YAMLMap.js';
|
|
10
10
|
export { YAMLSeq } from './nodes/YAMLSeq.js';
|
|
11
|
-
export { defaultOptions } from './options.js';
|
|
12
11
|
import * as cst from './parse/cst.js';
|
|
13
12
|
export { cst as CST };
|
|
14
13
|
export { Lexer } from './parse/lexer.js';
|
|
15
14
|
export { LineCounter } from './parse/line-counter.js';
|
|
16
15
|
export { Parser } from './parse/parser.js';
|
|
17
16
|
export { parse, parseAllDocuments, parseDocument, stringify } from './public-api.js';
|
|
18
|
-
export { visit } from './visit.js';
|
|
17
|
+
export { visit, visitAsync } from './visit.js';
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/*! *****************************************************************************
|
|
2
|
+
Copyright (c) Microsoft Corporation.
|
|
3
|
+
|
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
+
purpose with or without fee is hereby granted.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
9
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
11
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
+
***************************************************************************** */
|
|
15
|
+
|
|
16
|
+
/* global Reflect, Promise */
|
|
17
|
+
var extendStatics = function (d, b) {
|
|
18
|
+
extendStatics = Object.setPrototypeOf || {
|
|
19
|
+
__proto__: []
|
|
20
|
+
} instanceof Array && function (d, b) {
|
|
21
|
+
d.__proto__ = b;
|
|
22
|
+
} || function (d, b) {
|
|
23
|
+
for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return extendStatics(d, b);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
function __extends(d, b) {
|
|
30
|
+
if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
31
|
+
extendStatics(d, b);
|
|
32
|
+
|
|
33
|
+
function __() {
|
|
34
|
+
this.constructor = d;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
38
|
+
}
|
|
39
|
+
function __generator(thisArg, body) {
|
|
40
|
+
var _ = {
|
|
41
|
+
label: 0,
|
|
42
|
+
sent: function () {
|
|
43
|
+
if (t[0] & 1) throw t[1];
|
|
44
|
+
return t[1];
|
|
45
|
+
},
|
|
46
|
+
trys: [],
|
|
47
|
+
ops: []
|
|
48
|
+
},
|
|
49
|
+
f,
|
|
50
|
+
y,
|
|
51
|
+
t,
|
|
52
|
+
g;
|
|
53
|
+
return g = {
|
|
54
|
+
next: verb(0),
|
|
55
|
+
"throw": verb(1),
|
|
56
|
+
"return": verb(2)
|
|
57
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
58
|
+
return this;
|
|
59
|
+
}), g;
|
|
60
|
+
|
|
61
|
+
function verb(n) {
|
|
62
|
+
return function (v) {
|
|
63
|
+
return step([n, v]);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function step(op) {
|
|
68
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
69
|
+
|
|
70
|
+
while (_) try {
|
|
71
|
+
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;
|
|
72
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
73
|
+
|
|
74
|
+
switch (op[0]) {
|
|
75
|
+
case 0:
|
|
76
|
+
case 1:
|
|
77
|
+
t = op;
|
|
78
|
+
break;
|
|
79
|
+
|
|
80
|
+
case 4:
|
|
81
|
+
_.label++;
|
|
82
|
+
return {
|
|
83
|
+
value: op[1],
|
|
84
|
+
done: false
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
case 5:
|
|
88
|
+
_.label++;
|
|
89
|
+
y = op[1];
|
|
90
|
+
op = [0];
|
|
91
|
+
continue;
|
|
92
|
+
|
|
93
|
+
case 7:
|
|
94
|
+
op = _.ops.pop();
|
|
95
|
+
|
|
96
|
+
_.trys.pop();
|
|
97
|
+
|
|
98
|
+
continue;
|
|
99
|
+
|
|
100
|
+
default:
|
|
101
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
102
|
+
_ = 0;
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
107
|
+
_.label = op[1];
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
112
|
+
_.label = t[1];
|
|
113
|
+
t = op;
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (t && _.label < t[2]) {
|
|
118
|
+
_.label = t[2];
|
|
119
|
+
|
|
120
|
+
_.ops.push(op);
|
|
121
|
+
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (t[2]) _.ops.pop();
|
|
126
|
+
|
|
127
|
+
_.trys.pop();
|
|
128
|
+
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
op = body.call(thisArg, _);
|
|
133
|
+
} catch (e) {
|
|
134
|
+
op = [6, e];
|
|
135
|
+
y = 0;
|
|
136
|
+
} finally {
|
|
137
|
+
f = t = 0;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (op[0] & 5) throw op[1];
|
|
141
|
+
return {
|
|
142
|
+
value: op[0] ? op[1] : void 0,
|
|
143
|
+
done: true
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function __values(o) {
|
|
148
|
+
var s = typeof Symbol === "function" && Symbol.iterator,
|
|
149
|
+
m = s && o[s],
|
|
150
|
+
i = 0;
|
|
151
|
+
if (m) return m.call(o);
|
|
152
|
+
if (o && typeof o.length === "number") return {
|
|
153
|
+
next: function () {
|
|
154
|
+
if (o && i >= o.length) o = void 0;
|
|
155
|
+
return {
|
|
156
|
+
value: o && o[i++],
|
|
157
|
+
done: !o
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export { __extends, __generator, __values };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createNode } from '../doc/createNode.js';
|
|
2
|
-
import { NodeBase, isCollection, isScalar
|
|
2
|
+
import { NodeBase, isNode, isPair, isCollection, isScalar } from './Node.js';
|
|
3
3
|
|
|
4
4
|
function collectionFromPath(schema, path, value) {
|
|
5
5
|
let v = value;
|
|
@@ -11,19 +11,14 @@ function collectionFromPath(schema, path, value) {
|
|
|
11
11
|
v = a;
|
|
12
12
|
}
|
|
13
13
|
else {
|
|
14
|
-
|
|
15
|
-
Object.defineProperty(o, typeof k === 'symbol' ? k : String(k), {
|
|
16
|
-
value: v,
|
|
17
|
-
writable: true,
|
|
18
|
-
enumerable: true,
|
|
19
|
-
configurable: true
|
|
20
|
-
});
|
|
21
|
-
v = o;
|
|
14
|
+
v = new Map([[k, v]]);
|
|
22
15
|
}
|
|
23
16
|
}
|
|
24
17
|
return createNode(v, undefined, {
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
aliasDuplicateObjects: false,
|
|
19
|
+
keepUndefined: false,
|
|
20
|
+
onAnchor: () => {
|
|
21
|
+
throw new Error('This should not happen, please report a bug.');
|
|
27
22
|
},
|
|
28
23
|
schema,
|
|
29
24
|
sourceObjects: new Map()
|
|
@@ -42,6 +37,20 @@ class Collection extends NodeBase {
|
|
|
42
37
|
writable: true
|
|
43
38
|
});
|
|
44
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Create a copy of this collection.
|
|
42
|
+
*
|
|
43
|
+
* @param schema - If defined, overwrites the original's schema
|
|
44
|
+
*/
|
|
45
|
+
clone(schema) {
|
|
46
|
+
const copy = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));
|
|
47
|
+
if (schema)
|
|
48
|
+
copy.schema = schema;
|
|
49
|
+
copy.items = copy.items.map(it => isNode(it) || isPair(it) ? it.clone(schema) : it);
|
|
50
|
+
if (this.range)
|
|
51
|
+
copy.range = this.range.slice();
|
|
52
|
+
return copy;
|
|
53
|
+
}
|
|
45
54
|
/**
|
|
46
55
|
* Adds a value to the collection. For `!!map` and `!!omap` the value must
|
|
47
56
|
* be a Pair instance or a `{ key, value }` object, which may not have a key
|
|
@@ -65,7 +74,8 @@ class Collection extends NodeBase {
|
|
|
65
74
|
* Removes a value from the collection.
|
|
66
75
|
* @returns `true` if the item was found and removed.
|
|
67
76
|
*/
|
|
68
|
-
deleteIn(
|
|
77
|
+
deleteIn(path) {
|
|
78
|
+
const [key, ...rest] = path;
|
|
69
79
|
if (rest.length === 0)
|
|
70
80
|
return this.delete(key);
|
|
71
81
|
const node = this.get(key, true);
|
|
@@ -79,7 +89,8 @@ class Collection extends NodeBase {
|
|
|
79
89
|
* scalar values from their surrounding node; to disable set `keepScalar` to
|
|
80
90
|
* `true` (collections are always returned intact).
|
|
81
91
|
*/
|
|
82
|
-
getIn(
|
|
92
|
+
getIn(path, keepScalar) {
|
|
93
|
+
const [key, ...rest] = path;
|
|
83
94
|
const node = this.get(key, true);
|
|
84
95
|
if (rest.length === 0)
|
|
85
96
|
return !keepScalar && isScalar(node) ? node.value : node;
|
|
@@ -103,7 +114,8 @@ class Collection extends NodeBase {
|
|
|
103
114
|
/**
|
|
104
115
|
* Checks if the collection includes a value with the key `key`.
|
|
105
116
|
*/
|
|
106
|
-
hasIn(
|
|
117
|
+
hasIn(path) {
|
|
118
|
+
const [key, ...rest] = path;
|
|
107
119
|
if (rest.length === 0)
|
|
108
120
|
return this.has(key);
|
|
109
121
|
const node = this.get(key, true);
|
|
@@ -113,7 +125,8 @@ class Collection extends NodeBase {
|
|
|
113
125
|
* Sets a value in this collection. For `!!set`, `value` needs to be a
|
|
114
126
|
* boolean to add/remove the item from the set.
|
|
115
127
|
*/
|
|
116
|
-
setIn(
|
|
128
|
+
setIn(path, value) {
|
|
129
|
+
const [key, ...rest] = path;
|
|
117
130
|
if (rest.length === 0) {
|
|
118
131
|
this.set(key, value);
|
|
119
132
|
}
|
|
@@ -36,6 +36,13 @@ class NodeBase {
|
|
|
36
36
|
constructor(type) {
|
|
37
37
|
Object.defineProperty(this, NODE_TYPE, { value: type });
|
|
38
38
|
}
|
|
39
|
+
/** Create a copy of this node. */
|
|
40
|
+
clone() {
|
|
41
|
+
const copy = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));
|
|
42
|
+
if (this.range)
|
|
43
|
+
copy.range = this.range.slice();
|
|
44
|
+
return copy;
|
|
45
|
+
}
|
|
39
46
|
}
|
|
40
47
|
|
|
41
48
|
export { ALIAS, DOC, MAP, NODE_TYPE, NodeBase, PAIR, SCALAR, SEQ, hasAnchor, isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createNode } from '../doc/createNode.js';
|
|
2
2
|
import { stringifyPair } from '../stringify/stringifyPair.js';
|
|
3
3
|
import { addPairToJSMap } from './addPairToJSMap.js';
|
|
4
|
-
import { NODE_TYPE, PAIR } from './Node.js';
|
|
4
|
+
import { NODE_TYPE, PAIR, isNode } from './Node.js';
|
|
5
5
|
|
|
6
6
|
function createPair(key, value, ctx) {
|
|
7
7
|
const k = createNode(key, undefined, ctx);
|
|
@@ -14,12 +14,20 @@ class Pair {
|
|
|
14
14
|
this.key = key;
|
|
15
15
|
this.value = value;
|
|
16
16
|
}
|
|
17
|
+
clone(schema) {
|
|
18
|
+
let { key, value } = this;
|
|
19
|
+
if (isNode(key))
|
|
20
|
+
key = key.clone(schema);
|
|
21
|
+
if (isNode(value))
|
|
22
|
+
value = value.clone(schema);
|
|
23
|
+
return new Pair(key, value);
|
|
24
|
+
}
|
|
17
25
|
toJSON(_, ctx) {
|
|
18
|
-
const pair = ctx
|
|
26
|
+
const pair = (ctx === null || ctx === void 0 ? void 0 : ctx.mapAsMap) ? new Map() : {};
|
|
19
27
|
return addPairToJSMap(ctx, pair, this);
|
|
20
28
|
}
|
|
21
29
|
toString(ctx, onComment, onChompKeep) {
|
|
22
|
-
return ctx
|
|
30
|
+
return (ctx === null || ctx === void 0 ? void 0 : ctx.doc)
|
|
23
31
|
? stringifyPair(this, ctx, onComment, onChompKeep)
|
|
24
32
|
: JSON.stringify(this);
|
|
25
33
|
}
|
|
@@ -8,7 +8,7 @@ class Scalar extends NodeBase {
|
|
|
8
8
|
this.value = value;
|
|
9
9
|
}
|
|
10
10
|
toJSON(arg, ctx) {
|
|
11
|
-
return ctx
|
|
11
|
+
return (ctx === null || ctx === void 0 ? void 0 : ctx.keep) ? this.value : toJS(this.value, arg, ctx);
|
|
12
12
|
}
|
|
13
13
|
toString() {
|
|
14
14
|
return String(this.value);
|
|
@@ -32,6 +32,7 @@ class YAMLMap extends Collection {
|
|
|
32
32
|
* collection will throw. Otherwise, overwrites the previous value.
|
|
33
33
|
*/
|
|
34
34
|
add(pair, overwrite) {
|
|
35
|
+
var _a;
|
|
35
36
|
let _pair;
|
|
36
37
|
if (isPair(pair))
|
|
37
38
|
_pair = pair;
|
|
@@ -42,7 +43,7 @@ class YAMLMap extends Collection {
|
|
|
42
43
|
else
|
|
43
44
|
_pair = new Pair(pair.key, pair.value);
|
|
44
45
|
const prev = findPair(this.items, _pair.key);
|
|
45
|
-
const sortEntries = this.schema
|
|
46
|
+
const sortEntries = (_a = this.schema) === null || _a === void 0 ? void 0 : _a.sortMapEntries;
|
|
46
47
|
if (prev) {
|
|
47
48
|
if (!overwrite)
|
|
48
49
|
throw new Error(`Key ${_pair.key} already set`);
|
|
@@ -72,7 +73,7 @@ class YAMLMap extends Collection {
|
|
|
72
73
|
}
|
|
73
74
|
get(key, keepScalar) {
|
|
74
75
|
const it = findPair(this.items, key);
|
|
75
|
-
const node = it
|
|
76
|
+
const node = it === null || it === void 0 ? void 0 : it.value;
|
|
76
77
|
return !keepScalar && isScalar(node) ? node.value : node;
|
|
77
78
|
}
|
|
78
79
|
has(key) {
|
|
@@ -87,8 +88,8 @@ class YAMLMap extends Collection {
|
|
|
87
88
|
* @returns Instance of Type, Map, or Object
|
|
88
89
|
*/
|
|
89
90
|
toJSON(_, ctx, Type) {
|
|
90
|
-
const map = Type ? new Type() : ctx
|
|
91
|
-
if (ctx
|
|
91
|
+
const map = Type ? new Type() : (ctx === null || ctx === void 0 ? void 0 : ctx.mapAsMap) ? new Map() : {};
|
|
92
|
+
if (ctx === null || ctx === void 0 ? void 0 : ctx.onCreate)
|
|
92
93
|
ctx.onCreate(map);
|
|
93
94
|
for (const item of this.items)
|
|
94
95
|
addPairToJSMap(ctx, map, item);
|
|
@@ -104,7 +105,7 @@ class YAMLMap extends Collection {
|
|
|
104
105
|
if (!ctx.allNullValues && this.hasAllNullValues(false))
|
|
105
106
|
ctx = Object.assign({}, ctx, { allNullValues: true });
|
|
106
107
|
return stringifyCollection(this, ctx, {
|
|
107
|
-
|
|
108
|
+
blockItemPrefix: '',
|
|
108
109
|
flowChars: { start: '{', end: '}' },
|
|
109
110
|
itemIndent: ctx.indent || '',
|
|
110
111
|
onChompKeep,
|
|
@@ -74,7 +74,7 @@ class YAMLSeq extends Collection {
|
|
|
74
74
|
}
|
|
75
75
|
toJSON(_, ctx) {
|
|
76
76
|
const seq = [];
|
|
77
|
-
if (ctx
|
|
77
|
+
if (ctx === null || ctx === void 0 ? void 0 : ctx.onCreate)
|
|
78
78
|
ctx.onCreate(seq);
|
|
79
79
|
let i = 0;
|
|
80
80
|
for (const item of this.items)
|
|
@@ -85,7 +85,7 @@ class YAMLSeq extends Collection {
|
|
|
85
85
|
if (!ctx)
|
|
86
86
|
return JSON.stringify(this);
|
|
87
87
|
return stringifyCollection(this, ctx, {
|
|
88
|
-
|
|
88
|
+
blockItemPrefix: '- ',
|
|
89
89
|
flowChars: { start: '[', end: ']' },
|
|
90
90
|
itemIndent: (ctx.indent || '') + ' ',
|
|
91
91
|
onChompKeep,
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { warn } from '../log.js';
|
|
2
2
|
import { createStringifyContext } from '../stringify/stringify.js';
|
|
3
|
-
import {
|
|
3
|
+
import { isAlias, isSeq, isScalar, isMap, isNode } from './Node.js';
|
|
4
4
|
import { Scalar } from './Scalar.js';
|
|
5
5
|
import { toJS } from './toJS.js';
|
|
6
6
|
|
|
7
7
|
const MERGE_KEY = '<<';
|
|
8
8
|
function addPairToJSMap(ctx, map, { key, value }) {
|
|
9
|
-
if (ctx
|
|
9
|
+
if ((ctx === null || ctx === void 0 ? void 0 : ctx.doc.schema.merge) && isMergeKey(key)) {
|
|
10
|
+
value = isAlias(value) ? value.resolve(ctx.doc) : value;
|
|
10
11
|
if (isSeq(value))
|
|
11
12
|
for (const it of value.items)
|
|
12
13
|
mergeToJSMap(ctx, map, it);
|
|
@@ -11,9 +11,11 @@ import { hasAnchor } from './Node.js';
|
|
|
11
11
|
* stringification.
|
|
12
12
|
*/
|
|
13
13
|
function toJS(value, arg, ctx) {
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
14
15
|
if (Array.isArray(value))
|
|
15
16
|
return value.map((v, i) => toJS(v, String(i), ctx));
|
|
16
17
|
if (value && typeof value.toJSON === 'function') {
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
17
19
|
if (!ctx || !hasAnchor(value))
|
|
18
20
|
return value.toJSON(arg, ctx);
|
|
19
21
|
const data = { aliasCount: 0, count: 1, res: undefined };
|
|
@@ -27,7 +29,7 @@ function toJS(value, arg, ctx) {
|
|
|
27
29
|
ctx.onCreate(res);
|
|
28
30
|
return res;
|
|
29
31
|
}
|
|
30
|
-
if (typeof value === 'bigint' && !(ctx
|
|
32
|
+
if (typeof value === 'bigint' && !(ctx === null || ctx === void 0 ? void 0 : ctx.keep))
|
|
31
33
|
return Number(value);
|
|
32
34
|
return value;
|
|
33
35
|
}
|
|
@@ -3,10 +3,6 @@ import { resolveFlowScalar } from '../compose/resolve-flow-scalar.js';
|
|
|
3
3
|
import { YAMLParseError } from '../errors.js';
|
|
4
4
|
import { stringifyString } from '../stringify/stringifyString.js';
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* If `token` is a CST flow or block scalar, determine its string value and a few other attributes.
|
|
8
|
-
* Otherwise, return `null`.
|
|
9
|
-
*/
|
|
10
6
|
function resolveAsScalar(token, strict = true, onError) {
|
|
11
7
|
if (token) {
|
|
12
8
|
const _onError = (pos, code, message) => {
|
|
@@ -48,7 +44,7 @@ function createScalarToken(value, context) {
|
|
|
48
44
|
implicitKey,
|
|
49
45
|
indent: indent > 0 ? ' '.repeat(indent) : '',
|
|
50
46
|
inFlow,
|
|
51
|
-
options: { lineWidth: -1 }
|
|
47
|
+
options: { blockQuote: true, lineWidth: -1 }
|
|
52
48
|
});
|
|
53
49
|
const end = (_a = context.end) !== null && _a !== void 0 ? _a : [
|
|
54
50
|
{ type: 'newline', offset: -1, indent, source: '\n' }
|
|
@@ -117,7 +113,7 @@ function setScalarValue(token, value, context = {}) {
|
|
|
117
113
|
implicitKey: implicitKey || indent === null,
|
|
118
114
|
indent: indent !== null && indent > 0 ? ' '.repeat(indent) : '',
|
|
119
115
|
inFlow,
|
|
120
|
-
options: { lineWidth: -1 }
|
|
116
|
+
options: { blockQuote: true, lineWidth: -1 }
|
|
121
117
|
});
|
|
122
118
|
switch (source[0]) {
|
|
123
119
|
case '|':
|
|
@@ -47,7 +47,7 @@ visit.REMOVE = REMOVE;
|
|
|
47
47
|
visit.itemAtPath = (cst, path) => {
|
|
48
48
|
let item = cst;
|
|
49
49
|
for (const [field, index] of path) {
|
|
50
|
-
const tok = item
|
|
50
|
+
const tok = item === null || item === void 0 ? void 0 : item[field];
|
|
51
51
|
if (tok && 'items' in tok) {
|
|
52
52
|
item = tok.items[index];
|
|
53
53
|
}
|
|
@@ -64,7 +64,7 @@ visit.itemAtPath = (cst, path) => {
|
|
|
64
64
|
visit.parentCollection = (cst, path) => {
|
|
65
65
|
const parent = visit.itemAtPath(cst, path.slice(0, -1));
|
|
66
66
|
const field = path[path.length - 1][0];
|
|
67
|
-
const coll = parent
|
|
67
|
+
const coll = parent === null || parent === void 0 ? void 0 : parent[field];
|
|
68
68
|
if (coll && 'items' in coll)
|
|
69
69
|
return coll;
|
|
70
70
|
throw new Error('Parent collection not found');
|