yaml 2.0.0-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 +8 -9
- package/browser/dist/{Schema-d14032c2.js → Schema-ea978338.js} +291 -127
- package/browser/dist/{PlainValue-6b68dc0e.js → errors-2634d01a.js} +1 -181
- package/browser/dist/index.js +1085 -73
- package/browser/dist/parse-cst.js +2 -2
- package/browser/dist/{parse-6e806192.js → parse-d1ba890f.js} +182 -2
- package/browser/dist/{resolveSeq-3477c430.js → stringifyNumber-d8af95b1.js} +89 -1069
- package/browser/dist/types.js +3 -3
- package/browser/dist/util.js +2 -2
- package/browser/index.js +1 -1
- package/dist/Document-f89a2614.js +1783 -0
- package/dist/{Schema-fe1471c4.js → Schema-807430ba.js} +289 -163
- package/dist/{PlainValue-ec8e588e.js → _rollupPluginBabelHelpers-eed30217.js} +0 -167
- package/dist/index.js +43 -33
- package/dist/{parse-ab8de154.js → parse-3997f544.js} +313 -146
- package/dist/parse-cst.js +2 -2
- package/dist/{resolveSeq-6b2dc4ac.js → stringifyNumber-dea1120c.js} +107 -1038
- package/dist/test-events.js +5 -5
- package/dist/types.js +16 -16
- package/dist/util.js +12 -14
- package/index.d.ts +67 -23
- package/index.js +1 -1
- package/package.json +12 -12
- package/types.d.ts +9 -9
- package/util.d.ts +2 -12
- package/util.js +0 -2
- package/util.mjs +0 -3
- package/dist/Document-59bd9290.js +0 -803
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { b as _classCallCheck,
|
|
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,7 +39,7 @@ 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
|
|
|
@@ -53,8 +63,8 @@ var Scalar = /*#__PURE__*/function (_Node) {
|
|
|
53
63
|
|
|
54
64
|
_createClass(Scalar, [{
|
|
55
65
|
key: "toJSON",
|
|
56
|
-
value: function toJSON
|
|
57
|
-
return ctx && ctx.keep ? this.value :
|
|
66
|
+
value: function toJSON(arg, ctx) {
|
|
67
|
+
return ctx && ctx.keep ? this.value : toJS(this.value, arg, ctx);
|
|
58
68
|
}
|
|
59
69
|
}, {
|
|
60
70
|
key: "toString",
|
|
@@ -98,7 +108,7 @@ function createNode(value, tagName, ctx) {
|
|
|
98
108
|
|
|
99
109
|
if (!tagObj) {
|
|
100
110
|
if (typeof value.toJSON === 'function') value = value.toJSON();
|
|
101
|
-
if (_typeof(value) !== 'object') return wrapScalars ? new Scalar(value) : value;
|
|
111
|
+
if (!value || _typeof(value) !== 'object') return wrapScalars ? new Scalar(value) : value;
|
|
102
112
|
tagObj = value instanceof Map ? map : value[Symbol.iterator] ? seq : map;
|
|
103
113
|
}
|
|
104
114
|
|
|
@@ -109,7 +119,10 @@ function createNode(value, tagName, ctx) {
|
|
|
109
119
|
// after first. The `obj` wrapper allows for circular references to resolve.
|
|
110
120
|
|
|
111
121
|
|
|
112
|
-
var obj = {
|
|
122
|
+
var obj = {
|
|
123
|
+
value: undefined,
|
|
124
|
+
node: undefined
|
|
125
|
+
};
|
|
113
126
|
|
|
114
127
|
if (value && _typeof(value) === 'object') {
|
|
115
128
|
var prev = prevObjects.get(value);
|
|
@@ -128,9 +141,21 @@ function collectionFromPath(schema, path, value) {
|
|
|
128
141
|
|
|
129
142
|
for (var i = path.length - 1; i >= 0; --i) {
|
|
130
143
|
var k = path[i];
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
|
+
}
|
|
134
159
|
}
|
|
135
160
|
|
|
136
161
|
return createNode(v, null, {
|
|
@@ -230,9 +255,8 @@ var Collection = /*#__PURE__*/function (_Node) {
|
|
|
230
255
|
var node = this.get(key, true);
|
|
231
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));
|
|
232
257
|
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/* istanbul ignore next */
|
|
258
|
+
}
|
|
259
|
+
/* istanbul ignore next: overridden in implementations */
|
|
236
260
|
|
|
237
261
|
}, {
|
|
238
262
|
key: "toJSON",
|
|
@@ -419,7 +443,7 @@ var YAMLSeq = /*#__PURE__*/function (_Collection) {
|
|
|
419
443
|
}
|
|
420
444
|
}, {
|
|
421
445
|
key: "toJSON",
|
|
422
|
-
value: function toJSON
|
|
446
|
+
value: function toJSON(_, ctx) {
|
|
423
447
|
var seq = [];
|
|
424
448
|
if (ctx && ctx.onCreate) ctx.onCreate(seq);
|
|
425
449
|
var i = 0;
|
|
@@ -430,7 +454,7 @@ var YAMLSeq = /*#__PURE__*/function (_Collection) {
|
|
|
430
454
|
try {
|
|
431
455
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
432
456
|
var item = _step.value;
|
|
433
|
-
seq.push(
|
|
457
|
+
seq.push(toJS(item, String(i++), ctx));
|
|
434
458
|
}
|
|
435
459
|
} catch (err) {
|
|
436
460
|
_iterator.e(err);
|
|
@@ -465,7 +489,7 @@ var stringifyKey = function stringifyKey(key, jsKey, ctx) {
|
|
|
465
489
|
if (jsKey === null) return '';
|
|
466
490
|
if (_typeof(jsKey) !== 'object') return String(jsKey);
|
|
467
491
|
if (key instanceof Node && ctx && ctx.doc) return key.toString({
|
|
468
|
-
anchors:
|
|
492
|
+
anchors: Object.create(null),
|
|
469
493
|
doc: ctx.doc,
|
|
470
494
|
indent: '',
|
|
471
495
|
indentStep: ctx.indentStep,
|
|
@@ -503,16 +527,24 @@ var Pair = /*#__PURE__*/function (_Node) {
|
|
|
503
527
|
_createClass(Pair, [{
|
|
504
528
|
key: "addToJSMap",
|
|
505
529
|
value: function addToJSMap(ctx, map) {
|
|
506
|
-
var key =
|
|
530
|
+
var key = toJS(this.key, '', ctx);
|
|
507
531
|
|
|
508
532
|
if (map instanceof Map) {
|
|
509
|
-
var value =
|
|
533
|
+
var value = toJS(this.value, key, ctx);
|
|
510
534
|
map.set(key, value);
|
|
511
535
|
} else if (map instanceof Set) {
|
|
512
536
|
map.add(key);
|
|
513
537
|
} else {
|
|
514
538
|
var stringKey = stringifyKey(this.key, key, ctx);
|
|
515
|
-
|
|
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;
|
|
516
548
|
}
|
|
517
549
|
|
|
518
550
|
return map;
|
|
@@ -574,6 +606,15 @@ var Pair = /*#__PURE__*/function (_Node) {
|
|
|
574
606
|
return ctx.inFlow ? str : "? ".concat(str);
|
|
575
607
|
}
|
|
576
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
|
+
|
|
577
618
|
str = explicitKey ? "? ".concat(str, "\n").concat(indent, ":") : "".concat(str, ":");
|
|
578
619
|
|
|
579
620
|
if (this.comment) {
|
|
@@ -619,7 +660,7 @@ var Pair = /*#__PURE__*/function (_Node) {
|
|
|
619
660
|
} else if (!explicitKey && value instanceof Collection) {
|
|
620
661
|
var flow = valueStr[0] === '[' || valueStr[0] === '{';
|
|
621
662
|
if (!flow || valueStr.includes('\n')) ws = "\n".concat(ctx.indent);
|
|
622
|
-
}
|
|
663
|
+
} else if (valueStr[0] === '\n') ws = '';
|
|
623
664
|
|
|
624
665
|
if (chompKeep && !valueComment && onChompKeep) onChompKeep();
|
|
625
666
|
return addComment(str + ws + valueStr, ctx.indent, valueComment);
|
|
@@ -715,8 +756,8 @@ var Alias = /*#__PURE__*/function (_Node) {
|
|
|
715
756
|
|
|
716
757
|
_createClass(Alias, [{
|
|
717
758
|
key: "toJSON",
|
|
718
|
-
value: function toJSON
|
|
719
|
-
if (!ctx) return
|
|
759
|
+
value: function toJSON(arg, ctx) {
|
|
760
|
+
if (!ctx) return toJS(this.source, arg, ctx);
|
|
720
761
|
var anchors = ctx.anchors,
|
|
721
762
|
maxAliasCount = ctx.maxAliasCount;
|
|
722
763
|
var anchor = anchors.get(this.source);
|
|
@@ -838,10 +879,9 @@ var YAMLMap = /*#__PURE__*/function (_Collection) {
|
|
|
838
879
|
this.add(new Pair(key, value), true);
|
|
839
880
|
}
|
|
840
881
|
/**
|
|
841
|
-
* @param
|
|
842
|
-
* @param {
|
|
843
|
-
* @
|
|
844
|
-
* @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
|
|
845
885
|
*/
|
|
846
886
|
|
|
847
887
|
}, {
|
|
@@ -902,103 +942,6 @@ var YAMLMap = /*#__PURE__*/function (_Collection) {
|
|
|
902
942
|
return YAMLMap;
|
|
903
943
|
}(Collection);
|
|
904
944
|
|
|
905
|
-
var MERGE_KEY = '<<';
|
|
906
|
-
var Merge = /*#__PURE__*/function (_Pair) {
|
|
907
|
-
_inherits(Merge, _Pair);
|
|
908
|
-
|
|
909
|
-
var _super = _createSuper(Merge);
|
|
910
|
-
|
|
911
|
-
function Merge(pair) {
|
|
912
|
-
var _this;
|
|
913
|
-
|
|
914
|
-
_classCallCheck(this, Merge);
|
|
915
|
-
|
|
916
|
-
if (pair instanceof Pair) {
|
|
917
|
-
var seq = pair.value;
|
|
918
|
-
|
|
919
|
-
if (!(seq instanceof YAMLSeq)) {
|
|
920
|
-
seq = new YAMLSeq();
|
|
921
|
-
seq.items.push(pair.value);
|
|
922
|
-
seq.range = pair.value.range;
|
|
923
|
-
}
|
|
924
|
-
|
|
925
|
-
_this = _super.call(this, pair.key, seq);
|
|
926
|
-
_this.range = pair.range;
|
|
927
|
-
} else {
|
|
928
|
-
_this = _super.call(this, new Scalar(MERGE_KEY), new YAMLSeq());
|
|
929
|
-
}
|
|
930
|
-
|
|
931
|
-
_this.type = Pair.Type.MERGE_PAIR;
|
|
932
|
-
return _possibleConstructorReturn(_this);
|
|
933
|
-
} // If the value associated with a merge key is a single mapping node, each of
|
|
934
|
-
// its key/value pairs is inserted into the current mapping, unless the key
|
|
935
|
-
// already exists in it. If the value associated with the merge key is a
|
|
936
|
-
// sequence, then this sequence is expected to contain mapping nodes and each
|
|
937
|
-
// of these nodes is merged in turn according to its order in the sequence.
|
|
938
|
-
// Keys in mapping nodes earlier in the sequence override keys specified in
|
|
939
|
-
// later mapping nodes. -- http://yaml.org/type/merge.html
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
_createClass(Merge, [{
|
|
943
|
-
key: "addToJSMap",
|
|
944
|
-
value: function addToJSMap(ctx, map) {
|
|
945
|
-
var _iterator = _createForOfIteratorHelper(this.value.items),
|
|
946
|
-
_step;
|
|
947
|
-
|
|
948
|
-
try {
|
|
949
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
950
|
-
var source = _step.value.source;
|
|
951
|
-
if (!(source instanceof YAMLMap)) throw new Error('Merge sources must be maps');
|
|
952
|
-
var srcMap = source.toJSON(null, ctx, Map);
|
|
953
|
-
|
|
954
|
-
var _iterator2 = _createForOfIteratorHelper(srcMap),
|
|
955
|
-
_step2;
|
|
956
|
-
|
|
957
|
-
try {
|
|
958
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
959
|
-
var _step2$value = _slicedToArray(_step2.value, 2),
|
|
960
|
-
key = _step2$value[0],
|
|
961
|
-
value = _step2$value[1];
|
|
962
|
-
|
|
963
|
-
if (map instanceof Map) {
|
|
964
|
-
if (!map.has(key)) map.set(key, value);
|
|
965
|
-
} else if (map instanceof Set) {
|
|
966
|
-
map.add(key);
|
|
967
|
-
} else {
|
|
968
|
-
if (!Object.prototype.hasOwnProperty.call(map, key)) map[key] = value;
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
} catch (err) {
|
|
972
|
-
_iterator2.e(err);
|
|
973
|
-
} finally {
|
|
974
|
-
_iterator2.f();
|
|
975
|
-
}
|
|
976
|
-
}
|
|
977
|
-
} catch (err) {
|
|
978
|
-
_iterator.e(err);
|
|
979
|
-
} finally {
|
|
980
|
-
_iterator.f();
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
return map;
|
|
984
|
-
}
|
|
985
|
-
}, {
|
|
986
|
-
key: "toString",
|
|
987
|
-
value: function toString(ctx, onComment) {
|
|
988
|
-
var seq = this.value;
|
|
989
|
-
if (seq.items.length > 1) return _get(_getPrototypeOf(Merge.prototype), "toString", this).call(this, ctx, onComment);
|
|
990
|
-
this.value = seq.items[0];
|
|
991
|
-
|
|
992
|
-
var str = _get(_getPrototypeOf(Merge.prototype), "toString", this).call(this, ctx, onComment);
|
|
993
|
-
|
|
994
|
-
this.value = seq;
|
|
995
|
-
return str;
|
|
996
|
-
}
|
|
997
|
-
}]);
|
|
998
|
-
|
|
999
|
-
return Merge;
|
|
1000
|
-
}(Pair);
|
|
1001
|
-
|
|
1002
945
|
var binaryOptions = {
|
|
1003
946
|
defaultType: Type.BLOCK_LITERAL,
|
|
1004
947
|
lineWidth: 76
|
|
@@ -1027,7 +970,7 @@ var strOptions = {
|
|
|
1027
970
|
}
|
|
1028
971
|
};
|
|
1029
972
|
|
|
1030
|
-
function resolveScalar(str, tags
|
|
973
|
+
function resolveScalar(str, tags) {
|
|
1031
974
|
var _iterator = _createForOfIteratorHelper(tags),
|
|
1032
975
|
_step;
|
|
1033
976
|
|
|
@@ -1038,15 +981,11 @@ function resolveScalar(str, tags, scalarFallback) {
|
|
|
1038
981
|
test = _step$value.test,
|
|
1039
982
|
resolve = _step$value.resolve;
|
|
1040
983
|
|
|
1041
|
-
if (test) {
|
|
1042
|
-
var
|
|
1043
|
-
|
|
1044
|
-
if (
|
|
1045
|
-
|
|
1046
|
-
if (!(res instanceof Scalar)) res = new Scalar(res);
|
|
1047
|
-
if (format) res.format = format;
|
|
1048
|
-
return res;
|
|
1049
|
-
}
|
|
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;
|
|
1050
989
|
}
|
|
1051
990
|
}
|
|
1052
991
|
} catch (err) {
|
|
@@ -1055,8 +994,7 @@ function resolveScalar(str, tags, scalarFallback) {
|
|
|
1055
994
|
_iterator.f();
|
|
1056
995
|
}
|
|
1057
996
|
|
|
1058
|
-
|
|
1059
|
-
return new Scalar(str);
|
|
997
|
+
return new Scalar(str); // fallback to string
|
|
1060
998
|
}
|
|
1061
999
|
|
|
1062
1000
|
var FOLD_FLOW = 'flow';
|
|
@@ -1092,7 +1030,7 @@ var consumeMoreIndentedLines = function consumeMoreIndentedLines(text, i) {
|
|
|
1092
1030
|
* the first line, defaulting to `indent.length`
|
|
1093
1031
|
* @param {number} [options.lineWidth=80]
|
|
1094
1032
|
* @param {number} [options.minContentWidth=20] Allow highly indented lines to
|
|
1095
|
-
* stretch the line width
|
|
1033
|
+
* stretch the line width or indent content from the start
|
|
1096
1034
|
* @param {function} options.onFold Called once if the text is folded
|
|
1097
1035
|
* @param {function} options.onFold Called once if any line of text exceeds
|
|
1098
1036
|
* lineWidth characters
|
|
@@ -1112,7 +1050,12 @@ function foldFlowLines(text, indent, mode, _ref) {
|
|
|
1112
1050
|
if (text.length <= endStep) return text;
|
|
1113
1051
|
var folds = [];
|
|
1114
1052
|
var escapedFolds = {};
|
|
1115
|
-
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
|
+
|
|
1116
1059
|
var split = undefined;
|
|
1117
1060
|
var prev = undefined;
|
|
1118
1061
|
var overflow = false;
|
|
@@ -1191,8 +1134,10 @@ function foldFlowLines(text, indent, mode, _ref) {
|
|
|
1191
1134
|
|
|
1192
1135
|
var _end = folds[_i + 1] || text.length;
|
|
1193
1136
|
|
|
1194
|
-
if (
|
|
1195
|
-
|
|
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
|
+
}
|
|
1196
1141
|
}
|
|
1197
1142
|
|
|
1198
1143
|
return res;
|
|
@@ -1456,7 +1401,7 @@ function plainString(item, ctx, onComment, onChompKeep) {
|
|
|
1456
1401
|
|
|
1457
1402
|
if (actualString) {
|
|
1458
1403
|
var tags = ctx.doc.schema.tags;
|
|
1459
|
-
var resolved = resolveScalar(str, tags
|
|
1404
|
+
var resolved = resolveScalar(str, tags).value;
|
|
1460
1405
|
if (typeof resolved !== 'string') return doubleQuotedString(value, ctx);
|
|
1461
1406
|
}
|
|
1462
1407
|
|
|
@@ -1487,8 +1432,8 @@ function stringifyString(item, ctx, onComment, onChompKeep) {
|
|
|
1487
1432
|
}
|
|
1488
1433
|
|
|
1489
1434
|
if (type !== Type.QUOTE_DOUBLE) {
|
|
1490
|
-
// force double quotes on control characters
|
|
1491
|
-
if (/[\
|
|
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;
|
|
1492
1437
|
}
|
|
1493
1438
|
|
|
1494
1439
|
var _stringify = function _stringify(_type) {
|
|
@@ -1550,929 +1495,4 @@ function stringifyNumber(_ref) {
|
|
|
1550
1495
|
return n;
|
|
1551
1496
|
}
|
|
1552
1497
|
|
|
1553
|
-
|
|
1554
|
-
var char, name;
|
|
1555
|
-
|
|
1556
|
-
switch (cst.type) {
|
|
1557
|
-
case Type.FLOW_MAP:
|
|
1558
|
-
char = '}';
|
|
1559
|
-
name = 'flow map';
|
|
1560
|
-
break;
|
|
1561
|
-
|
|
1562
|
-
case Type.FLOW_SEQ:
|
|
1563
|
-
char = ']';
|
|
1564
|
-
name = 'flow sequence';
|
|
1565
|
-
break;
|
|
1566
|
-
|
|
1567
|
-
default:
|
|
1568
|
-
errors.push(new YAMLSemanticError(cst, 'Not a flow collection!?'));
|
|
1569
|
-
return;
|
|
1570
|
-
}
|
|
1571
|
-
|
|
1572
|
-
var lastItem;
|
|
1573
|
-
|
|
1574
|
-
for (var i = cst.items.length - 1; i >= 0; --i) {
|
|
1575
|
-
var item = cst.items[i];
|
|
1576
|
-
|
|
1577
|
-
if (!item || item.type !== Type.COMMENT) {
|
|
1578
|
-
lastItem = item;
|
|
1579
|
-
break;
|
|
1580
|
-
}
|
|
1581
|
-
}
|
|
1582
|
-
|
|
1583
|
-
if (lastItem && lastItem.char !== char) {
|
|
1584
|
-
var msg = "Expected ".concat(name, " to end with ").concat(char);
|
|
1585
|
-
var err;
|
|
1586
|
-
|
|
1587
|
-
if (typeof lastItem.offset === 'number') {
|
|
1588
|
-
err = new YAMLSemanticError(cst, msg);
|
|
1589
|
-
err.offset = lastItem.offset + 1;
|
|
1590
|
-
} else {
|
|
1591
|
-
err = new YAMLSemanticError(lastItem, msg);
|
|
1592
|
-
if (lastItem.range && lastItem.range.end) err.offset = lastItem.range.end - lastItem.range.start;
|
|
1593
|
-
}
|
|
1594
|
-
|
|
1595
|
-
errors.push(err);
|
|
1596
|
-
}
|
|
1597
|
-
}
|
|
1598
|
-
function checkFlowCommentSpace(errors, comment) {
|
|
1599
|
-
var prev = comment.context.src[comment.range.start - 1];
|
|
1600
|
-
|
|
1601
|
-
if (prev !== '\n' && prev !== '\t' && prev !== ' ') {
|
|
1602
|
-
var msg = 'Comments must be separated from other tokens by white space characters';
|
|
1603
|
-
errors.push(new YAMLSemanticError(comment, msg));
|
|
1604
|
-
}
|
|
1605
|
-
}
|
|
1606
|
-
function getLongKeyError(source, key) {
|
|
1607
|
-
var sk = String(key);
|
|
1608
|
-
var k = sk.substr(0, 8) + '...' + sk.substr(-8);
|
|
1609
|
-
return new YAMLSemanticError(source, "The \"".concat(k, "\" key is too long"));
|
|
1610
|
-
}
|
|
1611
|
-
function resolveComments(collection, comments) {
|
|
1612
|
-
var _iterator = _createForOfIteratorHelper(comments),
|
|
1613
|
-
_step;
|
|
1614
|
-
|
|
1615
|
-
try {
|
|
1616
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
1617
|
-
var _step$value = _step.value,
|
|
1618
|
-
afterKey = _step$value.afterKey,
|
|
1619
|
-
before = _step$value.before,
|
|
1620
|
-
comment = _step$value.comment;
|
|
1621
|
-
var item = collection.items[before];
|
|
1622
|
-
|
|
1623
|
-
if (!item) {
|
|
1624
|
-
if (comment !== undefined) {
|
|
1625
|
-
if (collection.comment) collection.comment += '\n' + comment;else collection.comment = comment;
|
|
1626
|
-
}
|
|
1627
|
-
} else {
|
|
1628
|
-
if (afterKey && item.value) item = item.value;
|
|
1629
|
-
|
|
1630
|
-
if (comment === undefined) {
|
|
1631
|
-
if (afterKey || !item.commentBefore) item.spaceBefore = true;
|
|
1632
|
-
} else {
|
|
1633
|
-
if (item.commentBefore) item.commentBefore += '\n' + comment;else item.commentBefore = comment;
|
|
1634
|
-
}
|
|
1635
|
-
}
|
|
1636
|
-
}
|
|
1637
|
-
} catch (err) {
|
|
1638
|
-
_iterator.e(err);
|
|
1639
|
-
} finally {
|
|
1640
|
-
_iterator.f();
|
|
1641
|
-
}
|
|
1642
|
-
}
|
|
1643
|
-
|
|
1644
|
-
// on error, will return { str: string, errors: Error[] }
|
|
1645
|
-
function resolveString(doc, node) {
|
|
1646
|
-
var res = node.strValue;
|
|
1647
|
-
if (!res) return '';
|
|
1648
|
-
if (typeof res === 'string') return res;
|
|
1649
|
-
res.errors.forEach(function (error) {
|
|
1650
|
-
if (!error.source) error.source = node;
|
|
1651
|
-
doc.errors.push(error);
|
|
1652
|
-
});
|
|
1653
|
-
return res.str;
|
|
1654
|
-
}
|
|
1655
|
-
|
|
1656
|
-
function resolveTagHandle(doc, node) {
|
|
1657
|
-
var _node$tag = node.tag,
|
|
1658
|
-
handle = _node$tag.handle,
|
|
1659
|
-
suffix = _node$tag.suffix;
|
|
1660
|
-
var prefix = doc.tagPrefixes.find(function (p) {
|
|
1661
|
-
return p.handle === handle;
|
|
1662
|
-
});
|
|
1663
|
-
|
|
1664
|
-
if (!prefix) {
|
|
1665
|
-
var dtp = doc.getDefaults().tagPrefixes;
|
|
1666
|
-
if (dtp) prefix = dtp.find(function (p) {
|
|
1667
|
-
return p.handle === handle;
|
|
1668
|
-
});
|
|
1669
|
-
if (!prefix) throw new YAMLSemanticError(node, "The ".concat(handle, " tag handle is non-default and was not declared."));
|
|
1670
|
-
}
|
|
1671
|
-
|
|
1672
|
-
if (!suffix) throw new YAMLSemanticError(node, "The ".concat(handle, " tag has no suffix."));
|
|
1673
|
-
|
|
1674
|
-
if (handle === '!' && (doc.version || doc.options.version) === '1.0') {
|
|
1675
|
-
if (suffix[0] === '^') {
|
|
1676
|
-
doc.warnings.push(new YAMLWarning(node, 'YAML 1.0 ^ tag expansion is not supported'));
|
|
1677
|
-
return suffix;
|
|
1678
|
-
}
|
|
1679
|
-
|
|
1680
|
-
if (/[:/]/.test(suffix)) {
|
|
1681
|
-
// word/foo -> tag:word.yaml.org,2002:foo
|
|
1682
|
-
var vocab = suffix.match(/^([a-z0-9-]+)\/(.*)/i);
|
|
1683
|
-
return vocab ? "tag:".concat(vocab[1], ".yaml.org,2002:").concat(vocab[2]) : "tag:".concat(suffix);
|
|
1684
|
-
}
|
|
1685
|
-
}
|
|
1686
|
-
|
|
1687
|
-
return prefix.prefix + decodeURIComponent(suffix);
|
|
1688
|
-
}
|
|
1689
|
-
|
|
1690
|
-
function resolveTagName(doc, node) {
|
|
1691
|
-
var tag = node.tag,
|
|
1692
|
-
type = node.type;
|
|
1693
|
-
var nonSpecific = false;
|
|
1694
|
-
|
|
1695
|
-
if (tag) {
|
|
1696
|
-
var handle = tag.handle,
|
|
1697
|
-
suffix = tag.suffix,
|
|
1698
|
-
verbatim = tag.verbatim;
|
|
1699
|
-
|
|
1700
|
-
if (verbatim) {
|
|
1701
|
-
if (verbatim !== '!' && verbatim !== '!!') return verbatim;
|
|
1702
|
-
var msg = "Verbatim tags aren't resolved, so ".concat(verbatim, " is invalid.");
|
|
1703
|
-
doc.errors.push(new YAMLSemanticError(node, msg));
|
|
1704
|
-
} else if (handle === '!' && !suffix) {
|
|
1705
|
-
nonSpecific = true;
|
|
1706
|
-
} else {
|
|
1707
|
-
try {
|
|
1708
|
-
return resolveTagHandle(doc, node);
|
|
1709
|
-
} catch (error) {
|
|
1710
|
-
doc.errors.push(error);
|
|
1711
|
-
}
|
|
1712
|
-
}
|
|
1713
|
-
}
|
|
1714
|
-
|
|
1715
|
-
switch (type) {
|
|
1716
|
-
case Type.BLOCK_FOLDED:
|
|
1717
|
-
case Type.BLOCK_LITERAL:
|
|
1718
|
-
case Type.QUOTE_DOUBLE:
|
|
1719
|
-
case Type.QUOTE_SINGLE:
|
|
1720
|
-
return defaultTags.STR;
|
|
1721
|
-
|
|
1722
|
-
case Type.FLOW_MAP:
|
|
1723
|
-
case Type.MAP:
|
|
1724
|
-
return defaultTags.MAP;
|
|
1725
|
-
|
|
1726
|
-
case Type.FLOW_SEQ:
|
|
1727
|
-
case Type.SEQ:
|
|
1728
|
-
return defaultTags.SEQ;
|
|
1729
|
-
|
|
1730
|
-
case Type.PLAIN:
|
|
1731
|
-
return nonSpecific ? defaultTags.STR : null;
|
|
1732
|
-
|
|
1733
|
-
default:
|
|
1734
|
-
return null;
|
|
1735
|
-
}
|
|
1736
|
-
}
|
|
1737
|
-
|
|
1738
|
-
function resolveByTagName(doc, node, tagName) {
|
|
1739
|
-
var _doc$schema = doc.schema,
|
|
1740
|
-
knownTags = _doc$schema.knownTags,
|
|
1741
|
-
tags = _doc$schema.tags;
|
|
1742
|
-
var matchWithTest = [];
|
|
1743
|
-
|
|
1744
|
-
var _iterator = _createForOfIteratorHelper(tags),
|
|
1745
|
-
_step;
|
|
1746
|
-
|
|
1747
|
-
try {
|
|
1748
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
1749
|
-
var tag = _step.value;
|
|
1750
|
-
|
|
1751
|
-
if (tag.tag === tagName) {
|
|
1752
|
-
if (tag.test) matchWithTest.push(tag);else {
|
|
1753
|
-
var _res = tag.resolve(doc, node);
|
|
1754
|
-
|
|
1755
|
-
return _res instanceof Collection ? _res : new Scalar(_res);
|
|
1756
|
-
}
|
|
1757
|
-
}
|
|
1758
|
-
}
|
|
1759
|
-
} catch (err) {
|
|
1760
|
-
_iterator.e(err);
|
|
1761
|
-
} finally {
|
|
1762
|
-
_iterator.f();
|
|
1763
|
-
}
|
|
1764
|
-
|
|
1765
|
-
var str = resolveString(doc, node);
|
|
1766
|
-
if (typeof str === 'string' && matchWithTest.length > 0) return resolveScalar(str, matchWithTest, tags.scalarFallback);
|
|
1767
|
-
var kt = knownTags[tagName];
|
|
1768
|
-
|
|
1769
|
-
if (kt) {
|
|
1770
|
-
tags.push(Object.assign({}, kt, {
|
|
1771
|
-
default: false,
|
|
1772
|
-
test: undefined
|
|
1773
|
-
}));
|
|
1774
|
-
var res = kt.resolve(doc, node);
|
|
1775
|
-
return res instanceof Collection ? res : new Scalar(res);
|
|
1776
|
-
}
|
|
1777
|
-
|
|
1778
|
-
return null;
|
|
1779
|
-
}
|
|
1780
|
-
|
|
1781
|
-
function getFallbackTagName(_ref) {
|
|
1782
|
-
var type = _ref.type;
|
|
1783
|
-
|
|
1784
|
-
switch (type) {
|
|
1785
|
-
case Type.FLOW_MAP:
|
|
1786
|
-
case Type.MAP:
|
|
1787
|
-
return defaultTags.MAP;
|
|
1788
|
-
|
|
1789
|
-
case Type.FLOW_SEQ:
|
|
1790
|
-
case Type.SEQ:
|
|
1791
|
-
return defaultTags.SEQ;
|
|
1792
|
-
|
|
1793
|
-
default:
|
|
1794
|
-
return defaultTags.STR;
|
|
1795
|
-
}
|
|
1796
|
-
}
|
|
1797
|
-
|
|
1798
|
-
function resolveTag(doc, node, tagName) {
|
|
1799
|
-
try {
|
|
1800
|
-
var res = resolveByTagName(doc, node, tagName);
|
|
1801
|
-
|
|
1802
|
-
if (res) {
|
|
1803
|
-
if (tagName && node.tag) res.tag = tagName;
|
|
1804
|
-
return res;
|
|
1805
|
-
}
|
|
1806
|
-
} catch (error) {
|
|
1807
|
-
/* istanbul ignore if */
|
|
1808
|
-
if (!error.source) error.source = node;
|
|
1809
|
-
doc.errors.push(error);
|
|
1810
|
-
return null;
|
|
1811
|
-
}
|
|
1812
|
-
|
|
1813
|
-
try {
|
|
1814
|
-
var fallback = getFallbackTagName(node);
|
|
1815
|
-
if (!fallback) throw new Error("The tag ".concat(tagName, " is unavailable"));
|
|
1816
|
-
var msg = "The tag ".concat(tagName, " is unavailable, falling back to ").concat(fallback);
|
|
1817
|
-
doc.warnings.push(new YAMLWarning(node, msg));
|
|
1818
|
-
|
|
1819
|
-
var _res2 = resolveByTagName(doc, node, fallback);
|
|
1820
|
-
|
|
1821
|
-
_res2.tag = tagName;
|
|
1822
|
-
return _res2;
|
|
1823
|
-
} catch (error) {
|
|
1824
|
-
var refError = new YAMLReferenceError(node, error.message);
|
|
1825
|
-
refError.stack = error.stack;
|
|
1826
|
-
doc.errors.push(refError);
|
|
1827
|
-
return null;
|
|
1828
|
-
}
|
|
1829
|
-
}
|
|
1830
|
-
|
|
1831
|
-
var isCollectionItem = function isCollectionItem(node) {
|
|
1832
|
-
if (!node) return false;
|
|
1833
|
-
var type = node.type;
|
|
1834
|
-
return type === Type.MAP_KEY || type === Type.MAP_VALUE || type === Type.SEQ_ITEM;
|
|
1835
|
-
};
|
|
1836
|
-
|
|
1837
|
-
function resolveNodeProps(errors, node) {
|
|
1838
|
-
var comments = {
|
|
1839
|
-
before: [],
|
|
1840
|
-
after: []
|
|
1841
|
-
};
|
|
1842
|
-
var hasAnchor = false;
|
|
1843
|
-
var hasTag = false;
|
|
1844
|
-
var props = isCollectionItem(node.context.parent) ? node.context.parent.props.concat(node.props) : node.props;
|
|
1845
|
-
|
|
1846
|
-
var _iterator = _createForOfIteratorHelper(props),
|
|
1847
|
-
_step;
|
|
1848
|
-
|
|
1849
|
-
try {
|
|
1850
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
1851
|
-
var _step$value = _step.value,
|
|
1852
|
-
start = _step$value.start,
|
|
1853
|
-
end = _step$value.end;
|
|
1854
|
-
|
|
1855
|
-
switch (node.context.src[start]) {
|
|
1856
|
-
case Char.COMMENT:
|
|
1857
|
-
{
|
|
1858
|
-
if (!node.commentHasRequiredWhitespace(start)) {
|
|
1859
|
-
var msg = 'Comments must be separated from other tokens by white space characters';
|
|
1860
|
-
errors.push(new YAMLSemanticError(node, msg));
|
|
1861
|
-
}
|
|
1862
|
-
|
|
1863
|
-
var header = node.header,
|
|
1864
|
-
valueRange = node.valueRange;
|
|
1865
|
-
var cc = valueRange && (start > valueRange.start || header && start > header.start) ? comments.after : comments.before;
|
|
1866
|
-
cc.push(node.context.src.slice(start + 1, end));
|
|
1867
|
-
break;
|
|
1868
|
-
}
|
|
1869
|
-
// Actual anchor & tag resolution is handled by schema, here we just complain
|
|
1870
|
-
|
|
1871
|
-
case Char.ANCHOR:
|
|
1872
|
-
if (hasAnchor) {
|
|
1873
|
-
var _msg = 'A node can have at most one anchor';
|
|
1874
|
-
errors.push(new YAMLSemanticError(node, _msg));
|
|
1875
|
-
}
|
|
1876
|
-
|
|
1877
|
-
hasAnchor = true;
|
|
1878
|
-
break;
|
|
1879
|
-
|
|
1880
|
-
case Char.TAG:
|
|
1881
|
-
if (hasTag) {
|
|
1882
|
-
var _msg2 = 'A node can have at most one tag';
|
|
1883
|
-
errors.push(new YAMLSemanticError(node, _msg2));
|
|
1884
|
-
}
|
|
1885
|
-
|
|
1886
|
-
hasTag = true;
|
|
1887
|
-
break;
|
|
1888
|
-
}
|
|
1889
|
-
}
|
|
1890
|
-
} catch (err) {
|
|
1891
|
-
_iterator.e(err);
|
|
1892
|
-
} finally {
|
|
1893
|
-
_iterator.f();
|
|
1894
|
-
}
|
|
1895
|
-
|
|
1896
|
-
return {
|
|
1897
|
-
comments: comments,
|
|
1898
|
-
hasAnchor: hasAnchor,
|
|
1899
|
-
hasTag: hasTag
|
|
1900
|
-
};
|
|
1901
|
-
}
|
|
1902
|
-
|
|
1903
|
-
function resolveNodeValue(doc, node) {
|
|
1904
|
-
var anchors = doc.anchors,
|
|
1905
|
-
errors = doc.errors,
|
|
1906
|
-
schema = doc.schema;
|
|
1907
|
-
|
|
1908
|
-
if (node.type === Type.ALIAS) {
|
|
1909
|
-
var name = node.rawValue;
|
|
1910
|
-
var src = anchors.getNode(name);
|
|
1911
|
-
|
|
1912
|
-
if (!src) {
|
|
1913
|
-
var msg = "Aliased anchor not found: ".concat(name);
|
|
1914
|
-
errors.push(new YAMLReferenceError(node, msg));
|
|
1915
|
-
return null;
|
|
1916
|
-
} // Lazy resolution for circular references
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
var res = new Alias(src);
|
|
1920
|
-
|
|
1921
|
-
anchors._cstAliases.push(res);
|
|
1922
|
-
|
|
1923
|
-
return res;
|
|
1924
|
-
}
|
|
1925
|
-
|
|
1926
|
-
var tagName = resolveTagName(doc, node);
|
|
1927
|
-
if (tagName) return resolveTag(doc, node, tagName);
|
|
1928
|
-
|
|
1929
|
-
if (node.type !== Type.PLAIN) {
|
|
1930
|
-
var _msg3 = "Failed to resolve ".concat(node.type, " node here");
|
|
1931
|
-
|
|
1932
|
-
errors.push(new YAMLSyntaxError(node, _msg3));
|
|
1933
|
-
return null;
|
|
1934
|
-
}
|
|
1935
|
-
|
|
1936
|
-
try {
|
|
1937
|
-
var str = resolveString(doc, node);
|
|
1938
|
-
return resolveScalar(str, schema.tags, schema.tags.scalarFallback);
|
|
1939
|
-
} catch (error) {
|
|
1940
|
-
if (!error.source) error.source = node;
|
|
1941
|
-
errors.push(error);
|
|
1942
|
-
return null;
|
|
1943
|
-
}
|
|
1944
|
-
} // sets node.resolved on success
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
function resolveNode(doc, node) {
|
|
1948
|
-
if (!node) return null;
|
|
1949
|
-
if (node.error) doc.errors.push(node.error);
|
|
1950
|
-
|
|
1951
|
-
var _resolveNodeProps = resolveNodeProps(doc.errors, node),
|
|
1952
|
-
comments = _resolveNodeProps.comments,
|
|
1953
|
-
hasAnchor = _resolveNodeProps.hasAnchor,
|
|
1954
|
-
hasTag = _resolveNodeProps.hasTag;
|
|
1955
|
-
|
|
1956
|
-
if (hasAnchor) {
|
|
1957
|
-
var anchors = doc.anchors;
|
|
1958
|
-
var name = node.anchor;
|
|
1959
|
-
var prev = anchors.getNode(name); // At this point, aliases for any preceding node with the same anchor
|
|
1960
|
-
// name have already been resolved, so it may safely be renamed.
|
|
1961
|
-
|
|
1962
|
-
if (prev) anchors.map[anchors.newName(name)] = prev; // During parsing, we need to store the CST node in anchors.map as
|
|
1963
|
-
// anchors need to be available during resolution to allow for
|
|
1964
|
-
// circular references.
|
|
1965
|
-
|
|
1966
|
-
anchors.map[name] = node;
|
|
1967
|
-
}
|
|
1968
|
-
|
|
1969
|
-
if (node.type === Type.ALIAS && (hasAnchor || hasTag)) {
|
|
1970
|
-
var msg = 'An alias node must not specify any properties';
|
|
1971
|
-
doc.errors.push(new YAMLSemanticError(node, msg));
|
|
1972
|
-
}
|
|
1973
|
-
|
|
1974
|
-
var res = resolveNodeValue(doc, node);
|
|
1975
|
-
|
|
1976
|
-
if (res) {
|
|
1977
|
-
res.range = [node.range.start, node.range.end];
|
|
1978
|
-
if (doc.options.keepCstNodes) res.cstNode = node;
|
|
1979
|
-
if (doc.options.keepNodeTypes) res.type = node.type;
|
|
1980
|
-
var cb = comments.before.join('\n');
|
|
1981
|
-
|
|
1982
|
-
if (cb) {
|
|
1983
|
-
res.commentBefore = res.commentBefore ? "".concat(res.commentBefore, "\n").concat(cb) : cb;
|
|
1984
|
-
}
|
|
1985
|
-
|
|
1986
|
-
var ca = comments.after.join('\n');
|
|
1987
|
-
if (ca) res.comment = res.comment ? "".concat(res.comment, "\n").concat(ca) : ca;
|
|
1988
|
-
}
|
|
1989
|
-
|
|
1990
|
-
return node.resolved = res;
|
|
1991
|
-
}
|
|
1992
|
-
|
|
1993
|
-
function resolveMap(doc, cst) {
|
|
1994
|
-
if (cst.type !== Type.MAP && cst.type !== Type.FLOW_MAP) {
|
|
1995
|
-
var msg = "A ".concat(cst.type, " node cannot be resolved as a mapping");
|
|
1996
|
-
doc.errors.push(new YAMLSyntaxError(cst, msg));
|
|
1997
|
-
return null;
|
|
1998
|
-
}
|
|
1999
|
-
|
|
2000
|
-
var _ref = cst.type === Type.FLOW_MAP ? resolveFlowMapItems(doc, cst) : resolveBlockMapItems(doc, cst),
|
|
2001
|
-
comments = _ref.comments,
|
|
2002
|
-
items = _ref.items;
|
|
2003
|
-
|
|
2004
|
-
var map = new YAMLMap(doc.schema);
|
|
2005
|
-
map.items = items;
|
|
2006
|
-
resolveComments(map, comments);
|
|
2007
|
-
var hasCollectionKey = false;
|
|
2008
|
-
|
|
2009
|
-
for (var i = 0; i < items.length; ++i) {
|
|
2010
|
-
var iKey = items[i].key;
|
|
2011
|
-
if (iKey instanceof Collection) hasCollectionKey = true;
|
|
2012
|
-
|
|
2013
|
-
if (doc.schema.merge && iKey && iKey.value === MERGE_KEY) {
|
|
2014
|
-
items[i] = new Merge(items[i]);
|
|
2015
|
-
var sources = items[i].value.items;
|
|
2016
|
-
var error = null;
|
|
2017
|
-
sources.some(function (node) {
|
|
2018
|
-
if (node instanceof Alias) {
|
|
2019
|
-
// During parsing, alias sources are CST nodes; to account for
|
|
2020
|
-
// circular references their resolved values can't be used here.
|
|
2021
|
-
var type = node.source.type;
|
|
2022
|
-
if (type === Type.MAP || type === Type.FLOW_MAP) return false;
|
|
2023
|
-
return error = 'Merge nodes aliases can only point to maps';
|
|
2024
|
-
}
|
|
2025
|
-
|
|
2026
|
-
return error = 'Merge nodes can only have Alias nodes as values';
|
|
2027
|
-
});
|
|
2028
|
-
if (error) doc.errors.push(new YAMLSemanticError(cst, error));
|
|
2029
|
-
} else {
|
|
2030
|
-
for (var j = i + 1; j < items.length; ++j) {
|
|
2031
|
-
var jKey = items[j].key;
|
|
2032
|
-
|
|
2033
|
-
if (iKey === jKey || iKey && jKey && Object.prototype.hasOwnProperty.call(iKey, 'value') && iKey.value === jKey.value) {
|
|
2034
|
-
var _msg = "Map keys must be unique; \"".concat(iKey, "\" is repeated");
|
|
2035
|
-
|
|
2036
|
-
doc.errors.push(new YAMLSemanticError(cst, _msg));
|
|
2037
|
-
break;
|
|
2038
|
-
}
|
|
2039
|
-
}
|
|
2040
|
-
}
|
|
2041
|
-
}
|
|
2042
|
-
|
|
2043
|
-
if (hasCollectionKey && !doc.options.mapAsMap) {
|
|
2044
|
-
var warn = 'Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.';
|
|
2045
|
-
doc.warnings.push(new YAMLWarning(cst, warn));
|
|
2046
|
-
}
|
|
2047
|
-
|
|
2048
|
-
cst.resolved = map;
|
|
2049
|
-
return map;
|
|
2050
|
-
}
|
|
2051
|
-
|
|
2052
|
-
var valueHasPairComment = function valueHasPairComment(_ref2) {
|
|
2053
|
-
var _ref2$context = _ref2.context,
|
|
2054
|
-
lineStart = _ref2$context.lineStart,
|
|
2055
|
-
node = _ref2$context.node,
|
|
2056
|
-
src = _ref2$context.src,
|
|
2057
|
-
props = _ref2.props;
|
|
2058
|
-
if (props.length === 0) return false;
|
|
2059
|
-
var start = props[0].start;
|
|
2060
|
-
if (node && start > node.valueRange.start) return false;
|
|
2061
|
-
if (src[start] !== Char.COMMENT) return false;
|
|
2062
|
-
|
|
2063
|
-
for (var i = lineStart; i < start; ++i) {
|
|
2064
|
-
if (src[i] === '\n') return false;
|
|
2065
|
-
}
|
|
2066
|
-
|
|
2067
|
-
return true;
|
|
2068
|
-
};
|
|
2069
|
-
|
|
2070
|
-
function resolvePairComment(item, pair) {
|
|
2071
|
-
if (!valueHasPairComment(item)) return;
|
|
2072
|
-
var comment = item.getPropValue(0, Char.COMMENT, true);
|
|
2073
|
-
var found = false;
|
|
2074
|
-
var cb = pair.value.commentBefore;
|
|
2075
|
-
|
|
2076
|
-
if (cb && cb.startsWith(comment)) {
|
|
2077
|
-
pair.value.commentBefore = cb.substr(comment.length + 1);
|
|
2078
|
-
found = true;
|
|
2079
|
-
} else {
|
|
2080
|
-
var cc = pair.value.comment;
|
|
2081
|
-
|
|
2082
|
-
if (!item.node && cc && cc.startsWith(comment)) {
|
|
2083
|
-
pair.value.comment = cc.substr(comment.length + 1);
|
|
2084
|
-
found = true;
|
|
2085
|
-
}
|
|
2086
|
-
}
|
|
2087
|
-
|
|
2088
|
-
if (found) pair.comment = comment;
|
|
2089
|
-
}
|
|
2090
|
-
|
|
2091
|
-
function resolveBlockMapItems(doc, cst) {
|
|
2092
|
-
var comments = [];
|
|
2093
|
-
var items = [];
|
|
2094
|
-
var key = undefined;
|
|
2095
|
-
var keyStart = null;
|
|
2096
|
-
|
|
2097
|
-
for (var i = 0; i < cst.items.length; ++i) {
|
|
2098
|
-
var item = cst.items[i];
|
|
2099
|
-
|
|
2100
|
-
switch (item.type) {
|
|
2101
|
-
case Type.BLANK_LINE:
|
|
2102
|
-
comments.push({
|
|
2103
|
-
afterKey: !!key,
|
|
2104
|
-
before: items.length
|
|
2105
|
-
});
|
|
2106
|
-
break;
|
|
2107
|
-
|
|
2108
|
-
case Type.COMMENT:
|
|
2109
|
-
comments.push({
|
|
2110
|
-
afterKey: !!key,
|
|
2111
|
-
before: items.length,
|
|
2112
|
-
comment: item.comment
|
|
2113
|
-
});
|
|
2114
|
-
break;
|
|
2115
|
-
|
|
2116
|
-
case Type.MAP_KEY:
|
|
2117
|
-
if (key !== undefined) items.push(new Pair(key));
|
|
2118
|
-
if (item.error) doc.errors.push(item.error);
|
|
2119
|
-
key = resolveNode(doc, item.node);
|
|
2120
|
-
keyStart = null;
|
|
2121
|
-
break;
|
|
2122
|
-
|
|
2123
|
-
case Type.MAP_VALUE:
|
|
2124
|
-
{
|
|
2125
|
-
if (key === undefined) key = null;
|
|
2126
|
-
if (item.error) doc.errors.push(item.error);
|
|
2127
|
-
|
|
2128
|
-
if (!item.context.atLineStart && item.node && item.node.type === Type.MAP && !item.node.context.atLineStart) {
|
|
2129
|
-
var msg = 'Nested mappings are not allowed in compact mappings';
|
|
2130
|
-
doc.errors.push(new YAMLSemanticError(item.node, msg));
|
|
2131
|
-
}
|
|
2132
|
-
|
|
2133
|
-
var valueNode = item.node;
|
|
2134
|
-
|
|
2135
|
-
if (!valueNode && item.props.length > 0) {
|
|
2136
|
-
// Comments on an empty mapping value need to be preserved, so we
|
|
2137
|
-
// need to construct a minimal empty node here to use instead of the
|
|
2138
|
-
// missing `item.node`. -- eemeli/yaml#19
|
|
2139
|
-
valueNode = new PlainValue(Type.PLAIN, []);
|
|
2140
|
-
valueNode.context = {
|
|
2141
|
-
parent: item,
|
|
2142
|
-
src: item.context.src
|
|
2143
|
-
};
|
|
2144
|
-
var pos = item.range.start + 1;
|
|
2145
|
-
valueNode.range = {
|
|
2146
|
-
start: pos,
|
|
2147
|
-
end: pos
|
|
2148
|
-
};
|
|
2149
|
-
valueNode.valueRange = {
|
|
2150
|
-
start: pos,
|
|
2151
|
-
end: pos
|
|
2152
|
-
};
|
|
2153
|
-
|
|
2154
|
-
if (typeof item.range.origStart === 'number') {
|
|
2155
|
-
var origPos = item.range.origStart + 1;
|
|
2156
|
-
valueNode.range.origStart = valueNode.range.origEnd = origPos;
|
|
2157
|
-
valueNode.valueRange.origStart = valueNode.valueRange.origEnd = origPos;
|
|
2158
|
-
}
|
|
2159
|
-
}
|
|
2160
|
-
|
|
2161
|
-
var pair = new Pair(key, resolveNode(doc, valueNode));
|
|
2162
|
-
resolvePairComment(item, pair);
|
|
2163
|
-
items.push(pair);
|
|
2164
|
-
|
|
2165
|
-
if (key && typeof keyStart === 'number') {
|
|
2166
|
-
if (item.range.start > keyStart + 1024) doc.errors.push(getLongKeyError(cst, key));
|
|
2167
|
-
}
|
|
2168
|
-
|
|
2169
|
-
key = undefined;
|
|
2170
|
-
keyStart = null;
|
|
2171
|
-
}
|
|
2172
|
-
break;
|
|
2173
|
-
|
|
2174
|
-
default:
|
|
2175
|
-
if (key !== undefined) items.push(new Pair(key));
|
|
2176
|
-
key = resolveNode(doc, item);
|
|
2177
|
-
keyStart = item.range.start;
|
|
2178
|
-
if (item.error) doc.errors.push(item.error);
|
|
2179
|
-
|
|
2180
|
-
next: for (var j = i + 1;; ++j) {
|
|
2181
|
-
var nextItem = cst.items[j];
|
|
2182
|
-
|
|
2183
|
-
switch (nextItem && nextItem.type) {
|
|
2184
|
-
case Type.BLANK_LINE:
|
|
2185
|
-
case Type.COMMENT:
|
|
2186
|
-
continue next;
|
|
2187
|
-
|
|
2188
|
-
case Type.MAP_VALUE:
|
|
2189
|
-
break next;
|
|
2190
|
-
|
|
2191
|
-
default:
|
|
2192
|
-
{
|
|
2193
|
-
var _msg2 = 'Implicit map keys need to be followed by map values';
|
|
2194
|
-
doc.errors.push(new YAMLSemanticError(item, _msg2));
|
|
2195
|
-
break next;
|
|
2196
|
-
}
|
|
2197
|
-
}
|
|
2198
|
-
}
|
|
2199
|
-
|
|
2200
|
-
if (item.valueRangeContainsNewline) {
|
|
2201
|
-
var _msg3 = 'Implicit map keys need to be on a single line';
|
|
2202
|
-
doc.errors.push(new YAMLSemanticError(item, _msg3));
|
|
2203
|
-
}
|
|
2204
|
-
|
|
2205
|
-
}
|
|
2206
|
-
}
|
|
2207
|
-
|
|
2208
|
-
if (key !== undefined) items.push(new Pair(key));
|
|
2209
|
-
return {
|
|
2210
|
-
comments: comments,
|
|
2211
|
-
items: items
|
|
2212
|
-
};
|
|
2213
|
-
}
|
|
2214
|
-
|
|
2215
|
-
function resolveFlowMapItems(doc, cst) {
|
|
2216
|
-
var comments = [];
|
|
2217
|
-
var items = [];
|
|
2218
|
-
var key = undefined;
|
|
2219
|
-
var explicitKey = false;
|
|
2220
|
-
var next = '{';
|
|
2221
|
-
|
|
2222
|
-
for (var i = 0; i < cst.items.length; ++i) {
|
|
2223
|
-
var item = cst.items[i];
|
|
2224
|
-
|
|
2225
|
-
if (typeof item.char === 'string') {
|
|
2226
|
-
var char = item.char,
|
|
2227
|
-
offset = item.offset;
|
|
2228
|
-
|
|
2229
|
-
if (char === '?' && key === undefined && !explicitKey) {
|
|
2230
|
-
explicitKey = true;
|
|
2231
|
-
next = ':';
|
|
2232
|
-
continue;
|
|
2233
|
-
}
|
|
2234
|
-
|
|
2235
|
-
if (char === ':') {
|
|
2236
|
-
if (key === undefined) key = null;
|
|
2237
|
-
|
|
2238
|
-
if (next === ':') {
|
|
2239
|
-
next = ',';
|
|
2240
|
-
continue;
|
|
2241
|
-
}
|
|
2242
|
-
} else {
|
|
2243
|
-
if (explicitKey) {
|
|
2244
|
-
if (key === undefined && char !== ',') key = null;
|
|
2245
|
-
explicitKey = false;
|
|
2246
|
-
}
|
|
2247
|
-
|
|
2248
|
-
if (key !== undefined) {
|
|
2249
|
-
items.push(new Pair(key));
|
|
2250
|
-
key = undefined;
|
|
2251
|
-
|
|
2252
|
-
if (char === ',') {
|
|
2253
|
-
next = ':';
|
|
2254
|
-
continue;
|
|
2255
|
-
}
|
|
2256
|
-
}
|
|
2257
|
-
}
|
|
2258
|
-
|
|
2259
|
-
if (char === '}') {
|
|
2260
|
-
if (i === cst.items.length - 1) continue;
|
|
2261
|
-
} else if (char === next) {
|
|
2262
|
-
next = ':';
|
|
2263
|
-
continue;
|
|
2264
|
-
}
|
|
2265
|
-
|
|
2266
|
-
var msg = "Flow map contains an unexpected ".concat(char);
|
|
2267
|
-
var err = new YAMLSyntaxError(cst, msg);
|
|
2268
|
-
err.offset = offset;
|
|
2269
|
-
doc.errors.push(err);
|
|
2270
|
-
} else if (item.type === Type.BLANK_LINE) {
|
|
2271
|
-
comments.push({
|
|
2272
|
-
afterKey: !!key,
|
|
2273
|
-
before: items.length
|
|
2274
|
-
});
|
|
2275
|
-
} else if (item.type === Type.COMMENT) {
|
|
2276
|
-
checkFlowCommentSpace(doc.errors, item);
|
|
2277
|
-
comments.push({
|
|
2278
|
-
afterKey: !!key,
|
|
2279
|
-
before: items.length,
|
|
2280
|
-
comment: item.comment
|
|
2281
|
-
});
|
|
2282
|
-
} else if (key === undefined) {
|
|
2283
|
-
if (next === ',') doc.errors.push(new YAMLSemanticError(item, 'Separator , missing in flow map'));
|
|
2284
|
-
key = resolveNode(doc, item);
|
|
2285
|
-
} else {
|
|
2286
|
-
if (next !== ',') doc.errors.push(new YAMLSemanticError(item, 'Indicator : missing in flow map entry'));
|
|
2287
|
-
items.push(new Pair(key, resolveNode(doc, item)));
|
|
2288
|
-
key = undefined;
|
|
2289
|
-
explicitKey = false;
|
|
2290
|
-
}
|
|
2291
|
-
}
|
|
2292
|
-
|
|
2293
|
-
checkFlowCollectionEnd(doc.errors, cst);
|
|
2294
|
-
if (key !== undefined) items.push(new Pair(key));
|
|
2295
|
-
return {
|
|
2296
|
-
comments: comments,
|
|
2297
|
-
items: items
|
|
2298
|
-
};
|
|
2299
|
-
}
|
|
2300
|
-
|
|
2301
|
-
function resolveSeq(doc, cst) {
|
|
2302
|
-
if (cst.type !== Type.SEQ && cst.type !== Type.FLOW_SEQ) {
|
|
2303
|
-
var msg = "A ".concat(cst.type, " node cannot be resolved as a sequence");
|
|
2304
|
-
doc.errors.push(new YAMLSyntaxError(cst, msg));
|
|
2305
|
-
return null;
|
|
2306
|
-
}
|
|
2307
|
-
|
|
2308
|
-
var _ref = cst.type === Type.FLOW_SEQ ? resolveFlowSeqItems(doc, cst) : resolveBlockSeqItems(doc, cst),
|
|
2309
|
-
comments = _ref.comments,
|
|
2310
|
-
items = _ref.items;
|
|
2311
|
-
|
|
2312
|
-
var seq = new YAMLSeq(doc.schema);
|
|
2313
|
-
seq.items = items;
|
|
2314
|
-
resolveComments(seq, comments);
|
|
2315
|
-
|
|
2316
|
-
if (!doc.options.mapAsMap && items.some(function (it) {
|
|
2317
|
-
return it instanceof Pair && it.key instanceof Collection;
|
|
2318
|
-
})) {
|
|
2319
|
-
var warn = 'Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.';
|
|
2320
|
-
doc.warnings.push(new YAMLWarning(cst, warn));
|
|
2321
|
-
}
|
|
2322
|
-
|
|
2323
|
-
cst.resolved = seq;
|
|
2324
|
-
return seq;
|
|
2325
|
-
}
|
|
2326
|
-
|
|
2327
|
-
function resolveBlockSeqItems(doc, cst) {
|
|
2328
|
-
var comments = [];
|
|
2329
|
-
var items = [];
|
|
2330
|
-
|
|
2331
|
-
for (var i = 0; i < cst.items.length; ++i) {
|
|
2332
|
-
var item = cst.items[i];
|
|
2333
|
-
|
|
2334
|
-
switch (item.type) {
|
|
2335
|
-
case Type.BLANK_LINE:
|
|
2336
|
-
comments.push({
|
|
2337
|
-
before: items.length
|
|
2338
|
-
});
|
|
2339
|
-
break;
|
|
2340
|
-
|
|
2341
|
-
case Type.COMMENT:
|
|
2342
|
-
comments.push({
|
|
2343
|
-
comment: item.comment,
|
|
2344
|
-
before: items.length
|
|
2345
|
-
});
|
|
2346
|
-
break;
|
|
2347
|
-
|
|
2348
|
-
case Type.SEQ_ITEM:
|
|
2349
|
-
if (item.error) doc.errors.push(item.error);
|
|
2350
|
-
items.push(resolveNode(doc, item.node));
|
|
2351
|
-
|
|
2352
|
-
if (item.hasProps) {
|
|
2353
|
-
var msg = 'Sequence items cannot have tags or anchors before the - indicator';
|
|
2354
|
-
doc.errors.push(new YAMLSemanticError(item, msg));
|
|
2355
|
-
}
|
|
2356
|
-
|
|
2357
|
-
break;
|
|
2358
|
-
|
|
2359
|
-
default:
|
|
2360
|
-
if (item.error) doc.errors.push(item.error);
|
|
2361
|
-
doc.errors.push(new YAMLSyntaxError(item, "Unexpected ".concat(item.type, " node in sequence")));
|
|
2362
|
-
}
|
|
2363
|
-
}
|
|
2364
|
-
|
|
2365
|
-
return {
|
|
2366
|
-
comments: comments,
|
|
2367
|
-
items: items
|
|
2368
|
-
};
|
|
2369
|
-
}
|
|
2370
|
-
|
|
2371
|
-
function resolveFlowSeqItems(doc, cst) {
|
|
2372
|
-
var comments = [];
|
|
2373
|
-
var items = [];
|
|
2374
|
-
var explicitKey = false;
|
|
2375
|
-
var key = undefined;
|
|
2376
|
-
var keyStart = null;
|
|
2377
|
-
var next = '[';
|
|
2378
|
-
var prevItem = null;
|
|
2379
|
-
|
|
2380
|
-
for (var i = 0; i < cst.items.length; ++i) {
|
|
2381
|
-
var item = cst.items[i];
|
|
2382
|
-
|
|
2383
|
-
if (typeof item.char === 'string') {
|
|
2384
|
-
var char = item.char,
|
|
2385
|
-
offset = item.offset;
|
|
2386
|
-
|
|
2387
|
-
if (char !== ':' && (explicitKey || key !== undefined)) {
|
|
2388
|
-
if (explicitKey && key === undefined) key = next ? items.pop() : null;
|
|
2389
|
-
items.push(new Pair(key));
|
|
2390
|
-
explicitKey = false;
|
|
2391
|
-
key = undefined;
|
|
2392
|
-
keyStart = null;
|
|
2393
|
-
}
|
|
2394
|
-
|
|
2395
|
-
if (char === next) {
|
|
2396
|
-
next = null;
|
|
2397
|
-
} else if (!next && char === '?') {
|
|
2398
|
-
explicitKey = true;
|
|
2399
|
-
} else if (next !== '[' && char === ':' && key === undefined) {
|
|
2400
|
-
if (next === ',') {
|
|
2401
|
-
key = items.pop();
|
|
2402
|
-
|
|
2403
|
-
if (key instanceof Pair) {
|
|
2404
|
-
var msg = 'Chaining flow sequence pairs is invalid';
|
|
2405
|
-
var err = new YAMLSemanticError(cst, msg);
|
|
2406
|
-
err.offset = offset;
|
|
2407
|
-
doc.errors.push(err);
|
|
2408
|
-
}
|
|
2409
|
-
|
|
2410
|
-
if (!explicitKey && typeof keyStart === 'number') {
|
|
2411
|
-
var keyEnd = item.range ? item.range.start : item.offset;
|
|
2412
|
-
if (keyEnd > keyStart + 1024) doc.errors.push(getLongKeyError(cst, key));
|
|
2413
|
-
var src = prevItem.context.src;
|
|
2414
|
-
|
|
2415
|
-
for (var _i = keyStart; _i < keyEnd; ++_i) {
|
|
2416
|
-
if (src[_i] === '\n') {
|
|
2417
|
-
var _msg = 'Implicit keys of flow sequence pairs need to be on a single line';
|
|
2418
|
-
doc.errors.push(new YAMLSemanticError(prevItem, _msg));
|
|
2419
|
-
break;
|
|
2420
|
-
}
|
|
2421
|
-
}
|
|
2422
|
-
}
|
|
2423
|
-
} else {
|
|
2424
|
-
key = null;
|
|
2425
|
-
}
|
|
2426
|
-
|
|
2427
|
-
keyStart = null;
|
|
2428
|
-
explicitKey = false;
|
|
2429
|
-
next = null;
|
|
2430
|
-
} else if (next === '[' || char !== ']' || i < cst.items.length - 1) {
|
|
2431
|
-
var _msg2 = "Flow sequence contains an unexpected ".concat(char);
|
|
2432
|
-
|
|
2433
|
-
var _err = new YAMLSyntaxError(cst, _msg2);
|
|
2434
|
-
|
|
2435
|
-
_err.offset = offset;
|
|
2436
|
-
doc.errors.push(_err);
|
|
2437
|
-
}
|
|
2438
|
-
} else if (item.type === Type.BLANK_LINE) {
|
|
2439
|
-
comments.push({
|
|
2440
|
-
before: items.length
|
|
2441
|
-
});
|
|
2442
|
-
} else if (item.type === Type.COMMENT) {
|
|
2443
|
-
checkFlowCommentSpace(doc.errors, item);
|
|
2444
|
-
comments.push({
|
|
2445
|
-
comment: item.comment,
|
|
2446
|
-
before: items.length
|
|
2447
|
-
});
|
|
2448
|
-
} else {
|
|
2449
|
-
if (next) {
|
|
2450
|
-
var _msg3 = "Expected a ".concat(next, " in flow sequence");
|
|
2451
|
-
|
|
2452
|
-
doc.errors.push(new YAMLSemanticError(item, _msg3));
|
|
2453
|
-
}
|
|
2454
|
-
|
|
2455
|
-
var value = resolveNode(doc, item);
|
|
2456
|
-
|
|
2457
|
-
if (key === undefined) {
|
|
2458
|
-
items.push(value);
|
|
2459
|
-
prevItem = item;
|
|
2460
|
-
} else {
|
|
2461
|
-
items.push(new Pair(key, value));
|
|
2462
|
-
key = undefined;
|
|
2463
|
-
}
|
|
2464
|
-
|
|
2465
|
-
keyStart = item.range.start;
|
|
2466
|
-
next = ',';
|
|
2467
|
-
}
|
|
2468
|
-
}
|
|
2469
|
-
|
|
2470
|
-
checkFlowCollectionEnd(doc.errors, cst);
|
|
2471
|
-
if (key !== undefined) items.push(new Pair(key));
|
|
2472
|
-
return {
|
|
2473
|
-
comments: comments,
|
|
2474
|
-
items: items
|
|
2475
|
-
};
|
|
2476
|
-
}
|
|
2477
|
-
|
|
2478
|
-
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, createNode as e, isEmptyPath as f, collectionFromPath as g, addComment as h, intOptions as i, resolveMap as j, createPair as k, resolveSeq as l, resolveString as m, nullOptions as n, stringifyNumber as o, findPair as p, 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 };
|