yaml 1.9.1 → 1.10.2

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.
Files changed (162) hide show
  1. package/README.md +25 -25
  2. package/browser/dist/PlainValue-b8036b75.js +1275 -0
  3. package/browser/dist/Schema-e94716c8.js +682 -0
  4. package/browser/dist/index.js +860 -27
  5. package/browser/dist/legacy-exports.js +3 -0
  6. package/browser/dist/package.json +1 -0
  7. package/browser/dist/parse-cst.js +1904 -0
  8. package/browser/dist/resolveSeq-492ab440.js +2419 -0
  9. package/browser/dist/types.js +4 -0
  10. package/browser/dist/util.js +2 -0
  11. package/browser/dist/warnings-df54cb69.js +499 -0
  12. package/browser/index.js +1 -1
  13. package/browser/map.js +2 -4
  14. package/browser/pair.js +2 -4
  15. package/browser/parse-cst.js +1 -1
  16. package/browser/scalar.js +2 -4
  17. package/browser/schema.js +7 -10
  18. package/browser/seq.js +2 -4
  19. package/browser/types/binary.js +7 -5
  20. package/browser/types/omap.js +3 -4
  21. package/browser/types/pairs.js +3 -4
  22. package/browser/types/set.js +3 -4
  23. package/browser/types/timestamp.js +9 -5
  24. package/browser/types.js +1 -13
  25. package/browser/util.js +1 -18
  26. package/dist/Document-9b4560a1.js +757 -0
  27. package/dist/PlainValue-ec8e588e.js +876 -0
  28. package/dist/Schema-88e323a7.js +525 -0
  29. package/dist/index.js +20 -84
  30. package/dist/legacy-exports.js +16 -0
  31. package/dist/parse-cst.js +1753 -0
  32. package/dist/resolveSeq-d03cb037.js +2161 -0
  33. package/dist/test-events.js +11 -9
  34. package/dist/types.js +23 -0
  35. package/dist/util.js +19 -0
  36. package/dist/warnings-1000a372.js +416 -0
  37. package/index.d.ts +23 -9
  38. package/map.js +2 -2
  39. package/package.json +27 -42
  40. package/pair.js +2 -2
  41. package/parse-cst.d.ts +4 -0
  42. package/parse-cst.js +1 -1
  43. package/scalar.js +2 -2
  44. package/schema.js +8 -6
  45. package/seq.js +2 -2
  46. package/types/binary.js +3 -2
  47. package/types/omap.js +3 -2
  48. package/types/pairs.js +3 -2
  49. package/types/set.js +3 -2
  50. package/types/timestamp.js +6 -6
  51. package/types.d.ts +113 -98
  52. package/types.js +16 -11
  53. package/types.mjs +15 -19
  54. package/util.js +14 -14
  55. package/util.mjs +13 -20
  56. package/browser/dist/Anchors.js +0 -130
  57. package/browser/dist/Document.js +0 -824
  58. package/browser/dist/addComment.js +0 -8
  59. package/browser/dist/constants.js +0 -26
  60. package/browser/dist/cst/Alias.js +0 -46
  61. package/browser/dist/cst/BlankLine.js +0 -52
  62. package/browser/dist/cst/BlockValue.js +0 -251
  63. package/browser/dist/cst/Collection.js +0 -278
  64. package/browser/dist/cst/CollectionItem.js +0 -140
  65. package/browser/dist/cst/Comment.js +0 -44
  66. package/browser/dist/cst/Directive.js +0 -76
  67. package/browser/dist/cst/Document.js +0 -286
  68. package/browser/dist/cst/FlowCollection.js +0 -220
  69. package/browser/dist/cst/Node.js +0 -386
  70. package/browser/dist/cst/ParseContext.js +0 -246
  71. package/browser/dist/cst/PlainValue.js +0 -170
  72. package/browser/dist/cst/QuoteDouble.js +0 -245
  73. package/browser/dist/cst/QuoteSingle.js +0 -120
  74. package/browser/dist/cst/Range.js +0 -64
  75. package/browser/dist/cst/parse.js +0 -48
  76. package/browser/dist/cst/source-utils.js +0 -168
  77. package/browser/dist/errors.js +0 -127
  78. package/browser/dist/foldFlowLines.js +0 -138
  79. package/browser/dist/listTagNames.js +0 -28
  80. package/browser/dist/schema/Alias.js +0 -135
  81. package/browser/dist/schema/Collection.js +0 -260
  82. package/browser/dist/schema/Map.js +0 -161
  83. package/browser/dist/schema/Merge.js +0 -118
  84. package/browser/dist/schema/Node.js +0 -4
  85. package/browser/dist/schema/Pair.js +0 -194
  86. package/browser/dist/schema/Scalar.js +0 -42
  87. package/browser/dist/schema/Seq.js +0 -116
  88. package/browser/dist/schema/index.js +0 -368
  89. package/browser/dist/schema/parseMap.js +0 -312
  90. package/browser/dist/schema/parseSeq.js +0 -168
  91. package/browser/dist/schema/parseUtils.js +0 -106
  92. package/browser/dist/stringify.js +0 -332
  93. package/browser/dist/tags/core.js +0 -141
  94. package/browser/dist/tags/failsafe/index.js +0 -4
  95. package/browser/dist/tags/failsafe/map.js +0 -53
  96. package/browser/dist/tags/failsafe/seq.js +0 -39
  97. package/browser/dist/tags/failsafe/string.js +0 -28
  98. package/browser/dist/tags/index.js +0 -36
  99. package/browser/dist/tags/json.js +0 -77
  100. package/browser/dist/tags/options.js +0 -26
  101. package/browser/dist/tags/yaml-1.1/binary.js +0 -87
  102. package/browser/dist/tags/yaml-1.1/index.js +0 -189
  103. package/browser/dist/tags/yaml-1.1/omap.js +0 -137
  104. package/browser/dist/tags/yaml-1.1/pairs.js +0 -78
  105. package/browser/dist/tags/yaml-1.1/set.js +0 -118
  106. package/browser/dist/tags/yaml-1.1/timestamp.js +0 -97
  107. package/browser/dist/test-events.js +0 -163
  108. package/browser/dist/toJSON.js +0 -19
  109. package/browser/dist/warnings.js +0 -39
  110. package/dist/Anchors.js +0 -120
  111. package/dist/Document.js +0 -714
  112. package/dist/addComment.js +0 -14
  113. package/dist/constants.js +0 -31
  114. package/dist/cst/Alias.js +0 -33
  115. package/dist/cst/BlankLine.js +0 -40
  116. package/dist/cst/BlockValue.js +0 -243
  117. package/dist/cst/Collection.js +0 -266
  118. package/dist/cst/CollectionItem.js +0 -135
  119. package/dist/cst/Comment.js +0 -33
  120. package/dist/cst/Directive.js +0 -59
  121. package/dist/cst/Document.js +0 -276
  122. package/dist/cst/FlowCollection.js +0 -213
  123. package/dist/cst/Node.js +0 -360
  124. package/dist/cst/ParseContext.js +0 -253
  125. package/dist/cst/PlainValue.js +0 -156
  126. package/dist/cst/QuoteDouble.js +0 -232
  127. package/dist/cst/QuoteSingle.js +0 -108
  128. package/dist/cst/Range.js +0 -60
  129. package/dist/cst/parse.js +0 -50
  130. package/dist/cst/source-utils.js +0 -175
  131. package/dist/errors.js +0 -97
  132. package/dist/foldFlowLines.js +0 -143
  133. package/dist/listTagNames.js +0 -33
  134. package/dist/schema/Alias.js +0 -105
  135. package/dist/schema/Collection.js +0 -184
  136. package/dist/schema/Map.js +0 -98
  137. package/dist/schema/Merge.js +0 -75
  138. package/dist/schema/Node.js +0 -7
  139. package/dist/schema/Pair.js +0 -174
  140. package/dist/schema/Scalar.js +0 -26
  141. package/dist/schema/Seq.js +0 -73
  142. package/dist/schema/index.js +0 -310
  143. package/dist/schema/parseMap.js +0 -334
  144. package/dist/schema/parseSeq.js +0 -175
  145. package/dist/schema/parseUtils.js +0 -101
  146. package/dist/stringify.js +0 -352
  147. package/dist/tags/core.js +0 -121
  148. package/dist/tags/failsafe/index.js +0 -12
  149. package/dist/tags/failsafe/map.js +0 -32
  150. package/dist/tags/failsafe/seq.js +0 -29
  151. package/dist/tags/failsafe/string.js +0 -37
  152. package/dist/tags/index.js +0 -53
  153. package/dist/tags/json.js +0 -64
  154. package/dist/tags/options.js +0 -36
  155. package/dist/tags/yaml-1.1/binary.js +0 -94
  156. package/dist/tags/yaml-1.1/index.js +0 -162
  157. package/dist/tags/yaml-1.1/omap.js +0 -100
  158. package/dist/tags/yaml-1.1/pairs.js +0 -75
  159. package/dist/tags/yaml-1.1/set.js +0 -82
  160. package/dist/tags/yaml-1.1/timestamp.js +0 -90
  161. package/dist/toJSON.js +0 -21
  162. package/dist/warnings.js +0 -48
@@ -1,140 +0,0 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
- import _get from "@babel/runtime/helpers/get";
4
- import _inherits from "@babel/runtime/helpers/inherits";
5
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
6
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
7
-
8
- function _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
9
-
10
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
11
-
12
- import { Type } from '../constants';
13
- import { YAMLSemanticError } from '../errors';
14
- import { BlankLine } from './BlankLine';
15
- import { Node } from './Node';
16
- import { Range } from './Range';
17
- export var CollectionItem = /*#__PURE__*/function (_Node) {
18
- _inherits(CollectionItem, _Node);
19
-
20
- var _super = _createSuper(CollectionItem);
21
-
22
- function CollectionItem(type, props) {
23
- var _this;
24
-
25
- _classCallCheck(this, CollectionItem);
26
-
27
- _this = _super.call(this, type, props);
28
- _this.node = null;
29
- return _this;
30
- }
31
-
32
- _createClass(CollectionItem, [{
33
- key: "parse",
34
-
35
- /**
36
- * @param {ParseContext} context
37
- * @param {number} start - Index of first character
38
- * @returns {number} - Index of the character after this
39
- */
40
- value: function parse(context, start) {
41
- this.context = context;
42
- var parseNode = context.parseNode,
43
- src = context.src;
44
- var atLineStart = context.atLineStart,
45
- lineStart = context.lineStart;
46
- if (!atLineStart && this.type === Type.SEQ_ITEM) this.error = new YAMLSemanticError(this, 'Sequence items must not have preceding content on the same line');
47
- var indent = atLineStart ? start - lineStart : context.indent;
48
- var offset = Node.endOfWhiteSpace(src, start + 1);
49
- var ch = src[offset];
50
- var inlineComment = ch === '#';
51
- var comments = [];
52
- var blankLine = null;
53
-
54
- while (ch === '\n' || ch === '#') {
55
- if (ch === '#') {
56
- var _end = Node.endOfLine(src, offset + 1);
57
-
58
- comments.push(new Range(offset, _end));
59
- offset = _end;
60
- } else {
61
- atLineStart = true;
62
- lineStart = offset + 1;
63
- var wsEnd = Node.endOfWhiteSpace(src, lineStart);
64
-
65
- if (src[wsEnd] === '\n' && comments.length === 0) {
66
- blankLine = new BlankLine();
67
- lineStart = blankLine.parse({
68
- src: src
69
- }, lineStart);
70
- }
71
-
72
- offset = Node.endOfIndent(src, lineStart);
73
- }
74
-
75
- ch = src[offset];
76
- }
77
-
78
- if (Node.nextNodeIsIndented(ch, offset - (lineStart + indent), this.type !== Type.SEQ_ITEM)) {
79
- this.node = parseNode({
80
- atLineStart: atLineStart,
81
- inCollection: false,
82
- indent: indent,
83
- lineStart: lineStart,
84
- parent: this
85
- }, offset);
86
- } else if (ch && lineStart > start + 1) {
87
- offset = lineStart - 1;
88
- }
89
-
90
- if (this.node) {
91
- if (blankLine) {
92
- // Only blank lines preceding non-empty nodes are captured. Note that
93
- // this means that collection item range start indices do not always
94
- // increase monotonically. -- eemeli/yaml#126
95
- var items = context.parent.items || context.parent.contents;
96
- if (items) items.push(blankLine);
97
- }
98
-
99
- if (comments.length) Array.prototype.push.apply(this.props, comments);
100
- offset = this.node.range.end;
101
- } else {
102
- if (inlineComment) {
103
- var c = comments[0];
104
- this.props.push(c);
105
- offset = c.end;
106
- } else {
107
- offset = Node.endOfLine(src, start + 1);
108
- }
109
- }
110
-
111
- var end = this.node ? this.node.valueRange.end : offset;
112
- this.valueRange = new Range(start, end);
113
- return offset;
114
- }
115
- }, {
116
- key: "setOrigRanges",
117
- value: function setOrigRanges(cr, offset) {
118
- offset = _get(_getPrototypeOf(CollectionItem.prototype), "setOrigRanges", this).call(this, cr, offset);
119
- return this.node ? this.node.setOrigRanges(cr, offset) : offset;
120
- }
121
- }, {
122
- key: "toString",
123
- value: function toString() {
124
- var src = this.context.src,
125
- node = this.node,
126
- range = this.range,
127
- value = this.value;
128
- if (value != null) return value;
129
- var str = node ? src.slice(range.start, node.range.start) + String(node) : src.slice(range.start, range.end);
130
- return Node.addStringTerminator(src, range.end, str);
131
- }
132
- }, {
133
- key: "includesTrailingLines",
134
- get: function get() {
135
- return !!this.node && this.node.includesTrailingLines;
136
- }
137
- }]);
138
-
139
- return CollectionItem;
140
- }(Node);
@@ -1,44 +0,0 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
- import _inherits from "@babel/runtime/helpers/inherits";
4
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
-
7
- function _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
8
-
9
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
10
-
11
- import { Type } from '../constants';
12
- import { Node } from './Node';
13
- import { Range } from './Range';
14
- export var Comment = /*#__PURE__*/function (_Node) {
15
- _inherits(Comment, _Node);
16
-
17
- var _super = _createSuper(Comment);
18
-
19
- function Comment() {
20
- _classCallCheck(this, Comment);
21
-
22
- return _super.call(this, Type.COMMENT);
23
- }
24
- /**
25
- * Parses a comment line from the source
26
- *
27
- * @param {ParseContext} context
28
- * @param {number} start - Index of first character
29
- * @returns {number} - Index of the character after this scalar
30
- */
31
-
32
-
33
- _createClass(Comment, [{
34
- key: "parse",
35
- value: function parse(context, start) {
36
- this.context = context;
37
- var offset = this.parseComment(start);
38
- this.range = new Range(start, offset);
39
- return offset;
40
- }
41
- }]);
42
-
43
- return Comment;
44
- }(Node);
@@ -1,76 +0,0 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
- import _inherits from "@babel/runtime/helpers/inherits";
4
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
-
7
- function _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
8
-
9
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
10
-
11
- import { Type } from '../constants';
12
- import { Node } from './Node';
13
- import { Range } from './Range';
14
- export var Directive = /*#__PURE__*/function (_Node) {
15
- _inherits(Directive, _Node);
16
-
17
- var _super = _createSuper(Directive);
18
-
19
- function Directive() {
20
- var _this;
21
-
22
- _classCallCheck(this, Directive);
23
-
24
- _this = _super.call(this, Type.DIRECTIVE);
25
- _this.name = null;
26
- return _this;
27
- }
28
-
29
- _createClass(Directive, [{
30
- key: "parseName",
31
- value: function parseName(start) {
32
- var src = this.context.src;
33
- var offset = start;
34
- var ch = src[offset];
35
-
36
- while (ch && ch !== '\n' && ch !== '\t' && ch !== ' ') {
37
- ch = src[offset += 1];
38
- }
39
-
40
- this.name = src.slice(start, offset);
41
- return offset;
42
- }
43
- }, {
44
- key: "parseParameters",
45
- value: function parseParameters(start) {
46
- var src = this.context.src;
47
- var offset = start;
48
- var ch = src[offset];
49
-
50
- while (ch && ch !== '\n' && ch !== '#') {
51
- ch = src[offset += 1];
52
- }
53
-
54
- this.valueRange = new Range(start, offset);
55
- return offset;
56
- }
57
- }, {
58
- key: "parse",
59
- value: function parse(context, start) {
60
- this.context = context;
61
- var offset = this.parseName(start + 1);
62
- offset = this.parseParameters(offset);
63
- offset = this.parseComment(offset);
64
- this.range = new Range(start, offset);
65
- return offset;
66
- }
67
- }, {
68
- key: "parameters",
69
- get: function get() {
70
- var raw = this.rawValue;
71
- return raw ? raw.trim().split(/[ \t]+/) : [];
72
- }
73
- }]);
74
-
75
- return Directive;
76
- }(Node);
@@ -1,286 +0,0 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _get from "@babel/runtime/helpers/get";
3
- import _createClass from "@babel/runtime/helpers/createClass";
4
- import _inherits from "@babel/runtime/helpers/inherits";
5
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
6
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
7
-
8
- function _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
9
-
10
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
11
-
12
- import { Char, Type } from '../constants';
13
- import { YAMLSemanticError, YAMLSyntaxError } from '../errors';
14
- import { BlankLine } from './BlankLine';
15
- import { grabCollectionEndComments } from './Collection';
16
- import { Comment } from './Comment';
17
- import { Directive } from './Directive';
18
- import { Node } from './Node';
19
- import { Range } from './Range';
20
- export var Document = /*#__PURE__*/function (_Node) {
21
- _inherits(Document, _Node);
22
-
23
- var _super = _createSuper(Document);
24
-
25
- _createClass(Document, null, [{
26
- key: "startCommentOrEndBlankLine",
27
- value: function startCommentOrEndBlankLine(src, start) {
28
- var offset = Node.endOfWhiteSpace(src, start);
29
- var ch = src[offset];
30
- return ch === '#' || ch === '\n' ? offset : start;
31
- }
32
- }]);
33
-
34
- function Document() {
35
- var _this;
36
-
37
- _classCallCheck(this, Document);
38
-
39
- _this = _super.call(this, Type.DOCUMENT);
40
- _this.directives = null;
41
- _this.contents = null;
42
- _this.directivesEndMarker = null;
43
- _this.documentEndMarker = null;
44
- return _this;
45
- }
46
-
47
- _createClass(Document, [{
48
- key: "parseDirectives",
49
- value: function parseDirectives(start) {
50
- var src = this.context.src;
51
- this.directives = [];
52
- var atLineStart = true;
53
- var hasDirectives = false;
54
- var offset = start;
55
-
56
- while (!Node.atDocumentBoundary(src, offset, Char.DIRECTIVES_END)) {
57
- offset = Document.startCommentOrEndBlankLine(src, offset);
58
-
59
- switch (src[offset]) {
60
- case '\n':
61
- if (atLineStart) {
62
- var blankLine = new BlankLine();
63
- offset = blankLine.parse({
64
- src: src
65
- }, offset);
66
-
67
- if (offset < src.length) {
68
- this.directives.push(blankLine);
69
- }
70
- } else {
71
- offset += 1;
72
- atLineStart = true;
73
- }
74
-
75
- break;
76
-
77
- case '#':
78
- {
79
- var comment = new Comment();
80
- offset = comment.parse({
81
- src: src
82
- }, offset);
83
- this.directives.push(comment);
84
- atLineStart = false;
85
- }
86
- break;
87
-
88
- case '%':
89
- {
90
- var directive = new Directive();
91
- offset = directive.parse({
92
- parent: this,
93
- src: src
94
- }, offset);
95
- this.directives.push(directive);
96
- hasDirectives = true;
97
- atLineStart = false;
98
- }
99
- break;
100
-
101
- default:
102
- if (hasDirectives) {
103
- this.error = new YAMLSemanticError(this, 'Missing directives-end indicator line');
104
- } else if (this.directives.length > 0) {
105
- this.contents = this.directives;
106
- this.directives = [];
107
- }
108
-
109
- return offset;
110
- }
111
- }
112
-
113
- if (src[offset]) {
114
- this.directivesEndMarker = new Range(offset, offset + 3);
115
- return offset + 3;
116
- }
117
-
118
- if (hasDirectives) {
119
- this.error = new YAMLSemanticError(this, 'Missing directives-end indicator line');
120
- } else if (this.directives.length > 0) {
121
- this.contents = this.directives;
122
- this.directives = [];
123
- }
124
-
125
- return offset;
126
- }
127
- }, {
128
- key: "parseContents",
129
- value: function parseContents(start) {
130
- var _this$context = this.context,
131
- parseNode = _this$context.parseNode,
132
- src = _this$context.src;
133
- if (!this.contents) this.contents = [];
134
- var lineStart = start;
135
-
136
- while (src[lineStart - 1] === '-') {
137
- lineStart -= 1;
138
- }
139
-
140
- var offset = Node.endOfWhiteSpace(src, start);
141
- var atLineStart = lineStart === start;
142
- this.valueRange = new Range(offset);
143
-
144
- while (!Node.atDocumentBoundary(src, offset, Char.DOCUMENT_END)) {
145
- switch (src[offset]) {
146
- case '\n':
147
- if (atLineStart) {
148
- var blankLine = new BlankLine();
149
- offset = blankLine.parse({
150
- src: src
151
- }, offset);
152
-
153
- if (offset < src.length) {
154
- this.contents.push(blankLine);
155
- }
156
- } else {
157
- offset += 1;
158
- atLineStart = true;
159
- }
160
-
161
- lineStart = offset;
162
- break;
163
-
164
- case '#':
165
- {
166
- var comment = new Comment();
167
- offset = comment.parse({
168
- src: src
169
- }, offset);
170
- this.contents.push(comment);
171
- atLineStart = false;
172
- }
173
- break;
174
-
175
- default:
176
- {
177
- var iEnd = Node.endOfIndent(src, offset);
178
- var context = {
179
- atLineStart: atLineStart,
180
- indent: -1,
181
- inFlow: false,
182
- inCollection: false,
183
- lineStart: lineStart,
184
- parent: this
185
- };
186
- var node = parseNode(context, iEnd);
187
- if (!node) return this.valueRange.end = iEnd; // at next document start
188
-
189
- this.contents.push(node);
190
- offset = node.range.end;
191
- atLineStart = false;
192
- var ec = grabCollectionEndComments(node);
193
- if (ec) Array.prototype.push.apply(this.contents, ec);
194
- }
195
- }
196
-
197
- offset = Document.startCommentOrEndBlankLine(src, offset);
198
- }
199
-
200
- this.valueRange.end = offset;
201
-
202
- if (src[offset]) {
203
- this.documentEndMarker = new Range(offset, offset + 3);
204
- offset += 3;
205
-
206
- if (src[offset]) {
207
- offset = Node.endOfWhiteSpace(src, offset);
208
-
209
- if (src[offset] === '#') {
210
- var _comment = new Comment();
211
-
212
- offset = _comment.parse({
213
- src: src
214
- }, offset);
215
- this.contents.push(_comment);
216
- }
217
-
218
- switch (src[offset]) {
219
- case '\n':
220
- offset += 1;
221
- break;
222
-
223
- case undefined:
224
- break;
225
-
226
- default:
227
- this.error = new YAMLSyntaxError(this, 'Document end marker line cannot have a non-comment suffix');
228
- }
229
- }
230
- }
231
-
232
- return offset;
233
- }
234
- /**
235
- * @param {ParseContext} context
236
- * @param {number} start - Index of first character
237
- * @returns {number} - Index of the character after this
238
- */
239
-
240
- }, {
241
- key: "parse",
242
- value: function parse(context, start) {
243
- context.root = this;
244
- this.context = context;
245
- var src = context.src;
246
- var offset = src.charCodeAt(start) === 0xfeff ? start + 1 : start; // skip BOM
247
-
248
- offset = this.parseDirectives(offset);
249
- offset = this.parseContents(offset);
250
- return offset;
251
- }
252
- }, {
253
- key: "setOrigRanges",
254
- value: function setOrigRanges(cr, offset) {
255
- offset = _get(_getPrototypeOf(Document.prototype), "setOrigRanges", this).call(this, cr, offset);
256
- this.directives.forEach(function (node) {
257
- offset = node.setOrigRanges(cr, offset);
258
- });
259
- if (this.directivesEndMarker) offset = this.directivesEndMarker.setOrigRange(cr, offset);
260
- this.contents.forEach(function (node) {
261
- offset = node.setOrigRanges(cr, offset);
262
- });
263
- if (this.documentEndMarker) offset = this.documentEndMarker.setOrigRange(cr, offset);
264
- return offset;
265
- }
266
- }, {
267
- key: "toString",
268
- value: function toString() {
269
- var contents = this.contents,
270
- directives = this.directives,
271
- value = this.value;
272
- if (value != null) return value;
273
- var str = directives.join('');
274
-
275
- if (contents.length > 0) {
276
- if (directives.length > 0 || contents[0].type === Type.COMMENT) str += '---\n';
277
- str += contents.join('');
278
- }
279
-
280
- if (str[str.length - 1] !== '\n') str += '\n';
281
- return str;
282
- }
283
- }]);
284
-
285
- return Document;
286
- }(Node);