yaml 1.4.0 → 1.5.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 +3 -5
- package/browser/dist/Anchors.js +1 -3
- package/browser/dist/Document.js +94 -37
- package/browser/dist/constants.js +34 -0
- package/browser/dist/cst/Alias.js +1 -3
- package/browser/dist/cst/BlankLine.js +5 -7
- package/browser/dist/cst/BlockValue.js +4 -4
- package/browser/dist/cst/Collection.js +7 -7
- package/browser/dist/cst/CollectionItem.js +6 -8
- package/browser/dist/cst/Comment.js +5 -7
- package/browser/dist/cst/Directive.js +5 -7
- package/browser/dist/cst/Document.js +8 -10
- package/browser/dist/cst/FlowCollection.js +5 -7
- package/browser/dist/cst/Node.js +12 -40
- package/browser/dist/cst/ParseContext.js +32 -34
- package/browser/dist/cst/PlainValue.js +1 -3
- package/browser/dist/cst/QuoteDouble.js +1 -3
- package/browser/dist/cst/QuoteSingle.js +1 -3
- package/browser/dist/cst/Range.js +1 -3
- package/browser/dist/cst/getLinePos.js +1 -4
- package/browser/dist/cst/parse.js +1 -4
- package/browser/dist/deprecation.js +34 -0
- package/browser/dist/errors.js +50 -59
- package/browser/dist/index.js +5 -4
- package/browser/dist/listTagNames.js +1 -3
- package/browser/dist/schema/Alias.js +85 -10
- package/browser/dist/schema/Map.js +14 -121
- package/browser/dist/schema/Merge.js +74 -1
- package/browser/dist/schema/Node.js +1 -3
- package/browser/dist/schema/Pair.js +36 -22
- package/browser/dist/schema/Scalar.js +1 -3
- package/browser/dist/schema/Seq.js +1 -3
- package/browser/dist/schema/index.js +61 -45
- package/browser/dist/schema/parseMap.js +18 -21
- package/browser/dist/schema/parseSeq.js +9 -12
- package/browser/dist/stringify.js +54 -39
- package/browser/dist/{schema → tags}/core.js +32 -20
- package/browser/dist/tags/failsafe/index.js +17 -0
- package/browser/dist/tags/failsafe/map.js +65 -0
- package/browser/dist/tags/failsafe/seq.js +54 -0
- package/browser/dist/{schema/_string.js → tags/failsafe/string.js} +11 -11
- package/browser/dist/tags/index.js +50 -0
- package/browser/dist/{schema → tags}/json.js +8 -8
- package/browser/dist/tags/options.js +35 -0
- package/browser/dist/{schema/_binary.js → tags/yaml-1.1/binary.js} +16 -22
- package/browser/dist/{schema/yaml-1.1.js → tags/yaml-1.1/index.js} +43 -29
- package/browser/dist/{schema/_omap.js → tags/yaml-1.1/omap.js} +8 -11
- package/browser/dist/{schema/_pairs.js → tags/yaml-1.1/pairs.js} +8 -12
- package/browser/dist/tags/yaml-1.1/set.js +140 -0
- package/browser/dist/{schema/_timestamp.js → tags/yaml-1.1/timestamp.js} +4 -7
- package/browser/dist/test-events.js +1 -4
- package/browser/dist/toJSON.js +1 -4
- package/browser/index.js +1 -0
- package/browser/map.js +2 -1
- package/browser/pair.js +2 -1
- package/browser/parse-cst.js +1 -1
- package/browser/scalar.js +2 -1
- package/browser/schema.js +7 -4
- package/browser/seq.js +2 -1
- package/browser/types/binary.js +7 -1
- package/browser/types/omap.js +2 -1
- package/browser/types/pairs.js +2 -1
- package/browser/types/set.js +2 -1
- package/browser/types/timestamp.js +10 -1
- package/browser/types.js +11 -0
- package/browser/util.js +15 -0
- package/dist/Anchors.js +1 -3
- package/dist/Document.js +38 -25
- package/dist/constants.js +34 -0
- package/dist/cst/Alias.js +1 -3
- package/dist/cst/BlankLine.js +5 -7
- package/dist/cst/BlockValue.js +4 -4
- package/dist/cst/Collection.js +7 -7
- package/dist/cst/CollectionItem.js +6 -8
- package/dist/cst/Comment.js +5 -7
- package/dist/cst/Directive.js +5 -7
- package/dist/cst/Document.js +8 -10
- package/dist/cst/FlowCollection.js +5 -7
- package/dist/cst/Node.js +12 -40
- package/dist/cst/ParseContext.js +32 -34
- package/dist/cst/PlainValue.js +1 -3
- package/dist/cst/QuoteDouble.js +1 -3
- package/dist/cst/QuoteSingle.js +1 -3
- package/dist/cst/Range.js +1 -3
- package/dist/cst/getLinePos.js +1 -4
- package/dist/cst/parse.js +1 -4
- package/dist/deprecation.js +34 -0
- package/dist/errors.js +29 -35
- package/dist/index.js +5 -4
- package/dist/listTagNames.js +1 -3
- package/dist/schema/Alias.js +66 -12
- package/dist/schema/Map.js +9 -77
- package/dist/schema/Merge.js +31 -0
- package/dist/schema/Node.js +1 -3
- package/dist/schema/Pair.js +29 -15
- package/dist/schema/Scalar.js +1 -3
- package/dist/schema/Seq.js +1 -3
- package/dist/schema/index.js +55 -45
- package/dist/schema/parseMap.js +18 -21
- package/dist/schema/parseSeq.js +9 -12
- package/dist/stringify.js +46 -32
- package/dist/{schema → tags}/core.js +32 -19
- package/dist/tags/failsafe/index.js +17 -0
- package/dist/tags/failsafe/map.js +33 -0
- package/dist/tags/failsafe/seq.js +34 -0
- package/dist/tags/failsafe/string.js +40 -0
- package/dist/tags/index.js +50 -0
- package/dist/{schema → tags}/json.js +8 -8
- package/dist/tags/options.js +35 -0
- package/dist/{schema/_binary.js → tags/yaml-1.1/binary.js} +15 -21
- package/dist/{schema/yaml-1.1.js → tags/yaml-1.1/index.js} +43 -30
- package/dist/{schema/_omap.js → tags/yaml-1.1/omap.js} +8 -9
- package/dist/{schema/_pairs.js → tags/yaml-1.1/pairs.js} +8 -10
- package/dist/{schema/_set.js → tags/yaml-1.1/set.js} +9 -42
- package/dist/{schema/_timestamp.js → tags/yaml-1.1/timestamp.js} +4 -7
- package/dist/test-events.js +1 -4
- package/dist/toJSON.js +1 -4
- package/index.js +1 -0
- package/map.js +2 -1
- package/package.json +17 -15
- package/pair.js +2 -1
- package/parse-cst.js +1 -1
- package/scalar.js +2 -1
- package/schema.js +7 -4
- package/seq.js +2 -1
- package/types/binary.js +7 -1
- package/types/omap.js +2 -1
- package/types/pairs.js +2 -1
- package/types/set.js +2 -1
- package/types/timestamp.js +10 -1
- package/types.js +11 -0
- package/util.js +15 -0
- package/browser/dist/schema/_set.js +0 -215
- package/browser/dist/schema/failsafe.js +0 -125
- package/dist/schema/_string.js +0 -40
- package/dist/schema/failsafe.js +0 -74
|
@@ -19,11 +19,60 @@ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits
|
|
|
19
19
|
|
|
20
20
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
21
21
|
|
|
22
|
-
var
|
|
22
|
+
var _constants = require("../constants");
|
|
23
|
+
|
|
24
|
+
var _errors = require("../errors");
|
|
23
25
|
|
|
24
26
|
var _toJSON2 = _interopRequireDefault(require("../toJSON"));
|
|
25
27
|
|
|
26
|
-
var
|
|
28
|
+
var _Collection = _interopRequireDefault(require("./Collection"));
|
|
29
|
+
|
|
30
|
+
var _Node2 = _interopRequireDefault(require("./Node"));
|
|
31
|
+
|
|
32
|
+
var _Pair = _interopRequireDefault(require("./Pair"));
|
|
33
|
+
|
|
34
|
+
var getAliasCount = function getAliasCount(node, anchors) {
|
|
35
|
+
if (node instanceof Alias) {
|
|
36
|
+
var anchor = anchors.find(function (a) {
|
|
37
|
+
return a.node === node.source;
|
|
38
|
+
});
|
|
39
|
+
return anchor.count * anchor.aliasCount;
|
|
40
|
+
} else if (node instanceof _Collection.default) {
|
|
41
|
+
var count = 0;
|
|
42
|
+
var _iteratorNormalCompletion = true;
|
|
43
|
+
var _didIteratorError = false;
|
|
44
|
+
var _iteratorError = undefined;
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
for (var _iterator = node.items[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
48
|
+
var item = _step.value;
|
|
49
|
+
var c = getAliasCount(item, anchors);
|
|
50
|
+
if (c > count) count = c;
|
|
51
|
+
}
|
|
52
|
+
} catch (err) {
|
|
53
|
+
_didIteratorError = true;
|
|
54
|
+
_iteratorError = err;
|
|
55
|
+
} finally {
|
|
56
|
+
try {
|
|
57
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
58
|
+
_iterator.return();
|
|
59
|
+
}
|
|
60
|
+
} finally {
|
|
61
|
+
if (_didIteratorError) {
|
|
62
|
+
throw _iteratorError;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return count;
|
|
68
|
+
} else if (node instanceof _Pair.default) {
|
|
69
|
+
var kc = getAliasCount(node.key, anchors);
|
|
70
|
+
var vc = getAliasCount(node.value, anchors);
|
|
71
|
+
return Math.max(kc, vc);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return 1;
|
|
75
|
+
};
|
|
27
76
|
|
|
28
77
|
var Alias =
|
|
29
78
|
/*#__PURE__*/
|
|
@@ -36,10 +85,12 @@ function (_Node) {
|
|
|
36
85
|
source = _ref.source;
|
|
37
86
|
var anchors = _ref2.anchors,
|
|
38
87
|
doc = _ref2.doc,
|
|
39
|
-
implicitKey = _ref2.implicitKey
|
|
88
|
+
implicitKey = _ref2.implicitKey,
|
|
89
|
+
inStringifyKey = _ref2.inStringifyKey;
|
|
40
90
|
var anchor = Object.keys(anchors).find(function (a) {
|
|
41
91
|
return anchors[a] === source;
|
|
42
92
|
});
|
|
93
|
+
if (!anchor && inStringifyKey) anchor = doc.anchors.getName(source) || doc.anchors.newName();
|
|
43
94
|
if (anchor) return "*".concat(anchor).concat(implicitKey ? ' ' : '');
|
|
44
95
|
var msg = doc.anchors.getName(source) ? 'Alias node must be after source node' : 'Source node not found for alias node';
|
|
45
96
|
throw new Error("".concat(msg, " [").concat(range, "]"));
|
|
@@ -52,7 +103,7 @@ function (_Node) {
|
|
|
52
103
|
(0, _classCallCheck2.default)(this, Alias);
|
|
53
104
|
_this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(Alias).call(this));
|
|
54
105
|
_this.source = source;
|
|
55
|
-
_this.type =
|
|
106
|
+
_this.type = _constants.Type.ALIAS;
|
|
56
107
|
return _this;
|
|
57
108
|
}
|
|
58
109
|
|
|
@@ -61,10 +112,36 @@ function (_Node) {
|
|
|
61
112
|
value: function toJSON(arg, ctx) {
|
|
62
113
|
var _this2 = this;
|
|
63
114
|
|
|
64
|
-
|
|
115
|
+
if (!ctx) return (0, _toJSON2.default)(this.source, arg, ctx);
|
|
116
|
+
var anchors = ctx.anchors,
|
|
117
|
+
maxAliasCount = ctx.maxAliasCount;
|
|
118
|
+
var anchor = anchors.find(function (a) {
|
|
65
119
|
return a.node === _this2.source;
|
|
66
120
|
});
|
|
67
|
-
|
|
121
|
+
|
|
122
|
+
if (!anchor || !anchor.res) {
|
|
123
|
+
var msg = 'This should not happen: Alias anchor was not resolved?';
|
|
124
|
+
if (this.cstNode) throw new _errors.YAMLReferenceError(this.cstNode, msg);else throw new ReferenceError(msg);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (maxAliasCount >= 0) {
|
|
128
|
+
anchor.count += 1;
|
|
129
|
+
if (anchor.aliasCount === 0) anchor.aliasCount = getAliasCount(this.source, anchors);
|
|
130
|
+
|
|
131
|
+
if (anchor.count * anchor.aliasCount > maxAliasCount) {
|
|
132
|
+
var _msg = 'Excessive alias count indicates a resource exhaustion attack';
|
|
133
|
+
if (this.cstNode) throw new _errors.YAMLReferenceError(this.cstNode, _msg);else throw new ReferenceError(_msg);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return anchor.res;
|
|
138
|
+
} // Only called when stringifying an alias mapping key while constructing
|
|
139
|
+
// Object output.
|
|
140
|
+
|
|
141
|
+
}, {
|
|
142
|
+
key: "toString",
|
|
143
|
+
value: function toString(ctx) {
|
|
144
|
+
return Alias.stringify(this, ctx);
|
|
68
145
|
}
|
|
69
146
|
}, {
|
|
70
147
|
key: "tag",
|
|
@@ -73,9 +150,7 @@ function (_Node) {
|
|
|
73
150
|
}
|
|
74
151
|
}]);
|
|
75
152
|
return Alias;
|
|
76
|
-
}(
|
|
153
|
+
}(_Node2.default);
|
|
77
154
|
|
|
78
155
|
exports.default = Alias;
|
|
79
|
-
(0, _defineProperty2.default)(Alias, "default", true);
|
|
80
|
-
module.exports = exports.default;
|
|
81
|
-
module.exports.default = exports.default;
|
|
156
|
+
(0, _defineProperty2.default)(Alias, "default", true);
|
|
@@ -8,8 +8,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
8
8
|
exports.findPair = findPair;
|
|
9
9
|
exports.default = void 0;
|
|
10
10
|
|
|
11
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
12
|
-
|
|
13
11
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
14
12
|
|
|
15
13
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
@@ -22,17 +20,12 @@ var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
|
|
|
22
20
|
|
|
23
21
|
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
24
22
|
|
|
25
|
-
var _toJSON2 = _interopRequireDefault(require("../toJSON"));
|
|
26
|
-
|
|
27
23
|
var _Collection2 = _interopRequireDefault(require("./Collection"));
|
|
28
24
|
|
|
29
|
-
var _Merge = _interopRequireDefault(require("./Merge"));
|
|
30
|
-
|
|
31
25
|
var _Pair = _interopRequireDefault(require("./Pair"));
|
|
32
26
|
|
|
33
27
|
var _Scalar = _interopRequireDefault(require("./Scalar"));
|
|
34
28
|
|
|
35
|
-
// Published as 'yaml/map'
|
|
36
29
|
function findPair(items, key) {
|
|
37
30
|
var k = key instanceof _Scalar.default ? key.value : key;
|
|
38
31
|
var _iteratorNormalCompletion = true;
|
|
@@ -110,11 +103,17 @@ function (_Collection) {
|
|
|
110
103
|
var prev = findPair(this.items, key);
|
|
111
104
|
if (prev) prev.value = value;else this.items.push(new _Pair.default(key, value));
|
|
112
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* @param {*} arg ignored
|
|
108
|
+
* @param {*} ctx Conversion context, originally set in Document#toJSON()
|
|
109
|
+
* @param {Class} Type If set, forces the returned collection type
|
|
110
|
+
* @returns {*} Instance of Type, Map, or Object
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
113
|
}, {
|
|
114
114
|
key: "toJSON",
|
|
115
|
-
value: function toJSON(_, ctx) {
|
|
116
|
-
|
|
117
|
-
var map = {};
|
|
115
|
+
value: function toJSON(_, ctx, Type) {
|
|
116
|
+
var map = Type ? new Type() : ctx && ctx.mapAsMap ? new Map() : {};
|
|
118
117
|
if (ctx && ctx.onCreate) ctx.onCreate(map);
|
|
119
118
|
var _iteratorNormalCompletion2 = true;
|
|
120
119
|
var _didIteratorError2 = false;
|
|
@@ -123,40 +122,7 @@ function (_Collection) {
|
|
|
123
122
|
try {
|
|
124
123
|
for (var _iterator2 = this.items[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
125
124
|
var item = _step2.value;
|
|
126
|
-
|
|
127
|
-
if (item instanceof _Merge.default) {
|
|
128
|
-
(function () {
|
|
129
|
-
// If the value associated with a merge key is a single mapping node,
|
|
130
|
-
// each of its key/value pairs is inserted into the current mapping,
|
|
131
|
-
// unless the key already exists in it. If the value associated with the
|
|
132
|
-
// merge key is a sequence, then this sequence is expected to contain
|
|
133
|
-
// mapping nodes and each of these nodes is merged in turn according to
|
|
134
|
-
// its order in the sequence. Keys in mapping nodes earlier in the
|
|
135
|
-
// sequence override keys specified in later mapping nodes.
|
|
136
|
-
// -- http://yaml.org/type/merge.html
|
|
137
|
-
var keys = Object.keys(map);
|
|
138
|
-
var items = item.value.items;
|
|
139
|
-
|
|
140
|
-
for (var i = items.length - 1; i >= 0; --i) {
|
|
141
|
-
var source = items[i].source;
|
|
142
|
-
|
|
143
|
-
if (source instanceof YAMLMap) {
|
|
144
|
-
(function () {
|
|
145
|
-
var obj = source.toJSON('', ctx);
|
|
146
|
-
Object.keys(obj).forEach(function (key) {
|
|
147
|
-
if (!keys.includes(key)) map[key] = obj[key];
|
|
148
|
-
});
|
|
149
|
-
})();
|
|
150
|
-
} else {
|
|
151
|
-
throw new Error('Merge sources must be maps');
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
})();
|
|
155
|
-
} else {
|
|
156
|
-
var stringKey = item.stringKey,
|
|
157
|
-
value = item.value;
|
|
158
|
-
map[stringKey] = (0, _toJSON2.default)(value, stringKey, ctx);
|
|
159
|
-
}
|
|
125
|
+
item.addToJSMap(ctx, map);
|
|
160
126
|
}
|
|
161
127
|
} catch (err) {
|
|
162
128
|
_didIteratorError2 = true;
|
|
@@ -176,10 +142,9 @@ function (_Collection) {
|
|
|
176
142
|
return map;
|
|
177
143
|
}
|
|
178
144
|
}, {
|
|
179
|
-
key: "
|
|
180
|
-
value: function
|
|
181
|
-
|
|
182
|
-
if (ctx && ctx.onCreate) ctx.onCreate(map);
|
|
145
|
+
key: "toString",
|
|
146
|
+
value: function toString(ctx, onComment, onChompKeep) {
|
|
147
|
+
if (!ctx) return JSON.stringify(this);
|
|
183
148
|
var _iteratorNormalCompletion3 = true;
|
|
184
149
|
var _didIteratorError3 = false;
|
|
185
150
|
var _iteratorError3 = undefined;
|
|
@@ -187,49 +152,7 @@ function (_Collection) {
|
|
|
187
152
|
try {
|
|
188
153
|
for (var _iterator3 = this.items[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
|
189
154
|
var item = _step3.value;
|
|
190
|
-
|
|
191
|
-
if (item instanceof _Merge.default) {
|
|
192
|
-
var items = item.value.items;
|
|
193
|
-
|
|
194
|
-
for (var i = items.length - 1; i >= 0; --i) {
|
|
195
|
-
var source = items[i].source;
|
|
196
|
-
|
|
197
|
-
if (source instanceof YAMLMap) {
|
|
198
|
-
var _iteratorNormalCompletion4 = true;
|
|
199
|
-
var _didIteratorError4 = false;
|
|
200
|
-
var _iteratorError4 = undefined;
|
|
201
|
-
|
|
202
|
-
try {
|
|
203
|
-
for (var _iterator4 = source.toJSMap(ctx)[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
|
|
204
|
-
var _step4$value = (0, _slicedToArray2.default)(_step4.value, 2),
|
|
205
|
-
key = _step4$value[0],
|
|
206
|
-
value = _step4$value[1];
|
|
207
|
-
|
|
208
|
-
if (!map.has(key)) map.set(key, value);
|
|
209
|
-
}
|
|
210
|
-
} catch (err) {
|
|
211
|
-
_didIteratorError4 = true;
|
|
212
|
-
_iteratorError4 = err;
|
|
213
|
-
} finally {
|
|
214
|
-
try {
|
|
215
|
-
if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
|
|
216
|
-
_iterator4.return();
|
|
217
|
-
}
|
|
218
|
-
} finally {
|
|
219
|
-
if (_didIteratorError4) {
|
|
220
|
-
throw _iteratorError4;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
} else {
|
|
225
|
-
throw new Error('Merge sources must be maps');
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
} else {
|
|
229
|
-
var key = (0, _toJSON2.default)(item.key, '', ctx);
|
|
230
|
-
var value = (0, _toJSON2.default)(item.value, key, ctx);
|
|
231
|
-
map.set(key, value);
|
|
232
|
-
}
|
|
155
|
+
if (!(item instanceof _Pair.default)) throw new Error("Map items must all be pairs; found ".concat(JSON.stringify(item), " instead"));
|
|
233
156
|
}
|
|
234
157
|
} catch (err) {
|
|
235
158
|
_didIteratorError3 = true;
|
|
@@ -246,36 +169,6 @@ function (_Collection) {
|
|
|
246
169
|
}
|
|
247
170
|
}
|
|
248
171
|
|
|
249
|
-
return map;
|
|
250
|
-
}
|
|
251
|
-
}, {
|
|
252
|
-
key: "toString",
|
|
253
|
-
value: function toString(ctx, onComment, onChompKeep) {
|
|
254
|
-
if (!ctx) return JSON.stringify(this);
|
|
255
|
-
var _iteratorNormalCompletion5 = true;
|
|
256
|
-
var _didIteratorError5 = false;
|
|
257
|
-
var _iteratorError5 = undefined;
|
|
258
|
-
|
|
259
|
-
try {
|
|
260
|
-
for (var _iterator5 = this.items[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
|
|
261
|
-
var item = _step5.value;
|
|
262
|
-
if (!(item instanceof _Pair.default)) throw new Error("Map items must all be pairs; found ".concat(JSON.stringify(item), " instead"));
|
|
263
|
-
}
|
|
264
|
-
} catch (err) {
|
|
265
|
-
_didIteratorError5 = true;
|
|
266
|
-
_iteratorError5 = err;
|
|
267
|
-
} finally {
|
|
268
|
-
try {
|
|
269
|
-
if (!_iteratorNormalCompletion5 && _iterator5.return != null) {
|
|
270
|
-
_iterator5.return();
|
|
271
|
-
}
|
|
272
|
-
} finally {
|
|
273
|
-
if (_didIteratorError5) {
|
|
274
|
-
throw _iteratorError5;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
172
|
return (0, _get2.default)((0, _getPrototypeOf2.default)(YAMLMap.prototype), "toString", this).call(this, ctx, {
|
|
280
173
|
blockItem: function blockItem(n) {
|
|
281
174
|
return n.str;
|
|
@@ -7,6 +7,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.default = exports.MERGE_KEY = void 0;
|
|
9
9
|
|
|
10
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
|
+
|
|
10
12
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
13
|
|
|
12
14
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
@@ -19,6 +21,8 @@ var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
|
|
|
19
21
|
|
|
20
22
|
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
21
23
|
|
|
24
|
+
var _Map = _interopRequireDefault(require("./Map"));
|
|
25
|
+
|
|
22
26
|
var _Pair2 = _interopRequireDefault(require("./Pair"));
|
|
23
27
|
|
|
24
28
|
var _Scalar = _interopRequireDefault(require("./Scalar"));
|
|
@@ -55,9 +59,78 @@ function (_Pair) {
|
|
|
55
59
|
|
|
56
60
|
_this.type = 'MERGE_PAIR';
|
|
57
61
|
return (0, _possibleConstructorReturn2.default)(_this);
|
|
58
|
-
}
|
|
62
|
+
} // If the value associated with a merge key is a single mapping node, each of
|
|
63
|
+
// its key/value pairs is inserted into the current mapping, unless the key
|
|
64
|
+
// already exists in it. If the value associated with the merge key is a
|
|
65
|
+
// sequence, then this sequence is expected to contain mapping nodes and each
|
|
66
|
+
// of these nodes is merged in turn according to its order in the sequence.
|
|
67
|
+
// Keys in mapping nodes earlier in the sequence override keys specified in
|
|
68
|
+
// later mapping nodes. -- http://yaml.org/type/merge.html
|
|
69
|
+
|
|
59
70
|
|
|
60
71
|
(0, _createClass2.default)(Merge, [{
|
|
72
|
+
key: "addToJSMap",
|
|
73
|
+
value: function addToJSMap(ctx, map) {
|
|
74
|
+
var _iteratorNormalCompletion = true;
|
|
75
|
+
var _didIteratorError = false;
|
|
76
|
+
var _iteratorError = undefined;
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
for (var _iterator = this.value.items[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
80
|
+
var source = _step.value.source;
|
|
81
|
+
if (!(source instanceof _Map.default)) throw new Error('Merge sources must be maps');
|
|
82
|
+
var srcMap = source.toJSON(null, ctx, Map);
|
|
83
|
+
var _iteratorNormalCompletion2 = true;
|
|
84
|
+
var _didIteratorError2 = false;
|
|
85
|
+
var _iteratorError2 = undefined;
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
for (var _iterator2 = srcMap[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
89
|
+
var _step2$value = (0, _slicedToArray2.default)(_step2.value, 2),
|
|
90
|
+
key = _step2$value[0],
|
|
91
|
+
value = _step2$value[1];
|
|
92
|
+
|
|
93
|
+
if (map instanceof Map) {
|
|
94
|
+
if (!map.has(key)) map.set(key, value);
|
|
95
|
+
} else if (map instanceof Set) {
|
|
96
|
+
map.add(key);
|
|
97
|
+
} else {
|
|
98
|
+
if (!map.hasOwnProperty(key)) map[key] = value;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
} catch (err) {
|
|
102
|
+
_didIteratorError2 = true;
|
|
103
|
+
_iteratorError2 = err;
|
|
104
|
+
} finally {
|
|
105
|
+
try {
|
|
106
|
+
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
|
|
107
|
+
_iterator2.return();
|
|
108
|
+
}
|
|
109
|
+
} finally {
|
|
110
|
+
if (_didIteratorError2) {
|
|
111
|
+
throw _iteratorError2;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
} catch (err) {
|
|
117
|
+
_didIteratorError = true;
|
|
118
|
+
_iteratorError = err;
|
|
119
|
+
} finally {
|
|
120
|
+
try {
|
|
121
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
122
|
+
_iterator.return();
|
|
123
|
+
}
|
|
124
|
+
} finally {
|
|
125
|
+
if (_didIteratorError) {
|
|
126
|
+
throw _iteratorError;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return map;
|
|
132
|
+
}
|
|
133
|
+
}, {
|
|
61
134
|
key: "toString",
|
|
62
135
|
value: function toString(ctx, onComment) {
|
|
63
136
|
var seq = this.value;
|
|
@@ -7,8 +7,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
9
|
|
|
10
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
11
|
-
|
|
12
10
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
13
11
|
|
|
14
12
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
@@ -19,9 +17,11 @@ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/ge
|
|
|
19
17
|
|
|
20
18
|
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
21
19
|
|
|
20
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
21
|
+
|
|
22
22
|
var _addComment = _interopRequireDefault(require("../addComment"));
|
|
23
23
|
|
|
24
|
-
var
|
|
24
|
+
var _toJSON = _interopRequireDefault(require("../toJSON"));
|
|
25
25
|
|
|
26
26
|
var _Collection = _interopRequireDefault(require("./Collection"));
|
|
27
27
|
|
|
@@ -30,6 +30,19 @@ var _Node2 = _interopRequireDefault(require("./Node"));
|
|
|
30
30
|
var _Scalar = _interopRequireDefault(require("./Scalar"));
|
|
31
31
|
|
|
32
32
|
// Published as 'yaml/pair'
|
|
33
|
+
var stringifyKey = function stringifyKey(key, jsKey, ctx) {
|
|
34
|
+
if (jsKey === null) return '';
|
|
35
|
+
if ((0, _typeof2.default)(jsKey) !== 'object') return String(jsKey);
|
|
36
|
+
if (key instanceof _Node2.default && ctx && ctx.doc) return key.toString({
|
|
37
|
+
anchors: {},
|
|
38
|
+
doc: ctx.doc,
|
|
39
|
+
indent: '',
|
|
40
|
+
inFlow: true,
|
|
41
|
+
inStringifyKey: true
|
|
42
|
+
});
|
|
43
|
+
return JSON.stringify(jsKey);
|
|
44
|
+
};
|
|
45
|
+
|
|
33
46
|
var Pair =
|
|
34
47
|
/*#__PURE__*/
|
|
35
48
|
function (_Node) {
|
|
@@ -48,12 +61,27 @@ function (_Node) {
|
|
|
48
61
|
}
|
|
49
62
|
|
|
50
63
|
(0, _createClass2.default)(Pair, [{
|
|
64
|
+
key: "addToJSMap",
|
|
65
|
+
value: function addToJSMap(ctx, map) {
|
|
66
|
+
var key = (0, _toJSON.default)(this.key, '', ctx);
|
|
67
|
+
|
|
68
|
+
if (map instanceof Map) {
|
|
69
|
+
var value = (0, _toJSON.default)(this.value, key, ctx);
|
|
70
|
+
map.set(key, value);
|
|
71
|
+
} else if (map instanceof Set) {
|
|
72
|
+
map.add(key);
|
|
73
|
+
} else {
|
|
74
|
+
var stringKey = stringifyKey(this.key, key, ctx);
|
|
75
|
+
map[stringKey] = (0, _toJSON.default)(this.value, stringKey, ctx);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return map;
|
|
79
|
+
}
|
|
80
|
+
}, {
|
|
51
81
|
key: "toJSON",
|
|
52
82
|
value: function toJSON(_, ctx) {
|
|
53
|
-
var pair = {};
|
|
54
|
-
|
|
55
|
-
pair[sk] = (0, _toJSON2.default)(this.value, sk, ctx);
|
|
56
|
-
return pair;
|
|
83
|
+
var pair = ctx && ctx.mapAsMap ? new Map() : {};
|
|
84
|
+
return this.addToJSMap(ctx, pair);
|
|
57
85
|
}
|
|
58
86
|
}, {
|
|
59
87
|
key: "toString",
|
|
@@ -139,22 +167,8 @@ function (_Node) {
|
|
|
139
167
|
if (this.key == null) this.key = new _Scalar.default(null);
|
|
140
168
|
this.key.commentBefore = cb;
|
|
141
169
|
}
|
|
142
|
-
}, {
|
|
143
|
-
key: "stringKey",
|
|
144
|
-
get: function get() {
|
|
145
|
-
var key = (0, _toJSON2.default)(this.key);
|
|
146
|
-
if (key === null) return '';
|
|
147
|
-
if ((0, _typeof2.default)(key) === 'object') try {
|
|
148
|
-
return JSON.stringify(key);
|
|
149
|
-
} catch (e) {
|
|
150
|
-
/* should not happen, but let's ignore in any case */
|
|
151
|
-
}
|
|
152
|
-
return String(key);
|
|
153
|
-
}
|
|
154
170
|
}]);
|
|
155
171
|
return Pair;
|
|
156
172
|
}(_Node2.default);
|
|
157
173
|
|
|
158
|
-
exports.default = Pair;
|
|
159
|
-
module.exports = exports.default;
|
|
160
|
-
module.exports.default = exports.default;
|
|
174
|
+
exports.default = Pair;
|