cdk8s-operator 0.1.406 → 0.1.408

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 (29) hide show
  1. package/.jsii +3 -3
  2. package/lib/operator.js +1 -1
  3. package/lib/server.js +1 -1
  4. package/node_modules/yaml/browser/dist/PlainValue-183afbad.js +751 -0
  5. package/node_modules/yaml/browser/dist/Schema-9530c078.js +467 -0
  6. package/node_modules/yaml/browser/dist/index.js +436 -746
  7. package/node_modules/yaml/browser/dist/legacy-exports.js +3 -3
  8. package/node_modules/yaml/browser/dist/parse-cst.js +1290 -1689
  9. package/node_modules/yaml/browser/dist/resolveSeq-67caf78a.js +1835 -0
  10. package/node_modules/yaml/browser/dist/types.js +4 -4
  11. package/node_modules/yaml/browser/dist/util.js +2 -2
  12. package/node_modules/yaml/browser/dist/warnings-5e4358fe.js +348 -0
  13. package/node_modules/yaml/dist/{Document-9b4560a1.js → Document-a8d0fbf9.js} +11 -131
  14. package/node_modules/yaml/dist/{PlainValue-ec8e588e.js → PlainValue-516d5bc2.js} +35 -146
  15. package/node_modules/yaml/dist/{Schema-88e323a7.js → Schema-bcc6c2d7.js} +10 -66
  16. package/node_modules/yaml/dist/index.js +5 -17
  17. package/node_modules/yaml/dist/legacy-exports.js +3 -3
  18. package/node_modules/yaml/dist/parse-cst.js +45 -291
  19. package/node_modules/yaml/dist/{resolveSeq-d03cb037.js → resolveSeq-95613e94.js} +44 -346
  20. package/node_modules/yaml/dist/test-events.js +28 -44
  21. package/node_modules/yaml/dist/types.js +4 -4
  22. package/node_modules/yaml/dist/util.js +2 -2
  23. package/node_modules/yaml/dist/{warnings-1000a372.js → warnings-793925ce.js} +16 -73
  24. package/node_modules/yaml/package.json +2 -3
  25. package/package.json +2 -2
  26. package/node_modules/yaml/browser/dist/PlainValue-b8036b75.js +0 -1275
  27. package/node_modules/yaml/browser/dist/Schema-e94716c8.js +0 -682
  28. package/node_modules/yaml/browser/dist/resolveSeq-492ab440.js +0 -2419
  29. package/node_modules/yaml/browser/dist/warnings-df54cb69.js +0 -499
@@ -1,10 +1,10 @@
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
1
  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';
2
+ import { d as defaultTagPrefix, _ as _defineProperty, T as Type, Y as YAMLSyntaxError, a as YAMLWarning, b as YAMLSemanticError, c as YAMLError } from './PlainValue-183afbad.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-67caf78a.js';
4
+ import { S as Schema } from './Schema-9530c078.js';
5
+ import { w as warn } from './warnings-5e4358fe.js';
6
6
 
7
- var defaultOptions = {
7
+ const defaultOptions = {
8
8
  anchorPrefix: 'a',
9
9
  customTags: null,
10
10
  indent: 2,
@@ -19,49 +19,39 @@ var defaultOptions = {
19
19
  simpleKeys: false,
20
20
  version: '1.2'
21
21
  };
22
- var scalarOptions = {
22
+ const scalarOptions = {
23
23
  get binary() {
24
24
  return binaryOptions;
25
25
  },
26
-
27
26
  set binary(opt) {
28
27
  Object.assign(binaryOptions, opt);
29
28
  },
30
-
31
29
  get bool() {
32
30
  return boolOptions;
33
31
  },
34
-
35
32
  set bool(opt) {
36
33
  Object.assign(boolOptions, opt);
37
34
  },
38
-
39
35
  get int() {
40
36
  return intOptions;
41
37
  },
42
-
43
38
  set int(opt) {
44
39
  Object.assign(intOptions, opt);
45
40
  },
46
-
47
41
  get null() {
48
42
  return nullOptions;
49
43
  },
50
-
51
44
  set null(opt) {
52
45
  Object.assign(nullOptions, opt);
53
46
  },
54
-
55
47
  get str() {
56
48
  return strOptions;
57
49
  },
58
-
59
50
  set str(opt) {
60
51
  Object.assign(strOptions, opt);
61
52
  }
62
-
63
53
  };
64
- var documentOptions = {
54
+ const documentOptions = {
65
55
  '1.0': {
66
56
  schema: 'yaml-1.1',
67
57
  merge: true,
@@ -99,280 +89,196 @@ var documentOptions = {
99
89
 
100
90
  function stringifyTag(doc, tag) {
101
91
  if ((doc.version || doc.options.version) === '1.0') {
102
- var priv = tag.match(/^tag:private\.yaml\.org,2002:([^:/]+)$/);
92
+ const priv = tag.match(/^tag:private\.yaml\.org,2002:([^:/]+)$/);
103
93
  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:/, ''));
94
+ const vocab = tag.match(/^tag:([a-zA-Z0-9-]+)\.yaml\.org,2002:(.*)/);
95
+ return vocab ? `!${vocab[1]}/${vocab[2]}` : `!${tag.replace(/^tag:/, '')}`;
106
96
  }
107
-
108
- var p = doc.tagPrefixes.find(function (p) {
109
- return tag.indexOf(p.prefix) === 0;
110
- });
111
-
97
+ let p = doc.tagPrefixes.find(p => tag.indexOf(p.prefix) === 0);
112
98
  if (!p) {
113
- var dtp = doc.getDefaults().tagPrefixes;
114
- p = dtp && dtp.find(function (p) {
115
- return tag.indexOf(p.prefix) === 0;
116
- });
99
+ const dtp = doc.getDefaults().tagPrefixes;
100
+ p = dtp && dtp.find(p => tag.indexOf(p.prefix) === 0);
117
101
  }
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
- });
102
+ if (!p) return tag[0] === '!' ? tag : `!<${tag}>`;
103
+ const suffix = tag.substr(p.prefix.length).replace(/[!,[\]{}]/g, ch => ({
104
+ '!': '%21',
105
+ ',': '%2C',
106
+ '[': '%5B',
107
+ ']': '%5D',
108
+ '{': '%7B',
109
+ '}': '%7D'
110
+ })[ch]);
130
111
  return p.handle + suffix;
131
112
  }
132
113
 
133
114
  function getTagObject(tags, item) {
134
115
  if (item instanceof Alias) return Alias;
135
-
136
116
  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];
117
+ const match = tags.filter(t => t.tag === item.tag);
118
+ if (match.length > 0) return match.find(t => t.format === item.format) || match[0];
143
119
  }
144
-
145
- var tagObj, obj;
146
-
120
+ let tagObj, obj;
147
121
  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
- });
122
+ obj = item.value;
123
+ // TODO: deprecate/remove class check
124
+ const match = tags.filter(t => t.identify && t.identify(obj) || t.class && obj instanceof t.class);
125
+ tagObj = match.find(t => t.format === item.format) || match.find(t => !t.format);
159
126
  } else {
160
127
  obj = item;
161
- tagObj = tags.find(function (t) {
162
- return t.nodeClass && obj instanceof t.nodeClass;
163
- });
128
+ tagObj = tags.find(t => t.nodeClass && obj instanceof t.nodeClass);
164
129
  }
165
-
166
130
  if (!tagObj) {
167
- var name = obj && obj.constructor ? obj.constructor.name : _typeof(obj);
168
- throw new Error("Tag not resolved for ".concat(name, " value"));
131
+ const name = obj && obj.constructor ? obj.constructor.name : typeof obj;
132
+ throw new Error(`Tag not resolved for ${name} value`);
169
133
  }
170
-
171
134
  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);
135
+ }
180
136
 
137
+ // needs to be called before value stringifier to allow for circular anchor refs
138
+ function stringifyProps(node, tagObj, {
139
+ anchors,
140
+ doc
141
+ }) {
142
+ const props = [];
143
+ const anchor = doc.anchors.getName(node);
181
144
  if (anchor) {
182
145
  anchors[anchor] = node;
183
- props.push("&".concat(anchor));
146
+ props.push(`&${anchor}`);
184
147
  }
185
-
186
148
  if (node.tag) {
187
149
  props.push(stringifyTag(doc, node.tag));
188
150
  } else if (!tagObj.default) {
189
151
  props.push(stringifyTag(doc, tagObj.tag));
190
152
  }
191
-
192
153
  return props.join(' ');
193
154
  }
194
-
195
155
  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
-
156
+ const {
157
+ anchors,
158
+ schema
159
+ } = ctx.doc;
160
+ let tagObj;
201
161
  if (!(item instanceof Node)) {
202
- var createCtx = {
162
+ const createCtx = {
203
163
  aliasNodes: [],
204
- onTagObj: function onTagObj(o) {
205
- return tagObj = o;
206
- },
164
+ onTagObj: o => tagObj = o,
207
165
  prevObjects: new Map()
208
166
  };
209
167
  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
- }
168
+ for (const alias of createCtx.aliasNodes) {
169
+ alias.source = alias.source.node;
170
+ let name = anchors.getName(alias.source);
171
+ if (!name) {
172
+ name = anchors.newName();
173
+ anchors.map[name] = alias.source;
224
174
  }
225
- } catch (err) {
226
- _iterator.e(err);
227
- } finally {
228
- _iterator.f();
229
175
  }
230
176
  }
231
-
232
177
  if (item instanceof Pair) return item.toString(ctx, onComment, onChompKeep);
233
178
  if (!tagObj) tagObj = getTagObject(schema.tags, item);
234
- var props = stringifyProps(item, tagObj, ctx);
179
+ const props = stringifyProps(item, tagObj, ctx);
235
180
  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);
181
+ const 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
182
  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);
183
+ return item instanceof Scalar || str[0] === '{' || str[0] === '[' ? `${props} ${str}` : `${props}\n${ctx.indent}${str}`;
239
184
  }
240
185
 
241
- var Anchors = /*#__PURE__*/function () {
242
- function Anchors(prefix) {
243
- _classCallCheck(this, Anchors);
244
-
186
+ class Anchors {
187
+ static validAnchorNode(node) {
188
+ return node instanceof Scalar || node instanceof YAMLSeq || node instanceof YAMLMap;
189
+ }
190
+ constructor(prefix) {
245
191
  _defineProperty(this, "map", Object.create(null));
246
-
247
192
  this.prefix = prefix;
248
193
  }
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];
194
+ createAlias(node, name) {
195
+ this.setAnchor(node, name);
196
+ return new Alias(node);
197
+ }
198
+ createMergePair(...sources) {
199
+ const merge = new Merge();
200
+ merge.value.items = sources.map(s => {
201
+ if (s instanceof Alias) {
202
+ if (s.source instanceof YAMLMap) return s;
203
+ } else if (s instanceof YAMLMap) {
204
+ return this.createAlias(s);
265
205
  }
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];
206
+ throw new Error('Merge sources must be Map nodes or their Aliases');
207
+ });
208
+ return merge;
209
+ }
210
+ getName(node) {
211
+ const {
212
+ map
213
+ } = this;
214
+ return Object.keys(map).find(a => map[a] === node);
215
+ }
216
+ getNames() {
217
+ return Object.keys(this.map);
218
+ }
219
+ getNode(name) {
220
+ return this.map[name];
221
+ }
222
+ newName(prefix) {
223
+ if (!prefix) prefix = this.prefix;
224
+ const names = Object.keys(this.map);
225
+ for (let i = 1; true; ++i) {
226
+ const name = `${prefix}${i}`;
227
+ if (!names.includes(name)) return name;
295
228
  }
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
- });
229
+ }
320
230
 
321
- delete this._cstAliases;
231
+ // During parsing, map & aliases contain CST nodes
232
+ resolveNodes() {
233
+ const {
234
+ map,
235
+ _cstAliases
236
+ } = this;
237
+ Object.keys(map).forEach(a => {
238
+ map[a] = map[a].resolved;
239
+ });
240
+ _cstAliases.forEach(a => {
241
+ a.source = a.source.resolved;
242
+ });
243
+ delete this._cstAliases;
244
+ }
245
+ setAnchor(node, name) {
246
+ if (node != null && !Anchors.validAnchorNode(node)) {
247
+ throw new Error('Anchors may only be set for Scalar, Seq and Map nodes');
322
248
  }
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
-
249
+ if (name && /[\x00-\x19\s,[\]{}]/.test(name)) {
250
+ throw new Error('Anchor names must not contain whitespace or control characters');
251
+ }
252
+ const {
253
+ map
254
+ } = this;
255
+ const prev = node && Object.keys(map).find(a => map[a] === node);
256
+ if (prev) {
257
+ if (!name) {
258
+ return prev;
259
+ } else if (prev !== name) {
260
+ delete map[prev];
352
261
  map[name] = node;
353
262
  }
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;
263
+ } else {
264
+ if (!name) {
265
+ if (!node) return null;
266
+ name = this.newName();
267
+ }
268
+ map[name] = node;
361
269
  }
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;
270
+ return name;
271
+ }
272
+ }
370
273
 
274
+ const visit = (node, tags) => {
275
+ if (node && typeof node === 'object') {
276
+ const {
277
+ tag
278
+ } = node;
371
279
  if (node instanceof Collection) {
372
280
  if (tag) tags[tag] = true;
373
- node.items.forEach(function (n) {
374
- return visit(n, tags);
375
- });
281
+ node.items.forEach(n => visit(n, tags));
376
282
  } else if (node instanceof Pair) {
377
283
  visit(node.key, tags);
378
284
  visit(node.value, tags);
@@ -380,197 +286,135 @@ var visit = function visit(node, tags) {
380
286
  if (tag) tags[tag] = true;
381
287
  }
382
288
  }
383
-
384
289
  return tags;
385
290
  };
386
-
387
- var listTagNames = function listTagNames(node) {
388
- return Object.keys(visit(node, {}));
389
- };
291
+ const listTagNames = node => Object.keys(visit(node, {}));
390
292
 
391
293
  function parseContents(doc, contents) {
392
- var comments = {
294
+ const comments = {
393
295
  before: [],
394
296
  after: []
395
297
  };
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
- }
298
+ let body = undefined;
299
+ let spaceBefore = false;
300
+ for (const node of contents) {
301
+ if (node.valueRange) {
302
+ if (body !== undefined) {
303
+ const msg = 'Document contains trailing content not separated by a ... or --- line';
304
+ doc.errors.push(new YAMLSyntaxError(node, msg));
305
+ break;
306
+ }
307
+ const res = resolveNode(doc, node);
308
+ if (spaceBefore) {
309
+ res.spaceBefore = true;
310
+ spaceBefore = false;
311
+ }
312
+ body = res;
313
+ } else if (node.comment !== null) {
314
+ const cc = body === undefined ? comments.before : comments.after;
315
+ cc.push(node.comment);
316
+ } else if (node.type === Type.BLANK_LINE) {
317
+ spaceBefore = true;
318
+ if (body === undefined && comments.before.length > 0 && !doc.commentBefore) {
319
+ // space-separated comments at start are parsed as document comments
320
+ doc.commentBefore = comments.before.join('\n');
321
+ comments.before = [];
432
322
  }
433
323
  }
434
- } catch (err) {
435
- _iterator.e(err);
436
- } finally {
437
- _iterator.f();
438
324
  }
439
-
440
325
  doc.contents = body || null;
441
-
442
326
  if (!body) {
443
327
  doc.comment = comments.before.concat(comments.after).join('\n') || null;
444
328
  } else {
445
- var cb = comments.before.join('\n');
446
-
329
+ const cb = comments.before.join('\n');
447
330
  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;
331
+ const cbNode = body instanceof Collection && body.items[0] ? body.items[0] : body;
332
+ cbNode.commentBefore = cbNode.commentBefore ? `${cb}\n${cbNode.commentBefore}` : cb;
450
333
  }
451
-
452
334
  doc.comment = comments.after.join('\n') || null;
453
335
  }
454
336
  }
455
337
 
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
-
338
+ function resolveTagDirective({
339
+ tagPrefixes
340
+ }, directive) {
341
+ const [handle, prefix] = directive.parameters;
463
342
  if (!handle || !prefix) {
464
- var msg = 'Insufficient parameters given for %TAG directive';
343
+ const msg = 'Insufficient parameters given for %TAG directive';
465
344
  throw new YAMLSemanticError(directive, msg);
466
345
  }
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);
346
+ if (tagPrefixes.some(p => p.handle === handle)) {
347
+ const msg = 'The %TAG directive must only be given at most once per handle in the same document.';
348
+ throw new YAMLSemanticError(directive, msg);
473
349
  }
474
-
475
350
  return {
476
- handle: handle,
477
- prefix: prefix
351
+ handle,
352
+ prefix
478
353
  };
479
354
  }
480
-
481
355
  function resolveYamlDirective(doc, directive) {
482
- var _directive$parameters2 = _slicedToArray(directive.parameters, 1),
483
- version = _directive$parameters2[0];
484
-
356
+ let [version] = directive.parameters;
485
357
  if (directive.name === 'YAML:1.0') version = '1.0';
486
-
487
358
  if (!version) {
488
- var msg = 'Insufficient parameters given for %YAML directive';
359
+ const msg = 'Insufficient parameters given for %YAML directive';
489
360
  throw new YAMLSemanticError(directive, msg);
490
361
  }
491
-
492
362
  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));
363
+ const v0 = doc.version || doc.options.version;
364
+ const msg = `Document will be parsed as YAML ${v0} rather than YAML ${version}`;
365
+ doc.warnings.push(new YAMLWarning(directive, msg));
498
366
  }
499
-
500
367
  return version;
501
368
  }
502
-
503
369
  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);
370
+ const directiveComments = [];
371
+ let hasDirectives = false;
372
+ for (const directive of directives) {
373
+ const {
374
+ comment,
375
+ name
376
+ } = directive;
377
+ switch (name) {
378
+ case 'TAG':
379
+ try {
380
+ doc.tagPrefixes.push(resolveTagDirective(doc, directive));
381
+ } catch (error) {
382
+ doc.errors.push(error);
383
+ }
384
+ hasDirectives = true;
385
+ break;
386
+ case 'YAML':
387
+ case 'YAML:1.0':
388
+ if (doc.version) {
389
+ const msg = 'The %YAML directive must only be given at most once per document.';
390
+ doc.errors.push(new YAMLSemanticError(directive, msg));
391
+ }
392
+ try {
393
+ doc.version = resolveYamlDirective(doc, directive);
394
+ } catch (error) {
395
+ doc.errors.push(error);
396
+ }
397
+ hasDirectives = true;
398
+ break;
399
+ default:
400
+ if (name) {
401
+ const msg = `YAML only supports %TAG and %YAML directives, and not %${name}`;
402
+ doc.warnings.push(new YAMLWarning(directive, msg));
403
+ }
553
404
  }
554
- } catch (err) {
555
- _iterator.e(err);
556
- } finally {
557
- _iterator.f();
405
+ if (comment) directiveComments.push(comment);
558
406
  }
559
-
560
407
  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
-
408
+ const copyTagPrefix = ({
409
+ handle,
410
+ prefix
411
+ }) => ({
412
+ handle,
413
+ prefix
414
+ });
570
415
  doc.tagPrefixes = prevDoc.tagPrefixes.map(copyTagPrefix);
571
416
  doc.version = prevDoc.version;
572
417
  }
573
-
574
418
  doc.commentBefore = directiveComments.join('\n') || null;
575
419
  }
576
420
 
@@ -578,11 +422,8 @@ function assertCollection(contents) {
578
422
  if (contents instanceof Collection) return true;
579
423
  throw new Error('Expected a YAML collection as document contents');
580
424
  }
581
-
582
- var Document$1 = /*#__PURE__*/function () {
583
- function Document(options) {
584
- _classCallCheck(this, Document);
585
-
425
+ class Document$1 {
426
+ constructor(options) {
586
427
  this.anchors = new Anchors(options.anchorPrefix);
587
428
  this.commentBefore = null;
588
429
  this.comment = null;
@@ -595,408 +436,257 @@ var Document$1 = /*#__PURE__*/function () {
595
436
  this.version = null;
596
437
  this.warnings = [];
597
438
  }
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;
439
+ add(value) {
440
+ assertCollection(this.contents);
441
+ return this.contents.add(value);
442
+ }
443
+ addIn(path, value) {
444
+ assertCollection(this.contents);
445
+ this.contents.addIn(path, value);
446
+ }
447
+ delete(key) {
448
+ assertCollection(this.contents);
449
+ return this.contents.delete(key);
450
+ }
451
+ deleteIn(path) {
452
+ if (isEmptyPath(path)) {
453
+ if (this.contents == null) return false;
454
+ this.contents = null;
455
+ return true;
655
456
  }
656
- }, {
657
- key: "set",
658
- value: function set(key, value) {
457
+ assertCollection(this.contents);
458
+ return this.contents.deleteIn(path);
459
+ }
460
+ getDefaults() {
461
+ return Document$1.defaults[this.version] || Document$1.defaults[this.options.version] || {};
462
+ }
463
+ get(key, keepScalar) {
464
+ return this.contents instanceof Collection ? this.contents.get(key, keepScalar) : undefined;
465
+ }
466
+ getIn(path, keepScalar) {
467
+ if (isEmptyPath(path)) return !keepScalar && this.contents instanceof Scalar ? this.contents.value : this.contents;
468
+ return this.contents instanceof Collection ? this.contents.getIn(path, keepScalar) : undefined;
469
+ }
470
+ has(key) {
471
+ return this.contents instanceof Collection ? this.contents.has(key) : false;
472
+ }
473
+ hasIn(path) {
474
+ if (isEmptyPath(path)) return this.contents !== undefined;
475
+ return this.contents instanceof Collection ? this.contents.hasIn(path) : false;
476
+ }
477
+ set(key, value) {
478
+ assertCollection(this.contents);
479
+ this.contents.set(key, value);
480
+ }
481
+ setIn(path, value) {
482
+ if (isEmptyPath(path)) this.contents = value;else {
659
483
  assertCollection(this.contents);
660
- this.contents.set(key, value);
484
+ this.contents.setIn(path, value);
661
485
  }
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
- }
486
+ }
487
+ setSchema(id, customTags) {
488
+ if (!id && !customTags && this.schema) return;
489
+ if (typeof id === 'number') id = id.toFixed(1);
490
+ if (id === '1.0' || id === '1.1' || id === '1.2') {
491
+ if (this.version) this.version = id;else this.options.version = id;
492
+ delete this.options.schema;
493
+ } else if (id && typeof id === 'string') {
494
+ this.options.schema = id;
669
495
  }
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);
496
+ if (Array.isArray(customTags)) this.options.customTags = customTags;
497
+ const opt = Object.assign({}, this.getDefaults(), this.options);
498
+ this.schema = new Schema(opt);
499
+ }
500
+ parse(node, prevDoc) {
501
+ if (this.options.keepCstNodes) this.cstNode = node;
502
+ if (this.options.keepNodeTypes) this.type = 'DOCUMENT';
503
+ const {
504
+ directives = [],
505
+ contents = [],
506
+ directivesEndMarker,
507
+ error,
508
+ valueRange
509
+ } = node;
510
+ if (error) {
511
+ if (!error.source) error.source = this;
512
+ this.errors.push(error);
686
513
  }
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;
514
+ parseDirectives(this, directives, prevDoc);
515
+ if (directivesEndMarker) this.directivesEndMarker = true;
516
+ this.range = valueRange ? [valueRange.start, valueRange.end] : null;
517
+ this.setSchema();
518
+ this.anchors._cstAliases = [];
519
+ parseContents(this, contents);
520
+ this.anchors.resolveNodes();
521
+ if (this.options.prettyErrors) {
522
+ for (const error of this.errors) if (error instanceof YAMLError) error.makePretty();
523
+ for (const warn of this.warnings) if (warn instanceof YAMLError) warn.makePretty();
744
524
  }
745
- }, {
746
- key: "listNonDefaultTags",
747
- value: function listNonDefaultTags() {
748
- return listTagNames(this.contents).filter(function (t) {
749
- return t.indexOf(Schema.defaultPrefix) !== 0;
525
+ return this;
526
+ }
527
+ listNonDefaultTags() {
528
+ return listTagNames(this.contents).filter(t => t.indexOf(Schema.defaultPrefix) !== 0);
529
+ }
530
+ setTagPrefix(handle, prefix) {
531
+ if (handle[0] !== '!' || handle[handle.length - 1] !== '!') throw new Error('Handle must start and end with !');
532
+ if (prefix) {
533
+ const prev = this.tagPrefixes.find(p => p.handle === handle);
534
+ if (prev) prev.prefix = prefix;else this.tagPrefixes.push({
535
+ handle,
536
+ prefix
750
537
  });
538
+ } else {
539
+ this.tagPrefixes = this.tagPrefixes.filter(p => p.handle !== handle);
751
540
  }
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
- }
541
+ }
542
+ toJSON(arg, onAnchor) {
543
+ const {
544
+ keepBlobsInJSON,
545
+ mapAsMap,
546
+ maxAliasCount
547
+ } = this.options;
548
+ const keep = keepBlobsInJSON && (typeof arg !== 'string' || !(this.contents instanceof Scalar));
549
+ const ctx = {
550
+ doc: this,
551
+ indentStep: ' ',
552
+ keep,
553
+ mapAsMap: keep && !!mapAsMap,
554
+ maxAliasCount,
555
+ stringify: stringify$1 // Requiring directly in Pair would create circular dependencies
556
+ };
557
+ const anchorNames = Object.keys(this.anchors.map);
558
+ if (anchorNames.length > 0) ctx.anchors = new Map(anchorNames.map(name => [this.anchors.map[name], {
559
+ alias: [],
560
+ aliasCount: 0,
561
+ count: 1
562
+ }]));
563
+ const res = toJSON(this.contents, arg, ctx);
564
+ if (typeof onAnchor === 'function' && ctx.anchors) for (const {
565
+ count,
566
+ res
567
+ } of ctx.anchors.values()) onAnchor(res, count);
568
+ return res;
569
+ }
570
+ toString() {
571
+ if (this.errors.length > 0) throw new Error('Document with errors cannot be stringified');
572
+ const indentSize = this.options.indent;
573
+ if (!Number.isInteger(indentSize) || indentSize <= 0) {
574
+ const s = JSON.stringify(indentSize);
575
+ throw new Error(`"indent" option must be a positive integer, not ${s}`);
770
576
  }
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
- }
577
+ this.setSchema();
578
+ const lines = [];
579
+ let hasDirectives = false;
580
+ if (this.version) {
581
+ let vd = '%YAML 1.2';
582
+ if (this.schema.name === 'yaml-1.1') {
583
+ if (this.version === '1.0') vd = '%YAML:1.0';else if (this.version === '1.1') vd = '%YAML 1.1';
817
584
  }
818
-
819
- return res;
585
+ lines.push(vd);
586
+ hasDirectives = true;
820
587
  }
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);
588
+ const tagNames = this.listNonDefaultTags();
589
+ this.tagPrefixes.forEach(({
590
+ handle,
591
+ prefix
592
+ }) => {
593
+ if (tagNames.some(t => t.indexOf(prefix) === 0)) {
594
+ lines.push(`%TAG ${handle} ${prefix}`);
844
595
  hasDirectives = true;
845
596
  }
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, '#'));
597
+ });
598
+ if (hasDirectives || this.directivesEndMarker) lines.push('---');
599
+ if (this.commentBefore) {
600
+ if (hasDirectives || !this.directivesEndMarker) lines.unshift('');
601
+ lines.unshift(this.commentBefore.replace(/^/gm, '#'));
602
+ }
603
+ const ctx = {
604
+ anchors: Object.create(null),
605
+ doc: this,
606
+ indent: '',
607
+ indentStep: ' '.repeat(indentSize),
608
+ stringify: stringify$1 // Requiring directly in nodes would create circular dependencies
609
+ };
610
+ let chompKeep = false;
611
+ let contentComment = null;
612
+ if (this.contents) {
613
+ if (this.contents instanceof Node) {
614
+ if (this.contents.spaceBefore && (hasDirectives || this.directivesEndMarker)) lines.push('');
615
+ if (this.contents.commentBefore) lines.push(this.contents.commentBefore.replace(/^/gm, '#'));
616
+ // top-level block scalars need to be indented if followed by a comment
617
+ ctx.forceBlockIndent = !!this.comment;
618
+ contentComment = this.contents.comment;
900
619
  }
901
-
902
- return lines.join('\n') + '\n';
620
+ const onChompKeep = contentComment ? null : () => chompKeep = true;
621
+ const body = stringify$1(this.contents, ctx, () => contentComment = null, onChompKeep);
622
+ lines.push(addComment(body, '', contentComment));
623
+ } else if (this.contents !== undefined) {
624
+ lines.push(stringify$1(this.contents, ctx));
903
625
  }
904
- }]);
905
-
906
- return Document;
907
- }();
908
-
626
+ if (this.comment) {
627
+ if ((!chompKeep || contentComment) && lines[lines.length - 1] !== '') lines.push('');
628
+ lines.push(this.comment.replace(/^/gm, '#'));
629
+ }
630
+ return lines.join('\n') + '\n';
631
+ }
632
+ }
909
633
  _defineProperty(Document$1, "defaults", documentOptions);
910
634
 
911
- function createNode(value) {
912
- var wrapScalars = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
913
- var tag = arguments.length > 2 ? arguments[2] : undefined;
914
-
635
+ function createNode(value, wrapScalars = true, tag) {
915
636
  if (tag === undefined && typeof wrapScalars === 'string') {
916
637
  tag = wrapScalars;
917
638
  wrapScalars = true;
918
639
  }
919
-
920
- var options = Object.assign({}, Document$1.defaults[defaultOptions.version], defaultOptions);
921
- var schema = new Schema(options);
640
+ const options = Object.assign({}, Document$1.defaults[defaultOptions.version], defaultOptions);
641
+ const schema = new Schema(options);
922
642
  return schema.createNode(value, wrapScalars, tag);
923
643
  }
924
-
925
- var Document = /*#__PURE__*/function (_YAMLDocument) {
926
- _inherits(Document, _YAMLDocument);
927
-
928
- var _super = _createSuper(Document);
929
-
930
- function Document(options) {
931
- _classCallCheck(this, Document);
932
-
933
- return _super.call(this, Object.assign({}, defaultOptions, options));
644
+ class Document extends Document$1 {
645
+ constructor(options) {
646
+ super(Object.assign({}, defaultOptions, options));
934
647
  }
935
-
936
- return Document;
937
- }(Document$1);
938
-
648
+ }
939
649
  function parseAllDocuments(src, options) {
940
- var stream = [];
941
- var prev;
942
-
943
- var _iterator = _createForOfIteratorHelper(parse$1(src)),
944
- _step;
945
-
946
- try {
947
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
948
- var cstDoc = _step.value;
949
- var doc = new Document(options);
950
- doc.parse(cstDoc, prev);
951
- stream.push(doc);
952
- prev = doc;
953
- }
954
- } catch (err) {
955
- _iterator.e(err);
956
- } finally {
957
- _iterator.f();
650
+ const stream = [];
651
+ let prev;
652
+ for (const cstDoc of parse$1(src)) {
653
+ const doc = new Document(options);
654
+ doc.parse(cstDoc, prev);
655
+ stream.push(doc);
656
+ prev = doc;
958
657
  }
959
-
960
658
  return stream;
961
659
  }
962
-
963
660
  function parseDocument(src, options) {
964
- var cst = parse$1(src);
965
- var doc = new Document(options).parse(cst[0]);
966
-
661
+ const cst = parse$1(src);
662
+ const doc = new Document(options).parse(cst[0]);
967
663
  if (cst.length > 1) {
968
- var errMsg = 'Source contains multiple documents; please use YAML.parseAllDocuments()';
664
+ const errMsg = 'Source contains multiple documents; please use YAML.parseAllDocuments()';
969
665
  doc.errors.unshift(new YAMLSemanticError(cst[1], errMsg));
970
666
  }
971
-
972
667
  return doc;
973
668
  }
974
-
975
669
  function parse(src, options) {
976
- var doc = parseDocument(src, options);
977
- doc.warnings.forEach(function (warning) {
978
- return warn(warning);
979
- });
670
+ const doc = parseDocument(src, options);
671
+ doc.warnings.forEach(warning => warn(warning));
980
672
  if (doc.errors.length > 0) throw doc.errors[0];
981
673
  return doc.toJSON();
982
674
  }
983
-
984
675
  function stringify(value, options) {
985
- var doc = new Document(options);
676
+ const doc = new Document(options);
986
677
  doc.contents = value;
987
678
  return String(doc);
988
679
  }
989
-
990
- var YAML = {
991
- createNode: createNode,
992
- defaultOptions: defaultOptions,
993
- Document: Document,
994
- parse: parse,
995
- parseAllDocuments: parseAllDocuments,
680
+ const YAML = {
681
+ createNode,
682
+ defaultOptions,
683
+ Document,
684
+ parse,
685
+ parseAllDocuments,
996
686
  parseCST: parse$1,
997
- parseDocument: parseDocument,
998
- scalarOptions: scalarOptions,
999
- stringify: stringify
687
+ parseDocument,
688
+ scalarOptions,
689
+ stringify
1000
690
  };
1001
691
 
1002
692
  export { YAML };