yaml 1.8.3 → 1.10.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.
Files changed (163) hide show
  1. package/README.md +4 -4
  2. package/browser/dist/PlainValue-ff5147c6.js +1277 -0
  3. package/browser/dist/Schema-2bf2c74e.js +679 -0
  4. package/browser/dist/index.js +923 -38
  5. package/browser/dist/legacy-exports.js +3 -0
  6. package/browser/dist/parse-cst.js +1904 -0
  7. package/browser/dist/resolveSeq-04825f30.js +2373 -0
  8. package/browser/dist/types.js +4 -0
  9. package/browser/dist/util.js +2 -0
  10. package/browser/dist/warnings-0e4b70d3.js +499 -0
  11. package/browser/index.js +1 -1
  12. package/browser/map.js +2 -2
  13. package/browser/pair.js +2 -2
  14. package/browser/parse-cst.js +1 -1
  15. package/browser/scalar.js +2 -2
  16. package/browser/schema.js +8 -6
  17. package/browser/seq.js +2 -2
  18. package/browser/types/binary.js +3 -2
  19. package/browser/types/omap.js +3 -2
  20. package/browser/types/pairs.js +3 -2
  21. package/browser/types/set.js +3 -2
  22. package/browser/types/timestamp.js +6 -6
  23. package/browser/types.js +1 -11
  24. package/browser/util.js +1 -15
  25. package/dist/Document-2cf6b08c.js +757 -0
  26. package/dist/PlainValue-ec8e588e.js +876 -0
  27. package/dist/Schema-42e9705c.js +522 -0
  28. package/dist/index.js +21 -43
  29. package/dist/legacy-exports.js +16 -0
  30. package/dist/parse-cst.js +1747 -0
  31. package/dist/resolveSeq-4a68b39b.js +2115 -0
  32. package/dist/test-events.js +11 -14
  33. package/dist/types.js +23 -0
  34. package/dist/util.js +19 -0
  35. package/dist/warnings-39684f17.js +416 -0
  36. package/index.d.ts +372 -0
  37. package/index.js +1 -1
  38. package/map.js +2 -2
  39. package/package.json +32 -45
  40. package/pair.js +2 -2
  41. package/parse-cst.d.ts +187 -0
  42. package/parse-cst.js +1 -1
  43. package/scalar.js +2 -2
  44. package/schema.js +8 -6
  45. package/seq.js +2 -2
  46. package/types/binary.js +3 -2
  47. package/types/omap.js +3 -2
  48. package/types/pairs.js +3 -2
  49. package/types/set.js +3 -2
  50. package/types/timestamp.js +6 -6
  51. package/types.d.ts +407 -0
  52. package/types.js +16 -10
  53. package/types.mjs +15 -18
  54. package/util.d.ts +86 -0
  55. package/util.js +14 -13
  56. package/util.mjs +13 -19
  57. package/browser/dist/Anchors.js +0 -133
  58. package/browser/dist/Document.js +0 -819
  59. package/browser/dist/addComment.js +0 -8
  60. package/browser/dist/constants.js +0 -26
  61. package/browser/dist/cst/Alias.js +0 -42
  62. package/browser/dist/cst/BlankLine.js +0 -56
  63. package/browser/dist/cst/BlockValue.js +0 -247
  64. package/browser/dist/cst/Collection.js +0 -274
  65. package/browser/dist/cst/CollectionItem.js +0 -136
  66. package/browser/dist/cst/Comment.js +0 -40
  67. package/browser/dist/cst/Directive.js +0 -72
  68. package/browser/dist/cst/Document.js +0 -282
  69. package/browser/dist/cst/FlowCollection.js +0 -216
  70. package/browser/dist/cst/Node.js +0 -388
  71. package/browser/dist/cst/ParseContext.js +0 -248
  72. package/browser/dist/cst/PlainValue.js +0 -166
  73. package/browser/dist/cst/QuoteDouble.js +0 -241
  74. package/browser/dist/cst/QuoteSingle.js +0 -116
  75. package/browser/dist/cst/Range.js +0 -67
  76. package/browser/dist/cst/parse.js +0 -48
  77. package/browser/dist/cst/source-utils.js +0 -168
  78. package/browser/dist/errors.js +0 -112
  79. package/browser/dist/foldFlowLines.js +0 -138
  80. package/browser/dist/listTagNames.js +0 -28
  81. package/browser/dist/schema/Alias.js +0 -139
  82. package/browser/dist/schema/Collection.js +0 -267
  83. package/browser/dist/schema/Map.js +0 -178
  84. package/browser/dist/schema/Merge.js +0 -127
  85. package/browser/dist/schema/Node.js +0 -7
  86. package/browser/dist/schema/Pair.js +0 -171
  87. package/browser/dist/schema/Scalar.js +0 -38
  88. package/browser/dist/schema/Seq.js +0 -114
  89. package/browser/dist/schema/index.js +0 -382
  90. package/browser/dist/schema/parseMap.js +0 -312
  91. package/browser/dist/schema/parseSeq.js +0 -168
  92. package/browser/dist/schema/parseUtils.js +0 -110
  93. package/browser/dist/stringify.js +0 -331
  94. package/browser/dist/tags/core.js +0 -126
  95. package/browser/dist/tags/failsafe/index.js +0 -4
  96. package/browser/dist/tags/failsafe/map.js +0 -56
  97. package/browser/dist/tags/failsafe/seq.js +0 -43
  98. package/browser/dist/tags/failsafe/string.js +0 -28
  99. package/browser/dist/tags/index.js +0 -36
  100. package/browser/dist/tags/json.js +0 -76
  101. package/browser/dist/tags/options.js +0 -23
  102. package/browser/dist/tags/yaml-1.1/binary.js +0 -87
  103. package/browser/dist/tags/yaml-1.1/index.js +0 -157
  104. package/browser/dist/tags/yaml-1.1/omap.js +0 -142
  105. package/browser/dist/tags/yaml-1.1/pairs.js +0 -81
  106. package/browser/dist/tags/yaml-1.1/set.js +0 -114
  107. package/browser/dist/tags/yaml-1.1/timestamp.js +0 -97
  108. package/browser/dist/test-events.js +0 -163
  109. package/browser/dist/toJSON.js +0 -20
  110. package/browser/dist/warnings.js +0 -28
  111. package/dist/Anchors.js +0 -125
  112. package/dist/Document.js +0 -710
  113. package/dist/addComment.js +0 -17
  114. package/dist/constants.js +0 -34
  115. package/dist/cst/Alias.js +0 -38
  116. package/dist/cst/BlankLine.js +0 -56
  117. package/dist/cst/BlockValue.js +0 -248
  118. package/dist/cst/Collection.js +0 -271
  119. package/dist/cst/CollectionItem.js +0 -140
  120. package/dist/cst/Comment.js +0 -38
  121. package/dist/cst/Directive.js +0 -64
  122. package/dist/cst/Document.js +0 -281
  123. package/dist/cst/FlowCollection.js +0 -218
  124. package/dist/cst/Node.js +0 -365
  125. package/dist/cst/ParseContext.js +0 -258
  126. package/dist/cst/PlainValue.js +0 -161
  127. package/dist/cst/QuoteDouble.js +0 -237
  128. package/dist/cst/QuoteSingle.js +0 -113
  129. package/dist/cst/Range.js +0 -63
  130. package/dist/cst/parse.js +0 -55
  131. package/dist/cst/source-utils.js +0 -178
  132. package/dist/errors.js +0 -102
  133. package/dist/foldFlowLines.js +0 -146
  134. package/dist/listTagNames.js +0 -38
  135. package/dist/schema/Alias.js +0 -110
  136. package/dist/schema/Collection.js +0 -188
  137. package/dist/schema/Map.js +0 -103
  138. package/dist/schema/Merge.js +0 -80
  139. package/dist/schema/Node.js +0 -10
  140. package/dist/schema/Pair.js +0 -161
  141. package/dist/schema/Scalar.js +0 -31
  142. package/dist/schema/Seq.js +0 -78
  143. package/dist/schema/index.js +0 -315
  144. package/dist/schema/parseMap.js +0 -343
  145. package/dist/schema/parseSeq.js +0 -180
  146. package/dist/schema/parseUtils.js +0 -104
  147. package/dist/stringify.js +0 -358
  148. package/dist/tags/core.js +0 -114
  149. package/dist/tags/failsafe/index.js +0 -17
  150. package/dist/tags/failsafe/map.js +0 -37
  151. package/dist/tags/failsafe/seq.js +0 -34
  152. package/dist/tags/failsafe/string.js +0 -40
  153. package/dist/tags/index.js +0 -62
  154. package/dist/tags/json.js +0 -60
  155. package/dist/tags/options.js +0 -35
  156. package/dist/tags/yaml-1.1/binary.js +0 -97
  157. package/dist/tags/yaml-1.1/index.js +0 -131
  158. package/dist/tags/yaml-1.1/omap.js +0 -105
  159. package/dist/tags/yaml-1.1/pairs.js +0 -80
  160. package/dist/tags/yaml-1.1/set.js +0 -91
  161. package/dist/tags/yaml-1.1/timestamp.js +0 -93
  162. package/dist/toJSON.js +0 -23
  163. package/dist/warnings.js +0 -39
@@ -1,819 +0,0 @@
1
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
- import _createClass from "@babel/runtime/helpers/createClass";
4
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
5
- import addComment from './addComment';
6
- import Anchors from './Anchors';
7
- import { Char, Type } from './constants';
8
- import { YAMLError, YAMLReferenceError, YAMLSemanticError, YAMLSyntaxError, YAMLWarning } from './errors';
9
- import listTagNames from './listTagNames';
10
- import Schema from './schema';
11
- import Alias from './schema/Alias';
12
- import Collection, { isEmptyPath } from './schema/Collection';
13
- import Node from './schema/Node';
14
- import Scalar from './schema/Scalar';
15
- import _toJSON from './toJSON';
16
-
17
- var isCollectionItem = function isCollectionItem(node) {
18
- return node && [Type.MAP_KEY, Type.MAP_VALUE, Type.SEQ_ITEM].includes(node.type);
19
- };
20
-
21
- var Document = /*#__PURE__*/function () {
22
- function Document(options) {
23
- _classCallCheck(this, Document);
24
-
25
- this.anchors = new Anchors(options.anchorPrefix);
26
- this.commentBefore = null;
27
- this.comment = null;
28
- this.contents = null;
29
- this.directivesEndMarker = null;
30
- this.errors = [];
31
- this.options = options;
32
- this.schema = null;
33
- this.tagPrefixes = [];
34
- this.version = null;
35
- this.warnings = [];
36
- }
37
-
38
- _createClass(Document, [{
39
- key: "assertCollectionContents",
40
- value: function assertCollectionContents() {
41
- if (this.contents instanceof Collection) return true;
42
- throw new Error('Expected a YAML collection as document contents');
43
- }
44
- }, {
45
- key: "add",
46
- value: function add(value) {
47
- this.assertCollectionContents();
48
- return this.contents.add(value);
49
- }
50
- }, {
51
- key: "addIn",
52
- value: function addIn(path, value) {
53
- this.assertCollectionContents();
54
- this.contents.addIn(path, value);
55
- }
56
- }, {
57
- key: "delete",
58
- value: function _delete(key) {
59
- this.assertCollectionContents();
60
- return this.contents.delete(key);
61
- }
62
- }, {
63
- key: "deleteIn",
64
- value: function deleteIn(path) {
65
- if (isEmptyPath(path)) {
66
- if (this.contents == null) return false;
67
- this.contents = null;
68
- return true;
69
- }
70
-
71
- this.assertCollectionContents();
72
- return this.contents.deleteIn(path);
73
- }
74
- }, {
75
- key: "getDefaults",
76
- value: function getDefaults() {
77
- return Document.defaults[this.version] || Document.defaults[this.options.version] || {};
78
- }
79
- }, {
80
- key: "get",
81
- value: function get(key, keepScalar) {
82
- return this.contents instanceof Collection ? this.contents.get(key, keepScalar) : undefined;
83
- }
84
- }, {
85
- key: "getIn",
86
- value: function getIn(path, keepScalar) {
87
- if (isEmptyPath(path)) return !keepScalar && this.contents instanceof Scalar ? this.contents.value : this.contents;
88
- return this.contents instanceof Collection ? this.contents.getIn(path, keepScalar) : undefined;
89
- }
90
- }, {
91
- key: "has",
92
- value: function has(key) {
93
- return this.contents instanceof Collection ? this.contents.has(key) : false;
94
- }
95
- }, {
96
- key: "hasIn",
97
- value: function hasIn(path) {
98
- if (isEmptyPath(path)) return this.contents !== undefined;
99
- return this.contents instanceof Collection ? this.contents.hasIn(path) : false;
100
- }
101
- }, {
102
- key: "set",
103
- value: function set(key, value) {
104
- this.assertCollectionContents();
105
- this.contents.set(key, value);
106
- }
107
- }, {
108
- key: "setIn",
109
- value: function setIn(path, value) {
110
- if (isEmptyPath(path)) this.contents = value;else {
111
- this.assertCollectionContents();
112
- this.contents.setIn(path, value);
113
- }
114
- }
115
- }, {
116
- key: "setSchema",
117
- value: function setSchema(id, customTags) {
118
- if (!id && !customTags && this.schema) return;
119
- if (typeof id === 'number') id = id.toFixed(1);
120
-
121
- if (id === '1.0' || id === '1.1' || id === '1.2') {
122
- if (this.version) this.version = id;else this.options.version = id;
123
- delete this.options.schema;
124
- } else if (id && typeof id === 'string') {
125
- this.options.schema = id;
126
- }
127
-
128
- if (Array.isArray(customTags)) this.options.customTags = customTags;
129
- var opt = Object.assign({}, this.getDefaults(), this.options);
130
- this.schema = new Schema(opt);
131
- }
132
- }, {
133
- key: "parse",
134
- value: function parse(node, prevDoc) {
135
- if (this.options.keepCstNodes) this.cstNode = node;
136
- if (this.options.keepNodeTypes) this.type = 'DOCUMENT';
137
- var _node$directives = node.directives,
138
- directives = _node$directives === void 0 ? [] : _node$directives,
139
- _node$contents = node.contents,
140
- contents = _node$contents === void 0 ? [] : _node$contents,
141
- directivesEndMarker = node.directivesEndMarker,
142
- error = node.error,
143
- valueRange = node.valueRange;
144
-
145
- if (error) {
146
- if (!error.source) error.source = this;
147
- this.errors.push(error);
148
- }
149
-
150
- this.parseDirectives(directives, prevDoc);
151
- if (directivesEndMarker) this.directivesEndMarker = true;
152
- this.range = valueRange ? [valueRange.start, valueRange.end] : null;
153
- this.setSchema();
154
- this.anchors._cstAliases = [];
155
- this.parseContents(contents);
156
- this.anchors.resolveNodes();
157
-
158
- if (this.options.prettyErrors) {
159
- var _iteratorNormalCompletion = true;
160
- var _didIteratorError = false;
161
- var _iteratorError = undefined;
162
-
163
- try {
164
- for (var _iterator = this.errors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
165
- var _error = _step.value;
166
- if (_error instanceof YAMLError) _error.makePretty();
167
- }
168
- } catch (err) {
169
- _didIteratorError = true;
170
- _iteratorError = err;
171
- } finally {
172
- try {
173
- if (!_iteratorNormalCompletion && _iterator.return != null) {
174
- _iterator.return();
175
- }
176
- } finally {
177
- if (_didIteratorError) {
178
- throw _iteratorError;
179
- }
180
- }
181
- }
182
-
183
- var _iteratorNormalCompletion2 = true;
184
- var _didIteratorError2 = false;
185
- var _iteratorError2 = undefined;
186
-
187
- try {
188
- for (var _iterator2 = this.warnings[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
189
- var warn = _step2.value;
190
- if (warn instanceof YAMLError) warn.makePretty();
191
- }
192
- } catch (err) {
193
- _didIteratorError2 = true;
194
- _iteratorError2 = err;
195
- } finally {
196
- try {
197
- if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
198
- _iterator2.return();
199
- }
200
- } finally {
201
- if (_didIteratorError2) {
202
- throw _iteratorError2;
203
- }
204
- }
205
- }
206
- }
207
-
208
- return this;
209
- }
210
- }, {
211
- key: "parseDirectives",
212
- value: function parseDirectives(directives, prevDoc) {
213
- var _this = this;
214
-
215
- var directiveComments = [];
216
- var hasDirectives = false;
217
- directives.forEach(function (directive) {
218
- var comment = directive.comment,
219
- name = directive.name;
220
-
221
- switch (name) {
222
- case 'TAG':
223
- _this.resolveTagDirective(directive);
224
-
225
- hasDirectives = true;
226
- break;
227
-
228
- case 'YAML':
229
- case 'YAML:1.0':
230
- _this.resolveYamlDirective(directive);
231
-
232
- hasDirectives = true;
233
- break;
234
-
235
- default:
236
- if (name) {
237
- var msg = "YAML only supports %TAG and %YAML directives, and not %".concat(name);
238
-
239
- _this.warnings.push(new YAMLWarning(directive, msg));
240
- }
241
-
242
- }
243
-
244
- if (comment) directiveComments.push(comment);
245
- });
246
-
247
- if (prevDoc && !hasDirectives && '1.1' === (this.version || prevDoc.version || this.options.version)) {
248
- var copyTagPrefix = function copyTagPrefix(_ref) {
249
- var handle = _ref.handle,
250
- prefix = _ref.prefix;
251
- return {
252
- handle: handle,
253
- prefix: prefix
254
- };
255
- };
256
-
257
- this.tagPrefixes = prevDoc.tagPrefixes.map(copyTagPrefix);
258
- this.version = prevDoc.version;
259
- }
260
-
261
- this.commentBefore = directiveComments.join('\n') || null;
262
- }
263
- }, {
264
- key: "parseContents",
265
- value: function parseContents(contents) {
266
- var _this2 = this;
267
-
268
- var comments = {
269
- before: [],
270
- after: []
271
- };
272
- var contentNodes = [];
273
- var spaceBefore = false;
274
- contents.forEach(function (node) {
275
- if (node.valueRange) {
276
- if (contentNodes.length === 1) {
277
- var msg = 'Document is not valid YAML (bad indentation?)';
278
-
279
- _this2.errors.push(new YAMLSyntaxError(node, msg));
280
- }
281
-
282
- var res = _this2.resolveNode(node);
283
-
284
- if (spaceBefore) {
285
- res.spaceBefore = true;
286
- spaceBefore = false;
287
- }
288
-
289
- contentNodes.push(res);
290
- } else if (node.comment !== null) {
291
- var cc = contentNodes.length === 0 ? comments.before : comments.after;
292
- cc.push(node.comment);
293
- } else if (node.type === Type.BLANK_LINE) {
294
- spaceBefore = true;
295
-
296
- if (contentNodes.length === 0 && comments.before.length > 0 && !_this2.commentBefore) {
297
- // space-separated comments at start are parsed as document comments
298
- _this2.commentBefore = comments.before.join('\n');
299
- comments.before = [];
300
- }
301
- }
302
- });
303
-
304
- switch (contentNodes.length) {
305
- case 0:
306
- this.contents = null;
307
- comments.after = comments.before;
308
- break;
309
-
310
- case 1:
311
- this.contents = contentNodes[0];
312
-
313
- if (this.contents) {
314
- var cb = comments.before.join('\n') || null;
315
-
316
- if (cb) {
317
- var cbNode = this.contents instanceof Collection && this.contents.items[0] ? this.contents.items[0] : this.contents;
318
- cbNode.commentBefore = cbNode.commentBefore ? "".concat(cb, "\n").concat(cbNode.commentBefore) : cb;
319
- }
320
- } else {
321
- comments.after = comments.before.concat(comments.after);
322
- }
323
-
324
- break;
325
-
326
- default:
327
- this.contents = contentNodes;
328
-
329
- if (this.contents[0]) {
330
- this.contents[0].commentBefore = comments.before.join('\n') || null;
331
- } else {
332
- comments.after = comments.before.concat(comments.after);
333
- }
334
-
335
- }
336
-
337
- this.comment = comments.after.join('\n') || null;
338
- }
339
- }, {
340
- key: "resolveTagDirective",
341
- value: function resolveTagDirective(directive) {
342
- var _directive$parameters = _slicedToArray(directive.parameters, 2),
343
- handle = _directive$parameters[0],
344
- prefix = _directive$parameters[1];
345
-
346
- if (handle && prefix) {
347
- if (this.tagPrefixes.every(function (p) {
348
- return p.handle !== handle;
349
- })) {
350
- this.tagPrefixes.push({
351
- handle: handle,
352
- prefix: prefix
353
- });
354
- } else {
355
- var msg = 'The %TAG directive must only be given at most once per handle in the same document.';
356
- this.errors.push(new YAMLSemanticError(directive, msg));
357
- }
358
- } else {
359
- var _msg = 'Insufficient parameters given for %TAG directive';
360
- this.errors.push(new YAMLSemanticError(directive, _msg));
361
- }
362
- }
363
- }, {
364
- key: "resolveYamlDirective",
365
- value: function resolveYamlDirective(directive) {
366
- var _directive$parameters2 = _slicedToArray(directive.parameters, 1),
367
- version = _directive$parameters2[0];
368
-
369
- if (directive.name === 'YAML:1.0') version = '1.0';
370
-
371
- if (this.version) {
372
- var msg = 'The %YAML directive must only be given at most once per document.';
373
- this.errors.push(new YAMLSemanticError(directive, msg));
374
- }
375
-
376
- if (!version) {
377
- var _msg2 = 'Insufficient parameters given for %YAML directive';
378
- this.errors.push(new YAMLSemanticError(directive, _msg2));
379
- } else {
380
- if (!Document.defaults[version]) {
381
- var v0 = this.version || this.options.version;
382
-
383
- var _msg3 = "Document will be parsed as YAML ".concat(v0, " rather than YAML ").concat(version);
384
-
385
- this.warnings.push(new YAMLWarning(directive, _msg3));
386
- }
387
-
388
- this.version = version;
389
- }
390
- }
391
- }, {
392
- key: "resolveTagName",
393
- value: function resolveTagName(node) {
394
- var tag = node.tag,
395
- type = node.type;
396
- var nonSpecific = false;
397
-
398
- if (tag) {
399
- var handle = tag.handle,
400
- suffix = tag.suffix,
401
- verbatim = tag.verbatim;
402
-
403
- if (verbatim) {
404
- if (verbatim !== '!' && verbatim !== '!!') return verbatim;
405
- var msg = "Verbatim tags aren't resolved, so ".concat(verbatim, " is invalid.");
406
- this.errors.push(new YAMLSemanticError(node, msg));
407
- } else if (handle === '!' && !suffix) {
408
- nonSpecific = true;
409
- } else {
410
- var prefix = this.tagPrefixes.find(function (p) {
411
- return p.handle === handle;
412
- });
413
-
414
- if (!prefix) {
415
- var dtp = this.getDefaults().tagPrefixes;
416
- if (dtp) prefix = dtp.find(function (p) {
417
- return p.handle === handle;
418
- });
419
- }
420
-
421
- if (prefix) {
422
- if (suffix) {
423
- if (handle === '!' && (this.version || this.options.version) === '1.0') {
424
- if (suffix[0] === '^') return suffix;
425
-
426
- if (/[:/]/.test(suffix)) {
427
- // word/foo -> tag:word.yaml.org,2002:foo
428
- var vocab = suffix.match(/^([a-z0-9-]+)\/(.*)/i);
429
- return vocab ? "tag:".concat(vocab[1], ".yaml.org,2002:").concat(vocab[2]) : "tag:".concat(suffix);
430
- }
431
- }
432
-
433
- return prefix.prefix + decodeURIComponent(suffix);
434
- }
435
-
436
- this.errors.push(new YAMLSemanticError(node, "The ".concat(handle, " tag has no suffix.")));
437
- } else {
438
- var _msg4 = "The ".concat(handle, " tag handle is non-default and was not declared.");
439
-
440
- this.errors.push(new YAMLSemanticError(node, _msg4));
441
- }
442
- }
443
- }
444
-
445
- switch (type) {
446
- case Type.BLOCK_FOLDED:
447
- case Type.BLOCK_LITERAL:
448
- case Type.QUOTE_DOUBLE:
449
- case Type.QUOTE_SINGLE:
450
- return Schema.defaultTags.STR;
451
-
452
- case Type.FLOW_MAP:
453
- case Type.MAP:
454
- return Schema.defaultTags.MAP;
455
-
456
- case Type.FLOW_SEQ:
457
- case Type.SEQ:
458
- return Schema.defaultTags.SEQ;
459
-
460
- case Type.PLAIN:
461
- return nonSpecific ? Schema.defaultTags.STR : null;
462
-
463
- default:
464
- return null;
465
- }
466
- }
467
- }, {
468
- key: "resolveNode",
469
- value: function resolveNode(node) {
470
- if (!node) return null;
471
- var anchors = this.anchors,
472
- errors = this.errors,
473
- schema = this.schema;
474
- var hasAnchor = false;
475
- var hasTag = false;
476
- var comments = {
477
- before: [],
478
- after: []
479
- };
480
- var props = isCollectionItem(node.context.parent) ? node.context.parent.props.concat(node.props) : node.props;
481
- var _iteratorNormalCompletion3 = true;
482
- var _didIteratorError3 = false;
483
- var _iteratorError3 = undefined;
484
-
485
- try {
486
- for (var _iterator3 = props[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
487
- var _step3$value = _step3.value,
488
- start = _step3$value.start,
489
- end = _step3$value.end;
490
-
491
- switch (node.context.src[start]) {
492
- case Char.COMMENT:
493
- {
494
- if (!node.commentHasRequiredWhitespace(start)) {
495
- var _msg7 = 'Comments must be separated from other tokens by white space characters';
496
- errors.push(new YAMLSemanticError(node, _msg7));
497
- }
498
-
499
- var c = node.context.src.slice(start + 1, end);
500
- var header = node.header,
501
- valueRange = node.valueRange;
502
-
503
- if (valueRange && (start > valueRange.start || header && start > header.start)) {
504
- comments.after.push(c);
505
- } else {
506
- comments.before.push(c);
507
- }
508
- }
509
- break;
510
-
511
- case Char.ANCHOR:
512
- if (hasAnchor) {
513
- var _msg8 = 'A node can have at most one anchor';
514
- errors.push(new YAMLSemanticError(node, _msg8));
515
- }
516
-
517
- hasAnchor = true;
518
- break;
519
-
520
- case Char.TAG:
521
- if (hasTag) {
522
- var _msg9 = 'A node can have at most one tag';
523
- errors.push(new YAMLSemanticError(node, _msg9));
524
- }
525
-
526
- hasTag = true;
527
- break;
528
- }
529
- }
530
- } catch (err) {
531
- _didIteratorError3 = true;
532
- _iteratorError3 = err;
533
- } finally {
534
- try {
535
- if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
536
- _iterator3.return();
537
- }
538
- } finally {
539
- if (_didIteratorError3) {
540
- throw _iteratorError3;
541
- }
542
- }
543
- }
544
-
545
- if (hasAnchor) {
546
- var name = node.anchor;
547
- var prev = anchors.getNode(name); // At this point, aliases for any preceding node with the same anchor
548
- // name have already been resolved, so it may safely be renamed.
549
-
550
- if (prev) anchors.map[anchors.newName(name)] = prev; // During parsing, we need to store the CST node in anchors.map as
551
- // anchors need to be available during resolution to allow for
552
- // circular references.
553
-
554
- anchors.map[name] = node;
555
- }
556
-
557
- var res;
558
-
559
- if (node.type === Type.ALIAS) {
560
- if (hasAnchor || hasTag) {
561
- var msg = 'An alias node must not specify any properties';
562
- errors.push(new YAMLSemanticError(node, msg));
563
- }
564
-
565
- var _name = node.rawValue;
566
- var src = anchors.getNode(_name);
567
-
568
- if (!src) {
569
- var _msg5 = "Aliased anchor not found: ".concat(_name);
570
-
571
- errors.push(new YAMLReferenceError(node, _msg5));
572
- return null;
573
- } // Lazy resolution for circular references
574
-
575
-
576
- res = new Alias(src);
577
-
578
- anchors._cstAliases.push(res);
579
- } else {
580
- var tagName = this.resolveTagName(node);
581
-
582
- if (tagName) {
583
- res = schema.resolveNodeWithFallback(this, node, tagName);
584
- } else {
585
- if (node.type !== Type.PLAIN) {
586
- var _msg6 = "Failed to resolve ".concat(node.type, " node here");
587
-
588
- errors.push(new YAMLSyntaxError(node, _msg6));
589
- return null;
590
- }
591
-
592
- try {
593
- res = schema.resolveScalar(node.strValue || '');
594
- } catch (error) {
595
- if (!error.source) error.source = node;
596
- errors.push(error);
597
- return null;
598
- }
599
- }
600
- }
601
-
602
- if (res) {
603
- res.range = [node.range.start, node.range.end];
604
- if (this.options.keepCstNodes) res.cstNode = node;
605
- if (this.options.keepNodeTypes) res.type = node.type;
606
- var cb = comments.before.join('\n');
607
-
608
- if (cb) {
609
- res.commentBefore = res.commentBefore ? "".concat(res.commentBefore, "\n").concat(cb) : cb;
610
- }
611
-
612
- var ca = comments.after.join('\n');
613
- if (ca) res.comment = res.comment ? "".concat(res.comment, "\n").concat(ca) : ca;
614
- }
615
-
616
- return node.resolved = res;
617
- }
618
- }, {
619
- key: "listNonDefaultTags",
620
- value: function listNonDefaultTags() {
621
- return listTagNames(this.contents).filter(function (t) {
622
- return t.indexOf(Schema.defaultPrefix) !== 0;
623
- });
624
- }
625
- }, {
626
- key: "setTagPrefix",
627
- value: function setTagPrefix(handle, prefix) {
628
- if (handle[0] !== '!' || handle[handle.length - 1] !== '!') throw new Error('Handle must start and end with !');
629
-
630
- if (prefix) {
631
- var prev = this.tagPrefixes.find(function (p) {
632
- return p.handle === handle;
633
- });
634
- if (prev) prev.prefix = prefix;else this.tagPrefixes.push({
635
- handle: handle,
636
- prefix: prefix
637
- });
638
- } else {
639
- this.tagPrefixes = this.tagPrefixes.filter(function (p) {
640
- return p.handle !== handle;
641
- });
642
- }
643
- }
644
- }, {
645
- key: "stringifyTag",
646
- value: function stringifyTag(tag) {
647
- if ((this.version || this.options.version) === '1.0') {
648
- var priv = tag.match(/^tag:private\.yaml\.org,2002:([^:/]+)$/);
649
- if (priv) return '!' + priv[1];
650
- var vocab = tag.match(/^tag:([a-zA-Z0-9-]+)\.yaml\.org,2002:(.*)/);
651
- return vocab ? "!".concat(vocab[1], "/").concat(vocab[2]) : "!".concat(tag.replace(/^tag:/, ''));
652
- } else {
653
- var p = this.tagPrefixes.find(function (p) {
654
- return tag.indexOf(p.prefix) === 0;
655
- });
656
-
657
- if (!p) {
658
- var dtp = this.getDefaults().tagPrefixes;
659
- p = dtp && dtp.find(function (p) {
660
- return tag.indexOf(p.prefix) === 0;
661
- });
662
- }
663
-
664
- if (!p) return tag[0] === '!' ? tag : "!<".concat(tag, ">");
665
- var suffix = tag.substr(p.prefix.length).replace(/[!,[\]{}]/g, function (ch) {
666
- return {
667
- '!': '%21',
668
- ',': '%2C',
669
- '[': '%5B',
670
- ']': '%5D',
671
- '{': '%7B',
672
- '}': '%7D'
673
- }[ch];
674
- });
675
- return p.handle + suffix;
676
- }
677
- }
678
- }, {
679
- key: "toJSON",
680
- value: function toJSON(arg) {
681
- var _this3 = this;
682
-
683
- var _this$options = this.options,
684
- keepBlobsInJSON = _this$options.keepBlobsInJSON,
685
- mapAsMap = _this$options.mapAsMap,
686
- maxAliasCount = _this$options.maxAliasCount;
687
- var keep = keepBlobsInJSON && (typeof arg !== 'string' || !(this.contents instanceof Scalar));
688
- var ctx = {
689
- doc: this,
690
- keep: keep,
691
- mapAsMap: keep && !!mapAsMap,
692
- maxAliasCount: maxAliasCount
693
- };
694
- var anchorNames = Object.keys(this.anchors.map);
695
- if (anchorNames.length > 0) ctx.anchors = anchorNames.map(function (name) {
696
- return {
697
- alias: [],
698
- aliasCount: 0,
699
- count: 1,
700
- node: _this3.anchors.map[name]
701
- };
702
- });
703
- return _toJSON(this.contents, arg, ctx);
704
- }
705
- }, {
706
- key: "toString",
707
- value: function toString() {
708
- if (this.errors.length > 0) throw new Error('Document with errors cannot be stringified');
709
- this.setSchema();
710
- var lines = [];
711
- var hasDirectives = false;
712
-
713
- if (this.version) {
714
- var vd = '%YAML 1.2';
715
-
716
- if (this.schema.name === 'yaml-1.1') {
717
- if (this.version === '1.0') vd = '%YAML:1.0';else if (this.version === '1.1') vd = '%YAML 1.1';
718
- }
719
-
720
- lines.push(vd);
721
- hasDirectives = true;
722
- }
723
-
724
- var tagNames = this.listNonDefaultTags();
725
- this.tagPrefixes.forEach(function (_ref2) {
726
- var handle = _ref2.handle,
727
- prefix = _ref2.prefix;
728
-
729
- if (tagNames.some(function (t) {
730
- return t.indexOf(prefix) === 0;
731
- })) {
732
- lines.push("%TAG ".concat(handle, " ").concat(prefix));
733
- hasDirectives = true;
734
- }
735
- });
736
- if (hasDirectives || this.directivesEndMarker) lines.push('---');
737
-
738
- if (this.commentBefore) {
739
- if (hasDirectives || !this.directivesEndMarker) lines.unshift('');
740
- lines.unshift(this.commentBefore.replace(/^/gm, '#'));
741
- }
742
-
743
- var ctx = {
744
- anchors: {},
745
- doc: this,
746
- indent: ''
747
- };
748
- var chompKeep = false;
749
- var contentComment = null;
750
-
751
- if (this.contents) {
752
- if (this.contents instanceof Node) {
753
- if (this.contents.spaceBefore && (hasDirectives || this.directivesEndMarker)) lines.push('');
754
- if (this.contents.commentBefore) lines.push(this.contents.commentBefore.replace(/^/gm, '#')); // top-level block scalars need to be indented if followed by a comment
755
-
756
- ctx.forceBlockIndent = !!this.comment;
757
- contentComment = this.contents.comment;
758
- }
759
-
760
- var onChompKeep = contentComment ? null : function () {
761
- return chompKeep = true;
762
- };
763
- var body = this.schema.stringify(this.contents, ctx, function () {
764
- return contentComment = null;
765
- }, onChompKeep);
766
- lines.push(addComment(body, '', contentComment));
767
- } else if (this.contents !== undefined) {
768
- lines.push(this.schema.stringify(this.contents, ctx));
769
- }
770
-
771
- if (this.comment) {
772
- if ((!chompKeep || contentComment) && lines[lines.length - 1] !== '') lines.push('');
773
- lines.push(this.comment.replace(/^/gm, '#'));
774
- }
775
-
776
- return lines.join('\n') + '\n';
777
- }
778
- }]);
779
-
780
- return Document;
781
- }();
782
-
783
- _defineProperty(Document, "defaults", {
784
- '1.0': {
785
- schema: 'yaml-1.1',
786
- merge: true,
787
- tagPrefixes: [{
788
- handle: '!',
789
- prefix: Schema.defaultPrefix
790
- }, {
791
- handle: '!!',
792
- prefix: 'tag:private.yaml.org,2002:'
793
- }]
794
- },
795
- '1.1': {
796
- schema: 'yaml-1.1',
797
- merge: true,
798
- tagPrefixes: [{
799
- handle: '!',
800
- prefix: '!'
801
- }, {
802
- handle: '!!',
803
- prefix: Schema.defaultPrefix
804
- }]
805
- },
806
- '1.2': {
807
- schema: 'core',
808
- merge: false,
809
- tagPrefixes: [{
810
- handle: '!',
811
- prefix: '!'
812
- }, {
813
- handle: '!!',
814
- prefix: Schema.defaultPrefix
815
- }]
816
- }
817
- });
818
-
819
- export { Document as default };