PlainValue-ff5147c6.js 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277
  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 () {
  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) {
  228. if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
  229. if (Array.isArray(o) || (o = _unsupportedIterableToArray(o))) {
  230. var i = 0;
  231. var F = function () {};
  232. return {
  233. s: F,
  234. n: function () {
  235. if (i >= o.length) return {
  236. done: true
  237. };
  238. return {
  239. done: false,
  240. value: o[i++]
  241. };
  242. },
  243. e: function (e) {
  244. throw e;
  245. },
  246. f: F
  247. };
  248. }
  249. throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  250. }
  251. var it,
  252. normalCompletion = true,
  253. didErr = false,
  254. err;
  255. return {
  256. s: function () {
  257. it = o[Symbol.iterator]();
  258. },
  259. n: function () {
  260. var step = it.next();
  261. normalCompletion = step.done;
  262. return step;
  263. },
  264. e: function (e) {
  265. didErr = true;
  266. err = e;
  267. },
  268. f: function () {
  269. try {
  270. if (!normalCompletion && it.return != null) it.return();
  271. } finally {
  272. if (didErr) throw err;
  273. }
  274. }
  275. };
  276. }
  277. var Char = {
  278. ANCHOR: '&',
  279. COMMENT: '#',
  280. TAG: '!',
  281. DIRECTIVES_END: '-',
  282. DOCUMENT_END: '.'
  283. };
  284. var Type = {
  285. ALIAS: 'ALIAS',
  286. BLANK_LINE: 'BLANK_LINE',
  287. BLOCK_FOLDED: 'BLOCK_FOLDED',
  288. BLOCK_LITERAL: 'BLOCK_LITERAL',
  289. COMMENT: 'COMMENT',
  290. DIRECTIVE: 'DIRECTIVE',
  291. DOCUMENT: 'DOCUMENT',
  292. FLOW_MAP: 'FLOW_MAP',
  293. FLOW_SEQ: 'FLOW_SEQ',
  294. MAP: 'MAP',
  295. MAP_KEY: 'MAP_KEY',
  296. MAP_VALUE: 'MAP_VALUE',
  297. PLAIN: 'PLAIN',
  298. QUOTE_DOUBLE: 'QUOTE_DOUBLE',
  299. QUOTE_SINGLE: 'QUOTE_SINGLE',
  300. SEQ: 'SEQ',
  301. SEQ_ITEM: 'SEQ_ITEM'
  302. };
  303. var defaultTagPrefix = 'tag:yaml.org,2002:';
  304. var defaultTags = {
  305. MAP: 'tag:yaml.org,2002:map',
  306. SEQ: 'tag:yaml.org,2002:seq',
  307. STR: 'tag:yaml.org,2002:str'
  308. };
  309. function findLineStarts(src) {
  310. var ls = [0];
  311. var offset = src.indexOf('\n');
  312. while (offset !== -1) {
  313. offset += 1;
  314. ls.push(offset);
  315. offset = src.indexOf('\n', offset);
  316. }
  317. return ls;
  318. }
  319. function getSrcInfo(cst) {
  320. var lineStarts, src;
  321. if (typeof cst === 'string') {
  322. lineStarts = findLineStarts(cst);
  323. src = cst;
  324. } else {
  325. if (Array.isArray(cst)) cst = cst[0];
  326. if (cst && cst.context) {
  327. if (!cst.lineStarts) cst.lineStarts = findLineStarts(cst.context.src);
  328. lineStarts = cst.lineStarts;
  329. src = cst.context.src;
  330. }
  331. }
  332. return {
  333. lineStarts: lineStarts,
  334. src: src
  335. };
  336. }
  337. /**
  338. * @typedef {Object} LinePos - One-indexed position in the source
  339. * @property {number} line
  340. * @property {number} col
  341. */
  342. /**
  343. * Determine the line/col position matching a character offset.
  344. *
  345. * Accepts a source string or a CST document as the second parameter. With
  346. * the latter, starting indices for lines are cached in the document as
  347. * `lineStarts: number[]`.
  348. *
  349. * Returns a one-indexed `{ line, col }` location if found, or
  350. * `undefined` otherwise.
  351. *
  352. * @param {number} offset
  353. * @param {string|Document|Document[]} cst
  354. * @returns {?LinePos}
  355. */
  356. function getLinePos(offset, cst) {
  357. if (typeof offset !== 'number' || offset < 0) return null;
  358. var _getSrcInfo = getSrcInfo(cst),
  359. lineStarts = _getSrcInfo.lineStarts,
  360. src = _getSrcInfo.src;
  361. if (!lineStarts || !src || offset > src.length) return null;
  362. for (var i = 0; i < lineStarts.length; ++i) {
  363. var start = lineStarts[i];
  364. if (offset < start) {
  365. return {
  366. line: i,
  367. col: offset - lineStarts[i - 1] + 1
  368. };
  369. }
  370. if (offset === start) return {
  371. line: i + 1,
  372. col: 1
  373. };
  374. }
  375. var line = lineStarts.length;
  376. return {
  377. line: line,
  378. col: offset - lineStarts[line - 1] + 1
  379. };
  380. }
  381. /**
  382. * Get a specified line from the source.
  383. *
  384. * Accepts a source string or a CST document as the second parameter. With
  385. * the latter, starting indices for lines are cached in the document as
  386. * `lineStarts: number[]`.
  387. *
  388. * Returns the line as a string if found, or `null` otherwise.
  389. *
  390. * @param {number} line One-indexed line number
  391. * @param {string|Document|Document[]} cst
  392. * @returns {?string}
  393. */
  394. function getLine(line, cst) {
  395. var _getSrcInfo2 = getSrcInfo(cst),
  396. lineStarts = _getSrcInfo2.lineStarts,
  397. src = _getSrcInfo2.src;
  398. if (!lineStarts || !(line >= 1) || line > lineStarts.length) return null;
  399. var start = lineStarts[line - 1];
  400. var end = lineStarts[line]; // undefined for last line; that's ok for slice()
  401. while (end && end > start && src[end - 1] === '\n') {
  402. --end;
  403. }
  404. return src.slice(start, end);
  405. }
  406. /**
  407. * Pretty-print the starting line from the source indicated by the range `pos`
  408. *
  409. * Trims output to `maxWidth` chars while keeping the starting column visible,
  410. * using `…` at either end to indicate dropped characters.
  411. *
  412. * Returns a two-line string (or `null`) with `\n` as separator; the second line
  413. * will hold appropriately indented `^` marks indicating the column range.
  414. *
  415. * @param {Object} pos
  416. * @param {LinePos} pos.start
  417. * @param {LinePos} [pos.end]
  418. * @param {string|Document|Document[]*} cst
  419. * @param {number} [maxWidth=80]
  420. * @returns {?string}
  421. */
  422. function getPrettyContext(_ref, cst) {
  423. var start = _ref.start,
  424. end = _ref.end;
  425. var maxWidth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 80;
  426. var src = getLine(start.line, cst);
  427. if (!src) return null;
  428. var col = start.col;
  429. if (src.length > maxWidth) {
  430. if (col <= maxWidth - 10) {
  431. src = src.substr(0, maxWidth - 1) + '…';
  432. } else {
  433. var halfWidth = Math.round(maxWidth / 2);
  434. if (src.length > col + halfWidth) src = src.substr(0, col + halfWidth - 1) + '…';
  435. col -= src.length - maxWidth;
  436. src = '…' + src.substr(1 - maxWidth);
  437. }
  438. }
  439. var errLen = 1;
  440. var errEnd = '';
  441. if (end) {
  442. if (end.line === start.line && col + (end.col - start.col) <= maxWidth + 1) {
  443. errLen = end.col - start.col;
  444. } else {
  445. errLen = Math.min(src.length + 1, maxWidth) - col;
  446. errEnd = '…';
  447. }
  448. }
  449. var offset = col > 1 ? ' '.repeat(col - 1) : '';
  450. var err = '^'.repeat(errLen);
  451. return "".concat(src, "\n").concat(offset).concat(err).concat(errEnd);
  452. }
  453. var Range = /*#__PURE__*/function () {
  454. _createClass(Range, null, [{
  455. key: "copy",
  456. value: function copy(orig) {
  457. return new Range(orig.start, orig.end);
  458. }
  459. }]);
  460. function Range(start, end) {
  461. _classCallCheck(this, Range);
  462. this.start = start;
  463. this.end = end || start;
  464. }
  465. _createClass(Range, [{
  466. key: "isEmpty",
  467. value: function isEmpty() {
  468. return typeof this.start !== 'number' || !this.end || this.end <= this.start;
  469. }
  470. /**
  471. * Set `origStart` and `origEnd` to point to the original source range for
  472. * this node, which may differ due to dropped CR characters.
  473. *
  474. * @param {number[]} cr - Positions of dropped CR characters
  475. * @param {number} offset - Starting index of `cr` from the last call
  476. * @returns {number} - The next offset, matching the one found for `origStart`
  477. */
  478. }, {
  479. key: "setOrigRange",
  480. value: function setOrigRange(cr, offset) {
  481. var start = this.start,
  482. end = this.end;
  483. if (cr.length === 0 || end <= cr[0]) {
  484. this.origStart = start;
  485. this.origEnd = end;
  486. return offset;
  487. }
  488. var i = offset;
  489. while (i < cr.length) {
  490. if (cr[i] > start) break;else ++i;
  491. }
  492. this.origStart = start + i;
  493. var nextOffset = i;
  494. while (i < cr.length) {
  495. // if end was at \n, it should now be at \r
  496. if (cr[i] >= end) break;else ++i;
  497. }
  498. this.origEnd = end + i;
  499. return nextOffset;
  500. }
  501. }]);
  502. return Range;
  503. }();
  504. /** Root class of all nodes */
  505. var Node = /*#__PURE__*/function () {
  506. _createClass(Node, null, [{
  507. key: "addStringTerminator",
  508. value: function addStringTerminator(src, offset, str) {
  509. if (str[str.length - 1] === '\n') return str;
  510. var next = Node.endOfWhiteSpace(src, offset);
  511. return next >= src.length || src[next] === '\n' ? str + '\n' : str;
  512. } // ^(---|...)
  513. }, {
  514. key: "atDocumentBoundary",
  515. value: function atDocumentBoundary(src, offset, sep) {
  516. var ch0 = src[offset];
  517. if (!ch0) return true;
  518. var prev = src[offset - 1];
  519. if (prev && prev !== '\n') return false;
  520. if (sep) {
  521. if (ch0 !== sep) return false;
  522. } else {
  523. if (ch0 !== Char.DIRECTIVES_END && ch0 !== Char.DOCUMENT_END) return false;
  524. }
  525. var ch1 = src[offset + 1];
  526. var ch2 = src[offset + 2];
  527. if (ch1 !== ch0 || ch2 !== ch0) return false;
  528. var ch3 = src[offset + 3];
  529. return !ch3 || ch3 === '\n' || ch3 === '\t' || ch3 === ' ';
  530. }
  531. }, {
  532. key: "endOfIdentifier",
  533. value: function endOfIdentifier(src, offset) {
  534. var ch = src[offset];
  535. var isVerbatim = ch === '<';
  536. var notOk = isVerbatim ? ['\n', '\t', ' ', '>'] : ['\n', '\t', ' ', '[', ']', '{', '}', ','];
  537. while (ch && notOk.indexOf(ch) === -1) {
  538. ch = src[offset += 1];
  539. }
  540. if (isVerbatim && ch === '>') offset += 1;
  541. return offset;
  542. }
  543. }, {
  544. key: "endOfIndent",
  545. value: function endOfIndent(src, offset) {
  546. var ch = src[offset];
  547. while (ch === ' ') {
  548. ch = src[offset += 1];
  549. }
  550. return offset;
  551. }
  552. }, {
  553. key: "endOfLine",
  554. value: function endOfLine(src, offset) {
  555. var ch = src[offset];
  556. while (ch && ch !== '\n') {
  557. ch = src[offset += 1];
  558. }
  559. return offset;
  560. }
  561. }, {
  562. key: "endOfWhiteSpace",
  563. value: function endOfWhiteSpace(src, offset) {
  564. var ch = src[offset];
  565. while (ch === '\t' || ch === ' ') {
  566. ch = src[offset += 1];
  567. }
  568. return offset;
  569. }
  570. }, {
  571. key: "startOfLine",
  572. value: function startOfLine(src, offset) {
  573. var ch = src[offset - 1];
  574. if (ch === '\n') return offset;
  575. while (ch && ch !== '\n') {
  576. ch = src[offset -= 1];
  577. }
  578. return offset + 1;
  579. }
  580. /**
  581. * End of indentation, or null if the line's indent level is not more
  582. * than `indent`
  583. *
  584. * @param {string} src
  585. * @param {number} indent
  586. * @param {number} lineStart
  587. * @returns {?number}
  588. */
  589. }, {
  590. key: "endOfBlockIndent",
  591. value: function endOfBlockIndent(src, indent, lineStart) {
  592. var inEnd = Node.endOfIndent(src, lineStart);
  593. if (inEnd > lineStart + indent) {
  594. return inEnd;
  595. } else {
  596. var wsEnd = Node.endOfWhiteSpace(src, inEnd);
  597. var ch = src[wsEnd];
  598. if (!ch || ch === '\n') return wsEnd;
  599. }
  600. return null;
  601. }
  602. }, {
  603. key: "atBlank",
  604. value: function atBlank(src, offset, endAsBlank) {
  605. var ch = src[offset];
  606. return ch === '\n' || ch === '\t' || ch === ' ' || endAsBlank && !ch;
  607. }
  608. }, {
  609. key: "nextNodeIsIndented",
  610. value: function nextNodeIsIndented(ch, indentDiff, indicatorAsIndent) {
  611. if (!ch || indentDiff < 0) return false;
  612. if (indentDiff > 0) return true;
  613. return indicatorAsIndent && ch === '-';
  614. } // should be at line or string end, or at next non-whitespace char
  615. }, {
  616. key: "normalizeOffset",
  617. value: function normalizeOffset(src, offset) {
  618. var ch = src[offset];
  619. return !ch ? offset : ch !== '\n' && src[offset - 1] === '\n' ? offset - 1 : Node.endOfWhiteSpace(src, offset);
  620. } // fold single newline into space, multiple newlines to N - 1 newlines
  621. // presumes src[offset] === '\n'
  622. }, {
  623. key: "foldNewline",
  624. value: function foldNewline(src, offset, indent) {
  625. var inCount = 0;
  626. var error = false;
  627. var fold = '';
  628. var ch = src[offset + 1];
  629. while (ch === ' ' || ch === '\t' || ch === '\n') {
  630. switch (ch) {
  631. case '\n':
  632. inCount = 0;
  633. offset += 1;
  634. fold += '\n';
  635. break;
  636. case '\t':
  637. if (inCount <= indent) error = true;
  638. offset = Node.endOfWhiteSpace(src, offset + 2) - 1;
  639. break;
  640. case ' ':
  641. inCount += 1;
  642. offset += 1;
  643. break;
  644. }
  645. ch = src[offset + 1];
  646. }
  647. if (!fold) fold = ' ';
  648. if (ch && inCount <= indent) error = true;
  649. return {
  650. fold: fold,
  651. offset: offset,
  652. error: error
  653. };
  654. }
  655. }]);
  656. function Node(type, props, context) {
  657. _classCallCheck(this, Node);
  658. Object.defineProperty(this, 'context', {
  659. value: context || null,
  660. writable: true
  661. });
  662. this.error = null;
  663. this.range = null;
  664. this.valueRange = null;
  665. this.props = props || [];
  666. this.type = type;
  667. this.value = null;
  668. }
  669. _createClass(Node, [{
  670. key: "getPropValue",
  671. value: function getPropValue(idx, key, skipKey) {
  672. if (!this.context) return null;
  673. var src = this.context.src;
  674. var prop = this.props[idx];
  675. return prop && src[prop.start] === key ? src.slice(prop.start + (skipKey ? 1 : 0), prop.end) : null;
  676. }
  677. }, {
  678. key: "commentHasRequiredWhitespace",
  679. value: function commentHasRequiredWhitespace(start) {
  680. var src = this.context.src;
  681. if (this.header && start === this.header.end) return false;
  682. if (!this.valueRange) return false;
  683. var end = this.valueRange.end;
  684. return start !== end || Node.atBlank(src, end - 1);
  685. }
  686. }, {
  687. key: "parseComment",
  688. value: function parseComment(start) {
  689. var src = this.context.src;
  690. if (src[start] === Char.COMMENT) {
  691. var end = Node.endOfLine(src, start + 1);
  692. var commentRange = new Range(start, end);
  693. this.props.push(commentRange);
  694. return end;
  695. }
  696. return start;
  697. }
  698. /**
  699. * Populates the `origStart` and `origEnd` values of all ranges for this
  700. * node. Extended by child classes to handle descendant nodes.
  701. *
  702. * @param {number[]} cr - Positions of dropped CR characters
  703. * @param {number} offset - Starting index of `cr` from the last call
  704. * @returns {number} - The next offset, matching the one found for `origStart`
  705. */
  706. }, {
  707. key: "setOrigRanges",
  708. value: function setOrigRanges(cr, offset) {
  709. if (this.range) offset = this.range.setOrigRange(cr, offset);
  710. if (this.valueRange) this.valueRange.setOrigRange(cr, offset);
  711. this.props.forEach(function (prop) {
  712. return prop.setOrigRange(cr, offset);
  713. });
  714. return offset;
  715. }
  716. }, {
  717. key: "toString",
  718. value: function toString() {
  719. var src = this.context.src,
  720. range = this.range,
  721. value = this.value;
  722. if (value != null) return value;
  723. var str = src.slice(range.start, range.end);
  724. return Node.addStringTerminator(src, range.end, str);
  725. }
  726. }, {
  727. key: "anchor",
  728. get: function get() {
  729. for (var i = 0; i < this.props.length; ++i) {
  730. var anchor = this.getPropValue(i, Char.ANCHOR, true);
  731. if (anchor != null) return anchor;
  732. }
  733. return null;
  734. }
  735. }, {
  736. key: "comment",
  737. get: function get() {
  738. var comments = [];
  739. for (var i = 0; i < this.props.length; ++i) {
  740. var comment = this.getPropValue(i, Char.COMMENT, true);
  741. if (comment != null) comments.push(comment);
  742. }
  743. return comments.length > 0 ? comments.join('\n') : null;
  744. }
  745. }, {
  746. key: "hasComment",
  747. get: function get() {
  748. if (this.context) {
  749. var src = this.context.src;
  750. for (var i = 0; i < this.props.length; ++i) {
  751. if (src[this.props[i].start] === Char.COMMENT) return true;
  752. }
  753. }
  754. return false;
  755. }
  756. }, {
  757. key: "hasProps",
  758. get: function get() {
  759. if (this.context) {
  760. var src = this.context.src;
  761. for (var i = 0; i < this.props.length; ++i) {
  762. if (src[this.props[i].start] !== Char.COMMENT) return true;
  763. }
  764. }
  765. return false;
  766. }
  767. }, {
  768. key: "includesTrailingLines",
  769. get: function get() {
  770. return false;
  771. }
  772. }, {
  773. key: "jsonLike",
  774. get: function get() {
  775. var jsonLikeTypes = [Type.FLOW_MAP, Type.FLOW_SEQ, Type.QUOTE_DOUBLE, Type.QUOTE_SINGLE];
  776. return jsonLikeTypes.indexOf(this.type) !== -1;
  777. }
  778. }, {
  779. key: "rangeAsLinePos",
  780. get: function get() {
  781. if (!this.range || !this.context) return undefined;
  782. var start = getLinePos(this.range.start, this.context.root);
  783. if (!start) return undefined;
  784. var end = getLinePos(this.range.end, this.context.root);
  785. return {
  786. start: start,
  787. end: end
  788. };
  789. }
  790. }, {
  791. key: "rawValue",
  792. get: function get() {
  793. if (!this.valueRange || !this.context) return null;
  794. var _this$valueRange = this.valueRange,
  795. start = _this$valueRange.start,
  796. end = _this$valueRange.end;
  797. return this.context.src.slice(start, end);
  798. }
  799. }, {
  800. key: "tag",
  801. get: function get() {
  802. for (var i = 0; i < this.props.length; ++i) {
  803. var tag = this.getPropValue(i, Char.TAG, false);
  804. if (tag != null) {
  805. if (tag[1] === '<') {
  806. return {
  807. verbatim: tag.slice(2, -1)
  808. };
  809. } else {
  810. // eslint-disable-next-line no-unused-vars
  811. var _tag$match = tag.match(/^(.*!)([^!]*)$/),
  812. _tag$match2 = _slicedToArray(_tag$match, 3),
  813. _ = _tag$match2[0],
  814. handle = _tag$match2[1],
  815. suffix = _tag$match2[2];
  816. return {
  817. handle: handle,
  818. suffix: suffix
  819. };
  820. }
  821. }
  822. }
  823. return null;
  824. }
  825. }, {
  826. key: "valueRangeContainsNewline",
  827. get: function get() {
  828. if (!this.valueRange || !this.context) return false;
  829. var _this$valueRange2 = this.valueRange,
  830. start = _this$valueRange2.start,
  831. end = _this$valueRange2.end;
  832. var src = this.context.src;
  833. for (var i = start; i < end; ++i) {
  834. if (src[i] === '\n') return true;
  835. }
  836. return false;
  837. }
  838. }]);
  839. return Node;
  840. }();
  841. var YAMLError = /*#__PURE__*/function (_Error) {
  842. _inherits(YAMLError, _Error);
  843. var _super = _createSuper(YAMLError);
  844. function YAMLError(name, source, message) {
  845. var _this;
  846. _classCallCheck(this, YAMLError);
  847. if (!message || !(source instanceof Node)) throw new Error("Invalid arguments for new ".concat(name));
  848. _this = _super.call(this);
  849. _this.name = name;
  850. _this.message = message;
  851. _this.source = source;
  852. return _this;
  853. }
  854. _createClass(YAMLError, [{
  855. key: "makePretty",
  856. value: function makePretty() {
  857. if (!this.source) return;
  858. this.nodeType = this.source.type;
  859. var cst = this.source.context && this.source.context.root;
  860. if (typeof this.offset === 'number') {
  861. this.range = new Range(this.offset, this.offset + 1);
  862. var start = cst && getLinePos(this.offset, cst);
  863. if (start) {
  864. var end = {
  865. line: start.line,
  866. col: start.col + 1
  867. };
  868. this.linePos = {
  869. start: start,
  870. end: end
  871. };
  872. }
  873. delete this.offset;
  874. } else {
  875. this.range = this.source.range;
  876. this.linePos = this.source.rangeAsLinePos;
  877. }
  878. if (this.linePos) {
  879. var _this$linePos$start = this.linePos.start,
  880. line = _this$linePos$start.line,
  881. col = _this$linePos$start.col;
  882. this.message += " at line ".concat(line, ", column ").concat(col);
  883. var ctx = cst && getPrettyContext(this.linePos, cst);
  884. if (ctx) this.message += ":\n\n".concat(ctx, "\n");
  885. }
  886. delete this.source;
  887. }
  888. }]);
  889. return YAMLError;
  890. }( /*#__PURE__*/_wrapNativeSuper(Error));
  891. var YAMLReferenceError = /*#__PURE__*/function (_YAMLError) {
  892. _inherits(YAMLReferenceError, _YAMLError);
  893. var _super2 = _createSuper(YAMLReferenceError);
  894. function YAMLReferenceError(source, message) {
  895. _classCallCheck(this, YAMLReferenceError);
  896. return _super2.call(this, 'YAMLReferenceError', source, message);
  897. }
  898. return YAMLReferenceError;
  899. }(YAMLError);
  900. var YAMLSemanticError = /*#__PURE__*/function (_YAMLError2) {
  901. _inherits(YAMLSemanticError, _YAMLError2);
  902. var _super3 = _createSuper(YAMLSemanticError);
  903. function YAMLSemanticError(source, message) {
  904. _classCallCheck(this, YAMLSemanticError);
  905. return _super3.call(this, 'YAMLSemanticError', source, message);
  906. }
  907. return YAMLSemanticError;
  908. }(YAMLError);
  909. var YAMLSyntaxError = /*#__PURE__*/function (_YAMLError3) {
  910. _inherits(YAMLSyntaxError, _YAMLError3);
  911. var _super4 = _createSuper(YAMLSyntaxError);
  912. function YAMLSyntaxError(source, message) {
  913. _classCallCheck(this, YAMLSyntaxError);
  914. return _super4.call(this, 'YAMLSyntaxError', source, message);
  915. }
  916. return YAMLSyntaxError;
  917. }(YAMLError);
  918. var YAMLWarning = /*#__PURE__*/function (_YAMLError4) {
  919. _inherits(YAMLWarning, _YAMLError4);
  920. var _super5 = _createSuper(YAMLWarning);
  921. function YAMLWarning(source, message) {
  922. _classCallCheck(this, YAMLWarning);
  923. return _super5.call(this, 'YAMLWarning', source, message);
  924. }
  925. return YAMLWarning;
  926. }(YAMLError);
  927. var PlainValue = /*#__PURE__*/function (_Node) {
  928. _inherits(PlainValue, _Node);
  929. var _super = _createSuper(PlainValue);
  930. function PlainValue() {
  931. _classCallCheck(this, PlainValue);
  932. return _super.apply(this, arguments);
  933. }
  934. _createClass(PlainValue, [{
  935. key: "parseBlockValue",
  936. value: function parseBlockValue(start) {
  937. var _this$context = this.context,
  938. indent = _this$context.indent,
  939. inFlow = _this$context.inFlow,
  940. src = _this$context.src;
  941. var offset = start;
  942. var valueEnd = start;
  943. for (var ch = src[offset]; ch === '\n'; ch = src[offset]) {
  944. if (Node.atDocumentBoundary(src, offset + 1)) break;
  945. var end = Node.endOfBlockIndent(src, indent, offset + 1);
  946. if (end === null || src[end] === '#') break;
  947. if (src[end] === '\n') {
  948. offset = end;
  949. } else {
  950. valueEnd = PlainValue.endOfLine(src, end, inFlow);
  951. offset = valueEnd;
  952. }
  953. }
  954. if (this.valueRange.isEmpty()) this.valueRange.start = start;
  955. this.valueRange.end = valueEnd;
  956. return valueEnd;
  957. }
  958. /**
  959. * Parses a plain value from the source
  960. *
  961. * Accepted forms are:
  962. * ```
  963. * #comment
  964. *
  965. * first line
  966. *
  967. * first line #comment
  968. *
  969. * first line
  970. * block
  971. * lines
  972. *
  973. * #comment
  974. * block
  975. * lines
  976. * ```
  977. * where block lines are empty or have an indent level greater than `indent`.
  978. *
  979. * @param {ParseContext} context
  980. * @param {number} start - Index of first character
  981. * @returns {number} - Index of the character after this scalar, may be `\n`
  982. */
  983. }, {
  984. key: "parse",
  985. value: function parse(context, start) {
  986. this.context = context;
  987. var inFlow = context.inFlow,
  988. src = context.src;
  989. var offset = start;
  990. var ch = src[offset];
  991. if (ch && ch !== '#' && ch !== '\n') {
  992. offset = PlainValue.endOfLine(src, start, inFlow);
  993. }
  994. this.valueRange = new Range(start, offset);
  995. offset = Node.endOfWhiteSpace(src, offset);
  996. offset = this.parseComment(offset);
  997. if (!this.hasComment || this.valueRange.isEmpty()) {
  998. offset = this.parseBlockValue(offset);
  999. }
  1000. return offset;
  1001. }
  1002. }, {
  1003. key: "strValue",
  1004. get: function get() {
  1005. if (!this.valueRange || !this.context) return null;
  1006. var _this$valueRange = this.valueRange,
  1007. start = _this$valueRange.start,
  1008. end = _this$valueRange.end;
  1009. var src = this.context.src;
  1010. var ch = src[end - 1];
  1011. while (start < end && (ch === '\n' || ch === '\t' || ch === ' ')) {
  1012. ch = src[--end - 1];
  1013. }
  1014. var str = '';
  1015. for (var i = start; i < end; ++i) {
  1016. var _ch = src[i];
  1017. if (_ch === '\n') {
  1018. var _Node$foldNewline = Node.foldNewline(src, i, -1),
  1019. fold = _Node$foldNewline.fold,
  1020. offset = _Node$foldNewline.offset;
  1021. str += fold;
  1022. i = offset;
  1023. } else if (_ch === ' ' || _ch === '\t') {
  1024. // trim trailing whitespace
  1025. var wsStart = i;
  1026. var next = src[i + 1];
  1027. while (i < end && (next === ' ' || next === '\t')) {
  1028. i += 1;
  1029. next = src[i + 1];
  1030. }
  1031. if (next !== '\n') str += i > wsStart ? src.slice(wsStart, i + 1) : _ch;
  1032. } else {
  1033. str += _ch;
  1034. }
  1035. }
  1036. var ch0 = src[start];
  1037. switch (ch0) {
  1038. case '\t':
  1039. {
  1040. var msg = 'Plain value cannot start with a tab character';
  1041. var errors = [new YAMLSemanticError(this, msg)];
  1042. return {
  1043. errors: errors,
  1044. str: str
  1045. };
  1046. }
  1047. case '@':
  1048. case '`':
  1049. {
  1050. var _msg = "Plain value cannot start with reserved character ".concat(ch0);
  1051. var _errors = [new YAMLSemanticError(this, _msg)];
  1052. return {
  1053. errors: _errors,
  1054. str: str
  1055. };
  1056. }
  1057. default:
  1058. return str;
  1059. }
  1060. }
  1061. }], [{
  1062. key: "endOfLine",
  1063. value: function endOfLine(src, start, inFlow) {
  1064. var ch = src[start];
  1065. var offset = start;
  1066. while (ch && ch !== '\n') {
  1067. if (inFlow && (ch === '[' || ch === ']' || ch === '{' || ch === '}' || ch === ',')) break;
  1068. var next = src[offset + 1];
  1069. if (ch === ':' && (!next || next === '\n' || next === '\t' || next === ' ' || inFlow && next === ',')) break;
  1070. if ((ch === ' ' || ch === '\t') && next === '#') break;
  1071. offset += 1;
  1072. ch = next;
  1073. }
  1074. return offset;
  1075. }
  1076. }]);
  1077. return PlainValue;
  1078. }(Node);
  1079. 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 };