yaml 1.6.0 → 1.8.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/browser/dist/Anchors.js +24 -39
- package/browser/dist/Document.js +99 -111
- package/browser/dist/addComment.js +2 -11
- package/browser/dist/constants.js +3 -11
- package/browser/dist/cst/Alias.js +19 -36
- package/browser/dist/cst/BlankLine.js +25 -38
- package/browser/dist/cst/BlockValue.js +29 -51
- package/browser/dist/cst/Collection.js +42 -65
- package/browser/dist/cst/CollectionItem.js +57 -58
- package/browser/dist/cst/Comment.js +19 -35
- package/browser/dist/cst/Directive.js +20 -56
- package/browser/dist/cst/Document.js +47 -71
- package/browser/dist/cst/FlowCollection.js +38 -61
- package/browser/dist/cst/Node.js +30 -47
- package/browser/dist/cst/ParseContext.js +100 -140
- package/browser/dist/cst/PlainValue.js +22 -39
- package/browser/dist/cst/QuoteDouble.js +26 -42
- package/browser/dist/cst/QuoteSingle.js +25 -41
- package/browser/dist/cst/Range.js +9 -19
- package/browser/dist/cst/parse.js +5 -16
- package/browser/dist/cst/source-utils.js +168 -0
- package/browser/dist/errors.js +71 -74
- package/browser/dist/foldFlowLines.js +4 -15
- package/browser/dist/index.js +26 -45
- package/browser/dist/listTagNames.js +10 -24
- package/browser/dist/schema/Alias.js +33 -50
- package/browser/dist/schema/Collection.js +54 -65
- package/browser/dist/schema/Map.js +39 -49
- package/browser/dist/schema/Merge.js +33 -53
- package/browser/dist/schema/Node.js +3 -12
- package/browser/dist/schema/Pair.js +53 -56
- package/browser/dist/schema/Scalar.js +18 -33
- package/browser/dist/schema/Seq.js +23 -40
- package/browser/dist/schema/index.js +67 -81
- package/browser/dist/schema/parseMap.js +63 -70
- package/browser/dist/schema/parseSeq.js +45 -44
- package/browser/dist/schema/parseUtils.js +47 -11
- package/browser/dist/stringify.js +43 -48
- package/browser/dist/tags/core.js +30 -37
- package/browser/dist/tags/failsafe/index.js +4 -17
- package/browser/dist/tags/failsafe/map.js +17 -26
- package/browser/dist/tags/failsafe/seq.js +7 -18
- package/browser/dist/tags/failsafe/string.js +7 -19
- package/browser/dist/tags/index.js +35 -49
- package/browser/dist/tags/json.js +11 -38
- package/browser/dist/tags/options.js +8 -20
- package/browser/dist/tags/yaml-1.1/binary.js +16 -29
- package/browser/dist/tags/yaml-1.1/index.js +34 -54
- package/browser/dist/tags/yaml-1.1/omap.js +39 -58
- package/browser/dist/tags/yaml-1.1/pairs.js +15 -34
- package/browser/dist/tags/yaml-1.1/set.js +35 -61
- package/browser/dist/tags/yaml-1.1/timestamp.js +6 -16
- package/browser/dist/test-events.js +7 -19
- package/browser/dist/toJSON.js +1 -8
- package/browser/dist/warnings.js +28 -0
- package/browser/map.js +1 -1
- package/browser/pair.js +1 -1
- package/browser/scalar.js +1 -1
- package/browser/schema.js +1 -1
- package/browser/seq.js +1 -1
- package/browser/types/binary.js +1 -1
- package/browser/types/omap.js +1 -1
- package/browser/types/pairs.js +1 -1
- package/browser/types/set.js +1 -1
- package/browser/types/timestamp.js +1 -1
- package/dist/Document.js +21 -9
- package/dist/cst/BlankLine.js +4 -0
- package/dist/cst/BlockValue.js +1 -1
- package/dist/cst/CollectionItem.js +27 -6
- package/dist/cst/Directive.js +0 -16
- package/dist/cst/Node.js +7 -9
- package/dist/cst/ParseContext.js +41 -55
- package/dist/cst/PlainValue.js +1 -1
- package/dist/cst/source-utils.js +178 -0
- package/dist/errors.js +37 -3
- package/dist/index.js +5 -4
- package/dist/schema/Alias.js +2 -1
- package/dist/schema/Collection.js +22 -5
- package/dist/schema/Map.js +12 -5
- package/dist/schema/Merge.js +4 -5
- package/dist/schema/Pair.js +20 -2
- package/dist/schema/index.js +14 -8
- package/dist/schema/parseMap.js +20 -5
- package/dist/schema/parseSeq.js +19 -6
- package/dist/schema/parseUtils.js +54 -6
- package/dist/stringify.js +21 -11
- package/dist/tags/core.js +27 -10
- package/dist/tags/failsafe/map.js +5 -1
- package/dist/tags/failsafe/seq.js +1 -1
- package/dist/tags/index.js +13 -1
- package/dist/tags/json.js +2 -9
- package/dist/tags/yaml-1.1/index.js +6 -6
- package/dist/tags/yaml-1.1/omap.js +3 -5
- package/dist/tags/yaml-1.1/pairs.js +1 -1
- package/dist/tags/yaml-1.1/set.js +3 -1
- package/dist/{deprecation.js → warnings.js} +12 -7
- package/map.js +1 -1
- package/package.json +35 -17
- package/pair.js +1 -1
- package/scalar.js +1 -1
- package/schema.js +1 -1
- package/seq.js +1 -1
- package/types/binary.js +1 -1
- package/types/omap.js +1 -1
- package/types/pairs.js +1 -1
- package/types/set.js +1 -1
- package/types/timestamp.js +1 -1
- package/types.mjs +20 -0
- package/util.mjs +24 -0
- package/browser/dist/cst/getLinePos.js +0 -79
- package/browser/dist/deprecation.js +0 -34
- package/dist/cst/getLinePos.js +0 -79
|
@@ -1,49 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
17
|
-
|
|
18
|
-
var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
|
|
19
|
-
|
|
20
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
21
|
-
|
|
22
|
-
var _constants = require("../constants");
|
|
23
|
-
|
|
24
|
-
var _errors = require("../errors");
|
|
25
|
-
|
|
26
|
-
var _BlankLine = _interopRequireDefault(require("./BlankLine"));
|
|
27
|
-
|
|
28
|
-
var _Node2 = _interopRequireDefault(require("./Node"));
|
|
29
|
-
|
|
30
|
-
var _Range = _interopRequireDefault(require("./Range"));
|
|
31
|
-
|
|
32
|
-
var CollectionItem =
|
|
33
|
-
/*#__PURE__*/
|
|
34
|
-
function (_Node) {
|
|
35
|
-
(0, _inherits2.default)(CollectionItem, _Node);
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
4
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
5
|
+
import _get from "@babel/runtime/helpers/get";
|
|
6
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
7
|
+
import { Type } from '../constants';
|
|
8
|
+
import { YAMLSemanticError } from '../errors';
|
|
9
|
+
import BlankLine from './BlankLine';
|
|
10
|
+
import Node from './Node';
|
|
11
|
+
import Range from './Range';
|
|
12
|
+
|
|
13
|
+
var CollectionItem = /*#__PURE__*/function (_Node) {
|
|
14
|
+
_inherits(CollectionItem, _Node);
|
|
36
15
|
|
|
37
16
|
function CollectionItem(type, props) {
|
|
38
17
|
var _this;
|
|
39
18
|
|
|
40
|
-
(
|
|
41
|
-
|
|
19
|
+
_classCallCheck(this, CollectionItem);
|
|
20
|
+
|
|
21
|
+
_this = _possibleConstructorReturn(this, _getPrototypeOf(CollectionItem).call(this, type, props));
|
|
42
22
|
_this.node = null;
|
|
43
23
|
return _this;
|
|
44
24
|
}
|
|
45
25
|
|
|
46
|
-
(
|
|
26
|
+
_createClass(CollectionItem, [{
|
|
47
27
|
key: "parse",
|
|
48
28
|
|
|
49
29
|
/**
|
|
@@ -57,41 +37,39 @@ function (_Node) {
|
|
|
57
37
|
src = context.src;
|
|
58
38
|
var atLineStart = context.atLineStart,
|
|
59
39
|
lineStart = context.lineStart;
|
|
60
|
-
if (!atLineStart && this.type ===
|
|
40
|
+
if (!atLineStart && this.type === Type.SEQ_ITEM) this.error = new YAMLSemanticError(this, 'Sequence items must not have preceding content on the same line');
|
|
61
41
|
var indent = atLineStart ? start - lineStart : context.indent;
|
|
62
|
-
|
|
63
|
-
var offset = _Node2.default.endOfWhiteSpace(src, start + 1);
|
|
64
|
-
|
|
42
|
+
var offset = Node.endOfWhiteSpace(src, start + 1);
|
|
65
43
|
var ch = src[offset];
|
|
44
|
+
var inlineComment = ch === '#';
|
|
45
|
+
var comments = [];
|
|
46
|
+
var blankLine = null;
|
|
66
47
|
|
|
67
48
|
while (ch === '\n' || ch === '#') {
|
|
68
49
|
if (ch === '#') {
|
|
69
|
-
var _end =
|
|
50
|
+
var _end = Node.endOfLine(src, offset + 1);
|
|
70
51
|
|
|
71
|
-
|
|
52
|
+
comments.push(new Range(offset, _end));
|
|
72
53
|
offset = _end;
|
|
73
54
|
} else {
|
|
74
55
|
atLineStart = true;
|
|
75
56
|
lineStart = offset + 1;
|
|
57
|
+
var wsEnd = Node.endOfWhiteSpace(src, lineStart);
|
|
76
58
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (src[wsEnd] === '\n') {
|
|
80
|
-
var blankLine = new _BlankLine.default();
|
|
59
|
+
if (src[wsEnd] === '\n' && comments.length === 0) {
|
|
60
|
+
blankLine = new BlankLine();
|
|
81
61
|
lineStart = blankLine.parse({
|
|
82
62
|
src: src
|
|
83
63
|
}, lineStart);
|
|
84
|
-
var items = context.parent.items || context.parent.contents;
|
|
85
|
-
items.push(blankLine);
|
|
86
64
|
}
|
|
87
65
|
|
|
88
|
-
offset =
|
|
66
|
+
offset = Node.endOfIndent(src, lineStart);
|
|
89
67
|
}
|
|
90
68
|
|
|
91
69
|
ch = src[offset];
|
|
92
70
|
}
|
|
93
71
|
|
|
94
|
-
if (
|
|
72
|
+
if (Node.nextNodeIsIndented(ch, offset - (lineStart + indent), this.type !== Type.SEQ_ITEM)) {
|
|
95
73
|
this.node = parseNode({
|
|
96
74
|
atLineStart: atLineStart,
|
|
97
75
|
inCollection: false,
|
|
@@ -99,19 +77,39 @@ function (_Node) {
|
|
|
99
77
|
lineStart: lineStart,
|
|
100
78
|
parent: this
|
|
101
79
|
}, offset);
|
|
102
|
-
if (this.node) offset = this.node.range.end;
|
|
103
80
|
} else if (ch && lineStart > start + 1) {
|
|
104
81
|
offset = lineStart - 1;
|
|
105
82
|
}
|
|
106
83
|
|
|
84
|
+
if (this.node) {
|
|
85
|
+
if (blankLine) {
|
|
86
|
+
// Only blank lines preceding non-empty nodes are captured. Note that
|
|
87
|
+
// this means that collection item range start indices do not always
|
|
88
|
+
// increase monotonically. -- eemeli/yaml#126
|
|
89
|
+
var items = context.parent.items || context.parent.contents;
|
|
90
|
+
if (items) items.push(blankLine);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (comments.length) Array.prototype.push.apply(this.props, comments);
|
|
94
|
+
offset = this.node.range.end;
|
|
95
|
+
} else {
|
|
96
|
+
if (inlineComment) {
|
|
97
|
+
var c = comments[0];
|
|
98
|
+
this.props.push(c);
|
|
99
|
+
offset = c.end;
|
|
100
|
+
} else {
|
|
101
|
+
offset = Node.endOfLine(src, start + 1);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
107
105
|
var end = this.node ? this.node.valueRange.end : offset;
|
|
108
|
-
this.valueRange = new
|
|
106
|
+
this.valueRange = new Range(start, end);
|
|
109
107
|
return offset;
|
|
110
108
|
}
|
|
111
109
|
}, {
|
|
112
110
|
key: "setOrigRanges",
|
|
113
111
|
value: function setOrigRanges(cr, offset) {
|
|
114
|
-
offset = (
|
|
112
|
+
offset = _get(_getPrototypeOf(CollectionItem.prototype), "setOrigRanges", this).call(this, cr, offset);
|
|
115
113
|
return this.node ? this.node.setOrigRanges(cr, offset) : offset;
|
|
116
114
|
}
|
|
117
115
|
}, {
|
|
@@ -123,7 +121,7 @@ function (_Node) {
|
|
|
123
121
|
value = this.value;
|
|
124
122
|
if (value != null) return value;
|
|
125
123
|
var str = node ? src.slice(range.start, node.range.start) + String(node) : src.slice(range.start, range.end);
|
|
126
|
-
return
|
|
124
|
+
return Node.addStringTerminator(src, range.end, str);
|
|
127
125
|
}
|
|
128
126
|
}, {
|
|
129
127
|
key: "includesTrailingLines",
|
|
@@ -131,7 +129,8 @@ function (_Node) {
|
|
|
131
129
|
return !!this.node && this.node.includesTrailingLines;
|
|
132
130
|
}
|
|
133
131
|
}]);
|
|
132
|
+
|
|
134
133
|
return CollectionItem;
|
|
135
|
-
}(
|
|
134
|
+
}(Node);
|
|
136
135
|
|
|
137
|
-
|
|
136
|
+
export { CollectionItem as default };
|
|
@@ -1,36 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
-
|
|
14
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
15
|
-
|
|
16
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
17
|
-
|
|
18
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
19
|
-
|
|
20
|
-
var _constants = require("../constants");
|
|
21
|
-
|
|
22
|
-
var _Node2 = _interopRequireDefault(require("./Node"));
|
|
23
|
-
|
|
24
|
-
var _Range = _interopRequireDefault(require("./Range"));
|
|
25
|
-
|
|
26
|
-
var Comment =
|
|
27
|
-
/*#__PURE__*/
|
|
28
|
-
function (_Node) {
|
|
29
|
-
(0, _inherits2.default)(Comment, _Node);
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
4
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
5
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
6
|
+
import { Type } from '../constants';
|
|
7
|
+
import Node from './Node';
|
|
8
|
+
import Range from './Range';
|
|
9
|
+
|
|
10
|
+
var Comment = /*#__PURE__*/function (_Node) {
|
|
11
|
+
_inherits(Comment, _Node);
|
|
30
12
|
|
|
31
13
|
function Comment() {
|
|
32
|
-
(
|
|
33
|
-
|
|
14
|
+
_classCallCheck(this, Comment);
|
|
15
|
+
|
|
16
|
+
return _possibleConstructorReturn(this, _getPrototypeOf(Comment).call(this, Type.COMMENT));
|
|
34
17
|
}
|
|
35
18
|
/**
|
|
36
19
|
* Parses a comment line from the source
|
|
@@ -41,16 +24,17 @@ function (_Node) {
|
|
|
41
24
|
*/
|
|
42
25
|
|
|
43
26
|
|
|
44
|
-
(
|
|
27
|
+
_createClass(Comment, [{
|
|
45
28
|
key: "parse",
|
|
46
29
|
value: function parse(context, start) {
|
|
47
30
|
this.context = context;
|
|
48
31
|
var offset = this.parseComment(start);
|
|
49
|
-
this.range = new
|
|
32
|
+
this.range = new Range(start, offset);
|
|
50
33
|
return offset;
|
|
51
34
|
}
|
|
52
35
|
}]);
|
|
36
|
+
|
|
53
37
|
return Comment;
|
|
54
|
-
}(
|
|
38
|
+
}(Node);
|
|
55
39
|
|
|
56
|
-
|
|
40
|
+
export { Comment as default };
|
|
@@ -1,63 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
13
|
-
|
|
14
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
15
|
-
|
|
16
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
17
|
-
|
|
18
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
19
|
-
|
|
20
|
-
var _constants = require("../constants");
|
|
21
|
-
|
|
22
|
-
var _Node2 = _interopRequireDefault(require("./Node"));
|
|
23
|
-
|
|
24
|
-
var _Range = _interopRequireDefault(require("./Range"));
|
|
25
|
-
|
|
26
|
-
var Directive =
|
|
27
|
-
/*#__PURE__*/
|
|
28
|
-
function (_Node) {
|
|
29
|
-
(0, _inherits2.default)(Directive, _Node);
|
|
30
|
-
(0, _createClass2.default)(Directive, null, [{
|
|
31
|
-
key: "endOfDirective",
|
|
32
|
-
value: function endOfDirective(src, offset) {
|
|
33
|
-
var ch = src[offset];
|
|
34
|
-
|
|
35
|
-
while (ch && ch !== '\n' && ch !== '#') {
|
|
36
|
-
ch = src[offset += 1];
|
|
37
|
-
} // last char can't be whitespace
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
ch = src[offset - 1];
|
|
41
|
-
|
|
42
|
-
while (ch === ' ' || ch === '\t') {
|
|
43
|
-
offset -= 1;
|
|
44
|
-
ch = src[offset - 1];
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return offset;
|
|
48
|
-
}
|
|
49
|
-
}]);
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
4
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
5
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
6
|
+
import { Type } from '../constants';
|
|
7
|
+
import Node from './Node';
|
|
8
|
+
import Range from './Range';
|
|
9
|
+
|
|
10
|
+
var Directive = /*#__PURE__*/function (_Node) {
|
|
11
|
+
_inherits(Directive, _Node);
|
|
50
12
|
|
|
51
13
|
function Directive() {
|
|
52
14
|
var _this;
|
|
53
15
|
|
|
54
|
-
(
|
|
55
|
-
|
|
16
|
+
_classCallCheck(this, Directive);
|
|
17
|
+
|
|
18
|
+
_this = _possibleConstructorReturn(this, _getPrototypeOf(Directive).call(this, Type.DIRECTIVE));
|
|
56
19
|
_this.name = null;
|
|
57
20
|
return _this;
|
|
58
21
|
}
|
|
59
22
|
|
|
60
|
-
(
|
|
23
|
+
_createClass(Directive, [{
|
|
61
24
|
key: "parseName",
|
|
62
25
|
value: function parseName(start) {
|
|
63
26
|
var src = this.context.src;
|
|
@@ -82,7 +45,7 @@ function (_Node) {
|
|
|
82
45
|
ch = src[offset += 1];
|
|
83
46
|
}
|
|
84
47
|
|
|
85
|
-
this.valueRange = new
|
|
48
|
+
this.valueRange = new Range(start, offset);
|
|
86
49
|
return offset;
|
|
87
50
|
}
|
|
88
51
|
}, {
|
|
@@ -92,7 +55,7 @@ function (_Node) {
|
|
|
92
55
|
var offset = this.parseName(start + 1);
|
|
93
56
|
offset = this.parseParameters(offset);
|
|
94
57
|
offset = this.parseComment(offset);
|
|
95
|
-
this.range = new
|
|
58
|
+
this.range = new Range(start, offset);
|
|
96
59
|
return offset;
|
|
97
60
|
}
|
|
98
61
|
}, {
|
|
@@ -102,7 +65,8 @@ function (_Node) {
|
|
|
102
65
|
return raw ? raw.trim().split(/[ \t]+/) : [];
|
|
103
66
|
}
|
|
104
67
|
}]);
|
|
68
|
+
|
|
105
69
|
return Directive;
|
|
106
|
-
}(
|
|
70
|
+
}(Node);
|
|
107
71
|
|
|
108
|
-
|
|
72
|
+
export { Directive as default };
|
|
@@ -1,49 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
21
|
-
|
|
22
|
-
var _constants = require("../constants");
|
|
23
|
-
|
|
24
|
-
var _errors = require("../errors");
|
|
25
|
-
|
|
26
|
-
var _BlankLine = _interopRequireDefault(require("./BlankLine"));
|
|
27
|
-
|
|
28
|
-
var _Collection = require("./Collection");
|
|
29
|
-
|
|
30
|
-
var _Comment = _interopRequireDefault(require("./Comment"));
|
|
31
|
-
|
|
32
|
-
var _Directive = _interopRequireDefault(require("./Directive"));
|
|
33
|
-
|
|
34
|
-
var _Node2 = _interopRequireDefault(require("./Node"));
|
|
35
|
-
|
|
36
|
-
var _Range = _interopRequireDefault(require("./Range"));
|
|
37
|
-
|
|
38
|
-
var Document =
|
|
39
|
-
/*#__PURE__*/
|
|
40
|
-
function (_Node) {
|
|
41
|
-
(0, _inherits2.default)(Document, _Node);
|
|
42
|
-
(0, _createClass2.default)(Document, null, [{
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
3
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
4
|
+
import _get from "@babel/runtime/helpers/get";
|
|
5
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
6
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
7
|
+
import { Char, Type } from '../constants';
|
|
8
|
+
import { YAMLSemanticError, YAMLSyntaxError } from '../errors';
|
|
9
|
+
import BlankLine from './BlankLine';
|
|
10
|
+
import { grabCollectionEndComments } from './Collection';
|
|
11
|
+
import Comment from './Comment';
|
|
12
|
+
import Directive from './Directive';
|
|
13
|
+
import Node from './Node';
|
|
14
|
+
import Range from './Range';
|
|
15
|
+
|
|
16
|
+
var Document = /*#__PURE__*/function (_Node) {
|
|
17
|
+
_inherits(Document, _Node);
|
|
18
|
+
|
|
19
|
+
_createClass(Document, null, [{
|
|
43
20
|
key: "startCommentOrEndBlankLine",
|
|
44
21
|
value: function startCommentOrEndBlankLine(src, start) {
|
|
45
|
-
var offset =
|
|
46
|
-
|
|
22
|
+
var offset = Node.endOfWhiteSpace(src, start);
|
|
47
23
|
var ch = src[offset];
|
|
48
24
|
return ch === '#' || ch === '\n' ? offset : start;
|
|
49
25
|
}
|
|
@@ -52,8 +28,9 @@ function (_Node) {
|
|
|
52
28
|
function Document() {
|
|
53
29
|
var _this;
|
|
54
30
|
|
|
55
|
-
(
|
|
56
|
-
|
|
31
|
+
_classCallCheck(this, Document);
|
|
32
|
+
|
|
33
|
+
_this = _possibleConstructorReturn(this, _getPrototypeOf(Document).call(this, Type.DOCUMENT));
|
|
57
34
|
_this.directives = null;
|
|
58
35
|
_this.contents = null;
|
|
59
36
|
_this.directivesEndMarker = null;
|
|
@@ -61,7 +38,7 @@ function (_Node) {
|
|
|
61
38
|
return _this;
|
|
62
39
|
}
|
|
63
40
|
|
|
64
|
-
(
|
|
41
|
+
_createClass(Document, [{
|
|
65
42
|
key: "parseDirectives",
|
|
66
43
|
value: function parseDirectives(start) {
|
|
67
44
|
var src = this.context.src;
|
|
@@ -70,13 +47,13 @@ function (_Node) {
|
|
|
70
47
|
var hasDirectives = false;
|
|
71
48
|
var offset = start;
|
|
72
49
|
|
|
73
|
-
while (!
|
|
50
|
+
while (!Node.atDocumentBoundary(src, offset, Char.DIRECTIVES_END)) {
|
|
74
51
|
offset = Document.startCommentOrEndBlankLine(src, offset);
|
|
75
52
|
|
|
76
53
|
switch (src[offset]) {
|
|
77
54
|
case '\n':
|
|
78
55
|
if (atLineStart) {
|
|
79
|
-
var blankLine = new
|
|
56
|
+
var blankLine = new BlankLine();
|
|
80
57
|
offset = blankLine.parse({
|
|
81
58
|
src: src
|
|
82
59
|
}, offset);
|
|
@@ -93,7 +70,7 @@ function (_Node) {
|
|
|
93
70
|
|
|
94
71
|
case '#':
|
|
95
72
|
{
|
|
96
|
-
var comment = new
|
|
73
|
+
var comment = new Comment();
|
|
97
74
|
offset = comment.parse({
|
|
98
75
|
src: src
|
|
99
76
|
}, offset);
|
|
@@ -104,7 +81,7 @@ function (_Node) {
|
|
|
104
81
|
|
|
105
82
|
case '%':
|
|
106
83
|
{
|
|
107
|
-
var directive = new
|
|
84
|
+
var directive = new Directive();
|
|
108
85
|
offset = directive.parse({
|
|
109
86
|
parent: this,
|
|
110
87
|
src: src
|
|
@@ -117,7 +94,7 @@ function (_Node) {
|
|
|
117
94
|
|
|
118
95
|
default:
|
|
119
96
|
if (hasDirectives) {
|
|
120
|
-
this.error = new
|
|
97
|
+
this.error = new YAMLSemanticError(this, 'Missing directives-end indicator line');
|
|
121
98
|
} else if (this.directives.length > 0) {
|
|
122
99
|
this.contents = this.directives;
|
|
123
100
|
this.directives = [];
|
|
@@ -128,12 +105,12 @@ function (_Node) {
|
|
|
128
105
|
}
|
|
129
106
|
|
|
130
107
|
if (src[offset]) {
|
|
131
|
-
this.directivesEndMarker = new
|
|
108
|
+
this.directivesEndMarker = new Range(offset, offset + 3);
|
|
132
109
|
return offset + 3;
|
|
133
110
|
}
|
|
134
111
|
|
|
135
112
|
if (hasDirectives) {
|
|
136
|
-
this.error = new
|
|
113
|
+
this.error = new YAMLSemanticError(this, 'Missing directives-end indicator line');
|
|
137
114
|
} else if (this.directives.length > 0) {
|
|
138
115
|
this.contents = this.directives;
|
|
139
116
|
this.directives = [];
|
|
@@ -154,16 +131,15 @@ function (_Node) {
|
|
|
154
131
|
lineStart -= 1;
|
|
155
132
|
}
|
|
156
133
|
|
|
157
|
-
var offset =
|
|
158
|
-
|
|
134
|
+
var offset = Node.endOfWhiteSpace(src, start);
|
|
159
135
|
var atLineStart = lineStart === start;
|
|
160
|
-
this.valueRange = new
|
|
136
|
+
this.valueRange = new Range(offset);
|
|
161
137
|
|
|
162
|
-
while (!
|
|
138
|
+
while (!Node.atDocumentBoundary(src, offset, Char.DOCUMENT_END)) {
|
|
163
139
|
switch (src[offset]) {
|
|
164
140
|
case '\n':
|
|
165
141
|
if (atLineStart) {
|
|
166
|
-
var blankLine = new
|
|
142
|
+
var blankLine = new BlankLine();
|
|
167
143
|
offset = blankLine.parse({
|
|
168
144
|
src: src
|
|
169
145
|
}, offset);
|
|
@@ -181,7 +157,7 @@ function (_Node) {
|
|
|
181
157
|
|
|
182
158
|
case '#':
|
|
183
159
|
{
|
|
184
|
-
var comment = new
|
|
160
|
+
var comment = new Comment();
|
|
185
161
|
offset = comment.parse({
|
|
186
162
|
src: src
|
|
187
163
|
}, offset);
|
|
@@ -192,8 +168,7 @@ function (_Node) {
|
|
|
192
168
|
|
|
193
169
|
default:
|
|
194
170
|
{
|
|
195
|
-
var iEnd =
|
|
196
|
-
|
|
171
|
+
var iEnd = Node.endOfIndent(src, offset);
|
|
197
172
|
var context = {
|
|
198
173
|
atLineStart: atLineStart,
|
|
199
174
|
indent: -1,
|
|
@@ -208,7 +183,7 @@ function (_Node) {
|
|
|
208
183
|
this.contents.push(node);
|
|
209
184
|
offset = node.range.end;
|
|
210
185
|
atLineStart = false;
|
|
211
|
-
var ec =
|
|
186
|
+
var ec = grabCollectionEndComments(node);
|
|
212
187
|
if (ec) Array.prototype.push.apply(this.contents, ec);
|
|
213
188
|
}
|
|
214
189
|
}
|
|
@@ -219,14 +194,14 @@ function (_Node) {
|
|
|
219
194
|
this.valueRange.end = offset;
|
|
220
195
|
|
|
221
196
|
if (src[offset]) {
|
|
222
|
-
this.documentEndMarker = new
|
|
197
|
+
this.documentEndMarker = new Range(offset, offset + 3);
|
|
223
198
|
offset += 3;
|
|
224
199
|
|
|
225
200
|
if (src[offset]) {
|
|
226
|
-
offset =
|
|
201
|
+
offset = Node.endOfWhiteSpace(src, offset);
|
|
227
202
|
|
|
228
203
|
if (src[offset] === '#') {
|
|
229
|
-
var _comment = new
|
|
204
|
+
var _comment = new Comment();
|
|
230
205
|
|
|
231
206
|
offset = _comment.parse({
|
|
232
207
|
src: src
|
|
@@ -243,7 +218,7 @@ function (_Node) {
|
|
|
243
218
|
break;
|
|
244
219
|
|
|
245
220
|
default:
|
|
246
|
-
this.error = new
|
|
221
|
+
this.error = new YAMLSyntaxError(this, 'Document end marker line cannot have a non-comment suffix');
|
|
247
222
|
}
|
|
248
223
|
}
|
|
249
224
|
}
|
|
@@ -271,7 +246,7 @@ function (_Node) {
|
|
|
271
246
|
}, {
|
|
272
247
|
key: "setOrigRanges",
|
|
273
248
|
value: function setOrigRanges(cr, offset) {
|
|
274
|
-
offset = (
|
|
249
|
+
offset = _get(_getPrototypeOf(Document.prototype), "setOrigRanges", this).call(this, cr, offset);
|
|
275
250
|
this.directives.forEach(function (node) {
|
|
276
251
|
offset = node.setOrigRanges(cr, offset);
|
|
277
252
|
});
|
|
@@ -292,7 +267,7 @@ function (_Node) {
|
|
|
292
267
|
var str = directives.join('');
|
|
293
268
|
|
|
294
269
|
if (contents.length > 0) {
|
|
295
|
-
if (directives.length > 0 || contents[0].type ===
|
|
270
|
+
if (directives.length > 0 || contents[0].type === Type.COMMENT) str += '---\n';
|
|
296
271
|
str += contents.join('');
|
|
297
272
|
}
|
|
298
273
|
|
|
@@ -300,7 +275,8 @@ function (_Node) {
|
|
|
300
275
|
return str;
|
|
301
276
|
}
|
|
302
277
|
}]);
|
|
278
|
+
|
|
303
279
|
return Document;
|
|
304
|
-
}(
|
|
280
|
+
}(Node);
|
|
305
281
|
|
|
306
|
-
|
|
282
|
+
export { Document as default };
|