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,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-b8036b75.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-492ab440.js';
4
+ import { S as Schema } from './Schema-e94716c8.js';
5
+ import { w as warn } from './warnings-df54cb69.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,852 @@ 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$1(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
+ function Anchors(prefix) {
243
+ _classCallCheck(this, Anchors);
244
+
245
+ _defineProperty(this, "map", Object.create(null));
246
+
247
+ this.prefix = prefix;
248
+ }
249
+
250
+ _createClass(Anchors, [{
251
+ key: "createAlias",
252
+ value: function createAlias(node, name) {
253
+ this.setAnchor(node, name);
254
+ return new Alias(node);
255
+ }
256
+ }, {
257
+ key: "createMergePair",
258
+ value: function createMergePair() {
259
+ var _this = this;
260
+
261
+ var merge = new Merge();
262
+
263
+ for (var _len = arguments.length, sources = new Array(_len), _key = 0; _key < _len; _key++) {
264
+ sources[_key] = arguments[_key];
265
+ }
266
+
267
+ merge.value.items = sources.map(function (s) {
268
+ if (s instanceof Alias) {
269
+ if (s.source instanceof YAMLMap) return s;
270
+ } else if (s instanceof YAMLMap) {
271
+ return _this.createAlias(s);
272
+ }
273
+
274
+ throw new Error('Merge sources must be Map nodes or their Aliases');
275
+ });
276
+ return merge;
277
+ }
278
+ }, {
279
+ key: "getName",
280
+ value: function getName(node) {
281
+ var map = this.map;
282
+ return Object.keys(map).find(function (a) {
283
+ return map[a] === node;
284
+ });
285
+ }
286
+ }, {
287
+ key: "getNames",
288
+ value: function getNames() {
289
+ return Object.keys(this.map);
290
+ }
291
+ }, {
292
+ key: "getNode",
293
+ value: function getNode(name) {
294
+ return this.map[name];
295
+ }
296
+ }, {
297
+ key: "newName",
298
+ value: function newName(prefix) {
299
+ if (!prefix) prefix = this.prefix;
300
+ var names = Object.keys(this.map);
301
+
302
+ for (var i = 1; true; ++i) {
303
+ var name = "".concat(prefix).concat(i);
304
+ if (!names.includes(name)) return name;
305
+ }
306
+ } // During parsing, map & aliases contain CST nodes
307
+
308
+ }, {
309
+ key: "resolveNodes",
310
+ value: function resolveNodes() {
311
+ var map = this.map,
312
+ _cstAliases = this._cstAliases;
313
+ Object.keys(map).forEach(function (a) {
314
+ map[a] = map[a].resolved;
315
+ });
316
+
317
+ _cstAliases.forEach(function (a) {
318
+ a.source = a.source.resolved;
319
+ });
320
+
321
+ delete this._cstAliases;
322
+ }
323
+ }, {
324
+ key: "setAnchor",
325
+ value: function setAnchor(node, name) {
326
+ if (node != null && !Anchors.validAnchorNode(node)) {
327
+ throw new Error('Anchors may only be set for Scalar, Seq and Map nodes');
328
+ }
329
+
330
+ if (name && /[\x00-\x19\s,[\]{}]/.test(name)) {
331
+ throw new Error('Anchor names must not contain whitespace or control characters');
332
+ }
333
+
334
+ var map = this.map;
335
+ var prev = node && Object.keys(map).find(function (a) {
336
+ return map[a] === node;
337
+ });
338
+
339
+ if (prev) {
340
+ if (!name) {
341
+ return prev;
342
+ } else if (prev !== name) {
343
+ delete map[prev];
344
+ map[name] = node;
345
+ }
346
+ } else {
347
+ if (!name) {
348
+ if (!node) return null;
349
+ name = this.newName();
350
+ }
351
+
352
+ map[name] = node;
353
+ }
354
+
355
+ return name;
356
+ }
357
+ }], [{
358
+ key: "validAnchorNode",
359
+ value: function validAnchorNode(node) {
360
+ return node instanceof Scalar || node instanceof YAMLSeq || node instanceof YAMLMap;
361
+ }
362
+ }]);
363
+
364
+ return Anchors;
365
+ }();
366
+
367
+ var visit = function visit(node, tags) {
368
+ if (node && _typeof(node) === 'object') {
369
+ var tag = node.tag;
370
+
371
+ if (node instanceof Collection) {
372
+ if (tag) tags[tag] = true;
373
+ node.items.forEach(function (n) {
374
+ return visit(n, tags);
375
+ });
376
+ } else if (node instanceof Pair) {
377
+ visit(node.key, tags);
378
+ visit(node.value, tags);
379
+ } else if (node instanceof Scalar) {
380
+ if (tag) tags[tag] = true;
381
+ }
382
+ }
383
+
384
+ return tags;
385
+ };
386
+
387
+ var listTagNames = function listTagNames(node) {
388
+ return Object.keys(visit(node, {}));
389
+ };
390
+
391
+ function parseContents(doc, contents) {
392
+ var comments = {
393
+ before: [],
394
+ after: []
395
+ };
396
+ var body = undefined;
397
+ var spaceBefore = false;
398
+
399
+ var _iterator = _createForOfIteratorHelper(contents),
400
+ _step;
401
+
402
+ try {
403
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
404
+ var node = _step.value;
405
+
406
+ if (node.valueRange) {
407
+ if (body !== undefined) {
408
+ var msg = 'Document contains trailing content not separated by a ... or --- line';
409
+ doc.errors.push(new YAMLSyntaxError(node, msg));
410
+ break;
411
+ }
412
+
413
+ var res = resolveNode(doc, node);
414
+
415
+ if (spaceBefore) {
416
+ res.spaceBefore = true;
417
+ spaceBefore = false;
418
+ }
419
+
420
+ body = res;
421
+ } else if (node.comment !== null) {
422
+ var cc = body === undefined ? comments.before : comments.after;
423
+ cc.push(node.comment);
424
+ } else if (node.type === Type.BLANK_LINE) {
425
+ spaceBefore = true;
426
+
427
+ if (body === undefined && comments.before.length > 0 && !doc.commentBefore) {
428
+ // space-separated comments at start are parsed as document comments
429
+ doc.commentBefore = comments.before.join('\n');
430
+ comments.before = [];
431
+ }
432
+ }
433
+ }
434
+ } catch (err) {
435
+ _iterator.e(err);
436
+ } finally {
437
+ _iterator.f();
438
+ }
439
+
440
+ doc.contents = body || null;
441
+
442
+ if (!body) {
443
+ doc.comment = comments.before.concat(comments.after).join('\n') || null;
444
+ } else {
445
+ var cb = comments.before.join('\n');
446
+
447
+ if (cb) {
448
+ var cbNode = body instanceof Collection && body.items[0] ? body.items[0] : body;
449
+ cbNode.commentBefore = cbNode.commentBefore ? "".concat(cb, "\n").concat(cbNode.commentBefore) : cb;
450
+ }
451
+
452
+ doc.comment = comments.after.join('\n') || null;
453
+ }
454
+ }
455
+
456
+ function resolveTagDirective(_ref, directive) {
457
+ var tagPrefixes = _ref.tagPrefixes;
458
+
459
+ var _directive$parameters = _slicedToArray(directive.parameters, 2),
460
+ handle = _directive$parameters[0],
461
+ prefix = _directive$parameters[1];
462
+
463
+ if (!handle || !prefix) {
464
+ var msg = 'Insufficient parameters given for %TAG directive';
465
+ throw new YAMLSemanticError(directive, msg);
466
+ }
467
+
468
+ if (tagPrefixes.some(function (p) {
469
+ return p.handle === handle;
470
+ })) {
471
+ var _msg = 'The %TAG directive must only be given at most once per handle in the same document.';
472
+ throw new YAMLSemanticError(directive, _msg);
473
+ }
474
+
475
+ return {
476
+ handle: handle,
477
+ prefix: prefix
478
+ };
479
+ }
480
+
481
+ function resolveYamlDirective(doc, directive) {
482
+ var _directive$parameters2 = _slicedToArray(directive.parameters, 1),
483
+ version = _directive$parameters2[0];
484
+
485
+ if (directive.name === 'YAML:1.0') version = '1.0';
486
+
487
+ if (!version) {
488
+ var msg = 'Insufficient parameters given for %YAML directive';
489
+ throw new YAMLSemanticError(directive, msg);
490
+ }
491
+
492
+ if (!documentOptions[version]) {
493
+ var v0 = doc.version || doc.options.version;
494
+
495
+ var _msg2 = "Document will be parsed as YAML ".concat(v0, " rather than YAML ").concat(version);
496
+
497
+ doc.warnings.push(new YAMLWarning(directive, _msg2));
498
+ }
499
+
500
+ return version;
501
+ }
502
+
503
+ function parseDirectives(doc, directives, prevDoc) {
504
+ var directiveComments = [];
505
+ var hasDirectives = false;
506
+
507
+ var _iterator = _createForOfIteratorHelper(directives),
508
+ _step;
509
+
510
+ try {
511
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
512
+ var directive = _step.value;
513
+ var comment = directive.comment,
514
+ name = directive.name;
515
+
516
+ switch (name) {
517
+ case 'TAG':
518
+ try {
519
+ doc.tagPrefixes.push(resolveTagDirective(doc, directive));
520
+ } catch (error) {
521
+ doc.errors.push(error);
522
+ }
523
+
524
+ hasDirectives = true;
525
+ break;
526
+
527
+ case 'YAML':
528
+ case 'YAML:1.0':
529
+ if (doc.version) {
530
+ var msg = 'The %YAML directive must only be given at most once per document.';
531
+ doc.errors.push(new YAMLSemanticError(directive, msg));
532
+ }
533
+
534
+ try {
535
+ doc.version = resolveYamlDirective(doc, directive);
536
+ } catch (error) {
537
+ doc.errors.push(error);
538
+ }
539
+
540
+ hasDirectives = true;
541
+ break;
542
+
543
+ default:
544
+ if (name) {
545
+ var _msg3 = "YAML only supports %TAG and %YAML directives, and not %".concat(name);
546
+
547
+ doc.warnings.push(new YAMLWarning(directive, _msg3));
548
+ }
549
+
550
+ }
551
+
552
+ if (comment) directiveComments.push(comment);
553
+ }
554
+ } catch (err) {
555
+ _iterator.e(err);
556
+ } finally {
557
+ _iterator.f();
558
+ }
559
+
560
+ if (prevDoc && !hasDirectives && '1.1' === (doc.version || prevDoc.version || doc.options.version)) {
561
+ var copyTagPrefix = function copyTagPrefix(_ref2) {
562
+ var handle = _ref2.handle,
563
+ prefix = _ref2.prefix;
564
+ return {
565
+ handle: handle,
566
+ prefix: prefix
567
+ };
568
+ };
569
+
570
+ doc.tagPrefixes = prevDoc.tagPrefixes.map(copyTagPrefix);
571
+ doc.version = prevDoc.version;
572
+ }
573
+
574
+ doc.commentBefore = directiveComments.join('\n') || null;
575
+ }
576
+
577
+ function assertCollection(contents) {
578
+ if (contents instanceof Collection) return true;
579
+ throw new Error('Expected a YAML collection as document contents');
580
+ }
581
+
582
+ var Document$1 = /*#__PURE__*/function () {
583
+ function Document(options) {
584
+ _classCallCheck(this, Document);
585
+
586
+ this.anchors = new Anchors(options.anchorPrefix);
587
+ this.commentBefore = null;
588
+ this.comment = null;
589
+ this.contents = null;
590
+ this.directivesEndMarker = null;
591
+ this.errors = [];
592
+ this.options = options;
593
+ this.schema = null;
594
+ this.tagPrefixes = [];
595
+ this.version = null;
596
+ this.warnings = [];
597
+ }
598
+
599
+ _createClass(Document, [{
600
+ key: "add",
601
+ value: function add(value) {
602
+ assertCollection(this.contents);
603
+ return this.contents.add(value);
604
+ }
605
+ }, {
606
+ key: "addIn",
607
+ value: function addIn(path, value) {
608
+ assertCollection(this.contents);
609
+ this.contents.addIn(path, value);
610
+ }
611
+ }, {
612
+ key: "delete",
613
+ value: function _delete(key) {
614
+ assertCollection(this.contents);
615
+ return this.contents.delete(key);
616
+ }
617
+ }, {
618
+ key: "deleteIn",
619
+ value: function deleteIn(path) {
620
+ if (isEmptyPath(path)) {
621
+ if (this.contents == null) return false;
622
+ this.contents = null;
623
+ return true;
624
+ }
625
+
626
+ assertCollection(this.contents);
627
+ return this.contents.deleteIn(path);
628
+ }
629
+ }, {
630
+ key: "getDefaults",
631
+ value: function getDefaults() {
632
+ return Document.defaults[this.version] || Document.defaults[this.options.version] || {};
633
+ }
634
+ }, {
635
+ key: "get",
636
+ value: function get(key, keepScalar) {
637
+ return this.contents instanceof Collection ? this.contents.get(key, keepScalar) : undefined;
638
+ }
639
+ }, {
640
+ key: "getIn",
641
+ value: function getIn(path, keepScalar) {
642
+ if (isEmptyPath(path)) return !keepScalar && this.contents instanceof Scalar ? this.contents.value : this.contents;
643
+ return this.contents instanceof Collection ? this.contents.getIn(path, keepScalar) : undefined;
644
+ }
645
+ }, {
646
+ key: "has",
647
+ value: function has(key) {
648
+ return this.contents instanceof Collection ? this.contents.has(key) : false;
649
+ }
650
+ }, {
651
+ key: "hasIn",
652
+ value: function hasIn(path) {
653
+ if (isEmptyPath(path)) return this.contents !== undefined;
654
+ return this.contents instanceof Collection ? this.contents.hasIn(path) : false;
655
+ }
656
+ }, {
657
+ key: "set",
658
+ value: function set(key, value) {
659
+ assertCollection(this.contents);
660
+ this.contents.set(key, value);
661
+ }
662
+ }, {
663
+ key: "setIn",
664
+ value: function setIn(path, value) {
665
+ if (isEmptyPath(path)) this.contents = value;else {
666
+ assertCollection(this.contents);
667
+ this.contents.setIn(path, value);
668
+ }
669
+ }
670
+ }, {
671
+ key: "setSchema",
672
+ value: function setSchema(id, customTags) {
673
+ if (!id && !customTags && this.schema) return;
674
+ if (typeof id === 'number') id = id.toFixed(1);
675
+
676
+ if (id === '1.0' || id === '1.1' || id === '1.2') {
677
+ if (this.version) this.version = id;else this.options.version = id;
678
+ delete this.options.schema;
679
+ } else if (id && typeof id === 'string') {
680
+ this.options.schema = id;
681
+ }
682
+
683
+ if (Array.isArray(customTags)) this.options.customTags = customTags;
684
+ var opt = Object.assign({}, this.getDefaults(), this.options);
685
+ this.schema = new Schema(opt);
686
+ }
687
+ }, {
688
+ key: "parse",
689
+ value: function parse(node, prevDoc) {
690
+ if (this.options.keepCstNodes) this.cstNode = node;
691
+ if (this.options.keepNodeTypes) this.type = 'DOCUMENT';
692
+ var _node$directives = node.directives,
693
+ directives = _node$directives === void 0 ? [] : _node$directives,
694
+ _node$contents = node.contents,
695
+ contents = _node$contents === void 0 ? [] : _node$contents,
696
+ directivesEndMarker = node.directivesEndMarker,
697
+ error = node.error,
698
+ valueRange = node.valueRange;
699
+
700
+ if (error) {
701
+ if (!error.source) error.source = this;
702
+ this.errors.push(error);
703
+ }
704
+
705
+ parseDirectives(this, directives, prevDoc);
706
+ if (directivesEndMarker) this.directivesEndMarker = true;
707
+ this.range = valueRange ? [valueRange.start, valueRange.end] : null;
708
+ this.setSchema();
709
+ this.anchors._cstAliases = [];
710
+ parseContents(this, contents);
711
+ this.anchors.resolveNodes();
712
+
713
+ if (this.options.prettyErrors) {
714
+ var _iterator = _createForOfIteratorHelper(this.errors),
715
+ _step;
716
+
717
+ try {
718
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
719
+ var _error = _step.value;
720
+ if (_error instanceof YAMLError) _error.makePretty();
721
+ }
722
+ } catch (err) {
723
+ _iterator.e(err);
724
+ } finally {
725
+ _iterator.f();
726
+ }
727
+
728
+ var _iterator2 = _createForOfIteratorHelper(this.warnings),
729
+ _step2;
730
+
731
+ try {
732
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
733
+ var warn = _step2.value;
734
+ if (warn instanceof YAMLError) warn.makePretty();
735
+ }
736
+ } catch (err) {
737
+ _iterator2.e(err);
738
+ } finally {
739
+ _iterator2.f();
740
+ }
741
+ }
742
+
743
+ return this;
744
+ }
745
+ }, {
746
+ key: "listNonDefaultTags",
747
+ value: function listNonDefaultTags() {
748
+ return listTagNames(this.contents).filter(function (t) {
749
+ return t.indexOf(Schema.defaultPrefix) !== 0;
750
+ });
751
+ }
752
+ }, {
753
+ key: "setTagPrefix",
754
+ value: function setTagPrefix(handle, prefix) {
755
+ if (handle[0] !== '!' || handle[handle.length - 1] !== '!') throw new Error('Handle must start and end with !');
756
+
757
+ if (prefix) {
758
+ var prev = this.tagPrefixes.find(function (p) {
759
+ return p.handle === handle;
760
+ });
761
+ if (prev) prev.prefix = prefix;else this.tagPrefixes.push({
762
+ handle: handle,
763
+ prefix: prefix
764
+ });
765
+ } else {
766
+ this.tagPrefixes = this.tagPrefixes.filter(function (p) {
767
+ return p.handle !== handle;
768
+ });
769
+ }
770
+ }
771
+ }, {
772
+ key: "toJSON",
773
+ value: function toJSON$1(arg, onAnchor) {
774
+ var _this = this;
775
+
776
+ var _this$options = this.options,
777
+ keepBlobsInJSON = _this$options.keepBlobsInJSON,
778
+ mapAsMap = _this$options.mapAsMap,
779
+ maxAliasCount = _this$options.maxAliasCount;
780
+ var keep = keepBlobsInJSON && (typeof arg !== 'string' || !(this.contents instanceof Scalar));
781
+ var ctx = {
782
+ doc: this,
783
+ indentStep: ' ',
784
+ keep: keep,
785
+ mapAsMap: keep && !!mapAsMap,
786
+ maxAliasCount: maxAliasCount,
787
+ stringify: stringify$1 // Requiring directly in Pair would create circular dependencies
788
+
789
+ };
790
+ var anchorNames = Object.keys(this.anchors.map);
791
+ if (anchorNames.length > 0) ctx.anchors = new Map(anchorNames.map(function (name) {
792
+ return [_this.anchors.map[name], {
793
+ alias: [],
794
+ aliasCount: 0,
795
+ count: 1
796
+ }];
797
+ }));
798
+
799
+ var res = toJSON(this.contents, arg, ctx);
800
+
801
+ if (typeof onAnchor === 'function' && ctx.anchors) {
802
+ var _iterator3 = _createForOfIteratorHelper(ctx.anchors.values()),
803
+ _step3;
804
+
805
+ try {
806
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
807
+ var _step3$value = _step3.value,
808
+ count = _step3$value.count,
809
+ _res = _step3$value.res;
810
+ onAnchor(_res, count);
811
+ }
812
+ } catch (err) {
813
+ _iterator3.e(err);
814
+ } finally {
815
+ _iterator3.f();
816
+ }
817
+ }
818
+
819
+ return res;
820
+ }
821
+ }, {
822
+ key: "toString",
823
+ value: function toString() {
824
+ if (this.errors.length > 0) throw new Error('Document with errors cannot be stringified');
825
+ var indentSize = this.options.indent;
826
+
827
+ if (!Number.isInteger(indentSize) || indentSize <= 0) {
828
+ var s = JSON.stringify(indentSize);
829
+ throw new Error("\"indent\" option must be a positive integer, not ".concat(s));
830
+ }
831
+
832
+ this.setSchema();
833
+ var lines = [];
834
+ var hasDirectives = false;
835
+
836
+ if (this.version) {
837
+ var vd = '%YAML 1.2';
838
+
839
+ if (this.schema.name === 'yaml-1.1') {
840
+ if (this.version === '1.0') vd = '%YAML:1.0';else if (this.version === '1.1') vd = '%YAML 1.1';
841
+ }
842
+
843
+ lines.push(vd);
844
+ hasDirectives = true;
845
+ }
846
+
847
+ var tagNames = this.listNonDefaultTags();
848
+ this.tagPrefixes.forEach(function (_ref) {
849
+ var handle = _ref.handle,
850
+ prefix = _ref.prefix;
851
+
852
+ if (tagNames.some(function (t) {
853
+ return t.indexOf(prefix) === 0;
854
+ })) {
855
+ lines.push("%TAG ".concat(handle, " ").concat(prefix));
856
+ hasDirectives = true;
857
+ }
858
+ });
859
+ if (hasDirectives || this.directivesEndMarker) lines.push('---');
860
+
861
+ if (this.commentBefore) {
862
+ if (hasDirectives || !this.directivesEndMarker) lines.unshift('');
863
+ lines.unshift(this.commentBefore.replace(/^/gm, '#'));
864
+ }
865
+
866
+ var ctx = {
867
+ anchors: Object.create(null),
868
+ doc: this,
869
+ indent: '',
870
+ indentStep: ' '.repeat(indentSize),
871
+ stringify: stringify$1 // Requiring directly in nodes would create circular dependencies
872
+
873
+ };
874
+ var chompKeep = false;
875
+ var contentComment = null;
876
+
877
+ if (this.contents) {
878
+ if (this.contents instanceof Node) {
879
+ if (this.contents.spaceBefore && (hasDirectives || this.directivesEndMarker)) lines.push('');
880
+ if (this.contents.commentBefore) lines.push(this.contents.commentBefore.replace(/^/gm, '#')); // top-level block scalars need to be indented if followed by a comment
881
+
882
+ ctx.forceBlockIndent = !!this.comment;
883
+ contentComment = this.contents.comment;
884
+ }
885
+
886
+ var onChompKeep = contentComment ? null : function () {
887
+ return chompKeep = true;
888
+ };
889
+ var body = stringify$1(this.contents, ctx, function () {
890
+ return contentComment = null;
891
+ }, onChompKeep);
892
+ lines.push(addComment(body, '', contentComment));
893
+ } else if (this.contents !== undefined) {
894
+ lines.push(stringify$1(this.contents, ctx));
895
+ }
896
+
897
+ if (this.comment) {
898
+ if ((!chompKeep || contentComment) && lines[lines.length - 1] !== '') lines.push('');
899
+ lines.push(this.comment.replace(/^/gm, '#'));
900
+ }
901
+
902
+ return lines.join('\n') + '\n';
903
+ }
904
+ }]);
905
+
906
+ return Document;
907
+ }();
908
+
909
+ _defineProperty(Document$1, "defaults", documentOptions);
79
910
 
80
911
  function createNode(value) {
81
912
  var wrapScalars = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
@@ -86,7 +917,7 @@ function createNode(value) {
86
917
  wrapScalars = true;
87
918
  }
88
919
 
89
- var options = Object.assign({}, YAMLDocument.defaults[defaultOptions.version], defaultOptions);
920
+ var options = Object.assign({}, Document$1.defaults[defaultOptions.version], defaultOptions);
90
921
  var schema = new Schema(options);
91
922
  return schema.createNode(value, wrapScalars, tag);
92
923
  }
@@ -103,13 +934,13 @@ var Document = /*#__PURE__*/function (_YAMLDocument) {
103
934
  }
104
935
 
105
936
  return Document;
106
- }(YAMLDocument);
937
+ }(Document$1);
107
938
 
108
939
  function parseAllDocuments(src, options) {
109
940
  var stream = [];
110
941
  var prev;
111
942
 
112
- var _iterator = _createForOfIteratorHelper(parseCST(src)),
943
+ var _iterator = _createForOfIteratorHelper(parse$1(src)),
113
944
  _step;
114
945
 
115
946
  try {
@@ -130,7 +961,7 @@ function parseAllDocuments(src, options) {
130
961
  }
131
962
 
132
963
  function parseDocument(src, options) {
133
- var cst = parseCST(src);
964
+ var cst = parse$1(src);
134
965
  var doc = new Document(options).parse(cst[0]);
135
966
 
136
967
  if (cst.length > 1) {
@@ -156,14 +987,16 @@ function stringify(value, options) {
156
987
  return String(doc);
157
988
  }
158
989
 
159
- export var YAML = {
990
+ var YAML = {
160
991
  createNode: createNode,
161
992
  defaultOptions: defaultOptions,
162
993
  Document: Document,
163
994
  parse: parse,
164
995
  parseAllDocuments: parseAllDocuments,
165
- parseCST: parseCST,
996
+ parseCST: parse$1,
166
997
  parseDocument: parseDocument,
167
998
  scalarOptions: scalarOptions,
168
999
  stringify: stringify
169
- };
1000
+ };
1001
+
1002
+ export { YAML };