yaml 1.9.1 → 1.10.2

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