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