yaml 1.9.2 → 1.10.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 +4 -4
- package/browser/dist/PlainValue-ff5147c6.js +1277 -0
- package/browser/dist/Schema-2bf2c74e.js +679 -0
- package/browser/dist/index.js +869 -34
- package/browser/dist/legacy-exports.js +3 -0
- package/browser/dist/parse-cst.js +1904 -0
- package/browser/dist/resolveSeq-04825f30.js +2373 -0
- package/browser/dist/types.js +4 -0
- package/browser/dist/util.js +2 -0
- package/browser/dist/warnings-0e4b70d3.js +499 -0
- package/browser/index.js +1 -1
- package/browser/map.js +2 -4
- package/browser/pair.js +2 -4
- package/browser/parse-cst.js +1 -1
- package/browser/scalar.js +2 -4
- package/browser/schema.js +7 -10
- package/browser/seq.js +2 -4
- package/browser/types/binary.js +7 -5
- package/browser/types/omap.js +3 -4
- package/browser/types/pairs.js +3 -4
- package/browser/types/set.js +3 -4
- package/browser/types/timestamp.js +9 -5
- package/browser/types.js +1 -13
- package/browser/util.js +1 -18
- package/dist/Document-2cf6b08c.js +757 -0
- package/dist/PlainValue-ec8e588e.js +876 -0
- package/dist/Schema-42e9705c.js +522 -0
- package/dist/index.js +20 -84
- package/dist/legacy-exports.js +16 -0
- package/dist/parse-cst.js +1747 -0
- package/dist/resolveSeq-4a68b39b.js +2115 -0
- package/dist/test-events.js +11 -9
- package/dist/types.js +23 -0
- package/dist/util.js +19 -0
- package/dist/warnings-39684f17.js +416 -0
- package/index.d.ts +22 -8
- package/map.js +2 -2
- package/package.json +22 -39
- package/pair.js +2 -2
- package/parse-cst.js +1 -1
- package/scalar.js +2 -2
- package/schema.js +8 -6
- package/seq.js +2 -2
- package/types/binary.js +3 -2
- package/types/omap.js +3 -2
- package/types/pairs.js +3 -2
- package/types/set.js +3 -2
- package/types/timestamp.js +6 -6
- package/types.d.ts +113 -99
- package/types.js +16 -11
- package/types.mjs +15 -19
- package/util.js +14 -14
- package/util.mjs +13 -20
- package/browser/dist/Anchors.js +0 -130
- package/browser/dist/Document.js +0 -824
- package/browser/dist/addComment.js +0 -8
- package/browser/dist/constants.js +0 -26
- package/browser/dist/cst/Alias.js +0 -46
- package/browser/dist/cst/BlankLine.js +0 -52
- package/browser/dist/cst/BlockValue.js +0 -251
- package/browser/dist/cst/Collection.js +0 -278
- package/browser/dist/cst/CollectionItem.js +0 -140
- package/browser/dist/cst/Comment.js +0 -44
- package/browser/dist/cst/Directive.js +0 -76
- package/browser/dist/cst/Document.js +0 -286
- package/browser/dist/cst/FlowCollection.js +0 -220
- package/browser/dist/cst/Node.js +0 -386
- package/browser/dist/cst/ParseContext.js +0 -246
- package/browser/dist/cst/PlainValue.js +0 -170
- package/browser/dist/cst/QuoteDouble.js +0 -245
- package/browser/dist/cst/QuoteSingle.js +0 -120
- package/browser/dist/cst/Range.js +0 -64
- package/browser/dist/cst/parse.js +0 -48
- package/browser/dist/cst/source-utils.js +0 -168
- package/browser/dist/errors.js +0 -127
- package/browser/dist/foldFlowLines.js +0 -138
- package/browser/dist/listTagNames.js +0 -28
- package/browser/dist/schema/Alias.js +0 -135
- package/browser/dist/schema/Collection.js +0 -260
- package/browser/dist/schema/Map.js +0 -161
- package/browser/dist/schema/Merge.js +0 -118
- package/browser/dist/schema/Node.js +0 -4
- package/browser/dist/schema/Pair.js +0 -194
- package/browser/dist/schema/Scalar.js +0 -42
- package/browser/dist/schema/Seq.js +0 -116
- package/browser/dist/schema/index.js +0 -368
- package/browser/dist/schema/parseMap.js +0 -312
- package/browser/dist/schema/parseSeq.js +0 -168
- package/browser/dist/schema/parseUtils.js +0 -106
- package/browser/dist/stringify.js +0 -332
- package/browser/dist/tags/core.js +0 -141
- package/browser/dist/tags/failsafe/index.js +0 -4
- package/browser/dist/tags/failsafe/map.js +0 -53
- package/browser/dist/tags/failsafe/seq.js +0 -39
- package/browser/dist/tags/failsafe/string.js +0 -28
- package/browser/dist/tags/index.js +0 -36
- package/browser/dist/tags/json.js +0 -77
- package/browser/dist/tags/options.js +0 -26
- package/browser/dist/tags/yaml-1.1/binary.js +0 -87
- package/browser/dist/tags/yaml-1.1/index.js +0 -189
- package/browser/dist/tags/yaml-1.1/omap.js +0 -137
- package/browser/dist/tags/yaml-1.1/pairs.js +0 -78
- package/browser/dist/tags/yaml-1.1/set.js +0 -118
- package/browser/dist/tags/yaml-1.1/timestamp.js +0 -97
- package/browser/dist/test-events.js +0 -163
- package/browser/dist/toJSON.js +0 -19
- package/browser/dist/warnings.js +0 -39
- package/dist/Anchors.js +0 -120
- package/dist/Document.js +0 -714
- package/dist/addComment.js +0 -14
- package/dist/constants.js +0 -31
- package/dist/cst/Alias.js +0 -33
- package/dist/cst/BlankLine.js +0 -40
- package/dist/cst/BlockValue.js +0 -243
- package/dist/cst/Collection.js +0 -266
- package/dist/cst/CollectionItem.js +0 -135
- package/dist/cst/Comment.js +0 -33
- package/dist/cst/Directive.js +0 -59
- package/dist/cst/Document.js +0 -276
- package/dist/cst/FlowCollection.js +0 -213
- package/dist/cst/Node.js +0 -360
- package/dist/cst/ParseContext.js +0 -253
- package/dist/cst/PlainValue.js +0 -156
- package/dist/cst/QuoteDouble.js +0 -232
- package/dist/cst/QuoteSingle.js +0 -108
- package/dist/cst/Range.js +0 -60
- package/dist/cst/parse.js +0 -50
- package/dist/cst/source-utils.js +0 -175
- package/dist/errors.js +0 -97
- package/dist/foldFlowLines.js +0 -143
- package/dist/listTagNames.js +0 -33
- package/dist/schema/Alias.js +0 -105
- package/dist/schema/Collection.js +0 -184
- package/dist/schema/Map.js +0 -98
- package/dist/schema/Merge.js +0 -75
- package/dist/schema/Node.js +0 -7
- package/dist/schema/Pair.js +0 -174
- package/dist/schema/Scalar.js +0 -26
- package/dist/schema/Seq.js +0 -73
- package/dist/schema/index.js +0 -310
- package/dist/schema/parseMap.js +0 -334
- package/dist/schema/parseSeq.js +0 -175
- package/dist/schema/parseUtils.js +0 -101
- package/dist/stringify.js +0 -352
- package/dist/tags/core.js +0 -121
- package/dist/tags/failsafe/index.js +0 -12
- package/dist/tags/failsafe/map.js +0 -32
- package/dist/tags/failsafe/seq.js +0 -29
- package/dist/tags/failsafe/string.js +0 -37
- package/dist/tags/index.js +0 -53
- package/dist/tags/json.js +0 -64
- package/dist/tags/options.js +0 -36
- package/dist/tags/yaml-1.1/binary.js +0 -94
- package/dist/tags/yaml-1.1/index.js +0 -162
- package/dist/tags/yaml-1.1/omap.js +0 -100
- package/dist/tags/yaml-1.1/pairs.js +0 -75
- package/dist/tags/yaml-1.1/set.js +0 -82
- package/dist/tags/yaml-1.1/timestamp.js +0 -90
- package/dist/toJSON.js +0 -21
- package/dist/warnings.js +0 -48
|
@@ -1,368 +0,0 @@
|
|
|
1
|
-
import _typeof from "@babel/runtime/helpers/typeof";
|
|
2
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
5
|
-
|
|
6
|
-
function _createForOfIteratorHelper(o) { if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (o = _unsupportedIterableToArray(o))) { var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var it, normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
7
|
-
|
|
8
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
9
|
-
|
|
10
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
11
|
-
|
|
12
|
-
import { warnOptionDeprecation } from '../warnings';
|
|
13
|
-
import { Type } from '../constants';
|
|
14
|
-
import { YAMLReferenceError, YAMLWarning } from '../errors';
|
|
15
|
-
import { stringifyString } from '../stringify';
|
|
16
|
-
import { schemas, tags } from '../tags';
|
|
17
|
-
import { resolveString } from '../tags/failsafe/string';
|
|
18
|
-
import { Alias } from './Alias';
|
|
19
|
-
import { Collection } from './Collection';
|
|
20
|
-
import { Node } from './Node';
|
|
21
|
-
import { Pair } from './Pair';
|
|
22
|
-
import { Scalar } from './Scalar';
|
|
23
|
-
|
|
24
|
-
var isMap = function isMap(_ref) {
|
|
25
|
-
var type = _ref.type;
|
|
26
|
-
return type === Type.FLOW_MAP || type === Type.MAP;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
var isSeq = function isSeq(_ref2) {
|
|
30
|
-
var type = _ref2.type;
|
|
31
|
-
return type === Type.FLOW_SEQ || type === Type.SEQ;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export var Schema = /*#__PURE__*/function () {
|
|
35
|
-
function Schema(_ref3) {
|
|
36
|
-
var customTags = _ref3.customTags,
|
|
37
|
-
merge = _ref3.merge,
|
|
38
|
-
schema = _ref3.schema,
|
|
39
|
-
sortMapEntries = _ref3.sortMapEntries,
|
|
40
|
-
deprecatedCustomTags = _ref3.tags;
|
|
41
|
-
|
|
42
|
-
_classCallCheck(this, Schema);
|
|
43
|
-
|
|
44
|
-
this.merge = !!merge;
|
|
45
|
-
this.name = schema;
|
|
46
|
-
this.sortMapEntries = sortMapEntries === true ? function (a, b) {
|
|
47
|
-
return a.key < b.key ? -1 : a.key > b.key ? 1 : 0;
|
|
48
|
-
} : sortMapEntries || null;
|
|
49
|
-
this.tags = schemas[schema.replace(/\W/g, '')]; // 'yaml-1.1' -> 'yaml11'
|
|
50
|
-
|
|
51
|
-
if (!this.tags) {
|
|
52
|
-
var keys = Object.keys(schemas).map(function (key) {
|
|
53
|
-
return JSON.stringify(key);
|
|
54
|
-
}).join(', ');
|
|
55
|
-
throw new Error("Unknown schema \"".concat(schema, "\"; use one of ").concat(keys));
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (!customTags && deprecatedCustomTags) {
|
|
59
|
-
customTags = deprecatedCustomTags;
|
|
60
|
-
warnOptionDeprecation('tags', 'customTags');
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (Array.isArray(customTags)) {
|
|
64
|
-
var _iterator = _createForOfIteratorHelper(customTags),
|
|
65
|
-
_step;
|
|
66
|
-
|
|
67
|
-
try {
|
|
68
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
69
|
-
var tag = _step.value;
|
|
70
|
-
this.tags = this.tags.concat(tag);
|
|
71
|
-
}
|
|
72
|
-
} catch (err) {
|
|
73
|
-
_iterator.e(err);
|
|
74
|
-
} finally {
|
|
75
|
-
_iterator.f();
|
|
76
|
-
}
|
|
77
|
-
} else if (typeof customTags === 'function') {
|
|
78
|
-
this.tags = customTags(this.tags.slice());
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
for (var i = 0; i < this.tags.length; ++i) {
|
|
82
|
-
var _tag = this.tags[i];
|
|
83
|
-
|
|
84
|
-
if (typeof _tag === 'string') {
|
|
85
|
-
var tagObj = tags[_tag];
|
|
86
|
-
|
|
87
|
-
if (!tagObj) {
|
|
88
|
-
var _keys = Object.keys(tags).map(function (key) {
|
|
89
|
-
return JSON.stringify(key);
|
|
90
|
-
}).join(', ');
|
|
91
|
-
|
|
92
|
-
throw new Error("Unknown custom tag \"".concat(_tag, "\"; use one of ").concat(_keys));
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
this.tags[i] = tagObj;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
_createClass(Schema, [{
|
|
101
|
-
key: "createNode",
|
|
102
|
-
value: function createNode(value, wrapScalars, tag, ctx) {
|
|
103
|
-
if (value instanceof Node) return value;
|
|
104
|
-
var tagObj;
|
|
105
|
-
|
|
106
|
-
if (tag) {
|
|
107
|
-
if (tag.startsWith('!!')) tag = Schema.defaultPrefix + tag.slice(2);
|
|
108
|
-
var match = this.tags.filter(function (t) {
|
|
109
|
-
return t.tag === tag;
|
|
110
|
-
});
|
|
111
|
-
tagObj = match.find(function (t) {
|
|
112
|
-
return !t.format;
|
|
113
|
-
}) || match[0];
|
|
114
|
-
if (!tagObj) throw new Error("Tag ".concat(tag, " not found"));
|
|
115
|
-
} else {
|
|
116
|
-
// TODO: deprecate/remove class check
|
|
117
|
-
tagObj = this.tags.find(function (t) {
|
|
118
|
-
return (t.identify && t.identify(value) || t.class && value instanceof t.class) && !t.format;
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
if (!tagObj) {
|
|
122
|
-
if (typeof value.toJSON === 'function') value = value.toJSON();
|
|
123
|
-
if (_typeof(value) !== 'object') return wrapScalars ? new Scalar(value) : value;
|
|
124
|
-
tagObj = value instanceof Map ? tags.map : value[Symbol.iterator] ? tags.seq : tags.map;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (!ctx) ctx = {
|
|
129
|
-
wrapScalars: wrapScalars
|
|
130
|
-
};else ctx.wrapScalars = wrapScalars;
|
|
131
|
-
|
|
132
|
-
if (ctx.onTagObj) {
|
|
133
|
-
ctx.onTagObj(tagObj);
|
|
134
|
-
delete ctx.onTagObj;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
var obj = {};
|
|
138
|
-
|
|
139
|
-
if (value && _typeof(value) === 'object' && ctx.prevObjects) {
|
|
140
|
-
var prev = ctx.prevObjects.get(value);
|
|
141
|
-
|
|
142
|
-
if (prev) {
|
|
143
|
-
var alias = new Alias(prev); // leaves source dirty; must be cleaned by caller
|
|
144
|
-
|
|
145
|
-
ctx.aliasNodes.push(alias);
|
|
146
|
-
return alias;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
obj.value = value;
|
|
150
|
-
ctx.prevObjects.set(value, obj);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
obj.node = tagObj.createNode ? tagObj.createNode(this, value, ctx) : wrapScalars ? new Scalar(value) : value;
|
|
154
|
-
if (tag && obj.node instanceof Node) obj.node.tag = tag;
|
|
155
|
-
return obj.node;
|
|
156
|
-
}
|
|
157
|
-
}, {
|
|
158
|
-
key: "createPair",
|
|
159
|
-
value: function createPair(key, value, ctx) {
|
|
160
|
-
var k = this.createNode(key, ctx.wrapScalars, null, ctx);
|
|
161
|
-
var v = this.createNode(value, ctx.wrapScalars, null, ctx);
|
|
162
|
-
return new Pair(k, v);
|
|
163
|
-
} // falls back to string on no match
|
|
164
|
-
|
|
165
|
-
}, {
|
|
166
|
-
key: "resolveScalar",
|
|
167
|
-
value: function resolveScalar(str, tags) {
|
|
168
|
-
if (!tags) tags = this.tags;
|
|
169
|
-
|
|
170
|
-
for (var i = 0; i < tags.length; ++i) {
|
|
171
|
-
var _tags$i = tags[i],
|
|
172
|
-
format = _tags$i.format,
|
|
173
|
-
test = _tags$i.test,
|
|
174
|
-
resolve = _tags$i.resolve;
|
|
175
|
-
|
|
176
|
-
if (test) {
|
|
177
|
-
var match = str.match(test);
|
|
178
|
-
|
|
179
|
-
if (match) {
|
|
180
|
-
var res = resolve.apply(null, match);
|
|
181
|
-
if (!(res instanceof Scalar)) res = new Scalar(res);
|
|
182
|
-
if (format) res.format = format;
|
|
183
|
-
return res;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
if (this.tags.scalarFallback) str = this.tags.scalarFallback(str);
|
|
189
|
-
return new Scalar(str);
|
|
190
|
-
} // sets node.resolved on success
|
|
191
|
-
|
|
192
|
-
}, {
|
|
193
|
-
key: "resolveNode",
|
|
194
|
-
value: function resolveNode(doc, node, tagName) {
|
|
195
|
-
var tags = this.tags.filter(function (_ref4) {
|
|
196
|
-
var tag = _ref4.tag;
|
|
197
|
-
return tag === tagName;
|
|
198
|
-
});
|
|
199
|
-
var generic = tags.find(function (_ref5) {
|
|
200
|
-
var test = _ref5.test;
|
|
201
|
-
return !test;
|
|
202
|
-
});
|
|
203
|
-
if (node.error) doc.errors.push(node.error);
|
|
204
|
-
|
|
205
|
-
try {
|
|
206
|
-
if (generic) {
|
|
207
|
-
var res = generic.resolve(doc, node);
|
|
208
|
-
if (!(res instanceof Collection)) res = new Scalar(res);
|
|
209
|
-
node.resolved = res;
|
|
210
|
-
} else {
|
|
211
|
-
var str = resolveString(doc, node);
|
|
212
|
-
|
|
213
|
-
if (typeof str === 'string' && tags.length > 0) {
|
|
214
|
-
node.resolved = this.resolveScalar(str, tags);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
} catch (error) {
|
|
218
|
-
/* istanbul ignore if */
|
|
219
|
-
if (!error.source) error.source = node;
|
|
220
|
-
doc.errors.push(error);
|
|
221
|
-
node.resolved = null;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
if (!node.resolved) return null;
|
|
225
|
-
if (tagName && node.tag) node.resolved.tag = tagName;
|
|
226
|
-
return node.resolved;
|
|
227
|
-
}
|
|
228
|
-
}, {
|
|
229
|
-
key: "resolveNodeWithFallback",
|
|
230
|
-
value: function resolveNodeWithFallback(doc, node, tagName) {
|
|
231
|
-
var res = this.resolveNode(doc, node, tagName);
|
|
232
|
-
if (Object.prototype.hasOwnProperty.call(node, 'resolved')) return res;
|
|
233
|
-
var fallback = isMap(node) ? Schema.defaultTags.MAP : isSeq(node) ? Schema.defaultTags.SEQ : Schema.defaultTags.STR;
|
|
234
|
-
/* istanbul ignore else */
|
|
235
|
-
|
|
236
|
-
if (fallback) {
|
|
237
|
-
doc.warnings.push(new YAMLWarning(node, "The tag ".concat(tagName, " is unavailable, falling back to ").concat(fallback)));
|
|
238
|
-
|
|
239
|
-
var _res = this.resolveNode(doc, node, fallback);
|
|
240
|
-
|
|
241
|
-
_res.tag = tagName;
|
|
242
|
-
return _res;
|
|
243
|
-
} else {
|
|
244
|
-
doc.errors.push(new YAMLReferenceError(node, "The tag ".concat(tagName, " is unavailable")));
|
|
245
|
-
return null;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}, {
|
|
249
|
-
key: "getTagObject",
|
|
250
|
-
value: function getTagObject(item) {
|
|
251
|
-
if (item instanceof Alias) return Alias;
|
|
252
|
-
|
|
253
|
-
if (item.tag) {
|
|
254
|
-
var match = this.tags.filter(function (t) {
|
|
255
|
-
return t.tag === item.tag;
|
|
256
|
-
});
|
|
257
|
-
if (match.length > 0) return match.find(function (t) {
|
|
258
|
-
return t.format === item.format;
|
|
259
|
-
}) || match[0];
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
var tagObj, obj;
|
|
263
|
-
|
|
264
|
-
if (item instanceof Scalar) {
|
|
265
|
-
obj = item.value; // TODO: deprecate/remove class check
|
|
266
|
-
|
|
267
|
-
var _match = this.tags.filter(function (t) {
|
|
268
|
-
return t.identify && t.identify(obj) || t.class && obj instanceof t.class;
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
tagObj = _match.find(function (t) {
|
|
272
|
-
return t.format === item.format;
|
|
273
|
-
}) || _match.find(function (t) {
|
|
274
|
-
return !t.format;
|
|
275
|
-
});
|
|
276
|
-
} else {
|
|
277
|
-
obj = item;
|
|
278
|
-
tagObj = this.tags.find(function (t) {
|
|
279
|
-
return t.nodeClass && obj instanceof t.nodeClass;
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
if (!tagObj) {
|
|
284
|
-
var name = obj && obj.constructor ? obj.constructor.name : _typeof(obj);
|
|
285
|
-
throw new Error("Tag not resolved for ".concat(name, " value"));
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
return tagObj;
|
|
289
|
-
} // needs to be called before stringifier to allow for circular anchor refs
|
|
290
|
-
|
|
291
|
-
}, {
|
|
292
|
-
key: "stringifyProps",
|
|
293
|
-
value: function stringifyProps(node, tagObj, _ref6) {
|
|
294
|
-
var anchors = _ref6.anchors,
|
|
295
|
-
doc = _ref6.doc;
|
|
296
|
-
var props = [];
|
|
297
|
-
var anchor = doc.anchors.getName(node);
|
|
298
|
-
|
|
299
|
-
if (anchor) {
|
|
300
|
-
anchors[anchor] = node;
|
|
301
|
-
props.push("&".concat(anchor));
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
if (node.tag) {
|
|
305
|
-
props.push(doc.stringifyTag(node.tag));
|
|
306
|
-
} else if (!tagObj.default) {
|
|
307
|
-
props.push(doc.stringifyTag(tagObj.tag));
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
return props.join(' ');
|
|
311
|
-
}
|
|
312
|
-
}, {
|
|
313
|
-
key: "stringify",
|
|
314
|
-
value: function stringify(item, ctx, onComment, onChompKeep) {
|
|
315
|
-
var tagObj;
|
|
316
|
-
|
|
317
|
-
if (!(item instanceof Node)) {
|
|
318
|
-
var createCtx = {
|
|
319
|
-
aliasNodes: [],
|
|
320
|
-
onTagObj: function onTagObj(o) {
|
|
321
|
-
return tagObj = o;
|
|
322
|
-
},
|
|
323
|
-
prevObjects: new Map()
|
|
324
|
-
};
|
|
325
|
-
item = this.createNode(item, true, null, createCtx);
|
|
326
|
-
var anchors = ctx.doc.anchors;
|
|
327
|
-
|
|
328
|
-
var _iterator2 = _createForOfIteratorHelper(createCtx.aliasNodes),
|
|
329
|
-
_step2;
|
|
330
|
-
|
|
331
|
-
try {
|
|
332
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
333
|
-
var alias = _step2.value;
|
|
334
|
-
alias.source = alias.source.node;
|
|
335
|
-
var name = anchors.getName(alias.source);
|
|
336
|
-
|
|
337
|
-
if (!name) {
|
|
338
|
-
name = anchors.newName();
|
|
339
|
-
anchors.map[name] = alias.source;
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
} catch (err) {
|
|
343
|
-
_iterator2.e(err);
|
|
344
|
-
} finally {
|
|
345
|
-
_iterator2.f();
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
ctx.tags = this;
|
|
350
|
-
if (item instanceof Pair) return item.toString(ctx, onComment, onChompKeep);
|
|
351
|
-
if (!tagObj) tagObj = this.getTagObject(item);
|
|
352
|
-
var props = this.stringifyProps(item, tagObj, ctx);
|
|
353
|
-
if (props.length > 0) ctx.indentAtStart = (ctx.indentAtStart || 0) + props.length + 1;
|
|
354
|
-
var str = typeof tagObj.stringify === 'function' ? tagObj.stringify(item, ctx, onComment, onChompKeep) : item instanceof Collection ? item.toString(ctx, onComment, onChompKeep) : stringifyString(item, ctx, onComment, onChompKeep);
|
|
355
|
-
return props ? item instanceof Collection && str[0] !== '{' && str[0] !== '[' ? "".concat(props, "\n").concat(ctx.indent).concat(str) : "".concat(props, " ").concat(str) : str;
|
|
356
|
-
}
|
|
357
|
-
}]);
|
|
358
|
-
|
|
359
|
-
return Schema;
|
|
360
|
-
}();
|
|
361
|
-
|
|
362
|
-
_defineProperty(Schema, "defaultPrefix", 'tag:yaml.org,2002:');
|
|
363
|
-
|
|
364
|
-
_defineProperty(Schema, "defaultTags", {
|
|
365
|
-
MAP: 'tag:yaml.org,2002:map',
|
|
366
|
-
SEQ: 'tag:yaml.org,2002:seq',
|
|
367
|
-
STR: 'tag:yaml.org,2002:str'
|
|
368
|
-
});
|
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
import { Char, Type } from '../constants';
|
|
2
|
-
import { PlainValue } from '../cst/PlainValue';
|
|
3
|
-
import { YAMLSemanticError, YAMLSyntaxError, YAMLWarning } from '../errors';
|
|
4
|
-
import { YAMLMap } from './Map';
|
|
5
|
-
import { Merge, MERGE_KEY } from './Merge';
|
|
6
|
-
import { Pair } from './Pair';
|
|
7
|
-
import { checkFlowCollectionEnd, checkKeyLength, resolveComments } from './parseUtils';
|
|
8
|
-
import { Alias } from './Alias';
|
|
9
|
-
import { Collection } from './Collection';
|
|
10
|
-
export function parseMap(doc, cst) {
|
|
11
|
-
if (cst.type !== Type.MAP && cst.type !== Type.FLOW_MAP) {
|
|
12
|
-
var msg = "A ".concat(cst.type, " node cannot be resolved as a mapping");
|
|
13
|
-
doc.errors.push(new YAMLSyntaxError(cst, msg));
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
var _ref = cst.type === Type.FLOW_MAP ? resolveFlowMapItems(doc, cst) : resolveBlockMapItems(doc, cst),
|
|
18
|
-
comments = _ref.comments,
|
|
19
|
-
items = _ref.items;
|
|
20
|
-
|
|
21
|
-
var map = new YAMLMap();
|
|
22
|
-
map.items = items;
|
|
23
|
-
resolveComments(map, comments);
|
|
24
|
-
var hasCollectionKey = false;
|
|
25
|
-
|
|
26
|
-
for (var i = 0; i < items.length; ++i) {
|
|
27
|
-
var iKey = items[i].key;
|
|
28
|
-
if (iKey instanceof Collection) hasCollectionKey = true;
|
|
29
|
-
|
|
30
|
-
if (doc.schema.merge && iKey && iKey.value === MERGE_KEY) {
|
|
31
|
-
items[i] = new Merge(items[i]);
|
|
32
|
-
var sources = items[i].value.items;
|
|
33
|
-
var error = null;
|
|
34
|
-
sources.some(function (node) {
|
|
35
|
-
if (node instanceof Alias) {
|
|
36
|
-
// During parsing, alias sources are CST nodes; to account for
|
|
37
|
-
// circular references their resolved values can't be used here.
|
|
38
|
-
var type = node.source.type;
|
|
39
|
-
if (type === Type.MAP || type === Type.FLOW_MAP) return false;
|
|
40
|
-
return error = 'Merge nodes aliases can only point to maps';
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return error = 'Merge nodes can only have Alias nodes as values';
|
|
44
|
-
});
|
|
45
|
-
if (error) doc.errors.push(new YAMLSemanticError(cst, error));
|
|
46
|
-
} else {
|
|
47
|
-
for (var j = i + 1; j < items.length; ++j) {
|
|
48
|
-
var jKey = items[j].key;
|
|
49
|
-
|
|
50
|
-
if (iKey === jKey || iKey && jKey && Object.prototype.hasOwnProperty.call(iKey, 'value') && iKey.value === jKey.value) {
|
|
51
|
-
var _msg = "Map keys must be unique; \"".concat(iKey, "\" is repeated");
|
|
52
|
-
|
|
53
|
-
doc.errors.push(new YAMLSemanticError(cst, _msg));
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (hasCollectionKey && !doc.options.mapAsMap) {
|
|
61
|
-
var warn = 'Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.';
|
|
62
|
-
doc.warnings.push(new YAMLWarning(cst, warn));
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
cst.resolved = map;
|
|
66
|
-
return map;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
var valueHasPairComment = function valueHasPairComment(_ref2) {
|
|
70
|
-
var _ref2$context = _ref2.context,
|
|
71
|
-
lineStart = _ref2$context.lineStart,
|
|
72
|
-
node = _ref2$context.node,
|
|
73
|
-
src = _ref2$context.src,
|
|
74
|
-
props = _ref2.props;
|
|
75
|
-
if (props.length === 0) return false;
|
|
76
|
-
var start = props[0].start;
|
|
77
|
-
if (node && start > node.valueRange.start) return false;
|
|
78
|
-
if (src[start] !== Char.COMMENT) return false;
|
|
79
|
-
|
|
80
|
-
for (var i = lineStart; i < start; ++i) {
|
|
81
|
-
if (src[i] === '\n') return false;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return true;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
function resolvePairComment(item, pair) {
|
|
88
|
-
if (!valueHasPairComment(item)) return;
|
|
89
|
-
var comment = item.getPropValue(0, Char.COMMENT, true);
|
|
90
|
-
var found = false;
|
|
91
|
-
var cb = pair.value.commentBefore;
|
|
92
|
-
|
|
93
|
-
if (cb && cb.startsWith(comment)) {
|
|
94
|
-
pair.value.commentBefore = cb.substr(comment.length + 1);
|
|
95
|
-
found = true;
|
|
96
|
-
} else {
|
|
97
|
-
var cc = pair.value.comment;
|
|
98
|
-
|
|
99
|
-
if (!item.node && cc && cc.startsWith(comment)) {
|
|
100
|
-
pair.value.comment = cc.substr(comment.length + 1);
|
|
101
|
-
found = true;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (found) pair.comment = comment;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function resolveBlockMapItems(doc, cst) {
|
|
109
|
-
var comments = [];
|
|
110
|
-
var items = [];
|
|
111
|
-
var key = undefined;
|
|
112
|
-
var keyStart = null;
|
|
113
|
-
|
|
114
|
-
for (var i = 0; i < cst.items.length; ++i) {
|
|
115
|
-
var item = cst.items[i];
|
|
116
|
-
|
|
117
|
-
switch (item.type) {
|
|
118
|
-
case Type.BLANK_LINE:
|
|
119
|
-
comments.push({
|
|
120
|
-
afterKey: !!key,
|
|
121
|
-
before: items.length
|
|
122
|
-
});
|
|
123
|
-
break;
|
|
124
|
-
|
|
125
|
-
case Type.COMMENT:
|
|
126
|
-
comments.push({
|
|
127
|
-
afterKey: !!key,
|
|
128
|
-
before: items.length,
|
|
129
|
-
comment: item.comment
|
|
130
|
-
});
|
|
131
|
-
break;
|
|
132
|
-
|
|
133
|
-
case Type.MAP_KEY:
|
|
134
|
-
if (key !== undefined) items.push(new Pair(key));
|
|
135
|
-
if (item.error) doc.errors.push(item.error);
|
|
136
|
-
key = doc.resolveNode(item.node);
|
|
137
|
-
keyStart = null;
|
|
138
|
-
break;
|
|
139
|
-
|
|
140
|
-
case Type.MAP_VALUE:
|
|
141
|
-
{
|
|
142
|
-
if (key === undefined) key = null;
|
|
143
|
-
if (item.error) doc.errors.push(item.error);
|
|
144
|
-
|
|
145
|
-
if (!item.context.atLineStart && item.node && item.node.type === Type.MAP && !item.node.context.atLineStart) {
|
|
146
|
-
var msg = 'Nested mappings are not allowed in compact mappings';
|
|
147
|
-
doc.errors.push(new YAMLSemanticError(item.node, msg));
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
var valueNode = item.node;
|
|
151
|
-
|
|
152
|
-
if (!valueNode && item.props.length > 0) {
|
|
153
|
-
// Comments on an empty mapping value need to be preserved, so we
|
|
154
|
-
// need to construct a minimal empty node here to use instead of the
|
|
155
|
-
// missing `item.node`. -- eemeli/yaml#19
|
|
156
|
-
valueNode = new PlainValue(Type.PLAIN, []);
|
|
157
|
-
valueNode.context = {
|
|
158
|
-
parent: item,
|
|
159
|
-
src: item.context.src
|
|
160
|
-
};
|
|
161
|
-
var pos = item.range.start + 1;
|
|
162
|
-
valueNode.range = {
|
|
163
|
-
start: pos,
|
|
164
|
-
end: pos
|
|
165
|
-
};
|
|
166
|
-
valueNode.valueRange = {
|
|
167
|
-
start: pos,
|
|
168
|
-
end: pos
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
if (typeof item.range.origStart === 'number') {
|
|
172
|
-
var origPos = item.range.origStart + 1;
|
|
173
|
-
valueNode.range.origStart = valueNode.range.origEnd = origPos;
|
|
174
|
-
valueNode.valueRange.origStart = valueNode.valueRange.origEnd = origPos;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
var pair = new Pair(key, doc.resolveNode(valueNode));
|
|
179
|
-
resolvePairComment(item, pair);
|
|
180
|
-
items.push(pair);
|
|
181
|
-
checkKeyLength(doc.errors, cst, i, key, keyStart);
|
|
182
|
-
key = undefined;
|
|
183
|
-
keyStart = null;
|
|
184
|
-
}
|
|
185
|
-
break;
|
|
186
|
-
|
|
187
|
-
default:
|
|
188
|
-
if (key !== undefined) items.push(new Pair(key));
|
|
189
|
-
key = doc.resolveNode(item);
|
|
190
|
-
keyStart = item.range.start;
|
|
191
|
-
if (item.error) doc.errors.push(item.error);
|
|
192
|
-
|
|
193
|
-
next: for (var j = i + 1;; ++j) {
|
|
194
|
-
var nextItem = cst.items[j];
|
|
195
|
-
|
|
196
|
-
switch (nextItem && nextItem.type) {
|
|
197
|
-
case Type.BLANK_LINE:
|
|
198
|
-
case Type.COMMENT:
|
|
199
|
-
continue next;
|
|
200
|
-
|
|
201
|
-
case Type.MAP_VALUE:
|
|
202
|
-
break next;
|
|
203
|
-
|
|
204
|
-
default:
|
|
205
|
-
doc.errors.push(new YAMLSemanticError(item, 'Implicit map keys need to be followed by map values'));
|
|
206
|
-
break next;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
if (item.valueRangeContainsNewline) {
|
|
211
|
-
var _msg2 = 'Implicit map keys need to be on a single line';
|
|
212
|
-
doc.errors.push(new YAMLSemanticError(item, _msg2));
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
if (key !== undefined) items.push(new Pair(key));
|
|
219
|
-
return {
|
|
220
|
-
comments: comments,
|
|
221
|
-
items: items
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
function resolveFlowMapItems(doc, cst) {
|
|
226
|
-
var comments = [];
|
|
227
|
-
var items = [];
|
|
228
|
-
var key = undefined;
|
|
229
|
-
var keyStart = null;
|
|
230
|
-
var explicitKey = false;
|
|
231
|
-
var next = '{';
|
|
232
|
-
|
|
233
|
-
for (var i = 0; i < cst.items.length; ++i) {
|
|
234
|
-
checkKeyLength(doc.errors, cst, i, key, keyStart);
|
|
235
|
-
var item = cst.items[i];
|
|
236
|
-
|
|
237
|
-
if (typeof item.char === 'string') {
|
|
238
|
-
var char = item.char,
|
|
239
|
-
offset = item.offset;
|
|
240
|
-
|
|
241
|
-
if (char === '?' && key === undefined && !explicitKey) {
|
|
242
|
-
explicitKey = true;
|
|
243
|
-
next = ':';
|
|
244
|
-
continue;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
if (char === ':') {
|
|
248
|
-
if (key === undefined) key = null;
|
|
249
|
-
|
|
250
|
-
if (next === ':') {
|
|
251
|
-
next = ',';
|
|
252
|
-
continue;
|
|
253
|
-
}
|
|
254
|
-
} else {
|
|
255
|
-
if (explicitKey) {
|
|
256
|
-
if (key === undefined && char !== ',') key = null;
|
|
257
|
-
explicitKey = false;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
if (key !== undefined) {
|
|
261
|
-
items.push(new Pair(key));
|
|
262
|
-
key = undefined;
|
|
263
|
-
keyStart = null;
|
|
264
|
-
|
|
265
|
-
if (char === ',') {
|
|
266
|
-
next = ':';
|
|
267
|
-
continue;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
if (char === '}') {
|
|
273
|
-
if (i === cst.items.length - 1) continue;
|
|
274
|
-
} else if (char === next) {
|
|
275
|
-
next = ':';
|
|
276
|
-
continue;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
var msg = "Flow map contains an unexpected ".concat(char);
|
|
280
|
-
var err = new YAMLSyntaxError(cst, msg);
|
|
281
|
-
err.offset = offset;
|
|
282
|
-
doc.errors.push(err);
|
|
283
|
-
} else if (item.type === Type.BLANK_LINE) {
|
|
284
|
-
comments.push({
|
|
285
|
-
afterKey: !!key,
|
|
286
|
-
before: items.length
|
|
287
|
-
});
|
|
288
|
-
} else if (item.type === Type.COMMENT) {
|
|
289
|
-
comments.push({
|
|
290
|
-
afterKey: !!key,
|
|
291
|
-
before: items.length,
|
|
292
|
-
comment: item.comment
|
|
293
|
-
});
|
|
294
|
-
} else if (key === undefined) {
|
|
295
|
-
if (next === ',') doc.errors.push(new YAMLSemanticError(item, 'Separator , missing in flow map'));
|
|
296
|
-
key = doc.resolveNode(item);
|
|
297
|
-
keyStart = explicitKey ? null : item.range.start; // TODO: add error for non-explicit multiline plain key
|
|
298
|
-
} else {
|
|
299
|
-
if (next !== ',') doc.errors.push(new YAMLSemanticError(item, 'Indicator : missing in flow map entry'));
|
|
300
|
-
items.push(new Pair(key, doc.resolveNode(item)));
|
|
301
|
-
key = undefined;
|
|
302
|
-
explicitKey = false;
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
checkFlowCollectionEnd(doc.errors, cst);
|
|
307
|
-
if (key !== undefined) items.push(new Pair(key));
|
|
308
|
-
return {
|
|
309
|
-
comments: comments,
|
|
310
|
-
items: items
|
|
311
|
-
};
|
|
312
|
-
}
|