yaml 1.9.2 → 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 (160) 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 +869 -34
  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 -4
  13. package/browser/pair.js +2 -4
  14. package/browser/parse-cst.js +1 -1
  15. package/browser/scalar.js +2 -4
  16. package/browser/schema.js +7 -10
  17. package/browser/seq.js +2 -4
  18. package/browser/types/binary.js +7 -5
  19. package/browser/types/omap.js +3 -4
  20. package/browser/types/pairs.js +3 -4
  21. package/browser/types/set.js +3 -4
  22. package/browser/types/timestamp.js +9 -5
  23. package/browser/types.js +1 -13
  24. package/browser/util.js +1 -18
  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 +20 -84
  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 -9
  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 +22 -8
  37. package/map.js +2 -2
  38. package/package.json +22 -39
  39. package/pair.js +2 -2
  40. package/parse-cst.js +1 -1
  41. package/scalar.js +2 -2
  42. package/schema.js +8 -6
  43. package/seq.js +2 -2
  44. package/types/binary.js +3 -2
  45. package/types/omap.js +3 -2
  46. package/types/pairs.js +3 -2
  47. package/types/set.js +3 -2
  48. package/types/timestamp.js +6 -6
  49. package/types.d.ts +113 -99
  50. package/types.js +16 -11
  51. package/types.mjs +15 -19
  52. package/util.js +14 -14
  53. package/util.mjs +13 -20
  54. package/browser/dist/Anchors.js +0 -130
  55. package/browser/dist/Document.js +0 -824
  56. package/browser/dist/addComment.js +0 -8
  57. package/browser/dist/constants.js +0 -26
  58. package/browser/dist/cst/Alias.js +0 -46
  59. package/browser/dist/cst/BlankLine.js +0 -52
  60. package/browser/dist/cst/BlockValue.js +0 -251
  61. package/browser/dist/cst/Collection.js +0 -278
  62. package/browser/dist/cst/CollectionItem.js +0 -140
  63. package/browser/dist/cst/Comment.js +0 -44
  64. package/browser/dist/cst/Directive.js +0 -76
  65. package/browser/dist/cst/Document.js +0 -286
  66. package/browser/dist/cst/FlowCollection.js +0 -220
  67. package/browser/dist/cst/Node.js +0 -386
  68. package/browser/dist/cst/ParseContext.js +0 -246
  69. package/browser/dist/cst/PlainValue.js +0 -170
  70. package/browser/dist/cst/QuoteDouble.js +0 -245
  71. package/browser/dist/cst/QuoteSingle.js +0 -120
  72. package/browser/dist/cst/Range.js +0 -64
  73. package/browser/dist/cst/parse.js +0 -48
  74. package/browser/dist/cst/source-utils.js +0 -168
  75. package/browser/dist/errors.js +0 -127
  76. package/browser/dist/foldFlowLines.js +0 -138
  77. package/browser/dist/listTagNames.js +0 -28
  78. package/browser/dist/schema/Alias.js +0 -135
  79. package/browser/dist/schema/Collection.js +0 -260
  80. package/browser/dist/schema/Map.js +0 -161
  81. package/browser/dist/schema/Merge.js +0 -118
  82. package/browser/dist/schema/Node.js +0 -4
  83. package/browser/dist/schema/Pair.js +0 -194
  84. package/browser/dist/schema/Scalar.js +0 -42
  85. package/browser/dist/schema/Seq.js +0 -116
  86. package/browser/dist/schema/index.js +0 -368
  87. package/browser/dist/schema/parseMap.js +0 -312
  88. package/browser/dist/schema/parseSeq.js +0 -168
  89. package/browser/dist/schema/parseUtils.js +0 -106
  90. package/browser/dist/stringify.js +0 -332
  91. package/browser/dist/tags/core.js +0 -141
  92. package/browser/dist/tags/failsafe/index.js +0 -4
  93. package/browser/dist/tags/failsafe/map.js +0 -53
  94. package/browser/dist/tags/failsafe/seq.js +0 -39
  95. package/browser/dist/tags/failsafe/string.js +0 -28
  96. package/browser/dist/tags/index.js +0 -36
  97. package/browser/dist/tags/json.js +0 -77
  98. package/browser/dist/tags/options.js +0 -26
  99. package/browser/dist/tags/yaml-1.1/binary.js +0 -87
  100. package/browser/dist/tags/yaml-1.1/index.js +0 -189
  101. package/browser/dist/tags/yaml-1.1/omap.js +0 -137
  102. package/browser/dist/tags/yaml-1.1/pairs.js +0 -78
  103. package/browser/dist/tags/yaml-1.1/set.js +0 -118
  104. package/browser/dist/tags/yaml-1.1/timestamp.js +0 -97
  105. package/browser/dist/test-events.js +0 -163
  106. package/browser/dist/toJSON.js +0 -19
  107. package/browser/dist/warnings.js +0 -39
  108. package/dist/Anchors.js +0 -120
  109. package/dist/Document.js +0 -714
  110. package/dist/addComment.js +0 -14
  111. package/dist/constants.js +0 -31
  112. package/dist/cst/Alias.js +0 -33
  113. package/dist/cst/BlankLine.js +0 -40
  114. package/dist/cst/BlockValue.js +0 -243
  115. package/dist/cst/Collection.js +0 -266
  116. package/dist/cst/CollectionItem.js +0 -135
  117. package/dist/cst/Comment.js +0 -33
  118. package/dist/cst/Directive.js +0 -59
  119. package/dist/cst/Document.js +0 -276
  120. package/dist/cst/FlowCollection.js +0 -213
  121. package/dist/cst/Node.js +0 -360
  122. package/dist/cst/ParseContext.js +0 -253
  123. package/dist/cst/PlainValue.js +0 -156
  124. package/dist/cst/QuoteDouble.js +0 -232
  125. package/dist/cst/QuoteSingle.js +0 -108
  126. package/dist/cst/Range.js +0 -60
  127. package/dist/cst/parse.js +0 -50
  128. package/dist/cst/source-utils.js +0 -175
  129. package/dist/errors.js +0 -97
  130. package/dist/foldFlowLines.js +0 -143
  131. package/dist/listTagNames.js +0 -33
  132. package/dist/schema/Alias.js +0 -105
  133. package/dist/schema/Collection.js +0 -184
  134. package/dist/schema/Map.js +0 -98
  135. package/dist/schema/Merge.js +0 -75
  136. package/dist/schema/Node.js +0 -7
  137. package/dist/schema/Pair.js +0 -174
  138. package/dist/schema/Scalar.js +0 -26
  139. package/dist/schema/Seq.js +0 -73
  140. package/dist/schema/index.js +0 -310
  141. package/dist/schema/parseMap.js +0 -334
  142. package/dist/schema/parseSeq.js +0 -175
  143. package/dist/schema/parseUtils.js +0 -101
  144. package/dist/stringify.js +0 -352
  145. package/dist/tags/core.js +0 -121
  146. package/dist/tags/failsafe/index.js +0 -12
  147. package/dist/tags/failsafe/map.js +0 -32
  148. package/dist/tags/failsafe/seq.js +0 -29
  149. package/dist/tags/failsafe/string.js +0 -37
  150. package/dist/tags/index.js +0 -53
  151. package/dist/tags/json.js +0 -64
  152. package/dist/tags/options.js +0 -36
  153. package/dist/tags/yaml-1.1/binary.js +0 -94
  154. package/dist/tags/yaml-1.1/index.js +0 -162
  155. package/dist/tags/yaml-1.1/omap.js +0 -100
  156. package/dist/tags/yaml-1.1/pairs.js +0 -75
  157. package/dist/tags/yaml-1.1/set.js +0 -82
  158. package/dist/tags/yaml-1.1/timestamp.js +0 -90
  159. package/dist/toJSON.js +0 -21
  160. package/dist/warnings.js +0 -48
@@ -1,24 +1,9 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _inherits from "@babel/runtime/helpers/inherits";
3
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
4
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
1
+ import { d as defaultTagPrefix, _ as _createForOfIteratorHelper, a as _typeof, b as _createClass, c as _classCallCheck, e as _defineProperty, Y as YAMLSyntaxError, T as Type, f as YAMLWarning, g as YAMLSemanticError, h as _slicedToArray, i as YAMLError, j as _inherits, k as _createSuper } from './PlainValue-ff5147c6.js';
2
+ import { parse as parse$1 } from './parse-cst.js';
3
+ import { b as binaryOptions, a as boolOptions, i as intOptions, n as nullOptions, s as strOptions, N as Node, P as Pair, S as Scalar, c as stringifyString, A as Alias, Y as YAMLSeq, d as YAMLMap, M as Merge, C as Collection, r as resolveNode, e as isEmptyPath, t as toJSON, f as addComment } from './resolveSeq-04825f30.js';
4
+ import { S as Schema } from './Schema-2bf2c74e.js';
5
+ import { w as warn } from './warnings-0e4b70d3.js';
5
6
 
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
- function _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
13
-
14
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
15
-
16
- import { parse as parseCST } from './cst/parse';
17
- import { Document as YAMLDocument } from './Document';
18
- import { YAMLSemanticError } from './errors';
19
- import { Schema } from './schema';
20
- import { binaryOptions, boolOptions, intOptions, nullOptions, strOptions } from './tags/options';
21
- import { warn } from './warnings';
22
7
  var defaultOptions = {
23
8
  anchorPrefix: 'a',
24
9
  customTags: null,
@@ -76,6 +61,854 @@ var scalarOptions = {
76
61
  }
77
62
 
78
63
  };
64
+ var documentOptions = {
65
+ '1.0': {
66
+ schema: 'yaml-1.1',
67
+ merge: true,
68
+ tagPrefixes: [{
69
+ handle: '!',
70
+ prefix: defaultTagPrefix
71
+ }, {
72
+ handle: '!!',
73
+ prefix: 'tag:private.yaml.org,2002:'
74
+ }]
75
+ },
76
+ '1.1': {
77
+ schema: 'yaml-1.1',
78
+ merge: true,
79
+ tagPrefixes: [{
80
+ handle: '!',
81
+ prefix: '!'
82
+ }, {
83
+ handle: '!!',
84
+ prefix: defaultTagPrefix
85
+ }]
86
+ },
87
+ '1.2': {
88
+ schema: 'core',
89
+ merge: false,
90
+ tagPrefixes: [{
91
+ handle: '!',
92
+ prefix: '!'
93
+ }, {
94
+ handle: '!!',
95
+ prefix: defaultTagPrefix
96
+ }]
97
+ }
98
+ };
99
+
100
+ function stringifyTag(doc, tag) {
101
+ if ((doc.version || doc.options.version) === '1.0') {
102
+ var priv = tag.match(/^tag:private\.yaml\.org,2002:([^:/]+)$/);
103
+ if (priv) return '!' + priv[1];
104
+ var vocab = tag.match(/^tag:([a-zA-Z0-9-]+)\.yaml\.org,2002:(.*)/);
105
+ return vocab ? "!".concat(vocab[1], "/").concat(vocab[2]) : "!".concat(tag.replace(/^tag:/, ''));
106
+ }
107
+
108
+ var p = doc.tagPrefixes.find(function (p) {
109
+ return tag.indexOf(p.prefix) === 0;
110
+ });
111
+
112
+ if (!p) {
113
+ var dtp = doc.getDefaults().tagPrefixes;
114
+ p = dtp && dtp.find(function (p) {
115
+ return tag.indexOf(p.prefix) === 0;
116
+ });
117
+ }
118
+
119
+ if (!p) return tag[0] === '!' ? tag : "!<".concat(tag, ">");
120
+ var suffix = tag.substr(p.prefix.length).replace(/[!,[\]{}]/g, function (ch) {
121
+ return {
122
+ '!': '%21',
123
+ ',': '%2C',
124
+ '[': '%5B',
125
+ ']': '%5D',
126
+ '{': '%7B',
127
+ '}': '%7D'
128
+ }[ch];
129
+ });
130
+ return p.handle + suffix;
131
+ }
132
+
133
+ function getTagObject(tags, item) {
134
+ if (item instanceof Alias) return Alias;
135
+
136
+ if (item.tag) {
137
+ var match = tags.filter(function (t) {
138
+ return t.tag === item.tag;
139
+ });
140
+ if (match.length > 0) return match.find(function (t) {
141
+ return t.format === item.format;
142
+ }) || match[0];
143
+ }
144
+
145
+ var tagObj, obj;
146
+
147
+ if (item instanceof Scalar) {
148
+ obj = item.value; // TODO: deprecate/remove class check
149
+
150
+ var _match = tags.filter(function (t) {
151
+ return t.identify && t.identify(obj) || t.class && obj instanceof t.class;
152
+ });
153
+
154
+ tagObj = _match.find(function (t) {
155
+ return t.format === item.format;
156
+ }) || _match.find(function (t) {
157
+ return !t.format;
158
+ });
159
+ } else {
160
+ obj = item;
161
+ tagObj = tags.find(function (t) {
162
+ return t.nodeClass && obj instanceof t.nodeClass;
163
+ });
164
+ }
165
+
166
+ if (!tagObj) {
167
+ var name = obj && obj.constructor ? obj.constructor.name : _typeof(obj);
168
+ throw new Error("Tag not resolved for ".concat(name, " value"));
169
+ }
170
+
171
+ return tagObj;
172
+ } // needs to be called before value stringifier to allow for circular anchor refs
173
+
174
+
175
+ function stringifyProps(node, tagObj, _ref) {
176
+ var anchors = _ref.anchors,
177
+ doc = _ref.doc;
178
+ var props = [];
179
+ var anchor = doc.anchors.getName(node);
180
+
181
+ if (anchor) {
182
+ anchors[anchor] = node;
183
+ props.push("&".concat(anchor));
184
+ }
185
+
186
+ if (node.tag) {
187
+ props.push(stringifyTag(doc, node.tag));
188
+ } else if (!tagObj.default) {
189
+ props.push(stringifyTag(doc, tagObj.tag));
190
+ }
191
+
192
+ return props.join(' ');
193
+ }
194
+
195
+ function stringify(item, ctx, onComment, onChompKeep) {
196
+ var _ctx$doc = ctx.doc,
197
+ anchors = _ctx$doc.anchors,
198
+ schema = _ctx$doc.schema;
199
+ var tagObj;
200
+
201
+ if (!(item instanceof Node)) {
202
+ var createCtx = {
203
+ aliasNodes: [],
204
+ onTagObj: function onTagObj(o) {
205
+ return tagObj = o;
206
+ },
207
+ prevObjects: new Map()
208
+ };
209
+ item = schema.createNode(item, true, null, createCtx);
210
+
211
+ var _iterator = _createForOfIteratorHelper(createCtx.aliasNodes),
212
+ _step;
213
+
214
+ try {
215
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
216
+ var alias = _step.value;
217
+ alias.source = alias.source.node;
218
+ var name = anchors.getName(alias.source);
219
+
220
+ if (!name) {
221
+ name = anchors.newName();
222
+ anchors.map[name] = alias.source;
223
+ }
224
+ }
225
+ } catch (err) {
226
+ _iterator.e(err);
227
+ } finally {
228
+ _iterator.f();
229
+ }
230
+ }
231
+
232
+ if (item instanceof Pair) return item.toString(ctx, onComment, onChompKeep);
233
+ if (!tagObj) tagObj = getTagObject(schema.tags, item);
234
+ var props = stringifyProps(item, tagObj, ctx);
235
+ if (props.length > 0) ctx.indentAtStart = (ctx.indentAtStart || 0) + props.length + 1;
236
+ var str = typeof tagObj.stringify === 'function' ? tagObj.stringify(item, ctx, onComment, onChompKeep) : item instanceof Scalar ? stringifyString(item, ctx, onComment, onChompKeep) : item.toString(ctx, onComment, onChompKeep);
237
+ if (!props) return str;
238
+ return item instanceof Scalar || str[0] === '{' || str[0] === '[' ? "".concat(props, " ").concat(str) : "".concat(props, "\n").concat(ctx.indent).concat(str);
239
+ }
240
+
241
+ var Anchors = /*#__PURE__*/function () {
242
+ _createClass(Anchors, null, [{
243
+ key: "validAnchorNode",
244
+ value: function validAnchorNode(node) {
245
+ return node instanceof Scalar || node instanceof YAMLSeq || node instanceof YAMLMap;
246
+ }
247
+ }]);
248
+
249
+ function Anchors(prefix) {
250
+ _classCallCheck(this, Anchors);
251
+
252
+ _defineProperty(this, "map", {});
253
+
254
+ this.prefix = prefix;
255
+ }
256
+
257
+ _createClass(Anchors, [{
258
+ key: "createAlias",
259
+ value: function createAlias(node, name) {
260
+ this.setAnchor(node, name);
261
+ return new Alias(node);
262
+ }
263
+ }, {
264
+ key: "createMergePair",
265
+ value: function createMergePair() {
266
+ var _this = this;
267
+
268
+ var merge = new Merge();
269
+
270
+ for (var _len = arguments.length, sources = new Array(_len), _key = 0; _key < _len; _key++) {
271
+ sources[_key] = arguments[_key];
272
+ }
273
+
274
+ merge.value.items = sources.map(function (s) {
275
+ if (s instanceof Alias) {
276
+ if (s.source instanceof YAMLMap) return s;
277
+ } else if (s instanceof YAMLMap) {
278
+ return _this.createAlias(s);
279
+ }
280
+
281
+ throw new Error('Merge sources must be Map nodes or their Aliases');
282
+ });
283
+ return merge;
284
+ }
285
+ }, {
286
+ key: "getName",
287
+ value: function getName(node) {
288
+ var map = this.map;
289
+ return Object.keys(map).find(function (a) {
290
+ return map[a] === node;
291
+ });
292
+ }
293
+ }, {
294
+ key: "getNames",
295
+ value: function getNames() {
296
+ return Object.keys(this.map);
297
+ }
298
+ }, {
299
+ key: "getNode",
300
+ value: function getNode(name) {
301
+ return this.map[name];
302
+ }
303
+ }, {
304
+ key: "newName",
305
+ value: function newName(prefix) {
306
+ if (!prefix) prefix = this.prefix;
307
+ var names = Object.keys(this.map);
308
+
309
+ for (var i = 1; true; ++i) {
310
+ var name = "".concat(prefix).concat(i);
311
+ if (!names.includes(name)) return name;
312
+ }
313
+ } // During parsing, map & aliases contain CST nodes
314
+
315
+ }, {
316
+ key: "resolveNodes",
317
+ value: function resolveNodes() {
318
+ var map = this.map,
319
+ _cstAliases = this._cstAliases;
320
+ Object.keys(map).forEach(function (a) {
321
+ map[a] = map[a].resolved;
322
+ });
323
+
324
+ _cstAliases.forEach(function (a) {
325
+ a.source = a.source.resolved;
326
+ });
327
+
328
+ delete this._cstAliases;
329
+ }
330
+ }, {
331
+ key: "setAnchor",
332
+ value: function setAnchor(node, name) {
333
+ if (node != null && !Anchors.validAnchorNode(node)) {
334
+ throw new Error('Anchors may only be set for Scalar, Seq and Map nodes');
335
+ }
336
+
337
+ if (name && /[\x00-\x19\s,[\]{}]/.test(name)) {
338
+ throw new Error('Anchor names must not contain whitespace or control characters');
339
+ }
340
+
341
+ var map = this.map;
342
+ var prev = node && Object.keys(map).find(function (a) {
343
+ return map[a] === node;
344
+ });
345
+
346
+ if (prev) {
347
+ if (!name) {
348
+ return prev;
349
+ } else if (prev !== name) {
350
+ delete map[prev];
351
+ map[name] = node;
352
+ }
353
+ } else {
354
+ if (!name) {
355
+ if (!node) return null;
356
+ name = this.newName();
357
+ }
358
+
359
+ map[name] = node;
360
+ }
361
+
362
+ return name;
363
+ }
364
+ }]);
365
+
366
+ return Anchors;
367
+ }();
368
+
369
+ var visit = function visit(node, tags) {
370
+ if (node && _typeof(node) === 'object') {
371
+ var tag = node.tag;
372
+
373
+ if (node instanceof Collection) {
374
+ if (tag) tags[tag] = true;
375
+ node.items.forEach(function (n) {
376
+ return visit(n, tags);
377
+ });
378
+ } else if (node instanceof Pair) {
379
+ visit(node.key, tags);
380
+ visit(node.value, tags);
381
+ } else if (node instanceof Scalar) {
382
+ if (tag) tags[tag] = true;
383
+ }
384
+ }
385
+
386
+ return tags;
387
+ };
388
+
389
+ var listTagNames = function listTagNames(node) {
390
+ return Object.keys(visit(node, {}));
391
+ };
392
+
393
+ function parseContents(doc, contents) {
394
+ var comments = {
395
+ before: [],
396
+ after: []
397
+ };
398
+ var body = undefined;
399
+ var spaceBefore = false;
400
+
401
+ var _iterator = _createForOfIteratorHelper(contents),
402
+ _step;
403
+
404
+ try {
405
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
406
+ var node = _step.value;
407
+
408
+ if (node.valueRange) {
409
+ if (body !== undefined) {
410
+ var msg = 'Document contains trailing content not separated by a ... or --- line';
411
+ doc.errors.push(new YAMLSyntaxError(node, msg));
412
+ break;
413
+ }
414
+
415
+ var res = resolveNode(doc, node);
416
+
417
+ if (spaceBefore) {
418
+ res.spaceBefore = true;
419
+ spaceBefore = false;
420
+ }
421
+
422
+ body = res;
423
+ } else if (node.comment !== null) {
424
+ var cc = body === undefined ? comments.before : comments.after;
425
+ cc.push(node.comment);
426
+ } else if (node.type === Type.BLANK_LINE) {
427
+ spaceBefore = true;
428
+
429
+ if (body === undefined && comments.before.length > 0 && !doc.commentBefore) {
430
+ // space-separated comments at start are parsed as document comments
431
+ doc.commentBefore = comments.before.join('\n');
432
+ comments.before = [];
433
+ }
434
+ }
435
+ }
436
+ } catch (err) {
437
+ _iterator.e(err);
438
+ } finally {
439
+ _iterator.f();
440
+ }
441
+
442
+ doc.contents = body || null;
443
+
444
+ if (!body) {
445
+ doc.comment = comments.before.concat(comments.after).join('\n') || null;
446
+ } else {
447
+ var cb = comments.before.join('\n');
448
+
449
+ if (cb) {
450
+ var cbNode = body instanceof Collection && body.items[0] ? body.items[0] : body;
451
+ cbNode.commentBefore = cbNode.commentBefore ? "".concat(cb, "\n").concat(cbNode.commentBefore) : cb;
452
+ }
453
+
454
+ doc.comment = comments.after.join('\n') || null;
455
+ }
456
+ }
457
+
458
+ function resolveTagDirective(_ref, directive) {
459
+ var tagPrefixes = _ref.tagPrefixes;
460
+
461
+ var _directive$parameters = _slicedToArray(directive.parameters, 2),
462
+ handle = _directive$parameters[0],
463
+ prefix = _directive$parameters[1];
464
+
465
+ if (!handle || !prefix) {
466
+ var msg = 'Insufficient parameters given for %TAG directive';
467
+ throw new YAMLSemanticError(directive, msg);
468
+ }
469
+
470
+ if (tagPrefixes.some(function (p) {
471
+ return p.handle === handle;
472
+ })) {
473
+ var _msg = 'The %TAG directive must only be given at most once per handle in the same document.';
474
+ throw new YAMLSemanticError(directive, _msg);
475
+ }
476
+
477
+ return {
478
+ handle: handle,
479
+ prefix: prefix
480
+ };
481
+ }
482
+
483
+ function resolveYamlDirective(doc, directive) {
484
+ var _directive$parameters2 = _slicedToArray(directive.parameters, 1),
485
+ version = _directive$parameters2[0];
486
+
487
+ if (directive.name === 'YAML:1.0') version = '1.0';
488
+
489
+ if (!version) {
490
+ var msg = 'Insufficient parameters given for %YAML directive';
491
+ throw new YAMLSemanticError(directive, msg);
492
+ }
493
+
494
+ if (!documentOptions[version]) {
495
+ var v0 = doc.version || doc.options.version;
496
+
497
+ var _msg2 = "Document will be parsed as YAML ".concat(v0, " rather than YAML ").concat(version);
498
+
499
+ doc.warnings.push(new YAMLWarning(directive, _msg2));
500
+ }
501
+
502
+ return version;
503
+ }
504
+
505
+ function parseDirectives(doc, directives, prevDoc) {
506
+ var directiveComments = [];
507
+ var hasDirectives = false;
508
+
509
+ var _iterator = _createForOfIteratorHelper(directives),
510
+ _step;
511
+
512
+ try {
513
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
514
+ var directive = _step.value;
515
+ var comment = directive.comment,
516
+ name = directive.name;
517
+
518
+ switch (name) {
519
+ case 'TAG':
520
+ try {
521
+ doc.tagPrefixes.push(resolveTagDirective(doc, directive));
522
+ } catch (error) {
523
+ doc.errors.push(error);
524
+ }
525
+
526
+ hasDirectives = true;
527
+ break;
528
+
529
+ case 'YAML':
530
+ case 'YAML:1.0':
531
+ if (doc.version) {
532
+ var msg = 'The %YAML directive must only be given at most once per document.';
533
+ doc.errors.push(new YAMLSemanticError(directive, msg));
534
+ }
535
+
536
+ try {
537
+ doc.version = resolveYamlDirective(doc, directive);
538
+ } catch (error) {
539
+ doc.errors.push(error);
540
+ }
541
+
542
+ hasDirectives = true;
543
+ break;
544
+
545
+ default:
546
+ if (name) {
547
+ var _msg3 = "YAML only supports %TAG and %YAML directives, and not %".concat(name);
548
+
549
+ doc.warnings.push(new YAMLWarning(directive, _msg3));
550
+ }
551
+
552
+ }
553
+
554
+ if (comment) directiveComments.push(comment);
555
+ }
556
+ } catch (err) {
557
+ _iterator.e(err);
558
+ } finally {
559
+ _iterator.f();
560
+ }
561
+
562
+ if (prevDoc && !hasDirectives && '1.1' === (doc.version || prevDoc.version || doc.options.version)) {
563
+ var copyTagPrefix = function copyTagPrefix(_ref2) {
564
+ var handle = _ref2.handle,
565
+ prefix = _ref2.prefix;
566
+ return {
567
+ handle: handle,
568
+ prefix: prefix
569
+ };
570
+ };
571
+
572
+ doc.tagPrefixes = prevDoc.tagPrefixes.map(copyTagPrefix);
573
+ doc.version = prevDoc.version;
574
+ }
575
+
576
+ doc.commentBefore = directiveComments.join('\n') || null;
577
+ }
578
+
579
+ function assertCollection(contents) {
580
+ if (contents instanceof Collection) return true;
581
+ throw new Error('Expected a YAML collection as document contents');
582
+ }
583
+
584
+ var Document = /*#__PURE__*/function () {
585
+ function Document(options) {
586
+ _classCallCheck(this, Document);
587
+
588
+ this.anchors = new Anchors(options.anchorPrefix);
589
+ this.commentBefore = null;
590
+ this.comment = null;
591
+ this.contents = null;
592
+ this.directivesEndMarker = null;
593
+ this.errors = [];
594
+ this.options = options;
595
+ this.schema = null;
596
+ this.tagPrefixes = [];
597
+ this.version = null;
598
+ this.warnings = [];
599
+ }
600
+
601
+ _createClass(Document, [{
602
+ key: "add",
603
+ value: function add(value) {
604
+ assertCollection(this.contents);
605
+ return this.contents.add(value);
606
+ }
607
+ }, {
608
+ key: "addIn",
609
+ value: function addIn(path, value) {
610
+ assertCollection(this.contents);
611
+ this.contents.addIn(path, value);
612
+ }
613
+ }, {
614
+ key: "delete",
615
+ value: function _delete(key) {
616
+ assertCollection(this.contents);
617
+ return this.contents.delete(key);
618
+ }
619
+ }, {
620
+ key: "deleteIn",
621
+ value: function deleteIn(path) {
622
+ if (isEmptyPath(path)) {
623
+ if (this.contents == null) return false;
624
+ this.contents = null;
625
+ return true;
626
+ }
627
+
628
+ assertCollection(this.contents);
629
+ return this.contents.deleteIn(path);
630
+ }
631
+ }, {
632
+ key: "getDefaults",
633
+ value: function getDefaults() {
634
+ return Document.defaults[this.version] || Document.defaults[this.options.version] || {};
635
+ }
636
+ }, {
637
+ key: "get",
638
+ value: function get(key, keepScalar) {
639
+ return this.contents instanceof Collection ? this.contents.get(key, keepScalar) : undefined;
640
+ }
641
+ }, {
642
+ key: "getIn",
643
+ value: function getIn(path, keepScalar) {
644
+ if (isEmptyPath(path)) return !keepScalar && this.contents instanceof Scalar ? this.contents.value : this.contents;
645
+ return this.contents instanceof Collection ? this.contents.getIn(path, keepScalar) : undefined;
646
+ }
647
+ }, {
648
+ key: "has",
649
+ value: function has(key) {
650
+ return this.contents instanceof Collection ? this.contents.has(key) : false;
651
+ }
652
+ }, {
653
+ key: "hasIn",
654
+ value: function hasIn(path) {
655
+ if (isEmptyPath(path)) return this.contents !== undefined;
656
+ return this.contents instanceof Collection ? this.contents.hasIn(path) : false;
657
+ }
658
+ }, {
659
+ key: "set",
660
+ value: function set(key, value) {
661
+ assertCollection(this.contents);
662
+ this.contents.set(key, value);
663
+ }
664
+ }, {
665
+ key: "setIn",
666
+ value: function setIn(path, value) {
667
+ if (isEmptyPath(path)) this.contents = value;else {
668
+ assertCollection(this.contents);
669
+ this.contents.setIn(path, value);
670
+ }
671
+ }
672
+ }, {
673
+ key: "setSchema",
674
+ value: function setSchema(id, customTags) {
675
+ if (!id && !customTags && this.schema) return;
676
+ if (typeof id === 'number') id = id.toFixed(1);
677
+
678
+ if (id === '1.0' || id === '1.1' || id === '1.2') {
679
+ if (this.version) this.version = id;else this.options.version = id;
680
+ delete this.options.schema;
681
+ } else if (id && typeof id === 'string') {
682
+ this.options.schema = id;
683
+ }
684
+
685
+ if (Array.isArray(customTags)) this.options.customTags = customTags;
686
+ var opt = Object.assign({}, this.getDefaults(), this.options);
687
+ this.schema = new Schema(opt);
688
+ }
689
+ }, {
690
+ key: "parse",
691
+ value: function parse(node, prevDoc) {
692
+ if (this.options.keepCstNodes) this.cstNode = node;
693
+ if (this.options.keepNodeTypes) this.type = 'DOCUMENT';
694
+ var _node$directives = node.directives,
695
+ directives = _node$directives === void 0 ? [] : _node$directives,
696
+ _node$contents = node.contents,
697
+ contents = _node$contents === void 0 ? [] : _node$contents,
698
+ directivesEndMarker = node.directivesEndMarker,
699
+ error = node.error,
700
+ valueRange = node.valueRange;
701
+
702
+ if (error) {
703
+ if (!error.source) error.source = this;
704
+ this.errors.push(error);
705
+ }
706
+
707
+ parseDirectives(this, directives, prevDoc);
708
+ if (directivesEndMarker) this.directivesEndMarker = true;
709
+ this.range = valueRange ? [valueRange.start, valueRange.end] : null;
710
+ this.setSchema();
711
+ this.anchors._cstAliases = [];
712
+ parseContents(this, contents);
713
+ this.anchors.resolveNodes();
714
+
715
+ if (this.options.prettyErrors) {
716
+ var _iterator = _createForOfIteratorHelper(this.errors),
717
+ _step;
718
+
719
+ try {
720
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
721
+ var _error = _step.value;
722
+ if (_error instanceof YAMLError) _error.makePretty();
723
+ }
724
+ } catch (err) {
725
+ _iterator.e(err);
726
+ } finally {
727
+ _iterator.f();
728
+ }
729
+
730
+ var _iterator2 = _createForOfIteratorHelper(this.warnings),
731
+ _step2;
732
+
733
+ try {
734
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
735
+ var warn = _step2.value;
736
+ if (warn instanceof YAMLError) warn.makePretty();
737
+ }
738
+ } catch (err) {
739
+ _iterator2.e(err);
740
+ } finally {
741
+ _iterator2.f();
742
+ }
743
+ }
744
+
745
+ return this;
746
+ }
747
+ }, {
748
+ key: "listNonDefaultTags",
749
+ value: function listNonDefaultTags() {
750
+ return listTagNames(this.contents).filter(function (t) {
751
+ return t.indexOf(Schema.defaultPrefix) !== 0;
752
+ });
753
+ }
754
+ }, {
755
+ key: "setTagPrefix",
756
+ value: function setTagPrefix(handle, prefix) {
757
+ if (handle[0] !== '!' || handle[handle.length - 1] !== '!') throw new Error('Handle must start and end with !');
758
+
759
+ if (prefix) {
760
+ var prev = this.tagPrefixes.find(function (p) {
761
+ return p.handle === handle;
762
+ });
763
+ if (prev) prev.prefix = prefix;else this.tagPrefixes.push({
764
+ handle: handle,
765
+ prefix: prefix
766
+ });
767
+ } else {
768
+ this.tagPrefixes = this.tagPrefixes.filter(function (p) {
769
+ return p.handle !== handle;
770
+ });
771
+ }
772
+ }
773
+ }, {
774
+ key: "toJSON",
775
+ value: function toJSON$1(arg, onAnchor) {
776
+ var _this = this;
777
+
778
+ var _this$options = this.options,
779
+ keepBlobsInJSON = _this$options.keepBlobsInJSON,
780
+ mapAsMap = _this$options.mapAsMap,
781
+ maxAliasCount = _this$options.maxAliasCount;
782
+ var keep = keepBlobsInJSON && (typeof arg !== 'string' || !(this.contents instanceof Scalar));
783
+ var ctx = {
784
+ doc: this,
785
+ indentStep: ' ',
786
+ keep: keep,
787
+ mapAsMap: keep && !!mapAsMap,
788
+ maxAliasCount: maxAliasCount,
789
+ stringify: stringify // Requiring directly in Pair would create circular dependencies
790
+
791
+ };
792
+ var anchorNames = Object.keys(this.anchors.map);
793
+ if (anchorNames.length > 0) ctx.anchors = new Map(anchorNames.map(function (name) {
794
+ return [_this.anchors.map[name], {
795
+ alias: [],
796
+ aliasCount: 0,
797
+ count: 1
798
+ }];
799
+ }));
800
+
801
+ var res = toJSON(this.contents, arg, ctx);
802
+
803
+ if (typeof onAnchor === 'function' && ctx.anchors) {
804
+ var _iterator3 = _createForOfIteratorHelper(ctx.anchors.values()),
805
+ _step3;
806
+
807
+ try {
808
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
809
+ var _step3$value = _step3.value,
810
+ count = _step3$value.count,
811
+ _res = _step3$value.res;
812
+ onAnchor(_res, count);
813
+ }
814
+ } catch (err) {
815
+ _iterator3.e(err);
816
+ } finally {
817
+ _iterator3.f();
818
+ }
819
+ }
820
+
821
+ return res;
822
+ }
823
+ }, {
824
+ key: "toString",
825
+ value: function toString() {
826
+ if (this.errors.length > 0) throw new Error('Document with errors cannot be stringified');
827
+ var indentSize = this.options.indent;
828
+
829
+ if (!Number.isInteger(indentSize) || indentSize <= 0) {
830
+ var s = JSON.stringify(indentSize);
831
+ throw new Error("\"indent\" option must be a positive integer, not ".concat(s));
832
+ }
833
+
834
+ this.setSchema();
835
+ var lines = [];
836
+ var hasDirectives = false;
837
+
838
+ if (this.version) {
839
+ var vd = '%YAML 1.2';
840
+
841
+ if (this.schema.name === 'yaml-1.1') {
842
+ if (this.version === '1.0') vd = '%YAML:1.0';else if (this.version === '1.1') vd = '%YAML 1.1';
843
+ }
844
+
845
+ lines.push(vd);
846
+ hasDirectives = true;
847
+ }
848
+
849
+ var tagNames = this.listNonDefaultTags();
850
+ this.tagPrefixes.forEach(function (_ref) {
851
+ var handle = _ref.handle,
852
+ prefix = _ref.prefix;
853
+
854
+ if (tagNames.some(function (t) {
855
+ return t.indexOf(prefix) === 0;
856
+ })) {
857
+ lines.push("%TAG ".concat(handle, " ").concat(prefix));
858
+ hasDirectives = true;
859
+ }
860
+ });
861
+ if (hasDirectives || this.directivesEndMarker) lines.push('---');
862
+
863
+ if (this.commentBefore) {
864
+ if (hasDirectives || !this.directivesEndMarker) lines.unshift('');
865
+ lines.unshift(this.commentBefore.replace(/^/gm, '#'));
866
+ }
867
+
868
+ var ctx = {
869
+ anchors: {},
870
+ doc: this,
871
+ indent: '',
872
+ indentStep: ' '.repeat(indentSize),
873
+ stringify: stringify // Requiring directly in nodes would create circular dependencies
874
+
875
+ };
876
+ var chompKeep = false;
877
+ var contentComment = null;
878
+
879
+ if (this.contents) {
880
+ if (this.contents instanceof Node) {
881
+ if (this.contents.spaceBefore && (hasDirectives || this.directivesEndMarker)) lines.push('');
882
+ if (this.contents.commentBefore) lines.push(this.contents.commentBefore.replace(/^/gm, '#')); // top-level block scalars need to be indented if followed by a comment
883
+
884
+ ctx.forceBlockIndent = !!this.comment;
885
+ contentComment = this.contents.comment;
886
+ }
887
+
888
+ var onChompKeep = contentComment ? null : function () {
889
+ return chompKeep = true;
890
+ };
891
+ var body = stringify(this.contents, ctx, function () {
892
+ return contentComment = null;
893
+ }, onChompKeep);
894
+ lines.push(addComment(body, '', contentComment));
895
+ } else if (this.contents !== undefined) {
896
+ lines.push(stringify(this.contents, ctx));
897
+ }
898
+
899
+ if (this.comment) {
900
+ if ((!chompKeep || contentComment) && lines[lines.length - 1] !== '') lines.push('');
901
+ lines.push(this.comment.replace(/^/gm, '#'));
902
+ }
903
+
904
+ return lines.join('\n') + '\n';
905
+ }
906
+ }]);
907
+
908
+ return Document;
909
+ }();
910
+
911
+ _defineProperty(Document, "defaults", documentOptions);
79
912
 
80
913
  function createNode(value) {
81
914
  var wrapScalars = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
@@ -86,12 +919,12 @@ function createNode(value) {
86
919
  wrapScalars = true;
87
920
  }
88
921
 
89
- var options = Object.assign({}, YAMLDocument.defaults[defaultOptions.version], defaultOptions);
922
+ var options = Object.assign({}, Document.defaults[defaultOptions.version], defaultOptions);
90
923
  var schema = new Schema(options);
91
924
  return schema.createNode(value, wrapScalars, tag);
92
925
  }
93
926
 
94
- var Document = /*#__PURE__*/function (_YAMLDocument) {
927
+ var Document$1 = /*#__PURE__*/function (_YAMLDocument) {
95
928
  _inherits(Document, _YAMLDocument);
96
929
 
97
930
  var _super = _createSuper(Document);
@@ -103,19 +936,19 @@ var Document = /*#__PURE__*/function (_YAMLDocument) {
103
936
  }
104
937
 
105
938
  return Document;
106
- }(YAMLDocument);
939
+ }(Document);
107
940
 
108
941
  function parseAllDocuments(src, options) {
109
942
  var stream = [];
110
943
  var prev;
111
944
 
112
- var _iterator = _createForOfIteratorHelper(parseCST(src)),
945
+ var _iterator = _createForOfIteratorHelper(parse$1(src)),
113
946
  _step;
114
947
 
115
948
  try {
116
949
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
117
950
  var cstDoc = _step.value;
118
- var doc = new Document(options);
951
+ var doc = new Document$1(options);
119
952
  doc.parse(cstDoc, prev);
120
953
  stream.push(doc);
121
954
  prev = doc;
@@ -130,8 +963,8 @@ function parseAllDocuments(src, options) {
130
963
  }
131
964
 
132
965
  function parseDocument(src, options) {
133
- var cst = parseCST(src);
134
- var doc = new Document(options).parse(cst[0]);
966
+ var cst = parse$1(src);
967
+ var doc = new Document$1(options).parse(cst[0]);
135
968
 
136
969
  if (cst.length > 1) {
137
970
  var errMsg = 'Source contains multiple documents; please use YAML.parseAllDocuments()';
@@ -150,20 +983,22 @@ function parse(src, options) {
150
983
  return doc.toJSON();
151
984
  }
152
985
 
153
- function stringify(value, options) {
154
- var doc = new Document(options);
986
+ function stringify$1(value, options) {
987
+ var doc = new Document$1(options);
155
988
  doc.contents = value;
156
989
  return String(doc);
157
990
  }
158
991
 
159
- export var YAML = {
992
+ var YAML = {
160
993
  createNode: createNode,
161
994
  defaultOptions: defaultOptions,
162
- Document: Document,
995
+ Document: Document$1,
163
996
  parse: parse,
164
997
  parseAllDocuments: parseAllDocuments,
165
- parseCST: parseCST,
998
+ parseCST: parse$1,
166
999
  parseDocument: parseDocument,
167
1000
  scalarOptions: scalarOptions,
168
- stringify: stringify
169
- };
1001
+ stringify: stringify$1
1002
+ };
1003
+
1004
+ export { YAML };