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,382 +0,0 @@
1
- import _typeof from "@babel/runtime/helpers/typeof";
2
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
- import _createClass from "@babel/runtime/helpers/createClass";
4
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
5
- import { warnOptionDeprecation } from '../warnings';
6
- import { Type } from '../constants';
7
- import { YAMLReferenceError, YAMLWarning } from '../errors';
8
- import { stringifyString } from '../stringify';
9
- import { schemas, tags } from '../tags';
10
- import { resolveString } from '../tags/failsafe/string';
11
- import Alias from './Alias';
12
- import Collection from './Collection';
13
- import Node from './Node';
14
- import Pair from './Pair';
15
- import Scalar from './Scalar';
16
-
17
- var isMap = function isMap(_ref) {
18
- var type = _ref.type;
19
- return type === Type.FLOW_MAP || type === Type.MAP;
20
- };
21
-
22
- var isSeq = function isSeq(_ref2) {
23
- var type = _ref2.type;
24
- return type === Type.FLOW_SEQ || type === Type.SEQ;
25
- };
26
-
27
- var Schema = /*#__PURE__*/function () {
28
- function Schema(_ref3) {
29
- var customTags = _ref3.customTags,
30
- merge = _ref3.merge,
31
- schema = _ref3.schema,
32
- sortMapEntries = _ref3.sortMapEntries,
33
- deprecatedCustomTags = _ref3.tags;
34
-
35
- _classCallCheck(this, Schema);
36
-
37
- this.merge = !!merge;
38
- this.name = schema;
39
- this.sortMapEntries = sortMapEntries === true ? function (a, b) {
40
- return a.key < b.key ? -1 : a.key > b.key ? 1 : 0;
41
- } : sortMapEntries || null;
42
- this.tags = schemas[schema.replace(/\W/g, '')]; // 'yaml-1.1' -> 'yaml11'
43
-
44
- if (!this.tags) {
45
- var keys = Object.keys(schemas).map(function (key) {
46
- return JSON.stringify(key);
47
- }).join(', ');
48
- throw new Error("Unknown schema \"".concat(schema, "\"; use one of ").concat(keys));
49
- }
50
-
51
- if (!customTags && deprecatedCustomTags) {
52
- customTags = deprecatedCustomTags;
53
- warnOptionDeprecation('tags', 'customTags');
54
- }
55
-
56
- if (Array.isArray(customTags)) {
57
- var _iteratorNormalCompletion = true;
58
- var _didIteratorError = false;
59
- var _iteratorError = undefined;
60
-
61
- try {
62
- for (var _iterator = customTags[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
63
- var tag = _step.value;
64
- this.tags = this.tags.concat(tag);
65
- }
66
- } catch (err) {
67
- _didIteratorError = true;
68
- _iteratorError = err;
69
- } finally {
70
- try {
71
- if (!_iteratorNormalCompletion && _iterator.return != null) {
72
- _iterator.return();
73
- }
74
- } finally {
75
- if (_didIteratorError) {
76
- throw _iteratorError;
77
- }
78
- }
79
- }
80
- } else if (typeof customTags === 'function') {
81
- this.tags = customTags(this.tags.slice());
82
- }
83
-
84
- for (var i = 0; i < this.tags.length; ++i) {
85
- var _tag = this.tags[i];
86
-
87
- if (typeof _tag === 'string') {
88
- var tagObj = tags[_tag];
89
-
90
- if (!tagObj) {
91
- var _keys = Object.keys(tags).map(function (key) {
92
- return JSON.stringify(key);
93
- }).join(', ');
94
-
95
- throw new Error("Unknown custom tag \"".concat(_tag, "\"; use one of ").concat(_keys));
96
- }
97
-
98
- this.tags[i] = tagObj;
99
- }
100
- }
101
- }
102
-
103
- _createClass(Schema, [{
104
- key: "createNode",
105
- value: function createNode(value, wrapScalars, tag, ctx) {
106
- if (value instanceof Node) return value;
107
- var tagObj;
108
-
109
- if (tag) {
110
- if (tag.startsWith('!!')) tag = Schema.defaultPrefix + tag.slice(2);
111
- var match = this.tags.filter(function (t) {
112
- return t.tag === tag;
113
- });
114
- tagObj = match.find(function (t) {
115
- return !t.format;
116
- }) || match[0];
117
- if (!tagObj) throw new Error("Tag ".concat(tag, " not found"));
118
- } else {
119
- // TODO: deprecate/remove class check
120
- tagObj = this.tags.find(function (t) {
121
- return (t.identify && t.identify(value) || t.class && value instanceof t.class) && !t.format;
122
- });
123
-
124
- if (!tagObj) {
125
- if (typeof value.toJSON === 'function') value = value.toJSON();
126
- if (_typeof(value) !== 'object') return wrapScalars ? new Scalar(value) : value;
127
- tagObj = value instanceof Map ? tags.map : value[Symbol.iterator] ? tags.seq : tags.map;
128
- }
129
- }
130
-
131
- if (!ctx) ctx = {
132
- wrapScalars: wrapScalars
133
- };else ctx.wrapScalars = wrapScalars;
134
-
135
- if (ctx.onTagObj) {
136
- ctx.onTagObj(tagObj);
137
- delete ctx.onTagObj;
138
- }
139
-
140
- var obj = {};
141
-
142
- if (value && _typeof(value) === 'object' && ctx.prevObjects) {
143
- var prev = ctx.prevObjects.get(value);
144
-
145
- if (prev) {
146
- var alias = new Alias(prev); // leaves source dirty; must be cleaned by caller
147
-
148
- ctx.aliasNodes.push(alias);
149
- return alias;
150
- }
151
-
152
- obj.value = value;
153
- ctx.prevObjects.set(value, obj);
154
- }
155
-
156
- obj.node = tagObj.createNode ? tagObj.createNode(this, value, ctx) : wrapScalars ? new Scalar(value) : value;
157
- if (tag && obj.node instanceof Node) obj.node.tag = tag;
158
- return obj.node;
159
- }
160
- }, {
161
- key: "createPair",
162
- value: function createPair(key, value, ctx) {
163
- var k = this.createNode(key, ctx.wrapScalars, null, ctx);
164
- var v = this.createNode(value, ctx.wrapScalars, null, ctx);
165
- return new Pair(k, v);
166
- } // falls back to string on no match
167
-
168
- }, {
169
- key: "resolveScalar",
170
- value: function resolveScalar(str, tags) {
171
- if (!tags) tags = this.tags;
172
-
173
- for (var i = 0; i < tags.length; ++i) {
174
- var _tags$i = tags[i],
175
- format = _tags$i.format,
176
- test = _tags$i.test,
177
- resolve = _tags$i.resolve;
178
-
179
- if (test) {
180
- var match = str.match(test);
181
-
182
- if (match) {
183
- var res = resolve.apply(null, match);
184
- if (!(res instanceof Scalar)) res = new Scalar(res);
185
- if (format) res.format = format;
186
- return res;
187
- }
188
- }
189
- }
190
-
191
- if (this.tags.scalarFallback) str = this.tags.scalarFallback(str);
192
- return new Scalar(str);
193
- } // sets node.resolved on success
194
-
195
- }, {
196
- key: "resolveNode",
197
- value: function resolveNode(doc, node, tagName) {
198
- var tags = this.tags.filter(function (_ref4) {
199
- var tag = _ref4.tag;
200
- return tag === tagName;
201
- });
202
- var generic = tags.find(function (_ref5) {
203
- var test = _ref5.test;
204
- return !test;
205
- });
206
- if (node.error) doc.errors.push(node.error);
207
-
208
- try {
209
- if (generic) {
210
- var res = generic.resolve(doc, node);
211
- if (!(res instanceof Collection)) res = new Scalar(res);
212
- node.resolved = res;
213
- } else {
214
- var str = resolveString(doc, node);
215
-
216
- if (typeof str === 'string' && tags.length > 0) {
217
- node.resolved = this.resolveScalar(str, tags);
218
- }
219
- }
220
- } catch (error) {
221
- /* istanbul ignore if */
222
- if (!error.source) error.source = node;
223
- doc.errors.push(error);
224
- node.resolved = null;
225
- }
226
-
227
- if (!node.resolved) return null;
228
- if (tagName && node.tag) node.resolved.tag = tagName;
229
- return node.resolved;
230
- }
231
- }, {
232
- key: "resolveNodeWithFallback",
233
- value: function resolveNodeWithFallback(doc, node, tagName) {
234
- var res = this.resolveNode(doc, node, tagName);
235
- if (Object.prototype.hasOwnProperty.call(node, 'resolved')) return res;
236
- var fallback = isMap(node) ? Schema.defaultTags.MAP : isSeq(node) ? Schema.defaultTags.SEQ : Schema.defaultTags.STR;
237
- /* istanbul ignore else */
238
-
239
- if (fallback) {
240
- doc.warnings.push(new YAMLWarning(node, "The tag ".concat(tagName, " is unavailable, falling back to ").concat(fallback)));
241
-
242
- var _res = this.resolveNode(doc, node, fallback);
243
-
244
- _res.tag = tagName;
245
- return _res;
246
- } else {
247
- doc.errors.push(new YAMLReferenceError(node, "The tag ".concat(tagName, " is unavailable")));
248
- return null;
249
- }
250
- }
251
- }, {
252
- key: "getTagObject",
253
- value: function getTagObject(item) {
254
- if (item instanceof Alias) return Alias;
255
-
256
- if (item.tag) {
257
- var match = this.tags.filter(function (t) {
258
- return t.tag === item.tag;
259
- });
260
- if (match.length > 0) return match.find(function (t) {
261
- return t.format === item.format;
262
- }) || match[0];
263
- }
264
-
265
- var tagObj, obj;
266
-
267
- if (item instanceof Scalar) {
268
- obj = item.value; // TODO: deprecate/remove class check
269
-
270
- var _match = this.tags.filter(function (t) {
271
- return t.identify && t.identify(obj) || t.class && obj instanceof t.class;
272
- });
273
-
274
- tagObj = _match.find(function (t) {
275
- return t.format === item.format;
276
- }) || _match.find(function (t) {
277
- return !t.format;
278
- });
279
- } else {
280
- obj = item;
281
- tagObj = this.tags.find(function (t) {
282
- return t.nodeClass && obj instanceof t.nodeClass;
283
- });
284
- }
285
-
286
- if (!tagObj) {
287
- var name = obj && obj.constructor ? obj.constructor.name : _typeof(obj);
288
- throw new Error("Tag not resolved for ".concat(name, " value"));
289
- }
290
-
291
- return tagObj;
292
- } // needs to be called before stringifier to allow for circular anchor refs
293
-
294
- }, {
295
- key: "stringifyProps",
296
- value: function stringifyProps(node, tagObj, _ref6) {
297
- var anchors = _ref6.anchors,
298
- doc = _ref6.doc;
299
- var props = [];
300
- var anchor = doc.anchors.getName(node);
301
-
302
- if (anchor) {
303
- anchors[anchor] = node;
304
- props.push("&".concat(anchor));
305
- }
306
-
307
- if (node.tag) {
308
- props.push(doc.stringifyTag(node.tag));
309
- } else if (!tagObj.default) {
310
- props.push(doc.stringifyTag(tagObj.tag));
311
- }
312
-
313
- return props.join(' ');
314
- }
315
- }, {
316
- key: "stringify",
317
- value: function stringify(item, ctx, onComment, onChompKeep) {
318
- var tagObj;
319
-
320
- if (!(item instanceof Node)) {
321
- var createCtx = {
322
- aliasNodes: [],
323
- onTagObj: function onTagObj(o) {
324
- return tagObj = o;
325
- },
326
- prevObjects: new Map()
327
- };
328
- item = this.createNode(item, true, null, createCtx);
329
- var anchors = ctx.doc.anchors;
330
- var _iteratorNormalCompletion2 = true;
331
- var _didIteratorError2 = false;
332
- var _iteratorError2 = undefined;
333
-
334
- try {
335
- for (var _iterator2 = createCtx.aliasNodes[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
336
- var alias = _step2.value;
337
- alias.source = alias.source.node;
338
- var name = anchors.getName(alias.source);
339
-
340
- if (!name) {
341
- name = anchors.newName();
342
- anchors.map[name] = alias.source;
343
- }
344
- }
345
- } catch (err) {
346
- _didIteratorError2 = true;
347
- _iteratorError2 = err;
348
- } finally {
349
- try {
350
- if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
351
- _iterator2.return();
352
- }
353
- } finally {
354
- if (_didIteratorError2) {
355
- throw _iteratorError2;
356
- }
357
- }
358
- }
359
- }
360
-
361
- ctx.tags = this;
362
- if (item instanceof Pair) return item.toString(ctx, onComment, onChompKeep);
363
- if (!tagObj) tagObj = this.getTagObject(item);
364
- var props = this.stringifyProps(item, tagObj, ctx);
365
- if (props.length > 0) ctx.indentAtStart = (ctx.indentAtStart || 0) + props.length + 1;
366
- var str = typeof tagObj.stringify === 'function' ? tagObj.stringify(item, ctx, onComment, onChompKeep) : item instanceof Collection ? item.toString(ctx, onComment, onChompKeep) : stringifyString(item, ctx, onComment, onChompKeep);
367
- return props ? item instanceof Collection && str[0] !== '{' && str[0] !== '[' ? "".concat(props, "\n").concat(ctx.indent).concat(str) : "".concat(props, " ").concat(str) : str;
368
- }
369
- }]);
370
-
371
- return Schema;
372
- }();
373
-
374
- _defineProperty(Schema, "defaultPrefix", 'tag:yaml.org,2002:');
375
-
376
- _defineProperty(Schema, "defaultTags", {
377
- MAP: 'tag:yaml.org,2002:map',
378
- SEQ: 'tag:yaml.org,2002:seq',
379
- STR: 'tag:yaml.org,2002:str'
380
- });
381
-
382
- export { Schema as default };
@@ -1,312 +0,0 @@
1
- import { Char, Type } from '../constants';
2
- import PlainValue from '../cst/PlainValue';
3
- import { YAMLSemanticError, YAMLSyntaxError, YAMLWarning } from '../errors';
4
- import Map from './Map';
5
- import Merge, { MERGE_KEY } from './Merge';
6
- import Pair from './Pair';
7
- import { checkFlowCollectionEnd, checkKeyLength, resolveComments } from './parseUtils';
8
- import Alias from './Alias';
9
- import Collection from './Collection';
10
- export default function parseMap(doc, cst) {
11
- if (cst.type !== Type.MAP && cst.type !== Type.FLOW_MAP) {
12
- var msg = "A ".concat(cst.type, " node cannot be resolved as a mapping");
13
- doc.errors.push(new YAMLSyntaxError(cst, msg));
14
- return null;
15
- }
16
-
17
- var _ref = cst.type === Type.FLOW_MAP ? resolveFlowMapItems(doc, cst) : resolveBlockMapItems(doc, cst),
18
- comments = _ref.comments,
19
- items = _ref.items;
20
-
21
- var map = new Map();
22
- map.items = items;
23
- resolveComments(map, comments);
24
- var hasCollectionKey = false;
25
-
26
- for (var i = 0; i < items.length; ++i) {
27
- var iKey = items[i].key;
28
- if (iKey instanceof Collection) hasCollectionKey = true;
29
-
30
- if (doc.schema.merge && iKey && iKey.value === MERGE_KEY) {
31
- items[i] = new Merge(items[i]);
32
- var sources = items[i].value.items;
33
- var error = null;
34
- sources.some(function (node) {
35
- if (node instanceof Alias) {
36
- // During parsing, alias sources are CST nodes; to account for
37
- // circular references their resolved values can't be used here.
38
- var type = node.source.type;
39
- if (type === Type.MAP || type === Type.FLOW_MAP) return false;
40
- return error = 'Merge nodes aliases can only point to maps';
41
- }
42
-
43
- return error = 'Merge nodes can only have Alias nodes as values';
44
- });
45
- if (error) doc.errors.push(new YAMLSemanticError(cst, error));
46
- } else {
47
- for (var j = i + 1; j < items.length; ++j) {
48
- var jKey = items[j].key;
49
-
50
- if (iKey === jKey || iKey && jKey && Object.prototype.hasOwnProperty.call(iKey, 'value') && iKey.value === jKey.value) {
51
- var _msg = "Map keys must be unique; \"".concat(iKey, "\" is repeated");
52
-
53
- doc.errors.push(new YAMLSemanticError(cst, _msg));
54
- break;
55
- }
56
- }
57
- }
58
- }
59
-
60
- if (hasCollectionKey && !doc.options.mapAsMap) {
61
- var warn = 'Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.';
62
- doc.warnings.push(new YAMLWarning(cst, warn));
63
- }
64
-
65
- cst.resolved = map;
66
- return map;
67
- }
68
-
69
- var valueHasPairComment = function valueHasPairComment(_ref2) {
70
- var _ref2$context = _ref2.context,
71
- lineStart = _ref2$context.lineStart,
72
- node = _ref2$context.node,
73
- src = _ref2$context.src,
74
- props = _ref2.props;
75
- if (props.length === 0) return false;
76
- var start = props[0].start;
77
- if (node && start > node.valueRange.start) return false;
78
- if (src[start] !== Char.COMMENT) return false;
79
-
80
- for (var i = lineStart; i < start; ++i) {
81
- if (src[i] === '\n') return false;
82
- }
83
-
84
- return true;
85
- };
86
-
87
- function resolvePairComment(item, pair) {
88
- if (!valueHasPairComment(item)) return;
89
- var comment = item.getPropValue(0, Char.COMMENT, true);
90
- var found = false;
91
- var cb = pair.value.commentBefore;
92
-
93
- if (cb && cb.startsWith(comment)) {
94
- pair.value.commentBefore = cb.substr(comment.length + 1);
95
- found = true;
96
- } else {
97
- var cc = pair.value.comment;
98
-
99
- if (!item.node && cc && cc.startsWith(comment)) {
100
- pair.value.comment = cc.substr(comment.length + 1);
101
- found = true;
102
- }
103
- }
104
-
105
- if (found) pair.comment = comment;
106
- }
107
-
108
- function resolveBlockMapItems(doc, cst) {
109
- var comments = [];
110
- var items = [];
111
- var key = undefined;
112
- var keyStart = null;
113
-
114
- for (var i = 0; i < cst.items.length; ++i) {
115
- var item = cst.items[i];
116
-
117
- switch (item.type) {
118
- case Type.BLANK_LINE:
119
- comments.push({
120
- afterKey: !!key,
121
- before: items.length
122
- });
123
- break;
124
-
125
- case Type.COMMENT:
126
- comments.push({
127
- afterKey: !!key,
128
- before: items.length,
129
- comment: item.comment
130
- });
131
- break;
132
-
133
- case Type.MAP_KEY:
134
- if (key !== undefined) items.push(new Pair(key));
135
- if (item.error) doc.errors.push(item.error);
136
- key = doc.resolveNode(item.node);
137
- keyStart = null;
138
- break;
139
-
140
- case Type.MAP_VALUE:
141
- {
142
- if (key === undefined) key = null;
143
- if (item.error) doc.errors.push(item.error);
144
-
145
- if (!item.context.atLineStart && item.node && item.node.type === Type.MAP && !item.node.context.atLineStart) {
146
- var msg = 'Nested mappings are not allowed in compact mappings';
147
- doc.errors.push(new YAMLSemanticError(item.node, msg));
148
- }
149
-
150
- var valueNode = item.node;
151
-
152
- if (!valueNode && item.props.length > 0) {
153
- // Comments on an empty mapping value need to be preserved, so we
154
- // need to construct a minimal empty node here to use instead of the
155
- // missing `item.node`. -- eemeli/yaml#19
156
- valueNode = new PlainValue(Type.PLAIN, []);
157
- valueNode.context = {
158
- parent: item,
159
- src: item.context.src
160
- };
161
- var pos = item.range.start + 1;
162
- valueNode.range = {
163
- start: pos,
164
- end: pos
165
- };
166
- valueNode.valueRange = {
167
- start: pos,
168
- end: pos
169
- };
170
-
171
- if (typeof item.range.origStart === 'number') {
172
- var origPos = item.range.origStart + 1;
173
- valueNode.range.origStart = valueNode.range.origEnd = origPos;
174
- valueNode.valueRange.origStart = valueNode.valueRange.origEnd = origPos;
175
- }
176
- }
177
-
178
- var pair = new Pair(key, doc.resolveNode(valueNode));
179
- resolvePairComment(item, pair);
180
- items.push(pair);
181
- checkKeyLength(doc.errors, cst, i, key, keyStart);
182
- key = undefined;
183
- keyStart = null;
184
- }
185
- break;
186
-
187
- default:
188
- if (key !== undefined) items.push(new Pair(key));
189
- key = doc.resolveNode(item);
190
- keyStart = item.range.start;
191
- if (item.error) doc.errors.push(item.error);
192
-
193
- next: for (var j = i + 1;; ++j) {
194
- var nextItem = cst.items[j];
195
-
196
- switch (nextItem && nextItem.type) {
197
- case Type.BLANK_LINE:
198
- case Type.COMMENT:
199
- continue next;
200
-
201
- case Type.MAP_VALUE:
202
- break next;
203
-
204
- default:
205
- doc.errors.push(new YAMLSemanticError(item, 'Implicit map keys need to be followed by map values'));
206
- break next;
207
- }
208
- }
209
-
210
- if (item.valueRangeContainsNewline) {
211
- var _msg2 = 'Implicit map keys need to be on a single line';
212
- doc.errors.push(new YAMLSemanticError(item, _msg2));
213
- }
214
-
215
- }
216
- }
217
-
218
- if (key !== undefined) items.push(new Pair(key));
219
- return {
220
- comments: comments,
221
- items: items
222
- };
223
- }
224
-
225
- function resolveFlowMapItems(doc, cst) {
226
- var comments = [];
227
- var items = [];
228
- var key = undefined;
229
- var keyStart = null;
230
- var explicitKey = false;
231
- var next = '{';
232
-
233
- for (var i = 0; i < cst.items.length; ++i) {
234
- checkKeyLength(doc.errors, cst, i, key, keyStart);
235
- var item = cst.items[i];
236
-
237
- if (typeof item.char === 'string') {
238
- var char = item.char,
239
- offset = item.offset;
240
-
241
- if (char === '?' && key === undefined && !explicitKey) {
242
- explicitKey = true;
243
- next = ':';
244
- continue;
245
- }
246
-
247
- if (char === ':') {
248
- if (key === undefined) key = null;
249
-
250
- if (next === ':') {
251
- next = ',';
252
- continue;
253
- }
254
- } else {
255
- if (explicitKey) {
256
- if (key === undefined && char !== ',') key = null;
257
- explicitKey = false;
258
- }
259
-
260
- if (key !== undefined) {
261
- items.push(new Pair(key));
262
- key = undefined;
263
- keyStart = null;
264
-
265
- if (char === ',') {
266
- next = ':';
267
- continue;
268
- }
269
- }
270
- }
271
-
272
- if (char === '}') {
273
- if (i === cst.items.length - 1) continue;
274
- } else if (char === next) {
275
- next = ':';
276
- continue;
277
- }
278
-
279
- var msg = "Flow map contains an unexpected ".concat(char);
280
- var err = new YAMLSyntaxError(cst, msg);
281
- err.offset = offset;
282
- doc.errors.push(err);
283
- } else if (item.type === Type.BLANK_LINE) {
284
- comments.push({
285
- afterKey: !!key,
286
- before: items.length
287
- });
288
- } else if (item.type === Type.COMMENT) {
289
- comments.push({
290
- afterKey: !!key,
291
- before: items.length,
292
- comment: item.comment
293
- });
294
- } else if (key === undefined) {
295
- if (next === ',') doc.errors.push(new YAMLSemanticError(item, 'Separator , missing in flow map'));
296
- key = doc.resolveNode(item);
297
- keyStart = explicitKey ? null : item.range.start; // TODO: add error for non-explicit multiline plain key
298
- } else {
299
- if (next !== ',') doc.errors.push(new YAMLSemanticError(item, 'Indicator : missing in flow map entry'));
300
- items.push(new Pair(key, doc.resolveNode(item)));
301
- key = undefined;
302
- explicitKey = false;
303
- }
304
- }
305
-
306
- checkFlowCollectionEnd(doc.errors, cst);
307
- if (key !== undefined) items.push(new Pair(key));
308
- return {
309
- comments: comments,
310
- items: items
311
- };
312
- }