yaml 1.8.3 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/README.md +4 -4
  2. package/browser/dist/PlainValue-ff5147c6.js +1277 -0
  3. package/browser/dist/Schema-2bf2c74e.js +679 -0
  4. package/browser/dist/index.js +923 -38
  5. package/browser/dist/legacy-exports.js +3 -0
  6. package/browser/dist/parse-cst.js +1904 -0
  7. package/browser/dist/resolveSeq-04825f30.js +2373 -0
  8. package/browser/dist/types.js +4 -0
  9. package/browser/dist/util.js +2 -0
  10. package/browser/dist/warnings-0e4b70d3.js +499 -0
  11. package/browser/index.js +1 -1
  12. package/browser/map.js +2 -2
  13. package/browser/pair.js +2 -2
  14. package/browser/parse-cst.js +1 -1
  15. package/browser/scalar.js +2 -2
  16. package/browser/schema.js +8 -6
  17. package/browser/seq.js +2 -2
  18. package/browser/types/binary.js +3 -2
  19. package/browser/types/omap.js +3 -2
  20. package/browser/types/pairs.js +3 -2
  21. package/browser/types/set.js +3 -2
  22. package/browser/types/timestamp.js +6 -6
  23. package/browser/types.js +1 -11
  24. package/browser/util.js +1 -15
  25. package/dist/Document-2cf6b08c.js +757 -0
  26. package/dist/PlainValue-ec8e588e.js +876 -0
  27. package/dist/Schema-42e9705c.js +522 -0
  28. package/dist/index.js +21 -43
  29. package/dist/legacy-exports.js +16 -0
  30. package/dist/parse-cst.js +1747 -0
  31. package/dist/resolveSeq-4a68b39b.js +2115 -0
  32. package/dist/test-events.js +11 -14
  33. package/dist/types.js +23 -0
  34. package/dist/util.js +19 -0
  35. package/dist/warnings-39684f17.js +416 -0
  36. package/index.d.ts +372 -0
  37. package/index.js +1 -1
  38. package/map.js +2 -2
  39. package/package.json +32 -45
  40. package/pair.js +2 -2
  41. package/parse-cst.d.ts +187 -0
  42. package/parse-cst.js +1 -1
  43. package/scalar.js +2 -2
  44. package/schema.js +8 -6
  45. package/seq.js +2 -2
  46. package/types/binary.js +3 -2
  47. package/types/omap.js +3 -2
  48. package/types/pairs.js +3 -2
  49. package/types/set.js +3 -2
  50. package/types/timestamp.js +6 -6
  51. package/types.d.ts +407 -0
  52. package/types.js +16 -10
  53. package/types.mjs +15 -18
  54. package/util.d.ts +86 -0
  55. package/util.js +14 -13
  56. package/util.mjs +13 -19
  57. package/browser/dist/Anchors.js +0 -133
  58. package/browser/dist/Document.js +0 -819
  59. package/browser/dist/addComment.js +0 -8
  60. package/browser/dist/constants.js +0 -26
  61. package/browser/dist/cst/Alias.js +0 -42
  62. package/browser/dist/cst/BlankLine.js +0 -56
  63. package/browser/dist/cst/BlockValue.js +0 -247
  64. package/browser/dist/cst/Collection.js +0 -274
  65. package/browser/dist/cst/CollectionItem.js +0 -136
  66. package/browser/dist/cst/Comment.js +0 -40
  67. package/browser/dist/cst/Directive.js +0 -72
  68. package/browser/dist/cst/Document.js +0 -282
  69. package/browser/dist/cst/FlowCollection.js +0 -216
  70. package/browser/dist/cst/Node.js +0 -388
  71. package/browser/dist/cst/ParseContext.js +0 -248
  72. package/browser/dist/cst/PlainValue.js +0 -166
  73. package/browser/dist/cst/QuoteDouble.js +0 -241
  74. package/browser/dist/cst/QuoteSingle.js +0 -116
  75. package/browser/dist/cst/Range.js +0 -67
  76. package/browser/dist/cst/parse.js +0 -48
  77. package/browser/dist/cst/source-utils.js +0 -168
  78. package/browser/dist/errors.js +0 -112
  79. package/browser/dist/foldFlowLines.js +0 -138
  80. package/browser/dist/listTagNames.js +0 -28
  81. package/browser/dist/schema/Alias.js +0 -139
  82. package/browser/dist/schema/Collection.js +0 -267
  83. package/browser/dist/schema/Map.js +0 -178
  84. package/browser/dist/schema/Merge.js +0 -127
  85. package/browser/dist/schema/Node.js +0 -7
  86. package/browser/dist/schema/Pair.js +0 -171
  87. package/browser/dist/schema/Scalar.js +0 -38
  88. package/browser/dist/schema/Seq.js +0 -114
  89. package/browser/dist/schema/index.js +0 -382
  90. package/browser/dist/schema/parseMap.js +0 -312
  91. package/browser/dist/schema/parseSeq.js +0 -168
  92. package/browser/dist/schema/parseUtils.js +0 -110
  93. package/browser/dist/stringify.js +0 -331
  94. package/browser/dist/tags/core.js +0 -126
  95. package/browser/dist/tags/failsafe/index.js +0 -4
  96. package/browser/dist/tags/failsafe/map.js +0 -56
  97. package/browser/dist/tags/failsafe/seq.js +0 -43
  98. package/browser/dist/tags/failsafe/string.js +0 -28
  99. package/browser/dist/tags/index.js +0 -36
  100. package/browser/dist/tags/json.js +0 -76
  101. package/browser/dist/tags/options.js +0 -23
  102. package/browser/dist/tags/yaml-1.1/binary.js +0 -87
  103. package/browser/dist/tags/yaml-1.1/index.js +0 -157
  104. package/browser/dist/tags/yaml-1.1/omap.js +0 -142
  105. package/browser/dist/tags/yaml-1.1/pairs.js +0 -81
  106. package/browser/dist/tags/yaml-1.1/set.js +0 -114
  107. package/browser/dist/tags/yaml-1.1/timestamp.js +0 -97
  108. package/browser/dist/test-events.js +0 -163
  109. package/browser/dist/toJSON.js +0 -20
  110. package/browser/dist/warnings.js +0 -28
  111. package/dist/Anchors.js +0 -125
  112. package/dist/Document.js +0 -710
  113. package/dist/addComment.js +0 -17
  114. package/dist/constants.js +0 -34
  115. package/dist/cst/Alias.js +0 -38
  116. package/dist/cst/BlankLine.js +0 -56
  117. package/dist/cst/BlockValue.js +0 -248
  118. package/dist/cst/Collection.js +0 -271
  119. package/dist/cst/CollectionItem.js +0 -140
  120. package/dist/cst/Comment.js +0 -38
  121. package/dist/cst/Directive.js +0 -64
  122. package/dist/cst/Document.js +0 -281
  123. package/dist/cst/FlowCollection.js +0 -218
  124. package/dist/cst/Node.js +0 -365
  125. package/dist/cst/ParseContext.js +0 -258
  126. package/dist/cst/PlainValue.js +0 -161
  127. package/dist/cst/QuoteDouble.js +0 -237
  128. package/dist/cst/QuoteSingle.js +0 -113
  129. package/dist/cst/Range.js +0 -63
  130. package/dist/cst/parse.js +0 -55
  131. package/dist/cst/source-utils.js +0 -178
  132. package/dist/errors.js +0 -102
  133. package/dist/foldFlowLines.js +0 -146
  134. package/dist/listTagNames.js +0 -38
  135. package/dist/schema/Alias.js +0 -110
  136. package/dist/schema/Collection.js +0 -188
  137. package/dist/schema/Map.js +0 -103
  138. package/dist/schema/Merge.js +0 -80
  139. package/dist/schema/Node.js +0 -10
  140. package/dist/schema/Pair.js +0 -161
  141. package/dist/schema/Scalar.js +0 -31
  142. package/dist/schema/Seq.js +0 -78
  143. package/dist/schema/index.js +0 -315
  144. package/dist/schema/parseMap.js +0 -343
  145. package/dist/schema/parseSeq.js +0 -180
  146. package/dist/schema/parseUtils.js +0 -104
  147. package/dist/stringify.js +0 -358
  148. package/dist/tags/core.js +0 -114
  149. package/dist/tags/failsafe/index.js +0 -17
  150. package/dist/tags/failsafe/map.js +0 -37
  151. package/dist/tags/failsafe/seq.js +0 -34
  152. package/dist/tags/failsafe/string.js +0 -40
  153. package/dist/tags/index.js +0 -62
  154. package/dist/tags/json.js +0 -60
  155. package/dist/tags/options.js +0 -35
  156. package/dist/tags/yaml-1.1/binary.js +0 -97
  157. package/dist/tags/yaml-1.1/index.js +0 -131
  158. package/dist/tags/yaml-1.1/omap.js +0 -105
  159. package/dist/tags/yaml-1.1/pairs.js +0 -80
  160. package/dist/tags/yaml-1.1/set.js +0 -91
  161. package/dist/tags/yaml-1.1/timestamp.js +0 -93
  162. package/dist/toJSON.js +0 -23
  163. package/dist/warnings.js +0 -39
@@ -1,8 +0,0 @@
1
- export function addCommentBefore(str, indent, comment) {
2
- if (!comment) return str;
3
- var cc = comment.replace(/[\s\S]^/gm, "$&".concat(indent, "#"));
4
- return "#".concat(cc, "\n").concat(indent).concat(str);
5
- }
6
- export default function addComment(str, indent, comment) {
7
- return !comment ? str : comment.indexOf('\n') === -1 ? "".concat(str, " #").concat(comment) : "".concat(str, "\n") + comment.replace(/^/gm, "".concat(indent || '', "#"));
8
- }
@@ -1,26 +0,0 @@
1
- export var Char = {
2
- ANCHOR: '&',
3
- COMMENT: '#',
4
- TAG: '!',
5
- DIRECTIVES_END: '-',
6
- DOCUMENT_END: '.'
7
- };
8
- export var Type = {
9
- ALIAS: 'ALIAS',
10
- BLANK_LINE: 'BLANK_LINE',
11
- BLOCK_FOLDED: 'BLOCK_FOLDED',
12
- BLOCK_LITERAL: 'BLOCK_LITERAL',
13
- COMMENT: 'COMMENT',
14
- DIRECTIVE: 'DIRECTIVE',
15
- DOCUMENT: 'DOCUMENT',
16
- FLOW_MAP: 'FLOW_MAP',
17
- FLOW_SEQ: 'FLOW_SEQ',
18
- MAP: 'MAP',
19
- MAP_KEY: 'MAP_KEY',
20
- MAP_VALUE: 'MAP_VALUE',
21
- PLAIN: 'PLAIN',
22
- QUOTE_DOUBLE: 'QUOTE_DOUBLE',
23
- QUOTE_SINGLE: 'QUOTE_SINGLE',
24
- SEQ: 'SEQ',
25
- SEQ_ITEM: 'SEQ_ITEM'
26
- };
@@ -1,42 +0,0 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
4
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
5
- import _inherits from "@babel/runtime/helpers/inherits";
6
- import Node from './Node';
7
- import Range from './Range';
8
-
9
- var Alias = /*#__PURE__*/function (_Node) {
10
- _inherits(Alias, _Node);
11
-
12
- function Alias() {
13
- _classCallCheck(this, Alias);
14
-
15
- return _possibleConstructorReturn(this, _getPrototypeOf(Alias).apply(this, arguments));
16
- }
17
-
18
- _createClass(Alias, [{
19
- key: "parse",
20
-
21
- /**
22
- * Parses an *alias from the source
23
- *
24
- * @param {ParseContext} context
25
- * @param {number} start - Index of first character
26
- * @returns {number} - Index of the character after this scalar
27
- */
28
- value: function parse(context, start) {
29
- this.context = context;
30
- var src = context.src;
31
- var offset = Node.endOfIdentifier(src, start + 1);
32
- this.valueRange = new Range(start + 1, offset);
33
- offset = Node.endOfWhiteSpace(src, offset);
34
- offset = this.parseComment(offset);
35
- return offset;
36
- }
37
- }]);
38
-
39
- return Alias;
40
- }(Node);
41
-
42
- export { Alias as default };
@@ -1,56 +0,0 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
4
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
5
- import _inherits from "@babel/runtime/helpers/inherits";
6
- import { Type } from '../constants';
7
- import Node from './Node';
8
- import Range from './Range';
9
-
10
- var BlankLine = /*#__PURE__*/function (_Node) {
11
- _inherits(BlankLine, _Node);
12
-
13
- function BlankLine() {
14
- _classCallCheck(this, BlankLine);
15
-
16
- return _possibleConstructorReturn(this, _getPrototypeOf(BlankLine).call(this, Type.BLANK_LINE));
17
- }
18
- /* istanbul ignore next */
19
-
20
-
21
- _createClass(BlankLine, [{
22
- key: "parse",
23
-
24
- /**
25
- * Parses blank lines from the source
26
- *
27
- * @param {ParseContext} context
28
- * @param {number} start - Index of first \n character
29
- * @returns {number} - Index of the character after this
30
- */
31
- value: function parse(context, start) {
32
- this.context = context;
33
- var src = context.src;
34
- var offset = start + 1;
35
-
36
- while (Node.atBlank(src, offset)) {
37
- var lineEnd = Node.endOfWhiteSpace(src, offset);
38
- if (lineEnd === '\n') offset = lineEnd + 1;else break;
39
- }
40
-
41
- this.range = new Range(start, offset);
42
- return offset;
43
- }
44
- }, {
45
- key: "includesTrailingLines",
46
- get: function get() {
47
- // This is never called from anywhere, but if it were,
48
- // this is the value it should return.
49
- return true;
50
- }
51
- }]);
52
-
53
- return BlankLine;
54
- }(Node);
55
-
56
- export { BlankLine as default };
@@ -1,247 +0,0 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
4
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
5
- import _get from "@babel/runtime/helpers/get";
6
- import _inherits from "@babel/runtime/helpers/inherits";
7
- import { Type } from '../constants';
8
- import Node from './Node';
9
- import Range from './Range';
10
- export var Chomp = {
11
- CLIP: 'CLIP',
12
- KEEP: 'KEEP',
13
- STRIP: 'STRIP'
14
- };
15
-
16
- var BlockValue = /*#__PURE__*/function (_Node) {
17
- _inherits(BlockValue, _Node);
18
-
19
- function BlockValue(type, props) {
20
- var _this;
21
-
22
- _classCallCheck(this, BlockValue);
23
-
24
- _this = _possibleConstructorReturn(this, _getPrototypeOf(BlockValue).call(this, type, props));
25
- _this.blockIndent = null;
26
- _this.chomping = Chomp.CLIP;
27
- _this.header = null;
28
- return _this;
29
- }
30
-
31
- _createClass(BlockValue, [{
32
- key: "parseBlockHeader",
33
- value: function parseBlockHeader(start) {
34
- var src = this.context.src;
35
- var offset = start + 1;
36
- var bi = '';
37
-
38
- while (true) {
39
- var ch = src[offset];
40
-
41
- switch (ch) {
42
- case '-':
43
- this.chomping = Chomp.STRIP;
44
- break;
45
-
46
- case '+':
47
- this.chomping = Chomp.KEEP;
48
- break;
49
-
50
- case '0':
51
- case '1':
52
- case '2':
53
- case '3':
54
- case '4':
55
- case '5':
56
- case '6':
57
- case '7':
58
- case '8':
59
- case '9':
60
- bi += ch;
61
- break;
62
-
63
- default:
64
- this.blockIndent = Number(bi) || null;
65
- this.header = new Range(start, offset);
66
- return offset;
67
- }
68
-
69
- offset += 1;
70
- }
71
- }
72
- }, {
73
- key: "parseBlockValue",
74
- value: function parseBlockValue(start) {
75
- var _this$context = this.context,
76
- indent = _this$context.indent,
77
- src = _this$context.src;
78
- var offset = start;
79
- var valueEnd = start;
80
- var bi = this.blockIndent ? indent + this.blockIndent - 1 : indent;
81
- var minBlockIndent = 1;
82
-
83
- for (var ch = src[offset]; ch === '\n'; ch = src[offset]) {
84
- offset += 1;
85
- if (Node.atDocumentBoundary(src, offset)) break;
86
- var end = Node.endOfBlockIndent(src, bi, offset); // should not include tab?
87
-
88
- if (end === null) break;
89
-
90
- if (!this.blockIndent) {
91
- // no explicit block indent, none yet detected
92
- var lineIndent = end - (offset + indent);
93
-
94
- if (src[end] !== '\n') {
95
- // first line with non-whitespace content
96
- if (lineIndent < minBlockIndent) {
97
- offset -= 1;
98
- break;
99
- }
100
-
101
- this.blockIndent = lineIndent;
102
- bi = indent + this.blockIndent - 1;
103
- } else if (lineIndent > minBlockIndent) {
104
- // empty line with more whitespace
105
- minBlockIndent = lineIndent;
106
- }
107
- }
108
-
109
- if (src[end] === '\n') {
110
- offset = end;
111
- } else {
112
- offset = valueEnd = Node.endOfLine(src, end);
113
- }
114
- }
115
-
116
- if (this.chomping !== Chomp.KEEP) {
117
- offset = src[valueEnd] ? valueEnd + 1 : valueEnd;
118
- }
119
-
120
- this.valueRange = new Range(start + 1, offset);
121
- return offset;
122
- }
123
- /**
124
- * Parses a block value from the source
125
- *
126
- * Accepted forms are:
127
- * ```
128
- * BS
129
- * block
130
- * lines
131
- *
132
- * BS #comment
133
- * block
134
- * lines
135
- * ```
136
- * where the block style BS matches the regexp `[|>][-+1-9]*` and block lines
137
- * are empty or have an indent level greater than `indent`.
138
- *
139
- * @param {ParseContext} context
140
- * @param {number} start - Index of first character
141
- * @returns {number} - Index of the character after this block
142
- */
143
-
144
- }, {
145
- key: "parse",
146
- value: function parse(context, start) {
147
- this.context = context;
148
- var src = context.src;
149
- var offset = this.parseBlockHeader(start);
150
- offset = Node.endOfWhiteSpace(src, offset);
151
- offset = this.parseComment(offset);
152
- offset = this.parseBlockValue(offset);
153
- return offset;
154
- }
155
- }, {
156
- key: "setOrigRanges",
157
- value: function setOrigRanges(cr, offset) {
158
- offset = _get(_getPrototypeOf(BlockValue.prototype), "setOrigRanges", this).call(this, cr, offset);
159
- return this.header ? this.header.setOrigRange(cr, offset) : offset;
160
- }
161
- }, {
162
- key: "includesTrailingLines",
163
- get: function get() {
164
- return this.chomping === Chomp.KEEP;
165
- }
166
- }, {
167
- key: "strValue",
168
- get: function get() {
169
- if (!this.valueRange || !this.context) return null;
170
- var _this$valueRange = this.valueRange,
171
- start = _this$valueRange.start,
172
- end = _this$valueRange.end;
173
- var _this$context2 = this.context,
174
- indent = _this$context2.indent,
175
- src = _this$context2.src;
176
- if (this.valueRange.isEmpty()) return '';
177
- var lastNewLine = null;
178
- var ch = src[end - 1];
179
-
180
- while (ch === '\n' || ch === '\t' || ch === ' ') {
181
- end -= 1;
182
-
183
- if (end <= start) {
184
- if (this.chomping === Chomp.KEEP) break;else return ''; // probably never happens
185
- }
186
-
187
- if (ch === '\n') lastNewLine = end;
188
- ch = src[end - 1];
189
- }
190
-
191
- var keepStart = end + 1;
192
-
193
- if (lastNewLine) {
194
- if (this.chomping === Chomp.KEEP) {
195
- keepStart = lastNewLine;
196
- end = this.valueRange.end;
197
- } else {
198
- end = lastNewLine;
199
- }
200
- }
201
-
202
- var bi = indent + this.blockIndent;
203
- var folded = this.type === Type.BLOCK_FOLDED;
204
- var atStart = true;
205
- var str = '';
206
- var sep = '';
207
- var prevMoreIndented = false;
208
-
209
- for (var i = start; i < end; ++i) {
210
- for (var j = 0; j < bi; ++j) {
211
- if (src[i] !== ' ') break;
212
- i += 1;
213
- }
214
-
215
- var _ch = src[i];
216
-
217
- if (_ch === '\n') {
218
- if (sep === '\n') str += '\n';else sep = '\n';
219
- } else {
220
- var lineEnd = Node.endOfLine(src, i);
221
- var line = src.slice(i, lineEnd);
222
- i = lineEnd;
223
-
224
- if (folded && (_ch === ' ' || _ch === '\t') && i < keepStart) {
225
- if (sep === ' ') sep = '\n';else if (!prevMoreIndented && !atStart && sep === '\n') sep = '\n\n';
226
- str += sep + line; //+ ((lineEnd < end && src[lineEnd]) || '')
227
-
228
- sep = lineEnd < end && src[lineEnd] || '';
229
- prevMoreIndented = true;
230
- } else {
231
- str += sep + line;
232
- sep = folded && i < keepStart ? ' ' : '\n';
233
- prevMoreIndented = false;
234
- }
235
-
236
- if (atStart && line !== '') atStart = false;
237
- }
238
- }
239
-
240
- return this.chomping === Chomp.STRIP ? str : str + '\n';
241
- }
242
- }]);
243
-
244
- return BlockValue;
245
- }(Node);
246
-
247
- export { BlockValue as default };
@@ -1,274 +0,0 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
3
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
4
- import _get from "@babel/runtime/helpers/get";
5
- import _createClass from "@babel/runtime/helpers/createClass";
6
- import _inherits from "@babel/runtime/helpers/inherits";
7
- import { Type } from '../constants';
8
- import BlankLine from './BlankLine';
9
- import CollectionItem from './CollectionItem';
10
- import Comment from './Comment';
11
- import Node from './Node';
12
- import Range from './Range';
13
- export function grabCollectionEndComments(node) {
14
- var cnode = node;
15
-
16
- while (cnode instanceof CollectionItem) {
17
- cnode = cnode.node;
18
- }
19
-
20
- if (!(cnode instanceof Collection)) return null;
21
- var len = cnode.items.length;
22
- var ci = -1;
23
-
24
- for (var i = len - 1; i >= 0; --i) {
25
- var n = cnode.items[i];
26
-
27
- if (n.type === Type.COMMENT) {
28
- // Keep sufficiently indented comments with preceding node
29
- var _n$context = n.context,
30
- indent = _n$context.indent,
31
- lineStart = _n$context.lineStart;
32
- if (indent > 0 && n.range.start >= lineStart + indent) break;
33
- ci = i;
34
- } else if (n.type === Type.BLANK_LINE) ci = i;else break;
35
- }
36
-
37
- if (ci === -1) return null;
38
- var ca = cnode.items.splice(ci, len - ci);
39
- var prevEnd = ca[0].range.start;
40
-
41
- while (true) {
42
- cnode.range.end = prevEnd;
43
- if (cnode.valueRange && cnode.valueRange.end > prevEnd) cnode.valueRange.end = prevEnd;
44
- if (cnode === node) break;
45
- cnode = cnode.context.parent;
46
- }
47
-
48
- return ca;
49
- }
50
-
51
- var Collection = /*#__PURE__*/function (_Node) {
52
- _inherits(Collection, _Node);
53
-
54
- _createClass(Collection, null, [{
55
- key: "nextContentHasIndent",
56
- value: function nextContentHasIndent(src, offset, indent) {
57
- var lineStart = Node.endOfLine(src, offset) + 1;
58
- offset = Node.endOfWhiteSpace(src, lineStart);
59
- var ch = src[offset];
60
- if (!ch) return false;
61
- if (offset >= lineStart + indent) return true;
62
- if (ch !== '#' && ch !== '\n') return false;
63
- return Collection.nextContentHasIndent(src, offset, indent);
64
- }
65
- }]);
66
-
67
- function Collection(firstItem) {
68
- var _this;
69
-
70
- _classCallCheck(this, Collection);
71
-
72
- _this = _possibleConstructorReturn(this, _getPrototypeOf(Collection).call(this, firstItem.type === Type.SEQ_ITEM ? Type.SEQ : Type.MAP));
73
-
74
- for (var i = firstItem.props.length - 1; i >= 0; --i) {
75
- if (firstItem.props[i].start < firstItem.context.lineStart) {
76
- // props on previous line are assumed by the collection
77
- _this.props = firstItem.props.slice(0, i + 1);
78
- firstItem.props = firstItem.props.slice(i + 1);
79
- var itemRange = firstItem.props[0] || firstItem.valueRange;
80
- firstItem.range.start = itemRange.start;
81
- break;
82
- }
83
- }
84
-
85
- _this.items = [firstItem];
86
- var ec = grabCollectionEndComments(firstItem);
87
- if (ec) Array.prototype.push.apply(_this.items, ec);
88
- return _this;
89
- }
90
-
91
- _createClass(Collection, [{
92
- key: "parse",
93
-
94
- /**
95
- * @param {ParseContext} context
96
- * @param {number} start - Index of first character
97
- * @returns {number} - Index of the character after this
98
- */
99
- value: function parse(context, start) {
100
- this.context = context;
101
- var parseNode = context.parseNode,
102
- src = context.src; // It's easier to recalculate lineStart here rather than tracking down the
103
- // last context from which to read it -- eemeli/yaml#2
104
-
105
- var lineStart = Node.startOfLine(src, start);
106
- var firstItem = this.items[0]; // First-item context needs to be correct for later comment handling
107
- // -- eemeli/yaml#17
108
-
109
- firstItem.context.parent = this;
110
- this.valueRange = Range.copy(firstItem.valueRange);
111
- var indent = firstItem.range.start - firstItem.context.lineStart;
112
- var offset = start;
113
- offset = Node.normalizeOffset(src, offset);
114
- var ch = src[offset];
115
- var atLineStart = Node.endOfWhiteSpace(src, lineStart) === offset;
116
- var prevIncludesTrailingLines = false;
117
-
118
- while (ch) {
119
- while (ch === '\n' || ch === '#') {
120
- if (atLineStart && ch === '\n' && !prevIncludesTrailingLines) {
121
- var blankLine = new BlankLine();
122
- offset = blankLine.parse({
123
- src: src
124
- }, offset);
125
- this.valueRange.end = offset;
126
-
127
- if (offset >= src.length) {
128
- ch = null;
129
- break;
130
- }
131
-
132
- this.items.push(blankLine);
133
- offset -= 1; // blankLine.parse() consumes terminal newline
134
- } else if (ch === '#') {
135
- if (offset < lineStart + indent && !Collection.nextContentHasIndent(src, offset, indent)) {
136
- return offset;
137
- }
138
-
139
- var comment = new Comment();
140
- offset = comment.parse({
141
- indent: indent,
142
- lineStart: lineStart,
143
- src: src
144
- }, offset);
145
- this.items.push(comment);
146
- this.valueRange.end = offset;
147
-
148
- if (offset >= src.length) {
149
- ch = null;
150
- break;
151
- }
152
- }
153
-
154
- lineStart = offset + 1;
155
- offset = Node.endOfIndent(src, lineStart);
156
-
157
- if (Node.atBlank(src, offset)) {
158
- var wsEnd = Node.endOfWhiteSpace(src, offset);
159
- var next = src[wsEnd];
160
-
161
- if (!next || next === '\n' || next === '#') {
162
- offset = wsEnd;
163
- }
164
- }
165
-
166
- ch = src[offset];
167
- atLineStart = true;
168
- }
169
-
170
- if (!ch) {
171
- break;
172
- }
173
-
174
- if (offset !== lineStart + indent && (atLineStart || ch !== ':')) {
175
- if (lineStart > start) offset = lineStart;
176
- break;
177
- }
178
-
179
- if (firstItem.type === Type.SEQ_ITEM !== (ch === '-')) {
180
- var typeswitch = true;
181
-
182
- if (ch === '-') {
183
- // map key may start with -, as long as it's followed by a non-whitespace char
184
- var _next = src[offset + 1];
185
- typeswitch = !_next || _next === '\n' || _next === '\t' || _next === ' ';
186
- }
187
-
188
- if (typeswitch) {
189
- if (lineStart > start) offset = lineStart;
190
- break;
191
- }
192
- }
193
-
194
- var node = parseNode({
195
- atLineStart: atLineStart,
196
- inCollection: true,
197
- indent: indent,
198
- lineStart: lineStart,
199
- parent: this
200
- }, offset);
201
- if (!node) return offset; // at next document start
202
-
203
- this.items.push(node);
204
- this.valueRange.end = node.valueRange.end;
205
- offset = Node.normalizeOffset(src, node.range.end);
206
- ch = src[offset];
207
- atLineStart = false;
208
- prevIncludesTrailingLines = node.includesTrailingLines; // Need to reset lineStart and atLineStart here if preceding node's range
209
- // has advanced to check the current line's indentation level
210
- // -- eemeli/yaml#10 & eemeli/yaml#38
211
-
212
- if (ch) {
213
- var ls = offset - 1;
214
- var prev = src[ls];
215
-
216
- while (prev === ' ' || prev === '\t') {
217
- prev = src[--ls];
218
- }
219
-
220
- if (prev === '\n') {
221
- lineStart = ls + 1;
222
- atLineStart = true;
223
- }
224
- }
225
-
226
- var ec = grabCollectionEndComments(node);
227
- if (ec) Array.prototype.push.apply(this.items, ec);
228
- }
229
-
230
- return offset;
231
- }
232
- }, {
233
- key: "setOrigRanges",
234
- value: function setOrigRanges(cr, offset) {
235
- offset = _get(_getPrototypeOf(Collection.prototype), "setOrigRanges", this).call(this, cr, offset);
236
- this.items.forEach(function (node) {
237
- offset = node.setOrigRanges(cr, offset);
238
- });
239
- return offset;
240
- }
241
- }, {
242
- key: "toString",
243
- value: function toString() {
244
- var src = this.context.src,
245
- items = this.items,
246
- range = this.range,
247
- value = this.value;
248
- if (value != null) return value;
249
- var str = src.slice(range.start, items[0].range.start) + String(items[0]);
250
-
251
- for (var i = 1; i < items.length; ++i) {
252
- var item = items[i];
253
- var _item$context = item.context,
254
- atLineStart = _item$context.atLineStart,
255
- indent = _item$context.indent;
256
- if (atLineStart) for (var _i = 0; _i < indent; ++_i) {
257
- str += ' ';
258
- }
259
- str += String(item);
260
- }
261
-
262
- return Node.addStringTerminator(src, range.end, str);
263
- }
264
- }, {
265
- key: "includesTrailingLines",
266
- get: function get() {
267
- return this.items.length > 0;
268
- }
269
- }]);
270
-
271
- return Collection;
272
- }(Node);
273
-
274
- export { Collection as default };