yaml 1.7.1 → 1.8.2
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.
- package/browser/dist/Anchors.js +24 -39
- package/browser/dist/Document.js +86 -110
- package/browser/dist/addComment.js +2 -11
- package/browser/dist/constants.js +3 -11
- package/browser/dist/cst/Alias.js +19 -36
- package/browser/dist/cst/BlankLine.js +25 -38
- package/browser/dist/cst/BlockValue.js +29 -51
- package/browser/dist/cst/Collection.js +42 -65
- package/browser/dist/cst/CollectionItem.js +33 -55
- package/browser/dist/cst/Comment.js +19 -35
- package/browser/dist/cst/Directive.js +20 -56
- package/browser/dist/cst/Document.js +47 -71
- package/browser/dist/cst/FlowCollection.js +38 -61
- package/browser/dist/cst/Node.js +26 -46
- package/browser/dist/cst/ParseContext.js +100 -140
- package/browser/dist/cst/PlainValue.js +21 -38
- package/browser/dist/cst/QuoteDouble.js +26 -42
- package/browser/dist/cst/QuoteSingle.js +25 -41
- package/browser/dist/cst/Range.js +9 -19
- package/browser/dist/cst/parse.js +5 -16
- package/browser/dist/cst/source-utils.js +3 -14
- package/browser/dist/errors.js +42 -78
- package/browser/dist/foldFlowLines.js +4 -15
- package/browser/dist/index.js +24 -44
- package/browser/dist/listTagNames.js +10 -24
- package/browser/dist/schema/Alias.js +32 -49
- package/browser/dist/schema/Collection.js +54 -65
- package/browser/dist/schema/Map.js +39 -49
- package/browser/dist/schema/Merge.js +32 -52
- package/browser/dist/schema/Node.js +3 -12
- package/browser/dist/schema/Pair.js +40 -58
- package/browser/dist/schema/Scalar.js +18 -33
- package/browser/dist/schema/Seq.js +23 -40
- package/browser/dist/schema/index.js +66 -80
- package/browser/dist/schema/parseMap.js +52 -72
- package/browser/dist/schema/parseSeq.js +30 -45
- package/browser/dist/schema/parseUtils.js +12 -25
- package/browser/dist/stringify.js +39 -45
- package/browser/dist/tags/core.js +30 -37
- package/browser/dist/tags/failsafe/index.js +4 -17
- package/browser/dist/tags/failsafe/map.js +17 -26
- package/browser/dist/tags/failsafe/seq.js +7 -18
- package/browser/dist/tags/failsafe/string.js +7 -19
- package/browser/dist/tags/index.js +35 -49
- package/browser/dist/tags/json.js +11 -38
- package/browser/dist/tags/options.js +8 -20
- package/browser/dist/tags/yaml-1.1/binary.js +16 -29
- package/browser/dist/tags/yaml-1.1/index.js +34 -54
- package/browser/dist/tags/yaml-1.1/omap.js +39 -58
- package/browser/dist/tags/yaml-1.1/pairs.js +15 -34
- package/browser/dist/tags/yaml-1.1/set.js +35 -61
- package/browser/dist/tags/yaml-1.1/timestamp.js +6 -16
- package/browser/dist/test-events.js +7 -19
- package/browser/dist/toJSON.js +1 -8
- package/browser/dist/warnings.js +3 -15
- package/dist/Document.js +7 -7
- package/dist/cst/BlankLine.js +4 -0
- package/dist/cst/BlockValue.js +1 -1
- package/dist/cst/Directive.js +0 -16
- package/dist/cst/Node.js +0 -5
- package/dist/cst/ParseContext.js +41 -55
- package/dist/schema/Alias.js +1 -0
- package/dist/schema/Collection.js +22 -5
- package/dist/schema/Map.js +12 -5
- package/dist/schema/Merge.js +3 -4
- package/dist/schema/Pair.js +1 -0
- package/dist/schema/index.js +11 -5
- package/dist/schema/parseMap.js +3 -1
- package/dist/schema/parseUtils.js +5 -6
- package/dist/stringify.js +17 -8
- package/dist/tags/core.js +27 -10
- package/dist/tags/failsafe/map.js +5 -1
- package/dist/tags/failsafe/seq.js +1 -1
- package/dist/tags/index.js +13 -1
- package/dist/tags/json.js +2 -9
- package/dist/tags/yaml-1.1/index.js +6 -6
- package/dist/tags/yaml-1.1/omap.js +3 -5
- package/dist/tags/yaml-1.1/pairs.js +1 -1
- package/dist/tags/yaml-1.1/set.js +3 -1
- package/package.json +40 -16
- package/types.mjs +20 -0
- package/util.mjs +24 -0
|
@@ -1,67 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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 ===
|
|
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 ===
|
|
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
|
-
|
|
34
|
+
|
|
35
|
+
_classCallCheck(this, Schema);
|
|
36
|
+
|
|
59
37
|
this.merge = !!merge;
|
|
60
38
|
this.name = schema;
|
|
61
|
-
this.
|
|
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(
|
|
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
|
-
|
|
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 =
|
|
88
|
+
var tagObj = tags[_tag];
|
|
108
89
|
|
|
109
90
|
if (!tagObj) {
|
|
110
|
-
var _keys = Object.keys(
|
|
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
|
-
(
|
|
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 ((
|
|
145
|
-
tagObj = value instanceof 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 && (
|
|
161
|
-
var prev = ctx.prevObjects.
|
|
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
|
|
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.
|
|
153
|
+
ctx.prevObjects.set(value, obj);
|
|
174
154
|
}
|
|
175
155
|
|
|
176
|
-
obj.node = tagObj.createNode ? tagObj.createNode(this, value, ctx) : wrapScalars ? new
|
|
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
|
|
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
|
|
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
|
|
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
|
|
211
|
+
if (!(res instanceof Collection)) res = new Scalar(res);
|
|
231
212
|
node.resolved = res;
|
|
232
213
|
} else {
|
|
233
|
-
var str =
|
|
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;
|
|
@@ -252,24 +234,24 @@ function () {
|
|
|
252
234
|
var res = this.resolveNode(doc, node, tagName);
|
|
253
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
|
|
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
|
|
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
|
|
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
|
|
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 : (
|
|
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
|
|
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
|
|
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
|
-
|
|
384
|
-
|
|
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
|
-
|
|
391
|
-
|
|
392
|
-
(
|
|
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,68 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
|
13
|
+
doc.errors.push(new YAMLSyntaxError(cst, msg));
|
|
34
14
|
return null;
|
|
35
15
|
}
|
|
36
16
|
|
|
37
|
-
var _ref = cst.type ===
|
|
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
|
|
21
|
+
var map = new Map();
|
|
42
22
|
map.items = items;
|
|
43
|
-
|
|
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
|
|
28
|
+
if (iKey instanceof Collection) hasCollectionKey = true;
|
|
49
29
|
|
|
50
|
-
if (doc.schema.merge && iKey && iKey.value ===
|
|
51
|
-
items[i] = new
|
|
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
|
|
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 ===
|
|
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
|
|
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
|
|
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
|
|
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] !==
|
|
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,
|
|
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
|
|
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
|
|
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
|
|
154
|
-
if (key !== undefined) items.push(new
|
|
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
|
|
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 ===
|
|
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
|
|
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
|
|
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
|
|
178
|
+
var pair = new Pair(key, doc.resolveNode(valueNode));
|
|
199
179
|
resolvePairComment(item, pair);
|
|
200
180
|
items.push(pair);
|
|
201
|
-
|
|
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
|
|
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
|
|
218
|
-
case
|
|
197
|
+
case Type.BLANK_LINE:
|
|
198
|
+
case Type.COMMENT:
|
|
219
199
|
continue next;
|
|
220
200
|
|
|
221
|
-
case
|
|
201
|
+
case Type.MAP_VALUE:
|
|
222
202
|
break next;
|
|
223
203
|
|
|
224
204
|
default:
|
|
225
|
-
doc.errors.push(new
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
280
|
+
var err = new YAMLSyntaxError(cst, msg);
|
|
301
281
|
err.offset = offset;
|
|
302
282
|
doc.errors.push(err);
|
|
303
|
-
} else if (item.type ===
|
|
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 ===
|
|
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
|
|
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
|
|
320
|
-
items.push(new
|
|
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
|
-
|
|
327
|
-
if (key !== undefined) items.push(new
|
|
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
|