yaml 1.3.1 → 1.5.1

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 +28 -22
  2. package/browser/dist/Anchors.js +12 -10
  3. package/browser/dist/Document.js +167 -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 +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 +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 +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 +86 -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 +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 +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 +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/dist/cst/Node.js CHANGED
@@ -3,7 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = exports.Char = exports.Type = void 0;
6
+ exports.default = void 0;
7
+
8
+ var _constants = require("../constants");
7
9
 
8
10
  var _getLinePos = _interopRequireDefault(require("./getLinePos"));
9
11
 
@@ -11,37 +13,7 @@ var _Range = _interopRequireDefault(require("./Range"));
11
13
 
12
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
15
 
14
- const Type = {
15
- ALIAS: 'ALIAS',
16
- BLANK_LINE: 'BLANK_LINE',
17
- BLOCK_FOLDED: 'BLOCK_FOLDED',
18
- BLOCK_LITERAL: 'BLOCK_LITERAL',
19
- COMMENT: 'COMMENT',
20
- DIRECTIVE: 'DIRECTIVE',
21
- DOCUMENT: 'DOCUMENT',
22
- FLOW_MAP: 'FLOW_MAP',
23
- FLOW_SEQ: 'FLOW_SEQ',
24
- MAP: 'MAP',
25
- MAP_KEY: 'MAP_KEY',
26
- MAP_VALUE: 'MAP_VALUE',
27
- PLAIN: 'PLAIN',
28
- QUOTE_DOUBLE: 'QUOTE_DOUBLE',
29
- QUOTE_SINGLE: 'QUOTE_SINGLE',
30
- SEQ: 'SEQ',
31
- SEQ_ITEM: 'SEQ_ITEM'
32
- };
33
- exports.Type = Type;
34
- const Char = {
35
- ANCHOR: '&',
36
- COMMENT: '#',
37
- TAG: '!',
38
- DIRECTIVES_END: '-',
39
- DOCUMENT_END: '.'
40
- /** Root class of all nodes */
41
-
42
- };
43
- exports.Char = Char;
44
-
16
+ /** Root class of all nodes */
45
17
  class Node {
46
18
  static addStringTerminator(src, offset, str) {
47
19
  if (str[str.length - 1] === '\n') return str;
@@ -59,7 +31,7 @@ class Node {
59
31
  if (sep) {
60
32
  if (ch0 !== sep) return false;
61
33
  } else {
62
- if (ch0 !== Char.DIRECTIVES_END && ch0 !== Char.DOCUMENT_END) return false;
34
+ if (ch0 !== _constants.Char.DIRECTIVES_END && ch0 !== _constants.Char.DOCUMENT_END) return false;
63
35
  }
64
36
 
65
37
  const ch1 = src[offset + 1];
@@ -219,7 +191,7 @@ class Node {
219
191
 
220
192
  get anchor() {
221
193
  for (let i = 0; i < this.props.length; ++i) {
222
- const anchor = this.getPropValue(i, Char.ANCHOR, true);
194
+ const anchor = this.getPropValue(i, _constants.Char.ANCHOR, true);
223
195
  if (anchor != null) return anchor;
224
196
  }
225
197
 
@@ -230,7 +202,7 @@ class Node {
230
202
  const comments = [];
231
203
 
232
204
  for (let i = 0; i < this.props.length; ++i) {
233
- const comment = this.getPropValue(i, Char.COMMENT, true);
205
+ const comment = this.getPropValue(i, _constants.Char.COMMENT, true);
234
206
  if (comment != null) comments.push(comment);
235
207
  }
236
208
 
@@ -256,7 +228,7 @@ class Node {
256
228
  } = this.context;
257
229
 
258
230
  for (let i = 0; i < this.props.length; ++i) {
259
- if (src[this.props[i].start] === Char.COMMENT) return true;
231
+ if (src[this.props[i].start] === _constants.Char.COMMENT) return true;
260
232
  }
261
233
  }
262
234
 
@@ -270,7 +242,7 @@ class Node {
270
242
  } = this.context;
271
243
 
272
244
  for (let i = 0; i < this.props.length; ++i) {
273
- if (src[this.props[i].start] !== Char.COMMENT) return true;
245
+ if (src[this.props[i].start] !== _constants.Char.COMMENT) return true;
274
246
  }
275
247
  }
276
248
 
@@ -282,7 +254,7 @@ class Node {
282
254
  }
283
255
 
284
256
  get jsonLike() {
285
- const jsonLikeTypes = [Type.FLOW_MAP, Type.FLOW_SEQ, Type.QUOTE_DOUBLE, Type.QUOTE_SINGLE];
257
+ const jsonLikeTypes = [_constants.Type.FLOW_MAP, _constants.Type.FLOW_SEQ, _constants.Type.QUOTE_DOUBLE, _constants.Type.QUOTE_SINGLE];
286
258
  return jsonLikeTypes.indexOf(this.type) !== -1;
287
259
  }
288
260
 
@@ -308,7 +280,7 @@ class Node {
308
280
 
309
281
  get tag() {
310
282
  for (let i = 0; i < this.props.length; ++i) {
311
- const tag = this.getPropValue(i, Char.TAG, false);
283
+ const tag = this.getPropValue(i, _constants.Char.TAG, false);
312
284
 
313
285
  if (tag != null) {
314
286
  if (tag[1] === '<') {
@@ -351,7 +323,7 @@ class Node {
351
323
  src
352
324
  } = this.context;
353
325
 
354
- if (src[start] === Char.COMMENT) {
326
+ if (src[start] === _constants.Char.COMMENT) {
355
327
  const end = Node.endOfLine(src, start + 1);
356
328
  const commentRange = new _Range.default(start, end);
357
329
  this.props.push(commentRange);
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
+ var _constants = require("../constants");
9
+
8
10
  var _errors = require("../errors");
9
11
 
10
12
  var _Alias = _interopRequireDefault(require("./Alias"));
@@ -17,7 +19,7 @@ var _CollectionItem = _interopRequireDefault(require("./CollectionItem"));
17
19
 
18
20
  var _FlowCollection = _interopRequireDefault(require("./FlowCollection"));
19
21
 
20
- var _Node = _interopRequireWildcard(require("./Node"));
22
+ var _Node = _interopRequireDefault(require("./Node"));
21
23
 
22
24
  var _PlainValue = _interopRequireDefault(require("./PlainValue"));
23
25
 
@@ -27,8 +29,6 @@ var _QuoteSingle = _interopRequireDefault(require("./QuoteSingle"));
27
29
 
28
30
  var _Range = _interopRequireDefault(require("./Range"));
29
31
 
30
- 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; } }
31
-
32
32
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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; }
@@ -46,37 +46,37 @@ class ParseContext {
46
46
  static parseType(src, offset, inFlow) {
47
47
  switch (src[offset]) {
48
48
  case '*':
49
- return _Node.Type.ALIAS;
49
+ return _constants.Type.ALIAS;
50
50
 
51
51
  case '>':
52
- return _Node.Type.BLOCK_FOLDED;
52
+ return _constants.Type.BLOCK_FOLDED;
53
53
 
54
54
  case '|':
55
- return _Node.Type.BLOCK_LITERAL;
55
+ return _constants.Type.BLOCK_LITERAL;
56
56
 
57
57
  case '{':
58
- return _Node.Type.FLOW_MAP;
58
+ return _constants.Type.FLOW_MAP;
59
59
 
60
60
  case '[':
61
- return _Node.Type.FLOW_SEQ;
61
+ return _constants.Type.FLOW_SEQ;
62
62
 
63
63
  case '?':
64
- return !inFlow && _Node.default.atBlank(src, offset + 1, true) ? _Node.Type.MAP_KEY : _Node.Type.PLAIN;
64
+ return !inFlow && _Node.default.atBlank(src, offset + 1, true) ? _constants.Type.MAP_KEY : _constants.Type.PLAIN;
65
65
 
66
66
  case ':':
67
- return !inFlow && _Node.default.atBlank(src, offset + 1, true) ? _Node.Type.MAP_VALUE : _Node.Type.PLAIN;
67
+ return !inFlow && _Node.default.atBlank(src, offset + 1, true) ? _constants.Type.MAP_VALUE : _constants.Type.PLAIN;
68
68
 
69
69
  case '-':
70
- return !inFlow && _Node.default.atBlank(src, offset + 1, true) ? _Node.Type.SEQ_ITEM : _Node.Type.PLAIN;
70
+ return !inFlow && _Node.default.atBlank(src, offset + 1, true) ? _constants.Type.SEQ_ITEM : _constants.Type.PLAIN;
71
71
 
72
72
  case '"':
73
- return _Node.Type.QUOTE_DOUBLE;
73
+ return _constants.Type.QUOTE_DOUBLE;
74
74
 
75
75
  case "'":
76
- return _Node.Type.QUOTE_SINGLE;
76
+ return _constants.Type.QUOTE_SINGLE;
77
77
 
78
78
  default:
79
- return _Node.Type.PLAIN;
79
+ return _constants.Type.PLAIN;
80
80
  }
81
81
  }
82
82
 
@@ -99,36 +99,36 @@ class ParseContext {
99
99
  let node;
100
100
 
101
101
  switch (type) {
102
- case _Node.Type.ALIAS:
102
+ case _constants.Type.ALIAS:
103
103
  node = new _Alias.default(type, props);
104
104
  break;
105
105
 
106
- case _Node.Type.BLOCK_FOLDED:
107
- case _Node.Type.BLOCK_LITERAL:
106
+ case _constants.Type.BLOCK_FOLDED:
107
+ case _constants.Type.BLOCK_LITERAL:
108
108
  node = new _BlockValue.default(type, props);
109
109
  break;
110
110
 
111
- case _Node.Type.FLOW_MAP:
112
- case _Node.Type.FLOW_SEQ:
111
+ case _constants.Type.FLOW_MAP:
112
+ case _constants.Type.FLOW_SEQ:
113
113
  node = new _FlowCollection.default(type, props);
114
114
  break;
115
115
 
116
- case _Node.Type.MAP_KEY:
117
- case _Node.Type.MAP_VALUE:
118
- case _Node.Type.SEQ_ITEM:
116
+ case _constants.Type.MAP_KEY:
117
+ case _constants.Type.MAP_VALUE:
118
+ case _constants.Type.SEQ_ITEM:
119
119
  node = new _CollectionItem.default(type, props);
120
120
  break;
121
121
 
122
- case _Node.Type.COMMENT:
123
- case _Node.Type.PLAIN:
122
+ case _constants.Type.COMMENT:
123
+ case _constants.Type.PLAIN:
124
124
  node = new _PlainValue.default(type, props);
125
125
  break;
126
126
 
127
- case _Node.Type.QUOTE_DOUBLE:
127
+ case _constants.Type.QUOTE_DOUBLE:
128
128
  node = new _QuoteDouble.default(type, props);
129
129
  break;
130
130
 
131
- case _Node.Type.QUOTE_SINGLE:
131
+ case _constants.Type.QUOTE_SINGLE:
132
132
  node = new _QuoteSingle.default(type, props);
133
133
  break;
134
134
 
@@ -149,7 +149,7 @@ class ParseContext {
149
149
  }
150
150
 
151
151
  if (context.nodeStartsCollection(node)) {
152
- if (!node.error && !context.atLineStart && context.parent.type === _Node.Type.DOCUMENT) {
152
+ if (!node.error && !context.atLineStart && context.parent.type === _constants.Type.DOCUMENT) {
153
153
  node.error = new _errors.YAMLSyntaxError(node, 'Block collection must not have preceding content here (e.g. directives-end indicator)');
154
154
  }
155
155
 
@@ -213,20 +213,20 @@ class ParseContext {
213
213
  offset = _Node.default.endOfWhiteSpace(src, offset);
214
214
  let ch = src[offset];
215
215
 
216
- while (ch === _Node.Char.ANCHOR || ch === _Node.Char.COMMENT || ch === _Node.Char.TAG || ch === '\n') {
216
+ while (ch === _constants.Char.ANCHOR || ch === _constants.Char.COMMENT || ch === _constants.Char.TAG || ch === '\n') {
217
217
  if (ch === '\n') {
218
218
  const lineStart = offset + 1;
219
219
 
220
220
  const inEnd = _Node.default.endOfIndent(src, lineStart);
221
221
 
222
222
  const indentDiff = inEnd - (lineStart + this.indent);
223
- const noIndicatorAsIndent = parent.type === _Node.Type.SEQ_ITEM && parent.context.atLineStart;
223
+ const noIndicatorAsIndent = parent.type === _constants.Type.SEQ_ITEM && parent.context.atLineStart;
224
224
  if (!_Node.default.nextNodeIsIndented(src[inEnd], indentDiff, !noIndicatorAsIndent)) break;
225
225
  this.atLineStart = true;
226
226
  this.lineStart = lineStart;
227
227
  lineHasProps = false;
228
228
  offset = inEnd;
229
- } else if (ch === _Node.Char.COMMENT) {
229
+ } else if (ch === _constants.Char.COMMENT) {
230
230
  const end = _Node.default.endOfLine(src, offset + 1);
231
231
 
232
232
  props.push(new _Range.default(offset, end));
@@ -234,7 +234,7 @@ class ParseContext {
234
234
  } else {
235
235
  let end = _Node.default.endOfIdentifier(src, offset + 1);
236
236
 
237
- if (ch === _Node.Char.TAG && src[end] === ',' && /^[a-zA-Z0-9-]+\.[a-zA-Z0-9-]+,\d\d\d\d(-\d\d){0,2}\/\S/.test(src.slice(offset + 1, end + 13))) {
237
+ if (ch === _constants.Char.TAG && src[end] === ',' && /^[a-zA-Z0-9-]+\.[a-zA-Z0-9-]+,\d\d\d\d(-\d\d){0,2}\/\S/.test(src.slice(offset + 1, end + 13))) {
238
238
  // Let's presume we're dealing with a YAML 1.0 domain tag here, rather
239
239
  // than an empty but 'foo.bar' private-tagged node in a flow collection
240
240
  // followed without whitespace by a plain string starting with a year
@@ -269,6 +269,4 @@ class ParseContext {
269
269
 
270
270
  }
271
271
 
272
- exports.default = ParseContext;
273
- module.exports = exports.default;
274
- module.exports.default = exports.default;
272
+ exports.default = ParseContext;
@@ -158,6 +158,4 @@ class PlainValue extends _Node.default {
158
158
 
159
159
  }
160
160
 
161
- exports.default = PlainValue;
162
- module.exports = exports.default;
163
- module.exports.default = exports.default;
161
+ exports.default = PlainValue;
@@ -234,6 +234,4 @@ class QuoteDouble extends _Node.default {
234
234
 
235
235
  }
236
236
 
237
- exports.default = QuoteDouble;
238
- module.exports = exports.default;
239
- module.exports.default = exports.default;
237
+ exports.default = QuoteDouble;
@@ -110,6 +110,4 @@ class QuoteSingle extends _Node.default {
110
110
 
111
111
  }
112
112
 
113
- exports.default = QuoteSingle;
114
- module.exports = exports.default;
115
- module.exports.default = exports.default;
113
+ exports.default = QuoteSingle;
package/dist/cst/Range.js CHANGED
@@ -60,6 +60,4 @@ class Range {
60
60
 
61
61
  }
62
62
 
63
- exports.default = Range;
64
- module.exports = exports.default;
65
- module.exports.default = exports.default;
63
+ exports.default = Range;
@@ -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
+ }
package/dist/cst/parse.js CHANGED
@@ -52,7 +52,4 @@ function parse(src) {
52
52
  documents.toString = () => documents.join('...\n');
53
53
 
54
54
  return documents;
55
- }
56
-
57
- module.exports = exports.default;
58
- module.exports.default = exports.default;
55
+ }
@@ -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: ${msg}`);
16
+ }
17
+ }
18
+
19
+ function warnFileDeprecation(filename) {
20
+ if (global && global._YAML_SILENCE_DEPRECATION_WARNINGS) return;
21
+ const path = filename.replace(/.*yaml[/\\]/i, '').replace(/\.js$/, '').replace(/\\/g, '/');
22
+ warn(`The endpoint 'yaml/${path}' will be removed in a future release.`);
23
+ }
24
+
25
+ const 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
+ let msg = `The option '${name}' will be removed in a future release`;
32
+ msg += alternative ? `, use '${alternative}' instead.` : '.';
33
+ warn(msg);
34
+ }
package/dist/errors.js CHANGED
@@ -3,70 +3,64 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.YAMLWarning = exports.YAMLSyntaxError = exports.YAMLSemanticError = exports.YAMLReferenceError = void 0;
6
+ exports.YAMLWarning = exports.YAMLSyntaxError = exports.YAMLSemanticError = exports.YAMLReferenceError = exports.YAMLError = void 0;
7
7
 
8
8
  var _Node = _interopRequireDefault(require("./cst/Node"));
9
9
 
10
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
11
 
12
- class YAMLReferenceError extends ReferenceError {
13
- constructor(source, message) {
14
- if (!message || !(source instanceof _Node.default)) {
15
- throw new Error('Invalid arguments for new YAMLReferenceError');
16
- }
17
-
12
+ class YAMLError extends Error {
13
+ constructor(name, source, message) {
14
+ if (!message || !(source instanceof _Node.default)) throw new Error(`Invalid arguments for new ${name}`);
18
15
  super();
19
- this.name = 'YAMLReferenceError';
16
+ this.name = name;
20
17
  this.message = message;
21
18
  this.source = source;
22
19
  }
23
20
 
21
+ makePretty() {
22
+ if (this.source) {
23
+ this.nodeType = this.source.type;
24
+ this.range = this.source.range;
25
+ this.linePos = this.source.rangeAsLinePos;
26
+ delete this.source;
27
+ }
28
+ }
29
+
24
30
  }
25
31
 
26
- exports.YAMLReferenceError = YAMLReferenceError;
32
+ exports.YAMLError = YAMLError;
27
33
 
28
- class YAMLSemanticError extends SyntaxError {
34
+ class YAMLReferenceError extends YAMLError {
29
35
  constructor(source, message) {
30
- if (!message || !(source instanceof _Node.default)) {
31
- throw new Error('Invalid arguments for new YAMLSemanticError');
32
- }
36
+ super('YAMLReferenceError', source, message);
37
+ }
33
38
 
34
- super();
35
- this.name = 'YAMLSemanticError';
36
- this.message = message;
37
- this.source = source;
39
+ }
40
+
41
+ exports.YAMLReferenceError = YAMLReferenceError;
42
+
43
+ class YAMLSemanticError extends YAMLError {
44
+ constructor(source, message) {
45
+ super('YAMLSemanticError', source, message);
38
46
  }
39
47
 
40
48
  }
41
49
 
42
50
  exports.YAMLSemanticError = YAMLSemanticError;
43
51
 
44
- class YAMLSyntaxError extends SyntaxError {
52
+ class YAMLSyntaxError extends YAMLError {
45
53
  constructor(source, message) {
46
- if (!message || !(source instanceof _Node.default)) {
47
- throw new Error('Invalid arguments for new YAMLSyntaxError');
48
- }
49
-
50
- super();
51
- this.name = 'YAMLSyntaxError';
52
- this.message = message;
53
- this.source = source;
54
+ super('YAMLSyntaxError', source, message);
54
55
  }
55
56
 
56
57
  }
57
58
 
58
59
  exports.YAMLSyntaxError = YAMLSyntaxError;
59
60
 
60
- class YAMLWarning extends Error {
61
+ class YAMLWarning extends YAMLError {
61
62
  constructor(source, message) {
62
- if (!message || !(source instanceof _Node.default)) {
63
- throw new Error('Invalid arguments for new YAMLWarning');
64
- }
65
-
66
- super();
67
- this.name = 'YAMLWarning';
68
- this.message = message;
69
- this.source = source;
63
+ super('YAMLWarning', source, message);
70
64
  }
71
65
 
72
66
  }
package/dist/index.js CHANGED
@@ -17,10 +17,15 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
17
17
 
18
18
  /* global console */
19
19
  const defaultOptions = {
20
+ anchorPrefix: 'a',
21
+ customTags: null,
22
+ keepCstNodes: false,
20
23
  keepNodeTypes: true,
21
24
  keepBlobsInJSON: true,
22
25
  mapAsMap: false,
23
- tags: null,
26
+ maxAliasCount: 100,
27
+ prettyErrors: false,
28
+ // TODO Set true in v2
24
29
  version: '1.2'
25
30
  };
26
31
 
@@ -43,7 +48,17 @@ class Document extends _Document.default {
43
48
  }
44
49
 
45
50
  function parseAllDocuments(src, options) {
46
- return (0, _parse.default)(src).map(cstDoc => new Document(options).parse(cstDoc));
51
+ const stream = [];
52
+ let prev;
53
+
54
+ for (const cstDoc of (0, _parse.default)(src)) {
55
+ const doc = new Document(options);
56
+ doc.parse(cstDoc, prev);
57
+ stream.push(doc);
58
+ prev = doc;
59
+ }
60
+
61
+ return stream;
47
62
  }
48
63
 
49
64
  function parseDocument(src, options) {
@@ -82,6 +97,4 @@ var _default = {
82
97
  parseDocument,
83
98
  stringify
84
99
  };
85
- exports.default = _default;
86
- module.exports = exports.default;
87
- module.exports.default = exports.default;
100
+ exports.default = _default;
@@ -35,6 +35,4 @@ const visit = (node, tags) => {
35
35
 
36
36
  var _default = node => Object.keys(visit(node, {}));
37
37
 
38
- exports.default = _default;
39
- module.exports = exports.default;
40
- module.exports.default = exports.default;
38
+ exports.default = _default;
@@ -5,26 +5,56 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- var _Node = require("../cst/Node");
8
+ var _constants = require("../constants");
9
+
10
+ var _errors = require("../errors");
9
11
 
10
12
  var _toJSON = _interopRequireDefault(require("../toJSON"));
11
13
 
12
- var _Node2 = _interopRequireDefault(require("./Node"));
14
+ var _Collection = _interopRequireDefault(require("./Collection"));
15
+
16
+ var _Node = _interopRequireDefault(require("./Node"));
17
+
18
+ var _Pair = _interopRequireDefault(require("./Pair"));
13
19
 
14
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
21
 
16
22
  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; }
17
23
 
18
- class Alias extends _Node2.default {
24
+ const getAliasCount = (node, anchors) => {
25
+ if (node instanceof Alias) {
26
+ const anchor = anchors.find(a => a.node === node.source);
27
+ return anchor.count * anchor.aliasCount;
28
+ } else if (node instanceof _Collection.default) {
29
+ let count = 0;
30
+
31
+ for (const item of node.items) {
32
+ const c = getAliasCount(item, anchors);
33
+ if (c > count) count = c;
34
+ }
35
+
36
+ return count;
37
+ } else if (node instanceof _Pair.default) {
38
+ const kc = getAliasCount(node.key, anchors);
39
+ const vc = getAliasCount(node.value, anchors);
40
+ return Math.max(kc, vc);
41
+ }
42
+
43
+ return 1;
44
+ };
45
+
46
+ class Alias extends _Node.default {
19
47
  static stringify({
20
48
  range,
21
49
  source
22
50
  }, {
23
51
  anchors,
24
52
  doc,
25
- implicitKey
53
+ implicitKey,
54
+ inStringifyKey
26
55
  }) {
27
- const anchor = Object.keys(anchors).find(a => anchors[a] === source);
56
+ let anchor = Object.keys(anchors).find(a => anchors[a] === source);
57
+ if (!anchor && inStringifyKey) anchor = doc.anchors.getName(source) || doc.anchors.newName();
28
58
  if (anchor) return `*${anchor}${implicitKey ? ' ' : ''}`;
29
59
  const msg = doc.anchors.getName(source) ? 'Alias node must be after source node' : 'Source node not found for alias node';
30
60
  throw new Error(`${msg} [${range}]`);
@@ -33,22 +63,47 @@ class Alias extends _Node2.default {
33
63
  constructor(source) {
34
64
  super();
35
65
  this.source = source;
36
- this.type = _Node.Type.ALIAS;
66
+ this.type = _constants.Type.ALIAS;
37
67
  }
38
68
 
39
69
  set tag(t) {
40
70
  throw new Error('Alias nodes cannot have tags');
41
71
  }
42
72
 
43
- toJSON(arg, opt) {
44
- return (0, _toJSON.default)(this.source, arg, opt);
73
+ toJSON(arg, ctx) {
74
+ if (!ctx) return (0, _toJSON.default)(this.source, arg, ctx);
75
+ const {
76
+ anchors,
77
+ maxAliasCount
78
+ } = ctx;
79
+ const anchor = anchors.find(a => a.node === this.source);
80
+
81
+ if (!anchor || !anchor.res) {
82
+ const msg = 'This should not happen: Alias anchor was not resolved?';
83
+ if (this.cstNode) throw new _errors.YAMLReferenceError(this.cstNode, msg);else throw new ReferenceError(msg);
84
+ }
85
+
86
+ if (maxAliasCount >= 0) {
87
+ anchor.count += 1;
88
+ if (anchor.aliasCount === 0) anchor.aliasCount = getAliasCount(this.source, anchors);
89
+
90
+ if (anchor.count * anchor.aliasCount > maxAliasCount) {
91
+ const msg = 'Excessive alias count indicates a resource exhaustion attack';
92
+ if (this.cstNode) throw new _errors.YAMLReferenceError(this.cstNode, msg);else throw new ReferenceError(msg);
93
+ }
94
+ }
95
+
96
+ return anchor.res;
97
+ } // Only called when stringifying an alias mapping key while constructing
98
+ // Object output.
99
+
100
+
101
+ toString(ctx) {
102
+ return Alias.stringify(this, ctx);
45
103
  }
46
104
 
47
105
  }
48
106
 
49
107
  exports.default = Alias;
50
108
 
51
- _defineProperty(Alias, "default", true);
52
-
53
- module.exports = exports.default;
54
- module.exports.default = exports.default;
109
+ _defineProperty(Alias, "default", true);