yaml 1.7.2 → 1.8.3

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