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/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,21 +21,23 @@ var _Alias = _interopRequireDefault(require("./schema/Alias"));
21
21
 
22
22
  var _Collection = _interopRequireWildcard(require("./schema/Collection"));
23
23
 
24
- var _toJSON = _interopRequireDefault(require("./toJSON"));
24
+ var _Node = _interopRequireDefault(require("./schema/Node"));
25
25
 
26
26
  var _Scalar = _interopRequireDefault(require("./schema/Scalar"));
27
27
 
28
+ var _toJSON = _interopRequireDefault(require("./toJSON"));
29
+
28
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; } }
29
31
 
30
32
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
33
 
32
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; }
33
35
 
34
- 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);
35
37
 
36
38
  class Document {
37
39
  constructor(options) {
38
- this.anchors = new _Anchors.default();
40
+ this.anchors = new _Anchors.default(options.anchorPrefix);
39
41
  this.commentBefore = null;
40
42
  this.comment = null;
41
43
  this.contents = null;
@@ -116,7 +118,7 @@ class Document {
116
118
  if (!this.schema) this.schema = new _schema.default(Object.assign({}, this.getDefaults(), this.options));
117
119
  }
118
120
 
119
- parse(node) {
121
+ parse(node, prevDoc) {
120
122
  if (this.options.keepCstNodes) this.cstNode = node;
121
123
  if (this.options.keepNodeTypes) this.type = 'DOCUMENT';
122
124
  const {
@@ -131,7 +133,25 @@ class Document {
131
133
  this.errors.push(error);
132
134
  }
133
135
 
136
+ this.parseDirectives(directives, prevDoc);
137
+ this.range = valueRange ? [valueRange.start, valueRange.end] : null;
138
+ this.setSchema();
139
+ this.anchors._cstAliases = [];
140
+ this.parseContents(contents);
141
+ this.anchors.resolveNodes();
142
+
143
+ if (this.options.prettyErrors) {
144
+ for (const error of this.errors) if (error instanceof _errors.YAMLError) error.makePretty();
145
+
146
+ for (const warn of this.warnings) if (warn instanceof _errors.YAMLError) warn.makePretty();
147
+ }
148
+
149
+ return this;
150
+ }
151
+
152
+ parseDirectives(directives, prevDoc) {
134
153
  const directiveComments = [];
154
+ let hasDirectives = false;
135
155
  directives.forEach(directive => {
136
156
  const {
137
157
  comment,
@@ -141,11 +161,13 @@ class Document {
141
161
  switch (name) {
142
162
  case 'TAG':
143
163
  this.resolveTagDirective(directive);
164
+ hasDirectives = true;
144
165
  break;
145
166
 
146
167
  case 'YAML':
147
168
  case 'YAML:1.0':
148
169
  this.resolveYamlDirective(directive);
170
+ hasDirectives = true;
149
171
  break;
150
172
 
151
173
  default:
@@ -158,10 +180,24 @@ class Document {
158
180
 
159
181
  if (comment) directiveComments.push(comment);
160
182
  });
161
- this.range = valueRange ? [valueRange.start, valueRange.end] : null;
162
- this.setSchema();
163
- this.anchors._cstAliases = [];
183
+
184
+ if (prevDoc && !hasDirectives && '1.1' === (this.version || prevDoc.version || this.options.version)) {
185
+ const copyTagPrefix = ({
186
+ handle,
187
+ prefix
188
+ }) => ({
189
+ handle,
190
+ prefix
191
+ });
192
+
193
+ this.tagPrefixes = prevDoc.tagPrefixes.map(copyTagPrefix);
194
+ this.version = prevDoc.version;
195
+ }
196
+
164
197
  this.commentBefore = directiveComments.join('\n') || null;
198
+ }
199
+
200
+ parseContents(contents) {
165
201
  const comments = {
166
202
  before: [],
167
203
  after: []
@@ -186,7 +222,7 @@ class Document {
186
222
  } else if (node.comment !== null) {
187
223
  const cc = contentNodes.length === 0 ? comments.before : comments.after;
188
224
  cc.push(node.comment);
189
- } else if (node.type === _Node.Type.BLANK_LINE) {
225
+ } else if (node.type === _constants.Type.BLANK_LINE) {
190
226
  spaceBefore = true;
191
227
 
192
228
  if (contentNodes.length === 0 && comments.before.length > 0 && !this.commentBefore) {
@@ -231,8 +267,6 @@ class Document {
231
267
  }
232
268
 
233
269
  this.comment = comments.after.join('\n') || null;
234
- this.anchors.resolveNodes();
235
- return this;
236
270
  }
237
271
 
238
272
  resolveTagDirective(directive) {
@@ -329,21 +363,21 @@ class Document {
329
363
  }
330
364
 
331
365
  switch (type) {
332
- case _Node.Type.BLOCK_FOLDED:
333
- case _Node.Type.BLOCK_LITERAL:
334
- case _Node.Type.QUOTE_DOUBLE:
335
- case _Node.Type.QUOTE_SINGLE:
366
+ case _constants.Type.BLOCK_FOLDED:
367
+ case _constants.Type.BLOCK_LITERAL:
368
+ case _constants.Type.QUOTE_DOUBLE:
369
+ case _constants.Type.QUOTE_SINGLE:
336
370
  return _schema.default.defaultTags.STR;
337
371
 
338
- case _Node.Type.FLOW_MAP:
339
- case _Node.Type.MAP:
372
+ case _constants.Type.FLOW_MAP:
373
+ case _constants.Type.MAP:
340
374
  return _schema.default.defaultTags.MAP;
341
375
 
342
- case _Node.Type.FLOW_SEQ:
343
- case _Node.Type.SEQ:
376
+ case _constants.Type.FLOW_SEQ:
377
+ case _constants.Type.SEQ:
344
378
  return _schema.default.defaultTags.SEQ;
345
379
 
346
- case _Node.Type.PLAIN:
380
+ case _constants.Type.PLAIN:
347
381
  return nonSpecific ? _schema.default.defaultTags.STR : null;
348
382
 
349
383
  default:
@@ -373,7 +407,7 @@ class Document {
373
407
  } = _ref;
374
408
 
375
409
  switch (node.context.src[start]) {
376
- case _Node.Char.COMMENT:
410
+ case _constants.Char.COMMENT:
377
411
  {
378
412
  if (!node.commentHasRequiredWhitespace(start)) {
379
413
  const msg = 'Comments must be separated from other tokens by white space characters';
@@ -394,7 +428,7 @@ class Document {
394
428
  }
395
429
  break;
396
430
 
397
- case _Node.Char.ANCHOR:
431
+ case _constants.Char.ANCHOR:
398
432
  if (hasAnchor) {
399
433
  const msg = 'A node can have at most one anchor';
400
434
  errors.push(new _errors.YAMLSemanticError(node, msg));
@@ -403,7 +437,7 @@ class Document {
403
437
  hasAnchor = true;
404
438
  break;
405
439
 
406
- case _Node.Char.TAG:
440
+ case _constants.Char.TAG:
407
441
  if (hasTag) {
408
442
  const msg = 'A node can have at most one tag';
409
443
  errors.push(new _errors.YAMLSemanticError(node, msg));
@@ -428,7 +462,7 @@ class Document {
428
462
 
429
463
  let res;
430
464
 
431
- if (node.type === _Node.Type.ALIAS) {
465
+ if (node.type === _constants.Type.ALIAS) {
432
466
  if (hasAnchor || hasTag) {
433
467
  const msg = 'An alias node must not specify any properties';
434
468
  errors.push(new _errors.YAMLSemanticError(node, msg));
@@ -447,18 +481,13 @@ class Document {
447
481
  res = new _Alias.default(src);
448
482
 
449
483
  anchors._cstAliases.push(res);
450
-
451
- if (!src.resolved) {
452
- const msg = 'Alias node contains a circular reference, which cannot be resolved as JSON';
453
- this.warnings.push(new _errors.YAMLWarning(node, msg));
454
- }
455
484
  } else {
456
485
  const tagName = this.resolveTagName(node);
457
486
 
458
487
  if (tagName) {
459
488
  res = schema.resolveNodeWithFallback(this, node, tagName);
460
489
  } else {
461
- if (node.type !== _Node.Type.PLAIN) {
490
+ if (node.type !== _constants.Type.PLAIN) {
462
491
  const msg = `Failed to resolve ${node.type} node here`;
463
492
  errors.push(new _errors.YAMLSyntaxError(node, msg));
464
493
  return null;
@@ -537,14 +566,26 @@ class Document {
537
566
  }
538
567
 
539
568
  toJSON(arg) {
540
- const cr = this.warnings.find(w => /circular reference/.test(w.message));
541
- if (cr) throw new _errors.YAMLSemanticError(cr.source, cr.message);
542
- const keep = this.options.keepBlobsInJSON && (typeof arg !== 'string' || !(this.contents instanceof _Scalar.default));
543
- const mapAsMap = keep && !!this.options.mapAsMap;
544
- return (0, _toJSON.default)(this.contents, arg, {
569
+ const {
570
+ keepBlobsInJSON,
571
+ mapAsMap,
572
+ maxAliasCount
573
+ } = this.options;
574
+ const keep = keepBlobsInJSON && (typeof arg !== 'string' || !(this.contents instanceof _Scalar.default));
575
+ const ctx = {
576
+ doc: this,
545
577
  keep,
546
- mapAsMap
547
- });
578
+ mapAsMap: keep && !!mapAsMap,
579
+ maxAliasCount
580
+ };
581
+ const anchorNames = Object.keys(this.anchors.map);
582
+ if (anchorNames.length > 0) ctx.anchors = anchorNames.map(name => ({
583
+ alias: [],
584
+ aliasCount: 0,
585
+ count: 1,
586
+ node: this.anchors.map[name]
587
+ }));
588
+ return (0, _toJSON.default)(this.contents, arg, ctx);
548
589
  }
549
590
 
550
591
  toString() {
@@ -585,11 +626,14 @@ class Document {
585
626
  let contentComment = null;
586
627
 
587
628
  if (this.contents) {
588
- if (this.contents.spaceBefore && hasDirectives) lines.push('');
589
- if (this.contents.commentBefore) lines.push(this.contents.commentBefore.replace(/^/gm, '#')); // top-level block scalars need to be indented if followed by a comment
629
+ if (this.contents instanceof _Node.default) {
630
+ if (this.contents.spaceBefore && hasDirectives) lines.push('');
631
+ if (this.contents.commentBefore) lines.push(this.contents.commentBefore.replace(/^/gm, '#')); // top-level block scalars need to be indented if followed by a comment
632
+
633
+ ctx.forceBlockIndent = !!this.comment;
634
+ contentComment = this.contents.comment;
635
+ }
590
636
 
591
- ctx.forceBlockIndent = !!this.comment;
592
- contentComment = this.contents.comment;
593
637
  const onChompKeep = contentComment ? null : () => chompKeep = true;
594
638
  const body = this.schema.stringify(this.contents, ctx, () => contentComment = null, onChompKeep);
595
639
  lines.push((0, _addComment.default)(body, '', contentComment));
@@ -643,7 +687,4 @@ _defineProperty(Document, "defaults", {
643
687
  prefix: _schema.default.defaultPrefix
644
688
  }]
645
689
  }
646
- });
647
-
648
- module.exports = exports.default;
649
- module.exports.default = exports.default;
690
+ });
@@ -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 = '';
@@ -6,18 +6,18 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.grabCollectionEndComments = grabCollectionEndComments;
7
7
  exports.default = void 0;
8
8
 
9
+ var _constants = require("../constants");
10
+
9
11
  var _BlankLine = _interopRequireDefault(require("./BlankLine"));
10
12
 
11
13
  var _CollectionItem = _interopRequireDefault(require("./CollectionItem"));
12
14
 
13
15
  var _Comment = _interopRequireDefault(require("./Comment"));
14
16
 
15
- var _Node = _interopRequireWildcard(require("./Node"));
17
+ var _Node = _interopRequireDefault(require("./Node"));
16
18
 
17
19
  var _Range = _interopRequireDefault(require("./Range"));
18
20
 
19
- 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; } }
20
-
21
21
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
22
 
23
23
  function grabCollectionEndComments(node) {
@@ -32,7 +32,7 @@ function grabCollectionEndComments(node) {
32
32
  for (let i = len - 1; i >= 0; --i) {
33
33
  const n = cnode.items[i];
34
34
 
35
- if (n.type === _Node.Type.COMMENT) {
35
+ if (n.type === _constants.Type.COMMENT) {
36
36
  // Keep sufficiently indented comments with preceding node
37
37
  const {
38
38
  indent,
@@ -40,7 +40,7 @@ function grabCollectionEndComments(node) {
40
40
  } = n.context;
41
41
  if (indent > 0 && n.range.start >= lineStart + indent) break;
42
42
  ci = i;
43
- } else if (n.type === _Node.Type.BLANK_LINE) ci = i;else break;
43
+ } else if (n.type === _constants.Type.BLANK_LINE) ci = i;else break;
44
44
  }
45
45
 
46
46
  if (ci === -1) return null;
@@ -64,12 +64,12 @@ class Collection extends _Node.default {
64
64
  const ch = src[offset];
65
65
  if (!ch) return false;
66
66
  if (offset >= lineStart + indent) return true;
67
- if (ch !== '#') return false;
67
+ if (ch !== '#' && ch !== '\n') return false;
68
68
  return Collection.nextContentHasIndent(src, offset, indent);
69
69
  }
70
70
 
71
71
  constructor(firstItem) {
72
- super(firstItem.type === _Node.Type.SEQ_ITEM ? _Node.Type.SEQ : _Node.Type.MAP);
72
+ super(firstItem.type === _constants.Type.SEQ_ITEM ? _constants.Type.SEQ : _constants.Type.MAP);
73
73
 
74
74
  for (let i = firstItem.props.length - 1; i >= 0; --i) {
75
75
  if (firstItem.props[i].start < firstItem.context.lineStart) {
@@ -181,7 +181,7 @@ class Collection extends _Node.default {
181
181
  break;
182
182
  }
183
183
 
184
- if (firstItem.type === _Node.Type.SEQ_ITEM !== (ch === '-')) {
184
+ if (firstItem.type === _constants.Type.SEQ_ITEM !== (ch === '-')) {
185
185
  let typeswitch = true;
186
186
 
187
187
  if (ch === '-') {
@@ -5,16 +5,16 @@ 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 _BlankLine = _interopRequireDefault(require("./BlankLine"));
11
13
 
12
- var _Node = _interopRequireWildcard(require("./Node"));
14
+ var _Node = _interopRequireDefault(require("./Node"));
13
15
 
14
16
  var _Range = _interopRequireDefault(require("./Range"));
15
17
 
16
- 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; } }
17
-
18
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
19
 
20
20
  class CollectionItem extends _Node.default {
@@ -43,7 +43,7 @@ class CollectionItem extends _Node.default {
43
43
  atLineStart,
44
44
  lineStart
45
45
  } = context;
46
- if (!atLineStart && this.type === _Node.Type.SEQ_ITEM) this.error = new _errors.YAMLSemanticError(this, 'Sequence items must not have preceding content on the same line');
46
+ if (!atLineStart && this.type === _constants.Type.SEQ_ITEM) this.error = new _errors.YAMLSemanticError(this, 'Sequence items must not have preceding content on the same line');
47
47
  const indent = atLineStart ? start - lineStart : context.indent;
48
48
 
49
49
  let offset = _Node.default.endOfWhiteSpace(src, start + 1);
@@ -77,7 +77,7 @@ class CollectionItem extends _Node.default {
77
77
  ch = src[offset];
78
78
  }
79
79
 
80
- if (_Node.default.nextNodeIsIndented(ch, offset - (lineStart + indent), this.type !== _Node.Type.SEQ_ITEM)) {
80
+ if (_Node.default.nextNodeIsIndented(ch, offset - (lineStart + indent), this.type !== _constants.Type.SEQ_ITEM)) {
81
81
  this.node = parseNode({
82
82
  atLineStart,
83
83
  inCollection: false,
@@ -116,6 +116,4 @@ class CollectionItem extends _Node.default {
116
116
 
117
117
  }
118
118
 
119
- exports.default = CollectionItem;
120
- module.exports = exports.default;
121
- module.exports.default = exports.default;
119
+ exports.default = CollectionItem;
@@ -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 Comment extends _Node.default {
17
17
  constructor() {
18
- super(_Node.Type.COMMENT);
18
+ super(_constants.Type.COMMENT);
19
19
  }
20
20
  /**
21
21
  * Parses a comment line from the source
@@ -35,6 +35,4 @@ class Comment extends _Node.default {
35
35
 
36
36
  }
37
37
 
38
- exports.default = Comment;
39
- module.exports = exports.default;
40
- module.exports.default = exports.default;
38
+ exports.default = Comment;
@@ -5,14 +5,14 @@ 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 Directive extends _Node.default {
17
17
  static endOfDirective(src, offset) {
18
18
  let ch = src[offset];
@@ -31,7 +31,7 @@ class Directive extends _Node.default {
31
31
  }
32
32
 
33
33
  constructor() {
34
- super(_Node.Type.DIRECTIVE);
34
+ super(_constants.Type.DIRECTIVE);
35
35
  this.name = null;
36
36
  }
37
37
 
@@ -77,6 +77,4 @@ class Directive extends _Node.default {
77
77
 
78
78
  }
79
79
 
80
- exports.default = Directive;
81
- module.exports = exports.default;
82
- module.exports.default = exports.default;
80
+ exports.default = Directive;
@@ -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 _BlankLine = _interopRequireDefault(require("./BlankLine"));
@@ -15,12 +17,10 @@ var _Comment = _interopRequireDefault(require("./Comment"));
15
17
 
16
18
  var _Directive = _interopRequireDefault(require("./Directive"));
17
19
 
18
- var _Node = _interopRequireWildcard(require("./Node"));
20
+ var _Node = _interopRequireDefault(require("./Node"));
19
21
 
20
22
  var _Range = _interopRequireDefault(require("./Range"));
21
23
 
22
- 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; } }
23
-
24
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
25
 
26
26
  class Document extends _Node.default {
@@ -32,7 +32,7 @@ class Document extends _Node.default {
32
32
  }
33
33
 
34
34
  constructor() {
35
- super(_Node.Type.DOCUMENT);
35
+ super(_constants.Type.DOCUMENT);
36
36
  this.directives = null;
37
37
  this.contents = null;
38
38
  }
@@ -46,7 +46,7 @@ class Document extends _Node.default {
46
46
  let hasDirectives = false;
47
47
  let offset = start;
48
48
 
49
- while (!_Node.default.atDocumentBoundary(src, offset, _Node.Char.DIRECTIVES_END)) {
49
+ while (!_Node.default.atDocumentBoundary(src, offset, _constants.Char.DIRECTIVES_END)) {
50
50
  offset = Document.startCommentOrEndBlankLine(src, offset);
51
51
 
52
52
  switch (src[offset]) {
@@ -130,7 +130,7 @@ class Document extends _Node.default {
130
130
  let atLineStart = lineStart === start;
131
131
  this.valueRange = new _Range.default(offset);
132
132
 
133
- while (!_Node.default.atDocumentBoundary(src, offset, _Node.Char.DOCUMENT_END)) {
133
+ while (!_Node.default.atDocumentBoundary(src, offset, _constants.Char.DOCUMENT_END)) {
134
134
  switch (src[offset]) {
135
135
  case '\n':
136
136
  if (atLineStart) {
@@ -260,7 +260,7 @@ class Document extends _Node.default {
260
260
  let str = directives.join('');
261
261
 
262
262
  if (contents.length > 0) {
263
- if (directives.length > 0 || contents[0].type === _Node.Type.COMMENT) str += '---\n';
263
+ if (directives.length > 0 || contents[0].type === _constants.Type.COMMENT) str += '---\n';
264
264
  str += contents.join('');
265
265
  }
266
266
 
@@ -270,6 +270,4 @@ class Document extends _Node.default {
270
270
 
271
271
  }
272
272
 
273
- exports.default = Document;
274
- module.exports = exports.default;
275
- module.exports.default = exports.default;
273
+ exports.default = Document;
@@ -5,18 +5,18 @@ 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 _BlankLine = _interopRequireDefault(require("./BlankLine"));
11
13
 
12
14
  var _Comment = _interopRequireDefault(require("./Comment"));
13
15
 
14
- var _Node = _interopRequireWildcard(require("./Node"));
16
+ var _Node = _interopRequireDefault(require("./Node"));
15
17
 
16
18
  var _Range = _interopRequireDefault(require("./Range"));
17
19
 
18
- 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; } }
19
-
20
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
21
 
22
22
  class FlowCollection extends _Node.default {
@@ -27,7 +27,7 @@ class FlowCollection extends _Node.default {
27
27
 
28
28
  prevNodeIsJsonLike(idx = this.items.length) {
29
29
  const node = this.items[idx - 1];
30
- return !!node && (node.jsonLike || node.type === _Node.Type.COMMENT && this.nodeIsJsonLike(idx - 1));
30
+ return !!node && (node.jsonLike || node.type === _constants.Type.COMMENT && this.nodeIsJsonLike(idx - 1));
31
31
  }
32
32
  /**
33
33
  * @param {ParseContext} context
@@ -207,6 +207,4 @@ class FlowCollection extends _Node.default {
207
207
 
208
208
  }
209
209
 
210
- exports.default = FlowCollection;
211
- module.exports = exports.default;
212
- module.exports.default = exports.default;
210
+ exports.default = FlowCollection;