resolveSeq-492ab440.js
   1  import { c as _classCallCheck, j as _inherits, k as _createSuper, b as _createClass, e as _defineProperty, p as _assertThisInitialized, a as _typeof, q as _toArray, T as Type, _ as _createForOfIteratorHelper, l as _get, m as _getPrototypeOf, o as YAMLReferenceError, r as _possibleConstructorReturn, h as _slicedToArray, g as YAMLSemanticError, n as defaultTags, f as YAMLWarning, C as Char, Y as YAMLSyntaxError, P as PlainValue } from './PlainValue-b8036b75.js';
   2  
   3  function addCommentBefore(str, indent, comment) {
   4    if (!comment) return str;
   5    var cc = comment.replace(/[\s\S]^/gm, "$&".concat(indent, "#"));
   6    return "#".concat(cc, "\n").concat(indent).concat(str);
   7  }
   8  function addComment(str, indent, comment) {
   9    return !comment ? str : comment.indexOf('\n') === -1 ? "".concat(str, " #").concat(comment) : "".concat(str, "\n") + comment.replace(/^/gm, "".concat(indent || '', "#"));
  10  }
  11  
  12  var Node = function Node() {
  13    _classCallCheck(this, Node);
  14  };
  15  
  16  function toJSON(value, arg, ctx) {
  17    if (Array.isArray(value)) return value.map(function (v, i) {
  18      return toJSON(v, String(i), ctx);
  19    });
  20  
  21    if (value && typeof value.toJSON === 'function') {
  22      var anchor = ctx && ctx.anchors && ctx.anchors.get(value);
  23      if (anchor) ctx.onCreate = function (res) {
  24        anchor.res = res;
  25        delete ctx.onCreate;
  26      };
  27      var res = value.toJSON(arg, ctx);
  28      if (anchor && ctx.onCreate) ctx.onCreate(res);
  29      return res;
  30    }
  31  
  32    if ((!ctx || !ctx.keep) && typeof value === 'bigint') return Number(value);
  33    return value;
  34  }
  35  
  36  var Scalar = /*#__PURE__*/function (_Node) {
  37    _inherits(Scalar, _Node);
  38  
  39    var _super = _createSuper(Scalar);
  40  
  41    function Scalar(value) {
  42      var _this;
  43  
  44      _classCallCheck(this, Scalar);
  45  
  46      _this = _super.call(this);
  47      _this.value = value;
  48      return _this;
  49    }
  50  
  51    _createClass(Scalar, [{
  52      key: "toJSON",
  53      value: function toJSON$1(arg, ctx) {
  54        return ctx && ctx.keep ? this.value : toJSON(this.value, arg, ctx);
  55      }
  56    }, {
  57      key: "toString",
  58      value: function toString() {
  59        return String(this.value);
  60      }
  61    }]);
  62  
  63    return Scalar;
  64  }(Node);
  65  
  66  function collectionFromPath(schema, path, value) {
  67    var v = value;
  68  
  69    for (var i = path.length - 1; i >= 0; --i) {
  70      var k = path[i];
  71  
  72      if (Number.isInteger(k) && k >= 0) {
  73        var a = [];
  74        a[k] = v;
  75        v = a;
  76      } else {
  77        var o = {};
  78        Object.defineProperty(o, k, {
  79          value: v,
  80          writable: true,
  81          enumerable: true,
  82          configurable: true
  83        });
  84        v = o;
  85      }
  86    }
  87  
  88    return schema.createNode(v, false);
  89  } // null, undefined, or an empty non-string iterable (e.g. [])
  90  
  91  
  92  var isEmptyPath = function isEmptyPath(path) {
  93    return path == null || _typeof(path) === 'object' && path[Symbol.iterator]().next().done;
  94  };
  95  var Collection = /*#__PURE__*/function (_Node) {
  96    _inherits(Collection, _Node);
  97  
  98    var _super = _createSuper(Collection);
  99  
 100    function Collection(schema) {
 101      var _this;
 102  
 103      _classCallCheck(this, Collection);
 104  
 105      _this = _super.call(this);
 106  
 107      _defineProperty(_assertThisInitialized(_this), "items", []);
 108  
 109      _this.schema = schema;
 110      return _this;
 111    }
 112  
 113    _createClass(Collection, [{
 114      key: "addIn",
 115      value: function addIn(path, value) {
 116        if (isEmptyPath(path)) this.add(value);else {
 117          var _path = _toArray(path),
 118              key = _path[0],
 119              rest = _path.slice(1);
 120  
 121          var node = this.get(key, true);
 122          if (node instanceof Collection) node.addIn(rest, value);else if (node === undefined && this.schema) this.set(key, collectionFromPath(this.schema, rest, value));else throw new Error("Expected YAML collection at ".concat(key, ". Remaining path: ").concat(rest));
 123        }
 124      }
 125    }, {
 126      key: "deleteIn",
 127      value: function deleteIn(_ref) {
 128        var _ref2 = _toArray(_ref),
 129            key = _ref2[0],
 130            rest = _ref2.slice(1);
 131  
 132        if (rest.length === 0) return this.delete(key);
 133        var node = this.get(key, true);
 134        if (node instanceof Collection) return node.deleteIn(rest);else throw new Error("Expected YAML collection at ".concat(key, ". Remaining path: ").concat(rest));
 135      }
 136    }, {
 137      key: "getIn",
 138      value: function getIn(_ref3, keepScalar) {
 139        var _ref4 = _toArray(_ref3),
 140            key = _ref4[0],
 141            rest = _ref4.slice(1);
 142  
 143        var node = this.get(key, true);
 144        if (rest.length === 0) return !keepScalar && node instanceof Scalar ? node.value : node;else return node instanceof Collection ? node.getIn(rest, keepScalar) : undefined;
 145      }
 146    }, {
 147      key: "hasAllNullValues",
 148      value: function hasAllNullValues() {
 149        return this.items.every(function (node) {
 150          if (!node || node.type !== 'PAIR') return false;
 151          var n = node.value;
 152          return n == null || n instanceof Scalar && n.value == null && !n.commentBefore && !n.comment && !n.tag;
 153        });
 154      }
 155    }, {
 156      key: "hasIn",
 157      value: function hasIn(_ref5) {
 158        var _ref6 = _toArray(_ref5),
 159            key = _ref6[0],
 160            rest = _ref6.slice(1);
 161  
 162        if (rest.length === 0) return this.has(key);
 163        var node = this.get(key, true);
 164        return node instanceof Collection ? node.hasIn(rest) : false;
 165      }
 166    }, {
 167      key: "setIn",
 168      value: function setIn(_ref7, value) {
 169        var _ref8 = _toArray(_ref7),
 170            key = _ref8[0],
 171            rest = _ref8.slice(1);
 172  
 173        if (rest.length === 0) {
 174          this.set(key, value);
 175        } else {
 176          var node = this.get(key, true);
 177          if (node instanceof Collection) node.setIn(rest, value);else if (node === undefined && this.schema) this.set(key, collectionFromPath(this.schema, rest, value));else throw new Error("Expected YAML collection at ".concat(key, ". Remaining path: ").concat(rest));
 178        }
 179      } // overridden in implementations
 180  
 181      /* istanbul ignore next */
 182  
 183    }, {
 184      key: "toJSON",
 185      value: function toJSON() {
 186        return null;
 187      }
 188    }, {
 189      key: "toString",
 190      value: function toString(ctx, _ref9, onComment, onChompKeep) {
 191        var _this2 = this;
 192  
 193        var blockItem = _ref9.blockItem,
 194            flowChars = _ref9.flowChars,
 195            isMap = _ref9.isMap,
 196            itemIndent = _ref9.itemIndent;
 197        var _ctx = ctx,
 198            indent = _ctx.indent,
 199            indentStep = _ctx.indentStep,
 200            stringify = _ctx.stringify;
 201        var inFlow = this.type === Type.FLOW_MAP || this.type === Type.FLOW_SEQ || ctx.inFlow;
 202        if (inFlow) itemIndent += indentStep;
 203        var allNullValues = isMap && this.hasAllNullValues();
 204        ctx = Object.assign({}, ctx, {
 205          allNullValues: allNullValues,
 206          indent: itemIndent,
 207          inFlow: inFlow,
 208          type: null
 209        });
 210        var chompKeep = false;
 211        var hasItemWithNewLine = false;
 212        var nodes = this.items.reduce(function (nodes, item, i) {
 213          var comment;
 214  
 215          if (item) {
 216            if (!chompKeep && item.spaceBefore) nodes.push({
 217              type: 'comment',
 218              str: ''
 219            });
 220            if (item.commentBefore) item.commentBefore.match(/^.*$/gm).forEach(function (line) {
 221              nodes.push({
 222                type: 'comment',
 223                str: "#".concat(line)
 224              });
 225            });
 226            if (item.comment) comment = item.comment;
 227            if (inFlow && (!chompKeep && item.spaceBefore || item.commentBefore || item.comment || item.key && (item.key.commentBefore || item.key.comment) || item.value && (item.value.commentBefore || item.value.comment))) hasItemWithNewLine = true;
 228          }
 229  
 230          chompKeep = false;
 231          var str = stringify(item, ctx, function () {
 232            return comment = null;
 233          }, function () {
 234            return chompKeep = true;
 235          });
 236          if (inFlow && !hasItemWithNewLine && str.includes('\n')) hasItemWithNewLine = true;
 237          if (inFlow && i < _this2.items.length - 1) str += ',';
 238          str = addComment(str, itemIndent, comment);
 239          if (chompKeep && (comment || inFlow)) chompKeep = false;
 240          nodes.push({
 241            type: 'item',
 242            str: str
 243          });
 244          return nodes;
 245        }, []);
 246        var str;
 247  
 248        if (nodes.length === 0) {
 249          str = flowChars.start + flowChars.end;
 250        } else if (inFlow) {
 251          var start = flowChars.start,
 252              end = flowChars.end;
 253          var strings = nodes.map(function (n) {
 254            return n.str;
 255          });
 256  
 257          if (hasItemWithNewLine || strings.reduce(function (sum, str) {
 258            return sum + str.length + 2;
 259          }, 2) > Collection.maxFlowStringSingleLineLength) {
 260            str = start;
 261  
 262            var _iterator = _createForOfIteratorHelper(strings),
 263                _step;
 264  
 265            try {
 266              for (_iterator.s(); !(_step = _iterator.n()).done;) {
 267                var s = _step.value;
 268                str += s ? "\n".concat(indentStep).concat(indent).concat(s) : '\n';
 269              }
 270            } catch (err) {
 271              _iterator.e(err);
 272            } finally {
 273              _iterator.f();
 274            }
 275  
 276            str += "\n".concat(indent).concat(end);
 277          } else {
 278            str = "".concat(start, " ").concat(strings.join(' '), " ").concat(end);
 279          }
 280        } else {
 281          var _strings = nodes.map(blockItem);
 282  
 283          str = _strings.shift();
 284  
 285          var _iterator2 = _createForOfIteratorHelper(_strings),
 286              _step2;
 287  
 288          try {
 289            for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
 290              var _s = _step2.value;
 291              str += _s ? "\n".concat(indent).concat(_s) : '\n';
 292            }
 293          } catch (err) {
 294            _iterator2.e(err);
 295          } finally {
 296            _iterator2.f();
 297          }
 298        }
 299  
 300        if (this.comment) {
 301          str += '\n' + this.comment.replace(/^/gm, "".concat(indent, "#"));
 302          if (onComment) onComment();
 303        } else if (chompKeep && onChompKeep) onChompKeep();
 304  
 305        return str;
 306      }
 307    }]);
 308  
 309    return Collection;
 310  }(Node);
 311  
 312  _defineProperty(Collection, "maxFlowStringSingleLineLength", 60);
 313  
 314  function asItemIndex(key) {
 315    var idx = key instanceof Scalar ? key.value : key;
 316    if (idx && typeof idx === 'string') idx = Number(idx);
 317    return Number.isInteger(idx) && idx >= 0 ? idx : null;
 318  }
 319  
 320  var YAMLSeq = /*#__PURE__*/function (_Collection) {
 321    _inherits(YAMLSeq, _Collection);
 322  
 323    var _super = _createSuper(YAMLSeq);
 324  
 325    function YAMLSeq() {
 326      _classCallCheck(this, YAMLSeq);
 327  
 328      return _super.apply(this, arguments);
 329    }
 330  
 331    _createClass(YAMLSeq, [{
 332      key: "add",
 333      value: function add(value) {
 334        this.items.push(value);
 335      }
 336    }, {
 337      key: "delete",
 338      value: function _delete(key) {
 339        var idx = asItemIndex(key);
 340        if (typeof idx !== 'number') return false;
 341        var del = this.items.splice(idx, 1);
 342        return del.length > 0;
 343      }
 344    }, {
 345      key: "get",
 346      value: function get(key, keepScalar) {
 347        var idx = asItemIndex(key);
 348        if (typeof idx !== 'number') return undefined;
 349        var it = this.items[idx];
 350        return !keepScalar && it instanceof Scalar ? it.value : it;
 351      }
 352    }, {
 353      key: "has",
 354      value: function has(key) {
 355        var idx = asItemIndex(key);
 356        return typeof idx === 'number' && idx < this.items.length;
 357      }
 358    }, {
 359      key: "set",
 360      value: function set(key, value) {
 361        var idx = asItemIndex(key);
 362        if (typeof idx !== 'number') throw new Error("Expected a valid index, not ".concat(key, "."));
 363        this.items[idx] = value;
 364      }
 365    }, {
 366      key: "toJSON",
 367      value: function toJSON$1(_, ctx) {
 368        var seq = [];
 369        if (ctx && ctx.onCreate) ctx.onCreate(seq);
 370        var i = 0;
 371  
 372        var _iterator = _createForOfIteratorHelper(this.items),
 373            _step;
 374  
 375        try {
 376          for (_iterator.s(); !(_step = _iterator.n()).done;) {
 377            var item = _step.value;
 378            seq.push(toJSON(item, String(i++), ctx));
 379          }
 380        } catch (err) {
 381          _iterator.e(err);
 382        } finally {
 383          _iterator.f();
 384        }
 385  
 386        return seq;
 387      }
 388    }, {
 389      key: "toString",
 390      value: function toString(ctx, onComment, onChompKeep) {
 391        if (!ctx) return JSON.stringify(this);
 392        return _get(_getPrototypeOf(YAMLSeq.prototype), "toString", this).call(this, ctx, {
 393          blockItem: function blockItem(n) {
 394            return n.type === 'comment' ? n.str : "- ".concat(n.str);
 395          },
 396          flowChars: {
 397            start: '[',
 398            end: ']'
 399          },
 400          isMap: false,
 401          itemIndent: (ctx.indent || '') + '  '
 402        }, onComment, onChompKeep);
 403      }
 404    }]);
 405  
 406    return YAMLSeq;
 407  }(Collection);
 408  
 409  var stringifyKey = function stringifyKey(key, jsKey, ctx) {
 410    if (jsKey === null) return '';
 411    if (_typeof(jsKey) !== 'object') return String(jsKey);
 412    if (key instanceof Node && ctx && ctx.doc) return key.toString({
 413      anchors: Object.create(null),
 414      doc: ctx.doc,
 415      indent: '',
 416      indentStep: ctx.indentStep,
 417      inFlow: true,
 418      inStringifyKey: true,
 419      stringify: ctx.stringify
 420    });
 421    return JSON.stringify(jsKey);
 422  };
 423  
 424  var Pair = /*#__PURE__*/function (_Node) {
 425    _inherits(Pair, _Node);
 426  
 427    var _super = _createSuper(Pair);
 428  
 429    function Pair(key) {
 430      var _this;
 431  
 432      var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
 433  
 434      _classCallCheck(this, Pair);
 435  
 436      _this = _super.call(this);
 437      _this.key = key;
 438      _this.value = value;
 439      _this.type = Pair.Type.PAIR;
 440      return _this;
 441    }
 442  
 443    _createClass(Pair, [{
 444      key: "commentBefore",
 445      get: function get() {
 446        return this.key instanceof Node ? this.key.commentBefore : undefined;
 447      },
 448      set: function set(cb) {
 449        if (this.key == null) this.key = new Scalar(null);
 450        if (this.key instanceof Node) this.key.commentBefore = cb;else {
 451          var msg = 'Pair.commentBefore is an alias for Pair.key.commentBefore. To set it, the key must be a Node.';
 452          throw new Error(msg);
 453        }
 454      }
 455    }, {
 456      key: "addToJSMap",
 457      value: function addToJSMap(ctx, map) {
 458        var key = toJSON(this.key, '', ctx);
 459  
 460        if (map instanceof Map) {
 461          var value = toJSON(this.value, key, ctx);
 462          map.set(key, value);
 463        } else if (map instanceof Set) {
 464          map.add(key);
 465        } else {
 466          var stringKey = stringifyKey(this.key, key, ctx);
 467  
 468          var _value = toJSON(this.value, stringKey, ctx);
 469  
 470          if (stringKey in map) Object.defineProperty(map, stringKey, {
 471            value: _value,
 472            writable: true,
 473            enumerable: true,
 474            configurable: true
 475          });else map[stringKey] = _value;
 476        }
 477  
 478        return map;
 479      }
 480    }, {
 481      key: "toJSON",
 482      value: function toJSON(_, ctx) {
 483        var pair = ctx && ctx.mapAsMap ? new Map() : {};
 484        return this.addToJSMap(ctx, pair);
 485      }
 486    }, {
 487      key: "toString",
 488      value: function toString(ctx, onComment, onChompKeep) {
 489        if (!ctx || !ctx.doc) return JSON.stringify(this);
 490        var _ctx$doc$options = ctx.doc.options,
 491            indentSize = _ctx$doc$options.indent,
 492            indentSeq = _ctx$doc$options.indentSeq,
 493            simpleKeys = _ctx$doc$options.simpleKeys;
 494        var key = this.key,
 495            value = this.value;
 496        var keyComment = key instanceof Node && key.comment;
 497  
 498        if (simpleKeys) {
 499          if (keyComment) {
 500            throw new Error('With simple keys, key nodes cannot have comments');
 501          }
 502  
 503          if (key instanceof Collection) {
 504            var msg = 'With simple keys, collection cannot be used as a key value';
 505            throw new Error(msg);
 506          }
 507        }
 508  
 509        var explicitKey = !simpleKeys && (!key || keyComment || (key instanceof Node ? key instanceof Collection || key.type === Type.BLOCK_FOLDED || key.type === Type.BLOCK_LITERAL : _typeof(key) === 'object'));
 510        var _ctx = ctx,
 511            doc = _ctx.doc,
 512            indent = _ctx.indent,
 513            indentStep = _ctx.indentStep,
 514            stringify = _ctx.stringify;
 515        ctx = Object.assign({}, ctx, {
 516          implicitKey: !explicitKey,
 517          indent: indent + indentStep
 518        });
 519        var chompKeep = false;
 520        var str = stringify(key, ctx, function () {
 521          return keyComment = null;
 522        }, function () {
 523          return chompKeep = true;
 524        });
 525        str = addComment(str, ctx.indent, keyComment);
 526  
 527        if (!explicitKey && str.length > 1024) {
 528          if (simpleKeys) throw new Error('With simple keys, single line scalar must not span more than 1024 characters');
 529          explicitKey = true;
 530        }
 531  
 532        if (ctx.allNullValues && !simpleKeys) {
 533          if (this.comment) {
 534            str = addComment(str, ctx.indent, this.comment);
 535            if (onComment) onComment();
 536          } else if (chompKeep && !keyComment && onChompKeep) onChompKeep();
 537  
 538          return ctx.inFlow && !explicitKey ? str : "? ".concat(str);
 539        }
 540  
 541        str = explicitKey ? "? ".concat(str, "\n").concat(indent, ":") : "".concat(str, ":");
 542  
 543        if (this.comment) {
 544          // expected (but not strictly required) to be a single-line comment
 545          str = addComment(str, ctx.indent, this.comment);
 546          if (onComment) onComment();
 547        }
 548  
 549        var vcb = '';
 550        var valueComment = null;
 551  
 552        if (value instanceof Node) {
 553          if (value.spaceBefore) vcb = '\n';
 554  
 555          if (value.commentBefore) {
 556            var cs = value.commentBefore.replace(/^/gm, "".concat(ctx.indent, "#"));
 557            vcb += "\n".concat(cs);
 558          }
 559  
 560          valueComment = value.comment;
 561        } else if (value && _typeof(value) === 'object') {
 562          value = doc.schema.createNode(value, true);
 563        }
 564  
 565        ctx.implicitKey = false;
 566        if (!explicitKey && !this.comment && value instanceof Scalar) ctx.indentAtStart = str.length + 1;
 567        chompKeep = false;
 568  
 569        if (!indentSeq && indentSize >= 2 && !ctx.inFlow && !explicitKey && value instanceof YAMLSeq && value.type !== Type.FLOW_SEQ && !value.tag && !doc.anchors.getName(value)) {
 570          // If indentSeq === false, consider '- ' as part of indentation where possible
 571          ctx.indent = ctx.indent.substr(2);
 572        }
 573  
 574        var valueStr = stringify(value, ctx, function () {
 575          return valueComment = null;
 576        }, function () {
 577          return chompKeep = true;
 578        });
 579        var ws = ' ';
 580  
 581        if (vcb || this.comment) {
 582          ws = "".concat(vcb, "\n").concat(ctx.indent);
 583        } else if (!explicitKey && value instanceof Collection) {
 584          var flow = valueStr[0] === '[' || valueStr[0] === '{';
 585          if (!flow || valueStr.includes('\n')) ws = "\n".concat(ctx.indent);
 586        } else if (valueStr[0] === '\n') ws = '';
 587  
 588        if (chompKeep && !valueComment && onChompKeep) onChompKeep();
 589        return addComment(str + ws + valueStr, ctx.indent, valueComment);
 590      }
 591    }]);
 592  
 593    return Pair;
 594  }(Node);
 595  
 596  _defineProperty(Pair, "Type", {
 597    PAIR: 'PAIR',
 598    MERGE_PAIR: 'MERGE_PAIR'
 599  });
 600  
 601  var getAliasCount = function getAliasCount(node, anchors) {
 602    if (node instanceof Alias) {
 603      var anchor = anchors.get(node.source);
 604      return anchor.count * anchor.aliasCount;
 605    } else if (node instanceof Collection) {
 606      var count = 0;
 607  
 608      var _iterator = _createForOfIteratorHelper(node.items),
 609          _step;
 610  
 611      try {
 612        for (_iterator.s(); !(_step = _iterator.n()).done;) {
 613          var item = _step.value;
 614          var c = getAliasCount(item, anchors);
 615          if (c > count) count = c;
 616        }
 617      } catch (err) {
 618        _iterator.e(err);
 619      } finally {
 620        _iterator.f();
 621      }
 622  
 623      return count;
 624    } else if (node instanceof Pair) {
 625      var kc = getAliasCount(node.key, anchors);
 626      var vc = getAliasCount(node.value, anchors);
 627      return Math.max(kc, vc);
 628    }
 629  
 630    return 1;
 631  };
 632  
 633  var Alias = /*#__PURE__*/function (_Node) {
 634    _inherits(Alias, _Node);
 635  
 636    var _super = _createSuper(Alias);
 637  
 638    function Alias(source) {
 639      var _this;
 640  
 641      _classCallCheck(this, Alias);
 642  
 643      _this = _super.call(this);
 644      _this.source = source;
 645      _this.type = Type.ALIAS;
 646      return _this;
 647    }
 648  
 649    _createClass(Alias, [{
 650      key: "tag",
 651      set: function set(t) {
 652        throw new Error('Alias nodes cannot have tags');
 653      }
 654    }, {
 655      key: "toJSON",
 656      value: function toJSON$1(arg, ctx) {
 657        if (!ctx) return toJSON(this.source, arg, ctx);
 658        var anchors = ctx.anchors,
 659            maxAliasCount = ctx.maxAliasCount;
 660        var anchor = anchors.get(this.source);
 661        /* istanbul ignore if */
 662  
 663        if (!anchor || anchor.res === undefined) {
 664          var msg = 'This should not happen: Alias anchor was not resolved?';
 665          if (this.cstNode) throw new YAMLReferenceError(this.cstNode, msg);else throw new ReferenceError(msg);
 666        }
 667  
 668        if (maxAliasCount >= 0) {
 669          anchor.count += 1;
 670          if (anchor.aliasCount === 0) anchor.aliasCount = getAliasCount(this.source, anchors);
 671  
 672          if (anchor.count * anchor.aliasCount > maxAliasCount) {
 673            var _msg = 'Excessive alias count indicates a resource exhaustion attack';
 674            if (this.cstNode) throw new YAMLReferenceError(this.cstNode, _msg);else throw new ReferenceError(_msg);
 675          }
 676        }
 677  
 678        return anchor.res;
 679      } // Only called when stringifying an alias mapping key while constructing
 680      // Object output.
 681  
 682    }, {
 683      key: "toString",
 684      value: function toString(ctx) {
 685        return Alias.stringify(this, ctx);
 686      }
 687    }], [{
 688      key: "stringify",
 689      value: function stringify(_ref, _ref2) {
 690        var range = _ref.range,
 691            source = _ref.source;
 692        var anchors = _ref2.anchors,
 693            doc = _ref2.doc,
 694            implicitKey = _ref2.implicitKey,
 695            inStringifyKey = _ref2.inStringifyKey;
 696        var anchor = Object.keys(anchors).find(function (a) {
 697          return anchors[a] === source;
 698        });
 699        if (!anchor && inStringifyKey) anchor = doc.anchors.getName(source) || doc.anchors.newName();
 700        if (anchor) return "*".concat(anchor).concat(implicitKey ? ' ' : '');
 701        var msg = doc.anchors.getName(source) ? 'Alias node must be after source node' : 'Source node not found for alias node';
 702        throw new Error("".concat(msg, " [").concat(range, "]"));
 703      }
 704    }]);
 705  
 706    return Alias;
 707  }(Node);
 708  
 709  _defineProperty(Alias, "default", true);
 710  
 711  function findPair(items, key) {
 712    var k = key instanceof Scalar ? key.value : key;
 713  
 714    var _iterator = _createForOfIteratorHelper(items),
 715        _step;
 716  
 717    try {
 718      for (_iterator.s(); !(_step = _iterator.n()).done;) {
 719        var it = _step.value;
 720  
 721        if (it instanceof Pair) {
 722          if (it.key === key || it.key === k) return it;
 723          if (it.key && it.key.value === k) return it;
 724        }
 725      }
 726    } catch (err) {
 727      _iterator.e(err);
 728    } finally {
 729      _iterator.f();
 730    }
 731  
 732    return undefined;
 733  }
 734  var YAMLMap = /*#__PURE__*/function (_Collection) {
 735    _inherits(YAMLMap, _Collection);
 736  
 737    var _super = _createSuper(YAMLMap);
 738  
 739    function YAMLMap() {
 740      _classCallCheck(this, YAMLMap);
 741  
 742      return _super.apply(this, arguments);
 743    }
 744  
 745    _createClass(YAMLMap, [{
 746      key: "add",
 747      value: function add(pair, overwrite) {
 748        if (!pair) pair = new Pair(pair);else if (!(pair instanceof Pair)) pair = new Pair(pair.key || pair, pair.value);
 749        var prev = findPair(this.items, pair.key);
 750        var sortEntries = this.schema && this.schema.sortMapEntries;
 751  
 752        if (prev) {
 753          if (overwrite) prev.value = pair.value;else throw new Error("Key ".concat(pair.key, " already set"));
 754        } else if (sortEntries) {
 755          var i = this.items.findIndex(function (item) {
 756            return sortEntries(pair, item) < 0;
 757          });
 758          if (i === -1) this.items.push(pair);else this.items.splice(i, 0, pair);
 759        } else {
 760          this.items.push(pair);
 761        }
 762      }
 763    }, {
 764      key: "delete",
 765      value: function _delete(key) {
 766        var it = findPair(this.items, key);
 767        if (!it) return false;
 768        var del = this.items.splice(this.items.indexOf(it), 1);
 769        return del.length > 0;
 770      }
 771    }, {
 772      key: "get",
 773      value: function get(key, keepScalar) {
 774        var it = findPair(this.items, key);
 775        var node = it && it.value;
 776        return !keepScalar && node instanceof Scalar ? node.value : node;
 777      }
 778    }, {
 779      key: "has",
 780      value: function has(key) {
 781        return !!findPair(this.items, key);
 782      }
 783    }, {
 784      key: "set",
 785      value: function set(key, value) {
 786        this.add(new Pair(key, value), true);
 787      }
 788      /**
 789       * @param {*} arg ignored
 790       * @param {*} ctx Conversion context, originally set in Document#toJSON()
 791       * @param {Class} Type If set, forces the returned collection type
 792       * @returns {*} Instance of Type, Map, or Object
 793       */
 794  
 795    }, {
 796      key: "toJSON",
 797      value: function toJSON(_, ctx, Type) {
 798        var map = Type ? new Type() : ctx && ctx.mapAsMap ? new Map() : {};
 799        if (ctx && ctx.onCreate) ctx.onCreate(map);
 800  
 801        var _iterator2 = _createForOfIteratorHelper(this.items),
 802            _step2;
 803  
 804        try {
 805          for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
 806            var item = _step2.value;
 807            item.addToJSMap(ctx, map);
 808          }
 809        } catch (err) {
 810          _iterator2.e(err);
 811        } finally {
 812          _iterator2.f();
 813        }
 814  
 815        return map;
 816      }
 817    }, {
 818      key: "toString",
 819      value: function toString(ctx, onComment, onChompKeep) {
 820        if (!ctx) return JSON.stringify(this);
 821  
 822        var _iterator3 = _createForOfIteratorHelper(this.items),
 823            _step3;
 824  
 825        try {
 826          for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
 827            var item = _step3.value;
 828            if (!(item instanceof Pair)) throw new Error("Map items must all be pairs; found ".concat(JSON.stringify(item), " instead"));
 829          }
 830        } catch (err) {
 831          _iterator3.e(err);
 832        } finally {
 833          _iterator3.f();
 834        }
 835  
 836        return _get(_getPrototypeOf(YAMLMap.prototype), "toString", this).call(this, ctx, {
 837          blockItem: function blockItem(n) {
 838            return n.str;
 839          },
 840          flowChars: {
 841            start: '{',
 842            end: '}'
 843          },
 844          isMap: true,
 845          itemIndent: ctx.indent || ''
 846        }, onComment, onChompKeep);
 847      }
 848    }]);
 849  
 850    return YAMLMap;
 851  }(Collection);
 852  
 853  var MERGE_KEY = '<<';
 854  var Merge = /*#__PURE__*/function (_Pair) {
 855    _inherits(Merge, _Pair);
 856  
 857    var _super = _createSuper(Merge);
 858  
 859    function Merge(pair) {
 860      var _this;
 861  
 862      _classCallCheck(this, Merge);
 863  
 864      if (pair instanceof Pair) {
 865        var seq = pair.value;
 866  
 867        if (!(seq instanceof YAMLSeq)) {
 868          seq = new YAMLSeq();
 869          seq.items.push(pair.value);
 870          seq.range = pair.value.range;
 871        }
 872  
 873        _this = _super.call(this, pair.key, seq);
 874        _this.range = pair.range;
 875      } else {
 876        _this = _super.call(this, new Scalar(MERGE_KEY), new YAMLSeq());
 877      }
 878  
 879      _this.type = Pair.Type.MERGE_PAIR;
 880      return _possibleConstructorReturn(_this);
 881    } // If the value associated with a merge key is a single mapping node, each of
 882    // its key/value pairs is inserted into the current mapping, unless the key
 883    // already exists in it. If the value associated with the merge key is a
 884    // sequence, then this sequence is expected to contain mapping nodes and each
 885    // of these nodes is merged in turn according to its order in the sequence.
 886    // Keys in mapping nodes earlier in the sequence override keys specified in
 887    // later mapping nodes. -- http://yaml.org/type/merge.html
 888  
 889  
 890    _createClass(Merge, [{
 891      key: "addToJSMap",
 892      value: function addToJSMap(ctx, map) {
 893        var _iterator = _createForOfIteratorHelper(this.value.items),
 894            _step;
 895  
 896        try {
 897          for (_iterator.s(); !(_step = _iterator.n()).done;) {
 898            var source = _step.value.source;
 899            if (!(source instanceof YAMLMap)) throw new Error('Merge sources must be maps');
 900            var srcMap = source.toJSON(null, ctx, Map);
 901  
 902            var _iterator2 = _createForOfIteratorHelper(srcMap),
 903                _step2;
 904  
 905            try {
 906              for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
 907                var _step2$value = _slicedToArray(_step2.value, 2),
 908                    key = _step2$value[0],
 909                    value = _step2$value[1];
 910  
 911                if (map instanceof Map) {
 912                  if (!map.has(key)) map.set(key, value);
 913                } else if (map instanceof Set) {
 914                  map.add(key);
 915                } else if (!Object.prototype.hasOwnProperty.call(map, key)) {
 916                  Object.defineProperty(map, key, {
 917                    value: value,
 918                    writable: true,
 919                    enumerable: true,
 920                    configurable: true
 921                  });
 922                }
 923              }
 924            } catch (err) {
 925              _iterator2.e(err);
 926            } finally {
 927              _iterator2.f();
 928            }
 929          }
 930        } catch (err) {
 931          _iterator.e(err);
 932        } finally {
 933          _iterator.f();
 934        }
 935  
 936        return map;
 937      }
 938    }, {
 939      key: "toString",
 940      value: function toString(ctx, onComment) {
 941        var seq = this.value;
 942        if (seq.items.length > 1) return _get(_getPrototypeOf(Merge.prototype), "toString", this).call(this, ctx, onComment);
 943        this.value = seq.items[0];
 944  
 945        var str = _get(_getPrototypeOf(Merge.prototype), "toString", this).call(this, ctx, onComment);
 946  
 947        this.value = seq;
 948        return str;
 949      }
 950    }]);
 951  
 952    return Merge;
 953  }(Pair);
 954  
 955  var binaryOptions = {
 956    defaultType: Type.BLOCK_LITERAL,
 957    lineWidth: 76
 958  };
 959  var boolOptions = {
 960    trueStr: 'true',
 961    falseStr: 'false'
 962  };
 963  var intOptions = {
 964    asBigInt: false
 965  };
 966  var nullOptions = {
 967    nullStr: 'null'
 968  };
 969  var strOptions = {
 970    defaultType: Type.PLAIN,
 971    doubleQuoted: {
 972      jsonEncoding: false,
 973      minMultiLineLength: 40
 974    },
 975    fold: {
 976      lineWidth: 80,
 977      minContentWidth: 20
 978    }
 979  };
 980  
 981  function resolveScalar(str, tags, scalarFallback) {
 982    var _iterator = _createForOfIteratorHelper(tags),
 983        _step;
 984  
 985    try {
 986      for (_iterator.s(); !(_step = _iterator.n()).done;) {
 987        var _step$value = _step.value,
 988            format = _step$value.format,
 989            test = _step$value.test,
 990            resolve = _step$value.resolve;
 991  
 992        if (test) {
 993          var match = str.match(test);
 994  
 995          if (match) {
 996            var res = resolve.apply(null, match);
 997            if (!(res instanceof Scalar)) res = new Scalar(res);
 998            if (format) res.format = format;
 999            return res;
1000          }
1001        }
1002      }
1003    } catch (err) {
1004      _iterator.e(err);
1005    } finally {
1006      _iterator.f();
1007    }
1008  
1009    if (scalarFallback) str = scalarFallback(str);
1010    return new Scalar(str);
1011  }
1012  
1013  var FOLD_FLOW = 'flow';
1014  var FOLD_BLOCK = 'block';
1015  var FOLD_QUOTED = 'quoted'; // presumes i+1 is at the start of a line
1016  // returns index of last newline in more-indented block
1017  
1018  var consumeMoreIndentedLines = function consumeMoreIndentedLines(text, i) {
1019    var ch = text[i + 1];
1020  
1021    while (ch === ' ' || ch === '\t') {
1022      do {
1023        ch = text[i += 1];
1024      } while (ch && ch !== '\n');
1025  
1026      ch = text[i + 1];
1027    }
1028  
1029    return i;
1030  };
1031  /**
1032   * Tries to keep input at up to `lineWidth` characters, splitting only on spaces
1033   * not followed by newlines or spaces unless `mode` is `'quoted'`. Lines are
1034   * terminated with `\n` and started with `indent`.
1035   *
1036   * @param {string} text
1037   * @param {string} indent
1038   * @param {string} [mode='flow'] `'block'` prevents more-indented lines
1039   *   from being folded; `'quoted'` allows for `\` escapes, including escaped
1040   *   newlines
1041   * @param {Object} options
1042   * @param {number} [options.indentAtStart] Accounts for leading contents on
1043   *   the first line, defaulting to `indent.length`
1044   * @param {number} [options.lineWidth=80]
1045   * @param {number} [options.minContentWidth=20] Allow highly indented lines to
1046   *   stretch the line width or indent content from the start
1047   * @param {function} options.onFold Called once if the text is folded
1048   * @param {function} options.onFold Called once if any line of text exceeds
1049   *   lineWidth characters
1050   */
1051  
1052  
1053  function foldFlowLines(text, indent, mode, _ref) {
1054    var indentAtStart = _ref.indentAtStart,
1055        _ref$lineWidth = _ref.lineWidth,
1056        lineWidth = _ref$lineWidth === void 0 ? 80 : _ref$lineWidth,
1057        _ref$minContentWidth = _ref.minContentWidth,
1058        minContentWidth = _ref$minContentWidth === void 0 ? 20 : _ref$minContentWidth,
1059        onFold = _ref.onFold,
1060        onOverflow = _ref.onOverflow;
1061    if (!lineWidth || lineWidth < 0) return text;
1062    var endStep = Math.max(1 + minContentWidth, 1 + lineWidth - indent.length);
1063    if (text.length <= endStep) return text;
1064    var folds = [];
1065    var escapedFolds = {};
1066    var end = lineWidth - indent.length;
1067  
1068    if (typeof indentAtStart === 'number') {
1069      if (indentAtStart > lineWidth - Math.max(2, minContentWidth)) folds.push(0);else end = lineWidth - indentAtStart;
1070    }
1071  
1072    var split = undefined;
1073    var prev = undefined;
1074    var overflow = false;
1075    var i = -1;
1076    var escStart = -1;
1077    var escEnd = -1;
1078  
1079    if (mode === FOLD_BLOCK) {
1080      i = consumeMoreIndentedLines(text, i);
1081      if (i !== -1) end = i + endStep;
1082    }
1083  
1084    for (var ch; ch = text[i += 1];) {
1085      if (mode === FOLD_QUOTED && ch === '\\') {
1086        escStart = i;
1087  
1088        switch (text[i + 1]) {
1089          case 'x':
1090            i += 3;
1091            break;
1092  
1093          case 'u':
1094            i += 5;
1095            break;
1096  
1097          case 'U':
1098            i += 9;
1099            break;
1100  
1101          default:
1102            i += 1;
1103        }
1104  
1105        escEnd = i;
1106      }
1107  
1108      if (ch === '\n') {
1109        if (mode === FOLD_BLOCK) i = consumeMoreIndentedLines(text, i);
1110        end = i + endStep;
1111        split = undefined;
1112      } else {
1113        if (ch === ' ' && prev && prev !== ' ' && prev !== '\n' && prev !== '\t') {
1114          // space surrounded by non-space can be replaced with newline + indent
1115          var next = text[i + 1];
1116          if (next && next !== ' ' && next !== '\n' && next !== '\t') split = i;
1117        }
1118  
1119        if (i >= end) {
1120          if (split) {
1121            folds.push(split);
1122            end = split + endStep;
1123            split = undefined;
1124          } else if (mode === FOLD_QUOTED) {
1125            // white-space collected at end may stretch past lineWidth
1126            while (prev === ' ' || prev === '\t') {
1127              prev = ch;
1128              ch = text[i += 1];
1129              overflow = true;
1130            } // Account for newline escape, but don't break preceding escape
1131  
1132  
1133            var j = i > escEnd + 1 ? i - 2 : escStart - 1; // Bail out if lineWidth & minContentWidth are shorter than an escape string
1134  
1135            if (escapedFolds[j]) return text;
1136            folds.push(j);
1137            escapedFolds[j] = true;
1138            end = j + endStep;
1139            split = undefined;
1140          } else {
1141            overflow = true;
1142          }
1143        }
1144      }
1145  
1146      prev = ch;
1147    }
1148  
1149    if (overflow && onOverflow) onOverflow();
1150    if (folds.length === 0) return text;
1151    if (onFold) onFold();
1152    var res = text.slice(0, folds[0]);
1153  
1154    for (var _i = 0; _i < folds.length; ++_i) {
1155      var fold = folds[_i];
1156  
1157      var _end = folds[_i + 1] || text.length;
1158  
1159      if (fold === 0) res = "\n".concat(indent).concat(text.slice(0, _end));else {
1160        if (mode === FOLD_QUOTED && escapedFolds[fold]) res += "".concat(text[fold], "\\");
1161        res += "\n".concat(indent).concat(text.slice(fold + 1, _end));
1162      }
1163    }
1164  
1165    return res;
1166  }
1167  
1168  var getFoldOptions = function getFoldOptions(_ref) {
1169    var indentAtStart = _ref.indentAtStart;
1170    return indentAtStart ? Object.assign({
1171      indentAtStart: indentAtStart
1172    }, strOptions.fold) : strOptions.fold;
1173  }; // Also checks for lines starting with %, as parsing the output as YAML 1.1 will
1174  // presume that's starting a new document.
1175  
1176  
1177  var containsDocumentMarker = function containsDocumentMarker(str) {
1178    return /^(%|---|\.\.\.)/m.test(str);
1179  };
1180  
1181  function lineLengthOverLimit(str, lineWidth, indentLength) {
1182    if (!lineWidth || lineWidth < 0) return false;
1183    var limit = lineWidth - indentLength;
1184    var strLen = str.length;
1185    if (strLen <= limit) return false;
1186  
1187    for (var i = 0, start = 0; i < strLen; ++i) {
1188      if (str[i] === '\n') {
1189        if (i - start > limit) return true;
1190        start = i + 1;
1191        if (strLen - start <= limit) return false;
1192      }
1193    }
1194  
1195    return true;
1196  }
1197  
1198  function doubleQuotedString(value, ctx) {
1199    var implicitKey = ctx.implicitKey;
1200    var _strOptions$doubleQuo = strOptions.doubleQuoted,
1201        jsonEncoding = _strOptions$doubleQuo.jsonEncoding,
1202        minMultiLineLength = _strOptions$doubleQuo.minMultiLineLength;
1203    var json = JSON.stringify(value);
1204    if (jsonEncoding) return json;
1205    var indent = ctx.indent || (containsDocumentMarker(value) ? '  ' : '');
1206    var str = '';
1207    var start = 0;
1208  
1209    for (var i = 0, ch = json[i]; ch; ch = json[++i]) {
1210      if (ch === ' ' && json[i + 1] === '\\' && json[i + 2] === 'n') {
1211        // space before newline needs to be escaped to not be folded
1212        str += json.slice(start, i) + '\\ ';
1213        i += 1;
1214        start = i;
1215        ch = '\\';
1216      }
1217  
1218      if (ch === '\\') switch (json[i + 1]) {
1219        case 'u':
1220          {
1221            str += json.slice(start, i);
1222            var code = json.substr(i + 2, 4);
1223  
1224            switch (code) {
1225              case '0000':
1226                str += '\\0';
1227                break;
1228  
1229              case '0007':
1230                str += '\\a';
1231                break;
1232  
1233              case '000b':
1234                str += '\\v';
1235                break;
1236  
1237              case '001b':
1238                str += '\\e';
1239                break;
1240  
1241              case '0085':
1242                str += '\\N';
1243                break;
1244  
1245              case '00a0':
1246                str += '\\_';
1247                break;
1248  
1249              case '2028':
1250                str += '\\L';
1251                break;
1252  
1253              case '2029':
1254                str += '\\P';
1255                break;
1256  
1257              default:
1258                if (code.substr(0, 2) === '00') str += '\\x' + code.substr(2);else str += json.substr(i, 6);
1259            }
1260  
1261            i += 5;
1262            start = i + 1;
1263          }
1264          break;
1265  
1266        case 'n':
1267          if (implicitKey || json[i + 2] === '"' || json.length < minMultiLineLength) {
1268            i += 1;
1269          } else {
1270            // folding will eat first newline
1271            str += json.slice(start, i) + '\n\n';
1272  
1273            while (json[i + 2] === '\\' && json[i + 3] === 'n' && json[i + 4] !== '"') {
1274              str += '\n';
1275              i += 2;
1276            }
1277  
1278            str += indent; // space after newline needs to be escaped to not be folded
1279  
1280            if (json[i + 2] === ' ') str += '\\';
1281            i += 1;
1282            start = i + 1;
1283          }
1284  
1285          break;
1286  
1287        default:
1288          i += 1;
1289      }
1290    }
1291  
1292    str = start ? str + json.slice(start) : json;
1293    return implicitKey ? str : foldFlowLines(str, indent, FOLD_QUOTED, getFoldOptions(ctx));
1294  }
1295  
1296  function singleQuotedString(value, ctx) {
1297    if (ctx.implicitKey) {
1298      if (/\n/.test(value)) return doubleQuotedString(value, ctx);
1299    } else {
1300      // single quoted string can't have leading or trailing whitespace around newline
1301      if (/[ \t]\n|\n[ \t]/.test(value)) return doubleQuotedString(value, ctx);
1302    }
1303  
1304    var indent = ctx.indent || (containsDocumentMarker(value) ? '  ' : '');
1305    var res = "'" + value.replace(/'/g, "''").replace(/\n+/g, "$&\n".concat(indent)) + "'";
1306    return ctx.implicitKey ? res : foldFlowLines(res, indent, FOLD_FLOW, getFoldOptions(ctx));
1307  }
1308  
1309  function blockString(_ref2, ctx, onComment, onChompKeep) {
1310    var comment = _ref2.comment,
1311        type = _ref2.type,
1312        value = _ref2.value;
1313  
1314    // 1. Block can't end in whitespace unless the last line is non-empty.
1315    // 2. Strings consisting of only whitespace are best rendered explicitly.
1316    if (/\n[\t ]+$/.test(value) || /^\s*$/.test(value)) {
1317      return doubleQuotedString(value, ctx);
1318    }
1319  
1320    var indent = ctx.indent || (ctx.forceBlockIndent || containsDocumentMarker(value) ? '  ' : '');
1321    var indentSize = indent ? '2' : '1'; // root is at -1
1322  
1323    var literal = type === Type.BLOCK_FOLDED ? false : type === Type.BLOCK_LITERAL ? true : !lineLengthOverLimit(value, strOptions.fold.lineWidth, indent.length);
1324    var header = literal ? '|' : '>';
1325    if (!value) return header + '\n';
1326    var wsStart = '';
1327    var wsEnd = '';
1328    value = value.replace(/[\n\t ]*$/, function (ws) {
1329      var n = ws.indexOf('\n');
1330  
1331      if (n === -1) {
1332        header += '-'; // strip
1333      } else if (value === ws || n !== ws.length - 1) {
1334        header += '+'; // keep
1335  
1336        if (onChompKeep) onChompKeep();
1337      }
1338  
1339      wsEnd = ws.replace(/\n$/, '');
1340      return '';
1341    }).replace(/^[\n ]*/, function (ws) {
1342      if (ws.indexOf(' ') !== -1) header += indentSize;
1343      var m = ws.match(/ +$/);
1344  
1345      if (m) {
1346        wsStart = ws.slice(0, -m[0].length);
1347        return m[0];
1348      } else {
1349        wsStart = ws;
1350        return '';
1351      }
1352    });
1353    if (wsEnd) wsEnd = wsEnd.replace(/\n+(?!\n|$)/g, "$&".concat(indent));
1354    if (wsStart) wsStart = wsStart.replace(/\n+/g, "$&".concat(indent));
1355  
1356    if (comment) {
1357      header += ' #' + comment.replace(/ ?[\r\n]+/g, ' ');
1358      if (onComment) onComment();
1359    }
1360  
1361    if (!value) return "".concat(header).concat(indentSize, "\n").concat(indent).concat(wsEnd);
1362  
1363    if (literal) {
1364      value = value.replace(/\n+/g, "$&".concat(indent));
1365      return "".concat(header, "\n").concat(indent).concat(wsStart).concat(value).concat(wsEnd);
1366    }
1367  
1368    value = value.replace(/\n+/g, '\n$&').replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, '$1$2') // more-indented lines aren't folded
1369    //         ^ ind.line  ^ empty     ^ capture next empty lines only at end of indent
1370    .replace(/\n+/g, "$&".concat(indent));
1371    var body = foldFlowLines("".concat(wsStart).concat(value).concat(wsEnd), indent, FOLD_BLOCK, strOptions.fold);
1372    return "".concat(header, "\n").concat(indent).concat(body);
1373  }
1374  
1375  function plainString(item, ctx, onComment, onChompKeep) {
1376    var comment = item.comment,
1377        type = item.type,
1378        value = item.value;
1379    var actualString = ctx.actualString,
1380        implicitKey = ctx.implicitKey,
1381        indent = ctx.indent,
1382        inFlow = ctx.inFlow;
1383  
1384    if (implicitKey && /[\n[\]{},]/.test(value) || inFlow && /[[\]{},]/.test(value)) {
1385      return doubleQuotedString(value, ctx);
1386    }
1387  
1388    if (!value || /^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(value)) {
1389      // not allowed:
1390      // - empty string, '-' or '?'
1391      // - start with an indicator character (except [?:-]) or /[?-] /
1392      // - '\n ', ': ' or ' \n' anywhere
1393      // - '#' not preceded by a non-space char
1394      // - end with ' ' or ':'
1395      return implicitKey || inFlow || value.indexOf('\n') === -1 ? value.indexOf('"') !== -1 && value.indexOf("'") === -1 ? singleQuotedString(value, ctx) : doubleQuotedString(value, ctx) : blockString(item, ctx, onComment, onChompKeep);
1396    }
1397  
1398    if (!implicitKey && !inFlow && type !== Type.PLAIN && value.indexOf('\n') !== -1) {
1399      // Where allowed & type not set explicitly, prefer block style for multiline strings
1400      return blockString(item, ctx, onComment, onChompKeep);
1401    }
1402  
1403    if (indent === '' && containsDocumentMarker(value)) {
1404      ctx.forceBlockIndent = true;
1405      return blockString(item, ctx, onComment, onChompKeep);
1406    }
1407  
1408    var str = value.replace(/\n+/g, "$&\n".concat(indent)); // Verify that output will be parsed as a string, as e.g. plain numbers and
1409    // booleans get parsed with those types in v1.2 (e.g. '42', 'true' & '0.9e-3'),
1410    // and others in v1.1.
1411  
1412    if (actualString) {
1413      var tags = ctx.doc.schema.tags;
1414      var resolved = resolveScalar(str, tags, tags.scalarFallback).value;
1415      if (typeof resolved !== 'string') return doubleQuotedString(value, ctx);
1416    }
1417  
1418    var body = implicitKey ? str : foldFlowLines(str, indent, FOLD_FLOW, getFoldOptions(ctx));
1419  
1420    if (comment && !inFlow && (body.indexOf('\n') !== -1 || comment.indexOf('\n') !== -1)) {
1421      if (onComment) onComment();
1422      return addCommentBefore(body, indent, comment);
1423    }
1424  
1425    return body;
1426  }
1427  
1428  function stringifyString(item, ctx, onComment, onChompKeep) {
1429    var defaultType = strOptions.defaultType;
1430    var implicitKey = ctx.implicitKey,
1431        inFlow = ctx.inFlow;
1432    var _item = item,
1433        type = _item.type,
1434        value = _item.value;
1435  
1436    if (typeof value !== 'string') {
1437      value = String(value);
1438      item = Object.assign({}, item, {
1439        value: value
1440      });
1441    }
1442  
1443    var _stringify = function _stringify(_type) {
1444      switch (_type) {
1445        case Type.BLOCK_FOLDED:
1446        case Type.BLOCK_LITERAL:
1447          return blockString(item, ctx, onComment, onChompKeep);
1448  
1449        case Type.QUOTE_DOUBLE:
1450          return doubleQuotedString(value, ctx);
1451  
1452        case Type.QUOTE_SINGLE:
1453          return singleQuotedString(value, ctx);
1454  
1455        case Type.PLAIN:
1456          return plainString(item, ctx, onComment, onChompKeep);
1457  
1458        default:
1459          return null;
1460      }
1461    };
1462  
1463    if (type !== Type.QUOTE_DOUBLE && /[\x00-\x08\x0b-\x1f\x7f-\x9f]/.test(value)) {
1464      // force double quotes on control characters
1465      type = Type.QUOTE_DOUBLE;
1466    } else if ((implicitKey || inFlow) && (type === Type.BLOCK_FOLDED || type === Type.BLOCK_LITERAL)) {
1467      // should not happen; blocks are not valid inside flow containers
1468      type = Type.QUOTE_DOUBLE;
1469    }
1470  
1471    var res = _stringify(type);
1472  
1473    if (res === null) {
1474      res = _stringify(defaultType);
1475      if (res === null) throw new Error("Unsupported default string type ".concat(defaultType));
1476    }
1477  
1478    return res;
1479  }
1480  
1481  function stringifyNumber(_ref) {
1482    var format = _ref.format,
1483        minFractionDigits = _ref.minFractionDigits,
1484        tag = _ref.tag,
1485        value = _ref.value;
1486    if (typeof value === 'bigint') return String(value);
1487    if (!isFinite(value)) return isNaN(value) ? '.nan' : value < 0 ? '-.inf' : '.inf';
1488    var n = JSON.stringify(value);
1489  
1490    if (!format && minFractionDigits && (!tag || tag === 'tag:yaml.org,2002:float') && /^\d/.test(n)) {
1491      var i = n.indexOf('.');
1492  
1493      if (i < 0) {
1494        i = n.length;
1495        n += '.';
1496      }
1497  
1498      var d = minFractionDigits - (n.length - i - 1);
1499  
1500      while (d-- > 0) {
1501        n += '0';
1502      }
1503    }
1504  
1505    return n;
1506  }
1507  
1508  function checkFlowCollectionEnd(errors, cst) {
1509    var char, name;
1510  
1511    switch (cst.type) {
1512      case Type.FLOW_MAP:
1513        char = '}';
1514        name = 'flow map';
1515        break;
1516  
1517      case Type.FLOW_SEQ:
1518        char = ']';
1519        name = 'flow sequence';
1520        break;
1521  
1522      default:
1523        errors.push(new YAMLSemanticError(cst, 'Not a flow collection!?'));
1524        return;
1525    }
1526  
1527    var lastItem;
1528  
1529    for (var i = cst.items.length - 1; i >= 0; --i) {
1530      var item = cst.items[i];
1531  
1532      if (!item || item.type !== Type.COMMENT) {
1533        lastItem = item;
1534        break;
1535      }
1536    }
1537  
1538    if (lastItem && lastItem.char !== char) {
1539      var msg = "Expected ".concat(name, " to end with ").concat(char);
1540      var err;
1541  
1542      if (typeof lastItem.offset === 'number') {
1543        err = new YAMLSemanticError(cst, msg);
1544        err.offset = lastItem.offset + 1;
1545      } else {
1546        err = new YAMLSemanticError(lastItem, msg);
1547        if (lastItem.range && lastItem.range.end) err.offset = lastItem.range.end - lastItem.range.start;
1548      }
1549  
1550      errors.push(err);
1551    }
1552  }
1553  function checkFlowCommentSpace(errors, comment) {
1554    var prev = comment.context.src[comment.range.start - 1];
1555  
1556    if (prev !== '\n' && prev !== '\t' && prev !== ' ') {
1557      var msg = 'Comments must be separated from other tokens by white space characters';
1558      errors.push(new YAMLSemanticError(comment, msg));
1559    }
1560  }
1561  function getLongKeyError(source, key) {
1562    var sk = String(key);
1563    var k = sk.substr(0, 8) + '...' + sk.substr(-8);
1564    return new YAMLSemanticError(source, "The \"".concat(k, "\" key is too long"));
1565  }
1566  function resolveComments(collection, comments) {
1567    var _iterator = _createForOfIteratorHelper(comments),
1568        _step;
1569  
1570    try {
1571      for (_iterator.s(); !(_step = _iterator.n()).done;) {
1572        var _step$value = _step.value,
1573            afterKey = _step$value.afterKey,
1574            before = _step$value.before,
1575            comment = _step$value.comment;
1576        var item = collection.items[before];
1577  
1578        if (!item) {
1579          if (comment !== undefined) {
1580            if (collection.comment) collection.comment += '\n' + comment;else collection.comment = comment;
1581          }
1582        } else {
1583          if (afterKey && item.value) item = item.value;
1584  
1585          if (comment === undefined) {
1586            if (afterKey || !item.commentBefore) item.spaceBefore = true;
1587          } else {
1588            if (item.commentBefore) item.commentBefore += '\n' + comment;else item.commentBefore = comment;
1589          }
1590        }
1591      }
1592    } catch (err) {
1593      _iterator.e(err);
1594    } finally {
1595      _iterator.f();
1596    }
1597  }
1598  
1599  // on error, will return { str: string, errors: Error[] }
1600  function resolveString(doc, node) {
1601    var res = node.strValue;
1602    if (!res) return '';
1603    if (typeof res === 'string') return res;
1604    res.errors.forEach(function (error) {
1605      if (!error.source) error.source = node;
1606      doc.errors.push(error);
1607    });
1608    return res.str;
1609  }
1610  
1611  function resolveTagHandle(doc, node) {
1612    var _node$tag = node.tag,
1613        handle = _node$tag.handle,
1614        suffix = _node$tag.suffix;
1615    var prefix = doc.tagPrefixes.find(function (p) {
1616      return p.handle === handle;
1617    });
1618  
1619    if (!prefix) {
1620      var dtp = doc.getDefaults().tagPrefixes;
1621      if (dtp) prefix = dtp.find(function (p) {
1622        return p.handle === handle;
1623      });
1624      if (!prefix) throw new YAMLSemanticError(node, "The ".concat(handle, " tag handle is non-default and was not declared."));
1625    }
1626  
1627    if (!suffix) throw new YAMLSemanticError(node, "The ".concat(handle, " tag has no suffix."));
1628  
1629    if (handle === '!' && (doc.version || doc.options.version) === '1.0') {
1630      if (suffix[0] === '^') {
1631        doc.warnings.push(new YAMLWarning(node, 'YAML 1.0 ^ tag expansion is not supported'));
1632        return suffix;
1633      }
1634  
1635      if (/[:/]/.test(suffix)) {
1636        // word/foo -> tag:word.yaml.org,2002:foo
1637        var vocab = suffix.match(/^([a-z0-9-]+)\/(.*)/i);
1638        return vocab ? "tag:".concat(vocab[1], ".yaml.org,2002:").concat(vocab[2]) : "tag:".concat(suffix);
1639      }
1640    }
1641  
1642    return prefix.prefix + decodeURIComponent(suffix);
1643  }
1644  
1645  function resolveTagName(doc, node) {
1646    var tag = node.tag,
1647        type = node.type;
1648    var nonSpecific = false;
1649  
1650    if (tag) {
1651      var handle = tag.handle,
1652          suffix = tag.suffix,
1653          verbatim = tag.verbatim;
1654  
1655      if (verbatim) {
1656        if (verbatim !== '!' && verbatim !== '!!') return verbatim;
1657        var msg = "Verbatim tags aren't resolved, so ".concat(verbatim, " is invalid.");
1658        doc.errors.push(new YAMLSemanticError(node, msg));
1659      } else if (handle === '!' && !suffix) {
1660        nonSpecific = true;
1661      } else {
1662        try {
1663          return resolveTagHandle(doc, node);
1664        } catch (error) {
1665          doc.errors.push(error);
1666        }
1667      }
1668    }
1669  
1670    switch (type) {
1671      case Type.BLOCK_FOLDED:
1672      case Type.BLOCK_LITERAL:
1673      case Type.QUOTE_DOUBLE:
1674      case Type.QUOTE_SINGLE:
1675        return defaultTags.STR;
1676  
1677      case Type.FLOW_MAP:
1678      case Type.MAP:
1679        return defaultTags.MAP;
1680  
1681      case Type.FLOW_SEQ:
1682      case Type.SEQ:
1683        return defaultTags.SEQ;
1684  
1685      case Type.PLAIN:
1686        return nonSpecific ? defaultTags.STR : null;
1687  
1688      default:
1689        return null;
1690    }
1691  }
1692  
1693  function resolveByTagName(doc, node, tagName) {
1694    var tags = doc.schema.tags;
1695    var matchWithTest = [];
1696  
1697    var _iterator = _createForOfIteratorHelper(tags),
1698        _step;
1699  
1700    try {
1701      for (_iterator.s(); !(_step = _iterator.n()).done;) {
1702        var tag = _step.value;
1703  
1704        if (tag.tag === tagName) {
1705          if (tag.test) matchWithTest.push(tag);else {
1706            var res = tag.resolve(doc, node);
1707            return res instanceof Collection ? res : new Scalar(res);
1708          }
1709        }
1710      }
1711    } catch (err) {
1712      _iterator.e(err);
1713    } finally {
1714      _iterator.f();
1715    }
1716  
1717    var str = resolveString(doc, node);
1718    if (typeof str === 'string' && matchWithTest.length > 0) return resolveScalar(str, matchWithTest, tags.scalarFallback);
1719    return null;
1720  }
1721  
1722  function getFallbackTagName(_ref) {
1723    var type = _ref.type;
1724  
1725    switch (type) {
1726      case Type.FLOW_MAP:
1727      case Type.MAP:
1728        return defaultTags.MAP;
1729  
1730      case Type.FLOW_SEQ:
1731      case Type.SEQ:
1732        return defaultTags.SEQ;
1733  
1734      default:
1735        return defaultTags.STR;
1736    }
1737  }
1738  
1739  function resolveTag(doc, node, tagName) {
1740    try {
1741      var res = resolveByTagName(doc, node, tagName);
1742  
1743      if (res) {
1744        if (tagName && node.tag) res.tag = tagName;
1745        return res;
1746      }
1747    } catch (error) {
1748      /* istanbul ignore if */
1749      if (!error.source) error.source = node;
1750      doc.errors.push(error);
1751      return null;
1752    }
1753  
1754    try {
1755      var fallback = getFallbackTagName(node);
1756      if (!fallback) throw new Error("The tag ".concat(tagName, " is unavailable"));
1757      var msg = "The tag ".concat(tagName, " is unavailable, falling back to ").concat(fallback);
1758      doc.warnings.push(new YAMLWarning(node, msg));
1759  
1760      var _res = resolveByTagName(doc, node, fallback);
1761  
1762      _res.tag = tagName;
1763      return _res;
1764    } catch (error) {
1765      var refError = new YAMLReferenceError(node, error.message);
1766      refError.stack = error.stack;
1767      doc.errors.push(refError);
1768      return null;
1769    }
1770  }
1771  
1772  var isCollectionItem = function isCollectionItem(node) {
1773    if (!node) return false;
1774    var type = node.type;
1775    return type === Type.MAP_KEY || type === Type.MAP_VALUE || type === Type.SEQ_ITEM;
1776  };
1777  
1778  function resolveNodeProps(errors, node) {
1779    var comments = {
1780      before: [],
1781      after: []
1782    };
1783    var hasAnchor = false;
1784    var hasTag = false;
1785    var props = isCollectionItem(node.context.parent) ? node.context.parent.props.concat(node.props) : node.props;
1786  
1787    var _iterator = _createForOfIteratorHelper(props),
1788        _step;
1789  
1790    try {
1791      for (_iterator.s(); !(_step = _iterator.n()).done;) {
1792        var _step$value = _step.value,
1793            start = _step$value.start,
1794            end = _step$value.end;
1795  
1796        switch (node.context.src[start]) {
1797          case Char.COMMENT:
1798            {
1799              if (!node.commentHasRequiredWhitespace(start)) {
1800                var msg = 'Comments must be separated from other tokens by white space characters';
1801                errors.push(new YAMLSemanticError(node, msg));
1802              }
1803  
1804              var header = node.header,
1805                  valueRange = node.valueRange;
1806              var cc = valueRange && (start > valueRange.start || header && start > header.start) ? comments.after : comments.before;
1807              cc.push(node.context.src.slice(start + 1, end));
1808              break;
1809            }
1810          // Actual anchor & tag resolution is handled by schema, here we just complain
1811  
1812          case Char.ANCHOR:
1813            if (hasAnchor) {
1814              var _msg = 'A node can have at most one anchor';
1815              errors.push(new YAMLSemanticError(node, _msg));
1816            }
1817  
1818            hasAnchor = true;
1819            break;
1820  
1821          case Char.TAG:
1822            if (hasTag) {
1823              var _msg2 = 'A node can have at most one tag';
1824              errors.push(new YAMLSemanticError(node, _msg2));
1825            }
1826  
1827            hasTag = true;
1828            break;
1829        }
1830      }
1831    } catch (err) {
1832      _iterator.e(err);
1833    } finally {
1834      _iterator.f();
1835    }
1836  
1837    return {
1838      comments: comments,
1839      hasAnchor: hasAnchor,
1840      hasTag: hasTag
1841    };
1842  }
1843  
1844  function resolveNodeValue(doc, node) {
1845    var anchors = doc.anchors,
1846        errors = doc.errors,
1847        schema = doc.schema;
1848  
1849    if (node.type === Type.ALIAS) {
1850      var name = node.rawValue;
1851      var src = anchors.getNode(name);
1852  
1853      if (!src) {
1854        var msg = "Aliased anchor not found: ".concat(name);
1855        errors.push(new YAMLReferenceError(node, msg));
1856        return null;
1857      } // Lazy resolution for circular references
1858  
1859  
1860      var res = new Alias(src);
1861  
1862      anchors._cstAliases.push(res);
1863  
1864      return res;
1865    }
1866  
1867    var tagName = resolveTagName(doc, node);
1868    if (tagName) return resolveTag(doc, node, tagName);
1869  
1870    if (node.type !== Type.PLAIN) {
1871      var _msg3 = "Failed to resolve ".concat(node.type, " node here");
1872  
1873      errors.push(new YAMLSyntaxError(node, _msg3));
1874      return null;
1875    }
1876  
1877    try {
1878      var str = resolveString(doc, node);
1879      return resolveScalar(str, schema.tags, schema.tags.scalarFallback);
1880    } catch (error) {
1881      if (!error.source) error.source = node;
1882      errors.push(error);
1883      return null;
1884    }
1885  } // sets node.resolved on success
1886  
1887  
1888  function resolveNode(doc, node) {
1889    if (!node) return null;
1890    if (node.error) doc.errors.push(node.error);
1891  
1892    var _resolveNodeProps = resolveNodeProps(doc.errors, node),
1893        comments = _resolveNodeProps.comments,
1894        hasAnchor = _resolveNodeProps.hasAnchor,
1895        hasTag = _resolveNodeProps.hasTag;
1896  
1897    if (hasAnchor) {
1898      var anchors = doc.anchors;
1899      var name = node.anchor;
1900      var prev = anchors.getNode(name); // At this point, aliases for any preceding node with the same anchor
1901      // name have already been resolved, so it may safely be renamed.
1902  
1903      if (prev) anchors.map[anchors.newName(name)] = prev; // During parsing, we need to store the CST node in anchors.map as
1904      // anchors need to be available during resolution to allow for
1905      // circular references.
1906  
1907      anchors.map[name] = node;
1908    }
1909  
1910    if (node.type === Type.ALIAS && (hasAnchor || hasTag)) {
1911      var msg = 'An alias node must not specify any properties';
1912      doc.errors.push(new YAMLSemanticError(node, msg));
1913    }
1914  
1915    var res = resolveNodeValue(doc, node);
1916  
1917    if (res) {
1918      res.range = [node.range.start, node.range.end];
1919      if (doc.options.keepCstNodes) res.cstNode = node;
1920      if (doc.options.keepNodeTypes) res.type = node.type;
1921      var cb = comments.before.join('\n');
1922  
1923      if (cb) {
1924        res.commentBefore = res.commentBefore ? "".concat(res.commentBefore, "\n").concat(cb) : cb;
1925      }
1926  
1927      var ca = comments.after.join('\n');
1928      if (ca) res.comment = res.comment ? "".concat(res.comment, "\n").concat(ca) : ca;
1929    }
1930  
1931    return node.resolved = res;
1932  }
1933  
1934  function resolveMap(doc, cst) {
1935    if (cst.type !== Type.MAP && cst.type !== Type.FLOW_MAP) {
1936      var msg = "A ".concat(cst.type, " node cannot be resolved as a mapping");
1937      doc.errors.push(new YAMLSyntaxError(cst, msg));
1938      return null;
1939    }
1940  
1941    var _ref = cst.type === Type.FLOW_MAP ? resolveFlowMapItems(doc, cst) : resolveBlockMapItems(doc, cst),
1942        comments = _ref.comments,
1943        items = _ref.items;
1944  
1945    var map = new YAMLMap();
1946    map.items = items;
1947    resolveComments(map, comments);
1948    var hasCollectionKey = false;
1949  
1950    for (var i = 0; i < items.length; ++i) {
1951      var iKey = items[i].key;
1952      if (iKey instanceof Collection) hasCollectionKey = true;
1953  
1954      if (doc.schema.merge && iKey && iKey.value === MERGE_KEY) {
1955        items[i] = new Merge(items[i]);
1956        var sources = items[i].value.items;
1957        var error = null;
1958        sources.some(function (node) {
1959          if (node instanceof Alias) {
1960            // During parsing, alias sources are CST nodes; to account for
1961            // circular references their resolved values can't be used here.
1962            var type = node.source.type;
1963            if (type === Type.MAP || type === Type.FLOW_MAP) return false;
1964            return error = 'Merge nodes aliases can only point to maps';
1965          }
1966  
1967          return error = 'Merge nodes can only have Alias nodes as values';
1968        });
1969        if (error) doc.errors.push(new YAMLSemanticError(cst, error));
1970      } else {
1971        for (var j = i + 1; j < items.length; ++j) {
1972          var jKey = items[j].key;
1973  
1974          if (iKey === jKey || iKey && jKey && Object.prototype.hasOwnProperty.call(iKey, 'value') && iKey.value === jKey.value) {
1975            var _msg = "Map keys must be unique; \"".concat(iKey, "\" is repeated");
1976  
1977            doc.errors.push(new YAMLSemanticError(cst, _msg));
1978            break;
1979          }
1980        }
1981      }
1982    }
1983  
1984    if (hasCollectionKey && !doc.options.mapAsMap) {
1985      var warn = 'Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.';
1986      doc.warnings.push(new YAMLWarning(cst, warn));
1987    }
1988  
1989    cst.resolved = map;
1990    return map;
1991  }
1992  
1993  var valueHasPairComment = function valueHasPairComment(_ref2) {
1994    var _ref2$context = _ref2.context,
1995        lineStart = _ref2$context.lineStart,
1996        node = _ref2$context.node,
1997        src = _ref2$context.src,
1998        props = _ref2.props;
1999    if (props.length === 0) return false;
2000    var start = props[0].start;
2001    if (node && start > node.valueRange.start) return false;
2002    if (src[start] !== Char.COMMENT) return false;
2003  
2004    for (var i = lineStart; i < start; ++i) {
2005      if (src[i] === '\n') return false;
2006    }
2007  
2008    return true;
2009  };
2010  
2011  function resolvePairComment(item, pair) {
2012    if (!valueHasPairComment(item)) return;
2013    var comment = item.getPropValue(0, Char.COMMENT, true);
2014    var found = false;
2015    var cb = pair.value.commentBefore;
2016  
2017    if (cb && cb.startsWith(comment)) {
2018      pair.value.commentBefore = cb.substr(comment.length + 1);
2019      found = true;
2020    } else {
2021      var cc = pair.value.comment;
2022  
2023      if (!item.node && cc && cc.startsWith(comment)) {
2024        pair.value.comment = cc.substr(comment.length + 1);
2025        found = true;
2026      }
2027    }
2028  
2029    if (found) pair.comment = comment;
2030  }
2031  
2032  function resolveBlockMapItems(doc, cst) {
2033    var comments = [];
2034    var items = [];
2035    var key = undefined;
2036    var keyStart = null;
2037  
2038    for (var i = 0; i < cst.items.length; ++i) {
2039      var item = cst.items[i];
2040  
2041      switch (item.type) {
2042        case Type.BLANK_LINE:
2043          comments.push({
2044            afterKey: !!key,
2045            before: items.length
2046          });
2047          break;
2048  
2049        case Type.COMMENT:
2050          comments.push({
2051            afterKey: !!key,
2052            before: items.length,
2053            comment: item.comment
2054          });
2055          break;
2056  
2057        case Type.MAP_KEY:
2058          if (key !== undefined) items.push(new Pair(key));
2059          if (item.error) doc.errors.push(item.error);
2060          key = resolveNode(doc, item.node);
2061          keyStart = null;
2062          break;
2063  
2064        case Type.MAP_VALUE:
2065          {
2066            if (key === undefined) key = null;
2067            if (item.error) doc.errors.push(item.error);
2068  
2069            if (!item.context.atLineStart && item.node && item.node.type === Type.MAP && !item.node.context.atLineStart) {
2070              var msg = 'Nested mappings are not allowed in compact mappings';
2071              doc.errors.push(new YAMLSemanticError(item.node, msg));
2072            }
2073  
2074            var valueNode = item.node;
2075  
2076            if (!valueNode && item.props.length > 0) {
2077              // Comments on an empty mapping value need to be preserved, so we
2078              // need to construct a minimal empty node here to use instead of the
2079              // missing `item.node`. -- eemeli/yaml#19
2080              valueNode = new PlainValue(Type.PLAIN, []);
2081              valueNode.context = {
2082                parent: item,
2083                src: item.context.src
2084              };
2085              var pos = item.range.start + 1;
2086              valueNode.range = {
2087                start: pos,
2088                end: pos
2089              };
2090              valueNode.valueRange = {
2091                start: pos,
2092                end: pos
2093              };
2094  
2095              if (typeof item.range.origStart === 'number') {
2096                var origPos = item.range.origStart + 1;
2097                valueNode.range.origStart = valueNode.range.origEnd = origPos;
2098                valueNode.valueRange.origStart = valueNode.valueRange.origEnd = origPos;
2099              }
2100            }
2101  
2102            var pair = new Pair(key, resolveNode(doc, valueNode));
2103            resolvePairComment(item, pair);
2104            items.push(pair);
2105  
2106            if (key && typeof keyStart === 'number') {
2107              if (item.range.start > keyStart + 1024) doc.errors.push(getLongKeyError(cst, key));
2108            }
2109  
2110            key = undefined;
2111            keyStart = null;
2112          }
2113          break;
2114  
2115        default:
2116          if (key !== undefined) items.push(new Pair(key));
2117          key = resolveNode(doc, item);
2118          keyStart = item.range.start;
2119          if (item.error) doc.errors.push(item.error);
2120  
2121          next: for (var j = i + 1;; ++j) {
2122            var nextItem = cst.items[j];
2123  
2124            switch (nextItem && nextItem.type) {
2125              case Type.BLANK_LINE:
2126              case Type.COMMENT:
2127                continue next;
2128  
2129              case Type.MAP_VALUE:
2130                break next;
2131  
2132              default:
2133                {
2134                  var _msg2 = 'Implicit map keys need to be followed by map values';
2135                  doc.errors.push(new YAMLSemanticError(item, _msg2));
2136                  break next;
2137                }
2138            }
2139          }
2140  
2141          if (item.valueRangeContainsNewline) {
2142            var _msg3 = 'Implicit map keys need to be on a single line';
2143            doc.errors.push(new YAMLSemanticError(item, _msg3));
2144          }
2145  
2146      }
2147    }
2148  
2149    if (key !== undefined) items.push(new Pair(key));
2150    return {
2151      comments: comments,
2152      items: items
2153    };
2154  }
2155  
2156  function resolveFlowMapItems(doc, cst) {
2157    var comments = [];
2158    var items = [];
2159    var key = undefined;
2160    var explicitKey = false;
2161    var next = '{';
2162  
2163    for (var i = 0; i < cst.items.length; ++i) {
2164      var item = cst.items[i];
2165  
2166      if (typeof item.char === 'string') {
2167        var char = item.char,
2168            offset = item.offset;
2169  
2170        if (char === '?' && key === undefined && !explicitKey) {
2171          explicitKey = true;
2172          next = ':';
2173          continue;
2174        }
2175  
2176        if (char === ':') {
2177          if (key === undefined) key = null;
2178  
2179          if (next === ':') {
2180            next = ',';
2181            continue;
2182          }
2183        } else {
2184          if (explicitKey) {
2185            if (key === undefined && char !== ',') key = null;
2186            explicitKey = false;
2187          }
2188  
2189          if (key !== undefined) {
2190            items.push(new Pair(key));
2191            key = undefined;
2192  
2193            if (char === ',') {
2194              next = ':';
2195              continue;
2196            }
2197          }
2198        }
2199  
2200        if (char === '}') {
2201          if (i === cst.items.length - 1) continue;
2202        } else if (char === next) {
2203          next = ':';
2204          continue;
2205        }
2206  
2207        var msg = "Flow map contains an unexpected ".concat(char);
2208        var err = new YAMLSyntaxError(cst, msg);
2209        err.offset = offset;
2210        doc.errors.push(err);
2211      } else if (item.type === Type.BLANK_LINE) {
2212        comments.push({
2213          afterKey: !!key,
2214          before: items.length
2215        });
2216      } else if (item.type === Type.COMMENT) {
2217        checkFlowCommentSpace(doc.errors, item);
2218        comments.push({
2219          afterKey: !!key,
2220          before: items.length,
2221          comment: item.comment
2222        });
2223      } else if (key === undefined) {
2224        if (next === ',') doc.errors.push(new YAMLSemanticError(item, 'Separator , missing in flow map'));
2225        key = resolveNode(doc, item);
2226      } else {
2227        if (next !== ',') doc.errors.push(new YAMLSemanticError(item, 'Indicator : missing in flow map entry'));
2228        items.push(new Pair(key, resolveNode(doc, item)));
2229        key = undefined;
2230        explicitKey = false;
2231      }
2232    }
2233  
2234    checkFlowCollectionEnd(doc.errors, cst);
2235    if (key !== undefined) items.push(new Pair(key));
2236    return {
2237      comments: comments,
2238      items: items
2239    };
2240  }
2241  
2242  function resolveSeq(doc, cst) {
2243    if (cst.type !== Type.SEQ && cst.type !== Type.FLOW_SEQ) {
2244      var msg = "A ".concat(cst.type, " node cannot be resolved as a sequence");
2245      doc.errors.push(new YAMLSyntaxError(cst, msg));
2246      return null;
2247    }
2248  
2249    var _ref = cst.type === Type.FLOW_SEQ ? resolveFlowSeqItems(doc, cst) : resolveBlockSeqItems(doc, cst),
2250        comments = _ref.comments,
2251        items = _ref.items;
2252  
2253    var seq = new YAMLSeq();
2254    seq.items = items;
2255    resolveComments(seq, comments);
2256  
2257    if (!doc.options.mapAsMap && items.some(function (it) {
2258      return it instanceof Pair && it.key instanceof Collection;
2259    })) {
2260      var warn = 'Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.';
2261      doc.warnings.push(new YAMLWarning(cst, warn));
2262    }
2263  
2264    cst.resolved = seq;
2265    return seq;
2266  }
2267  
2268  function resolveBlockSeqItems(doc, cst) {
2269    var comments = [];
2270    var items = [];
2271  
2272    for (var i = 0; i < cst.items.length; ++i) {
2273      var item = cst.items[i];
2274  
2275      switch (item.type) {
2276        case Type.BLANK_LINE:
2277          comments.push({
2278            before: items.length
2279          });
2280          break;
2281  
2282        case Type.COMMENT:
2283          comments.push({
2284            comment: item.comment,
2285            before: items.length
2286          });
2287          break;
2288  
2289        case Type.SEQ_ITEM:
2290          if (item.error) doc.errors.push(item.error);
2291          items.push(resolveNode(doc, item.node));
2292  
2293          if (item.hasProps) {
2294            var msg = 'Sequence items cannot have tags or anchors before the - indicator';
2295            doc.errors.push(new YAMLSemanticError(item, msg));
2296          }
2297  
2298          break;
2299  
2300        default:
2301          if (item.error) doc.errors.push(item.error);
2302          doc.errors.push(new YAMLSyntaxError(item, "Unexpected ".concat(item.type, " node in sequence")));
2303      }
2304    }
2305  
2306    return {
2307      comments: comments,
2308      items: items
2309    };
2310  }
2311  
2312  function resolveFlowSeqItems(doc, cst) {
2313    var comments = [];
2314    var items = [];
2315    var explicitKey = false;
2316    var key = undefined;
2317    var keyStart = null;
2318    var next = '[';
2319    var prevItem = null;
2320  
2321    for (var i = 0; i < cst.items.length; ++i) {
2322      var item = cst.items[i];
2323  
2324      if (typeof item.char === 'string') {
2325        var char = item.char,
2326            offset = item.offset;
2327  
2328        if (char !== ':' && (explicitKey || key !== undefined)) {
2329          if (explicitKey && key === undefined) key = next ? items.pop() : null;
2330          items.push(new Pair(key));
2331          explicitKey = false;
2332          key = undefined;
2333          keyStart = null;
2334        }
2335  
2336        if (char === next) {
2337          next = null;
2338        } else if (!next && char === '?') {
2339          explicitKey = true;
2340        } else if (next !== '[' && char === ':' && key === undefined) {
2341          if (next === ',') {
2342            key = items.pop();
2343  
2344            if (key instanceof Pair) {
2345              var msg = 'Chaining flow sequence pairs is invalid';
2346              var err = new YAMLSemanticError(cst, msg);
2347              err.offset = offset;
2348              doc.errors.push(err);
2349            }
2350  
2351            if (!explicitKey && typeof keyStart === 'number') {
2352              var keyEnd = item.range ? item.range.start : item.offset;
2353              if (keyEnd > keyStart + 1024) doc.errors.push(getLongKeyError(cst, key));
2354              var src = prevItem.context.src;
2355  
2356              for (var _i = keyStart; _i < keyEnd; ++_i) {
2357                if (src[_i] === '\n') {
2358                  var _msg = 'Implicit keys of flow sequence pairs need to be on a single line';
2359                  doc.errors.push(new YAMLSemanticError(prevItem, _msg));
2360                  break;
2361                }
2362              }
2363            }
2364          } else {
2365            key = null;
2366          }
2367  
2368          keyStart = null;
2369          explicitKey = false;
2370          next = null;
2371        } else if (next === '[' || char !== ']' || i < cst.items.length - 1) {
2372          var _msg2 = "Flow sequence contains an unexpected ".concat(char);
2373  
2374          var _err = new YAMLSyntaxError(cst, _msg2);
2375  
2376          _err.offset = offset;
2377          doc.errors.push(_err);
2378        }
2379      } else if (item.type === Type.BLANK_LINE) {
2380        comments.push({
2381          before: items.length
2382        });
2383      } else if (item.type === Type.COMMENT) {
2384        checkFlowCommentSpace(doc.errors, item);
2385        comments.push({
2386          comment: item.comment,
2387          before: items.length
2388        });
2389      } else {
2390        if (next) {
2391          var _msg3 = "Expected a ".concat(next, " in flow sequence");
2392  
2393          doc.errors.push(new YAMLSemanticError(item, _msg3));
2394        }
2395  
2396        var value = resolveNode(doc, item);
2397  
2398        if (key === undefined) {
2399          items.push(value);
2400          prevItem = item;
2401        } else {
2402          items.push(new Pair(key, value));
2403          key = undefined;
2404        }
2405  
2406        keyStart = item.range.start;
2407        next = ',';
2408      }
2409    }
2410  
2411    checkFlowCollectionEnd(doc.errors, cst);
2412    if (key !== undefined) items.push(new Pair(key));
2413    return {
2414      comments: comments,
2415      items: items
2416    };
2417  }
2418  
2419  export { Alias as A, Collection as C, Merge as M, Node as N, Pair as P, Scalar as S, YAMLSeq as Y, boolOptions as a, binaryOptions as b, stringifyString as c, YAMLMap as d, isEmptyPath as e, addComment as f, resolveMap as g, resolveSeq as h, intOptions as i, resolveString as j, stringifyNumber as k, findPair as l, nullOptions as n, resolveNode as r, strOptions as s, toJSON as t };