yaml 1.3.2 → 1.6.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 +4 -6
- package/browser/dist/Anchors.js +12 -10
- package/browser/dist/Document.js +170 -75
- 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 +8 -8
- 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 +17 -11
- package/browser/dist/cst/FlowCollection.js +14 -8
- 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 +37 -7
- package/browser/dist/listTagNames.js +1 -3
- package/browser/dist/schema/Alias.js +90 -10
- package/browser/dist/schema/Collection.js +3 -3
- package/browser/dist/schema/Map.js +22 -105
- package/browser/dist/schema/Merge.js +74 -1
- package/browser/dist/schema/Node.js +1 -3
- package/browser/dist/schema/Pair.js +37 -23
- package/browser/dist/schema/Scalar.js +3 -5
- package/browser/dist/schema/Seq.js +30 -7
- package/browser/dist/schema/index.js +158 -82
- package/browser/dist/schema/parseMap.js +18 -21
- package/browser/dist/schema/parseSeq.js +9 -12
- package/browser/dist/{schema/_string.js → stringify.js} +65 -73
- package/browser/dist/tags/core.js +132 -0
- 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/tags/failsafe/string.js +40 -0
- package/browser/dist/tags/index.js +50 -0
- package/browser/dist/tags/json.js +103 -0
- package/browser/dist/tags/options.js +35 -0
- package/browser/dist/{schema/_binary.js → tags/yaml-1.1/binary.js} +20 -20
- package/browser/dist/tags/yaml-1.1/index.js +177 -0
- package/browser/dist/{schema/_omap.js → tags/yaml-1.1/omap.js} +25 -25
- package/browser/dist/{schema/_pairs.js → tags/yaml-1.1/pairs.js} +9 -13
- package/browser/dist/tags/yaml-1.1/set.js +140 -0
- package/browser/dist/{schema/_timestamp.js → tags/yaml-1.1/timestamp.js} +13 -10
- package/browser/dist/test-events.js +1 -4
- package/browser/dist/toJSON.js +20 -8
- 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 -3
- 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 +9 -8
- package/dist/Document.js +89 -45
- 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 +8 -8
- 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 +17 -11
- package/dist/cst/FlowCollection.js +14 -8
- 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 +18 -5
- package/dist/listTagNames.js +1 -3
- package/dist/schema/Alias.js +67 -12
- package/dist/schema/Map.js +10 -74
- package/dist/schema/Merge.js +31 -0
- package/dist/schema/Node.js +1 -3
- package/dist/schema/Pair.js +30 -16
- package/dist/schema/Scalar.js +3 -5
- package/dist/schema/Seq.js +9 -5
- package/dist/schema/index.js +109 -74
- package/dist/schema/parseMap.js +18 -21
- package/dist/schema/parseSeq.js +9 -12
- package/dist/{schema/_string.js → stringify.js} +56 -65
- package/dist/tags/core.js +96 -0
- 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/tags/json.js +67 -0
- package/dist/tags/options.js +35 -0
- package/dist/{schema/_binary.js → tags/yaml-1.1/binary.js} +18 -20
- package/dist/tags/yaml-1.1/index.js +131 -0
- package/dist/{schema/_omap.js → tags/yaml-1.1/omap.js} +16 -16
- package/dist/{schema/_pairs.js → tags/yaml-1.1/pairs.js} +9 -11
- package/dist/{schema/_set.js → tags/yaml-1.1/set.js} +12 -44
- package/dist/{schema/_timestamp.js → tags/yaml-1.1/timestamp.js} +7 -10
- package/dist/test-events.js +1 -4
- package/dist/toJSON.js +15 -5
- package/index.js +1 -0
- package/map.js +2 -1
- package/package.json +23 -17
- package/pair.js +2 -1
- package/parse-cst.js +1 -1
- package/scalar.js +2 -1
- package/schema.js +7 -3
- 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/polyfill.js +0 -251
- package/browser/dist/schema/_set.js +0 -212
- package/browser/dist/schema/core.js +0 -98
- package/browser/dist/schema/failsafe.js +0 -125
- package/browser/dist/schema/json.js +0 -66
- package/browser/dist/schema/yaml-1.1.js +0 -140
- package/dist/polyfill.js +0 -27
- package/dist/schema/core.js +0 -79
- package/dist/schema/failsafe.js +0 -74
- package/dist/schema/json.js +0 -56
- package/dist/schema/yaml-1.1.js +0 -115
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
`yaml` is a JavaScript parser and stringifier for [YAML](http://yaml.org/), a human friendly data serialization standard. It supports both parsing and stringifying data using all versions of YAML, along with all common data schemas. As a particularly distinguishing feature, `yaml` fully supports reading and writing comments and blank lines in YAML documents.
|
|
4
4
|
|
|
5
|
-
The library is released under the ISC open source license, and the code is [available on GitHub](https://github.com/eemeli/yaml/). It runs on Node.js 6 and later with no external dependencies, and in browsers from IE 11 upwards
|
|
5
|
+
The library is released under the ISC open source license, and the code is [available on GitHub](https://github.com/eemeli/yaml/). It runs on Node.js 6 and later with no external dependencies, and in browsers from IE 11 upwards (Note: `@babel/runtime` is used only by the `"browser"` entry point).
|
|
6
6
|
|
|
7
7
|
For more information, see the project's documentation site: [**eemeli.org/yaml**](https://eemeli.org/yaml/)
|
|
8
8
|
|
|
@@ -45,14 +45,12 @@ const YAML = require('yaml')
|
|
|
45
45
|
- [`YAML.parseDocument(str, options): YAML.Document`](https://eemeli.org/yaml/#parsing-documents)
|
|
46
46
|
|
|
47
47
|
```js
|
|
48
|
-
import
|
|
49
|
-
import Pair from 'yaml/pair'
|
|
50
|
-
import Seq from 'yaml/seq'
|
|
48
|
+
import { Pair, YAMLMap, YAMLSeq } from 'yaml/types'
|
|
51
49
|
```
|
|
52
50
|
|
|
53
|
-
- [`new Map()`](https://eemeli.org/yaml/#creating-nodes)
|
|
54
51
|
- [`new Pair(key, value)`](https://eemeli.org/yaml/#creating-nodes)
|
|
55
|
-
- [`new
|
|
52
|
+
- [`new YAMLMap()`](https://eemeli.org/yaml/#creating-nodes)
|
|
53
|
+
- [`new YAMLSeq()`](https://eemeli.org/yaml/#creating-nodes)
|
|
56
54
|
|
|
57
55
|
### CST Parser
|
|
58
56
|
|
package/browser/dist/Anchors.js
CHANGED
|
@@ -26,9 +26,17 @@ var _Seq = _interopRequireDefault(require("./schema/Seq"));
|
|
|
26
26
|
var Anchors =
|
|
27
27
|
/*#__PURE__*/
|
|
28
28
|
function () {
|
|
29
|
-
|
|
29
|
+
(0, _createClass2.default)(Anchors, null, [{
|
|
30
|
+
key: "validAnchorNode",
|
|
31
|
+
value: function validAnchorNode(node) {
|
|
32
|
+
return node instanceof _Scalar.default || node instanceof _Seq.default || node instanceof _Map.default;
|
|
33
|
+
}
|
|
34
|
+
}]);
|
|
35
|
+
|
|
36
|
+
function Anchors(prefix) {
|
|
30
37
|
(0, _classCallCheck2.default)(this, Anchors);
|
|
31
38
|
(0, _defineProperty2.default)(this, "map", {});
|
|
39
|
+
this.prefix = prefix;
|
|
32
40
|
}
|
|
33
41
|
|
|
34
42
|
(0, _createClass2.default)(Anchors, [{
|
|
@@ -75,6 +83,7 @@ function () {
|
|
|
75
83
|
}, {
|
|
76
84
|
key: "newName",
|
|
77
85
|
value: function newName(prefix) {
|
|
86
|
+
if (!prefix) prefix = this.prefix;
|
|
78
87
|
var names = Object.keys(this.map);
|
|
79
88
|
|
|
80
89
|
for (var i = 1; true; ++i) {
|
|
@@ -124,7 +133,7 @@ function () {
|
|
|
124
133
|
} else {
|
|
125
134
|
if (!name) {
|
|
126
135
|
if (!node) return null;
|
|
127
|
-
name = this.newName(
|
|
136
|
+
name = this.newName();
|
|
128
137
|
}
|
|
129
138
|
|
|
130
139
|
map[name] = node;
|
|
@@ -132,15 +141,8 @@ function () {
|
|
|
132
141
|
|
|
133
142
|
return name;
|
|
134
143
|
}
|
|
135
|
-
}], [{
|
|
136
|
-
key: "validAnchorNode",
|
|
137
|
-
value: function validAnchorNode(node) {
|
|
138
|
-
return node instanceof _Scalar.default || node instanceof _Seq.default || node instanceof _Map.default;
|
|
139
|
-
}
|
|
140
144
|
}]);
|
|
141
145
|
return Anchors;
|
|
142
146
|
}();
|
|
143
147
|
|
|
144
|
-
exports.default = Anchors;
|
|
145
|
-
module.exports = exports.default;
|
|
146
|
-
module.exports.default = exports.default;
|
|
148
|
+
exports.default = Anchors;
|
package/browser/dist/Document.js
CHANGED
|
@@ -21,7 +21,7 @@ var _addComment = _interopRequireDefault(require("./addComment"));
|
|
|
21
21
|
|
|
22
22
|
var _Anchors = _interopRequireDefault(require("./Anchors"));
|
|
23
23
|
|
|
24
|
-
var
|
|
24
|
+
var _constants = require("./constants");
|
|
25
25
|
|
|
26
26
|
var _errors = require("./errors");
|
|
27
27
|
|
|
@@ -33,14 +33,14 @@ var _Alias = _interopRequireDefault(require("./schema/Alias"));
|
|
|
33
33
|
|
|
34
34
|
var _Collection = _interopRequireWildcard(require("./schema/Collection"));
|
|
35
35
|
|
|
36
|
-
var
|
|
36
|
+
var _Node = _interopRequireDefault(require("./schema/Node"));
|
|
37
37
|
|
|
38
38
|
var _Scalar = _interopRequireDefault(require("./schema/Scalar"));
|
|
39
39
|
|
|
40
40
|
var _toJSON2 = _interopRequireDefault(require("./toJSON"));
|
|
41
41
|
|
|
42
42
|
var isCollectionItem = function isCollectionItem(node) {
|
|
43
|
-
return node && [
|
|
43
|
+
return node && [_constants.Type.MAP_KEY, _constants.Type.MAP_VALUE, _constants.Type.SEQ_ITEM].includes(node.type);
|
|
44
44
|
};
|
|
45
45
|
|
|
46
46
|
var Document =
|
|
@@ -48,10 +48,11 @@ var Document =
|
|
|
48
48
|
function () {
|
|
49
49
|
function Document(options) {
|
|
50
50
|
(0, _classCallCheck2.default)(this, Document);
|
|
51
|
-
this.anchors = new _Anchors.default();
|
|
51
|
+
this.anchors = new _Anchors.default(options.anchorPrefix);
|
|
52
52
|
this.commentBefore = null;
|
|
53
53
|
this.comment = null;
|
|
54
54
|
this.contents = null;
|
|
55
|
+
this.directivesEndMarker = null;
|
|
55
56
|
this.errors = [];
|
|
56
57
|
this.options = options;
|
|
57
58
|
this.schema = null;
|
|
@@ -144,15 +145,14 @@ function () {
|
|
|
144
145
|
}
|
|
145
146
|
}, {
|
|
146
147
|
key: "parse",
|
|
147
|
-
value: function parse(node) {
|
|
148
|
-
var _this = this;
|
|
149
|
-
|
|
148
|
+
value: function parse(node, prevDoc) {
|
|
150
149
|
if (this.options.keepCstNodes) this.cstNode = node;
|
|
151
150
|
if (this.options.keepNodeTypes) this.type = 'DOCUMENT';
|
|
152
151
|
var _node$directives = node.directives,
|
|
153
152
|
directives = _node$directives === void 0 ? [] : _node$directives,
|
|
154
153
|
_node$contents = node.contents,
|
|
155
154
|
contents = _node$contents === void 0 ? [] : _node$contents,
|
|
155
|
+
directivesEndMarker = node.directivesEndMarker,
|
|
156
156
|
error = node.error,
|
|
157
157
|
valueRange = node.valueRange;
|
|
158
158
|
|
|
@@ -161,7 +161,73 @@ function () {
|
|
|
161
161
|
this.errors.push(error);
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
+
this.parseDirectives(directives, prevDoc);
|
|
165
|
+
if (directivesEndMarker) this.directivesEndMarker = true;
|
|
166
|
+
this.range = valueRange ? [valueRange.start, valueRange.end] : null;
|
|
167
|
+
this.setSchema();
|
|
168
|
+
this.anchors._cstAliases = [];
|
|
169
|
+
this.parseContents(contents);
|
|
170
|
+
this.anchors.resolveNodes();
|
|
171
|
+
|
|
172
|
+
if (this.options.prettyErrors) {
|
|
173
|
+
var _iteratorNormalCompletion = true;
|
|
174
|
+
var _didIteratorError = false;
|
|
175
|
+
var _iteratorError = undefined;
|
|
176
|
+
|
|
177
|
+
try {
|
|
178
|
+
for (var _iterator = this.errors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
179
|
+
var _error = _step.value;
|
|
180
|
+
if (_error instanceof _errors.YAMLError) _error.makePretty();
|
|
181
|
+
}
|
|
182
|
+
} catch (err) {
|
|
183
|
+
_didIteratorError = true;
|
|
184
|
+
_iteratorError = err;
|
|
185
|
+
} finally {
|
|
186
|
+
try {
|
|
187
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
188
|
+
_iterator.return();
|
|
189
|
+
}
|
|
190
|
+
} finally {
|
|
191
|
+
if (_didIteratorError) {
|
|
192
|
+
throw _iteratorError;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
var _iteratorNormalCompletion2 = true;
|
|
198
|
+
var _didIteratorError2 = false;
|
|
199
|
+
var _iteratorError2 = undefined;
|
|
200
|
+
|
|
201
|
+
try {
|
|
202
|
+
for (var _iterator2 = this.warnings[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
203
|
+
var warn = _step2.value;
|
|
204
|
+
if (warn instanceof _errors.YAMLError) warn.makePretty();
|
|
205
|
+
}
|
|
206
|
+
} catch (err) {
|
|
207
|
+
_didIteratorError2 = true;
|
|
208
|
+
_iteratorError2 = err;
|
|
209
|
+
} finally {
|
|
210
|
+
try {
|
|
211
|
+
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
|
|
212
|
+
_iterator2.return();
|
|
213
|
+
}
|
|
214
|
+
} finally {
|
|
215
|
+
if (_didIteratorError2) {
|
|
216
|
+
throw _iteratorError2;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return this;
|
|
223
|
+
}
|
|
224
|
+
}, {
|
|
225
|
+
key: "parseDirectives",
|
|
226
|
+
value: function parseDirectives(directives, prevDoc) {
|
|
227
|
+
var _this = this;
|
|
228
|
+
|
|
164
229
|
var directiveComments = [];
|
|
230
|
+
var hasDirectives = false;
|
|
165
231
|
directives.forEach(function (directive) {
|
|
166
232
|
var comment = directive.comment,
|
|
167
233
|
name = directive.name;
|
|
@@ -170,12 +236,14 @@ function () {
|
|
|
170
236
|
case 'TAG':
|
|
171
237
|
_this.resolveTagDirective(directive);
|
|
172
238
|
|
|
239
|
+
hasDirectives = true;
|
|
173
240
|
break;
|
|
174
241
|
|
|
175
242
|
case 'YAML':
|
|
176
243
|
case 'YAML:1.0':
|
|
177
244
|
_this.resolveYamlDirective(directive);
|
|
178
245
|
|
|
246
|
+
hasDirectives = true;
|
|
179
247
|
break;
|
|
180
248
|
|
|
181
249
|
default:
|
|
@@ -189,10 +257,28 @@ function () {
|
|
|
189
257
|
|
|
190
258
|
if (comment) directiveComments.push(comment);
|
|
191
259
|
});
|
|
192
|
-
|
|
193
|
-
this.
|
|
194
|
-
|
|
260
|
+
|
|
261
|
+
if (prevDoc && !hasDirectives && '1.1' === (this.version || prevDoc.version || this.options.version)) {
|
|
262
|
+
var copyTagPrefix = function copyTagPrefix(_ref) {
|
|
263
|
+
var handle = _ref.handle,
|
|
264
|
+
prefix = _ref.prefix;
|
|
265
|
+
return {
|
|
266
|
+
handle: handle,
|
|
267
|
+
prefix: prefix
|
|
268
|
+
};
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
this.tagPrefixes = prevDoc.tagPrefixes.map(copyTagPrefix);
|
|
272
|
+
this.version = prevDoc.version;
|
|
273
|
+
}
|
|
274
|
+
|
|
195
275
|
this.commentBefore = directiveComments.join('\n') || null;
|
|
276
|
+
}
|
|
277
|
+
}, {
|
|
278
|
+
key: "parseContents",
|
|
279
|
+
value: function parseContents(contents) {
|
|
280
|
+
var _this2 = this;
|
|
281
|
+
|
|
196
282
|
var comments = {
|
|
197
283
|
before: [],
|
|
198
284
|
after: []
|
|
@@ -204,10 +290,10 @@ function () {
|
|
|
204
290
|
if (contentNodes.length === 1) {
|
|
205
291
|
var msg = 'Document is not valid YAML (bad indentation?)';
|
|
206
292
|
|
|
207
|
-
|
|
293
|
+
_this2.errors.push(new _errors.YAMLSyntaxError(node, msg));
|
|
208
294
|
}
|
|
209
295
|
|
|
210
|
-
var res =
|
|
296
|
+
var res = _this2.resolveNode(node);
|
|
211
297
|
|
|
212
298
|
if (spaceBefore) {
|
|
213
299
|
res.spaceBefore = true;
|
|
@@ -218,12 +304,12 @@ function () {
|
|
|
218
304
|
} else if (node.comment !== null) {
|
|
219
305
|
var cc = contentNodes.length === 0 ? comments.before : comments.after;
|
|
220
306
|
cc.push(node.comment);
|
|
221
|
-
} else if (node.type ===
|
|
307
|
+
} else if (node.type === _constants.Type.BLANK_LINE) {
|
|
222
308
|
spaceBefore = true;
|
|
223
309
|
|
|
224
|
-
if (contentNodes.length === 0 && comments.before.length > 0 && !
|
|
310
|
+
if (contentNodes.length === 0 && comments.before.length > 0 && !_this2.commentBefore) {
|
|
225
311
|
// space-separated comments at start are parsed as document comments
|
|
226
|
-
|
|
312
|
+
_this2.commentBefore = comments.before.join('\n');
|
|
227
313
|
comments.before = [];
|
|
228
314
|
}
|
|
229
315
|
}
|
|
@@ -263,8 +349,6 @@ function () {
|
|
|
263
349
|
}
|
|
264
350
|
|
|
265
351
|
this.comment = comments.after.join('\n') || null;
|
|
266
|
-
this.anchors.resolveNodes();
|
|
267
|
-
return this;
|
|
268
352
|
}
|
|
269
353
|
}, {
|
|
270
354
|
key: "resolveTagDirective",
|
|
@@ -373,21 +457,21 @@ function () {
|
|
|
373
457
|
}
|
|
374
458
|
|
|
375
459
|
switch (type) {
|
|
376
|
-
case
|
|
377
|
-
case
|
|
378
|
-
case
|
|
379
|
-
case
|
|
460
|
+
case _constants.Type.BLOCK_FOLDED:
|
|
461
|
+
case _constants.Type.BLOCK_LITERAL:
|
|
462
|
+
case _constants.Type.QUOTE_DOUBLE:
|
|
463
|
+
case _constants.Type.QUOTE_SINGLE:
|
|
380
464
|
return _schema.default.defaultTags.STR;
|
|
381
465
|
|
|
382
|
-
case
|
|
383
|
-
case
|
|
466
|
+
case _constants.Type.FLOW_MAP:
|
|
467
|
+
case _constants.Type.MAP:
|
|
384
468
|
return _schema.default.defaultTags.MAP;
|
|
385
469
|
|
|
386
|
-
case
|
|
387
|
-
case
|
|
470
|
+
case _constants.Type.FLOW_SEQ:
|
|
471
|
+
case _constants.Type.SEQ:
|
|
388
472
|
return _schema.default.defaultTags.SEQ;
|
|
389
473
|
|
|
390
|
-
case
|
|
474
|
+
case _constants.Type.PLAIN:
|
|
391
475
|
return nonSpecific ? _schema.default.defaultTags.STR : null;
|
|
392
476
|
|
|
393
477
|
default:
|
|
@@ -408,22 +492,22 @@ function () {
|
|
|
408
492
|
after: []
|
|
409
493
|
};
|
|
410
494
|
var props = isCollectionItem(node.context.parent) ? node.context.parent.props.concat(node.props) : node.props;
|
|
411
|
-
var
|
|
412
|
-
var
|
|
413
|
-
var
|
|
495
|
+
var _iteratorNormalCompletion3 = true;
|
|
496
|
+
var _didIteratorError3 = false;
|
|
497
|
+
var _iteratorError3 = undefined;
|
|
414
498
|
|
|
415
499
|
try {
|
|
416
|
-
for (var
|
|
417
|
-
var
|
|
418
|
-
start =
|
|
419
|
-
end =
|
|
500
|
+
for (var _iterator3 = props[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
|
501
|
+
var _step3$value = _step3.value,
|
|
502
|
+
start = _step3$value.start,
|
|
503
|
+
end = _step3$value.end;
|
|
420
504
|
|
|
421
505
|
switch (node.context.src[start]) {
|
|
422
|
-
case
|
|
506
|
+
case _constants.Char.COMMENT:
|
|
423
507
|
{
|
|
424
508
|
if (!node.commentHasRequiredWhitespace(start)) {
|
|
425
|
-
var
|
|
426
|
-
errors.push(new _errors.YAMLSemanticError(node,
|
|
509
|
+
var _msg7 = 'Comments must be separated from other tokens by white space characters';
|
|
510
|
+
errors.push(new _errors.YAMLSemanticError(node, _msg7));
|
|
427
511
|
}
|
|
428
512
|
|
|
429
513
|
var c = node.context.src.slice(start + 1, end);
|
|
@@ -438,19 +522,19 @@ function () {
|
|
|
438
522
|
}
|
|
439
523
|
break;
|
|
440
524
|
|
|
441
|
-
case
|
|
525
|
+
case _constants.Char.ANCHOR:
|
|
442
526
|
if (hasAnchor) {
|
|
443
|
-
var
|
|
444
|
-
errors.push(new _errors.YAMLSemanticError(node,
|
|
527
|
+
var _msg8 = 'A node can have at most one anchor';
|
|
528
|
+
errors.push(new _errors.YAMLSemanticError(node, _msg8));
|
|
445
529
|
}
|
|
446
530
|
|
|
447
531
|
hasAnchor = true;
|
|
448
532
|
break;
|
|
449
533
|
|
|
450
|
-
case
|
|
534
|
+
case _constants.Char.TAG:
|
|
451
535
|
if (hasTag) {
|
|
452
|
-
var
|
|
453
|
-
errors.push(new _errors.YAMLSemanticError(node,
|
|
536
|
+
var _msg9 = 'A node can have at most one tag';
|
|
537
|
+
errors.push(new _errors.YAMLSemanticError(node, _msg9));
|
|
454
538
|
}
|
|
455
539
|
|
|
456
540
|
hasTag = true;
|
|
@@ -458,16 +542,16 @@ function () {
|
|
|
458
542
|
}
|
|
459
543
|
}
|
|
460
544
|
} catch (err) {
|
|
461
|
-
|
|
462
|
-
|
|
545
|
+
_didIteratorError3 = true;
|
|
546
|
+
_iteratorError3 = err;
|
|
463
547
|
} finally {
|
|
464
548
|
try {
|
|
465
|
-
if (!
|
|
466
|
-
|
|
549
|
+
if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
|
|
550
|
+
_iterator3.return();
|
|
467
551
|
}
|
|
468
552
|
} finally {
|
|
469
|
-
if (
|
|
470
|
-
throw
|
|
553
|
+
if (_didIteratorError3) {
|
|
554
|
+
throw _iteratorError3;
|
|
471
555
|
}
|
|
472
556
|
}
|
|
473
557
|
}
|
|
@@ -486,7 +570,7 @@ function () {
|
|
|
486
570
|
|
|
487
571
|
var res;
|
|
488
572
|
|
|
489
|
-
if (node.type ===
|
|
573
|
+
if (node.type === _constants.Type.ALIAS) {
|
|
490
574
|
if (hasAnchor || hasTag) {
|
|
491
575
|
var msg = 'An alias node must not specify any properties';
|
|
492
576
|
errors.push(new _errors.YAMLSemanticError(node, msg));
|
|
@@ -506,21 +590,16 @@ function () {
|
|
|
506
590
|
res = new _Alias.default(src);
|
|
507
591
|
|
|
508
592
|
anchors._cstAliases.push(res);
|
|
509
|
-
|
|
510
|
-
if (!src.resolved) {
|
|
511
|
-
var _msg6 = 'Alias node contains a circular reference, which cannot be resolved as JSON';
|
|
512
|
-
this.warnings.push(new _errors.YAMLWarning(node, _msg6));
|
|
513
|
-
}
|
|
514
593
|
} else {
|
|
515
594
|
var tagName = this.resolveTagName(node);
|
|
516
595
|
|
|
517
596
|
if (tagName) {
|
|
518
597
|
res = schema.resolveNodeWithFallback(this, node, tagName);
|
|
519
598
|
} else {
|
|
520
|
-
if (node.type !==
|
|
521
|
-
var
|
|
599
|
+
if (node.type !== _constants.Type.PLAIN) {
|
|
600
|
+
var _msg6 = "Failed to resolve ".concat(node.type, " node here");
|
|
522
601
|
|
|
523
|
-
errors.push(new _errors.YAMLSyntaxError(node,
|
|
602
|
+
errors.push(new _errors.YAMLSyntaxError(node, _msg6));
|
|
524
603
|
return null;
|
|
525
604
|
}
|
|
526
605
|
|
|
@@ -613,16 +692,29 @@ function () {
|
|
|
613
692
|
}, {
|
|
614
693
|
key: "toJSON",
|
|
615
694
|
value: function toJSON(arg) {
|
|
616
|
-
var
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
695
|
+
var _this3 = this;
|
|
696
|
+
|
|
697
|
+
var _this$options = this.options,
|
|
698
|
+
keepBlobsInJSON = _this$options.keepBlobsInJSON,
|
|
699
|
+
mapAsMap = _this$options.mapAsMap,
|
|
700
|
+
maxAliasCount = _this$options.maxAliasCount;
|
|
701
|
+
var keep = keepBlobsInJSON && (typeof arg !== 'string' || !(this.contents instanceof _Scalar.default));
|
|
702
|
+
var ctx = {
|
|
703
|
+
doc: this,
|
|
623
704
|
keep: keep,
|
|
624
|
-
mapAsMap: mapAsMap
|
|
705
|
+
mapAsMap: keep && !!mapAsMap,
|
|
706
|
+
maxAliasCount: maxAliasCount
|
|
707
|
+
};
|
|
708
|
+
var anchorNames = Object.keys(this.anchors.map);
|
|
709
|
+
if (anchorNames.length > 0) ctx.anchors = anchorNames.map(function (name) {
|
|
710
|
+
return {
|
|
711
|
+
alias: [],
|
|
712
|
+
aliasCount: 0,
|
|
713
|
+
count: 1,
|
|
714
|
+
node: _this3.anchors.map[name]
|
|
715
|
+
};
|
|
625
716
|
});
|
|
717
|
+
return (0, _toJSON2.default)(this.contents, arg, ctx);
|
|
626
718
|
}
|
|
627
719
|
}, {
|
|
628
720
|
key: "toString",
|
|
@@ -630,7 +722,6 @@ function () {
|
|
|
630
722
|
if (this.errors.length > 0) throw new Error('Document with errors cannot be stringified');
|
|
631
723
|
this.setSchema();
|
|
632
724
|
var lines = [];
|
|
633
|
-
if (this.commentBefore) lines.push(this.commentBefore.replace(/^/gm, '#'), '');
|
|
634
725
|
var hasDirectives = false;
|
|
635
726
|
|
|
636
727
|
if (this.version) {
|
|
@@ -645,9 +736,9 @@ function () {
|
|
|
645
736
|
}
|
|
646
737
|
|
|
647
738
|
var tagNames = this.listNonDefaultTags();
|
|
648
|
-
this.tagPrefixes.forEach(function (
|
|
649
|
-
var handle =
|
|
650
|
-
prefix =
|
|
739
|
+
this.tagPrefixes.forEach(function (_ref2) {
|
|
740
|
+
var handle = _ref2.handle,
|
|
741
|
+
prefix = _ref2.prefix;
|
|
651
742
|
|
|
652
743
|
if (tagNames.some(function (t) {
|
|
653
744
|
return t.indexOf(prefix) === 0;
|
|
@@ -656,7 +747,13 @@ function () {
|
|
|
656
747
|
hasDirectives = true;
|
|
657
748
|
}
|
|
658
749
|
});
|
|
659
|
-
if (hasDirectives) lines.push('---');
|
|
750
|
+
if (hasDirectives || this.directivesEndMarker) lines.push('---');
|
|
751
|
+
|
|
752
|
+
if (this.commentBefore) {
|
|
753
|
+
if (hasDirectives || !this.directivesEndMarker) lines.unshift('');
|
|
754
|
+
lines.unshift(this.commentBefore.replace(/^/gm, '#'));
|
|
755
|
+
}
|
|
756
|
+
|
|
660
757
|
var ctx = {
|
|
661
758
|
anchors: {},
|
|
662
759
|
doc: this,
|
|
@@ -666,8 +763,8 @@ function () {
|
|
|
666
763
|
var contentComment = null;
|
|
667
764
|
|
|
668
765
|
if (this.contents) {
|
|
669
|
-
if (this.contents instanceof
|
|
670
|
-
if (this.contents.spaceBefore && hasDirectives) lines.push('');
|
|
766
|
+
if (this.contents instanceof _Node.default) {
|
|
767
|
+
if (this.contents.spaceBefore && (hasDirectives || this.directivesEndMarker)) lines.push('');
|
|
671
768
|
if (this.contents.commentBefore) lines.push(this.contents.commentBefore.replace(/^/gm, '#')); // top-level block scalars need to be indented if followed by a comment
|
|
672
769
|
|
|
673
770
|
ctx.forceBlockIndent = !!this.comment;
|
|
@@ -731,6 +828,4 @@ exports.default = Document;
|
|
|
731
828
|
prefix: _schema.default.defaultPrefix
|
|
732
829
|
}]
|
|
733
830
|
}
|
|
734
|
-
});
|
|
735
|
-
module.exports = exports.default;
|
|
736
|
-
module.exports.default = exports.default;
|
|
831
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Type = exports.Char = void 0;
|
|
7
|
+
var Char = {
|
|
8
|
+
ANCHOR: '&',
|
|
9
|
+
COMMENT: '#',
|
|
10
|
+
TAG: '!',
|
|
11
|
+
DIRECTIVES_END: '-',
|
|
12
|
+
DOCUMENT_END: '.'
|
|
13
|
+
};
|
|
14
|
+
exports.Char = Char;
|
|
15
|
+
var Type = {
|
|
16
|
+
ALIAS: 'ALIAS',
|
|
17
|
+
BLANK_LINE: 'BLANK_LINE',
|
|
18
|
+
BLOCK_FOLDED: 'BLOCK_FOLDED',
|
|
19
|
+
BLOCK_LITERAL: 'BLOCK_LITERAL',
|
|
20
|
+
COMMENT: 'COMMENT',
|
|
21
|
+
DIRECTIVE: 'DIRECTIVE',
|
|
22
|
+
DOCUMENT: 'DOCUMENT',
|
|
23
|
+
FLOW_MAP: 'FLOW_MAP',
|
|
24
|
+
FLOW_SEQ: 'FLOW_SEQ',
|
|
25
|
+
MAP: 'MAP',
|
|
26
|
+
MAP_KEY: 'MAP_KEY',
|
|
27
|
+
MAP_VALUE: 'MAP_VALUE',
|
|
28
|
+
PLAIN: 'PLAIN',
|
|
29
|
+
QUOTE_DOUBLE: 'QUOTE_DOUBLE',
|
|
30
|
+
QUOTE_SINGLE: 'QUOTE_SINGLE',
|
|
31
|
+
SEQ: 'SEQ',
|
|
32
|
+
SEQ_ITEM: 'SEQ_ITEM'
|
|
33
|
+
};
|
|
34
|
+
exports.Type = Type;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
|
4
|
-
|
|
5
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
6
4
|
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -19,7 +17,9 @@ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/ge
|
|
|
19
17
|
|
|
20
18
|
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
21
19
|
|
|
22
|
-
var
|
|
20
|
+
var _constants = require("../constants");
|
|
21
|
+
|
|
22
|
+
var _Node2 = _interopRequireDefault(require("./Node"));
|
|
23
23
|
|
|
24
24
|
var _Range = _interopRequireDefault(require("./Range"));
|
|
25
25
|
|
|
@@ -30,7 +30,7 @@ function (_Node) {
|
|
|
30
30
|
|
|
31
31
|
function BlankLine() {
|
|
32
32
|
(0, _classCallCheck2.default)(this, BlankLine);
|
|
33
|
-
return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(BlankLine).call(this,
|
|
33
|
+
return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(BlankLine).call(this, _constants.Type.BLANK_LINE));
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
(0, _createClass2.default)(BlankLine, [{
|
|
@@ -66,6 +66,4 @@ function (_Node) {
|
|
|
66
66
|
return BlankLine;
|
|
67
67
|
}(_Node2.default);
|
|
68
68
|
|
|
69
|
-
exports.default = BlankLine;
|
|
70
|
-
module.exports = exports.default;
|
|
71
|
-
module.exports.default = exports.default;
|
|
69
|
+
exports.default = BlankLine;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
|
4
|
-
|
|
5
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
6
4
|
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -21,7 +19,9 @@ var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
|
|
|
21
19
|
|
|
22
20
|
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
23
21
|
|
|
24
|
-
var
|
|
22
|
+
var _constants = require("../constants");
|
|
23
|
+
|
|
24
|
+
var _Node2 = _interopRequireDefault(require("./Node"));
|
|
25
25
|
|
|
26
26
|
var _Range = _interopRequireDefault(require("./Range"));
|
|
27
27
|
|
|
@@ -222,7 +222,7 @@ function (_Node) {
|
|
|
222
222
|
}
|
|
223
223
|
|
|
224
224
|
var bi = indent + this.blockIndent;
|
|
225
|
-
var folded = this.type ===
|
|
225
|
+
var folded = this.type === _constants.Type.BLOCK_FOLDED;
|
|
226
226
|
var atStart = true;
|
|
227
227
|
var str = '';
|
|
228
228
|
var sep = '';
|