yaml 1.3.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. package/README.md +29 -23
  2. package/browser/dist/Anchors.js +12 -10
  3. package/browser/dist/Document.js +122 -60
  4. package/browser/dist/constants.js +34 -0
  5. package/browser/dist/cst/Alias.js +1 -3
  6. package/browser/dist/cst/BlankLine.js +5 -7
  7. package/browser/dist/cst/BlockValue.js +4 -4
  8. package/browser/dist/cst/Collection.js +8 -8
  9. package/browser/dist/cst/CollectionItem.js +6 -8
  10. package/browser/dist/cst/Comment.js +5 -7
  11. package/browser/dist/cst/Directive.js +5 -7
  12. package/browser/dist/cst/Document.js +8 -10
  13. package/browser/dist/cst/FlowCollection.js +5 -7
  14. package/browser/dist/cst/Node.js +12 -40
  15. package/browser/dist/cst/ParseContext.js +32 -34
  16. package/browser/dist/cst/PlainValue.js +1 -3
  17. package/browser/dist/cst/QuoteDouble.js +1 -3
  18. package/browser/dist/cst/QuoteSingle.js +1 -3
  19. package/browser/dist/cst/Range.js +1 -3
  20. package/browser/dist/cst/getLinePos.js +8 -13
  21. package/browser/dist/cst/parse.js +1 -4
  22. package/browser/dist/deprecation.js +34 -0
  23. package/browser/dist/errors.js +50 -59
  24. package/browser/dist/index.js +7 -4
  25. package/browser/dist/listTagNames.js +1 -3
  26. package/browser/dist/schema/Alias.js +90 -10
  27. package/browser/dist/schema/Collection.js +3 -3
  28. package/browser/dist/schema/Map.js +22 -105
  29. package/browser/dist/schema/Merge.js +74 -1
  30. package/browser/dist/schema/Node.js +1 -3
  31. package/browser/dist/schema/Pair.js +52 -26
  32. package/browser/dist/schema/Scalar.js +3 -5
  33. package/browser/dist/schema/Seq.js +30 -7
  34. package/browser/dist/schema/index.js +158 -82
  35. package/browser/dist/schema/parseMap.js +18 -21
  36. package/browser/dist/schema/parseSeq.js +9 -12
  37. package/browser/dist/{schema/_string.js → stringify.js} +65 -73
  38. package/browser/dist/tags/core.js +132 -0
  39. package/browser/dist/tags/failsafe/index.js +17 -0
  40. package/browser/dist/tags/failsafe/map.js +65 -0
  41. package/browser/dist/tags/failsafe/seq.js +54 -0
  42. package/browser/dist/tags/failsafe/string.js +40 -0
  43. package/browser/dist/tags/index.js +50 -0
  44. package/browser/dist/tags/json.js +103 -0
  45. package/browser/dist/tags/options.js +35 -0
  46. package/browser/dist/{schema/_binary.js → tags/yaml-1.1/binary.js} +20 -20
  47. package/browser/dist/tags/yaml-1.1/index.js +177 -0
  48. package/browser/dist/{schema/_omap.js → tags/yaml-1.1/omap.js} +25 -25
  49. package/browser/dist/{schema/_pairs.js → tags/yaml-1.1/pairs.js} +9 -13
  50. package/browser/dist/tags/yaml-1.1/set.js +140 -0
  51. package/browser/dist/{schema/_timestamp.js → tags/yaml-1.1/timestamp.js} +13 -10
  52. package/browser/dist/test-events.js +1 -4
  53. package/browser/dist/toJSON.js +20 -8
  54. package/browser/index.js +1 -0
  55. package/browser/map.js +2 -1
  56. package/browser/pair.js +2 -1
  57. package/browser/parse-cst.js +1 -1
  58. package/browser/scalar.js +2 -1
  59. package/browser/schema.js +7 -3
  60. package/browser/seq.js +2 -1
  61. package/browser/types/binary.js +7 -1
  62. package/browser/types/omap.js +2 -1
  63. package/browser/types/pairs.js +2 -1
  64. package/browser/types/set.js +2 -1
  65. package/browser/types/timestamp.js +10 -1
  66. package/browser/types.js +11 -0
  67. package/browser/util.js +15 -0
  68. package/dist/Anchors.js +9 -8
  69. package/dist/Document.js +55 -39
  70. package/dist/constants.js +34 -0
  71. package/dist/cst/Alias.js +1 -3
  72. package/dist/cst/BlankLine.js +5 -7
  73. package/dist/cst/BlockValue.js +4 -4
  74. package/dist/cst/Collection.js +8 -8
  75. package/dist/cst/CollectionItem.js +6 -8
  76. package/dist/cst/Comment.js +5 -7
  77. package/dist/cst/Directive.js +5 -7
  78. package/dist/cst/Document.js +8 -10
  79. package/dist/cst/FlowCollection.js +5 -7
  80. package/dist/cst/Node.js +12 -40
  81. package/dist/cst/ParseContext.js +32 -34
  82. package/dist/cst/PlainValue.js +1 -3
  83. package/dist/cst/QuoteDouble.js +1 -3
  84. package/dist/cst/QuoteSingle.js +1 -3
  85. package/dist/cst/Range.js +1 -3
  86. package/dist/cst/getLinePos.js +8 -12
  87. package/dist/cst/parse.js +1 -4
  88. package/dist/deprecation.js +34 -0
  89. package/dist/errors.js +29 -35
  90. package/dist/index.js +7 -4
  91. package/dist/listTagNames.js +1 -3
  92. package/dist/schema/Alias.js +67 -12
  93. package/dist/schema/Map.js +10 -74
  94. package/dist/schema/Merge.js +31 -0
  95. package/dist/schema/Node.js +1 -3
  96. package/dist/schema/Pair.js +46 -20
  97. package/dist/schema/Scalar.js +3 -5
  98. package/dist/schema/Seq.js +9 -5
  99. package/dist/schema/index.js +109 -74
  100. package/dist/schema/parseMap.js +18 -21
  101. package/dist/schema/parseSeq.js +9 -12
  102. package/dist/{schema/_string.js → stringify.js} +56 -65
  103. package/dist/tags/core.js +96 -0
  104. package/dist/tags/failsafe/index.js +17 -0
  105. package/dist/tags/failsafe/map.js +33 -0
  106. package/dist/tags/failsafe/seq.js +34 -0
  107. package/dist/tags/failsafe/string.js +40 -0
  108. package/dist/tags/index.js +50 -0
  109. package/dist/tags/json.js +67 -0
  110. package/dist/tags/options.js +35 -0
  111. package/dist/{schema/_binary.js → tags/yaml-1.1/binary.js} +18 -20
  112. package/dist/tags/yaml-1.1/index.js +131 -0
  113. package/dist/{schema/_omap.js → tags/yaml-1.1/omap.js} +16 -16
  114. package/dist/{schema/_pairs.js → tags/yaml-1.1/pairs.js} +9 -11
  115. package/dist/{schema/_set.js → tags/yaml-1.1/set.js} +12 -44
  116. package/dist/{schema/_timestamp.js → tags/yaml-1.1/timestamp.js} +7 -10
  117. package/dist/test-events.js +1 -4
  118. package/dist/toJSON.js +15 -5
  119. package/index.js +1 -0
  120. package/map.js +2 -1
  121. package/package.json +22 -17
  122. package/pair.js +2 -1
  123. package/parse-cst.js +1 -1
  124. package/scalar.js +2 -1
  125. package/schema.js +7 -3
  126. package/seq.js +2 -1
  127. package/types/binary.js +7 -1
  128. package/types/omap.js +2 -1
  129. package/types/pairs.js +2 -1
  130. package/types/set.js +2 -1
  131. package/types/timestamp.js +10 -1
  132. package/types.js +11 -0
  133. package/util.js +15 -0
  134. package/browser/dist/polyfill.js +0 -251
  135. package/browser/dist/schema/_set.js +0 -212
  136. package/browser/dist/schema/core.js +0 -98
  137. package/browser/dist/schema/failsafe.js +0 -125
  138. package/browser/dist/schema/json.js +0 -66
  139. package/browser/dist/schema/yaml-1.1.js +0 -140
  140. package/dist/linePos.js +0 -58
  141. package/dist/polyfill.js +0 -27
  142. package/dist/schema/core.js +0 -79
  143. package/dist/schema/failsafe.js +0 -74
  144. package/dist/schema/json.js +0 -56
  145. package/dist/schema/yaml-1.1.js +0 -115
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  `yaml` is a JavaScript parser and stringifier for [YAML](http://yaml.org/), a human friendly data serialization standard. It supports both parsing and stringifying data using all versions of YAML, along with all common data schemas. As a particularly distinguishing feature, `yaml` fully supports reading and writing comments and blank lines in YAML documents.
4
4
 
5
- The library is released under the ISC open source license, and the code is [available on GitHub](https://github.com/eemeli/yaml/). It has no external dependencies, and is usable in both browser and node environments.
5
+ The library is released under the ISC open source license, and the code is [available on GitHub](https://github.com/eemeli/yaml/). It runs on Node.js 6 and later with no external dependencies, and in browsers from IE 11 upwards (Note: `@babel/runtime` is used only by the `"browser"` entry point).
6
6
 
7
7
  For more information, see the project's documentation site: [**eemeli.org/yaml**](https://eemeli.org/yaml/)
8
8
 
@@ -18,7 +18,7 @@ Note: `yaml` 0.x and 1.x are rather different implementations. For the earlier `
18
18
 
19
19
  ## API Overview
20
20
 
21
- The API provided by `yaml` has three layers, depending on how deep you need to go: [Pure JavaScript](https://eemeli.org/yaml/#pure-javascript), [YAML Documents](https://eemeli.org/yaml/#yaml-documents), and the [CST Parser](https://eemeli.org/yaml/#cst-parser). The first has the simplest API and "just works", the second gets you all the bells and whistles supported by the library along with a decent [AST](https://eemeli.org/yaml/#content-nodes), and the third is the closest to YAML source, making it fast, raw, and crude.
21
+ The API provided by `yaml` has three layers, depending on how deep you need to go: [Parse & Stringify](https://eemeli.org/yaml/#parse-amp-stringify), [Documents](https://eemeli.org/yaml/#documents), and the [CST Parser](https://eemeli.org/yaml/#cst-parser). The first has the simplest API and "just works", the second gets you all the bells and whistles supported by the library along with a decent [AST](https://eemeli.org/yaml/#content-nodes), and the third is the closest to YAML source, making it fast, raw, and crude.
22
22
 
23
23
  ```js
24
24
  import YAML from 'yaml'
@@ -26,33 +26,31 @@ import YAML from 'yaml'
26
26
  const YAML = require('yaml')
27
27
  ```
28
28
 
29
- ### Pure JavaScript
29
+ ### Parse & Stringify
30
30
 
31
- * [`YAML.parse(str, options): value`](https://eemeli.org/yaml/#yaml-parse)
32
- * [`YAML.stringify(value, options): string`](https://eemeli.org/yaml/#yaml-stringify)
31
+ - [`YAML.parse(str, options): value`](https://eemeli.org/yaml/#yaml-parse)
32
+ - [`YAML.stringify(value, options): string`](https://eemeli.org/yaml/#yaml-stringify)
33
33
 
34
34
  ### YAML Documents
35
35
 
36
- * [`YAML.createNode(value, wrapScalars, tag): Node`](https://eemeli.org/yaml/#creating-nodes)
37
- * [`YAML.defaultOptions`](https://eemeli.org/yaml/#options)
38
- * [`YAML.Document`](https://eemeli.org/yaml/#yaml-documents)
39
- * [`constructor(options)`](https://eemeli.org/yaml/#creating-documents)
40
- * [`defaults`](https://eemeli.org/yaml/#options)
41
- * [`#anchors`](https://eemeli.org/yaml/#working-with-anchors)
42
- * [`#contents`](https://eemeli.org/yaml/#content-nodes)
43
- * [`#errors`](https://eemeli.org/yaml/#errors)
44
- * [`YAML.parseAllDocuments(str, options): YAML.Document[]`](https://eemeli.org/yaml/#parsing-documents)
45
- * [`YAML.parseDocument(str, options): YAML.Document`](https://eemeli.org/yaml/#parsing-documents)
36
+ - [`YAML.createNode(value, wrapScalars, tag): Node`](https://eemeli.org/yaml/#creating-nodes)
37
+ - [`YAML.defaultOptions`](https://eemeli.org/yaml/#options)
38
+ - [`YAML.Document`](https://eemeli.org/yaml/#yaml-documents)
39
+ - [`constructor(options)`](https://eemeli.org/yaml/#creating-documents)
40
+ - [`defaults`](https://eemeli.org/yaml/#options)
41
+ - [`#anchors`](https://eemeli.org/yaml/#working-with-anchors)
42
+ - [`#contents`](https://eemeli.org/yaml/#content-nodes)
43
+ - [`#errors`](https://eemeli.org/yaml/#errors)
44
+ - [`YAML.parseAllDocuments(str, options): YAML.Document[]`](https://eemeli.org/yaml/#parsing-documents)
45
+ - [`YAML.parseDocument(str, options): YAML.Document`](https://eemeli.org/yaml/#parsing-documents)
46
46
 
47
47
  ```js
48
- import Map from 'yaml/map'
49
- import Pair from 'yaml/pair'
50
- import Seq from 'yaml/seq'
48
+ import { Pair, YAMLMap, YAMLSeq } from 'yaml/types'
51
49
  ```
52
50
 
53
- * [`new Map()`](https://eemeli.org/yaml/#creating-nodes)
54
- * [`new Pair(key, value)`](https://eemeli.org/yaml/#creating-nodes)
55
- * [`new Seq()`](https://eemeli.org/yaml/#creating-nodes)
51
+ - [`new Pair(key, value)`](https://eemeli.org/yaml/#creating-nodes)
52
+ - [`new YAMLMap()`](https://eemeli.org/yaml/#creating-nodes)
53
+ - [`new YAMLSeq()`](https://eemeli.org/yaml/#creating-nodes)
56
54
 
57
55
  ### CST Parser
58
56
 
@@ -60,8 +58,8 @@ import Seq from 'yaml/seq'
60
58
  import parseCST from 'yaml/parse-cst'
61
59
  ```
62
60
 
63
- * [`parseCST(str): CSTDocument[]`](https://eemeli.org/yaml/#parsecst)
64
- * [`YAML.parseCST(str): CSTDocument[]`](https://eemeli.org/yaml/#parsecst)
61
+ - [`parseCST(str): CSTDocument[]`](https://eemeli.org/yaml/#parsecst)
62
+ - [`YAML.parseCST(str): CSTDocument[]`](https://eemeli.org/yaml/#parsecst)
65
63
 
66
64
  ## YAML.parse
67
65
 
@@ -119,3 +117,11 @@ YAML.stringify({ number: 3, plain: 'string', block: 'two\nlines\n' })
119
117
  // lines
120
118
  // `
121
119
  ```
120
+
121
+ ---
122
+
123
+ Browser testing provided by:
124
+
125
+ <a href="https://www.browserstack.com/open-source">
126
+ <img width=200 src="https://eemeli.org/yaml/images/browserstack.svg" />
127
+ </a>
@@ -26,9 +26,17 @@ var _Seq = _interopRequireDefault(require("./schema/Seq"));
26
26
  var Anchors =
27
27
  /*#__PURE__*/
28
28
  function () {
29
- function Anchors() {
29
+ (0, _createClass2.default)(Anchors, null, [{
30
+ key: "validAnchorNode",
31
+ value: function validAnchorNode(node) {
32
+ return node instanceof _Scalar.default || node instanceof _Seq.default || node instanceof _Map.default;
33
+ }
34
+ }]);
35
+
36
+ function Anchors(prefix) {
30
37
  (0, _classCallCheck2.default)(this, Anchors);
31
38
  (0, _defineProperty2.default)(this, "map", {});
39
+ this.prefix = prefix;
32
40
  }
33
41
 
34
42
  (0, _createClass2.default)(Anchors, [{
@@ -75,6 +83,7 @@ function () {
75
83
  }, {
76
84
  key: "newName",
77
85
  value: function newName(prefix) {
86
+ if (!prefix) prefix = this.prefix;
78
87
  var names = Object.keys(this.map);
79
88
 
80
89
  for (var i = 1; true; ++i) {
@@ -124,7 +133,7 @@ function () {
124
133
  } else {
125
134
  if (!name) {
126
135
  if (!node) return null;
127
- name = this.newName('a');
136
+ name = this.newName();
128
137
  }
129
138
 
130
139
  map[name] = node;
@@ -132,15 +141,8 @@ function () {
132
141
 
133
142
  return name;
134
143
  }
135
- }], [{
136
- key: "validAnchorNode",
137
- value: function validAnchorNode(node) {
138
- return node instanceof _Scalar.default || node instanceof _Seq.default || node instanceof _Map.default;
139
- }
140
144
  }]);
141
145
  return Anchors;
142
146
  }();
143
147
 
144
- exports.default = Anchors;
145
- module.exports = exports.default;
146
- module.exports.default = exports.default;
148
+ exports.default = Anchors;
@@ -21,7 +21,7 @@ var _addComment = _interopRequireDefault(require("./addComment"));
21
21
 
22
22
  var _Anchors = _interopRequireDefault(require("./Anchors"));
23
23
 
24
- var _Node = require("./cst/Node");
24
+ var _constants = require("./constants");
25
25
 
26
26
  var _errors = require("./errors");
27
27
 
@@ -33,12 +33,14 @@ var _Alias = _interopRequireDefault(require("./schema/Alias"));
33
33
 
34
34
  var _Collection = _interopRequireWildcard(require("./schema/Collection"));
35
35
 
36
- var _toJSON2 = _interopRequireDefault(require("./toJSON"));
36
+ var _Node = _interopRequireDefault(require("./schema/Node"));
37
37
 
38
38
  var _Scalar = _interopRequireDefault(require("./schema/Scalar"));
39
39
 
40
+ var _toJSON2 = _interopRequireDefault(require("./toJSON"));
41
+
40
42
  var isCollectionItem = function isCollectionItem(node) {
41
- return node && [_Node.Type.MAP_KEY, _Node.Type.MAP_VALUE, _Node.Type.SEQ_ITEM].includes(node.type);
43
+ return node && [_constants.Type.MAP_KEY, _constants.Type.MAP_VALUE, _constants.Type.SEQ_ITEM].includes(node.type);
42
44
  };
43
45
 
44
46
  var Document =
@@ -46,7 +48,7 @@ var Document =
46
48
  function () {
47
49
  function Document(options) {
48
50
  (0, _classCallCheck2.default)(this, Document);
49
- this.anchors = new _Anchors.default();
51
+ this.anchors = new _Anchors.default(options.anchorPrefix);
50
52
  this.commentBefore = null;
51
53
  this.comment = null;
52
54
  this.contents = null;
@@ -216,7 +218,7 @@ function () {
216
218
  } else if (node.comment !== null) {
217
219
  var cc = contentNodes.length === 0 ? comments.before : comments.after;
218
220
  cc.push(node.comment);
219
- } else if (node.type === _Node.Type.BLANK_LINE) {
221
+ } else if (node.type === _constants.Type.BLANK_LINE) {
220
222
  spaceBefore = true;
221
223
 
222
224
  if (contentNodes.length === 0 && comments.before.length > 0 && !_this.commentBefore) {
@@ -262,6 +264,57 @@ function () {
262
264
 
263
265
  this.comment = comments.after.join('\n') || null;
264
266
  this.anchors.resolveNodes();
267
+
268
+ if (this.options.prettyErrors) {
269
+ var _iteratorNormalCompletion = true;
270
+ var _didIteratorError = false;
271
+ var _iteratorError = undefined;
272
+
273
+ try {
274
+ for (var _iterator = this.errors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
275
+ var _error = _step.value;
276
+ if (_error instanceof _errors.YAMLError) _error.makePretty();
277
+ }
278
+ } catch (err) {
279
+ _didIteratorError = true;
280
+ _iteratorError = err;
281
+ } finally {
282
+ try {
283
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
284
+ _iterator.return();
285
+ }
286
+ } finally {
287
+ if (_didIteratorError) {
288
+ throw _iteratorError;
289
+ }
290
+ }
291
+ }
292
+
293
+ var _iteratorNormalCompletion2 = true;
294
+ var _didIteratorError2 = false;
295
+ var _iteratorError2 = undefined;
296
+
297
+ try {
298
+ for (var _iterator2 = this.warnings[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
299
+ var warn = _step2.value;
300
+ if (warn instanceof _errors.YAMLError) warn.makePretty();
301
+ }
302
+ } catch (err) {
303
+ _didIteratorError2 = true;
304
+ _iteratorError2 = err;
305
+ } finally {
306
+ try {
307
+ if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
308
+ _iterator2.return();
309
+ }
310
+ } finally {
311
+ if (_didIteratorError2) {
312
+ throw _iteratorError2;
313
+ }
314
+ }
315
+ }
316
+ }
317
+
265
318
  return this;
266
319
  }
267
320
  }, {
@@ -371,21 +424,21 @@ function () {
371
424
  }
372
425
 
373
426
  switch (type) {
374
- case _Node.Type.BLOCK_FOLDED:
375
- case _Node.Type.BLOCK_LITERAL:
376
- case _Node.Type.QUOTE_DOUBLE:
377
- case _Node.Type.QUOTE_SINGLE:
427
+ case _constants.Type.BLOCK_FOLDED:
428
+ case _constants.Type.BLOCK_LITERAL:
429
+ case _constants.Type.QUOTE_DOUBLE:
430
+ case _constants.Type.QUOTE_SINGLE:
378
431
  return _schema.default.defaultTags.STR;
379
432
 
380
- case _Node.Type.FLOW_MAP:
381
- case _Node.Type.MAP:
433
+ case _constants.Type.FLOW_MAP:
434
+ case _constants.Type.MAP:
382
435
  return _schema.default.defaultTags.MAP;
383
436
 
384
- case _Node.Type.FLOW_SEQ:
385
- case _Node.Type.SEQ:
437
+ case _constants.Type.FLOW_SEQ:
438
+ case _constants.Type.SEQ:
386
439
  return _schema.default.defaultTags.SEQ;
387
440
 
388
- case _Node.Type.PLAIN:
441
+ case _constants.Type.PLAIN:
389
442
  return nonSpecific ? _schema.default.defaultTags.STR : null;
390
443
 
391
444
  default:
@@ -406,22 +459,22 @@ function () {
406
459
  after: []
407
460
  };
408
461
  var props = isCollectionItem(node.context.parent) ? node.context.parent.props.concat(node.props) : node.props;
409
- var _iteratorNormalCompletion = true;
410
- var _didIteratorError = false;
411
- var _iteratorError = undefined;
462
+ var _iteratorNormalCompletion3 = true;
463
+ var _didIteratorError3 = false;
464
+ var _iteratorError3 = undefined;
412
465
 
413
466
  try {
414
- for (var _iterator = props[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
415
- var _step$value = _step.value,
416
- start = _step$value.start,
417
- end = _step$value.end;
467
+ for (var _iterator3 = props[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
468
+ var _step3$value = _step3.value,
469
+ start = _step3$value.start,
470
+ end = _step3$value.end;
418
471
 
419
472
  switch (node.context.src[start]) {
420
- case _Node.Char.COMMENT:
473
+ case _constants.Char.COMMENT:
421
474
  {
422
475
  if (!node.commentHasRequiredWhitespace(start)) {
423
- var _msg8 = 'Comments must be separated from other tokens by white space characters';
424
- errors.push(new _errors.YAMLSemanticError(node, _msg8));
476
+ var _msg7 = 'Comments must be separated from other tokens by white space characters';
477
+ errors.push(new _errors.YAMLSemanticError(node, _msg7));
425
478
  }
426
479
 
427
480
  var c = node.context.src.slice(start + 1, end);
@@ -436,19 +489,19 @@ function () {
436
489
  }
437
490
  break;
438
491
 
439
- case _Node.Char.ANCHOR:
492
+ case _constants.Char.ANCHOR:
440
493
  if (hasAnchor) {
441
- var _msg9 = 'A node can have at most one anchor';
442
- errors.push(new _errors.YAMLSemanticError(node, _msg9));
494
+ var _msg8 = 'A node can have at most one anchor';
495
+ errors.push(new _errors.YAMLSemanticError(node, _msg8));
443
496
  }
444
497
 
445
498
  hasAnchor = true;
446
499
  break;
447
500
 
448
- case _Node.Char.TAG:
501
+ case _constants.Char.TAG:
449
502
  if (hasTag) {
450
- var _msg10 = 'A node can have at most one tag';
451
- errors.push(new _errors.YAMLSemanticError(node, _msg10));
503
+ var _msg9 = 'A node can have at most one tag';
504
+ errors.push(new _errors.YAMLSemanticError(node, _msg9));
452
505
  }
453
506
 
454
507
  hasTag = true;
@@ -456,16 +509,16 @@ function () {
456
509
  }
457
510
  }
458
511
  } catch (err) {
459
- _didIteratorError = true;
460
- _iteratorError = err;
512
+ _didIteratorError3 = true;
513
+ _iteratorError3 = err;
461
514
  } finally {
462
515
  try {
463
- if (!_iteratorNormalCompletion && _iterator.return != null) {
464
- _iterator.return();
516
+ if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
517
+ _iterator3.return();
465
518
  }
466
519
  } finally {
467
- if (_didIteratorError) {
468
- throw _iteratorError;
520
+ if (_didIteratorError3) {
521
+ throw _iteratorError3;
469
522
  }
470
523
  }
471
524
  }
@@ -484,7 +537,7 @@ function () {
484
537
 
485
538
  var res;
486
539
 
487
- if (node.type === _Node.Type.ALIAS) {
540
+ if (node.type === _constants.Type.ALIAS) {
488
541
  if (hasAnchor || hasTag) {
489
542
  var msg = 'An alias node must not specify any properties';
490
543
  errors.push(new _errors.YAMLSemanticError(node, msg));
@@ -504,21 +557,16 @@ function () {
504
557
  res = new _Alias.default(src);
505
558
 
506
559
  anchors._cstAliases.push(res);
507
-
508
- if (!src.resolved) {
509
- var _msg6 = 'Alias node contains a circular reference, which cannot be resolved as JSON';
510
- this.warnings.push(new _errors.YAMLWarning(node, _msg6));
511
- }
512
560
  } else {
513
561
  var tagName = this.resolveTagName(node);
514
562
 
515
563
  if (tagName) {
516
564
  res = schema.resolveNodeWithFallback(this, node, tagName);
517
565
  } else {
518
- if (node.type !== _Node.Type.PLAIN) {
519
- var _msg7 = "Failed to resolve ".concat(node.type, " node here");
566
+ if (node.type !== _constants.Type.PLAIN) {
567
+ var _msg6 = "Failed to resolve ".concat(node.type, " node here");
520
568
 
521
- errors.push(new _errors.YAMLSyntaxError(node, _msg7));
569
+ errors.push(new _errors.YAMLSyntaxError(node, _msg6));
522
570
  return null;
523
571
  }
524
572
 
@@ -611,16 +659,29 @@ function () {
611
659
  }, {
612
660
  key: "toJSON",
613
661
  value: function toJSON(arg) {
614
- var cr = this.warnings.find(function (w) {
615
- return /circular reference/.test(w.message);
616
- });
617
- if (cr) throw new _errors.YAMLSemanticError(cr.source, cr.message);
618
- var keep = this.options.keepBlobsInJSON && (typeof arg !== 'string' || !(this.contents instanceof _Scalar.default));
619
- var mapAsMap = keep && !!this.options.mapAsMap;
620
- return (0, _toJSON2.default)(this.contents, arg, {
662
+ var _this2 = this;
663
+
664
+ var _this$options = this.options,
665
+ keepBlobsInJSON = _this$options.keepBlobsInJSON,
666
+ mapAsMap = _this$options.mapAsMap,
667
+ maxAliasCount = _this$options.maxAliasCount;
668
+ var keep = keepBlobsInJSON && (typeof arg !== 'string' || !(this.contents instanceof _Scalar.default));
669
+ var ctx = {
670
+ doc: this,
621
671
  keep: keep,
622
- mapAsMap: mapAsMap
672
+ mapAsMap: keep && !!mapAsMap,
673
+ maxAliasCount: maxAliasCount
674
+ };
675
+ var anchorNames = Object.keys(this.anchors.map);
676
+ if (anchorNames.length > 0) ctx.anchors = anchorNames.map(function (name) {
677
+ return {
678
+ alias: [],
679
+ aliasCount: 0,
680
+ count: 1,
681
+ node: _this2.anchors.map[name]
682
+ };
623
683
  });
684
+ return (0, _toJSON2.default)(this.contents, arg, ctx);
624
685
  }
625
686
  }, {
626
687
  key: "toString",
@@ -664,11 +725,14 @@ function () {
664
725
  var contentComment = null;
665
726
 
666
727
  if (this.contents) {
667
- if (this.contents.spaceBefore && hasDirectives) lines.push('');
668
- if (this.contents.commentBefore) lines.push(this.contents.commentBefore.replace(/^/gm, '#')); // top-level block scalars need to be indented if followed by a comment
728
+ if (this.contents instanceof _Node.default) {
729
+ if (this.contents.spaceBefore && hasDirectives) lines.push('');
730
+ if (this.contents.commentBefore) lines.push(this.contents.commentBefore.replace(/^/gm, '#')); // top-level block scalars need to be indented if followed by a comment
731
+
732
+ ctx.forceBlockIndent = !!this.comment;
733
+ contentComment = this.contents.comment;
734
+ }
669
735
 
670
- ctx.forceBlockIndent = !!this.comment;
671
- contentComment = this.contents.comment;
672
736
  var onChompKeep = contentComment ? null : function () {
673
737
  return chompKeep = true;
674
738
  };
@@ -726,6 +790,4 @@ exports.default = Document;
726
790
  prefix: _schema.default.defaultPrefix
727
791
  }]
728
792
  }
729
- });
730
- module.exports = exports.default;
731
- module.exports.default = exports.default;
793
+ });
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Type = exports.Char = void 0;
7
+ var Char = {
8
+ ANCHOR: '&',
9
+ COMMENT: '#',
10
+ TAG: '!',
11
+ DIRECTIVES_END: '-',
12
+ DOCUMENT_END: '.'
13
+ };
14
+ exports.Char = Char;
15
+ var Type = {
16
+ ALIAS: 'ALIAS',
17
+ BLANK_LINE: 'BLANK_LINE',
18
+ BLOCK_FOLDED: 'BLOCK_FOLDED',
19
+ BLOCK_LITERAL: 'BLOCK_LITERAL',
20
+ COMMENT: 'COMMENT',
21
+ DIRECTIVE: 'DIRECTIVE',
22
+ DOCUMENT: 'DOCUMENT',
23
+ FLOW_MAP: 'FLOW_MAP',
24
+ FLOW_SEQ: 'FLOW_SEQ',
25
+ MAP: 'MAP',
26
+ MAP_KEY: 'MAP_KEY',
27
+ MAP_VALUE: 'MAP_VALUE',
28
+ PLAIN: 'PLAIN',
29
+ QUOTE_DOUBLE: 'QUOTE_DOUBLE',
30
+ QUOTE_SINGLE: 'QUOTE_SINGLE',
31
+ SEQ: 'SEQ',
32
+ SEQ_ITEM: 'SEQ_ITEM'
33
+ };
34
+ exports.Type = Type;
@@ -56,6 +56,4 @@ function (_Node) {
56
56
  return Alias;
57
57
  }(_Node2.default);
58
58
 
59
- exports.default = Alias;
60
- module.exports = exports.default;
61
- module.exports.default = exports.default;
59
+ exports.default = Alias;
@@ -1,7 +1,5 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
-
5
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
4
 
7
5
  Object.defineProperty(exports, "__esModule", {
@@ -19,7 +17,9 @@ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/ge
19
17
 
20
18
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
21
19
 
22
- var _Node2 = _interopRequireWildcard(require("./Node"));
20
+ var _constants = require("../constants");
21
+
22
+ var _Node2 = _interopRequireDefault(require("./Node"));
23
23
 
24
24
  var _Range = _interopRequireDefault(require("./Range"));
25
25
 
@@ -30,7 +30,7 @@ function (_Node) {
30
30
 
31
31
  function BlankLine() {
32
32
  (0, _classCallCheck2.default)(this, BlankLine);
33
- return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(BlankLine).call(this, _Node2.Type.BLANK_LINE));
33
+ return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(BlankLine).call(this, _constants.Type.BLANK_LINE));
34
34
  }
35
35
 
36
36
  (0, _createClass2.default)(BlankLine, [{
@@ -66,6 +66,4 @@ function (_Node) {
66
66
  return BlankLine;
67
67
  }(_Node2.default);
68
68
 
69
- exports.default = BlankLine;
70
- module.exports = exports.default;
71
- module.exports.default = exports.default;
69
+ exports.default = BlankLine;
@@ -1,7 +1,5 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
-
5
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
4
 
7
5
  Object.defineProperty(exports, "__esModule", {
@@ -21,7 +19,9 @@ var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
21
19
 
22
20
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
23
21
 
24
- var _Node2 = _interopRequireWildcard(require("./Node"));
22
+ var _constants = require("../constants");
23
+
24
+ var _Node2 = _interopRequireDefault(require("./Node"));
25
25
 
26
26
  var _Range = _interopRequireDefault(require("./Range"));
27
27
 
@@ -222,7 +222,7 @@ function (_Node) {
222
222
  }
223
223
 
224
224
  var bi = indent + this.blockIndent;
225
- var folded = this.type === _Node2.Type.BLOCK_FOLDED;
225
+ var folded = this.type === _constants.Type.BLOCK_FOLDED;
226
226
  var atStart = true;
227
227
  var str = '';
228
228
  var sep = '';
@@ -1,7 +1,5 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
-
5
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
4
 
7
5
  Object.defineProperty(exports, "__esModule", {
@@ -22,13 +20,15 @@ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/creat
22
20
 
23
21
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
24
22
 
23
+ var _constants = require("../constants");
24
+
25
25
  var _BlankLine = _interopRequireDefault(require("./BlankLine"));
26
26
 
27
27
  var _CollectionItem = _interopRequireDefault(require("./CollectionItem"));
28
28
 
29
29
  var _Comment = _interopRequireDefault(require("./Comment"));
30
30
 
31
- var _Node2 = _interopRequireWildcard(require("./Node"));
31
+ var _Node2 = _interopRequireDefault(require("./Node"));
32
32
 
33
33
  var _Range = _interopRequireDefault(require("./Range"));
34
34
 
@@ -46,14 +46,14 @@ function grabCollectionEndComments(node) {
46
46
  for (var i = len - 1; i >= 0; --i) {
47
47
  var n = cnode.items[i];
48
48
 
49
- if (n.type === _Node2.Type.COMMENT) {
49
+ if (n.type === _constants.Type.COMMENT) {
50
50
  // Keep sufficiently indented comments with preceding node
51
51
  var _n$context = n.context,
52
52
  indent = _n$context.indent,
53
53
  lineStart = _n$context.lineStart;
54
54
  if (indent > 0 && n.range.start >= lineStart + indent) break;
55
55
  ci = i;
56
- } else if (n.type === _Node2.Type.BLANK_LINE) ci = i;else break;
56
+ } else if (n.type === _constants.Type.BLANK_LINE) ci = i;else break;
57
57
  }
58
58
 
59
59
  if (ci === -1) return null;
@@ -82,7 +82,7 @@ function (_Node) {
82
82
  var ch = src[offset];
83
83
  if (!ch) return false;
84
84
  if (offset >= lineStart + indent) return true;
85
- if (ch !== '#') return false;
85
+ if (ch !== '#' && ch !== '\n') return false;
86
86
  return Collection.nextContentHasIndent(src, offset, indent);
87
87
  }
88
88
  }]);
@@ -91,7 +91,7 @@ function (_Node) {
91
91
  var _this;
92
92
 
93
93
  (0, _classCallCheck2.default)(this, Collection);
94
- _this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(Collection).call(this, firstItem.type === _Node2.Type.SEQ_ITEM ? _Node2.Type.SEQ : _Node2.Type.MAP));
94
+ _this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(Collection).call(this, firstItem.type === _constants.Type.SEQ_ITEM ? _constants.Type.SEQ : _constants.Type.MAP));
95
95
 
96
96
  for (var i = firstItem.props.length - 1; i >= 0; --i) {
97
97
  if (firstItem.props[i].start < firstItem.context.lineStart) {
@@ -200,7 +200,7 @@ function (_Node) {
200
200
  break;
201
201
  }
202
202
 
203
- if (firstItem.type === _Node2.Type.SEQ_ITEM !== (ch === '-')) {
203
+ if (firstItem.type === _constants.Type.SEQ_ITEM !== (ch === '-')) {
204
204
  var typeswitch = true;
205
205
 
206
206
  if (ch === '-') {