yaml 1.4.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 (136) hide show
  1. package/README.md +3 -5
  2. package/browser/dist/Anchors.js +1 -3
  3. package/browser/dist/Document.js +94 -37
  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 +7 -7
  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 +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 +5 -4
  25. package/browser/dist/listTagNames.js +1 -3
  26. package/browser/dist/schema/Alias.js +85 -10
  27. package/browser/dist/schema/Map.js +14 -121
  28. package/browser/dist/schema/Merge.js +74 -1
  29. package/browser/dist/schema/Node.js +1 -3
  30. package/browser/dist/schema/Pair.js +36 -22
  31. package/browser/dist/schema/Scalar.js +1 -3
  32. package/browser/dist/schema/Seq.js +1 -3
  33. package/browser/dist/schema/index.js +61 -45
  34. package/browser/dist/schema/parseMap.js +18 -21
  35. package/browser/dist/schema/parseSeq.js +9 -12
  36. package/browser/dist/stringify.js +54 -39
  37. package/browser/dist/{schema → tags}/core.js +32 -20
  38. package/browser/dist/tags/failsafe/index.js +17 -0
  39. package/browser/dist/tags/failsafe/map.js +65 -0
  40. package/browser/dist/tags/failsafe/seq.js +54 -0
  41. package/browser/dist/{schema/_string.js → tags/failsafe/string.js} +11 -11
  42. package/browser/dist/tags/index.js +50 -0
  43. package/browser/dist/{schema → tags}/json.js +8 -8
  44. package/browser/dist/tags/options.js +35 -0
  45. package/browser/dist/{schema/_binary.js → tags/yaml-1.1/binary.js} +16 -22
  46. package/browser/dist/{schema/yaml-1.1.js → tags/yaml-1.1/index.js} +43 -29
  47. package/browser/dist/{schema/_omap.js → tags/yaml-1.1/omap.js} +8 -11
  48. package/browser/dist/{schema/_pairs.js → tags/yaml-1.1/pairs.js} +8 -12
  49. package/browser/dist/tags/yaml-1.1/set.js +140 -0
  50. package/browser/dist/{schema/_timestamp.js → tags/yaml-1.1/timestamp.js} +4 -7
  51. package/browser/dist/test-events.js +1 -4
  52. package/browser/dist/toJSON.js +1 -4
  53. package/browser/index.js +1 -0
  54. package/browser/map.js +2 -1
  55. package/browser/pair.js +2 -1
  56. package/browser/parse-cst.js +1 -1
  57. package/browser/scalar.js +2 -1
  58. package/browser/schema.js +7 -4
  59. package/browser/seq.js +2 -1
  60. package/browser/types/binary.js +7 -1
  61. package/browser/types/omap.js +2 -1
  62. package/browser/types/pairs.js +2 -1
  63. package/browser/types/set.js +2 -1
  64. package/browser/types/timestamp.js +10 -1
  65. package/browser/types.js +11 -0
  66. package/browser/util.js +15 -0
  67. package/dist/Anchors.js +1 -3
  68. package/dist/Document.js +38 -25
  69. package/dist/constants.js +34 -0
  70. package/dist/cst/Alias.js +1 -3
  71. package/dist/cst/BlankLine.js +5 -7
  72. package/dist/cst/BlockValue.js +4 -4
  73. package/dist/cst/Collection.js +7 -7
  74. package/dist/cst/CollectionItem.js +6 -8
  75. package/dist/cst/Comment.js +5 -7
  76. package/dist/cst/Directive.js +5 -7
  77. package/dist/cst/Document.js +8 -10
  78. package/dist/cst/FlowCollection.js +5 -7
  79. package/dist/cst/Node.js +12 -40
  80. package/dist/cst/ParseContext.js +32 -34
  81. package/dist/cst/PlainValue.js +1 -3
  82. package/dist/cst/QuoteDouble.js +1 -3
  83. package/dist/cst/QuoteSingle.js +1 -3
  84. package/dist/cst/Range.js +1 -3
  85. package/dist/cst/getLinePos.js +1 -4
  86. package/dist/cst/parse.js +1 -4
  87. package/dist/deprecation.js +34 -0
  88. package/dist/errors.js +29 -35
  89. package/dist/index.js +5 -4
  90. package/dist/listTagNames.js +1 -3
  91. package/dist/schema/Alias.js +66 -12
  92. package/dist/schema/Map.js +9 -77
  93. package/dist/schema/Merge.js +31 -0
  94. package/dist/schema/Node.js +1 -3
  95. package/dist/schema/Pair.js +29 -15
  96. package/dist/schema/Scalar.js +1 -3
  97. package/dist/schema/Seq.js +1 -3
  98. package/dist/schema/index.js +55 -45
  99. package/dist/schema/parseMap.js +18 -21
  100. package/dist/schema/parseSeq.js +9 -12
  101. package/dist/stringify.js +46 -32
  102. package/dist/{schema → tags}/core.js +32 -19
  103. package/dist/tags/failsafe/index.js +17 -0
  104. package/dist/tags/failsafe/map.js +33 -0
  105. package/dist/tags/failsafe/seq.js +34 -0
  106. package/dist/tags/failsafe/string.js +40 -0
  107. package/dist/tags/index.js +50 -0
  108. package/dist/{schema → tags}/json.js +8 -8
  109. package/dist/tags/options.js +35 -0
  110. package/dist/{schema/_binary.js → tags/yaml-1.1/binary.js} +15 -21
  111. package/dist/{schema/yaml-1.1.js → tags/yaml-1.1/index.js} +43 -30
  112. package/dist/{schema/_omap.js → tags/yaml-1.1/omap.js} +8 -9
  113. package/dist/{schema/_pairs.js → tags/yaml-1.1/pairs.js} +8 -10
  114. package/dist/{schema/_set.js → tags/yaml-1.1/set.js} +9 -42
  115. package/dist/{schema/_timestamp.js → tags/yaml-1.1/timestamp.js} +4 -7
  116. package/dist/test-events.js +1 -4
  117. package/dist/toJSON.js +1 -4
  118. package/index.js +1 -0
  119. package/map.js +2 -1
  120. package/package.json +17 -15
  121. package/pair.js +2 -1
  122. package/parse-cst.js +1 -1
  123. package/scalar.js +2 -1
  124. package/schema.js +7 -4
  125. package/seq.js +2 -1
  126. package/types/binary.js +7 -1
  127. package/types/omap.js +2 -1
  128. package/types/pairs.js +2 -1
  129. package/types/set.js +2 -1
  130. package/types/timestamp.js +10 -1
  131. package/types.js +11 -0
  132. package/util.js +15 -0
  133. package/browser/dist/schema/_set.js +0 -215
  134. package/browser/dist/schema/failsafe.js +0 -125
  135. package/dist/schema/_string.js +0 -40
  136. package/dist/schema/failsafe.js +0 -74
@@ -9,15 +9,15 @@ exports.parsePairs = parsePairs;
9
9
  exports.createPairs = createPairs;
10
10
  exports.default = void 0;
11
11
 
12
- var _errors = require("../errors");
12
+ var _errors = require("../../errors");
13
13
 
14
- var _Map = _interopRequireDefault(require("./Map"));
14
+ var _Map = _interopRequireDefault(require("../../schema/Map"));
15
15
 
16
- var _Pair = _interopRequireDefault(require("./Pair"));
16
+ var _Pair = _interopRequireDefault(require("../../schema/Pair"));
17
17
 
18
- var _parseSeq = _interopRequireDefault(require("./parseSeq"));
18
+ var _parseSeq = _interopRequireDefault(require("../../schema/parseSeq"));
19
19
 
20
- var _Seq = _interopRequireDefault(require("./Seq"));
20
+ var _Seq = _interopRequireDefault(require("../../schema/Seq"));
21
21
 
22
22
  function parsePairs(doc, cst) {
23
23
  var seq = (0, _parseSeq.default)(doc, cst);
@@ -70,9 +70,8 @@ function createPairs(schema, iterable, ctx) {
70
70
  key = it;
71
71
  }
72
72
 
73
- var k = schema.createNode(key, ctx.wrapScalars, null, ctx);
74
- var v = schema.createNode(value, ctx.wrapScalars, null, ctx);
75
- pairs.items.push(new _Pair.default(k, v));
73
+ var pair = schema.createPair(key, value, ctx);
74
+ pairs.items.push(pair);
76
75
  }
77
76
  } catch (err) {
78
77
  _didIteratorError = true;
@@ -96,9 +95,6 @@ var _default = {
96
95
  default: false,
97
96
  tag: 'tag:yaml.org,2002:pairs',
98
97
  resolve: parsePairs,
99
- createNode: createPairs,
100
- stringify: function stringify(value, ctx, onComment, onChompKeep) {
101
- return value.toString(ctx, onComment, onChompKeep);
102
- }
98
+ createNode: createPairs
103
99
  };
104
100
  exports.default = _default;
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
+
5
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports.default = exports.YAMLSet = void 0;
11
+
12
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
13
+
14
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
15
+
16
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
17
+
18
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
19
+
20
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
21
+
22
+ var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
23
+
24
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
25
+
26
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
27
+
28
+ var _errors = require("../../errors");
29
+
30
+ var _Map = _interopRequireWildcard(require("../../schema/Map"));
31
+
32
+ var _Pair = _interopRequireDefault(require("../../schema/Pair"));
33
+
34
+ var _parseMap = _interopRequireDefault(require("../../schema/parseMap"));
35
+
36
+ var _Scalar = _interopRequireDefault(require("../../schema/Scalar"));
37
+
38
+ var YAMLSet =
39
+ /*#__PURE__*/
40
+ function (_YAMLMap) {
41
+ (0, _inherits2.default)(YAMLSet, _YAMLMap);
42
+
43
+ function YAMLSet() {
44
+ var _this;
45
+
46
+ (0, _classCallCheck2.default)(this, YAMLSet);
47
+ _this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(YAMLSet).call(this));
48
+ _this.tag = YAMLSet.tag;
49
+ return _this;
50
+ }
51
+
52
+ (0, _createClass2.default)(YAMLSet, [{
53
+ key: "add",
54
+ value: function add(key) {
55
+ var pair = key instanceof _Pair.default ? key : new _Pair.default(key);
56
+ var prev = (0, _Map.findPair)(this.items, pair.key);
57
+ if (!prev) this.items.push(pair);
58
+ }
59
+ }, {
60
+ key: "get",
61
+ value: function get(key, keepPair) {
62
+ var pair = (0, _Map.findPair)(this.items, key);
63
+ return !keepPair && pair instanceof _Pair.default ? pair.key instanceof _Scalar.default ? pair.key.value : pair.key : pair;
64
+ }
65
+ }, {
66
+ key: "set",
67
+ value: function set(key, value) {
68
+ if (typeof value !== 'boolean') throw new Error("Expected boolean value for set(key, value) in a YAML set, not ".concat((0, _typeof2.default)(value)));
69
+ var prev = (0, _Map.findPair)(this.items, key);
70
+
71
+ if (prev && !value) {
72
+ this.items.splice(this.items.indexOf(prev), 1);
73
+ } else if (!prev && value) {
74
+ this.items.push(new _Pair.default(key));
75
+ }
76
+ }
77
+ }, {
78
+ key: "toJSON",
79
+ value: function toJSON(_, ctx) {
80
+ return (0, _get2.default)((0, _getPrototypeOf2.default)(YAMLSet.prototype), "toJSON", this).call(this, _, ctx, Set);
81
+ }
82
+ }, {
83
+ key: "toString",
84
+ value: function toString(ctx, onComment, onChompKeep) {
85
+ if (!ctx) return JSON.stringify(this);
86
+ if (this.hasAllNullValues()) return (0, _get2.default)((0, _getPrototypeOf2.default)(YAMLSet.prototype), "toString", this).call(this, ctx, onComment, onChompKeep);else throw new Error('Set items must all have null values');
87
+ }
88
+ }]);
89
+ return YAMLSet;
90
+ }(_Map.default);
91
+
92
+ exports.YAMLSet = YAMLSet;
93
+ (0, _defineProperty2.default)(YAMLSet, "tag", 'tag:yaml.org,2002:set');
94
+
95
+ function parseSet(doc, cst) {
96
+ var map = (0, _parseMap.default)(doc, cst);
97
+ if (!map.hasAllNullValues()) throw new _errors.YAMLSemanticError(cst, 'Set items must all have null values');
98
+ return Object.assign(new YAMLSet(), map);
99
+ }
100
+
101
+ function createSet(schema, iterable, ctx) {
102
+ var set = new YAMLSet();
103
+ var _iteratorNormalCompletion = true;
104
+ var _didIteratorError = false;
105
+ var _iteratorError = undefined;
106
+
107
+ try {
108
+ for (var _iterator = iterable[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
109
+ var value = _step.value;
110
+ set.items.push(schema.createPair(value, null, ctx));
111
+ }
112
+ } catch (err) {
113
+ _didIteratorError = true;
114
+ _iteratorError = err;
115
+ } finally {
116
+ try {
117
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
118
+ _iterator.return();
119
+ }
120
+ } finally {
121
+ if (_didIteratorError) {
122
+ throw _iteratorError;
123
+ }
124
+ }
125
+ }
126
+
127
+ return set;
128
+ }
129
+
130
+ var _default = {
131
+ identify: function identify(value) {
132
+ return value instanceof Set;
133
+ },
134
+ nodeClass: YAMLSet,
135
+ default: false,
136
+ tag: 'tag:yaml.org,2002:set',
137
+ resolve: parseSet,
138
+ createNode: createSet
139
+ };
140
+ exports.default = _default;
@@ -3,11 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = exports.timestamp = exports.floatTime = exports.intTime = void 0;
6
+ exports.timestamp = exports.floatTime = exports.intTime = void 0;
7
7
 
8
- var _core = require("./core");
8
+ var _stringify = require("../../stringify");
9
9
 
10
- // Published as 'yaml/types/timestamp'
11
10
  var parseSexagesimal = function parseSexagesimal(sign, parts) {
12
11
  var n = parts.split(':').reduce(function (n, p) {
13
12
  return n * 60 + Number(p);
@@ -18,7 +17,7 @@ var parseSexagesimal = function parseSexagesimal(sign, parts) {
18
17
 
19
18
  var stringifySexagesimal = function stringifySexagesimal(_ref) {
20
19
  var value = _ref.value;
21
- if (isNaN(value) || !isFinite(value)) return (0, _core.stringifyNumber)(value);
20
+ if (isNaN(value) || !isFinite(value)) return (0, _stringify.stringifyNumber)(value);
22
21
  var sign = '';
23
22
 
24
23
  if (value < 0) {
@@ -105,6 +104,4 @@ var timestamp = {
105
104
  return value.toISOString().replace(/((T00:00)?:00)?\.000Z$/, '');
106
105
  }
107
106
  };
108
- exports.timestamp = timestamp;
109
- var _default = [intTime, floatTime, timestamp];
110
- exports.default = _default;
107
+ exports.timestamp = timestamp;
@@ -172,7 +172,4 @@ function addEvents(events, doc, e, node) {
172
172
  var value = node.cstNode.strValue.replace(/\\/g, '\\\\').replace(/\0/g, '\\0').replace(/\x07/g, '\\a').replace(/\x08/g, '\\b').replace(/\t/g, '\\t').replace(/\n/g, '\\n').replace(/\v/g, '\\v').replace(/\f/g, '\\f').replace(/\r/g, '\\r').replace(/\x1b/g, '\\e');
173
173
  events.push("=VAL".concat(props, " ").concat(scalar).concat(value));
174
174
  }
175
- }
176
-
177
- module.exports = exports.default;
178
- module.exports.default = exports.default;
175
+ }
@@ -24,7 +24,4 @@ function toJSON(value, arg, ctx) {
24
24
  }
25
25
 
26
26
  return value;
27
- }
28
-
29
- module.exports = exports.default;
30
- module.exports.default = exports.default;
27
+ }
@@ -0,0 +1 @@
1
+ module.exports = require('./dist').default
package/browser/map.js CHANGED
@@ -1 +1,2 @@
1
- module.exports = require('./dist/schema/Map')
1
+ module.exports = require('./dist/schema/Map').default
2
+ require('./dist/deprecation').warnFileDeprecation(__filename)
package/browser/pair.js CHANGED
@@ -1 +1,2 @@
1
- module.exports = require('./dist/schema/Pair')
1
+ module.exports = require('./dist/schema/Pair').default
2
+ require('./dist/deprecation').warnFileDeprecation(__filename)
@@ -1 +1 @@
1
- module.exports = require('./dist/cst/parse')
1
+ module.exports = require('./dist/cst/parse').default
package/browser/scalar.js CHANGED
@@ -1 +1,2 @@
1
- module.exports = require('./dist/schema/Scalar')
1
+ module.exports = require('./dist/schema/Scalar').default
2
+ require('./dist/deprecation').warnFileDeprecation(__filename)
package/browser/schema.js CHANGED
@@ -1,4 +1,7 @@
1
- module.exports = require('./dist/schema')
2
- module.exports.nullOptions = require('./dist/schema/core').nullOptions
3
- module.exports.stringify = require('./dist/stringify').default
4
- module.exports.strOptions = require('./dist/stringify').strOptions
1
+ module.exports = require('./dist/schema').default
2
+ var opt = require('./dist/tags/options')
3
+ module.exports.nullOptions = opt.nullOptions
4
+ module.exports.strOptions = opt.strOptions
5
+ module.exports.stringify = require('./dist/stringify').stringifyString
6
+
7
+ require('./dist/deprecation').warnFileDeprecation(__filename)
package/browser/seq.js CHANGED
@@ -1 +1,2 @@
1
- module.exports = require('./dist/schema/Seq')
1
+ module.exports = require('./dist/schema/Seq').default
2
+ require('./dist/deprecation').warnFileDeprecation(__filename)
@@ -1 +1,7 @@
1
- module.exports = require('../dist/schema/_binary')
1
+ 'use strict'
2
+ Object.defineProperty(exports, '__esModule', { value: true })
3
+
4
+ exports.binary = require('../dist/tags/yaml-1.1/binary').default
5
+ exports.default = [exports.binary]
6
+
7
+ require('../dist/deprecation').warnFileDeprecation(__filename)
@@ -1 +1,2 @@
1
- module.exports = require('../dist/schema/_omap').default
1
+ module.exports = require('../dist/tags/yaml-1.1/omap').default
2
+ require('../dist/deprecation').warnFileDeprecation(__filename)
@@ -1 +1,2 @@
1
- module.exports = require('../dist/schema/_pairs').default
1
+ module.exports = require('../dist/tags/yaml-1.1/pairs').default
2
+ require('../dist/deprecation').warnFileDeprecation(__filename)
@@ -1 +1,2 @@
1
- module.exports = require('../dist/schema/_set').default
1
+ module.exports = require('../dist/tags/yaml-1.1/set').default
2
+ require('../dist/deprecation').warnFileDeprecation(__filename)
@@ -1 +1,10 @@
1
- module.exports = require('../dist/schema/_timestamp')
1
+ 'use strict'
2
+ Object.defineProperty(exports, '__esModule', { value: true })
3
+
4
+ var ts = require('../dist/tags/yaml-1.1/timestamp')
5
+ exports.default = [ts.intTime, ts.floatTime, ts.timestamp]
6
+ exports.floatTime = ts.floatTime
7
+ exports.intTime = ts.intTime
8
+ exports.timestamp = ts.timestamp
9
+
10
+ require('../dist/deprecation').warnFileDeprecation(__filename)
@@ -0,0 +1,11 @@
1
+ var opt = require('./dist/tags/options')
2
+ exports.binaryOptions = opt.binaryOptions
3
+ exports.boolOptions = opt.boolOptions
4
+ exports.nullOptions = opt.nullOptions
5
+ exports.strOptions = opt.strOptions
6
+
7
+ exports.Schema = require('./dist/schema').default
8
+ exports.YAMLMap = require('./dist/schema/Map').default
9
+ exports.YAMLSeq = require('./dist/schema/Seq').default
10
+ exports.Pair = require('./dist/schema/Pair').default
11
+ exports.Scalar = require('./dist/schema/Scalar').default
@@ -0,0 +1,15 @@
1
+ exports.findPair = require('./dist/schema/Map').findPair
2
+ exports.parseMap = require('./dist/schema/parseMap').default
3
+ exports.parseSeq = require('./dist/schema/parseSeq').default
4
+
5
+ var str = require('./dist/stringify')
6
+ exports.stringifyNumber = str.stringifyNumber
7
+ exports.stringifyString = str.stringifyString
8
+ exports.toJSON = require('./dist/toJSON').default
9
+ exports.Type = require('./dist/cst/Node').Type
10
+
11
+ var err = require('./dist/errors')
12
+ exports.YAMLReferenceError = err.YAMLReferenceError
13
+ exports.YAMLSemanticError = err.YAMLSemanticError
14
+ exports.YAMLSyntaxError = err.YAMLSyntaxError
15
+ exports.YAMLWarning = err.YAMLWarning
package/dist/Anchors.js CHANGED
@@ -122,6 +122,4 @@ class Anchors {
122
122
 
123
123
  }
124
124
 
125
- exports.default = Anchors;
126
- module.exports = exports.default;
127
- module.exports.default = exports.default;
125
+ exports.default = Anchors;
package/dist/Document.js CHANGED
@@ -9,7 +9,7 @@ var _addComment = _interopRequireDefault(require("./addComment"));
9
9
 
10
10
  var _Anchors = _interopRequireDefault(require("./Anchors"));
11
11
 
12
- var _Node = require("./cst/Node");
12
+ var _constants = require("./constants");
13
13
 
14
14
  var _errors = require("./errors");
15
15
 
@@ -21,7 +21,7 @@ var _Alias = _interopRequireDefault(require("./schema/Alias"));
21
21
 
22
22
  var _Collection = _interopRequireWildcard(require("./schema/Collection"));
23
23
 
24
- var _Node2 = _interopRequireDefault(require("./schema/Node"));
24
+ var _Node = _interopRequireDefault(require("./schema/Node"));
25
25
 
26
26
  var _Scalar = _interopRequireDefault(require("./schema/Scalar"));
27
27
 
@@ -33,7 +33,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
33
33
 
34
34
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
35
35
 
36
- const isCollectionItem = node => node && [_Node.Type.MAP_KEY, _Node.Type.MAP_VALUE, _Node.Type.SEQ_ITEM].includes(node.type);
36
+ const isCollectionItem = node => node && [_constants.Type.MAP_KEY, _constants.Type.MAP_VALUE, _constants.Type.SEQ_ITEM].includes(node.type);
37
37
 
38
38
  class Document {
39
39
  constructor(options) {
@@ -188,7 +188,7 @@ class Document {
188
188
  } else if (node.comment !== null) {
189
189
  const cc = contentNodes.length === 0 ? comments.before : comments.after;
190
190
  cc.push(node.comment);
191
- } else if (node.type === _Node.Type.BLANK_LINE) {
191
+ } else if (node.type === _constants.Type.BLANK_LINE) {
192
192
  spaceBefore = true;
193
193
 
194
194
  if (contentNodes.length === 0 && comments.before.length > 0 && !this.commentBefore) {
@@ -234,6 +234,13 @@ class Document {
234
234
 
235
235
  this.comment = comments.after.join('\n') || null;
236
236
  this.anchors.resolveNodes();
237
+
238
+ if (this.options.prettyErrors) {
239
+ for (const error of this.errors) if (error instanceof _errors.YAMLError) error.makePretty();
240
+
241
+ for (const warn of this.warnings) if (warn instanceof _errors.YAMLError) warn.makePretty();
242
+ }
243
+
237
244
  return this;
238
245
  }
239
246
 
@@ -331,21 +338,21 @@ class Document {
331
338
  }
332
339
 
333
340
  switch (type) {
334
- case _Node.Type.BLOCK_FOLDED:
335
- case _Node.Type.BLOCK_LITERAL:
336
- case _Node.Type.QUOTE_DOUBLE:
337
- case _Node.Type.QUOTE_SINGLE:
341
+ case _constants.Type.BLOCK_FOLDED:
342
+ case _constants.Type.BLOCK_LITERAL:
343
+ case _constants.Type.QUOTE_DOUBLE:
344
+ case _constants.Type.QUOTE_SINGLE:
338
345
  return _schema.default.defaultTags.STR;
339
346
 
340
- case _Node.Type.FLOW_MAP:
341
- case _Node.Type.MAP:
347
+ case _constants.Type.FLOW_MAP:
348
+ case _constants.Type.MAP:
342
349
  return _schema.default.defaultTags.MAP;
343
350
 
344
- case _Node.Type.FLOW_SEQ:
345
- case _Node.Type.SEQ:
351
+ case _constants.Type.FLOW_SEQ:
352
+ case _constants.Type.SEQ:
346
353
  return _schema.default.defaultTags.SEQ;
347
354
 
348
- case _Node.Type.PLAIN:
355
+ case _constants.Type.PLAIN:
349
356
  return nonSpecific ? _schema.default.defaultTags.STR : null;
350
357
 
351
358
  default:
@@ -375,7 +382,7 @@ class Document {
375
382
  } = _ref;
376
383
 
377
384
  switch (node.context.src[start]) {
378
- case _Node.Char.COMMENT:
385
+ case _constants.Char.COMMENT:
379
386
  {
380
387
  if (!node.commentHasRequiredWhitespace(start)) {
381
388
  const msg = 'Comments must be separated from other tokens by white space characters';
@@ -396,7 +403,7 @@ class Document {
396
403
  }
397
404
  break;
398
405
 
399
- case _Node.Char.ANCHOR:
406
+ case _constants.Char.ANCHOR:
400
407
  if (hasAnchor) {
401
408
  const msg = 'A node can have at most one anchor';
402
409
  errors.push(new _errors.YAMLSemanticError(node, msg));
@@ -405,7 +412,7 @@ class Document {
405
412
  hasAnchor = true;
406
413
  break;
407
414
 
408
- case _Node.Char.TAG:
415
+ case _constants.Char.TAG:
409
416
  if (hasTag) {
410
417
  const msg = 'A node can have at most one tag';
411
418
  errors.push(new _errors.YAMLSemanticError(node, msg));
@@ -430,7 +437,7 @@ class Document {
430
437
 
431
438
  let res;
432
439
 
433
- if (node.type === _Node.Type.ALIAS) {
440
+ if (node.type === _constants.Type.ALIAS) {
434
441
  if (hasAnchor || hasTag) {
435
442
  const msg = 'An alias node must not specify any properties';
436
443
  errors.push(new _errors.YAMLSemanticError(node, msg));
@@ -455,7 +462,7 @@ class Document {
455
462
  if (tagName) {
456
463
  res = schema.resolveNodeWithFallback(this, node, tagName);
457
464
  } else {
458
- if (node.type !== _Node.Type.PLAIN) {
465
+ if (node.type !== _constants.Type.PLAIN) {
459
466
  const msg = `Failed to resolve ${node.type} node here`;
460
467
  errors.push(new _errors.YAMLSyntaxError(node, msg));
461
468
  return null;
@@ -534,14 +541,23 @@ class Document {
534
541
  }
535
542
 
536
543
  toJSON(arg) {
537
- const keep = this.options.keepBlobsInJSON && (typeof arg !== 'string' || !(this.contents instanceof _Scalar.default));
544
+ const {
545
+ keepBlobsInJSON,
546
+ mapAsMap,
547
+ maxAliasCount
548
+ } = this.options;
549
+ const keep = keepBlobsInJSON && (typeof arg !== 'string' || !(this.contents instanceof _Scalar.default));
538
550
  const ctx = {
551
+ doc: this,
539
552
  keep,
540
- mapAsMap: keep && !!this.options.mapAsMap
553
+ mapAsMap: keep && !!mapAsMap,
554
+ maxAliasCount
541
555
  };
542
556
  const anchorNames = Object.keys(this.anchors.map);
543
557
  if (anchorNames.length > 0) ctx.anchors = anchorNames.map(name => ({
544
558
  alias: [],
559
+ aliasCount: 0,
560
+ count: 1,
545
561
  node: this.anchors.map[name]
546
562
  }));
547
563
  return (0, _toJSON.default)(this.contents, arg, ctx);
@@ -585,7 +601,7 @@ class Document {
585
601
  let contentComment = null;
586
602
 
587
603
  if (this.contents) {
588
- if (this.contents instanceof _Node2.default) {
604
+ if (this.contents instanceof _Node.default) {
589
605
  if (this.contents.spaceBefore && hasDirectives) lines.push('');
590
606
  if (this.contents.commentBefore) lines.push(this.contents.commentBefore.replace(/^/gm, '#')); // top-level block scalars need to be indented if followed by a comment
591
607
 
@@ -646,7 +662,4 @@ _defineProperty(Document, "defaults", {
646
662
  prefix: _schema.default.defaultPrefix
647
663
  }]
648
664
  }
649
- });
650
-
651
- module.exports = exports.default;
652
- module.exports.default = exports.default;
665
+ });
@@ -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
+ const Char = {
8
+ ANCHOR: '&',
9
+ COMMENT: '#',
10
+ TAG: '!',
11
+ DIRECTIVES_END: '-',
12
+ DOCUMENT_END: '.'
13
+ };
14
+ exports.Char = Char;
15
+ const 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;
package/dist/cst/Alias.js CHANGED
@@ -35,6 +35,4 @@ class Alias extends _Node.default {
35
35
 
36
36
  }
37
37
 
38
- exports.default = Alias;
39
- module.exports = exports.default;
40
- module.exports.default = exports.default;
38
+ exports.default = Alias;
@@ -5,17 +5,17 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- var _Node = _interopRequireWildcard(require("./Node"));
8
+ var _constants = require("../constants");
9
+
10
+ var _Node = _interopRequireDefault(require("./Node"));
9
11
 
10
12
  var _Range = _interopRequireDefault(require("./Range"));
11
13
 
12
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
15
 
14
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
15
-
16
16
  class BlankLine extends _Node.default {
17
17
  constructor() {
18
- super(_Node.Type.BLANK_LINE);
18
+ super(_constants.Type.BLANK_LINE);
19
19
  }
20
20
 
21
21
  get includesTrailingLines() {
@@ -49,6 +49,4 @@ class BlankLine extends _Node.default {
49
49
 
50
50
  }
51
51
 
52
- exports.default = BlankLine;
53
- module.exports = exports.default;
54
- module.exports.default = exports.default;
52
+ exports.default = BlankLine;
@@ -5,14 +5,14 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = exports.Chomp = void 0;
7
7
 
8
- var _Node = _interopRequireWildcard(require("./Node"));
8
+ var _constants = require("../constants");
9
+
10
+ var _Node = _interopRequireDefault(require("./Node"));
9
11
 
10
12
  var _Range = _interopRequireDefault(require("./Range"));
11
13
 
12
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
15
 
14
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
15
-
16
16
  const Chomp = {
17
17
  CLIP: 'CLIP',
18
18
  KEEP: 'KEEP',
@@ -69,7 +69,7 @@ class BlockValue extends _Node.default {
69
69
  }
70
70
 
71
71
  const bi = indent + this.blockIndent;
72
- const folded = this.type === _Node.Type.BLOCK_FOLDED;
72
+ const folded = this.type === _constants.Type.BLOCK_FOLDED;
73
73
  let atStart = true;
74
74
  let str = '';
75
75
  let sep = '';