yaml 1.3.2 → 1.6.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 (144) hide show
  1. package/README.md +4 -6
  2. package/browser/dist/Anchors.js +12 -10
  3. package/browser/dist/Document.js +170 -75
  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 +17 -11
  13. package/browser/dist/cst/FlowCollection.js +14 -8
  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 +1 -4
  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 +37 -7
  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 +37 -23
  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 +89 -45
  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 +17 -11
  79. package/dist/cst/FlowCollection.js +14 -8
  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 +1 -4
  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 +18 -5
  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 +30 -16
  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 +23 -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/polyfill.js +0 -27
  141. package/dist/schema/core.js +0 -79
  142. package/dist/schema/failsafe.js +0 -74
  143. package/dist/schema/json.js +0 -56
  144. package/dist/schema/yaml-1.1.js +0 -115
@@ -76,7 +76,4 @@ function getLinePos(offset, cst) {
76
76
  }
77
77
 
78
78
  return undefined;
79
- }
80
-
81
- module.exports = exports.default;
82
- module.exports.default = exports.default;
79
+ }
@@ -56,7 +56,4 @@ function parse(src) {
56
56
  };
57
57
 
58
58
  return documents;
59
- }
60
-
61
- module.exports = exports.default;
62
- module.exports.default = exports.default;
59
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.warnFileDeprecation = warnFileDeprecation;
7
+ exports.warnOptionDeprecation = warnOptionDeprecation;
8
+
9
+ /* global global, console */
10
+ function warn(msg) {
11
+ if (global && global.process && global.process.emitWarning) {
12
+ global.process.emitWarning(msg, 'DeprecationWarning');
13
+ } else {
14
+ // eslint-disable-next-line no-console
15
+ console.warn("DeprecationWarning: ".concat(msg));
16
+ }
17
+ }
18
+
19
+ function warnFileDeprecation(filename) {
20
+ if (global && global._YAML_SILENCE_DEPRECATION_WARNINGS) return;
21
+ var path = filename.replace(/.*yaml[/\\]/i, '').replace(/\.js$/, '').replace(/\\/g, '/');
22
+ warn("The endpoint 'yaml/".concat(path, "' will be removed in a future release."));
23
+ }
24
+
25
+ var warned = {};
26
+
27
+ function warnOptionDeprecation(name, alternative) {
28
+ if (global && global._YAML_SILENCE_DEPRECATION_WARNINGS) return;
29
+ if (warned[name]) return;
30
+ warned[name] = true;
31
+ var msg = "The option '".concat(name, "' will be removed in a future release");
32
+ msg += alternative ? ", use '".concat(alternative, "' instead.") : '.';
33
+ warn(msg);
34
+ }
@@ -5,10 +5,12 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.YAMLWarning = exports.YAMLSyntaxError = exports.YAMLSemanticError = exports.YAMLReferenceError = void 0;
8
+ exports.YAMLWarning = exports.YAMLSyntaxError = exports.YAMLSemanticError = exports.YAMLReferenceError = exports.YAMLError = void 0;
9
9
 
10
10
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
11
 
12
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
+
12
14
  var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
13
15
 
14
16
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
@@ -19,106 +21,95 @@ var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/w
19
21
 
20
22
  var _Node = _interopRequireDefault(require("./cst/Node"));
21
23
 
22
- var YAMLReferenceError =
24
+ var YAMLError =
23
25
  /*#__PURE__*/
24
- function (_ReferenceError) {
25
- (0, _inherits2.default)(YAMLReferenceError, _ReferenceError);
26
+ function (_Error) {
27
+ (0, _inherits2.default)(YAMLError, _Error);
26
28
 
27
- function YAMLReferenceError(source, message) {
29
+ function YAMLError(name, source, message) {
28
30
  var _this;
29
31
 
30
- (0, _classCallCheck2.default)(this, YAMLReferenceError);
31
-
32
- if (!message || !(source instanceof _Node.default)) {
33
- throw new Error('Invalid arguments for new YAMLReferenceError');
34
- }
35
-
36
- _this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(YAMLReferenceError).call(this));
37
- _this.name = 'YAMLReferenceError';
32
+ (0, _classCallCheck2.default)(this, YAMLError);
33
+ if (!message || !(source instanceof _Node.default)) throw new Error("Invalid arguments for new ".concat(name));
34
+ _this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(YAMLError).call(this));
35
+ _this.name = name;
38
36
  _this.message = message;
39
37
  _this.source = source;
40
38
  return _this;
41
39
  }
42
40
 
41
+ (0, _createClass2.default)(YAMLError, [{
42
+ key: "makePretty",
43
+ value: function makePretty() {
44
+ if (this.source) {
45
+ this.nodeType = this.source.type;
46
+ this.range = this.source.range;
47
+ this.linePos = this.source.rangeAsLinePos;
48
+ delete this.source;
49
+ }
50
+ }
51
+ }]);
52
+ return YAMLError;
53
+ }((0, _wrapNativeSuper2.default)(Error));
54
+
55
+ exports.YAMLError = YAMLError;
56
+
57
+ var YAMLReferenceError =
58
+ /*#__PURE__*/
59
+ function (_YAMLError) {
60
+ (0, _inherits2.default)(YAMLReferenceError, _YAMLError);
61
+
62
+ function YAMLReferenceError(source, message) {
63
+ (0, _classCallCheck2.default)(this, YAMLReferenceError);
64
+ return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(YAMLReferenceError).call(this, 'YAMLReferenceError', source, message));
65
+ }
66
+
43
67
  return YAMLReferenceError;
44
- }((0, _wrapNativeSuper2.default)(ReferenceError));
68
+ }(YAMLError);
45
69
 
46
70
  exports.YAMLReferenceError = YAMLReferenceError;
47
71
 
48
72
  var YAMLSemanticError =
49
73
  /*#__PURE__*/
50
- function (_SyntaxError) {
51
- (0, _inherits2.default)(YAMLSemanticError, _SyntaxError);
74
+ function (_YAMLError2) {
75
+ (0, _inherits2.default)(YAMLSemanticError, _YAMLError2);
52
76
 
53
77
  function YAMLSemanticError(source, message) {
54
- var _this2;
55
-
56
78
  (0, _classCallCheck2.default)(this, YAMLSemanticError);
57
-
58
- if (!message || !(source instanceof _Node.default)) {
59
- throw new Error('Invalid arguments for new YAMLSemanticError');
60
- }
61
-
62
- _this2 = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(YAMLSemanticError).call(this));
63
- _this2.name = 'YAMLSemanticError';
64
- _this2.message = message;
65
- _this2.source = source;
66
- return _this2;
79
+ return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(YAMLSemanticError).call(this, 'YAMLSemanticError', source, message));
67
80
  }
68
81
 
69
82
  return YAMLSemanticError;
70
- }((0, _wrapNativeSuper2.default)(SyntaxError));
83
+ }(YAMLError);
71
84
 
72
85
  exports.YAMLSemanticError = YAMLSemanticError;
73
86
 
74
87
  var YAMLSyntaxError =
75
88
  /*#__PURE__*/
76
- function (_SyntaxError2) {
77
- (0, _inherits2.default)(YAMLSyntaxError, _SyntaxError2);
89
+ function (_YAMLError3) {
90
+ (0, _inherits2.default)(YAMLSyntaxError, _YAMLError3);
78
91
 
79
92
  function YAMLSyntaxError(source, message) {
80
- var _this3;
81
-
82
93
  (0, _classCallCheck2.default)(this, YAMLSyntaxError);
83
-
84
- if (!message || !(source instanceof _Node.default)) {
85
- throw new Error('Invalid arguments for new YAMLSyntaxError');
86
- }
87
-
88
- _this3 = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(YAMLSyntaxError).call(this));
89
- _this3.name = 'YAMLSyntaxError';
90
- _this3.message = message;
91
- _this3.source = source;
92
- return _this3;
94
+ return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(YAMLSyntaxError).call(this, 'YAMLSyntaxError', source, message));
93
95
  }
94
96
 
95
97
  return YAMLSyntaxError;
96
- }((0, _wrapNativeSuper2.default)(SyntaxError));
98
+ }(YAMLError);
97
99
 
98
100
  exports.YAMLSyntaxError = YAMLSyntaxError;
99
101
 
100
102
  var YAMLWarning =
101
103
  /*#__PURE__*/
102
- function (_Error) {
103
- (0, _inherits2.default)(YAMLWarning, _Error);
104
+ function (_YAMLError4) {
105
+ (0, _inherits2.default)(YAMLWarning, _YAMLError4);
104
106
 
105
107
  function YAMLWarning(source, message) {
106
- var _this4;
107
-
108
108
  (0, _classCallCheck2.default)(this, YAMLWarning);
109
-
110
- if (!message || !(source instanceof _Node.default)) {
111
- throw new Error('Invalid arguments for new YAMLWarning');
112
- }
113
-
114
- _this4 = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(YAMLWarning).call(this));
115
- _this4.name = 'YAMLWarning';
116
- _this4.message = message;
117
- _this4.source = source;
118
- return _this4;
109
+ return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(YAMLWarning).call(this, 'YAMLWarning', source, message));
119
110
  }
120
111
 
121
112
  return YAMLWarning;
122
- }((0, _wrapNativeSuper2.default)(Error));
113
+ }(YAMLError);
123
114
 
124
115
  exports.YAMLWarning = YAMLWarning;
@@ -25,10 +25,15 @@ var _schema = _interopRequireDefault(require("./schema"));
25
25
 
26
26
  /* global console */
27
27
  var defaultOptions = {
28
+ anchorPrefix: 'a',
29
+ customTags: null,
30
+ keepCstNodes: false,
28
31
  keepNodeTypes: true,
29
32
  keepBlobsInJSON: true,
30
33
  mapAsMap: false,
31
- tags: null,
34
+ maxAliasCount: 100,
35
+ prettyErrors: false,
36
+ // TODO Set true in v2
32
37
  version: '1.2'
33
38
  };
34
39
 
@@ -60,9 +65,36 @@ function (_YAMLDocument) {
60
65
  }(_Document.default);
61
66
 
62
67
  function parseAllDocuments(src, options) {
63
- return (0, _parse.default)(src).map(function (cstDoc) {
64
- return new Document(options).parse(cstDoc);
65
- });
68
+ var stream = [];
69
+ var prev;
70
+ var _iteratorNormalCompletion = true;
71
+ var _didIteratorError = false;
72
+ var _iteratorError = undefined;
73
+
74
+ try {
75
+ for (var _iterator = (0, _parse.default)(src)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
76
+ var cstDoc = _step.value;
77
+ var doc = new Document(options);
78
+ doc.parse(cstDoc, prev);
79
+ stream.push(doc);
80
+ prev = doc;
81
+ }
82
+ } catch (err) {
83
+ _didIteratorError = true;
84
+ _iteratorError = err;
85
+ } finally {
86
+ try {
87
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
88
+ _iterator.return();
89
+ }
90
+ } finally {
91
+ if (_didIteratorError) {
92
+ throw _iteratorError;
93
+ }
94
+ }
95
+ }
96
+
97
+ return stream;
66
98
  }
67
99
 
68
100
  function parseDocument(src, options) {
@@ -103,6 +135,4 @@ var _default = {
103
135
  parseDocument: parseDocument,
104
136
  stringify: stringify
105
137
  };
106
- exports.default = _default;
107
- module.exports = exports.default;
108
- module.exports.default = exports.default;
138
+ exports.default = _default;
@@ -39,6 +39,4 @@ var _default = function _default(node) {
39
39
  return Object.keys(visit(node, {}));
40
40
  };
41
41
 
42
- exports.default = _default;
43
- module.exports = exports.default;
44
- module.exports.default = exports.default;
42
+ exports.default = _default;
@@ -19,11 +19,60 @@ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits
19
19
 
20
20
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
21
21
 
22
- var _Node2 = require("../cst/Node");
22
+ var _constants = require("../constants");
23
+
24
+ var _errors = require("../errors");
23
25
 
24
26
  var _toJSON2 = _interopRequireDefault(require("../toJSON"));
25
27
 
26
- var _Node3 = _interopRequireDefault(require("./Node"));
28
+ var _Collection = _interopRequireDefault(require("./Collection"));
29
+
30
+ var _Node2 = _interopRequireDefault(require("./Node"));
31
+
32
+ var _Pair = _interopRequireDefault(require("./Pair"));
33
+
34
+ var getAliasCount = function getAliasCount(node, anchors) {
35
+ if (node instanceof Alias) {
36
+ var anchor = anchors.find(function (a) {
37
+ return a.node === node.source;
38
+ });
39
+ return anchor.count * anchor.aliasCount;
40
+ } else if (node instanceof _Collection.default) {
41
+ var count = 0;
42
+ var _iteratorNormalCompletion = true;
43
+ var _didIteratorError = false;
44
+ var _iteratorError = undefined;
45
+
46
+ try {
47
+ for (var _iterator = node.items[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
48
+ var item = _step.value;
49
+ var c = getAliasCount(item, anchors);
50
+ if (c > count) count = c;
51
+ }
52
+ } catch (err) {
53
+ _didIteratorError = true;
54
+ _iteratorError = err;
55
+ } finally {
56
+ try {
57
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
58
+ _iterator.return();
59
+ }
60
+ } finally {
61
+ if (_didIteratorError) {
62
+ throw _iteratorError;
63
+ }
64
+ }
65
+ }
66
+
67
+ return count;
68
+ } else if (node instanceof _Pair.default) {
69
+ var kc = getAliasCount(node.key, anchors);
70
+ var vc = getAliasCount(node.value, anchors);
71
+ return Math.max(kc, vc);
72
+ }
73
+
74
+ return 1;
75
+ };
27
76
 
28
77
  var Alias =
29
78
  /*#__PURE__*/
@@ -36,10 +85,12 @@ function (_Node) {
36
85
  source = _ref.source;
37
86
  var anchors = _ref2.anchors,
38
87
  doc = _ref2.doc,
39
- implicitKey = _ref2.implicitKey;
88
+ implicitKey = _ref2.implicitKey,
89
+ inStringifyKey = _ref2.inStringifyKey;
40
90
  var anchor = Object.keys(anchors).find(function (a) {
41
91
  return anchors[a] === source;
42
92
  });
93
+ if (!anchor && inStringifyKey) anchor = doc.anchors.getName(source) || doc.anchors.newName();
43
94
  if (anchor) return "*".concat(anchor).concat(implicitKey ? ' ' : '');
44
95
  var msg = doc.anchors.getName(source) ? 'Alias node must be after source node' : 'Source node not found for alias node';
45
96
  throw new Error("".concat(msg, " [").concat(range, "]"));
@@ -52,14 +103,45 @@ function (_Node) {
52
103
  (0, _classCallCheck2.default)(this, Alias);
53
104
  _this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(Alias).call(this));
54
105
  _this.source = source;
55
- _this.type = _Node2.Type.ALIAS;
106
+ _this.type = _constants.Type.ALIAS;
56
107
  return _this;
57
108
  }
58
109
 
59
110
  (0, _createClass2.default)(Alias, [{
60
111
  key: "toJSON",
61
- value: function toJSON(arg, opt) {
62
- return (0, _toJSON2.default)(this.source, arg, opt);
112
+ value: function toJSON(arg, ctx) {
113
+ var _this2 = this;
114
+
115
+ if (!ctx) return (0, _toJSON2.default)(this.source, arg, ctx);
116
+ var anchors = ctx.anchors,
117
+ maxAliasCount = ctx.maxAliasCount;
118
+ var anchor = anchors.find(function (a) {
119
+ return a.node === _this2.source;
120
+ });
121
+
122
+ if (!anchor || !anchor.res) {
123
+ var msg = 'This should not happen: Alias anchor was not resolved?';
124
+ if (this.cstNode) throw new _errors.YAMLReferenceError(this.cstNode, msg);else throw new ReferenceError(msg);
125
+ }
126
+
127
+ if (maxAliasCount >= 0) {
128
+ anchor.count += 1;
129
+ if (anchor.aliasCount === 0) anchor.aliasCount = getAliasCount(this.source, anchors);
130
+
131
+ if (anchor.count * anchor.aliasCount > maxAliasCount) {
132
+ var _msg = 'Excessive alias count indicates a resource exhaustion attack';
133
+ if (this.cstNode) throw new _errors.YAMLReferenceError(this.cstNode, _msg);else throw new ReferenceError(_msg);
134
+ }
135
+ }
136
+
137
+ return anchor.res;
138
+ } // Only called when stringifying an alias mapping key while constructing
139
+ // Object output.
140
+
141
+ }, {
142
+ key: "toString",
143
+ value: function toString(ctx) {
144
+ return Alias.stringify(this, ctx);
63
145
  }
64
146
  }, {
65
147
  key: "tag",
@@ -68,9 +150,7 @@ function (_Node) {
68
150
  }
69
151
  }]);
70
152
  return Alias;
71
- }(_Node3.default);
153
+ }(_Node2.default);
72
154
 
73
155
  exports.default = Alias;
74
- (0, _defineProperty2.default)(Alias, "default", true);
75
- module.exports = exports.default;
76
- module.exports.default = exports.default;
156
+ (0, _defineProperty2.default)(Alias, "default", true);
@@ -17,10 +17,10 @@ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime
17
17
 
18
18
  var _getPrototypeOf3 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
19
19
 
20
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
21
-
22
20
  var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
23
21
 
22
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
23
+
24
24
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
25
25
 
26
26
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
@@ -57,7 +57,7 @@ function (_Node) {
57
57
  }
58
58
 
59
59
  _this = (0, _possibleConstructorReturn2.default)(this, (_getPrototypeOf2 = (0, _getPrototypeOf3.default)(Collection)).call.apply(_getPrototypeOf2, [this].concat(args)));
60
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)), "items", []);
60
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "items", []);
61
61
  return _this;
62
62
  }
63
63
 
@@ -8,8 +8,6 @@ Object.defineProperty(exports, "__esModule", {
8
8
  exports.findPair = findPair;
9
9
  exports.default = void 0;
10
10
 
11
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
12
-
13
11
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
14
12
 
15
13
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
@@ -22,17 +20,12 @@ var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
22
20
 
23
21
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
24
22
 
25
- var _toJSON2 = _interopRequireDefault(require("../toJSON"));
26
-
27
23
  var _Collection2 = _interopRequireDefault(require("./Collection"));
28
24
 
29
- var _Merge = _interopRequireDefault(require("./Merge"));
30
-
31
25
  var _Pair = _interopRequireDefault(require("./Pair"));
32
26
 
33
27
  var _Scalar = _interopRequireDefault(require("./Scalar"));
34
28
 
35
- // Published as 'yaml/map'
36
29
  function findPair(items, key) {
37
30
  var k = key instanceof _Scalar.default ? key.value : key;
38
31
  var _iteratorNormalCompletion = true;
@@ -110,52 +103,18 @@ function (_Collection) {
110
103
  var prev = findPair(this.items, key);
111
104
  if (prev) prev.value = value;else this.items.push(new _Pair.default(key, value));
112
105
  }
113
- }, {
114
- key: "toJSON",
115
- value: function toJSON(_, opt) {
116
- if (opt && opt.mapAsMap) return this.toJSMap(opt);
117
- return this.items.reduce(function (map, item) {
118
- if (item instanceof _Merge.default) {
119
- (function () {
120
- // If the value associated with a merge key is a single mapping node,
121
- // each of its key/value pairs is inserted into the current mapping,
122
- // unless the key already exists in it. If the value associated with the
123
- // merge key is a sequence, then this sequence is expected to contain
124
- // mapping nodes and each of these nodes is merged in turn according to
125
- // its order in the sequence. Keys in mapping nodes earlier in the
126
- // sequence override keys specified in later mapping nodes.
127
- // -- http://yaml.org/type/merge.html
128
- var keys = Object.keys(map);
129
- var items = item.value.items;
130
-
131
- for (var i = items.length - 1; i >= 0; --i) {
132
- var source = items[i].source;
133
-
134
- if (source instanceof YAMLMap) {
135
- (function () {
136
- var obj = source.toJSON('', opt);
137
- Object.keys(obj).forEach(function (key) {
138
- if (!keys.includes(key)) map[key] = obj[key];
139
- });
140
- })();
141
- } else {
142
- throw new Error('Merge sources must be maps');
143
- }
144
- }
145
- })();
146
- } else {
147
- var stringKey = item.stringKey,
148
- value = item.value;
149
- map[stringKey] = (0, _toJSON2.default)(value, stringKey, opt);
150
- }
106
+ /**
107
+ * @param {*} arg ignored
108
+ * @param {*} ctx Conversion context, originally set in Document#toJSON()
109
+ * @param {Class} Type If set, forces the returned collection type
110
+ * @returns {*} Instance of Type, Map, or Object
111
+ */
151
112
 
152
- return map;
153
- }, {});
154
- }
155
113
  }, {
156
- key: "toJSMap",
157
- value: function toJSMap(opt) {
158
- var map = new Map();
114
+ key: "toJSON",
115
+ value: function toJSON(_, ctx, Type) {
116
+ var map = Type ? new Type() : ctx && ctx.mapAsMap ? new Map() : {};
117
+ if (ctx && ctx.onCreate) ctx.onCreate(map);
159
118
  var _iteratorNormalCompletion2 = true;
160
119
  var _didIteratorError2 = false;
161
120
  var _iteratorError2 = undefined;
@@ -163,49 +122,7 @@ function (_Collection) {
163
122
  try {
164
123
  for (var _iterator2 = this.items[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
165
124
  var item = _step2.value;
166
-
167
- if (item instanceof _Merge.default) {
168
- var items = item.value.items;
169
-
170
- for (var i = items.length - 1; i >= 0; --i) {
171
- var source = items[i].source;
172
-
173
- if (source instanceof YAMLMap) {
174
- var _iteratorNormalCompletion3 = true;
175
- var _didIteratorError3 = false;
176
- var _iteratorError3 = undefined;
177
-
178
- try {
179
- for (var _iterator3 = source.toJSMap(opt)[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
180
- var _step3$value = (0, _slicedToArray2.default)(_step3.value, 2),
181
- key = _step3$value[0],
182
- value = _step3$value[1];
183
-
184
- if (!map.has(key)) map.set(key, value);
185
- }
186
- } catch (err) {
187
- _didIteratorError3 = true;
188
- _iteratorError3 = err;
189
- } finally {
190
- try {
191
- if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
192
- _iterator3.return();
193
- }
194
- } finally {
195
- if (_didIteratorError3) {
196
- throw _iteratorError3;
197
- }
198
- }
199
- }
200
- } else {
201
- throw new Error('Merge sources must be maps');
202
- }
203
- }
204
- } else {
205
- var key = (0, _toJSON2.default)(item.key, '', opt);
206
- var value = (0, _toJSON2.default)(item.value, key, opt);
207
- map.set(key, value);
208
- }
125
+ item.addToJSMap(ctx, map);
209
126
  }
210
127
  } catch (err) {
211
128
  _didIteratorError2 = true;
@@ -228,26 +145,26 @@ function (_Collection) {
228
145
  key: "toString",
229
146
  value: function toString(ctx, onComment, onChompKeep) {
230
147
  if (!ctx) return JSON.stringify(this);
231
- var _iteratorNormalCompletion4 = true;
232
- var _didIteratorError4 = false;
233
- var _iteratorError4 = undefined;
148
+ var _iteratorNormalCompletion3 = true;
149
+ var _didIteratorError3 = false;
150
+ var _iteratorError3 = undefined;
234
151
 
235
152
  try {
236
- for (var _iterator4 = this.items[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
237
- var item = _step4.value;
153
+ for (var _iterator3 = this.items[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
154
+ var item = _step3.value;
238
155
  if (!(item instanceof _Pair.default)) throw new Error("Map items must all be pairs; found ".concat(JSON.stringify(item), " instead"));
239
156
  }
240
157
  } catch (err) {
241
- _didIteratorError4 = true;
242
- _iteratorError4 = err;
158
+ _didIteratorError3 = true;
159
+ _iteratorError3 = err;
243
160
  } finally {
244
161
  try {
245
- if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
246
- _iterator4.return();
162
+ if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
163
+ _iterator3.return();
247
164
  }
248
165
  } finally {
249
- if (_didIteratorError4) {
250
- throw _iteratorError4;
166
+ if (_didIteratorError3) {
167
+ throw _iteratorError3;
251
168
  }
252
169
  }
253
170
  }