yaml 1.8.2 → 1.9.2

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 (142) hide show
  1. package/browser/dist/Anchors.js +10 -13
  2. package/browser/dist/Document.js +72 -67
  3. package/browser/dist/addComment.js +1 -1
  4. package/browser/dist/cst/Alias.js +12 -8
  5. package/browser/dist/cst/BlankLine.js +16 -20
  6. package/browser/dist/cst/BlockValue.js +14 -10
  7. package/browser/dist/cst/Collection.js +17 -13
  8. package/browser/dist/cst/CollectionItem.js +15 -11
  9. package/browser/dist/cst/Comment.js +13 -9
  10. package/browser/dist/cst/Directive.js +13 -9
  11. package/browser/dist/cst/Document.js +17 -13
  12. package/browser/dist/cst/FlowCollection.js +17 -13
  13. package/browser/dist/cst/Node.js +3 -5
  14. package/browser/dist/cst/ParseContext.js +12 -14
  15. package/browser/dist/cst/PlainValue.js +12 -8
  16. package/browser/dist/cst/QuoteDouble.js +13 -9
  17. package/browser/dist/cst/QuoteSingle.js +13 -9
  18. package/browser/dist/cst/Range.js +2 -5
  19. package/browser/dist/cst/parse.js +3 -3
  20. package/browser/dist/errors.js +23 -8
  21. package/browser/dist/foldFlowLines.js +1 -1
  22. package/browser/dist/index.js +71 -21
  23. package/browser/dist/listTagNames.js +5 -5
  24. package/browser/dist/schema/Alias.js +30 -34
  25. package/browser/dist/schema/Collection.js +40 -47
  26. package/browser/dist/schema/Map.js +39 -56
  27. package/browser/dist/schema/Merge.js +37 -46
  28. package/browser/dist/schema/Node.js +2 -5
  29. package/browser/dist/schema/Pair.js +36 -13
  30. package/browser/dist/schema/Scalar.js +13 -9
  31. package/browser/dist/schema/Seq.js +27 -25
  32. package/browser/dist/schema/index.js +25 -39
  33. package/browser/dist/schema/parseMap.js +8 -8
  34. package/browser/dist/schema/parseSeq.js +5 -5
  35. package/browser/dist/schema/parseUtils.js +11 -15
  36. package/browser/dist/stringify.js +2 -1
  37. package/browser/dist/tags/core.js +39 -23
  38. package/browser/dist/tags/failsafe/index.js +4 -4
  39. package/browser/dist/tags/failsafe/map.js +15 -18
  40. package/browser/dist/tags/failsafe/seq.js +14 -18
  41. package/browser/dist/tags/failsafe/string.js +1 -1
  42. package/browser/dist/tags/index.js +10 -10
  43. package/browser/dist/tags/json.js +27 -26
  44. package/browser/dist/tags/options.js +3 -0
  45. package/browser/dist/tags/yaml-1.1/binary.js +10 -8
  46. package/browser/dist/tags/yaml-1.1/index.js +75 -43
  47. package/browser/dist/tags/yaml-1.1/omap.js +34 -39
  48. package/browser/dist/tags/yaml-1.1/pairs.js +17 -20
  49. package/browser/dist/tags/yaml-1.1/set.js +27 -23
  50. package/browser/dist/test-events.js +4 -4
  51. package/browser/dist/toJSON.js +3 -4
  52. package/browser/dist/warnings.js +29 -18
  53. package/browser/index.js +1 -1
  54. package/browser/map.js +4 -2
  55. package/browser/pair.js +4 -2
  56. package/browser/parse-cst.js +1 -1
  57. package/browser/scalar.js +4 -2
  58. package/browser/schema.js +11 -6
  59. package/browser/seq.js +4 -2
  60. package/browser/types/binary.js +5 -6
  61. package/browser/types/omap.js +4 -2
  62. package/browser/types/pairs.js +4 -2
  63. package/browser/types/set.js +4 -2
  64. package/browser/types/timestamp.js +5 -9
  65. package/browser/types.js +12 -10
  66. package/browser/util.js +16 -13
  67. package/dist/Anchors.js +13 -18
  68. package/dist/Document.js +52 -48
  69. package/dist/addComment.js +1 -4
  70. package/dist/constants.js +0 -3
  71. package/dist/cst/Alias.js +8 -13
  72. package/dist/cst/BlankLine.js +8 -24
  73. package/dist/cst/BlockValue.js +12 -17
  74. package/dist/cst/Collection.js +22 -27
  75. package/dist/cst/CollectionItem.js +16 -21
  76. package/dist/cst/Comment.js +6 -11
  77. package/dist/cst/Directive.js +7 -12
  78. package/dist/cst/Document.js +23 -28
  79. package/dist/cst/FlowCollection.js +21 -26
  80. package/dist/cst/Node.js +4 -9
  81. package/dist/cst/ParseContext.js +38 -43
  82. package/dist/cst/PlainValue.js +10 -15
  83. package/dist/cst/QuoteDouble.js +9 -14
  84. package/dist/cst/QuoteSingle.js +9 -14
  85. package/dist/cst/Range.js +2 -5
  86. package/dist/cst/parse.js +5 -10
  87. package/dist/cst/source-utils.js +0 -3
  88. package/dist/errors.js +4 -9
  89. package/dist/foldFlowLines.js +1 -4
  90. package/dist/index.js +59 -17
  91. package/dist/listTagNames.js +9 -14
  92. package/dist/schema/Alias.js +12 -17
  93. package/dist/schema/Collection.js +16 -20
  94. package/dist/schema/Map.js +12 -17
  95. package/dist/schema/Merge.js +13 -18
  96. package/dist/schema/Node.js +2 -5
  97. package/dist/schema/Pair.js +44 -31
  98. package/dist/schema/Scalar.js +6 -11
  99. package/dist/schema/Seq.js +9 -14
  100. package/dist/schema/index.js +22 -27
  101. package/dist/schema/parseMap.js +19 -28
  102. package/dist/schema/parseSeq.js +10 -15
  103. package/dist/schema/parseUtils.js +0 -3
  104. package/dist/stringify.js +6 -12
  105. package/dist/tags/core.js +34 -26
  106. package/dist/tags/failsafe/index.js +6 -11
  107. package/dist/tags/failsafe/map.js +8 -13
  108. package/dist/tags/failsafe/seq.js +8 -13
  109. package/dist/tags/failsafe/string.js +3 -6
  110. package/dist/tags/index.js +20 -29
  111. package/dist/tags/json.js +26 -22
  112. package/dist/tags/options.js +5 -4
  113. package/dist/tags/yaml-1.1/binary.js +11 -11
  114. package/dist/tags/yaml-1.1/index.js +69 -38
  115. package/dist/tags/yaml-1.1/omap.js +19 -24
  116. package/dist/tags/yaml-1.1/pairs.js +12 -17
  117. package/dist/tags/yaml-1.1/set.js +12 -21
  118. package/dist/tags/yaml-1.1/timestamp.js +0 -3
  119. package/dist/test-events.js +4 -9
  120. package/dist/toJSON.js +3 -5
  121. package/dist/warnings.js +31 -22
  122. package/index.d.ts +358 -0
  123. package/index.js +1 -1
  124. package/map.js +1 -1
  125. package/package.json +29 -23
  126. package/pair.js +1 -1
  127. package/parse-cst.d.ts +187 -0
  128. package/parse-cst.js +1 -1
  129. package/scalar.js +1 -1
  130. package/schema.js +2 -2
  131. package/seq.js +1 -1
  132. package/types/binary.js +1 -1
  133. package/types/omap.js +1 -1
  134. package/types/pairs.js +1 -1
  135. package/types/set.js +1 -1
  136. package/types/timestamp.js +1 -1
  137. package/types.d.ts +393 -0
  138. package/types.js +7 -6
  139. package/types.mjs +6 -5
  140. package/util.d.ts +86 -0
  141. package/util.js +6 -5
  142. package/util.mjs +4 -3
@@ -1,31 +1,26 @@
1
1
  "use strict";
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
3
+ exports.Alias = void 0;
7
4
 
8
5
  var _constants = require("../constants");
9
6
 
10
7
  var _errors = require("../errors");
11
8
 
12
- var _toJSON = _interopRequireDefault(require("../toJSON"));
9
+ var _toJSON = require("../toJSON");
13
10
 
14
- var _Collection = _interopRequireDefault(require("./Collection"));
11
+ var _Collection = require("./Collection");
15
12
 
16
- var _Node = _interopRequireDefault(require("./Node"));
13
+ var _Node = require("./Node");
17
14
 
18
- var _Pair = _interopRequireDefault(require("./Pair"));
19
-
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+ var _Pair = require("./Pair");
21
16
 
22
17
  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; }
23
18
 
24
19
  const getAliasCount = (node, anchors) => {
25
20
  if (node instanceof Alias) {
26
- const anchor = anchors.find(a => a.node === node.source);
21
+ const anchor = anchors.get(node.source);
27
22
  return anchor.count * anchor.aliasCount;
28
- } else if (node instanceof _Collection.default) {
23
+ } else if (node instanceof _Collection.Collection) {
29
24
  let count = 0;
30
25
 
31
26
  for (const item of node.items) {
@@ -34,7 +29,7 @@ const getAliasCount = (node, anchors) => {
34
29
  }
35
30
 
36
31
  return count;
37
- } else if (node instanceof _Pair.default) {
32
+ } else if (node instanceof _Pair.Pair) {
38
33
  const kc = getAliasCount(node.key, anchors);
39
34
  const vc = getAliasCount(node.value, anchors);
40
35
  return Math.max(kc, vc);
@@ -43,7 +38,7 @@ const getAliasCount = (node, anchors) => {
43
38
  return 1;
44
39
  };
45
40
 
46
- class Alias extends _Node.default {
41
+ class Alias extends _Node.Node {
47
42
  static stringify({
48
43
  range,
49
44
  source
@@ -71,12 +66,12 @@ class Alias extends _Node.default {
71
66
  }
72
67
 
73
68
  toJSON(arg, ctx) {
74
- if (!ctx) return (0, _toJSON.default)(this.source, arg, ctx);
69
+ if (!ctx) return (0, _toJSON.toJSON)(this.source, arg, ctx);
75
70
  const {
76
71
  anchors,
77
72
  maxAliasCount
78
73
  } = ctx;
79
- const anchor = anchors.find(a => a.node === this.source);
74
+ const anchor = anchors.get(this.source);
80
75
  /* istanbul ignore if */
81
76
 
82
77
  if (!anchor || anchor.res === undefined) {
@@ -105,6 +100,6 @@ class Alias extends _Node.default {
105
100
 
106
101
  }
107
102
 
108
- exports.default = Alias;
103
+ exports.Alias = Alias;
109
104
 
110
105
  _defineProperty(Alias, "default", true);
@@ -1,19 +1,14 @@
1
1
  "use strict";
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.isEmptyPath = void 0;
3
+ exports.Collection = exports.isEmptyPath = void 0;
7
4
 
8
- var _addComment = _interopRequireDefault(require("../addComment"));
5
+ var _addComment = require("../addComment");
9
6
 
10
- var _Node = _interopRequireDefault(require("./Node"));
7
+ var _constants = require("../constants");
11
8
 
12
- var _Pair = _interopRequireDefault(require("./Pair"));
9
+ var _Node = require("./Node");
13
10
 
14
- var _Scalar = _interopRequireDefault(require("./Scalar"));
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ var _Scalar = require("./Scalar");
17
12
 
18
13
  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; }
19
14
 
@@ -35,7 +30,7 @@ const isEmptyPath = path => path == null || typeof path === 'object' && path[Sym
35
30
 
36
31
  exports.isEmptyPath = isEmptyPath;
37
32
 
38
- class Collection extends _Node.default {
33
+ class Collection extends _Node.Node {
39
34
  constructor(schema) {
40
35
  super();
41
36
 
@@ -60,14 +55,14 @@ class Collection extends _Node.default {
60
55
 
61
56
  getIn([key, ...rest], keepScalar) {
62
57
  const node = this.get(key, true);
63
- if (rest.length === 0) return !keepScalar && node instanceof _Scalar.default ? node.value : node;else return node instanceof Collection ? node.getIn(rest, keepScalar) : undefined;
58
+ if (rest.length === 0) return !keepScalar && node instanceof _Scalar.Scalar ? node.value : node;else return node instanceof Collection ? node.getIn(rest, keepScalar) : undefined;
64
59
  }
65
60
 
66
61
  hasAllNullValues() {
67
62
  return this.items.every(node => {
68
- if (!(node instanceof _Pair.default)) return false;
63
+ if (!node || node.type !== 'PAIR') return false;
69
64
  const n = node.value;
70
- return n == null || n instanceof _Scalar.default && n.value == null && !n.commentBefore && !n.comment && !n.tag;
65
+ return n == null || n instanceof _Scalar.Scalar && n.value == null && !n.commentBefore && !n.comment && !n.tag;
71
66
  });
72
67
  }
73
68
 
@@ -101,10 +96,11 @@ class Collection extends _Node.default {
101
96
  }, onComment, onChompKeep) {
102
97
  const {
103
98
  doc,
104
- indent
99
+ indent,
100
+ indentStep
105
101
  } = ctx;
106
- const inFlow = this.type && this.type.substr(0, 4) === 'FLOW' || ctx.inFlow;
107
- if (inFlow) itemIndent += ' ';
102
+ const inFlow = this.type === _constants.Type.FLOW_MAP || this.type === _constants.Type.FLOW_SEQ || ctx.inFlow;
103
+ if (inFlow) itemIndent += indentStep;
108
104
  const allNullValues = isMap && this.hasAllNullValues();
109
105
  ctx = Object.assign({}, ctx, {
110
106
  allNullValues,
@@ -136,7 +132,7 @@ class Collection extends _Node.default {
136
132
  let str = doc.schema.stringify(item, ctx, () => comment = null, () => chompKeep = true);
137
133
  if (inFlow && !hasItemWithNewLine && str.includes('\n')) hasItemWithNewLine = true;
138
134
  if (inFlow && i < this.items.length - 1) str += ',';
139
- str = (0, _addComment.default)(str, itemIndent, comment);
135
+ str = (0, _addComment.addComment)(str, itemIndent, comment);
140
136
  if (chompKeep && (comment || inFlow)) chompKeep = false;
141
137
  nodes.push({
142
138
  type: 'item',
@@ -159,7 +155,7 @@ class Collection extends _Node.default {
159
155
  str = start;
160
156
 
161
157
  for (const s of strings) {
162
- str += s ? `\n ${indent}${s}` : '\n';
158
+ str += s ? `\n${indentStep}${indent}${s}` : '\n';
163
159
  }
164
160
 
165
161
  str += `\n${indent}${end}`;
@@ -183,6 +179,6 @@ class Collection extends _Node.default {
183
179
 
184
180
  }
185
181
 
186
- exports.default = Collection;
182
+ exports.Collection = Collection;
187
183
 
188
184
  _defineProperty(Collection, "maxFlowStringSingleLineLength", 60);
@@ -1,24 +1,19 @@
1
1
  "use strict";
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
3
  exports.findPair = findPair;
7
- exports.default = void 0;
4
+ exports.YAMLMap = void 0;
8
5
 
9
- var _Collection = _interopRequireDefault(require("./Collection"));
6
+ var _Collection = require("./Collection");
10
7
 
11
- var _Pair = _interopRequireDefault(require("./Pair"));
8
+ var _Pair = require("./Pair");
12
9
 
13
- var _Scalar = _interopRequireDefault(require("./Scalar"));
14
-
15
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ var _Scalar = require("./Scalar");
16
11
 
17
12
  function findPair(items, key) {
18
- const k = key instanceof _Scalar.default ? key.value : key;
13
+ const k = key instanceof _Scalar.Scalar ? key.value : key;
19
14
 
20
15
  for (const it of items) {
21
- if (it instanceof _Pair.default) {
16
+ if (it instanceof _Pair.Pair) {
22
17
  if (it.key === key || it.key === k) return it;
23
18
  if (it.key && it.key.value === k) return it;
24
19
  }
@@ -27,9 +22,9 @@ function findPair(items, key) {
27
22
  return undefined;
28
23
  }
29
24
 
30
- class YAMLMap extends _Collection.default {
25
+ class YAMLMap extends _Collection.Collection {
31
26
  add(pair, overwrite) {
32
- if (!pair) pair = new _Pair.default(pair);else if (!(pair instanceof _Pair.default)) pair = new _Pair.default(pair.key || pair, pair.value);
27
+ if (!pair) pair = new _Pair.Pair(pair);else if (!(pair instanceof _Pair.Pair)) pair = new _Pair.Pair(pair.key || pair, pair.value);
33
28
  const prev = findPair(this.items, pair.key);
34
29
  const sortEntries = this.schema && this.schema.sortMapEntries;
35
30
 
@@ -53,7 +48,7 @@ class YAMLMap extends _Collection.default {
53
48
  get(key, keepScalar) {
54
49
  const it = findPair(this.items, key);
55
50
  const node = it && it.value;
56
- return !keepScalar && node instanceof _Scalar.default ? node.value : node;
51
+ return !keepScalar && node instanceof _Scalar.Scalar ? node.value : node;
57
52
  }
58
53
 
59
54
  has(key) {
@@ -61,7 +56,7 @@ class YAMLMap extends _Collection.default {
61
56
  }
62
57
 
63
58
  set(key, value) {
64
- this.add(new _Pair.default(key, value), true);
59
+ this.add(new _Pair.Pair(key, value), true);
65
60
  }
66
61
  /**
67
62
  * @param {*} arg ignored
@@ -84,7 +79,7 @@ class YAMLMap extends _Collection.default {
84
79
  if (!ctx) return JSON.stringify(this);
85
80
 
86
81
  for (const item of this.items) {
87
- if (!(item instanceof _Pair.default)) throw new Error(`Map items must all be pairs; found ${JSON.stringify(item)} instead`);
82
+ if (!(item instanceof _Pair.Pair)) throw new Error(`Map items must all be pairs; found ${JSON.stringify(item)} instead`);
88
83
  }
89
84
 
90
85
  return super.toString(ctx, {
@@ -100,4 +95,4 @@ class YAMLMap extends _Collection.default {
100
95
 
101
96
  }
102
97
 
103
- exports.default = YAMLMap;
98
+ exports.YAMLMap = YAMLMap;
@@ -1,30 +1,25 @@
1
1
  "use strict";
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.MERGE_KEY = void 0;
3
+ exports.Merge = exports.MERGE_KEY = void 0;
7
4
 
8
- var _Map = _interopRequireDefault(require("./Map"));
5
+ var _Map = require("./Map");
9
6
 
10
- var _Pair = _interopRequireDefault(require("./Pair"));
7
+ var _Pair = require("./Pair");
11
8
 
12
- var _Scalar = _interopRequireDefault(require("./Scalar"));
9
+ var _Scalar = require("./Scalar");
13
10
 
14
- var _Seq = _interopRequireDefault(require("./Seq"));
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ var _Seq = require("./Seq");
17
12
 
18
13
  const MERGE_KEY = '<<';
19
14
  exports.MERGE_KEY = MERGE_KEY;
20
15
 
21
- class Merge extends _Pair.default {
16
+ class Merge extends _Pair.Pair {
22
17
  constructor(pair) {
23
- if (pair instanceof _Pair.default) {
18
+ if (pair instanceof _Pair.Pair) {
24
19
  let seq = pair.value;
25
20
 
26
- if (!(seq instanceof _Seq.default)) {
27
- seq = new _Seq.default();
21
+ if (!(seq instanceof _Seq.YAMLSeq)) {
22
+ seq = new _Seq.YAMLSeq();
28
23
  seq.items.push(pair.value);
29
24
  seq.range = pair.value.range;
30
25
  }
@@ -32,10 +27,10 @@ class Merge extends _Pair.default {
32
27
  super(pair.key, seq);
33
28
  this.range = pair.range;
34
29
  } else {
35
- super(new _Scalar.default(MERGE_KEY), new _Seq.default());
30
+ super(new _Scalar.Scalar(MERGE_KEY), new _Seq.YAMLSeq());
36
31
  }
37
32
 
38
- this.type = 'MERGE_PAIR';
33
+ this.type = _Pair.Pair.Type.MERGE_PAIR;
39
34
  } // If the value associated with a merge key is a single mapping node, each of
40
35
  // its key/value pairs is inserted into the current mapping, unless the key
41
36
  // already exists in it. If the value associated with the merge key is a
@@ -49,7 +44,7 @@ class Merge extends _Pair.default {
49
44
  for (const {
50
45
  source
51
46
  } of this.value.items) {
52
- if (!(source instanceof _Map.default)) throw new Error('Merge sources must be maps');
47
+ if (!(source instanceof _Map.YAMLMap)) throw new Error('Merge sources must be maps');
53
48
  const srcMap = source.toJSON(null, ctx, Map);
54
49
 
55
50
  for (const [key, value] of srcMap) {
@@ -77,4 +72,4 @@ class Merge extends _Pair.default {
77
72
 
78
73
  }
79
74
 
80
- exports.default = Merge;
75
+ exports.Merge = Merge;
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
3
+ exports.Node = void 0;
7
4
 
8
5
  class Node {}
9
6
 
10
- exports.default = Node;
7
+ exports.Node = Node;
@@ -1,44 +1,43 @@
1
1
  "use strict";
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
3
+ exports.Pair = void 0;
7
4
 
8
- var _addComment = _interopRequireDefault(require("../addComment"));
5
+ var _addComment = require("../addComment");
9
6
 
10
7
  var _constants = require("../constants");
11
8
 
12
- var _toJSON = _interopRequireDefault(require("../toJSON"));
9
+ var _toJSON = require("../toJSON");
13
10
 
14
- var _Collection = _interopRequireDefault(require("./Collection"));
11
+ var _Collection = require("./Collection");
15
12
 
16
- var _Node = _interopRequireDefault(require("./Node"));
13
+ var _Node = require("./Node");
17
14
 
18
- var _Scalar = _interopRequireDefault(require("./Scalar"));
15
+ var _Scalar = require("./Scalar");
19
16
 
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+ var _Seq = require("./Seq");
18
+
19
+ 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; }
21
20
 
22
- // Published as 'yaml/pair'
23
21
  const stringifyKey = (key, jsKey, ctx) => {
24
22
  if (jsKey === null) return '';
25
23
  if (typeof jsKey !== 'object') return String(jsKey);
26
- if (key instanceof _Node.default && ctx && ctx.doc) return key.toString({
24
+ if (key instanceof _Node.Node && ctx && ctx.doc) return key.toString({
27
25
  anchors: {},
28
26
  doc: ctx.doc,
29
27
  indent: '',
28
+ indentStep: ctx.indentStep,
30
29
  inFlow: true,
31
30
  inStringifyKey: true
32
31
  });
33
32
  return JSON.stringify(jsKey);
34
33
  };
35
34
 
36
- class Pair extends _Node.default {
35
+ class Pair extends _Node.Node {
37
36
  constructor(key, value = null) {
38
37
  super();
39
38
  this.key = key;
40
39
  this.value = value;
41
- this.type = 'PAIR';
40
+ this.type = Pair.Type.PAIR;
42
41
  }
43
42
 
44
43
  get commentBefore() {
@@ -46,21 +45,21 @@ class Pair extends _Node.default {
46
45
  }
47
46
 
48
47
  set commentBefore(cb) {
49
- if (this.key == null) this.key = new _Scalar.default(null);
48
+ if (this.key == null) this.key = new _Scalar.Scalar(null);
50
49
  this.key.commentBefore = cb;
51
50
  }
52
51
 
53
52
  addToJSMap(ctx, map) {
54
- const key = (0, _toJSON.default)(this.key, '', ctx);
53
+ const key = (0, _toJSON.toJSON)(this.key, '', ctx);
55
54
 
56
55
  if (map instanceof Map) {
57
- const value = (0, _toJSON.default)(this.value, key, ctx);
56
+ const value = (0, _toJSON.toJSON)(this.value, key, ctx);
58
57
  map.set(key, value);
59
58
  } else if (map instanceof Set) {
60
59
  map.add(key);
61
60
  } else {
62
61
  const stringKey = stringifyKey(this.key, key, ctx);
63
- map[stringKey] = (0, _toJSON.default)(this.value, stringKey, ctx);
62
+ map[stringKey] = (0, _toJSON.toJSON)(this.value, stringKey, ctx);
64
63
  }
65
64
 
66
65
  return map;
@@ -74,41 +73,44 @@ class Pair extends _Node.default {
74
73
  toString(ctx, onComment, onChompKeep) {
75
74
  if (!ctx || !ctx.doc) return JSON.stringify(this);
76
75
  const {
76
+ indent: indentSize,
77
+ indentSeq,
77
78
  simpleKeys
78
79
  } = ctx.doc.options;
79
80
  let {
80
81
  key,
81
82
  value
82
83
  } = this;
83
- let keyComment = key instanceof _Node.default && key.comment;
84
+ let keyComment = key instanceof _Node.Node && key.comment;
84
85
 
85
86
  if (simpleKeys) {
86
87
  if (keyComment) {
87
88
  throw new Error('With simple keys, key nodes cannot have comments');
88
89
  }
89
90
 
90
- if (key instanceof _Collection.default) {
91
+ if (key instanceof _Collection.Collection) {
91
92
  const msg = 'With simple keys, collection cannot be used as a key value';
92
93
  throw new Error(msg);
93
94
  }
94
95
  }
95
96
 
96
- const explicitKey = !simpleKeys && (!key || keyComment || key instanceof _Collection.default || key.type === _constants.Type.BLOCK_FOLDED || key.type === _constants.Type.BLOCK_LITERAL);
97
+ const explicitKey = !simpleKeys && (!key || keyComment || key instanceof _Collection.Collection || key.type === _constants.Type.BLOCK_FOLDED || key.type === _constants.Type.BLOCK_LITERAL);
97
98
  const {
98
99
  doc,
99
- indent
100
+ indent,
101
+ indentStep
100
102
  } = ctx;
101
103
  ctx = Object.assign({}, ctx, {
102
104
  implicitKey: !explicitKey,
103
- indent: indent + ' '
105
+ indent: indent + indentStep
104
106
  });
105
107
  let chompKeep = false;
106
108
  let str = doc.schema.stringify(key, ctx, () => keyComment = null, () => chompKeep = true);
107
- str = (0, _addComment.default)(str, ctx.indent, keyComment);
109
+ str = (0, _addComment.addComment)(str, ctx.indent, keyComment);
108
110
 
109
111
  if (ctx.allNullValues && !simpleKeys) {
110
112
  if (this.comment) {
111
- str = (0, _addComment.default)(str, ctx.indent, this.comment);
113
+ str = (0, _addComment.addComment)(str, ctx.indent, this.comment);
112
114
  if (onComment) onComment();
113
115
  } else if (chompKeep && !keyComment && onChompKeep) onChompKeep();
114
116
 
@@ -119,14 +121,14 @@ class Pair extends _Node.default {
119
121
 
120
122
  if (this.comment) {
121
123
  // expected (but not strictly required) to be a single-line comment
122
- str = (0, _addComment.default)(str, ctx.indent, this.comment);
124
+ str = (0, _addComment.addComment)(str, ctx.indent, this.comment);
123
125
  if (onComment) onComment();
124
126
  }
125
127
 
126
128
  let vcb = '';
127
129
  let valueComment = null;
128
130
 
129
- if (value instanceof _Node.default) {
131
+ if (value instanceof _Node.Node) {
130
132
  if (value.spaceBefore) vcb = '\n';
131
133
 
132
134
  if (value.commentBefore) {
@@ -140,22 +142,33 @@ class Pair extends _Node.default {
140
142
  }
141
143
 
142
144
  ctx.implicitKey = false;
143
- if (!explicitKey && !this.comment && value instanceof _Scalar.default) ctx.indentAtStart = str.length + 1;
145
+ if (!explicitKey && !this.comment && value instanceof _Scalar.Scalar) ctx.indentAtStart = str.length + 1;
144
146
  chompKeep = false;
147
+
148
+ if (!indentSeq && indentSize >= 2 && !ctx.inFlow && !explicitKey && value instanceof _Seq.YAMLSeq && value.type !== _constants.Type.FLOW_SEQ && !value.tag && !doc.anchors.getName(value)) {
149
+ // If indentSeq === false, consider '- ' as part of indentation where possible
150
+ ctx.indent = ctx.indent.substr(2);
151
+ }
152
+
145
153
  const valueStr = doc.schema.stringify(value, ctx, () => valueComment = null, () => chompKeep = true);
146
154
  let ws = ' ';
147
155
 
148
156
  if (vcb || this.comment) {
149
157
  ws = `${vcb}\n${ctx.indent}`;
150
- } else if (!explicitKey && value instanceof _Collection.default) {
158
+ } else if (!explicitKey && value instanceof _Collection.Collection) {
151
159
  const flow = valueStr[0] === '[' || valueStr[0] === '{';
152
160
  if (!flow || valueStr.includes('\n')) ws = `\n${ctx.indent}`;
153
161
  }
154
162
 
155
163
  if (chompKeep && !valueComment && onChompKeep) onChompKeep();
156
- return (0, _addComment.default)(str + ws + valueStr, ctx.indent, valueComment);
164
+ return (0, _addComment.addComment)(str + ws + valueStr, ctx.indent, valueComment);
157
165
  }
158
166
 
159
167
  }
160
168
 
161
- exports.default = Pair;
169
+ exports.Pair = Pair;
170
+
171
+ _defineProperty(Pair, "Type", {
172
+ PAIR: 'PAIR',
173
+ MERGE_PAIR: 'MERGE_PAIR'
174
+ });
@@ -1,25 +1,20 @@
1
1
  "use strict";
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
3
+ exports.Scalar = void 0;
7
4
 
8
- var _toJSON = _interopRequireDefault(require("../toJSON"));
5
+ var _toJSON = require("../toJSON");
9
6
 
10
- var _Node = _interopRequireDefault(require("./Node"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
7
+ var _Node = require("./Node");
13
8
 
14
9
  // Published as 'yaml/scalar'
15
- class Scalar extends _Node.default {
10
+ class Scalar extends _Node.Node {
16
11
  constructor(value) {
17
12
  super();
18
13
  this.value = value;
19
14
  }
20
15
 
21
16
  toJSON(arg, ctx) {
22
- return ctx && ctx.keep ? this.value : (0, _toJSON.default)(this.value, arg, ctx);
17
+ return ctx && ctx.keep ? this.value : (0, _toJSON.toJSON)(this.value, arg, ctx);
23
18
  }
24
19
 
25
20
  toString() {
@@ -28,4 +23,4 @@ class Scalar extends _Node.default {
28
23
 
29
24
  }
30
25
 
31
- exports.default = Scalar;
26
+ exports.Scalar = Scalar;
@@ -1,26 +1,21 @@
1
1
  "use strict";
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
3
+ exports.YAMLSeq = void 0;
7
4
 
8
- var _toJSON = _interopRequireDefault(require("../toJSON"));
5
+ var _toJSON = require("../toJSON");
9
6
 
10
- var _Collection = _interopRequireDefault(require("./Collection"));
7
+ var _Collection = require("./Collection");
11
8
 
12
- var _Scalar = _interopRequireDefault(require("./Scalar"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ var _Scalar = require("./Scalar");
15
10
 
16
11
  // Published as 'yaml/seq'
17
12
  function asItemIndex(key) {
18
- let idx = key instanceof _Scalar.default ? key.value : key;
13
+ let idx = key instanceof _Scalar.Scalar ? key.value : key;
19
14
  if (idx && typeof idx === 'string') idx = Number(idx);
20
15
  return Number.isInteger(idx) && idx >= 0 ? idx : null;
21
16
  }
22
17
 
23
- class YAMLSeq extends _Collection.default {
18
+ class YAMLSeq extends _Collection.Collection {
24
19
  add(value) {
25
20
  this.items.push(value);
26
21
  }
@@ -36,7 +31,7 @@ class YAMLSeq extends _Collection.default {
36
31
  const idx = asItemIndex(key);
37
32
  if (typeof idx !== 'number') return undefined;
38
33
  const it = this.items[idx];
39
- return !keepScalar && it instanceof _Scalar.default ? it.value : it;
34
+ return !keepScalar && it instanceof _Scalar.Scalar ? it.value : it;
40
35
  }
41
36
 
42
37
  has(key) {
@@ -55,7 +50,7 @@ class YAMLSeq extends _Collection.default {
55
50
  if (ctx && ctx.onCreate) ctx.onCreate(seq);
56
51
  let i = 0;
57
52
 
58
- for (const item of this.items) seq.push((0, _toJSON.default)(item, String(i++), ctx));
53
+ for (const item of this.items) seq.push((0, _toJSON.toJSON)(item, String(i++), ctx));
59
54
 
60
55
  return seq;
61
56
  }
@@ -75,4 +70,4 @@ class YAMLSeq extends _Collection.default {
75
70
 
76
71
  }
77
72
 
78
- exports.default = YAMLSeq;
73
+ exports.YAMLSeq = YAMLSeq;