|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275 |
- 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 {
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], 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 _createSuperInternal() {
- 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, allowArrayLike) {
- var it;
-
- if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
- if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
- if (it) o = it;
- 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 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 () {
- 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;
- }
- }], [{
- key: "copy",
- value: function copy(orig) {
- return new Range(orig.start, orig.end);
- }
- }]);
-
- return Range;
- }();
-
- /** Root class of all nodes */
-
- var Node = /*#__PURE__*/function () {
- 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: "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: "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: "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];
- var 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;
- }
- }, {
- 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: "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
- };
- }
- }]);
-
- 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: "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: "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: "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 };
|