yaml 1.3.1 → 1.5.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 +28 -22
- package/browser/dist/Anchors.js +12 -10
- package/browser/dist/Document.js +167 -75
- 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 +1 -4
- 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 +37 -7
- 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 +86 -45
- 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 +1 -4
- package/dist/cst/parse.js +1 -4
- package/dist/deprecation.js +34 -0
- package/dist/errors.js +29 -35
- package/dist/index.js +18 -5
- 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
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
`yaml` is a JavaScript parser and stringifier for [YAML](http://yaml.org/), a human friendly data serialization standard. It supports both parsing and stringifying data using all versions of YAML, along with all common data schemas. As a particularly distinguishing feature, `yaml` fully supports reading and writing comments and blank lines in YAML documents.
|
|
4
4
|
|
|
5
|
-
The library is released under the ISC open source license, and the code is [available on GitHub](https://github.com/eemeli/yaml/). It runs on Node.js 6 and later with no external dependencies, and in browsers from IE 11 upwards
|
|
5
|
+
The library is released under the ISC open source license, and the code is [available on GitHub](https://github.com/eemeli/yaml/). It runs on Node.js 6 and later with no external dependencies, and in browsers from IE 11 upwards (Note: `@babel/runtime` is used only by the `"browser"` entry point).
|
|
6
6
|
|
|
7
7
|
For more information, see the project's documentation site: [**eemeli.org/yaml**](https://eemeli.org/yaml/)
|
|
8
8
|
|
|
@@ -26,33 +26,31 @@ import YAML from 'yaml'
|
|
|
26
26
|
const YAML = require('yaml')
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
###
|
|
29
|
+
### Parse & Stringify
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
- [`YAML.parse(str, options): value`](https://eemeli.org/yaml/#yaml-parse)
|
|
32
|
+
- [`YAML.stringify(value, options): string`](https://eemeli.org/yaml/#yaml-stringify)
|
|
33
33
|
|
|
34
34
|
### YAML Documents
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
36
|
+
- [`YAML.createNode(value, wrapScalars, tag): Node`](https://eemeli.org/yaml/#creating-nodes)
|
|
37
|
+
- [`YAML.defaultOptions`](https://eemeli.org/yaml/#options)
|
|
38
|
+
- [`YAML.Document`](https://eemeli.org/yaml/#yaml-documents)
|
|
39
|
+
- [`constructor(options)`](https://eemeli.org/yaml/#creating-documents)
|
|
40
|
+
- [`defaults`](https://eemeli.org/yaml/#options)
|
|
41
|
+
- [`#anchors`](https://eemeli.org/yaml/#working-with-anchors)
|
|
42
|
+
- [`#contents`](https://eemeli.org/yaml/#content-nodes)
|
|
43
|
+
- [`#errors`](https://eemeli.org/yaml/#errors)
|
|
44
|
+
- [`YAML.parseAllDocuments(str, options): YAML.Document[]`](https://eemeli.org/yaml/#parsing-documents)
|
|
45
|
+
- [`YAML.parseDocument(str, options): YAML.Document`](https://eemeli.org/yaml/#parsing-documents)
|
|
46
46
|
|
|
47
47
|
```js
|
|
48
|
-
import
|
|
49
|
-
import Pair from 'yaml/pair'
|
|
50
|
-
import Seq from 'yaml/seq'
|
|
48
|
+
import { Pair, YAMLMap, YAMLSeq } from 'yaml/types'
|
|
51
49
|
```
|
|
52
50
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
- [`new Pair(key, value)`](https://eemeli.org/yaml/#creating-nodes)
|
|
52
|
+
- [`new YAMLMap()`](https://eemeli.org/yaml/#creating-nodes)
|
|
53
|
+
- [`new YAMLSeq()`](https://eemeli.org/yaml/#creating-nodes)
|
|
56
54
|
|
|
57
55
|
### CST Parser
|
|
58
56
|
|
|
@@ -60,8 +58,8 @@ import Seq from 'yaml/seq'
|
|
|
60
58
|
import parseCST from 'yaml/parse-cst'
|
|
61
59
|
```
|
|
62
60
|
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
- [`parseCST(str): CSTDocument[]`](https://eemeli.org/yaml/#parsecst)
|
|
62
|
+
- [`YAML.parseCST(str): CSTDocument[]`](https://eemeli.org/yaml/#parsecst)
|
|
65
63
|
|
|
66
64
|
## YAML.parse
|
|
67
65
|
|
|
@@ -119,3 +117,11 @@ YAML.stringify({ number: 3, plain: 'string', block: 'two\nlines\n' })
|
|
|
119
117
|
// lines
|
|
120
118
|
// `
|
|
121
119
|
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
Browser testing provided by:
|
|
124
|
+
|
|
125
|
+
<a href="https://www.browserstack.com/open-source">
|
|
126
|
+
<img width=200 src="https://eemeli.org/yaml/images/browserstack.svg" />
|
|
127
|
+
</a>
|
package/browser/dist/Anchors.js
CHANGED
|
@@ -26,9 +26,17 @@ var _Seq = _interopRequireDefault(require("./schema/Seq"));
|
|
|
26
26
|
var Anchors =
|
|
27
27
|
/*#__PURE__*/
|
|
28
28
|
function () {
|
|
29
|
-
|
|
29
|
+
(0, _createClass2.default)(Anchors, null, [{
|
|
30
|
+
key: "validAnchorNode",
|
|
31
|
+
value: function validAnchorNode(node) {
|
|
32
|
+
return node instanceof _Scalar.default || node instanceof _Seq.default || node instanceof _Map.default;
|
|
33
|
+
}
|
|
34
|
+
}]);
|
|
35
|
+
|
|
36
|
+
function Anchors(prefix) {
|
|
30
37
|
(0, _classCallCheck2.default)(this, Anchors);
|
|
31
38
|
(0, _defineProperty2.default)(this, "map", {});
|
|
39
|
+
this.prefix = prefix;
|
|
32
40
|
}
|
|
33
41
|
|
|
34
42
|
(0, _createClass2.default)(Anchors, [{
|
|
@@ -75,6 +83,7 @@ function () {
|
|
|
75
83
|
}, {
|
|
76
84
|
key: "newName",
|
|
77
85
|
value: function newName(prefix) {
|
|
86
|
+
if (!prefix) prefix = this.prefix;
|
|
78
87
|
var names = Object.keys(this.map);
|
|
79
88
|
|
|
80
89
|
for (var i = 1; true; ++i) {
|
|
@@ -124,7 +133,7 @@ function () {
|
|
|
124
133
|
} else {
|
|
125
134
|
if (!name) {
|
|
126
135
|
if (!node) return null;
|
|
127
|
-
name = this.newName(
|
|
136
|
+
name = this.newName();
|
|
128
137
|
}
|
|
129
138
|
|
|
130
139
|
map[name] = node;
|
|
@@ -132,15 +141,8 @@ function () {
|
|
|
132
141
|
|
|
133
142
|
return name;
|
|
134
143
|
}
|
|
135
|
-
}], [{
|
|
136
|
-
key: "validAnchorNode",
|
|
137
|
-
value: function validAnchorNode(node) {
|
|
138
|
-
return node instanceof _Scalar.default || node instanceof _Seq.default || node instanceof _Map.default;
|
|
139
|
-
}
|
|
140
144
|
}]);
|
|
141
145
|
return Anchors;
|
|
142
146
|
}();
|
|
143
147
|
|
|
144
|
-
exports.default = Anchors;
|
|
145
|
-
module.exports = exports.default;
|
|
146
|
-
module.exports.default = exports.default;
|
|
148
|
+
exports.default = Anchors;
|
package/browser/dist/Document.js
CHANGED
|
@@ -21,7 +21,7 @@ var _addComment = _interopRequireDefault(require("./addComment"));
|
|
|
21
21
|
|
|
22
22
|
var _Anchors = _interopRequireDefault(require("./Anchors"));
|
|
23
23
|
|
|
24
|
-
var
|
|
24
|
+
var _constants = require("./constants");
|
|
25
25
|
|
|
26
26
|
var _errors = require("./errors");
|
|
27
27
|
|
|
@@ -33,12 +33,14 @@ var _Alias = _interopRequireDefault(require("./schema/Alias"));
|
|
|
33
33
|
|
|
34
34
|
var _Collection = _interopRequireWildcard(require("./schema/Collection"));
|
|
35
35
|
|
|
36
|
-
var
|
|
36
|
+
var _Node = _interopRequireDefault(require("./schema/Node"));
|
|
37
37
|
|
|
38
38
|
var _Scalar = _interopRequireDefault(require("./schema/Scalar"));
|
|
39
39
|
|
|
40
|
+
var _toJSON2 = _interopRequireDefault(require("./toJSON"));
|
|
41
|
+
|
|
40
42
|
var isCollectionItem = function isCollectionItem(node) {
|
|
41
|
-
return node && [
|
|
43
|
+
return node && [_constants.Type.MAP_KEY, _constants.Type.MAP_VALUE, _constants.Type.SEQ_ITEM].includes(node.type);
|
|
42
44
|
};
|
|
43
45
|
|
|
44
46
|
var Document =
|
|
@@ -46,7 +48,7 @@ var Document =
|
|
|
46
48
|
function () {
|
|
47
49
|
function Document(options) {
|
|
48
50
|
(0, _classCallCheck2.default)(this, Document);
|
|
49
|
-
this.anchors = new _Anchors.default();
|
|
51
|
+
this.anchors = new _Anchors.default(options.anchorPrefix);
|
|
50
52
|
this.commentBefore = null;
|
|
51
53
|
this.comment = null;
|
|
52
54
|
this.contents = null;
|
|
@@ -142,9 +144,7 @@ function () {
|
|
|
142
144
|
}
|
|
143
145
|
}, {
|
|
144
146
|
key: "parse",
|
|
145
|
-
value: function parse(node) {
|
|
146
|
-
var _this = this;
|
|
147
|
-
|
|
147
|
+
value: function parse(node, prevDoc) {
|
|
148
148
|
if (this.options.keepCstNodes) this.cstNode = node;
|
|
149
149
|
if (this.options.keepNodeTypes) this.type = 'DOCUMENT';
|
|
150
150
|
var _node$directives = node.directives,
|
|
@@ -159,7 +159,72 @@ function () {
|
|
|
159
159
|
this.errors.push(error);
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
+
this.parseDirectives(directives, prevDoc);
|
|
163
|
+
this.range = valueRange ? [valueRange.start, valueRange.end] : null;
|
|
164
|
+
this.setSchema();
|
|
165
|
+
this.anchors._cstAliases = [];
|
|
166
|
+
this.parseContents(contents);
|
|
167
|
+
this.anchors.resolveNodes();
|
|
168
|
+
|
|
169
|
+
if (this.options.prettyErrors) {
|
|
170
|
+
var _iteratorNormalCompletion = true;
|
|
171
|
+
var _didIteratorError = false;
|
|
172
|
+
var _iteratorError = undefined;
|
|
173
|
+
|
|
174
|
+
try {
|
|
175
|
+
for (var _iterator = this.errors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
176
|
+
var _error = _step.value;
|
|
177
|
+
if (_error instanceof _errors.YAMLError) _error.makePretty();
|
|
178
|
+
}
|
|
179
|
+
} catch (err) {
|
|
180
|
+
_didIteratorError = true;
|
|
181
|
+
_iteratorError = err;
|
|
182
|
+
} finally {
|
|
183
|
+
try {
|
|
184
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
185
|
+
_iterator.return();
|
|
186
|
+
}
|
|
187
|
+
} finally {
|
|
188
|
+
if (_didIteratorError) {
|
|
189
|
+
throw _iteratorError;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
var _iteratorNormalCompletion2 = true;
|
|
195
|
+
var _didIteratorError2 = false;
|
|
196
|
+
var _iteratorError2 = undefined;
|
|
197
|
+
|
|
198
|
+
try {
|
|
199
|
+
for (var _iterator2 = this.warnings[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
200
|
+
var warn = _step2.value;
|
|
201
|
+
if (warn instanceof _errors.YAMLError) warn.makePretty();
|
|
202
|
+
}
|
|
203
|
+
} catch (err) {
|
|
204
|
+
_didIteratorError2 = true;
|
|
205
|
+
_iteratorError2 = err;
|
|
206
|
+
} finally {
|
|
207
|
+
try {
|
|
208
|
+
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
|
|
209
|
+
_iterator2.return();
|
|
210
|
+
}
|
|
211
|
+
} finally {
|
|
212
|
+
if (_didIteratorError2) {
|
|
213
|
+
throw _iteratorError2;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return this;
|
|
220
|
+
}
|
|
221
|
+
}, {
|
|
222
|
+
key: "parseDirectives",
|
|
223
|
+
value: function parseDirectives(directives, prevDoc) {
|
|
224
|
+
var _this = this;
|
|
225
|
+
|
|
162
226
|
var directiveComments = [];
|
|
227
|
+
var hasDirectives = false;
|
|
163
228
|
directives.forEach(function (directive) {
|
|
164
229
|
var comment = directive.comment,
|
|
165
230
|
name = directive.name;
|
|
@@ -168,12 +233,14 @@ function () {
|
|
|
168
233
|
case 'TAG':
|
|
169
234
|
_this.resolveTagDirective(directive);
|
|
170
235
|
|
|
236
|
+
hasDirectives = true;
|
|
171
237
|
break;
|
|
172
238
|
|
|
173
239
|
case 'YAML':
|
|
174
240
|
case 'YAML:1.0':
|
|
175
241
|
_this.resolveYamlDirective(directive);
|
|
176
242
|
|
|
243
|
+
hasDirectives = true;
|
|
177
244
|
break;
|
|
178
245
|
|
|
179
246
|
default:
|
|
@@ -187,10 +254,28 @@ function () {
|
|
|
187
254
|
|
|
188
255
|
if (comment) directiveComments.push(comment);
|
|
189
256
|
});
|
|
190
|
-
|
|
191
|
-
this.
|
|
192
|
-
|
|
257
|
+
|
|
258
|
+
if (prevDoc && !hasDirectives && '1.1' === (this.version || prevDoc.version || this.options.version)) {
|
|
259
|
+
var copyTagPrefix = function copyTagPrefix(_ref) {
|
|
260
|
+
var handle = _ref.handle,
|
|
261
|
+
prefix = _ref.prefix;
|
|
262
|
+
return {
|
|
263
|
+
handle: handle,
|
|
264
|
+
prefix: prefix
|
|
265
|
+
};
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
this.tagPrefixes = prevDoc.tagPrefixes.map(copyTagPrefix);
|
|
269
|
+
this.version = prevDoc.version;
|
|
270
|
+
}
|
|
271
|
+
|
|
193
272
|
this.commentBefore = directiveComments.join('\n') || null;
|
|
273
|
+
}
|
|
274
|
+
}, {
|
|
275
|
+
key: "parseContents",
|
|
276
|
+
value: function parseContents(contents) {
|
|
277
|
+
var _this2 = this;
|
|
278
|
+
|
|
194
279
|
var comments = {
|
|
195
280
|
before: [],
|
|
196
281
|
after: []
|
|
@@ -202,10 +287,10 @@ function () {
|
|
|
202
287
|
if (contentNodes.length === 1) {
|
|
203
288
|
var msg = 'Document is not valid YAML (bad indentation?)';
|
|
204
289
|
|
|
205
|
-
|
|
290
|
+
_this2.errors.push(new _errors.YAMLSyntaxError(node, msg));
|
|
206
291
|
}
|
|
207
292
|
|
|
208
|
-
var res =
|
|
293
|
+
var res = _this2.resolveNode(node);
|
|
209
294
|
|
|
210
295
|
if (spaceBefore) {
|
|
211
296
|
res.spaceBefore = true;
|
|
@@ -216,12 +301,12 @@ function () {
|
|
|
216
301
|
} else if (node.comment !== null) {
|
|
217
302
|
var cc = contentNodes.length === 0 ? comments.before : comments.after;
|
|
218
303
|
cc.push(node.comment);
|
|
219
|
-
} else if (node.type ===
|
|
304
|
+
} else if (node.type === _constants.Type.BLANK_LINE) {
|
|
220
305
|
spaceBefore = true;
|
|
221
306
|
|
|
222
|
-
if (contentNodes.length === 0 && comments.before.length > 0 && !
|
|
307
|
+
if (contentNodes.length === 0 && comments.before.length > 0 && !_this2.commentBefore) {
|
|
223
308
|
// space-separated comments at start are parsed as document comments
|
|
224
|
-
|
|
309
|
+
_this2.commentBefore = comments.before.join('\n');
|
|
225
310
|
comments.before = [];
|
|
226
311
|
}
|
|
227
312
|
}
|
|
@@ -261,8 +346,6 @@ function () {
|
|
|
261
346
|
}
|
|
262
347
|
|
|
263
348
|
this.comment = comments.after.join('\n') || null;
|
|
264
|
-
this.anchors.resolveNodes();
|
|
265
|
-
return this;
|
|
266
349
|
}
|
|
267
350
|
}, {
|
|
268
351
|
key: "resolveTagDirective",
|
|
@@ -371,21 +454,21 @@ function () {
|
|
|
371
454
|
}
|
|
372
455
|
|
|
373
456
|
switch (type) {
|
|
374
|
-
case
|
|
375
|
-
case
|
|
376
|
-
case
|
|
377
|
-
case
|
|
457
|
+
case _constants.Type.BLOCK_FOLDED:
|
|
458
|
+
case _constants.Type.BLOCK_LITERAL:
|
|
459
|
+
case _constants.Type.QUOTE_DOUBLE:
|
|
460
|
+
case _constants.Type.QUOTE_SINGLE:
|
|
378
461
|
return _schema.default.defaultTags.STR;
|
|
379
462
|
|
|
380
|
-
case
|
|
381
|
-
case
|
|
463
|
+
case _constants.Type.FLOW_MAP:
|
|
464
|
+
case _constants.Type.MAP:
|
|
382
465
|
return _schema.default.defaultTags.MAP;
|
|
383
466
|
|
|
384
|
-
case
|
|
385
|
-
case
|
|
467
|
+
case _constants.Type.FLOW_SEQ:
|
|
468
|
+
case _constants.Type.SEQ:
|
|
386
469
|
return _schema.default.defaultTags.SEQ;
|
|
387
470
|
|
|
388
|
-
case
|
|
471
|
+
case _constants.Type.PLAIN:
|
|
389
472
|
return nonSpecific ? _schema.default.defaultTags.STR : null;
|
|
390
473
|
|
|
391
474
|
default:
|
|
@@ -406,22 +489,22 @@ function () {
|
|
|
406
489
|
after: []
|
|
407
490
|
};
|
|
408
491
|
var props = isCollectionItem(node.context.parent) ? node.context.parent.props.concat(node.props) : node.props;
|
|
409
|
-
var
|
|
410
|
-
var
|
|
411
|
-
var
|
|
492
|
+
var _iteratorNormalCompletion3 = true;
|
|
493
|
+
var _didIteratorError3 = false;
|
|
494
|
+
var _iteratorError3 = undefined;
|
|
412
495
|
|
|
413
496
|
try {
|
|
414
|
-
for (var
|
|
415
|
-
var
|
|
416
|
-
start =
|
|
417
|
-
end =
|
|
497
|
+
for (var _iterator3 = props[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
|
498
|
+
var _step3$value = _step3.value,
|
|
499
|
+
start = _step3$value.start,
|
|
500
|
+
end = _step3$value.end;
|
|
418
501
|
|
|
419
502
|
switch (node.context.src[start]) {
|
|
420
|
-
case
|
|
503
|
+
case _constants.Char.COMMENT:
|
|
421
504
|
{
|
|
422
505
|
if (!node.commentHasRequiredWhitespace(start)) {
|
|
423
|
-
var
|
|
424
|
-
errors.push(new _errors.YAMLSemanticError(node,
|
|
506
|
+
var _msg7 = 'Comments must be separated from other tokens by white space characters';
|
|
507
|
+
errors.push(new _errors.YAMLSemanticError(node, _msg7));
|
|
425
508
|
}
|
|
426
509
|
|
|
427
510
|
var c = node.context.src.slice(start + 1, end);
|
|
@@ -436,19 +519,19 @@ function () {
|
|
|
436
519
|
}
|
|
437
520
|
break;
|
|
438
521
|
|
|
439
|
-
case
|
|
522
|
+
case _constants.Char.ANCHOR:
|
|
440
523
|
if (hasAnchor) {
|
|
441
|
-
var
|
|
442
|
-
errors.push(new _errors.YAMLSemanticError(node,
|
|
524
|
+
var _msg8 = 'A node can have at most one anchor';
|
|
525
|
+
errors.push(new _errors.YAMLSemanticError(node, _msg8));
|
|
443
526
|
}
|
|
444
527
|
|
|
445
528
|
hasAnchor = true;
|
|
446
529
|
break;
|
|
447
530
|
|
|
448
|
-
case
|
|
531
|
+
case _constants.Char.TAG:
|
|
449
532
|
if (hasTag) {
|
|
450
|
-
var
|
|
451
|
-
errors.push(new _errors.YAMLSemanticError(node,
|
|
533
|
+
var _msg9 = 'A node can have at most one tag';
|
|
534
|
+
errors.push(new _errors.YAMLSemanticError(node, _msg9));
|
|
452
535
|
}
|
|
453
536
|
|
|
454
537
|
hasTag = true;
|
|
@@ -456,16 +539,16 @@ function () {
|
|
|
456
539
|
}
|
|
457
540
|
}
|
|
458
541
|
} catch (err) {
|
|
459
|
-
|
|
460
|
-
|
|
542
|
+
_didIteratorError3 = true;
|
|
543
|
+
_iteratorError3 = err;
|
|
461
544
|
} finally {
|
|
462
545
|
try {
|
|
463
|
-
if (!
|
|
464
|
-
|
|
546
|
+
if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
|
|
547
|
+
_iterator3.return();
|
|
465
548
|
}
|
|
466
549
|
} finally {
|
|
467
|
-
if (
|
|
468
|
-
throw
|
|
550
|
+
if (_didIteratorError3) {
|
|
551
|
+
throw _iteratorError3;
|
|
469
552
|
}
|
|
470
553
|
}
|
|
471
554
|
}
|
|
@@ -484,7 +567,7 @@ function () {
|
|
|
484
567
|
|
|
485
568
|
var res;
|
|
486
569
|
|
|
487
|
-
if (node.type ===
|
|
570
|
+
if (node.type === _constants.Type.ALIAS) {
|
|
488
571
|
if (hasAnchor || hasTag) {
|
|
489
572
|
var msg = 'An alias node must not specify any properties';
|
|
490
573
|
errors.push(new _errors.YAMLSemanticError(node, msg));
|
|
@@ -504,21 +587,16 @@ function () {
|
|
|
504
587
|
res = new _Alias.default(src);
|
|
505
588
|
|
|
506
589
|
anchors._cstAliases.push(res);
|
|
507
|
-
|
|
508
|
-
if (!src.resolved) {
|
|
509
|
-
var _msg6 = 'Alias node contains a circular reference, which cannot be resolved as JSON';
|
|
510
|
-
this.warnings.push(new _errors.YAMLWarning(node, _msg6));
|
|
511
|
-
}
|
|
512
590
|
} else {
|
|
513
591
|
var tagName = this.resolveTagName(node);
|
|
514
592
|
|
|
515
593
|
if (tagName) {
|
|
516
594
|
res = schema.resolveNodeWithFallback(this, node, tagName);
|
|
517
595
|
} else {
|
|
518
|
-
if (node.type !==
|
|
519
|
-
var
|
|
596
|
+
if (node.type !== _constants.Type.PLAIN) {
|
|
597
|
+
var _msg6 = "Failed to resolve ".concat(node.type, " node here");
|
|
520
598
|
|
|
521
|
-
errors.push(new _errors.YAMLSyntaxError(node,
|
|
599
|
+
errors.push(new _errors.YAMLSyntaxError(node, _msg6));
|
|
522
600
|
return null;
|
|
523
601
|
}
|
|
524
602
|
|
|
@@ -611,16 +689,29 @@ function () {
|
|
|
611
689
|
}, {
|
|
612
690
|
key: "toJSON",
|
|
613
691
|
value: function toJSON(arg) {
|
|
614
|
-
var
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
692
|
+
var _this3 = this;
|
|
693
|
+
|
|
694
|
+
var _this$options = this.options,
|
|
695
|
+
keepBlobsInJSON = _this$options.keepBlobsInJSON,
|
|
696
|
+
mapAsMap = _this$options.mapAsMap,
|
|
697
|
+
maxAliasCount = _this$options.maxAliasCount;
|
|
698
|
+
var keep = keepBlobsInJSON && (typeof arg !== 'string' || !(this.contents instanceof _Scalar.default));
|
|
699
|
+
var ctx = {
|
|
700
|
+
doc: this,
|
|
621
701
|
keep: keep,
|
|
622
|
-
mapAsMap: mapAsMap
|
|
702
|
+
mapAsMap: keep && !!mapAsMap,
|
|
703
|
+
maxAliasCount: maxAliasCount
|
|
704
|
+
};
|
|
705
|
+
var anchorNames = Object.keys(this.anchors.map);
|
|
706
|
+
if (anchorNames.length > 0) ctx.anchors = anchorNames.map(function (name) {
|
|
707
|
+
return {
|
|
708
|
+
alias: [],
|
|
709
|
+
aliasCount: 0,
|
|
710
|
+
count: 1,
|
|
711
|
+
node: _this3.anchors.map[name]
|
|
712
|
+
};
|
|
623
713
|
});
|
|
714
|
+
return (0, _toJSON2.default)(this.contents, arg, ctx);
|
|
624
715
|
}
|
|
625
716
|
}, {
|
|
626
717
|
key: "toString",
|
|
@@ -643,9 +734,9 @@ function () {
|
|
|
643
734
|
}
|
|
644
735
|
|
|
645
736
|
var tagNames = this.listNonDefaultTags();
|
|
646
|
-
this.tagPrefixes.forEach(function (
|
|
647
|
-
var handle =
|
|
648
|
-
prefix =
|
|
737
|
+
this.tagPrefixes.forEach(function (_ref2) {
|
|
738
|
+
var handle = _ref2.handle,
|
|
739
|
+
prefix = _ref2.prefix;
|
|
649
740
|
|
|
650
741
|
if (tagNames.some(function (t) {
|
|
651
742
|
return t.indexOf(prefix) === 0;
|
|
@@ -664,11 +755,14 @@ function () {
|
|
|
664
755
|
var contentComment = null;
|
|
665
756
|
|
|
666
757
|
if (this.contents) {
|
|
667
|
-
if (this.contents
|
|
668
|
-
|
|
758
|
+
if (this.contents instanceof _Node.default) {
|
|
759
|
+
if (this.contents.spaceBefore && hasDirectives) lines.push('');
|
|
760
|
+
if (this.contents.commentBefore) lines.push(this.contents.commentBefore.replace(/^/gm, '#')); // top-level block scalars need to be indented if followed by a comment
|
|
761
|
+
|
|
762
|
+
ctx.forceBlockIndent = !!this.comment;
|
|
763
|
+
contentComment = this.contents.comment;
|
|
764
|
+
}
|
|
669
765
|
|
|
670
|
-
ctx.forceBlockIndent = !!this.comment;
|
|
671
|
-
contentComment = this.contents.comment;
|
|
672
766
|
var onChompKeep = contentComment ? null : function () {
|
|
673
767
|
return chompKeep = true;
|
|
674
768
|
};
|
|
@@ -726,6 +820,4 @@ exports.default = Document;
|
|
|
726
820
|
prefix: _schema.default.defaultPrefix
|
|
727
821
|
}]
|
|
728
822
|
}
|
|
729
|
-
});
|
|
730
|
-
module.exports = exports.default;
|
|
731
|
-
module.exports.default = exports.default;
|
|
823
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Type = exports.Char = void 0;
|
|
7
|
+
var Char = {
|
|
8
|
+
ANCHOR: '&',
|
|
9
|
+
COMMENT: '#',
|
|
10
|
+
TAG: '!',
|
|
11
|
+
DIRECTIVES_END: '-',
|
|
12
|
+
DOCUMENT_END: '.'
|
|
13
|
+
};
|
|
14
|
+
exports.Char = Char;
|
|
15
|
+
var Type = {
|
|
16
|
+
ALIAS: 'ALIAS',
|
|
17
|
+
BLANK_LINE: 'BLANK_LINE',
|
|
18
|
+
BLOCK_FOLDED: 'BLOCK_FOLDED',
|
|
19
|
+
BLOCK_LITERAL: 'BLOCK_LITERAL',
|
|
20
|
+
COMMENT: 'COMMENT',
|
|
21
|
+
DIRECTIVE: 'DIRECTIVE',
|
|
22
|
+
DOCUMENT: 'DOCUMENT',
|
|
23
|
+
FLOW_MAP: 'FLOW_MAP',
|
|
24
|
+
FLOW_SEQ: 'FLOW_SEQ',
|
|
25
|
+
MAP: 'MAP',
|
|
26
|
+
MAP_KEY: 'MAP_KEY',
|
|
27
|
+
MAP_VALUE: 'MAP_VALUE',
|
|
28
|
+
PLAIN: 'PLAIN',
|
|
29
|
+
QUOTE_DOUBLE: 'QUOTE_DOUBLE',
|
|
30
|
+
QUOTE_SINGLE: 'QUOTE_SINGLE',
|
|
31
|
+
SEQ: 'SEQ',
|
|
32
|
+
SEQ_ITEM: 'SEQ_ITEM'
|
|
33
|
+
};
|
|
34
|
+
exports.Type = Type;
|
|
@@ -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", {
|
|
@@ -19,7 +17,9 @@ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/ge
|
|
|
19
17
|
|
|
20
18
|
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
21
19
|
|
|
22
|
-
var
|
|
20
|
+
var _constants = require("../constants");
|
|
21
|
+
|
|
22
|
+
var _Node2 = _interopRequireDefault(require("./Node"));
|
|
23
23
|
|
|
24
24
|
var _Range = _interopRequireDefault(require("./Range"));
|
|
25
25
|
|
|
@@ -30,7 +30,7 @@ function (_Node) {
|
|
|
30
30
|
|
|
31
31
|
function BlankLine() {
|
|
32
32
|
(0, _classCallCheck2.default)(this, BlankLine);
|
|
33
|
-
return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(BlankLine).call(this,
|
|
33
|
+
return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(BlankLine).call(this, _constants.Type.BLANK_LINE));
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
(0, _createClass2.default)(BlankLine, [{
|
|
@@ -66,6 +66,4 @@ function (_Node) {
|
|
|
66
66
|
return BlankLine;
|
|
67
67
|
}(_Node2.default);
|
|
68
68
|
|
|
69
|
-
exports.default = BlankLine;
|
|
70
|
-
module.exports = exports.default;
|
|
71
|
-
module.exports.default = exports.default;
|
|
69
|
+
exports.default = BlankLine;
|
|
@@ -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", {
|
|
@@ -21,7 +19,9 @@ var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
|
|
|
21
19
|
|
|
22
20
|
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
23
21
|
|
|
24
|
-
var
|
|
22
|
+
var _constants = require("../constants");
|
|
23
|
+
|
|
24
|
+
var _Node2 = _interopRequireDefault(require("./Node"));
|
|
25
25
|
|
|
26
26
|
var _Range = _interopRequireDefault(require("./Range"));
|
|
27
27
|
|
|
@@ -222,7 +222,7 @@ function (_Node) {
|
|
|
222
222
|
}
|
|
223
223
|
|
|
224
224
|
var bi = indent + this.blockIndent;
|
|
225
|
-
var folded = this.type ===
|
|
225
|
+
var folded = this.type === _constants.Type.BLOCK_FOLDED;
|
|
226
226
|
var atStart = true;
|
|
227
227
|
var str = '';
|
|
228
228
|
var sep = '';
|