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