yaml 1.3.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -23
- package/browser/dist/Anchors.js +12 -10
- package/browser/dist/Document.js +122 -60
- package/browser/dist/constants.js +34 -0
- package/browser/dist/cst/Alias.js +1 -3
- package/browser/dist/cst/BlankLine.js +5 -7
- package/browser/dist/cst/BlockValue.js +4 -4
- package/browser/dist/cst/Collection.js +8 -8
- package/browser/dist/cst/CollectionItem.js +6 -8
- package/browser/dist/cst/Comment.js +5 -7
- package/browser/dist/cst/Directive.js +5 -7
- package/browser/dist/cst/Document.js +8 -10
- package/browser/dist/cst/FlowCollection.js +5 -7
- package/browser/dist/cst/Node.js +12 -40
- package/browser/dist/cst/ParseContext.js +32 -34
- package/browser/dist/cst/PlainValue.js +1 -3
- package/browser/dist/cst/QuoteDouble.js +1 -3
- package/browser/dist/cst/QuoteSingle.js +1 -3
- package/browser/dist/cst/Range.js +1 -3
- package/browser/dist/cst/getLinePos.js +8 -13
- package/browser/dist/cst/parse.js +1 -4
- package/browser/dist/deprecation.js +34 -0
- package/browser/dist/errors.js +50 -59
- package/browser/dist/index.js +7 -4
- package/browser/dist/listTagNames.js +1 -3
- package/browser/dist/schema/Alias.js +90 -10
- package/browser/dist/schema/Collection.js +3 -3
- package/browser/dist/schema/Map.js +22 -105
- package/browser/dist/schema/Merge.js +74 -1
- package/browser/dist/schema/Node.js +1 -3
- package/browser/dist/schema/Pair.js +52 -26
- package/browser/dist/schema/Scalar.js +3 -5
- package/browser/dist/schema/Seq.js +30 -7
- package/browser/dist/schema/index.js +158 -82
- package/browser/dist/schema/parseMap.js +18 -21
- package/browser/dist/schema/parseSeq.js +9 -12
- package/browser/dist/{schema/_string.js → stringify.js} +65 -73
- package/browser/dist/tags/core.js +132 -0
- package/browser/dist/tags/failsafe/index.js +17 -0
- package/browser/dist/tags/failsafe/map.js +65 -0
- package/browser/dist/tags/failsafe/seq.js +54 -0
- package/browser/dist/tags/failsafe/string.js +40 -0
- package/browser/dist/tags/index.js +50 -0
- package/browser/dist/tags/json.js +103 -0
- package/browser/dist/tags/options.js +35 -0
- package/browser/dist/{schema/_binary.js → tags/yaml-1.1/binary.js} +20 -20
- package/browser/dist/tags/yaml-1.1/index.js +177 -0
- package/browser/dist/{schema/_omap.js → tags/yaml-1.1/omap.js} +25 -25
- package/browser/dist/{schema/_pairs.js → tags/yaml-1.1/pairs.js} +9 -13
- package/browser/dist/tags/yaml-1.1/set.js +140 -0
- package/browser/dist/{schema/_timestamp.js → tags/yaml-1.1/timestamp.js} +13 -10
- package/browser/dist/test-events.js +1 -4
- package/browser/dist/toJSON.js +20 -8
- package/browser/index.js +1 -0
- package/browser/map.js +2 -1
- package/browser/pair.js +2 -1
- package/browser/parse-cst.js +1 -1
- package/browser/scalar.js +2 -1
- package/browser/schema.js +7 -3
- package/browser/seq.js +2 -1
- package/browser/types/binary.js +7 -1
- package/browser/types/omap.js +2 -1
- package/browser/types/pairs.js +2 -1
- package/browser/types/set.js +2 -1
- package/browser/types/timestamp.js +10 -1
- package/browser/types.js +11 -0
- package/browser/util.js +15 -0
- package/dist/Anchors.js +9 -8
- package/dist/Document.js +55 -39
- package/dist/constants.js +34 -0
- package/dist/cst/Alias.js +1 -3
- package/dist/cst/BlankLine.js +5 -7
- package/dist/cst/BlockValue.js +4 -4
- package/dist/cst/Collection.js +8 -8
- package/dist/cst/CollectionItem.js +6 -8
- package/dist/cst/Comment.js +5 -7
- package/dist/cst/Directive.js +5 -7
- package/dist/cst/Document.js +8 -10
- package/dist/cst/FlowCollection.js +5 -7
- package/dist/cst/Node.js +12 -40
- package/dist/cst/ParseContext.js +32 -34
- package/dist/cst/PlainValue.js +1 -3
- package/dist/cst/QuoteDouble.js +1 -3
- package/dist/cst/QuoteSingle.js +1 -3
- package/dist/cst/Range.js +1 -3
- package/dist/cst/getLinePos.js +8 -12
- package/dist/cst/parse.js +1 -4
- package/dist/deprecation.js +34 -0
- package/dist/errors.js +29 -35
- package/dist/index.js +7 -4
- package/dist/listTagNames.js +1 -3
- package/dist/schema/Alias.js +67 -12
- package/dist/schema/Map.js +10 -74
- package/dist/schema/Merge.js +31 -0
- package/dist/schema/Node.js +1 -3
- package/dist/schema/Pair.js +46 -20
- package/dist/schema/Scalar.js +3 -5
- package/dist/schema/Seq.js +9 -5
- package/dist/schema/index.js +109 -74
- package/dist/schema/parseMap.js +18 -21
- package/dist/schema/parseSeq.js +9 -12
- package/dist/{schema/_string.js → stringify.js} +56 -65
- package/dist/tags/core.js +96 -0
- package/dist/tags/failsafe/index.js +17 -0
- package/dist/tags/failsafe/map.js +33 -0
- package/dist/tags/failsafe/seq.js +34 -0
- package/dist/tags/failsafe/string.js +40 -0
- package/dist/tags/index.js +50 -0
- package/dist/tags/json.js +67 -0
- package/dist/tags/options.js +35 -0
- package/dist/{schema/_binary.js → tags/yaml-1.1/binary.js} +18 -20
- package/dist/tags/yaml-1.1/index.js +131 -0
- package/dist/{schema/_omap.js → tags/yaml-1.1/omap.js} +16 -16
- package/dist/{schema/_pairs.js → tags/yaml-1.1/pairs.js} +9 -11
- package/dist/{schema/_set.js → tags/yaml-1.1/set.js} +12 -44
- package/dist/{schema/_timestamp.js → tags/yaml-1.1/timestamp.js} +7 -10
- package/dist/test-events.js +1 -4
- package/dist/toJSON.js +15 -5
- package/index.js +1 -0
- package/map.js +2 -1
- package/package.json +22 -17
- package/pair.js +2 -1
- package/parse-cst.js +1 -1
- package/scalar.js +2 -1
- package/schema.js +7 -3
- package/seq.js +2 -1
- package/types/binary.js +7 -1
- package/types/omap.js +2 -1
- package/types/pairs.js +2 -1
- package/types/set.js +2 -1
- package/types/timestamp.js +10 -1
- package/types.js +11 -0
- package/util.js +15 -0
- package/browser/dist/polyfill.js +0 -251
- package/browser/dist/schema/_set.js +0 -212
- package/browser/dist/schema/core.js +0 -98
- package/browser/dist/schema/failsafe.js +0 -125
- package/browser/dist/schema/json.js +0 -66
- package/browser/dist/schema/yaml-1.1.js +0 -140
- package/dist/linePos.js +0 -58
- package/dist/polyfill.js +0 -27
- package/dist/schema/core.js +0 -79
- package/dist/schema/failsafe.js +0 -74
- package/dist/schema/json.js +0 -56
- package/dist/schema/yaml-1.1.js +0 -115
|
@@ -7,8 +7,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
9
|
|
|
10
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
11
|
-
|
|
12
10
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
13
11
|
|
|
14
12
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
@@ -19,9 +17,11 @@ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/ge
|
|
|
19
17
|
|
|
20
18
|
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
21
19
|
|
|
20
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
21
|
+
|
|
22
22
|
var _addComment = _interopRequireDefault(require("../addComment"));
|
|
23
23
|
|
|
24
|
-
var
|
|
24
|
+
var _toJSON = _interopRequireDefault(require("../toJSON"));
|
|
25
25
|
|
|
26
26
|
var _Collection = _interopRequireDefault(require("./Collection"));
|
|
27
27
|
|
|
@@ -30,6 +30,19 @@ var _Node2 = _interopRequireDefault(require("./Node"));
|
|
|
30
30
|
var _Scalar = _interopRequireDefault(require("./Scalar"));
|
|
31
31
|
|
|
32
32
|
// Published as 'yaml/pair'
|
|
33
|
+
var stringifyKey = function stringifyKey(key, jsKey, ctx) {
|
|
34
|
+
if (jsKey === null) return '';
|
|
35
|
+
if ((0, _typeof2.default)(jsKey) !== 'object') return String(jsKey);
|
|
36
|
+
if (key instanceof _Node2.default && ctx && ctx.doc) return key.toString({
|
|
37
|
+
anchors: {},
|
|
38
|
+
doc: ctx.doc,
|
|
39
|
+
indent: '',
|
|
40
|
+
inFlow: true,
|
|
41
|
+
inStringifyKey: true
|
|
42
|
+
});
|
|
43
|
+
return JSON.stringify(jsKey);
|
|
44
|
+
};
|
|
45
|
+
|
|
33
46
|
var Pair =
|
|
34
47
|
/*#__PURE__*/
|
|
35
48
|
function (_Node) {
|
|
@@ -48,12 +61,27 @@ function (_Node) {
|
|
|
48
61
|
}
|
|
49
62
|
|
|
50
63
|
(0, _createClass2.default)(Pair, [{
|
|
64
|
+
key: "addToJSMap",
|
|
65
|
+
value: function addToJSMap(ctx, map) {
|
|
66
|
+
var key = (0, _toJSON.default)(this.key, '', ctx);
|
|
67
|
+
|
|
68
|
+
if (map instanceof Map) {
|
|
69
|
+
var value = (0, _toJSON.default)(this.value, key, ctx);
|
|
70
|
+
map.set(key, value);
|
|
71
|
+
} else if (map instanceof Set) {
|
|
72
|
+
map.add(key);
|
|
73
|
+
} else {
|
|
74
|
+
var stringKey = stringifyKey(this.key, key, ctx);
|
|
75
|
+
map[stringKey] = (0, _toJSON.default)(this.value, stringKey, ctx);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return map;
|
|
79
|
+
}
|
|
80
|
+
}, {
|
|
51
81
|
key: "toJSON",
|
|
52
|
-
value: function toJSON(_,
|
|
53
|
-
var pair = {};
|
|
54
|
-
|
|
55
|
-
pair[sk] = (0, _toJSON2.default)(this.value, sk, opt);
|
|
56
|
-
return pair;
|
|
82
|
+
value: function toJSON(_, ctx) {
|
|
83
|
+
var pair = ctx && ctx.mapAsMap ? new Map() : {};
|
|
84
|
+
return this.addToJSMap(ctx, pair);
|
|
57
85
|
}
|
|
58
86
|
}, {
|
|
59
87
|
key: "toString",
|
|
@@ -96,25 +124,37 @@ function (_Node) {
|
|
|
96
124
|
}
|
|
97
125
|
|
|
98
126
|
var vcb = '';
|
|
127
|
+
var valueComment = null;
|
|
99
128
|
|
|
100
|
-
if (value) {
|
|
129
|
+
if (value instanceof _Node2.default) {
|
|
101
130
|
if (value.spaceBefore) vcb = '\n';
|
|
102
131
|
|
|
103
132
|
if (value.commentBefore) {
|
|
104
133
|
var cs = value.commentBefore.replace(/^/gm, "".concat(ctx.indent, "#"));
|
|
105
134
|
vcb += "\n".concat(cs);
|
|
106
135
|
}
|
|
136
|
+
|
|
137
|
+
valueComment = value.comment;
|
|
138
|
+
} else if (value && (0, _typeof2.default)(value) === 'object') {
|
|
139
|
+
value = doc.schema.createNode(value, true);
|
|
107
140
|
}
|
|
108
141
|
|
|
109
142
|
ctx.implicitKey = false;
|
|
110
|
-
var valueComment = value instanceof _Node2.default && value.comment;
|
|
111
143
|
chompKeep = false;
|
|
112
144
|
var valueStr = doc.schema.stringify(value, ctx, function () {
|
|
113
145
|
return valueComment = null;
|
|
114
146
|
}, function () {
|
|
115
147
|
return chompKeep = true;
|
|
116
148
|
});
|
|
117
|
-
var ws =
|
|
149
|
+
var ws = ' ';
|
|
150
|
+
|
|
151
|
+
if (vcb || this.comment) {
|
|
152
|
+
ws = "".concat(vcb, "\n").concat(ctx.indent);
|
|
153
|
+
} else if (!explicitKey && value instanceof _Collection.default) {
|
|
154
|
+
var flow = valueStr[0] === '[' || valueStr[0] === '{';
|
|
155
|
+
if (!flow || valueStr.includes('\n')) ws = "\n".concat(ctx.indent);
|
|
156
|
+
}
|
|
157
|
+
|
|
118
158
|
if (chompKeep && !valueComment && onChompKeep) onChompKeep();
|
|
119
159
|
return (0, _addComment.default)(str + ws + valueStr, ctx.indent, valueComment);
|
|
120
160
|
}
|
|
@@ -127,22 +167,8 @@ function (_Node) {
|
|
|
127
167
|
if (this.key == null) this.key = new _Scalar.default(null);
|
|
128
168
|
this.key.commentBefore = cb;
|
|
129
169
|
}
|
|
130
|
-
}, {
|
|
131
|
-
key: "stringKey",
|
|
132
|
-
get: function get() {
|
|
133
|
-
var key = (0, _toJSON2.default)(this.key);
|
|
134
|
-
if (key === null) return '';
|
|
135
|
-
if ((0, _typeof2.default)(key) === 'object') try {
|
|
136
|
-
return JSON.stringify(key);
|
|
137
|
-
} catch (e) {
|
|
138
|
-
/* should not happen, but let's ignore in any case */
|
|
139
|
-
}
|
|
140
|
-
return String(key);
|
|
141
|
-
}
|
|
142
170
|
}]);
|
|
143
171
|
return Pair;
|
|
144
172
|
}(_Node2.default);
|
|
145
173
|
|
|
146
|
-
exports.default = Pair;
|
|
147
|
-
module.exports = exports.default;
|
|
148
|
-
module.exports.default = exports.default;
|
|
174
|
+
exports.default = Pair;
|
|
@@ -38,8 +38,8 @@ function (_Node) {
|
|
|
38
38
|
|
|
39
39
|
(0, _createClass2.default)(Scalar, [{
|
|
40
40
|
key: "toJSON",
|
|
41
|
-
value: function toJSON(arg,
|
|
42
|
-
return
|
|
41
|
+
value: function toJSON(arg, ctx) {
|
|
42
|
+
return ctx && ctx.keep ? this.value : (0, _toJSON2.default)(this.value, arg, ctx);
|
|
43
43
|
}
|
|
44
44
|
}, {
|
|
45
45
|
key: "toString",
|
|
@@ -50,6 +50,4 @@ function (_Node) {
|
|
|
50
50
|
return Scalar;
|
|
51
51
|
}(_Node2.default);
|
|
52
52
|
|
|
53
|
-
exports.default = Scalar;
|
|
54
|
-
module.exports = exports.default;
|
|
55
|
-
module.exports.default = exports.default;
|
|
53
|
+
exports.default = Scalar;
|
|
@@ -78,10 +78,35 @@ function (_Collection) {
|
|
|
78
78
|
}
|
|
79
79
|
}, {
|
|
80
80
|
key: "toJSON",
|
|
81
|
-
value: function toJSON(_,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
value: function toJSON(_, ctx) {
|
|
82
|
+
var seq = [];
|
|
83
|
+
if (ctx && ctx.onCreate) ctx.onCreate(seq);
|
|
84
|
+
var i = 0;
|
|
85
|
+
var _iteratorNormalCompletion = true;
|
|
86
|
+
var _didIteratorError = false;
|
|
87
|
+
var _iteratorError = undefined;
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
for (var _iterator = this.items[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
91
|
+
var item = _step.value;
|
|
92
|
+
seq.push((0, _toJSON2.default)(item, String(i++), ctx));
|
|
93
|
+
}
|
|
94
|
+
} catch (err) {
|
|
95
|
+
_didIteratorError = true;
|
|
96
|
+
_iteratorError = err;
|
|
97
|
+
} finally {
|
|
98
|
+
try {
|
|
99
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
100
|
+
_iterator.return();
|
|
101
|
+
}
|
|
102
|
+
} finally {
|
|
103
|
+
if (_didIteratorError) {
|
|
104
|
+
throw _iteratorError;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return seq;
|
|
85
110
|
}
|
|
86
111
|
}, {
|
|
87
112
|
key: "toString",
|
|
@@ -103,6 +128,4 @@ function (_Collection) {
|
|
|
103
128
|
return YAMLSeq;
|
|
104
129
|
}(_Collection2.default);
|
|
105
130
|
|
|
106
|
-
exports.default = YAMLSeq;
|
|
107
|
-
module.exports = exports.default;
|
|
108
|
-
module.exports.default = exports.default;
|
|
131
|
+
exports.default = YAMLSeq;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
|
4
|
-
|
|
5
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
6
4
|
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -17,76 +15,113 @@ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/creat
|
|
|
17
15
|
|
|
18
16
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
19
17
|
|
|
20
|
-
var
|
|
18
|
+
var _deprecation = require("../deprecation");
|
|
19
|
+
|
|
20
|
+
var _constants = require("../constants");
|
|
21
21
|
|
|
22
22
|
var _errors = require("../errors");
|
|
23
23
|
|
|
24
|
-
var
|
|
24
|
+
var _stringify = require("../stringify");
|
|
25
25
|
|
|
26
|
-
var
|
|
26
|
+
var _tags = require("../tags");
|
|
27
27
|
|
|
28
|
-
var
|
|
28
|
+
var _string = require("../tags/failsafe/string");
|
|
29
29
|
|
|
30
|
-
var
|
|
30
|
+
var _Alias = _interopRequireDefault(require("./Alias"));
|
|
31
31
|
|
|
32
|
-
var
|
|
32
|
+
var _Collection = _interopRequireDefault(require("./Collection"));
|
|
33
33
|
|
|
34
|
-
var
|
|
34
|
+
var _Node = _interopRequireDefault(require("./Node"));
|
|
35
35
|
|
|
36
36
|
var _Pair = _interopRequireDefault(require("./Pair"));
|
|
37
37
|
|
|
38
38
|
var _Scalar = _interopRequireDefault(require("./Scalar"));
|
|
39
39
|
|
|
40
|
-
var _string = require("./_string");
|
|
41
|
-
|
|
42
|
-
var _yaml = _interopRequireDefault(require("./yaml-1.1"));
|
|
43
|
-
|
|
44
40
|
var isMap = function isMap(_ref) {
|
|
45
41
|
var type = _ref.type;
|
|
46
|
-
return type ===
|
|
42
|
+
return type === _constants.Type.FLOW_MAP || type === _constants.Type.MAP;
|
|
47
43
|
};
|
|
48
44
|
|
|
49
45
|
var isSeq = function isSeq(_ref2) {
|
|
50
46
|
var type = _ref2.type;
|
|
51
|
-
return type ===
|
|
47
|
+
return type === _constants.Type.FLOW_SEQ || type === _constants.Type.SEQ;
|
|
52
48
|
};
|
|
53
49
|
|
|
54
50
|
var Schema =
|
|
55
51
|
/*#__PURE__*/
|
|
56
52
|
function () {
|
|
57
|
-
(0, _createClass2.default)(Schema, null, [{
|
|
58
|
-
key: "defaultStringify",
|
|
59
|
-
value: function defaultStringify(value) {
|
|
60
|
-
return JSON.stringify(value);
|
|
61
|
-
}
|
|
62
|
-
}]);
|
|
63
|
-
|
|
64
53
|
function Schema(_ref3) {
|
|
65
|
-
var
|
|
54
|
+
var customTags = _ref3.customTags,
|
|
55
|
+
merge = _ref3.merge,
|
|
66
56
|
schema = _ref3.schema,
|
|
67
|
-
|
|
57
|
+
deprecatedCustomTags = _ref3.tags;
|
|
68
58
|
(0, _classCallCheck2.default)(this, Schema);
|
|
69
59
|
this.merge = !!merge;
|
|
70
60
|
this.name = schema;
|
|
71
|
-
this.tags =
|
|
61
|
+
this.tags = _tags.schemas[schema.replace(/\W/g, '')]; // 'yaml-1.1' -> 'yaml11'
|
|
72
62
|
|
|
73
63
|
if (!this.tags) {
|
|
74
|
-
var keys = Object.keys(
|
|
64
|
+
var keys = Object.keys(_tags.schemas).map(function (key) {
|
|
75
65
|
return JSON.stringify(key);
|
|
76
|
-
});
|
|
77
|
-
throw new Error("Unknown schema; use one of ".concat(keys
|
|
66
|
+
}).join(', ');
|
|
67
|
+
throw new Error("Unknown schema \"".concat(schema, "\"; use one of ").concat(keys));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!customTags && deprecatedCustomTags) {
|
|
71
|
+
customTags = deprecatedCustomTags;
|
|
72
|
+
(0, _deprecation.warnOptionDeprecation)('tags', 'customTags');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (Array.isArray(customTags)) {
|
|
76
|
+
var _iteratorNormalCompletion = true;
|
|
77
|
+
var _didIteratorError = false;
|
|
78
|
+
var _iteratorError = undefined;
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
for (var _iterator = customTags[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
82
|
+
var tag = _step.value;
|
|
83
|
+
this.tags = this.tags.concat(tag);
|
|
84
|
+
}
|
|
85
|
+
} catch (err) {
|
|
86
|
+
_didIteratorError = true;
|
|
87
|
+
_iteratorError = err;
|
|
88
|
+
} finally {
|
|
89
|
+
try {
|
|
90
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
91
|
+
_iterator.return();
|
|
92
|
+
}
|
|
93
|
+
} finally {
|
|
94
|
+
if (_didIteratorError) {
|
|
95
|
+
throw _iteratorError;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
} else if (typeof customTags === 'function') {
|
|
100
|
+
this.tags = customTags(this.tags.slice());
|
|
78
101
|
}
|
|
79
102
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
103
|
+
for (var i = 0; i < this.tags.length; ++i) {
|
|
104
|
+
var _tag = this.tags[i];
|
|
105
|
+
|
|
106
|
+
if (typeof _tag === 'string') {
|
|
107
|
+
var tagObj = _tags.tags[_tag];
|
|
108
|
+
|
|
109
|
+
if (!tagObj) {
|
|
110
|
+
var _keys = Object.keys(_tags.tags).map(function (key) {
|
|
111
|
+
return JSON.stringify(key);
|
|
112
|
+
}).join(', ');
|
|
113
|
+
|
|
114
|
+
throw new Error("Unknown custom tag \"".concat(_tag, "\"; use one of ").concat(_keys));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
this.tags[i] = tagObj;
|
|
118
|
+
}
|
|
84
119
|
}
|
|
85
120
|
}
|
|
86
121
|
|
|
87
122
|
(0, _createClass2.default)(Schema, [{
|
|
88
123
|
key: "createNode",
|
|
89
|
-
value: function createNode(value, wrapScalars, tag,
|
|
124
|
+
value: function createNode(value, wrapScalars, tag, ctx) {
|
|
90
125
|
var tagObj;
|
|
91
126
|
|
|
92
127
|
if (tag) {
|
|
@@ -99,20 +134,54 @@ function () {
|
|
|
99
134
|
}) || match[0];
|
|
100
135
|
if (!tagObj) throw new Error("Tag ".concat(tag, " not found"));
|
|
101
136
|
} else {
|
|
137
|
+
// TODO: deprecate/remove class check
|
|
102
138
|
tagObj = this.tags.find(function (t) {
|
|
103
|
-
return t.class && value instanceof t.class && !t.format;
|
|
139
|
+
return (t.identify && t.identify(value) || t.class && value instanceof t.class) && !t.format;
|
|
104
140
|
});
|
|
105
141
|
|
|
106
142
|
if (!tagObj) {
|
|
107
|
-
if (value == null) return new _Scalar.default(null);
|
|
108
143
|
if (typeof value.toJSON === 'function') value = value.toJSON();
|
|
109
144
|
if ((0, _typeof2.default)(value) !== 'object') return wrapScalars ? new _Scalar.default(value) : value;
|
|
110
|
-
tagObj = value instanceof Map ?
|
|
145
|
+
tagObj = value instanceof Map ? _tags.tags.map : value[Symbol.iterator] ? _tags.tags.seq : _tags.tags.map;
|
|
111
146
|
}
|
|
112
147
|
}
|
|
113
148
|
|
|
114
|
-
if (
|
|
115
|
-
|
|
149
|
+
if (!ctx) ctx = {
|
|
150
|
+
wrapScalars: wrapScalars
|
|
151
|
+
};else ctx.wrapScalars = wrapScalars;
|
|
152
|
+
|
|
153
|
+
if (ctx.onTagObj) {
|
|
154
|
+
ctx.onTagObj(tagObj);
|
|
155
|
+
delete ctx.onTagObj;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
var obj = {};
|
|
159
|
+
|
|
160
|
+
if (value && (0, _typeof2.default)(value) === 'object' && ctx.prevObjects) {
|
|
161
|
+
var prev = ctx.prevObjects.find(function (o) {
|
|
162
|
+
return o.value === value;
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
if (prev) {
|
|
166
|
+
var alias = new _Alias.default(prev); // leaves source dirty; must be cleaned by caller
|
|
167
|
+
|
|
168
|
+
ctx.aliasNodes.push(alias);
|
|
169
|
+
return alias;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
obj.value = value;
|
|
173
|
+
ctx.prevObjects.push(obj);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
obj.node = tagObj.createNode ? tagObj.createNode(this, value, ctx) : wrapScalars ? new _Scalar.default(value) : value;
|
|
177
|
+
return obj.node;
|
|
178
|
+
}
|
|
179
|
+
}, {
|
|
180
|
+
key: "createPair",
|
|
181
|
+
value: function createPair(key, value, ctx) {
|
|
182
|
+
var k = this.createNode(key, ctx.wrapScalars, null, ctx);
|
|
183
|
+
var v = this.createNode(value, ctx.wrapScalars, null, ctx);
|
|
184
|
+
return new _Pair.default(k, v);
|
|
116
185
|
} // falls back to string on no match
|
|
117
186
|
|
|
118
187
|
}, {
|
|
@@ -130,7 +199,8 @@ function () {
|
|
|
130
199
|
var match = str.match(test);
|
|
131
200
|
|
|
132
201
|
if (match) {
|
|
133
|
-
var res =
|
|
202
|
+
var res = resolve.apply(null, match);
|
|
203
|
+
if (!(res instanceof _Scalar.default)) res = new _Scalar.default(res);
|
|
134
204
|
if (format) res.format = format;
|
|
135
205
|
return res;
|
|
136
206
|
}
|
|
@@ -160,7 +230,7 @@ function () {
|
|
|
160
230
|
if (!(res instanceof _Collection.default)) res = new _Scalar.default(res);
|
|
161
231
|
node.resolved = res;
|
|
162
232
|
} else {
|
|
163
|
-
var str = (0, _string.
|
|
233
|
+
var str = (0, _string.resolveString)(doc, node);
|
|
164
234
|
|
|
165
235
|
if (typeof str === 'string' && tags.length > 0) {
|
|
166
236
|
node.resolved = this.resolveScalar(str, tags);
|
|
@@ -173,7 +243,7 @@ function () {
|
|
|
173
243
|
}
|
|
174
244
|
|
|
175
245
|
if (!node.resolved) return null;
|
|
176
|
-
if (tagName) node.resolved.tag = tagName;
|
|
246
|
+
if (tagName && node.tag) node.resolved.tag = tagName;
|
|
177
247
|
return node.resolved;
|
|
178
248
|
}
|
|
179
249
|
}, {
|
|
@@ -210,37 +280,13 @@ function () {
|
|
|
210
280
|
}) || match[0];
|
|
211
281
|
}
|
|
212
282
|
|
|
213
|
-
if (item.value === null) {
|
|
214
|
-
var _tagObj = this.tags.find(function (t) {
|
|
215
|
-
return t.class === null && !t.format;
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
if (!_tagObj) throw new Error('Tag not resolved for null value');
|
|
219
|
-
return _tagObj;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
283
|
var tagObj, obj;
|
|
223
284
|
|
|
224
285
|
if (item instanceof _Scalar.default) {
|
|
225
|
-
|
|
226
|
-
case 'boolean':
|
|
227
|
-
obj = new Boolean();
|
|
228
|
-
break;
|
|
229
|
-
|
|
230
|
-
case 'number':
|
|
231
|
-
obj = new Number();
|
|
232
|
-
break;
|
|
233
|
-
|
|
234
|
-
case 'string':
|
|
235
|
-
obj = new String();
|
|
236
|
-
break;
|
|
237
|
-
|
|
238
|
-
default:
|
|
239
|
-
obj = item.value;
|
|
240
|
-
}
|
|
286
|
+
obj = item.value; // TODO: deprecate/remove class check
|
|
241
287
|
|
|
242
288
|
var _match = this.tags.filter(function (t) {
|
|
243
|
-
return t.
|
|
289
|
+
return t.identify && t.identify(obj) || t.class && obj instanceof t.class;
|
|
244
290
|
});
|
|
245
291
|
|
|
246
292
|
tagObj = _match.find(function (t) {
|
|
@@ -276,7 +322,7 @@ function () {
|
|
|
276
322
|
props.push("&".concat(anchor));
|
|
277
323
|
}
|
|
278
324
|
|
|
279
|
-
if (node.tag
|
|
325
|
+
if (node.tag) {
|
|
280
326
|
props.push(doc.stringifyTag(node.tag));
|
|
281
327
|
} else if (!tagObj.default) {
|
|
282
328
|
props.push(doc.stringifyTag(tagObj.tag));
|
|
@@ -288,15 +334,53 @@ function () {
|
|
|
288
334
|
key: "stringify",
|
|
289
335
|
value: function stringify(item, ctx, onComment, onChompKeep) {
|
|
290
336
|
var tagObj;
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
337
|
+
|
|
338
|
+
if (!(item instanceof _Node.default)) {
|
|
339
|
+
var createCtx = {
|
|
340
|
+
aliasNodes: [],
|
|
341
|
+
onTagObj: function onTagObj(o) {
|
|
342
|
+
return tagObj = o;
|
|
343
|
+
},
|
|
344
|
+
prevObjects: []
|
|
345
|
+
};
|
|
346
|
+
item = this.createNode(item, true, null, createCtx);
|
|
347
|
+
var anchors = ctx.doc.anchors;
|
|
348
|
+
var _iteratorNormalCompletion2 = true;
|
|
349
|
+
var _didIteratorError2 = false;
|
|
350
|
+
var _iteratorError2 = undefined;
|
|
351
|
+
|
|
352
|
+
try {
|
|
353
|
+
for (var _iterator2 = createCtx.aliasNodes[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
354
|
+
var alias = _step2.value;
|
|
355
|
+
alias.source = alias.source.node;
|
|
356
|
+
var name = anchors.getName(alias.source);
|
|
357
|
+
|
|
358
|
+
if (!name) {
|
|
359
|
+
name = anchors.newName();
|
|
360
|
+
anchors.map[name] = alias.source;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
} catch (err) {
|
|
364
|
+
_didIteratorError2 = true;
|
|
365
|
+
_iteratorError2 = err;
|
|
366
|
+
} finally {
|
|
367
|
+
try {
|
|
368
|
+
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
|
|
369
|
+
_iterator2.return();
|
|
370
|
+
}
|
|
371
|
+
} finally {
|
|
372
|
+
if (_didIteratorError2) {
|
|
373
|
+
throw _iteratorError2;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
294
379
|
ctx.tags = this;
|
|
295
380
|
if (item instanceof _Pair.default) return item.toString(ctx, onComment, onChompKeep);
|
|
296
381
|
if (!tagObj) tagObj = this.getTagObject(item);
|
|
297
382
|
var props = this.stringifyProps(item, tagObj, ctx);
|
|
298
|
-
var
|
|
299
|
-
var str = stringify(item, ctx, onComment, onChompKeep);
|
|
383
|
+
var str = typeof tagObj.stringify === 'function' ? tagObj.stringify(item, ctx, onComment, onChompKeep) : item instanceof _Collection.default ? item.toString(ctx, onComment, onChompKeep) : (0, _stringify.stringifyString)(item, ctx, onComment, onChompKeep);
|
|
300
384
|
return props ? item instanceof _Collection.default && str[0] !== '{' && str[0] !== '[' ? "".concat(props, "\n").concat(ctx.indent).concat(str) : "".concat(props, " ").concat(str) : str;
|
|
301
385
|
}
|
|
302
386
|
}]);
|
|
@@ -309,12 +393,4 @@ exports.default = Schema;
|
|
|
309
393
|
MAP: 'tag:yaml.org,2002:map',
|
|
310
394
|
SEQ: 'tag:yaml.org,2002:seq',
|
|
311
395
|
STR: 'tag:yaml.org,2002:str'
|
|
312
|
-
});
|
|
313
|
-
(0, _defineProperty2.default)(Schema, "tags", {
|
|
314
|
-
core: _core.default,
|
|
315
|
-
failsafe: _failsafe.default,
|
|
316
|
-
json: _json.default,
|
|
317
|
-
'yaml-1.1': _yaml.default
|
|
318
|
-
});
|
|
319
|
-
module.exports = exports.default;
|
|
320
|
-
module.exports.default = exports.default;
|
|
396
|
+
});
|