errors-2634d01a.js 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099
  1. function _typeof(obj) {
  2. "@babel/helpers - typeof";
  3. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  4. _typeof = function (obj) {
  5. return typeof obj;
  6. };
  7. } else {
  8. _typeof = function (obj) {
  9. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  10. };
  11. }
  12. return _typeof(obj);
  13. }
  14. function _classCallCheck(instance, Constructor) {
  15. if (!(instance instanceof Constructor)) {
  16. throw new TypeError("Cannot call a class as a function");
  17. }
  18. }
  19. function _defineProperties(target, props) {
  20. for (var i = 0; i < props.length; i++) {
  21. var descriptor = props[i];
  22. descriptor.enumerable = descriptor.enumerable || false;
  23. descriptor.configurable = true;
  24. if ("value" in descriptor) descriptor.writable = true;
  25. Object.defineProperty(target, descriptor.key, descriptor);
  26. }
  27. }
  28. function _createClass(Constructor, protoProps, staticProps) {
  29. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  30. if (staticProps) _defineProperties(Constructor, staticProps);
  31. return Constructor;
  32. }
  33. function _defineProperty(obj, key, value) {
  34. if (key in obj) {
  35. Object.defineProperty(obj, key, {
  36. value: value,
  37. enumerable: true,
  38. configurable: true,
  39. writable: true
  40. });
  41. } else {
  42. obj[key] = value;
  43. }
  44. return obj;
  45. }
  46. function _inherits(subClass, superClass) {
  47. if (typeof superClass !== "function" && superClass !== null) {
  48. throw new TypeError("Super expression must either be null or a function");
  49. }
  50. subClass.prototype = Object.create(superClass && superClass.prototype, {
  51. constructor: {
  52. value: subClass,
  53. writable: true,
  54. configurable: true
  55. }
  56. });
  57. if (superClass) _setPrototypeOf(subClass, superClass);
  58. }
  59. function _getPrototypeOf(o) {
  60. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  61. return o.__proto__ || Object.getPrototypeOf(o);
  62. };
  63. return _getPrototypeOf(o);
  64. }
  65. function _setPrototypeOf(o, p) {
  66. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  67. o.__proto__ = p;
  68. return o;
  69. };
  70. return _setPrototypeOf(o, p);
  71. }
  72. function _isNativeReflectConstruct() {
  73. if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  74. if (Reflect.construct.sham) return false;
  75. if (typeof Proxy === "function") return true;
  76. try {
  77. Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
  78. return true;
  79. } catch (e) {
  80. return false;
  81. }
  82. }
  83. function _construct(Parent, args, Class) {
  84. if (_isNativeReflectConstruct()) {
  85. _construct = Reflect.construct;
  86. } else {
  87. _construct = function _construct(Parent, args, Class) {
  88. var a = [null];
  89. a.push.apply(a, args);
  90. var Constructor = Function.bind.apply(Parent, a);
  91. var instance = new Constructor();
  92. if (Class) _setPrototypeOf(instance, Class.prototype);
  93. return instance;
  94. };
  95. }
  96. return _construct.apply(null, arguments);
  97. }
  98. function _isNativeFunction(fn) {
  99. return Function.toString.call(fn).indexOf("[native code]") !== -1;
  100. }
  101. function _wrapNativeSuper(Class) {
  102. var _cache = typeof Map === "function" ? new Map() : undefined;
  103. _wrapNativeSuper = function _wrapNativeSuper(Class) {
  104. if (Class === null || !_isNativeFunction(Class)) return Class;
  105. if (typeof Class !== "function") {
  106. throw new TypeError("Super expression must either be null or a function");
  107. }
  108. if (typeof _cache !== "undefined") {
  109. if (_cache.has(Class)) return _cache.get(Class);
  110. _cache.set(Class, Wrapper);
  111. }
  112. function Wrapper() {
  113. return _construct(Class, arguments, _getPrototypeOf(this).constructor);
  114. }
  115. Wrapper.prototype = Object.create(Class.prototype, {
  116. constructor: {
  117. value: Wrapper,
  118. enumerable: false,
  119. writable: true,
  120. configurable: true
  121. }
  122. });
  123. return _setPrototypeOf(Wrapper, Class);
  124. };
  125. return _wrapNativeSuper(Class);
  126. }
  127. function _assertThisInitialized(self) {
  128. if (self === void 0) {
  129. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  130. }
  131. return self;
  132. }
  133. function _possibleConstructorReturn(self, call) {
  134. if (call && (typeof call === "object" || typeof call === "function")) {
  135. return call;
  136. }
  137. return _assertThisInitialized(self);
  138. }
  139. function _createSuper(Derived) {
  140. var hasNativeReflectConstruct = _isNativeReflectConstruct();
  141. return function _createSuperInternal() {
  142. var Super = _getPrototypeOf(Derived),
  143. result;
  144. if (hasNativeReflectConstruct) {
  145. var NewTarget = _getPrototypeOf(this).constructor;
  146. result = Reflect.construct(Super, arguments, NewTarget);
  147. } else {
  148. result = Super.apply(this, arguments);
  149. }
  150. return _possibleConstructorReturn(this, result);
  151. };
  152. }
  153. function _superPropBase(object, property) {
  154. while (!Object.prototype.hasOwnProperty.call(object, property)) {
  155. object = _getPrototypeOf(object);
  156. if (object === null) break;
  157. }
  158. return object;
  159. }
  160. function _get(target, property, receiver) {
  161. if (typeof Reflect !== "undefined" && Reflect.get) {
  162. _get = Reflect.get;
  163. } else {
  164. _get = function _get(target, property, receiver) {
  165. var base = _superPropBase(target, property);
  166. if (!base) return;
  167. var desc = Object.getOwnPropertyDescriptor(base, property);
  168. if (desc.get) {
  169. return desc.get.call(receiver);
  170. }
  171. return desc.value;
  172. };
  173. }
  174. return _get(target, property, receiver || target);
  175. }
  176. function _slicedToArray(arr, i) {
  177. return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
  178. }
  179. function _toArray(arr) {
  180. return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest();
  181. }
  182. function _arrayWithHoles(arr) {
  183. if (Array.isArray(arr)) return arr;
  184. }
  185. function _iterableToArray(iter) {
  186. if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
  187. }
  188. function _iterableToArrayLimit(arr, i) {
  189. if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
  190. var _arr = [];
  191. var _n = true;
  192. var _d = false;
  193. var _e = undefined;
  194. try {
  195. for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
  196. _arr.push(_s.value);
  197. if (i && _arr.length === i) break;
  198. }
  199. } catch (err) {
  200. _d = true;
  201. _e = err;
  202. } finally {
  203. try {
  204. if (!_n && _i["return"] != null) _i["return"]();
  205. } finally {
  206. if (_d) throw _e;
  207. }
  208. }
  209. return _arr;
  210. }
  211. function _unsupportedIterableToArray(o, minLen) {
  212. if (!o) return;
  213. if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  214. var n = Object.prototype.toString.call(o).slice(8, -1);
  215. if (n === "Object" && o.constructor) n = o.constructor.name;
  216. if (n === "Map" || n === "Set") return Array.from(o);
  217. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
  218. }
  219. function _arrayLikeToArray(arr, len) {
  220. if (len == null || len > arr.length) len = arr.length;
  221. for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
  222. return arr2;
  223. }
  224. function _nonIterableRest() {
  225. throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  226. }
  227. function _createForOfIteratorHelper(o, allowArrayLike) {
  228. var it;
  229. if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
  230. if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
  231. if (it) o = it;
  232. var i = 0;
  233. var F = function () {};
  234. return {
  235. s: F,
  236. n: function () {
  237. if (i >= o.length) return {
  238. done: true
  239. };
  240. return {
  241. done: false,
  242. value: o[i++]
  243. };
  244. },
  245. e: function (e) {
  246. throw e;
  247. },
  248. f: F
  249. };
  250. }
  251. throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  252. }
  253. var normalCompletion = true,
  254. didErr = false,
  255. err;
  256. return {
  257. s: function () {
  258. it = o[Symbol.iterator]();
  259. },
  260. n: function () {
  261. var step = it.next();
  262. normalCompletion = step.done;
  263. return step;
  264. },
  265. e: function (e) {
  266. didErr = true;
  267. err = e;
  268. },
  269. f: function () {
  270. try {
  271. if (!normalCompletion && it.return != null) it.return();
  272. } finally {
  273. if (didErr) throw err;
  274. }
  275. }
  276. };
  277. }
  278. var Char = {
  279. ANCHOR: '&',
  280. COMMENT: '#',
  281. TAG: '!',
  282. DIRECTIVES_END: '-',
  283. DOCUMENT_END: '.'
  284. };
  285. var Type = {
  286. ALIAS: 'ALIAS',
  287. BLANK_LINE: 'BLANK_LINE',
  288. BLOCK_FOLDED: 'BLOCK_FOLDED',
  289. BLOCK_LITERAL: 'BLOCK_LITERAL',
  290. COMMENT: 'COMMENT',
  291. DIRECTIVE: 'DIRECTIVE',
  292. DOCUMENT: 'DOCUMENT',
  293. FLOW_MAP: 'FLOW_MAP',
  294. FLOW_SEQ: 'FLOW_SEQ',
  295. MAP: 'MAP',
  296. MAP_KEY: 'MAP_KEY',
  297. MAP_VALUE: 'MAP_VALUE',
  298. PLAIN: 'PLAIN',
  299. QUOTE_DOUBLE: 'QUOTE_DOUBLE',
  300. QUOTE_SINGLE: 'QUOTE_SINGLE',
  301. SEQ: 'SEQ',
  302. SEQ_ITEM: 'SEQ_ITEM'
  303. };
  304. var defaultTagPrefix = 'tag:yaml.org,2002:';
  305. var defaultTags = {
  306. MAP: 'tag:yaml.org,2002:map',
  307. SEQ: 'tag:yaml.org,2002:seq',
  308. STR: 'tag:yaml.org,2002:str'
  309. };
  310. function findLineStarts(src) {
  311. var ls = [0];
  312. var offset = src.indexOf('\n');
  313. while (offset !== -1) {
  314. offset += 1;
  315. ls.push(offset);
  316. offset = src.indexOf('\n', offset);
  317. }
  318. return ls;
  319. }
  320. function getSrcInfo(cst) {
  321. var lineStarts, src;
  322. if (typeof cst === 'string') {
  323. lineStarts = findLineStarts(cst);
  324. src = cst;
  325. } else {
  326. if (Array.isArray(cst)) cst = cst[0];
  327. if (cst && cst.context) {
  328. if (!cst.lineStarts) cst.lineStarts = findLineStarts(cst.context.src);
  329. lineStarts = cst.lineStarts;
  330. src = cst.context.src;
  331. }
  332. }
  333. return {
  334. lineStarts: lineStarts,
  335. src: src
  336. };
  337. }
  338. /**
  339. * @typedef {Object} LinePos - One-indexed position in the source
  340. * @property {number} line
  341. * @property {number} col
  342. */
  343. /**
  344. * Determine the line/col position matching a character offset.
  345. *
  346. * Accepts a source string or a CST document as the second parameter. With
  347. * the latter, starting indices for lines are cached in the document as
  348. * `lineStarts: number[]`.
  349. *
  350. * Returns a one-indexed `{ line, col }` location if found, or
  351. * `undefined` otherwise.
  352. *
  353. * @param {number} offset
  354. * @param {string|Document|Document[]} cst
  355. * @returns {?LinePos}
  356. */
  357. function getLinePos(offset, cst) {
  358. if (typeof offset !== 'number' || offset < 0) return null;
  359. var _getSrcInfo = getSrcInfo(cst),
  360. lineStarts = _getSrcInfo.lineStarts,
  361. src = _getSrcInfo.src;
  362. if (!lineStarts || !src || offset > src.length) return null;
  363. for (var i = 0; i < lineStarts.length; ++i) {
  364. var start = lineStarts[i];
  365. if (offset < start) {
  366. return {
  367. line: i,
  368. col: offset - lineStarts[i - 1] + 1
  369. };
  370. }
  371. if (offset === start) return {
  372. line: i + 1,
  373. col: 1
  374. };
  375. }
  376. var line = lineStarts.length;
  377. return {
  378. line: line,
  379. col: offset - lineStarts[line - 1] + 1
  380. };
  381. }
  382. /**
  383. * Get a specified line from the source.
  384. *
  385. * Accepts a source string or a CST document as the second parameter. With
  386. * the latter, starting indices for lines are cached in the document as
  387. * `lineStarts: number[]`.
  388. *
  389. * Returns the line as a string if found, or `null` otherwise.
  390. *
  391. * @param {number} line One-indexed line number
  392. * @param {string|Document|Document[]} cst
  393. * @returns {?string}
  394. */
  395. function getLine(line, cst) {
  396. var _getSrcInfo2 = getSrcInfo(cst),
  397. lineStarts = _getSrcInfo2.lineStarts,
  398. src = _getSrcInfo2.src;
  399. if (!lineStarts || !(line >= 1) || line > lineStarts.length) return null;
  400. var start = lineStarts[line - 1];
  401. var end = lineStarts[line]; // undefined for last line; that's ok for slice()
  402. while (end && end > start && src[end - 1] === '\n') {
  403. --end;
  404. }
  405. return src.slice(start, end);
  406. }
  407. /**
  408. * Pretty-print the starting line from the source indicated by the range `pos`
  409. *
  410. * Trims output to `maxWidth` chars while keeping the starting column visible,
  411. * using `…` at either end to indicate dropped characters.
  412. *
  413. * Returns a two-line string (or `null`) with `\n` as separator; the second line
  414. * will hold appropriately indented `^` marks indicating the column range.
  415. *
  416. * @param {Object} pos
  417. * @param {LinePos} pos.start
  418. * @param {LinePos} [pos.end]
  419. * @param {string|Document|Document[]*} cst
  420. * @param {number} [maxWidth=80]
  421. * @returns {?string}
  422. */
  423. function getPrettyContext(_ref, cst) {
  424. var start = _ref.start,
  425. end = _ref.end;
  426. var maxWidth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 80;
  427. var src = getLine(start.line, cst);
  428. if (!src) return null;
  429. var col = start.col;
  430. if (src.length > maxWidth) {
  431. if (col <= maxWidth - 10) {
  432. src = src.substr(0, maxWidth - 1) + '…';
  433. } else {
  434. var halfWidth = Math.round(maxWidth / 2);
  435. if (src.length > col + halfWidth) src = src.substr(0, col + halfWidth - 1) + '…';
  436. col -= src.length - maxWidth;
  437. src = '…' + src.substr(1 - maxWidth);
  438. }
  439. }
  440. var errLen = 1;
  441. var errEnd = '';
  442. if (end) {
  443. if (end.line === start.line && col + (end.col - start.col) <= maxWidth + 1) {
  444. errLen = end.col - start.col;
  445. } else {
  446. errLen = Math.min(src.length + 1, maxWidth) - col;
  447. errEnd = '…';
  448. }
  449. }
  450. var offset = col > 1 ? ' '.repeat(col - 1) : '';
  451. var err = '^'.repeat(errLen);
  452. return "".concat(src, "\n").concat(offset).concat(err).concat(errEnd);
  453. }
  454. var Range = /*#__PURE__*/function () {
  455. _createClass(Range, null, [{
  456. key: "copy",
  457. value: function copy(orig) {
  458. return new Range(orig.start, orig.end);
  459. }
  460. }]);
  461. function Range(start, end) {
  462. _classCallCheck(this, Range);
  463. this.start = start;
  464. this.end = end || start;
  465. }
  466. _createClass(Range, [{
  467. key: "isEmpty",
  468. value: function isEmpty() {
  469. return typeof this.start !== 'number' || !this.end || this.end <= this.start;
  470. }
  471. /**
  472. * Set `origStart` and `origEnd` to point to the original source range for
  473. * this node, which may differ due to dropped CR characters.
  474. *
  475. * @param {number[]} cr - Positions of dropped CR characters
  476. * @param {number} offset - Starting index of `cr` from the last call
  477. * @returns {number} - The next offset, matching the one found for `origStart`
  478. */
  479. }, {
  480. key: "setOrigRange",
  481. value: function setOrigRange(cr, offset) {
  482. var start = this.start,
  483. end = this.end;
  484. if (cr.length === 0 || end <= cr[0]) {
  485. this.origStart = start;
  486. this.origEnd = end;
  487. return offset;
  488. }
  489. var i = offset;
  490. while (i < cr.length) {
  491. if (cr[i] > start) break;else ++i;
  492. }
  493. this.origStart = start + i;
  494. var nextOffset = i;
  495. while (i < cr.length) {
  496. // if end was at \n, it should now be at \r
  497. if (cr[i] >= end) break;else ++i;
  498. }
  499. this.origEnd = end + i;
  500. return nextOffset;
  501. }
  502. }]);
  503. return Range;
  504. }();
  505. /** Root class of all nodes */
  506. var Node = /*#__PURE__*/function () {
  507. _createClass(Node, null, [{
  508. key: "addStringTerminator",
  509. value: function addStringTerminator(src, offset, str) {
  510. if (str[str.length - 1] === '\n') return str;
  511. var next = Node.endOfWhiteSpace(src, offset);
  512. return next >= src.length || src[next] === '\n' ? str + '\n' : str;
  513. } // ^(---|...)
  514. }, {
  515. key: "atDocumentBoundary",
  516. value: function atDocumentBoundary(src, offset, sep) {
  517. var ch0 = src[offset];
  518. if (!ch0) return true;
  519. var prev = src[offset - 1];
  520. if (prev && prev !== '\n') return false;
  521. if (sep) {
  522. if (ch0 !== sep) return false;
  523. } else {
  524. if (ch0 !== Char.DIRECTIVES_END && ch0 !== Char.DOCUMENT_END) return false;
  525. }
  526. var ch1 = src[offset + 1];
  527. var ch2 = src[offset + 2];
  528. if (ch1 !== ch0 || ch2 !== ch0) return false;
  529. var ch3 = src[offset + 3];
  530. return !ch3 || ch3 === '\n' || ch3 === '\t' || ch3 === ' ';
  531. }
  532. }, {
  533. key: "endOfIdentifier",
  534. value: function endOfIdentifier(src, offset) {
  535. var ch = src[offset];
  536. var isVerbatim = ch === '<';
  537. var notOk = isVerbatim ? ['\n', '\t', ' ', '>'] : ['\n', '\t', ' ', '[', ']', '{', '}', ','];
  538. while (ch && notOk.indexOf(ch) === -1) {
  539. ch = src[offset += 1];
  540. }
  541. if (isVerbatim && ch === '>') offset += 1;
  542. return offset;
  543. }
  544. }, {
  545. key: "endOfIndent",
  546. value: function endOfIndent(src, offset) {
  547. var ch = src[offset];
  548. while (ch === ' ') {
  549. ch = src[offset += 1];
  550. }
  551. return offset;
  552. }
  553. }, {
  554. key: "endOfLine",
  555. value: function endOfLine(src, offset) {
  556. var ch = src[offset];
  557. while (ch && ch !== '\n') {
  558. ch = src[offset += 1];
  559. }
  560. return offset;
  561. }
  562. }, {
  563. key: "endOfWhiteSpace",
  564. value: function endOfWhiteSpace(src, offset) {
  565. var ch = src[offset];
  566. while (ch === '\t' || ch === ' ') {
  567. ch = src[offset += 1];
  568. }
  569. return offset;
  570. }
  571. }, {
  572. key: "startOfLine",
  573. value: function startOfLine(src, offset) {
  574. var ch = src[offset - 1];
  575. if (ch === '\n') return offset;
  576. while (ch && ch !== '\n') {
  577. ch = src[offset -= 1];
  578. }
  579. return offset + 1;
  580. }
  581. /**
  582. * End of indentation, or null if the line's indent level is not more
  583. * than `indent`
  584. *
  585. * @param {string} src
  586. * @param {number} indent
  587. * @param {number} lineStart
  588. * @returns {?number}
  589. */
  590. }, {
  591. key: "endOfBlockIndent",
  592. value: function endOfBlockIndent(src, indent, lineStart) {
  593. var inEnd = Node.endOfIndent(src, lineStart);
  594. if (inEnd > lineStart + indent) {
  595. return inEnd;
  596. } else {
  597. var wsEnd = Node.endOfWhiteSpace(src, inEnd);
  598. var ch = src[wsEnd];
  599. if (!ch || ch === '\n') return wsEnd;
  600. }
  601. return null;
  602. }
  603. }, {
  604. key: "atBlank",
  605. value: function atBlank(src, offset, endAsBlank) {
  606. var ch = src[offset];
  607. return ch === '\n' || ch === '\t' || ch === ' ' || endAsBlank && !ch;
  608. }
  609. }, {
  610. key: "nextNodeIsIndented",
  611. value: function nextNodeIsIndented(ch, indentDiff, indicatorAsIndent) {
  612. if (!ch || indentDiff < 0) return false;
  613. if (indentDiff > 0) return true;
  614. return indicatorAsIndent && ch === '-';
  615. } // should be at line or string end, or at next non-whitespace char
  616. }, {
  617. key: "normalizeOffset",
  618. value: function normalizeOffset(src, offset) {
  619. var ch = src[offset];
  620. return !ch ? offset : ch !== '\n' && src[offset - 1] === '\n' ? offset - 1 : Node.endOfWhiteSpace(src, offset);
  621. } // fold single newline into space, multiple newlines to N - 1 newlines
  622. // presumes src[offset] === '\n'
  623. }, {
  624. key: "foldNewline",
  625. value: function foldNewline(src, offset, indent) {
  626. var inCount = 0;
  627. var error = false;
  628. var fold = '';
  629. var ch = src[offset + 1];
  630. while (ch === ' ' || ch === '\t' || ch === '\n') {
  631. switch (ch) {
  632. case '\n':
  633. inCount = 0;
  634. offset += 1;
  635. fold += '\n';
  636. break;
  637. case '\t':
  638. if (inCount <= indent) error = true;
  639. offset = Node.endOfWhiteSpace(src, offset + 2) - 1;
  640. break;
  641. case ' ':
  642. inCount += 1;
  643. offset += 1;
  644. break;
  645. }
  646. ch = src[offset + 1];
  647. }
  648. if (!fold) fold = ' ';
  649. if (ch && inCount <= indent) error = true;
  650. return {
  651. fold: fold,
  652. offset: offset,
  653. error: error
  654. };
  655. }
  656. }]);
  657. function Node(type, props, context) {
  658. _classCallCheck(this, Node);
  659. Object.defineProperty(this, 'context', {
  660. value: context || null,
  661. writable: true
  662. });
  663. this.error = null;
  664. this.range = null;
  665. this.valueRange = null;
  666. this.props = props || [];
  667. this.type = type;
  668. this.value = null;
  669. }
  670. _createClass(Node, [{
  671. key: "getPropValue",
  672. value: function getPropValue(idx, key, skipKey) {
  673. if (!this.context) return null;
  674. var src = this.context.src;
  675. var prop = this.props[idx];
  676. return prop && src[prop.start] === key ? src.slice(prop.start + (skipKey ? 1 : 0), prop.end) : null;
  677. }
  678. }, {
  679. key: "commentHasRequiredWhitespace",
  680. value: function commentHasRequiredWhitespace(start) {
  681. var src = this.context.src;
  682. if (this.header && start === this.header.end) return false;
  683. if (!this.valueRange) return false;
  684. var end = this.valueRange.end;
  685. return start !== end || Node.atBlank(src, end - 1);
  686. }
  687. }, {
  688. key: "parseComment",
  689. value: function parseComment(start) {
  690. var src = this.context.src;
  691. if (src[start] === Char.COMMENT) {
  692. var end = Node.endOfLine(src, start + 1);
  693. var commentRange = new Range(start, end);
  694. this.props.push(commentRange);
  695. return end;
  696. }
  697. return start;
  698. }
  699. /**
  700. * Populates the `origStart` and `origEnd` values of all ranges for this
  701. * node. Extended by child classes to handle descendant nodes.
  702. *
  703. * @param {number[]} cr - Positions of dropped CR characters
  704. * @param {number} offset - Starting index of `cr` from the last call
  705. * @returns {number} - The next offset, matching the one found for `origStart`
  706. */
  707. }, {
  708. key: "setOrigRanges",
  709. value: function setOrigRanges(cr, offset) {
  710. if (this.range) offset = this.range.setOrigRange(cr, offset);
  711. if (this.valueRange) this.valueRange.setOrigRange(cr, offset);
  712. this.props.forEach(function (prop) {
  713. return prop.setOrigRange(cr, offset);
  714. });
  715. return offset;
  716. }
  717. }, {
  718. key: "toString",
  719. value: function toString() {
  720. var src = this.context.src,
  721. range = this.range,
  722. value = this.value;
  723. if (value != null) return value;
  724. var str = src.slice(range.start, range.end);
  725. return Node.addStringTerminator(src, range.end, str);
  726. }
  727. }, {
  728. key: "anchor",
  729. get: function get() {
  730. for (var i = 0; i < this.props.length; ++i) {
  731. var anchor = this.getPropValue(i, Char.ANCHOR, true);
  732. if (anchor != null) return anchor;
  733. }
  734. return null;
  735. }
  736. }, {
  737. key: "comment",
  738. get: function get() {
  739. var comments = [];
  740. for (var i = 0; i < this.props.length; ++i) {
  741. var comment = this.getPropValue(i, Char.COMMENT, true);
  742. if (comment != null) comments.push(comment);
  743. }
  744. return comments.length > 0 ? comments.join('\n') : null;
  745. }
  746. }, {
  747. key: "hasComment",
  748. get: function get() {
  749. if (this.context) {
  750. var src = this.context.src;
  751. for (var i = 0; i < this.props.length; ++i) {
  752. if (src[this.props[i].start] === Char.COMMENT) return true;
  753. }
  754. }
  755. return false;
  756. }
  757. }, {
  758. key: "hasProps",
  759. get: function get() {
  760. if (this.context) {
  761. var src = this.context.src;
  762. for (var i = 0; i < this.props.length; ++i) {
  763. if (src[this.props[i].start] !== Char.COMMENT) return true;
  764. }
  765. }
  766. return false;
  767. }
  768. }, {
  769. key: "includesTrailingLines",
  770. get: function get() {
  771. return false;
  772. }
  773. }, {
  774. key: "jsonLike",
  775. get: function get() {
  776. var jsonLikeTypes = [Type.FLOW_MAP, Type.FLOW_SEQ, Type.QUOTE_DOUBLE, Type.QUOTE_SINGLE];
  777. return jsonLikeTypes.indexOf(this.type) !== -1;
  778. }
  779. }, {
  780. key: "rangeAsLinePos",
  781. get: function get() {
  782. if (!this.range || !this.context) return undefined;
  783. var start = getLinePos(this.range.start, this.context.root);
  784. if (!start) return undefined;
  785. var end = getLinePos(this.range.end, this.context.root);
  786. return {
  787. start: start,
  788. end: end
  789. };
  790. }
  791. }, {
  792. key: "rawValue",
  793. get: function get() {
  794. if (!this.valueRange || !this.context) return null;
  795. var _this$valueRange = this.valueRange,
  796. start = _this$valueRange.start,
  797. end = _this$valueRange.end;
  798. return this.context.src.slice(start, end);
  799. }
  800. }, {
  801. key: "tag",
  802. get: function get() {
  803. for (var i = 0; i < this.props.length; ++i) {
  804. var tag = this.getPropValue(i, Char.TAG, false);
  805. if (tag != null) {
  806. if (tag[1] === '<') {
  807. return {
  808. verbatim: tag.slice(2, -1)
  809. };
  810. } else {
  811. // eslint-disable-next-line no-unused-vars
  812. var _tag$match = tag.match(/^(.*!)([^!]*)$/),
  813. _tag$match2 = _slicedToArray(_tag$match, 3),
  814. _ = _tag$match2[0],
  815. handle = _tag$match2[1],
  816. suffix = _tag$match2[2];
  817. return {
  818. handle: handle,
  819. suffix: suffix
  820. };
  821. }
  822. }
  823. }
  824. return null;
  825. }
  826. }, {
  827. key: "valueRangeContainsNewline",
  828. get: function get() {
  829. if (!this.valueRange || !this.context) return false;
  830. var _this$valueRange2 = this.valueRange,
  831. start = _this$valueRange2.start,
  832. end = _this$valueRange2.end;
  833. var src = this.context.src;
  834. for (var i = start; i < end; ++i) {
  835. if (src[i] === '\n') return true;
  836. }
  837. return false;
  838. }
  839. }]);
  840. return Node;
  841. }();
  842. var YAMLError = /*#__PURE__*/function (_Error) {
  843. _inherits(YAMLError, _Error);
  844. var _super = _createSuper(YAMLError);
  845. function YAMLError(name, source, message) {
  846. var _this;
  847. _classCallCheck(this, YAMLError);
  848. if (!message || !(source instanceof Node)) throw new Error("Invalid arguments for new ".concat(name));
  849. _this = _super.call(this);
  850. _this.name = name;
  851. _this.message = message;
  852. _this.source = source;
  853. return _this;
  854. }
  855. _createClass(YAMLError, [{
  856. key: "makePretty",
  857. value: function makePretty() {
  858. if (!this.source) return;
  859. this.nodeType = this.source.type;
  860. var cst = this.source.context && this.source.context.root;
  861. if (typeof this.offset === 'number') {
  862. this.range = new Range(this.offset, this.offset + 1);
  863. var start = cst && getLinePos(this.offset, cst);
  864. if (start) {
  865. var end = {
  866. line: start.line,
  867. col: start.col + 1
  868. };
  869. this.linePos = {
  870. start: start,
  871. end: end
  872. };
  873. }
  874. delete this.offset;
  875. } else {
  876. this.range = this.source.range;
  877. this.linePos = this.source.rangeAsLinePos;
  878. }
  879. if (this.linePos) {
  880. var _this$linePos$start = this.linePos.start,
  881. line = _this$linePos$start.line,
  882. col = _this$linePos$start.col;
  883. this.message += " at line ".concat(line, ", column ").concat(col);
  884. var ctx = cst && getPrettyContext(this.linePos, cst);
  885. if (ctx) this.message += ":\n\n".concat(ctx, "\n");
  886. }
  887. delete this.source;
  888. }
  889. }]);
  890. return YAMLError;
  891. }( /*#__PURE__*/_wrapNativeSuper(Error));
  892. var YAMLReferenceError = /*#__PURE__*/function (_YAMLError) {
  893. _inherits(YAMLReferenceError, _YAMLError);
  894. var _super2 = _createSuper(YAMLReferenceError);
  895. function YAMLReferenceError(source, message) {
  896. _classCallCheck(this, YAMLReferenceError);
  897. return _super2.call(this, 'YAMLReferenceError', source, message);
  898. }
  899. return YAMLReferenceError;
  900. }(YAMLError);
  901. var YAMLSemanticError = /*#__PURE__*/function (_YAMLError2) {
  902. _inherits(YAMLSemanticError, _YAMLError2);
  903. var _super3 = _createSuper(YAMLSemanticError);
  904. function YAMLSemanticError(source, message) {
  905. _classCallCheck(this, YAMLSemanticError);
  906. return _super3.call(this, 'YAMLSemanticError', source, message);
  907. }
  908. return YAMLSemanticError;
  909. }(YAMLError);
  910. var YAMLSyntaxError = /*#__PURE__*/function (_YAMLError3) {
  911. _inherits(YAMLSyntaxError, _YAMLError3);
  912. var _super4 = _createSuper(YAMLSyntaxError);
  913. function YAMLSyntaxError(source, message) {
  914. _classCallCheck(this, YAMLSyntaxError);
  915. return _super4.call(this, 'YAMLSyntaxError', source, message);
  916. }
  917. return YAMLSyntaxError;
  918. }(YAMLError);
  919. var YAMLWarning = /*#__PURE__*/function (_YAMLError4) {
  920. _inherits(YAMLWarning, _YAMLError4);
  921. var _super5 = _createSuper(YAMLWarning);
  922. function YAMLWarning(source, message) {
  923. _classCallCheck(this, YAMLWarning);
  924. return _super5.call(this, 'YAMLWarning', source, message);
  925. }
  926. return YAMLWarning;
  927. }(YAMLError);
  928. export { Char as C, Node as N, Range as R, Type as T, YAMLSemanticError as Y, _typeof as _, _createClass as a, _classCallCheck as b, _defineProperty as c, defaultTagPrefix as d, _slicedToArray as e, defaultTags as f, YAMLWarning as g, _createForOfIteratorHelper as h, YAMLSyntaxError as i, YAMLReferenceError as j, YAMLError as k, _inherits as l, _createSuper as m, _get as n, _getPrototypeOf as o, _assertThisInitialized as p, _toArray as q, _possibleConstructorReturn as r };