From 7b2f0761a98e1586302b81018fbe19510c55743c Mon Sep 17 00:00:00 2001 From: Dawid Dziurla Date: Wed, 9 Dec 2020 11:56:40 +0100 Subject: [PATCH] package: add yaml --- node_modules/.package-lock.json | 33 + node_modules/yaml/LICENSE | 13 + node_modules/yaml/README.md | 127 + .../yaml/browser/dist/PlainValue-ff5147c6.js | 1277 +++++++++ .../yaml/browser/dist/Schema-2bf2c74e.js | 679 +++++ node_modules/yaml/browser/dist/index.js | 1004 +++++++ .../yaml/browser/dist/legacy-exports.js | 3 + node_modules/yaml/browser/dist/parse-cst.js | 1904 +++++++++++++ .../yaml/browser/dist/resolveSeq-04825f30.js | 2373 +++++++++++++++++ node_modules/yaml/browser/dist/types.js | 4 + node_modules/yaml/browser/dist/util.js | 2 + .../yaml/browser/dist/warnings-0e4b70d3.js | 499 ++++ node_modules/yaml/browser/index.js | 1 + node_modules/yaml/browser/map.js | 2 + node_modules/yaml/browser/pair.js | 2 + node_modules/yaml/browser/parse-cst.js | 1 + node_modules/yaml/browser/scalar.js | 2 + node_modules/yaml/browser/schema.js | 9 + node_modules/yaml/browser/seq.js | 2 + node_modules/yaml/browser/types.js | 1 + node_modules/yaml/browser/types/binary.js | 8 + node_modules/yaml/browser/types/omap.js | 3 + node_modules/yaml/browser/types/pairs.js | 3 + node_modules/yaml/browser/types/set.js | 3 + node_modules/yaml/browser/types/timestamp.js | 10 + node_modules/yaml/browser/util.js | 1 + node_modules/yaml/dist/Document-2cf6b08c.js | 757 ++++++ node_modules/yaml/dist/PlainValue-ec8e588e.js | 876 ++++++ node_modules/yaml/dist/Schema-42e9705c.js | 522 ++++ node_modules/yaml/dist/index.js | 79 + node_modules/yaml/dist/legacy-exports.js | 16 + node_modules/yaml/dist/parse-cst.js | 1747 ++++++++++++ node_modules/yaml/dist/resolveSeq-4a68b39b.js | 2115 +++++++++++++++ node_modules/yaml/dist/test-events.js | 162 ++ node_modules/yaml/dist/types.js | 23 + node_modules/yaml/dist/util.js | 19 + node_modules/yaml/dist/warnings-39684f17.js | 416 +++ node_modules/yaml/index.d.ts | 372 +++ node_modules/yaml/index.js | 1 + node_modules/yaml/map.js | 2 + node_modules/yaml/package.json | 106 + node_modules/yaml/pair.js | 2 + node_modules/yaml/parse-cst.d.ts | 187 ++ node_modules/yaml/parse-cst.js | 1 + node_modules/yaml/scalar.js | 2 + node_modules/yaml/schema.js | 9 + node_modules/yaml/seq.js | 2 + node_modules/yaml/types.d.ts | 407 +++ node_modules/yaml/types.js | 17 + node_modules/yaml/types.mjs | 17 + node_modules/yaml/types/binary.js | 8 + node_modules/yaml/types/omap.js | 3 + node_modules/yaml/types/pairs.js | 3 + node_modules/yaml/types/set.js | 3 + node_modules/yaml/types/timestamp.js | 10 + node_modules/yaml/util.d.ts | 86 + node_modules/yaml/util.js | 16 + node_modules/yaml/util.mjs | 18 + package-lock.json | 42 +- package.json | 3 +- 60 files changed, 16013 insertions(+), 2 deletions(-) create mode 100644 node_modules/.package-lock.json create mode 100644 node_modules/yaml/LICENSE create mode 100644 node_modules/yaml/README.md create mode 100644 node_modules/yaml/browser/dist/PlainValue-ff5147c6.js create mode 100644 node_modules/yaml/browser/dist/Schema-2bf2c74e.js create mode 100644 node_modules/yaml/browser/dist/index.js create mode 100644 node_modules/yaml/browser/dist/legacy-exports.js create mode 100644 node_modules/yaml/browser/dist/parse-cst.js create mode 100644 node_modules/yaml/browser/dist/resolveSeq-04825f30.js create mode 100644 node_modules/yaml/browser/dist/types.js create mode 100644 node_modules/yaml/browser/dist/util.js create mode 100644 node_modules/yaml/browser/dist/warnings-0e4b70d3.js create mode 100644 node_modules/yaml/browser/index.js create mode 100644 node_modules/yaml/browser/map.js create mode 100644 node_modules/yaml/browser/pair.js create mode 100644 node_modules/yaml/browser/parse-cst.js create mode 100644 node_modules/yaml/browser/scalar.js create mode 100644 node_modules/yaml/browser/schema.js create mode 100644 node_modules/yaml/browser/seq.js create mode 100644 node_modules/yaml/browser/types.js create mode 100644 node_modules/yaml/browser/types/binary.js create mode 100644 node_modules/yaml/browser/types/omap.js create mode 100644 node_modules/yaml/browser/types/pairs.js create mode 100644 node_modules/yaml/browser/types/set.js create mode 100644 node_modules/yaml/browser/types/timestamp.js create mode 100644 node_modules/yaml/browser/util.js create mode 100644 node_modules/yaml/dist/Document-2cf6b08c.js create mode 100644 node_modules/yaml/dist/PlainValue-ec8e588e.js create mode 100644 node_modules/yaml/dist/Schema-42e9705c.js create mode 100644 node_modules/yaml/dist/index.js create mode 100644 node_modules/yaml/dist/legacy-exports.js create mode 100644 node_modules/yaml/dist/parse-cst.js create mode 100644 node_modules/yaml/dist/resolveSeq-4a68b39b.js create mode 100644 node_modules/yaml/dist/test-events.js create mode 100644 node_modules/yaml/dist/types.js create mode 100644 node_modules/yaml/dist/util.js create mode 100644 node_modules/yaml/dist/warnings-39684f17.js create mode 100644 node_modules/yaml/index.d.ts create mode 100644 node_modules/yaml/index.js create mode 100644 node_modules/yaml/map.js create mode 100644 node_modules/yaml/package.json create mode 100644 node_modules/yaml/pair.js create mode 100644 node_modules/yaml/parse-cst.d.ts create mode 100644 node_modules/yaml/parse-cst.js create mode 100644 node_modules/yaml/scalar.js create mode 100644 node_modules/yaml/schema.js create mode 100644 node_modules/yaml/seq.js create mode 100644 node_modules/yaml/types.d.ts create mode 100644 node_modules/yaml/types.js create mode 100644 node_modules/yaml/types.mjs create mode 100644 node_modules/yaml/types/binary.js create mode 100644 node_modules/yaml/types/omap.js create mode 100644 node_modules/yaml/types/pairs.js create mode 100644 node_modules/yaml/types/set.js create mode 100644 node_modules/yaml/types/timestamp.js create mode 100644 node_modules/yaml/util.d.ts create mode 100644 node_modules/yaml/util.js create mode 100644 node_modules/yaml/util.mjs diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json new file mode 100644 index 0000000..20be8cf --- /dev/null +++ b/node_modules/.package-lock.json @@ -0,0 +1,33 @@ +{ + "name": "action-ansible-playbook", + "lockfileVersion": 2, + "requires": true, + "packages": { + "node_modules/@actions/core": { + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.6.tgz", + "integrity": "sha512-ZQYitnqiyBc3D+k7LsgSBmMDVkOVidaagDG7j3fOym77jNunWRuYx7VSHa9GNfFZh+zh61xsCjRj4JxMZlDqTA==" + }, + "node_modules/@actions/exec": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.0.4.tgz", + "integrity": "sha512-4DPChWow9yc9W3WqEbUj8Nr86xkpyE29ZzWjXucHItclLbEW6jr80Zx4nqv18QL6KK65+cifiQZXvnqgTV6oHw==", + "dependencies": { + "@actions/io": "^1.0.1" + } + }, + "node_modules/@actions/io": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@actions/io/-/io-1.0.2.tgz", + "integrity": "sha512-J8KuFqVPr3p6U8W93DOXlXW6zFvrQAJANdS+vw0YhusLIq+bszW8zmK2Fh1C2kDPX8FMvwIl1OUcFgvJoXLbAg==" + }, + "node_modules/yaml": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-1.10.0.tgz", + "integrity": "sha512-yr2icI4glYaNG+KWONODapy2/jDdMSDnrONSjblABjD9B4Z5LgiircSt8m8sRZFNi08kG9Sm0uSHtEmP3zaEGg==", + "engines": { + "node": ">= 6" + } + } + } +} diff --git a/node_modules/yaml/LICENSE b/node_modules/yaml/LICENSE new file mode 100644 index 0000000..7ca44e3 --- /dev/null +++ b/node_modules/yaml/LICENSE @@ -0,0 +1,13 @@ +Copyright 2018 Eemeli Aro + +Permission to use, copy, modify, and/or distribute this software for any purpose +with or without fee is hereby granted, provided that the above copyright notice +and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. diff --git a/node_modules/yaml/README.md b/node_modules/yaml/README.md new file mode 100644 index 0000000..cb39f98 --- /dev/null +++ b/node_modules/yaml/README.md @@ -0,0 +1,127 @@ +# YAML + +`yaml` is a JavaScript parser and stringifier for [YAML](http://yaml.org/), a human friendly data serialization standard. It supports both parsing and stringifying data using all versions of YAML, along with all common data schemas. As a particularly distinguishing feature, `yaml` fully supports reading and writing comments and blank lines in YAML documents. + +The library is released under the ISC open source license, and the code is [available on GitHub](https://github.com/eemeli/yaml/). It has no external dependencies and runs on Node.js 6 and later, and in browsers from IE 11 upwards. + +For the purposes of versioning, any changes that break any of the endpoints or APIs documented here will be considered semver-major breaking changes. Undocumented library internals may change between minor versions, and previous APIs may be deprecated (but not removed). + +For more information, see the project's documentation site: [**eemeli.org/yaml**](https://eemeli.org/yaml/) + +To install: + +```sh +npm install yaml +``` + +Note: `yaml` 0.x and 1.x are rather different implementations. For the earlier `yaml`, see [tj/js-yaml](https://github.com/tj/js-yaml). + +## API Overview + +The API provided by `yaml` has three layers, depending on how deep you need to go: [Parse & Stringify](https://eemeli.org/yaml/#parse-amp-stringify), [Documents](https://eemeli.org/yaml/#documents), and the [CST Parser](https://eemeli.org/yaml/#cst-parser). The first has the simplest API and "just works", the second gets you all the bells and whistles supported by the library along with a decent [AST](https://eemeli.org/yaml/#content-nodes), and the third is the closest to YAML source, making it fast, raw, and crude. + +```js +import YAML from 'yaml' +// or +const YAML = require('yaml') +``` + +### Parse & Stringify + +- [`YAML.parse(str, options): value`](https://eemeli.org/yaml/#yaml-parse) +- [`YAML.stringify(value, options): string`](https://eemeli.org/yaml/#yaml-stringify) + +### YAML Documents + +- [`YAML.createNode(value, wrapScalars, tag): Node`](https://eemeli.org/yaml/#creating-nodes) +- [`YAML.defaultOptions`](https://eemeli.org/yaml/#options) +- [`YAML.Document`](https://eemeli.org/yaml/#yaml-documents) + - [`constructor(options)`](https://eemeli.org/yaml/#creating-documents) + - [`defaults`](https://eemeli.org/yaml/#options) + - [`#anchors`](https://eemeli.org/yaml/#working-with-anchors) + - [`#contents`](https://eemeli.org/yaml/#content-nodes) + - [`#errors`](https://eemeli.org/yaml/#errors) +- [`YAML.parseAllDocuments(str, options): YAML.Document[]`](https://eemeli.org/yaml/#parsing-documents) +- [`YAML.parseDocument(str, options): YAML.Document`](https://eemeli.org/yaml/#parsing-documents) + +```js +import { Pair, YAMLMap, YAMLSeq } from 'yaml/types' +``` + +- [`new Pair(key, value)`](https://eemeli.org/yaml/#creating-nodes) +- [`new YAMLMap()`](https://eemeli.org/yaml/#creating-nodes) +- [`new YAMLSeq()`](https://eemeli.org/yaml/#creating-nodes) + +### CST Parser + +```js +import parseCST from 'yaml/parse-cst' +``` + +- [`parseCST(str): CSTDocument[]`](https://eemeli.org/yaml/#parsecst) +- [`YAML.parseCST(str): CSTDocument[]`](https://eemeli.org/yaml/#parsecst) + +## YAML.parse + +```yaml +# file.yml +YAML: + - A human-readable data serialization language + - https://en.wikipedia.org/wiki/YAML +yaml: + - A complete JavaScript implementation + - https://www.npmjs.com/package/yaml +``` + +```js +import fs from 'fs' +import YAML from 'yaml' + +YAML.parse('3.14159') +// 3.14159 + +YAML.parse('[ true, false, maybe, null ]\n') +// [ true, false, 'maybe', null ] + +const file = fs.readFileSync('./file.yml', 'utf8') +YAML.parse(file) +// { YAML: +// [ 'A human-readable data serialization language', +// 'https://en.wikipedia.org/wiki/YAML' ], +// yaml: +// [ 'A complete JavaScript implementation', +// 'https://www.npmjs.com/package/yaml' ] } +``` + +## YAML.stringify + +```js +import YAML from 'yaml' + +YAML.stringify(3.14159) +// '3.14159\n' + +YAML.stringify([true, false, 'maybe', null]) +// `- true +// - false +// - maybe +// - null +// ` + +YAML.stringify({ number: 3, plain: 'string', block: 'two\nlines\n' }) +// `number: 3 +// plain: string +// block: > +// two +// +// lines +// ` +``` + +--- + +Browser testing provided by: + + + + diff --git a/node_modules/yaml/browser/dist/PlainValue-ff5147c6.js b/node_modules/yaml/browser/dist/PlainValue-ff5147c6.js new file mode 100644 index 0000000..0456a48 --- /dev/null +++ b/node_modules/yaml/browser/dist/PlainValue-ff5147c6.js @@ -0,0 +1,1277 @@ +function _typeof(obj) { + "@babel/helpers - typeof"; + + if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { + _typeof = function (obj) { + return typeof obj; + }; + } else { + _typeof = function (obj) { + return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; + }; + } + + return _typeof(obj); +} + +function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } +} + +function _defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } +} + +function _createClass(Constructor, protoProps, staticProps) { + if (protoProps) _defineProperties(Constructor.prototype, protoProps); + if (staticProps) _defineProperties(Constructor, staticProps); + return Constructor; +} + +function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; +} + +function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function"); + } + + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + writable: true, + configurable: true + } + }); + if (superClass) _setPrototypeOf(subClass, superClass); +} + +function _getPrototypeOf(o) { + _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }; + return _getPrototypeOf(o); +} + +function _setPrototypeOf(o, p) { + _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { + o.__proto__ = p; + return o; + }; + + return _setPrototypeOf(o, p); +} + +function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + + try { + Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); + return true; + } catch (e) { + return false; + } +} + +function _construct(Parent, args, Class) { + if (_isNativeReflectConstruct()) { + _construct = Reflect.construct; + } else { + _construct = function _construct(Parent, args, Class) { + var a = [null]; + a.push.apply(a, args); + var Constructor = Function.bind.apply(Parent, a); + var instance = new Constructor(); + if (Class) _setPrototypeOf(instance, Class.prototype); + return instance; + }; + } + + return _construct.apply(null, arguments); +} + +function _isNativeFunction(fn) { + return Function.toString.call(fn).indexOf("[native code]") !== -1; +} + +function _wrapNativeSuper(Class) { + var _cache = typeof Map === "function" ? new Map() : undefined; + + _wrapNativeSuper = function _wrapNativeSuper(Class) { + if (Class === null || !_isNativeFunction(Class)) return Class; + + if (typeof Class !== "function") { + throw new TypeError("Super expression must either be null or a function"); + } + + if (typeof _cache !== "undefined") { + if (_cache.has(Class)) return _cache.get(Class); + + _cache.set(Class, Wrapper); + } + + function Wrapper() { + return _construct(Class, arguments, _getPrototypeOf(this).constructor); + } + + Wrapper.prototype = Object.create(Class.prototype, { + constructor: { + value: Wrapper, + enumerable: false, + writable: true, + configurable: true + } + }); + return _setPrototypeOf(Wrapper, Class); + }; + + return _wrapNativeSuper(Class); +} + +function _assertThisInitialized(self) { + if (self === void 0) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } + + return self; +} + +function _possibleConstructorReturn(self, call) { + if (call && (typeof call === "object" || typeof call === "function")) { + return call; + } + + return _assertThisInitialized(self); +} + +function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + + return function () { + var Super = _getPrototypeOf(Derived), + result; + + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + + return _possibleConstructorReturn(this, result); + }; +} + +function _superPropBase(object, property) { + while (!Object.prototype.hasOwnProperty.call(object, property)) { + object = _getPrototypeOf(object); + if (object === null) break; + } + + return object; +} + +function _get(target, property, receiver) { + if (typeof Reflect !== "undefined" && Reflect.get) { + _get = Reflect.get; + } else { + _get = function _get(target, property, receiver) { + var base = _superPropBase(target, property); + + if (!base) return; + var desc = Object.getOwnPropertyDescriptor(base, property); + + if (desc.get) { + return desc.get.call(receiver); + } + + return desc.value; + }; + } + + return _get(target, property, receiver || target); +} + +function _slicedToArray(arr, i) { + return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); +} + +function _toArray(arr) { + return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); +} + +function _arrayWithHoles(arr) { + if (Array.isArray(arr)) return arr; +} + +function _iterableToArray(iter) { + if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); +} + +function _iterableToArrayLimit(arr, i) { + if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; + var _arr = []; + var _n = true; + var _d = false; + var _e = undefined; + + try { + for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { + _arr.push(_s.value); + + if (i && _arr.length === i) break; + } + } catch (err) { + _d = true; + _e = err; + } finally { + try { + if (!_n && _i["return"] != null) _i["return"](); + } finally { + if (_d) throw _e; + } + } + + return _arr; +} + +function _unsupportedIterableToArray(o, minLen) { + if (!o) return; + if (typeof o === "string") return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if (n === "Object" && o.constructor) n = o.constructor.name; + if (n === "Map" || n === "Set") return Array.from(o); + if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); +} + +function _arrayLikeToArray(arr, len) { + if (len == null || len > arr.length) len = arr.length; + + for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; + + return arr2; +} + +function _nonIterableRest() { + throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); +} + +function _createForOfIteratorHelper(o) { + if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { + if (Array.isArray(o) || (o = _unsupportedIterableToArray(o))) { + var i = 0; + + var F = function () {}; + + return { + s: F, + n: function () { + if (i >= o.length) return { + done: true + }; + return { + done: false, + value: o[i++] + }; + }, + e: function (e) { + throw e; + }, + f: F + }; + } + + throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + } + + var it, + normalCompletion = true, + didErr = false, + err; + return { + s: function () { + it = o[Symbol.iterator](); + }, + n: function () { + var step = it.next(); + normalCompletion = step.done; + return step; + }, + e: function (e) { + didErr = true; + err = e; + }, + f: function () { + try { + if (!normalCompletion && it.return != null) it.return(); + } finally { + if (didErr) throw err; + } + } + }; +} + +var Char = { + ANCHOR: '&', + COMMENT: '#', + TAG: '!', + DIRECTIVES_END: '-', + DOCUMENT_END: '.' +}; +var Type = { + ALIAS: 'ALIAS', + BLANK_LINE: 'BLANK_LINE', + BLOCK_FOLDED: 'BLOCK_FOLDED', + BLOCK_LITERAL: 'BLOCK_LITERAL', + COMMENT: 'COMMENT', + DIRECTIVE: 'DIRECTIVE', + DOCUMENT: 'DOCUMENT', + FLOW_MAP: 'FLOW_MAP', + FLOW_SEQ: 'FLOW_SEQ', + MAP: 'MAP', + MAP_KEY: 'MAP_KEY', + MAP_VALUE: 'MAP_VALUE', + PLAIN: 'PLAIN', + QUOTE_DOUBLE: 'QUOTE_DOUBLE', + QUOTE_SINGLE: 'QUOTE_SINGLE', + SEQ: 'SEQ', + SEQ_ITEM: 'SEQ_ITEM' +}; +var defaultTagPrefix = 'tag:yaml.org,2002:'; +var defaultTags = { + MAP: 'tag:yaml.org,2002:map', + SEQ: 'tag:yaml.org,2002:seq', + STR: 'tag:yaml.org,2002:str' +}; + +function findLineStarts(src) { + var ls = [0]; + var offset = src.indexOf('\n'); + + while (offset !== -1) { + offset += 1; + ls.push(offset); + offset = src.indexOf('\n', offset); + } + + return ls; +} + +function getSrcInfo(cst) { + var lineStarts, src; + + if (typeof cst === 'string') { + lineStarts = findLineStarts(cst); + src = cst; + } else { + if (Array.isArray(cst)) cst = cst[0]; + + if (cst && cst.context) { + if (!cst.lineStarts) cst.lineStarts = findLineStarts(cst.context.src); + lineStarts = cst.lineStarts; + src = cst.context.src; + } + } + + return { + lineStarts: lineStarts, + src: src + }; +} +/** + * @typedef {Object} LinePos - One-indexed position in the source + * @property {number} line + * @property {number} col + */ + +/** + * Determine the line/col position matching a character offset. + * + * Accepts a source string or a CST document as the second parameter. With + * the latter, starting indices for lines are cached in the document as + * `lineStarts: number[]`. + * + * Returns a one-indexed `{ line, col }` location if found, or + * `undefined` otherwise. + * + * @param {number} offset + * @param {string|Document|Document[]} cst + * @returns {?LinePos} + */ + + +function getLinePos(offset, cst) { + if (typeof offset !== 'number' || offset < 0) return null; + + var _getSrcInfo = getSrcInfo(cst), + lineStarts = _getSrcInfo.lineStarts, + src = _getSrcInfo.src; + + if (!lineStarts || !src || offset > src.length) return null; + + for (var i = 0; i < lineStarts.length; ++i) { + var start = lineStarts[i]; + + if (offset < start) { + return { + line: i, + col: offset - lineStarts[i - 1] + 1 + }; + } + + if (offset === start) return { + line: i + 1, + col: 1 + }; + } + + var line = lineStarts.length; + return { + line: line, + col: offset - lineStarts[line - 1] + 1 + }; +} +/** + * Get a specified line from the source. + * + * Accepts a source string or a CST document as the second parameter. With + * the latter, starting indices for lines are cached in the document as + * `lineStarts: number[]`. + * + * Returns the line as a string if found, or `null` otherwise. + * + * @param {number} line One-indexed line number + * @param {string|Document|Document[]} cst + * @returns {?string} + */ + +function getLine(line, cst) { + var _getSrcInfo2 = getSrcInfo(cst), + lineStarts = _getSrcInfo2.lineStarts, + src = _getSrcInfo2.src; + + if (!lineStarts || !(line >= 1) || line > lineStarts.length) return null; + var start = lineStarts[line - 1]; + var end = lineStarts[line]; // undefined for last line; that's ok for slice() + + while (end && end > start && src[end - 1] === '\n') { + --end; + } + + return src.slice(start, end); +} +/** + * Pretty-print the starting line from the source indicated by the range `pos` + * + * Trims output to `maxWidth` chars while keeping the starting column visible, + * using `…` at either end to indicate dropped characters. + * + * Returns a two-line string (or `null`) with `\n` as separator; the second line + * will hold appropriately indented `^` marks indicating the column range. + * + * @param {Object} pos + * @param {LinePos} pos.start + * @param {LinePos} [pos.end] + * @param {string|Document|Document[]*} cst + * @param {number} [maxWidth=80] + * @returns {?string} + */ + +function getPrettyContext(_ref, cst) { + var start = _ref.start, + end = _ref.end; + var maxWidth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 80; + var src = getLine(start.line, cst); + if (!src) return null; + var col = start.col; + + if (src.length > maxWidth) { + if (col <= maxWidth - 10) { + src = src.substr(0, maxWidth - 1) + '…'; + } else { + var halfWidth = Math.round(maxWidth / 2); + if (src.length > col + halfWidth) src = src.substr(0, col + halfWidth - 1) + '…'; + col -= src.length - maxWidth; + src = '…' + src.substr(1 - maxWidth); + } + } + + var errLen = 1; + var errEnd = ''; + + if (end) { + if (end.line === start.line && col + (end.col - start.col) <= maxWidth + 1) { + errLen = end.col - start.col; + } else { + errLen = Math.min(src.length + 1, maxWidth) - col; + errEnd = '…'; + } + } + + var offset = col > 1 ? ' '.repeat(col - 1) : ''; + var err = '^'.repeat(errLen); + return "".concat(src, "\n").concat(offset).concat(err).concat(errEnd); +} + +var Range = /*#__PURE__*/function () { + _createClass(Range, null, [{ + key: "copy", + value: function copy(orig) { + return new Range(orig.start, orig.end); + } + }]); + + function Range(start, end) { + _classCallCheck(this, Range); + + this.start = start; + this.end = end || start; + } + + _createClass(Range, [{ + key: "isEmpty", + value: function isEmpty() { + return typeof this.start !== 'number' || !this.end || this.end <= this.start; + } + /** + * Set `origStart` and `origEnd` to point to the original source range for + * this node, which may differ due to dropped CR characters. + * + * @param {number[]} cr - Positions of dropped CR characters + * @param {number} offset - Starting index of `cr` from the last call + * @returns {number} - The next offset, matching the one found for `origStart` + */ + + }, { + key: "setOrigRange", + value: function setOrigRange(cr, offset) { + var start = this.start, + end = this.end; + + if (cr.length === 0 || end <= cr[0]) { + this.origStart = start; + this.origEnd = end; + return offset; + } + + var i = offset; + + while (i < cr.length) { + if (cr[i] > start) break;else ++i; + } + + this.origStart = start + i; + var nextOffset = i; + + while (i < cr.length) { + // if end was at \n, it should now be at \r + if (cr[i] >= end) break;else ++i; + } + + this.origEnd = end + i; + return nextOffset; + } + }]); + + return Range; +}(); + +/** Root class of all nodes */ + +var Node = /*#__PURE__*/function () { + _createClass(Node, null, [{ + key: "addStringTerminator", + value: function addStringTerminator(src, offset, str) { + if (str[str.length - 1] === '\n') return str; + var next = Node.endOfWhiteSpace(src, offset); + return next >= src.length || src[next] === '\n' ? str + '\n' : str; + } // ^(---|...) + + }, { + key: "atDocumentBoundary", + value: function atDocumentBoundary(src, offset, sep) { + var ch0 = src[offset]; + if (!ch0) return true; + var prev = src[offset - 1]; + if (prev && prev !== '\n') return false; + + if (sep) { + if (ch0 !== sep) return false; + } else { + if (ch0 !== Char.DIRECTIVES_END && ch0 !== Char.DOCUMENT_END) return false; + } + + var ch1 = src[offset + 1]; + var ch2 = src[offset + 2]; + if (ch1 !== ch0 || ch2 !== ch0) return false; + var ch3 = src[offset + 3]; + return !ch3 || ch3 === '\n' || ch3 === '\t' || ch3 === ' '; + } + }, { + key: "endOfIdentifier", + value: function endOfIdentifier(src, offset) { + var ch = src[offset]; + var isVerbatim = ch === '<'; + var notOk = isVerbatim ? ['\n', '\t', ' ', '>'] : ['\n', '\t', ' ', '[', ']', '{', '}', ',']; + + while (ch && notOk.indexOf(ch) === -1) { + ch = src[offset += 1]; + } + + if (isVerbatim && ch === '>') offset += 1; + return offset; + } + }, { + key: "endOfIndent", + value: function endOfIndent(src, offset) { + var ch = src[offset]; + + while (ch === ' ') { + ch = src[offset += 1]; + } + + return offset; + } + }, { + key: "endOfLine", + value: function endOfLine(src, offset) { + var ch = src[offset]; + + while (ch && ch !== '\n') { + ch = src[offset += 1]; + } + + return offset; + } + }, { + key: "endOfWhiteSpace", + value: function endOfWhiteSpace(src, offset) { + var ch = src[offset]; + + while (ch === '\t' || ch === ' ') { + ch = src[offset += 1]; + } + + return offset; + } + }, { + key: "startOfLine", + value: function startOfLine(src, offset) { + var ch = src[offset - 1]; + if (ch === '\n') return offset; + + while (ch && ch !== '\n') { + ch = src[offset -= 1]; + } + + return offset + 1; + } + /** + * End of indentation, or null if the line's indent level is not more + * than `indent` + * + * @param {string} src + * @param {number} indent + * @param {number} lineStart + * @returns {?number} + */ + + }, { + key: "endOfBlockIndent", + value: function endOfBlockIndent(src, indent, lineStart) { + var inEnd = Node.endOfIndent(src, lineStart); + + if (inEnd > lineStart + indent) { + return inEnd; + } else { + var wsEnd = Node.endOfWhiteSpace(src, inEnd); + var ch = src[wsEnd]; + if (!ch || ch === '\n') return wsEnd; + } + + return null; + } + }, { + key: "atBlank", + value: function atBlank(src, offset, endAsBlank) { + var ch = src[offset]; + return ch === '\n' || ch === '\t' || ch === ' ' || endAsBlank && !ch; + } + }, { + key: "nextNodeIsIndented", + value: function nextNodeIsIndented(ch, indentDiff, indicatorAsIndent) { + if (!ch || indentDiff < 0) return false; + if (indentDiff > 0) return true; + return indicatorAsIndent && ch === '-'; + } // should be at line or string end, or at next non-whitespace char + + }, { + key: "normalizeOffset", + value: function normalizeOffset(src, offset) { + var ch = src[offset]; + return !ch ? offset : ch !== '\n' && src[offset - 1] === '\n' ? offset - 1 : Node.endOfWhiteSpace(src, offset); + } // fold single newline into space, multiple newlines to N - 1 newlines + // presumes src[offset] === '\n' + + }, { + key: "foldNewline", + value: function foldNewline(src, offset, indent) { + var inCount = 0; + var error = false; + var fold = ''; + var ch = src[offset + 1]; + + while (ch === ' ' || ch === '\t' || ch === '\n') { + switch (ch) { + case '\n': + inCount = 0; + offset += 1; + fold += '\n'; + break; + + case '\t': + if (inCount <= indent) error = true; + offset = Node.endOfWhiteSpace(src, offset + 2) - 1; + break; + + case ' ': + inCount += 1; + offset += 1; + break; + } + + ch = src[offset + 1]; + } + + if (!fold) fold = ' '; + if (ch && inCount <= indent) error = true; + return { + fold: fold, + offset: offset, + error: error + }; + } + }]); + + function Node(type, props, context) { + _classCallCheck(this, Node); + + Object.defineProperty(this, 'context', { + value: context || null, + writable: true + }); + this.error = null; + this.range = null; + this.valueRange = null; + this.props = props || []; + this.type = type; + this.value = null; + } + + _createClass(Node, [{ + key: "getPropValue", + value: function getPropValue(idx, key, skipKey) { + if (!this.context) return null; + var src = this.context.src; + var prop = this.props[idx]; + return prop && src[prop.start] === key ? src.slice(prop.start + (skipKey ? 1 : 0), prop.end) : null; + } + }, { + key: "commentHasRequiredWhitespace", + value: function commentHasRequiredWhitespace(start) { + var src = this.context.src; + if (this.header && start === this.header.end) return false; + if (!this.valueRange) return false; + var end = this.valueRange.end; + return start !== end || Node.atBlank(src, end - 1); + } + }, { + key: "parseComment", + value: function parseComment(start) { + var src = this.context.src; + + if (src[start] === Char.COMMENT) { + var end = Node.endOfLine(src, start + 1); + var commentRange = new Range(start, end); + this.props.push(commentRange); + return end; + } + + return start; + } + /** + * Populates the `origStart` and `origEnd` values of all ranges for this + * node. Extended by child classes to handle descendant nodes. + * + * @param {number[]} cr - Positions of dropped CR characters + * @param {number} offset - Starting index of `cr` from the last call + * @returns {number} - The next offset, matching the one found for `origStart` + */ + + }, { + key: "setOrigRanges", + value: function setOrigRanges(cr, offset) { + if (this.range) offset = this.range.setOrigRange(cr, offset); + if (this.valueRange) this.valueRange.setOrigRange(cr, offset); + this.props.forEach(function (prop) { + return prop.setOrigRange(cr, offset); + }); + return offset; + } + }, { + key: "toString", + value: function toString() { + var src = this.context.src, + range = this.range, + value = this.value; + if (value != null) return value; + var str = src.slice(range.start, range.end); + return Node.addStringTerminator(src, range.end, str); + } + }, { + key: "anchor", + get: function get() { + for (var i = 0; i < this.props.length; ++i) { + var anchor = this.getPropValue(i, Char.ANCHOR, true); + if (anchor != null) return anchor; + } + + return null; + } + }, { + key: "comment", + get: function get() { + var comments = []; + + for (var i = 0; i < this.props.length; ++i) { + var comment = this.getPropValue(i, Char.COMMENT, true); + if (comment != null) comments.push(comment); + } + + return comments.length > 0 ? comments.join('\n') : null; + } + }, { + key: "hasComment", + get: function get() { + if (this.context) { + var src = this.context.src; + + for (var i = 0; i < this.props.length; ++i) { + if (src[this.props[i].start] === Char.COMMENT) return true; + } + } + + return false; + } + }, { + key: "hasProps", + get: function get() { + if (this.context) { + var src = this.context.src; + + for (var i = 0; i < this.props.length; ++i) { + if (src[this.props[i].start] !== Char.COMMENT) return true; + } + } + + return false; + } + }, { + key: "includesTrailingLines", + get: function get() { + return false; + } + }, { + key: "jsonLike", + get: function get() { + var jsonLikeTypes = [Type.FLOW_MAP, Type.FLOW_SEQ, Type.QUOTE_DOUBLE, Type.QUOTE_SINGLE]; + return jsonLikeTypes.indexOf(this.type) !== -1; + } + }, { + key: "rangeAsLinePos", + get: function get() { + if (!this.range || !this.context) return undefined; + var start = getLinePos(this.range.start, this.context.root); + if (!start) return undefined; + var end = getLinePos(this.range.end, this.context.root); + return { + start: start, + end: end + }; + } + }, { + key: "rawValue", + get: function get() { + if (!this.valueRange || !this.context) return null; + var _this$valueRange = this.valueRange, + start = _this$valueRange.start, + end = _this$valueRange.end; + return this.context.src.slice(start, end); + } + }, { + key: "tag", + get: function get() { + for (var i = 0; i < this.props.length; ++i) { + var tag = this.getPropValue(i, Char.TAG, false); + + if (tag != null) { + if (tag[1] === '<') { + return { + verbatim: tag.slice(2, -1) + }; + } else { + // eslint-disable-next-line no-unused-vars + var _tag$match = tag.match(/^(.*!)([^!]*)$/), + _tag$match2 = _slicedToArray(_tag$match, 3), + _ = _tag$match2[0], + handle = _tag$match2[1], + suffix = _tag$match2[2]; + + return { + handle: handle, + suffix: suffix + }; + } + } + } + + return null; + } + }, { + key: "valueRangeContainsNewline", + get: function get() { + if (!this.valueRange || !this.context) return false; + var _this$valueRange2 = this.valueRange, + start = _this$valueRange2.start, + end = _this$valueRange2.end; + var src = this.context.src; + + for (var i = start; i < end; ++i) { + if (src[i] === '\n') return true; + } + + return false; + } + }]); + + return Node; +}(); + +var YAMLError = /*#__PURE__*/function (_Error) { + _inherits(YAMLError, _Error); + + var _super = _createSuper(YAMLError); + + function YAMLError(name, source, message) { + var _this; + + _classCallCheck(this, YAMLError); + + if (!message || !(source instanceof Node)) throw new Error("Invalid arguments for new ".concat(name)); + _this = _super.call(this); + _this.name = name; + _this.message = message; + _this.source = source; + return _this; + } + + _createClass(YAMLError, [{ + key: "makePretty", + value: function makePretty() { + if (!this.source) return; + this.nodeType = this.source.type; + var cst = this.source.context && this.source.context.root; + + if (typeof this.offset === 'number') { + this.range = new Range(this.offset, this.offset + 1); + var start = cst && getLinePos(this.offset, cst); + + if (start) { + var end = { + line: start.line, + col: start.col + 1 + }; + this.linePos = { + start: start, + end: end + }; + } + + delete this.offset; + } else { + this.range = this.source.range; + this.linePos = this.source.rangeAsLinePos; + } + + if (this.linePos) { + var _this$linePos$start = this.linePos.start, + line = _this$linePos$start.line, + col = _this$linePos$start.col; + this.message += " at line ".concat(line, ", column ").concat(col); + var ctx = cst && getPrettyContext(this.linePos, cst); + if (ctx) this.message += ":\n\n".concat(ctx, "\n"); + } + + delete this.source; + } + }]); + + return YAMLError; +}( /*#__PURE__*/_wrapNativeSuper(Error)); +var YAMLReferenceError = /*#__PURE__*/function (_YAMLError) { + _inherits(YAMLReferenceError, _YAMLError); + + var _super2 = _createSuper(YAMLReferenceError); + + function YAMLReferenceError(source, message) { + _classCallCheck(this, YAMLReferenceError); + + return _super2.call(this, 'YAMLReferenceError', source, message); + } + + return YAMLReferenceError; +}(YAMLError); +var YAMLSemanticError = /*#__PURE__*/function (_YAMLError2) { + _inherits(YAMLSemanticError, _YAMLError2); + + var _super3 = _createSuper(YAMLSemanticError); + + function YAMLSemanticError(source, message) { + _classCallCheck(this, YAMLSemanticError); + + return _super3.call(this, 'YAMLSemanticError', source, message); + } + + return YAMLSemanticError; +}(YAMLError); +var YAMLSyntaxError = /*#__PURE__*/function (_YAMLError3) { + _inherits(YAMLSyntaxError, _YAMLError3); + + var _super4 = _createSuper(YAMLSyntaxError); + + function YAMLSyntaxError(source, message) { + _classCallCheck(this, YAMLSyntaxError); + + return _super4.call(this, 'YAMLSyntaxError', source, message); + } + + return YAMLSyntaxError; +}(YAMLError); +var YAMLWarning = /*#__PURE__*/function (_YAMLError4) { + _inherits(YAMLWarning, _YAMLError4); + + var _super5 = _createSuper(YAMLWarning); + + function YAMLWarning(source, message) { + _classCallCheck(this, YAMLWarning); + + return _super5.call(this, 'YAMLWarning', source, message); + } + + return YAMLWarning; +}(YAMLError); + +var PlainValue = /*#__PURE__*/function (_Node) { + _inherits(PlainValue, _Node); + + var _super = _createSuper(PlainValue); + + function PlainValue() { + _classCallCheck(this, PlainValue); + + return _super.apply(this, arguments); + } + + _createClass(PlainValue, [{ + key: "parseBlockValue", + value: function parseBlockValue(start) { + var _this$context = this.context, + indent = _this$context.indent, + inFlow = _this$context.inFlow, + src = _this$context.src; + var offset = start; + var valueEnd = start; + + for (var ch = src[offset]; ch === '\n'; ch = src[offset]) { + if (Node.atDocumentBoundary(src, offset + 1)) break; + var end = Node.endOfBlockIndent(src, indent, offset + 1); + if (end === null || src[end] === '#') break; + + if (src[end] === '\n') { + offset = end; + } else { + valueEnd = PlainValue.endOfLine(src, end, inFlow); + offset = valueEnd; + } + } + + if (this.valueRange.isEmpty()) this.valueRange.start = start; + this.valueRange.end = valueEnd; + return valueEnd; + } + /** + * Parses a plain value from the source + * + * Accepted forms are: + * ``` + * #comment + * + * first line + * + * first line #comment + * + * first line + * block + * lines + * + * #comment + * block + * lines + * ``` + * where block lines are empty or have an indent level greater than `indent`. + * + * @param {ParseContext} context + * @param {number} start - Index of first character + * @returns {number} - Index of the character after this scalar, may be `\n` + */ + + }, { + key: "parse", + value: function parse(context, start) { + this.context = context; + var inFlow = context.inFlow, + src = context.src; + var offset = start; + var ch = src[offset]; + + if (ch && ch !== '#' && ch !== '\n') { + offset = PlainValue.endOfLine(src, start, inFlow); + } + + this.valueRange = new Range(start, offset); + offset = Node.endOfWhiteSpace(src, offset); + offset = this.parseComment(offset); + + if (!this.hasComment || this.valueRange.isEmpty()) { + offset = this.parseBlockValue(offset); + } + + return offset; + } + }, { + key: "strValue", + get: function get() { + if (!this.valueRange || !this.context) return null; + var _this$valueRange = this.valueRange, + start = _this$valueRange.start, + end = _this$valueRange.end; + var src = this.context.src; + var ch = src[end - 1]; + + while (start < end && (ch === '\n' || ch === '\t' || ch === ' ')) { + ch = src[--end - 1]; + } + + var str = ''; + + for (var i = start; i < end; ++i) { + var _ch = src[i]; + + if (_ch === '\n') { + var _Node$foldNewline = Node.foldNewline(src, i, -1), + fold = _Node$foldNewline.fold, + offset = _Node$foldNewline.offset; + + str += fold; + i = offset; + } else if (_ch === ' ' || _ch === '\t') { + // trim trailing whitespace + var wsStart = i; + var next = src[i + 1]; + + while (i < end && (next === ' ' || next === '\t')) { + i += 1; + next = src[i + 1]; + } + + if (next !== '\n') str += i > wsStart ? src.slice(wsStart, i + 1) : _ch; + } else { + str += _ch; + } + } + + var ch0 = src[start]; + + switch (ch0) { + case '\t': + { + var msg = 'Plain value cannot start with a tab character'; + var errors = [new YAMLSemanticError(this, msg)]; + return { + errors: errors, + str: str + }; + } + + case '@': + case '`': + { + var _msg = "Plain value cannot start with reserved character ".concat(ch0); + + var _errors = [new YAMLSemanticError(this, _msg)]; + return { + errors: _errors, + str: str + }; + } + + default: + return str; + } + } + }], [{ + key: "endOfLine", + value: function endOfLine(src, start, inFlow) { + var ch = src[start]; + var offset = start; + + while (ch && ch !== '\n') { + if (inFlow && (ch === '[' || ch === ']' || ch === '{' || ch === '}' || ch === ',')) break; + var next = src[offset + 1]; + if (ch === ':' && (!next || next === '\n' || next === '\t' || next === ' ' || inFlow && next === ',')) break; + if ((ch === ' ' || ch === '\t') && next === '#') break; + offset += 1; + ch = next; + } + + return offset; + } + }]); + + return PlainValue; +}(Node); + +export { Char as C, Node as N, PlainValue as P, Range as R, Type as T, YAMLSyntaxError as Y, _createForOfIteratorHelper as _, _typeof as a, _createClass as b, _classCallCheck as c, defaultTagPrefix as d, _defineProperty as e, YAMLWarning as f, YAMLSemanticError as g, _slicedToArray as h, YAMLError as i, _inherits as j, _createSuper as k, _get as l, _getPrototypeOf as m, defaultTags as n, YAMLReferenceError as o, _assertThisInitialized as p, _toArray as q, _possibleConstructorReturn as r }; diff --git a/node_modules/yaml/browser/dist/Schema-2bf2c74e.js b/node_modules/yaml/browser/dist/Schema-2bf2c74e.js new file mode 100644 index 0000000..1f1c013 --- /dev/null +++ b/node_modules/yaml/browser/dist/Schema-2bf2c74e.js @@ -0,0 +1,679 @@ +import { _ as _createForOfIteratorHelper, h as _slicedToArray, a as _typeof, b as _createClass, e as _defineProperty, c as _classCallCheck, d as defaultTagPrefix, n as defaultTags } from './PlainValue-ff5147c6.js'; +import { d as YAMLMap, g as resolveMap, Y as YAMLSeq, h as resolveSeq, j as resolveString, c as stringifyString, s as strOptions, S as Scalar, n as nullOptions, a as boolOptions, i as intOptions, k as stringifyNumber, N as Node, A as Alias, P as Pair } from './resolveSeq-04825f30.js'; +import { b as binary, o as omap, p as pairs, s as set, i as intTime, f as floatTime, t as timestamp, a as warnOptionDeprecation } from './warnings-0e4b70d3.js'; + +function createMap(schema, obj, ctx) { + var map = new YAMLMap(schema); + + if (obj instanceof Map) { + var _iterator = _createForOfIteratorHelper(obj), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var _step$value = _slicedToArray(_step.value, 2), + key = _step$value[0], + value = _step$value[1]; + + map.items.push(schema.createPair(key, value, ctx)); + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + } else if (obj && _typeof(obj) === 'object') { + for (var _i = 0, _Object$keys = Object.keys(obj); _i < _Object$keys.length; _i++) { + var _key = _Object$keys[_i]; + map.items.push(schema.createPair(_key, obj[_key], ctx)); + } + } + + if (typeof schema.sortMapEntries === 'function') { + map.items.sort(schema.sortMapEntries); + } + + return map; +} + +var map = { + createNode: createMap, + default: true, + nodeClass: YAMLMap, + tag: 'tag:yaml.org,2002:map', + resolve: resolveMap +}; + +function createSeq(schema, obj, ctx) { + var seq = new YAMLSeq(schema); + + if (obj && obj[Symbol.iterator]) { + var _iterator = _createForOfIteratorHelper(obj), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var it = _step.value; + var v = schema.createNode(it, ctx.wrapScalars, null, ctx); + seq.items.push(v); + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + } + + return seq; +} + +var seq = { + createNode: createSeq, + default: true, + nodeClass: YAMLSeq, + tag: 'tag:yaml.org,2002:seq', + resolve: resolveSeq +}; + +var string = { + identify: function identify(value) { + return typeof value === 'string'; + }, + default: true, + tag: 'tag:yaml.org,2002:str', + resolve: resolveString, + stringify: function stringify(item, ctx, onComment, onChompKeep) { + ctx = Object.assign({ + actualString: true + }, ctx); + return stringifyString(item, ctx, onComment, onChompKeep); + }, + options: strOptions +}; + +var failsafe = [map, seq, string]; + +/* global BigInt */ + +var intIdentify = function intIdentify(value) { + return typeof value === 'bigint' || Number.isInteger(value); +}; + +var intResolve = function intResolve(src, part, radix) { + return intOptions.asBigInt ? BigInt(src) : parseInt(part, radix); +}; + +function intStringify(node, radix, prefix) { + var value = node.value; + if (intIdentify(value) && value >= 0) return prefix + value.toString(radix); + return stringifyNumber(node); +} + +var nullObj = { + identify: function identify(value) { + return value == null; + }, + createNode: function createNode(schema, value, ctx) { + return ctx.wrapScalars ? new Scalar(null) : null; + }, + default: true, + tag: 'tag:yaml.org,2002:null', + test: /^(?:~|[Nn]ull|NULL)?$/, + resolve: function resolve() { + return null; + }, + options: nullOptions, + stringify: function stringify() { + return nullOptions.nullStr; + } +}; +var boolObj = { + identify: function identify(value) { + return typeof value === 'boolean'; + }, + default: true, + tag: 'tag:yaml.org,2002:bool', + test: /^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/, + resolve: function resolve(str) { + return str[0] === 't' || str[0] === 'T'; + }, + options: boolOptions, + stringify: function stringify(_ref) { + var value = _ref.value; + return value ? boolOptions.trueStr : boolOptions.falseStr; + } +}; +var octObj = { + identify: function identify(value) { + return intIdentify(value) && value >= 0; + }, + default: true, + tag: 'tag:yaml.org,2002:int', + format: 'OCT', + test: /^0o([0-7]+)$/, + resolve: function resolve(str, oct) { + return intResolve(str, oct, 8); + }, + options: intOptions, + stringify: function stringify(node) { + return intStringify(node, 8, '0o'); + } +}; +var intObj = { + identify: intIdentify, + default: true, + tag: 'tag:yaml.org,2002:int', + test: /^[-+]?[0-9]+$/, + resolve: function resolve(str) { + return intResolve(str, str, 10); + }, + options: intOptions, + stringify: stringifyNumber +}; +var hexObj = { + identify: function identify(value) { + return intIdentify(value) && value >= 0; + }, + default: true, + tag: 'tag:yaml.org,2002:int', + format: 'HEX', + test: /^0x([0-9a-fA-F]+)$/, + resolve: function resolve(str, hex) { + return intResolve(str, hex, 16); + }, + options: intOptions, + stringify: function stringify(node) { + return intStringify(node, 16, '0x'); + } +}; +var nanObj = { + identify: function identify(value) { + return typeof value === 'number'; + }, + default: true, + tag: 'tag:yaml.org,2002:float', + test: /^(?:[-+]?\.inf|(\.nan))$/i, + resolve: function resolve(str, nan) { + return nan ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY; + }, + stringify: stringifyNumber +}; +var expObj = { + identify: function identify(value) { + return typeof value === 'number'; + }, + default: true, + tag: 'tag:yaml.org,2002:float', + format: 'EXP', + test: /^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/, + resolve: function resolve(str) { + return parseFloat(str); + }, + stringify: function stringify(_ref2) { + var value = _ref2.value; + return Number(value).toExponential(); + } +}; +var floatObj = { + identify: function identify(value) { + return typeof value === 'number'; + }, + default: true, + tag: 'tag:yaml.org,2002:float', + test: /^[-+]?(?:\.([0-9]+)|[0-9]+\.([0-9]*))$/, + resolve: function resolve(str, frac1, frac2) { + var frac = frac1 || frac2; + var node = new Scalar(parseFloat(str)); + if (frac && frac[frac.length - 1] === '0') node.minFractionDigits = frac.length; + return node; + }, + stringify: stringifyNumber +}; +var core = failsafe.concat([nullObj, boolObj, octObj, intObj, hexObj, nanObj, expObj, floatObj]); + +/* global BigInt */ + +var intIdentify$1 = function intIdentify(value) { + return typeof value === 'bigint' || Number.isInteger(value); +}; + +var stringifyJSON = function stringifyJSON(_ref) { + var value = _ref.value; + return JSON.stringify(value); +}; + +var json = [map, seq, { + identify: function identify(value) { + return typeof value === 'string'; + }, + default: true, + tag: 'tag:yaml.org,2002:str', + resolve: resolveString, + stringify: stringifyJSON +}, { + identify: function identify(value) { + return value == null; + }, + createNode: function createNode(schema, value, ctx) { + return ctx.wrapScalars ? new Scalar(null) : null; + }, + default: true, + tag: 'tag:yaml.org,2002:null', + test: /^null$/, + resolve: function resolve() { + return null; + }, + stringify: stringifyJSON +}, { + identify: function identify(value) { + return typeof value === 'boolean'; + }, + default: true, + tag: 'tag:yaml.org,2002:bool', + test: /^true|false$/, + resolve: function resolve(str) { + return str === 'true'; + }, + stringify: stringifyJSON +}, { + identify: intIdentify$1, + default: true, + tag: 'tag:yaml.org,2002:int', + test: /^-?(?:0|[1-9][0-9]*)$/, + resolve: function resolve(str) { + return intOptions.asBigInt ? BigInt(str) : parseInt(str, 10); + }, + stringify: function stringify(_ref2) { + var value = _ref2.value; + return intIdentify$1(value) ? value.toString() : JSON.stringify(value); + } +}, { + identify: function identify(value) { + return typeof value === 'number'; + }, + default: true, + tag: 'tag:yaml.org,2002:float', + test: /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/, + resolve: function resolve(str) { + return parseFloat(str); + }, + stringify: stringifyJSON +}]; + +json.scalarFallback = function (str) { + throw new SyntaxError("Unresolved plain scalar ".concat(JSON.stringify(str))); +}; + +/* global BigInt */ + +var boolStringify = function boolStringify(_ref) { + var value = _ref.value; + return value ? boolOptions.trueStr : boolOptions.falseStr; +}; + +var intIdentify$2 = function intIdentify(value) { + return typeof value === 'bigint' || Number.isInteger(value); +}; + +function intResolve$1(sign, src, radix) { + var str = src.replace(/_/g, ''); + + if (intOptions.asBigInt) { + switch (radix) { + case 2: + str = "0b".concat(str); + break; + + case 8: + str = "0o".concat(str); + break; + + case 16: + str = "0x".concat(str); + break; + } + + var _n = BigInt(str); + + return sign === '-' ? BigInt(-1) * _n : _n; + } + + var n = parseInt(str, radix); + return sign === '-' ? -1 * n : n; +} + +function intStringify$1(node, radix, prefix) { + var value = node.value; + + if (intIdentify$2(value)) { + var str = value.toString(radix); + return value < 0 ? '-' + prefix + str.substr(1) : prefix + str; + } + + return stringifyNumber(node); +} + +var yaml11 = failsafe.concat([{ + identify: function identify(value) { + return value == null; + }, + createNode: function createNode(schema, value, ctx) { + return ctx.wrapScalars ? new Scalar(null) : null; + }, + default: true, + tag: 'tag:yaml.org,2002:null', + test: /^(?:~|[Nn]ull|NULL)?$/, + resolve: function resolve() { + return null; + }, + options: nullOptions, + stringify: function stringify() { + return nullOptions.nullStr; + } +}, { + identify: function identify(value) { + return typeof value === 'boolean'; + }, + default: true, + tag: 'tag:yaml.org,2002:bool', + test: /^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/, + resolve: function resolve() { + return true; + }, + options: boolOptions, + stringify: boolStringify +}, { + identify: function identify(value) { + return typeof value === 'boolean'; + }, + default: true, + tag: 'tag:yaml.org,2002:bool', + test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/i, + resolve: function resolve() { + return false; + }, + options: boolOptions, + stringify: boolStringify +}, { + identify: intIdentify$2, + default: true, + tag: 'tag:yaml.org,2002:int', + format: 'BIN', + test: /^([-+]?)0b([0-1_]+)$/, + resolve: function resolve(str, sign, bin) { + return intResolve$1(sign, bin, 2); + }, + stringify: function stringify(node) { + return intStringify$1(node, 2, '0b'); + } +}, { + identify: intIdentify$2, + default: true, + tag: 'tag:yaml.org,2002:int', + format: 'OCT', + test: /^([-+]?)0([0-7_]+)$/, + resolve: function resolve(str, sign, oct) { + return intResolve$1(sign, oct, 8); + }, + stringify: function stringify(node) { + return intStringify$1(node, 8, '0'); + } +}, { + identify: intIdentify$2, + default: true, + tag: 'tag:yaml.org,2002:int', + test: /^([-+]?)([0-9][0-9_]*)$/, + resolve: function resolve(str, sign, abs) { + return intResolve$1(sign, abs, 10); + }, + stringify: stringifyNumber +}, { + identify: intIdentify$2, + default: true, + tag: 'tag:yaml.org,2002:int', + format: 'HEX', + test: /^([-+]?)0x([0-9a-fA-F_]+)$/, + resolve: function resolve(str, sign, hex) { + return intResolve$1(sign, hex, 16); + }, + stringify: function stringify(node) { + return intStringify$1(node, 16, '0x'); + } +}, { + identify: function identify(value) { + return typeof value === 'number'; + }, + default: true, + tag: 'tag:yaml.org,2002:float', + test: /^(?:[-+]?\.inf|(\.nan))$/i, + resolve: function resolve(str, nan) { + return nan ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY; + }, + stringify: stringifyNumber +}, { + identify: function identify(value) { + return typeof value === 'number'; + }, + default: true, + tag: 'tag:yaml.org,2002:float', + format: 'EXP', + test: /^[-+]?([0-9][0-9_]*)?(\.[0-9_]*)?[eE][-+]?[0-9]+$/, + resolve: function resolve(str) { + return parseFloat(str.replace(/_/g, '')); + }, + stringify: function stringify(_ref2) { + var value = _ref2.value; + return Number(value).toExponential(); + } +}, { + identify: function identify(value) { + return typeof value === 'number'; + }, + default: true, + tag: 'tag:yaml.org,2002:float', + test: /^[-+]?(?:[0-9][0-9_]*)?\.([0-9_]*)$/, + resolve: function resolve(str, frac) { + var node = new Scalar(parseFloat(str.replace(/_/g, ''))); + + if (frac) { + var f = frac.replace(/_/g, ''); + if (f[f.length - 1] === '0') node.minFractionDigits = f.length; + } + + return node; + }, + stringify: stringifyNumber +}], binary, omap, pairs, set, intTime, floatTime, timestamp); + +var schemas = { + core: core, + failsafe: failsafe, + json: json, + yaml11: yaml11 +}; +var tags = { + binary: binary, + bool: boolObj, + float: floatObj, + floatExp: expObj, + floatNaN: nanObj, + floatTime: floatTime, + int: intObj, + intHex: hexObj, + intOct: octObj, + intTime: intTime, + map: map, + null: nullObj, + omap: omap, + pairs: pairs, + seq: seq, + set: set, + timestamp: timestamp +}; + +function findTagObject(value, tagName, tags) { + if (tagName) { + var match = tags.filter(function (t) { + return t.tag === tagName; + }); + var tagObj = match.find(function (t) { + return !t.format; + }) || match[0]; + if (!tagObj) throw new Error("Tag ".concat(tagName, " not found")); + return tagObj; + } // TODO: deprecate/remove class check + + + return tags.find(function (t) { + return (t.identify && t.identify(value) || t.class && value instanceof t.class) && !t.format; + }); +} + +function createNode(value, tagName, ctx) { + if (value instanceof Node) return value; + var defaultPrefix = ctx.defaultPrefix, + onTagObj = ctx.onTagObj, + prevObjects = ctx.prevObjects, + schema = ctx.schema, + wrapScalars = ctx.wrapScalars; + if (tagName && tagName.startsWith('!!')) tagName = defaultPrefix + tagName.slice(2); + var tagObj = findTagObject(value, tagName, schema.tags); + + if (!tagObj) { + if (typeof value.toJSON === 'function') value = value.toJSON(); + if (_typeof(value) !== 'object') return wrapScalars ? new Scalar(value) : value; + tagObj = value instanceof Map ? map : value[Symbol.iterator] ? seq : map; + } + + if (onTagObj) { + onTagObj(tagObj); + delete ctx.onTagObj; + } // Detect duplicate references to the same object & use Alias nodes for all + // after first. The `obj` wrapper allows for circular references to resolve. + + + var obj = {}; + + if (value && _typeof(value) === 'object' && prevObjects) { + var prev = prevObjects.get(value); + + if (prev) { + var alias = new Alias(prev); // leaves source dirty; must be cleaned by caller + + ctx.aliasNodes.push(alias); // defined along with prevObjects + + return alias; + } + + obj.value = value; + prevObjects.set(value, obj); + } + + obj.node = tagObj.createNode ? tagObj.createNode(ctx.schema, value, ctx) : wrapScalars ? new Scalar(value) : value; + if (tagName && obj.node instanceof Node) obj.node.tag = tagName; + return obj.node; +} + +function getSchemaTags(schemas, knownTags, customTags, schemaId) { + var tags = schemas[schemaId.replace(/\W/g, '')]; // 'yaml-1.1' -> 'yaml11' + + if (!tags) { + var keys = Object.keys(schemas).map(function (key) { + return JSON.stringify(key); + }).join(', '); + throw new Error("Unknown schema \"".concat(schemaId, "\"; use one of ").concat(keys)); + } + + if (Array.isArray(customTags)) { + var _iterator = _createForOfIteratorHelper(customTags), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var tag = _step.value; + tags = tags.concat(tag); + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + } else if (typeof customTags === 'function') { + tags = customTags(tags.slice()); + } + + for (var i = 0; i < tags.length; ++i) { + var _tag = tags[i]; + + if (typeof _tag === 'string') { + var tagObj = knownTags[_tag]; + + if (!tagObj) { + var _keys = Object.keys(knownTags).map(function (key) { + return JSON.stringify(key); + }).join(', '); + + throw new Error("Unknown custom tag \"".concat(_tag, "\"; use one of ").concat(_keys)); + } + + tags[i] = tagObj; + } + } + + return tags; +} + +var sortMapEntriesByKey = function sortMapEntriesByKey(a, b) { + return a.key < b.key ? -1 : a.key > b.key ? 1 : 0; +}; + +var Schema = /*#__PURE__*/function () { + // TODO: remove in v2 + // TODO: remove in v2 + function Schema(_ref) { + var customTags = _ref.customTags, + merge = _ref.merge, + schema = _ref.schema, + sortMapEntries = _ref.sortMapEntries, + deprecatedCustomTags = _ref.tags; + + _classCallCheck(this, Schema); + + this.merge = !!merge; + this.name = schema; + this.sortMapEntries = sortMapEntries === true ? sortMapEntriesByKey : sortMapEntries || null; + if (!customTags && deprecatedCustomTags) warnOptionDeprecation('tags', 'customTags'); + this.tags = getSchemaTags(schemas, tags, customTags || deprecatedCustomTags, schema); + } + + _createClass(Schema, [{ + key: "createNode", + value: function createNode$1(value, wrapScalars, tagName, ctx) { + var baseCtx = { + defaultPrefix: Schema.defaultPrefix, + schema: this, + wrapScalars: wrapScalars + }; + var createCtx = ctx ? Object.assign(ctx, baseCtx) : baseCtx; + return createNode(value, tagName, createCtx); + } + }, { + key: "createPair", + value: function createPair(key, value, ctx) { + if (!ctx) ctx = { + wrapScalars: true + }; + var k = this.createNode(key, ctx.wrapScalars, null, ctx); + var v = this.createNode(value, ctx.wrapScalars, null, ctx); + return new Pair(k, v); + } + }]); + + return Schema; +}(); + +_defineProperty(Schema, "defaultPrefix", defaultTagPrefix); + +_defineProperty(Schema, "defaultTags", defaultTags); + +export { Schema as S }; diff --git a/node_modules/yaml/browser/dist/index.js b/node_modules/yaml/browser/dist/index.js new file mode 100644 index 0000000..2d65436 --- /dev/null +++ b/node_modules/yaml/browser/dist/index.js @@ -0,0 +1,1004 @@ +import { d as defaultTagPrefix, _ as _createForOfIteratorHelper, a as _typeof, b as _createClass, c as _classCallCheck, e as _defineProperty, Y as YAMLSyntaxError, T as Type, f as YAMLWarning, g as YAMLSemanticError, h as _slicedToArray, i as YAMLError, j as _inherits, k as _createSuper } from './PlainValue-ff5147c6.js'; +import { parse as parse$1 } from './parse-cst.js'; +import { b as binaryOptions, a as boolOptions, i as intOptions, n as nullOptions, s as strOptions, N as Node, P as Pair, S as Scalar, c as stringifyString, A as Alias, Y as YAMLSeq, d as YAMLMap, M as Merge, C as Collection, r as resolveNode, e as isEmptyPath, t as toJSON, f as addComment } from './resolveSeq-04825f30.js'; +import { S as Schema } from './Schema-2bf2c74e.js'; +import { w as warn } from './warnings-0e4b70d3.js'; + +var defaultOptions = { + anchorPrefix: 'a', + customTags: null, + indent: 2, + indentSeq: true, + keepCstNodes: false, + keepNodeTypes: true, + keepBlobsInJSON: true, + mapAsMap: false, + maxAliasCount: 100, + prettyErrors: false, + // TODO Set true in v2 + simpleKeys: false, + version: '1.2' +}; +var scalarOptions = { + get binary() { + return binaryOptions; + }, + + set binary(opt) { + Object.assign(binaryOptions, opt); + }, + + get bool() { + return boolOptions; + }, + + set bool(opt) { + Object.assign(boolOptions, opt); + }, + + get int() { + return intOptions; + }, + + set int(opt) { + Object.assign(intOptions, opt); + }, + + get null() { + return nullOptions; + }, + + set null(opt) { + Object.assign(nullOptions, opt); + }, + + get str() { + return strOptions; + }, + + set str(opt) { + Object.assign(strOptions, opt); + } + +}; +var documentOptions = { + '1.0': { + schema: 'yaml-1.1', + merge: true, + tagPrefixes: [{ + handle: '!', + prefix: defaultTagPrefix + }, { + handle: '!!', + prefix: 'tag:private.yaml.org,2002:' + }] + }, + '1.1': { + schema: 'yaml-1.1', + merge: true, + tagPrefixes: [{ + handle: '!', + prefix: '!' + }, { + handle: '!!', + prefix: defaultTagPrefix + }] + }, + '1.2': { + schema: 'core', + merge: false, + tagPrefixes: [{ + handle: '!', + prefix: '!' + }, { + handle: '!!', + prefix: defaultTagPrefix + }] + } +}; + +function stringifyTag(doc, tag) { + if ((doc.version || doc.options.version) === '1.0') { + var priv = tag.match(/^tag:private\.yaml\.org,2002:([^:/]+)$/); + if (priv) return '!' + priv[1]; + var vocab = tag.match(/^tag:([a-zA-Z0-9-]+)\.yaml\.org,2002:(.*)/); + return vocab ? "!".concat(vocab[1], "/").concat(vocab[2]) : "!".concat(tag.replace(/^tag:/, '')); + } + + var p = doc.tagPrefixes.find(function (p) { + return tag.indexOf(p.prefix) === 0; + }); + + if (!p) { + var dtp = doc.getDefaults().tagPrefixes; + p = dtp && dtp.find(function (p) { + return tag.indexOf(p.prefix) === 0; + }); + } + + if (!p) return tag[0] === '!' ? tag : "!<".concat(tag, ">"); + var suffix = tag.substr(p.prefix.length).replace(/[!,[\]{}]/g, function (ch) { + return { + '!': '%21', + ',': '%2C', + '[': '%5B', + ']': '%5D', + '{': '%7B', + '}': '%7D' + }[ch]; + }); + return p.handle + suffix; +} + +function getTagObject(tags, item) { + if (item instanceof Alias) return Alias; + + if (item.tag) { + var match = tags.filter(function (t) { + return t.tag === item.tag; + }); + if (match.length > 0) return match.find(function (t) { + return t.format === item.format; + }) || match[0]; + } + + var tagObj, obj; + + if (item instanceof Scalar) { + obj = item.value; // TODO: deprecate/remove class check + + var _match = tags.filter(function (t) { + return t.identify && t.identify(obj) || t.class && obj instanceof t.class; + }); + + tagObj = _match.find(function (t) { + return t.format === item.format; + }) || _match.find(function (t) { + return !t.format; + }); + } else { + obj = item; + tagObj = tags.find(function (t) { + return t.nodeClass && obj instanceof t.nodeClass; + }); + } + + if (!tagObj) { + var name = obj && obj.constructor ? obj.constructor.name : _typeof(obj); + throw new Error("Tag not resolved for ".concat(name, " value")); + } + + return tagObj; +} // needs to be called before value stringifier to allow for circular anchor refs + + +function stringifyProps(node, tagObj, _ref) { + var anchors = _ref.anchors, + doc = _ref.doc; + var props = []; + var anchor = doc.anchors.getName(node); + + if (anchor) { + anchors[anchor] = node; + props.push("&".concat(anchor)); + } + + if (node.tag) { + props.push(stringifyTag(doc, node.tag)); + } else if (!tagObj.default) { + props.push(stringifyTag(doc, tagObj.tag)); + } + + return props.join(' '); +} + +function stringify(item, ctx, onComment, onChompKeep) { + var _ctx$doc = ctx.doc, + anchors = _ctx$doc.anchors, + schema = _ctx$doc.schema; + var tagObj; + + if (!(item instanceof Node)) { + var createCtx = { + aliasNodes: [], + onTagObj: function onTagObj(o) { + return tagObj = o; + }, + prevObjects: new Map() + }; + item = schema.createNode(item, true, null, createCtx); + + var _iterator = _createForOfIteratorHelper(createCtx.aliasNodes), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var alias = _step.value; + alias.source = alias.source.node; + var name = anchors.getName(alias.source); + + if (!name) { + name = anchors.newName(); + anchors.map[name] = alias.source; + } + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + } + + if (item instanceof Pair) return item.toString(ctx, onComment, onChompKeep); + if (!tagObj) tagObj = getTagObject(schema.tags, item); + var props = stringifyProps(item, tagObj, ctx); + if (props.length > 0) ctx.indentAtStart = (ctx.indentAtStart || 0) + props.length + 1; + 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); + if (!props) return str; + return item instanceof Scalar || str[0] === '{' || str[0] === '[' ? "".concat(props, " ").concat(str) : "".concat(props, "\n").concat(ctx.indent).concat(str); +} + +var Anchors = /*#__PURE__*/function () { + _createClass(Anchors, null, [{ + key: "validAnchorNode", + value: function validAnchorNode(node) { + return node instanceof Scalar || node instanceof YAMLSeq || node instanceof YAMLMap; + } + }]); + + function Anchors(prefix) { + _classCallCheck(this, Anchors); + + _defineProperty(this, "map", {}); + + this.prefix = prefix; + } + + _createClass(Anchors, [{ + key: "createAlias", + value: function createAlias(node, name) { + this.setAnchor(node, name); + return new Alias(node); + } + }, { + key: "createMergePair", + value: function createMergePair() { + var _this = this; + + var merge = new Merge(); + + for (var _len = arguments.length, sources = new Array(_len), _key = 0; _key < _len; _key++) { + sources[_key] = arguments[_key]; + } + + merge.value.items = sources.map(function (s) { + if (s instanceof Alias) { + if (s.source instanceof YAMLMap) return s; + } else if (s instanceof YAMLMap) { + return _this.createAlias(s); + } + + throw new Error('Merge sources must be Map nodes or their Aliases'); + }); + return merge; + } + }, { + key: "getName", + value: function getName(node) { + var map = this.map; + return Object.keys(map).find(function (a) { + return map[a] === node; + }); + } + }, { + key: "getNames", + value: function getNames() { + return Object.keys(this.map); + } + }, { + key: "getNode", + value: function getNode(name) { + return this.map[name]; + } + }, { + key: "newName", + value: function newName(prefix) { + if (!prefix) prefix = this.prefix; + var names = Object.keys(this.map); + + for (var i = 1; true; ++i) { + var name = "".concat(prefix).concat(i); + if (!names.includes(name)) return name; + } + } // During parsing, map & aliases contain CST nodes + + }, { + key: "resolveNodes", + value: function resolveNodes() { + var map = this.map, + _cstAliases = this._cstAliases; + Object.keys(map).forEach(function (a) { + map[a] = map[a].resolved; + }); + + _cstAliases.forEach(function (a) { + a.source = a.source.resolved; + }); + + delete this._cstAliases; + } + }, { + key: "setAnchor", + value: function setAnchor(node, name) { + if (node != null && !Anchors.validAnchorNode(node)) { + throw new Error('Anchors may only be set for Scalar, Seq and Map nodes'); + } + + if (name && /[\x00-\x19\s,[\]{}]/.test(name)) { + throw new Error('Anchor names must not contain whitespace or control characters'); + } + + var map = this.map; + var prev = node && Object.keys(map).find(function (a) { + return map[a] === node; + }); + + if (prev) { + if (!name) { + return prev; + } else if (prev !== name) { + delete map[prev]; + map[name] = node; + } + } else { + if (!name) { + if (!node) return null; + name = this.newName(); + } + + map[name] = node; + } + + return name; + } + }]); + + return Anchors; +}(); + +var visit = function visit(node, tags) { + if (node && _typeof(node) === 'object') { + var tag = node.tag; + + if (node instanceof Collection) { + if (tag) tags[tag] = true; + node.items.forEach(function (n) { + return visit(n, tags); + }); + } else if (node instanceof Pair) { + visit(node.key, tags); + visit(node.value, tags); + } else if (node instanceof Scalar) { + if (tag) tags[tag] = true; + } + } + + return tags; +}; + +var listTagNames = function listTagNames(node) { + return Object.keys(visit(node, {})); +}; + +function parseContents(doc, contents) { + var comments = { + before: [], + after: [] + }; + var body = undefined; + var spaceBefore = false; + + var _iterator = _createForOfIteratorHelper(contents), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var node = _step.value; + + if (node.valueRange) { + if (body !== undefined) { + var msg = 'Document contains trailing content not separated by a ... or --- line'; + doc.errors.push(new YAMLSyntaxError(node, msg)); + break; + } + + var res = resolveNode(doc, node); + + if (spaceBefore) { + res.spaceBefore = true; + spaceBefore = false; + } + + body = res; + } else if (node.comment !== null) { + var cc = body === undefined ? comments.before : comments.after; + cc.push(node.comment); + } else if (node.type === Type.BLANK_LINE) { + spaceBefore = true; + + if (body === undefined && comments.before.length > 0 && !doc.commentBefore) { + // space-separated comments at start are parsed as document comments + doc.commentBefore = comments.before.join('\n'); + comments.before = []; + } + } + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + + doc.contents = body || null; + + if (!body) { + doc.comment = comments.before.concat(comments.after).join('\n') || null; + } else { + var cb = comments.before.join('\n'); + + if (cb) { + var cbNode = body instanceof Collection && body.items[0] ? body.items[0] : body; + cbNode.commentBefore = cbNode.commentBefore ? "".concat(cb, "\n").concat(cbNode.commentBefore) : cb; + } + + doc.comment = comments.after.join('\n') || null; + } +} + +function resolveTagDirective(_ref, directive) { + var tagPrefixes = _ref.tagPrefixes; + + var _directive$parameters = _slicedToArray(directive.parameters, 2), + handle = _directive$parameters[0], + prefix = _directive$parameters[1]; + + if (!handle || !prefix) { + var msg = 'Insufficient parameters given for %TAG directive'; + throw new YAMLSemanticError(directive, msg); + } + + if (tagPrefixes.some(function (p) { + return p.handle === handle; + })) { + var _msg = 'The %TAG directive must only be given at most once per handle in the same document.'; + throw new YAMLSemanticError(directive, _msg); + } + + return { + handle: handle, + prefix: prefix + }; +} + +function resolveYamlDirective(doc, directive) { + var _directive$parameters2 = _slicedToArray(directive.parameters, 1), + version = _directive$parameters2[0]; + + if (directive.name === 'YAML:1.0') version = '1.0'; + + if (!version) { + var msg = 'Insufficient parameters given for %YAML directive'; + throw new YAMLSemanticError(directive, msg); + } + + if (!documentOptions[version]) { + var v0 = doc.version || doc.options.version; + + var _msg2 = "Document will be parsed as YAML ".concat(v0, " rather than YAML ").concat(version); + + doc.warnings.push(new YAMLWarning(directive, _msg2)); + } + + return version; +} + +function parseDirectives(doc, directives, prevDoc) { + var directiveComments = []; + var hasDirectives = false; + + var _iterator = _createForOfIteratorHelper(directives), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var directive = _step.value; + var comment = directive.comment, + name = directive.name; + + switch (name) { + case 'TAG': + try { + doc.tagPrefixes.push(resolveTagDirective(doc, directive)); + } catch (error) { + doc.errors.push(error); + } + + hasDirectives = true; + break; + + case 'YAML': + case 'YAML:1.0': + if (doc.version) { + var msg = 'The %YAML directive must only be given at most once per document.'; + doc.errors.push(new YAMLSemanticError(directive, msg)); + } + + try { + doc.version = resolveYamlDirective(doc, directive); + } catch (error) { + doc.errors.push(error); + } + + hasDirectives = true; + break; + + default: + if (name) { + var _msg3 = "YAML only supports %TAG and %YAML directives, and not %".concat(name); + + doc.warnings.push(new YAMLWarning(directive, _msg3)); + } + + } + + if (comment) directiveComments.push(comment); + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + + if (prevDoc && !hasDirectives && '1.1' === (doc.version || prevDoc.version || doc.options.version)) { + var copyTagPrefix = function copyTagPrefix(_ref2) { + var handle = _ref2.handle, + prefix = _ref2.prefix; + return { + handle: handle, + prefix: prefix + }; + }; + + doc.tagPrefixes = prevDoc.tagPrefixes.map(copyTagPrefix); + doc.version = prevDoc.version; + } + + doc.commentBefore = directiveComments.join('\n') || null; +} + +function assertCollection(contents) { + if (contents instanceof Collection) return true; + throw new Error('Expected a YAML collection as document contents'); +} + +var Document = /*#__PURE__*/function () { + function Document(options) { + _classCallCheck(this, Document); + + this.anchors = new Anchors(options.anchorPrefix); + this.commentBefore = null; + this.comment = null; + this.contents = null; + this.directivesEndMarker = null; + this.errors = []; + this.options = options; + this.schema = null; + this.tagPrefixes = []; + this.version = null; + this.warnings = []; + } + + _createClass(Document, [{ + key: "add", + value: function add(value) { + assertCollection(this.contents); + return this.contents.add(value); + } + }, { + key: "addIn", + value: function addIn(path, value) { + assertCollection(this.contents); + this.contents.addIn(path, value); + } + }, { + key: "delete", + value: function _delete(key) { + assertCollection(this.contents); + return this.contents.delete(key); + } + }, { + key: "deleteIn", + value: function deleteIn(path) { + if (isEmptyPath(path)) { + if (this.contents == null) return false; + this.contents = null; + return true; + } + + assertCollection(this.contents); + return this.contents.deleteIn(path); + } + }, { + key: "getDefaults", + value: function getDefaults() { + return Document.defaults[this.version] || Document.defaults[this.options.version] || {}; + } + }, { + key: "get", + value: function get(key, keepScalar) { + return this.contents instanceof Collection ? this.contents.get(key, keepScalar) : undefined; + } + }, { + key: "getIn", + value: function getIn(path, keepScalar) { + if (isEmptyPath(path)) return !keepScalar && this.contents instanceof Scalar ? this.contents.value : this.contents; + return this.contents instanceof Collection ? this.contents.getIn(path, keepScalar) : undefined; + } + }, { + key: "has", + value: function has(key) { + return this.contents instanceof Collection ? this.contents.has(key) : false; + } + }, { + key: "hasIn", + value: function hasIn(path) { + if (isEmptyPath(path)) return this.contents !== undefined; + return this.contents instanceof Collection ? this.contents.hasIn(path) : false; + } + }, { + key: "set", + value: function set(key, value) { + assertCollection(this.contents); + this.contents.set(key, value); + } + }, { + key: "setIn", + value: function setIn(path, value) { + if (isEmptyPath(path)) this.contents = value;else { + assertCollection(this.contents); + this.contents.setIn(path, value); + } + } + }, { + key: "setSchema", + value: function setSchema(id, customTags) { + if (!id && !customTags && this.schema) return; + if (typeof id === 'number') id = id.toFixed(1); + + if (id === '1.0' || id === '1.1' || id === '1.2') { + if (this.version) this.version = id;else this.options.version = id; + delete this.options.schema; + } else if (id && typeof id === 'string') { + this.options.schema = id; + } + + if (Array.isArray(customTags)) this.options.customTags = customTags; + var opt = Object.assign({}, this.getDefaults(), this.options); + this.schema = new Schema(opt); + } + }, { + key: "parse", + value: function parse(node, prevDoc) { + if (this.options.keepCstNodes) this.cstNode = node; + if (this.options.keepNodeTypes) this.type = 'DOCUMENT'; + var _node$directives = node.directives, + directives = _node$directives === void 0 ? [] : _node$directives, + _node$contents = node.contents, + contents = _node$contents === void 0 ? [] : _node$contents, + directivesEndMarker = node.directivesEndMarker, + error = node.error, + valueRange = node.valueRange; + + if (error) { + if (!error.source) error.source = this; + this.errors.push(error); + } + + parseDirectives(this, directives, prevDoc); + if (directivesEndMarker) this.directivesEndMarker = true; + this.range = valueRange ? [valueRange.start, valueRange.end] : null; + this.setSchema(); + this.anchors._cstAliases = []; + parseContents(this, contents); + this.anchors.resolveNodes(); + + if (this.options.prettyErrors) { + var _iterator = _createForOfIteratorHelper(this.errors), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var _error = _step.value; + if (_error instanceof YAMLError) _error.makePretty(); + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + + var _iterator2 = _createForOfIteratorHelper(this.warnings), + _step2; + + try { + for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { + var warn = _step2.value; + if (warn instanceof YAMLError) warn.makePretty(); + } + } catch (err) { + _iterator2.e(err); + } finally { + _iterator2.f(); + } + } + + return this; + } + }, { + key: "listNonDefaultTags", + value: function listNonDefaultTags() { + return listTagNames(this.contents).filter(function (t) { + return t.indexOf(Schema.defaultPrefix) !== 0; + }); + } + }, { + key: "setTagPrefix", + value: function setTagPrefix(handle, prefix) { + if (handle[0] !== '!' || handle[handle.length - 1] !== '!') throw new Error('Handle must start and end with !'); + + if (prefix) { + var prev = this.tagPrefixes.find(function (p) { + return p.handle === handle; + }); + if (prev) prev.prefix = prefix;else this.tagPrefixes.push({ + handle: handle, + prefix: prefix + }); + } else { + this.tagPrefixes = this.tagPrefixes.filter(function (p) { + return p.handle !== handle; + }); + } + } + }, { + key: "toJSON", + value: function toJSON$1(arg, onAnchor) { + var _this = this; + + var _this$options = this.options, + keepBlobsInJSON = _this$options.keepBlobsInJSON, + mapAsMap = _this$options.mapAsMap, + maxAliasCount = _this$options.maxAliasCount; + var keep = keepBlobsInJSON && (typeof arg !== 'string' || !(this.contents instanceof Scalar)); + var ctx = { + doc: this, + indentStep: ' ', + keep: keep, + mapAsMap: keep && !!mapAsMap, + maxAliasCount: maxAliasCount, + stringify: stringify // Requiring directly in Pair would create circular dependencies + + }; + var anchorNames = Object.keys(this.anchors.map); + if (anchorNames.length > 0) ctx.anchors = new Map(anchorNames.map(function (name) { + return [_this.anchors.map[name], { + alias: [], + aliasCount: 0, + count: 1 + }]; + })); + + var res = toJSON(this.contents, arg, ctx); + + if (typeof onAnchor === 'function' && ctx.anchors) { + var _iterator3 = _createForOfIteratorHelper(ctx.anchors.values()), + _step3; + + try { + for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { + var _step3$value = _step3.value, + count = _step3$value.count, + _res = _step3$value.res; + onAnchor(_res, count); + } + } catch (err) { + _iterator3.e(err); + } finally { + _iterator3.f(); + } + } + + return res; + } + }, { + key: "toString", + value: function toString() { + if (this.errors.length > 0) throw new Error('Document with errors cannot be stringified'); + var indentSize = this.options.indent; + + if (!Number.isInteger(indentSize) || indentSize <= 0) { + var s = JSON.stringify(indentSize); + throw new Error("\"indent\" option must be a positive integer, not ".concat(s)); + } + + this.setSchema(); + var lines = []; + var hasDirectives = false; + + if (this.version) { + var vd = '%YAML 1.2'; + + if (this.schema.name === 'yaml-1.1') { + if (this.version === '1.0') vd = '%YAML:1.0';else if (this.version === '1.1') vd = '%YAML 1.1'; + } + + lines.push(vd); + hasDirectives = true; + } + + var tagNames = this.listNonDefaultTags(); + this.tagPrefixes.forEach(function (_ref) { + var handle = _ref.handle, + prefix = _ref.prefix; + + if (tagNames.some(function (t) { + return t.indexOf(prefix) === 0; + })) { + lines.push("%TAG ".concat(handle, " ").concat(prefix)); + hasDirectives = true; + } + }); + if (hasDirectives || this.directivesEndMarker) lines.push('---'); + + if (this.commentBefore) { + if (hasDirectives || !this.directivesEndMarker) lines.unshift(''); + lines.unshift(this.commentBefore.replace(/^/gm, '#')); + } + + var ctx = { + anchors: {}, + doc: this, + indent: '', + indentStep: ' '.repeat(indentSize), + stringify: stringify // Requiring directly in nodes would create circular dependencies + + }; + var chompKeep = false; + var contentComment = null; + + if (this.contents) { + if (this.contents instanceof Node) { + if (this.contents.spaceBefore && (hasDirectives || this.directivesEndMarker)) lines.push(''); + if (this.contents.commentBefore) lines.push(this.contents.commentBefore.replace(/^/gm, '#')); // top-level block scalars need to be indented if followed by a comment + + ctx.forceBlockIndent = !!this.comment; + contentComment = this.contents.comment; + } + + var onChompKeep = contentComment ? null : function () { + return chompKeep = true; + }; + var body = stringify(this.contents, ctx, function () { + return contentComment = null; + }, onChompKeep); + lines.push(addComment(body, '', contentComment)); + } else if (this.contents !== undefined) { + lines.push(stringify(this.contents, ctx)); + } + + if (this.comment) { + if ((!chompKeep || contentComment) && lines[lines.length - 1] !== '') lines.push(''); + lines.push(this.comment.replace(/^/gm, '#')); + } + + return lines.join('\n') + '\n'; + } + }]); + + return Document; +}(); + +_defineProperty(Document, "defaults", documentOptions); + +function createNode(value) { + var wrapScalars = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; + var tag = arguments.length > 2 ? arguments[2] : undefined; + + if (tag === undefined && typeof wrapScalars === 'string') { + tag = wrapScalars; + wrapScalars = true; + } + + var options = Object.assign({}, Document.defaults[defaultOptions.version], defaultOptions); + var schema = new Schema(options); + return schema.createNode(value, wrapScalars, tag); +} + +var Document$1 = /*#__PURE__*/function (_YAMLDocument) { + _inherits(Document, _YAMLDocument); + + var _super = _createSuper(Document); + + function Document(options) { + _classCallCheck(this, Document); + + return _super.call(this, Object.assign({}, defaultOptions, options)); + } + + return Document; +}(Document); + +function parseAllDocuments(src, options) { + var stream = []; + var prev; + + var _iterator = _createForOfIteratorHelper(parse$1(src)), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var cstDoc = _step.value; + var doc = new Document$1(options); + doc.parse(cstDoc, prev); + stream.push(doc); + prev = doc; + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + + return stream; +} + +function parseDocument(src, options) { + var cst = parse$1(src); + var doc = new Document$1(options).parse(cst[0]); + + if (cst.length > 1) { + var errMsg = 'Source contains multiple documents; please use YAML.parseAllDocuments()'; + doc.errors.unshift(new YAMLSemanticError(cst[1], errMsg)); + } + + return doc; +} + +function parse(src, options) { + var doc = parseDocument(src, options); + doc.warnings.forEach(function (warning) { + return warn(warning); + }); + if (doc.errors.length > 0) throw doc.errors[0]; + return doc.toJSON(); +} + +function stringify$1(value, options) { + var doc = new Document$1(options); + doc.contents = value; + return String(doc); +} + +var YAML = { + createNode: createNode, + defaultOptions: defaultOptions, + Document: Document$1, + parse: parse, + parseAllDocuments: parseAllDocuments, + parseCST: parse$1, + parseDocument: parseDocument, + scalarOptions: scalarOptions, + stringify: stringify$1 +}; + +export { YAML }; diff --git a/node_modules/yaml/browser/dist/legacy-exports.js b/node_modules/yaml/browser/dist/legacy-exports.js new file mode 100644 index 0000000..8824264 --- /dev/null +++ b/node_modules/yaml/browser/dist/legacy-exports.js @@ -0,0 +1,3 @@ +import './PlainValue-ff5147c6.js'; +import './resolveSeq-04825f30.js'; +export { b as binary, f as floatTime, i as intTime, o as omap, p as pairs, s as set, t as timestamp, c as warnFileDeprecation } from './warnings-0e4b70d3.js'; diff --git a/node_modules/yaml/browser/dist/parse-cst.js b/node_modules/yaml/browser/dist/parse-cst.js new file mode 100644 index 0000000..2789fad --- /dev/null +++ b/node_modules/yaml/browser/dist/parse-cst.js @@ -0,0 +1,1904 @@ +import { j as _inherits, k as _createSuper, c as _classCallCheck, T as Type, b as _createClass, R as Range, N as Node, g as YAMLSemanticError, l as _get, m as _getPrototypeOf, Y as YAMLSyntaxError, C as Char, e as _defineProperty, P as PlainValue } from './PlainValue-ff5147c6.js'; + +var BlankLine = /*#__PURE__*/function (_Node) { + _inherits(BlankLine, _Node); + + var _super = _createSuper(BlankLine); + + function BlankLine() { + _classCallCheck(this, BlankLine); + + return _super.call(this, Type.BLANK_LINE); + } + /* istanbul ignore next */ + + + _createClass(BlankLine, [{ + key: "parse", + + /** + * Parses a blank line from the source + * + * @param {ParseContext} context + * @param {number} start - Index of first \n character + * @returns {number} - Index of the character after this + */ + value: function parse(context, start) { + this.context = context; + this.range = new Range(start, start + 1); + return start + 1; + } + }, { + key: "includesTrailingLines", + get: function get() { + // This is never called from anywhere, but if it were, + // this is the value it should return. + return true; + } + }]); + + return BlankLine; +}(Node); + +var CollectionItem = /*#__PURE__*/function (_Node) { + _inherits(CollectionItem, _Node); + + var _super = _createSuper(CollectionItem); + + function CollectionItem(type, props) { + var _this; + + _classCallCheck(this, CollectionItem); + + _this = _super.call(this, type, props); + _this.node = null; + return _this; + } + + _createClass(CollectionItem, [{ + key: "parse", + + /** + * @param {ParseContext} context + * @param {number} start - Index of first character + * @returns {number} - Index of the character after this + */ + value: function parse(context, start) { + this.context = context; + var parseNode = context.parseNode, + src = context.src; + var atLineStart = context.atLineStart, + lineStart = context.lineStart; + if (!atLineStart && this.type === Type.SEQ_ITEM) this.error = new YAMLSemanticError(this, 'Sequence items must not have preceding content on the same line'); + var indent = atLineStart ? start - lineStart : context.indent; + var offset = Node.endOfWhiteSpace(src, start + 1); + var ch = src[offset]; + var inlineComment = ch === '#'; + var comments = []; + var blankLine = null; + + while (ch === '\n' || ch === '#') { + if (ch === '#') { + var _end = Node.endOfLine(src, offset + 1); + + comments.push(new Range(offset, _end)); + offset = _end; + } else { + atLineStart = true; + lineStart = offset + 1; + var wsEnd = Node.endOfWhiteSpace(src, lineStart); + + if (src[wsEnd] === '\n' && comments.length === 0) { + blankLine = new BlankLine(); + lineStart = blankLine.parse({ + src: src + }, lineStart); + } + + offset = Node.endOfIndent(src, lineStart); + } + + ch = src[offset]; + } + + if (Node.nextNodeIsIndented(ch, offset - (lineStart + indent), this.type !== Type.SEQ_ITEM)) { + this.node = parseNode({ + atLineStart: atLineStart, + inCollection: false, + indent: indent, + lineStart: lineStart, + parent: this + }, offset); + } else if (ch && lineStart > start + 1) { + offset = lineStart - 1; + } + + if (this.node) { + if (blankLine) { + // Only blank lines preceding non-empty nodes are captured. Note that + // this means that collection item range start indices do not always + // increase monotonically. -- eemeli/yaml#126 + var items = context.parent.items || context.parent.contents; + if (items) items.push(blankLine); + } + + if (comments.length) Array.prototype.push.apply(this.props, comments); + offset = this.node.range.end; + } else { + if (inlineComment) { + var c = comments[0]; + this.props.push(c); + offset = c.end; + } else { + offset = Node.endOfLine(src, start + 1); + } + } + + var end = this.node ? this.node.valueRange.end : offset; + this.valueRange = new Range(start, end); + return offset; + } + }, { + key: "setOrigRanges", + value: function setOrigRanges(cr, offset) { + offset = _get(_getPrototypeOf(CollectionItem.prototype), "setOrigRanges", this).call(this, cr, offset); + return this.node ? this.node.setOrigRanges(cr, offset) : offset; + } + }, { + key: "toString", + value: function toString() { + var src = this.context.src, + node = this.node, + range = this.range, + value = this.value; + if (value != null) return value; + var str = node ? src.slice(range.start, node.range.start) + String(node) : src.slice(range.start, range.end); + return Node.addStringTerminator(src, range.end, str); + } + }, { + key: "includesTrailingLines", + get: function get() { + return !!this.node && this.node.includesTrailingLines; + } + }]); + + return CollectionItem; +}(Node); + +var Comment = /*#__PURE__*/function (_Node) { + _inherits(Comment, _Node); + + var _super = _createSuper(Comment); + + function Comment() { + _classCallCheck(this, Comment); + + return _super.call(this, Type.COMMENT); + } + /** + * Parses a comment line from the source + * + * @param {ParseContext} context + * @param {number} start - Index of first character + * @returns {number} - Index of the character after this scalar + */ + + + _createClass(Comment, [{ + key: "parse", + value: function parse(context, start) { + this.context = context; + var offset = this.parseComment(start); + this.range = new Range(start, offset); + return offset; + } + }]); + + return Comment; +}(Node); + +function grabCollectionEndComments(node) { + var cnode = node; + + while (cnode instanceof CollectionItem) { + cnode = cnode.node; + } + + if (!(cnode instanceof Collection)) return null; + var len = cnode.items.length; + var ci = -1; + + for (var i = len - 1; i >= 0; --i) { + var n = cnode.items[i]; + + if (n.type === Type.COMMENT) { + // Keep sufficiently indented comments with preceding node + var _n$context = n.context, + indent = _n$context.indent, + lineStart = _n$context.lineStart; + if (indent > 0 && n.range.start >= lineStart + indent) break; + ci = i; + } else if (n.type === Type.BLANK_LINE) ci = i;else break; + } + + if (ci === -1) return null; + var ca = cnode.items.splice(ci, len - ci); + var prevEnd = ca[0].range.start; + + while (true) { + cnode.range.end = prevEnd; + if (cnode.valueRange && cnode.valueRange.end > prevEnd) cnode.valueRange.end = prevEnd; + if (cnode === node) break; + cnode = cnode.context.parent; + } + + return ca; +} +var Collection = /*#__PURE__*/function (_Node) { + _inherits(Collection, _Node); + + var _super = _createSuper(Collection); + + _createClass(Collection, null, [{ + key: "nextContentHasIndent", + value: function nextContentHasIndent(src, offset, indent) { + var lineStart = Node.endOfLine(src, offset) + 1; + offset = Node.endOfWhiteSpace(src, lineStart); + var ch = src[offset]; + if (!ch) return false; + if (offset >= lineStart + indent) return true; + if (ch !== '#' && ch !== '\n') return false; + return Collection.nextContentHasIndent(src, offset, indent); + } + }]); + + function Collection(firstItem) { + var _this; + + _classCallCheck(this, Collection); + + _this = _super.call(this, firstItem.type === Type.SEQ_ITEM ? Type.SEQ : Type.MAP); + + for (var i = firstItem.props.length - 1; i >= 0; --i) { + if (firstItem.props[i].start < firstItem.context.lineStart) { + // props on previous line are assumed by the collection + _this.props = firstItem.props.slice(0, i + 1); + firstItem.props = firstItem.props.slice(i + 1); + var itemRange = firstItem.props[0] || firstItem.valueRange; + firstItem.range.start = itemRange.start; + break; + } + } + + _this.items = [firstItem]; + var ec = grabCollectionEndComments(firstItem); + if (ec) Array.prototype.push.apply(_this.items, ec); + return _this; + } + + _createClass(Collection, [{ + key: "parse", + + /** + * @param {ParseContext} context + * @param {number} start - Index of first character + * @returns {number} - Index of the character after this + */ + value: function parse(context, start) { + this.context = context; + var parseNode = context.parseNode, + src = context.src; // It's easier to recalculate lineStart here rather than tracking down the + // last context from which to read it -- eemeli/yaml#2 + + var lineStart = Node.startOfLine(src, start); + var firstItem = this.items[0]; // First-item context needs to be correct for later comment handling + // -- eemeli/yaml#17 + + firstItem.context.parent = this; + this.valueRange = Range.copy(firstItem.valueRange); + var indent = firstItem.range.start - firstItem.context.lineStart; + var offset = start; + offset = Node.normalizeOffset(src, offset); + var ch = src[offset]; + var atLineStart = Node.endOfWhiteSpace(src, lineStart) === offset; + var prevIncludesTrailingLines = false; + + while (ch) { + while (ch === '\n' || ch === '#') { + if (atLineStart && ch === '\n' && !prevIncludesTrailingLines) { + var blankLine = new BlankLine(); + offset = blankLine.parse({ + src: src + }, offset); + this.valueRange.end = offset; + + if (offset >= src.length) { + ch = null; + break; + } + + this.items.push(blankLine); + offset -= 1; // blankLine.parse() consumes terminal newline + } else if (ch === '#') { + if (offset < lineStart + indent && !Collection.nextContentHasIndent(src, offset, indent)) { + return offset; + } + + var comment = new Comment(); + offset = comment.parse({ + indent: indent, + lineStart: lineStart, + src: src + }, offset); + this.items.push(comment); + this.valueRange.end = offset; + + if (offset >= src.length) { + ch = null; + break; + } + } + + lineStart = offset + 1; + offset = Node.endOfIndent(src, lineStart); + + if (Node.atBlank(src, offset)) { + var wsEnd = Node.endOfWhiteSpace(src, offset); + var next = src[wsEnd]; + + if (!next || next === '\n' || next === '#') { + offset = wsEnd; + } + } + + ch = src[offset]; + atLineStart = true; + } + + if (!ch) { + break; + } + + if (offset !== lineStart + indent && (atLineStart || ch !== ':')) { + if (offset < lineStart + indent) { + if (lineStart > start) offset = lineStart; + break; + } else if (!this.error) { + var msg = 'All collection items must start at the same column'; + this.error = new YAMLSyntaxError(this, msg); + } + } + + if (firstItem.type === Type.SEQ_ITEM) { + if (ch !== '-') { + if (lineStart > start) offset = lineStart; + break; + } + } else if (ch === '-' && !this.error) { + // map key may start with -, as long as it's followed by a non-whitespace char + var _next = src[offset + 1]; + + if (!_next || _next === '\n' || _next === '\t' || _next === ' ') { + var _msg = 'A collection cannot be both a mapping and a sequence'; + this.error = new YAMLSyntaxError(this, _msg); + } + } + + var node = parseNode({ + atLineStart: atLineStart, + inCollection: true, + indent: indent, + lineStart: lineStart, + parent: this + }, offset); + if (!node) return offset; // at next document start + + this.items.push(node); + this.valueRange.end = node.valueRange.end; + offset = Node.normalizeOffset(src, node.range.end); + ch = src[offset]; + atLineStart = false; + prevIncludesTrailingLines = node.includesTrailingLines; // Need to reset lineStart and atLineStart here if preceding node's range + // has advanced to check the current line's indentation level + // -- eemeli/yaml#10 & eemeli/yaml#38 + + if (ch) { + var ls = offset - 1; + var prev = src[ls]; + + while (prev === ' ' || prev === '\t') { + prev = src[--ls]; + } + + if (prev === '\n') { + lineStart = ls + 1; + atLineStart = true; + } + } + + var ec = grabCollectionEndComments(node); + if (ec) Array.prototype.push.apply(this.items, ec); + } + + return offset; + } + }, { + key: "setOrigRanges", + value: function setOrigRanges(cr, offset) { + offset = _get(_getPrototypeOf(Collection.prototype), "setOrigRanges", this).call(this, cr, offset); + this.items.forEach(function (node) { + offset = node.setOrigRanges(cr, offset); + }); + return offset; + } + }, { + key: "toString", + value: function toString() { + var src = this.context.src, + items = this.items, + range = this.range, + value = this.value; + if (value != null) return value; + var str = src.slice(range.start, items[0].range.start) + String(items[0]); + + for (var i = 1; i < items.length; ++i) { + var item = items[i]; + var _item$context = item.context, + atLineStart = _item$context.atLineStart, + indent = _item$context.indent; + if (atLineStart) for (var _i = 0; _i < indent; ++_i) { + str += ' '; + } + str += String(item); + } + + return Node.addStringTerminator(src, range.end, str); + } + }, { + key: "includesTrailingLines", + get: function get() { + return this.items.length > 0; + } + }]); + + return Collection; +}(Node); + +var Directive = /*#__PURE__*/function (_Node) { + _inherits(Directive, _Node); + + var _super = _createSuper(Directive); + + function Directive() { + var _this; + + _classCallCheck(this, Directive); + + _this = _super.call(this, Type.DIRECTIVE); + _this.name = null; + return _this; + } + + _createClass(Directive, [{ + key: "parseName", + value: function parseName(start) { + var src = this.context.src; + var offset = start; + var ch = src[offset]; + + while (ch && ch !== '\n' && ch !== '\t' && ch !== ' ') { + ch = src[offset += 1]; + } + + this.name = src.slice(start, offset); + return offset; + } + }, { + key: "parseParameters", + value: function parseParameters(start) { + var src = this.context.src; + var offset = start; + var ch = src[offset]; + + while (ch && ch !== '\n' && ch !== '#') { + ch = src[offset += 1]; + } + + this.valueRange = new Range(start, offset); + return offset; + } + }, { + key: "parse", + value: function parse(context, start) { + this.context = context; + var offset = this.parseName(start + 1); + offset = this.parseParameters(offset); + offset = this.parseComment(offset); + this.range = new Range(start, offset); + return offset; + } + }, { + key: "parameters", + get: function get() { + var raw = this.rawValue; + return raw ? raw.trim().split(/[ \t]+/) : []; + } + }]); + + return Directive; +}(Node); + +var Document = /*#__PURE__*/function (_Node) { + _inherits(Document, _Node); + + var _super = _createSuper(Document); + + _createClass(Document, null, [{ + key: "startCommentOrEndBlankLine", + value: function startCommentOrEndBlankLine(src, start) { + var offset = Node.endOfWhiteSpace(src, start); + var ch = src[offset]; + return ch === '#' || ch === '\n' ? offset : start; + } + }]); + + function Document() { + var _this; + + _classCallCheck(this, Document); + + _this = _super.call(this, Type.DOCUMENT); + _this.directives = null; + _this.contents = null; + _this.directivesEndMarker = null; + _this.documentEndMarker = null; + return _this; + } + + _createClass(Document, [{ + key: "parseDirectives", + value: function parseDirectives(start) { + var src = this.context.src; + this.directives = []; + var atLineStart = true; + var hasDirectives = false; + var offset = start; + + while (!Node.atDocumentBoundary(src, offset, Char.DIRECTIVES_END)) { + offset = Document.startCommentOrEndBlankLine(src, offset); + + switch (src[offset]) { + case '\n': + if (atLineStart) { + var blankLine = new BlankLine(); + offset = blankLine.parse({ + src: src + }, offset); + + if (offset < src.length) { + this.directives.push(blankLine); + } + } else { + offset += 1; + atLineStart = true; + } + + break; + + case '#': + { + var comment = new Comment(); + offset = comment.parse({ + src: src + }, offset); + this.directives.push(comment); + atLineStart = false; + } + break; + + case '%': + { + var directive = new Directive(); + offset = directive.parse({ + parent: this, + src: src + }, offset); + this.directives.push(directive); + hasDirectives = true; + atLineStart = false; + } + break; + + default: + if (hasDirectives) { + this.error = new YAMLSemanticError(this, 'Missing directives-end indicator line'); + } else if (this.directives.length > 0) { + this.contents = this.directives; + this.directives = []; + } + + return offset; + } + } + + if (src[offset]) { + this.directivesEndMarker = new Range(offset, offset + 3); + return offset + 3; + } + + if (hasDirectives) { + this.error = new YAMLSemanticError(this, 'Missing directives-end indicator line'); + } else if (this.directives.length > 0) { + this.contents = this.directives; + this.directives = []; + } + + return offset; + } + }, { + key: "parseContents", + value: function parseContents(start) { + var _this$context = this.context, + parseNode = _this$context.parseNode, + src = _this$context.src; + if (!this.contents) this.contents = []; + var lineStart = start; + + while (src[lineStart - 1] === '-') { + lineStart -= 1; + } + + var offset = Node.endOfWhiteSpace(src, start); + var atLineStart = lineStart === start; + this.valueRange = new Range(offset); + + while (!Node.atDocumentBoundary(src, offset, Char.DOCUMENT_END)) { + switch (src[offset]) { + case '\n': + if (atLineStart) { + var blankLine = new BlankLine(); + offset = blankLine.parse({ + src: src + }, offset); + + if (offset < src.length) { + this.contents.push(blankLine); + } + } else { + offset += 1; + atLineStart = true; + } + + lineStart = offset; + break; + + case '#': + { + var comment = new Comment(); + offset = comment.parse({ + src: src + }, offset); + this.contents.push(comment); + atLineStart = false; + } + break; + + default: + { + var iEnd = Node.endOfIndent(src, offset); + var context = { + atLineStart: atLineStart, + indent: -1, + inFlow: false, + inCollection: false, + lineStart: lineStart, + parent: this + }; + var node = parseNode(context, iEnd); + if (!node) return this.valueRange.end = iEnd; // at next document start + + this.contents.push(node); + offset = node.range.end; + atLineStart = false; + var ec = grabCollectionEndComments(node); + if (ec) Array.prototype.push.apply(this.contents, ec); + } + } + + offset = Document.startCommentOrEndBlankLine(src, offset); + } + + this.valueRange.end = offset; + + if (src[offset]) { + this.documentEndMarker = new Range(offset, offset + 3); + offset += 3; + + if (src[offset]) { + offset = Node.endOfWhiteSpace(src, offset); + + if (src[offset] === '#') { + var _comment = new Comment(); + + offset = _comment.parse({ + src: src + }, offset); + this.contents.push(_comment); + } + + switch (src[offset]) { + case '\n': + offset += 1; + break; + + case undefined: + break; + + default: + this.error = new YAMLSyntaxError(this, 'Document end marker line cannot have a non-comment suffix'); + } + } + } + + return offset; + } + /** + * @param {ParseContext} context + * @param {number} start - Index of first character + * @returns {number} - Index of the character after this + */ + + }, { + key: "parse", + value: function parse(context, start) { + context.root = this; + this.context = context; + var src = context.src; + var offset = src.charCodeAt(start) === 0xfeff ? start + 1 : start; // skip BOM + + offset = this.parseDirectives(offset); + offset = this.parseContents(offset); + return offset; + } + }, { + key: "setOrigRanges", + value: function setOrigRanges(cr, offset) { + offset = _get(_getPrototypeOf(Document.prototype), "setOrigRanges", this).call(this, cr, offset); + this.directives.forEach(function (node) { + offset = node.setOrigRanges(cr, offset); + }); + if (this.directivesEndMarker) offset = this.directivesEndMarker.setOrigRange(cr, offset); + this.contents.forEach(function (node) { + offset = node.setOrigRanges(cr, offset); + }); + if (this.documentEndMarker) offset = this.documentEndMarker.setOrigRange(cr, offset); + return offset; + } + }, { + key: "toString", + value: function toString() { + var contents = this.contents, + directives = this.directives, + value = this.value; + if (value != null) return value; + var str = directives.join(''); + + if (contents.length > 0) { + if (directives.length > 0 || contents[0].type === Type.COMMENT) str += '---\n'; + str += contents.join(''); + } + + if (str[str.length - 1] !== '\n') str += '\n'; + return str; + } + }]); + + return Document; +}(Node); + +var Alias = /*#__PURE__*/function (_Node) { + _inherits(Alias, _Node); + + var _super = _createSuper(Alias); + + function Alias() { + _classCallCheck(this, Alias); + + return _super.apply(this, arguments); + } + + _createClass(Alias, [{ + key: "parse", + + /** + * Parses an *alias from the source + * + * @param {ParseContext} context + * @param {number} start - Index of first character + * @returns {number} - Index of the character after this scalar + */ + value: function parse(context, start) { + this.context = context; + var src = context.src; + var offset = Node.endOfIdentifier(src, start + 1); + this.valueRange = new Range(start + 1, offset); + offset = Node.endOfWhiteSpace(src, offset); + offset = this.parseComment(offset); + return offset; + } + }]); + + return Alias; +}(Node); + +var Chomp = { + CLIP: 'CLIP', + KEEP: 'KEEP', + STRIP: 'STRIP' +}; +var BlockValue = /*#__PURE__*/function (_Node) { + _inherits(BlockValue, _Node); + + var _super = _createSuper(BlockValue); + + function BlockValue(type, props) { + var _this; + + _classCallCheck(this, BlockValue); + + _this = _super.call(this, type, props); + _this.blockIndent = null; + _this.chomping = Chomp.CLIP; + _this.header = null; + return _this; + } + + _createClass(BlockValue, [{ + key: "parseBlockHeader", + value: function parseBlockHeader(start) { + var src = this.context.src; + var offset = start + 1; + var bi = ''; + + while (true) { + var ch = src[offset]; + + switch (ch) { + case '-': + this.chomping = Chomp.STRIP; + break; + + case '+': + this.chomping = Chomp.KEEP; + break; + + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + bi += ch; + break; + + default: + this.blockIndent = Number(bi) || null; + this.header = new Range(start, offset); + return offset; + } + + offset += 1; + } + } + }, { + key: "parseBlockValue", + value: function parseBlockValue(start) { + var _this$context = this.context, + indent = _this$context.indent, + src = _this$context.src; + var explicit = !!this.blockIndent; + var offset = start; + var valueEnd = start; + var minBlockIndent = 1; + + for (var ch = src[offset]; ch === '\n'; ch = src[offset]) { + offset += 1; + if (Node.atDocumentBoundary(src, offset)) break; + var end = Node.endOfBlockIndent(src, indent, offset); // should not include tab? + + if (end === null) break; + var _ch = src[end]; + var lineIndent = end - (offset + indent); + + if (!this.blockIndent) { + // no explicit block indent, none yet detected + if (src[end] !== '\n') { + // first line with non-whitespace content + if (lineIndent < minBlockIndent) { + var msg = 'Block scalars with more-indented leading empty lines must use an explicit indentation indicator'; + this.error = new YAMLSemanticError(this, msg); + } + + this.blockIndent = lineIndent; + } else if (lineIndent > minBlockIndent) { + // empty line with more whitespace + minBlockIndent = lineIndent; + } + } else if (_ch && _ch !== '\n' && lineIndent < this.blockIndent) { + if (src[end] === '#') break; + + if (!this.error) { + var _src = explicit ? 'explicit indentation indicator' : 'first line'; + + var _msg = "Block scalars must not be less indented than their ".concat(_src); + + this.error = new YAMLSemanticError(this, _msg); + } + } + + if (src[end] === '\n') { + offset = end; + } else { + offset = valueEnd = Node.endOfLine(src, end); + } + } + + if (this.chomping !== Chomp.KEEP) { + offset = src[valueEnd] ? valueEnd + 1 : valueEnd; + } + + this.valueRange = new Range(start + 1, offset); + return offset; + } + /** + * Parses a block value from the source + * + * Accepted forms are: + * ``` + * BS + * block + * lines + * + * BS #comment + * block + * lines + * ``` + * where the block style BS matches the regexp `[|>][-+1-9]*` and block lines + * are empty or have an indent level greater than `indent`. + * + * @param {ParseContext} context + * @param {number} start - Index of first character + * @returns {number} - Index of the character after this block + */ + + }, { + key: "parse", + value: function parse(context, start) { + this.context = context; + var src = context.src; + var offset = this.parseBlockHeader(start); + offset = Node.endOfWhiteSpace(src, offset); + offset = this.parseComment(offset); + offset = this.parseBlockValue(offset); + return offset; + } + }, { + key: "setOrigRanges", + value: function setOrigRanges(cr, offset) { + offset = _get(_getPrototypeOf(BlockValue.prototype), "setOrigRanges", this).call(this, cr, offset); + return this.header ? this.header.setOrigRange(cr, offset) : offset; + } + }, { + key: "includesTrailingLines", + get: function get() { + return this.chomping === Chomp.KEEP; + } + }, { + key: "strValue", + get: function get() { + if (!this.valueRange || !this.context) return null; + var _this$valueRange = this.valueRange, + start = _this$valueRange.start, + end = _this$valueRange.end; + var _this$context2 = this.context, + indent = _this$context2.indent, + src = _this$context2.src; + if (this.valueRange.isEmpty()) return ''; + var lastNewLine = null; + var ch = src[end - 1]; + + while (ch === '\n' || ch === '\t' || ch === ' ') { + end -= 1; + + if (end <= start) { + if (this.chomping === Chomp.KEEP) break;else return ''; // probably never happens + } + + if (ch === '\n') lastNewLine = end; + ch = src[end - 1]; + } + + var keepStart = end + 1; + + if (lastNewLine) { + if (this.chomping === Chomp.KEEP) { + keepStart = lastNewLine; + end = this.valueRange.end; + } else { + end = lastNewLine; + } + } + + var bi = indent + this.blockIndent; + var folded = this.type === Type.BLOCK_FOLDED; + var atStart = true; + var str = ''; + var sep = ''; + var prevMoreIndented = false; + + for (var i = start; i < end; ++i) { + for (var j = 0; j < bi; ++j) { + if (src[i] !== ' ') break; + i += 1; + } + + var _ch2 = src[i]; + + if (_ch2 === '\n') { + if (sep === '\n') str += '\n';else sep = '\n'; + } else { + var lineEnd = Node.endOfLine(src, i); + var line = src.slice(i, lineEnd); + i = lineEnd; + + if (folded && (_ch2 === ' ' || _ch2 === '\t') && i < keepStart) { + if (sep === ' ') sep = '\n';else if (!prevMoreIndented && !atStart && sep === '\n') sep = '\n\n'; + str += sep + line; //+ ((lineEnd < end && src[lineEnd]) || '') + + sep = lineEnd < end && src[lineEnd] || ''; + prevMoreIndented = true; + } else { + str += sep + line; + sep = folded && i < keepStart ? ' ' : '\n'; + prevMoreIndented = false; + } + + if (atStart && line !== '') atStart = false; + } + } + + return this.chomping === Chomp.STRIP ? str : str + '\n'; + } + }]); + + return BlockValue; +}(Node); + +var FlowCollection = /*#__PURE__*/function (_Node) { + _inherits(FlowCollection, _Node); + + var _super = _createSuper(FlowCollection); + + function FlowCollection(type, props) { + var _this; + + _classCallCheck(this, FlowCollection); + + _this = _super.call(this, type, props); + _this.items = null; + return _this; + } + + _createClass(FlowCollection, [{ + key: "prevNodeIsJsonLike", + value: function prevNodeIsJsonLike() { + var idx = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.items.length; + var node = this.items[idx - 1]; + return !!node && (node.jsonLike || node.type === Type.COMMENT && this.prevNodeIsJsonLike(idx - 1)); + } + /** + * @param {ParseContext} context + * @param {number} start - Index of first character + * @returns {number} - Index of the character after this + */ + + }, { + key: "parse", + value: function parse(context, start) { + this.context = context; + var parseNode = context.parseNode, + src = context.src; + var indent = context.indent, + lineStart = context.lineStart; + var char = src[start]; // { or [ + + this.items = [{ + char: char, + offset: start + }]; + var offset = Node.endOfWhiteSpace(src, start + 1); + char = src[offset]; + + while (char && char !== ']' && char !== '}') { + switch (char) { + case '\n': + { + lineStart = offset + 1; + var wsEnd = Node.endOfWhiteSpace(src, lineStart); + + if (src[wsEnd] === '\n') { + var blankLine = new BlankLine(); + lineStart = blankLine.parse({ + src: src + }, lineStart); + this.items.push(blankLine); + } + + offset = Node.endOfIndent(src, lineStart); + + if (offset <= lineStart + indent) { + char = src[offset]; + + if (offset < lineStart + indent || char !== ']' && char !== '}') { + var msg = 'Insufficient indentation in flow collection'; + this.error = new YAMLSemanticError(this, msg); + } + } + } + break; + + case ',': + { + this.items.push({ + char: char, + offset: offset + }); + offset += 1; + } + break; + + case '#': + { + var comment = new Comment(); + offset = comment.parse({ + src: src + }, offset); + this.items.push(comment); + } + break; + + case '?': + case ':': + { + var next = src[offset + 1]; + + if (next === '\n' || next === '\t' || next === ' ' || next === ',' || // in-flow : after JSON-like key does not need to be followed by whitespace + char === ':' && this.prevNodeIsJsonLike()) { + this.items.push({ + char: char, + offset: offset + }); + offset += 1; + break; + } + } + // fallthrough + + default: + { + var node = parseNode({ + atLineStart: false, + inCollection: false, + inFlow: true, + indent: -1, + lineStart: lineStart, + parent: this + }, offset); + + if (!node) { + // at next document start + this.valueRange = new Range(start, offset); + return offset; + } + + this.items.push(node); + offset = Node.normalizeOffset(src, node.range.end); + } + } + + offset = Node.endOfWhiteSpace(src, offset); + char = src[offset]; + } + + this.valueRange = new Range(start, offset + 1); + + if (char) { + this.items.push({ + char: char, + offset: offset + }); + offset = Node.endOfWhiteSpace(src, offset + 1); + offset = this.parseComment(offset); + } + + return offset; + } + }, { + key: "setOrigRanges", + value: function setOrigRanges(cr, offset) { + offset = _get(_getPrototypeOf(FlowCollection.prototype), "setOrigRanges", this).call(this, cr, offset); + this.items.forEach(function (node) { + if (node instanceof Node) { + offset = node.setOrigRanges(cr, offset); + } else if (cr.length === 0) { + node.origOffset = node.offset; + } else { + var i = offset; + + while (i < cr.length) { + if (cr[i] > node.offset) break;else ++i; + } + + node.origOffset = node.offset + i; + offset = i; + } + }); + return offset; + } + }, { + key: "toString", + value: function toString() { + var src = this.context.src, + items = this.items, + range = this.range, + value = this.value; + if (value != null) return value; + var nodes = items.filter(function (item) { + return item instanceof Node; + }); + var str = ''; + var prevEnd = range.start; + nodes.forEach(function (node) { + var prefix = src.slice(prevEnd, node.range.start); + prevEnd = node.range.end; + str += prefix + String(node); + + if (str[str.length - 1] === '\n' && src[prevEnd - 1] !== '\n' && src[prevEnd] === '\n') { + // Comment range does not include the terminal newline, but its + // stringified value does. Without this fix, newlines at comment ends + // get duplicated. + prevEnd += 1; + } + }); + str += src.slice(prevEnd, range.end); + return Node.addStringTerminator(src, range.end, str); + } + }]); + + return FlowCollection; +}(Node); + +var QuoteDouble = /*#__PURE__*/function (_Node) { + _inherits(QuoteDouble, _Node); + + var _super = _createSuper(QuoteDouble); + + function QuoteDouble() { + _classCallCheck(this, QuoteDouble); + + return _super.apply(this, arguments); + } + + _createClass(QuoteDouble, [{ + key: "parseCharCode", + value: function parseCharCode(offset, length, errors) { + var src = this.context.src; + var cc = src.substr(offset, length); + var ok = cc.length === length && /^[0-9a-fA-F]+$/.test(cc); + var code = ok ? parseInt(cc, 16) : NaN; + + if (isNaN(code)) { + errors.push(new YAMLSyntaxError(this, "Invalid escape sequence ".concat(src.substr(offset - 2, length + 2)))); + return src.substr(offset - 2, length + 2); + } + + return String.fromCodePoint(code); + } + /** + * Parses a "double quoted" value from the source + * + * @param {ParseContext} context + * @param {number} start - Index of first character + * @returns {number} - Index of the character after this scalar + */ + + }, { + key: "parse", + value: function parse(context, start) { + this.context = context; + var src = context.src; + var offset = QuoteDouble.endOfQuote(src, start + 1); + this.valueRange = new Range(start, offset); + offset = Node.endOfWhiteSpace(src, offset); + offset = this.parseComment(offset); + return offset; + } + }, { + key: "strValue", + + /** + * @returns {string | { str: string, errors: YAMLSyntaxError[] }} + */ + get: function get() { + if (!this.valueRange || !this.context) return null; + var errors = []; + var _this$valueRange = this.valueRange, + start = _this$valueRange.start, + end = _this$valueRange.end; + var _this$context = this.context, + indent = _this$context.indent, + src = _this$context.src; + if (src[end - 1] !== '"') errors.push(new YAMLSyntaxError(this, 'Missing closing "quote')); // Using String#replace is too painful with escaped newlines preceded by + // escaped backslashes; also, this should be faster. + + var str = ''; + + for (var i = start + 1; i < end - 1; ++i) { + var ch = src[i]; + + if (ch === '\n') { + if (Node.atDocumentBoundary(src, i + 1)) errors.push(new YAMLSemanticError(this, 'Document boundary indicators are not allowed within string values')); + + var _Node$foldNewline = Node.foldNewline(src, i, indent), + fold = _Node$foldNewline.fold, + offset = _Node$foldNewline.offset, + error = _Node$foldNewline.error; + + str += fold; + i = offset; + if (error) errors.push(new YAMLSemanticError(this, 'Multi-line double-quoted string needs to be sufficiently indented')); + } else if (ch === '\\') { + i += 1; + + switch (src[i]) { + case '0': + str += '\0'; + break; + // null character + + case 'a': + str += '\x07'; + break; + // bell character + + case 'b': + str += '\b'; + break; + // backspace + + case 'e': + str += '\x1b'; + break; + // escape character + + case 'f': + str += '\f'; + break; + // form feed + + case 'n': + str += '\n'; + break; + // line feed + + case 'r': + str += '\r'; + break; + // carriage return + + case 't': + str += '\t'; + break; + // horizontal tab + + case 'v': + str += '\v'; + break; + // vertical tab + + case 'N': + str += "\x85"; + break; + // Unicode next line + + case '_': + str += "\xA0"; + break; + // Unicode non-breaking space + + case 'L': + str += "\u2028"; + break; + // Unicode line separator + + case 'P': + str += "\u2029"; + break; + // Unicode paragraph separator + + case ' ': + str += ' '; + break; + + case '"': + str += '"'; + break; + + case '/': + str += '/'; + break; + + case '\\': + str += '\\'; + break; + + case '\t': + str += '\t'; + break; + + case 'x': + str += this.parseCharCode(i + 1, 2, errors); + i += 2; + break; + + case 'u': + str += this.parseCharCode(i + 1, 4, errors); + i += 4; + break; + + case 'U': + str += this.parseCharCode(i + 1, 8, errors); + i += 8; + break; + + case '\n': + // skip escaped newlines, but still trim the following line + while (src[i + 1] === ' ' || src[i + 1] === '\t') { + i += 1; + } + + break; + + default: + errors.push(new YAMLSyntaxError(this, "Invalid escape sequence ".concat(src.substr(i - 1, 2)))); + str += '\\' + src[i]; + } + } else if (ch === ' ' || ch === '\t') { + // trim trailing whitespace + var wsStart = i; + var next = src[i + 1]; + + while (next === ' ' || next === '\t') { + i += 1; + next = src[i + 1]; + } + + if (next !== '\n') str += i > wsStart ? src.slice(wsStart, i + 1) : ch; + } else { + str += ch; + } + } + + return errors.length > 0 ? { + errors: errors, + str: str + } : str; + } + }], [{ + key: "endOfQuote", + value: function endOfQuote(src, offset) { + var ch = src[offset]; + + while (ch && ch !== '"') { + offset += ch === '\\' ? 2 : 1; + ch = src[offset]; + } + + return offset + 1; + } + }]); + + return QuoteDouble; +}(Node); + +var QuoteSingle = /*#__PURE__*/function (_Node) { + _inherits(QuoteSingle, _Node); + + var _super = _createSuper(QuoteSingle); + + function QuoteSingle() { + _classCallCheck(this, QuoteSingle); + + return _super.apply(this, arguments); + } + + _createClass(QuoteSingle, [{ + key: "parse", + + /** + * Parses a 'single quoted' value from the source + * + * @param {ParseContext} context + * @param {number} start - Index of first character + * @returns {number} - Index of the character after this scalar + */ + value: function parse(context, start) { + this.context = context; + var src = context.src; + var offset = QuoteSingle.endOfQuote(src, start + 1); + this.valueRange = new Range(start, offset); + offset = Node.endOfWhiteSpace(src, offset); + offset = this.parseComment(offset); + return offset; + } + }, { + key: "strValue", + + /** + * @returns {string | { str: string, errors: YAMLSyntaxError[] }} + */ + get: function get() { + if (!this.valueRange || !this.context) return null; + var errors = []; + var _this$valueRange = this.valueRange, + start = _this$valueRange.start, + end = _this$valueRange.end; + var _this$context = this.context, + indent = _this$context.indent, + src = _this$context.src; + if (src[end - 1] !== "'") errors.push(new YAMLSyntaxError(this, "Missing closing 'quote")); + var str = ''; + + for (var i = start + 1; i < end - 1; ++i) { + var ch = src[i]; + + if (ch === '\n') { + if (Node.atDocumentBoundary(src, i + 1)) errors.push(new YAMLSemanticError(this, 'Document boundary indicators are not allowed within string values')); + + var _Node$foldNewline = Node.foldNewline(src, i, indent), + fold = _Node$foldNewline.fold, + offset = _Node$foldNewline.offset, + error = _Node$foldNewline.error; + + str += fold; + i = offset; + if (error) errors.push(new YAMLSemanticError(this, 'Multi-line single-quoted string needs to be sufficiently indented')); + } else if (ch === "'") { + str += ch; + i += 1; + if (src[i] !== "'") errors.push(new YAMLSyntaxError(this, 'Unescaped single quote? This should not happen.')); + } else if (ch === ' ' || ch === '\t') { + // trim trailing whitespace + var wsStart = i; + var next = src[i + 1]; + + while (next === ' ' || next === '\t') { + i += 1; + next = src[i + 1]; + } + + if (next !== '\n') str += i > wsStart ? src.slice(wsStart, i + 1) : ch; + } else { + str += ch; + } + } + + return errors.length > 0 ? { + errors: errors, + str: str + } : str; + } + }], [{ + key: "endOfQuote", + value: function endOfQuote(src, offset) { + var ch = src[offset]; + + while (ch) { + if (ch === "'") { + if (src[offset + 1] !== "'") break; + ch = src[offset += 2]; + } else { + ch = src[offset += 1]; + } + } + + return offset + 1; + } + }]); + + return QuoteSingle; +}(Node); + +function createNewNode(type, props) { + switch (type) { + case Type.ALIAS: + return new Alias(type, props); + + case Type.BLOCK_FOLDED: + case Type.BLOCK_LITERAL: + return new BlockValue(type, props); + + case Type.FLOW_MAP: + case Type.FLOW_SEQ: + return new FlowCollection(type, props); + + case Type.MAP_KEY: + case Type.MAP_VALUE: + case Type.SEQ_ITEM: + return new CollectionItem(type, props); + + case Type.COMMENT: + case Type.PLAIN: + return new PlainValue(type, props); + + case Type.QUOTE_DOUBLE: + return new QuoteDouble(type, props); + + case Type.QUOTE_SINGLE: + return new QuoteSingle(type, props); + + /* istanbul ignore next */ + + default: + return null; + // should never happen + } +} +/** + * @param {boolean} atLineStart - Node starts at beginning of line + * @param {boolean} inFlow - true if currently in a flow context + * @param {boolean} inCollection - true if currently in a collection context + * @param {number} indent - Current level of indentation + * @param {number} lineStart - Start of the current line + * @param {Node} parent - The parent of the node + * @param {string} src - Source of the YAML document + */ + + +var ParseContext = /*#__PURE__*/function () { + _createClass(ParseContext, null, [{ + key: "parseType", + value: function parseType(src, offset, inFlow) { + switch (src[offset]) { + case '*': + return Type.ALIAS; + + case '>': + return Type.BLOCK_FOLDED; + + case '|': + return Type.BLOCK_LITERAL; + + case '{': + return Type.FLOW_MAP; + + case '[': + return Type.FLOW_SEQ; + + case '?': + return !inFlow && Node.atBlank(src, offset + 1, true) ? Type.MAP_KEY : Type.PLAIN; + + case ':': + return !inFlow && Node.atBlank(src, offset + 1, true) ? Type.MAP_VALUE : Type.PLAIN; + + case '-': + return !inFlow && Node.atBlank(src, offset + 1, true) ? Type.SEQ_ITEM : Type.PLAIN; + + case '"': + return Type.QUOTE_DOUBLE; + + case "'": + return Type.QUOTE_SINGLE; + + default: + return Type.PLAIN; + } + } + }]); + + function ParseContext() { + var _this = this; + + var orig = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + atLineStart = _ref.atLineStart, + inCollection = _ref.inCollection, + inFlow = _ref.inFlow, + indent = _ref.indent, + lineStart = _ref.lineStart, + parent = _ref.parent; + + _classCallCheck(this, ParseContext); + + _defineProperty(this, "parseNode", function (overlay, start) { + if (Node.atDocumentBoundary(_this.src, start)) return null; + var context = new ParseContext(_this, overlay); + + var _context$parseProps = context.parseProps(start), + props = _context$parseProps.props, + type = _context$parseProps.type, + valueStart = _context$parseProps.valueStart; + + var node = createNewNode(type, props); + var offset = node.parse(context, valueStart); + node.range = new Range(start, offset); + /* istanbul ignore if */ + + if (offset <= start) { + // This should never happen, but if it does, let's make sure to at least + // step one character forward to avoid a busy loop. + node.error = new Error("Node#parse consumed no characters"); + node.error.parseEnd = offset; + node.error.source = node; + node.range.end = start + 1; + } + + if (context.nodeStartsCollection(node)) { + if (!node.error && !context.atLineStart && context.parent.type === Type.DOCUMENT) { + node.error = new YAMLSyntaxError(node, 'Block collection must not have preceding content here (e.g. directives-end indicator)'); + } + + var collection = new Collection(node); + offset = collection.parse(new ParseContext(context), offset); + collection.range = new Range(start, offset); + return collection; + } + + return node; + }); + + this.atLineStart = atLineStart != null ? atLineStart : orig.atLineStart || false; + this.inCollection = inCollection != null ? inCollection : orig.inCollection || false; + this.inFlow = inFlow != null ? inFlow : orig.inFlow || false; + this.indent = indent != null ? indent : orig.indent; + this.lineStart = lineStart != null ? lineStart : orig.lineStart; + this.parent = parent != null ? parent : orig.parent || {}; + this.root = orig.root; + this.src = orig.src; + } + + _createClass(ParseContext, [{ + key: "nodeStartsCollection", + value: function nodeStartsCollection(node) { + var inCollection = this.inCollection, + inFlow = this.inFlow, + src = this.src; + if (inCollection || inFlow) return false; + if (node instanceof CollectionItem) return true; // check for implicit key + + var offset = node.range.end; + if (src[offset] === '\n' || src[offset - 1] === '\n') return false; + offset = Node.endOfWhiteSpace(src, offset); + return src[offset] === ':'; + } // Anchor and tag are before type, which determines the node implementation + // class; hence this intermediate step. + + }, { + key: "parseProps", + value: function parseProps(offset) { + var inFlow = this.inFlow, + parent = this.parent, + src = this.src; + var props = []; + var lineHasProps = false; + offset = this.atLineStart ? Node.endOfIndent(src, offset) : Node.endOfWhiteSpace(src, offset); + var ch = src[offset]; + + while (ch === Char.ANCHOR || ch === Char.COMMENT || ch === Char.TAG || ch === '\n') { + if (ch === '\n') { + var lineStart = offset + 1; + var inEnd = Node.endOfIndent(src, lineStart); + var indentDiff = inEnd - (lineStart + this.indent); + var noIndicatorAsIndent = parent.type === Type.SEQ_ITEM && parent.context.atLineStart; + if (!Node.nextNodeIsIndented(src[inEnd], indentDiff, !noIndicatorAsIndent)) break; + this.atLineStart = true; + this.lineStart = lineStart; + lineHasProps = false; + offset = inEnd; + } else if (ch === Char.COMMENT) { + var end = Node.endOfLine(src, offset + 1); + props.push(new Range(offset, end)); + offset = end; + } else { + var _end = Node.endOfIdentifier(src, offset + 1); + + if (ch === Char.TAG && src[_end] === ',' && /^[a-zA-Z0-9-]+\.[a-zA-Z0-9-]+,\d\d\d\d(-\d\d){0,2}\/\S/.test(src.slice(offset + 1, _end + 13))) { + // Let's presume we're dealing with a YAML 1.0 domain tag here, rather + // than an empty but 'foo.bar' private-tagged node in a flow collection + // followed without whitespace by a plain string starting with a year + // or date divided by something. + _end = Node.endOfIdentifier(src, _end + 5); + } + + props.push(new Range(offset, _end)); + lineHasProps = true; + offset = Node.endOfWhiteSpace(src, _end); + } + + ch = src[offset]; + } // '- &a : b' has an anchor on an empty node + + + if (lineHasProps && ch === ':' && Node.atBlank(src, offset + 1, true)) offset -= 1; + var type = ParseContext.parseType(src, offset, inFlow); + return { + props: props, + type: type, + valueStart: offset + }; + } + /** + * Parses a node from the source + * @param {ParseContext} overlay + * @param {number} start - Index of first non-whitespace character for the node + * @returns {?Node} - null if at a document boundary + */ + + }]); + + return ParseContext; +}(); + +// Published as 'yaml/parse-cst' +function parse(src) { + var cr = []; + + if (src.indexOf('\r') !== -1) { + src = src.replace(/\r\n?/g, function (match, offset) { + if (match.length > 1) cr.push(offset); + return '\n'; + }); + } + + var documents = []; + var offset = 0; + + do { + var doc = new Document(); + var context = new ParseContext({ + src: src + }); + offset = doc.parse(context, offset); + documents.push(doc); + } while (offset < src.length); + + documents.setOrigRanges = function () { + if (cr.length === 0) return false; + + for (var i = 1; i < cr.length; ++i) { + cr[i] -= i; + } + + var crOffset = 0; + + for (var _i = 0; _i < documents.length; ++_i) { + crOffset = documents[_i].setOrigRanges(cr, crOffset); + } + + cr.splice(0, cr.length); + return true; + }; + + documents.toString = function () { + return documents.join('...\n'); + }; + + return documents; +} + +export { parse }; diff --git a/node_modules/yaml/browser/dist/resolveSeq-04825f30.js b/node_modules/yaml/browser/dist/resolveSeq-04825f30.js new file mode 100644 index 0000000..231fd7e --- /dev/null +++ b/node_modules/yaml/browser/dist/resolveSeq-04825f30.js @@ -0,0 +1,2373 @@ +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-ff5147c6.js'; + +function addCommentBefore(str, indent, comment) { + if (!comment) return str; + var cc = comment.replace(/[\s\S]^/gm, "$&".concat(indent, "#")); + return "#".concat(cc, "\n").concat(indent).concat(str); +} +function addComment(str, indent, comment) { + return !comment ? str : comment.indexOf('\n') === -1 ? "".concat(str, " #").concat(comment) : "".concat(str, "\n") + comment.replace(/^/gm, "".concat(indent || '', "#")); +} + +var Node = function Node() { + _classCallCheck(this, Node); +}; + +function toJSON(value, arg, ctx) { + if (Array.isArray(value)) return value.map(function (v, i) { + return toJSON(v, String(i), ctx); + }); + + if (value && typeof value.toJSON === 'function') { + var anchor = ctx && ctx.anchors && ctx.anchors.get(value); + if (anchor) ctx.onCreate = function (res) { + anchor.res = res; + delete ctx.onCreate; + }; + var res = value.toJSON(arg, ctx); + if (anchor && ctx.onCreate) ctx.onCreate(res); + return res; + } + + if ((!ctx || !ctx.keep) && typeof value === 'bigint') return Number(value); + return value; +} + +var Scalar = /*#__PURE__*/function (_Node) { + _inherits(Scalar, _Node); + + var _super = _createSuper(Scalar); + + function Scalar(value) { + var _this; + + _classCallCheck(this, Scalar); + + _this = _super.call(this); + _this.value = value; + return _this; + } + + _createClass(Scalar, [{ + key: "toJSON", + value: function toJSON$1(arg, ctx) { + return ctx && ctx.keep ? this.value : toJSON(this.value, arg, ctx); + } + }, { + key: "toString", + value: function toString() { + return String(this.value); + } + }]); + + return Scalar; +}(Node); + +function collectionFromPath(schema, path, value) { + var v = value; + + for (var i = path.length - 1; i >= 0; --i) { + var k = path[i]; + var o = Number.isInteger(k) && k >= 0 ? [] : {}; + o[k] = v; + v = o; + } + + return schema.createNode(v, false); +} // null, undefined, or an empty non-string iterable (e.g. []) + + +var isEmptyPath = function isEmptyPath(path) { + return path == null || _typeof(path) === 'object' && path[Symbol.iterator]().next().done; +}; +var Collection = /*#__PURE__*/function (_Node) { + _inherits(Collection, _Node); + + var _super = _createSuper(Collection); + + function Collection(schema) { + var _this; + + _classCallCheck(this, Collection); + + _this = _super.call(this); + + _defineProperty(_assertThisInitialized(_this), "items", []); + + _this.schema = schema; + return _this; + } + + _createClass(Collection, [{ + key: "addIn", + value: function addIn(path, value) { + if (isEmptyPath(path)) this.add(value);else { + var _path = _toArray(path), + key = _path[0], + rest = _path.slice(1); + + var node = this.get(key, true); + 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)); + } + } + }, { + key: "deleteIn", + value: function deleteIn(_ref) { + var _ref2 = _toArray(_ref), + key = _ref2[0], + rest = _ref2.slice(1); + + if (rest.length === 0) return this.delete(key); + var node = this.get(key, true); + if (node instanceof Collection) return node.deleteIn(rest);else throw new Error("Expected YAML collection at ".concat(key, ". Remaining path: ").concat(rest)); + } + }, { + key: "getIn", + value: function getIn(_ref3, keepScalar) { + var _ref4 = _toArray(_ref3), + key = _ref4[0], + rest = _ref4.slice(1); + + var node = this.get(key, true); + if (rest.length === 0) return !keepScalar && node instanceof Scalar ? node.value : node;else return node instanceof Collection ? node.getIn(rest, keepScalar) : undefined; + } + }, { + key: "hasAllNullValues", + value: function hasAllNullValues() { + return this.items.every(function (node) { + if (!node || node.type !== 'PAIR') return false; + var n = node.value; + return n == null || n instanceof Scalar && n.value == null && !n.commentBefore && !n.comment && !n.tag; + }); + } + }, { + key: "hasIn", + value: function hasIn(_ref5) { + var _ref6 = _toArray(_ref5), + key = _ref6[0], + rest = _ref6.slice(1); + + if (rest.length === 0) return this.has(key); + var node = this.get(key, true); + return node instanceof Collection ? node.hasIn(rest) : false; + } + }, { + key: "setIn", + value: function setIn(_ref7, value) { + var _ref8 = _toArray(_ref7), + key = _ref8[0], + rest = _ref8.slice(1); + + if (rest.length === 0) { + this.set(key, value); + } else { + var node = this.get(key, true); + 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)); + } + } // overridden in implementations + + /* istanbul ignore next */ + + }, { + key: "toJSON", + value: function toJSON() { + return null; + } + }, { + key: "toString", + value: function toString(ctx, _ref9, onComment, onChompKeep) { + var _this2 = this; + + var blockItem = _ref9.blockItem, + flowChars = _ref9.flowChars, + isMap = _ref9.isMap, + itemIndent = _ref9.itemIndent; + var _ctx = ctx, + indent = _ctx.indent, + indentStep = _ctx.indentStep, + stringify = _ctx.stringify; + var inFlow = this.type === Type.FLOW_MAP || this.type === Type.FLOW_SEQ || ctx.inFlow; + if (inFlow) itemIndent += indentStep; + var allNullValues = isMap && this.hasAllNullValues(); + ctx = Object.assign({}, ctx, { + allNullValues: allNullValues, + indent: itemIndent, + inFlow: inFlow, + type: null + }); + var chompKeep = false; + var hasItemWithNewLine = false; + var nodes = this.items.reduce(function (nodes, item, i) { + var comment; + + if (item) { + if (!chompKeep && item.spaceBefore) nodes.push({ + type: 'comment', + str: '' + }); + if (item.commentBefore) item.commentBefore.match(/^.*$/gm).forEach(function (line) { + nodes.push({ + type: 'comment', + str: "#".concat(line) + }); + }); + if (item.comment) comment = item.comment; + 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; + } + + chompKeep = false; + var str = stringify(item, ctx, function () { + return comment = null; + }, function () { + return chompKeep = true; + }); + if (inFlow && !hasItemWithNewLine && str.includes('\n')) hasItemWithNewLine = true; + if (inFlow && i < _this2.items.length - 1) str += ','; + str = addComment(str, itemIndent, comment); + if (chompKeep && (comment || inFlow)) chompKeep = false; + nodes.push({ + type: 'item', + str: str + }); + return nodes; + }, []); + var str; + + if (nodes.length === 0) { + str = flowChars.start + flowChars.end; + } else if (inFlow) { + var start = flowChars.start, + end = flowChars.end; + var strings = nodes.map(function (n) { + return n.str; + }); + + if (hasItemWithNewLine || strings.reduce(function (sum, str) { + return sum + str.length + 2; + }, 2) > Collection.maxFlowStringSingleLineLength) { + str = start; + + var _iterator = _createForOfIteratorHelper(strings), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var s = _step.value; + str += s ? "\n".concat(indentStep).concat(indent).concat(s) : '\n'; + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + + str += "\n".concat(indent).concat(end); + } else { + str = "".concat(start, " ").concat(strings.join(' '), " ").concat(end); + } + } else { + var _strings = nodes.map(blockItem); + + str = _strings.shift(); + + var _iterator2 = _createForOfIteratorHelper(_strings), + _step2; + + try { + for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { + var _s = _step2.value; + str += _s ? "\n".concat(indent).concat(_s) : '\n'; + } + } catch (err) { + _iterator2.e(err); + } finally { + _iterator2.f(); + } + } + + if (this.comment) { + str += '\n' + this.comment.replace(/^/gm, "".concat(indent, "#")); + if (onComment) onComment(); + } else if (chompKeep && onChompKeep) onChompKeep(); + + return str; + } + }]); + + return Collection; +}(Node); + +_defineProperty(Collection, "maxFlowStringSingleLineLength", 60); + +function asItemIndex(key) { + var idx = key instanceof Scalar ? key.value : key; + if (idx && typeof idx === 'string') idx = Number(idx); + return Number.isInteger(idx) && idx >= 0 ? idx : null; +} + +var YAMLSeq = /*#__PURE__*/function (_Collection) { + _inherits(YAMLSeq, _Collection); + + var _super = _createSuper(YAMLSeq); + + function YAMLSeq() { + _classCallCheck(this, YAMLSeq); + + return _super.apply(this, arguments); + } + + _createClass(YAMLSeq, [{ + key: "add", + value: function add(value) { + this.items.push(value); + } + }, { + key: "delete", + value: function _delete(key) { + var idx = asItemIndex(key); + if (typeof idx !== 'number') return false; + var del = this.items.splice(idx, 1); + return del.length > 0; + } + }, { + key: "get", + value: function get(key, keepScalar) { + var idx = asItemIndex(key); + if (typeof idx !== 'number') return undefined; + var it = this.items[idx]; + return !keepScalar && it instanceof Scalar ? it.value : it; + } + }, { + key: "has", + value: function has(key) { + var idx = asItemIndex(key); + return typeof idx === 'number' && idx < this.items.length; + } + }, { + key: "set", + value: function set(key, value) { + var idx = asItemIndex(key); + if (typeof idx !== 'number') throw new Error("Expected a valid index, not ".concat(key, ".")); + this.items[idx] = value; + } + }, { + key: "toJSON", + value: function toJSON$1(_, ctx) { + var seq = []; + if (ctx && ctx.onCreate) ctx.onCreate(seq); + var i = 0; + + var _iterator = _createForOfIteratorHelper(this.items), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var item = _step.value; + seq.push(toJSON(item, String(i++), ctx)); + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + + return seq; + } + }, { + key: "toString", + value: function toString(ctx, onComment, onChompKeep) { + if (!ctx) return JSON.stringify(this); + return _get(_getPrototypeOf(YAMLSeq.prototype), "toString", this).call(this, ctx, { + blockItem: function blockItem(n) { + return n.type === 'comment' ? n.str : "- ".concat(n.str); + }, + flowChars: { + start: '[', + end: ']' + }, + isMap: false, + itemIndent: (ctx.indent || '') + ' ' + }, onComment, onChompKeep); + } + }]); + + return YAMLSeq; +}(Collection); + +var stringifyKey = function stringifyKey(key, jsKey, ctx) { + if (jsKey === null) return ''; + if (_typeof(jsKey) !== 'object') return String(jsKey); + if (key instanceof Node && ctx && ctx.doc) return key.toString({ + anchors: {}, + doc: ctx.doc, + indent: '', + indentStep: ctx.indentStep, + inFlow: true, + inStringifyKey: true, + stringify: ctx.stringify + }); + return JSON.stringify(jsKey); +}; + +var Pair = /*#__PURE__*/function (_Node) { + _inherits(Pair, _Node); + + var _super = _createSuper(Pair); + + function Pair(key) { + var _this; + + var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + + _classCallCheck(this, Pair); + + _this = _super.call(this); + _this.key = key; + _this.value = value; + _this.type = Pair.Type.PAIR; + return _this; + } + + _createClass(Pair, [{ + key: "addToJSMap", + value: function addToJSMap(ctx, map) { + var key = toJSON(this.key, '', ctx); + + if (map instanceof Map) { + var value = toJSON(this.value, key, ctx); + map.set(key, value); + } else if (map instanceof Set) { + map.add(key); + } else { + var stringKey = stringifyKey(this.key, key, ctx); + map[stringKey] = toJSON(this.value, stringKey, ctx); + } + + return map; + } + }, { + key: "toJSON", + value: function toJSON(_, ctx) { + var pair = ctx && ctx.mapAsMap ? new Map() : {}; + return this.addToJSMap(ctx, pair); + } + }, { + key: "toString", + value: function toString(ctx, onComment, onChompKeep) { + if (!ctx || !ctx.doc) return JSON.stringify(this); + var _ctx$doc$options = ctx.doc.options, + indentSize = _ctx$doc$options.indent, + indentSeq = _ctx$doc$options.indentSeq, + simpleKeys = _ctx$doc$options.simpleKeys; + var key = this.key, + value = this.value; + var keyComment = key instanceof Node && key.comment; + + if (simpleKeys) { + if (keyComment) { + throw new Error('With simple keys, key nodes cannot have comments'); + } + + if (key instanceof Collection) { + var msg = 'With simple keys, collection cannot be used as a key value'; + throw new Error(msg); + } + } + + var explicitKey = !simpleKeys && (!key || keyComment || key instanceof Collection || key.type === Type.BLOCK_FOLDED || key.type === Type.BLOCK_LITERAL); + var _ctx = ctx, + doc = _ctx.doc, + indent = _ctx.indent, + indentStep = _ctx.indentStep, + stringify = _ctx.stringify; + ctx = Object.assign({}, ctx, { + implicitKey: !explicitKey, + indent: indent + indentStep + }); + var chompKeep = false; + var str = stringify(key, ctx, function () { + return keyComment = null; + }, function () { + return chompKeep = true; + }); + str = addComment(str, ctx.indent, keyComment); + + if (ctx.allNullValues && !simpleKeys) { + if (this.comment) { + str = addComment(str, ctx.indent, this.comment); + if (onComment) onComment(); + } else if (chompKeep && !keyComment && onChompKeep) onChompKeep(); + + return ctx.inFlow ? str : "? ".concat(str); + } + + str = explicitKey ? "? ".concat(str, "\n").concat(indent, ":") : "".concat(str, ":"); + + if (this.comment) { + // expected (but not strictly required) to be a single-line comment + str = addComment(str, ctx.indent, this.comment); + if (onComment) onComment(); + } + + var vcb = ''; + var valueComment = null; + + if (value instanceof Node) { + if (value.spaceBefore) vcb = '\n'; + + if (value.commentBefore) { + var cs = value.commentBefore.replace(/^/gm, "".concat(ctx.indent, "#")); + vcb += "\n".concat(cs); + } + + valueComment = value.comment; + } else if (value && _typeof(value) === 'object') { + value = doc.schema.createNode(value, true); + } + + ctx.implicitKey = false; + if (!explicitKey && !this.comment && value instanceof Scalar) ctx.indentAtStart = str.length + 1; + chompKeep = false; + + if (!indentSeq && indentSize >= 2 && !ctx.inFlow && !explicitKey && value instanceof YAMLSeq && value.type !== Type.FLOW_SEQ && !value.tag && !doc.anchors.getName(value)) { + // If indentSeq === false, consider '- ' as part of indentation where possible + ctx.indent = ctx.indent.substr(2); + } + + var valueStr = stringify(value, ctx, function () { + return valueComment = null; + }, function () { + return chompKeep = true; + }); + var ws = ' '; + + if (vcb || this.comment) { + ws = "".concat(vcb, "\n").concat(ctx.indent); + } else if (!explicitKey && value instanceof Collection) { + var flow = valueStr[0] === '[' || valueStr[0] === '{'; + if (!flow || valueStr.includes('\n')) ws = "\n".concat(ctx.indent); + } + + if (chompKeep && !valueComment && onChompKeep) onChompKeep(); + return addComment(str + ws + valueStr, ctx.indent, valueComment); + } + }, { + key: "commentBefore", + get: function get() { + return this.key instanceof Node ? this.key.commentBefore : undefined; + }, + set: function set(cb) { + if (this.key == null) this.key = new Scalar(null); + if (this.key instanceof Node) this.key.commentBefore = cb;else { + var msg = 'Pair.commentBefore is an alias for Pair.key.commentBefore. To set it, the key must be a Node.'; + throw new Error(msg); + } + } + }]); + + return Pair; +}(Node); + +_defineProperty(Pair, "Type", { + PAIR: 'PAIR', + MERGE_PAIR: 'MERGE_PAIR' +}); + +var getAliasCount = function getAliasCount(node, anchors) { + if (node instanceof Alias) { + var anchor = anchors.get(node.source); + return anchor.count * anchor.aliasCount; + } else if (node instanceof Collection) { + var count = 0; + + var _iterator = _createForOfIteratorHelper(node.items), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var item = _step.value; + var c = getAliasCount(item, anchors); + if (c > count) count = c; + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + + return count; + } else if (node instanceof Pair) { + var kc = getAliasCount(node.key, anchors); + var vc = getAliasCount(node.value, anchors); + return Math.max(kc, vc); + } + + return 1; +}; + +var Alias = /*#__PURE__*/function (_Node) { + _inherits(Alias, _Node); + + var _super = _createSuper(Alias); + + _createClass(Alias, null, [{ + key: "stringify", + value: function stringify(_ref, _ref2) { + var range = _ref.range, + source = _ref.source; + var anchors = _ref2.anchors, + doc = _ref2.doc, + implicitKey = _ref2.implicitKey, + inStringifyKey = _ref2.inStringifyKey; + var anchor = Object.keys(anchors).find(function (a) { + return anchors[a] === source; + }); + if (!anchor && inStringifyKey) anchor = doc.anchors.getName(source) || doc.anchors.newName(); + if (anchor) return "*".concat(anchor).concat(implicitKey ? ' ' : ''); + var msg = doc.anchors.getName(source) ? 'Alias node must be after source node' : 'Source node not found for alias node'; + throw new Error("".concat(msg, " [").concat(range, "]")); + } + }]); + + function Alias(source) { + var _this; + + _classCallCheck(this, Alias); + + _this = _super.call(this); + _this.source = source; + _this.type = Type.ALIAS; + return _this; + } + + _createClass(Alias, [{ + key: "toJSON", + value: function toJSON$1(arg, ctx) { + if (!ctx) return toJSON(this.source, arg, ctx); + var anchors = ctx.anchors, + maxAliasCount = ctx.maxAliasCount; + var anchor = anchors.get(this.source); + /* istanbul ignore if */ + + if (!anchor || anchor.res === undefined) { + var msg = 'This should not happen: Alias anchor was not resolved?'; + if (this.cstNode) throw new YAMLReferenceError(this.cstNode, msg);else throw new ReferenceError(msg); + } + + if (maxAliasCount >= 0) { + anchor.count += 1; + if (anchor.aliasCount === 0) anchor.aliasCount = getAliasCount(this.source, anchors); + + if (anchor.count * anchor.aliasCount > maxAliasCount) { + var _msg = 'Excessive alias count indicates a resource exhaustion attack'; + if (this.cstNode) throw new YAMLReferenceError(this.cstNode, _msg);else throw new ReferenceError(_msg); + } + } + + return anchor.res; + } // Only called when stringifying an alias mapping key while constructing + // Object output. + + }, { + key: "toString", + value: function toString(ctx) { + return Alias.stringify(this, ctx); + } + }, { + key: "tag", + set: function set(t) { + throw new Error('Alias nodes cannot have tags'); + } + }]); + + return Alias; +}(Node); + +_defineProperty(Alias, "default", true); + +function findPair(items, key) { + var k = key instanceof Scalar ? key.value : key; + + var _iterator = _createForOfIteratorHelper(items), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var it = _step.value; + + if (it instanceof Pair) { + if (it.key === key || it.key === k) return it; + if (it.key && it.key.value === k) return it; + } + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + + return undefined; +} +var YAMLMap = /*#__PURE__*/function (_Collection) { + _inherits(YAMLMap, _Collection); + + var _super = _createSuper(YAMLMap); + + function YAMLMap() { + _classCallCheck(this, YAMLMap); + + return _super.apply(this, arguments); + } + + _createClass(YAMLMap, [{ + key: "add", + value: function add(pair, overwrite) { + if (!pair) pair = new Pair(pair);else if (!(pair instanceof Pair)) pair = new Pair(pair.key || pair, pair.value); + var prev = findPair(this.items, pair.key); + var sortEntries = this.schema && this.schema.sortMapEntries; + + if (prev) { + if (overwrite) prev.value = pair.value;else throw new Error("Key ".concat(pair.key, " already set")); + } else if (sortEntries) { + var i = this.items.findIndex(function (item) { + return sortEntries(pair, item) < 0; + }); + if (i === -1) this.items.push(pair);else this.items.splice(i, 0, pair); + } else { + this.items.push(pair); + } + } + }, { + key: "delete", + value: function _delete(key) { + var it = findPair(this.items, key); + if (!it) return false; + var del = this.items.splice(this.items.indexOf(it), 1); + return del.length > 0; + } + }, { + key: "get", + value: function get(key, keepScalar) { + var it = findPair(this.items, key); + var node = it && it.value; + return !keepScalar && node instanceof Scalar ? node.value : node; + } + }, { + key: "has", + value: function has(key) { + return !!findPair(this.items, key); + } + }, { + key: "set", + value: function set(key, value) { + this.add(new Pair(key, value), true); + } + /** + * @param {*} arg ignored + * @param {*} ctx Conversion context, originally set in Document#toJSON() + * @param {Class} Type If set, forces the returned collection type + * @returns {*} Instance of Type, Map, or Object + */ + + }, { + key: "toJSON", + value: function toJSON(_, ctx, Type) { + var map = Type ? new Type() : ctx && ctx.mapAsMap ? new Map() : {}; + if (ctx && ctx.onCreate) ctx.onCreate(map); + + var _iterator2 = _createForOfIteratorHelper(this.items), + _step2; + + try { + for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { + var item = _step2.value; + item.addToJSMap(ctx, map); + } + } catch (err) { + _iterator2.e(err); + } finally { + _iterator2.f(); + } + + return map; + } + }, { + key: "toString", + value: function toString(ctx, onComment, onChompKeep) { + if (!ctx) return JSON.stringify(this); + + var _iterator3 = _createForOfIteratorHelper(this.items), + _step3; + + try { + for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { + var item = _step3.value; + if (!(item instanceof Pair)) throw new Error("Map items must all be pairs; found ".concat(JSON.stringify(item), " instead")); + } + } catch (err) { + _iterator3.e(err); + } finally { + _iterator3.f(); + } + + return _get(_getPrototypeOf(YAMLMap.prototype), "toString", this).call(this, ctx, { + blockItem: function blockItem(n) { + return n.str; + }, + flowChars: { + start: '{', + end: '}' + }, + isMap: true, + itemIndent: ctx.indent || '' + }, onComment, onChompKeep); + } + }]); + + return YAMLMap; +}(Collection); + +var MERGE_KEY = '<<'; +var Merge = /*#__PURE__*/function (_Pair) { + _inherits(Merge, _Pair); + + var _super = _createSuper(Merge); + + function Merge(pair) { + var _this; + + _classCallCheck(this, Merge); + + if (pair instanceof Pair) { + var seq = pair.value; + + if (!(seq instanceof YAMLSeq)) { + seq = new YAMLSeq(); + seq.items.push(pair.value); + seq.range = pair.value.range; + } + + _this = _super.call(this, pair.key, seq); + _this.range = pair.range; + } else { + _this = _super.call(this, new Scalar(MERGE_KEY), new YAMLSeq()); + } + + _this.type = Pair.Type.MERGE_PAIR; + return _possibleConstructorReturn(_this); + } // If the value associated with a merge key is a single mapping node, each of + // its key/value pairs is inserted into the current mapping, unless the key + // already exists in it. If the value associated with the merge key is a + // sequence, then this sequence is expected to contain mapping nodes and each + // of these nodes is merged in turn according to its order in the sequence. + // Keys in mapping nodes earlier in the sequence override keys specified in + // later mapping nodes. -- http://yaml.org/type/merge.html + + + _createClass(Merge, [{ + key: "addToJSMap", + value: function addToJSMap(ctx, map) { + var _iterator = _createForOfIteratorHelper(this.value.items), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var source = _step.value.source; + if (!(source instanceof YAMLMap)) throw new Error('Merge sources must be maps'); + var srcMap = source.toJSON(null, ctx, Map); + + var _iterator2 = _createForOfIteratorHelper(srcMap), + _step2; + + try { + for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { + var _step2$value = _slicedToArray(_step2.value, 2), + key = _step2$value[0], + value = _step2$value[1]; + + if (map instanceof Map) { + if (!map.has(key)) map.set(key, value); + } else if (map instanceof Set) { + map.add(key); + } else { + if (!Object.prototype.hasOwnProperty.call(map, key)) map[key] = value; + } + } + } catch (err) { + _iterator2.e(err); + } finally { + _iterator2.f(); + } + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + + return map; + } + }, { + key: "toString", + value: function toString(ctx, onComment) { + var seq = this.value; + if (seq.items.length > 1) return _get(_getPrototypeOf(Merge.prototype), "toString", this).call(this, ctx, onComment); + this.value = seq.items[0]; + + var str = _get(_getPrototypeOf(Merge.prototype), "toString", this).call(this, ctx, onComment); + + this.value = seq; + return str; + } + }]); + + return Merge; +}(Pair); + +var binaryOptions = { + defaultType: Type.BLOCK_LITERAL, + lineWidth: 76 +}; +var boolOptions = { + trueStr: 'true', + falseStr: 'false' +}; +var intOptions = { + asBigInt: false +}; +var nullOptions = { + nullStr: 'null' +}; +var strOptions = { + defaultType: Type.PLAIN, + doubleQuoted: { + jsonEncoding: false, + minMultiLineLength: 40 + }, + fold: { + lineWidth: 80, + minContentWidth: 20 + } +}; + +function resolveScalar(str, tags, scalarFallback) { + var _iterator = _createForOfIteratorHelper(tags), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var _step$value = _step.value, + format = _step$value.format, + test = _step$value.test, + resolve = _step$value.resolve; + + if (test) { + var match = str.match(test); + + if (match) { + var res = resolve.apply(null, match); + if (!(res instanceof Scalar)) res = new Scalar(res); + if (format) res.format = format; + return res; + } + } + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + + if (scalarFallback) str = scalarFallback(str); + return new Scalar(str); +} + +var FOLD_FLOW = 'flow'; +var FOLD_BLOCK = 'block'; +var FOLD_QUOTED = 'quoted'; // presumes i+1 is at the start of a line +// returns index of last newline in more-indented block + +var consumeMoreIndentedLines = function consumeMoreIndentedLines(text, i) { + var ch = text[i + 1]; + + while (ch === ' ' || ch === '\t') { + do { + ch = text[i += 1]; + } while (ch && ch !== '\n'); + + ch = text[i + 1]; + } + + return i; +}; +/** + * Tries to keep input at up to `lineWidth` characters, splitting only on spaces + * not followed by newlines or spaces unless `mode` is `'quoted'`. Lines are + * terminated with `\n` and started with `indent`. + * + * @param {string} text + * @param {string} indent + * @param {string} [mode='flow'] `'block'` prevents more-indented lines + * from being folded; `'quoted'` allows for `\` escapes, including escaped + * newlines + * @param {Object} options + * @param {number} [options.indentAtStart] Accounts for leading contents on + * the first line, defaulting to `indent.length` + * @param {number} [options.lineWidth=80] + * @param {number} [options.minContentWidth=20] Allow highly indented lines to + * stretch the line width + * @param {function} options.onFold Called once if the text is folded + * @param {function} options.onFold Called once if any line of text exceeds + * lineWidth characters + */ + + +function foldFlowLines(text, indent, mode, _ref) { + var indentAtStart = _ref.indentAtStart, + _ref$lineWidth = _ref.lineWidth, + lineWidth = _ref$lineWidth === void 0 ? 80 : _ref$lineWidth, + _ref$minContentWidth = _ref.minContentWidth, + minContentWidth = _ref$minContentWidth === void 0 ? 20 : _ref$minContentWidth, + onFold = _ref.onFold, + onOverflow = _ref.onOverflow; + if (!lineWidth || lineWidth < 0) return text; + var endStep = Math.max(1 + minContentWidth, 1 + lineWidth - indent.length); + if (text.length <= endStep) return text; + var folds = []; + var escapedFolds = {}; + var end = lineWidth - (typeof indentAtStart === 'number' ? indentAtStart : indent.length); + var split = undefined; + var prev = undefined; + var overflow = false; + var i = -1; + + if (mode === FOLD_BLOCK) { + i = consumeMoreIndentedLines(text, i); + if (i !== -1) end = i + endStep; + } + + for (var ch; ch = text[i += 1];) { + if (mode === FOLD_QUOTED && ch === '\\') { + switch (text[i + 1]) { + case 'x': + i += 3; + break; + + case 'u': + i += 5; + break; + + case 'U': + i += 9; + break; + + default: + i += 1; + } + } + + if (ch === '\n') { + if (mode === FOLD_BLOCK) i = consumeMoreIndentedLines(text, i); + end = i + endStep; + split = undefined; + } else { + if (ch === ' ' && prev && prev !== ' ' && prev !== '\n' && prev !== '\t') { + // space surrounded by non-space can be replaced with newline + indent + var next = text[i + 1]; + if (next && next !== ' ' && next !== '\n' && next !== '\t') split = i; + } + + if (i >= end) { + if (split) { + folds.push(split); + end = split + endStep; + split = undefined; + } else if (mode === FOLD_QUOTED) { + // white-space collected at end may stretch past lineWidth + while (prev === ' ' || prev === '\t') { + prev = ch; + ch = text[i += 1]; + overflow = true; + } // i - 2 accounts for not-dropped last char + newline-escaping \ + + + folds.push(i - 2); + escapedFolds[i - 2] = true; + end = i - 2 + endStep; + split = undefined; + } else { + overflow = true; + } + } + } + + prev = ch; + } + + if (overflow && onOverflow) onOverflow(); + if (folds.length === 0) return text; + if (onFold) onFold(); + var res = text.slice(0, folds[0]); + + for (var _i = 0; _i < folds.length; ++_i) { + var fold = folds[_i]; + + var _end = folds[_i + 1] || text.length; + + if (mode === FOLD_QUOTED && escapedFolds[fold]) res += "".concat(text[fold], "\\"); + res += "\n".concat(indent).concat(text.slice(fold + 1, _end)); + } + + return res; +} + +var getFoldOptions = function getFoldOptions(_ref) { + var indentAtStart = _ref.indentAtStart; + return indentAtStart ? Object.assign({ + indentAtStart: indentAtStart + }, strOptions.fold) : strOptions.fold; +}; // Also checks for lines starting with %, as parsing the output as YAML 1.1 will +// presume that's starting a new document. + + +var containsDocumentMarker = function containsDocumentMarker(str) { + return /^(%|---|\.\.\.)/m.test(str); +}; + +function lineLengthOverLimit(str, limit) { + var strLen = str.length; + if (strLen <= limit) return false; + + for (var i = 0, start = 0; i < strLen; ++i) { + if (str[i] === '\n') { + if (i - start > limit) return true; + start = i + 1; + if (strLen - start <= limit) return false; + } + } + + return true; +} + +function doubleQuotedString(value, ctx) { + var implicitKey = ctx.implicitKey; + var _strOptions$doubleQuo = strOptions.doubleQuoted, + jsonEncoding = _strOptions$doubleQuo.jsonEncoding, + minMultiLineLength = _strOptions$doubleQuo.minMultiLineLength; + var json = JSON.stringify(value); + if (jsonEncoding) return json; + var indent = ctx.indent || (containsDocumentMarker(value) ? ' ' : ''); + var str = ''; + var start = 0; + + for (var i = 0, ch = json[i]; ch; ch = json[++i]) { + if (ch === ' ' && json[i + 1] === '\\' && json[i + 2] === 'n') { + // space before newline needs to be escaped to not be folded + str += json.slice(start, i) + '\\ '; + i += 1; + start = i; + ch = '\\'; + } + + if (ch === '\\') switch (json[i + 1]) { + case 'u': + { + str += json.slice(start, i); + var code = json.substr(i + 2, 4); + + switch (code) { + case '0000': + str += '\\0'; + break; + + case '0007': + str += '\\a'; + break; + + case '000b': + str += '\\v'; + break; + + case '001b': + str += '\\e'; + break; + + case '0085': + str += '\\N'; + break; + + case '00a0': + str += '\\_'; + break; + + case '2028': + str += '\\L'; + break; + + case '2029': + str += '\\P'; + break; + + default: + if (code.substr(0, 2) === '00') str += '\\x' + code.substr(2);else str += json.substr(i, 6); + } + + i += 5; + start = i + 1; + } + break; + + case 'n': + if (implicitKey || json[i + 2] === '"' || json.length < minMultiLineLength) { + i += 1; + } else { + // folding will eat first newline + str += json.slice(start, i) + '\n\n'; + + while (json[i + 2] === '\\' && json[i + 3] === 'n' && json[i + 4] !== '"') { + str += '\n'; + i += 2; + } + + str += indent; // space after newline needs to be escaped to not be folded + + if (json[i + 2] === ' ') str += '\\'; + i += 1; + start = i + 1; + } + + break; + + default: + i += 1; + } + } + + str = start ? str + json.slice(start) : json; + return implicitKey ? str : foldFlowLines(str, indent, FOLD_QUOTED, getFoldOptions(ctx)); +} + +function singleQuotedString(value, ctx) { + if (ctx.implicitKey) { + if (/\n/.test(value)) return doubleQuotedString(value, ctx); + } else { + // single quoted string can't have leading or trailing whitespace around newline + if (/[ \t]\n|\n[ \t]/.test(value)) return doubleQuotedString(value, ctx); + } + + var indent = ctx.indent || (containsDocumentMarker(value) ? ' ' : ''); + var res = "'" + value.replace(/'/g, "''").replace(/\n+/g, "$&\n".concat(indent)) + "'"; + return ctx.implicitKey ? res : foldFlowLines(res, indent, FOLD_FLOW, getFoldOptions(ctx)); +} + +function blockString(_ref2, ctx, onComment, onChompKeep) { + var comment = _ref2.comment, + type = _ref2.type, + value = _ref2.value; + + // 1. Block can't end in whitespace unless the last line is non-empty. + // 2. Strings consisting of only whitespace are best rendered explicitly. + if (/\n[\t ]+$/.test(value) || /^\s*$/.test(value)) { + return doubleQuotedString(value, ctx); + } + + var indent = ctx.indent || (ctx.forceBlockIndent || containsDocumentMarker(value) ? ' ' : ''); + var indentSize = indent ? '2' : '1'; // root is at -1 + + var literal = type === Type.BLOCK_FOLDED ? false : type === Type.BLOCK_LITERAL ? true : !lineLengthOverLimit(value, strOptions.fold.lineWidth - indent.length); + var header = literal ? '|' : '>'; + if (!value) return header + '\n'; + var wsStart = ''; + var wsEnd = ''; + value = value.replace(/[\n\t ]*$/, function (ws) { + var n = ws.indexOf('\n'); + + if (n === -1) { + header += '-'; // strip + } else if (value === ws || n !== ws.length - 1) { + header += '+'; // keep + + if (onChompKeep) onChompKeep(); + } + + wsEnd = ws.replace(/\n$/, ''); + return ''; + }).replace(/^[\n ]*/, function (ws) { + if (ws.indexOf(' ') !== -1) header += indentSize; + var m = ws.match(/ +$/); + + if (m) { + wsStart = ws.slice(0, -m[0].length); + return m[0]; + } else { + wsStart = ws; + return ''; + } + }); + if (wsEnd) wsEnd = wsEnd.replace(/\n+(?!\n|$)/g, "$&".concat(indent)); + if (wsStart) wsStart = wsStart.replace(/\n+/g, "$&".concat(indent)); + + if (comment) { + header += ' #' + comment.replace(/ ?[\r\n]+/g, ' '); + if (onComment) onComment(); + } + + if (!value) return "".concat(header).concat(indentSize, "\n").concat(indent).concat(wsEnd); + + if (literal) { + value = value.replace(/\n+/g, "$&".concat(indent)); + return "".concat(header, "\n").concat(indent).concat(wsStart).concat(value).concat(wsEnd); + } + + value = value.replace(/\n+/g, '\n$&').replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, '$1$2') // more-indented lines aren't folded + // ^ ind.line ^ empty ^ capture next empty lines only at end of indent + .replace(/\n+/g, "$&".concat(indent)); + var body = foldFlowLines("".concat(wsStart).concat(value).concat(wsEnd), indent, FOLD_BLOCK, strOptions.fold); + return "".concat(header, "\n").concat(indent).concat(body); +} + +function plainString(item, ctx, onComment, onChompKeep) { + var comment = item.comment, + type = item.type, + value = item.value; + var actualString = ctx.actualString, + implicitKey = ctx.implicitKey, + indent = ctx.indent, + inFlow = ctx.inFlow; + + if (implicitKey && /[\n[\]{},]/.test(value) || inFlow && /[[\]{},]/.test(value)) { + return doubleQuotedString(value, ctx); + } + + if (!value || /^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(value)) { + // not allowed: + // - empty string, '-' or '?' + // - start with an indicator character (except [?:-]) or /[?-] / + // - '\n ', ': ' or ' \n' anywhere + // - '#' not preceded by a non-space char + // - end with ' ' or ':' + return implicitKey || inFlow || value.indexOf('\n') === -1 ? value.indexOf('"') !== -1 && value.indexOf("'") === -1 ? singleQuotedString(value, ctx) : doubleQuotedString(value, ctx) : blockString(item, ctx, onComment, onChompKeep); + } + + if (!implicitKey && !inFlow && type !== Type.PLAIN && value.indexOf('\n') !== -1) { + // Where allowed & type not set explicitly, prefer block style for multiline strings + return blockString(item, ctx, onComment, onChompKeep); + } + + if (indent === '' && containsDocumentMarker(value)) { + ctx.forceBlockIndent = true; + return blockString(item, ctx, onComment, onChompKeep); + } + + var str = value.replace(/\n+/g, "$&\n".concat(indent)); // Verify that output will be parsed as a string, as e.g. plain numbers and + // booleans get parsed with those types in v1.2 (e.g. '42', 'true' & '0.9e-3'), + // and others in v1.1. + + if (actualString) { + var tags = ctx.doc.schema.tags; + var resolved = resolveScalar(str, tags, tags.scalarFallback).value; + if (typeof resolved !== 'string') return doubleQuotedString(value, ctx); + } + + var body = implicitKey ? str : foldFlowLines(str, indent, FOLD_FLOW, getFoldOptions(ctx)); + + if (comment && !inFlow && (body.indexOf('\n') !== -1 || comment.indexOf('\n') !== -1)) { + if (onComment) onComment(); + return addCommentBefore(body, indent, comment); + } + + return body; +} + +function stringifyString(item, ctx, onComment, onChompKeep) { + var defaultType = strOptions.defaultType; + var implicitKey = ctx.implicitKey, + inFlow = ctx.inFlow; + var _item = item, + type = _item.type, + value = _item.value; + + if (typeof value !== 'string') { + value = String(value); + item = Object.assign({}, item, { + value: value + }); + } + + var _stringify = function _stringify(_type) { + switch (_type) { + case Type.BLOCK_FOLDED: + case Type.BLOCK_LITERAL: + return blockString(item, ctx, onComment, onChompKeep); + + case Type.QUOTE_DOUBLE: + return doubleQuotedString(value, ctx); + + case Type.QUOTE_SINGLE: + return singleQuotedString(value, ctx); + + case Type.PLAIN: + return plainString(item, ctx, onComment, onChompKeep); + + default: + return null; + } + }; + + if (type !== Type.QUOTE_DOUBLE && /[\x00-\x08\x0b-\x1f\x7f-\x9f]/.test(value)) { + // force double quotes on control characters + type = Type.QUOTE_DOUBLE; + } else if ((implicitKey || inFlow) && (type === Type.BLOCK_FOLDED || type === Type.BLOCK_LITERAL)) { + // should not happen; blocks are not valid inside flow containers + type = Type.QUOTE_DOUBLE; + } + + var res = _stringify(type); + + if (res === null) { + res = _stringify(defaultType); + if (res === null) throw new Error("Unsupported default string type ".concat(defaultType)); + } + + return res; +} + +function stringifyNumber(_ref) { + var format = _ref.format, + minFractionDigits = _ref.minFractionDigits, + tag = _ref.tag, + value = _ref.value; + if (typeof value === 'bigint') return String(value); + if (!isFinite(value)) return isNaN(value) ? '.nan' : value < 0 ? '-.inf' : '.inf'; + var n = JSON.stringify(value); + + if (!format && minFractionDigits && (!tag || tag === 'tag:yaml.org,2002:float') && /^\d/.test(n)) { + var i = n.indexOf('.'); + + if (i < 0) { + i = n.length; + n += '.'; + } + + var d = minFractionDigits - (n.length - i - 1); + + while (d-- > 0) { + n += '0'; + } + } + + return n; +} + +function checkFlowCollectionEnd(errors, cst) { + var char, name; + + switch (cst.type) { + case Type.FLOW_MAP: + char = '}'; + name = 'flow map'; + break; + + case Type.FLOW_SEQ: + char = ']'; + name = 'flow sequence'; + break; + + default: + errors.push(new YAMLSemanticError(cst, 'Not a flow collection!?')); + return; + } + + var lastItem; + + for (var i = cst.items.length - 1; i >= 0; --i) { + var item = cst.items[i]; + + if (!item || item.type !== Type.COMMENT) { + lastItem = item; + break; + } + } + + if (lastItem && lastItem.char !== char) { + var msg = "Expected ".concat(name, " to end with ").concat(char); + var err; + + if (typeof lastItem.offset === 'number') { + err = new YAMLSemanticError(cst, msg); + err.offset = lastItem.offset + 1; + } else { + err = new YAMLSemanticError(lastItem, msg); + if (lastItem.range && lastItem.range.end) err.offset = lastItem.range.end - lastItem.range.start; + } + + errors.push(err); + } +} +function checkFlowCommentSpace(errors, comment) { + var prev = comment.context.src[comment.range.start - 1]; + + if (prev !== '\n' && prev !== '\t' && prev !== ' ') { + var msg = 'Comments must be separated from other tokens by white space characters'; + errors.push(new YAMLSemanticError(comment, msg)); + } +} +function getLongKeyError(source, key) { + var sk = String(key); + var k = sk.substr(0, 8) + '...' + sk.substr(-8); + return new YAMLSemanticError(source, "The \"".concat(k, "\" key is too long")); +} +function resolveComments(collection, comments) { + var _iterator = _createForOfIteratorHelper(comments), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var _step$value = _step.value, + afterKey = _step$value.afterKey, + before = _step$value.before, + comment = _step$value.comment; + var item = collection.items[before]; + + if (!item) { + if (comment !== undefined) { + if (collection.comment) collection.comment += '\n' + comment;else collection.comment = comment; + } + } else { + if (afterKey && item.value) item = item.value; + + if (comment === undefined) { + if (afterKey || !item.commentBefore) item.spaceBefore = true; + } else { + if (item.commentBefore) item.commentBefore += '\n' + comment;else item.commentBefore = comment; + } + } + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } +} + +// on error, will return { str: string, errors: Error[] } +function resolveString(doc, node) { + var res = node.strValue; + if (!res) return ''; + if (typeof res === 'string') return res; + res.errors.forEach(function (error) { + if (!error.source) error.source = node; + doc.errors.push(error); + }); + return res.str; +} + +function resolveTagHandle(doc, node) { + var _node$tag = node.tag, + handle = _node$tag.handle, + suffix = _node$tag.suffix; + var prefix = doc.tagPrefixes.find(function (p) { + return p.handle === handle; + }); + + if (!prefix) { + var dtp = doc.getDefaults().tagPrefixes; + if (dtp) prefix = dtp.find(function (p) { + return p.handle === handle; + }); + if (!prefix) throw new YAMLSemanticError(node, "The ".concat(handle, " tag handle is non-default and was not declared.")); + } + + if (!suffix) throw new YAMLSemanticError(node, "The ".concat(handle, " tag has no suffix.")); + + if (handle === '!' && (doc.version || doc.options.version) === '1.0') { + if (suffix[0] === '^') { + doc.warnings.push(new YAMLWarning(node, 'YAML 1.0 ^ tag expansion is not supported')); + return suffix; + } + + if (/[:/]/.test(suffix)) { + // word/foo -> tag:word.yaml.org,2002:foo + var vocab = suffix.match(/^([a-z0-9-]+)\/(.*)/i); + return vocab ? "tag:".concat(vocab[1], ".yaml.org,2002:").concat(vocab[2]) : "tag:".concat(suffix); + } + } + + return prefix.prefix + decodeURIComponent(suffix); +} + +function resolveTagName(doc, node) { + var tag = node.tag, + type = node.type; + var nonSpecific = false; + + if (tag) { + var handle = tag.handle, + suffix = tag.suffix, + verbatim = tag.verbatim; + + if (verbatim) { + if (verbatim !== '!' && verbatim !== '!!') return verbatim; + var msg = "Verbatim tags aren't resolved, so ".concat(verbatim, " is invalid."); + doc.errors.push(new YAMLSemanticError(node, msg)); + } else if (handle === '!' && !suffix) { + nonSpecific = true; + } else { + try { + return resolveTagHandle(doc, node); + } catch (error) { + doc.errors.push(error); + } + } + } + + switch (type) { + case Type.BLOCK_FOLDED: + case Type.BLOCK_LITERAL: + case Type.QUOTE_DOUBLE: + case Type.QUOTE_SINGLE: + return defaultTags.STR; + + case Type.FLOW_MAP: + case Type.MAP: + return defaultTags.MAP; + + case Type.FLOW_SEQ: + case Type.SEQ: + return defaultTags.SEQ; + + case Type.PLAIN: + return nonSpecific ? defaultTags.STR : null; + + default: + return null; + } +} + +function resolveByTagName(doc, node, tagName) { + var tags = doc.schema.tags; + var matchWithTest = []; + + var _iterator = _createForOfIteratorHelper(tags), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var tag = _step.value; + + if (tag.tag === tagName) { + if (tag.test) matchWithTest.push(tag);else { + var res = tag.resolve(doc, node); + return res instanceof Collection ? res : new Scalar(res); + } + } + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + + var str = resolveString(doc, node); + if (typeof str === 'string' && matchWithTest.length > 0) return resolveScalar(str, matchWithTest, tags.scalarFallback); + return null; +} + +function getFallbackTagName(_ref) { + var type = _ref.type; + + switch (type) { + case Type.FLOW_MAP: + case Type.MAP: + return defaultTags.MAP; + + case Type.FLOW_SEQ: + case Type.SEQ: + return defaultTags.SEQ; + + default: + return defaultTags.STR; + } +} + +function resolveTag(doc, node, tagName) { + try { + var res = resolveByTagName(doc, node, tagName); + + if (res) { + if (tagName && node.tag) res.tag = tagName; + return res; + } + } catch (error) { + /* istanbul ignore if */ + if (!error.source) error.source = node; + doc.errors.push(error); + return null; + } + + try { + var fallback = getFallbackTagName(node); + if (!fallback) throw new Error("The tag ".concat(tagName, " is unavailable")); + var msg = "The tag ".concat(tagName, " is unavailable, falling back to ").concat(fallback); + doc.warnings.push(new YAMLWarning(node, msg)); + + var _res = resolveByTagName(doc, node, fallback); + + _res.tag = tagName; + return _res; + } catch (error) { + var refError = new YAMLReferenceError(node, error.message); + refError.stack = error.stack; + doc.errors.push(refError); + return null; + } +} + +var isCollectionItem = function isCollectionItem(node) { + if (!node) return false; + var type = node.type; + return type === Type.MAP_KEY || type === Type.MAP_VALUE || type === Type.SEQ_ITEM; +}; + +function resolveNodeProps(errors, node) { + var comments = { + before: [], + after: [] + }; + var hasAnchor = false; + var hasTag = false; + var props = isCollectionItem(node.context.parent) ? node.context.parent.props.concat(node.props) : node.props; + + var _iterator = _createForOfIteratorHelper(props), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var _step$value = _step.value, + start = _step$value.start, + end = _step$value.end; + + switch (node.context.src[start]) { + case Char.COMMENT: + { + if (!node.commentHasRequiredWhitespace(start)) { + var msg = 'Comments must be separated from other tokens by white space characters'; + errors.push(new YAMLSemanticError(node, msg)); + } + + var header = node.header, + valueRange = node.valueRange; + var cc = valueRange && (start > valueRange.start || header && start > header.start) ? comments.after : comments.before; + cc.push(node.context.src.slice(start + 1, end)); + break; + } + // Actual anchor & tag resolution is handled by schema, here we just complain + + case Char.ANCHOR: + if (hasAnchor) { + var _msg = 'A node can have at most one anchor'; + errors.push(new YAMLSemanticError(node, _msg)); + } + + hasAnchor = true; + break; + + case Char.TAG: + if (hasTag) { + var _msg2 = 'A node can have at most one tag'; + errors.push(new YAMLSemanticError(node, _msg2)); + } + + hasTag = true; + break; + } + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + + return { + comments: comments, + hasAnchor: hasAnchor, + hasTag: hasTag + }; +} + +function resolveNodeValue(doc, node) { + var anchors = doc.anchors, + errors = doc.errors, + schema = doc.schema; + + if (node.type === Type.ALIAS) { + var name = node.rawValue; + var src = anchors.getNode(name); + + if (!src) { + var msg = "Aliased anchor not found: ".concat(name); + errors.push(new YAMLReferenceError(node, msg)); + return null; + } // Lazy resolution for circular references + + + var res = new Alias(src); + + anchors._cstAliases.push(res); + + return res; + } + + var tagName = resolveTagName(doc, node); + if (tagName) return resolveTag(doc, node, tagName); + + if (node.type !== Type.PLAIN) { + var _msg3 = "Failed to resolve ".concat(node.type, " node here"); + + errors.push(new YAMLSyntaxError(node, _msg3)); + return null; + } + + try { + var str = resolveString(doc, node); + return resolveScalar(str, schema.tags, schema.tags.scalarFallback); + } catch (error) { + if (!error.source) error.source = node; + errors.push(error); + return null; + } +} // sets node.resolved on success + + +function resolveNode(doc, node) { + if (!node) return null; + if (node.error) doc.errors.push(node.error); + + var _resolveNodeProps = resolveNodeProps(doc.errors, node), + comments = _resolveNodeProps.comments, + hasAnchor = _resolveNodeProps.hasAnchor, + hasTag = _resolveNodeProps.hasTag; + + if (hasAnchor) { + var anchors = doc.anchors; + var name = node.anchor; + var prev = anchors.getNode(name); // At this point, aliases for any preceding node with the same anchor + // name have already been resolved, so it may safely be renamed. + + if (prev) anchors.map[anchors.newName(name)] = prev; // During parsing, we need to store the CST node in anchors.map as + // anchors need to be available during resolution to allow for + // circular references. + + anchors.map[name] = node; + } + + if (node.type === Type.ALIAS && (hasAnchor || hasTag)) { + var msg = 'An alias node must not specify any properties'; + doc.errors.push(new YAMLSemanticError(node, msg)); + } + + var res = resolveNodeValue(doc, node); + + if (res) { + res.range = [node.range.start, node.range.end]; + if (doc.options.keepCstNodes) res.cstNode = node; + if (doc.options.keepNodeTypes) res.type = node.type; + var cb = comments.before.join('\n'); + + if (cb) { + res.commentBefore = res.commentBefore ? "".concat(res.commentBefore, "\n").concat(cb) : cb; + } + + var ca = comments.after.join('\n'); + if (ca) res.comment = res.comment ? "".concat(res.comment, "\n").concat(ca) : ca; + } + + return node.resolved = res; +} + +function resolveMap(doc, cst) { + if (cst.type !== Type.MAP && cst.type !== Type.FLOW_MAP) { + var msg = "A ".concat(cst.type, " node cannot be resolved as a mapping"); + doc.errors.push(new YAMLSyntaxError(cst, msg)); + return null; + } + + var _ref = cst.type === Type.FLOW_MAP ? resolveFlowMapItems(doc, cst) : resolveBlockMapItems(doc, cst), + comments = _ref.comments, + items = _ref.items; + + var map = new YAMLMap(); + map.items = items; + resolveComments(map, comments); + var hasCollectionKey = false; + + for (var i = 0; i < items.length; ++i) { + var iKey = items[i].key; + if (iKey instanceof Collection) hasCollectionKey = true; + + if (doc.schema.merge && iKey && iKey.value === MERGE_KEY) { + items[i] = new Merge(items[i]); + var sources = items[i].value.items; + var error = null; + sources.some(function (node) { + if (node instanceof Alias) { + // During parsing, alias sources are CST nodes; to account for + // circular references their resolved values can't be used here. + var type = node.source.type; + if (type === Type.MAP || type === Type.FLOW_MAP) return false; + return error = 'Merge nodes aliases can only point to maps'; + } + + return error = 'Merge nodes can only have Alias nodes as values'; + }); + if (error) doc.errors.push(new YAMLSemanticError(cst, error)); + } else { + for (var j = i + 1; j < items.length; ++j) { + var jKey = items[j].key; + + if (iKey === jKey || iKey && jKey && Object.prototype.hasOwnProperty.call(iKey, 'value') && iKey.value === jKey.value) { + var _msg = "Map keys must be unique; \"".concat(iKey, "\" is repeated"); + + doc.errors.push(new YAMLSemanticError(cst, _msg)); + break; + } + } + } + } + + if (hasCollectionKey && !doc.options.mapAsMap) { + var warn = 'Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.'; + doc.warnings.push(new YAMLWarning(cst, warn)); + } + + cst.resolved = map; + return map; +} + +var valueHasPairComment = function valueHasPairComment(_ref2) { + var _ref2$context = _ref2.context, + lineStart = _ref2$context.lineStart, + node = _ref2$context.node, + src = _ref2$context.src, + props = _ref2.props; + if (props.length === 0) return false; + var start = props[0].start; + if (node && start > node.valueRange.start) return false; + if (src[start] !== Char.COMMENT) return false; + + for (var i = lineStart; i < start; ++i) { + if (src[i] === '\n') return false; + } + + return true; +}; + +function resolvePairComment(item, pair) { + if (!valueHasPairComment(item)) return; + var comment = item.getPropValue(0, Char.COMMENT, true); + var found = false; + var cb = pair.value.commentBefore; + + if (cb && cb.startsWith(comment)) { + pair.value.commentBefore = cb.substr(comment.length + 1); + found = true; + } else { + var cc = pair.value.comment; + + if (!item.node && cc && cc.startsWith(comment)) { + pair.value.comment = cc.substr(comment.length + 1); + found = true; + } + } + + if (found) pair.comment = comment; +} + +function resolveBlockMapItems(doc, cst) { + var comments = []; + var items = []; + var key = undefined; + var keyStart = null; + + for (var i = 0; i < cst.items.length; ++i) { + var item = cst.items[i]; + + switch (item.type) { + case Type.BLANK_LINE: + comments.push({ + afterKey: !!key, + before: items.length + }); + break; + + case Type.COMMENT: + comments.push({ + afterKey: !!key, + before: items.length, + comment: item.comment + }); + break; + + case Type.MAP_KEY: + if (key !== undefined) items.push(new Pair(key)); + if (item.error) doc.errors.push(item.error); + key = resolveNode(doc, item.node); + keyStart = null; + break; + + case Type.MAP_VALUE: + { + if (key === undefined) key = null; + if (item.error) doc.errors.push(item.error); + + if (!item.context.atLineStart && item.node && item.node.type === Type.MAP && !item.node.context.atLineStart) { + var msg = 'Nested mappings are not allowed in compact mappings'; + doc.errors.push(new YAMLSemanticError(item.node, msg)); + } + + var valueNode = item.node; + + if (!valueNode && item.props.length > 0) { + // Comments on an empty mapping value need to be preserved, so we + // need to construct a minimal empty node here to use instead of the + // missing `item.node`. -- eemeli/yaml#19 + valueNode = new PlainValue(Type.PLAIN, []); + valueNode.context = { + parent: item, + src: item.context.src + }; + var pos = item.range.start + 1; + valueNode.range = { + start: pos, + end: pos + }; + valueNode.valueRange = { + start: pos, + end: pos + }; + + if (typeof item.range.origStart === 'number') { + var origPos = item.range.origStart + 1; + valueNode.range.origStart = valueNode.range.origEnd = origPos; + valueNode.valueRange.origStart = valueNode.valueRange.origEnd = origPos; + } + } + + var pair = new Pair(key, resolveNode(doc, valueNode)); + resolvePairComment(item, pair); + items.push(pair); + + if (key && typeof keyStart === 'number') { + if (item.range.start > keyStart + 1024) doc.errors.push(getLongKeyError(cst, key)); + } + + key = undefined; + keyStart = null; + } + break; + + default: + if (key !== undefined) items.push(new Pair(key)); + key = resolveNode(doc, item); + keyStart = item.range.start; + if (item.error) doc.errors.push(item.error); + + next: for (var j = i + 1;; ++j) { + var nextItem = cst.items[j]; + + switch (nextItem && nextItem.type) { + case Type.BLANK_LINE: + case Type.COMMENT: + continue next; + + case Type.MAP_VALUE: + break next; + + default: + { + var _msg2 = 'Implicit map keys need to be followed by map values'; + doc.errors.push(new YAMLSemanticError(item, _msg2)); + break next; + } + } + } + + if (item.valueRangeContainsNewline) { + var _msg3 = 'Implicit map keys need to be on a single line'; + doc.errors.push(new YAMLSemanticError(item, _msg3)); + } + + } + } + + if (key !== undefined) items.push(new Pair(key)); + return { + comments: comments, + items: items + }; +} + +function resolveFlowMapItems(doc, cst) { + var comments = []; + var items = []; + var key = undefined; + var explicitKey = false; + var next = '{'; + + for (var i = 0; i < cst.items.length; ++i) { + var item = cst.items[i]; + + if (typeof item.char === 'string') { + var char = item.char, + offset = item.offset; + + if (char === '?' && key === undefined && !explicitKey) { + explicitKey = true; + next = ':'; + continue; + } + + if (char === ':') { + if (key === undefined) key = null; + + if (next === ':') { + next = ','; + continue; + } + } else { + if (explicitKey) { + if (key === undefined && char !== ',') key = null; + explicitKey = false; + } + + if (key !== undefined) { + items.push(new Pair(key)); + key = undefined; + + if (char === ',') { + next = ':'; + continue; + } + } + } + + if (char === '}') { + if (i === cst.items.length - 1) continue; + } else if (char === next) { + next = ':'; + continue; + } + + var msg = "Flow map contains an unexpected ".concat(char); + var err = new YAMLSyntaxError(cst, msg); + err.offset = offset; + doc.errors.push(err); + } else if (item.type === Type.BLANK_LINE) { + comments.push({ + afterKey: !!key, + before: items.length + }); + } else if (item.type === Type.COMMENT) { + checkFlowCommentSpace(doc.errors, item); + comments.push({ + afterKey: !!key, + before: items.length, + comment: item.comment + }); + } else if (key === undefined) { + if (next === ',') doc.errors.push(new YAMLSemanticError(item, 'Separator , missing in flow map')); + key = resolveNode(doc, item); + } else { + if (next !== ',') doc.errors.push(new YAMLSemanticError(item, 'Indicator : missing in flow map entry')); + items.push(new Pair(key, resolveNode(doc, item))); + key = undefined; + explicitKey = false; + } + } + + checkFlowCollectionEnd(doc.errors, cst); + if (key !== undefined) items.push(new Pair(key)); + return { + comments: comments, + items: items + }; +} + +function resolveSeq(doc, cst) { + if (cst.type !== Type.SEQ && cst.type !== Type.FLOW_SEQ) { + var msg = "A ".concat(cst.type, " node cannot be resolved as a sequence"); + doc.errors.push(new YAMLSyntaxError(cst, msg)); + return null; + } + + var _ref = cst.type === Type.FLOW_SEQ ? resolveFlowSeqItems(doc, cst) : resolveBlockSeqItems(doc, cst), + comments = _ref.comments, + items = _ref.items; + + var seq = new YAMLSeq(); + seq.items = items; + resolveComments(seq, comments); + + if (!doc.options.mapAsMap && items.some(function (it) { + return it instanceof Pair && it.key instanceof Collection; + })) { + var warn = 'Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.'; + doc.warnings.push(new YAMLWarning(cst, warn)); + } + + cst.resolved = seq; + return seq; +} + +function resolveBlockSeqItems(doc, cst) { + var comments = []; + var items = []; + + for (var i = 0; i < cst.items.length; ++i) { + var item = cst.items[i]; + + switch (item.type) { + case Type.BLANK_LINE: + comments.push({ + before: items.length + }); + break; + + case Type.COMMENT: + comments.push({ + comment: item.comment, + before: items.length + }); + break; + + case Type.SEQ_ITEM: + if (item.error) doc.errors.push(item.error); + items.push(resolveNode(doc, item.node)); + + if (item.hasProps) { + var msg = 'Sequence items cannot have tags or anchors before the - indicator'; + doc.errors.push(new YAMLSemanticError(item, msg)); + } + + break; + + default: + if (item.error) doc.errors.push(item.error); + doc.errors.push(new YAMLSyntaxError(item, "Unexpected ".concat(item.type, " node in sequence"))); + } + } + + return { + comments: comments, + items: items + }; +} + +function resolveFlowSeqItems(doc, cst) { + var comments = []; + var items = []; + var explicitKey = false; + var key = undefined; + var keyStart = null; + var next = '['; + var prevItem = null; + + for (var i = 0; i < cst.items.length; ++i) { + var item = cst.items[i]; + + if (typeof item.char === 'string') { + var char = item.char, + offset = item.offset; + + if (char !== ':' && (explicitKey || key !== undefined)) { + if (explicitKey && key === undefined) key = next ? items.pop() : null; + items.push(new Pair(key)); + explicitKey = false; + key = undefined; + keyStart = null; + } + + if (char === next) { + next = null; + } else if (!next && char === '?') { + explicitKey = true; + } else if (next !== '[' && char === ':' && key === undefined) { + if (next === ',') { + key = items.pop(); + + if (key instanceof Pair) { + var msg = 'Chaining flow sequence pairs is invalid'; + var err = new YAMLSemanticError(cst, msg); + err.offset = offset; + doc.errors.push(err); + } + + if (!explicitKey && typeof keyStart === 'number') { + var keyEnd = item.range ? item.range.start : item.offset; + if (keyEnd > keyStart + 1024) doc.errors.push(getLongKeyError(cst, key)); + var src = prevItem.context.src; + + for (var _i = keyStart; _i < keyEnd; ++_i) { + if (src[_i] === '\n') { + var _msg = 'Implicit keys of flow sequence pairs need to be on a single line'; + doc.errors.push(new YAMLSemanticError(prevItem, _msg)); + break; + } + } + } + } else { + key = null; + } + + keyStart = null; + explicitKey = false; + next = null; + } else if (next === '[' || char !== ']' || i < cst.items.length - 1) { + var _msg2 = "Flow sequence contains an unexpected ".concat(char); + + var _err = new YAMLSyntaxError(cst, _msg2); + + _err.offset = offset; + doc.errors.push(_err); + } + } else if (item.type === Type.BLANK_LINE) { + comments.push({ + before: items.length + }); + } else if (item.type === Type.COMMENT) { + checkFlowCommentSpace(doc.errors, item); + comments.push({ + comment: item.comment, + before: items.length + }); + } else { + if (next) { + var _msg3 = "Expected a ".concat(next, " in flow sequence"); + + doc.errors.push(new YAMLSemanticError(item, _msg3)); + } + + var value = resolveNode(doc, item); + + if (key === undefined) { + items.push(value); + prevItem = item; + } else { + items.push(new Pair(key, value)); + key = undefined; + } + + keyStart = item.range.start; + next = ','; + } + } + + checkFlowCollectionEnd(doc.errors, cst); + if (key !== undefined) items.push(new Pair(key)); + return { + comments: comments, + items: items + }; +} + +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 }; diff --git a/node_modules/yaml/browser/dist/types.js b/node_modules/yaml/browser/dist/types.js new file mode 100644 index 0000000..01b525f --- /dev/null +++ b/node_modules/yaml/browser/dist/types.js @@ -0,0 +1,4 @@ +import './PlainValue-ff5147c6.js'; +export { A as Alias, C as Collection, M as Merge, N as Node, P as Pair, S as Scalar, d as YAMLMap, Y as YAMLSeq, b as binaryOptions, a as boolOptions, i as intOptions, n as nullOptions, s as strOptions } from './resolveSeq-04825f30.js'; +export { S as Schema } from './Schema-2bf2c74e.js'; +import './warnings-0e4b70d3.js'; diff --git a/node_modules/yaml/browser/dist/util.js b/node_modules/yaml/browser/dist/util.js new file mode 100644 index 0000000..987eab8 --- /dev/null +++ b/node_modules/yaml/browser/dist/util.js @@ -0,0 +1,2 @@ +export { T as Type, i as YAMLError, o as YAMLReferenceError, g as YAMLSemanticError, Y as YAMLSyntaxError, f as YAMLWarning } from './PlainValue-ff5147c6.js'; +export { l as findPair, g as parseMap, h as parseSeq, k as stringifyNumber, c as stringifyString, t as toJSON } from './resolveSeq-04825f30.js'; diff --git a/node_modules/yaml/browser/dist/warnings-0e4b70d3.js b/node_modules/yaml/browser/dist/warnings-0e4b70d3.js new file mode 100644 index 0000000..4150492 --- /dev/null +++ b/node_modules/yaml/browser/dist/warnings-0e4b70d3.js @@ -0,0 +1,499 @@ +import { o as YAMLReferenceError, T as Type, g as YAMLSemanticError, _ as _createForOfIteratorHelper, e as _defineProperty, j as _inherits, k as _createSuper, c as _classCallCheck, p as _assertThisInitialized, b as _createClass, a as _typeof, l as _get, m as _getPrototypeOf } from './PlainValue-ff5147c6.js'; +import { j as resolveString, b as binaryOptions, c as stringifyString, h as resolveSeq, P as Pair, d as YAMLMap, Y as YAMLSeq, t as toJSON, S as Scalar, l as findPair, g as resolveMap, k as stringifyNumber } from './resolveSeq-04825f30.js'; + +/* global atob, btoa, Buffer */ +var binary = { + identify: function identify(value) { + return value instanceof Uint8Array; + }, + // Buffer inherits from Uint8Array + default: false, + tag: 'tag:yaml.org,2002:binary', + + /** + * Returns a Buffer in node and an Uint8Array in browsers + * + * To use the resulting buffer as an image, you'll want to do something like: + * + * const blob = new Blob([buffer], { type: 'image/jpeg' }) + * document.querySelector('#photo').src = URL.createObjectURL(blob) + */ + resolve: function resolve(doc, node) { + var src = resolveString(doc, node); + + if (typeof Buffer === 'function') { + return Buffer.from(src, 'base64'); + } else if (typeof atob === 'function') { + // On IE 11, atob() can't handle newlines + var str = atob(src.replace(/[\n\r]/g, '')); + var buffer = new Uint8Array(str.length); + + for (var i = 0; i < str.length; ++i) { + buffer[i] = str.charCodeAt(i); + } + + return buffer; + } else { + var msg = 'This environment does not support reading binary tags; either Buffer or atob is required'; + doc.errors.push(new YAMLReferenceError(node, msg)); + return null; + } + }, + options: binaryOptions, + stringify: function stringify(_ref, ctx, onComment, onChompKeep) { + var comment = _ref.comment, + type = _ref.type, + value = _ref.value; + var src; + + if (typeof Buffer === 'function') { + src = value instanceof Buffer ? value.toString('base64') : Buffer.from(value.buffer).toString('base64'); + } else if (typeof btoa === 'function') { + var s = ''; + + for (var i = 0; i < value.length; ++i) { + s += String.fromCharCode(value[i]); + } + + src = btoa(s); + } else { + throw new Error('This environment does not support writing binary tags; either Buffer or btoa is required'); + } + + if (!type) type = binaryOptions.defaultType; + + if (type === Type.QUOTE_DOUBLE) { + value = src; + } else { + var lineWidth = binaryOptions.lineWidth; + var n = Math.ceil(src.length / lineWidth); + var lines = new Array(n); + + for (var _i = 0, o = 0; _i < n; ++_i, o += lineWidth) { + lines[_i] = src.substr(o, lineWidth); + } + + value = lines.join(type === Type.BLOCK_LITERAL ? '\n' : ' '); + } + + return stringifyString({ + comment: comment, + type: type, + value: value + }, ctx, onComment, onChompKeep); + } +}; + +function parsePairs(doc, cst) { + var seq = resolveSeq(doc, cst); + + for (var i = 0; i < seq.items.length; ++i) { + var item = seq.items[i]; + if (item instanceof Pair) continue;else if (item instanceof YAMLMap) { + if (item.items.length > 1) { + var msg = 'Each pair must have its own sequence indicator'; + throw new YAMLSemanticError(cst, msg); + } + + var pair = item.items[0] || new Pair(); + if (item.commentBefore) pair.commentBefore = pair.commentBefore ? "".concat(item.commentBefore, "\n").concat(pair.commentBefore) : item.commentBefore; + if (item.comment) pair.comment = pair.comment ? "".concat(item.comment, "\n").concat(pair.comment) : item.comment; + item = pair; + } + seq.items[i] = item instanceof Pair ? item : new Pair(item); + } + + return seq; +} +function createPairs(schema, iterable, ctx) { + var pairs = new YAMLSeq(schema); + pairs.tag = 'tag:yaml.org,2002:pairs'; + + var _iterator = _createForOfIteratorHelper(iterable), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var it = _step.value; + var key = void 0, + value = void 0; + + if (Array.isArray(it)) { + if (it.length === 2) { + key = it[0]; + value = it[1]; + } else throw new TypeError("Expected [key, value] tuple: ".concat(it)); + } else if (it && it instanceof Object) { + var keys = Object.keys(it); + + if (keys.length === 1) { + key = keys[0]; + value = it[key]; + } else throw new TypeError("Expected { key: value } tuple: ".concat(it)); + } else { + key = it; + } + + var pair = schema.createPair(key, value, ctx); + pairs.items.push(pair); + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + + return pairs; +} +var pairs = { + default: false, + tag: 'tag:yaml.org,2002:pairs', + resolve: parsePairs, + createNode: createPairs +}; + +var YAMLOMap = /*#__PURE__*/function (_YAMLSeq) { + _inherits(YAMLOMap, _YAMLSeq); + + var _super = _createSuper(YAMLOMap); + + function YAMLOMap() { + var _this; + + _classCallCheck(this, YAMLOMap); + + _this = _super.call(this); + + _defineProperty(_assertThisInitialized(_this), "add", YAMLMap.prototype.add.bind(_assertThisInitialized(_this))); + + _defineProperty(_assertThisInitialized(_this), "delete", YAMLMap.prototype.delete.bind(_assertThisInitialized(_this))); + + _defineProperty(_assertThisInitialized(_this), "get", YAMLMap.prototype.get.bind(_assertThisInitialized(_this))); + + _defineProperty(_assertThisInitialized(_this), "has", YAMLMap.prototype.has.bind(_assertThisInitialized(_this))); + + _defineProperty(_assertThisInitialized(_this), "set", YAMLMap.prototype.set.bind(_assertThisInitialized(_this))); + + _this.tag = YAMLOMap.tag; + return _this; + } + + _createClass(YAMLOMap, [{ + key: "toJSON", + value: function toJSON$1(_, ctx) { + var map = new Map(); + if (ctx && ctx.onCreate) ctx.onCreate(map); + + var _iterator = _createForOfIteratorHelper(this.items), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var pair = _step.value; + var key = void 0, + value = void 0; + + if (pair instanceof Pair) { + key = toJSON(pair.key, '', ctx); + value = toJSON(pair.value, key, ctx); + } else { + key = toJSON(pair, '', ctx); + } + + if (map.has(key)) throw new Error('Ordered maps must not include duplicate keys'); + map.set(key, value); + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + + return map; + } + }]); + + return YAMLOMap; +}(YAMLSeq); + +_defineProperty(YAMLOMap, "tag", 'tag:yaml.org,2002:omap'); + +function parseOMap(doc, cst) { + var pairs = parsePairs(doc, cst); + var seenKeys = []; + + var _iterator2 = _createForOfIteratorHelper(pairs.items), + _step2; + + try { + for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { + var key = _step2.value.key; + + if (key instanceof Scalar) { + if (seenKeys.includes(key.value)) { + var msg = 'Ordered maps must not include duplicate keys'; + throw new YAMLSemanticError(cst, msg); + } else { + seenKeys.push(key.value); + } + } + } + } catch (err) { + _iterator2.e(err); + } finally { + _iterator2.f(); + } + + return Object.assign(new YAMLOMap(), pairs); +} + +function createOMap(schema, iterable, ctx) { + var pairs = createPairs(schema, iterable, ctx); + var omap = new YAMLOMap(); + omap.items = pairs.items; + return omap; +} + +var omap = { + identify: function identify(value) { + return value instanceof Map; + }, + nodeClass: YAMLOMap, + default: false, + tag: 'tag:yaml.org,2002:omap', + resolve: parseOMap, + createNode: createOMap +}; + +var YAMLSet = /*#__PURE__*/function (_YAMLMap) { + _inherits(YAMLSet, _YAMLMap); + + var _super = _createSuper(YAMLSet); + + function YAMLSet() { + var _this; + + _classCallCheck(this, YAMLSet); + + _this = _super.call(this); + _this.tag = YAMLSet.tag; + return _this; + } + + _createClass(YAMLSet, [{ + key: "add", + value: function add(key) { + var pair = key instanceof Pair ? key : new Pair(key); + var prev = findPair(this.items, pair.key); + if (!prev) this.items.push(pair); + } + }, { + key: "get", + value: function get(key, keepPair) { + var pair = findPair(this.items, key); + return !keepPair && pair instanceof Pair ? pair.key instanceof Scalar ? pair.key.value : pair.key : pair; + } + }, { + key: "set", + value: function set(key, value) { + if (typeof value !== 'boolean') throw new Error("Expected boolean value for set(key, value) in a YAML set, not ".concat(_typeof(value))); + var prev = findPair(this.items, key); + + if (prev && !value) { + this.items.splice(this.items.indexOf(prev), 1); + } else if (!prev && value) { + this.items.push(new Pair(key)); + } + } + }, { + key: "toJSON", + value: function toJSON(_, ctx) { + return _get(_getPrototypeOf(YAMLSet.prototype), "toJSON", this).call(this, _, ctx, Set); + } + }, { + key: "toString", + value: function toString(ctx, onComment, onChompKeep) { + if (!ctx) return JSON.stringify(this); + if (this.hasAllNullValues()) return _get(_getPrototypeOf(YAMLSet.prototype), "toString", this).call(this, ctx, onComment, onChompKeep);else throw new Error('Set items must all have null values'); + } + }]); + + return YAMLSet; +}(YAMLMap); + +_defineProperty(YAMLSet, "tag", 'tag:yaml.org,2002:set'); + +function parseSet(doc, cst) { + var map = resolveMap(doc, cst); + if (!map.hasAllNullValues()) throw new YAMLSemanticError(cst, 'Set items must all have null values'); + return Object.assign(new YAMLSet(), map); +} + +function createSet(schema, iterable, ctx) { + var set = new YAMLSet(); + + var _iterator = _createForOfIteratorHelper(iterable), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var value = _step.value; + set.items.push(schema.createPair(value, null, ctx)); + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + + return set; +} + +var set = { + identify: function identify(value) { + return value instanceof Set; + }, + nodeClass: YAMLSet, + default: false, + tag: 'tag:yaml.org,2002:set', + resolve: parseSet, + createNode: createSet +}; + +var parseSexagesimal = function parseSexagesimal(sign, parts) { + var n = parts.split(':').reduce(function (n, p) { + return n * 60 + Number(p); + }, 0); + return sign === '-' ? -n : n; +}; // hhhh:mm:ss.sss + + +var stringifySexagesimal = function stringifySexagesimal(_ref) { + var value = _ref.value; + if (isNaN(value) || !isFinite(value)) return stringifyNumber(value); + var sign = ''; + + if (value < 0) { + sign = '-'; + value = Math.abs(value); + } + + var parts = [value % 60]; // seconds, including ms + + if (value < 60) { + parts.unshift(0); // at least one : is required + } else { + value = Math.round((value - parts[0]) / 60); + parts.unshift(value % 60); // minutes + + if (value >= 60) { + value = Math.round((value - parts[0]) / 60); + parts.unshift(value); // hours + } + } + + return sign + parts.map(function (n) { + return n < 10 ? '0' + String(n) : String(n); + }).join(':').replace(/000000\d*$/, '') // % 60 may introduce error + ; +}; + +var intTime = { + identify: function identify(value) { + return typeof value === 'number'; + }, + default: true, + tag: 'tag:yaml.org,2002:int', + format: 'TIME', + test: /^([-+]?)([0-9][0-9_]*(?::[0-5]?[0-9])+)$/, + resolve: function resolve(str, sign, parts) { + return parseSexagesimal(sign, parts.replace(/_/g, '')); + }, + stringify: stringifySexagesimal +}; +var floatTime = { + identify: function identify(value) { + return typeof value === 'number'; + }, + default: true, + tag: 'tag:yaml.org,2002:float', + format: 'TIME', + test: /^([-+]?)([0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*)$/, + resolve: function resolve(str, sign, parts) { + return parseSexagesimal(sign, parts.replace(/_/g, '')); + }, + stringify: stringifySexagesimal +}; +var timestamp = { + identify: function identify(value) { + return value instanceof Date; + }, + default: true, + tag: 'tag:yaml.org,2002:timestamp', + // If the time zone is omitted, the timestamp is assumed to be specified in UTC. The time part + // may be omitted altogether, resulting in a date format. In such a case, the time part is + // assumed to be 00:00:00Z (start of day, UTC). + test: RegExp('^(?:' + '([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})' + // YYYY-Mm-Dd + '(?:(?:t|T|[ \\t]+)' + // t | T | whitespace + '([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)' + // Hh:Mm:Ss(.ss)? + '(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?' + // Z | +5 | -03:30 + ')?' + ')$'), + resolve: function resolve(str, year, month, day, hour, minute, second, millisec, tz) { + if (millisec) millisec = (millisec + '00').substr(1, 3); + var date = Date.UTC(year, month - 1, day, hour || 0, minute || 0, second || 0, millisec || 0); + + if (tz && tz !== 'Z') { + var d = parseSexagesimal(tz[0], tz.slice(1)); + if (Math.abs(d) < 30) d *= 60; + date -= 60000 * d; + } + + return new Date(date); + }, + stringify: function stringify(_ref2) { + var value = _ref2.value; + return value.toISOString().replace(/((T00:00)?:00)?\.000Z$/, ''); + } +}; + +/* global console, process, YAML_SILENCE_DEPRECATION_WARNINGS, YAML_SILENCE_WARNINGS */ +function shouldWarn(deprecation) { + var env = typeof process !== 'undefined' && process.env || {}; + + if (deprecation) { + if (typeof YAML_SILENCE_DEPRECATION_WARNINGS !== 'undefined') return !YAML_SILENCE_DEPRECATION_WARNINGS; + return !env.YAML_SILENCE_DEPRECATION_WARNINGS; + } + + if (typeof YAML_SILENCE_WARNINGS !== 'undefined') return !YAML_SILENCE_WARNINGS; + return !env.YAML_SILENCE_WARNINGS; +} + +function warn(warning, type) { + if (shouldWarn(false)) { + var emit = typeof process !== 'undefined' && process.emitWarning; // This will throw in Jest if `warning` is an Error instance due to + // https://github.com/facebook/jest/issues/2549 + + if (emit) emit(warning, type);else { + // eslint-disable-next-line no-console + console.warn(type ? "".concat(type, ": ").concat(warning) : warning); + } + } +} +function warnFileDeprecation(filename) { + if (shouldWarn(true)) { + var path = filename.replace(/.*yaml[/\\]/i, '').replace(/\.js$/, '').replace(/\\/g, '/'); + warn("The endpoint 'yaml/".concat(path, "' will be removed in a future release."), 'DeprecationWarning'); + } +} +var warned = {}; +function warnOptionDeprecation(name, alternative) { + if (!warned[name] && shouldWarn(true)) { + warned[name] = true; + var msg = "The option '".concat(name, "' will be removed in a future release"); + msg += alternative ? ", use '".concat(alternative, "' instead.") : '.'; + warn(msg, 'DeprecationWarning'); + } +} + +export { warnOptionDeprecation as a, binary as b, warnFileDeprecation as c, floatTime as f, intTime as i, omap as o, pairs as p, set as s, timestamp as t, warn as w }; diff --git a/node_modules/yaml/browser/index.js b/node_modules/yaml/browser/index.js new file mode 100644 index 0000000..b501ac4 --- /dev/null +++ b/node_modules/yaml/browser/index.js @@ -0,0 +1 @@ +module.exports = require('./dist').YAML diff --git a/node_modules/yaml/browser/map.js b/node_modules/yaml/browser/map.js new file mode 100644 index 0000000..78f2ebc --- /dev/null +++ b/node_modules/yaml/browser/map.js @@ -0,0 +1,2 @@ +module.exports = require('./dist/types').YAMLMap +require('./dist/legacy-exports').warnFileDeprecation(__filename) diff --git a/node_modules/yaml/browser/pair.js b/node_modules/yaml/browser/pair.js new file mode 100644 index 0000000..b2880a2 --- /dev/null +++ b/node_modules/yaml/browser/pair.js @@ -0,0 +1,2 @@ +module.exports = require('./dist/types').Pair +require('./dist/legacy-exports').warnFileDeprecation(__filename) diff --git a/node_modules/yaml/browser/parse-cst.js b/node_modules/yaml/browser/parse-cst.js new file mode 100644 index 0000000..8065756 --- /dev/null +++ b/node_modules/yaml/browser/parse-cst.js @@ -0,0 +1 @@ +module.exports = require('./dist/parse-cst').parse diff --git a/node_modules/yaml/browser/scalar.js b/node_modules/yaml/browser/scalar.js new file mode 100644 index 0000000..deee1b0 --- /dev/null +++ b/node_modules/yaml/browser/scalar.js @@ -0,0 +1,2 @@ +module.exports = require('./dist/types').Scalar +require('./dist/legacy-exports').warnFileDeprecation(__filename) diff --git a/node_modules/yaml/browser/schema.js b/node_modules/yaml/browser/schema.js new file mode 100644 index 0000000..4139c4b --- /dev/null +++ b/node_modules/yaml/browser/schema.js @@ -0,0 +1,9 @@ +const types = require('./dist/types') +const util = require('./dist/util') + +module.exports = types.Schema +module.exports.nullOptions = types.nullOptions +module.exports.strOptions = types.strOptions +module.exports.stringify = util.stringifyString + +require('./dist/legacy-exports').warnFileDeprecation(__filename) diff --git a/node_modules/yaml/browser/seq.js b/node_modules/yaml/browser/seq.js new file mode 100644 index 0000000..66147df --- /dev/null +++ b/node_modules/yaml/browser/seq.js @@ -0,0 +1,2 @@ +module.exports = require('./dist/types').YAMLSeq +require('./dist/legacy-exports').warnFileDeprecation(__filename) diff --git a/node_modules/yaml/browser/types.js b/node_modules/yaml/browser/types.js new file mode 100644 index 0000000..26a1254 --- /dev/null +++ b/node_modules/yaml/browser/types.js @@ -0,0 +1 @@ +export * from './dist/types.js' diff --git a/node_modules/yaml/browser/types/binary.js b/node_modules/yaml/browser/types/binary.js new file mode 100644 index 0000000..271b9de --- /dev/null +++ b/node_modules/yaml/browser/types/binary.js @@ -0,0 +1,8 @@ +'use strict' +Object.defineProperty(exports, '__esModule', { value: true }) + +const legacy = require('../dist/legacy-exports') +exports.binary = legacy.binary +exports.default = [exports.binary] + +legacy.warnFileDeprecation(__filename) diff --git a/node_modules/yaml/browser/types/omap.js b/node_modules/yaml/browser/types/omap.js new file mode 100644 index 0000000..37b638b --- /dev/null +++ b/node_modules/yaml/browser/types/omap.js @@ -0,0 +1,3 @@ +const legacy = require('../dist/legacy-exports') +module.exports = legacy.omap +legacy.warnFileDeprecation(__filename) diff --git a/node_modules/yaml/browser/types/pairs.js b/node_modules/yaml/browser/types/pairs.js new file mode 100644 index 0000000..f1df201 --- /dev/null +++ b/node_modules/yaml/browser/types/pairs.js @@ -0,0 +1,3 @@ +const legacy = require('../dist/legacy-exports') +module.exports = legacy.pairs +legacy.warnFileDeprecation(__filename) diff --git a/node_modules/yaml/browser/types/set.js b/node_modules/yaml/browser/types/set.js new file mode 100644 index 0000000..e7dc9d4 --- /dev/null +++ b/node_modules/yaml/browser/types/set.js @@ -0,0 +1,3 @@ +const legacy = require('../dist/legacy-exports') +module.exports = legacy.set +legacy.warnFileDeprecation(__filename) diff --git a/node_modules/yaml/browser/types/timestamp.js b/node_modules/yaml/browser/types/timestamp.js new file mode 100644 index 0000000..39c5b6d --- /dev/null +++ b/node_modules/yaml/browser/types/timestamp.js @@ -0,0 +1,10 @@ +'use strict' +Object.defineProperty(exports, '__esModule', { value: true }) + +const legacy = require('../dist/legacy-exports') +exports.default = [legacy.intTime, legacy.floatTime, legacy.timestamp] +exports.floatTime = legacy.floatTime +exports.intTime = legacy.intTime +exports.timestamp = legacy.timestamp + +legacy.warnFileDeprecation(__filename) diff --git a/node_modules/yaml/browser/util.js b/node_modules/yaml/browser/util.js new file mode 100644 index 0000000..3135a1c --- /dev/null +++ b/node_modules/yaml/browser/util.js @@ -0,0 +1 @@ +export * from './dist/util.js' diff --git a/node_modules/yaml/dist/Document-2cf6b08c.js b/node_modules/yaml/dist/Document-2cf6b08c.js new file mode 100644 index 0000000..6a3b947 --- /dev/null +++ b/node_modules/yaml/dist/Document-2cf6b08c.js @@ -0,0 +1,757 @@ +'use strict'; + +var PlainValue = require('./PlainValue-ec8e588e.js'); +var resolveSeq = require('./resolveSeq-4a68b39b.js'); +var Schema = require('./Schema-42e9705c.js'); + +const defaultOptions = { + anchorPrefix: 'a', + customTags: null, + indent: 2, + indentSeq: true, + keepCstNodes: false, + keepNodeTypes: true, + keepBlobsInJSON: true, + mapAsMap: false, + maxAliasCount: 100, + prettyErrors: false, + // TODO Set true in v2 + simpleKeys: false, + version: '1.2' +}; +const scalarOptions = { + get binary() { + return resolveSeq.binaryOptions; + }, + + set binary(opt) { + Object.assign(resolveSeq.binaryOptions, opt); + }, + + get bool() { + return resolveSeq.boolOptions; + }, + + set bool(opt) { + Object.assign(resolveSeq.boolOptions, opt); + }, + + get int() { + return resolveSeq.intOptions; + }, + + set int(opt) { + Object.assign(resolveSeq.intOptions, opt); + }, + + get null() { + return resolveSeq.nullOptions; + }, + + set null(opt) { + Object.assign(resolveSeq.nullOptions, opt); + }, + + get str() { + return resolveSeq.strOptions; + }, + + set str(opt) { + Object.assign(resolveSeq.strOptions, opt); + } + +}; +const documentOptions = { + '1.0': { + schema: 'yaml-1.1', + merge: true, + tagPrefixes: [{ + handle: '!', + prefix: PlainValue.defaultTagPrefix + }, { + handle: '!!', + prefix: 'tag:private.yaml.org,2002:' + }] + }, + '1.1': { + schema: 'yaml-1.1', + merge: true, + tagPrefixes: [{ + handle: '!', + prefix: '!' + }, { + handle: '!!', + prefix: PlainValue.defaultTagPrefix + }] + }, + '1.2': { + schema: 'core', + merge: false, + tagPrefixes: [{ + handle: '!', + prefix: '!' + }, { + handle: '!!', + prefix: PlainValue.defaultTagPrefix + }] + } +}; + +function stringifyTag(doc, tag) { + if ((doc.version || doc.options.version) === '1.0') { + const priv = tag.match(/^tag:private\.yaml\.org,2002:([^:/]+)$/); + if (priv) return '!' + priv[1]; + const vocab = tag.match(/^tag:([a-zA-Z0-9-]+)\.yaml\.org,2002:(.*)/); + return vocab ? `!${vocab[1]}/${vocab[2]}` : `!${tag.replace(/^tag:/, '')}`; + } + + let p = doc.tagPrefixes.find(p => tag.indexOf(p.prefix) === 0); + + if (!p) { + const dtp = doc.getDefaults().tagPrefixes; + p = dtp && dtp.find(p => tag.indexOf(p.prefix) === 0); + } + + if (!p) return tag[0] === '!' ? tag : `!<${tag}>`; + const suffix = tag.substr(p.prefix.length).replace(/[!,[\]{}]/g, ch => ({ + '!': '%21', + ',': '%2C', + '[': '%5B', + ']': '%5D', + '{': '%7B', + '}': '%7D' + })[ch]); + return p.handle + suffix; +} + +function getTagObject(tags, item) { + if (item instanceof resolveSeq.Alias) return resolveSeq.Alias; + + if (item.tag) { + const match = tags.filter(t => t.tag === item.tag); + if (match.length > 0) return match.find(t => t.format === item.format) || match[0]; + } + + let tagObj, obj; + + if (item instanceof resolveSeq.Scalar) { + obj = item.value; // TODO: deprecate/remove class check + + const match = tags.filter(t => t.identify && t.identify(obj) || t.class && obj instanceof t.class); + tagObj = match.find(t => t.format === item.format) || match.find(t => !t.format); + } else { + obj = item; + tagObj = tags.find(t => t.nodeClass && obj instanceof t.nodeClass); + } + + if (!tagObj) { + const name = obj && obj.constructor ? obj.constructor.name : typeof obj; + throw new Error(`Tag not resolved for ${name} value`); + } + + return tagObj; +} // needs to be called before value stringifier to allow for circular anchor refs + + +function stringifyProps(node, tagObj, { + anchors, + doc +}) { + const props = []; + const anchor = doc.anchors.getName(node); + + if (anchor) { + anchors[anchor] = node; + props.push(`&${anchor}`); + } + + if (node.tag) { + props.push(stringifyTag(doc, node.tag)); + } else if (!tagObj.default) { + props.push(stringifyTag(doc, tagObj.tag)); + } + + return props.join(' '); +} + +function stringify(item, ctx, onComment, onChompKeep) { + const { + anchors, + schema + } = ctx.doc; + let tagObj; + + if (!(item instanceof resolveSeq.Node)) { + const createCtx = { + aliasNodes: [], + onTagObj: o => tagObj = o, + prevObjects: new Map() + }; + item = schema.createNode(item, true, null, createCtx); + + for (const alias of createCtx.aliasNodes) { + alias.source = alias.source.node; + let name = anchors.getName(alias.source); + + if (!name) { + name = anchors.newName(); + anchors.map[name] = alias.source; + } + } + } + + if (item instanceof resolveSeq.Pair) return item.toString(ctx, onComment, onChompKeep); + if (!tagObj) tagObj = getTagObject(schema.tags, item); + const props = stringifyProps(item, tagObj, ctx); + if (props.length > 0) ctx.indentAtStart = (ctx.indentAtStart || 0) + props.length + 1; + const str = typeof tagObj.stringify === 'function' ? tagObj.stringify(item, ctx, onComment, onChompKeep) : item instanceof resolveSeq.Scalar ? resolveSeq.stringifyString(item, ctx, onComment, onChompKeep) : item.toString(ctx, onComment, onChompKeep); + if (!props) return str; + return item instanceof resolveSeq.Scalar || str[0] === '{' || str[0] === '[' ? `${props} ${str}` : `${props}\n${ctx.indent}${str}`; +} + +class Anchors { + static validAnchorNode(node) { + return node instanceof resolveSeq.Scalar || node instanceof resolveSeq.YAMLSeq || node instanceof resolveSeq.YAMLMap; + } + + constructor(prefix) { + PlainValue._defineProperty(this, "map", {}); + + this.prefix = prefix; + } + + createAlias(node, name) { + this.setAnchor(node, name); + return new resolveSeq.Alias(node); + } + + createMergePair(...sources) { + const merge = new resolveSeq.Merge(); + merge.value.items = sources.map(s => { + if (s instanceof resolveSeq.Alias) { + if (s.source instanceof resolveSeq.YAMLMap) return s; + } else if (s instanceof resolveSeq.YAMLMap) { + return this.createAlias(s); + } + + throw new Error('Merge sources must be Map nodes or their Aliases'); + }); + return merge; + } + + getName(node) { + const { + map + } = this; + return Object.keys(map).find(a => map[a] === node); + } + + getNames() { + return Object.keys(this.map); + } + + getNode(name) { + return this.map[name]; + } + + newName(prefix) { + if (!prefix) prefix = this.prefix; + const names = Object.keys(this.map); + + for (let i = 1; true; ++i) { + const name = `${prefix}${i}`; + if (!names.includes(name)) return name; + } + } // During parsing, map & aliases contain CST nodes + + + resolveNodes() { + const { + map, + _cstAliases + } = this; + Object.keys(map).forEach(a => { + map[a] = map[a].resolved; + }); + + _cstAliases.forEach(a => { + a.source = a.source.resolved; + }); + + delete this._cstAliases; + } + + setAnchor(node, name) { + if (node != null && !Anchors.validAnchorNode(node)) { + throw new Error('Anchors may only be set for Scalar, Seq and Map nodes'); + } + + if (name && /[\x00-\x19\s,[\]{}]/.test(name)) { + throw new Error('Anchor names must not contain whitespace or control characters'); + } + + const { + map + } = this; + const prev = node && Object.keys(map).find(a => map[a] === node); + + if (prev) { + if (!name) { + return prev; + } else if (prev !== name) { + delete map[prev]; + map[name] = node; + } + } else { + if (!name) { + if (!node) return null; + name = this.newName(); + } + + map[name] = node; + } + + return name; + } + +} + +const visit = (node, tags) => { + if (node && typeof node === 'object') { + const { + tag + } = node; + + if (node instanceof resolveSeq.Collection) { + if (tag) tags[tag] = true; + node.items.forEach(n => visit(n, tags)); + } else if (node instanceof resolveSeq.Pair) { + visit(node.key, tags); + visit(node.value, tags); + } else if (node instanceof resolveSeq.Scalar) { + if (tag) tags[tag] = true; + } + } + + return tags; +}; + +const listTagNames = node => Object.keys(visit(node, {})); + +function parseContents(doc, contents) { + const comments = { + before: [], + after: [] + }; + let body = undefined; + let spaceBefore = false; + + for (const node of contents) { + if (node.valueRange) { + if (body !== undefined) { + const msg = 'Document contains trailing content not separated by a ... or --- line'; + doc.errors.push(new PlainValue.YAMLSyntaxError(node, msg)); + break; + } + + const res = resolveSeq.resolveNode(doc, node); + + if (spaceBefore) { + res.spaceBefore = true; + spaceBefore = false; + } + + body = res; + } else if (node.comment !== null) { + const cc = body === undefined ? comments.before : comments.after; + cc.push(node.comment); + } else if (node.type === PlainValue.Type.BLANK_LINE) { + spaceBefore = true; + + if (body === undefined && comments.before.length > 0 && !doc.commentBefore) { + // space-separated comments at start are parsed as document comments + doc.commentBefore = comments.before.join('\n'); + comments.before = []; + } + } + } + + doc.contents = body || null; + + if (!body) { + doc.comment = comments.before.concat(comments.after).join('\n') || null; + } else { + const cb = comments.before.join('\n'); + + if (cb) { + const cbNode = body instanceof resolveSeq.Collection && body.items[0] ? body.items[0] : body; + cbNode.commentBefore = cbNode.commentBefore ? `${cb}\n${cbNode.commentBefore}` : cb; + } + + doc.comment = comments.after.join('\n') || null; + } +} + +function resolveTagDirective({ + tagPrefixes +}, directive) { + const [handle, prefix] = directive.parameters; + + if (!handle || !prefix) { + const msg = 'Insufficient parameters given for %TAG directive'; + throw new PlainValue.YAMLSemanticError(directive, msg); + } + + if (tagPrefixes.some(p => p.handle === handle)) { + const msg = 'The %TAG directive must only be given at most once per handle in the same document.'; + throw new PlainValue.YAMLSemanticError(directive, msg); + } + + return { + handle, + prefix + }; +} + +function resolveYamlDirective(doc, directive) { + let [version] = directive.parameters; + if (directive.name === 'YAML:1.0') version = '1.0'; + + if (!version) { + const msg = 'Insufficient parameters given for %YAML directive'; + throw new PlainValue.YAMLSemanticError(directive, msg); + } + + if (!documentOptions[version]) { + const v0 = doc.version || doc.options.version; + const msg = `Document will be parsed as YAML ${v0} rather than YAML ${version}`; + doc.warnings.push(new PlainValue.YAMLWarning(directive, msg)); + } + + return version; +} + +function parseDirectives(doc, directives, prevDoc) { + const directiveComments = []; + let hasDirectives = false; + + for (const directive of directives) { + const { + comment, + name + } = directive; + + switch (name) { + case 'TAG': + try { + doc.tagPrefixes.push(resolveTagDirective(doc, directive)); + } catch (error) { + doc.errors.push(error); + } + + hasDirectives = true; + break; + + case 'YAML': + case 'YAML:1.0': + if (doc.version) { + const msg = 'The %YAML directive must only be given at most once per document.'; + doc.errors.push(new PlainValue.YAMLSemanticError(directive, msg)); + } + + try { + doc.version = resolveYamlDirective(doc, directive); + } catch (error) { + doc.errors.push(error); + } + + hasDirectives = true; + break; + + default: + if (name) { + const msg = `YAML only supports %TAG and %YAML directives, and not %${name}`; + doc.warnings.push(new PlainValue.YAMLWarning(directive, msg)); + } + + } + + if (comment) directiveComments.push(comment); + } + + if (prevDoc && !hasDirectives && '1.1' === (doc.version || prevDoc.version || doc.options.version)) { + const copyTagPrefix = ({ + handle, + prefix + }) => ({ + handle, + prefix + }); + + doc.tagPrefixes = prevDoc.tagPrefixes.map(copyTagPrefix); + doc.version = prevDoc.version; + } + + doc.commentBefore = directiveComments.join('\n') || null; +} + +function assertCollection(contents) { + if (contents instanceof resolveSeq.Collection) return true; + throw new Error('Expected a YAML collection as document contents'); +} + +class Document { + constructor(options) { + this.anchors = new Anchors(options.anchorPrefix); + this.commentBefore = null; + this.comment = null; + this.contents = null; + this.directivesEndMarker = null; + this.errors = []; + this.options = options; + this.schema = null; + this.tagPrefixes = []; + this.version = null; + this.warnings = []; + } + + add(value) { + assertCollection(this.contents); + return this.contents.add(value); + } + + addIn(path, value) { + assertCollection(this.contents); + this.contents.addIn(path, value); + } + + delete(key) { + assertCollection(this.contents); + return this.contents.delete(key); + } + + deleteIn(path) { + if (resolveSeq.isEmptyPath(path)) { + if (this.contents == null) return false; + this.contents = null; + return true; + } + + assertCollection(this.contents); + return this.contents.deleteIn(path); + } + + getDefaults() { + return Document.defaults[this.version] || Document.defaults[this.options.version] || {}; + } + + get(key, keepScalar) { + return this.contents instanceof resolveSeq.Collection ? this.contents.get(key, keepScalar) : undefined; + } + + getIn(path, keepScalar) { + if (resolveSeq.isEmptyPath(path)) return !keepScalar && this.contents instanceof resolveSeq.Scalar ? this.contents.value : this.contents; + return this.contents instanceof resolveSeq.Collection ? this.contents.getIn(path, keepScalar) : undefined; + } + + has(key) { + return this.contents instanceof resolveSeq.Collection ? this.contents.has(key) : false; + } + + hasIn(path) { + if (resolveSeq.isEmptyPath(path)) return this.contents !== undefined; + return this.contents instanceof resolveSeq.Collection ? this.contents.hasIn(path) : false; + } + + set(key, value) { + assertCollection(this.contents); + this.contents.set(key, value); + } + + setIn(path, value) { + if (resolveSeq.isEmptyPath(path)) this.contents = value;else { + assertCollection(this.contents); + this.contents.setIn(path, value); + } + } + + setSchema(id, customTags) { + if (!id && !customTags && this.schema) return; + if (typeof id === 'number') id = id.toFixed(1); + + if (id === '1.0' || id === '1.1' || id === '1.2') { + if (this.version) this.version = id;else this.options.version = id; + delete this.options.schema; + } else if (id && typeof id === 'string') { + this.options.schema = id; + } + + if (Array.isArray(customTags)) this.options.customTags = customTags; + const opt = Object.assign({}, this.getDefaults(), this.options); + this.schema = new Schema.Schema(opt); + } + + parse(node, prevDoc) { + if (this.options.keepCstNodes) this.cstNode = node; + if (this.options.keepNodeTypes) this.type = 'DOCUMENT'; + const { + directives = [], + contents = [], + directivesEndMarker, + error, + valueRange + } = node; + + if (error) { + if (!error.source) error.source = this; + this.errors.push(error); + } + + parseDirectives(this, directives, prevDoc); + if (directivesEndMarker) this.directivesEndMarker = true; + this.range = valueRange ? [valueRange.start, valueRange.end] : null; + this.setSchema(); + this.anchors._cstAliases = []; + parseContents(this, contents); + this.anchors.resolveNodes(); + + if (this.options.prettyErrors) { + for (const error of this.errors) if (error instanceof PlainValue.YAMLError) error.makePretty(); + + for (const warn of this.warnings) if (warn instanceof PlainValue.YAMLError) warn.makePretty(); + } + + return this; + } + + listNonDefaultTags() { + return listTagNames(this.contents).filter(t => t.indexOf(Schema.Schema.defaultPrefix) !== 0); + } + + setTagPrefix(handle, prefix) { + if (handle[0] !== '!' || handle[handle.length - 1] !== '!') throw new Error('Handle must start and end with !'); + + if (prefix) { + const prev = this.tagPrefixes.find(p => p.handle === handle); + if (prev) prev.prefix = prefix;else this.tagPrefixes.push({ + handle, + prefix + }); + } else { + this.tagPrefixes = this.tagPrefixes.filter(p => p.handle !== handle); + } + } + + toJSON(arg, onAnchor) { + const { + keepBlobsInJSON, + mapAsMap, + maxAliasCount + } = this.options; + const keep = keepBlobsInJSON && (typeof arg !== 'string' || !(this.contents instanceof resolveSeq.Scalar)); + const ctx = { + doc: this, + indentStep: ' ', + keep, + mapAsMap: keep && !!mapAsMap, + maxAliasCount, + stringify // Requiring directly in Pair would create circular dependencies + + }; + const anchorNames = Object.keys(this.anchors.map); + if (anchorNames.length > 0) ctx.anchors = new Map(anchorNames.map(name => [this.anchors.map[name], { + alias: [], + aliasCount: 0, + count: 1 + }])); + const res = resolveSeq.toJSON(this.contents, arg, ctx); + if (typeof onAnchor === 'function' && ctx.anchors) for (const { + count, + res + } of ctx.anchors.values()) onAnchor(res, count); + return res; + } + + toString() { + if (this.errors.length > 0) throw new Error('Document with errors cannot be stringified'); + const indentSize = this.options.indent; + + if (!Number.isInteger(indentSize) || indentSize <= 0) { + const s = JSON.stringify(indentSize); + throw new Error(`"indent" option must be a positive integer, not ${s}`); + } + + this.setSchema(); + const lines = []; + let hasDirectives = false; + + if (this.version) { + let vd = '%YAML 1.2'; + + if (this.schema.name === 'yaml-1.1') { + if (this.version === '1.0') vd = '%YAML:1.0';else if (this.version === '1.1') vd = '%YAML 1.1'; + } + + lines.push(vd); + hasDirectives = true; + } + + const tagNames = this.listNonDefaultTags(); + this.tagPrefixes.forEach(({ + handle, + prefix + }) => { + if (tagNames.some(t => t.indexOf(prefix) === 0)) { + lines.push(`%TAG ${handle} ${prefix}`); + hasDirectives = true; + } + }); + if (hasDirectives || this.directivesEndMarker) lines.push('---'); + + if (this.commentBefore) { + if (hasDirectives || !this.directivesEndMarker) lines.unshift(''); + lines.unshift(this.commentBefore.replace(/^/gm, '#')); + } + + const ctx = { + anchors: {}, + doc: this, + indent: '', + indentStep: ' '.repeat(indentSize), + stringify // Requiring directly in nodes would create circular dependencies + + }; + let chompKeep = false; + let contentComment = null; + + if (this.contents) { + if (this.contents instanceof resolveSeq.Node) { + if (this.contents.spaceBefore && (hasDirectives || this.directivesEndMarker)) lines.push(''); + if (this.contents.commentBefore) lines.push(this.contents.commentBefore.replace(/^/gm, '#')); // top-level block scalars need to be indented if followed by a comment + + ctx.forceBlockIndent = !!this.comment; + contentComment = this.contents.comment; + } + + const onChompKeep = contentComment ? null : () => chompKeep = true; + const body = stringify(this.contents, ctx, () => contentComment = null, onChompKeep); + lines.push(resolveSeq.addComment(body, '', contentComment)); + } else if (this.contents !== undefined) { + lines.push(stringify(this.contents, ctx)); + } + + if (this.comment) { + if ((!chompKeep || contentComment) && lines[lines.length - 1] !== '') lines.push(''); + lines.push(this.comment.replace(/^/gm, '#')); + } + + return lines.join('\n') + '\n'; + } + +} + +PlainValue._defineProperty(Document, "defaults", documentOptions); + +exports.Document = Document; +exports.defaultOptions = defaultOptions; +exports.scalarOptions = scalarOptions; diff --git a/node_modules/yaml/dist/PlainValue-ec8e588e.js b/node_modules/yaml/dist/PlainValue-ec8e588e.js new file mode 100644 index 0000000..db8a14e --- /dev/null +++ b/node_modules/yaml/dist/PlainValue-ec8e588e.js @@ -0,0 +1,876 @@ +'use strict'; + +const Char = { + ANCHOR: '&', + COMMENT: '#', + TAG: '!', + DIRECTIVES_END: '-', + DOCUMENT_END: '.' +}; +const Type = { + ALIAS: 'ALIAS', + BLANK_LINE: 'BLANK_LINE', + BLOCK_FOLDED: 'BLOCK_FOLDED', + BLOCK_LITERAL: 'BLOCK_LITERAL', + COMMENT: 'COMMENT', + DIRECTIVE: 'DIRECTIVE', + DOCUMENT: 'DOCUMENT', + FLOW_MAP: 'FLOW_MAP', + FLOW_SEQ: 'FLOW_SEQ', + MAP: 'MAP', + MAP_KEY: 'MAP_KEY', + MAP_VALUE: 'MAP_VALUE', + PLAIN: 'PLAIN', + QUOTE_DOUBLE: 'QUOTE_DOUBLE', + QUOTE_SINGLE: 'QUOTE_SINGLE', + SEQ: 'SEQ', + SEQ_ITEM: 'SEQ_ITEM' +}; +const defaultTagPrefix = 'tag:yaml.org,2002:'; +const defaultTags = { + MAP: 'tag:yaml.org,2002:map', + SEQ: 'tag:yaml.org,2002:seq', + STR: 'tag:yaml.org,2002:str' +}; + +function findLineStarts(src) { + const ls = [0]; + let offset = src.indexOf('\n'); + + while (offset !== -1) { + offset += 1; + ls.push(offset); + offset = src.indexOf('\n', offset); + } + + return ls; +} + +function getSrcInfo(cst) { + let lineStarts, src; + + if (typeof cst === 'string') { + lineStarts = findLineStarts(cst); + src = cst; + } else { + if (Array.isArray(cst)) cst = cst[0]; + + if (cst && cst.context) { + if (!cst.lineStarts) cst.lineStarts = findLineStarts(cst.context.src); + lineStarts = cst.lineStarts; + src = cst.context.src; + } + } + + return { + lineStarts, + src + }; +} +/** + * @typedef {Object} LinePos - One-indexed position in the source + * @property {number} line + * @property {number} col + */ + +/** + * Determine the line/col position matching a character offset. + * + * Accepts a source string or a CST document as the second parameter. With + * the latter, starting indices for lines are cached in the document as + * `lineStarts: number[]`. + * + * Returns a one-indexed `{ line, col }` location if found, or + * `undefined` otherwise. + * + * @param {number} offset + * @param {string|Document|Document[]} cst + * @returns {?LinePos} + */ + + +function getLinePos(offset, cst) { + if (typeof offset !== 'number' || offset < 0) return null; + const { + lineStarts, + src + } = getSrcInfo(cst); + if (!lineStarts || !src || offset > src.length) return null; + + for (let i = 0; i < lineStarts.length; ++i) { + const start = lineStarts[i]; + + if (offset < start) { + return { + line: i, + col: offset - lineStarts[i - 1] + 1 + }; + } + + if (offset === start) return { + line: i + 1, + col: 1 + }; + } + + const line = lineStarts.length; + return { + line, + col: offset - lineStarts[line - 1] + 1 + }; +} +/** + * Get a specified line from the source. + * + * Accepts a source string or a CST document as the second parameter. With + * the latter, starting indices for lines are cached in the document as + * `lineStarts: number[]`. + * + * Returns the line as a string if found, or `null` otherwise. + * + * @param {number} line One-indexed line number + * @param {string|Document|Document[]} cst + * @returns {?string} + */ + +function getLine(line, cst) { + const { + lineStarts, + src + } = getSrcInfo(cst); + if (!lineStarts || !(line >= 1) || line > lineStarts.length) return null; + const start = lineStarts[line - 1]; + let end = lineStarts[line]; // undefined for last line; that's ok for slice() + + while (end && end > start && src[end - 1] === '\n') --end; + + return src.slice(start, end); +} +/** + * Pretty-print the starting line from the source indicated by the range `pos` + * + * Trims output to `maxWidth` chars while keeping the starting column visible, + * using `…` at either end to indicate dropped characters. + * + * Returns a two-line string (or `null`) with `\n` as separator; the second line + * will hold appropriately indented `^` marks indicating the column range. + * + * @param {Object} pos + * @param {LinePos} pos.start + * @param {LinePos} [pos.end] + * @param {string|Document|Document[]*} cst + * @param {number} [maxWidth=80] + * @returns {?string} + */ + +function getPrettyContext({ + start, + end +}, cst, maxWidth = 80) { + let src = getLine(start.line, cst); + if (!src) return null; + let { + col + } = start; + + if (src.length > maxWidth) { + if (col <= maxWidth - 10) { + src = src.substr(0, maxWidth - 1) + '…'; + } else { + const halfWidth = Math.round(maxWidth / 2); + if (src.length > col + halfWidth) src = src.substr(0, col + halfWidth - 1) + '…'; + col -= src.length - maxWidth; + src = '…' + src.substr(1 - maxWidth); + } + } + + let errLen = 1; + let errEnd = ''; + + if (end) { + if (end.line === start.line && col + (end.col - start.col) <= maxWidth + 1) { + errLen = end.col - start.col; + } else { + errLen = Math.min(src.length + 1, maxWidth) - col; + errEnd = '…'; + } + } + + const offset = col > 1 ? ' '.repeat(col - 1) : ''; + const err = '^'.repeat(errLen); + return `${src}\n${offset}${err}${errEnd}`; +} + +class Range { + static copy(orig) { + return new Range(orig.start, orig.end); + } + + constructor(start, end) { + this.start = start; + this.end = end || start; + } + + isEmpty() { + return typeof this.start !== 'number' || !this.end || this.end <= this.start; + } + /** + * Set `origStart` and `origEnd` to point to the original source range for + * this node, which may differ due to dropped CR characters. + * + * @param {number[]} cr - Positions of dropped CR characters + * @param {number} offset - Starting index of `cr` from the last call + * @returns {number} - The next offset, matching the one found for `origStart` + */ + + + setOrigRange(cr, offset) { + const { + start, + end + } = this; + + if (cr.length === 0 || end <= cr[0]) { + this.origStart = start; + this.origEnd = end; + return offset; + } + + let i = offset; + + while (i < cr.length) { + if (cr[i] > start) break;else ++i; + } + + this.origStart = start + i; + const nextOffset = i; + + while (i < cr.length) { + // if end was at \n, it should now be at \r + if (cr[i] >= end) break;else ++i; + } + + this.origEnd = end + i; + return nextOffset; + } + +} + +/** Root class of all nodes */ + +class Node { + static addStringTerminator(src, offset, str) { + if (str[str.length - 1] === '\n') return str; + const next = Node.endOfWhiteSpace(src, offset); + return next >= src.length || src[next] === '\n' ? str + '\n' : str; + } // ^(---|...) + + + static atDocumentBoundary(src, offset, sep) { + const ch0 = src[offset]; + if (!ch0) return true; + const prev = src[offset - 1]; + if (prev && prev !== '\n') return false; + + if (sep) { + if (ch0 !== sep) return false; + } else { + if (ch0 !== Char.DIRECTIVES_END && ch0 !== Char.DOCUMENT_END) return false; + } + + const ch1 = src[offset + 1]; + const ch2 = src[offset + 2]; + if (ch1 !== ch0 || ch2 !== ch0) return false; + const ch3 = src[offset + 3]; + return !ch3 || ch3 === '\n' || ch3 === '\t' || ch3 === ' '; + } + + static endOfIdentifier(src, offset) { + let ch = src[offset]; + const isVerbatim = ch === '<'; + const notOk = isVerbatim ? ['\n', '\t', ' ', '>'] : ['\n', '\t', ' ', '[', ']', '{', '}', ',']; + + while (ch && notOk.indexOf(ch) === -1) ch = src[offset += 1]; + + if (isVerbatim && ch === '>') offset += 1; + return offset; + } + + static endOfIndent(src, offset) { + let ch = src[offset]; + + while (ch === ' ') ch = src[offset += 1]; + + return offset; + } + + static endOfLine(src, offset) { + let ch = src[offset]; + + while (ch && ch !== '\n') ch = src[offset += 1]; + + return offset; + } + + static endOfWhiteSpace(src, offset) { + let ch = src[offset]; + + while (ch === '\t' || ch === ' ') ch = src[offset += 1]; + + return offset; + } + + static startOfLine(src, offset) { + let ch = src[offset - 1]; + if (ch === '\n') return offset; + + while (ch && ch !== '\n') ch = src[offset -= 1]; + + return offset + 1; + } + /** + * End of indentation, or null if the line's indent level is not more + * than `indent` + * + * @param {string} src + * @param {number} indent + * @param {number} lineStart + * @returns {?number} + */ + + + static endOfBlockIndent(src, indent, lineStart) { + const inEnd = Node.endOfIndent(src, lineStart); + + if (inEnd > lineStart + indent) { + return inEnd; + } else { + const wsEnd = Node.endOfWhiteSpace(src, inEnd); + const ch = src[wsEnd]; + if (!ch || ch === '\n') return wsEnd; + } + + return null; + } + + static atBlank(src, offset, endAsBlank) { + const ch = src[offset]; + return ch === '\n' || ch === '\t' || ch === ' ' || endAsBlank && !ch; + } + + static nextNodeIsIndented(ch, indentDiff, indicatorAsIndent) { + if (!ch || indentDiff < 0) return false; + if (indentDiff > 0) return true; + return indicatorAsIndent && ch === '-'; + } // should be at line or string end, or at next non-whitespace char + + + static normalizeOffset(src, offset) { + const ch = src[offset]; + return !ch ? offset : ch !== '\n' && src[offset - 1] === '\n' ? offset - 1 : Node.endOfWhiteSpace(src, offset); + } // fold single newline into space, multiple newlines to N - 1 newlines + // presumes src[offset] === '\n' + + + static foldNewline(src, offset, indent) { + let inCount = 0; + let error = false; + let fold = ''; + let ch = src[offset + 1]; + + while (ch === ' ' || ch === '\t' || ch === '\n') { + switch (ch) { + case '\n': + inCount = 0; + offset += 1; + fold += '\n'; + break; + + case '\t': + if (inCount <= indent) error = true; + offset = Node.endOfWhiteSpace(src, offset + 2) - 1; + break; + + case ' ': + inCount += 1; + offset += 1; + break; + } + + ch = src[offset + 1]; + } + + if (!fold) fold = ' '; + if (ch && inCount <= indent) error = true; + return { + fold, + offset, + error + }; + } + + constructor(type, props, context) { + Object.defineProperty(this, 'context', { + value: context || null, + writable: true + }); + this.error = null; + this.range = null; + this.valueRange = null; + this.props = props || []; + this.type = type; + this.value = null; + } + + getPropValue(idx, key, skipKey) { + if (!this.context) return null; + const { + src + } = this.context; + const prop = this.props[idx]; + return prop && src[prop.start] === key ? src.slice(prop.start + (skipKey ? 1 : 0), prop.end) : null; + } + + get anchor() { + for (let i = 0; i < this.props.length; ++i) { + const anchor = this.getPropValue(i, Char.ANCHOR, true); + if (anchor != null) return anchor; + } + + return null; + } + + get comment() { + const comments = []; + + for (let i = 0; i < this.props.length; ++i) { + const comment = this.getPropValue(i, Char.COMMENT, true); + if (comment != null) comments.push(comment); + } + + return comments.length > 0 ? comments.join('\n') : null; + } + + commentHasRequiredWhitespace(start) { + const { + src + } = this.context; + if (this.header && start === this.header.end) return false; + if (!this.valueRange) return false; + const { + end + } = this.valueRange; + return start !== end || Node.atBlank(src, end - 1); + } + + get hasComment() { + if (this.context) { + const { + src + } = this.context; + + for (let i = 0; i < this.props.length; ++i) { + if (src[this.props[i].start] === Char.COMMENT) return true; + } + } + + return false; + } + + get hasProps() { + if (this.context) { + const { + src + } = this.context; + + for (let i = 0; i < this.props.length; ++i) { + if (src[this.props[i].start] !== Char.COMMENT) return true; + } + } + + return false; + } + + get includesTrailingLines() { + return false; + } + + get jsonLike() { + const jsonLikeTypes = [Type.FLOW_MAP, Type.FLOW_SEQ, Type.QUOTE_DOUBLE, Type.QUOTE_SINGLE]; + return jsonLikeTypes.indexOf(this.type) !== -1; + } + + get rangeAsLinePos() { + if (!this.range || !this.context) return undefined; + const start = getLinePos(this.range.start, this.context.root); + if (!start) return undefined; + const end = getLinePos(this.range.end, this.context.root); + return { + start, + end + }; + } + + get rawValue() { + if (!this.valueRange || !this.context) return null; + const { + start, + end + } = this.valueRange; + return this.context.src.slice(start, end); + } + + get tag() { + for (let i = 0; i < this.props.length; ++i) { + const tag = this.getPropValue(i, Char.TAG, false); + + if (tag != null) { + if (tag[1] === '<') { + return { + verbatim: tag.slice(2, -1) + }; + } else { + // eslint-disable-next-line no-unused-vars + const [_, handle, suffix] = tag.match(/^(.*!)([^!]*)$/); + return { + handle, + suffix + }; + } + } + } + + return null; + } + + get valueRangeContainsNewline() { + if (!this.valueRange || !this.context) return false; + const { + start, + end + } = this.valueRange; + const { + src + } = this.context; + + for (let i = start; i < end; ++i) { + if (src[i] === '\n') return true; + } + + return false; + } + + parseComment(start) { + const { + src + } = this.context; + + if (src[start] === Char.COMMENT) { + const end = Node.endOfLine(src, start + 1); + const commentRange = new Range(start, end); + this.props.push(commentRange); + return end; + } + + return start; + } + /** + * Populates the `origStart` and `origEnd` values of all ranges for this + * node. Extended by child classes to handle descendant nodes. + * + * @param {number[]} cr - Positions of dropped CR characters + * @param {number} offset - Starting index of `cr` from the last call + * @returns {number} - The next offset, matching the one found for `origStart` + */ + + + setOrigRanges(cr, offset) { + if (this.range) offset = this.range.setOrigRange(cr, offset); + if (this.valueRange) this.valueRange.setOrigRange(cr, offset); + this.props.forEach(prop => prop.setOrigRange(cr, offset)); + return offset; + } + + toString() { + const { + context: { + src + }, + range, + value + } = this; + if (value != null) return value; + const str = src.slice(range.start, range.end); + return Node.addStringTerminator(src, range.end, str); + } + +} + +class YAMLError extends Error { + constructor(name, source, message) { + if (!message || !(source instanceof Node)) throw new Error(`Invalid arguments for new ${name}`); + super(); + this.name = name; + this.message = message; + this.source = source; + } + + makePretty() { + if (!this.source) return; + this.nodeType = this.source.type; + const cst = this.source.context && this.source.context.root; + + if (typeof this.offset === 'number') { + this.range = new Range(this.offset, this.offset + 1); + const start = cst && getLinePos(this.offset, cst); + + if (start) { + const end = { + line: start.line, + col: start.col + 1 + }; + this.linePos = { + start, + end + }; + } + + delete this.offset; + } else { + this.range = this.source.range; + this.linePos = this.source.rangeAsLinePos; + } + + if (this.linePos) { + const { + line, + col + } = this.linePos.start; + this.message += ` at line ${line}, column ${col}`; + const ctx = cst && getPrettyContext(this.linePos, cst); + if (ctx) this.message += `:\n\n${ctx}\n`; + } + + delete this.source; + } + +} +class YAMLReferenceError extends YAMLError { + constructor(source, message) { + super('YAMLReferenceError', source, message); + } + +} +class YAMLSemanticError extends YAMLError { + constructor(source, message) { + super('YAMLSemanticError', source, message); + } + +} +class YAMLSyntaxError extends YAMLError { + constructor(source, message) { + super('YAMLSyntaxError', source, message); + } + +} +class YAMLWarning extends YAMLError { + constructor(source, message) { + super('YAMLWarning', source, message); + } + +} + +function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; +} + +class PlainValue extends Node { + static endOfLine(src, start, inFlow) { + let ch = src[start]; + let offset = start; + + while (ch && ch !== '\n') { + if (inFlow && (ch === '[' || ch === ']' || ch === '{' || ch === '}' || ch === ',')) break; + const next = src[offset + 1]; + if (ch === ':' && (!next || next === '\n' || next === '\t' || next === ' ' || inFlow && next === ',')) break; + if ((ch === ' ' || ch === '\t') && next === '#') break; + offset += 1; + ch = next; + } + + return offset; + } + + get strValue() { + if (!this.valueRange || !this.context) return null; + let { + start, + end + } = this.valueRange; + const { + src + } = this.context; + let ch = src[end - 1]; + + while (start < end && (ch === '\n' || ch === '\t' || ch === ' ')) ch = src[--end - 1]; + + let str = ''; + + for (let i = start; i < end; ++i) { + const ch = src[i]; + + if (ch === '\n') { + const { + fold, + offset + } = Node.foldNewline(src, i, -1); + str += fold; + i = offset; + } else if (ch === ' ' || ch === '\t') { + // trim trailing whitespace + const wsStart = i; + let next = src[i + 1]; + + while (i < end && (next === ' ' || next === '\t')) { + i += 1; + next = src[i + 1]; + } + + if (next !== '\n') str += i > wsStart ? src.slice(wsStart, i + 1) : ch; + } else { + str += ch; + } + } + + const ch0 = src[start]; + + switch (ch0) { + case '\t': + { + const msg = 'Plain value cannot start with a tab character'; + const errors = [new YAMLSemanticError(this, msg)]; + return { + errors, + str + }; + } + + case '@': + case '`': + { + const msg = `Plain value cannot start with reserved character ${ch0}`; + const errors = [new YAMLSemanticError(this, msg)]; + return { + errors, + str + }; + } + + default: + return str; + } + } + + parseBlockValue(start) { + const { + indent, + inFlow, + src + } = this.context; + let offset = start; + let valueEnd = start; + + for (let ch = src[offset]; ch === '\n'; ch = src[offset]) { + if (Node.atDocumentBoundary(src, offset + 1)) break; + const end = Node.endOfBlockIndent(src, indent, offset + 1); + if (end === null || src[end] === '#') break; + + if (src[end] === '\n') { + offset = end; + } else { + valueEnd = PlainValue.endOfLine(src, end, inFlow); + offset = valueEnd; + } + } + + if (this.valueRange.isEmpty()) this.valueRange.start = start; + this.valueRange.end = valueEnd; + return valueEnd; + } + /** + * Parses a plain value from the source + * + * Accepted forms are: + * ``` + * #comment + * + * first line + * + * first line #comment + * + * first line + * block + * lines + * + * #comment + * block + * lines + * ``` + * where block lines are empty or have an indent level greater than `indent`. + * + * @param {ParseContext} context + * @param {number} start - Index of first character + * @returns {number} - Index of the character after this scalar, may be `\n` + */ + + + parse(context, start) { + this.context = context; + const { + inFlow, + src + } = context; + let offset = start; + const ch = src[offset]; + + if (ch && ch !== '#' && ch !== '\n') { + offset = PlainValue.endOfLine(src, start, inFlow); + } + + this.valueRange = new Range(start, offset); + offset = Node.endOfWhiteSpace(src, offset); + offset = this.parseComment(offset); + + if (!this.hasComment || this.valueRange.isEmpty()) { + offset = this.parseBlockValue(offset); + } + + return offset; + } + +} + +exports.Char = Char; +exports.Node = Node; +exports.PlainValue = PlainValue; +exports.Range = Range; +exports.Type = Type; +exports.YAMLError = YAMLError; +exports.YAMLReferenceError = YAMLReferenceError; +exports.YAMLSemanticError = YAMLSemanticError; +exports.YAMLSyntaxError = YAMLSyntaxError; +exports.YAMLWarning = YAMLWarning; +exports._defineProperty = _defineProperty; +exports.defaultTagPrefix = defaultTagPrefix; +exports.defaultTags = defaultTags; diff --git a/node_modules/yaml/dist/Schema-42e9705c.js b/node_modules/yaml/dist/Schema-42e9705c.js new file mode 100644 index 0000000..172f3e8 --- /dev/null +++ b/node_modules/yaml/dist/Schema-42e9705c.js @@ -0,0 +1,522 @@ +'use strict'; + +var PlainValue = require('./PlainValue-ec8e588e.js'); +var resolveSeq = require('./resolveSeq-4a68b39b.js'); +var warnings = require('./warnings-39684f17.js'); + +function createMap(schema, obj, ctx) { + const map = new resolveSeq.YAMLMap(schema); + + if (obj instanceof Map) { + for (const [key, value] of obj) map.items.push(schema.createPair(key, value, ctx)); + } else if (obj && typeof obj === 'object') { + for (const key of Object.keys(obj)) map.items.push(schema.createPair(key, obj[key], ctx)); + } + + if (typeof schema.sortMapEntries === 'function') { + map.items.sort(schema.sortMapEntries); + } + + return map; +} + +const map = { + createNode: createMap, + default: true, + nodeClass: resolveSeq.YAMLMap, + tag: 'tag:yaml.org,2002:map', + resolve: resolveSeq.resolveMap +}; + +function createSeq(schema, obj, ctx) { + const seq = new resolveSeq.YAMLSeq(schema); + + if (obj && obj[Symbol.iterator]) { + for (const it of obj) { + const v = schema.createNode(it, ctx.wrapScalars, null, ctx); + seq.items.push(v); + } + } + + return seq; +} + +const seq = { + createNode: createSeq, + default: true, + nodeClass: resolveSeq.YAMLSeq, + tag: 'tag:yaml.org,2002:seq', + resolve: resolveSeq.resolveSeq +}; + +const string = { + identify: value => typeof value === 'string', + default: true, + tag: 'tag:yaml.org,2002:str', + resolve: resolveSeq.resolveString, + + stringify(item, ctx, onComment, onChompKeep) { + ctx = Object.assign({ + actualString: true + }, ctx); + return resolveSeq.stringifyString(item, ctx, onComment, onChompKeep); + }, + + options: resolveSeq.strOptions +}; + +const failsafe = [map, seq, string]; + +/* global BigInt */ + +const intIdentify = value => typeof value === 'bigint' || Number.isInteger(value); + +const intResolve = (src, part, radix) => resolveSeq.intOptions.asBigInt ? BigInt(src) : parseInt(part, radix); + +function intStringify(node, radix, prefix) { + const { + value + } = node; + if (intIdentify(value) && value >= 0) return prefix + value.toString(radix); + return resolveSeq.stringifyNumber(node); +} + +const nullObj = { + identify: value => value == null, + createNode: (schema, value, ctx) => ctx.wrapScalars ? new resolveSeq.Scalar(null) : null, + default: true, + tag: 'tag:yaml.org,2002:null', + test: /^(?:~|[Nn]ull|NULL)?$/, + resolve: () => null, + options: resolveSeq.nullOptions, + stringify: () => resolveSeq.nullOptions.nullStr +}; +const boolObj = { + identify: value => typeof value === 'boolean', + default: true, + tag: 'tag:yaml.org,2002:bool', + test: /^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/, + resolve: str => str[0] === 't' || str[0] === 'T', + options: resolveSeq.boolOptions, + stringify: ({ + value + }) => value ? resolveSeq.boolOptions.trueStr : resolveSeq.boolOptions.falseStr +}; +const octObj = { + identify: value => intIdentify(value) && value >= 0, + default: true, + tag: 'tag:yaml.org,2002:int', + format: 'OCT', + test: /^0o([0-7]+)$/, + resolve: (str, oct) => intResolve(str, oct, 8), + options: resolveSeq.intOptions, + stringify: node => intStringify(node, 8, '0o') +}; +const intObj = { + identify: intIdentify, + default: true, + tag: 'tag:yaml.org,2002:int', + test: /^[-+]?[0-9]+$/, + resolve: str => intResolve(str, str, 10), + options: resolveSeq.intOptions, + stringify: resolveSeq.stringifyNumber +}; +const hexObj = { + identify: value => intIdentify(value) && value >= 0, + default: true, + tag: 'tag:yaml.org,2002:int', + format: 'HEX', + test: /^0x([0-9a-fA-F]+)$/, + resolve: (str, hex) => intResolve(str, hex, 16), + options: resolveSeq.intOptions, + stringify: node => intStringify(node, 16, '0x') +}; +const nanObj = { + identify: value => typeof value === 'number', + default: true, + tag: 'tag:yaml.org,2002:float', + test: /^(?:[-+]?\.inf|(\.nan))$/i, + resolve: (str, nan) => nan ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY, + stringify: resolveSeq.stringifyNumber +}; +const expObj = { + identify: value => typeof value === 'number', + default: true, + tag: 'tag:yaml.org,2002:float', + format: 'EXP', + test: /^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/, + resolve: str => parseFloat(str), + stringify: ({ + value + }) => Number(value).toExponential() +}; +const floatObj = { + identify: value => typeof value === 'number', + default: true, + tag: 'tag:yaml.org,2002:float', + test: /^[-+]?(?:\.([0-9]+)|[0-9]+\.([0-9]*))$/, + + resolve(str, frac1, frac2) { + const frac = frac1 || frac2; + const node = new resolveSeq.Scalar(parseFloat(str)); + if (frac && frac[frac.length - 1] === '0') node.minFractionDigits = frac.length; + return node; + }, + + stringify: resolveSeq.stringifyNumber +}; +const core = failsafe.concat([nullObj, boolObj, octObj, intObj, hexObj, nanObj, expObj, floatObj]); + +/* global BigInt */ + +const intIdentify$1 = value => typeof value === 'bigint' || Number.isInteger(value); + +const stringifyJSON = ({ + value +}) => JSON.stringify(value); + +const json = [map, seq, { + identify: value => typeof value === 'string', + default: true, + tag: 'tag:yaml.org,2002:str', + resolve: resolveSeq.resolveString, + stringify: stringifyJSON +}, { + identify: value => value == null, + createNode: (schema, value, ctx) => ctx.wrapScalars ? new resolveSeq.Scalar(null) : null, + default: true, + tag: 'tag:yaml.org,2002:null', + test: /^null$/, + resolve: () => null, + stringify: stringifyJSON +}, { + identify: value => typeof value === 'boolean', + default: true, + tag: 'tag:yaml.org,2002:bool', + test: /^true|false$/, + resolve: str => str === 'true', + stringify: stringifyJSON +}, { + identify: intIdentify$1, + default: true, + tag: 'tag:yaml.org,2002:int', + test: /^-?(?:0|[1-9][0-9]*)$/, + resolve: str => resolveSeq.intOptions.asBigInt ? BigInt(str) : parseInt(str, 10), + stringify: ({ + value + }) => intIdentify$1(value) ? value.toString() : JSON.stringify(value) +}, { + identify: value => typeof value === 'number', + default: true, + tag: 'tag:yaml.org,2002:float', + test: /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/, + resolve: str => parseFloat(str), + stringify: stringifyJSON +}]; + +json.scalarFallback = str => { + throw new SyntaxError(`Unresolved plain scalar ${JSON.stringify(str)}`); +}; + +/* global BigInt */ + +const boolStringify = ({ + value +}) => value ? resolveSeq.boolOptions.trueStr : resolveSeq.boolOptions.falseStr; + +const intIdentify$2 = value => typeof value === 'bigint' || Number.isInteger(value); + +function intResolve$1(sign, src, radix) { + let str = src.replace(/_/g, ''); + + if (resolveSeq.intOptions.asBigInt) { + switch (radix) { + case 2: + str = `0b${str}`; + break; + + case 8: + str = `0o${str}`; + break; + + case 16: + str = `0x${str}`; + break; + } + + const n = BigInt(str); + return sign === '-' ? BigInt(-1) * n : n; + } + + const n = parseInt(str, radix); + return sign === '-' ? -1 * n : n; +} + +function intStringify$1(node, radix, prefix) { + const { + value + } = node; + + if (intIdentify$2(value)) { + const str = value.toString(radix); + return value < 0 ? '-' + prefix + str.substr(1) : prefix + str; + } + + return resolveSeq.stringifyNumber(node); +} + +const yaml11 = failsafe.concat([{ + identify: value => value == null, + createNode: (schema, value, ctx) => ctx.wrapScalars ? new resolveSeq.Scalar(null) : null, + default: true, + tag: 'tag:yaml.org,2002:null', + test: /^(?:~|[Nn]ull|NULL)?$/, + resolve: () => null, + options: resolveSeq.nullOptions, + stringify: () => resolveSeq.nullOptions.nullStr +}, { + identify: value => typeof value === 'boolean', + default: true, + tag: 'tag:yaml.org,2002:bool', + test: /^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/, + resolve: () => true, + options: resolveSeq.boolOptions, + stringify: boolStringify +}, { + identify: value => typeof value === 'boolean', + default: true, + tag: 'tag:yaml.org,2002:bool', + test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/i, + resolve: () => false, + options: resolveSeq.boolOptions, + stringify: boolStringify +}, { + identify: intIdentify$2, + default: true, + tag: 'tag:yaml.org,2002:int', + format: 'BIN', + test: /^([-+]?)0b([0-1_]+)$/, + resolve: (str, sign, bin) => intResolve$1(sign, bin, 2), + stringify: node => intStringify$1(node, 2, '0b') +}, { + identify: intIdentify$2, + default: true, + tag: 'tag:yaml.org,2002:int', + format: 'OCT', + test: /^([-+]?)0([0-7_]+)$/, + resolve: (str, sign, oct) => intResolve$1(sign, oct, 8), + stringify: node => intStringify$1(node, 8, '0') +}, { + identify: intIdentify$2, + default: true, + tag: 'tag:yaml.org,2002:int', + test: /^([-+]?)([0-9][0-9_]*)$/, + resolve: (str, sign, abs) => intResolve$1(sign, abs, 10), + stringify: resolveSeq.stringifyNumber +}, { + identify: intIdentify$2, + default: true, + tag: 'tag:yaml.org,2002:int', + format: 'HEX', + test: /^([-+]?)0x([0-9a-fA-F_]+)$/, + resolve: (str, sign, hex) => intResolve$1(sign, hex, 16), + stringify: node => intStringify$1(node, 16, '0x') +}, { + identify: value => typeof value === 'number', + default: true, + tag: 'tag:yaml.org,2002:float', + test: /^(?:[-+]?\.inf|(\.nan))$/i, + resolve: (str, nan) => nan ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY, + stringify: resolveSeq.stringifyNumber +}, { + identify: value => typeof value === 'number', + default: true, + tag: 'tag:yaml.org,2002:float', + format: 'EXP', + test: /^[-+]?([0-9][0-9_]*)?(\.[0-9_]*)?[eE][-+]?[0-9]+$/, + resolve: str => parseFloat(str.replace(/_/g, '')), + stringify: ({ + value + }) => Number(value).toExponential() +}, { + identify: value => typeof value === 'number', + default: true, + tag: 'tag:yaml.org,2002:float', + test: /^[-+]?(?:[0-9][0-9_]*)?\.([0-9_]*)$/, + + resolve(str, frac) { + const node = new resolveSeq.Scalar(parseFloat(str.replace(/_/g, ''))); + + if (frac) { + const f = frac.replace(/_/g, ''); + if (f[f.length - 1] === '0') node.minFractionDigits = f.length; + } + + return node; + }, + + stringify: resolveSeq.stringifyNumber +}], warnings.binary, warnings.omap, warnings.pairs, warnings.set, warnings.intTime, warnings.floatTime, warnings.timestamp); + +const schemas = { + core, + failsafe, + json, + yaml11 +}; +const tags = { + binary: warnings.binary, + bool: boolObj, + float: floatObj, + floatExp: expObj, + floatNaN: nanObj, + floatTime: warnings.floatTime, + int: intObj, + intHex: hexObj, + intOct: octObj, + intTime: warnings.intTime, + map, + null: nullObj, + omap: warnings.omap, + pairs: warnings.pairs, + seq, + set: warnings.set, + timestamp: warnings.timestamp +}; + +function findTagObject(value, tagName, tags) { + if (tagName) { + const match = tags.filter(t => t.tag === tagName); + const tagObj = match.find(t => !t.format) || match[0]; + if (!tagObj) throw new Error(`Tag ${tagName} not found`); + return tagObj; + } // TODO: deprecate/remove class check + + + return tags.find(t => (t.identify && t.identify(value) || t.class && value instanceof t.class) && !t.format); +} + +function createNode(value, tagName, ctx) { + if (value instanceof resolveSeq.Node) return value; + const { + defaultPrefix, + onTagObj, + prevObjects, + schema, + wrapScalars + } = ctx; + if (tagName && tagName.startsWith('!!')) tagName = defaultPrefix + tagName.slice(2); + let tagObj = findTagObject(value, tagName, schema.tags); + + if (!tagObj) { + if (typeof value.toJSON === 'function') value = value.toJSON(); + if (typeof value !== 'object') return wrapScalars ? new resolveSeq.Scalar(value) : value; + tagObj = value instanceof Map ? map : value[Symbol.iterator] ? seq : map; + } + + if (onTagObj) { + onTagObj(tagObj); + delete ctx.onTagObj; + } // Detect duplicate references to the same object & use Alias nodes for all + // after first. The `obj` wrapper allows for circular references to resolve. + + + const obj = {}; + + if (value && typeof value === 'object' && prevObjects) { + const prev = prevObjects.get(value); + + if (prev) { + const alias = new resolveSeq.Alias(prev); // leaves source dirty; must be cleaned by caller + + ctx.aliasNodes.push(alias); // defined along with prevObjects + + return alias; + } + + obj.value = value; + prevObjects.set(value, obj); + } + + obj.node = tagObj.createNode ? tagObj.createNode(ctx.schema, value, ctx) : wrapScalars ? new resolveSeq.Scalar(value) : value; + if (tagName && obj.node instanceof resolveSeq.Node) obj.node.tag = tagName; + return obj.node; +} + +function getSchemaTags(schemas, knownTags, customTags, schemaId) { + let tags = schemas[schemaId.replace(/\W/g, '')]; // 'yaml-1.1' -> 'yaml11' + + if (!tags) { + const keys = Object.keys(schemas).map(key => JSON.stringify(key)).join(', '); + throw new Error(`Unknown schema "${schemaId}"; use one of ${keys}`); + } + + if (Array.isArray(customTags)) { + for (const tag of customTags) tags = tags.concat(tag); + } else if (typeof customTags === 'function') { + tags = customTags(tags.slice()); + } + + for (let i = 0; i < tags.length; ++i) { + const tag = tags[i]; + + if (typeof tag === 'string') { + const tagObj = knownTags[tag]; + + if (!tagObj) { + const keys = Object.keys(knownTags).map(key => JSON.stringify(key)).join(', '); + throw new Error(`Unknown custom tag "${tag}"; use one of ${keys}`); + } + + tags[i] = tagObj; + } + } + + return tags; +} + +const sortMapEntriesByKey = (a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0; + +class Schema { + // TODO: remove in v2 + // TODO: remove in v2 + constructor({ + customTags, + merge, + schema, + sortMapEntries, + tags: deprecatedCustomTags + }) { + this.merge = !!merge; + this.name = schema; + this.sortMapEntries = sortMapEntries === true ? sortMapEntriesByKey : sortMapEntries || null; + if (!customTags && deprecatedCustomTags) warnings.warnOptionDeprecation('tags', 'customTags'); + this.tags = getSchemaTags(schemas, tags, customTags || deprecatedCustomTags, schema); + } + + createNode(value, wrapScalars, tagName, ctx) { + const baseCtx = { + defaultPrefix: Schema.defaultPrefix, + schema: this, + wrapScalars + }; + const createCtx = ctx ? Object.assign(ctx, baseCtx) : baseCtx; + return createNode(value, tagName, createCtx); + } + + createPair(key, value, ctx) { + if (!ctx) ctx = { + wrapScalars: true + }; + const k = this.createNode(key, ctx.wrapScalars, null, ctx); + const v = this.createNode(value, ctx.wrapScalars, null, ctx); + return new resolveSeq.Pair(k, v); + } + +} + +PlainValue._defineProperty(Schema, "defaultPrefix", PlainValue.defaultTagPrefix); + +PlainValue._defineProperty(Schema, "defaultTags", PlainValue.defaultTags); + +exports.Schema = Schema; diff --git a/node_modules/yaml/dist/index.js b/node_modules/yaml/dist/index.js new file mode 100644 index 0000000..df2f8b0 --- /dev/null +++ b/node_modules/yaml/dist/index.js @@ -0,0 +1,79 @@ +'use strict'; + +var PlainValue = require('./PlainValue-ec8e588e.js'); +var parseCst = require('./parse-cst.js'); +require('./resolveSeq-4a68b39b.js'); +var Document$1 = require('./Document-2cf6b08c.js'); +var Schema = require('./Schema-42e9705c.js'); +var warnings = require('./warnings-39684f17.js'); + +function createNode(value, wrapScalars = true, tag) { + if (tag === undefined && typeof wrapScalars === 'string') { + tag = wrapScalars; + wrapScalars = true; + } + + const options = Object.assign({}, Document$1.Document.defaults[Document$1.defaultOptions.version], Document$1.defaultOptions); + const schema = new Schema.Schema(options); + return schema.createNode(value, wrapScalars, tag); +} + +class Document extends Document$1.Document { + constructor(options) { + super(Object.assign({}, Document$1.defaultOptions, options)); + } + +} + +function parseAllDocuments(src, options) { + const stream = []; + let prev; + + for (const cstDoc of parseCst.parse(src)) { + const doc = new Document(options); + doc.parse(cstDoc, prev); + stream.push(doc); + prev = doc; + } + + return stream; +} + +function parseDocument(src, options) { + const cst = parseCst.parse(src); + const doc = new Document(options).parse(cst[0]); + + if (cst.length > 1) { + const errMsg = 'Source contains multiple documents; please use YAML.parseAllDocuments()'; + doc.errors.unshift(new PlainValue.YAMLSemanticError(cst[1], errMsg)); + } + + return doc; +} + +function parse(src, options) { + const doc = parseDocument(src, options); + doc.warnings.forEach(warning => warnings.warn(warning)); + if (doc.errors.length > 0) throw doc.errors[0]; + return doc.toJSON(); +} + +function stringify(value, options) { + const doc = new Document(options); + doc.contents = value; + return String(doc); +} + +const YAML = { + createNode, + defaultOptions: Document$1.defaultOptions, + Document, + parse, + parseAllDocuments, + parseCST: parseCst.parse, + parseDocument, + scalarOptions: Document$1.scalarOptions, + stringify +}; + +exports.YAML = YAML; diff --git a/node_modules/yaml/dist/legacy-exports.js b/node_modules/yaml/dist/legacy-exports.js new file mode 100644 index 0000000..11d7886 --- /dev/null +++ b/node_modules/yaml/dist/legacy-exports.js @@ -0,0 +1,16 @@ +'use strict'; + +require('./PlainValue-ec8e588e.js'); +require('./resolveSeq-4a68b39b.js'); +var warnings = require('./warnings-39684f17.js'); + + + +exports.binary = warnings.binary; +exports.floatTime = warnings.floatTime; +exports.intTime = warnings.intTime; +exports.omap = warnings.omap; +exports.pairs = warnings.pairs; +exports.set = warnings.set; +exports.timestamp = warnings.timestamp; +exports.warnFileDeprecation = warnings.warnFileDeprecation; diff --git a/node_modules/yaml/dist/parse-cst.js b/node_modules/yaml/dist/parse-cst.js new file mode 100644 index 0000000..c052027 --- /dev/null +++ b/node_modules/yaml/dist/parse-cst.js @@ -0,0 +1,1747 @@ +'use strict'; + +var PlainValue = require('./PlainValue-ec8e588e.js'); + +class BlankLine extends PlainValue.Node { + constructor() { + super(PlainValue.Type.BLANK_LINE); + } + /* istanbul ignore next */ + + + get includesTrailingLines() { + // This is never called from anywhere, but if it were, + // this is the value it should return. + return true; + } + /** + * Parses a blank line from the source + * + * @param {ParseContext} context + * @param {number} start - Index of first \n character + * @returns {number} - Index of the character after this + */ + + + parse(context, start) { + this.context = context; + this.range = new PlainValue.Range(start, start + 1); + return start + 1; + } + +} + +class CollectionItem extends PlainValue.Node { + constructor(type, props) { + super(type, props); + this.node = null; + } + + get includesTrailingLines() { + return !!this.node && this.node.includesTrailingLines; + } + /** + * @param {ParseContext} context + * @param {number} start - Index of first character + * @returns {number} - Index of the character after this + */ + + + parse(context, start) { + this.context = context; + const { + parseNode, + src + } = context; + let { + atLineStart, + lineStart + } = context; + if (!atLineStart && this.type === PlainValue.Type.SEQ_ITEM) this.error = new PlainValue.YAMLSemanticError(this, 'Sequence items must not have preceding content on the same line'); + const indent = atLineStart ? start - lineStart : context.indent; + let offset = PlainValue.Node.endOfWhiteSpace(src, start + 1); + let ch = src[offset]; + const inlineComment = ch === '#'; + const comments = []; + let blankLine = null; + + while (ch === '\n' || ch === '#') { + if (ch === '#') { + const end = PlainValue.Node.endOfLine(src, offset + 1); + comments.push(new PlainValue.Range(offset, end)); + offset = end; + } else { + atLineStart = true; + lineStart = offset + 1; + const wsEnd = PlainValue.Node.endOfWhiteSpace(src, lineStart); + + if (src[wsEnd] === '\n' && comments.length === 0) { + blankLine = new BlankLine(); + lineStart = blankLine.parse({ + src + }, lineStart); + } + + offset = PlainValue.Node.endOfIndent(src, lineStart); + } + + ch = src[offset]; + } + + if (PlainValue.Node.nextNodeIsIndented(ch, offset - (lineStart + indent), this.type !== PlainValue.Type.SEQ_ITEM)) { + this.node = parseNode({ + atLineStart, + inCollection: false, + indent, + lineStart, + parent: this + }, offset); + } else if (ch && lineStart > start + 1) { + offset = lineStart - 1; + } + + if (this.node) { + if (blankLine) { + // Only blank lines preceding non-empty nodes are captured. Note that + // this means that collection item range start indices do not always + // increase monotonically. -- eemeli/yaml#126 + const items = context.parent.items || context.parent.contents; + if (items) items.push(blankLine); + } + + if (comments.length) Array.prototype.push.apply(this.props, comments); + offset = this.node.range.end; + } else { + if (inlineComment) { + const c = comments[0]; + this.props.push(c); + offset = c.end; + } else { + offset = PlainValue.Node.endOfLine(src, start + 1); + } + } + + const end = this.node ? this.node.valueRange.end : offset; + this.valueRange = new PlainValue.Range(start, end); + return offset; + } + + setOrigRanges(cr, offset) { + offset = super.setOrigRanges(cr, offset); + return this.node ? this.node.setOrigRanges(cr, offset) : offset; + } + + toString() { + const { + context: { + src + }, + node, + range, + value + } = this; + if (value != null) return value; + const str = node ? src.slice(range.start, node.range.start) + String(node) : src.slice(range.start, range.end); + return PlainValue.Node.addStringTerminator(src, range.end, str); + } + +} + +class Comment extends PlainValue.Node { + constructor() { + super(PlainValue.Type.COMMENT); + } + /** + * Parses a comment line from the source + * + * @param {ParseContext} context + * @param {number} start - Index of first character + * @returns {number} - Index of the character after this scalar + */ + + + parse(context, start) { + this.context = context; + const offset = this.parseComment(start); + this.range = new PlainValue.Range(start, offset); + return offset; + } + +} + +function grabCollectionEndComments(node) { + let cnode = node; + + while (cnode instanceof CollectionItem) cnode = cnode.node; + + if (!(cnode instanceof Collection)) return null; + const len = cnode.items.length; + let ci = -1; + + for (let i = len - 1; i >= 0; --i) { + const n = cnode.items[i]; + + if (n.type === PlainValue.Type.COMMENT) { + // Keep sufficiently indented comments with preceding node + const { + indent, + lineStart + } = n.context; + if (indent > 0 && n.range.start >= lineStart + indent) break; + ci = i; + } else if (n.type === PlainValue.Type.BLANK_LINE) ci = i;else break; + } + + if (ci === -1) return null; + const ca = cnode.items.splice(ci, len - ci); + const prevEnd = ca[0].range.start; + + while (true) { + cnode.range.end = prevEnd; + if (cnode.valueRange && cnode.valueRange.end > prevEnd) cnode.valueRange.end = prevEnd; + if (cnode === node) break; + cnode = cnode.context.parent; + } + + return ca; +} +class Collection extends PlainValue.Node { + static nextContentHasIndent(src, offset, indent) { + const lineStart = PlainValue.Node.endOfLine(src, offset) + 1; + offset = PlainValue.Node.endOfWhiteSpace(src, lineStart); + const ch = src[offset]; + if (!ch) return false; + if (offset >= lineStart + indent) return true; + if (ch !== '#' && ch !== '\n') return false; + return Collection.nextContentHasIndent(src, offset, indent); + } + + constructor(firstItem) { + super(firstItem.type === PlainValue.Type.SEQ_ITEM ? PlainValue.Type.SEQ : PlainValue.Type.MAP); + + for (let i = firstItem.props.length - 1; i >= 0; --i) { + if (firstItem.props[i].start < firstItem.context.lineStart) { + // props on previous line are assumed by the collection + this.props = firstItem.props.slice(0, i + 1); + firstItem.props = firstItem.props.slice(i + 1); + const itemRange = firstItem.props[0] || firstItem.valueRange; + firstItem.range.start = itemRange.start; + break; + } + } + + this.items = [firstItem]; + const ec = grabCollectionEndComments(firstItem); + if (ec) Array.prototype.push.apply(this.items, ec); + } + + get includesTrailingLines() { + return this.items.length > 0; + } + /** + * @param {ParseContext} context + * @param {number} start - Index of first character + * @returns {number} - Index of the character after this + */ + + + parse(context, start) { + this.context = context; + const { + parseNode, + src + } = context; // It's easier to recalculate lineStart here rather than tracking down the + // last context from which to read it -- eemeli/yaml#2 + + let lineStart = PlainValue.Node.startOfLine(src, start); + const firstItem = this.items[0]; // First-item context needs to be correct for later comment handling + // -- eemeli/yaml#17 + + firstItem.context.parent = this; + this.valueRange = PlainValue.Range.copy(firstItem.valueRange); + const indent = firstItem.range.start - firstItem.context.lineStart; + let offset = start; + offset = PlainValue.Node.normalizeOffset(src, offset); + let ch = src[offset]; + let atLineStart = PlainValue.Node.endOfWhiteSpace(src, lineStart) === offset; + let prevIncludesTrailingLines = false; + + while (ch) { + while (ch === '\n' || ch === '#') { + if (atLineStart && ch === '\n' && !prevIncludesTrailingLines) { + const blankLine = new BlankLine(); + offset = blankLine.parse({ + src + }, offset); + this.valueRange.end = offset; + + if (offset >= src.length) { + ch = null; + break; + } + + this.items.push(blankLine); + offset -= 1; // blankLine.parse() consumes terminal newline + } else if (ch === '#') { + if (offset < lineStart + indent && !Collection.nextContentHasIndent(src, offset, indent)) { + return offset; + } + + const comment = new Comment(); + offset = comment.parse({ + indent, + lineStart, + src + }, offset); + this.items.push(comment); + this.valueRange.end = offset; + + if (offset >= src.length) { + ch = null; + break; + } + } + + lineStart = offset + 1; + offset = PlainValue.Node.endOfIndent(src, lineStart); + + if (PlainValue.Node.atBlank(src, offset)) { + const wsEnd = PlainValue.Node.endOfWhiteSpace(src, offset); + const next = src[wsEnd]; + + if (!next || next === '\n' || next === '#') { + offset = wsEnd; + } + } + + ch = src[offset]; + atLineStart = true; + } + + if (!ch) { + break; + } + + if (offset !== lineStart + indent && (atLineStart || ch !== ':')) { + if (offset < lineStart + indent) { + if (lineStart > start) offset = lineStart; + break; + } else if (!this.error) { + const msg = 'All collection items must start at the same column'; + this.error = new PlainValue.YAMLSyntaxError(this, msg); + } + } + + if (firstItem.type === PlainValue.Type.SEQ_ITEM) { + if (ch !== '-') { + if (lineStart > start) offset = lineStart; + break; + } + } else if (ch === '-' && !this.error) { + // map key may start with -, as long as it's followed by a non-whitespace char + const next = src[offset + 1]; + + if (!next || next === '\n' || next === '\t' || next === ' ') { + const msg = 'A collection cannot be both a mapping and a sequence'; + this.error = new PlainValue.YAMLSyntaxError(this, msg); + } + } + + const node = parseNode({ + atLineStart, + inCollection: true, + indent, + lineStart, + parent: this + }, offset); + if (!node) return offset; // at next document start + + this.items.push(node); + this.valueRange.end = node.valueRange.end; + offset = PlainValue.Node.normalizeOffset(src, node.range.end); + ch = src[offset]; + atLineStart = false; + prevIncludesTrailingLines = node.includesTrailingLines; // Need to reset lineStart and atLineStart here if preceding node's range + // has advanced to check the current line's indentation level + // -- eemeli/yaml#10 & eemeli/yaml#38 + + if (ch) { + let ls = offset - 1; + let prev = src[ls]; + + while (prev === ' ' || prev === '\t') prev = src[--ls]; + + if (prev === '\n') { + lineStart = ls + 1; + atLineStart = true; + } + } + + const ec = grabCollectionEndComments(node); + if (ec) Array.prototype.push.apply(this.items, ec); + } + + return offset; + } + + setOrigRanges(cr, offset) { + offset = super.setOrigRanges(cr, offset); + this.items.forEach(node => { + offset = node.setOrigRanges(cr, offset); + }); + return offset; + } + + toString() { + const { + context: { + src + }, + items, + range, + value + } = this; + if (value != null) return value; + let str = src.slice(range.start, items[0].range.start) + String(items[0]); + + for (let i = 1; i < items.length; ++i) { + const item = items[i]; + const { + atLineStart, + indent + } = item.context; + if (atLineStart) for (let i = 0; i < indent; ++i) str += ' '; + str += String(item); + } + + return PlainValue.Node.addStringTerminator(src, range.end, str); + } + +} + +class Directive extends PlainValue.Node { + constructor() { + super(PlainValue.Type.DIRECTIVE); + this.name = null; + } + + get parameters() { + const raw = this.rawValue; + return raw ? raw.trim().split(/[ \t]+/) : []; + } + + parseName(start) { + const { + src + } = this.context; + let offset = start; + let ch = src[offset]; + + while (ch && ch !== '\n' && ch !== '\t' && ch !== ' ') ch = src[offset += 1]; + + this.name = src.slice(start, offset); + return offset; + } + + parseParameters(start) { + const { + src + } = this.context; + let offset = start; + let ch = src[offset]; + + while (ch && ch !== '\n' && ch !== '#') ch = src[offset += 1]; + + this.valueRange = new PlainValue.Range(start, offset); + return offset; + } + + parse(context, start) { + this.context = context; + let offset = this.parseName(start + 1); + offset = this.parseParameters(offset); + offset = this.parseComment(offset); + this.range = new PlainValue.Range(start, offset); + return offset; + } + +} + +class Document extends PlainValue.Node { + static startCommentOrEndBlankLine(src, start) { + const offset = PlainValue.Node.endOfWhiteSpace(src, start); + const ch = src[offset]; + return ch === '#' || ch === '\n' ? offset : start; + } + + constructor() { + super(PlainValue.Type.DOCUMENT); + this.directives = null; + this.contents = null; + this.directivesEndMarker = null; + this.documentEndMarker = null; + } + + parseDirectives(start) { + const { + src + } = this.context; + this.directives = []; + let atLineStart = true; + let hasDirectives = false; + let offset = start; + + while (!PlainValue.Node.atDocumentBoundary(src, offset, PlainValue.Char.DIRECTIVES_END)) { + offset = Document.startCommentOrEndBlankLine(src, offset); + + switch (src[offset]) { + case '\n': + if (atLineStart) { + const blankLine = new BlankLine(); + offset = blankLine.parse({ + src + }, offset); + + if (offset < src.length) { + this.directives.push(blankLine); + } + } else { + offset += 1; + atLineStart = true; + } + + break; + + case '#': + { + const comment = new Comment(); + offset = comment.parse({ + src + }, offset); + this.directives.push(comment); + atLineStart = false; + } + break; + + case '%': + { + const directive = new Directive(); + offset = directive.parse({ + parent: this, + src + }, offset); + this.directives.push(directive); + hasDirectives = true; + atLineStart = false; + } + break; + + default: + if (hasDirectives) { + this.error = new PlainValue.YAMLSemanticError(this, 'Missing directives-end indicator line'); + } else if (this.directives.length > 0) { + this.contents = this.directives; + this.directives = []; + } + + return offset; + } + } + + if (src[offset]) { + this.directivesEndMarker = new PlainValue.Range(offset, offset + 3); + return offset + 3; + } + + if (hasDirectives) { + this.error = new PlainValue.YAMLSemanticError(this, 'Missing directives-end indicator line'); + } else if (this.directives.length > 0) { + this.contents = this.directives; + this.directives = []; + } + + return offset; + } + + parseContents(start) { + const { + parseNode, + src + } = this.context; + if (!this.contents) this.contents = []; + let lineStart = start; + + while (src[lineStart - 1] === '-') lineStart -= 1; + + let offset = PlainValue.Node.endOfWhiteSpace(src, start); + let atLineStart = lineStart === start; + this.valueRange = new PlainValue.Range(offset); + + while (!PlainValue.Node.atDocumentBoundary(src, offset, PlainValue.Char.DOCUMENT_END)) { + switch (src[offset]) { + case '\n': + if (atLineStart) { + const blankLine = new BlankLine(); + offset = blankLine.parse({ + src + }, offset); + + if (offset < src.length) { + this.contents.push(blankLine); + } + } else { + offset += 1; + atLineStart = true; + } + + lineStart = offset; + break; + + case '#': + { + const comment = new Comment(); + offset = comment.parse({ + src + }, offset); + this.contents.push(comment); + atLineStart = false; + } + break; + + default: + { + const iEnd = PlainValue.Node.endOfIndent(src, offset); + const context = { + atLineStart, + indent: -1, + inFlow: false, + inCollection: false, + lineStart, + parent: this + }; + const node = parseNode(context, iEnd); + if (!node) return this.valueRange.end = iEnd; // at next document start + + this.contents.push(node); + offset = node.range.end; + atLineStart = false; + const ec = grabCollectionEndComments(node); + if (ec) Array.prototype.push.apply(this.contents, ec); + } + } + + offset = Document.startCommentOrEndBlankLine(src, offset); + } + + this.valueRange.end = offset; + + if (src[offset]) { + this.documentEndMarker = new PlainValue.Range(offset, offset + 3); + offset += 3; + + if (src[offset]) { + offset = PlainValue.Node.endOfWhiteSpace(src, offset); + + if (src[offset] === '#') { + const comment = new Comment(); + offset = comment.parse({ + src + }, offset); + this.contents.push(comment); + } + + switch (src[offset]) { + case '\n': + offset += 1; + break; + + case undefined: + break; + + default: + this.error = new PlainValue.YAMLSyntaxError(this, 'Document end marker line cannot have a non-comment suffix'); + } + } + } + + return offset; + } + /** + * @param {ParseContext} context + * @param {number} start - Index of first character + * @returns {number} - Index of the character after this + */ + + + parse(context, start) { + context.root = this; + this.context = context; + const { + src + } = context; + let offset = src.charCodeAt(start) === 0xfeff ? start + 1 : start; // skip BOM + + offset = this.parseDirectives(offset); + offset = this.parseContents(offset); + return offset; + } + + setOrigRanges(cr, offset) { + offset = super.setOrigRanges(cr, offset); + this.directives.forEach(node => { + offset = node.setOrigRanges(cr, offset); + }); + if (this.directivesEndMarker) offset = this.directivesEndMarker.setOrigRange(cr, offset); + this.contents.forEach(node => { + offset = node.setOrigRanges(cr, offset); + }); + if (this.documentEndMarker) offset = this.documentEndMarker.setOrigRange(cr, offset); + return offset; + } + + toString() { + const { + contents, + directives, + value + } = this; + if (value != null) return value; + let str = directives.join(''); + + if (contents.length > 0) { + if (directives.length > 0 || contents[0].type === PlainValue.Type.COMMENT) str += '---\n'; + str += contents.join(''); + } + + if (str[str.length - 1] !== '\n') str += '\n'; + return str; + } + +} + +class Alias extends PlainValue.Node { + /** + * Parses an *alias from the source + * + * @param {ParseContext} context + * @param {number} start - Index of first character + * @returns {number} - Index of the character after this scalar + */ + parse(context, start) { + this.context = context; + const { + src + } = context; + let offset = PlainValue.Node.endOfIdentifier(src, start + 1); + this.valueRange = new PlainValue.Range(start + 1, offset); + offset = PlainValue.Node.endOfWhiteSpace(src, offset); + offset = this.parseComment(offset); + return offset; + } + +} + +const Chomp = { + CLIP: 'CLIP', + KEEP: 'KEEP', + STRIP: 'STRIP' +}; +class BlockValue extends PlainValue.Node { + constructor(type, props) { + super(type, props); + this.blockIndent = null; + this.chomping = Chomp.CLIP; + this.header = null; + } + + get includesTrailingLines() { + return this.chomping === Chomp.KEEP; + } + + get strValue() { + if (!this.valueRange || !this.context) return null; + let { + start, + end + } = this.valueRange; + const { + indent, + src + } = this.context; + if (this.valueRange.isEmpty()) return ''; + let lastNewLine = null; + let ch = src[end - 1]; + + while (ch === '\n' || ch === '\t' || ch === ' ') { + end -= 1; + + if (end <= start) { + if (this.chomping === Chomp.KEEP) break;else return ''; // probably never happens + } + + if (ch === '\n') lastNewLine = end; + ch = src[end - 1]; + } + + let keepStart = end + 1; + + if (lastNewLine) { + if (this.chomping === Chomp.KEEP) { + keepStart = lastNewLine; + end = this.valueRange.end; + } else { + end = lastNewLine; + } + } + + const bi = indent + this.blockIndent; + const folded = this.type === PlainValue.Type.BLOCK_FOLDED; + let atStart = true; + let str = ''; + let sep = ''; + let prevMoreIndented = false; + + for (let i = start; i < end; ++i) { + for (let j = 0; j < bi; ++j) { + if (src[i] !== ' ') break; + i += 1; + } + + const ch = src[i]; + + if (ch === '\n') { + if (sep === '\n') str += '\n';else sep = '\n'; + } else { + const lineEnd = PlainValue.Node.endOfLine(src, i); + const line = src.slice(i, lineEnd); + i = lineEnd; + + if (folded && (ch === ' ' || ch === '\t') && i < keepStart) { + if (sep === ' ') sep = '\n';else if (!prevMoreIndented && !atStart && sep === '\n') sep = '\n\n'; + str += sep + line; //+ ((lineEnd < end && src[lineEnd]) || '') + + sep = lineEnd < end && src[lineEnd] || ''; + prevMoreIndented = true; + } else { + str += sep + line; + sep = folded && i < keepStart ? ' ' : '\n'; + prevMoreIndented = false; + } + + if (atStart && line !== '') atStart = false; + } + } + + return this.chomping === Chomp.STRIP ? str : str + '\n'; + } + + parseBlockHeader(start) { + const { + src + } = this.context; + let offset = start + 1; + let bi = ''; + + while (true) { + const ch = src[offset]; + + switch (ch) { + case '-': + this.chomping = Chomp.STRIP; + break; + + case '+': + this.chomping = Chomp.KEEP; + break; + + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + bi += ch; + break; + + default: + this.blockIndent = Number(bi) || null; + this.header = new PlainValue.Range(start, offset); + return offset; + } + + offset += 1; + } + } + + parseBlockValue(start) { + const { + indent, + src + } = this.context; + const explicit = !!this.blockIndent; + let offset = start; + let valueEnd = start; + let minBlockIndent = 1; + + for (let ch = src[offset]; ch === '\n'; ch = src[offset]) { + offset += 1; + if (PlainValue.Node.atDocumentBoundary(src, offset)) break; + const end = PlainValue.Node.endOfBlockIndent(src, indent, offset); // should not include tab? + + if (end === null) break; + const ch = src[end]; + const lineIndent = end - (offset + indent); + + if (!this.blockIndent) { + // no explicit block indent, none yet detected + if (src[end] !== '\n') { + // first line with non-whitespace content + if (lineIndent < minBlockIndent) { + const msg = 'Block scalars with more-indented leading empty lines must use an explicit indentation indicator'; + this.error = new PlainValue.YAMLSemanticError(this, msg); + } + + this.blockIndent = lineIndent; + } else if (lineIndent > minBlockIndent) { + // empty line with more whitespace + minBlockIndent = lineIndent; + } + } else if (ch && ch !== '\n' && lineIndent < this.blockIndent) { + if (src[end] === '#') break; + + if (!this.error) { + const src = explicit ? 'explicit indentation indicator' : 'first line'; + const msg = `Block scalars must not be less indented than their ${src}`; + this.error = new PlainValue.YAMLSemanticError(this, msg); + } + } + + if (src[end] === '\n') { + offset = end; + } else { + offset = valueEnd = PlainValue.Node.endOfLine(src, end); + } + } + + if (this.chomping !== Chomp.KEEP) { + offset = src[valueEnd] ? valueEnd + 1 : valueEnd; + } + + this.valueRange = new PlainValue.Range(start + 1, offset); + return offset; + } + /** + * Parses a block value from the source + * + * Accepted forms are: + * ``` + * BS + * block + * lines + * + * BS #comment + * block + * lines + * ``` + * where the block style BS matches the regexp `[|>][-+1-9]*` and block lines + * are empty or have an indent level greater than `indent`. + * + * @param {ParseContext} context + * @param {number} start - Index of first character + * @returns {number} - Index of the character after this block + */ + + + parse(context, start) { + this.context = context; + const { + src + } = context; + let offset = this.parseBlockHeader(start); + offset = PlainValue.Node.endOfWhiteSpace(src, offset); + offset = this.parseComment(offset); + offset = this.parseBlockValue(offset); + return offset; + } + + setOrigRanges(cr, offset) { + offset = super.setOrigRanges(cr, offset); + return this.header ? this.header.setOrigRange(cr, offset) : offset; + } + +} + +class FlowCollection extends PlainValue.Node { + constructor(type, props) { + super(type, props); + this.items = null; + } + + prevNodeIsJsonLike(idx = this.items.length) { + const node = this.items[idx - 1]; + return !!node && (node.jsonLike || node.type === PlainValue.Type.COMMENT && this.prevNodeIsJsonLike(idx - 1)); + } + /** + * @param {ParseContext} context + * @param {number} start - Index of first character + * @returns {number} - Index of the character after this + */ + + + parse(context, start) { + this.context = context; + const { + parseNode, + src + } = context; + let { + indent, + lineStart + } = context; + let char = src[start]; // { or [ + + this.items = [{ + char, + offset: start + }]; + let offset = PlainValue.Node.endOfWhiteSpace(src, start + 1); + char = src[offset]; + + while (char && char !== ']' && char !== '}') { + switch (char) { + case '\n': + { + lineStart = offset + 1; + const wsEnd = PlainValue.Node.endOfWhiteSpace(src, lineStart); + + if (src[wsEnd] === '\n') { + const blankLine = new BlankLine(); + lineStart = blankLine.parse({ + src + }, lineStart); + this.items.push(blankLine); + } + + offset = PlainValue.Node.endOfIndent(src, lineStart); + + if (offset <= lineStart + indent) { + char = src[offset]; + + if (offset < lineStart + indent || char !== ']' && char !== '}') { + const msg = 'Insufficient indentation in flow collection'; + this.error = new PlainValue.YAMLSemanticError(this, msg); + } + } + } + break; + + case ',': + { + this.items.push({ + char, + offset + }); + offset += 1; + } + break; + + case '#': + { + const comment = new Comment(); + offset = comment.parse({ + src + }, offset); + this.items.push(comment); + } + break; + + case '?': + case ':': + { + const next = src[offset + 1]; + + if (next === '\n' || next === '\t' || next === ' ' || next === ',' || // in-flow : after JSON-like key does not need to be followed by whitespace + char === ':' && this.prevNodeIsJsonLike()) { + this.items.push({ + char, + offset + }); + offset += 1; + break; + } + } + // fallthrough + + default: + { + const node = parseNode({ + atLineStart: false, + inCollection: false, + inFlow: true, + indent: -1, + lineStart, + parent: this + }, offset); + + if (!node) { + // at next document start + this.valueRange = new PlainValue.Range(start, offset); + return offset; + } + + this.items.push(node); + offset = PlainValue.Node.normalizeOffset(src, node.range.end); + } + } + + offset = PlainValue.Node.endOfWhiteSpace(src, offset); + char = src[offset]; + } + + this.valueRange = new PlainValue.Range(start, offset + 1); + + if (char) { + this.items.push({ + char, + offset + }); + offset = PlainValue.Node.endOfWhiteSpace(src, offset + 1); + offset = this.parseComment(offset); + } + + return offset; + } + + setOrigRanges(cr, offset) { + offset = super.setOrigRanges(cr, offset); + this.items.forEach(node => { + if (node instanceof PlainValue.Node) { + offset = node.setOrigRanges(cr, offset); + } else if (cr.length === 0) { + node.origOffset = node.offset; + } else { + let i = offset; + + while (i < cr.length) { + if (cr[i] > node.offset) break;else ++i; + } + + node.origOffset = node.offset + i; + offset = i; + } + }); + return offset; + } + + toString() { + const { + context: { + src + }, + items, + range, + value + } = this; + if (value != null) return value; + const nodes = items.filter(item => item instanceof PlainValue.Node); + let str = ''; + let prevEnd = range.start; + nodes.forEach(node => { + const prefix = src.slice(prevEnd, node.range.start); + prevEnd = node.range.end; + str += prefix + String(node); + + if (str[str.length - 1] === '\n' && src[prevEnd - 1] !== '\n' && src[prevEnd] === '\n') { + // Comment range does not include the terminal newline, but its + // stringified value does. Without this fix, newlines at comment ends + // get duplicated. + prevEnd += 1; + } + }); + str += src.slice(prevEnd, range.end); + return PlainValue.Node.addStringTerminator(src, range.end, str); + } + +} + +class QuoteDouble extends PlainValue.Node { + static endOfQuote(src, offset) { + let ch = src[offset]; + + while (ch && ch !== '"') { + offset += ch === '\\' ? 2 : 1; + ch = src[offset]; + } + + return offset + 1; + } + /** + * @returns {string | { str: string, errors: YAMLSyntaxError[] }} + */ + + + get strValue() { + if (!this.valueRange || !this.context) return null; + const errors = []; + const { + start, + end + } = this.valueRange; + const { + indent, + src + } = this.context; + if (src[end - 1] !== '"') errors.push(new PlainValue.YAMLSyntaxError(this, 'Missing closing "quote')); // Using String#replace is too painful with escaped newlines preceded by + // escaped backslashes; also, this should be faster. + + let str = ''; + + for (let i = start + 1; i < end - 1; ++i) { + const ch = src[i]; + + if (ch === '\n') { + if (PlainValue.Node.atDocumentBoundary(src, i + 1)) errors.push(new PlainValue.YAMLSemanticError(this, 'Document boundary indicators are not allowed within string values')); + const { + fold, + offset, + error + } = PlainValue.Node.foldNewline(src, i, indent); + str += fold; + i = offset; + if (error) errors.push(new PlainValue.YAMLSemanticError(this, 'Multi-line double-quoted string needs to be sufficiently indented')); + } else if (ch === '\\') { + i += 1; + + switch (src[i]) { + case '0': + str += '\0'; + break; + // null character + + case 'a': + str += '\x07'; + break; + // bell character + + case 'b': + str += '\b'; + break; + // backspace + + case 'e': + str += '\x1b'; + break; + // escape character + + case 'f': + str += '\f'; + break; + // form feed + + case 'n': + str += '\n'; + break; + // line feed + + case 'r': + str += '\r'; + break; + // carriage return + + case 't': + str += '\t'; + break; + // horizontal tab + + case 'v': + str += '\v'; + break; + // vertical tab + + case 'N': + str += '\u0085'; + break; + // Unicode next line + + case '_': + str += '\u00a0'; + break; + // Unicode non-breaking space + + case 'L': + str += '\u2028'; + break; + // Unicode line separator + + case 'P': + str += '\u2029'; + break; + // Unicode paragraph separator + + case ' ': + str += ' '; + break; + + case '"': + str += '"'; + break; + + case '/': + str += '/'; + break; + + case '\\': + str += '\\'; + break; + + case '\t': + str += '\t'; + break; + + case 'x': + str += this.parseCharCode(i + 1, 2, errors); + i += 2; + break; + + case 'u': + str += this.parseCharCode(i + 1, 4, errors); + i += 4; + break; + + case 'U': + str += this.parseCharCode(i + 1, 8, errors); + i += 8; + break; + + case '\n': + // skip escaped newlines, but still trim the following line + while (src[i + 1] === ' ' || src[i + 1] === '\t') i += 1; + + break; + + default: + errors.push(new PlainValue.YAMLSyntaxError(this, `Invalid escape sequence ${src.substr(i - 1, 2)}`)); + str += '\\' + src[i]; + } + } else if (ch === ' ' || ch === '\t') { + // trim trailing whitespace + const wsStart = i; + let next = src[i + 1]; + + while (next === ' ' || next === '\t') { + i += 1; + next = src[i + 1]; + } + + if (next !== '\n') str += i > wsStart ? src.slice(wsStart, i + 1) : ch; + } else { + str += ch; + } + } + + return errors.length > 0 ? { + errors, + str + } : str; + } + + parseCharCode(offset, length, errors) { + const { + src + } = this.context; + const cc = src.substr(offset, length); + const ok = cc.length === length && /^[0-9a-fA-F]+$/.test(cc); + const code = ok ? parseInt(cc, 16) : NaN; + + if (isNaN(code)) { + errors.push(new PlainValue.YAMLSyntaxError(this, `Invalid escape sequence ${src.substr(offset - 2, length + 2)}`)); + return src.substr(offset - 2, length + 2); + } + + return String.fromCodePoint(code); + } + /** + * Parses a "double quoted" value from the source + * + * @param {ParseContext} context + * @param {number} start - Index of first character + * @returns {number} - Index of the character after this scalar + */ + + + parse(context, start) { + this.context = context; + const { + src + } = context; + let offset = QuoteDouble.endOfQuote(src, start + 1); + this.valueRange = new PlainValue.Range(start, offset); + offset = PlainValue.Node.endOfWhiteSpace(src, offset); + offset = this.parseComment(offset); + return offset; + } + +} + +class QuoteSingle extends PlainValue.Node { + static endOfQuote(src, offset) { + let ch = src[offset]; + + while (ch) { + if (ch === "'") { + if (src[offset + 1] !== "'") break; + ch = src[offset += 2]; + } else { + ch = src[offset += 1]; + } + } + + return offset + 1; + } + /** + * @returns {string | { str: string, errors: YAMLSyntaxError[] }} + */ + + + get strValue() { + if (!this.valueRange || !this.context) return null; + const errors = []; + const { + start, + end + } = this.valueRange; + const { + indent, + src + } = this.context; + if (src[end - 1] !== "'") errors.push(new PlainValue.YAMLSyntaxError(this, "Missing closing 'quote")); + let str = ''; + + for (let i = start + 1; i < end - 1; ++i) { + const ch = src[i]; + + if (ch === '\n') { + if (PlainValue.Node.atDocumentBoundary(src, i + 1)) errors.push(new PlainValue.YAMLSemanticError(this, 'Document boundary indicators are not allowed within string values')); + const { + fold, + offset, + error + } = PlainValue.Node.foldNewline(src, i, indent); + str += fold; + i = offset; + if (error) errors.push(new PlainValue.YAMLSemanticError(this, 'Multi-line single-quoted string needs to be sufficiently indented')); + } else if (ch === "'") { + str += ch; + i += 1; + if (src[i] !== "'") errors.push(new PlainValue.YAMLSyntaxError(this, 'Unescaped single quote? This should not happen.')); + } else if (ch === ' ' || ch === '\t') { + // trim trailing whitespace + const wsStart = i; + let next = src[i + 1]; + + while (next === ' ' || next === '\t') { + i += 1; + next = src[i + 1]; + } + + if (next !== '\n') str += i > wsStart ? src.slice(wsStart, i + 1) : ch; + } else { + str += ch; + } + } + + return errors.length > 0 ? { + errors, + str + } : str; + } + /** + * Parses a 'single quoted' value from the source + * + * @param {ParseContext} context + * @param {number} start - Index of first character + * @returns {number} - Index of the character after this scalar + */ + + + parse(context, start) { + this.context = context; + const { + src + } = context; + let offset = QuoteSingle.endOfQuote(src, start + 1); + this.valueRange = new PlainValue.Range(start, offset); + offset = PlainValue.Node.endOfWhiteSpace(src, offset); + offset = this.parseComment(offset); + return offset; + } + +} + +function createNewNode(type, props) { + switch (type) { + case PlainValue.Type.ALIAS: + return new Alias(type, props); + + case PlainValue.Type.BLOCK_FOLDED: + case PlainValue.Type.BLOCK_LITERAL: + return new BlockValue(type, props); + + case PlainValue.Type.FLOW_MAP: + case PlainValue.Type.FLOW_SEQ: + return new FlowCollection(type, props); + + case PlainValue.Type.MAP_KEY: + case PlainValue.Type.MAP_VALUE: + case PlainValue.Type.SEQ_ITEM: + return new CollectionItem(type, props); + + case PlainValue.Type.COMMENT: + case PlainValue.Type.PLAIN: + return new PlainValue.PlainValue(type, props); + + case PlainValue.Type.QUOTE_DOUBLE: + return new QuoteDouble(type, props); + + case PlainValue.Type.QUOTE_SINGLE: + return new QuoteSingle(type, props); + + /* istanbul ignore next */ + + default: + return null; + // should never happen + } +} +/** + * @param {boolean} atLineStart - Node starts at beginning of line + * @param {boolean} inFlow - true if currently in a flow context + * @param {boolean} inCollection - true if currently in a collection context + * @param {number} indent - Current level of indentation + * @param {number} lineStart - Start of the current line + * @param {Node} parent - The parent of the node + * @param {string} src - Source of the YAML document + */ + + +class ParseContext { + static parseType(src, offset, inFlow) { + switch (src[offset]) { + case '*': + return PlainValue.Type.ALIAS; + + case '>': + return PlainValue.Type.BLOCK_FOLDED; + + case '|': + return PlainValue.Type.BLOCK_LITERAL; + + case '{': + return PlainValue.Type.FLOW_MAP; + + case '[': + return PlainValue.Type.FLOW_SEQ; + + case '?': + return !inFlow && PlainValue.Node.atBlank(src, offset + 1, true) ? PlainValue.Type.MAP_KEY : PlainValue.Type.PLAIN; + + case ':': + return !inFlow && PlainValue.Node.atBlank(src, offset + 1, true) ? PlainValue.Type.MAP_VALUE : PlainValue.Type.PLAIN; + + case '-': + return !inFlow && PlainValue.Node.atBlank(src, offset + 1, true) ? PlainValue.Type.SEQ_ITEM : PlainValue.Type.PLAIN; + + case '"': + return PlainValue.Type.QUOTE_DOUBLE; + + case "'": + return PlainValue.Type.QUOTE_SINGLE; + + default: + return PlainValue.Type.PLAIN; + } + } + + constructor(orig = {}, { + atLineStart, + inCollection, + inFlow, + indent, + lineStart, + parent + } = {}) { + PlainValue._defineProperty(this, "parseNode", (overlay, start) => { + if (PlainValue.Node.atDocumentBoundary(this.src, start)) return null; + const context = new ParseContext(this, overlay); + const { + props, + type, + valueStart + } = context.parseProps(start); + const node = createNewNode(type, props); + let offset = node.parse(context, valueStart); + node.range = new PlainValue.Range(start, offset); + /* istanbul ignore if */ + + if (offset <= start) { + // This should never happen, but if it does, let's make sure to at least + // step one character forward to avoid a busy loop. + node.error = new Error(`Node#parse consumed no characters`); + node.error.parseEnd = offset; + node.error.source = node; + node.range.end = start + 1; + } + + if (context.nodeStartsCollection(node)) { + if (!node.error && !context.atLineStart && context.parent.type === PlainValue.Type.DOCUMENT) { + node.error = new PlainValue.YAMLSyntaxError(node, 'Block collection must not have preceding content here (e.g. directives-end indicator)'); + } + + const collection = new Collection(node); + offset = collection.parse(new ParseContext(context), offset); + collection.range = new PlainValue.Range(start, offset); + return collection; + } + + return node; + }); + + this.atLineStart = atLineStart != null ? atLineStart : orig.atLineStart || false; + this.inCollection = inCollection != null ? inCollection : orig.inCollection || false; + this.inFlow = inFlow != null ? inFlow : orig.inFlow || false; + this.indent = indent != null ? indent : orig.indent; + this.lineStart = lineStart != null ? lineStart : orig.lineStart; + this.parent = parent != null ? parent : orig.parent || {}; + this.root = orig.root; + this.src = orig.src; + } + + nodeStartsCollection(node) { + const { + inCollection, + inFlow, + src + } = this; + if (inCollection || inFlow) return false; + if (node instanceof CollectionItem) return true; // check for implicit key + + let offset = node.range.end; + if (src[offset] === '\n' || src[offset - 1] === '\n') return false; + offset = PlainValue.Node.endOfWhiteSpace(src, offset); + return src[offset] === ':'; + } // Anchor and tag are before type, which determines the node implementation + // class; hence this intermediate step. + + + parseProps(offset) { + const { + inFlow, + parent, + src + } = this; + const props = []; + let lineHasProps = false; + offset = this.atLineStart ? PlainValue.Node.endOfIndent(src, offset) : PlainValue.Node.endOfWhiteSpace(src, offset); + let ch = src[offset]; + + while (ch === PlainValue.Char.ANCHOR || ch === PlainValue.Char.COMMENT || ch === PlainValue.Char.TAG || ch === '\n') { + if (ch === '\n') { + const lineStart = offset + 1; + const inEnd = PlainValue.Node.endOfIndent(src, lineStart); + const indentDiff = inEnd - (lineStart + this.indent); + const noIndicatorAsIndent = parent.type === PlainValue.Type.SEQ_ITEM && parent.context.atLineStart; + if (!PlainValue.Node.nextNodeIsIndented(src[inEnd], indentDiff, !noIndicatorAsIndent)) break; + this.atLineStart = true; + this.lineStart = lineStart; + lineHasProps = false; + offset = inEnd; + } else if (ch === PlainValue.Char.COMMENT) { + const end = PlainValue.Node.endOfLine(src, offset + 1); + props.push(new PlainValue.Range(offset, end)); + offset = end; + } else { + let end = PlainValue.Node.endOfIdentifier(src, offset + 1); + + if (ch === PlainValue.Char.TAG && src[end] === ',' && /^[a-zA-Z0-9-]+\.[a-zA-Z0-9-]+,\d\d\d\d(-\d\d){0,2}\/\S/.test(src.slice(offset + 1, end + 13))) { + // Let's presume we're dealing with a YAML 1.0 domain tag here, rather + // than an empty but 'foo.bar' private-tagged node in a flow collection + // followed without whitespace by a plain string starting with a year + // or date divided by something. + end = PlainValue.Node.endOfIdentifier(src, end + 5); + } + + props.push(new PlainValue.Range(offset, end)); + lineHasProps = true; + offset = PlainValue.Node.endOfWhiteSpace(src, end); + } + + ch = src[offset]; + } // '- &a : b' has an anchor on an empty node + + + if (lineHasProps && ch === ':' && PlainValue.Node.atBlank(src, offset + 1, true)) offset -= 1; + const type = ParseContext.parseType(src, offset, inFlow); + return { + props, + type, + valueStart: offset + }; + } + /** + * Parses a node from the source + * @param {ParseContext} overlay + * @param {number} start - Index of first non-whitespace character for the node + * @returns {?Node} - null if at a document boundary + */ + + +} + +// Published as 'yaml/parse-cst' +function parse(src) { + const cr = []; + + if (src.indexOf('\r') !== -1) { + src = src.replace(/\r\n?/g, (match, offset) => { + if (match.length > 1) cr.push(offset); + return '\n'; + }); + } + + const documents = []; + let offset = 0; + + do { + const doc = new Document(); + const context = new ParseContext({ + src + }); + offset = doc.parse(context, offset); + documents.push(doc); + } while (offset < src.length); + + documents.setOrigRanges = () => { + if (cr.length === 0) return false; + + for (let i = 1; i < cr.length; ++i) cr[i] -= i; + + let crOffset = 0; + + for (let i = 0; i < documents.length; ++i) { + crOffset = documents[i].setOrigRanges(cr, crOffset); + } + + cr.splice(0, cr.length); + return true; + }; + + documents.toString = () => documents.join('...\n'); + + return documents; +} + +exports.parse = parse; diff --git a/node_modules/yaml/dist/resolveSeq-4a68b39b.js b/node_modules/yaml/dist/resolveSeq-4a68b39b.js new file mode 100644 index 0000000..da211e4 --- /dev/null +++ b/node_modules/yaml/dist/resolveSeq-4a68b39b.js @@ -0,0 +1,2115 @@ +'use strict'; + +var PlainValue = require('./PlainValue-ec8e588e.js'); + +function addCommentBefore(str, indent, comment) { + if (!comment) return str; + const cc = comment.replace(/[\s\S]^/gm, `$&${indent}#`); + return `#${cc}\n${indent}${str}`; +} +function addComment(str, indent, comment) { + return !comment ? str : comment.indexOf('\n') === -1 ? `${str} #${comment}` : `${str}\n` + comment.replace(/^/gm, `${indent || ''}#`); +} + +class Node {} + +function toJSON(value, arg, ctx) { + if (Array.isArray(value)) return value.map((v, i) => toJSON(v, String(i), ctx)); + + if (value && typeof value.toJSON === 'function') { + const anchor = ctx && ctx.anchors && ctx.anchors.get(value); + if (anchor) ctx.onCreate = res => { + anchor.res = res; + delete ctx.onCreate; + }; + const res = value.toJSON(arg, ctx); + if (anchor && ctx.onCreate) ctx.onCreate(res); + return res; + } + + if ((!ctx || !ctx.keep) && typeof value === 'bigint') return Number(value); + return value; +} + +class Scalar extends Node { + constructor(value) { + super(); + this.value = value; + } + + toJSON(arg, ctx) { + return ctx && ctx.keep ? this.value : toJSON(this.value, arg, ctx); + } + + toString() { + return String(this.value); + } + +} + +function collectionFromPath(schema, path, value) { + let v = value; + + for (let i = path.length - 1; i >= 0; --i) { + const k = path[i]; + const o = Number.isInteger(k) && k >= 0 ? [] : {}; + o[k] = v; + v = o; + } + + return schema.createNode(v, false); +} // null, undefined, or an empty non-string iterable (e.g. []) + + +const isEmptyPath = path => path == null || typeof path === 'object' && path[Symbol.iterator]().next().done; +class Collection extends Node { + constructor(schema) { + super(); + + PlainValue._defineProperty(this, "items", []); + + this.schema = schema; + } + + addIn(path, value) { + if (isEmptyPath(path)) this.add(value);else { + const [key, ...rest] = path; + const node = this.get(key, true); + 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 ${key}. Remaining path: ${rest}`); + } + } + + deleteIn([key, ...rest]) { + if (rest.length === 0) return this.delete(key); + const node = this.get(key, true); + if (node instanceof Collection) return node.deleteIn(rest);else throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`); + } + + getIn([key, ...rest], keepScalar) { + const node = this.get(key, true); + if (rest.length === 0) return !keepScalar && node instanceof Scalar ? node.value : node;else return node instanceof Collection ? node.getIn(rest, keepScalar) : undefined; + } + + hasAllNullValues() { + return this.items.every(node => { + if (!node || node.type !== 'PAIR') return false; + const n = node.value; + return n == null || n instanceof Scalar && n.value == null && !n.commentBefore && !n.comment && !n.tag; + }); + } + + hasIn([key, ...rest]) { + if (rest.length === 0) return this.has(key); + const node = this.get(key, true); + return node instanceof Collection ? node.hasIn(rest) : false; + } + + setIn([key, ...rest], value) { + if (rest.length === 0) { + this.set(key, value); + } else { + const node = this.get(key, true); + 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 ${key}. Remaining path: ${rest}`); + } + } // overridden in implementations + + /* istanbul ignore next */ + + + toJSON() { + return null; + } + + toString(ctx, { + blockItem, + flowChars, + isMap, + itemIndent + }, onComment, onChompKeep) { + const { + indent, + indentStep, + stringify + } = ctx; + const inFlow = this.type === PlainValue.Type.FLOW_MAP || this.type === PlainValue.Type.FLOW_SEQ || ctx.inFlow; + if (inFlow) itemIndent += indentStep; + const allNullValues = isMap && this.hasAllNullValues(); + ctx = Object.assign({}, ctx, { + allNullValues, + indent: itemIndent, + inFlow, + type: null + }); + let chompKeep = false; + let hasItemWithNewLine = false; + const nodes = this.items.reduce((nodes, item, i) => { + let comment; + + if (item) { + if (!chompKeep && item.spaceBefore) nodes.push({ + type: 'comment', + str: '' + }); + if (item.commentBefore) item.commentBefore.match(/^.*$/gm).forEach(line => { + nodes.push({ + type: 'comment', + str: `#${line}` + }); + }); + if (item.comment) comment = item.comment; + 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; + } + + chompKeep = false; + let str = stringify(item, ctx, () => comment = null, () => chompKeep = true); + if (inFlow && !hasItemWithNewLine && str.includes('\n')) hasItemWithNewLine = true; + if (inFlow && i < this.items.length - 1) str += ','; + str = addComment(str, itemIndent, comment); + if (chompKeep && (comment || inFlow)) chompKeep = false; + nodes.push({ + type: 'item', + str + }); + return nodes; + }, []); + let str; + + if (nodes.length === 0) { + str = flowChars.start + flowChars.end; + } else if (inFlow) { + const { + start, + end + } = flowChars; + const strings = nodes.map(n => n.str); + + if (hasItemWithNewLine || strings.reduce((sum, str) => sum + str.length + 2, 2) > Collection.maxFlowStringSingleLineLength) { + str = start; + + for (const s of strings) { + str += s ? `\n${indentStep}${indent}${s}` : '\n'; + } + + str += `\n${indent}${end}`; + } else { + str = `${start} ${strings.join(' ')} ${end}`; + } + } else { + const strings = nodes.map(blockItem); + str = strings.shift(); + + for (const s of strings) str += s ? `\n${indent}${s}` : '\n'; + } + + if (this.comment) { + str += '\n' + this.comment.replace(/^/gm, `${indent}#`); + if (onComment) onComment(); + } else if (chompKeep && onChompKeep) onChompKeep(); + + return str; + } + +} + +PlainValue._defineProperty(Collection, "maxFlowStringSingleLineLength", 60); + +function asItemIndex(key) { + let idx = key instanceof Scalar ? key.value : key; + if (idx && typeof idx === 'string') idx = Number(idx); + return Number.isInteger(idx) && idx >= 0 ? idx : null; +} + +class YAMLSeq extends Collection { + add(value) { + this.items.push(value); + } + + delete(key) { + const idx = asItemIndex(key); + if (typeof idx !== 'number') return false; + const del = this.items.splice(idx, 1); + return del.length > 0; + } + + get(key, keepScalar) { + const idx = asItemIndex(key); + if (typeof idx !== 'number') return undefined; + const it = this.items[idx]; + return !keepScalar && it instanceof Scalar ? it.value : it; + } + + has(key) { + const idx = asItemIndex(key); + return typeof idx === 'number' && idx < this.items.length; + } + + set(key, value) { + const idx = asItemIndex(key); + if (typeof idx !== 'number') throw new Error(`Expected a valid index, not ${key}.`); + this.items[idx] = value; + } + + toJSON(_, ctx) { + const seq = []; + if (ctx && ctx.onCreate) ctx.onCreate(seq); + let i = 0; + + for (const item of this.items) seq.push(toJSON(item, String(i++), ctx)); + + return seq; + } + + toString(ctx, onComment, onChompKeep) { + if (!ctx) return JSON.stringify(this); + return super.toString(ctx, { + blockItem: n => n.type === 'comment' ? n.str : `- ${n.str}`, + flowChars: { + start: '[', + end: ']' + }, + isMap: false, + itemIndent: (ctx.indent || '') + ' ' + }, onComment, onChompKeep); + } + +} + +const stringifyKey = (key, jsKey, ctx) => { + if (jsKey === null) return ''; + if (typeof jsKey !== 'object') return String(jsKey); + if (key instanceof Node && ctx && ctx.doc) return key.toString({ + anchors: {}, + doc: ctx.doc, + indent: '', + indentStep: ctx.indentStep, + inFlow: true, + inStringifyKey: true, + stringify: ctx.stringify + }); + return JSON.stringify(jsKey); +}; + +class Pair extends Node { + constructor(key, value = null) { + super(); + this.key = key; + this.value = value; + this.type = Pair.Type.PAIR; + } + + get commentBefore() { + return this.key instanceof Node ? this.key.commentBefore : undefined; + } + + set commentBefore(cb) { + if (this.key == null) this.key = new Scalar(null); + if (this.key instanceof Node) this.key.commentBefore = cb;else { + const msg = 'Pair.commentBefore is an alias for Pair.key.commentBefore. To set it, the key must be a Node.'; + throw new Error(msg); + } + } + + addToJSMap(ctx, map) { + const key = toJSON(this.key, '', ctx); + + if (map instanceof Map) { + const value = toJSON(this.value, key, ctx); + map.set(key, value); + } else if (map instanceof Set) { + map.add(key); + } else { + const stringKey = stringifyKey(this.key, key, ctx); + map[stringKey] = toJSON(this.value, stringKey, ctx); + } + + return map; + } + + toJSON(_, ctx) { + const pair = ctx && ctx.mapAsMap ? new Map() : {}; + return this.addToJSMap(ctx, pair); + } + + toString(ctx, onComment, onChompKeep) { + if (!ctx || !ctx.doc) return JSON.stringify(this); + const { + indent: indentSize, + indentSeq, + simpleKeys + } = ctx.doc.options; + let { + key, + value + } = this; + let keyComment = key instanceof Node && key.comment; + + if (simpleKeys) { + if (keyComment) { + throw new Error('With simple keys, key nodes cannot have comments'); + } + + if (key instanceof Collection) { + const msg = 'With simple keys, collection cannot be used as a key value'; + throw new Error(msg); + } + } + + const explicitKey = !simpleKeys && (!key || keyComment || key instanceof Collection || key.type === PlainValue.Type.BLOCK_FOLDED || key.type === PlainValue.Type.BLOCK_LITERAL); + const { + doc, + indent, + indentStep, + stringify + } = ctx; + ctx = Object.assign({}, ctx, { + implicitKey: !explicitKey, + indent: indent + indentStep + }); + let chompKeep = false; + let str = stringify(key, ctx, () => keyComment = null, () => chompKeep = true); + str = addComment(str, ctx.indent, keyComment); + + if (ctx.allNullValues && !simpleKeys) { + if (this.comment) { + str = addComment(str, ctx.indent, this.comment); + if (onComment) onComment(); + } else if (chompKeep && !keyComment && onChompKeep) onChompKeep(); + + return ctx.inFlow ? str : `? ${str}`; + } + + str = explicitKey ? `? ${str}\n${indent}:` : `${str}:`; + + if (this.comment) { + // expected (but not strictly required) to be a single-line comment + str = addComment(str, ctx.indent, this.comment); + if (onComment) onComment(); + } + + let vcb = ''; + let valueComment = null; + + if (value instanceof Node) { + if (value.spaceBefore) vcb = '\n'; + + if (value.commentBefore) { + const cs = value.commentBefore.replace(/^/gm, `${ctx.indent}#`); + vcb += `\n${cs}`; + } + + valueComment = value.comment; + } else if (value && typeof value === 'object') { + value = doc.schema.createNode(value, true); + } + + ctx.implicitKey = false; + if (!explicitKey && !this.comment && value instanceof Scalar) ctx.indentAtStart = str.length + 1; + chompKeep = false; + + if (!indentSeq && indentSize >= 2 && !ctx.inFlow && !explicitKey && value instanceof YAMLSeq && value.type !== PlainValue.Type.FLOW_SEQ && !value.tag && !doc.anchors.getName(value)) { + // If indentSeq === false, consider '- ' as part of indentation where possible + ctx.indent = ctx.indent.substr(2); + } + + const valueStr = stringify(value, ctx, () => valueComment = null, () => chompKeep = true); + let ws = ' '; + + if (vcb || this.comment) { + ws = `${vcb}\n${ctx.indent}`; + } else if (!explicitKey && value instanceof Collection) { + const flow = valueStr[0] === '[' || valueStr[0] === '{'; + if (!flow || valueStr.includes('\n')) ws = `\n${ctx.indent}`; + } + + if (chompKeep && !valueComment && onChompKeep) onChompKeep(); + return addComment(str + ws + valueStr, ctx.indent, valueComment); + } + +} + +PlainValue._defineProperty(Pair, "Type", { + PAIR: 'PAIR', + MERGE_PAIR: 'MERGE_PAIR' +}); + +const getAliasCount = (node, anchors) => { + if (node instanceof Alias) { + const anchor = anchors.get(node.source); + return anchor.count * anchor.aliasCount; + } else if (node instanceof Collection) { + let count = 0; + + for (const item of node.items) { + const c = getAliasCount(item, anchors); + if (c > count) count = c; + } + + return count; + } else if (node instanceof Pair) { + const kc = getAliasCount(node.key, anchors); + const vc = getAliasCount(node.value, anchors); + return Math.max(kc, vc); + } + + return 1; +}; + +class Alias extends Node { + static stringify({ + range, + source + }, { + anchors, + doc, + implicitKey, + inStringifyKey + }) { + let anchor = Object.keys(anchors).find(a => anchors[a] === source); + if (!anchor && inStringifyKey) anchor = doc.anchors.getName(source) || doc.anchors.newName(); + if (anchor) return `*${anchor}${implicitKey ? ' ' : ''}`; + const msg = doc.anchors.getName(source) ? 'Alias node must be after source node' : 'Source node not found for alias node'; + throw new Error(`${msg} [${range}]`); + } + + constructor(source) { + super(); + this.source = source; + this.type = PlainValue.Type.ALIAS; + } + + set tag(t) { + throw new Error('Alias nodes cannot have tags'); + } + + toJSON(arg, ctx) { + if (!ctx) return toJSON(this.source, arg, ctx); + const { + anchors, + maxAliasCount + } = ctx; + const anchor = anchors.get(this.source); + /* istanbul ignore if */ + + if (!anchor || anchor.res === undefined) { + const msg = 'This should not happen: Alias anchor was not resolved?'; + if (this.cstNode) throw new PlainValue.YAMLReferenceError(this.cstNode, msg);else throw new ReferenceError(msg); + } + + if (maxAliasCount >= 0) { + anchor.count += 1; + if (anchor.aliasCount === 0) anchor.aliasCount = getAliasCount(this.source, anchors); + + if (anchor.count * anchor.aliasCount > maxAliasCount) { + const msg = 'Excessive alias count indicates a resource exhaustion attack'; + if (this.cstNode) throw new PlainValue.YAMLReferenceError(this.cstNode, msg);else throw new ReferenceError(msg); + } + } + + return anchor.res; + } // Only called when stringifying an alias mapping key while constructing + // Object output. + + + toString(ctx) { + return Alias.stringify(this, ctx); + } + +} + +PlainValue._defineProperty(Alias, "default", true); + +function findPair(items, key) { + const k = key instanceof Scalar ? key.value : key; + + for (const it of items) { + if (it instanceof Pair) { + if (it.key === key || it.key === k) return it; + if (it.key && it.key.value === k) return it; + } + } + + return undefined; +} +class YAMLMap extends Collection { + add(pair, overwrite) { + if (!pair) pair = new Pair(pair);else if (!(pair instanceof Pair)) pair = new Pair(pair.key || pair, pair.value); + const prev = findPair(this.items, pair.key); + const sortEntries = this.schema && this.schema.sortMapEntries; + + if (prev) { + if (overwrite) prev.value = pair.value;else throw new Error(`Key ${pair.key} already set`); + } else if (sortEntries) { + const i = this.items.findIndex(item => sortEntries(pair, item) < 0); + if (i === -1) this.items.push(pair);else this.items.splice(i, 0, pair); + } else { + this.items.push(pair); + } + } + + delete(key) { + const it = findPair(this.items, key); + if (!it) return false; + const del = this.items.splice(this.items.indexOf(it), 1); + return del.length > 0; + } + + get(key, keepScalar) { + const it = findPair(this.items, key); + const node = it && it.value; + return !keepScalar && node instanceof Scalar ? node.value : node; + } + + has(key) { + return !!findPair(this.items, key); + } + + set(key, value) { + this.add(new Pair(key, value), true); + } + /** + * @param {*} arg ignored + * @param {*} ctx Conversion context, originally set in Document#toJSON() + * @param {Class} Type If set, forces the returned collection type + * @returns {*} Instance of Type, Map, or Object + */ + + + toJSON(_, ctx, Type) { + const map = Type ? new Type() : ctx && ctx.mapAsMap ? new Map() : {}; + if (ctx && ctx.onCreate) ctx.onCreate(map); + + for (const item of this.items) item.addToJSMap(ctx, map); + + return map; + } + + toString(ctx, onComment, onChompKeep) { + if (!ctx) return JSON.stringify(this); + + for (const item of this.items) { + if (!(item instanceof Pair)) throw new Error(`Map items must all be pairs; found ${JSON.stringify(item)} instead`); + } + + return super.toString(ctx, { + blockItem: n => n.str, + flowChars: { + start: '{', + end: '}' + }, + isMap: true, + itemIndent: ctx.indent || '' + }, onComment, onChompKeep); + } + +} + +const MERGE_KEY = '<<'; +class Merge extends Pair { + constructor(pair) { + if (pair instanceof Pair) { + let seq = pair.value; + + if (!(seq instanceof YAMLSeq)) { + seq = new YAMLSeq(); + seq.items.push(pair.value); + seq.range = pair.value.range; + } + + super(pair.key, seq); + this.range = pair.range; + } else { + super(new Scalar(MERGE_KEY), new YAMLSeq()); + } + + this.type = Pair.Type.MERGE_PAIR; + } // If the value associated with a merge key is a single mapping node, each of + // its key/value pairs is inserted into the current mapping, unless the key + // already exists in it. If the value associated with the merge key is a + // sequence, then this sequence is expected to contain mapping nodes and each + // of these nodes is merged in turn according to its order in the sequence. + // Keys in mapping nodes earlier in the sequence override keys specified in + // later mapping nodes. -- http://yaml.org/type/merge.html + + + addToJSMap(ctx, map) { + for (const { + source + } of this.value.items) { + if (!(source instanceof YAMLMap)) throw new Error('Merge sources must be maps'); + const srcMap = source.toJSON(null, ctx, Map); + + for (const [key, value] of srcMap) { + if (map instanceof Map) { + if (!map.has(key)) map.set(key, value); + } else if (map instanceof Set) { + map.add(key); + } else { + if (!Object.prototype.hasOwnProperty.call(map, key)) map[key] = value; + } + } + } + + return map; + } + + toString(ctx, onComment) { + const seq = this.value; + if (seq.items.length > 1) return super.toString(ctx, onComment); + this.value = seq.items[0]; + const str = super.toString(ctx, onComment); + this.value = seq; + return str; + } + +} + +const binaryOptions = { + defaultType: PlainValue.Type.BLOCK_LITERAL, + lineWidth: 76 +}; +const boolOptions = { + trueStr: 'true', + falseStr: 'false' +}; +const intOptions = { + asBigInt: false +}; +const nullOptions = { + nullStr: 'null' +}; +const strOptions = { + defaultType: PlainValue.Type.PLAIN, + doubleQuoted: { + jsonEncoding: false, + minMultiLineLength: 40 + }, + fold: { + lineWidth: 80, + minContentWidth: 20 + } +}; + +function resolveScalar(str, tags, scalarFallback) { + for (const { + format, + test, + resolve + } of tags) { + if (test) { + const match = str.match(test); + + if (match) { + let res = resolve.apply(null, match); + if (!(res instanceof Scalar)) res = new Scalar(res); + if (format) res.format = format; + return res; + } + } + } + + if (scalarFallback) str = scalarFallback(str); + return new Scalar(str); +} + +const FOLD_FLOW = 'flow'; +const FOLD_BLOCK = 'block'; +const FOLD_QUOTED = 'quoted'; // presumes i+1 is at the start of a line +// returns index of last newline in more-indented block + +const consumeMoreIndentedLines = (text, i) => { + let ch = text[i + 1]; + + while (ch === ' ' || ch === '\t') { + do { + ch = text[i += 1]; + } while (ch && ch !== '\n'); + + ch = text[i + 1]; + } + + return i; +}; +/** + * Tries to keep input at up to `lineWidth` characters, splitting only on spaces + * not followed by newlines or spaces unless `mode` is `'quoted'`. Lines are + * terminated with `\n` and started with `indent`. + * + * @param {string} text + * @param {string} indent + * @param {string} [mode='flow'] `'block'` prevents more-indented lines + * from being folded; `'quoted'` allows for `\` escapes, including escaped + * newlines + * @param {Object} options + * @param {number} [options.indentAtStart] Accounts for leading contents on + * the first line, defaulting to `indent.length` + * @param {number} [options.lineWidth=80] + * @param {number} [options.minContentWidth=20] Allow highly indented lines to + * stretch the line width + * @param {function} options.onFold Called once if the text is folded + * @param {function} options.onFold Called once if any line of text exceeds + * lineWidth characters + */ + + +function foldFlowLines(text, indent, mode, { + indentAtStart, + lineWidth = 80, + minContentWidth = 20, + onFold, + onOverflow +}) { + if (!lineWidth || lineWidth < 0) return text; + const endStep = Math.max(1 + minContentWidth, 1 + lineWidth - indent.length); + if (text.length <= endStep) return text; + const folds = []; + const escapedFolds = {}; + let end = lineWidth - (typeof indentAtStart === 'number' ? indentAtStart : indent.length); + let split = undefined; + let prev = undefined; + let overflow = false; + let i = -1; + + if (mode === FOLD_BLOCK) { + i = consumeMoreIndentedLines(text, i); + if (i !== -1) end = i + endStep; + } + + for (let ch; ch = text[i += 1];) { + if (mode === FOLD_QUOTED && ch === '\\') { + switch (text[i + 1]) { + case 'x': + i += 3; + break; + + case 'u': + i += 5; + break; + + case 'U': + i += 9; + break; + + default: + i += 1; + } + } + + if (ch === '\n') { + if (mode === FOLD_BLOCK) i = consumeMoreIndentedLines(text, i); + end = i + endStep; + split = undefined; + } else { + if (ch === ' ' && prev && prev !== ' ' && prev !== '\n' && prev !== '\t') { + // space surrounded by non-space can be replaced with newline + indent + const next = text[i + 1]; + if (next && next !== ' ' && next !== '\n' && next !== '\t') split = i; + } + + if (i >= end) { + if (split) { + folds.push(split); + end = split + endStep; + split = undefined; + } else if (mode === FOLD_QUOTED) { + // white-space collected at end may stretch past lineWidth + while (prev === ' ' || prev === '\t') { + prev = ch; + ch = text[i += 1]; + overflow = true; + } // i - 2 accounts for not-dropped last char + newline-escaping \ + + + folds.push(i - 2); + escapedFolds[i - 2] = true; + end = i - 2 + endStep; + split = undefined; + } else { + overflow = true; + } + } + } + + prev = ch; + } + + if (overflow && onOverflow) onOverflow(); + if (folds.length === 0) return text; + if (onFold) onFold(); + let res = text.slice(0, folds[0]); + + for (let i = 0; i < folds.length; ++i) { + const fold = folds[i]; + const end = folds[i + 1] || text.length; + if (mode === FOLD_QUOTED && escapedFolds[fold]) res += `${text[fold]}\\`; + res += `\n${indent}${text.slice(fold + 1, end)}`; + } + + return res; +} + +const getFoldOptions = ({ + indentAtStart +}) => indentAtStart ? Object.assign({ + indentAtStart +}, strOptions.fold) : strOptions.fold; // Also checks for lines starting with %, as parsing the output as YAML 1.1 will +// presume that's starting a new document. + + +const containsDocumentMarker = str => /^(%|---|\.\.\.)/m.test(str); + +function lineLengthOverLimit(str, limit) { + const strLen = str.length; + if (strLen <= limit) return false; + + for (let i = 0, start = 0; i < strLen; ++i) { + if (str[i] === '\n') { + if (i - start > limit) return true; + start = i + 1; + if (strLen - start <= limit) return false; + } + } + + return true; +} + +function doubleQuotedString(value, ctx) { + const { + implicitKey + } = ctx; + const { + jsonEncoding, + minMultiLineLength + } = strOptions.doubleQuoted; + const json = JSON.stringify(value); + if (jsonEncoding) return json; + const indent = ctx.indent || (containsDocumentMarker(value) ? ' ' : ''); + let str = ''; + let start = 0; + + for (let i = 0, ch = json[i]; ch; ch = json[++i]) { + if (ch === ' ' && json[i + 1] === '\\' && json[i + 2] === 'n') { + // space before newline needs to be escaped to not be folded + str += json.slice(start, i) + '\\ '; + i += 1; + start = i; + ch = '\\'; + } + + if (ch === '\\') switch (json[i + 1]) { + case 'u': + { + str += json.slice(start, i); + const code = json.substr(i + 2, 4); + + switch (code) { + case '0000': + str += '\\0'; + break; + + case '0007': + str += '\\a'; + break; + + case '000b': + str += '\\v'; + break; + + case '001b': + str += '\\e'; + break; + + case '0085': + str += '\\N'; + break; + + case '00a0': + str += '\\_'; + break; + + case '2028': + str += '\\L'; + break; + + case '2029': + str += '\\P'; + break; + + default: + if (code.substr(0, 2) === '00') str += '\\x' + code.substr(2);else str += json.substr(i, 6); + } + + i += 5; + start = i + 1; + } + break; + + case 'n': + if (implicitKey || json[i + 2] === '"' || json.length < minMultiLineLength) { + i += 1; + } else { + // folding will eat first newline + str += json.slice(start, i) + '\n\n'; + + while (json[i + 2] === '\\' && json[i + 3] === 'n' && json[i + 4] !== '"') { + str += '\n'; + i += 2; + } + + str += indent; // space after newline needs to be escaped to not be folded + + if (json[i + 2] === ' ') str += '\\'; + i += 1; + start = i + 1; + } + + break; + + default: + i += 1; + } + } + + str = start ? str + json.slice(start) : json; + return implicitKey ? str : foldFlowLines(str, indent, FOLD_QUOTED, getFoldOptions(ctx)); +} + +function singleQuotedString(value, ctx) { + if (ctx.implicitKey) { + if (/\n/.test(value)) return doubleQuotedString(value, ctx); + } else { + // single quoted string can't have leading or trailing whitespace around newline + if (/[ \t]\n|\n[ \t]/.test(value)) return doubleQuotedString(value, ctx); + } + + const indent = ctx.indent || (containsDocumentMarker(value) ? ' ' : ''); + const res = "'" + value.replace(/'/g, "''").replace(/\n+/g, `$&\n${indent}`) + "'"; + return ctx.implicitKey ? res : foldFlowLines(res, indent, FOLD_FLOW, getFoldOptions(ctx)); +} + +function blockString({ + comment, + type, + value +}, ctx, onComment, onChompKeep) { + // 1. Block can't end in whitespace unless the last line is non-empty. + // 2. Strings consisting of only whitespace are best rendered explicitly. + if (/\n[\t ]+$/.test(value) || /^\s*$/.test(value)) { + return doubleQuotedString(value, ctx); + } + + const indent = ctx.indent || (ctx.forceBlockIndent || containsDocumentMarker(value) ? ' ' : ''); + const indentSize = indent ? '2' : '1'; // root is at -1 + + const literal = type === PlainValue.Type.BLOCK_FOLDED ? false : type === PlainValue.Type.BLOCK_LITERAL ? true : !lineLengthOverLimit(value, strOptions.fold.lineWidth - indent.length); + let header = literal ? '|' : '>'; + if (!value) return header + '\n'; + let wsStart = ''; + let wsEnd = ''; + value = value.replace(/[\n\t ]*$/, ws => { + const n = ws.indexOf('\n'); + + if (n === -1) { + header += '-'; // strip + } else if (value === ws || n !== ws.length - 1) { + header += '+'; // keep + + if (onChompKeep) onChompKeep(); + } + + wsEnd = ws.replace(/\n$/, ''); + return ''; + }).replace(/^[\n ]*/, ws => { + if (ws.indexOf(' ') !== -1) header += indentSize; + const m = ws.match(/ +$/); + + if (m) { + wsStart = ws.slice(0, -m[0].length); + return m[0]; + } else { + wsStart = ws; + return ''; + } + }); + if (wsEnd) wsEnd = wsEnd.replace(/\n+(?!\n|$)/g, `$&${indent}`); + if (wsStart) wsStart = wsStart.replace(/\n+/g, `$&${indent}`); + + if (comment) { + header += ' #' + comment.replace(/ ?[\r\n]+/g, ' '); + if (onComment) onComment(); + } + + if (!value) return `${header}${indentSize}\n${indent}${wsEnd}`; + + if (literal) { + value = value.replace(/\n+/g, `$&${indent}`); + return `${header}\n${indent}${wsStart}${value}${wsEnd}`; + } + + value = value.replace(/\n+/g, '\n$&').replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, '$1$2') // more-indented lines aren't folded + // ^ ind.line ^ empty ^ capture next empty lines only at end of indent + .replace(/\n+/g, `$&${indent}`); + const body = foldFlowLines(`${wsStart}${value}${wsEnd}`, indent, FOLD_BLOCK, strOptions.fold); + return `${header}\n${indent}${body}`; +} + +function plainString(item, ctx, onComment, onChompKeep) { + const { + comment, + type, + value + } = item; + const { + actualString, + implicitKey, + indent, + inFlow + } = ctx; + + if (implicitKey && /[\n[\]{},]/.test(value) || inFlow && /[[\]{},]/.test(value)) { + return doubleQuotedString(value, ctx); + } + + if (!value || /^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(value)) { + // not allowed: + // - empty string, '-' or '?' + // - start with an indicator character (except [?:-]) or /[?-] / + // - '\n ', ': ' or ' \n' anywhere + // - '#' not preceded by a non-space char + // - end with ' ' or ':' + return implicitKey || inFlow || value.indexOf('\n') === -1 ? value.indexOf('"') !== -1 && value.indexOf("'") === -1 ? singleQuotedString(value, ctx) : doubleQuotedString(value, ctx) : blockString(item, ctx, onComment, onChompKeep); + } + + if (!implicitKey && !inFlow && type !== PlainValue.Type.PLAIN && value.indexOf('\n') !== -1) { + // Where allowed & type not set explicitly, prefer block style for multiline strings + return blockString(item, ctx, onComment, onChompKeep); + } + + if (indent === '' && containsDocumentMarker(value)) { + ctx.forceBlockIndent = true; + return blockString(item, ctx, onComment, onChompKeep); + } + + const str = value.replace(/\n+/g, `$&\n${indent}`); // Verify that output will be parsed as a string, as e.g. plain numbers and + // booleans get parsed with those types in v1.2 (e.g. '42', 'true' & '0.9e-3'), + // and others in v1.1. + + if (actualString) { + const { + tags + } = ctx.doc.schema; + const resolved = resolveScalar(str, tags, tags.scalarFallback).value; + if (typeof resolved !== 'string') return doubleQuotedString(value, ctx); + } + + const body = implicitKey ? str : foldFlowLines(str, indent, FOLD_FLOW, getFoldOptions(ctx)); + + if (comment && !inFlow && (body.indexOf('\n') !== -1 || comment.indexOf('\n') !== -1)) { + if (onComment) onComment(); + return addCommentBefore(body, indent, comment); + } + + return body; +} + +function stringifyString(item, ctx, onComment, onChompKeep) { + const { + defaultType + } = strOptions; + const { + implicitKey, + inFlow + } = ctx; + let { + type, + value + } = item; + + if (typeof value !== 'string') { + value = String(value); + item = Object.assign({}, item, { + value + }); + } + + const _stringify = _type => { + switch (_type) { + case PlainValue.Type.BLOCK_FOLDED: + case PlainValue.Type.BLOCK_LITERAL: + return blockString(item, ctx, onComment, onChompKeep); + + case PlainValue.Type.QUOTE_DOUBLE: + return doubleQuotedString(value, ctx); + + case PlainValue.Type.QUOTE_SINGLE: + return singleQuotedString(value, ctx); + + case PlainValue.Type.PLAIN: + return plainString(item, ctx, onComment, onChompKeep); + + default: + return null; + } + }; + + if (type !== PlainValue.Type.QUOTE_DOUBLE && /[\x00-\x08\x0b-\x1f\x7f-\x9f]/.test(value)) { + // force double quotes on control characters + type = PlainValue.Type.QUOTE_DOUBLE; + } else if ((implicitKey || inFlow) && (type === PlainValue.Type.BLOCK_FOLDED || type === PlainValue.Type.BLOCK_LITERAL)) { + // should not happen; blocks are not valid inside flow containers + type = PlainValue.Type.QUOTE_DOUBLE; + } + + let res = _stringify(type); + + if (res === null) { + res = _stringify(defaultType); + if (res === null) throw new Error(`Unsupported default string type ${defaultType}`); + } + + return res; +} + +function stringifyNumber({ + format, + minFractionDigits, + tag, + value +}) { + if (typeof value === 'bigint') return String(value); + if (!isFinite(value)) return isNaN(value) ? '.nan' : value < 0 ? '-.inf' : '.inf'; + let n = JSON.stringify(value); + + if (!format && minFractionDigits && (!tag || tag === 'tag:yaml.org,2002:float') && /^\d/.test(n)) { + let i = n.indexOf('.'); + + if (i < 0) { + i = n.length; + n += '.'; + } + + let d = minFractionDigits - (n.length - i - 1); + + while (d-- > 0) n += '0'; + } + + return n; +} + +function checkFlowCollectionEnd(errors, cst) { + let char, name; + + switch (cst.type) { + case PlainValue.Type.FLOW_MAP: + char = '}'; + name = 'flow map'; + break; + + case PlainValue.Type.FLOW_SEQ: + char = ']'; + name = 'flow sequence'; + break; + + default: + errors.push(new PlainValue.YAMLSemanticError(cst, 'Not a flow collection!?')); + return; + } + + let lastItem; + + for (let i = cst.items.length - 1; i >= 0; --i) { + const item = cst.items[i]; + + if (!item || item.type !== PlainValue.Type.COMMENT) { + lastItem = item; + break; + } + } + + if (lastItem && lastItem.char !== char) { + const msg = `Expected ${name} to end with ${char}`; + let err; + + if (typeof lastItem.offset === 'number') { + err = new PlainValue.YAMLSemanticError(cst, msg); + err.offset = lastItem.offset + 1; + } else { + err = new PlainValue.YAMLSemanticError(lastItem, msg); + if (lastItem.range && lastItem.range.end) err.offset = lastItem.range.end - lastItem.range.start; + } + + errors.push(err); + } +} +function checkFlowCommentSpace(errors, comment) { + const prev = comment.context.src[comment.range.start - 1]; + + if (prev !== '\n' && prev !== '\t' && prev !== ' ') { + const msg = 'Comments must be separated from other tokens by white space characters'; + errors.push(new PlainValue.YAMLSemanticError(comment, msg)); + } +} +function getLongKeyError(source, key) { + const sk = String(key); + const k = sk.substr(0, 8) + '...' + sk.substr(-8); + return new PlainValue.YAMLSemanticError(source, `The "${k}" key is too long`); +} +function resolveComments(collection, comments) { + for (const { + afterKey, + before, + comment + } of comments) { + let item = collection.items[before]; + + if (!item) { + if (comment !== undefined) { + if (collection.comment) collection.comment += '\n' + comment;else collection.comment = comment; + } + } else { + if (afterKey && item.value) item = item.value; + + if (comment === undefined) { + if (afterKey || !item.commentBefore) item.spaceBefore = true; + } else { + if (item.commentBefore) item.commentBefore += '\n' + comment;else item.commentBefore = comment; + } + } + } +} + +// on error, will return { str: string, errors: Error[] } +function resolveString(doc, node) { + const res = node.strValue; + if (!res) return ''; + if (typeof res === 'string') return res; + res.errors.forEach(error => { + if (!error.source) error.source = node; + doc.errors.push(error); + }); + return res.str; +} + +function resolveTagHandle(doc, node) { + const { + handle, + suffix + } = node.tag; + let prefix = doc.tagPrefixes.find(p => p.handle === handle); + + if (!prefix) { + const dtp = doc.getDefaults().tagPrefixes; + if (dtp) prefix = dtp.find(p => p.handle === handle); + if (!prefix) throw new PlainValue.YAMLSemanticError(node, `The ${handle} tag handle is non-default and was not declared.`); + } + + if (!suffix) throw new PlainValue.YAMLSemanticError(node, `The ${handle} tag has no suffix.`); + + if (handle === '!' && (doc.version || doc.options.version) === '1.0') { + if (suffix[0] === '^') { + doc.warnings.push(new PlainValue.YAMLWarning(node, 'YAML 1.0 ^ tag expansion is not supported')); + return suffix; + } + + if (/[:/]/.test(suffix)) { + // word/foo -> tag:word.yaml.org,2002:foo + const vocab = suffix.match(/^([a-z0-9-]+)\/(.*)/i); + return vocab ? `tag:${vocab[1]}.yaml.org,2002:${vocab[2]}` : `tag:${suffix}`; + } + } + + return prefix.prefix + decodeURIComponent(suffix); +} + +function resolveTagName(doc, node) { + const { + tag, + type + } = node; + let nonSpecific = false; + + if (tag) { + const { + handle, + suffix, + verbatim + } = tag; + + if (verbatim) { + if (verbatim !== '!' && verbatim !== '!!') return verbatim; + const msg = `Verbatim tags aren't resolved, so ${verbatim} is invalid.`; + doc.errors.push(new PlainValue.YAMLSemanticError(node, msg)); + } else if (handle === '!' && !suffix) { + nonSpecific = true; + } else { + try { + return resolveTagHandle(doc, node); + } catch (error) { + doc.errors.push(error); + } + } + } + + switch (type) { + case PlainValue.Type.BLOCK_FOLDED: + case PlainValue.Type.BLOCK_LITERAL: + case PlainValue.Type.QUOTE_DOUBLE: + case PlainValue.Type.QUOTE_SINGLE: + return PlainValue.defaultTags.STR; + + case PlainValue.Type.FLOW_MAP: + case PlainValue.Type.MAP: + return PlainValue.defaultTags.MAP; + + case PlainValue.Type.FLOW_SEQ: + case PlainValue.Type.SEQ: + return PlainValue.defaultTags.SEQ; + + case PlainValue.Type.PLAIN: + return nonSpecific ? PlainValue.defaultTags.STR : null; + + default: + return null; + } +} + +function resolveByTagName(doc, node, tagName) { + const { + tags + } = doc.schema; + const matchWithTest = []; + + for (const tag of tags) { + if (tag.tag === tagName) { + if (tag.test) matchWithTest.push(tag);else { + const res = tag.resolve(doc, node); + return res instanceof Collection ? res : new Scalar(res); + } + } + } + + const str = resolveString(doc, node); + if (typeof str === 'string' && matchWithTest.length > 0) return resolveScalar(str, matchWithTest, tags.scalarFallback); + return null; +} + +function getFallbackTagName({ + type +}) { + switch (type) { + case PlainValue.Type.FLOW_MAP: + case PlainValue.Type.MAP: + return PlainValue.defaultTags.MAP; + + case PlainValue.Type.FLOW_SEQ: + case PlainValue.Type.SEQ: + return PlainValue.defaultTags.SEQ; + + default: + return PlainValue.defaultTags.STR; + } +} + +function resolveTag(doc, node, tagName) { + try { + const res = resolveByTagName(doc, node, tagName); + + if (res) { + if (tagName && node.tag) res.tag = tagName; + return res; + } + } catch (error) { + /* istanbul ignore if */ + if (!error.source) error.source = node; + doc.errors.push(error); + return null; + } + + try { + const fallback = getFallbackTagName(node); + if (!fallback) throw new Error(`The tag ${tagName} is unavailable`); + const msg = `The tag ${tagName} is unavailable, falling back to ${fallback}`; + doc.warnings.push(new PlainValue.YAMLWarning(node, msg)); + const res = resolveByTagName(doc, node, fallback); + res.tag = tagName; + return res; + } catch (error) { + const refError = new PlainValue.YAMLReferenceError(node, error.message); + refError.stack = error.stack; + doc.errors.push(refError); + return null; + } +} + +const isCollectionItem = node => { + if (!node) return false; + const { + type + } = node; + return type === PlainValue.Type.MAP_KEY || type === PlainValue.Type.MAP_VALUE || type === PlainValue.Type.SEQ_ITEM; +}; + +function resolveNodeProps(errors, node) { + const comments = { + before: [], + after: [] + }; + let hasAnchor = false; + let hasTag = false; + const props = isCollectionItem(node.context.parent) ? node.context.parent.props.concat(node.props) : node.props; + + for (const { + start, + end + } of props) { + switch (node.context.src[start]) { + case PlainValue.Char.COMMENT: + { + if (!node.commentHasRequiredWhitespace(start)) { + const msg = 'Comments must be separated from other tokens by white space characters'; + errors.push(new PlainValue.YAMLSemanticError(node, msg)); + } + + const { + header, + valueRange + } = node; + const cc = valueRange && (start > valueRange.start || header && start > header.start) ? comments.after : comments.before; + cc.push(node.context.src.slice(start + 1, end)); + break; + } + // Actual anchor & tag resolution is handled by schema, here we just complain + + case PlainValue.Char.ANCHOR: + if (hasAnchor) { + const msg = 'A node can have at most one anchor'; + errors.push(new PlainValue.YAMLSemanticError(node, msg)); + } + + hasAnchor = true; + break; + + case PlainValue.Char.TAG: + if (hasTag) { + const msg = 'A node can have at most one tag'; + errors.push(new PlainValue.YAMLSemanticError(node, msg)); + } + + hasTag = true; + break; + } + } + + return { + comments, + hasAnchor, + hasTag + }; +} + +function resolveNodeValue(doc, node) { + const { + anchors, + errors, + schema + } = doc; + + if (node.type === PlainValue.Type.ALIAS) { + const name = node.rawValue; + const src = anchors.getNode(name); + + if (!src) { + const msg = `Aliased anchor not found: ${name}`; + errors.push(new PlainValue.YAMLReferenceError(node, msg)); + return null; + } // Lazy resolution for circular references + + + const res = new Alias(src); + + anchors._cstAliases.push(res); + + return res; + } + + const tagName = resolveTagName(doc, node); + if (tagName) return resolveTag(doc, node, tagName); + + if (node.type !== PlainValue.Type.PLAIN) { + const msg = `Failed to resolve ${node.type} node here`; + errors.push(new PlainValue.YAMLSyntaxError(node, msg)); + return null; + } + + try { + const str = resolveString(doc, node); + return resolveScalar(str, schema.tags, schema.tags.scalarFallback); + } catch (error) { + if (!error.source) error.source = node; + errors.push(error); + return null; + } +} // sets node.resolved on success + + +function resolveNode(doc, node) { + if (!node) return null; + if (node.error) doc.errors.push(node.error); + const { + comments, + hasAnchor, + hasTag + } = resolveNodeProps(doc.errors, node); + + if (hasAnchor) { + const { + anchors + } = doc; + const name = node.anchor; + const prev = anchors.getNode(name); // At this point, aliases for any preceding node with the same anchor + // name have already been resolved, so it may safely be renamed. + + if (prev) anchors.map[anchors.newName(name)] = prev; // During parsing, we need to store the CST node in anchors.map as + // anchors need to be available during resolution to allow for + // circular references. + + anchors.map[name] = node; + } + + if (node.type === PlainValue.Type.ALIAS && (hasAnchor || hasTag)) { + const msg = 'An alias node must not specify any properties'; + doc.errors.push(new PlainValue.YAMLSemanticError(node, msg)); + } + + const res = resolveNodeValue(doc, node); + + if (res) { + res.range = [node.range.start, node.range.end]; + if (doc.options.keepCstNodes) res.cstNode = node; + if (doc.options.keepNodeTypes) res.type = node.type; + const cb = comments.before.join('\n'); + + if (cb) { + res.commentBefore = res.commentBefore ? `${res.commentBefore}\n${cb}` : cb; + } + + const ca = comments.after.join('\n'); + if (ca) res.comment = res.comment ? `${res.comment}\n${ca}` : ca; + } + + return node.resolved = res; +} + +function resolveMap(doc, cst) { + if (cst.type !== PlainValue.Type.MAP && cst.type !== PlainValue.Type.FLOW_MAP) { + const msg = `A ${cst.type} node cannot be resolved as a mapping`; + doc.errors.push(new PlainValue.YAMLSyntaxError(cst, msg)); + return null; + } + + const { + comments, + items + } = cst.type === PlainValue.Type.FLOW_MAP ? resolveFlowMapItems(doc, cst) : resolveBlockMapItems(doc, cst); + const map = new YAMLMap(); + map.items = items; + resolveComments(map, comments); + let hasCollectionKey = false; + + for (let i = 0; i < items.length; ++i) { + const { + key: iKey + } = items[i]; + if (iKey instanceof Collection) hasCollectionKey = true; + + if (doc.schema.merge && iKey && iKey.value === MERGE_KEY) { + items[i] = new Merge(items[i]); + const sources = items[i].value.items; + let error = null; + sources.some(node => { + if (node instanceof Alias) { + // During parsing, alias sources are CST nodes; to account for + // circular references their resolved values can't be used here. + const { + type + } = node.source; + if (type === PlainValue.Type.MAP || type === PlainValue.Type.FLOW_MAP) return false; + return error = 'Merge nodes aliases can only point to maps'; + } + + return error = 'Merge nodes can only have Alias nodes as values'; + }); + if (error) doc.errors.push(new PlainValue.YAMLSemanticError(cst, error)); + } else { + for (let j = i + 1; j < items.length; ++j) { + const { + key: jKey + } = items[j]; + + if (iKey === jKey || iKey && jKey && Object.prototype.hasOwnProperty.call(iKey, 'value') && iKey.value === jKey.value) { + const msg = `Map keys must be unique; "${iKey}" is repeated`; + doc.errors.push(new PlainValue.YAMLSemanticError(cst, msg)); + break; + } + } + } + } + + if (hasCollectionKey && !doc.options.mapAsMap) { + const warn = 'Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.'; + doc.warnings.push(new PlainValue.YAMLWarning(cst, warn)); + } + + cst.resolved = map; + return map; +} + +const valueHasPairComment = ({ + context: { + lineStart, + node, + src + }, + props +}) => { + if (props.length === 0) return false; + const { + start + } = props[0]; + if (node && start > node.valueRange.start) return false; + if (src[start] !== PlainValue.Char.COMMENT) return false; + + for (let i = lineStart; i < start; ++i) if (src[i] === '\n') return false; + + return true; +}; + +function resolvePairComment(item, pair) { + if (!valueHasPairComment(item)) return; + const comment = item.getPropValue(0, PlainValue.Char.COMMENT, true); + let found = false; + const cb = pair.value.commentBefore; + + if (cb && cb.startsWith(comment)) { + pair.value.commentBefore = cb.substr(comment.length + 1); + found = true; + } else { + const cc = pair.value.comment; + + if (!item.node && cc && cc.startsWith(comment)) { + pair.value.comment = cc.substr(comment.length + 1); + found = true; + } + } + + if (found) pair.comment = comment; +} + +function resolveBlockMapItems(doc, cst) { + const comments = []; + const items = []; + let key = undefined; + let keyStart = null; + + for (let i = 0; i < cst.items.length; ++i) { + const item = cst.items[i]; + + switch (item.type) { + case PlainValue.Type.BLANK_LINE: + comments.push({ + afterKey: !!key, + before: items.length + }); + break; + + case PlainValue.Type.COMMENT: + comments.push({ + afterKey: !!key, + before: items.length, + comment: item.comment + }); + break; + + case PlainValue.Type.MAP_KEY: + if (key !== undefined) items.push(new Pair(key)); + if (item.error) doc.errors.push(item.error); + key = resolveNode(doc, item.node); + keyStart = null; + break; + + case PlainValue.Type.MAP_VALUE: + { + if (key === undefined) key = null; + if (item.error) doc.errors.push(item.error); + + if (!item.context.atLineStart && item.node && item.node.type === PlainValue.Type.MAP && !item.node.context.atLineStart) { + const msg = 'Nested mappings are not allowed in compact mappings'; + doc.errors.push(new PlainValue.YAMLSemanticError(item.node, msg)); + } + + let valueNode = item.node; + + if (!valueNode && item.props.length > 0) { + // Comments on an empty mapping value need to be preserved, so we + // need to construct a minimal empty node here to use instead of the + // missing `item.node`. -- eemeli/yaml#19 + valueNode = new PlainValue.PlainValue(PlainValue.Type.PLAIN, []); + valueNode.context = { + parent: item, + src: item.context.src + }; + const pos = item.range.start + 1; + valueNode.range = { + start: pos, + end: pos + }; + valueNode.valueRange = { + start: pos, + end: pos + }; + + if (typeof item.range.origStart === 'number') { + const origPos = item.range.origStart + 1; + valueNode.range.origStart = valueNode.range.origEnd = origPos; + valueNode.valueRange.origStart = valueNode.valueRange.origEnd = origPos; + } + } + + const pair = new Pair(key, resolveNode(doc, valueNode)); + resolvePairComment(item, pair); + items.push(pair); + + if (key && typeof keyStart === 'number') { + if (item.range.start > keyStart + 1024) doc.errors.push(getLongKeyError(cst, key)); + } + + key = undefined; + keyStart = null; + } + break; + + default: + if (key !== undefined) items.push(new Pair(key)); + key = resolveNode(doc, item); + keyStart = item.range.start; + if (item.error) doc.errors.push(item.error); + + next: for (let j = i + 1;; ++j) { + const nextItem = cst.items[j]; + + switch (nextItem && nextItem.type) { + case PlainValue.Type.BLANK_LINE: + case PlainValue.Type.COMMENT: + continue next; + + case PlainValue.Type.MAP_VALUE: + break next; + + default: + { + const msg = 'Implicit map keys need to be followed by map values'; + doc.errors.push(new PlainValue.YAMLSemanticError(item, msg)); + break next; + } + } + } + + if (item.valueRangeContainsNewline) { + const msg = 'Implicit map keys need to be on a single line'; + doc.errors.push(new PlainValue.YAMLSemanticError(item, msg)); + } + + } + } + + if (key !== undefined) items.push(new Pair(key)); + return { + comments, + items + }; +} + +function resolveFlowMapItems(doc, cst) { + const comments = []; + const items = []; + let key = undefined; + let explicitKey = false; + let next = '{'; + + for (let i = 0; i < cst.items.length; ++i) { + const item = cst.items[i]; + + if (typeof item.char === 'string') { + const { + char, + offset + } = item; + + if (char === '?' && key === undefined && !explicitKey) { + explicitKey = true; + next = ':'; + continue; + } + + if (char === ':') { + if (key === undefined) key = null; + + if (next === ':') { + next = ','; + continue; + } + } else { + if (explicitKey) { + if (key === undefined && char !== ',') key = null; + explicitKey = false; + } + + if (key !== undefined) { + items.push(new Pair(key)); + key = undefined; + + if (char === ',') { + next = ':'; + continue; + } + } + } + + if (char === '}') { + if (i === cst.items.length - 1) continue; + } else if (char === next) { + next = ':'; + continue; + } + + const msg = `Flow map contains an unexpected ${char}`; + const err = new PlainValue.YAMLSyntaxError(cst, msg); + err.offset = offset; + doc.errors.push(err); + } else if (item.type === PlainValue.Type.BLANK_LINE) { + comments.push({ + afterKey: !!key, + before: items.length + }); + } else if (item.type === PlainValue.Type.COMMENT) { + checkFlowCommentSpace(doc.errors, item); + comments.push({ + afterKey: !!key, + before: items.length, + comment: item.comment + }); + } else if (key === undefined) { + if (next === ',') doc.errors.push(new PlainValue.YAMLSemanticError(item, 'Separator , missing in flow map')); + key = resolveNode(doc, item); + } else { + if (next !== ',') doc.errors.push(new PlainValue.YAMLSemanticError(item, 'Indicator : missing in flow map entry')); + items.push(new Pair(key, resolveNode(doc, item))); + key = undefined; + explicitKey = false; + } + } + + checkFlowCollectionEnd(doc.errors, cst); + if (key !== undefined) items.push(new Pair(key)); + return { + comments, + items + }; +} + +function resolveSeq(doc, cst) { + if (cst.type !== PlainValue.Type.SEQ && cst.type !== PlainValue.Type.FLOW_SEQ) { + const msg = `A ${cst.type} node cannot be resolved as a sequence`; + doc.errors.push(new PlainValue.YAMLSyntaxError(cst, msg)); + return null; + } + + const { + comments, + items + } = cst.type === PlainValue.Type.FLOW_SEQ ? resolveFlowSeqItems(doc, cst) : resolveBlockSeqItems(doc, cst); + const seq = new YAMLSeq(); + seq.items = items; + resolveComments(seq, comments); + + if (!doc.options.mapAsMap && items.some(it => it instanceof Pair && it.key instanceof Collection)) { + const warn = 'Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.'; + doc.warnings.push(new PlainValue.YAMLWarning(cst, warn)); + } + + cst.resolved = seq; + return seq; +} + +function resolveBlockSeqItems(doc, cst) { + const comments = []; + const items = []; + + for (let i = 0; i < cst.items.length; ++i) { + const item = cst.items[i]; + + switch (item.type) { + case PlainValue.Type.BLANK_LINE: + comments.push({ + before: items.length + }); + break; + + case PlainValue.Type.COMMENT: + comments.push({ + comment: item.comment, + before: items.length + }); + break; + + case PlainValue.Type.SEQ_ITEM: + if (item.error) doc.errors.push(item.error); + items.push(resolveNode(doc, item.node)); + + if (item.hasProps) { + const msg = 'Sequence items cannot have tags or anchors before the - indicator'; + doc.errors.push(new PlainValue.YAMLSemanticError(item, msg)); + } + + break; + + default: + if (item.error) doc.errors.push(item.error); + doc.errors.push(new PlainValue.YAMLSyntaxError(item, `Unexpected ${item.type} node in sequence`)); + } + } + + return { + comments, + items + }; +} + +function resolveFlowSeqItems(doc, cst) { + const comments = []; + const items = []; + let explicitKey = false; + let key = undefined; + let keyStart = null; + let next = '['; + let prevItem = null; + + for (let i = 0; i < cst.items.length; ++i) { + const item = cst.items[i]; + + if (typeof item.char === 'string') { + const { + char, + offset + } = item; + + if (char !== ':' && (explicitKey || key !== undefined)) { + if (explicitKey && key === undefined) key = next ? items.pop() : null; + items.push(new Pair(key)); + explicitKey = false; + key = undefined; + keyStart = null; + } + + if (char === next) { + next = null; + } else if (!next && char === '?') { + explicitKey = true; + } else if (next !== '[' && char === ':' && key === undefined) { + if (next === ',') { + key = items.pop(); + + if (key instanceof Pair) { + const msg = 'Chaining flow sequence pairs is invalid'; + const err = new PlainValue.YAMLSemanticError(cst, msg); + err.offset = offset; + doc.errors.push(err); + } + + if (!explicitKey && typeof keyStart === 'number') { + const keyEnd = item.range ? item.range.start : item.offset; + if (keyEnd > keyStart + 1024) doc.errors.push(getLongKeyError(cst, key)); + const { + src + } = prevItem.context; + + for (let i = keyStart; i < keyEnd; ++i) if (src[i] === '\n') { + const msg = 'Implicit keys of flow sequence pairs need to be on a single line'; + doc.errors.push(new PlainValue.YAMLSemanticError(prevItem, msg)); + break; + } + } + } else { + key = null; + } + + keyStart = null; + explicitKey = false; + next = null; + } else if (next === '[' || char !== ']' || i < cst.items.length - 1) { + const msg = `Flow sequence contains an unexpected ${char}`; + const err = new PlainValue.YAMLSyntaxError(cst, msg); + err.offset = offset; + doc.errors.push(err); + } + } else if (item.type === PlainValue.Type.BLANK_LINE) { + comments.push({ + before: items.length + }); + } else if (item.type === PlainValue.Type.COMMENT) { + checkFlowCommentSpace(doc.errors, item); + comments.push({ + comment: item.comment, + before: items.length + }); + } else { + if (next) { + const msg = `Expected a ${next} in flow sequence`; + doc.errors.push(new PlainValue.YAMLSemanticError(item, msg)); + } + + const value = resolveNode(doc, item); + + if (key === undefined) { + items.push(value); + prevItem = item; + } else { + items.push(new Pair(key, value)); + key = undefined; + } + + keyStart = item.range.start; + next = ','; + } + } + + checkFlowCollectionEnd(doc.errors, cst); + if (key !== undefined) items.push(new Pair(key)); + return { + comments, + items + }; +} + +exports.Alias = Alias; +exports.Collection = Collection; +exports.Merge = Merge; +exports.Node = Node; +exports.Pair = Pair; +exports.Scalar = Scalar; +exports.YAMLMap = YAMLMap; +exports.YAMLSeq = YAMLSeq; +exports.addComment = addComment; +exports.binaryOptions = binaryOptions; +exports.boolOptions = boolOptions; +exports.findPair = findPair; +exports.intOptions = intOptions; +exports.isEmptyPath = isEmptyPath; +exports.nullOptions = nullOptions; +exports.resolveMap = resolveMap; +exports.resolveNode = resolveNode; +exports.resolveSeq = resolveSeq; +exports.resolveString = resolveString; +exports.strOptions = strOptions; +exports.stringifyNumber = stringifyNumber; +exports.stringifyString = stringifyString; +exports.toJSON = toJSON; diff --git a/node_modules/yaml/dist/test-events.js b/node_modules/yaml/dist/test-events.js new file mode 100644 index 0000000..1337ace --- /dev/null +++ b/node_modules/yaml/dist/test-events.js @@ -0,0 +1,162 @@ +'use strict'; + +require('./PlainValue-ec8e588e.js'); +var parseCst = require('./parse-cst.js'); +require('./resolveSeq-4a68b39b.js'); +var Document$1 = require('./Document-2cf6b08c.js'); +require('./Schema-42e9705c.js'); +require('./warnings-39684f17.js'); + +function testEvents(src, options) { + const opt = Object.assign({ + keepCstNodes: true, + keepNodeTypes: true, + version: '1.2' + }, options); + const docs = parseCst.parse(src).map(cstDoc => new Document$1.Document(opt).parse(cstDoc)); + const errDoc = docs.find(doc => doc.errors.length > 0); + const error = errDoc ? errDoc.errors[0].message : null; + const events = ['+STR']; + + try { + for (let i = 0; i < docs.length; ++i) { + const doc = docs[i]; + let root = doc.contents; + if (Array.isArray(root)) root = root[0]; + const [rootStart, rootEnd] = doc.range || [0, 0]; + let e = doc.errors[0] && doc.errors[0].source; + if (e && e.type === 'SEQ_ITEM') e = e.node; + if (e && (e.type === 'DOCUMENT' || e.range.start < rootStart)) throw new Error(); + let docStart = '+DOC'; + const pre = src.slice(0, rootStart); + const explicitDoc = /---\s*$/.test(pre); + if (explicitDoc) docStart += ' ---';else if (!doc.contents) continue; + events.push(docStart); + addEvents(events, doc, e, root); + if (doc.contents && doc.contents.length > 1) throw new Error(); + let docEnd = '-DOC'; + + if (rootEnd) { + const post = src.slice(rootEnd); + if (/^\.\.\./.test(post)) docEnd += ' ...'; + } + + events.push(docEnd); + } + } catch (e) { + return { + events, + error: error || e + }; + } + + events.push('-STR'); + return { + events, + error + }; +} + +function addEvents(events, doc, e, node) { + if (!node) { + events.push('=VAL :'); + return; + } + + if (e && node.cstNode === e) throw new Error(); + let props = ''; + let anchor = doc.anchors.getName(node); + + if (anchor) { + if (/\d$/.test(anchor)) { + const alt = anchor.replace(/\d$/, ''); + if (doc.anchors.getNode(alt)) anchor = alt; + } + + props = ` &${anchor}`; + } + + if (node.cstNode && node.cstNode.tag) { + const { + handle, + suffix + } = node.cstNode.tag; + props += handle === '!' && !suffix ? ' ' : ` <${node.tag}>`; + } + + let scalar = null; + + switch (node.type) { + case 'ALIAS': + { + let alias = doc.anchors.getName(node.source); + + if (/\d$/.test(alias)) { + const alt = alias.replace(/\d$/, ''); + if (doc.anchors.getNode(alt)) alias = alt; + } + + events.push(`=ALI${props} *${alias}`); + } + break; + + case 'BLOCK_FOLDED': + scalar = '>'; + break; + + case 'BLOCK_LITERAL': + scalar = '|'; + break; + + case 'PLAIN': + scalar = ':'; + break; + + case 'QUOTE_DOUBLE': + scalar = '"'; + break; + + case 'QUOTE_SINGLE': + scalar = "'"; + break; + + case 'PAIR': + events.push(`+MAP${props}`); + addEvents(events, doc, e, node.key); + addEvents(events, doc, e, node.value); + events.push('-MAP'); + break; + + case 'FLOW_SEQ': + case 'SEQ': + events.push(`+SEQ${props}`); + node.items.forEach(item => { + addEvents(events, doc, e, item); + }); + events.push('-SEQ'); + break; + + case 'FLOW_MAP': + case 'MAP': + events.push(`+MAP${props}`); + node.items.forEach(({ + key, + value + }) => { + addEvents(events, doc, e, key); + addEvents(events, doc, e, value); + }); + events.push('-MAP'); + break; + + default: + throw new Error(`Unexpected node type ${node.type}`); + } + + if (scalar) { + const value = node.cstNode.strValue.replace(/\\/g, '\\\\').replace(/\0/g, '\\0').replace(/\x07/g, '\\a').replace(/\x08/g, '\\b').replace(/\t/g, '\\t').replace(/\n/g, '\\n').replace(/\v/g, '\\v').replace(/\f/g, '\\f').replace(/\r/g, '\\r').replace(/\x1b/g, '\\e'); + events.push(`=VAL${props} ${scalar}${value}`); + } +} + +exports.testEvents = testEvents; diff --git a/node_modules/yaml/dist/types.js b/node_modules/yaml/dist/types.js new file mode 100644 index 0000000..515f0b6 --- /dev/null +++ b/node_modules/yaml/dist/types.js @@ -0,0 +1,23 @@ +'use strict'; + +require('./PlainValue-ec8e588e.js'); +var resolveSeq = require('./resolveSeq-4a68b39b.js'); +var Schema = require('./Schema-42e9705c.js'); +require('./warnings-39684f17.js'); + + + +exports.Alias = resolveSeq.Alias; +exports.Collection = resolveSeq.Collection; +exports.Merge = resolveSeq.Merge; +exports.Node = resolveSeq.Node; +exports.Pair = resolveSeq.Pair; +exports.Scalar = resolveSeq.Scalar; +exports.YAMLMap = resolveSeq.YAMLMap; +exports.YAMLSeq = resolveSeq.YAMLSeq; +exports.binaryOptions = resolveSeq.binaryOptions; +exports.boolOptions = resolveSeq.boolOptions; +exports.intOptions = resolveSeq.intOptions; +exports.nullOptions = resolveSeq.nullOptions; +exports.strOptions = resolveSeq.strOptions; +exports.Schema = Schema.Schema; diff --git a/node_modules/yaml/dist/util.js b/node_modules/yaml/dist/util.js new file mode 100644 index 0000000..3fc35d1 --- /dev/null +++ b/node_modules/yaml/dist/util.js @@ -0,0 +1,19 @@ +'use strict'; + +var PlainValue = require('./PlainValue-ec8e588e.js'); +var resolveSeq = require('./resolveSeq-4a68b39b.js'); + + + +exports.Type = PlainValue.Type; +exports.YAMLError = PlainValue.YAMLError; +exports.YAMLReferenceError = PlainValue.YAMLReferenceError; +exports.YAMLSemanticError = PlainValue.YAMLSemanticError; +exports.YAMLSyntaxError = PlainValue.YAMLSyntaxError; +exports.YAMLWarning = PlainValue.YAMLWarning; +exports.findPair = resolveSeq.findPair; +exports.parseMap = resolveSeq.resolveMap; +exports.parseSeq = resolveSeq.resolveSeq; +exports.stringifyNumber = resolveSeq.stringifyNumber; +exports.stringifyString = resolveSeq.stringifyString; +exports.toJSON = resolveSeq.toJSON; diff --git a/node_modules/yaml/dist/warnings-39684f17.js b/node_modules/yaml/dist/warnings-39684f17.js new file mode 100644 index 0000000..edc1940 --- /dev/null +++ b/node_modules/yaml/dist/warnings-39684f17.js @@ -0,0 +1,416 @@ +'use strict'; + +var PlainValue = require('./PlainValue-ec8e588e.js'); +var resolveSeq = require('./resolveSeq-4a68b39b.js'); + +/* global atob, btoa, Buffer */ +const binary = { + identify: value => value instanceof Uint8Array, + // Buffer inherits from Uint8Array + default: false, + tag: 'tag:yaml.org,2002:binary', + + /** + * Returns a Buffer in node and an Uint8Array in browsers + * + * To use the resulting buffer as an image, you'll want to do something like: + * + * const blob = new Blob([buffer], { type: 'image/jpeg' }) + * document.querySelector('#photo').src = URL.createObjectURL(blob) + */ + resolve: (doc, node) => { + const src = resolveSeq.resolveString(doc, node); + + if (typeof Buffer === 'function') { + return Buffer.from(src, 'base64'); + } else if (typeof atob === 'function') { + // On IE 11, atob() can't handle newlines + const str = atob(src.replace(/[\n\r]/g, '')); + const buffer = new Uint8Array(str.length); + + for (let i = 0; i < str.length; ++i) buffer[i] = str.charCodeAt(i); + + return buffer; + } else { + const msg = 'This environment does not support reading binary tags; either Buffer or atob is required'; + doc.errors.push(new PlainValue.YAMLReferenceError(node, msg)); + return null; + } + }, + options: resolveSeq.binaryOptions, + stringify: ({ + comment, + type, + value + }, ctx, onComment, onChompKeep) => { + let src; + + if (typeof Buffer === 'function') { + src = value instanceof Buffer ? value.toString('base64') : Buffer.from(value.buffer).toString('base64'); + } else if (typeof btoa === 'function') { + let s = ''; + + for (let i = 0; i < value.length; ++i) s += String.fromCharCode(value[i]); + + src = btoa(s); + } else { + throw new Error('This environment does not support writing binary tags; either Buffer or btoa is required'); + } + + if (!type) type = resolveSeq.binaryOptions.defaultType; + + if (type === PlainValue.Type.QUOTE_DOUBLE) { + value = src; + } else { + const { + lineWidth + } = resolveSeq.binaryOptions; + const n = Math.ceil(src.length / lineWidth); + const lines = new Array(n); + + for (let i = 0, o = 0; i < n; ++i, o += lineWidth) { + lines[i] = src.substr(o, lineWidth); + } + + value = lines.join(type === PlainValue.Type.BLOCK_LITERAL ? '\n' : ' '); + } + + return resolveSeq.stringifyString({ + comment, + type, + value + }, ctx, onComment, onChompKeep); + } +}; + +function parsePairs(doc, cst) { + const seq = resolveSeq.resolveSeq(doc, cst); + + for (let i = 0; i < seq.items.length; ++i) { + let item = seq.items[i]; + if (item instanceof resolveSeq.Pair) continue;else if (item instanceof resolveSeq.YAMLMap) { + if (item.items.length > 1) { + const msg = 'Each pair must have its own sequence indicator'; + throw new PlainValue.YAMLSemanticError(cst, msg); + } + + const pair = item.items[0] || new resolveSeq.Pair(); + if (item.commentBefore) pair.commentBefore = pair.commentBefore ? `${item.commentBefore}\n${pair.commentBefore}` : item.commentBefore; + if (item.comment) pair.comment = pair.comment ? `${item.comment}\n${pair.comment}` : item.comment; + item = pair; + } + seq.items[i] = item instanceof resolveSeq.Pair ? item : new resolveSeq.Pair(item); + } + + return seq; +} +function createPairs(schema, iterable, ctx) { + const pairs = new resolveSeq.YAMLSeq(schema); + pairs.tag = 'tag:yaml.org,2002:pairs'; + + for (const it of iterable) { + let key, value; + + if (Array.isArray(it)) { + if (it.length === 2) { + key = it[0]; + value = it[1]; + } else throw new TypeError(`Expected [key, value] tuple: ${it}`); + } else if (it && it instanceof Object) { + const keys = Object.keys(it); + + if (keys.length === 1) { + key = keys[0]; + value = it[key]; + } else throw new TypeError(`Expected { key: value } tuple: ${it}`); + } else { + key = it; + } + + const pair = schema.createPair(key, value, ctx); + pairs.items.push(pair); + } + + return pairs; +} +const pairs = { + default: false, + tag: 'tag:yaml.org,2002:pairs', + resolve: parsePairs, + createNode: createPairs +}; + +class YAMLOMap extends resolveSeq.YAMLSeq { + constructor() { + super(); + + PlainValue._defineProperty(this, "add", resolveSeq.YAMLMap.prototype.add.bind(this)); + + PlainValue._defineProperty(this, "delete", resolveSeq.YAMLMap.prototype.delete.bind(this)); + + PlainValue._defineProperty(this, "get", resolveSeq.YAMLMap.prototype.get.bind(this)); + + PlainValue._defineProperty(this, "has", resolveSeq.YAMLMap.prototype.has.bind(this)); + + PlainValue._defineProperty(this, "set", resolveSeq.YAMLMap.prototype.set.bind(this)); + + this.tag = YAMLOMap.tag; + } + + toJSON(_, ctx) { + const map = new Map(); + if (ctx && ctx.onCreate) ctx.onCreate(map); + + for (const pair of this.items) { + let key, value; + + if (pair instanceof resolveSeq.Pair) { + key = resolveSeq.toJSON(pair.key, '', ctx); + value = resolveSeq.toJSON(pair.value, key, ctx); + } else { + key = resolveSeq.toJSON(pair, '', ctx); + } + + if (map.has(key)) throw new Error('Ordered maps must not include duplicate keys'); + map.set(key, value); + } + + return map; + } + +} + +PlainValue._defineProperty(YAMLOMap, "tag", 'tag:yaml.org,2002:omap'); + +function parseOMap(doc, cst) { + const pairs = parsePairs(doc, cst); + const seenKeys = []; + + for (const { + key + } of pairs.items) { + if (key instanceof resolveSeq.Scalar) { + if (seenKeys.includes(key.value)) { + const msg = 'Ordered maps must not include duplicate keys'; + throw new PlainValue.YAMLSemanticError(cst, msg); + } else { + seenKeys.push(key.value); + } + } + } + + return Object.assign(new YAMLOMap(), pairs); +} + +function createOMap(schema, iterable, ctx) { + const pairs = createPairs(schema, iterable, ctx); + const omap = new YAMLOMap(); + omap.items = pairs.items; + return omap; +} + +const omap = { + identify: value => value instanceof Map, + nodeClass: YAMLOMap, + default: false, + tag: 'tag:yaml.org,2002:omap', + resolve: parseOMap, + createNode: createOMap +}; + +class YAMLSet extends resolveSeq.YAMLMap { + constructor() { + super(); + this.tag = YAMLSet.tag; + } + + add(key) { + const pair = key instanceof resolveSeq.Pair ? key : new resolveSeq.Pair(key); + const prev = resolveSeq.findPair(this.items, pair.key); + if (!prev) this.items.push(pair); + } + + get(key, keepPair) { + const pair = resolveSeq.findPair(this.items, key); + return !keepPair && pair instanceof resolveSeq.Pair ? pair.key instanceof resolveSeq.Scalar ? pair.key.value : pair.key : pair; + } + + set(key, value) { + if (typeof value !== 'boolean') throw new Error(`Expected boolean value for set(key, value) in a YAML set, not ${typeof value}`); + const prev = resolveSeq.findPair(this.items, key); + + if (prev && !value) { + this.items.splice(this.items.indexOf(prev), 1); + } else if (!prev && value) { + this.items.push(new resolveSeq.Pair(key)); + } + } + + toJSON(_, ctx) { + return super.toJSON(_, ctx, Set); + } + + toString(ctx, onComment, onChompKeep) { + if (!ctx) return JSON.stringify(this); + if (this.hasAllNullValues()) return super.toString(ctx, onComment, onChompKeep);else throw new Error('Set items must all have null values'); + } + +} + +PlainValue._defineProperty(YAMLSet, "tag", 'tag:yaml.org,2002:set'); + +function parseSet(doc, cst) { + const map = resolveSeq.resolveMap(doc, cst); + if (!map.hasAllNullValues()) throw new PlainValue.YAMLSemanticError(cst, 'Set items must all have null values'); + return Object.assign(new YAMLSet(), map); +} + +function createSet(schema, iterable, ctx) { + const set = new YAMLSet(); + + for (const value of iterable) set.items.push(schema.createPair(value, null, ctx)); + + return set; +} + +const set = { + identify: value => value instanceof Set, + nodeClass: YAMLSet, + default: false, + tag: 'tag:yaml.org,2002:set', + resolve: parseSet, + createNode: createSet +}; + +const parseSexagesimal = (sign, parts) => { + const n = parts.split(':').reduce((n, p) => n * 60 + Number(p), 0); + return sign === '-' ? -n : n; +}; // hhhh:mm:ss.sss + + +const stringifySexagesimal = ({ + value +}) => { + if (isNaN(value) || !isFinite(value)) return resolveSeq.stringifyNumber(value); + let sign = ''; + + if (value < 0) { + sign = '-'; + value = Math.abs(value); + } + + const parts = [value % 60]; // seconds, including ms + + if (value < 60) { + parts.unshift(0); // at least one : is required + } else { + value = Math.round((value - parts[0]) / 60); + parts.unshift(value % 60); // minutes + + if (value >= 60) { + value = Math.round((value - parts[0]) / 60); + parts.unshift(value); // hours + } + } + + return sign + parts.map(n => n < 10 ? '0' + String(n) : String(n)).join(':').replace(/000000\d*$/, '') // % 60 may introduce error + ; +}; + +const intTime = { + identify: value => typeof value === 'number', + default: true, + tag: 'tag:yaml.org,2002:int', + format: 'TIME', + test: /^([-+]?)([0-9][0-9_]*(?::[0-5]?[0-9])+)$/, + resolve: (str, sign, parts) => parseSexagesimal(sign, parts.replace(/_/g, '')), + stringify: stringifySexagesimal +}; +const floatTime = { + identify: value => typeof value === 'number', + default: true, + tag: 'tag:yaml.org,2002:float', + format: 'TIME', + test: /^([-+]?)([0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*)$/, + resolve: (str, sign, parts) => parseSexagesimal(sign, parts.replace(/_/g, '')), + stringify: stringifySexagesimal +}; +const timestamp = { + identify: value => value instanceof Date, + default: true, + tag: 'tag:yaml.org,2002:timestamp', + // If the time zone is omitted, the timestamp is assumed to be specified in UTC. The time part + // may be omitted altogether, resulting in a date format. In such a case, the time part is + // assumed to be 00:00:00Z (start of day, UTC). + test: RegExp('^(?:' + '([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})' + // YYYY-Mm-Dd + '(?:(?:t|T|[ \\t]+)' + // t | T | whitespace + '([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)' + // Hh:Mm:Ss(.ss)? + '(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?' + // Z | +5 | -03:30 + ')?' + ')$'), + resolve: (str, year, month, day, hour, minute, second, millisec, tz) => { + if (millisec) millisec = (millisec + '00').substr(1, 3); + let date = Date.UTC(year, month - 1, day, hour || 0, minute || 0, second || 0, millisec || 0); + + if (tz && tz !== 'Z') { + let d = parseSexagesimal(tz[0], tz.slice(1)); + if (Math.abs(d) < 30) d *= 60; + date -= 60000 * d; + } + + return new Date(date); + }, + stringify: ({ + value + }) => value.toISOString().replace(/((T00:00)?:00)?\.000Z$/, '') +}; + +/* global console, process, YAML_SILENCE_DEPRECATION_WARNINGS, YAML_SILENCE_WARNINGS */ +function shouldWarn(deprecation) { + const env = typeof process !== 'undefined' && process.env || {}; + + if (deprecation) { + if (typeof YAML_SILENCE_DEPRECATION_WARNINGS !== 'undefined') return !YAML_SILENCE_DEPRECATION_WARNINGS; + return !env.YAML_SILENCE_DEPRECATION_WARNINGS; + } + + if (typeof YAML_SILENCE_WARNINGS !== 'undefined') return !YAML_SILENCE_WARNINGS; + return !env.YAML_SILENCE_WARNINGS; +} + +function warn(warning, type) { + if (shouldWarn(false)) { + const emit = typeof process !== 'undefined' && process.emitWarning; // This will throw in Jest if `warning` is an Error instance due to + // https://github.com/facebook/jest/issues/2549 + + if (emit) emit(warning, type);else { + // eslint-disable-next-line no-console + console.warn(type ? `${type}: ${warning}` : warning); + } + } +} +function warnFileDeprecation(filename) { + if (shouldWarn(true)) { + const path = filename.replace(/.*yaml[/\\]/i, '').replace(/\.js$/, '').replace(/\\/g, '/'); + warn(`The endpoint 'yaml/${path}' will be removed in a future release.`, 'DeprecationWarning'); + } +} +const warned = {}; +function warnOptionDeprecation(name, alternative) { + if (!warned[name] && shouldWarn(true)) { + warned[name] = true; + let msg = `The option '${name}' will be removed in a future release`; + msg += alternative ? `, use '${alternative}' instead.` : '.'; + warn(msg, 'DeprecationWarning'); + } +} + +exports.binary = binary; +exports.floatTime = floatTime; +exports.intTime = intTime; +exports.omap = omap; +exports.pairs = pairs; +exports.set = set; +exports.timestamp = timestamp; +exports.warn = warn; +exports.warnFileDeprecation = warnFileDeprecation; +exports.warnOptionDeprecation = warnOptionDeprecation; diff --git a/node_modules/yaml/index.d.ts b/node_modules/yaml/index.d.ts new file mode 100644 index 0000000..36aa3c6 --- /dev/null +++ b/node_modules/yaml/index.d.ts @@ -0,0 +1,372 @@ +import { CST } from './parse-cst' +import { + AST, + Alias, + Collection, + Merge, + Node, + Scalar, + Schema, + YAMLMap, + YAMLSeq +} from './types' +import { Type, YAMLError, YAMLWarning } from './util' + +export { AST, CST } +export { default as parseCST } from './parse-cst' + +/** + * `yaml` defines document-specific options in three places: as an argument of + * parse, create and stringify calls, in the values of `YAML.defaultOptions`, + * and in the version-dependent `YAML.Document.defaults` object. Values set in + * `YAML.defaultOptions` override version-dependent defaults, and argument + * options override both. + */ +export const defaultOptions: Options + +export interface Options extends Schema.Options { + /** + * Default prefix for anchors. + * + * Default: `'a'`, resulting in anchors `a1`, `a2`, etc. + */ + anchorPrefix?: string + /** + * The number of spaces to use when indenting code. + * + * Default: `2` + */ + indent?: number + /** + * Whether block sequences should be indented. + * + * Default: `true` + */ + indentSeq?: boolean + /** + * Allow non-JSON JavaScript objects to remain in the `toJSON` output. + * Relevant with the YAML 1.1 `!!timestamp` and `!!binary` tags as well as BigInts. + * + * Default: `true` + */ + keepBlobsInJSON?: boolean + /** + * Include references in the AST to each node's corresponding CST node. + * + * Default: `false` + */ + keepCstNodes?: boolean + /** + * Store the original node type when parsing documents. + * + * Default: `true` + */ + keepNodeTypes?: boolean + /** + * When outputting JS, use Map rather than Object to represent mappings. + * + * Default: `false` + */ + mapAsMap?: boolean + /** + * Prevent exponential entity expansion attacks by limiting data aliasing count; + * set to `-1` to disable checks; `0` disallows all alias nodes. + * + * Default: `100` + */ + maxAliasCount?: number + /** + * Include line position & node type directly in errors; drop their verbose source and context. + * + * Default: `false` + */ + prettyErrors?: boolean + /** + * When stringifying, require keys to be scalars and to use implicit rather than explicit notation. + * + * Default: `false` + */ + simpleKeys?: boolean + /** + * The YAML version used by documents without a `%YAML` directive. + * + * Default: `"1.2"` + */ + version?: '1.0' | '1.1' | '1.2' +} + +/** + * Some customization options are availabe to control the parsing and + * stringification of scalars. Note that these values are used by all documents. + */ +export const scalarOptions: { + binary: scalarOptions.Binary + bool: scalarOptions.Bool + int: scalarOptions.Int + null: scalarOptions.Null + str: scalarOptions.Str +} +export namespace scalarOptions { + interface Binary { + /** + * The type of string literal used to stringify `!!binary` values. + * + * Default: `'BLOCK_LITERAL'` + */ + defaultType: Scalar.Type + /** + * Maximum line width for `!!binary`. + * + * Default: `76` + */ + lineWidth: number + } + + interface Bool { + /** + * String representation for `true`. With the core schema, use `'true' | 'True' | 'TRUE'`. + * + * Default: `'true'` + */ + trueStr: string + /** + * String representation for `false`. With the core schema, use `'false' | 'False' | 'FALSE'`. + * + * Default: `'false'` + */ + falseStr: string + } + + interface Int { + /** + * Whether integers should be parsed into BigInt values. + * + * Default: `false` + */ + asBigInt: false + } + + interface Null { + /** + * String representation for `null`. With the core schema, use `'null' | 'Null' | 'NULL' | '~' | ''`. + * + * Default: `'null'` + */ + nullStr: string + } + + interface Str { + /** + * The default type of string literal used to stringify values + * + * Default: `'PLAIN'` + */ + defaultType: Scalar.Type + doubleQuoted: { + /** + * Whether to restrict double-quoted strings to use JSON-compatible syntax. + * + * Default: `false` + */ + jsonEncoding: boolean + /** + * Minimum length to use multiple lines to represent the value. + * + * Default: `40` + */ + minMultiLineLength: number + } + fold: { + /** + * Maximum line width (set to `0` to disable folding). + * + * Default: `80` + */ + lineWidth: number + /** + * Minimum width for highly-indented content. + * + * Default: `20` + */ + minContentWidth: number + } + } +} + +export class Document extends Collection { + cstNode?: CST.Document + constructor(options?: Options) + tag: never + directivesEndMarker?: boolean + type: Type.DOCUMENT + /** + * Anchors associated with the document's nodes; + * also provides alias & merge node creators. + */ + anchors: Document.Anchors + /** The document contents. */ + contents: any + /** Errors encountered during parsing. */ + errors: YAMLError[] + /** + * The schema used with the document. Use `setSchema()` to change or + * initialise. + */ + schema?: Schema + /** + * Array of prefixes; each will have a string `handle` that + * starts and ends with `!` and a string `prefix` that the handle will be replaced by. + */ + tagPrefixes: Document.TagPrefix[] + /** + * The parsed version of the source document; + * if true-ish, stringified output will include a `%YAML` directive. + */ + version?: string + /** Warnings encountered during parsing. */ + warnings: YAMLWarning[] + /** + * List the tags used in the document that are not in the default + * `tag:yaml.org,2002:` namespace. + */ + listNonDefaultTags(): string[] + /** Parse a CST into this document */ + parse(cst: CST.Document): this + /** + * When a document is created with `new YAML.Document()`, the schema object is + * not set as it may be influenced by parsed directives; call this with no + * arguments to set it manually, or with arguments to change the schema used + * by the document. + **/ + setSchema( + id?: Options['version'] | Schema.Name, + customTags?: (Schema.TagId | Schema.Tag)[] + ): void + /** Set `handle` as a shorthand string for the `prefix` tag namespace. */ + setTagPrefix(handle: string, prefix: string): void + /** + * A plain JavaScript representation of the document `contents`. + * + * @param arg Used by `JSON.stringify` to indicate the array index or property + * name. If its value is a `string` and the document `contents` has a scalar + * value, the `keepBlobsInJSON` option has no effect. + * @param onAnchor If defined, called with the resolved `value` and reference + * `count` for each anchor in the document. + * */ + toJSON(arg?: string, onAnchor?: (value: any, count: number) => void): any + /** A YAML representation of the document. */ + toString(): string +} + +export namespace Document { + interface Parsed extends Document { + contents: Node | null + /** The schema used with the document. */ + schema: Schema + } + + interface Anchors { + /** + * Create a new `Alias` node, adding the required anchor for `node`. + * If `name` is empty, a new anchor name will be generated. + */ + createAlias(node: Node, name?: string): Alias + /** + * Create a new `Merge` node with the given source nodes. + * Non-`Alias` sources will be automatically wrapped. + */ + createMergePair(...nodes: Node[]): Merge + /** The anchor name associated with `node`, if set. */ + getName(node: Node): undefined | string + /** List of all defined anchor names. */ + getNames(): string[] + /** The node associated with the anchor `name`, if set. */ + getNode(name: string): undefined | Node + /** + * Find an available anchor name with the given `prefix` and a + * numerical suffix. + */ + newName(prefix: string): string + /** + * Associate an anchor with `node`. If `name` is empty, a new name will be generated. + * To remove an anchor, use `setAnchor(null, name)`. + */ + setAnchor(node: Node | null, name?: string): void | string + } + + interface TagPrefix { + handle: string + prefix: string + } +} + +/** + * Recursively turns objects into collections. Generic objects as well as `Map` + * and its descendants become mappings, while arrays and other iterable objects + * result in sequences. + * + * The primary purpose of this function is to enable attaching comments or other + * metadata to a value, or to otherwise exert more fine-grained control over the + * stringified output. To that end, you'll need to assign its return value to + * the `contents` of a Document (or somewhere within said contents), as the + * document's schema is required for YAML string output. + * + * @param wrapScalars If undefined or `true`, also wraps plain values in + * `Scalar` objects; if `false` and `value` is not an object, it will be + * returned directly. + * @param tag Use to specify the collection type, e.g. `"!!omap"`. Note that + * this requires the corresponding tag to be available based on the default + * options. To use a specific document's schema, use `doc.schema.createNode`. + */ +export function createNode( + value: any, + wrapScalars?: true, + tag?: string +): YAMLMap | YAMLSeq | Scalar + +/** + * YAML.createNode recursively turns objects into Map and arrays to Seq collections. + * Its primary use is to enable attaching comments or other metadata to a value, + * or to otherwise exert more fine-grained control over the stringified output. + * + * Doesn't wrap plain values in Scalar objects. + */ +export function createNode( + value: any, + wrapScalars: false, + tag?: string +): YAMLMap | YAMLSeq | string | number | boolean | null + +/** + * Parse an input string into a single YAML.Document. + */ +export function parseDocument(str: string, options?: Options): Document.Parsed + +/** + * Parse the input as a stream of YAML documents. + * + * Documents should be separated from each other by `...` or `---` marker lines. + */ +export function parseAllDocuments( + str: string, + options?: Options +): Document.Parsed[] + +/** + * Parse an input string into JavaScript. + * + * Only supports input consisting of a single YAML document; for multi-document + * support you should use `YAML.parseAllDocuments`. May throw on error, and may + * log warnings using `console.warn`. + * + * @param str A string with YAML formatting. + * @returns The value will match the type of the root value of the parsed YAML + * document, so Maps become objects, Sequences arrays, and scalars result in + * nulls, booleans, numbers and strings. + */ +export function parse(str: string, options?: Options): any + +/** + * @returns Will always include \n as the last character, as is expected of YAML documents. + */ +export function stringify(value: any, options?: Options): string diff --git a/node_modules/yaml/index.js b/node_modules/yaml/index.js new file mode 100644 index 0000000..b501ac4 --- /dev/null +++ b/node_modules/yaml/index.js @@ -0,0 +1 @@ +module.exports = require('./dist').YAML diff --git a/node_modules/yaml/map.js b/node_modules/yaml/map.js new file mode 100644 index 0000000..78f2ebc --- /dev/null +++ b/node_modules/yaml/map.js @@ -0,0 +1,2 @@ +module.exports = require('./dist/types').YAMLMap +require('./dist/legacy-exports').warnFileDeprecation(__filename) diff --git a/node_modules/yaml/package.json b/node_modules/yaml/package.json new file mode 100644 index 0000000..a0b4bd3 --- /dev/null +++ b/node_modules/yaml/package.json @@ -0,0 +1,106 @@ +{ + "name": "yaml", + "version": "1.10.0", + "license": "ISC", + "author": "Eemeli Aro ", + "repository": "github:eemeli/yaml", + "description": "JavaScript parser and stringifier for YAML", + "keywords": [ + "YAML", + "parser", + "stringifier" + ], + "homepage": "https://eemeli.org/yaml/", + "files": [ + "browser/", + "dist/", + "types/", + "*.d.ts", + "*.js", + "*.mjs", + "!*config.js" + ], + "type": "commonjs", + "main": "./index.js", + "browser": { + "./index.js": "./browser/index.js", + "./map.js": "./browser/map.js", + "./pair.js": "./browser/pair.js", + "./parse-cst.js": "./browser/parse-cst.js", + "./scalar.js": "./browser/scalar.js", + "./schema.js": "./browser/schema.js", + "./seq.js": "./browser/seq.js", + "./types.js": "./browser/types.js", + "./types.mjs": "./browser/types.js", + "./types/binary.js": "./browser/types/binary.js", + "./types/omap.js": "./browser/types/omap.js", + "./types/pairs.js": "./browser/types/pairs.js", + "./types/set.js": "./browser/types/set.js", + "./types/timestamp.js": "./browser/types/timestamp.js", + "./util.js": "./browser/util.js", + "./util.mjs": "./browser/util.js" + }, + "exports": { + ".": "./index.js", + "./parse-cst": "./parse-cst.js", + "./types": [ + { + "import": "./types.mjs" + }, + "./types.js" + ], + "./util": [ + { + "import": "./util.mjs" + }, + "./util.js" + ], + "./": "./" + }, + "scripts": { + "build": "npm run build:node && npm run build:browser", + "build:browser": "rollup -c rollup.browser-config.js", + "build:node": "rollup -c rollup.node-config.js", + "clean": "git clean -fdxe node_modules", + "lint": "eslint src/", + "prettier": "prettier --write .", + "start": "cross-env TRACE_LEVEL=log npm run build:node && node -i -e 'YAML=require(\".\")'", + "test": "jest", + "test:dist": "npm run build:node && jest", + "test:types": "tsc --lib ES2017 --noEmit tests/typings.ts", + "docs:install": "cd docs-slate && bundle install", + "docs:deploy": "cd docs-slate && ./deploy.sh", + "docs": "cd docs-slate && bundle exec middleman server", + "preversion": "npm test && npm run build", + "prepublishOnly": "npm run clean && npm test && npm run build" + }, + "browserslist": "> 0.5%, not dead", + "prettier": { + "arrowParens": "avoid", + "semi": false, + "singleQuote": true, + "trailingComma": "none" + }, + "devDependencies": { + "@babel/core": "^7.9.6", + "@babel/plugin-proposal-class-properties": "^7.8.3", + "@babel/preset-env": "^7.9.6", + "@rollup/plugin-babel": "^5.0.0", + "babel-eslint": "^10.1.0", + "babel-jest": "^26.0.1", + "babel-plugin-trace": "^1.1.0", + "common-tags": "^1.8.0", + "cross-env": "^7.0.2", + "eslint": "^7.0.0", + "eslint-config-prettier": "^6.11.0", + "eslint-plugin-prettier": "^3.1.3", + "fast-check": "^1.24.2", + "jest": "^26.0.1", + "prettier": "^2.0.5", + "rollup": "^2.10.2", + "typescript": "^3.9.2" + }, + "engines": { + "node": ">= 6" + } +} diff --git a/node_modules/yaml/pair.js b/node_modules/yaml/pair.js new file mode 100644 index 0000000..b2880a2 --- /dev/null +++ b/node_modules/yaml/pair.js @@ -0,0 +1,2 @@ +module.exports = require('./dist/types').Pair +require('./dist/legacy-exports').warnFileDeprecation(__filename) diff --git a/node_modules/yaml/parse-cst.d.ts b/node_modules/yaml/parse-cst.d.ts new file mode 100644 index 0000000..bd8a5b4 --- /dev/null +++ b/node_modules/yaml/parse-cst.d.ts @@ -0,0 +1,187 @@ +import { Type, YAMLSyntaxError } from './util' + +export default function parseCST(str: string): ParsedCST + +export interface ParsedCST extends Array { + setOrigRanges(): boolean +} + +export namespace CST { + interface Range { + start: number + end: number + origStart?: number + origEnd?: number + isEmpty(): boolean + } + + interface ParseContext { + /** Node starts at beginning of line */ + atLineStart: boolean + /** true if currently in a collection context */ + inCollection: boolean + /** true if currently in a flow context */ + inFlow: boolean + /** Current level of indentation */ + indent: number + /** Start of the current line */ + lineStart: number + /** The parent of the node */ + parent: Node + /** Source of the YAML document */ + src: string + } + + interface Node { + context: ParseContext | null + /** if not null, indicates a parser failure */ + error: YAMLSyntaxError | null + /** span of context.src parsed into this node */ + range: Range | null + valueRange: Range | null + /** anchors, tags and comments */ + props: Range[] + /** specific node type */ + type: Type + /** if non-null, overrides source value */ + value: string | null + + readonly anchor: string | null + readonly comment: string | null + readonly hasComment: boolean + readonly hasProps: boolean + readonly jsonLike: boolean + readonly rawValue: string | null + readonly tag: + | null + | { verbatim: string } + | { handle: string; suffix: string } + readonly valueRangeContainsNewline: boolean + } + + interface Alias extends Node { + type: Type.ALIAS + /** contain the anchor without the * prefix */ + readonly rawValue: string + } + + type Scalar = BlockValue | PlainValue | QuoteValue + + interface BlockValue extends Node { + type: Type.BLOCK_FOLDED | Type.BLOCK_LITERAL + chomping: 'CLIP' | 'KEEP' | 'STRIP' + blockIndent: number | null + header: Range + readonly strValue: string | null + } + + interface BlockFolded extends BlockValue { + type: Type.BLOCK_FOLDED + } + + interface BlockLiteral extends BlockValue { + type: Type.BLOCK_LITERAL + } + + interface PlainValue extends Node { + type: Type.PLAIN + readonly strValue: string | null + } + + interface QuoteValue extends Node { + type: Type.QUOTE_DOUBLE | Type.QUOTE_SINGLE + readonly strValue: + | null + | string + | { str: string; errors: YAMLSyntaxError[] } + } + + interface QuoteDouble extends QuoteValue { + type: Type.QUOTE_DOUBLE + } + + interface QuoteSingle extends QuoteValue { + type: Type.QUOTE_SINGLE + } + + interface Comment extends Node { + type: Type.COMMENT + readonly anchor: null + readonly comment: string + readonly rawValue: null + readonly tag: null + } + + interface BlankLine extends Node { + type: Type.BLANK_LINE + } + + interface MapItem extends Node { + type: Type.MAP_KEY | Type.MAP_VALUE + node: ContentNode | null + } + + interface MapKey extends MapItem { + type: Type.MAP_KEY + } + + interface MapValue extends MapItem { + type: Type.MAP_VALUE + } + + interface Map extends Node { + type: Type.MAP + /** implicit keys are not wrapped */ + items: Array + } + + interface SeqItem extends Node { + type: Type.SEQ_ITEM + node: ContentNode | null + } + + interface Seq extends Node { + type: Type.SEQ + items: Array + } + + interface FlowChar { + char: '{' | '}' | '[' | ']' | ',' | '?' | ':' + offset: number + origOffset?: number + } + + interface FlowCollection extends Node { + type: Type.FLOW_MAP | Type.FLOW_SEQ + items: Array< + FlowChar | BlankLine | Comment | Alias | Scalar | FlowCollection + > + } + + interface FlowMap extends FlowCollection { + type: Type.FLOW_MAP + } + + interface FlowSeq extends FlowCollection { + type: Type.FLOW_SEQ + } + + type ContentNode = Alias | Scalar | Map | Seq | FlowCollection + + interface Directive extends Node { + type: Type.DIRECTIVE + name: string + readonly anchor: null + readonly parameters: string[] + readonly tag: null + } + + interface Document extends Node { + type: Type.DOCUMENT + directives: Array + contents: Array + readonly anchor: null + readonly comment: null + readonly tag: null + } +} diff --git a/node_modules/yaml/parse-cst.js b/node_modules/yaml/parse-cst.js new file mode 100644 index 0000000..8065756 --- /dev/null +++ b/node_modules/yaml/parse-cst.js @@ -0,0 +1 @@ +module.exports = require('./dist/parse-cst').parse diff --git a/node_modules/yaml/scalar.js b/node_modules/yaml/scalar.js new file mode 100644 index 0000000..deee1b0 --- /dev/null +++ b/node_modules/yaml/scalar.js @@ -0,0 +1,2 @@ +module.exports = require('./dist/types').Scalar +require('./dist/legacy-exports').warnFileDeprecation(__filename) diff --git a/node_modules/yaml/schema.js b/node_modules/yaml/schema.js new file mode 100644 index 0000000..4139c4b --- /dev/null +++ b/node_modules/yaml/schema.js @@ -0,0 +1,9 @@ +const types = require('./dist/types') +const util = require('./dist/util') + +module.exports = types.Schema +module.exports.nullOptions = types.nullOptions +module.exports.strOptions = types.strOptions +module.exports.stringify = util.stringifyString + +require('./dist/legacy-exports').warnFileDeprecation(__filename) diff --git a/node_modules/yaml/seq.js b/node_modules/yaml/seq.js new file mode 100644 index 0000000..66147df --- /dev/null +++ b/node_modules/yaml/seq.js @@ -0,0 +1,2 @@ +module.exports = require('./dist/types').YAMLSeq +require('./dist/legacy-exports').warnFileDeprecation(__filename) diff --git a/node_modules/yaml/types.d.ts b/node_modules/yaml/types.d.ts new file mode 100644 index 0000000..411e74e --- /dev/null +++ b/node_modules/yaml/types.d.ts @@ -0,0 +1,407 @@ +import { Document, scalarOptions } from './index' +import { CST } from './parse-cst' +import { Type } from './util' + +export const binaryOptions: scalarOptions.Binary +export const boolOptions: scalarOptions.Bool +export const intOptions: scalarOptions.Int +export const nullOptions: scalarOptions.Null +export const strOptions: scalarOptions.Str + +export class Schema { + /** Default: `'tag:yaml.org,2002:'` */ + static defaultPrefix: string + static defaultTags: { + /** Default: `'tag:yaml.org,2002:map'` */ + MAP: string + /** Default: `'tag:yaml.org,2002:seq'` */ + SEQ: string + /** Default: `'tag:yaml.org,2002:str'` */ + STR: string + } + constructor(options: Schema.Options) + /** + * Convert any value into a `Node` using this schema, recursively turning + * objects into collections. + * + * @param wrapScalars If `true`, also wraps plain values in `Scalar` objects; + * if undefined or `false` and `value` is not an object, it will be returned + * directly. + * @param tag Use to specify the collection type, e.g. `"!!omap"`. Note that + * this requires the corresponding tag to be available in this schema. + */ + createNode( + value: any, + wrapScalars?: boolean, + tag?: string, + ctx?: Schema.CreateNodeContext + ): Node + /** + * Convert a key and a value into a `Pair` using this schema, recursively + * wrapping all values as `Scalar` or `Collection` nodes. + * + * @param ctx To not wrap scalars, use a context `{ wrapScalars: false }` + */ + createPair(key: any, value: any, ctx?: Schema.CreateNodeContext): Pair + merge: boolean + name: Schema.Name + sortMapEntries: ((a: Pair, b: Pair) => number) | null + tags: Schema.Tag[] +} + +export namespace Schema { + type Name = 'core' | 'failsafe' | 'json' | 'yaml-1.1' + + interface Options { + /** + * Array of additional tags to include in the schema, or a function that may + * modify the schema's base tag array. + */ + customTags?: (TagId | Tag)[] | ((tags: Tag[]) => Tag[]) + /** + * Enable support for `<<` merge keys. + * + * Default: `false` for YAML 1.2, `true` for earlier versions + */ + merge?: boolean + /** + * The base schema to use. + * + * Default: `"core"` for YAML 1.2, `"yaml-1.1"` for earlier versions + */ + schema?: Name + /** + * When stringifying, sort map entries. If `true`, sort by comparing key values with `<`. + * + * Default: `false` + */ + sortMapEntries?: boolean | ((a: Pair, b: Pair) => number) + /** + * @deprecated Use `customTags` instead. + */ + tags?: Options['customTags'] + } + + interface CreateNodeContext { + wrapScalars?: boolean + [key: string]: any + } + + interface StringifyContext { + forceBlockIndent?: boolean + implicitKey?: boolean + indent?: string + indentAtStart?: number + inFlow?: boolean + [key: string]: any + } + + type TagId = + | 'binary' + | 'bool' + | 'float' + | 'floatExp' + | 'floatNaN' + | 'floatTime' + | 'int' + | 'intHex' + | 'intOct' + | 'intTime' + | 'null' + | 'omap' + | 'pairs' + | 'set' + | 'timestamp' + + type Tag = CustomTag | DefaultTag + + interface BaseTag { + /** + * An optional factory function, used e.g. by collections when wrapping JS objects as AST nodes. + */ + createNode?: ( + schema: Schema, + value: any, + ctx: Schema.CreateNodeContext + ) => YAMLMap | YAMLSeq | Scalar + /** + * If a tag has multiple forms that should be parsed and/or stringified differently, use `format` to identify them. + */ + format?: string + /** + * Used by `YAML.createNode` to detect your data type, e.g. using `typeof` or + * `instanceof`. + */ + identify(value: any): boolean + /** + * The `Node` child class that implements this tag. Required for collections and tags that have overlapping JS representations. + */ + nodeClass?: new () => any + /** + * Used by some tags to configure their stringification, where applicable. + */ + options?: object + /** + * Optional function stringifying the AST node in the current context. If your + * data includes a suitable `.toString()` method, you can probably leave this + * undefined and use the default stringifier. + * + * @param item The node being stringified. + * @param ctx Contains the stringifying context variables. + * @param onComment Callback to signal that the stringifier includes the + * item's comment in its output. + * @param onChompKeep Callback to signal that the output uses a block scalar + * type with the `+` chomping indicator. + */ + stringify?: ( + item: Node, + ctx: Schema.StringifyContext, + onComment?: () => void, + onChompKeep?: () => void + ) => string + /** + * The identifier for your data type, with which its stringified form will be + * prefixed. Should either be a !-prefixed local `!tag`, or a fully qualified + * `tag:domain,date:foo`. + */ + tag: string + } + + interface CustomTag extends BaseTag { + /** + * A JavaScript class that should be matched to this tag, e.g. `Date` for `!!timestamp`. + * @deprecated Use `Tag.identify` instead + */ + class?: new () => any + /** + * Turns a CST node into an AST node. If returning a non-`Node` value, the + * output will be wrapped as a `Scalar`. + */ + resolve(doc: Document, cstNode: CST.Node): Node | any + } + + interface DefaultTag extends BaseTag { + /** + * If `true`, together with `test` allows for values to be stringified without + * an explicit tag. For most cases, it's unlikely that you'll actually want to + * use this, even if you first think you do. + */ + default: true + /** + * Alternative form used by default tags; called with `test` match results. + */ + resolve(...match: string[]): Node | any + /** + * Together with `default` allows for values to be stringified without an + * explicit tag and detected using a regular expression. For most cases, it's + * unlikely that you'll actually want to use these, even if you first think + * you do. + */ + test: RegExp + } +} + +export class Node { + /** A comment on or immediately after this */ + comment?: string | null + /** A comment before this */ + commentBefore?: string | null + /** Only available when `keepCstNodes` is set to `true` */ + cstNode?: CST.Node + /** + * The [start, end] range of characters of the source parsed + * into this node (undefined for pairs or if not parsed) + */ + range?: [number, number] | null + /** A blank line before this node and its commentBefore */ + spaceBefore?: boolean + /** A fully qualified tag, if required */ + tag?: string + /** A plain JS representation of this node */ + toJSON(arg?: any): any + /** The type of this node */ + type?: Type | Pair.Type +} + +export class Scalar extends Node { + constructor(value: any) + type?: Scalar.Type + /** + * By default (undefined), numbers use decimal notation. + * The YAML 1.2 core schema only supports 'HEX' and 'OCT'. + */ + format?: 'BIN' | 'HEX' | 'OCT' | 'TIME' + value: any + toJSON(arg?: any, ctx?: AST.NodeToJsonContext): any + toString(): string +} +export namespace Scalar { + type Type = + | Type.BLOCK_FOLDED + | Type.BLOCK_LITERAL + | Type.PLAIN + | Type.QUOTE_DOUBLE + | Type.QUOTE_SINGLE +} + +export class Alias extends Node { + type: Type.ALIAS + source: Node + cstNode?: CST.Alias + toString(ctx: Schema.StringifyContext): string +} + +export class Pair extends Node { + constructor(key: any, value?: any) + type: Pair.Type.PAIR | Pair.Type.MERGE_PAIR + /** Always Node or null when parsed, but can be set to anything. */ + key: any + /** Always Node or null when parsed, but can be set to anything. */ + value: any + cstNode?: never // no corresponding cstNode + toJSON(arg?: any, ctx?: AST.NodeToJsonContext): object | Map + toString( + ctx?: Schema.StringifyContext, + onComment?: () => void, + onChompKeep?: () => void + ): string +} +export namespace Pair { + enum Type { + PAIR = 'PAIR', + MERGE_PAIR = 'MERGE_PAIR' + } +} + +export class Merge extends Pair { + type: Pair.Type.MERGE_PAIR + /** Always Scalar('<<'), defined by the type specification */ + key: AST.PlainValue + /** Always YAMLSeq, stringified as *A if length = 1 */ + value: YAMLSeq + toString(ctx?: Schema.StringifyContext, onComment?: () => void): string +} + +export class Collection extends Node { + type?: Type.MAP | Type.FLOW_MAP | Type.SEQ | Type.FLOW_SEQ | Type.DOCUMENT + items: any[] + schema?: Schema + + /** + * Adds a value to the collection. For `!!map` and `!!omap` the value must + * be a Pair instance or a `{ key, value }` object, which may not have a key + * that already exists in the map. + */ + add(value: any): void + addIn(path: Iterable, value: any): void + /** + * Removes a value from the collection. + * @returns `true` if the item was found and removed. + */ + delete(key: any): boolean + deleteIn(path: Iterable): boolean + /** + * Returns item at `key`, or `undefined` if not found. By default unwraps + * scalar values from their surrounding node; to disable set `keepScalar` to + * `true` (collections are always returned intact). + */ + get(key: any, keepScalar?: boolean): any + getIn(path: Iterable, keepScalar?: boolean): any + /** + * Checks if the collection includes a value with the key `key`. + */ + has(key: any): boolean + hasIn(path: Iterable): boolean + /** + * Sets a value in this collection. For `!!set`, `value` needs to be a + * boolean to add/remove the item from the set. + */ + set(key: any, value: any): void + setIn(path: Iterable, value: any): void +} + +export class YAMLMap extends Collection { + type?: Type.FLOW_MAP | Type.MAP + items: Array + hasAllNullValues(): boolean + toJSON(arg?: any, ctx?: AST.NodeToJsonContext): object | Map + toString( + ctx?: Schema.StringifyContext, + onComment?: () => void, + onChompKeep?: () => void + ): string +} + +export class YAMLSeq extends Collection { + type?: Type.FLOW_SEQ | Type.SEQ + delete(key: number | string | Scalar): boolean + get(key: number | string | Scalar, keepScalar?: boolean): any + has(key: number | string | Scalar): boolean + set(key: number | string | Scalar, value: any): void + hasAllNullValues(): boolean + toJSON(arg?: any, ctx?: AST.NodeToJsonContext): any[] + toString( + ctx?: Schema.StringifyContext, + onComment?: () => void, + onChompKeep?: () => void + ): string +} + +export namespace AST { + interface NodeToJsonContext { + anchors?: any[] + doc: Document + keep?: boolean + mapAsMap?: boolean + maxAliasCount?: number + onCreate?: (node: Node) => void + [key: string]: any + } + + interface BlockFolded extends Scalar { + type: Type.BLOCK_FOLDED + cstNode?: CST.BlockFolded + } + + interface BlockLiteral extends Scalar { + type: Type.BLOCK_LITERAL + cstNode?: CST.BlockLiteral + } + + interface PlainValue extends Scalar { + type: Type.PLAIN + cstNode?: CST.PlainValue + } + + interface QuoteDouble extends Scalar { + type: Type.QUOTE_DOUBLE + cstNode?: CST.QuoteDouble + } + + interface QuoteSingle extends Scalar { + type: Type.QUOTE_SINGLE + cstNode?: CST.QuoteSingle + } + + interface FlowMap extends YAMLMap { + type: Type.FLOW_MAP + cstNode?: CST.FlowMap + } + + interface BlockMap extends YAMLMap { + type: Type.MAP + cstNode?: CST.Map + } + + interface FlowSeq extends YAMLSeq { + type: Type.FLOW_SEQ + items: Array + cstNode?: CST.FlowSeq + } + + interface BlockSeq extends YAMLSeq { + type: Type.SEQ + items: Array + cstNode?: CST.Seq + } +} diff --git a/node_modules/yaml/types.js b/node_modules/yaml/types.js new file mode 100644 index 0000000..8874749 --- /dev/null +++ b/node_modules/yaml/types.js @@ -0,0 +1,17 @@ +const types = require('./dist/types') + +exports.binaryOptions = types.binaryOptions +exports.boolOptions = types.boolOptions +exports.intOptions = types.intOptions +exports.nullOptions = types.nullOptions +exports.strOptions = types.strOptions + +exports.Schema = types.Schema +exports.Alias = types.Alias +exports.Collection = types.Collection +exports.Merge = types.Merge +exports.Node = types.Node +exports.Pair = types.Pair +exports.Scalar = types.Scalar +exports.YAMLMap = types.YAMLMap +exports.YAMLSeq = types.YAMLSeq diff --git a/node_modules/yaml/types.mjs b/node_modules/yaml/types.mjs new file mode 100644 index 0000000..7132288 --- /dev/null +++ b/node_modules/yaml/types.mjs @@ -0,0 +1,17 @@ +import types from './dist/types.js' + +export const binaryOptions = types.binaryOptions +export const boolOptions = types.boolOptions +export const intOptions = types.intOptions +export const nullOptions = types.nullOptions +export const strOptions = types.strOptions + +export const Schema = types.Schema +export const Alias = types.Alias +export const Collection = types.Collection +export const Merge = types.Merge +export const Node = types.Node +export const Pair = types.Pair +export const Scalar = types.Scalar +export const YAMLMap = types.YAMLMap +export const YAMLSeq = types.YAMLSeq diff --git a/node_modules/yaml/types/binary.js b/node_modules/yaml/types/binary.js new file mode 100644 index 0000000..271b9de --- /dev/null +++ b/node_modules/yaml/types/binary.js @@ -0,0 +1,8 @@ +'use strict' +Object.defineProperty(exports, '__esModule', { value: true }) + +const legacy = require('../dist/legacy-exports') +exports.binary = legacy.binary +exports.default = [exports.binary] + +legacy.warnFileDeprecation(__filename) diff --git a/node_modules/yaml/types/omap.js b/node_modules/yaml/types/omap.js new file mode 100644 index 0000000..37b638b --- /dev/null +++ b/node_modules/yaml/types/omap.js @@ -0,0 +1,3 @@ +const legacy = require('../dist/legacy-exports') +module.exports = legacy.omap +legacy.warnFileDeprecation(__filename) diff --git a/node_modules/yaml/types/pairs.js b/node_modules/yaml/types/pairs.js new file mode 100644 index 0000000..f1df201 --- /dev/null +++ b/node_modules/yaml/types/pairs.js @@ -0,0 +1,3 @@ +const legacy = require('../dist/legacy-exports') +module.exports = legacy.pairs +legacy.warnFileDeprecation(__filename) diff --git a/node_modules/yaml/types/set.js b/node_modules/yaml/types/set.js new file mode 100644 index 0000000..e7dc9d4 --- /dev/null +++ b/node_modules/yaml/types/set.js @@ -0,0 +1,3 @@ +const legacy = require('../dist/legacy-exports') +module.exports = legacy.set +legacy.warnFileDeprecation(__filename) diff --git a/node_modules/yaml/types/timestamp.js b/node_modules/yaml/types/timestamp.js new file mode 100644 index 0000000..39c5b6d --- /dev/null +++ b/node_modules/yaml/types/timestamp.js @@ -0,0 +1,10 @@ +'use strict' +Object.defineProperty(exports, '__esModule', { value: true }) + +const legacy = require('../dist/legacy-exports') +exports.default = [legacy.intTime, legacy.floatTime, legacy.timestamp] +exports.floatTime = legacy.floatTime +exports.intTime = legacy.intTime +exports.timestamp = legacy.timestamp + +legacy.warnFileDeprecation(__filename) diff --git a/node_modules/yaml/util.d.ts b/node_modules/yaml/util.d.ts new file mode 100644 index 0000000..b135541 --- /dev/null +++ b/node_modules/yaml/util.d.ts @@ -0,0 +1,86 @@ +import { Document } from './index' +import { CST } from './parse-cst' +import { AST, Pair, Scalar, Schema } from './types' + +export function findPair(items: any[], key: Scalar | any): Pair | undefined + +export function parseMap(doc: Document, cst: CST.Map): AST.BlockMap +export function parseMap(doc: Document, cst: CST.FlowMap): AST.FlowMap +export function parseSeq(doc: Document, cst: CST.Seq): AST.BlockSeq +export function parseSeq(doc: Document, cst: CST.FlowSeq): AST.FlowSeq + +export function stringifyNumber(item: Scalar): string +export function stringifyString( + item: Scalar, + ctx: Schema.StringifyContext, + onComment?: () => void, + onChompKeep?: () => void +): string + +export function toJSON( + value: any, + arg?: any, + ctx?: Schema.CreateNodeContext +): any + +export enum Type { + ALIAS = 'ALIAS', + BLANK_LINE = 'BLANK_LINE', + BLOCK_FOLDED = 'BLOCK_FOLDED', + BLOCK_LITERAL = 'BLOCK_LITERAL', + COMMENT = 'COMMENT', + DIRECTIVE = 'DIRECTIVE', + DOCUMENT = 'DOCUMENT', + FLOW_MAP = 'FLOW_MAP', + FLOW_SEQ = 'FLOW_SEQ', + MAP = 'MAP', + MAP_KEY = 'MAP_KEY', + MAP_VALUE = 'MAP_VALUE', + PLAIN = 'PLAIN', + QUOTE_DOUBLE = 'QUOTE_DOUBLE', + QUOTE_SINGLE = 'QUOTE_SINGLE', + SEQ = 'SEQ', + SEQ_ITEM = 'SEQ_ITEM' +} + +interface LinePos { + line: number + col: number +} + +export class YAMLError extends Error { + name: + | 'YAMLReferenceError' + | 'YAMLSemanticError' + | 'YAMLSyntaxError' + | 'YAMLWarning' + message: string + source?: CST.Node + + nodeType?: Type + range?: CST.Range + linePos?: { start: LinePos; end: LinePos } + + /** + * Drops `source` and adds `nodeType`, `range` and `linePos`, as well as + * adding details to `message`. Run automatically for document errors if + * the `prettyErrors` option is set. + */ + makePretty(): void +} + +export class YAMLReferenceError extends YAMLError { + name: 'YAMLReferenceError' +} + +export class YAMLSemanticError extends YAMLError { + name: 'YAMLSemanticError' +} + +export class YAMLSyntaxError extends YAMLError { + name: 'YAMLSyntaxError' +} + +export class YAMLWarning extends YAMLError { + name: 'YAMLWarning' +} diff --git a/node_modules/yaml/util.js b/node_modules/yaml/util.js new file mode 100644 index 0000000..06dd2c9 --- /dev/null +++ b/node_modules/yaml/util.js @@ -0,0 +1,16 @@ +const util = require('./dist/util') + +exports.findPair = util.findPair +exports.toJSON = util.toJSON +exports.parseMap = util.parseMap +exports.parseSeq = util.parseSeq + +exports.stringifyNumber = util.stringifyNumber +exports.stringifyString = util.stringifyString +exports.Type = util.Type + +exports.YAMLError = util.YAMLError +exports.YAMLReferenceError = util.YAMLReferenceError +exports.YAMLSemanticError = util.YAMLSemanticError +exports.YAMLSyntaxError = util.YAMLSyntaxError +exports.YAMLWarning = util.YAMLWarning diff --git a/node_modules/yaml/util.mjs b/node_modules/yaml/util.mjs new file mode 100644 index 0000000..89e654a --- /dev/null +++ b/node_modules/yaml/util.mjs @@ -0,0 +1,18 @@ +import util from './dist/util.js' + +export const findPair = util.findPair +export const toJSON = util.toJSON + +export const parseMap = util.parseMap +export const parseSeq = util.parseSeq + +export const stringifyNumber = util.stringifyNumber +export const stringifyString = util.stringifyString + +export const Type = util.Type + +export const YAMLError = util.YAMLError +export const YAMLReferenceError = util.YAMLReferenceError +export const YAMLSemanticError = util.YAMLSemanticError +export const YAMLSyntaxError = util.YAMLSyntaxError +export const YAMLWarning = util.YAMLWarning diff --git a/package-lock.json b/package-lock.json index a1e32f7..008542a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,7 +1,42 @@ { "name": "action-ansible-playbook", + "lockfileVersion": 2, "requires": true, - "lockfileVersion": 1, + "packages": { + "": { + "dependencies": { + "@actions/core": "^1.2.6", + "@actions/exec": "^1.0.4", + "yaml": "^1.10.0" + } + }, + "node_modules/@actions/core": { + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.6.tgz", + "integrity": "sha512-ZQYitnqiyBc3D+k7LsgSBmMDVkOVidaagDG7j3fOym77jNunWRuYx7VSHa9GNfFZh+zh61xsCjRj4JxMZlDqTA==" + }, + "node_modules/@actions/exec": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.0.4.tgz", + "integrity": "sha512-4DPChWow9yc9W3WqEbUj8Nr86xkpyE29ZzWjXucHItclLbEW6jr80Zx4nqv18QL6KK65+cifiQZXvnqgTV6oHw==", + "dependencies": { + "@actions/io": "^1.0.1" + } + }, + "node_modules/@actions/io": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@actions/io/-/io-1.0.2.tgz", + "integrity": "sha512-J8KuFqVPr3p6U8W93DOXlXW6zFvrQAJANdS+vw0YhusLIq+bszW8zmK2Fh1C2kDPX8FMvwIl1OUcFgvJoXLbAg==" + }, + "node_modules/yaml": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-1.10.0.tgz", + "integrity": "sha512-yr2icI4glYaNG+KWONODapy2/jDdMSDnrONSjblABjD9B4Z5LgiircSt8m8sRZFNi08kG9Sm0uSHtEmP3zaEGg==", + "engines": { + "node": ">= 6" + } + } + }, "dependencies": { "@actions/core": { "version": "1.2.6", @@ -20,6 +55,11 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/@actions/io/-/io-1.0.2.tgz", "integrity": "sha512-J8KuFqVPr3p6U8W93DOXlXW6zFvrQAJANdS+vw0YhusLIq+bszW8zmK2Fh1C2kDPX8FMvwIl1OUcFgvJoXLbAg==" + }, + "yaml": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-1.10.0.tgz", + "integrity": "sha512-yr2icI4glYaNG+KWONODapy2/jDdMSDnrONSjblABjD9B4Z5LgiircSt8m8sRZFNi08kG9Sm0uSHtEmP3zaEGg==" } } } diff --git a/package.json b/package.json index d85084e..1851331 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "main": "main.js", "dependencies": { "@actions/core": "^1.2.6", - "@actions/exec": "^1.0.4" + "@actions/exec": "^1.0.4", + "yaml": "^1.10.0" } }