yaml 1.10.0 → 2.0.0-1
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/README.md +10 -11
- package/browser/dist/Schema-ea978338.js +1211 -0
- package/browser/dist/{PlainValue-ff5147c6.js → errors-2634d01a.js} +8 -186
- package/browser/dist/index.js +1174 -121
- package/browser/dist/parse-cst.js +2 -1904
- package/browser/dist/parse-d1ba890f.js +2084 -0
- package/browser/dist/{resolveSeq-04825f30.js → stringifyNumber-d8af95b1.js} +197 -1072
- package/browser/dist/types.js +3 -4
- package/browser/dist/util.js +2 -2
- package/browser/index.js +1 -1
- package/dist/Document-f89a2614.js +1783 -0
- package/dist/Schema-807430ba.js +934 -0
- package/dist/{PlainValue-ec8e588e.js → _rollupPluginBabelHelpers-eed30217.js} +0 -167
- package/dist/index.js +58 -44
- package/dist/parse-3997f544.js +1915 -0
- package/dist/parse-cst.js +3 -1742
- package/dist/stringifyNumber-dea1120c.js +1286 -0
- package/dist/test-events.js +6 -7
- package/dist/types.js +16 -17
- package/dist/util.js +12 -14
- package/index.d.ts +103 -20
- package/index.js +1 -1
- package/package.json +16 -26
- package/types.d.ts +19 -47
- package/util.d.ts +2 -12
- package/util.js +0 -2
- package/util.mjs +0 -3
- package/browser/dist/Schema-2bf2c74e.js +0 -679
- package/browser/dist/legacy-exports.js +0 -3
- package/browser/dist/warnings-0e4b70d3.js +0 -499
- package/browser/map.js +0 -2
- package/browser/pair.js +0 -2
- package/browser/scalar.js +0 -2
- package/browser/schema.js +0 -9
- package/browser/seq.js +0 -2
- package/browser/types/binary.js +0 -8
- package/browser/types/omap.js +0 -3
- package/browser/types/pairs.js +0 -3
- package/browser/types/set.js +0 -3
- package/browser/types/timestamp.js +0 -10
- package/dist/Document-2cf6b08c.js +0 -757
- package/dist/Schema-42e9705c.js +0 -522
- package/dist/legacy-exports.js +0 -16
- package/dist/resolveSeq-4a68b39b.js +0 -2115
- package/dist/warnings-39684f17.js +0 -416
- package/map.js +0 -2
- package/pair.js +0 -2
- package/scalar.js +0 -2
- package/schema.js +0 -9
- package/seq.js +0 -2
- package/types/binary.js +0 -8
- package/types/omap.js +0 -3
- package/types/pairs.js +0 -3
- package/types/set.js +0 -3
- package/types/timestamp.js +0 -10
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { b as _classCallCheck, l as _inherits, m as _createSuper, a as _createClass, _ as _typeof, d as defaultTagPrefix, c as _defineProperty, p as _assertThisInitialized, q as _toArray, T as Type, h as _createForOfIteratorHelper, n as _get, o as _getPrototypeOf, j as YAMLReferenceError } from './errors-2634d01a.js';
|
|
2
2
|
|
|
3
3
|
function addCommentBefore(str, indent, comment) {
|
|
4
4
|
if (!comment) return str;
|
|
@@ -13,9 +13,19 @@ var Node = function Node() {
|
|
|
13
13
|
_classCallCheck(this, Node);
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Recursively convert any node or its contents to native JavaScript
|
|
18
|
+
*
|
|
19
|
+
* @param value - The input value
|
|
20
|
+
* @param {string|null} arg - If `value` defines a `toJSON()` method, use this
|
|
21
|
+
* as its first argument
|
|
22
|
+
* @param ctx - Conversion context, originally set in Document#toJS(). If
|
|
23
|
+
* `{ keep: true }` is not set, output should be suitable for JSON
|
|
24
|
+
* stringification.
|
|
25
|
+
*/
|
|
26
|
+
function toJS(value, arg, ctx) {
|
|
17
27
|
if (Array.isArray(value)) return value.map(function (v, i) {
|
|
18
|
-
return
|
|
28
|
+
return toJS(v, String(i), ctx);
|
|
19
29
|
});
|
|
20
30
|
|
|
21
31
|
if (value && typeof value.toJSON === 'function') {
|
|
@@ -29,10 +39,13 @@ function toJSON(value, arg, ctx) {
|
|
|
29
39
|
return res;
|
|
30
40
|
}
|
|
31
41
|
|
|
32
|
-
if ((
|
|
42
|
+
if (!(ctx && ctx.keep) && typeof value === 'bigint') return Number(value);
|
|
33
43
|
return value;
|
|
34
44
|
}
|
|
35
45
|
|
|
46
|
+
var isScalarValue = function isScalarValue(value) {
|
|
47
|
+
return !value || typeof value !== 'function' && _typeof(value) !== 'object';
|
|
48
|
+
};
|
|
36
49
|
var Scalar = /*#__PURE__*/function (_Node) {
|
|
37
50
|
_inherits(Scalar, _Node);
|
|
38
51
|
|
|
@@ -50,8 +63,8 @@ var Scalar = /*#__PURE__*/function (_Node) {
|
|
|
50
63
|
|
|
51
64
|
_createClass(Scalar, [{
|
|
52
65
|
key: "toJSON",
|
|
53
|
-
value: function toJSON
|
|
54
|
-
return ctx && ctx.keep ? this.value :
|
|
66
|
+
value: function toJSON(arg, ctx) {
|
|
67
|
+
return ctx && ctx.keep ? this.value : toJS(this.value, arg, ctx);
|
|
55
68
|
}
|
|
56
69
|
}, {
|
|
57
70
|
key: "toString",
|
|
@@ -63,20 +76,98 @@ var Scalar = /*#__PURE__*/function (_Node) {
|
|
|
63
76
|
return Scalar;
|
|
64
77
|
}(Node);
|
|
65
78
|
|
|
79
|
+
function findTagObject(value, tagName, tags) {
|
|
80
|
+
if (tagName) {
|
|
81
|
+
var match = tags.filter(function (t) {
|
|
82
|
+
return t.tag === tagName;
|
|
83
|
+
});
|
|
84
|
+
var tagObj = match.find(function (t) {
|
|
85
|
+
return !t.format;
|
|
86
|
+
}) || match[0];
|
|
87
|
+
if (!tagObj) throw new Error("Tag ".concat(tagName, " not found"));
|
|
88
|
+
return tagObj;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return tags.find(function (t) {
|
|
92
|
+
return t.identify && t.identify(value) && !t.format;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function createNode(value, tagName, ctx) {
|
|
97
|
+
if (value instanceof Node) return value;
|
|
98
|
+
var onAlias = ctx.onAlias,
|
|
99
|
+
onTagObj = ctx.onTagObj,
|
|
100
|
+
prevObjects = ctx.prevObjects,
|
|
101
|
+
wrapScalars = ctx.wrapScalars;
|
|
102
|
+
var _ctx$schema = ctx.schema,
|
|
103
|
+
map = _ctx$schema.map,
|
|
104
|
+
seq = _ctx$schema.seq,
|
|
105
|
+
tags = _ctx$schema.tags;
|
|
106
|
+
if (tagName && tagName.startsWith('!!')) tagName = defaultTagPrefix + tagName.slice(2);
|
|
107
|
+
var tagObj = findTagObject(value, tagName, tags);
|
|
108
|
+
|
|
109
|
+
if (!tagObj) {
|
|
110
|
+
if (typeof value.toJSON === 'function') value = value.toJSON();
|
|
111
|
+
if (!value || _typeof(value) !== 'object') return wrapScalars ? new Scalar(value) : value;
|
|
112
|
+
tagObj = value instanceof Map ? map : value[Symbol.iterator] ? seq : map;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (onTagObj) {
|
|
116
|
+
onTagObj(tagObj);
|
|
117
|
+
delete ctx.onTagObj;
|
|
118
|
+
} // Detect duplicate references to the same object & use Alias nodes for all
|
|
119
|
+
// after first. The `obj` wrapper allows for circular references to resolve.
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
var obj = {
|
|
123
|
+
value: undefined,
|
|
124
|
+
node: undefined
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
if (value && _typeof(value) === 'object') {
|
|
128
|
+
var prev = prevObjects.get(value);
|
|
129
|
+
if (prev) return onAlias(prev);
|
|
130
|
+
obj.value = value;
|
|
131
|
+
prevObjects.set(value, obj);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
obj.node = tagObj.createNode ? tagObj.createNode(ctx.schema, value, ctx) : wrapScalars ? new Scalar(value) : value;
|
|
135
|
+
if (tagName && obj.node instanceof Node) obj.node.tag = tagName;
|
|
136
|
+
return obj.node;
|
|
137
|
+
}
|
|
138
|
+
|
|
66
139
|
function collectionFromPath(schema, path, value) {
|
|
67
140
|
var v = value;
|
|
68
141
|
|
|
69
142
|
for (var i = path.length - 1; i >= 0; --i) {
|
|
70
143
|
var k = path[i];
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
144
|
+
|
|
145
|
+
if (Number.isInteger(k) && k >= 0) {
|
|
146
|
+
var a = [];
|
|
147
|
+
a[k] = v;
|
|
148
|
+
v = a;
|
|
149
|
+
} else {
|
|
150
|
+
var o = {};
|
|
151
|
+
Object.defineProperty(o, k, {
|
|
152
|
+
value: v,
|
|
153
|
+
writable: true,
|
|
154
|
+
enumerable: true,
|
|
155
|
+
configurable: true
|
|
156
|
+
});
|
|
157
|
+
v = o;
|
|
158
|
+
}
|
|
74
159
|
}
|
|
75
160
|
|
|
76
|
-
return
|
|
161
|
+
return createNode(v, null, {
|
|
162
|
+
onAlias: function onAlias() {
|
|
163
|
+
throw new Error('Repeated objects are not supported here');
|
|
164
|
+
},
|
|
165
|
+
prevObjects: new Map(),
|
|
166
|
+
schema: schema,
|
|
167
|
+
wrapScalars: false
|
|
168
|
+
});
|
|
77
169
|
} // null, undefined, or an empty non-string iterable (e.g. [])
|
|
78
170
|
|
|
79
|
-
|
|
80
171
|
var isEmptyPath = function isEmptyPath(path) {
|
|
81
172
|
return path == null || _typeof(path) === 'object' && path[Symbol.iterator]().next().done;
|
|
82
173
|
};
|
|
@@ -164,9 +255,8 @@ var Collection = /*#__PURE__*/function (_Node) {
|
|
|
164
255
|
var node = this.get(key, true);
|
|
165
256
|
if (node instanceof Collection) node.setIn(rest, value);else if (node === undefined && this.schema) this.set(key, collectionFromPath(this.schema, rest, value));else throw new Error("Expected YAML collection at ".concat(key, ". Remaining path: ").concat(rest));
|
|
166
257
|
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/* istanbul ignore next */
|
|
258
|
+
}
|
|
259
|
+
/* istanbul ignore next: overridden in implementations */
|
|
170
260
|
|
|
171
261
|
}, {
|
|
172
262
|
key: "toJSON",
|
|
@@ -348,11 +438,12 @@ var YAMLSeq = /*#__PURE__*/function (_Collection) {
|
|
|
348
438
|
value: function set(key, value) {
|
|
349
439
|
var idx = asItemIndex(key);
|
|
350
440
|
if (typeof idx !== 'number') throw new Error("Expected a valid index, not ".concat(key, "."));
|
|
351
|
-
this.items[idx]
|
|
441
|
+
var prev = this.items[idx];
|
|
442
|
+
if (prev instanceof Scalar && isScalarValue(value)) prev.value = value;else this.items[idx] = value;
|
|
352
443
|
}
|
|
353
444
|
}, {
|
|
354
445
|
key: "toJSON",
|
|
355
|
-
value: function toJSON
|
|
446
|
+
value: function toJSON(_, ctx) {
|
|
356
447
|
var seq = [];
|
|
357
448
|
if (ctx && ctx.onCreate) ctx.onCreate(seq);
|
|
358
449
|
var i = 0;
|
|
@@ -363,7 +454,7 @@ var YAMLSeq = /*#__PURE__*/function (_Collection) {
|
|
|
363
454
|
try {
|
|
364
455
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
365
456
|
var item = _step.value;
|
|
366
|
-
seq.push(
|
|
457
|
+
seq.push(toJS(item, String(i++), ctx));
|
|
367
458
|
}
|
|
368
459
|
} catch (err) {
|
|
369
460
|
_iterator.e(err);
|
|
@@ -398,7 +489,7 @@ var stringifyKey = function stringifyKey(key, jsKey, ctx) {
|
|
|
398
489
|
if (jsKey === null) return '';
|
|
399
490
|
if (_typeof(jsKey) !== 'object') return String(jsKey);
|
|
400
491
|
if (key instanceof Node && ctx && ctx.doc) return key.toString({
|
|
401
|
-
anchors:
|
|
492
|
+
anchors: Object.create(null),
|
|
402
493
|
doc: ctx.doc,
|
|
403
494
|
indent: '',
|
|
404
495
|
indentStep: ctx.indentStep,
|
|
@@ -409,6 +500,11 @@ var stringifyKey = function stringifyKey(key, jsKey, ctx) {
|
|
|
409
500
|
return JSON.stringify(jsKey);
|
|
410
501
|
};
|
|
411
502
|
|
|
503
|
+
function createPair(key, value, ctx) {
|
|
504
|
+
var k = createNode(key, null, ctx);
|
|
505
|
+
var v = createNode(value, null, ctx);
|
|
506
|
+
return new Pair(k, v);
|
|
507
|
+
}
|
|
412
508
|
var Pair = /*#__PURE__*/function (_Node) {
|
|
413
509
|
_inherits(Pair, _Node);
|
|
414
510
|
|
|
@@ -431,16 +527,24 @@ var Pair = /*#__PURE__*/function (_Node) {
|
|
|
431
527
|
_createClass(Pair, [{
|
|
432
528
|
key: "addToJSMap",
|
|
433
529
|
value: function addToJSMap(ctx, map) {
|
|
434
|
-
var key =
|
|
530
|
+
var key = toJS(this.key, '', ctx);
|
|
435
531
|
|
|
436
532
|
if (map instanceof Map) {
|
|
437
|
-
var value =
|
|
533
|
+
var value = toJS(this.value, key, ctx);
|
|
438
534
|
map.set(key, value);
|
|
439
535
|
} else if (map instanceof Set) {
|
|
440
536
|
map.add(key);
|
|
441
537
|
} else {
|
|
442
538
|
var stringKey = stringifyKey(this.key, key, ctx);
|
|
443
|
-
|
|
539
|
+
|
|
540
|
+
var _value = toJS(this.value, stringKey, ctx);
|
|
541
|
+
|
|
542
|
+
if (stringKey in map) Object.defineProperty(map, stringKey, {
|
|
543
|
+
value: _value,
|
|
544
|
+
writable: true,
|
|
545
|
+
enumerable: true,
|
|
546
|
+
configurable: true
|
|
547
|
+
});else map[stringKey] = _value;
|
|
444
548
|
}
|
|
445
549
|
|
|
446
550
|
return map;
|
|
@@ -476,12 +580,13 @@ var Pair = /*#__PURE__*/function (_Node) {
|
|
|
476
580
|
|
|
477
581
|
var explicitKey = !simpleKeys && (!key || keyComment || key instanceof Collection || key.type === Type.BLOCK_FOLDED || key.type === Type.BLOCK_LITERAL);
|
|
478
582
|
var _ctx = ctx,
|
|
583
|
+
allNullValues = _ctx.allNullValues,
|
|
479
584
|
doc = _ctx.doc,
|
|
480
585
|
indent = _ctx.indent,
|
|
481
586
|
indentStep = _ctx.indentStep,
|
|
482
587
|
stringify = _ctx.stringify;
|
|
483
588
|
ctx = Object.assign({}, ctx, {
|
|
484
|
-
implicitKey: !explicitKey,
|
|
589
|
+
implicitKey: !explicitKey && (simpleKeys || !allNullValues),
|
|
485
590
|
indent: indent + indentStep
|
|
486
591
|
});
|
|
487
592
|
var chompKeep = false;
|
|
@@ -492,7 +597,7 @@ var Pair = /*#__PURE__*/function (_Node) {
|
|
|
492
597
|
});
|
|
493
598
|
str = addComment(str, ctx.indent, keyComment);
|
|
494
599
|
|
|
495
|
-
if (
|
|
600
|
+
if (allNullValues && !simpleKeys) {
|
|
496
601
|
if (this.comment) {
|
|
497
602
|
str = addComment(str, ctx.indent, this.comment);
|
|
498
603
|
if (onComment) onComment();
|
|
@@ -501,6 +606,15 @@ var Pair = /*#__PURE__*/function (_Node) {
|
|
|
501
606
|
return ctx.inFlow ? str : "? ".concat(str);
|
|
502
607
|
}
|
|
503
608
|
|
|
609
|
+
if (!explicitKey && str.length > 1024) {
|
|
610
|
+
if (!simpleKeys) {
|
|
611
|
+
explicitKey = true;
|
|
612
|
+
} else {
|
|
613
|
+
var _msg = 'With simple keys, single line scalar must not span more than 1024 characters';
|
|
614
|
+
throw new Error(_msg);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
|
|
504
618
|
str = explicitKey ? "? ".concat(str, "\n").concat(indent, ":") : "".concat(str, ":");
|
|
505
619
|
|
|
506
620
|
if (this.comment) {
|
|
@@ -522,7 +636,7 @@ var Pair = /*#__PURE__*/function (_Node) {
|
|
|
522
636
|
|
|
523
637
|
valueComment = value.comment;
|
|
524
638
|
} else if (value && _typeof(value) === 'object') {
|
|
525
|
-
value = doc.
|
|
639
|
+
value = doc.createNode(value);
|
|
526
640
|
}
|
|
527
641
|
|
|
528
642
|
ctx.implicitKey = false;
|
|
@@ -546,7 +660,7 @@ var Pair = /*#__PURE__*/function (_Node) {
|
|
|
546
660
|
} else if (!explicitKey && value instanceof Collection) {
|
|
547
661
|
var flow = valueStr[0] === '[' || valueStr[0] === '{';
|
|
548
662
|
if (!flow || valueStr.includes('\n')) ws = "\n".concat(ctx.indent);
|
|
549
|
-
}
|
|
663
|
+
} else if (valueStr[0] === '\n') ws = '';
|
|
550
664
|
|
|
551
665
|
if (chompKeep && !valueComment && onChompKeep) onChompKeep();
|
|
552
666
|
return addComment(str + ws + valueStr, ctx.indent, valueComment);
|
|
@@ -642,8 +756,8 @@ var Alias = /*#__PURE__*/function (_Node) {
|
|
|
642
756
|
|
|
643
757
|
_createClass(Alias, [{
|
|
644
758
|
key: "toJSON",
|
|
645
|
-
value: function toJSON
|
|
646
|
-
if (!ctx) return
|
|
759
|
+
value: function toJSON(arg, ctx) {
|
|
760
|
+
if (!ctx) return toJS(this.source, arg, ctx);
|
|
647
761
|
var anchors = ctx.anchors,
|
|
648
762
|
maxAliasCount = ctx.maxAliasCount;
|
|
649
763
|
var anchor = anchors.get(this.source);
|
|
@@ -727,7 +841,9 @@ var YAMLMap = /*#__PURE__*/function (_Collection) {
|
|
|
727
841
|
var sortEntries = this.schema && this.schema.sortMapEntries;
|
|
728
842
|
|
|
729
843
|
if (prev) {
|
|
730
|
-
if (overwrite)
|
|
844
|
+
if (!overwrite) throw new Error("Key ".concat(pair.key, " already set")); // For scalars, keep the old node & its comments and anchors
|
|
845
|
+
|
|
846
|
+
if (prev.value instanceof Scalar && isScalarValue(pair.value)) prev.value.value = pair.value;else prev.value = pair.value;
|
|
731
847
|
} else if (sortEntries) {
|
|
732
848
|
var i = this.items.findIndex(function (item) {
|
|
733
849
|
return sortEntries(pair, item) < 0;
|
|
@@ -763,10 +879,9 @@ var YAMLMap = /*#__PURE__*/function (_Collection) {
|
|
|
763
879
|
this.add(new Pair(key, value), true);
|
|
764
880
|
}
|
|
765
881
|
/**
|
|
766
|
-
* @param
|
|
767
|
-
* @param {
|
|
768
|
-
* @
|
|
769
|
-
* @returns {*} Instance of Type, Map, or Object
|
|
882
|
+
* @param ctx - Conversion context, originally set in Document#toJS()
|
|
883
|
+
* @param {Class} Type - If set, forces the returned collection type
|
|
884
|
+
* @returns Instance of Type, Map, or Object
|
|
770
885
|
*/
|
|
771
886
|
|
|
772
887
|
}, {
|
|
@@ -827,103 +942,6 @@ var YAMLMap = /*#__PURE__*/function (_Collection) {
|
|
|
827
942
|
return YAMLMap;
|
|
828
943
|
}(Collection);
|
|
829
944
|
|
|
830
|
-
var MERGE_KEY = '<<';
|
|
831
|
-
var Merge = /*#__PURE__*/function (_Pair) {
|
|
832
|
-
_inherits(Merge, _Pair);
|
|
833
|
-
|
|
834
|
-
var _super = _createSuper(Merge);
|
|
835
|
-
|
|
836
|
-
function Merge(pair) {
|
|
837
|
-
var _this;
|
|
838
|
-
|
|
839
|
-
_classCallCheck(this, Merge);
|
|
840
|
-
|
|
841
|
-
if (pair instanceof Pair) {
|
|
842
|
-
var seq = pair.value;
|
|
843
|
-
|
|
844
|
-
if (!(seq instanceof YAMLSeq)) {
|
|
845
|
-
seq = new YAMLSeq();
|
|
846
|
-
seq.items.push(pair.value);
|
|
847
|
-
seq.range = pair.value.range;
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
_this = _super.call(this, pair.key, seq);
|
|
851
|
-
_this.range = pair.range;
|
|
852
|
-
} else {
|
|
853
|
-
_this = _super.call(this, new Scalar(MERGE_KEY), new YAMLSeq());
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
_this.type = Pair.Type.MERGE_PAIR;
|
|
857
|
-
return _possibleConstructorReturn(_this);
|
|
858
|
-
} // If the value associated with a merge key is a single mapping node, each of
|
|
859
|
-
// its key/value pairs is inserted into the current mapping, unless the key
|
|
860
|
-
// already exists in it. If the value associated with the merge key is a
|
|
861
|
-
// sequence, then this sequence is expected to contain mapping nodes and each
|
|
862
|
-
// of these nodes is merged in turn according to its order in the sequence.
|
|
863
|
-
// Keys in mapping nodes earlier in the sequence override keys specified in
|
|
864
|
-
// later mapping nodes. -- http://yaml.org/type/merge.html
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
_createClass(Merge, [{
|
|
868
|
-
key: "addToJSMap",
|
|
869
|
-
value: function addToJSMap(ctx, map) {
|
|
870
|
-
var _iterator = _createForOfIteratorHelper(this.value.items),
|
|
871
|
-
_step;
|
|
872
|
-
|
|
873
|
-
try {
|
|
874
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
875
|
-
var source = _step.value.source;
|
|
876
|
-
if (!(source instanceof YAMLMap)) throw new Error('Merge sources must be maps');
|
|
877
|
-
var srcMap = source.toJSON(null, ctx, Map);
|
|
878
|
-
|
|
879
|
-
var _iterator2 = _createForOfIteratorHelper(srcMap),
|
|
880
|
-
_step2;
|
|
881
|
-
|
|
882
|
-
try {
|
|
883
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
884
|
-
var _step2$value = _slicedToArray(_step2.value, 2),
|
|
885
|
-
key = _step2$value[0],
|
|
886
|
-
value = _step2$value[1];
|
|
887
|
-
|
|
888
|
-
if (map instanceof Map) {
|
|
889
|
-
if (!map.has(key)) map.set(key, value);
|
|
890
|
-
} else if (map instanceof Set) {
|
|
891
|
-
map.add(key);
|
|
892
|
-
} else {
|
|
893
|
-
if (!Object.prototype.hasOwnProperty.call(map, key)) map[key] = value;
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
} catch (err) {
|
|
897
|
-
_iterator2.e(err);
|
|
898
|
-
} finally {
|
|
899
|
-
_iterator2.f();
|
|
900
|
-
}
|
|
901
|
-
}
|
|
902
|
-
} catch (err) {
|
|
903
|
-
_iterator.e(err);
|
|
904
|
-
} finally {
|
|
905
|
-
_iterator.f();
|
|
906
|
-
}
|
|
907
|
-
|
|
908
|
-
return map;
|
|
909
|
-
}
|
|
910
|
-
}, {
|
|
911
|
-
key: "toString",
|
|
912
|
-
value: function toString(ctx, onComment) {
|
|
913
|
-
var seq = this.value;
|
|
914
|
-
if (seq.items.length > 1) return _get(_getPrototypeOf(Merge.prototype), "toString", this).call(this, ctx, onComment);
|
|
915
|
-
this.value = seq.items[0];
|
|
916
|
-
|
|
917
|
-
var str = _get(_getPrototypeOf(Merge.prototype), "toString", this).call(this, ctx, onComment);
|
|
918
|
-
|
|
919
|
-
this.value = seq;
|
|
920
|
-
return str;
|
|
921
|
-
}
|
|
922
|
-
}]);
|
|
923
|
-
|
|
924
|
-
return Merge;
|
|
925
|
-
}(Pair);
|
|
926
|
-
|
|
927
945
|
var binaryOptions = {
|
|
928
946
|
defaultType: Type.BLOCK_LITERAL,
|
|
929
947
|
lineWidth: 76
|
|
@@ -940,6 +958,8 @@ var nullOptions = {
|
|
|
940
958
|
};
|
|
941
959
|
var strOptions = {
|
|
942
960
|
defaultType: Type.PLAIN,
|
|
961
|
+
defaultKeyType: Type.PLAIN,
|
|
962
|
+
defaultQuoteSingle: false,
|
|
943
963
|
doubleQuoted: {
|
|
944
964
|
jsonEncoding: false,
|
|
945
965
|
minMultiLineLength: 40
|
|
@@ -950,7 +970,7 @@ var strOptions = {
|
|
|
950
970
|
}
|
|
951
971
|
};
|
|
952
972
|
|
|
953
|
-
function resolveScalar(str, tags
|
|
973
|
+
function resolveScalar(str, tags) {
|
|
954
974
|
var _iterator = _createForOfIteratorHelper(tags),
|
|
955
975
|
_step;
|
|
956
976
|
|
|
@@ -961,15 +981,11 @@ function resolveScalar(str, tags, scalarFallback) {
|
|
|
961
981
|
test = _step$value.test,
|
|
962
982
|
resolve = _step$value.resolve;
|
|
963
983
|
|
|
964
|
-
if (test) {
|
|
965
|
-
var
|
|
966
|
-
|
|
967
|
-
if (
|
|
968
|
-
|
|
969
|
-
if (!(res instanceof Scalar)) res = new Scalar(res);
|
|
970
|
-
if (format) res.format = format;
|
|
971
|
-
return res;
|
|
972
|
-
}
|
|
984
|
+
if (test && test.test(str)) {
|
|
985
|
+
var res = resolve(str);
|
|
986
|
+
if (!(res instanceof Scalar)) res = new Scalar(res);
|
|
987
|
+
if (format) res.format = format;
|
|
988
|
+
return res;
|
|
973
989
|
}
|
|
974
990
|
}
|
|
975
991
|
} catch (err) {
|
|
@@ -978,8 +994,7 @@ function resolveScalar(str, tags, scalarFallback) {
|
|
|
978
994
|
_iterator.f();
|
|
979
995
|
}
|
|
980
996
|
|
|
981
|
-
|
|
982
|
-
return new Scalar(str);
|
|
997
|
+
return new Scalar(str); // fallback to string
|
|
983
998
|
}
|
|
984
999
|
|
|
985
1000
|
var FOLD_FLOW = 'flow';
|
|
@@ -1015,7 +1030,7 @@ var consumeMoreIndentedLines = function consumeMoreIndentedLines(text, i) {
|
|
|
1015
1030
|
* the first line, defaulting to `indent.length`
|
|
1016
1031
|
* @param {number} [options.lineWidth=80]
|
|
1017
1032
|
* @param {number} [options.minContentWidth=20] Allow highly indented lines to
|
|
1018
|
-
* stretch the line width
|
|
1033
|
+
* stretch the line width or indent content from the start
|
|
1019
1034
|
* @param {function} options.onFold Called once if the text is folded
|
|
1020
1035
|
* @param {function} options.onFold Called once if any line of text exceeds
|
|
1021
1036
|
* lineWidth characters
|
|
@@ -1035,7 +1050,12 @@ function foldFlowLines(text, indent, mode, _ref) {
|
|
|
1035
1050
|
if (text.length <= endStep) return text;
|
|
1036
1051
|
var folds = [];
|
|
1037
1052
|
var escapedFolds = {};
|
|
1038
|
-
var end = lineWidth -
|
|
1053
|
+
var end = lineWidth - indent.length;
|
|
1054
|
+
|
|
1055
|
+
if (typeof indentAtStart === 'number') {
|
|
1056
|
+
if (indentAtStart > lineWidth - Math.max(2, minContentWidth)) folds.push(0);else end = lineWidth - indentAtStart;
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1039
1059
|
var split = undefined;
|
|
1040
1060
|
var prev = undefined;
|
|
1041
1061
|
var overflow = false;
|
|
@@ -1114,8 +1134,10 @@ function foldFlowLines(text, indent, mode, _ref) {
|
|
|
1114
1134
|
|
|
1115
1135
|
var _end = folds[_i + 1] || text.length;
|
|
1116
1136
|
|
|
1117
|
-
if (
|
|
1118
|
-
|
|
1137
|
+
if (fold === 0) res = "\n".concat(indent).concat(text.slice(0, _end));else {
|
|
1138
|
+
if (mode === FOLD_QUOTED && escapedFolds[fold]) res += "".concat(text[fold], "\\");
|
|
1139
|
+
res += "\n".concat(indent).concat(text.slice(fold + 1, _end));
|
|
1140
|
+
}
|
|
1119
1141
|
}
|
|
1120
1142
|
|
|
1121
1143
|
return res;
|
|
@@ -1340,13 +1362,27 @@ function plainString(item, ctx, onComment, onChompKeep) {
|
|
|
1340
1362
|
}
|
|
1341
1363
|
|
|
1342
1364
|
if (!value || /^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(value)) {
|
|
1343
|
-
|
|
1365
|
+
var hasDouble = value.indexOf('"') !== -1;
|
|
1366
|
+
var hasSingle = value.indexOf("'") !== -1;
|
|
1367
|
+
var quotedString;
|
|
1368
|
+
|
|
1369
|
+
if (hasDouble && !hasSingle) {
|
|
1370
|
+
quotedString = singleQuotedString;
|
|
1371
|
+
} else if (hasSingle && !hasDouble) {
|
|
1372
|
+
quotedString = doubleQuotedString;
|
|
1373
|
+
} else if (strOptions.defaultQuoteSingle) {
|
|
1374
|
+
quotedString = singleQuotedString;
|
|
1375
|
+
} else {
|
|
1376
|
+
quotedString = doubleQuotedString;
|
|
1377
|
+
} // not allowed:
|
|
1344
1378
|
// - empty string, '-' or '?'
|
|
1345
1379
|
// - start with an indicator character (except [?:-]) or /[?-] /
|
|
1346
1380
|
// - '\n ', ': ' or ' \n' anywhere
|
|
1347
1381
|
// - '#' not preceded by a non-space char
|
|
1348
1382
|
// - end with ' ' or ':'
|
|
1349
|
-
|
|
1383
|
+
|
|
1384
|
+
|
|
1385
|
+
return implicitKey || inFlow || value.indexOf('\n') === -1 ? quotedString(value, ctx) : blockString(item, ctx, onComment, onChompKeep);
|
|
1350
1386
|
}
|
|
1351
1387
|
|
|
1352
1388
|
if (!implicitKey && !inFlow && type !== Type.PLAIN && value.indexOf('\n') !== -1) {
|
|
@@ -1365,7 +1401,7 @@ function plainString(item, ctx, onComment, onChompKeep) {
|
|
|
1365
1401
|
|
|
1366
1402
|
if (actualString) {
|
|
1367
1403
|
var tags = ctx.doc.schema.tags;
|
|
1368
|
-
var resolved = resolveScalar(str, tags
|
|
1404
|
+
var resolved = resolveScalar(str, tags).value;
|
|
1369
1405
|
if (typeof resolved !== 'string') return doubleQuotedString(value, ctx);
|
|
1370
1406
|
}
|
|
1371
1407
|
|
|
@@ -1380,7 +1416,8 @@ function plainString(item, ctx, onComment, onChompKeep) {
|
|
|
1380
1416
|
}
|
|
1381
1417
|
|
|
1382
1418
|
function stringifyString(item, ctx, onComment, onChompKeep) {
|
|
1383
|
-
var
|
|
1419
|
+
var defaultKeyType = strOptions.defaultKeyType,
|
|
1420
|
+
defaultType = strOptions.defaultType;
|
|
1384
1421
|
var implicitKey = ctx.implicitKey,
|
|
1385
1422
|
inFlow = ctx.inFlow;
|
|
1386
1423
|
var _item = item,
|
|
@@ -1394,11 +1431,17 @@ function stringifyString(item, ctx, onComment, onChompKeep) {
|
|
|
1394
1431
|
});
|
|
1395
1432
|
}
|
|
1396
1433
|
|
|
1434
|
+
if (type !== Type.QUOTE_DOUBLE) {
|
|
1435
|
+
// force double quotes on control characters & unpaired surrogates
|
|
1436
|
+
if (/(?:[\0-\x08\x0B-\x1F\x7F-\x9F]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])/.test(value)) type = Type.QUOTE_DOUBLE;
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1397
1439
|
var _stringify = function _stringify(_type) {
|
|
1398
1440
|
switch (_type) {
|
|
1399
1441
|
case Type.BLOCK_FOLDED:
|
|
1400
1442
|
case Type.BLOCK_LITERAL:
|
|
1401
|
-
return
|
|
1443
|
+
return implicitKey || inFlow ? doubleQuotedString(value, ctx) // blocks are not valid inside flow containers
|
|
1444
|
+
: blockString(item, ctx, onComment, onChompKeep);
|
|
1402
1445
|
|
|
1403
1446
|
case Type.QUOTE_DOUBLE:
|
|
1404
1447
|
return doubleQuotedString(value, ctx);
|
|
@@ -1414,19 +1457,12 @@ function stringifyString(item, ctx, onComment, onChompKeep) {
|
|
|
1414
1457
|
}
|
|
1415
1458
|
};
|
|
1416
1459
|
|
|
1417
|
-
if (type !== Type.QUOTE_DOUBLE && /[\x00-\x08\x0b-\x1f\x7f-\x9f]/.test(value)) {
|
|
1418
|
-
// force double quotes on control characters
|
|
1419
|
-
type = Type.QUOTE_DOUBLE;
|
|
1420
|
-
} else if ((implicitKey || inFlow) && (type === Type.BLOCK_FOLDED || type === Type.BLOCK_LITERAL)) {
|
|
1421
|
-
// should not happen; blocks are not valid inside flow containers
|
|
1422
|
-
type = Type.QUOTE_DOUBLE;
|
|
1423
|
-
}
|
|
1424
|
-
|
|
1425
1460
|
var res = _stringify(type);
|
|
1426
1461
|
|
|
1427
1462
|
if (res === null) {
|
|
1428
|
-
|
|
1429
|
-
|
|
1463
|
+
var t = implicitKey ? defaultKeyType : defaultType;
|
|
1464
|
+
res = _stringify(t);
|
|
1465
|
+
if (res === null) throw new Error("Unsupported default string type ".concat(t));
|
|
1430
1466
|
}
|
|
1431
1467
|
|
|
1432
1468
|
return res;
|
|
@@ -1459,915 +1495,4 @@ function stringifyNumber(_ref) {
|
|
|
1459
1495
|
return n;
|
|
1460
1496
|
}
|
|
1461
1497
|
|
|
1462
|
-
|
|
1463
|
-
var char, name;
|
|
1464
|
-
|
|
1465
|
-
switch (cst.type) {
|
|
1466
|
-
case Type.FLOW_MAP:
|
|
1467
|
-
char = '}';
|
|
1468
|
-
name = 'flow map';
|
|
1469
|
-
break;
|
|
1470
|
-
|
|
1471
|
-
case Type.FLOW_SEQ:
|
|
1472
|
-
char = ']';
|
|
1473
|
-
name = 'flow sequence';
|
|
1474
|
-
break;
|
|
1475
|
-
|
|
1476
|
-
default:
|
|
1477
|
-
errors.push(new YAMLSemanticError(cst, 'Not a flow collection!?'));
|
|
1478
|
-
return;
|
|
1479
|
-
}
|
|
1480
|
-
|
|
1481
|
-
var lastItem;
|
|
1482
|
-
|
|
1483
|
-
for (var i = cst.items.length - 1; i >= 0; --i) {
|
|
1484
|
-
var item = cst.items[i];
|
|
1485
|
-
|
|
1486
|
-
if (!item || item.type !== Type.COMMENT) {
|
|
1487
|
-
lastItem = item;
|
|
1488
|
-
break;
|
|
1489
|
-
}
|
|
1490
|
-
}
|
|
1491
|
-
|
|
1492
|
-
if (lastItem && lastItem.char !== char) {
|
|
1493
|
-
var msg = "Expected ".concat(name, " to end with ").concat(char);
|
|
1494
|
-
var err;
|
|
1495
|
-
|
|
1496
|
-
if (typeof lastItem.offset === 'number') {
|
|
1497
|
-
err = new YAMLSemanticError(cst, msg);
|
|
1498
|
-
err.offset = lastItem.offset + 1;
|
|
1499
|
-
} else {
|
|
1500
|
-
err = new YAMLSemanticError(lastItem, msg);
|
|
1501
|
-
if (lastItem.range && lastItem.range.end) err.offset = lastItem.range.end - lastItem.range.start;
|
|
1502
|
-
}
|
|
1503
|
-
|
|
1504
|
-
errors.push(err);
|
|
1505
|
-
}
|
|
1506
|
-
}
|
|
1507
|
-
function checkFlowCommentSpace(errors, comment) {
|
|
1508
|
-
var prev = comment.context.src[comment.range.start - 1];
|
|
1509
|
-
|
|
1510
|
-
if (prev !== '\n' && prev !== '\t' && prev !== ' ') {
|
|
1511
|
-
var msg = 'Comments must be separated from other tokens by white space characters';
|
|
1512
|
-
errors.push(new YAMLSemanticError(comment, msg));
|
|
1513
|
-
}
|
|
1514
|
-
}
|
|
1515
|
-
function getLongKeyError(source, key) {
|
|
1516
|
-
var sk = String(key);
|
|
1517
|
-
var k = sk.substr(0, 8) + '...' + sk.substr(-8);
|
|
1518
|
-
return new YAMLSemanticError(source, "The \"".concat(k, "\" key is too long"));
|
|
1519
|
-
}
|
|
1520
|
-
function resolveComments(collection, comments) {
|
|
1521
|
-
var _iterator = _createForOfIteratorHelper(comments),
|
|
1522
|
-
_step;
|
|
1523
|
-
|
|
1524
|
-
try {
|
|
1525
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
1526
|
-
var _step$value = _step.value,
|
|
1527
|
-
afterKey = _step$value.afterKey,
|
|
1528
|
-
before = _step$value.before,
|
|
1529
|
-
comment = _step$value.comment;
|
|
1530
|
-
var item = collection.items[before];
|
|
1531
|
-
|
|
1532
|
-
if (!item) {
|
|
1533
|
-
if (comment !== undefined) {
|
|
1534
|
-
if (collection.comment) collection.comment += '\n' + comment;else collection.comment = comment;
|
|
1535
|
-
}
|
|
1536
|
-
} else {
|
|
1537
|
-
if (afterKey && item.value) item = item.value;
|
|
1538
|
-
|
|
1539
|
-
if (comment === undefined) {
|
|
1540
|
-
if (afterKey || !item.commentBefore) item.spaceBefore = true;
|
|
1541
|
-
} else {
|
|
1542
|
-
if (item.commentBefore) item.commentBefore += '\n' + comment;else item.commentBefore = comment;
|
|
1543
|
-
}
|
|
1544
|
-
}
|
|
1545
|
-
}
|
|
1546
|
-
} catch (err) {
|
|
1547
|
-
_iterator.e(err);
|
|
1548
|
-
} finally {
|
|
1549
|
-
_iterator.f();
|
|
1550
|
-
}
|
|
1551
|
-
}
|
|
1552
|
-
|
|
1553
|
-
// on error, will return { str: string, errors: Error[] }
|
|
1554
|
-
function resolveString(doc, node) {
|
|
1555
|
-
var res = node.strValue;
|
|
1556
|
-
if (!res) return '';
|
|
1557
|
-
if (typeof res === 'string') return res;
|
|
1558
|
-
res.errors.forEach(function (error) {
|
|
1559
|
-
if (!error.source) error.source = node;
|
|
1560
|
-
doc.errors.push(error);
|
|
1561
|
-
});
|
|
1562
|
-
return res.str;
|
|
1563
|
-
}
|
|
1564
|
-
|
|
1565
|
-
function resolveTagHandle(doc, node) {
|
|
1566
|
-
var _node$tag = node.tag,
|
|
1567
|
-
handle = _node$tag.handle,
|
|
1568
|
-
suffix = _node$tag.suffix;
|
|
1569
|
-
var prefix = doc.tagPrefixes.find(function (p) {
|
|
1570
|
-
return p.handle === handle;
|
|
1571
|
-
});
|
|
1572
|
-
|
|
1573
|
-
if (!prefix) {
|
|
1574
|
-
var dtp = doc.getDefaults().tagPrefixes;
|
|
1575
|
-
if (dtp) prefix = dtp.find(function (p) {
|
|
1576
|
-
return p.handle === handle;
|
|
1577
|
-
});
|
|
1578
|
-
if (!prefix) throw new YAMLSemanticError(node, "The ".concat(handle, " tag handle is non-default and was not declared."));
|
|
1579
|
-
}
|
|
1580
|
-
|
|
1581
|
-
if (!suffix) throw new YAMLSemanticError(node, "The ".concat(handle, " tag has no suffix."));
|
|
1582
|
-
|
|
1583
|
-
if (handle === '!' && (doc.version || doc.options.version) === '1.0') {
|
|
1584
|
-
if (suffix[0] === '^') {
|
|
1585
|
-
doc.warnings.push(new YAMLWarning(node, 'YAML 1.0 ^ tag expansion is not supported'));
|
|
1586
|
-
return suffix;
|
|
1587
|
-
}
|
|
1588
|
-
|
|
1589
|
-
if (/[:/]/.test(suffix)) {
|
|
1590
|
-
// word/foo -> tag:word.yaml.org,2002:foo
|
|
1591
|
-
var vocab = suffix.match(/^([a-z0-9-]+)\/(.*)/i);
|
|
1592
|
-
return vocab ? "tag:".concat(vocab[1], ".yaml.org,2002:").concat(vocab[2]) : "tag:".concat(suffix);
|
|
1593
|
-
}
|
|
1594
|
-
}
|
|
1595
|
-
|
|
1596
|
-
return prefix.prefix + decodeURIComponent(suffix);
|
|
1597
|
-
}
|
|
1598
|
-
|
|
1599
|
-
function resolveTagName(doc, node) {
|
|
1600
|
-
var tag = node.tag,
|
|
1601
|
-
type = node.type;
|
|
1602
|
-
var nonSpecific = false;
|
|
1603
|
-
|
|
1604
|
-
if (tag) {
|
|
1605
|
-
var handle = tag.handle,
|
|
1606
|
-
suffix = tag.suffix,
|
|
1607
|
-
verbatim = tag.verbatim;
|
|
1608
|
-
|
|
1609
|
-
if (verbatim) {
|
|
1610
|
-
if (verbatim !== '!' && verbatim !== '!!') return verbatim;
|
|
1611
|
-
var msg = "Verbatim tags aren't resolved, so ".concat(verbatim, " is invalid.");
|
|
1612
|
-
doc.errors.push(new YAMLSemanticError(node, msg));
|
|
1613
|
-
} else if (handle === '!' && !suffix) {
|
|
1614
|
-
nonSpecific = true;
|
|
1615
|
-
} else {
|
|
1616
|
-
try {
|
|
1617
|
-
return resolveTagHandle(doc, node);
|
|
1618
|
-
} catch (error) {
|
|
1619
|
-
doc.errors.push(error);
|
|
1620
|
-
}
|
|
1621
|
-
}
|
|
1622
|
-
}
|
|
1623
|
-
|
|
1624
|
-
switch (type) {
|
|
1625
|
-
case Type.BLOCK_FOLDED:
|
|
1626
|
-
case Type.BLOCK_LITERAL:
|
|
1627
|
-
case Type.QUOTE_DOUBLE:
|
|
1628
|
-
case Type.QUOTE_SINGLE:
|
|
1629
|
-
return defaultTags.STR;
|
|
1630
|
-
|
|
1631
|
-
case Type.FLOW_MAP:
|
|
1632
|
-
case Type.MAP:
|
|
1633
|
-
return defaultTags.MAP;
|
|
1634
|
-
|
|
1635
|
-
case Type.FLOW_SEQ:
|
|
1636
|
-
case Type.SEQ:
|
|
1637
|
-
return defaultTags.SEQ;
|
|
1638
|
-
|
|
1639
|
-
case Type.PLAIN:
|
|
1640
|
-
return nonSpecific ? defaultTags.STR : null;
|
|
1641
|
-
|
|
1642
|
-
default:
|
|
1643
|
-
return null;
|
|
1644
|
-
}
|
|
1645
|
-
}
|
|
1646
|
-
|
|
1647
|
-
function resolveByTagName(doc, node, tagName) {
|
|
1648
|
-
var tags = doc.schema.tags;
|
|
1649
|
-
var matchWithTest = [];
|
|
1650
|
-
|
|
1651
|
-
var _iterator = _createForOfIteratorHelper(tags),
|
|
1652
|
-
_step;
|
|
1653
|
-
|
|
1654
|
-
try {
|
|
1655
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
1656
|
-
var tag = _step.value;
|
|
1657
|
-
|
|
1658
|
-
if (tag.tag === tagName) {
|
|
1659
|
-
if (tag.test) matchWithTest.push(tag);else {
|
|
1660
|
-
var res = tag.resolve(doc, node);
|
|
1661
|
-
return res instanceof Collection ? res : new Scalar(res);
|
|
1662
|
-
}
|
|
1663
|
-
}
|
|
1664
|
-
}
|
|
1665
|
-
} catch (err) {
|
|
1666
|
-
_iterator.e(err);
|
|
1667
|
-
} finally {
|
|
1668
|
-
_iterator.f();
|
|
1669
|
-
}
|
|
1670
|
-
|
|
1671
|
-
var str = resolveString(doc, node);
|
|
1672
|
-
if (typeof str === 'string' && matchWithTest.length > 0) return resolveScalar(str, matchWithTest, tags.scalarFallback);
|
|
1673
|
-
return null;
|
|
1674
|
-
}
|
|
1675
|
-
|
|
1676
|
-
function getFallbackTagName(_ref) {
|
|
1677
|
-
var type = _ref.type;
|
|
1678
|
-
|
|
1679
|
-
switch (type) {
|
|
1680
|
-
case Type.FLOW_MAP:
|
|
1681
|
-
case Type.MAP:
|
|
1682
|
-
return defaultTags.MAP;
|
|
1683
|
-
|
|
1684
|
-
case Type.FLOW_SEQ:
|
|
1685
|
-
case Type.SEQ:
|
|
1686
|
-
return defaultTags.SEQ;
|
|
1687
|
-
|
|
1688
|
-
default:
|
|
1689
|
-
return defaultTags.STR;
|
|
1690
|
-
}
|
|
1691
|
-
}
|
|
1692
|
-
|
|
1693
|
-
function resolveTag(doc, node, tagName) {
|
|
1694
|
-
try {
|
|
1695
|
-
var res = resolveByTagName(doc, node, tagName);
|
|
1696
|
-
|
|
1697
|
-
if (res) {
|
|
1698
|
-
if (tagName && node.tag) res.tag = tagName;
|
|
1699
|
-
return res;
|
|
1700
|
-
}
|
|
1701
|
-
} catch (error) {
|
|
1702
|
-
/* istanbul ignore if */
|
|
1703
|
-
if (!error.source) error.source = node;
|
|
1704
|
-
doc.errors.push(error);
|
|
1705
|
-
return null;
|
|
1706
|
-
}
|
|
1707
|
-
|
|
1708
|
-
try {
|
|
1709
|
-
var fallback = getFallbackTagName(node);
|
|
1710
|
-
if (!fallback) throw new Error("The tag ".concat(tagName, " is unavailable"));
|
|
1711
|
-
var msg = "The tag ".concat(tagName, " is unavailable, falling back to ").concat(fallback);
|
|
1712
|
-
doc.warnings.push(new YAMLWarning(node, msg));
|
|
1713
|
-
|
|
1714
|
-
var _res = resolveByTagName(doc, node, fallback);
|
|
1715
|
-
|
|
1716
|
-
_res.tag = tagName;
|
|
1717
|
-
return _res;
|
|
1718
|
-
} catch (error) {
|
|
1719
|
-
var refError = new YAMLReferenceError(node, error.message);
|
|
1720
|
-
refError.stack = error.stack;
|
|
1721
|
-
doc.errors.push(refError);
|
|
1722
|
-
return null;
|
|
1723
|
-
}
|
|
1724
|
-
}
|
|
1725
|
-
|
|
1726
|
-
var isCollectionItem = function isCollectionItem(node) {
|
|
1727
|
-
if (!node) return false;
|
|
1728
|
-
var type = node.type;
|
|
1729
|
-
return type === Type.MAP_KEY || type === Type.MAP_VALUE || type === Type.SEQ_ITEM;
|
|
1730
|
-
};
|
|
1731
|
-
|
|
1732
|
-
function resolveNodeProps(errors, node) {
|
|
1733
|
-
var comments = {
|
|
1734
|
-
before: [],
|
|
1735
|
-
after: []
|
|
1736
|
-
};
|
|
1737
|
-
var hasAnchor = false;
|
|
1738
|
-
var hasTag = false;
|
|
1739
|
-
var props = isCollectionItem(node.context.parent) ? node.context.parent.props.concat(node.props) : node.props;
|
|
1740
|
-
|
|
1741
|
-
var _iterator = _createForOfIteratorHelper(props),
|
|
1742
|
-
_step;
|
|
1743
|
-
|
|
1744
|
-
try {
|
|
1745
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
1746
|
-
var _step$value = _step.value,
|
|
1747
|
-
start = _step$value.start,
|
|
1748
|
-
end = _step$value.end;
|
|
1749
|
-
|
|
1750
|
-
switch (node.context.src[start]) {
|
|
1751
|
-
case Char.COMMENT:
|
|
1752
|
-
{
|
|
1753
|
-
if (!node.commentHasRequiredWhitespace(start)) {
|
|
1754
|
-
var msg = 'Comments must be separated from other tokens by white space characters';
|
|
1755
|
-
errors.push(new YAMLSemanticError(node, msg));
|
|
1756
|
-
}
|
|
1757
|
-
|
|
1758
|
-
var header = node.header,
|
|
1759
|
-
valueRange = node.valueRange;
|
|
1760
|
-
var cc = valueRange && (start > valueRange.start || header && start > header.start) ? comments.after : comments.before;
|
|
1761
|
-
cc.push(node.context.src.slice(start + 1, end));
|
|
1762
|
-
break;
|
|
1763
|
-
}
|
|
1764
|
-
// Actual anchor & tag resolution is handled by schema, here we just complain
|
|
1765
|
-
|
|
1766
|
-
case Char.ANCHOR:
|
|
1767
|
-
if (hasAnchor) {
|
|
1768
|
-
var _msg = 'A node can have at most one anchor';
|
|
1769
|
-
errors.push(new YAMLSemanticError(node, _msg));
|
|
1770
|
-
}
|
|
1771
|
-
|
|
1772
|
-
hasAnchor = true;
|
|
1773
|
-
break;
|
|
1774
|
-
|
|
1775
|
-
case Char.TAG:
|
|
1776
|
-
if (hasTag) {
|
|
1777
|
-
var _msg2 = 'A node can have at most one tag';
|
|
1778
|
-
errors.push(new YAMLSemanticError(node, _msg2));
|
|
1779
|
-
}
|
|
1780
|
-
|
|
1781
|
-
hasTag = true;
|
|
1782
|
-
break;
|
|
1783
|
-
}
|
|
1784
|
-
}
|
|
1785
|
-
} catch (err) {
|
|
1786
|
-
_iterator.e(err);
|
|
1787
|
-
} finally {
|
|
1788
|
-
_iterator.f();
|
|
1789
|
-
}
|
|
1790
|
-
|
|
1791
|
-
return {
|
|
1792
|
-
comments: comments,
|
|
1793
|
-
hasAnchor: hasAnchor,
|
|
1794
|
-
hasTag: hasTag
|
|
1795
|
-
};
|
|
1796
|
-
}
|
|
1797
|
-
|
|
1798
|
-
function resolveNodeValue(doc, node) {
|
|
1799
|
-
var anchors = doc.anchors,
|
|
1800
|
-
errors = doc.errors,
|
|
1801
|
-
schema = doc.schema;
|
|
1802
|
-
|
|
1803
|
-
if (node.type === Type.ALIAS) {
|
|
1804
|
-
var name = node.rawValue;
|
|
1805
|
-
var src = anchors.getNode(name);
|
|
1806
|
-
|
|
1807
|
-
if (!src) {
|
|
1808
|
-
var msg = "Aliased anchor not found: ".concat(name);
|
|
1809
|
-
errors.push(new YAMLReferenceError(node, msg));
|
|
1810
|
-
return null;
|
|
1811
|
-
} // Lazy resolution for circular references
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
var res = new Alias(src);
|
|
1815
|
-
|
|
1816
|
-
anchors._cstAliases.push(res);
|
|
1817
|
-
|
|
1818
|
-
return res;
|
|
1819
|
-
}
|
|
1820
|
-
|
|
1821
|
-
var tagName = resolveTagName(doc, node);
|
|
1822
|
-
if (tagName) return resolveTag(doc, node, tagName);
|
|
1823
|
-
|
|
1824
|
-
if (node.type !== Type.PLAIN) {
|
|
1825
|
-
var _msg3 = "Failed to resolve ".concat(node.type, " node here");
|
|
1826
|
-
|
|
1827
|
-
errors.push(new YAMLSyntaxError(node, _msg3));
|
|
1828
|
-
return null;
|
|
1829
|
-
}
|
|
1830
|
-
|
|
1831
|
-
try {
|
|
1832
|
-
var str = resolveString(doc, node);
|
|
1833
|
-
return resolveScalar(str, schema.tags, schema.tags.scalarFallback);
|
|
1834
|
-
} catch (error) {
|
|
1835
|
-
if (!error.source) error.source = node;
|
|
1836
|
-
errors.push(error);
|
|
1837
|
-
return null;
|
|
1838
|
-
}
|
|
1839
|
-
} // sets node.resolved on success
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
function resolveNode(doc, node) {
|
|
1843
|
-
if (!node) return null;
|
|
1844
|
-
if (node.error) doc.errors.push(node.error);
|
|
1845
|
-
|
|
1846
|
-
var _resolveNodeProps = resolveNodeProps(doc.errors, node),
|
|
1847
|
-
comments = _resolveNodeProps.comments,
|
|
1848
|
-
hasAnchor = _resolveNodeProps.hasAnchor,
|
|
1849
|
-
hasTag = _resolveNodeProps.hasTag;
|
|
1850
|
-
|
|
1851
|
-
if (hasAnchor) {
|
|
1852
|
-
var anchors = doc.anchors;
|
|
1853
|
-
var name = node.anchor;
|
|
1854
|
-
var prev = anchors.getNode(name); // At this point, aliases for any preceding node with the same anchor
|
|
1855
|
-
// name have already been resolved, so it may safely be renamed.
|
|
1856
|
-
|
|
1857
|
-
if (prev) anchors.map[anchors.newName(name)] = prev; // During parsing, we need to store the CST node in anchors.map as
|
|
1858
|
-
// anchors need to be available during resolution to allow for
|
|
1859
|
-
// circular references.
|
|
1860
|
-
|
|
1861
|
-
anchors.map[name] = node;
|
|
1862
|
-
}
|
|
1863
|
-
|
|
1864
|
-
if (node.type === Type.ALIAS && (hasAnchor || hasTag)) {
|
|
1865
|
-
var msg = 'An alias node must not specify any properties';
|
|
1866
|
-
doc.errors.push(new YAMLSemanticError(node, msg));
|
|
1867
|
-
}
|
|
1868
|
-
|
|
1869
|
-
var res = resolveNodeValue(doc, node);
|
|
1870
|
-
|
|
1871
|
-
if (res) {
|
|
1872
|
-
res.range = [node.range.start, node.range.end];
|
|
1873
|
-
if (doc.options.keepCstNodes) res.cstNode = node;
|
|
1874
|
-
if (doc.options.keepNodeTypes) res.type = node.type;
|
|
1875
|
-
var cb = comments.before.join('\n');
|
|
1876
|
-
|
|
1877
|
-
if (cb) {
|
|
1878
|
-
res.commentBefore = res.commentBefore ? "".concat(res.commentBefore, "\n").concat(cb) : cb;
|
|
1879
|
-
}
|
|
1880
|
-
|
|
1881
|
-
var ca = comments.after.join('\n');
|
|
1882
|
-
if (ca) res.comment = res.comment ? "".concat(res.comment, "\n").concat(ca) : ca;
|
|
1883
|
-
}
|
|
1884
|
-
|
|
1885
|
-
return node.resolved = res;
|
|
1886
|
-
}
|
|
1887
|
-
|
|
1888
|
-
function resolveMap(doc, cst) {
|
|
1889
|
-
if (cst.type !== Type.MAP && cst.type !== Type.FLOW_MAP) {
|
|
1890
|
-
var msg = "A ".concat(cst.type, " node cannot be resolved as a mapping");
|
|
1891
|
-
doc.errors.push(new YAMLSyntaxError(cst, msg));
|
|
1892
|
-
return null;
|
|
1893
|
-
}
|
|
1894
|
-
|
|
1895
|
-
var _ref = cst.type === Type.FLOW_MAP ? resolveFlowMapItems(doc, cst) : resolveBlockMapItems(doc, cst),
|
|
1896
|
-
comments = _ref.comments,
|
|
1897
|
-
items = _ref.items;
|
|
1898
|
-
|
|
1899
|
-
var map = new YAMLMap();
|
|
1900
|
-
map.items = items;
|
|
1901
|
-
resolveComments(map, comments);
|
|
1902
|
-
var hasCollectionKey = false;
|
|
1903
|
-
|
|
1904
|
-
for (var i = 0; i < items.length; ++i) {
|
|
1905
|
-
var iKey = items[i].key;
|
|
1906
|
-
if (iKey instanceof Collection) hasCollectionKey = true;
|
|
1907
|
-
|
|
1908
|
-
if (doc.schema.merge && iKey && iKey.value === MERGE_KEY) {
|
|
1909
|
-
items[i] = new Merge(items[i]);
|
|
1910
|
-
var sources = items[i].value.items;
|
|
1911
|
-
var error = null;
|
|
1912
|
-
sources.some(function (node) {
|
|
1913
|
-
if (node instanceof Alias) {
|
|
1914
|
-
// During parsing, alias sources are CST nodes; to account for
|
|
1915
|
-
// circular references their resolved values can't be used here.
|
|
1916
|
-
var type = node.source.type;
|
|
1917
|
-
if (type === Type.MAP || type === Type.FLOW_MAP) return false;
|
|
1918
|
-
return error = 'Merge nodes aliases can only point to maps';
|
|
1919
|
-
}
|
|
1920
|
-
|
|
1921
|
-
return error = 'Merge nodes can only have Alias nodes as values';
|
|
1922
|
-
});
|
|
1923
|
-
if (error) doc.errors.push(new YAMLSemanticError(cst, error));
|
|
1924
|
-
} else {
|
|
1925
|
-
for (var j = i + 1; j < items.length; ++j) {
|
|
1926
|
-
var jKey = items[j].key;
|
|
1927
|
-
|
|
1928
|
-
if (iKey === jKey || iKey && jKey && Object.prototype.hasOwnProperty.call(iKey, 'value') && iKey.value === jKey.value) {
|
|
1929
|
-
var _msg = "Map keys must be unique; \"".concat(iKey, "\" is repeated");
|
|
1930
|
-
|
|
1931
|
-
doc.errors.push(new YAMLSemanticError(cst, _msg));
|
|
1932
|
-
break;
|
|
1933
|
-
}
|
|
1934
|
-
}
|
|
1935
|
-
}
|
|
1936
|
-
}
|
|
1937
|
-
|
|
1938
|
-
if (hasCollectionKey && !doc.options.mapAsMap) {
|
|
1939
|
-
var warn = 'Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.';
|
|
1940
|
-
doc.warnings.push(new YAMLWarning(cst, warn));
|
|
1941
|
-
}
|
|
1942
|
-
|
|
1943
|
-
cst.resolved = map;
|
|
1944
|
-
return map;
|
|
1945
|
-
}
|
|
1946
|
-
|
|
1947
|
-
var valueHasPairComment = function valueHasPairComment(_ref2) {
|
|
1948
|
-
var _ref2$context = _ref2.context,
|
|
1949
|
-
lineStart = _ref2$context.lineStart,
|
|
1950
|
-
node = _ref2$context.node,
|
|
1951
|
-
src = _ref2$context.src,
|
|
1952
|
-
props = _ref2.props;
|
|
1953
|
-
if (props.length === 0) return false;
|
|
1954
|
-
var start = props[0].start;
|
|
1955
|
-
if (node && start > node.valueRange.start) return false;
|
|
1956
|
-
if (src[start] !== Char.COMMENT) return false;
|
|
1957
|
-
|
|
1958
|
-
for (var i = lineStart; i < start; ++i) {
|
|
1959
|
-
if (src[i] === '\n') return false;
|
|
1960
|
-
}
|
|
1961
|
-
|
|
1962
|
-
return true;
|
|
1963
|
-
};
|
|
1964
|
-
|
|
1965
|
-
function resolvePairComment(item, pair) {
|
|
1966
|
-
if (!valueHasPairComment(item)) return;
|
|
1967
|
-
var comment = item.getPropValue(0, Char.COMMENT, true);
|
|
1968
|
-
var found = false;
|
|
1969
|
-
var cb = pair.value.commentBefore;
|
|
1970
|
-
|
|
1971
|
-
if (cb && cb.startsWith(comment)) {
|
|
1972
|
-
pair.value.commentBefore = cb.substr(comment.length + 1);
|
|
1973
|
-
found = true;
|
|
1974
|
-
} else {
|
|
1975
|
-
var cc = pair.value.comment;
|
|
1976
|
-
|
|
1977
|
-
if (!item.node && cc && cc.startsWith(comment)) {
|
|
1978
|
-
pair.value.comment = cc.substr(comment.length + 1);
|
|
1979
|
-
found = true;
|
|
1980
|
-
}
|
|
1981
|
-
}
|
|
1982
|
-
|
|
1983
|
-
if (found) pair.comment = comment;
|
|
1984
|
-
}
|
|
1985
|
-
|
|
1986
|
-
function resolveBlockMapItems(doc, cst) {
|
|
1987
|
-
var comments = [];
|
|
1988
|
-
var items = [];
|
|
1989
|
-
var key = undefined;
|
|
1990
|
-
var keyStart = null;
|
|
1991
|
-
|
|
1992
|
-
for (var i = 0; i < cst.items.length; ++i) {
|
|
1993
|
-
var item = cst.items[i];
|
|
1994
|
-
|
|
1995
|
-
switch (item.type) {
|
|
1996
|
-
case Type.BLANK_LINE:
|
|
1997
|
-
comments.push({
|
|
1998
|
-
afterKey: !!key,
|
|
1999
|
-
before: items.length
|
|
2000
|
-
});
|
|
2001
|
-
break;
|
|
2002
|
-
|
|
2003
|
-
case Type.COMMENT:
|
|
2004
|
-
comments.push({
|
|
2005
|
-
afterKey: !!key,
|
|
2006
|
-
before: items.length,
|
|
2007
|
-
comment: item.comment
|
|
2008
|
-
});
|
|
2009
|
-
break;
|
|
2010
|
-
|
|
2011
|
-
case Type.MAP_KEY:
|
|
2012
|
-
if (key !== undefined) items.push(new Pair(key));
|
|
2013
|
-
if (item.error) doc.errors.push(item.error);
|
|
2014
|
-
key = resolveNode(doc, item.node);
|
|
2015
|
-
keyStart = null;
|
|
2016
|
-
break;
|
|
2017
|
-
|
|
2018
|
-
case Type.MAP_VALUE:
|
|
2019
|
-
{
|
|
2020
|
-
if (key === undefined) key = null;
|
|
2021
|
-
if (item.error) doc.errors.push(item.error);
|
|
2022
|
-
|
|
2023
|
-
if (!item.context.atLineStart && item.node && item.node.type === Type.MAP && !item.node.context.atLineStart) {
|
|
2024
|
-
var msg = 'Nested mappings are not allowed in compact mappings';
|
|
2025
|
-
doc.errors.push(new YAMLSemanticError(item.node, msg));
|
|
2026
|
-
}
|
|
2027
|
-
|
|
2028
|
-
var valueNode = item.node;
|
|
2029
|
-
|
|
2030
|
-
if (!valueNode && item.props.length > 0) {
|
|
2031
|
-
// Comments on an empty mapping value need to be preserved, so we
|
|
2032
|
-
// need to construct a minimal empty node here to use instead of the
|
|
2033
|
-
// missing `item.node`. -- eemeli/yaml#19
|
|
2034
|
-
valueNode = new PlainValue(Type.PLAIN, []);
|
|
2035
|
-
valueNode.context = {
|
|
2036
|
-
parent: item,
|
|
2037
|
-
src: item.context.src
|
|
2038
|
-
};
|
|
2039
|
-
var pos = item.range.start + 1;
|
|
2040
|
-
valueNode.range = {
|
|
2041
|
-
start: pos,
|
|
2042
|
-
end: pos
|
|
2043
|
-
};
|
|
2044
|
-
valueNode.valueRange = {
|
|
2045
|
-
start: pos,
|
|
2046
|
-
end: pos
|
|
2047
|
-
};
|
|
2048
|
-
|
|
2049
|
-
if (typeof item.range.origStart === 'number') {
|
|
2050
|
-
var origPos = item.range.origStart + 1;
|
|
2051
|
-
valueNode.range.origStart = valueNode.range.origEnd = origPos;
|
|
2052
|
-
valueNode.valueRange.origStart = valueNode.valueRange.origEnd = origPos;
|
|
2053
|
-
}
|
|
2054
|
-
}
|
|
2055
|
-
|
|
2056
|
-
var pair = new Pair(key, resolveNode(doc, valueNode));
|
|
2057
|
-
resolvePairComment(item, pair);
|
|
2058
|
-
items.push(pair);
|
|
2059
|
-
|
|
2060
|
-
if (key && typeof keyStart === 'number') {
|
|
2061
|
-
if (item.range.start > keyStart + 1024) doc.errors.push(getLongKeyError(cst, key));
|
|
2062
|
-
}
|
|
2063
|
-
|
|
2064
|
-
key = undefined;
|
|
2065
|
-
keyStart = null;
|
|
2066
|
-
}
|
|
2067
|
-
break;
|
|
2068
|
-
|
|
2069
|
-
default:
|
|
2070
|
-
if (key !== undefined) items.push(new Pair(key));
|
|
2071
|
-
key = resolveNode(doc, item);
|
|
2072
|
-
keyStart = item.range.start;
|
|
2073
|
-
if (item.error) doc.errors.push(item.error);
|
|
2074
|
-
|
|
2075
|
-
next: for (var j = i + 1;; ++j) {
|
|
2076
|
-
var nextItem = cst.items[j];
|
|
2077
|
-
|
|
2078
|
-
switch (nextItem && nextItem.type) {
|
|
2079
|
-
case Type.BLANK_LINE:
|
|
2080
|
-
case Type.COMMENT:
|
|
2081
|
-
continue next;
|
|
2082
|
-
|
|
2083
|
-
case Type.MAP_VALUE:
|
|
2084
|
-
break next;
|
|
2085
|
-
|
|
2086
|
-
default:
|
|
2087
|
-
{
|
|
2088
|
-
var _msg2 = 'Implicit map keys need to be followed by map values';
|
|
2089
|
-
doc.errors.push(new YAMLSemanticError(item, _msg2));
|
|
2090
|
-
break next;
|
|
2091
|
-
}
|
|
2092
|
-
}
|
|
2093
|
-
}
|
|
2094
|
-
|
|
2095
|
-
if (item.valueRangeContainsNewline) {
|
|
2096
|
-
var _msg3 = 'Implicit map keys need to be on a single line';
|
|
2097
|
-
doc.errors.push(new YAMLSemanticError(item, _msg3));
|
|
2098
|
-
}
|
|
2099
|
-
|
|
2100
|
-
}
|
|
2101
|
-
}
|
|
2102
|
-
|
|
2103
|
-
if (key !== undefined) items.push(new Pair(key));
|
|
2104
|
-
return {
|
|
2105
|
-
comments: comments,
|
|
2106
|
-
items: items
|
|
2107
|
-
};
|
|
2108
|
-
}
|
|
2109
|
-
|
|
2110
|
-
function resolveFlowMapItems(doc, cst) {
|
|
2111
|
-
var comments = [];
|
|
2112
|
-
var items = [];
|
|
2113
|
-
var key = undefined;
|
|
2114
|
-
var explicitKey = false;
|
|
2115
|
-
var next = '{';
|
|
2116
|
-
|
|
2117
|
-
for (var i = 0; i < cst.items.length; ++i) {
|
|
2118
|
-
var item = cst.items[i];
|
|
2119
|
-
|
|
2120
|
-
if (typeof item.char === 'string') {
|
|
2121
|
-
var char = item.char,
|
|
2122
|
-
offset = item.offset;
|
|
2123
|
-
|
|
2124
|
-
if (char === '?' && key === undefined && !explicitKey) {
|
|
2125
|
-
explicitKey = true;
|
|
2126
|
-
next = ':';
|
|
2127
|
-
continue;
|
|
2128
|
-
}
|
|
2129
|
-
|
|
2130
|
-
if (char === ':') {
|
|
2131
|
-
if (key === undefined) key = null;
|
|
2132
|
-
|
|
2133
|
-
if (next === ':') {
|
|
2134
|
-
next = ',';
|
|
2135
|
-
continue;
|
|
2136
|
-
}
|
|
2137
|
-
} else {
|
|
2138
|
-
if (explicitKey) {
|
|
2139
|
-
if (key === undefined && char !== ',') key = null;
|
|
2140
|
-
explicitKey = false;
|
|
2141
|
-
}
|
|
2142
|
-
|
|
2143
|
-
if (key !== undefined) {
|
|
2144
|
-
items.push(new Pair(key));
|
|
2145
|
-
key = undefined;
|
|
2146
|
-
|
|
2147
|
-
if (char === ',') {
|
|
2148
|
-
next = ':';
|
|
2149
|
-
continue;
|
|
2150
|
-
}
|
|
2151
|
-
}
|
|
2152
|
-
}
|
|
2153
|
-
|
|
2154
|
-
if (char === '}') {
|
|
2155
|
-
if (i === cst.items.length - 1) continue;
|
|
2156
|
-
} else if (char === next) {
|
|
2157
|
-
next = ':';
|
|
2158
|
-
continue;
|
|
2159
|
-
}
|
|
2160
|
-
|
|
2161
|
-
var msg = "Flow map contains an unexpected ".concat(char);
|
|
2162
|
-
var err = new YAMLSyntaxError(cst, msg);
|
|
2163
|
-
err.offset = offset;
|
|
2164
|
-
doc.errors.push(err);
|
|
2165
|
-
} else if (item.type === Type.BLANK_LINE) {
|
|
2166
|
-
comments.push({
|
|
2167
|
-
afterKey: !!key,
|
|
2168
|
-
before: items.length
|
|
2169
|
-
});
|
|
2170
|
-
} else if (item.type === Type.COMMENT) {
|
|
2171
|
-
checkFlowCommentSpace(doc.errors, item);
|
|
2172
|
-
comments.push({
|
|
2173
|
-
afterKey: !!key,
|
|
2174
|
-
before: items.length,
|
|
2175
|
-
comment: item.comment
|
|
2176
|
-
});
|
|
2177
|
-
} else if (key === undefined) {
|
|
2178
|
-
if (next === ',') doc.errors.push(new YAMLSemanticError(item, 'Separator , missing in flow map'));
|
|
2179
|
-
key = resolveNode(doc, item);
|
|
2180
|
-
} else {
|
|
2181
|
-
if (next !== ',') doc.errors.push(new YAMLSemanticError(item, 'Indicator : missing in flow map entry'));
|
|
2182
|
-
items.push(new Pair(key, resolveNode(doc, item)));
|
|
2183
|
-
key = undefined;
|
|
2184
|
-
explicitKey = false;
|
|
2185
|
-
}
|
|
2186
|
-
}
|
|
2187
|
-
|
|
2188
|
-
checkFlowCollectionEnd(doc.errors, cst);
|
|
2189
|
-
if (key !== undefined) items.push(new Pair(key));
|
|
2190
|
-
return {
|
|
2191
|
-
comments: comments,
|
|
2192
|
-
items: items
|
|
2193
|
-
};
|
|
2194
|
-
}
|
|
2195
|
-
|
|
2196
|
-
function resolveSeq(doc, cst) {
|
|
2197
|
-
if (cst.type !== Type.SEQ && cst.type !== Type.FLOW_SEQ) {
|
|
2198
|
-
var msg = "A ".concat(cst.type, " node cannot be resolved as a sequence");
|
|
2199
|
-
doc.errors.push(new YAMLSyntaxError(cst, msg));
|
|
2200
|
-
return null;
|
|
2201
|
-
}
|
|
2202
|
-
|
|
2203
|
-
var _ref = cst.type === Type.FLOW_SEQ ? resolveFlowSeqItems(doc, cst) : resolveBlockSeqItems(doc, cst),
|
|
2204
|
-
comments = _ref.comments,
|
|
2205
|
-
items = _ref.items;
|
|
2206
|
-
|
|
2207
|
-
var seq = new YAMLSeq();
|
|
2208
|
-
seq.items = items;
|
|
2209
|
-
resolveComments(seq, comments);
|
|
2210
|
-
|
|
2211
|
-
if (!doc.options.mapAsMap && items.some(function (it) {
|
|
2212
|
-
return it instanceof Pair && it.key instanceof Collection;
|
|
2213
|
-
})) {
|
|
2214
|
-
var warn = 'Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.';
|
|
2215
|
-
doc.warnings.push(new YAMLWarning(cst, warn));
|
|
2216
|
-
}
|
|
2217
|
-
|
|
2218
|
-
cst.resolved = seq;
|
|
2219
|
-
return seq;
|
|
2220
|
-
}
|
|
2221
|
-
|
|
2222
|
-
function resolveBlockSeqItems(doc, cst) {
|
|
2223
|
-
var comments = [];
|
|
2224
|
-
var items = [];
|
|
2225
|
-
|
|
2226
|
-
for (var i = 0; i < cst.items.length; ++i) {
|
|
2227
|
-
var item = cst.items[i];
|
|
2228
|
-
|
|
2229
|
-
switch (item.type) {
|
|
2230
|
-
case Type.BLANK_LINE:
|
|
2231
|
-
comments.push({
|
|
2232
|
-
before: items.length
|
|
2233
|
-
});
|
|
2234
|
-
break;
|
|
2235
|
-
|
|
2236
|
-
case Type.COMMENT:
|
|
2237
|
-
comments.push({
|
|
2238
|
-
comment: item.comment,
|
|
2239
|
-
before: items.length
|
|
2240
|
-
});
|
|
2241
|
-
break;
|
|
2242
|
-
|
|
2243
|
-
case Type.SEQ_ITEM:
|
|
2244
|
-
if (item.error) doc.errors.push(item.error);
|
|
2245
|
-
items.push(resolveNode(doc, item.node));
|
|
2246
|
-
|
|
2247
|
-
if (item.hasProps) {
|
|
2248
|
-
var msg = 'Sequence items cannot have tags or anchors before the - indicator';
|
|
2249
|
-
doc.errors.push(new YAMLSemanticError(item, msg));
|
|
2250
|
-
}
|
|
2251
|
-
|
|
2252
|
-
break;
|
|
2253
|
-
|
|
2254
|
-
default:
|
|
2255
|
-
if (item.error) doc.errors.push(item.error);
|
|
2256
|
-
doc.errors.push(new YAMLSyntaxError(item, "Unexpected ".concat(item.type, " node in sequence")));
|
|
2257
|
-
}
|
|
2258
|
-
}
|
|
2259
|
-
|
|
2260
|
-
return {
|
|
2261
|
-
comments: comments,
|
|
2262
|
-
items: items
|
|
2263
|
-
};
|
|
2264
|
-
}
|
|
2265
|
-
|
|
2266
|
-
function resolveFlowSeqItems(doc, cst) {
|
|
2267
|
-
var comments = [];
|
|
2268
|
-
var items = [];
|
|
2269
|
-
var explicitKey = false;
|
|
2270
|
-
var key = undefined;
|
|
2271
|
-
var keyStart = null;
|
|
2272
|
-
var next = '[';
|
|
2273
|
-
var prevItem = null;
|
|
2274
|
-
|
|
2275
|
-
for (var i = 0; i < cst.items.length; ++i) {
|
|
2276
|
-
var item = cst.items[i];
|
|
2277
|
-
|
|
2278
|
-
if (typeof item.char === 'string') {
|
|
2279
|
-
var char = item.char,
|
|
2280
|
-
offset = item.offset;
|
|
2281
|
-
|
|
2282
|
-
if (char !== ':' && (explicitKey || key !== undefined)) {
|
|
2283
|
-
if (explicitKey && key === undefined) key = next ? items.pop() : null;
|
|
2284
|
-
items.push(new Pair(key));
|
|
2285
|
-
explicitKey = false;
|
|
2286
|
-
key = undefined;
|
|
2287
|
-
keyStart = null;
|
|
2288
|
-
}
|
|
2289
|
-
|
|
2290
|
-
if (char === next) {
|
|
2291
|
-
next = null;
|
|
2292
|
-
} else if (!next && char === '?') {
|
|
2293
|
-
explicitKey = true;
|
|
2294
|
-
} else if (next !== '[' && char === ':' && key === undefined) {
|
|
2295
|
-
if (next === ',') {
|
|
2296
|
-
key = items.pop();
|
|
2297
|
-
|
|
2298
|
-
if (key instanceof Pair) {
|
|
2299
|
-
var msg = 'Chaining flow sequence pairs is invalid';
|
|
2300
|
-
var err = new YAMLSemanticError(cst, msg);
|
|
2301
|
-
err.offset = offset;
|
|
2302
|
-
doc.errors.push(err);
|
|
2303
|
-
}
|
|
2304
|
-
|
|
2305
|
-
if (!explicitKey && typeof keyStart === 'number') {
|
|
2306
|
-
var keyEnd = item.range ? item.range.start : item.offset;
|
|
2307
|
-
if (keyEnd > keyStart + 1024) doc.errors.push(getLongKeyError(cst, key));
|
|
2308
|
-
var src = prevItem.context.src;
|
|
2309
|
-
|
|
2310
|
-
for (var _i = keyStart; _i < keyEnd; ++_i) {
|
|
2311
|
-
if (src[_i] === '\n') {
|
|
2312
|
-
var _msg = 'Implicit keys of flow sequence pairs need to be on a single line';
|
|
2313
|
-
doc.errors.push(new YAMLSemanticError(prevItem, _msg));
|
|
2314
|
-
break;
|
|
2315
|
-
}
|
|
2316
|
-
}
|
|
2317
|
-
}
|
|
2318
|
-
} else {
|
|
2319
|
-
key = null;
|
|
2320
|
-
}
|
|
2321
|
-
|
|
2322
|
-
keyStart = null;
|
|
2323
|
-
explicitKey = false;
|
|
2324
|
-
next = null;
|
|
2325
|
-
} else if (next === '[' || char !== ']' || i < cst.items.length - 1) {
|
|
2326
|
-
var _msg2 = "Flow sequence contains an unexpected ".concat(char);
|
|
2327
|
-
|
|
2328
|
-
var _err = new YAMLSyntaxError(cst, _msg2);
|
|
2329
|
-
|
|
2330
|
-
_err.offset = offset;
|
|
2331
|
-
doc.errors.push(_err);
|
|
2332
|
-
}
|
|
2333
|
-
} else if (item.type === Type.BLANK_LINE) {
|
|
2334
|
-
comments.push({
|
|
2335
|
-
before: items.length
|
|
2336
|
-
});
|
|
2337
|
-
} else if (item.type === Type.COMMENT) {
|
|
2338
|
-
checkFlowCommentSpace(doc.errors, item);
|
|
2339
|
-
comments.push({
|
|
2340
|
-
comment: item.comment,
|
|
2341
|
-
before: items.length
|
|
2342
|
-
});
|
|
2343
|
-
} else {
|
|
2344
|
-
if (next) {
|
|
2345
|
-
var _msg3 = "Expected a ".concat(next, " in flow sequence");
|
|
2346
|
-
|
|
2347
|
-
doc.errors.push(new YAMLSemanticError(item, _msg3));
|
|
2348
|
-
}
|
|
2349
|
-
|
|
2350
|
-
var value = resolveNode(doc, item);
|
|
2351
|
-
|
|
2352
|
-
if (key === undefined) {
|
|
2353
|
-
items.push(value);
|
|
2354
|
-
prevItem = item;
|
|
2355
|
-
} else {
|
|
2356
|
-
items.push(new Pair(key, value));
|
|
2357
|
-
key = undefined;
|
|
2358
|
-
}
|
|
2359
|
-
|
|
2360
|
-
keyStart = item.range.start;
|
|
2361
|
-
next = ',';
|
|
2362
|
-
}
|
|
2363
|
-
}
|
|
2364
|
-
|
|
2365
|
-
checkFlowCollectionEnd(doc.errors, cst);
|
|
2366
|
-
if (key !== undefined) items.push(new Pair(key));
|
|
2367
|
-
return {
|
|
2368
|
-
comments: comments,
|
|
2369
|
-
items: items
|
|
2370
|
-
};
|
|
2371
|
-
}
|
|
2372
|
-
|
|
2373
|
-
export { Alias as A, Collection as C, Merge as M, Node as N, Pair as P, Scalar as S, YAMLSeq as Y, boolOptions as a, binaryOptions as b, stringifyString as c, YAMLMap as d, isEmptyPath as e, addComment as f, resolveMap as g, resolveSeq as h, intOptions as i, resolveString as j, stringifyNumber as k, findPair as l, nullOptions as n, resolveNode as r, strOptions as s, toJSON as t };
|
|
1498
|
+
export { Alias as A, Collection as C, Node as N, Pair as P, Scalar as S, YAMLSeq as Y, boolOptions as a, binaryOptions as b, stringifyString as c, YAMLMap as d, createNode as e, isEmptyPath as f, collectionFromPath as g, addComment as h, intOptions as i, createPair as j, stringifyNumber as k, findPair as l, nullOptions as n, resolveScalar as r, strOptions as s, toJS as t };
|