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,343 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = parseMap;
7
-
8
- var _constants = require("../constants");
9
-
10
- var _PlainValue = _interopRequireDefault(require("../cst/PlainValue"));
11
-
12
- var _errors = require("../errors");
13
-
14
- var _Map = _interopRequireDefault(require("./Map"));
15
-
16
- var _Merge = _interopRequireWildcard(require("./Merge"));
17
-
18
- var _Pair = _interopRequireDefault(require("./Pair"));
19
-
20
- var _parseUtils = require("./parseUtils");
21
-
22
- var _Alias = _interopRequireDefault(require("./Alias"));
23
-
24
- var _Collection = _interopRequireDefault(require("./Collection"));
25
-
26
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
27
-
28
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
29
-
30
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
-
32
- function parseMap(doc, cst) {
33
- if (cst.type !== _constants.Type.MAP && cst.type !== _constants.Type.FLOW_MAP) {
34
- const msg = `A ${cst.type} node cannot be resolved as a mapping`;
35
- doc.errors.push(new _errors.YAMLSyntaxError(cst, msg));
36
- return null;
37
- }
38
-
39
- const {
40
- comments,
41
- items
42
- } = cst.type === _constants.Type.FLOW_MAP ? resolveFlowMapItems(doc, cst) : resolveBlockMapItems(doc, cst);
43
- const map = new _Map.default();
44
- map.items = items;
45
- (0, _parseUtils.resolveComments)(map, comments);
46
- let hasCollectionKey = false;
47
-
48
- for (let i = 0; i < items.length; ++i) {
49
- const {
50
- key: iKey
51
- } = items[i];
52
- if (iKey instanceof _Collection.default) hasCollectionKey = true;
53
-
54
- if (doc.schema.merge && iKey && iKey.value === _Merge.MERGE_KEY) {
55
- items[i] = new _Merge.default(items[i]);
56
- const sources = items[i].value.items;
57
- let error = null;
58
- sources.some(node => {
59
- if (node instanceof _Alias.default) {
60
- // During parsing, alias sources are CST nodes; to account for
61
- // circular references their resolved values can't be used here.
62
- const {
63
- type
64
- } = node.source;
65
- if (type === _constants.Type.MAP || type === _constants.Type.FLOW_MAP) return false;
66
- return error = 'Merge nodes aliases can only point to maps';
67
- }
68
-
69
- return error = 'Merge nodes can only have Alias nodes as values';
70
- });
71
- if (error) doc.errors.push(new _errors.YAMLSemanticError(cst, error));
72
- } else {
73
- for (let j = i + 1; j < items.length; ++j) {
74
- const {
75
- key: jKey
76
- } = items[j];
77
-
78
- if (iKey === jKey || iKey && jKey && Object.prototype.hasOwnProperty.call(iKey, 'value') && iKey.value === jKey.value) {
79
- const msg = `Map keys must be unique; "${iKey}" is repeated`;
80
- doc.errors.push(new _errors.YAMLSemanticError(cst, msg));
81
- break;
82
- }
83
- }
84
- }
85
- }
86
-
87
- if (hasCollectionKey && !doc.options.mapAsMap) {
88
- const warn = 'Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.';
89
- doc.warnings.push(new _errors.YAMLWarning(cst, warn));
90
- }
91
-
92
- cst.resolved = map;
93
- return map;
94
- }
95
-
96
- const valueHasPairComment = ({
97
- context: {
98
- lineStart,
99
- node,
100
- src
101
- },
102
- props
103
- }) => {
104
- if (props.length === 0) return false;
105
- const {
106
- start
107
- } = props[0];
108
- if (node && start > node.valueRange.start) return false;
109
- if (src[start] !== _constants.Char.COMMENT) return false;
110
-
111
- for (let i = lineStart; i < start; ++i) if (src[i] === '\n') return false;
112
-
113
- return true;
114
- };
115
-
116
- function resolvePairComment(item, pair) {
117
- if (!valueHasPairComment(item)) return;
118
- const comment = item.getPropValue(0, _constants.Char.COMMENT, true);
119
- let found = false;
120
- const cb = pair.value.commentBefore;
121
-
122
- if (cb && cb.startsWith(comment)) {
123
- pair.value.commentBefore = cb.substr(comment.length + 1);
124
- found = true;
125
- } else {
126
- const cc = pair.value.comment;
127
-
128
- if (!item.node && cc && cc.startsWith(comment)) {
129
- pair.value.comment = cc.substr(comment.length + 1);
130
- found = true;
131
- }
132
- }
133
-
134
- if (found) pair.comment = comment;
135
- }
136
-
137
- function resolveBlockMapItems(doc, cst) {
138
- const comments = [];
139
- const items = [];
140
- let key = undefined;
141
- let keyStart = null;
142
-
143
- for (let i = 0; i < cst.items.length; ++i) {
144
- const item = cst.items[i];
145
-
146
- switch (item.type) {
147
- case _constants.Type.BLANK_LINE:
148
- comments.push({
149
- afterKey: !!key,
150
- before: items.length
151
- });
152
- break;
153
-
154
- case _constants.Type.COMMENT:
155
- comments.push({
156
- afterKey: !!key,
157
- before: items.length,
158
- comment: item.comment
159
- });
160
- break;
161
-
162
- case _constants.Type.MAP_KEY:
163
- if (key !== undefined) items.push(new _Pair.default(key));
164
- if (item.error) doc.errors.push(item.error);
165
- key = doc.resolveNode(item.node);
166
- keyStart = null;
167
- break;
168
-
169
- case _constants.Type.MAP_VALUE:
170
- {
171
- if (key === undefined) key = null;
172
- if (item.error) doc.errors.push(item.error);
173
-
174
- if (!item.context.atLineStart && item.node && item.node.type === _constants.Type.MAP && !item.node.context.atLineStart) {
175
- const msg = 'Nested mappings are not allowed in compact mappings';
176
- doc.errors.push(new _errors.YAMLSemanticError(item.node, msg));
177
- }
178
-
179
- let valueNode = item.node;
180
-
181
- if (!valueNode && item.props.length > 0) {
182
- // Comments on an empty mapping value need to be preserved, so we
183
- // need to construct a minimal empty node here to use instead of the
184
- // missing `item.node`. -- eemeli/yaml#19
185
- valueNode = new _PlainValue.default(_constants.Type.PLAIN, []);
186
- valueNode.context = {
187
- parent: item,
188
- src: item.context.src
189
- };
190
- const pos = item.range.start + 1;
191
- valueNode.range = {
192
- start: pos,
193
- end: pos
194
- };
195
- valueNode.valueRange = {
196
- start: pos,
197
- end: pos
198
- };
199
-
200
- if (typeof item.range.origStart === 'number') {
201
- const origPos = item.range.origStart + 1;
202
- valueNode.range.origStart = valueNode.range.origEnd = origPos;
203
- valueNode.valueRange.origStart = valueNode.valueRange.origEnd = origPos;
204
- }
205
- }
206
-
207
- const pair = new _Pair.default(key, doc.resolveNode(valueNode));
208
- resolvePairComment(item, pair);
209
- items.push(pair);
210
- (0, _parseUtils.checkKeyLength)(doc.errors, cst, i, key, keyStart);
211
- key = undefined;
212
- keyStart = null;
213
- }
214
- break;
215
-
216
- default:
217
- if (key !== undefined) items.push(new _Pair.default(key));
218
- key = doc.resolveNode(item);
219
- keyStart = item.range.start;
220
- if (item.error) doc.errors.push(item.error);
221
-
222
- next: for (let j = i + 1;; ++j) {
223
- const nextItem = cst.items[j];
224
-
225
- switch (nextItem && nextItem.type) {
226
- case _constants.Type.BLANK_LINE:
227
- case _constants.Type.COMMENT:
228
- continue next;
229
-
230
- case _constants.Type.MAP_VALUE:
231
- break next;
232
-
233
- default:
234
- doc.errors.push(new _errors.YAMLSemanticError(item, 'Implicit map keys need to be followed by map values'));
235
- break next;
236
- }
237
- }
238
-
239
- if (item.valueRangeContainsNewline) {
240
- const msg = 'Implicit map keys need to be on a single line';
241
- doc.errors.push(new _errors.YAMLSemanticError(item, msg));
242
- }
243
-
244
- }
245
- }
246
-
247
- if (key !== undefined) items.push(new _Pair.default(key));
248
- return {
249
- comments,
250
- items
251
- };
252
- }
253
-
254
- function resolveFlowMapItems(doc, cst) {
255
- const comments = [];
256
- const items = [];
257
- let key = undefined;
258
- let keyStart = null;
259
- let explicitKey = false;
260
- let next = '{';
261
-
262
- for (let i = 0; i < cst.items.length; ++i) {
263
- (0, _parseUtils.checkKeyLength)(doc.errors, cst, i, key, keyStart);
264
- const item = cst.items[i];
265
-
266
- if (typeof item.char === 'string') {
267
- const {
268
- char,
269
- offset
270
- } = item;
271
-
272
- if (char === '?' && key === undefined && !explicitKey) {
273
- explicitKey = true;
274
- next = ':';
275
- continue;
276
- }
277
-
278
- if (char === ':') {
279
- if (key === undefined) key = null;
280
-
281
- if (next === ':') {
282
- next = ',';
283
- continue;
284
- }
285
- } else {
286
- if (explicitKey) {
287
- if (key === undefined && char !== ',') key = null;
288
- explicitKey = false;
289
- }
290
-
291
- if (key !== undefined) {
292
- items.push(new _Pair.default(key));
293
- key = undefined;
294
- keyStart = null;
295
-
296
- if (char === ',') {
297
- next = ':';
298
- continue;
299
- }
300
- }
301
- }
302
-
303
- if (char === '}') {
304
- if (i === cst.items.length - 1) continue;
305
- } else if (char === next) {
306
- next = ':';
307
- continue;
308
- }
309
-
310
- const msg = `Flow map contains an unexpected ${char}`;
311
- const err = new _errors.YAMLSyntaxError(cst, msg);
312
- err.offset = offset;
313
- doc.errors.push(err);
314
- } else if (item.type === _constants.Type.BLANK_LINE) {
315
- comments.push({
316
- afterKey: !!key,
317
- before: items.length
318
- });
319
- } else if (item.type === _constants.Type.COMMENT) {
320
- comments.push({
321
- afterKey: !!key,
322
- before: items.length,
323
- comment: item.comment
324
- });
325
- } else if (key === undefined) {
326
- if (next === ',') doc.errors.push(new _errors.YAMLSemanticError(item, 'Separator , missing in flow map'));
327
- key = doc.resolveNode(item);
328
- keyStart = explicitKey ? null : item.range.start; // TODO: add error for non-explicit multiline plain key
329
- } else {
330
- if (next !== ',') doc.errors.push(new _errors.YAMLSemanticError(item, 'Indicator : missing in flow map entry'));
331
- items.push(new _Pair.default(key, doc.resolveNode(item)));
332
- key = undefined;
333
- explicitKey = false;
334
- }
335
- }
336
-
337
- (0, _parseUtils.checkFlowCollectionEnd)(doc.errors, cst);
338
- if (key !== undefined) items.push(new _Pair.default(key));
339
- return {
340
- comments,
341
- items
342
- };
343
- }
@@ -1,180 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = parseSeq;
7
-
8
- var _constants = require("../constants");
9
-
10
- var _errors = require("../errors");
11
-
12
- var _Pair = _interopRequireDefault(require("./Pair"));
13
-
14
- var _parseUtils = require("./parseUtils");
15
-
16
- var _Seq = _interopRequireDefault(require("./Seq"));
17
-
18
- var _Collection = _interopRequireDefault(require("./Collection"));
19
-
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
22
- function parseSeq(doc, cst) {
23
- if (cst.type !== _constants.Type.SEQ && cst.type !== _constants.Type.FLOW_SEQ) {
24
- const msg = `A ${cst.type} node cannot be resolved as a sequence`;
25
- doc.errors.push(new _errors.YAMLSyntaxError(cst, msg));
26
- return null;
27
- }
28
-
29
- const {
30
- comments,
31
- items
32
- } = cst.type === _constants.Type.FLOW_SEQ ? resolveFlowSeqItems(doc, cst) : resolveBlockSeqItems(doc, cst);
33
- const seq = new _Seq.default();
34
- seq.items = items;
35
- (0, _parseUtils.resolveComments)(seq, comments);
36
-
37
- if (!doc.options.mapAsMap && items.some(it => it instanceof _Pair.default && it.key instanceof _Collection.default)) {
38
- const warn = 'Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.';
39
- doc.warnings.push(new _errors.YAMLWarning(cst, warn));
40
- }
41
-
42
- cst.resolved = seq;
43
- return seq;
44
- }
45
-
46
- function resolveBlockSeqItems(doc, cst) {
47
- const comments = [];
48
- const items = [];
49
-
50
- for (let i = 0; i < cst.items.length; ++i) {
51
- const item = cst.items[i];
52
-
53
- switch (item.type) {
54
- case _constants.Type.BLANK_LINE:
55
- comments.push({
56
- before: items.length
57
- });
58
- break;
59
-
60
- case _constants.Type.COMMENT:
61
- comments.push({
62
- comment: item.comment,
63
- before: items.length
64
- });
65
- break;
66
-
67
- case _constants.Type.SEQ_ITEM:
68
- if (item.error) doc.errors.push(item.error);
69
- items.push(doc.resolveNode(item.node));
70
-
71
- if (item.hasProps) {
72
- const msg = 'Sequence items cannot have tags or anchors before the - indicator';
73
- doc.errors.push(new _errors.YAMLSemanticError(item, msg));
74
- }
75
-
76
- break;
77
-
78
- default:
79
- if (item.error) doc.errors.push(item.error);
80
- doc.errors.push(new _errors.YAMLSyntaxError(item, `Unexpected ${item.type} node in sequence`));
81
- }
82
- }
83
-
84
- return {
85
- comments,
86
- items
87
- };
88
- }
89
-
90
- function resolveFlowSeqItems(doc, cst) {
91
- const comments = [];
92
- const items = [];
93
- let explicitKey = false;
94
- let key = undefined;
95
- let keyStart = null;
96
- let next = '[';
97
-
98
- for (let i = 0; i < cst.items.length; ++i) {
99
- const item = cst.items[i];
100
-
101
- if (typeof item.char === 'string') {
102
- const {
103
- char,
104
- offset
105
- } = item;
106
-
107
- if (char !== ':' && (explicitKey || key !== undefined)) {
108
- if (explicitKey && key === undefined) key = next ? items.pop() : null;
109
- items.push(new _Pair.default(key));
110
- explicitKey = false;
111
- key = undefined;
112
- keyStart = null;
113
- }
114
-
115
- if (char === next) {
116
- next = null;
117
- } else if (!next && char === '?') {
118
- explicitKey = true;
119
- } else if (next !== '[' && char === ':' && key === undefined) {
120
- if (next === ',') {
121
- key = items.pop();
122
-
123
- if (key instanceof _Pair.default) {
124
- const msg = 'Chaining flow sequence pairs is invalid';
125
- const err = new _errors.YAMLSemanticError(cst, msg);
126
- err.offset = offset;
127
- doc.errors.push(err);
128
- }
129
-
130
- if (!explicitKey) (0, _parseUtils.checkKeyLength)(doc.errors, cst, i, key, keyStart);
131
- } else {
132
- key = null;
133
- }
134
-
135
- keyStart = null;
136
- explicitKey = false; // TODO: add error for non-explicit multiline plain key
137
-
138
- next = null;
139
- } else if (next === '[' || char !== ']' || i < cst.items.length - 1) {
140
- const msg = `Flow sequence contains an unexpected ${char}`;
141
- const err = new _errors.YAMLSyntaxError(cst, msg);
142
- err.offset = offset;
143
- doc.errors.push(err);
144
- }
145
- } else if (item.type === _constants.Type.BLANK_LINE) {
146
- comments.push({
147
- before: items.length
148
- });
149
- } else if (item.type === _constants.Type.COMMENT) {
150
- comments.push({
151
- comment: item.comment,
152
- before: items.length
153
- });
154
- } else {
155
- if (next) {
156
- const msg = `Expected a ${next} in flow sequence`;
157
- doc.errors.push(new _errors.YAMLSemanticError(item, msg));
158
- }
159
-
160
- const value = doc.resolveNode(item);
161
-
162
- if (key === undefined) {
163
- items.push(value);
164
- } else {
165
- items.push(new _Pair.default(key, value));
166
- key = undefined;
167
- }
168
-
169
- keyStart = item.range.start;
170
- next = ',';
171
- }
172
- }
173
-
174
- (0, _parseUtils.checkFlowCollectionEnd)(doc.errors, cst);
175
- if (key !== undefined) items.push(new _Pair.default(key));
176
- return {
177
- comments,
178
- items
179
- };
180
- }
@@ -1,104 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.checkFlowCollectionEnd = checkFlowCollectionEnd;
7
- exports.checkKeyLength = checkKeyLength;
8
- exports.resolveComments = resolveComments;
9
-
10
- var _errors = require("../errors");
11
-
12
- var _constants = require("../constants");
13
-
14
- function checkFlowCollectionEnd(errors, cst) {
15
- let char, name;
16
-
17
- switch (cst.type) {
18
- case _constants.Type.FLOW_MAP:
19
- char = '}';
20
- name = 'flow map';
21
- break;
22
-
23
- case _constants.Type.FLOW_SEQ:
24
- char = ']';
25
- name = 'flow sequence';
26
- break;
27
-
28
- default:
29
- errors.push(new _errors.YAMLSemanticError(cst, 'Not a flow collection!?'));
30
- return;
31
- }
32
-
33
- let lastItem;
34
-
35
- for (let i = cst.items.length - 1; i >= 0; --i) {
36
- const item = cst.items[i];
37
-
38
- if (!item || item.type !== _constants.Type.COMMENT) {
39
- lastItem = item;
40
- break;
41
- }
42
- }
43
-
44
- if (lastItem && lastItem.char !== char) {
45
- const msg = `Expected ${name} to end with ${char}`;
46
- let err;
47
-
48
- if (typeof lastItem.offset === 'number') {
49
- err = new _errors.YAMLSemanticError(cst, msg);
50
- err.offset = lastItem.offset + 1;
51
- } else {
52
- err = new _errors.YAMLSemanticError(lastItem, msg);
53
- if (lastItem.range && lastItem.range.end) err.offset = lastItem.range.end - lastItem.range.start;
54
- }
55
-
56
- errors.push(err);
57
- }
58
- }
59
-
60
- function checkKeyLength(errors, node, itemIdx, key, keyStart) {
61
- if (!key || typeof keyStart !== 'number') return;
62
- const item = node.items[itemIdx];
63
- let keyEnd = item && item.range && item.range.start;
64
-
65
- if (!keyEnd) {
66
- for (let i = itemIdx - 1; i >= 0; --i) {
67
- const it = node.items[i];
68
-
69
- if (it && it.range) {
70
- keyEnd = it.range.end + 2 * (itemIdx - i);
71
- break;
72
- }
73
- }
74
- }
75
-
76
- if (keyEnd > keyStart + 1024) {
77
- const k = String(key).substr(0, 8) + '...' + String(key).substr(-8);
78
- errors.push(new _errors.YAMLSemanticError(node, `The "${k}" key is too long`));
79
- }
80
- }
81
-
82
- function resolveComments(collection, comments) {
83
- for (const {
84
- afterKey,
85
- before,
86
- comment
87
- } of comments) {
88
- let item = collection.items[before];
89
-
90
- if (!item) {
91
- if (comment !== undefined) {
92
- if (collection.comment) collection.comment += '\n' + comment;else collection.comment = comment;
93
- }
94
- } else {
95
- if (afterKey && item.value) item = item.value;
96
-
97
- if (comment === undefined) {
98
- if (afterKey || !item.commentBefore) item.spaceBefore = true;
99
- } else {
100
- if (item.commentBefore) item.commentBefore += '\n' + comment;else item.commentBefore = comment;
101
- }
102
- }
103
- }
104
- }