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,8 +0,0 @@
1
- export function addCommentBefore(str, indent, comment) {
2
- if (!comment) return str;
3
- var cc = comment.replace(/[\s\S]^/gm, "$&".concat(indent, "#"));
4
- return "#".concat(cc, "\n").concat(indent).concat(str);
5
- }
6
- export function addComment(str, indent, comment) {
7
- return !comment ? str : comment.indexOf('\n') === -1 ? "".concat(str, " #").concat(comment) : "".concat(str, "\n") + comment.replace(/^/gm, "".concat(indent || '', "#"));
8
- }
@@ -1,26 +0,0 @@
1
- export var Char = {
2
- ANCHOR: '&',
3
- COMMENT: '#',
4
- TAG: '!',
5
- DIRECTIVES_END: '-',
6
- DOCUMENT_END: '.'
7
- };
8
- export var Type = {
9
- ALIAS: 'ALIAS',
10
- BLANK_LINE: 'BLANK_LINE',
11
- BLOCK_FOLDED: 'BLOCK_FOLDED',
12
- BLOCK_LITERAL: 'BLOCK_LITERAL',
13
- COMMENT: 'COMMENT',
14
- DIRECTIVE: 'DIRECTIVE',
15
- DOCUMENT: 'DOCUMENT',
16
- FLOW_MAP: 'FLOW_MAP',
17
- FLOW_SEQ: 'FLOW_SEQ',
18
- MAP: 'MAP',
19
- MAP_KEY: 'MAP_KEY',
20
- MAP_VALUE: 'MAP_VALUE',
21
- PLAIN: 'PLAIN',
22
- QUOTE_DOUBLE: 'QUOTE_DOUBLE',
23
- QUOTE_SINGLE: 'QUOTE_SINGLE',
24
- SEQ: 'SEQ',
25
- SEQ_ITEM: 'SEQ_ITEM'
26
- };
@@ -1,46 +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 { Node } from './Node';
12
- import { Range } from './Range';
13
- export var Alias = /*#__PURE__*/function (_Node) {
14
- _inherits(Alias, _Node);
15
-
16
- var _super = _createSuper(Alias);
17
-
18
- function Alias() {
19
- _classCallCheck(this, Alias);
20
-
21
- return _super.apply(this, arguments);
22
- }
23
-
24
- _createClass(Alias, [{
25
- key: "parse",
26
-
27
- /**
28
- * Parses an *alias from the source
29
- *
30
- * @param {ParseContext} context
31
- * @param {number} start - Index of first character
32
- * @returns {number} - Index of the character after this scalar
33
- */
34
- value: function parse(context, start) {
35
- this.context = context;
36
- var src = context.src;
37
- var offset = Node.endOfIdentifier(src, start + 1);
38
- this.valueRange = new Range(start + 1, offset);
39
- offset = Node.endOfWhiteSpace(src, offset);
40
- offset = this.parseComment(offset);
41
- return offset;
42
- }
43
- }]);
44
-
45
- return Alias;
46
- }(Node);
@@ -1,52 +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 BlankLine = /*#__PURE__*/function (_Node) {
15
- _inherits(BlankLine, _Node);
16
-
17
- var _super = _createSuper(BlankLine);
18
-
19
- function BlankLine() {
20
- _classCallCheck(this, BlankLine);
21
-
22
- return _super.call(this, Type.BLANK_LINE);
23
- }
24
- /* istanbul ignore next */
25
-
26
-
27
- _createClass(BlankLine, [{
28
- key: "parse",
29
-
30
- /**
31
- * Parses a blank line from the source
32
- *
33
- * @param {ParseContext} context
34
- * @param {number} start - Index of first \n character
35
- * @returns {number} - Index of the character after this
36
- */
37
- value: function parse(context, start) {
38
- this.context = context;
39
- this.range = new Range(start, start + 1);
40
- return start + 1;
41
- }
42
- }, {
43
- key: "includesTrailingLines",
44
- get: function get() {
45
- // This is never called from anywhere, but if it were,
46
- // this is the value it should return.
47
- return true;
48
- }
49
- }]);
50
-
51
- return BlankLine;
52
- }(Node);
@@ -1,251 +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 { Node } from './Node';
14
- import { Range } from './Range';
15
- export var Chomp = {
16
- CLIP: 'CLIP',
17
- KEEP: 'KEEP',
18
- STRIP: 'STRIP'
19
- };
20
- export var BlockValue = /*#__PURE__*/function (_Node) {
21
- _inherits(BlockValue, _Node);
22
-
23
- var _super = _createSuper(BlockValue);
24
-
25
- function BlockValue(type, props) {
26
- var _this;
27
-
28
- _classCallCheck(this, BlockValue);
29
-
30
- _this = _super.call(this, type, props);
31
- _this.blockIndent = null;
32
- _this.chomping = Chomp.CLIP;
33
- _this.header = null;
34
- return _this;
35
- }
36
-
37
- _createClass(BlockValue, [{
38
- key: "parseBlockHeader",
39
- value: function parseBlockHeader(start) {
40
- var src = this.context.src;
41
- var offset = start + 1;
42
- var bi = '';
43
-
44
- while (true) {
45
- var ch = src[offset];
46
-
47
- switch (ch) {
48
- case '-':
49
- this.chomping = Chomp.STRIP;
50
- break;
51
-
52
- case '+':
53
- this.chomping = Chomp.KEEP;
54
- break;
55
-
56
- case '0':
57
- case '1':
58
- case '2':
59
- case '3':
60
- case '4':
61
- case '5':
62
- case '6':
63
- case '7':
64
- case '8':
65
- case '9':
66
- bi += ch;
67
- break;
68
-
69
- default:
70
- this.blockIndent = Number(bi) || null;
71
- this.header = new Range(start, offset);
72
- return offset;
73
- }
74
-
75
- offset += 1;
76
- }
77
- }
78
- }, {
79
- key: "parseBlockValue",
80
- value: function parseBlockValue(start) {
81
- var _this$context = this.context,
82
- indent = _this$context.indent,
83
- src = _this$context.src;
84
- var offset = start;
85
- var valueEnd = start;
86
- var bi = this.blockIndent ? indent + this.blockIndent - 1 : indent;
87
- var minBlockIndent = 1;
88
-
89
- for (var ch = src[offset]; ch === '\n'; ch = src[offset]) {
90
- offset += 1;
91
- if (Node.atDocumentBoundary(src, offset)) break;
92
- var end = Node.endOfBlockIndent(src, bi, offset); // should not include tab?
93
-
94
- if (end === null) break;
95
-
96
- if (!this.blockIndent) {
97
- // no explicit block indent, none yet detected
98
- var lineIndent = end - (offset + indent);
99
-
100
- if (src[end] !== '\n') {
101
- // first line with non-whitespace content
102
- if (lineIndent < minBlockIndent) {
103
- offset -= 1;
104
- break;
105
- }
106
-
107
- this.blockIndent = lineIndent;
108
- bi = indent + this.blockIndent - 1;
109
- } else if (lineIndent > minBlockIndent) {
110
- // empty line with more whitespace
111
- minBlockIndent = lineIndent;
112
- }
113
- }
114
-
115
- if (src[end] === '\n') {
116
- offset = end;
117
- } else {
118
- offset = valueEnd = Node.endOfLine(src, end);
119
- }
120
- }
121
-
122
- if (this.chomping !== Chomp.KEEP) {
123
- offset = src[valueEnd] ? valueEnd + 1 : valueEnd;
124
- }
125
-
126
- this.valueRange = new Range(start + 1, offset);
127
- return offset;
128
- }
129
- /**
130
- * Parses a block value from the source
131
- *
132
- * Accepted forms are:
133
- * ```
134
- * BS
135
- * block
136
- * lines
137
- *
138
- * BS #comment
139
- * block
140
- * lines
141
- * ```
142
- * where the block style BS matches the regexp `[|>][-+1-9]*` and block lines
143
- * are empty or have an indent level greater than `indent`.
144
- *
145
- * @param {ParseContext} context
146
- * @param {number} start - Index of first character
147
- * @returns {number} - Index of the character after this block
148
- */
149
-
150
- }, {
151
- key: "parse",
152
- value: function parse(context, start) {
153
- this.context = context;
154
- var src = context.src;
155
- var offset = this.parseBlockHeader(start);
156
- offset = Node.endOfWhiteSpace(src, offset);
157
- offset = this.parseComment(offset);
158
- offset = this.parseBlockValue(offset);
159
- return offset;
160
- }
161
- }, {
162
- key: "setOrigRanges",
163
- value: function setOrigRanges(cr, offset) {
164
- offset = _get(_getPrototypeOf(BlockValue.prototype), "setOrigRanges", this).call(this, cr, offset);
165
- return this.header ? this.header.setOrigRange(cr, offset) : offset;
166
- }
167
- }, {
168
- key: "includesTrailingLines",
169
- get: function get() {
170
- return this.chomping === Chomp.KEEP;
171
- }
172
- }, {
173
- key: "strValue",
174
- get: function get() {
175
- if (!this.valueRange || !this.context) return null;
176
- var _this$valueRange = this.valueRange,
177
- start = _this$valueRange.start,
178
- end = _this$valueRange.end;
179
- var _this$context2 = this.context,
180
- indent = _this$context2.indent,
181
- src = _this$context2.src;
182
- if (this.valueRange.isEmpty()) return '';
183
- var lastNewLine = null;
184
- var ch = src[end - 1];
185
-
186
- while (ch === '\n' || ch === '\t' || ch === ' ') {
187
- end -= 1;
188
-
189
- if (end <= start) {
190
- if (this.chomping === Chomp.KEEP) break;else return ''; // probably never happens
191
- }
192
-
193
- if (ch === '\n') lastNewLine = end;
194
- ch = src[end - 1];
195
- }
196
-
197
- var keepStart = end + 1;
198
-
199
- if (lastNewLine) {
200
- if (this.chomping === Chomp.KEEP) {
201
- keepStart = lastNewLine;
202
- end = this.valueRange.end;
203
- } else {
204
- end = lastNewLine;
205
- }
206
- }
207
-
208
- var bi = indent + this.blockIndent;
209
- var folded = this.type === Type.BLOCK_FOLDED;
210
- var atStart = true;
211
- var str = '';
212
- var sep = '';
213
- var prevMoreIndented = false;
214
-
215
- for (var i = start; i < end; ++i) {
216
- for (var j = 0; j < bi; ++j) {
217
- if (src[i] !== ' ') break;
218
- i += 1;
219
- }
220
-
221
- var _ch = src[i];
222
-
223
- if (_ch === '\n') {
224
- if (sep === '\n') str += '\n';else sep = '\n';
225
- } else {
226
- var lineEnd = Node.endOfLine(src, i);
227
- var line = src.slice(i, lineEnd);
228
- i = lineEnd;
229
-
230
- if (folded && (_ch === ' ' || _ch === '\t') && i < keepStart) {
231
- if (sep === ' ') sep = '\n';else if (!prevMoreIndented && !atStart && sep === '\n') sep = '\n\n';
232
- str += sep + line; //+ ((lineEnd < end && src[lineEnd]) || '')
233
-
234
- sep = lineEnd < end && src[lineEnd] || '';
235
- prevMoreIndented = true;
236
- } else {
237
- str += sep + line;
238
- sep = folded && i < keepStart ? ' ' : '\n';
239
- prevMoreIndented = false;
240
- }
241
-
242
- if (atStart && line !== '') atStart = false;
243
- }
244
- }
245
-
246
- return this.chomping === Chomp.STRIP ? str : str + '\n';
247
- }
248
- }]);
249
-
250
- return BlockValue;
251
- }(Node);
@@ -1,278 +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 { Type } from '../constants';
13
- import { BlankLine } from './BlankLine';
14
- import { CollectionItem } from './CollectionItem';
15
- import { Comment } from './Comment';
16
- import { Node } from './Node';
17
- import { Range } from './Range';
18
- export function grabCollectionEndComments(node) {
19
- var cnode = node;
20
-
21
- while (cnode instanceof CollectionItem) {
22
- cnode = cnode.node;
23
- }
24
-
25
- if (!(cnode instanceof Collection)) return null;
26
- var len = cnode.items.length;
27
- var ci = -1;
28
-
29
- for (var i = len - 1; i >= 0; --i) {
30
- var n = cnode.items[i];
31
-
32
- if (n.type === Type.COMMENT) {
33
- // Keep sufficiently indented comments with preceding node
34
- var _n$context = n.context,
35
- indent = _n$context.indent,
36
- lineStart = _n$context.lineStart;
37
- if (indent > 0 && n.range.start >= lineStart + indent) break;
38
- ci = i;
39
- } else if (n.type === Type.BLANK_LINE) ci = i;else break;
40
- }
41
-
42
- if (ci === -1) return null;
43
- var ca = cnode.items.splice(ci, len - ci);
44
- var prevEnd = ca[0].range.start;
45
-
46
- while (true) {
47
- cnode.range.end = prevEnd;
48
- if (cnode.valueRange && cnode.valueRange.end > prevEnd) cnode.valueRange.end = prevEnd;
49
- if (cnode === node) break;
50
- cnode = cnode.context.parent;
51
- }
52
-
53
- return ca;
54
- }
55
- export var Collection = /*#__PURE__*/function (_Node) {
56
- _inherits(Collection, _Node);
57
-
58
- var _super = _createSuper(Collection);
59
-
60
- _createClass(Collection, null, [{
61
- key: "nextContentHasIndent",
62
- value: function nextContentHasIndent(src, offset, indent) {
63
- var lineStart = Node.endOfLine(src, offset) + 1;
64
- offset = Node.endOfWhiteSpace(src, lineStart);
65
- var ch = src[offset];
66
- if (!ch) return false;
67
- if (offset >= lineStart + indent) return true;
68
- if (ch !== '#' && ch !== '\n') return false;
69
- return Collection.nextContentHasIndent(src, offset, indent);
70
- }
71
- }]);
72
-
73
- function Collection(firstItem) {
74
- var _this;
75
-
76
- _classCallCheck(this, Collection);
77
-
78
- _this = _super.call(this, firstItem.type === Type.SEQ_ITEM ? Type.SEQ : Type.MAP);
79
-
80
- for (var i = firstItem.props.length - 1; i >= 0; --i) {
81
- if (firstItem.props[i].start < firstItem.context.lineStart) {
82
- // props on previous line are assumed by the collection
83
- _this.props = firstItem.props.slice(0, i + 1);
84
- firstItem.props = firstItem.props.slice(i + 1);
85
- var itemRange = firstItem.props[0] || firstItem.valueRange;
86
- firstItem.range.start = itemRange.start;
87
- break;
88
- }
89
- }
90
-
91
- _this.items = [firstItem];
92
- var ec = grabCollectionEndComments(firstItem);
93
- if (ec) Array.prototype.push.apply(_this.items, ec);
94
- return _this;
95
- }
96
-
97
- _createClass(Collection, [{
98
- key: "parse",
99
-
100
- /**
101
- * @param {ParseContext} context
102
- * @param {number} start - Index of first character
103
- * @returns {number} - Index of the character after this
104
- */
105
- value: function parse(context, start) {
106
- this.context = context;
107
- var parseNode = context.parseNode,
108
- src = context.src; // It's easier to recalculate lineStart here rather than tracking down the
109
- // last context from which to read it -- eemeli/yaml#2
110
-
111
- var lineStart = Node.startOfLine(src, start);
112
- var firstItem = this.items[0]; // First-item context needs to be correct for later comment handling
113
- // -- eemeli/yaml#17
114
-
115
- firstItem.context.parent = this;
116
- this.valueRange = Range.copy(firstItem.valueRange);
117
- var indent = firstItem.range.start - firstItem.context.lineStart;
118
- var offset = start;
119
- offset = Node.normalizeOffset(src, offset);
120
- var ch = src[offset];
121
- var atLineStart = Node.endOfWhiteSpace(src, lineStart) === offset;
122
- var prevIncludesTrailingLines = false;
123
-
124
- while (ch) {
125
- while (ch === '\n' || ch === '#') {
126
- if (atLineStart && ch === '\n' && !prevIncludesTrailingLines) {
127
- var blankLine = new BlankLine();
128
- offset = blankLine.parse({
129
- src: src
130
- }, offset);
131
- this.valueRange.end = offset;
132
-
133
- if (offset >= src.length) {
134
- ch = null;
135
- break;
136
- }
137
-
138
- this.items.push(blankLine);
139
- offset -= 1; // blankLine.parse() consumes terminal newline
140
- } else if (ch === '#') {
141
- if (offset < lineStart + indent && !Collection.nextContentHasIndent(src, offset, indent)) {
142
- return offset;
143
- }
144
-
145
- var comment = new Comment();
146
- offset = comment.parse({
147
- indent: indent,
148
- lineStart: lineStart,
149
- src: src
150
- }, offset);
151
- this.items.push(comment);
152
- this.valueRange.end = offset;
153
-
154
- if (offset >= src.length) {
155
- ch = null;
156
- break;
157
- }
158
- }
159
-
160
- lineStart = offset + 1;
161
- offset = Node.endOfIndent(src, lineStart);
162
-
163
- if (Node.atBlank(src, offset)) {
164
- var wsEnd = Node.endOfWhiteSpace(src, offset);
165
- var next = src[wsEnd];
166
-
167
- if (!next || next === '\n' || next === '#') {
168
- offset = wsEnd;
169
- }
170
- }
171
-
172
- ch = src[offset];
173
- atLineStart = true;
174
- }
175
-
176
- if (!ch) {
177
- break;
178
- }
179
-
180
- if (offset !== lineStart + indent && (atLineStart || ch !== ':')) {
181
- if (lineStart > start) offset = lineStart;
182
- break;
183
- }
184
-
185
- if (firstItem.type === Type.SEQ_ITEM !== (ch === '-')) {
186
- var typeswitch = true;
187
-
188
- if (ch === '-') {
189
- // map key may start with -, as long as it's followed by a non-whitespace char
190
- var _next = src[offset + 1];
191
- typeswitch = !_next || _next === '\n' || _next === '\t' || _next === ' ';
192
- }
193
-
194
- if (typeswitch) {
195
- if (lineStart > start) offset = lineStart;
196
- break;
197
- }
198
- }
199
-
200
- var node = parseNode({
201
- atLineStart: atLineStart,
202
- inCollection: true,
203
- indent: indent,
204
- lineStart: lineStart,
205
- parent: this
206
- }, offset);
207
- if (!node) return offset; // at next document start
208
-
209
- this.items.push(node);
210
- this.valueRange.end = node.valueRange.end;
211
- offset = Node.normalizeOffset(src, node.range.end);
212
- ch = src[offset];
213
- atLineStart = false;
214
- prevIncludesTrailingLines = node.includesTrailingLines; // Need to reset lineStart and atLineStart here if preceding node's range
215
- // has advanced to check the current line's indentation level
216
- // -- eemeli/yaml#10 & eemeli/yaml#38
217
-
218
- if (ch) {
219
- var ls = offset - 1;
220
- var prev = src[ls];
221
-
222
- while (prev === ' ' || prev === '\t') {
223
- prev = src[--ls];
224
- }
225
-
226
- if (prev === '\n') {
227
- lineStart = ls + 1;
228
- atLineStart = true;
229
- }
230
- }
231
-
232
- var ec = grabCollectionEndComments(node);
233
- if (ec) Array.prototype.push.apply(this.items, ec);
234
- }
235
-
236
- return offset;
237
- }
238
- }, {
239
- key: "setOrigRanges",
240
- value: function setOrigRanges(cr, offset) {
241
- offset = _get(_getPrototypeOf(Collection.prototype), "setOrigRanges", this).call(this, cr, offset);
242
- this.items.forEach(function (node) {
243
- offset = node.setOrigRanges(cr, offset);
244
- });
245
- return offset;
246
- }
247
- }, {
248
- key: "toString",
249
- value: function toString() {
250
- var src = this.context.src,
251
- items = this.items,
252
- range = this.range,
253
- value = this.value;
254
- if (value != null) return value;
255
- var str = src.slice(range.start, items[0].range.start) + String(items[0]);
256
-
257
- for (var i = 1; i < items.length; ++i) {
258
- var item = items[i];
259
- var _item$context = item.context,
260
- atLineStart = _item$context.atLineStart,
261
- indent = _item$context.indent;
262
- if (atLineStart) for (var _i = 0; _i < indent; ++_i) {
263
- str += ' ';
264
- }
265
- str += String(item);
266
- }
267
-
268
- return Node.addStringTerminator(src, range.end, str);
269
- }
270
- }, {
271
- key: "includesTrailingLines",
272
- get: function get() {
273
- return this.items.length > 0;
274
- }
275
- }]);
276
-
277
- return Collection;
278
- }(Node);