yaml 1.3.0 → 1.5.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 (145) hide show
  1. package/README.md +29 -23
  2. package/browser/dist/Anchors.js +12 -10
  3. package/browser/dist/Document.js +122 -60
  4. package/browser/dist/constants.js +34 -0
  5. package/browser/dist/cst/Alias.js +1 -3
  6. package/browser/dist/cst/BlankLine.js +5 -7
  7. package/browser/dist/cst/BlockValue.js +4 -4
  8. package/browser/dist/cst/Collection.js +8 -8
  9. package/browser/dist/cst/CollectionItem.js +6 -8
  10. package/browser/dist/cst/Comment.js +5 -7
  11. package/browser/dist/cst/Directive.js +5 -7
  12. package/browser/dist/cst/Document.js +8 -10
  13. package/browser/dist/cst/FlowCollection.js +5 -7
  14. package/browser/dist/cst/Node.js +12 -40
  15. package/browser/dist/cst/ParseContext.js +32 -34
  16. package/browser/dist/cst/PlainValue.js +1 -3
  17. package/browser/dist/cst/QuoteDouble.js +1 -3
  18. package/browser/dist/cst/QuoteSingle.js +1 -3
  19. package/browser/dist/cst/Range.js +1 -3
  20. package/browser/dist/cst/getLinePos.js +8 -13
  21. package/browser/dist/cst/parse.js +1 -4
  22. package/browser/dist/deprecation.js +34 -0
  23. package/browser/dist/errors.js +50 -59
  24. package/browser/dist/index.js +7 -4
  25. package/browser/dist/listTagNames.js +1 -3
  26. package/browser/dist/schema/Alias.js +90 -10
  27. package/browser/dist/schema/Collection.js +3 -3
  28. package/browser/dist/schema/Map.js +22 -105
  29. package/browser/dist/schema/Merge.js +74 -1
  30. package/browser/dist/schema/Node.js +1 -3
  31. package/browser/dist/schema/Pair.js +52 -26
  32. package/browser/dist/schema/Scalar.js +3 -5
  33. package/browser/dist/schema/Seq.js +30 -7
  34. package/browser/dist/schema/index.js +158 -82
  35. package/browser/dist/schema/parseMap.js +18 -21
  36. package/browser/dist/schema/parseSeq.js +9 -12
  37. package/browser/dist/{schema/_string.js → stringify.js} +65 -73
  38. package/browser/dist/tags/core.js +132 -0
  39. package/browser/dist/tags/failsafe/index.js +17 -0
  40. package/browser/dist/tags/failsafe/map.js +65 -0
  41. package/browser/dist/tags/failsafe/seq.js +54 -0
  42. package/browser/dist/tags/failsafe/string.js +40 -0
  43. package/browser/dist/tags/index.js +50 -0
  44. package/browser/dist/tags/json.js +103 -0
  45. package/browser/dist/tags/options.js +35 -0
  46. package/browser/dist/{schema/_binary.js → tags/yaml-1.1/binary.js} +20 -20
  47. package/browser/dist/tags/yaml-1.1/index.js +177 -0
  48. package/browser/dist/{schema/_omap.js → tags/yaml-1.1/omap.js} +25 -25
  49. package/browser/dist/{schema/_pairs.js → tags/yaml-1.1/pairs.js} +9 -13
  50. package/browser/dist/tags/yaml-1.1/set.js +140 -0
  51. package/browser/dist/{schema/_timestamp.js → tags/yaml-1.1/timestamp.js} +13 -10
  52. package/browser/dist/test-events.js +1 -4
  53. package/browser/dist/toJSON.js +20 -8
  54. package/browser/index.js +1 -0
  55. package/browser/map.js +2 -1
  56. package/browser/pair.js +2 -1
  57. package/browser/parse-cst.js +1 -1
  58. package/browser/scalar.js +2 -1
  59. package/browser/schema.js +7 -3
  60. package/browser/seq.js +2 -1
  61. package/browser/types/binary.js +7 -1
  62. package/browser/types/omap.js +2 -1
  63. package/browser/types/pairs.js +2 -1
  64. package/browser/types/set.js +2 -1
  65. package/browser/types/timestamp.js +10 -1
  66. package/browser/types.js +11 -0
  67. package/browser/util.js +15 -0
  68. package/dist/Anchors.js +9 -8
  69. package/dist/Document.js +55 -39
  70. package/dist/constants.js +34 -0
  71. package/dist/cst/Alias.js +1 -3
  72. package/dist/cst/BlankLine.js +5 -7
  73. package/dist/cst/BlockValue.js +4 -4
  74. package/dist/cst/Collection.js +8 -8
  75. package/dist/cst/CollectionItem.js +6 -8
  76. package/dist/cst/Comment.js +5 -7
  77. package/dist/cst/Directive.js +5 -7
  78. package/dist/cst/Document.js +8 -10
  79. package/dist/cst/FlowCollection.js +5 -7
  80. package/dist/cst/Node.js +12 -40
  81. package/dist/cst/ParseContext.js +32 -34
  82. package/dist/cst/PlainValue.js +1 -3
  83. package/dist/cst/QuoteDouble.js +1 -3
  84. package/dist/cst/QuoteSingle.js +1 -3
  85. package/dist/cst/Range.js +1 -3
  86. package/dist/cst/getLinePos.js +8 -12
  87. package/dist/cst/parse.js +1 -4
  88. package/dist/deprecation.js +34 -0
  89. package/dist/errors.js +29 -35
  90. package/dist/index.js +7 -4
  91. package/dist/listTagNames.js +1 -3
  92. package/dist/schema/Alias.js +67 -12
  93. package/dist/schema/Map.js +10 -74
  94. package/dist/schema/Merge.js +31 -0
  95. package/dist/schema/Node.js +1 -3
  96. package/dist/schema/Pair.js +46 -20
  97. package/dist/schema/Scalar.js +3 -5
  98. package/dist/schema/Seq.js +9 -5
  99. package/dist/schema/index.js +109 -74
  100. package/dist/schema/parseMap.js +18 -21
  101. package/dist/schema/parseSeq.js +9 -12
  102. package/dist/{schema/_string.js → stringify.js} +56 -65
  103. package/dist/tags/core.js +96 -0
  104. package/dist/tags/failsafe/index.js +17 -0
  105. package/dist/tags/failsafe/map.js +33 -0
  106. package/dist/tags/failsafe/seq.js +34 -0
  107. package/dist/tags/failsafe/string.js +40 -0
  108. package/dist/tags/index.js +50 -0
  109. package/dist/tags/json.js +67 -0
  110. package/dist/tags/options.js +35 -0
  111. package/dist/{schema/_binary.js → tags/yaml-1.1/binary.js} +18 -20
  112. package/dist/tags/yaml-1.1/index.js +131 -0
  113. package/dist/{schema/_omap.js → tags/yaml-1.1/omap.js} +16 -16
  114. package/dist/{schema/_pairs.js → tags/yaml-1.1/pairs.js} +9 -11
  115. package/dist/{schema/_set.js → tags/yaml-1.1/set.js} +12 -44
  116. package/dist/{schema/_timestamp.js → tags/yaml-1.1/timestamp.js} +7 -10
  117. package/dist/test-events.js +1 -4
  118. package/dist/toJSON.js +15 -5
  119. package/index.js +1 -0
  120. package/map.js +2 -1
  121. package/package.json +22 -17
  122. package/pair.js +2 -1
  123. package/parse-cst.js +1 -1
  124. package/scalar.js +2 -1
  125. package/schema.js +7 -3
  126. package/seq.js +2 -1
  127. package/types/binary.js +7 -1
  128. package/types/omap.js +2 -1
  129. package/types/pairs.js +2 -1
  130. package/types/set.js +2 -1
  131. package/types/timestamp.js +10 -1
  132. package/types.js +11 -0
  133. package/util.js +15 -0
  134. package/browser/dist/polyfill.js +0 -251
  135. package/browser/dist/schema/_set.js +0 -212
  136. package/browser/dist/schema/core.js +0 -98
  137. package/browser/dist/schema/failsafe.js +0 -125
  138. package/browser/dist/schema/json.js +0 -66
  139. package/browser/dist/schema/yaml-1.1.js +0 -140
  140. package/dist/linePos.js +0 -58
  141. package/dist/polyfill.js +0 -27
  142. package/dist/schema/core.js +0 -79
  143. package/dist/schema/failsafe.js +0 -74
  144. package/dist/schema/json.js +0 -56
  145. package/dist/schema/yaml-1.1.js +0 -115
@@ -50,8 +50,14 @@ class YAMLSeq extends _Collection.default {
50
50
  this.items[idx] = value;
51
51
  }
52
52
 
53
- toJSON(_, opt) {
54
- return this.items.map((v, i) => (0, _toJSON.default)(v, String(i), opt));
53
+ toJSON(_, ctx) {
54
+ const seq = [];
55
+ if (ctx && ctx.onCreate) ctx.onCreate(seq);
56
+ let i = 0;
57
+
58
+ for (const item of this.items) seq.push((0, _toJSON.default)(item, String(i++), ctx));
59
+
60
+ return seq;
55
61
  }
56
62
 
57
63
  toString(ctx, onComment, onChompKeep) {
@@ -69,6 +75,4 @@ class YAMLSeq extends _Collection.default {
69
75
 
70
76
  }
71
77
 
72
- exports.default = YAMLSeq;
73
- module.exports = exports.default;
74
- module.exports.default = exports.default;
78
+ exports.default = YAMLSeq;
@@ -5,71 +5,84 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- var _Node = require("../cst/Node");
8
+ var _deprecation = require("../deprecation");
9
+
10
+ var _constants = require("../constants");
9
11
 
10
12
  var _errors = require("../errors");
11
13
 
12
- var _Alias = _interopRequireDefault(require("./Alias"));
14
+ var _stringify = require("../stringify");
13
15
 
14
- var _Collection = _interopRequireDefault(require("./Collection"));
16
+ var _tags = require("../tags");
15
17
 
16
- var _core = _interopRequireDefault(require("./core"));
18
+ var _string = require("../tags/failsafe/string");
17
19
 
18
- var _failsafe = _interopRequireWildcard(require("./failsafe"));
20
+ var _Alias = _interopRequireDefault(require("./Alias"));
19
21
 
20
- var _json = _interopRequireDefault(require("./json"));
22
+ var _Collection = _interopRequireDefault(require("./Collection"));
21
23
 
22
- var _Node2 = _interopRequireDefault(require("./Node"));
24
+ var _Node = _interopRequireDefault(require("./Node"));
23
25
 
24
26
  var _Pair = _interopRequireDefault(require("./Pair"));
25
27
 
26
28
  var _Scalar = _interopRequireDefault(require("./Scalar"));
27
29
 
28
- var _string = require("./_string");
29
-
30
- var _yaml = _interopRequireDefault(require("./yaml-1.1"));
31
-
32
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
33
-
34
30
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
31
 
36
32
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
37
33
 
38
34
  const isMap = ({
39
35
  type
40
- }) => type === _Node.Type.FLOW_MAP || type === _Node.Type.MAP;
36
+ }) => type === _constants.Type.FLOW_MAP || type === _constants.Type.MAP;
41
37
 
42
38
  const isSeq = ({
43
39
  type
44
- }) => type === _Node.Type.FLOW_SEQ || type === _Node.Type.SEQ;
40
+ }) => type === _constants.Type.FLOW_SEQ || type === _constants.Type.SEQ;
45
41
 
46
42
  class Schema {
47
- static defaultStringify(value) {
48
- return JSON.stringify(value);
49
- }
50
-
51
43
  constructor({
44
+ customTags,
52
45
  merge,
53
46
  schema,
54
- tags
47
+ tags: deprecatedCustomTags
55
48
  }) {
56
49
  this.merge = !!merge;
57
50
  this.name = schema;
58
- this.tags = Schema.tags[schema];
51
+ this.tags = _tags.schemas[schema.replace(/\W/g, '')]; // 'yaml-1.1' -> 'yaml11'
59
52
 
60
53
  if (!this.tags) {
61
- const keys = Object.keys(Schema.tags).map(key => JSON.stringify(key));
62
- throw new Error(`Unknown schema; use one of ${keys.join(', ')}`);
54
+ const keys = Object.keys(_tags.schemas).map(key => JSON.stringify(key)).join(', ');
55
+ throw new Error(`Unknown schema "${schema}"; use one of ${keys}`);
63
56
  }
64
57
 
65
- if (Array.isArray(tags)) {
66
- this.tags = this.tags.concat(tags);
67
- } else if (typeof tags === 'function') {
68
- this.tags = tags(this.tags.slice());
58
+ if (!customTags && deprecatedCustomTags) {
59
+ customTags = deprecatedCustomTags;
60
+ (0, _deprecation.warnOptionDeprecation)('tags', 'customTags');
61
+ }
62
+
63
+ if (Array.isArray(customTags)) {
64
+ for (const tag of customTags) this.tags = this.tags.concat(tag);
65
+ } else if (typeof customTags === 'function') {
66
+ this.tags = customTags(this.tags.slice());
67
+ }
68
+
69
+ for (let i = 0; i < this.tags.length; ++i) {
70
+ const tag = this.tags[i];
71
+
72
+ if (typeof tag === 'string') {
73
+ const tagObj = _tags.tags[tag];
74
+
75
+ if (!tagObj) {
76
+ const keys = Object.keys(_tags.tags).map(key => JSON.stringify(key)).join(', ');
77
+ throw new Error(`Unknown custom tag "${tag}"; use one of ${keys}`);
78
+ }
79
+
80
+ this.tags[i] = tagObj;
81
+ }
69
82
  }
70
83
  }
71
84
 
72
- createNode(value, wrapScalars, tag, onTagObj) {
85
+ createNode(value, wrapScalars, tag, ctx) {
73
86
  let tagObj;
74
87
 
75
88
  if (tag) {
@@ -78,18 +91,49 @@ class Schema {
78
91
  tagObj = match.find(t => !t.format) || match[0];
79
92
  if (!tagObj) throw new Error(`Tag ${tag} not found`);
80
93
  } else {
81
- tagObj = this.tags.find(t => t.class && value instanceof t.class && !t.format);
94
+ // TODO: deprecate/remove class check
95
+ tagObj = this.tags.find(t => (t.identify && t.identify(value) || t.class && value instanceof t.class) && !t.format);
82
96
 
83
97
  if (!tagObj) {
84
- if (value == null) return new _Scalar.default(null);
85
98
  if (typeof value.toJSON === 'function') value = value.toJSON();
86
99
  if (typeof value !== 'object') return wrapScalars ? new _Scalar.default(value) : value;
87
- tagObj = value instanceof Map ? _failsafe.map : value[Symbol.iterator] ? _failsafe.seq : _failsafe.map;
100
+ tagObj = value instanceof Map ? _tags.tags.map : value[Symbol.iterator] ? _tags.tags.seq : _tags.tags.map;
88
101
  }
89
102
  }
90
103
 
91
- if (onTagObj) onTagObj(tagObj);
92
- return tagObj.createNode ? tagObj.createNode(this, value, wrapScalars) : new _Scalar.default(value);
104
+ if (!ctx) ctx = {
105
+ wrapScalars
106
+ };else ctx.wrapScalars = wrapScalars;
107
+
108
+ if (ctx.onTagObj) {
109
+ ctx.onTagObj(tagObj);
110
+ delete ctx.onTagObj;
111
+ }
112
+
113
+ const obj = {};
114
+
115
+ if (value && typeof value === 'object' && ctx.prevObjects) {
116
+ const prev = ctx.prevObjects.find(o => o.value === value);
117
+
118
+ if (prev) {
119
+ const alias = new _Alias.default(prev); // leaves source dirty; must be cleaned by caller
120
+
121
+ ctx.aliasNodes.push(alias);
122
+ return alias;
123
+ }
124
+
125
+ obj.value = value;
126
+ ctx.prevObjects.push(obj);
127
+ }
128
+
129
+ obj.node = tagObj.createNode ? tagObj.createNode(this, value, ctx) : wrapScalars ? new _Scalar.default(value) : value;
130
+ return obj.node;
131
+ }
132
+
133
+ createPair(key, value, ctx) {
134
+ const k = this.createNode(key, ctx.wrapScalars, null, ctx);
135
+ const v = this.createNode(value, ctx.wrapScalars, null, ctx);
136
+ return new _Pair.default(k, v);
93
137
  } // falls back to string on no match
94
138
 
95
139
 
@@ -107,7 +151,8 @@ class Schema {
107
151
  const match = str.match(test);
108
152
 
109
153
  if (match) {
110
- const res = new _Scalar.default(resolve.apply(null, match));
154
+ let res = resolve.apply(null, match);
155
+ if (!(res instanceof _Scalar.default)) res = new _Scalar.default(res);
111
156
  if (format) res.format = format;
112
157
  return res;
113
158
  }
@@ -134,7 +179,7 @@ class Schema {
134
179
  if (!(res instanceof _Collection.default)) res = new _Scalar.default(res);
135
180
  node.resolved = res;
136
181
  } else {
137
- const str = (0, _string.resolve)(doc, node);
182
+ const str = (0, _string.resolveString)(doc, node);
138
183
 
139
184
  if (typeof str === 'string' && tags.length > 0) {
140
185
  node.resolved = this.resolveScalar(str, tags);
@@ -147,7 +192,7 @@ class Schema {
147
192
  }
148
193
 
149
194
  if (!node.resolved) return null;
150
- if (tagName) node.resolved.tag = tagName;
195
+ if (tagName && node.tag) node.resolved.tag = tagName;
151
196
  return node.resolved;
152
197
  }
153
198
 
@@ -176,33 +221,12 @@ class Schema {
176
221
  if (match.length > 0) return match.find(t => t.format === item.format) || match[0];
177
222
  }
178
223
 
179
- if (item.value === null) {
180
- const tagObj = this.tags.find(t => t.class === null && !t.format);
181
- if (!tagObj) throw new Error('Tag not resolved for null value');
182
- return tagObj;
183
- }
184
-
185
224
  let tagObj, obj;
186
225
 
187
226
  if (item instanceof _Scalar.default) {
188
- switch (typeof item.value) {
189
- case 'boolean':
190
- obj = new Boolean();
191
- break;
192
-
193
- case 'number':
194
- obj = new Number();
195
- break;
196
-
197
- case 'string':
198
- obj = new String();
199
- break;
200
-
201
- default:
202
- obj = item.value;
203
- }
227
+ obj = item.value; // TODO: deprecate/remove class check
204
228
 
205
- const match = this.tags.filter(t => t.class && (obj instanceof t.class || obj && obj.constructor === t.class));
229
+ const match = this.tags.filter(t => t.identify && t.identify(obj) || t.class && obj instanceof t.class);
206
230
  tagObj = match.find(t => t.format === item.format) || match.find(t => !t.format);
207
231
  } else {
208
232
  obj = item;
@@ -230,7 +254,7 @@ class Schema {
230
254
  props.push(`&${anchor}`);
231
255
  }
232
256
 
233
- if (node.tag && node.tag !== tagObj.tag) {
257
+ if (node.tag) {
234
258
  props.push(doc.stringifyTag(node.tag));
235
259
  } else if (!tagObj.default) {
236
260
  props.push(doc.stringifyTag(tagObj.tag));
@@ -241,13 +265,34 @@ class Schema {
241
265
 
242
266
  stringify(item, ctx, onComment, onChompKeep) {
243
267
  let tagObj;
244
- if (!(item instanceof _Node2.default)) item = this.createNode(item, true, null, o => tagObj = o);
268
+
269
+ if (!(item instanceof _Node.default)) {
270
+ const createCtx = {
271
+ aliasNodes: [],
272
+ onTagObj: o => tagObj = o,
273
+ prevObjects: []
274
+ };
275
+ item = this.createNode(item, true, null, createCtx);
276
+ const {
277
+ anchors
278
+ } = ctx.doc;
279
+
280
+ for (const alias of createCtx.aliasNodes) {
281
+ alias.source = alias.source.node;
282
+ let name = anchors.getName(alias.source);
283
+
284
+ if (!name) {
285
+ name = anchors.newName();
286
+ anchors.map[name] = alias.source;
287
+ }
288
+ }
289
+ }
290
+
245
291
  ctx.tags = this;
246
292
  if (item instanceof _Pair.default) return item.toString(ctx, onComment, onChompKeep);
247
293
  if (!tagObj) tagObj = this.getTagObject(item);
248
294
  const props = this.stringifyProps(item, tagObj, ctx);
249
- const stringify = tagObj.stringify || Schema.defaultStringify;
250
- const str = stringify(item, ctx, onComment, onChompKeep);
295
+ const 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);
251
296
  return props ? item instanceof _Collection.default && str[0] !== '{' && str[0] !== '[' ? `${props}\n${ctx.indent}${str}` : `${props} ${str}` : str;
252
297
  }
253
298
 
@@ -261,14 +306,4 @@ _defineProperty(Schema, "defaultTags", {
261
306
  MAP: 'tag:yaml.org,2002:map',
262
307
  SEQ: 'tag:yaml.org,2002:seq',
263
308
  STR: 'tag:yaml.org,2002:str'
264
- });
265
-
266
- _defineProperty(Schema, "tags", {
267
- core: _core.default,
268
- failsafe: _failsafe.default,
269
- json: _json.default,
270
- 'yaml-1.1': _yaml.default
271
- });
272
-
273
- module.exports = exports.default;
274
- module.exports.default = exports.default;
309
+ });
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = parseMap;
7
7
 
8
- var _Node = require("../cst/Node");
8
+ var _constants = require("../constants");
9
9
 
10
10
  var _PlainValue = _interopRequireDefault(require("../cst/PlainValue"));
11
11
 
@@ -26,7 +26,7 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
26
26
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
27
 
28
28
  function parseMap(doc, cst) {
29
- if (cst.type !== _Node.Type.MAP && cst.type !== _Node.Type.FLOW_MAP) {
29
+ if (cst.type !== _constants.Type.MAP && cst.type !== _constants.Type.FLOW_MAP) {
30
30
  const msg = `A ${cst.type} node cannot be resolved as a mapping`;
31
31
  doc.errors.push(new _errors.YAMLSyntaxError(cst, msg));
32
32
  return null;
@@ -35,7 +35,7 @@ function parseMap(doc, cst) {
35
35
  const {
36
36
  comments,
37
37
  items
38
- } = cst.type === _Node.Type.FLOW_MAP ? resolveFlowMapItems(doc, cst) : resolveBlockMapItems(doc, cst);
38
+ } = cst.type === _constants.Type.FLOW_MAP ? resolveFlowMapItems(doc, cst) : resolveBlockMapItems(doc, cst);
39
39
  const map = new _Map.default();
40
40
  map.items = items;
41
41
  (0, _parseUtils.resolveComments)(map, comments);
@@ -56,7 +56,7 @@ function parseMap(doc, cst) {
56
56
  const {
57
57
  type
58
58
  } = node.source;
59
- if (type === _Node.Type.MAP || type === _Node.Type.FLOW_MAP) return false;
59
+ if (type === _constants.Type.MAP || type === _constants.Type.FLOW_MAP) return false;
60
60
  return error = 'Merge nodes aliases can only point to maps';
61
61
  }
62
62
 
@@ -95,7 +95,7 @@ const valueHasPairComment = ({
95
95
  start
96
96
  } = props[0];
97
97
  if (node && start > node.valueRange.start) return false;
98
- if (src[start] !== _Node.Char.COMMENT) return false;
98
+ if (src[start] !== _constants.Char.COMMENT) return false;
99
99
 
100
100
  for (let i = lineStart; i < start; ++i) if (src[i] === '\n') return false;
101
101
 
@@ -104,7 +104,7 @@ const valueHasPairComment = ({
104
104
 
105
105
  function resolvePairComment(item, pair) {
106
106
  if (!valueHasPairComment(item)) return;
107
- const comment = item.getPropValue(0, _Node.Char.COMMENT, true);
107
+ const comment = item.getPropValue(0, _constants.Char.COMMENT, true);
108
108
  let found = false;
109
109
  const cb = pair.value.commentBefore;
110
110
 
@@ -133,14 +133,14 @@ function resolveBlockMapItems(doc, cst) {
133
133
  const item = cst.items[i];
134
134
 
135
135
  switch (item.type) {
136
- case _Node.Type.BLANK_LINE:
136
+ case _constants.Type.BLANK_LINE:
137
137
  comments.push({
138
138
  afterKey: !!key,
139
139
  before: items.length
140
140
  });
141
141
  break;
142
142
 
143
- case _Node.Type.COMMENT:
143
+ case _constants.Type.COMMENT:
144
144
  comments.push({
145
145
  afterKey: !!key,
146
146
  before: items.length,
@@ -148,19 +148,19 @@ function resolveBlockMapItems(doc, cst) {
148
148
  });
149
149
  break;
150
150
 
151
- case _Node.Type.MAP_KEY:
151
+ case _constants.Type.MAP_KEY:
152
152
  if (key !== undefined) items.push(new _Pair.default(key));
153
153
  if (item.error) doc.errors.push(item.error);
154
154
  key = doc.resolveNode(item.node);
155
155
  keyStart = null;
156
156
  break;
157
157
 
158
- case _Node.Type.MAP_VALUE:
158
+ case _constants.Type.MAP_VALUE:
159
159
  {
160
160
  if (key === undefined) key = null;
161
161
  if (item.error) doc.errors.push(item.error);
162
162
 
163
- if (!item.context.atLineStart && item.node && item.node.type === _Node.Type.MAP && !item.node.context.atLineStart) {
163
+ if (!item.context.atLineStart && item.node && item.node.type === _constants.Type.MAP && !item.node.context.atLineStart) {
164
164
  const msg = 'Nested mappings are not allowed in compact mappings';
165
165
  doc.errors.push(new _errors.YAMLSemanticError(item.node, msg));
166
166
  }
@@ -171,7 +171,7 @@ function resolveBlockMapItems(doc, cst) {
171
171
  // Comments on an empty mapping value need to be preserved, so we
172
172
  // need to construct a minimal empty node here to use instead of the
173
173
  // missing `item.node`. -- eemeli/yaml#19
174
- valueNode = new _PlainValue.default(_Node.Type.PLAIN, []);
174
+ valueNode = new _PlainValue.default(_constants.Type.PLAIN, []);
175
175
  valueNode.context = {
176
176
  parent: item,
177
177
  src: item.context.src
@@ -212,11 +212,11 @@ function resolveBlockMapItems(doc, cst) {
212
212
  const nextItem = cst.items[j];
213
213
 
214
214
  switch (nextItem && nextItem.type) {
215
- case _Node.Type.BLANK_LINE:
216
- case _Node.Type.COMMENT:
215
+ case _constants.Type.BLANK_LINE:
216
+ case _constants.Type.COMMENT:
217
217
  continue next;
218
218
 
219
- case _Node.Type.MAP_VALUE:
219
+ case _constants.Type.MAP_VALUE:
220
220
  break next;
221
221
 
222
222
  default:
@@ -296,12 +296,12 @@ function resolveFlowMapItems(doc, cst) {
296
296
  }
297
297
 
298
298
  doc.errors.push(new _errors.YAMLSyntaxError(cst, `Flow map contains an unexpected ${char}`));
299
- } else if (item.type === _Node.Type.BLANK_LINE) {
299
+ } else if (item.type === _constants.Type.BLANK_LINE) {
300
300
  comments.push({
301
301
  afterKey: !!key,
302
302
  before: items.length
303
303
  });
304
- } else if (item.type === _Node.Type.COMMENT) {
304
+ } else if (item.type === _constants.Type.COMMENT) {
305
305
  comments.push({
306
306
  afterKey: !!key,
307
307
  before: items.length,
@@ -325,7 +325,4 @@ function resolveFlowMapItems(doc, cst) {
325
325
  comments,
326
326
  items
327
327
  };
328
- }
329
-
330
- module.exports = exports.default;
331
- module.exports.default = exports.default;
328
+ }
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = parseSeq;
7
7
 
8
- var _Node = require("../cst/Node");
8
+ var _constants = require("../constants");
9
9
 
10
10
  var _errors = require("../errors");
11
11
 
@@ -18,7 +18,7 @@ var _Seq = _interopRequireDefault(require("./Seq"));
18
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
19
 
20
20
  function parseSeq(doc, cst) {
21
- if (cst.type !== _Node.Type.SEQ && cst.type !== _Node.Type.FLOW_SEQ) {
21
+ if (cst.type !== _constants.Type.SEQ && cst.type !== _constants.Type.FLOW_SEQ) {
22
22
  const msg = `A ${cst.type} node cannot be resolved as a sequence`;
23
23
  doc.errors.push(new _errors.YAMLSyntaxError(cst, msg));
24
24
  return null;
@@ -27,7 +27,7 @@ function parseSeq(doc, cst) {
27
27
  const {
28
28
  comments,
29
29
  items
30
- } = cst.type === _Node.Type.FLOW_SEQ ? resolveFlowSeqItems(doc, cst) : resolveBlockSeqItems(doc, cst);
30
+ } = cst.type === _constants.Type.FLOW_SEQ ? resolveFlowSeqItems(doc, cst) : resolveBlockSeqItems(doc, cst);
31
31
  const seq = new _Seq.default();
32
32
  seq.items = items;
33
33
  (0, _parseUtils.resolveComments)(seq, comments);
@@ -43,20 +43,20 @@ function resolveBlockSeqItems(doc, cst) {
43
43
  const item = cst.items[i];
44
44
 
45
45
  switch (item.type) {
46
- case _Node.Type.BLANK_LINE:
46
+ case _constants.Type.BLANK_LINE:
47
47
  comments.push({
48
48
  before: items.length
49
49
  });
50
50
  break;
51
51
 
52
- case _Node.Type.COMMENT:
52
+ case _constants.Type.COMMENT:
53
53
  comments.push({
54
54
  comment: item.comment,
55
55
  before: items.length
56
56
  });
57
57
  break;
58
58
 
59
- case _Node.Type.SEQ_ITEM:
59
+ case _constants.Type.SEQ_ITEM:
60
60
  if (item.error) doc.errors.push(item.error);
61
61
  items.push(doc.resolveNode(item.node));
62
62
 
@@ -129,11 +129,11 @@ function resolveFlowSeqItems(doc, cst) {
129
129
  const msg = `Flow sequence contains an unexpected ${char}`;
130
130
  doc.errors.push(new _errors.YAMLSyntaxError(cst, msg));
131
131
  }
132
- } else if (item.type === _Node.Type.BLANK_LINE) {
132
+ } else if (item.type === _constants.Type.BLANK_LINE) {
133
133
  comments.push({
134
134
  before: items.length
135
135
  });
136
- } else if (item.type === _Node.Type.COMMENT) {
136
+ } else if (item.type === _constants.Type.COMMENT) {
137
137
  comments.push({
138
138
  comment: item.comment,
139
139
  before: items.length
@@ -164,7 +164,4 @@ function resolveFlowSeqItems(doc, cst) {
164
164
  comments,
165
165
  items
166
166
  };
167
- }
168
-
169
- module.exports = exports.default;
170
- module.exports.default = exports.default;
167
+ }