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.
- package/browser/dist/Anchors.js +24 -39
- package/browser/dist/Document.js +99 -111
- 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 +57 -58
- 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 +30 -47
- package/browser/dist/cst/ParseContext.js +100 -140
- package/browser/dist/cst/PlainValue.js +22 -39
- 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 +168 -0
- package/browser/dist/errors.js +71 -74
- package/browser/dist/foldFlowLines.js +4 -15
- package/browser/dist/index.js +26 -45
- package/browser/dist/listTagNames.js +10 -24
- package/browser/dist/schema/Alias.js +33 -50
- package/browser/dist/schema/Collection.js +54 -65
- package/browser/dist/schema/Map.js +39 -49
- package/browser/dist/schema/Merge.js +33 -53
- package/browser/dist/schema/Node.js +3 -12
- package/browser/dist/schema/Pair.js +53 -56
- package/browser/dist/schema/Scalar.js +18 -33
- package/browser/dist/schema/Seq.js +23 -40
- package/browser/dist/schema/index.js +67 -81
- package/browser/dist/schema/parseMap.js +63 -70
- package/browser/dist/schema/parseSeq.js +45 -44
- package/browser/dist/schema/parseUtils.js +47 -11
- package/browser/dist/stringify.js +43 -48
- 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 +28 -0
- package/browser/map.js +1 -1
- package/browser/pair.js +1 -1
- package/browser/scalar.js +1 -1
- package/browser/schema.js +1 -1
- package/browser/seq.js +1 -1
- package/browser/types/binary.js +1 -1
- package/browser/types/omap.js +1 -1
- package/browser/types/pairs.js +1 -1
- package/browser/types/set.js +1 -1
- package/browser/types/timestamp.js +1 -1
- package/dist/Document.js +21 -9
- package/dist/cst/BlankLine.js +4 -0
- package/dist/cst/BlockValue.js +1 -1
- package/dist/cst/CollectionItem.js +27 -6
- package/dist/cst/Directive.js +0 -16
- package/dist/cst/Node.js +7 -9
- package/dist/cst/ParseContext.js +41 -55
- package/dist/cst/PlainValue.js +1 -1
- package/dist/cst/source-utils.js +178 -0
- package/dist/errors.js +37 -3
- package/dist/index.js +5 -4
- package/dist/schema/Alias.js +2 -1
- package/dist/schema/Collection.js +22 -5
- package/dist/schema/Map.js +12 -5
- package/dist/schema/Merge.js +4 -5
- package/dist/schema/Pair.js +20 -2
- package/dist/schema/index.js +14 -8
- package/dist/schema/parseMap.js +20 -5
- package/dist/schema/parseSeq.js +19 -6
- package/dist/schema/parseUtils.js +54 -6
- package/dist/stringify.js +21 -11
- 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/dist/{deprecation.js → warnings.js} +12 -7
- package/map.js +1 -1
- package/package.json +35 -17
- package/pair.js +1 -1
- package/scalar.js +1 -1
- package/schema.js +1 -1
- package/seq.js +1 -1
- package/types/binary.js +1 -1
- package/types/omap.js +1 -1
- package/types/pairs.js +1 -1
- package/types/set.js +1 -1
- package/types/timestamp.js +1 -1
- package/types.mjs +20 -0
- package/util.mjs +24 -0
- package/browser/dist/cst/getLinePos.js +0 -79
- package/browser/dist/deprecation.js +0 -34
- package/dist/cst/getLinePos.js +0 -79
|
@@ -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 _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 ===
|
|
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;
|
|
@@ -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 (
|
|
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,78 +1,67 @@
|
|
|
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
|
-
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
|
|
13
|
+
doc.errors.push(new YAMLSyntaxError(cst, msg));
|
|
32
14
|
return null;
|
|
33
15
|
}
|
|
34
16
|
|
|
35
|
-
var _ref = cst.type ===
|
|
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
|
|
21
|
+
var map = new Map();
|
|
40
22
|
map.items = items;
|
|
41
|
-
|
|
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 ===
|
|
47
|
-
items[i] = new
|
|
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
|
|
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 ===
|
|
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
|
|
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 &&
|
|
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
|
|
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] !==
|
|
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,
|
|
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
|
|
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
|
|
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
|
|
145
|
-
if (key !== undefined) items.push(new
|
|
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
|
|
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 ===
|
|
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
|
|
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
|
|
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
|
|
178
|
+
var pair = new Pair(key, doc.resolveNode(valueNode));
|
|
190
179
|
resolvePairComment(item, pair);
|
|
191
180
|
items.push(pair);
|
|
192
|
-
|
|
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
|
|
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
|
|
209
|
-
case
|
|
197
|
+
case Type.BLANK_LINE:
|
|
198
|
+
case Type.COMMENT:
|
|
210
199
|
continue next;
|
|
211
200
|
|
|
212
|
-
case
|
|
201
|
+
case Type.MAP_VALUE:
|
|
213
202
|
break next;
|
|
214
203
|
|
|
215
204
|
default:
|
|
216
|
-
doc.errors.push(new
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
290
|
-
|
|
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 ===
|
|
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
|
|
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
|
|
307
|
-
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)));
|
|
308
301
|
key = undefined;
|
|
309
302
|
explicitKey = false;
|
|
310
303
|
}
|
|
311
304
|
}
|
|
312
305
|
|
|
313
|
-
|
|
314
|
-
if (key !== undefined) items.push(new
|
|
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
|