cdk8s-operator 0.1.407 → 0.1.408
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/.jsii +3 -3
- package/lib/operator.js +1 -1
- package/lib/server.js +1 -1
- package/node_modules/yaml/browser/dist/PlainValue-183afbad.js +751 -0
- package/node_modules/yaml/browser/dist/Schema-9530c078.js +467 -0
- package/node_modules/yaml/browser/dist/index.js +436 -746
- package/node_modules/yaml/browser/dist/legacy-exports.js +3 -3
- package/node_modules/yaml/browser/dist/parse-cst.js +1290 -1689
- package/node_modules/yaml/browser/dist/resolveSeq-67caf78a.js +1835 -0
- package/node_modules/yaml/browser/dist/types.js +4 -4
- package/node_modules/yaml/browser/dist/util.js +2 -2
- package/node_modules/yaml/browser/dist/warnings-5e4358fe.js +348 -0
- package/node_modules/yaml/dist/{Document-9b4560a1.js → Document-a8d0fbf9.js} +11 -131
- package/node_modules/yaml/dist/{PlainValue-ec8e588e.js → PlainValue-516d5bc2.js} +35 -146
- package/node_modules/yaml/dist/{Schema-88e323a7.js → Schema-bcc6c2d7.js} +10 -66
- package/node_modules/yaml/dist/index.js +5 -17
- package/node_modules/yaml/dist/legacy-exports.js +3 -3
- package/node_modules/yaml/dist/parse-cst.js +45 -291
- package/node_modules/yaml/dist/{resolveSeq-d03cb037.js → resolveSeq-95613e94.js} +44 -346
- package/node_modules/yaml/dist/test-events.js +28 -44
- package/node_modules/yaml/dist/types.js +4 -4
- package/node_modules/yaml/dist/util.js +2 -2
- package/node_modules/yaml/dist/{warnings-1000a372.js → warnings-793925ce.js} +16 -73
- package/node_modules/yaml/package.json +2 -3
- package/package.json +2 -2
- package/node_modules/yaml/browser/dist/PlainValue-b8036b75.js +0 -1275
- package/node_modules/yaml/browser/dist/Schema-e94716c8.js +0 -682
- package/node_modules/yaml/browser/dist/resolveSeq-492ab440.js +0 -2419
- package/node_modules/yaml/browser/dist/warnings-df54cb69.js +0 -499
|
@@ -1,180 +1,139 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { N as Node, T as Type, R as Range, b as YAMLSemanticError, Y as YAMLSyntaxError, C as Char, _ as _defineProperty, P as PlainValue } from './PlainValue-183afbad.js';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var _super = _createSuper(BlankLine);
|
|
7
|
-
|
|
8
|
-
function BlankLine() {
|
|
9
|
-
_classCallCheck(this, BlankLine);
|
|
10
|
-
|
|
11
|
-
return _super.call(this, Type.BLANK_LINE);
|
|
3
|
+
class BlankLine extends Node {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(Type.BLANK_LINE);
|
|
12
6
|
}
|
|
13
|
-
/* istanbul ignore next */
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
_createClass(BlankLine, [{
|
|
17
|
-
key: "includesTrailingLines",
|
|
18
|
-
get: function get() {
|
|
19
|
-
// This is never called from anywhere, but if it were,
|
|
20
|
-
// this is the value it should return.
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Parses a blank line from the source
|
|
25
|
-
*
|
|
26
|
-
* @param {ParseContext} context
|
|
27
|
-
* @param {number} start - Index of first \n character
|
|
28
|
-
* @returns {number} - Index of the character after this
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
}, {
|
|
32
|
-
key: "parse",
|
|
33
|
-
value: function parse(context, start) {
|
|
34
|
-
this.context = context;
|
|
35
|
-
this.range = new Range(start, start + 1);
|
|
36
|
-
return start + 1;
|
|
37
|
-
}
|
|
38
|
-
}]);
|
|
39
|
-
|
|
40
|
-
return BlankLine;
|
|
41
|
-
}(Node);
|
|
42
|
-
|
|
43
|
-
var CollectionItem = /*#__PURE__*/function (_Node) {
|
|
44
|
-
_inherits(CollectionItem, _Node);
|
|
45
|
-
|
|
46
|
-
var _super = _createSuper(CollectionItem);
|
|
47
|
-
|
|
48
|
-
function CollectionItem(type, props) {
|
|
49
|
-
var _this;
|
|
50
|
-
|
|
51
|
-
_classCallCheck(this, CollectionItem);
|
|
52
7
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
8
|
+
/* istanbul ignore next */
|
|
9
|
+
get includesTrailingLines() {
|
|
10
|
+
// This is never called from anywhere, but if it were,
|
|
11
|
+
// this is the value it should return.
|
|
12
|
+
return true;
|
|
56
13
|
}
|
|
57
14
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
value: function parse(context, start) {
|
|
72
|
-
this.context = context;
|
|
73
|
-
var parseNode = context.parseNode,
|
|
74
|
-
src = context.src;
|
|
75
|
-
var atLineStart = context.atLineStart,
|
|
76
|
-
lineStart = context.lineStart;
|
|
77
|
-
if (!atLineStart && this.type === Type.SEQ_ITEM) this.error = new YAMLSemanticError(this, 'Sequence items must not have preceding content on the same line');
|
|
78
|
-
var indent = atLineStart ? start - lineStart : context.indent;
|
|
79
|
-
var offset = Node.endOfWhiteSpace(src, start + 1);
|
|
80
|
-
var ch = src[offset];
|
|
81
|
-
var inlineComment = ch === '#';
|
|
82
|
-
var comments = [];
|
|
83
|
-
var blankLine = null;
|
|
84
|
-
|
|
85
|
-
while (ch === '\n' || ch === '#') {
|
|
86
|
-
if (ch === '#') {
|
|
87
|
-
var _end = Node.endOfLine(src, offset + 1);
|
|
88
|
-
|
|
89
|
-
comments.push(new Range(offset, _end));
|
|
90
|
-
offset = _end;
|
|
91
|
-
} else {
|
|
92
|
-
atLineStart = true;
|
|
93
|
-
lineStart = offset + 1;
|
|
94
|
-
var wsEnd = Node.endOfWhiteSpace(src, lineStart);
|
|
95
|
-
|
|
96
|
-
if (src[wsEnd] === '\n' && comments.length === 0) {
|
|
97
|
-
blankLine = new BlankLine();
|
|
98
|
-
lineStart = blankLine.parse({
|
|
99
|
-
src: src
|
|
100
|
-
}, lineStart);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
offset = Node.endOfIndent(src, lineStart);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
ch = src[offset];
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (Node.nextNodeIsIndented(ch, offset - (lineStart + indent), this.type !== Type.SEQ_ITEM)) {
|
|
110
|
-
this.node = parseNode({
|
|
111
|
-
atLineStart: atLineStart,
|
|
112
|
-
inCollection: false,
|
|
113
|
-
indent: indent,
|
|
114
|
-
lineStart: lineStart,
|
|
115
|
-
parent: this
|
|
116
|
-
}, offset);
|
|
117
|
-
} else if (ch && lineStart > start + 1) {
|
|
118
|
-
offset = lineStart - 1;
|
|
119
|
-
}
|
|
15
|
+
/**
|
|
16
|
+
* Parses a blank line from the source
|
|
17
|
+
*
|
|
18
|
+
* @param {ParseContext} context
|
|
19
|
+
* @param {number} start - Index of first \n character
|
|
20
|
+
* @returns {number} - Index of the character after this
|
|
21
|
+
*/
|
|
22
|
+
parse(context, start) {
|
|
23
|
+
this.context = context;
|
|
24
|
+
this.range = new Range(start, start + 1);
|
|
25
|
+
return start + 1;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
120
28
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
29
|
+
class CollectionItem extends Node {
|
|
30
|
+
constructor(type, props) {
|
|
31
|
+
super(type, props);
|
|
32
|
+
this.node = null;
|
|
33
|
+
}
|
|
34
|
+
get includesTrailingLines() {
|
|
35
|
+
return !!this.node && this.node.includesTrailingLines;
|
|
36
|
+
}
|
|
129
37
|
|
|
130
|
-
|
|
131
|
-
|
|
38
|
+
/**
|
|
39
|
+
* @param {ParseContext} context
|
|
40
|
+
* @param {number} start - Index of first character
|
|
41
|
+
* @returns {number} - Index of the character after this
|
|
42
|
+
*/
|
|
43
|
+
parse(context, start) {
|
|
44
|
+
this.context = context;
|
|
45
|
+
const {
|
|
46
|
+
parseNode,
|
|
47
|
+
src
|
|
48
|
+
} = context;
|
|
49
|
+
let {
|
|
50
|
+
atLineStart,
|
|
51
|
+
lineStart
|
|
52
|
+
} = context;
|
|
53
|
+
if (!atLineStart && this.type === Type.SEQ_ITEM) this.error = new YAMLSemanticError(this, 'Sequence items must not have preceding content on the same line');
|
|
54
|
+
const indent = atLineStart ? start - lineStart : context.indent;
|
|
55
|
+
let offset = Node.endOfWhiteSpace(src, start + 1);
|
|
56
|
+
let ch = src[offset];
|
|
57
|
+
const inlineComment = ch === '#';
|
|
58
|
+
const comments = [];
|
|
59
|
+
let blankLine = null;
|
|
60
|
+
while (ch === '\n' || ch === '#') {
|
|
61
|
+
if (ch === '#') {
|
|
62
|
+
const end = Node.endOfLine(src, offset + 1);
|
|
63
|
+
comments.push(new Range(offset, end));
|
|
64
|
+
offset = end;
|
|
132
65
|
} else {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
66
|
+
atLineStart = true;
|
|
67
|
+
lineStart = offset + 1;
|
|
68
|
+
const wsEnd = Node.endOfWhiteSpace(src, lineStart);
|
|
69
|
+
if (src[wsEnd] === '\n' && comments.length === 0) {
|
|
70
|
+
blankLine = new BlankLine();
|
|
71
|
+
lineStart = blankLine.parse({
|
|
72
|
+
src
|
|
73
|
+
}, lineStart);
|
|
139
74
|
}
|
|
75
|
+
offset = Node.endOfIndent(src, lineStart);
|
|
140
76
|
}
|
|
141
|
-
|
|
142
|
-
var end = this.node ? this.node.valueRange.end : offset;
|
|
143
|
-
this.valueRange = new Range(start, end);
|
|
144
|
-
return offset;
|
|
77
|
+
ch = src[offset];
|
|
145
78
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
79
|
+
if (Node.nextNodeIsIndented(ch, offset - (lineStart + indent), this.type !== Type.SEQ_ITEM)) {
|
|
80
|
+
this.node = parseNode({
|
|
81
|
+
atLineStart,
|
|
82
|
+
inCollection: false,
|
|
83
|
+
indent,
|
|
84
|
+
lineStart,
|
|
85
|
+
parent: this
|
|
86
|
+
}, offset);
|
|
87
|
+
} else if (ch && lineStart > start + 1) {
|
|
88
|
+
offset = lineStart - 1;
|
|
151
89
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|
+
const items = context.parent.items || context.parent.contents;
|
|
96
|
+
if (items) items.push(blankLine);
|
|
97
|
+
}
|
|
98
|
+
if (comments.length) Array.prototype.push.apply(this.props, comments);
|
|
99
|
+
offset = this.node.range.end;
|
|
100
|
+
} else {
|
|
101
|
+
if (inlineComment) {
|
|
102
|
+
const c = comments[0];
|
|
103
|
+
this.props.push(c);
|
|
104
|
+
offset = c.end;
|
|
105
|
+
} else {
|
|
106
|
+
offset = Node.endOfLine(src, start + 1);
|
|
107
|
+
}
|
|
162
108
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
109
|
+
const end = this.node ? this.node.valueRange.end : offset;
|
|
110
|
+
this.valueRange = new Range(start, end);
|
|
111
|
+
return offset;
|
|
112
|
+
}
|
|
113
|
+
setOrigRanges(cr, offset) {
|
|
114
|
+
offset = super.setOrigRanges(cr, offset);
|
|
115
|
+
return this.node ? this.node.setOrigRanges(cr, offset) : offset;
|
|
116
|
+
}
|
|
117
|
+
toString() {
|
|
118
|
+
const {
|
|
119
|
+
context: {
|
|
120
|
+
src
|
|
121
|
+
},
|
|
122
|
+
node,
|
|
123
|
+
range,
|
|
124
|
+
value
|
|
125
|
+
} = this;
|
|
126
|
+
if (value != null) return value;
|
|
127
|
+
const str = node ? src.slice(range.start, node.range.start) + String(node) : src.slice(range.start, range.end);
|
|
128
|
+
return Node.addStringTerminator(src, range.end, str);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
175
131
|
|
|
176
|
-
|
|
132
|
+
class Comment extends Node {
|
|
133
|
+
constructor() {
|
|
134
|
+
super(Type.COMMENT);
|
|
177
135
|
}
|
|
136
|
+
|
|
178
137
|
/**
|
|
179
138
|
* Parses a comment line from the source
|
|
180
139
|
*
|
|
@@ -182,1478 +141,1166 @@ var Comment = /*#__PURE__*/function (_Node) {
|
|
|
182
141
|
* @param {number} start - Index of first character
|
|
183
142
|
* @returns {number} - Index of the character after this scalar
|
|
184
143
|
*/
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
this.context = context;
|
|
191
|
-
var offset = this.parseComment(start);
|
|
192
|
-
this.range = new Range(start, offset);
|
|
193
|
-
return offset;
|
|
194
|
-
}
|
|
195
|
-
}]);
|
|
196
|
-
|
|
197
|
-
return Comment;
|
|
198
|
-
}(Node);
|
|
199
|
-
|
|
200
|
-
function grabCollectionEndComments(node) {
|
|
201
|
-
var cnode = node;
|
|
202
|
-
|
|
203
|
-
while (cnode instanceof CollectionItem) {
|
|
204
|
-
cnode = cnode.node;
|
|
144
|
+
parse(context, start) {
|
|
145
|
+
this.context = context;
|
|
146
|
+
const offset = this.parseComment(start);
|
|
147
|
+
this.range = new Range(start, offset);
|
|
148
|
+
return offset;
|
|
205
149
|
}
|
|
150
|
+
}
|
|
206
151
|
|
|
152
|
+
function grabCollectionEndComments(node) {
|
|
153
|
+
let cnode = node;
|
|
154
|
+
while (cnode instanceof CollectionItem) cnode = cnode.node;
|
|
207
155
|
if (!(cnode instanceof Collection)) return null;
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
var n = cnode.items[i];
|
|
213
|
-
|
|
156
|
+
const len = cnode.items.length;
|
|
157
|
+
let ci = -1;
|
|
158
|
+
for (let i = len - 1; i >= 0; --i) {
|
|
159
|
+
const n = cnode.items[i];
|
|
214
160
|
if (n.type === Type.COMMENT) {
|
|
215
161
|
// Keep sufficiently indented comments with preceding node
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
162
|
+
const {
|
|
163
|
+
indent,
|
|
164
|
+
lineStart
|
|
165
|
+
} = n.context;
|
|
219
166
|
if (indent > 0 && n.range.start >= lineStart + indent) break;
|
|
220
167
|
ci = i;
|
|
221
168
|
} else if (n.type === Type.BLANK_LINE) ci = i;else break;
|
|
222
169
|
}
|
|
223
|
-
|
|
224
170
|
if (ci === -1) return null;
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
171
|
+
const ca = cnode.items.splice(ci, len - ci);
|
|
172
|
+
const prevEnd = ca[0].range.start;
|
|
228
173
|
while (true) {
|
|
229
174
|
cnode.range.end = prevEnd;
|
|
230
175
|
if (cnode.valueRange && cnode.valueRange.end > prevEnd) cnode.valueRange.end = prevEnd;
|
|
231
176
|
if (cnode === node) break;
|
|
232
177
|
cnode = cnode.context.parent;
|
|
233
178
|
}
|
|
234
|
-
|
|
235
179
|
return ca;
|
|
236
180
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
for (
|
|
181
|
+
class Collection extends Node {
|
|
182
|
+
static nextContentHasIndent(src, offset, indent) {
|
|
183
|
+
const lineStart = Node.endOfLine(src, offset) + 1;
|
|
184
|
+
offset = Node.endOfWhiteSpace(src, lineStart);
|
|
185
|
+
const ch = src[offset];
|
|
186
|
+
if (!ch) return false;
|
|
187
|
+
if (offset >= lineStart + indent) return true;
|
|
188
|
+
if (ch !== '#' && ch !== '\n') return false;
|
|
189
|
+
return Collection.nextContentHasIndent(src, offset, indent);
|
|
190
|
+
}
|
|
191
|
+
constructor(firstItem) {
|
|
192
|
+
super(firstItem.type === Type.SEQ_ITEM ? Type.SEQ : Type.MAP);
|
|
193
|
+
for (let i = firstItem.props.length - 1; i >= 0; --i) {
|
|
250
194
|
if (firstItem.props[i].start < firstItem.context.lineStart) {
|
|
251
195
|
// props on previous line are assumed by the collection
|
|
252
|
-
|
|
196
|
+
this.props = firstItem.props.slice(0, i + 1);
|
|
253
197
|
firstItem.props = firstItem.props.slice(i + 1);
|
|
254
|
-
|
|
198
|
+
const itemRange = firstItem.props[0] || firstItem.valueRange;
|
|
255
199
|
firstItem.range.start = itemRange.start;
|
|
256
200
|
break;
|
|
257
201
|
}
|
|
258
202
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
203
|
+
this.items = [firstItem];
|
|
204
|
+
const ec = grabCollectionEndComments(firstItem);
|
|
205
|
+
if (ec) Array.prototype.push.apply(this.items, ec);
|
|
206
|
+
}
|
|
207
|
+
get includesTrailingLines() {
|
|
208
|
+
return this.items.length > 0;
|
|
264
209
|
}
|
|
265
210
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
offset = blankLine.parse({
|
|
303
|
-
src: src
|
|
304
|
-
}, offset);
|
|
305
|
-
this.valueRange.end = offset;
|
|
306
|
-
|
|
307
|
-
if (offset >= src.length) {
|
|
308
|
-
ch = null;
|
|
309
|
-
break;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
this.items.push(blankLine);
|
|
313
|
-
offset -= 1; // blankLine.parse() consumes terminal newline
|
|
314
|
-
} else if (ch === '#') {
|
|
315
|
-
if (offset < lineStart + indent && !Collection.nextContentHasIndent(src, offset, indent)) {
|
|
316
|
-
return offset;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
var comment = new Comment();
|
|
320
|
-
offset = comment.parse({
|
|
321
|
-
indent: indent,
|
|
322
|
-
lineStart: lineStart,
|
|
323
|
-
src: src
|
|
324
|
-
}, offset);
|
|
325
|
-
this.items.push(comment);
|
|
326
|
-
this.valueRange.end = offset;
|
|
327
|
-
|
|
328
|
-
if (offset >= src.length) {
|
|
329
|
-
ch = null;
|
|
330
|
-
break;
|
|
331
|
-
}
|
|
211
|
+
/**
|
|
212
|
+
* @param {ParseContext} context
|
|
213
|
+
* @param {number} start - Index of first character
|
|
214
|
+
* @returns {number} - Index of the character after this
|
|
215
|
+
*/
|
|
216
|
+
parse(context, start) {
|
|
217
|
+
this.context = context;
|
|
218
|
+
const {
|
|
219
|
+
parseNode,
|
|
220
|
+
src
|
|
221
|
+
} = context;
|
|
222
|
+
// It's easier to recalculate lineStart here rather than tracking down the
|
|
223
|
+
// last context from which to read it -- eemeli/yaml#2
|
|
224
|
+
let lineStart = Node.startOfLine(src, start);
|
|
225
|
+
const firstItem = this.items[0];
|
|
226
|
+
// First-item context needs to be correct for later comment handling
|
|
227
|
+
// -- eemeli/yaml#17
|
|
228
|
+
firstItem.context.parent = this;
|
|
229
|
+
this.valueRange = Range.copy(firstItem.valueRange);
|
|
230
|
+
const indent = firstItem.range.start - firstItem.context.lineStart;
|
|
231
|
+
let offset = start;
|
|
232
|
+
offset = Node.normalizeOffset(src, offset);
|
|
233
|
+
let ch = src[offset];
|
|
234
|
+
let atLineStart = Node.endOfWhiteSpace(src, lineStart) === offset;
|
|
235
|
+
let prevIncludesTrailingLines = false;
|
|
236
|
+
while (ch) {
|
|
237
|
+
while (ch === '\n' || ch === '#') {
|
|
238
|
+
if (atLineStart && ch === '\n' && !prevIncludesTrailingLines) {
|
|
239
|
+
const blankLine = new BlankLine();
|
|
240
|
+
offset = blankLine.parse({
|
|
241
|
+
src
|
|
242
|
+
}, offset);
|
|
243
|
+
this.valueRange.end = offset;
|
|
244
|
+
if (offset >= src.length) {
|
|
245
|
+
ch = null;
|
|
246
|
+
break;
|
|
332
247
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
var wsEnd = Node.endOfWhiteSpace(src, offset);
|
|
339
|
-
var next = src[wsEnd];
|
|
340
|
-
|
|
341
|
-
if (!next || next === '\n' || next === '#') {
|
|
342
|
-
offset = wsEnd;
|
|
343
|
-
}
|
|
248
|
+
this.items.push(blankLine);
|
|
249
|
+
offset -= 1; // blankLine.parse() consumes terminal newline
|
|
250
|
+
} else if (ch === '#') {
|
|
251
|
+
if (offset < lineStart + indent && !Collection.nextContentHasIndent(src, offset, indent)) {
|
|
252
|
+
return offset;
|
|
344
253
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
if (offset < lineStart + indent) {
|
|
356
|
-
if (lineStart > start) offset = lineStart;
|
|
254
|
+
const comment = new Comment();
|
|
255
|
+
offset = comment.parse({
|
|
256
|
+
indent,
|
|
257
|
+
lineStart,
|
|
258
|
+
src
|
|
259
|
+
}, offset);
|
|
260
|
+
this.items.push(comment);
|
|
261
|
+
this.valueRange.end = offset;
|
|
262
|
+
if (offset >= src.length) {
|
|
263
|
+
ch = null;
|
|
357
264
|
break;
|
|
358
|
-
} else if (!this.error) {
|
|
359
|
-
var msg = 'All collection items must start at the same column';
|
|
360
|
-
this.error = new YAMLSyntaxError(this, msg);
|
|
361
265
|
}
|
|
362
266
|
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
// map key may start with -, as long as it's followed by a non-whitespace char
|
|
371
|
-
var _next = src[offset + 1];
|
|
372
|
-
|
|
373
|
-
if (!_next || _next === '\n' || _next === '\t' || _next === ' ') {
|
|
374
|
-
var _msg = 'A collection cannot be both a mapping and a sequence';
|
|
375
|
-
this.error = new YAMLSyntaxError(this, _msg);
|
|
267
|
+
lineStart = offset + 1;
|
|
268
|
+
offset = Node.endOfIndent(src, lineStart);
|
|
269
|
+
if (Node.atBlank(src, offset)) {
|
|
270
|
+
const wsEnd = Node.endOfWhiteSpace(src, offset);
|
|
271
|
+
const next = src[wsEnd];
|
|
272
|
+
if (!next || next === '\n' || next === '#') {
|
|
273
|
+
offset = wsEnd;
|
|
376
274
|
}
|
|
377
275
|
}
|
|
378
|
-
|
|
379
|
-
var node = parseNode({
|
|
380
|
-
atLineStart: atLineStart,
|
|
381
|
-
inCollection: true,
|
|
382
|
-
indent: indent,
|
|
383
|
-
lineStart: lineStart,
|
|
384
|
-
parent: this
|
|
385
|
-
}, offset);
|
|
386
|
-
if (!node) return offset; // at next document start
|
|
387
|
-
|
|
388
|
-
this.items.push(node);
|
|
389
|
-
this.valueRange.end = node.valueRange.end;
|
|
390
|
-
offset = Node.normalizeOffset(src, node.range.end);
|
|
391
276
|
ch = src[offset];
|
|
392
|
-
atLineStart =
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
if (prev === '\n') {
|
|
406
|
-
lineStart = ls + 1;
|
|
407
|
-
atLineStart = true;
|
|
408
|
-
}
|
|
277
|
+
atLineStart = true;
|
|
278
|
+
}
|
|
279
|
+
if (!ch) {
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
if (offset !== lineStart + indent && (atLineStart || ch !== ':')) {
|
|
283
|
+
if (offset < lineStart + indent) {
|
|
284
|
+
if (lineStart > start) offset = lineStart;
|
|
285
|
+
break;
|
|
286
|
+
} else if (!this.error) {
|
|
287
|
+
const msg = 'All collection items must start at the same column';
|
|
288
|
+
this.error = new YAMLSyntaxError(this, msg);
|
|
409
289
|
}
|
|
410
|
-
|
|
411
|
-
var ec = grabCollectionEndComments(node);
|
|
412
|
-
if (ec) Array.prototype.push.apply(this.items, ec);
|
|
413
290
|
}
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
}
|
|
426
|
-
}, {
|
|
427
|
-
key: "toString",
|
|
428
|
-
value: function toString() {
|
|
429
|
-
var src = this.context.src,
|
|
430
|
-
items = this.items,
|
|
431
|
-
range = this.range,
|
|
432
|
-
value = this.value;
|
|
433
|
-
if (value != null) return value;
|
|
434
|
-
var str = src.slice(range.start, items[0].range.start) + String(items[0]);
|
|
435
|
-
|
|
436
|
-
for (var i = 1; i < items.length; ++i) {
|
|
437
|
-
var item = items[i];
|
|
438
|
-
var _item$context = item.context,
|
|
439
|
-
atLineStart = _item$context.atLineStart,
|
|
440
|
-
indent = _item$context.indent;
|
|
441
|
-
if (atLineStart) for (var _i = 0; _i < indent; ++_i) {
|
|
442
|
-
str += ' ';
|
|
291
|
+
if (firstItem.type === Type.SEQ_ITEM) {
|
|
292
|
+
if (ch !== '-') {
|
|
293
|
+
if (lineStart > start) offset = lineStart;
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
} else if (ch === '-' && !this.error) {
|
|
297
|
+
// map key may start with -, as long as it's followed by a non-whitespace char
|
|
298
|
+
const next = src[offset + 1];
|
|
299
|
+
if (!next || next === '\n' || next === '\t' || next === ' ') {
|
|
300
|
+
const msg = 'A collection cannot be both a mapping and a sequence';
|
|
301
|
+
this.error = new YAMLSyntaxError(this, msg);
|
|
443
302
|
}
|
|
444
|
-
str += String(item);
|
|
445
303
|
}
|
|
446
|
-
|
|
447
|
-
|
|
304
|
+
const node = parseNode({
|
|
305
|
+
atLineStart,
|
|
306
|
+
inCollection: true,
|
|
307
|
+
indent,
|
|
308
|
+
lineStart,
|
|
309
|
+
parent: this
|
|
310
|
+
}, offset);
|
|
311
|
+
if (!node) return offset; // at next document start
|
|
312
|
+
this.items.push(node);
|
|
313
|
+
this.valueRange.end = node.valueRange.end;
|
|
314
|
+
offset = Node.normalizeOffset(src, node.range.end);
|
|
315
|
+
ch = src[offset];
|
|
316
|
+
atLineStart = false;
|
|
317
|
+
prevIncludesTrailingLines = node.includesTrailingLines;
|
|
318
|
+
// Need to reset lineStart and atLineStart here if preceding node's range
|
|
319
|
+
// has advanced to check the current line's indentation level
|
|
320
|
+
// -- eemeli/yaml#10 & eemeli/yaml#38
|
|
321
|
+
if (ch) {
|
|
322
|
+
let ls = offset - 1;
|
|
323
|
+
let prev = src[ls];
|
|
324
|
+
while (prev === ' ' || prev === '\t') prev = src[--ls];
|
|
325
|
+
if (prev === '\n') {
|
|
326
|
+
lineStart = ls + 1;
|
|
327
|
+
atLineStart = true;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
const ec = grabCollectionEndComments(node);
|
|
331
|
+
if (ec) Array.prototype.push.apply(this.items, ec);
|
|
448
332
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
333
|
+
return offset;
|
|
334
|
+
}
|
|
335
|
+
setOrigRanges(cr, offset) {
|
|
336
|
+
offset = super.setOrigRanges(cr, offset);
|
|
337
|
+
this.items.forEach(node => {
|
|
338
|
+
offset = node.setOrigRanges(cr, offset);
|
|
339
|
+
});
|
|
340
|
+
return offset;
|
|
341
|
+
}
|
|
342
|
+
toString() {
|
|
343
|
+
const {
|
|
344
|
+
context: {
|
|
345
|
+
src
|
|
346
|
+
},
|
|
347
|
+
items,
|
|
348
|
+
range,
|
|
349
|
+
value
|
|
350
|
+
} = this;
|
|
351
|
+
if (value != null) return value;
|
|
352
|
+
let str = src.slice(range.start, items[0].range.start) + String(items[0]);
|
|
353
|
+
for (let i = 1; i < items.length; ++i) {
|
|
354
|
+
const item = items[i];
|
|
355
|
+
const {
|
|
356
|
+
atLineStart,
|
|
357
|
+
indent
|
|
358
|
+
} = item.context;
|
|
359
|
+
if (atLineStart) for (let i = 0; i < indent; ++i) str += ' ';
|
|
360
|
+
str += String(item);
|
|
459
361
|
}
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
return Collection;
|
|
463
|
-
}(Node);
|
|
464
|
-
|
|
465
|
-
var Directive = /*#__PURE__*/function (_Node) {
|
|
466
|
-
_inherits(Directive, _Node);
|
|
467
|
-
|
|
468
|
-
var _super = _createSuper(Directive);
|
|
469
|
-
|
|
470
|
-
function Directive() {
|
|
471
|
-
var _this;
|
|
472
|
-
|
|
473
|
-
_classCallCheck(this, Directive);
|
|
474
|
-
|
|
475
|
-
_this = _super.call(this, Type.DIRECTIVE);
|
|
476
|
-
_this.name = null;
|
|
477
|
-
return _this;
|
|
362
|
+
return Node.addStringTerminator(src, range.end, str);
|
|
478
363
|
}
|
|
364
|
+
}
|
|
479
365
|
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
366
|
+
class Directive extends Node {
|
|
367
|
+
constructor() {
|
|
368
|
+
super(Type.DIRECTIVE);
|
|
369
|
+
this.name = null;
|
|
370
|
+
}
|
|
371
|
+
get parameters() {
|
|
372
|
+
const raw = this.rawValue;
|
|
373
|
+
return raw ? raw.trim().split(/[ \t]+/) : [];
|
|
374
|
+
}
|
|
375
|
+
parseName(start) {
|
|
376
|
+
const {
|
|
377
|
+
src
|
|
378
|
+
} = this.context;
|
|
379
|
+
let offset = start;
|
|
380
|
+
let ch = src[offset];
|
|
381
|
+
while (ch && ch !== '\n' && ch !== '\t' && ch !== ' ') ch = src[offset += 1];
|
|
382
|
+
this.name = src.slice(start, offset);
|
|
383
|
+
return offset;
|
|
384
|
+
}
|
|
385
|
+
parseParameters(start) {
|
|
386
|
+
const {
|
|
387
|
+
src
|
|
388
|
+
} = this.context;
|
|
389
|
+
let offset = start;
|
|
390
|
+
let ch = src[offset];
|
|
391
|
+
while (ch && ch !== '\n' && ch !== '#') ch = src[offset += 1];
|
|
392
|
+
this.valueRange = new Range(start, offset);
|
|
393
|
+
return offset;
|
|
394
|
+
}
|
|
395
|
+
parse(context, start) {
|
|
396
|
+
this.context = context;
|
|
397
|
+
let offset = this.parseName(start + 1);
|
|
398
|
+
offset = this.parseParameters(offset);
|
|
399
|
+
offset = this.parseComment(offset);
|
|
400
|
+
this.range = new Range(start, offset);
|
|
401
|
+
return offset;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
492
404
|
|
|
493
|
-
|
|
494
|
-
|
|
405
|
+
class Document extends Node {
|
|
406
|
+
static startCommentOrEndBlankLine(src, start) {
|
|
407
|
+
const offset = Node.endOfWhiteSpace(src, start);
|
|
408
|
+
const ch = src[offset];
|
|
409
|
+
return ch === '#' || ch === '\n' ? offset : start;
|
|
410
|
+
}
|
|
411
|
+
constructor() {
|
|
412
|
+
super(Type.DOCUMENT);
|
|
413
|
+
this.directives = null;
|
|
414
|
+
this.contents = null;
|
|
415
|
+
this.directivesEndMarker = null;
|
|
416
|
+
this.documentEndMarker = null;
|
|
417
|
+
}
|
|
418
|
+
parseDirectives(start) {
|
|
419
|
+
const {
|
|
420
|
+
src
|
|
421
|
+
} = this.context;
|
|
422
|
+
this.directives = [];
|
|
423
|
+
let atLineStart = true;
|
|
424
|
+
let hasDirectives = false;
|
|
425
|
+
let offset = start;
|
|
426
|
+
while (!Node.atDocumentBoundary(src, offset, Char.DIRECTIVES_END)) {
|
|
427
|
+
offset = Document.startCommentOrEndBlankLine(src, offset);
|
|
428
|
+
switch (src[offset]) {
|
|
429
|
+
case '\n':
|
|
430
|
+
if (atLineStart) {
|
|
431
|
+
const blankLine = new BlankLine();
|
|
432
|
+
offset = blankLine.parse({
|
|
433
|
+
src
|
|
434
|
+
}, offset);
|
|
435
|
+
if (offset < src.length) {
|
|
436
|
+
this.directives.push(blankLine);
|
|
437
|
+
}
|
|
438
|
+
} else {
|
|
439
|
+
offset += 1;
|
|
440
|
+
atLineStart = true;
|
|
441
|
+
}
|
|
442
|
+
break;
|
|
443
|
+
case '#':
|
|
444
|
+
{
|
|
445
|
+
const comment = new Comment();
|
|
446
|
+
offset = comment.parse({
|
|
447
|
+
src
|
|
448
|
+
}, offset);
|
|
449
|
+
this.directives.push(comment);
|
|
450
|
+
atLineStart = false;
|
|
451
|
+
}
|
|
452
|
+
break;
|
|
453
|
+
case '%':
|
|
454
|
+
{
|
|
455
|
+
const directive = new Directive();
|
|
456
|
+
offset = directive.parse({
|
|
457
|
+
parent: this,
|
|
458
|
+
src
|
|
459
|
+
}, offset);
|
|
460
|
+
this.directives.push(directive);
|
|
461
|
+
hasDirectives = true;
|
|
462
|
+
atLineStart = false;
|
|
463
|
+
}
|
|
464
|
+
break;
|
|
465
|
+
default:
|
|
466
|
+
if (hasDirectives) {
|
|
467
|
+
this.error = new YAMLSemanticError(this, 'Missing directives-end indicator line');
|
|
468
|
+
} else if (this.directives.length > 0) {
|
|
469
|
+
this.contents = this.directives;
|
|
470
|
+
this.directives = [];
|
|
471
|
+
}
|
|
472
|
+
return offset;
|
|
495
473
|
}
|
|
496
|
-
|
|
497
|
-
this.name = src.slice(start, offset);
|
|
498
|
-
return offset;
|
|
499
474
|
}
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
var src = this.context.src;
|
|
504
|
-
var offset = start;
|
|
505
|
-
var ch = src[offset];
|
|
506
|
-
|
|
507
|
-
while (ch && ch !== '\n' && ch !== '#') {
|
|
508
|
-
ch = src[offset += 1];
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
this.valueRange = new Range(start, offset);
|
|
512
|
-
return offset;
|
|
475
|
+
if (src[offset]) {
|
|
476
|
+
this.directivesEndMarker = new Range(offset, offset + 3);
|
|
477
|
+
return offset + 3;
|
|
513
478
|
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
this.
|
|
518
|
-
|
|
519
|
-
offset = this.parseParameters(offset);
|
|
520
|
-
offset = this.parseComment(offset);
|
|
521
|
-
this.range = new Range(start, offset);
|
|
522
|
-
return offset;
|
|
479
|
+
if (hasDirectives) {
|
|
480
|
+
this.error = new YAMLSemanticError(this, 'Missing directives-end indicator line');
|
|
481
|
+
} else if (this.directives.length > 0) {
|
|
482
|
+
this.contents = this.directives;
|
|
483
|
+
this.directives = [];
|
|
523
484
|
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
return Directive;
|
|
527
|
-
}(Node);
|
|
528
|
-
|
|
529
|
-
var Document = /*#__PURE__*/function (_Node) {
|
|
530
|
-
_inherits(Document, _Node);
|
|
531
|
-
|
|
532
|
-
var _super = _createSuper(Document);
|
|
533
|
-
|
|
534
|
-
function Document() {
|
|
535
|
-
var _this;
|
|
536
|
-
|
|
537
|
-
_classCallCheck(this, Document);
|
|
538
|
-
|
|
539
|
-
_this = _super.call(this, Type.DOCUMENT);
|
|
540
|
-
_this.directives = null;
|
|
541
|
-
_this.contents = null;
|
|
542
|
-
_this.directivesEndMarker = null;
|
|
543
|
-
_this.documentEndMarker = null;
|
|
544
|
-
return _this;
|
|
485
|
+
return offset;
|
|
545
486
|
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
if (offset < src.length) {
|
|
568
|
-
this.directives.push(blankLine);
|
|
569
|
-
}
|
|
570
|
-
} else {
|
|
571
|
-
offset += 1;
|
|
572
|
-
atLineStart = true;
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
break;
|
|
576
|
-
|
|
577
|
-
case '#':
|
|
578
|
-
{
|
|
579
|
-
var comment = new Comment();
|
|
580
|
-
offset = comment.parse({
|
|
581
|
-
src: src
|
|
582
|
-
}, offset);
|
|
583
|
-
this.directives.push(comment);
|
|
584
|
-
atLineStart = false;
|
|
585
|
-
}
|
|
586
|
-
break;
|
|
587
|
-
|
|
588
|
-
case '%':
|
|
589
|
-
{
|
|
590
|
-
var directive = new Directive();
|
|
591
|
-
offset = directive.parse({
|
|
592
|
-
parent: this,
|
|
593
|
-
src: src
|
|
594
|
-
}, offset);
|
|
595
|
-
this.directives.push(directive);
|
|
596
|
-
hasDirectives = true;
|
|
597
|
-
atLineStart = false;
|
|
598
|
-
}
|
|
599
|
-
break;
|
|
600
|
-
|
|
601
|
-
default:
|
|
602
|
-
if (hasDirectives) {
|
|
603
|
-
this.error = new YAMLSemanticError(this, 'Missing directives-end indicator line');
|
|
604
|
-
} else if (this.directives.length > 0) {
|
|
605
|
-
this.contents = this.directives;
|
|
606
|
-
this.directives = [];
|
|
487
|
+
parseContents(start) {
|
|
488
|
+
const {
|
|
489
|
+
parseNode,
|
|
490
|
+
src
|
|
491
|
+
} = this.context;
|
|
492
|
+
if (!this.contents) this.contents = [];
|
|
493
|
+
let lineStart = start;
|
|
494
|
+
while (src[lineStart - 1] === '-') lineStart -= 1;
|
|
495
|
+
let offset = Node.endOfWhiteSpace(src, start);
|
|
496
|
+
let atLineStart = lineStart === start;
|
|
497
|
+
this.valueRange = new Range(offset);
|
|
498
|
+
while (!Node.atDocumentBoundary(src, offset, Char.DOCUMENT_END)) {
|
|
499
|
+
switch (src[offset]) {
|
|
500
|
+
case '\n':
|
|
501
|
+
if (atLineStart) {
|
|
502
|
+
const blankLine = new BlankLine();
|
|
503
|
+
offset = blankLine.parse({
|
|
504
|
+
src
|
|
505
|
+
}, offset);
|
|
506
|
+
if (offset < src.length) {
|
|
507
|
+
this.contents.push(blankLine);
|
|
607
508
|
}
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
509
|
+
} else {
|
|
510
|
+
offset += 1;
|
|
511
|
+
atLineStart = true;
|
|
512
|
+
}
|
|
513
|
+
lineStart = offset;
|
|
514
|
+
break;
|
|
515
|
+
case '#':
|
|
516
|
+
{
|
|
517
|
+
const comment = new Comment();
|
|
518
|
+
offset = comment.parse({
|
|
519
|
+
src
|
|
520
|
+
}, offset);
|
|
521
|
+
this.contents.push(comment);
|
|
522
|
+
atLineStart = false;
|
|
523
|
+
}
|
|
524
|
+
break;
|
|
525
|
+
default:
|
|
526
|
+
{
|
|
527
|
+
const iEnd = Node.endOfIndent(src, offset);
|
|
528
|
+
const context = {
|
|
529
|
+
atLineStart,
|
|
530
|
+
indent: -1,
|
|
531
|
+
inFlow: false,
|
|
532
|
+
inCollection: false,
|
|
533
|
+
lineStart,
|
|
534
|
+
parent: this
|
|
535
|
+
};
|
|
536
|
+
const node = parseNode(context, iEnd);
|
|
537
|
+
if (!node) return this.valueRange.end = iEnd; // at next document start
|
|
538
|
+
this.contents.push(node);
|
|
539
|
+
offset = node.range.end;
|
|
540
|
+
atLineStart = false;
|
|
541
|
+
const ec = grabCollectionEndComments(node);
|
|
542
|
+
if (ec) Array.prototype.push.apply(this.contents, ec);
|
|
543
|
+
}
|
|
623
544
|
}
|
|
624
|
-
|
|
625
|
-
return offset;
|
|
545
|
+
offset = Document.startCommentOrEndBlankLine(src, offset);
|
|
626
546
|
}
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
var offset = Node.endOfWhiteSpace(src, start);
|
|
641
|
-
var atLineStart = lineStart === start;
|
|
642
|
-
this.valueRange = new Range(offset);
|
|
643
|
-
|
|
644
|
-
while (!Node.atDocumentBoundary(src, offset, Char.DOCUMENT_END)) {
|
|
547
|
+
this.valueRange.end = offset;
|
|
548
|
+
if (src[offset]) {
|
|
549
|
+
this.documentEndMarker = new Range(offset, offset + 3);
|
|
550
|
+
offset += 3;
|
|
551
|
+
if (src[offset]) {
|
|
552
|
+
offset = Node.endOfWhiteSpace(src, offset);
|
|
553
|
+
if (src[offset] === '#') {
|
|
554
|
+
const comment = new Comment();
|
|
555
|
+
offset = comment.parse({
|
|
556
|
+
src
|
|
557
|
+
}, offset);
|
|
558
|
+
this.contents.push(comment);
|
|
559
|
+
}
|
|
645
560
|
switch (src[offset]) {
|
|
646
561
|
case '\n':
|
|
647
|
-
|
|
648
|
-
var blankLine = new BlankLine();
|
|
649
|
-
offset = blankLine.parse({
|
|
650
|
-
src: src
|
|
651
|
-
}, offset);
|
|
652
|
-
|
|
653
|
-
if (offset < src.length) {
|
|
654
|
-
this.contents.push(blankLine);
|
|
655
|
-
}
|
|
656
|
-
} else {
|
|
657
|
-
offset += 1;
|
|
658
|
-
atLineStart = true;
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
lineStart = offset;
|
|
562
|
+
offset += 1;
|
|
662
563
|
break;
|
|
663
|
-
|
|
664
|
-
case '#':
|
|
665
|
-
{
|
|
666
|
-
var comment = new Comment();
|
|
667
|
-
offset = comment.parse({
|
|
668
|
-
src: src
|
|
669
|
-
}, offset);
|
|
670
|
-
this.contents.push(comment);
|
|
671
|
-
atLineStart = false;
|
|
672
|
-
}
|
|
564
|
+
case undefined:
|
|
673
565
|
break;
|
|
674
|
-
|
|
675
566
|
default:
|
|
676
|
-
|
|
677
|
-
var iEnd = Node.endOfIndent(src, offset);
|
|
678
|
-
var context = {
|
|
679
|
-
atLineStart: atLineStart,
|
|
680
|
-
indent: -1,
|
|
681
|
-
inFlow: false,
|
|
682
|
-
inCollection: false,
|
|
683
|
-
lineStart: lineStart,
|
|
684
|
-
parent: this
|
|
685
|
-
};
|
|
686
|
-
var node = parseNode(context, iEnd);
|
|
687
|
-
if (!node) return this.valueRange.end = iEnd; // at next document start
|
|
688
|
-
|
|
689
|
-
this.contents.push(node);
|
|
690
|
-
offset = node.range.end;
|
|
691
|
-
atLineStart = false;
|
|
692
|
-
var ec = grabCollectionEndComments(node);
|
|
693
|
-
if (ec) Array.prototype.push.apply(this.contents, ec);
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
offset = Document.startCommentOrEndBlankLine(src, offset);
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
this.valueRange.end = offset;
|
|
701
|
-
|
|
702
|
-
if (src[offset]) {
|
|
703
|
-
this.documentEndMarker = new Range(offset, offset + 3);
|
|
704
|
-
offset += 3;
|
|
705
|
-
|
|
706
|
-
if (src[offset]) {
|
|
707
|
-
offset = Node.endOfWhiteSpace(src, offset);
|
|
708
|
-
|
|
709
|
-
if (src[offset] === '#') {
|
|
710
|
-
var _comment = new Comment();
|
|
711
|
-
|
|
712
|
-
offset = _comment.parse({
|
|
713
|
-
src: src
|
|
714
|
-
}, offset);
|
|
715
|
-
this.contents.push(_comment);
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
switch (src[offset]) {
|
|
719
|
-
case '\n':
|
|
720
|
-
offset += 1;
|
|
721
|
-
break;
|
|
722
|
-
|
|
723
|
-
case undefined:
|
|
724
|
-
break;
|
|
725
|
-
|
|
726
|
-
default:
|
|
727
|
-
this.error = new YAMLSyntaxError(this, 'Document end marker line cannot have a non-comment suffix');
|
|
728
|
-
}
|
|
567
|
+
this.error = new YAMLSyntaxError(this, 'Document end marker line cannot have a non-comment suffix');
|
|
729
568
|
}
|
|
730
569
|
}
|
|
731
|
-
|
|
732
|
-
return offset;
|
|
733
|
-
}
|
|
734
|
-
/**
|
|
735
|
-
* @param {ParseContext} context
|
|
736
|
-
* @param {number} start - Index of first character
|
|
737
|
-
* @returns {number} - Index of the character after this
|
|
738
|
-
*/
|
|
739
|
-
|
|
740
|
-
}, {
|
|
741
|
-
key: "parse",
|
|
742
|
-
value: function parse(context, start) {
|
|
743
|
-
context.root = this;
|
|
744
|
-
this.context = context;
|
|
745
|
-
var src = context.src;
|
|
746
|
-
var offset = src.charCodeAt(start) === 0xfeff ? start + 1 : start; // skip BOM
|
|
747
|
-
|
|
748
|
-
offset = this.parseDirectives(offset);
|
|
749
|
-
offset = this.parseContents(offset);
|
|
750
|
-
return offset;
|
|
751
|
-
}
|
|
752
|
-
}, {
|
|
753
|
-
key: "setOrigRanges",
|
|
754
|
-
value: function setOrigRanges(cr, offset) {
|
|
755
|
-
offset = _get(_getPrototypeOf(Document.prototype), "setOrigRanges", this).call(this, cr, offset);
|
|
756
|
-
this.directives.forEach(function (node) {
|
|
757
|
-
offset = node.setOrigRanges(cr, offset);
|
|
758
|
-
});
|
|
759
|
-
if (this.directivesEndMarker) offset = this.directivesEndMarker.setOrigRange(cr, offset);
|
|
760
|
-
this.contents.forEach(function (node) {
|
|
761
|
-
offset = node.setOrigRanges(cr, offset);
|
|
762
|
-
});
|
|
763
|
-
if (this.documentEndMarker) offset = this.documentEndMarker.setOrigRange(cr, offset);
|
|
764
|
-
return offset;
|
|
765
|
-
}
|
|
766
|
-
}, {
|
|
767
|
-
key: "toString",
|
|
768
|
-
value: function toString() {
|
|
769
|
-
var contents = this.contents,
|
|
770
|
-
directives = this.directives,
|
|
771
|
-
value = this.value;
|
|
772
|
-
if (value != null) return value;
|
|
773
|
-
var str = directives.join('');
|
|
774
|
-
|
|
775
|
-
if (contents.length > 0) {
|
|
776
|
-
if (directives.length > 0 || contents[0].type === Type.COMMENT) str += '---\n';
|
|
777
|
-
str += contents.join('');
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
if (str[str.length - 1] !== '\n') str += '\n';
|
|
781
|
-
return str;
|
|
782
570
|
}
|
|
783
|
-
|
|
784
|
-
key: "startCommentOrEndBlankLine",
|
|
785
|
-
value: function startCommentOrEndBlankLine(src, start) {
|
|
786
|
-
var offset = Node.endOfWhiteSpace(src, start);
|
|
787
|
-
var ch = src[offset];
|
|
788
|
-
return ch === '#' || ch === '\n' ? offset : start;
|
|
789
|
-
}
|
|
790
|
-
}]);
|
|
791
|
-
|
|
792
|
-
return Document;
|
|
793
|
-
}(Node);
|
|
794
|
-
|
|
795
|
-
var Alias = /*#__PURE__*/function (_Node) {
|
|
796
|
-
_inherits(Alias, _Node);
|
|
797
|
-
|
|
798
|
-
var _super = _createSuper(Alias);
|
|
799
|
-
|
|
800
|
-
function Alias() {
|
|
801
|
-
_classCallCheck(this, Alias);
|
|
802
|
-
|
|
803
|
-
return _super.apply(this, arguments);
|
|
571
|
+
return offset;
|
|
804
572
|
}
|
|
805
573
|
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
574
|
+
/**
|
|
575
|
+
* @param {ParseContext} context
|
|
576
|
+
* @param {number} start - Index of first character
|
|
577
|
+
* @returns {number} - Index of the character after this
|
|
578
|
+
*/
|
|
579
|
+
parse(context, start) {
|
|
580
|
+
context.root = this;
|
|
581
|
+
this.context = context;
|
|
582
|
+
const {
|
|
583
|
+
src
|
|
584
|
+
} = context;
|
|
585
|
+
let offset = src.charCodeAt(start) === 0xfeff ? start + 1 : start; // skip BOM
|
|
586
|
+
offset = this.parseDirectives(offset);
|
|
587
|
+
offset = this.parseContents(offset);
|
|
588
|
+
return offset;
|
|
589
|
+
}
|
|
590
|
+
setOrigRanges(cr, offset) {
|
|
591
|
+
offset = super.setOrigRanges(cr, offset);
|
|
592
|
+
this.directives.forEach(node => {
|
|
593
|
+
offset = node.setOrigRanges(cr, offset);
|
|
594
|
+
});
|
|
595
|
+
if (this.directivesEndMarker) offset = this.directivesEndMarker.setOrigRange(cr, offset);
|
|
596
|
+
this.contents.forEach(node => {
|
|
597
|
+
offset = node.setOrigRanges(cr, offset);
|
|
598
|
+
});
|
|
599
|
+
if (this.documentEndMarker) offset = this.documentEndMarker.setOrigRange(cr, offset);
|
|
600
|
+
return offset;
|
|
601
|
+
}
|
|
602
|
+
toString() {
|
|
603
|
+
const {
|
|
604
|
+
contents,
|
|
605
|
+
directives,
|
|
606
|
+
value
|
|
607
|
+
} = this;
|
|
608
|
+
if (value != null) return value;
|
|
609
|
+
let str = directives.join('');
|
|
610
|
+
if (contents.length > 0) {
|
|
611
|
+
if (directives.length > 0 || contents[0].type === Type.COMMENT) str += '---\n';
|
|
612
|
+
str += contents.join('');
|
|
824
613
|
}
|
|
825
|
-
|
|
614
|
+
if (str[str.length - 1] !== '\n') str += '\n';
|
|
615
|
+
return str;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
826
618
|
|
|
827
|
-
|
|
828
|
-
|
|
619
|
+
class Alias extends Node {
|
|
620
|
+
/**
|
|
621
|
+
* Parses an *alias from the source
|
|
622
|
+
*
|
|
623
|
+
* @param {ParseContext} context
|
|
624
|
+
* @param {number} start - Index of first character
|
|
625
|
+
* @returns {number} - Index of the character after this scalar
|
|
626
|
+
*/
|
|
627
|
+
parse(context, start) {
|
|
628
|
+
this.context = context;
|
|
629
|
+
const {
|
|
630
|
+
src
|
|
631
|
+
} = context;
|
|
632
|
+
let offset = Node.endOfIdentifier(src, start + 1);
|
|
633
|
+
this.valueRange = new Range(start + 1, offset);
|
|
634
|
+
offset = Node.endOfWhiteSpace(src, offset);
|
|
635
|
+
offset = this.parseComment(offset);
|
|
636
|
+
return offset;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
829
639
|
|
|
830
|
-
|
|
640
|
+
const Chomp = {
|
|
831
641
|
CLIP: 'CLIP',
|
|
832
642
|
KEEP: 'KEEP',
|
|
833
643
|
STRIP: 'STRIP'
|
|
834
644
|
};
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
var _this;
|
|
842
|
-
|
|
843
|
-
_classCallCheck(this, BlockValue);
|
|
844
|
-
|
|
845
|
-
_this = _super.call(this, type, props);
|
|
846
|
-
_this.blockIndent = null;
|
|
847
|
-
_this.chomping = Chomp.CLIP;
|
|
848
|
-
_this.header = null;
|
|
849
|
-
return _this;
|
|
645
|
+
class BlockValue extends Node {
|
|
646
|
+
constructor(type, props) {
|
|
647
|
+
super(type, props);
|
|
648
|
+
this.blockIndent = null;
|
|
649
|
+
this.chomping = Chomp.CLIP;
|
|
650
|
+
this.header = null;
|
|
850
651
|
}
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
while (ch === '\n' || ch === '\t' || ch === ' ') {
|
|
872
|
-
end -= 1;
|
|
873
|
-
|
|
874
|
-
if (end <= start) {
|
|
875
|
-
if (this.chomping === Chomp.KEEP) break;else return ''; // probably never happens
|
|
876
|
-
}
|
|
877
|
-
|
|
878
|
-
if (ch === '\n') lastNewLine = end;
|
|
879
|
-
ch = src[end - 1];
|
|
880
|
-
}
|
|
881
|
-
|
|
882
|
-
var keepStart = end + 1;
|
|
883
|
-
|
|
884
|
-
if (lastNewLine) {
|
|
885
|
-
if (this.chomping === Chomp.KEEP) {
|
|
886
|
-
keepStart = lastNewLine;
|
|
887
|
-
end = this.valueRange.end;
|
|
888
|
-
} else {
|
|
889
|
-
end = lastNewLine;
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
|
|
893
|
-
var bi = indent + this.blockIndent;
|
|
894
|
-
var folded = this.type === Type.BLOCK_FOLDED;
|
|
895
|
-
var atStart = true;
|
|
896
|
-
var str = '';
|
|
897
|
-
var sep = '';
|
|
898
|
-
var prevMoreIndented = false;
|
|
899
|
-
|
|
900
|
-
for (var i = start; i < end; ++i) {
|
|
901
|
-
for (var j = 0; j < bi; ++j) {
|
|
902
|
-
if (src[i] !== ' ') break;
|
|
903
|
-
i += 1;
|
|
904
|
-
}
|
|
905
|
-
|
|
906
|
-
var _ch = src[i];
|
|
907
|
-
|
|
908
|
-
if (_ch === '\n') {
|
|
909
|
-
if (sep === '\n') str += '\n';else sep = '\n';
|
|
910
|
-
} else {
|
|
911
|
-
var lineEnd = Node.endOfLine(src, i);
|
|
912
|
-
var line = src.slice(i, lineEnd);
|
|
913
|
-
i = lineEnd;
|
|
914
|
-
|
|
915
|
-
if (folded && (_ch === ' ' || _ch === '\t') && i < keepStart) {
|
|
916
|
-
if (sep === ' ') sep = '\n';else if (!prevMoreIndented && !atStart && sep === '\n') sep = '\n\n';
|
|
917
|
-
str += sep + line; //+ ((lineEnd < end && src[lineEnd]) || '')
|
|
918
|
-
|
|
919
|
-
sep = lineEnd < end && src[lineEnd] || '';
|
|
920
|
-
prevMoreIndented = true;
|
|
921
|
-
} else {
|
|
922
|
-
str += sep + line;
|
|
923
|
-
sep = folded && i < keepStart ? ' ' : '\n';
|
|
924
|
-
prevMoreIndented = false;
|
|
925
|
-
}
|
|
926
|
-
|
|
927
|
-
if (atStart && line !== '') atStart = false;
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
|
|
931
|
-
return this.chomping === Chomp.STRIP ? str : str + '\n';
|
|
932
|
-
}
|
|
933
|
-
}, {
|
|
934
|
-
key: "parseBlockHeader",
|
|
935
|
-
value: function parseBlockHeader(start) {
|
|
936
|
-
var src = this.context.src;
|
|
937
|
-
var offset = start + 1;
|
|
938
|
-
var bi = '';
|
|
939
|
-
|
|
940
|
-
while (true) {
|
|
941
|
-
var ch = src[offset];
|
|
942
|
-
|
|
943
|
-
switch (ch) {
|
|
944
|
-
case '-':
|
|
945
|
-
this.chomping = Chomp.STRIP;
|
|
946
|
-
break;
|
|
947
|
-
|
|
948
|
-
case '+':
|
|
949
|
-
this.chomping = Chomp.KEEP;
|
|
950
|
-
break;
|
|
951
|
-
|
|
952
|
-
case '0':
|
|
953
|
-
case '1':
|
|
954
|
-
case '2':
|
|
955
|
-
case '3':
|
|
956
|
-
case '4':
|
|
957
|
-
case '5':
|
|
958
|
-
case '6':
|
|
959
|
-
case '7':
|
|
960
|
-
case '8':
|
|
961
|
-
case '9':
|
|
962
|
-
bi += ch;
|
|
963
|
-
break;
|
|
964
|
-
|
|
965
|
-
default:
|
|
966
|
-
this.blockIndent = Number(bi) || null;
|
|
967
|
-
this.header = new Range(start, offset);
|
|
968
|
-
return offset;
|
|
969
|
-
}
|
|
970
|
-
|
|
971
|
-
offset += 1;
|
|
652
|
+
get includesTrailingLines() {
|
|
653
|
+
return this.chomping === Chomp.KEEP;
|
|
654
|
+
}
|
|
655
|
+
get strValue() {
|
|
656
|
+
if (!this.valueRange || !this.context) return null;
|
|
657
|
+
let {
|
|
658
|
+
start,
|
|
659
|
+
end
|
|
660
|
+
} = this.valueRange;
|
|
661
|
+
const {
|
|
662
|
+
indent,
|
|
663
|
+
src
|
|
664
|
+
} = this.context;
|
|
665
|
+
if (this.valueRange.isEmpty()) return '';
|
|
666
|
+
let lastNewLine = null;
|
|
667
|
+
let ch = src[end - 1];
|
|
668
|
+
while (ch === '\n' || ch === '\t' || ch === ' ') {
|
|
669
|
+
end -= 1;
|
|
670
|
+
if (end <= start) {
|
|
671
|
+
if (this.chomping === Chomp.KEEP) break;else return ''; // probably never happens
|
|
972
672
|
}
|
|
673
|
+
if (ch === '\n') lastNewLine = end;
|
|
674
|
+
ch = src[end - 1];
|
|
973
675
|
}
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
var offset = start;
|
|
982
|
-
var valueEnd = start;
|
|
983
|
-
var minBlockIndent = 1;
|
|
984
|
-
|
|
985
|
-
for (var ch = src[offset]; ch === '\n'; ch = src[offset]) {
|
|
986
|
-
offset += 1;
|
|
987
|
-
if (Node.atDocumentBoundary(src, offset)) break;
|
|
988
|
-
var end = Node.endOfBlockIndent(src, indent, offset); // should not include tab?
|
|
989
|
-
|
|
990
|
-
if (end === null) break;
|
|
991
|
-
var _ch2 = src[end];
|
|
992
|
-
var lineIndent = end - (offset + indent);
|
|
993
|
-
|
|
994
|
-
if (!this.blockIndent) {
|
|
995
|
-
// no explicit block indent, none yet detected
|
|
996
|
-
if (src[end] !== '\n') {
|
|
997
|
-
// first line with non-whitespace content
|
|
998
|
-
if (lineIndent < minBlockIndent) {
|
|
999
|
-
var msg = 'Block scalars with more-indented leading empty lines must use an explicit indentation indicator';
|
|
1000
|
-
this.error = new YAMLSemanticError(this, msg);
|
|
1001
|
-
}
|
|
1002
|
-
|
|
1003
|
-
this.blockIndent = lineIndent;
|
|
1004
|
-
} else if (lineIndent > minBlockIndent) {
|
|
1005
|
-
// empty line with more whitespace
|
|
1006
|
-
minBlockIndent = lineIndent;
|
|
1007
|
-
}
|
|
1008
|
-
} else if (_ch2 && _ch2 !== '\n' && lineIndent < this.blockIndent) {
|
|
1009
|
-
if (src[end] === '#') break;
|
|
1010
|
-
|
|
1011
|
-
if (!this.error) {
|
|
1012
|
-
var _src = explicit ? 'explicit indentation indicator' : 'first line';
|
|
1013
|
-
|
|
1014
|
-
var _msg = "Block scalars must not be less indented than their ".concat(_src);
|
|
1015
|
-
|
|
1016
|
-
this.error = new YAMLSemanticError(this, _msg);
|
|
1017
|
-
}
|
|
1018
|
-
}
|
|
1019
|
-
|
|
1020
|
-
if (src[end] === '\n') {
|
|
1021
|
-
offset = end;
|
|
1022
|
-
} else {
|
|
1023
|
-
offset = valueEnd = Node.endOfLine(src, end);
|
|
1024
|
-
}
|
|
1025
|
-
}
|
|
1026
|
-
|
|
1027
|
-
if (this.chomping !== Chomp.KEEP) {
|
|
1028
|
-
offset = src[valueEnd] ? valueEnd + 1 : valueEnd;
|
|
676
|
+
let keepStart = end + 1;
|
|
677
|
+
if (lastNewLine) {
|
|
678
|
+
if (this.chomping === Chomp.KEEP) {
|
|
679
|
+
keepStart = lastNewLine;
|
|
680
|
+
end = this.valueRange.end;
|
|
681
|
+
} else {
|
|
682
|
+
end = lastNewLine;
|
|
1029
683
|
}
|
|
1030
|
-
|
|
1031
|
-
this.valueRange = new Range(start + 1, offset);
|
|
1032
|
-
return offset;
|
|
1033
|
-
}
|
|
1034
|
-
/**
|
|
1035
|
-
* Parses a block value from the source
|
|
1036
|
-
*
|
|
1037
|
-
* Accepted forms are:
|
|
1038
|
-
* ```
|
|
1039
|
-
* BS
|
|
1040
|
-
* block
|
|
1041
|
-
* lines
|
|
1042
|
-
*
|
|
1043
|
-
* BS #comment
|
|
1044
|
-
* block
|
|
1045
|
-
* lines
|
|
1046
|
-
* ```
|
|
1047
|
-
* where the block style BS matches the regexp `[|>][-+1-9]*` and block lines
|
|
1048
|
-
* are empty or have an indent level greater than `indent`.
|
|
1049
|
-
*
|
|
1050
|
-
* @param {ParseContext} context
|
|
1051
|
-
* @param {number} start - Index of first character
|
|
1052
|
-
* @returns {number} - Index of the character after this block
|
|
1053
|
-
*/
|
|
1054
|
-
|
|
1055
|
-
}, {
|
|
1056
|
-
key: "parse",
|
|
1057
|
-
value: function parse(context, start) {
|
|
1058
|
-
this.context = context;
|
|
1059
|
-
var src = context.src;
|
|
1060
|
-
var offset = this.parseBlockHeader(start);
|
|
1061
|
-
offset = Node.endOfWhiteSpace(src, offset);
|
|
1062
|
-
offset = this.parseComment(offset);
|
|
1063
|
-
offset = this.parseBlockValue(offset);
|
|
1064
|
-
return offset;
|
|
1065
|
-
}
|
|
1066
|
-
}, {
|
|
1067
|
-
key: "setOrigRanges",
|
|
1068
|
-
value: function setOrigRanges(cr, offset) {
|
|
1069
|
-
offset = _get(_getPrototypeOf(BlockValue.prototype), "setOrigRanges", this).call(this, cr, offset);
|
|
1070
|
-
return this.header ? this.header.setOrigRange(cr, offset) : offset;
|
|
1071
|
-
}
|
|
1072
|
-
}]);
|
|
1073
|
-
|
|
1074
|
-
return BlockValue;
|
|
1075
|
-
}(Node);
|
|
1076
|
-
|
|
1077
|
-
var FlowCollection = /*#__PURE__*/function (_Node) {
|
|
1078
|
-
_inherits(FlowCollection, _Node);
|
|
1079
|
-
|
|
1080
|
-
var _super = _createSuper(FlowCollection);
|
|
1081
|
-
|
|
1082
|
-
function FlowCollection(type, props) {
|
|
1083
|
-
var _this;
|
|
1084
|
-
|
|
1085
|
-
_classCallCheck(this, FlowCollection);
|
|
1086
|
-
|
|
1087
|
-
_this = _super.call(this, type, props);
|
|
1088
|
-
_this.items = null;
|
|
1089
|
-
return _this;
|
|
1090
|
-
}
|
|
1091
|
-
|
|
1092
|
-
_createClass(FlowCollection, [{
|
|
1093
|
-
key: "prevNodeIsJsonLike",
|
|
1094
|
-
value: function prevNodeIsJsonLike() {
|
|
1095
|
-
var idx = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.items.length;
|
|
1096
|
-
var node = this.items[idx - 1];
|
|
1097
|
-
return !!node && (node.jsonLike || node.type === Type.COMMENT && this.prevNodeIsJsonLike(idx - 1));
|
|
1098
684
|
}
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
var parseNode = context.parseNode,
|
|
1110
|
-
src = context.src;
|
|
1111
|
-
var indent = context.indent,
|
|
1112
|
-
lineStart = context.lineStart;
|
|
1113
|
-
var char = src[start]; // { or [
|
|
1114
|
-
|
|
1115
|
-
this.items = [{
|
|
1116
|
-
char: char,
|
|
1117
|
-
offset: start
|
|
1118
|
-
}];
|
|
1119
|
-
var offset = Node.endOfWhiteSpace(src, start + 1);
|
|
1120
|
-
char = src[offset];
|
|
1121
|
-
|
|
1122
|
-
while (char && char !== ']' && char !== '}') {
|
|
1123
|
-
switch (char) {
|
|
1124
|
-
case '\n':
|
|
1125
|
-
{
|
|
1126
|
-
lineStart = offset + 1;
|
|
1127
|
-
var wsEnd = Node.endOfWhiteSpace(src, lineStart);
|
|
1128
|
-
|
|
1129
|
-
if (src[wsEnd] === '\n') {
|
|
1130
|
-
var blankLine = new BlankLine();
|
|
1131
|
-
lineStart = blankLine.parse({
|
|
1132
|
-
src: src
|
|
1133
|
-
}, lineStart);
|
|
1134
|
-
this.items.push(blankLine);
|
|
1135
|
-
}
|
|
1136
|
-
|
|
1137
|
-
offset = Node.endOfIndent(src, lineStart);
|
|
1138
|
-
|
|
1139
|
-
if (offset <= lineStart + indent) {
|
|
1140
|
-
char = src[offset];
|
|
1141
|
-
|
|
1142
|
-
if (offset < lineStart + indent || char !== ']' && char !== '}') {
|
|
1143
|
-
var msg = 'Insufficient indentation in flow collection';
|
|
1144
|
-
this.error = new YAMLSemanticError(this, msg);
|
|
1145
|
-
}
|
|
1146
|
-
}
|
|
1147
|
-
}
|
|
1148
|
-
break;
|
|
1149
|
-
|
|
1150
|
-
case ',':
|
|
1151
|
-
{
|
|
1152
|
-
this.items.push({
|
|
1153
|
-
char: char,
|
|
1154
|
-
offset: offset
|
|
1155
|
-
});
|
|
1156
|
-
offset += 1;
|
|
1157
|
-
}
|
|
1158
|
-
break;
|
|
1159
|
-
|
|
1160
|
-
case '#':
|
|
1161
|
-
{
|
|
1162
|
-
var comment = new Comment();
|
|
1163
|
-
offset = comment.parse({
|
|
1164
|
-
src: src
|
|
1165
|
-
}, offset);
|
|
1166
|
-
this.items.push(comment);
|
|
1167
|
-
}
|
|
1168
|
-
break;
|
|
1169
|
-
|
|
1170
|
-
case '?':
|
|
1171
|
-
case ':':
|
|
1172
|
-
{
|
|
1173
|
-
var next = src[offset + 1];
|
|
1174
|
-
|
|
1175
|
-
if (next === '\n' || next === '\t' || next === ' ' || next === ',' || // in-flow : after JSON-like key does not need to be followed by whitespace
|
|
1176
|
-
char === ':' && this.prevNodeIsJsonLike()) {
|
|
1177
|
-
this.items.push({
|
|
1178
|
-
char: char,
|
|
1179
|
-
offset: offset
|
|
1180
|
-
});
|
|
1181
|
-
offset += 1;
|
|
1182
|
-
break;
|
|
1183
|
-
}
|
|
1184
|
-
}
|
|
1185
|
-
// fallthrough
|
|
1186
|
-
|
|
1187
|
-
default:
|
|
1188
|
-
{
|
|
1189
|
-
var node = parseNode({
|
|
1190
|
-
atLineStart: false,
|
|
1191
|
-
inCollection: false,
|
|
1192
|
-
inFlow: true,
|
|
1193
|
-
indent: -1,
|
|
1194
|
-
lineStart: lineStart,
|
|
1195
|
-
parent: this
|
|
1196
|
-
}, offset);
|
|
1197
|
-
|
|
1198
|
-
if (!node) {
|
|
1199
|
-
// at next document start
|
|
1200
|
-
this.valueRange = new Range(start, offset);
|
|
1201
|
-
return offset;
|
|
1202
|
-
}
|
|
1203
|
-
|
|
1204
|
-
this.items.push(node);
|
|
1205
|
-
offset = Node.normalizeOffset(src, node.range.end);
|
|
1206
|
-
}
|
|
1207
|
-
}
|
|
1208
|
-
|
|
1209
|
-
offset = Node.endOfWhiteSpace(src, offset);
|
|
1210
|
-
char = src[offset];
|
|
1211
|
-
}
|
|
1212
|
-
|
|
1213
|
-
this.valueRange = new Range(start, offset + 1);
|
|
1214
|
-
|
|
1215
|
-
if (char) {
|
|
1216
|
-
this.items.push({
|
|
1217
|
-
char: char,
|
|
1218
|
-
offset: offset
|
|
1219
|
-
});
|
|
1220
|
-
offset = Node.endOfWhiteSpace(src, offset + 1);
|
|
1221
|
-
offset = this.parseComment(offset);
|
|
685
|
+
const bi = indent + this.blockIndent;
|
|
686
|
+
const folded = this.type === Type.BLOCK_FOLDED;
|
|
687
|
+
let atStart = true;
|
|
688
|
+
let str = '';
|
|
689
|
+
let sep = '';
|
|
690
|
+
let prevMoreIndented = false;
|
|
691
|
+
for (let i = start; i < end; ++i) {
|
|
692
|
+
for (let j = 0; j < bi; ++j) {
|
|
693
|
+
if (src[i] !== ' ') break;
|
|
694
|
+
i += 1;
|
|
1222
695
|
}
|
|
696
|
+
const ch = src[i];
|
|
697
|
+
if (ch === '\n') {
|
|
698
|
+
if (sep === '\n') str += '\n';else sep = '\n';
|
|
699
|
+
} else {
|
|
700
|
+
const lineEnd = Node.endOfLine(src, i);
|
|
701
|
+
const line = src.slice(i, lineEnd);
|
|
702
|
+
i = lineEnd;
|
|
703
|
+
if (folded && (ch === ' ' || ch === '\t') && i < keepStart) {
|
|
704
|
+
if (sep === ' ') sep = '\n';else if (!prevMoreIndented && !atStart && sep === '\n') sep = '\n\n';
|
|
705
|
+
str += sep + line; //+ ((lineEnd < end && src[lineEnd]) || '')
|
|
706
|
+
sep = lineEnd < end && src[lineEnd] || '';
|
|
707
|
+
prevMoreIndented = true;
|
|
708
|
+
} else {
|
|
709
|
+
str += sep + line;
|
|
710
|
+
sep = folded && i < keepStart ? ' ' : '\n';
|
|
711
|
+
prevMoreIndented = false;
|
|
712
|
+
}
|
|
713
|
+
if (atStart && line !== '') atStart = false;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
return this.chomping === Chomp.STRIP ? str : str + '\n';
|
|
717
|
+
}
|
|
718
|
+
parseBlockHeader(start) {
|
|
719
|
+
const {
|
|
720
|
+
src
|
|
721
|
+
} = this.context;
|
|
722
|
+
let offset = start + 1;
|
|
723
|
+
let bi = '';
|
|
724
|
+
while (true) {
|
|
725
|
+
const ch = src[offset];
|
|
726
|
+
switch (ch) {
|
|
727
|
+
case '-':
|
|
728
|
+
this.chomping = Chomp.STRIP;
|
|
729
|
+
break;
|
|
730
|
+
case '+':
|
|
731
|
+
this.chomping = Chomp.KEEP;
|
|
732
|
+
break;
|
|
733
|
+
case '0':
|
|
734
|
+
case '1':
|
|
735
|
+
case '2':
|
|
736
|
+
case '3':
|
|
737
|
+
case '4':
|
|
738
|
+
case '5':
|
|
739
|
+
case '6':
|
|
740
|
+
case '7':
|
|
741
|
+
case '8':
|
|
742
|
+
case '9':
|
|
743
|
+
bi += ch;
|
|
744
|
+
break;
|
|
745
|
+
default:
|
|
746
|
+
this.blockIndent = Number(bi) || null;
|
|
747
|
+
this.header = new Range(start, offset);
|
|
748
|
+
return offset;
|
|
749
|
+
}
|
|
750
|
+
offset += 1;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
parseBlockValue(start) {
|
|
754
|
+
const {
|
|
755
|
+
indent,
|
|
756
|
+
src
|
|
757
|
+
} = this.context;
|
|
758
|
+
const explicit = !!this.blockIndent;
|
|
759
|
+
let offset = start;
|
|
760
|
+
let valueEnd = start;
|
|
761
|
+
let minBlockIndent = 1;
|
|
762
|
+
for (let ch = src[offset]; ch === '\n'; ch = src[offset]) {
|
|
763
|
+
offset += 1;
|
|
764
|
+
if (Node.atDocumentBoundary(src, offset)) break;
|
|
765
|
+
const end = Node.endOfBlockIndent(src, indent, offset); // should not include tab?
|
|
766
|
+
if (end === null) break;
|
|
767
|
+
const ch = src[end];
|
|
768
|
+
const lineIndent = end - (offset + indent);
|
|
769
|
+
if (!this.blockIndent) {
|
|
770
|
+
// no explicit block indent, none yet detected
|
|
771
|
+
if (src[end] !== '\n') {
|
|
772
|
+
// first line with non-whitespace content
|
|
773
|
+
if (lineIndent < minBlockIndent) {
|
|
774
|
+
const msg = 'Block scalars with more-indented leading empty lines must use an explicit indentation indicator';
|
|
775
|
+
this.error = new YAMLSemanticError(this, msg);
|
|
776
|
+
}
|
|
777
|
+
this.blockIndent = lineIndent;
|
|
778
|
+
} else if (lineIndent > minBlockIndent) {
|
|
779
|
+
// empty line with more whitespace
|
|
780
|
+
minBlockIndent = lineIndent;
|
|
781
|
+
}
|
|
782
|
+
} else if (ch && ch !== '\n' && lineIndent < this.blockIndent) {
|
|
783
|
+
if (src[end] === '#') break;
|
|
784
|
+
if (!this.error) {
|
|
785
|
+
const src = explicit ? 'explicit indentation indicator' : 'first line';
|
|
786
|
+
const msg = `Block scalars must not be less indented than their ${src}`;
|
|
787
|
+
this.error = new YAMLSemanticError(this, msg);
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
if (src[end] === '\n') {
|
|
791
|
+
offset = end;
|
|
792
|
+
} else {
|
|
793
|
+
offset = valueEnd = Node.endOfLine(src, end);
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
if (this.chomping !== Chomp.KEEP) {
|
|
797
|
+
offset = src[valueEnd] ? valueEnd + 1 : valueEnd;
|
|
798
|
+
}
|
|
799
|
+
this.valueRange = new Range(start + 1, offset);
|
|
800
|
+
return offset;
|
|
801
|
+
}
|
|
1223
802
|
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
var prevEnd = range.start;
|
|
1261
|
-
nodes.forEach(function (node) {
|
|
1262
|
-
var prefix = src.slice(prevEnd, node.range.start);
|
|
1263
|
-
prevEnd = node.range.end;
|
|
1264
|
-
str += prefix + String(node);
|
|
1265
|
-
|
|
1266
|
-
if (str[str.length - 1] === '\n' && src[prevEnd - 1] !== '\n' && src[prevEnd] === '\n') {
|
|
1267
|
-
// Comment range does not include the terminal newline, but its
|
|
1268
|
-
// stringified value does. Without this fix, newlines at comment ends
|
|
1269
|
-
// get duplicated.
|
|
1270
|
-
prevEnd += 1;
|
|
1271
|
-
}
|
|
1272
|
-
});
|
|
1273
|
-
str += src.slice(prevEnd, range.end);
|
|
1274
|
-
return Node.addStringTerminator(src, range.end, str);
|
|
1275
|
-
}
|
|
1276
|
-
}]);
|
|
1277
|
-
|
|
1278
|
-
return FlowCollection;
|
|
1279
|
-
}(Node);
|
|
1280
|
-
|
|
1281
|
-
var QuoteDouble = /*#__PURE__*/function (_Node) {
|
|
1282
|
-
_inherits(QuoteDouble, _Node);
|
|
1283
|
-
|
|
1284
|
-
var _super = _createSuper(QuoteDouble);
|
|
1285
|
-
|
|
1286
|
-
function QuoteDouble() {
|
|
1287
|
-
_classCallCheck(this, QuoteDouble);
|
|
1288
|
-
|
|
1289
|
-
return _super.apply(this, arguments);
|
|
1290
|
-
}
|
|
1291
|
-
|
|
1292
|
-
_createClass(QuoteDouble, [{
|
|
1293
|
-
key: "strValue",
|
|
1294
|
-
get:
|
|
1295
|
-
/**
|
|
1296
|
-
* @returns {string | { str: string, errors: YAMLSyntaxError[] }}
|
|
1297
|
-
*/
|
|
1298
|
-
function get() {
|
|
1299
|
-
if (!this.valueRange || !this.context) return null;
|
|
1300
|
-
var errors = [];
|
|
1301
|
-
var _this$valueRange = this.valueRange,
|
|
1302
|
-
start = _this$valueRange.start,
|
|
1303
|
-
end = _this$valueRange.end;
|
|
1304
|
-
var _this$context = this.context,
|
|
1305
|
-
indent = _this$context.indent,
|
|
1306
|
-
src = _this$context.src;
|
|
1307
|
-
if (src[end - 1] !== '"') errors.push(new YAMLSyntaxError(this, 'Missing closing "quote')); // Using String#replace is too painful with escaped newlines preceded by
|
|
1308
|
-
// escaped backslashes; also, this should be faster.
|
|
1309
|
-
|
|
1310
|
-
var str = '';
|
|
1311
|
-
|
|
1312
|
-
for (var i = start + 1; i < end - 1; ++i) {
|
|
1313
|
-
var ch = src[i];
|
|
1314
|
-
|
|
1315
|
-
if (ch === '\n') {
|
|
1316
|
-
if (Node.atDocumentBoundary(src, i + 1)) errors.push(new YAMLSemanticError(this, 'Document boundary indicators are not allowed within string values'));
|
|
1317
|
-
|
|
1318
|
-
var _Node$foldNewline = Node.foldNewline(src, i, indent),
|
|
1319
|
-
fold = _Node$foldNewline.fold,
|
|
1320
|
-
offset = _Node$foldNewline.offset,
|
|
1321
|
-
error = _Node$foldNewline.error;
|
|
1322
|
-
|
|
1323
|
-
str += fold;
|
|
1324
|
-
i = offset;
|
|
1325
|
-
if (error) errors.push(new YAMLSemanticError(this, 'Multi-line double-quoted string needs to be sufficiently indented'));
|
|
1326
|
-
} else if (ch === '\\') {
|
|
1327
|
-
i += 1;
|
|
1328
|
-
|
|
1329
|
-
switch (src[i]) {
|
|
1330
|
-
case '0':
|
|
1331
|
-
str += '\0';
|
|
1332
|
-
break;
|
|
1333
|
-
// null character
|
|
1334
|
-
|
|
1335
|
-
case 'a':
|
|
1336
|
-
str += '\x07';
|
|
1337
|
-
break;
|
|
1338
|
-
// bell character
|
|
1339
|
-
|
|
1340
|
-
case 'b':
|
|
1341
|
-
str += '\b';
|
|
1342
|
-
break;
|
|
1343
|
-
// backspace
|
|
1344
|
-
|
|
1345
|
-
case 'e':
|
|
1346
|
-
str += '\x1b';
|
|
1347
|
-
break;
|
|
1348
|
-
// escape character
|
|
1349
|
-
|
|
1350
|
-
case 'f':
|
|
1351
|
-
str += '\f';
|
|
1352
|
-
break;
|
|
1353
|
-
// form feed
|
|
1354
|
-
|
|
1355
|
-
case 'n':
|
|
1356
|
-
str += '\n';
|
|
1357
|
-
break;
|
|
1358
|
-
// line feed
|
|
1359
|
-
|
|
1360
|
-
case 'r':
|
|
1361
|
-
str += '\r';
|
|
1362
|
-
break;
|
|
1363
|
-
// carriage return
|
|
1364
|
-
|
|
1365
|
-
case 't':
|
|
1366
|
-
str += '\t';
|
|
1367
|
-
break;
|
|
1368
|
-
// horizontal tab
|
|
1369
|
-
|
|
1370
|
-
case 'v':
|
|
1371
|
-
str += '\v';
|
|
1372
|
-
break;
|
|
1373
|
-
// vertical tab
|
|
1374
|
-
|
|
1375
|
-
case 'N':
|
|
1376
|
-
str += "\x85";
|
|
1377
|
-
break;
|
|
1378
|
-
// Unicode next line
|
|
1379
|
-
|
|
1380
|
-
case '_':
|
|
1381
|
-
str += "\xA0";
|
|
1382
|
-
break;
|
|
1383
|
-
// Unicode non-breaking space
|
|
1384
|
-
|
|
1385
|
-
case 'L':
|
|
1386
|
-
str += "\u2028";
|
|
1387
|
-
break;
|
|
1388
|
-
// Unicode line separator
|
|
1389
|
-
|
|
1390
|
-
case 'P':
|
|
1391
|
-
str += "\u2029";
|
|
1392
|
-
break;
|
|
1393
|
-
// Unicode paragraph separator
|
|
1394
|
-
|
|
1395
|
-
case ' ':
|
|
1396
|
-
str += ' ';
|
|
1397
|
-
break;
|
|
1398
|
-
|
|
1399
|
-
case '"':
|
|
1400
|
-
str += '"';
|
|
1401
|
-
break;
|
|
1402
|
-
|
|
1403
|
-
case '/':
|
|
1404
|
-
str += '/';
|
|
1405
|
-
break;
|
|
1406
|
-
|
|
1407
|
-
case '\\':
|
|
1408
|
-
str += '\\';
|
|
1409
|
-
break;
|
|
1410
|
-
|
|
1411
|
-
case '\t':
|
|
1412
|
-
str += '\t';
|
|
1413
|
-
break;
|
|
1414
|
-
|
|
1415
|
-
case 'x':
|
|
1416
|
-
str += this.parseCharCode(i + 1, 2, errors);
|
|
1417
|
-
i += 2;
|
|
1418
|
-
break;
|
|
1419
|
-
|
|
1420
|
-
case 'u':
|
|
1421
|
-
str += this.parseCharCode(i + 1, 4, errors);
|
|
1422
|
-
i += 4;
|
|
1423
|
-
break;
|
|
803
|
+
/**
|
|
804
|
+
* Parses a block value from the source
|
|
805
|
+
*
|
|
806
|
+
* Accepted forms are:
|
|
807
|
+
* ```
|
|
808
|
+
* BS
|
|
809
|
+
* block
|
|
810
|
+
* lines
|
|
811
|
+
*
|
|
812
|
+
* BS #comment
|
|
813
|
+
* block
|
|
814
|
+
* lines
|
|
815
|
+
* ```
|
|
816
|
+
* where the block style BS matches the regexp `[|>][-+1-9]*` and block lines
|
|
817
|
+
* are empty or have an indent level greater than `indent`.
|
|
818
|
+
*
|
|
819
|
+
* @param {ParseContext} context
|
|
820
|
+
* @param {number} start - Index of first character
|
|
821
|
+
* @returns {number} - Index of the character after this block
|
|
822
|
+
*/
|
|
823
|
+
parse(context, start) {
|
|
824
|
+
this.context = context;
|
|
825
|
+
const {
|
|
826
|
+
src
|
|
827
|
+
} = context;
|
|
828
|
+
let offset = this.parseBlockHeader(start);
|
|
829
|
+
offset = Node.endOfWhiteSpace(src, offset);
|
|
830
|
+
offset = this.parseComment(offset);
|
|
831
|
+
offset = this.parseBlockValue(offset);
|
|
832
|
+
return offset;
|
|
833
|
+
}
|
|
834
|
+
setOrigRanges(cr, offset) {
|
|
835
|
+
offset = super.setOrigRanges(cr, offset);
|
|
836
|
+
return this.header ? this.header.setOrigRange(cr, offset) : offset;
|
|
837
|
+
}
|
|
838
|
+
}
|
|
1424
839
|
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
840
|
+
class FlowCollection extends Node {
|
|
841
|
+
constructor(type, props) {
|
|
842
|
+
super(type, props);
|
|
843
|
+
this.items = null;
|
|
844
|
+
}
|
|
845
|
+
prevNodeIsJsonLike(idx = this.items.length) {
|
|
846
|
+
const node = this.items[idx - 1];
|
|
847
|
+
return !!node && (node.jsonLike || node.type === Type.COMMENT && this.prevNodeIsJsonLike(idx - 1));
|
|
848
|
+
}
|
|
1429
849
|
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
850
|
+
/**
|
|
851
|
+
* @param {ParseContext} context
|
|
852
|
+
* @param {number} start - Index of first character
|
|
853
|
+
* @returns {number} - Index of the character after this
|
|
854
|
+
*/
|
|
855
|
+
parse(context, start) {
|
|
856
|
+
this.context = context;
|
|
857
|
+
const {
|
|
858
|
+
parseNode,
|
|
859
|
+
src
|
|
860
|
+
} = context;
|
|
861
|
+
let {
|
|
862
|
+
indent,
|
|
863
|
+
lineStart
|
|
864
|
+
} = context;
|
|
865
|
+
let char = src[start]; // { or [
|
|
866
|
+
this.items = [{
|
|
867
|
+
char,
|
|
868
|
+
offset: start
|
|
869
|
+
}];
|
|
870
|
+
let offset = Node.endOfWhiteSpace(src, start + 1);
|
|
871
|
+
char = src[offset];
|
|
872
|
+
while (char && char !== ']' && char !== '}') {
|
|
873
|
+
switch (char) {
|
|
874
|
+
case '\n':
|
|
875
|
+
{
|
|
876
|
+
lineStart = offset + 1;
|
|
877
|
+
const wsEnd = Node.endOfWhiteSpace(src, lineStart);
|
|
878
|
+
if (src[wsEnd] === '\n') {
|
|
879
|
+
const blankLine = new BlankLine();
|
|
880
|
+
lineStart = blankLine.parse({
|
|
881
|
+
src
|
|
882
|
+
}, lineStart);
|
|
883
|
+
this.items.push(blankLine);
|
|
884
|
+
}
|
|
885
|
+
offset = Node.endOfIndent(src, lineStart);
|
|
886
|
+
if (offset <= lineStart + indent) {
|
|
887
|
+
char = src[offset];
|
|
888
|
+
if (offset < lineStart + indent || char !== ']' && char !== '}') {
|
|
889
|
+
const msg = 'Insufficient indentation in flow collection';
|
|
890
|
+
this.error = new YAMLSemanticError(this, msg);
|
|
1434
891
|
}
|
|
1435
|
-
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
break;
|
|
895
|
+
case ',':
|
|
896
|
+
{
|
|
897
|
+
this.items.push({
|
|
898
|
+
char,
|
|
899
|
+
offset
|
|
900
|
+
});
|
|
901
|
+
offset += 1;
|
|
902
|
+
}
|
|
903
|
+
break;
|
|
904
|
+
case '#':
|
|
905
|
+
{
|
|
906
|
+
const comment = new Comment();
|
|
907
|
+
offset = comment.parse({
|
|
908
|
+
src
|
|
909
|
+
}, offset);
|
|
910
|
+
this.items.push(comment);
|
|
911
|
+
}
|
|
912
|
+
break;
|
|
913
|
+
case '?':
|
|
914
|
+
case ':':
|
|
915
|
+
{
|
|
916
|
+
const next = src[offset + 1];
|
|
917
|
+
if (next === '\n' || next === '\t' || next === ' ' || next === ',' ||
|
|
918
|
+
// in-flow : after JSON-like key does not need to be followed by whitespace
|
|
919
|
+
char === ':' && this.prevNodeIsJsonLike()) {
|
|
920
|
+
this.items.push({
|
|
921
|
+
char,
|
|
922
|
+
offset
|
|
923
|
+
});
|
|
924
|
+
offset += 1;
|
|
1436
925
|
break;
|
|
1437
|
-
|
|
1438
|
-
default:
|
|
1439
|
-
errors.push(new YAMLSyntaxError(this, "Invalid escape sequence ".concat(src.substr(i - 1, 2))));
|
|
1440
|
-
str += '\\' + src[i];
|
|
926
|
+
}
|
|
1441
927
|
}
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
928
|
+
// fallthrough
|
|
929
|
+
default:
|
|
930
|
+
{
|
|
931
|
+
const node = parseNode({
|
|
932
|
+
atLineStart: false,
|
|
933
|
+
inCollection: false,
|
|
934
|
+
inFlow: true,
|
|
935
|
+
indent: -1,
|
|
936
|
+
lineStart,
|
|
937
|
+
parent: this
|
|
938
|
+
}, offset);
|
|
939
|
+
if (!node) {
|
|
940
|
+
// at next document start
|
|
941
|
+
this.valueRange = new Range(start, offset);
|
|
942
|
+
return offset;
|
|
943
|
+
}
|
|
944
|
+
this.items.push(node);
|
|
945
|
+
offset = Node.normalizeOffset(src, node.range.end);
|
|
1450
946
|
}
|
|
1451
|
-
|
|
1452
|
-
if (next !== '\n') str += i > wsStart ? src.slice(wsStart, i + 1) : ch;
|
|
1453
|
-
} else {
|
|
1454
|
-
str += ch;
|
|
1455
|
-
}
|
|
1456
|
-
}
|
|
1457
|
-
|
|
1458
|
-
return errors.length > 0 ? {
|
|
1459
|
-
errors: errors,
|
|
1460
|
-
str: str
|
|
1461
|
-
} : str;
|
|
1462
|
-
}
|
|
1463
|
-
}, {
|
|
1464
|
-
key: "parseCharCode",
|
|
1465
|
-
value: function parseCharCode(offset, length, errors) {
|
|
1466
|
-
var src = this.context.src;
|
|
1467
|
-
var cc = src.substr(offset, length);
|
|
1468
|
-
var ok = cc.length === length && /^[0-9a-fA-F]+$/.test(cc);
|
|
1469
|
-
var code = ok ? parseInt(cc, 16) : NaN;
|
|
1470
|
-
|
|
1471
|
-
if (isNaN(code)) {
|
|
1472
|
-
errors.push(new YAMLSyntaxError(this, "Invalid escape sequence ".concat(src.substr(offset - 2, length + 2))));
|
|
1473
|
-
return src.substr(offset - 2, length + 2);
|
|
1474
947
|
}
|
|
1475
|
-
|
|
1476
|
-
return String.fromCodePoint(code);
|
|
1477
|
-
}
|
|
1478
|
-
/**
|
|
1479
|
-
* Parses a "double quoted" value from the source
|
|
1480
|
-
*
|
|
1481
|
-
* @param {ParseContext} context
|
|
1482
|
-
* @param {number} start - Index of first character
|
|
1483
|
-
* @returns {number} - Index of the character after this scalar
|
|
1484
|
-
*/
|
|
1485
|
-
|
|
1486
|
-
}, {
|
|
1487
|
-
key: "parse",
|
|
1488
|
-
value: function parse(context, start) {
|
|
1489
|
-
this.context = context;
|
|
1490
|
-
var src = context.src;
|
|
1491
|
-
var offset = QuoteDouble.endOfQuote(src, start + 1);
|
|
1492
|
-
this.valueRange = new Range(start, offset);
|
|
1493
948
|
offset = Node.endOfWhiteSpace(src, offset);
|
|
949
|
+
char = src[offset];
|
|
950
|
+
}
|
|
951
|
+
this.valueRange = new Range(start, offset + 1);
|
|
952
|
+
if (char) {
|
|
953
|
+
this.items.push({
|
|
954
|
+
char,
|
|
955
|
+
offset
|
|
956
|
+
});
|
|
957
|
+
offset = Node.endOfWhiteSpace(src, offset + 1);
|
|
1494
958
|
offset = this.parseComment(offset);
|
|
1495
|
-
return offset;
|
|
1496
959
|
}
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
offset
|
|
1504
|
-
|
|
960
|
+
return offset;
|
|
961
|
+
}
|
|
962
|
+
setOrigRanges(cr, offset) {
|
|
963
|
+
offset = super.setOrigRanges(cr, offset);
|
|
964
|
+
this.items.forEach(node => {
|
|
965
|
+
if (node instanceof Node) {
|
|
966
|
+
offset = node.setOrigRanges(cr, offset);
|
|
967
|
+
} else if (cr.length === 0) {
|
|
968
|
+
node.origOffset = node.offset;
|
|
969
|
+
} else {
|
|
970
|
+
let i = offset;
|
|
971
|
+
while (i < cr.length) {
|
|
972
|
+
if (cr[i] > node.offset) break;else ++i;
|
|
973
|
+
}
|
|
974
|
+
node.origOffset = node.offset + i;
|
|
975
|
+
offset = i;
|
|
976
|
+
}
|
|
977
|
+
});
|
|
978
|
+
return offset;
|
|
979
|
+
}
|
|
980
|
+
toString() {
|
|
981
|
+
const {
|
|
982
|
+
context: {
|
|
983
|
+
src
|
|
984
|
+
},
|
|
985
|
+
items,
|
|
986
|
+
range,
|
|
987
|
+
value
|
|
988
|
+
} = this;
|
|
989
|
+
if (value != null) return value;
|
|
990
|
+
const nodes = items.filter(item => item instanceof Node);
|
|
991
|
+
let str = '';
|
|
992
|
+
let prevEnd = range.start;
|
|
993
|
+
nodes.forEach(node => {
|
|
994
|
+
const prefix = src.slice(prevEnd, node.range.start);
|
|
995
|
+
prevEnd = node.range.end;
|
|
996
|
+
str += prefix + String(node);
|
|
997
|
+
if (str[str.length - 1] === '\n' && src[prevEnd - 1] !== '\n' && src[prevEnd] === '\n') {
|
|
998
|
+
// Comment range does not include the terminal newline, but its
|
|
999
|
+
// stringified value does. Without this fix, newlines at comment ends
|
|
1000
|
+
// get duplicated.
|
|
1001
|
+
prevEnd += 1;
|
|
1505
1002
|
}
|
|
1003
|
+
});
|
|
1004
|
+
str += src.slice(prevEnd, range.end);
|
|
1005
|
+
return Node.addStringTerminator(src, range.end, str);
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1506
1008
|
|
|
1507
|
-
|
|
1009
|
+
class QuoteDouble extends Node {
|
|
1010
|
+
static endOfQuote(src, offset) {
|
|
1011
|
+
let ch = src[offset];
|
|
1012
|
+
while (ch && ch !== '"') {
|
|
1013
|
+
offset += ch === '\\' ? 2 : 1;
|
|
1014
|
+
ch = src[offset];
|
|
1508
1015
|
}
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
return QuoteDouble;
|
|
1512
|
-
}(Node);
|
|
1513
|
-
|
|
1514
|
-
var QuoteSingle = /*#__PURE__*/function (_Node) {
|
|
1515
|
-
_inherits(QuoteSingle, _Node);
|
|
1516
|
-
|
|
1517
|
-
var _super = _createSuper(QuoteSingle);
|
|
1518
|
-
|
|
1519
|
-
function QuoteSingle() {
|
|
1520
|
-
_classCallCheck(this, QuoteSingle);
|
|
1521
|
-
|
|
1522
|
-
return _super.apply(this, arguments);
|
|
1016
|
+
return offset + 1;
|
|
1523
1017
|
}
|
|
1524
1018
|
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
if (
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1019
|
+
/**
|
|
1020
|
+
* @returns {string | { str: string, errors: YAMLSyntaxError[] }}
|
|
1021
|
+
*/
|
|
1022
|
+
get strValue() {
|
|
1023
|
+
if (!this.valueRange || !this.context) return null;
|
|
1024
|
+
const errors = [];
|
|
1025
|
+
const {
|
|
1026
|
+
start,
|
|
1027
|
+
end
|
|
1028
|
+
} = this.valueRange;
|
|
1029
|
+
const {
|
|
1030
|
+
indent,
|
|
1031
|
+
src
|
|
1032
|
+
} = this.context;
|
|
1033
|
+
if (src[end - 1] !== '"') errors.push(new YAMLSyntaxError(this, 'Missing closing "quote'));
|
|
1034
|
+
// Using String#replace is too painful with escaped newlines preceded by
|
|
1035
|
+
// escaped backslashes; also, this should be faster.
|
|
1036
|
+
let str = '';
|
|
1037
|
+
for (let i = start + 1; i < end - 1; ++i) {
|
|
1038
|
+
const ch = src[i];
|
|
1039
|
+
if (ch === '\n') {
|
|
1040
|
+
if (Node.atDocumentBoundary(src, i + 1)) errors.push(new YAMLSemanticError(this, 'Document boundary indicators are not allowed within string values'));
|
|
1041
|
+
const {
|
|
1042
|
+
fold,
|
|
1043
|
+
offset,
|
|
1044
|
+
error
|
|
1045
|
+
} = Node.foldNewline(src, i, indent);
|
|
1046
|
+
str += fold;
|
|
1047
|
+
i = offset;
|
|
1048
|
+
if (error) errors.push(new YAMLSemanticError(this, 'Multi-line double-quoted string needs to be sufficiently indented'));
|
|
1049
|
+
} else if (ch === '\\') {
|
|
1050
|
+
i += 1;
|
|
1051
|
+
switch (src[i]) {
|
|
1052
|
+
case '0':
|
|
1053
|
+
str += '\0';
|
|
1054
|
+
break;
|
|
1055
|
+
// null character
|
|
1056
|
+
case 'a':
|
|
1057
|
+
str += '\x07';
|
|
1058
|
+
break;
|
|
1059
|
+
// bell character
|
|
1060
|
+
case 'b':
|
|
1061
|
+
str += '\b';
|
|
1062
|
+
break;
|
|
1063
|
+
// backspace
|
|
1064
|
+
case 'e':
|
|
1065
|
+
str += '\x1b';
|
|
1066
|
+
break;
|
|
1067
|
+
// escape character
|
|
1068
|
+
case 'f':
|
|
1069
|
+
str += '\f';
|
|
1070
|
+
break;
|
|
1071
|
+
// form feed
|
|
1072
|
+
case 'n':
|
|
1073
|
+
str += '\n';
|
|
1074
|
+
break;
|
|
1075
|
+
// line feed
|
|
1076
|
+
case 'r':
|
|
1077
|
+
str += '\r';
|
|
1078
|
+
break;
|
|
1079
|
+
// carriage return
|
|
1080
|
+
case 't':
|
|
1081
|
+
str += '\t';
|
|
1082
|
+
break;
|
|
1083
|
+
// horizontal tab
|
|
1084
|
+
case 'v':
|
|
1085
|
+
str += '\v';
|
|
1086
|
+
break;
|
|
1087
|
+
// vertical tab
|
|
1088
|
+
case 'N':
|
|
1089
|
+
str += '\u0085';
|
|
1090
|
+
break;
|
|
1091
|
+
// Unicode next line
|
|
1092
|
+
case '_':
|
|
1093
|
+
str += '\u00a0';
|
|
1094
|
+
break;
|
|
1095
|
+
// Unicode non-breaking space
|
|
1096
|
+
case 'L':
|
|
1097
|
+
str += '\u2028';
|
|
1098
|
+
break;
|
|
1099
|
+
// Unicode line separator
|
|
1100
|
+
case 'P':
|
|
1101
|
+
str += '\u2029';
|
|
1102
|
+
break;
|
|
1103
|
+
// Unicode paragraph separator
|
|
1104
|
+
case ' ':
|
|
1105
|
+
str += ' ';
|
|
1106
|
+
break;
|
|
1107
|
+
case '"':
|
|
1108
|
+
str += '"';
|
|
1109
|
+
break;
|
|
1110
|
+
case '/':
|
|
1111
|
+
str += '/';
|
|
1112
|
+
break;
|
|
1113
|
+
case '\\':
|
|
1114
|
+
str += '\\';
|
|
1115
|
+
break;
|
|
1116
|
+
case '\t':
|
|
1117
|
+
str += '\t';
|
|
1118
|
+
break;
|
|
1119
|
+
case 'x':
|
|
1120
|
+
str += this.parseCharCode(i + 1, 2, errors);
|
|
1121
|
+
i += 2;
|
|
1122
|
+
break;
|
|
1123
|
+
case 'u':
|
|
1124
|
+
str += this.parseCharCode(i + 1, 4, errors);
|
|
1125
|
+
i += 4;
|
|
1126
|
+
break;
|
|
1127
|
+
case 'U':
|
|
1128
|
+
str += this.parseCharCode(i + 1, 8, errors);
|
|
1129
|
+
i += 8;
|
|
1130
|
+
break;
|
|
1131
|
+
case '\n':
|
|
1132
|
+
// skip escaped newlines, but still trim the following line
|
|
1133
|
+
while (src[i + 1] === ' ' || src[i + 1] === '\t') i += 1;
|
|
1134
|
+
break;
|
|
1135
|
+
default:
|
|
1136
|
+
errors.push(new YAMLSyntaxError(this, `Invalid escape sequence ${src.substr(i - 1, 2)}`));
|
|
1137
|
+
str += '\\' + src[i];
|
|
1138
|
+
}
|
|
1139
|
+
} else if (ch === ' ' || ch === '\t') {
|
|
1140
|
+
// trim trailing whitespace
|
|
1141
|
+
const wsStart = i;
|
|
1142
|
+
let next = src[i + 1];
|
|
1143
|
+
while (next === ' ' || next === '\t') {
|
|
1559
1144
|
i += 1;
|
|
1560
|
-
|
|
1561
|
-
} else if (ch === ' ' || ch === '\t') {
|
|
1562
|
-
// trim trailing whitespace
|
|
1563
|
-
var wsStart = i;
|
|
1564
|
-
var next = src[i + 1];
|
|
1565
|
-
|
|
1566
|
-
while (next === ' ' || next === '\t') {
|
|
1567
|
-
i += 1;
|
|
1568
|
-
next = src[i + 1];
|
|
1569
|
-
}
|
|
1570
|
-
|
|
1571
|
-
if (next !== '\n') str += i > wsStart ? src.slice(wsStart, i + 1) : ch;
|
|
1572
|
-
} else {
|
|
1573
|
-
str += ch;
|
|
1145
|
+
next = src[i + 1];
|
|
1574
1146
|
}
|
|
1147
|
+
if (next !== '\n') str += i > wsStart ? src.slice(wsStart, i + 1) : ch;
|
|
1148
|
+
} else {
|
|
1149
|
+
str += ch;
|
|
1575
1150
|
}
|
|
1576
|
-
|
|
1577
|
-
return errors.length > 0 ? {
|
|
1578
|
-
errors: errors,
|
|
1579
|
-
str: str
|
|
1580
|
-
} : str;
|
|
1581
1151
|
}
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1152
|
+
return errors.length > 0 ? {
|
|
1153
|
+
errors,
|
|
1154
|
+
str
|
|
1155
|
+
} : str;
|
|
1156
|
+
}
|
|
1157
|
+
parseCharCode(offset, length, errors) {
|
|
1158
|
+
const {
|
|
1159
|
+
src
|
|
1160
|
+
} = this.context;
|
|
1161
|
+
const cc = src.substr(offset, length);
|
|
1162
|
+
const ok = cc.length === length && /^[0-9a-fA-F]+$/.test(cc);
|
|
1163
|
+
const code = ok ? parseInt(cc, 16) : NaN;
|
|
1164
|
+
if (isNaN(code)) {
|
|
1165
|
+
errors.push(new YAMLSyntaxError(this, `Invalid escape sequence ${src.substr(offset - 2, length + 2)}`));
|
|
1166
|
+
return src.substr(offset - 2, length + 2);
|
|
1167
|
+
}
|
|
1168
|
+
return String.fromCodePoint(code);
|
|
1169
|
+
}
|
|
1589
1170
|
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1171
|
+
/**
|
|
1172
|
+
* Parses a "double quoted" value from the source
|
|
1173
|
+
*
|
|
1174
|
+
* @param {ParseContext} context
|
|
1175
|
+
* @param {number} start - Index of first character
|
|
1176
|
+
* @returns {number} - Index of the character after this scalar
|
|
1177
|
+
*/
|
|
1178
|
+
parse(context, start) {
|
|
1179
|
+
this.context = context;
|
|
1180
|
+
const {
|
|
1181
|
+
src
|
|
1182
|
+
} = context;
|
|
1183
|
+
let offset = QuoteDouble.endOfQuote(src, start + 1);
|
|
1184
|
+
this.valueRange = new Range(start, offset);
|
|
1185
|
+
offset = Node.endOfWhiteSpace(src, offset);
|
|
1186
|
+
offset = this.parseComment(offset);
|
|
1187
|
+
return offset;
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
class QuoteSingle extends Node {
|
|
1192
|
+
static endOfQuote(src, offset) {
|
|
1193
|
+
let ch = src[offset];
|
|
1194
|
+
while (ch) {
|
|
1195
|
+
if (ch === "'") {
|
|
1196
|
+
if (src[offset + 1] !== "'") break;
|
|
1197
|
+
ch = src[offset += 2];
|
|
1198
|
+
} else {
|
|
1199
|
+
ch = src[offset += 1];
|
|
1200
|
+
}
|
|
1600
1201
|
}
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
value: function endOfQuote(src, offset) {
|
|
1604
|
-
var ch = src[offset];
|
|
1202
|
+
return offset + 1;
|
|
1203
|
+
}
|
|
1605
1204
|
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1205
|
+
/**
|
|
1206
|
+
* @returns {string | { str: string, errors: YAMLSyntaxError[] }}
|
|
1207
|
+
*/
|
|
1208
|
+
get strValue() {
|
|
1209
|
+
if (!this.valueRange || !this.context) return null;
|
|
1210
|
+
const errors = [];
|
|
1211
|
+
const {
|
|
1212
|
+
start,
|
|
1213
|
+
end
|
|
1214
|
+
} = this.valueRange;
|
|
1215
|
+
const {
|
|
1216
|
+
indent,
|
|
1217
|
+
src
|
|
1218
|
+
} = this.context;
|
|
1219
|
+
if (src[end - 1] !== "'") errors.push(new YAMLSyntaxError(this, "Missing closing 'quote"));
|
|
1220
|
+
let str = '';
|
|
1221
|
+
for (let i = start + 1; i < end - 1; ++i) {
|
|
1222
|
+
const ch = src[i];
|
|
1223
|
+
if (ch === '\n') {
|
|
1224
|
+
if (Node.atDocumentBoundary(src, i + 1)) errors.push(new YAMLSemanticError(this, 'Document boundary indicators are not allowed within string values'));
|
|
1225
|
+
const {
|
|
1226
|
+
fold,
|
|
1227
|
+
offset,
|
|
1228
|
+
error
|
|
1229
|
+
} = Node.foldNewline(src, i, indent);
|
|
1230
|
+
str += fold;
|
|
1231
|
+
i = offset;
|
|
1232
|
+
if (error) errors.push(new YAMLSemanticError(this, 'Multi-line single-quoted string needs to be sufficiently indented'));
|
|
1233
|
+
} else if (ch === "'") {
|
|
1234
|
+
str += ch;
|
|
1235
|
+
i += 1;
|
|
1236
|
+
if (src[i] !== "'") errors.push(new YAMLSyntaxError(this, 'Unescaped single quote? This should not happen.'));
|
|
1237
|
+
} else if (ch === ' ' || ch === '\t') {
|
|
1238
|
+
// trim trailing whitespace
|
|
1239
|
+
const wsStart = i;
|
|
1240
|
+
let next = src[i + 1];
|
|
1241
|
+
while (next === ' ' || next === '\t') {
|
|
1242
|
+
i += 1;
|
|
1243
|
+
next = src[i + 1];
|
|
1612
1244
|
}
|
|
1245
|
+
if (next !== '\n') str += i > wsStart ? src.slice(wsStart, i + 1) : ch;
|
|
1246
|
+
} else {
|
|
1247
|
+
str += ch;
|
|
1613
1248
|
}
|
|
1614
|
-
|
|
1615
|
-
return offset + 1;
|
|
1616
1249
|
}
|
|
1617
|
-
|
|
1250
|
+
return errors.length > 0 ? {
|
|
1251
|
+
errors,
|
|
1252
|
+
str
|
|
1253
|
+
} : str;
|
|
1254
|
+
}
|
|
1618
1255
|
|
|
1619
|
-
|
|
1620
|
-
|
|
1256
|
+
/**
|
|
1257
|
+
* Parses a 'single quoted' value from the source
|
|
1258
|
+
*
|
|
1259
|
+
* @param {ParseContext} context
|
|
1260
|
+
* @param {number} start - Index of first character
|
|
1261
|
+
* @returns {number} - Index of the character after this scalar
|
|
1262
|
+
*/
|
|
1263
|
+
parse(context, start) {
|
|
1264
|
+
this.context = context;
|
|
1265
|
+
const {
|
|
1266
|
+
src
|
|
1267
|
+
} = context;
|
|
1268
|
+
let offset = QuoteSingle.endOfQuote(src, start + 1);
|
|
1269
|
+
this.valueRange = new Range(start, offset);
|
|
1270
|
+
offset = Node.endOfWhiteSpace(src, offset);
|
|
1271
|
+
offset = this.parseComment(offset);
|
|
1272
|
+
return offset;
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1621
1275
|
|
|
1622
1276
|
function createNewNode(type, props) {
|
|
1623
1277
|
switch (type) {
|
|
1624
1278
|
case Type.ALIAS:
|
|
1625
1279
|
return new Alias(type, props);
|
|
1626
|
-
|
|
1627
1280
|
case Type.BLOCK_FOLDED:
|
|
1628
1281
|
case Type.BLOCK_LITERAL:
|
|
1629
1282
|
return new BlockValue(type, props);
|
|
1630
|
-
|
|
1631
1283
|
case Type.FLOW_MAP:
|
|
1632
1284
|
case Type.FLOW_SEQ:
|
|
1633
1285
|
return new FlowCollection(type, props);
|
|
1634
|
-
|
|
1635
1286
|
case Type.MAP_KEY:
|
|
1636
1287
|
case Type.MAP_VALUE:
|
|
1637
1288
|
case Type.SEQ_ITEM:
|
|
1638
1289
|
return new CollectionItem(type, props);
|
|
1639
|
-
|
|
1640
1290
|
case Type.COMMENT:
|
|
1641
1291
|
case Type.PLAIN:
|
|
1642
1292
|
return new PlainValue(type, props);
|
|
1643
|
-
|
|
1644
1293
|
case Type.QUOTE_DOUBLE:
|
|
1645
1294
|
return new QuoteDouble(type, props);
|
|
1646
|
-
|
|
1647
1295
|
case Type.QUOTE_SINGLE:
|
|
1648
1296
|
return new QuoteSingle(type, props);
|
|
1649
|
-
|
|
1650
1297
|
/* istanbul ignore next */
|
|
1651
|
-
|
|
1652
1298
|
default:
|
|
1653
1299
|
return null;
|
|
1654
1300
|
// should never happen
|
|
1655
1301
|
}
|
|
1656
1302
|
}
|
|
1303
|
+
|
|
1657
1304
|
/**
|
|
1658
1305
|
* @param {boolean} atLineStart - Node starts at beginning of line
|
|
1659
1306
|
* @param {boolean} inFlow - true if currently in a flow context
|
|
@@ -1663,61 +1310,84 @@ function createNewNode(type, props) {
|
|
|
1663
1310
|
* @param {Node} parent - The parent of the node
|
|
1664
1311
|
* @param {string} src - Source of the YAML document
|
|
1665
1312
|
*/
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1313
|
+
class ParseContext {
|
|
1314
|
+
static parseType(src, offset, inFlow) {
|
|
1315
|
+
switch (src[offset]) {
|
|
1316
|
+
case '*':
|
|
1317
|
+
return Type.ALIAS;
|
|
1318
|
+
case '>':
|
|
1319
|
+
return Type.BLOCK_FOLDED;
|
|
1320
|
+
case '|':
|
|
1321
|
+
return Type.BLOCK_LITERAL;
|
|
1322
|
+
case '{':
|
|
1323
|
+
return Type.FLOW_MAP;
|
|
1324
|
+
case '[':
|
|
1325
|
+
return Type.FLOW_SEQ;
|
|
1326
|
+
case '?':
|
|
1327
|
+
return !inFlow && Node.atBlank(src, offset + 1, true) ? Type.MAP_KEY : Type.PLAIN;
|
|
1328
|
+
case ':':
|
|
1329
|
+
return !inFlow && Node.atBlank(src, offset + 1, true) ? Type.MAP_VALUE : Type.PLAIN;
|
|
1330
|
+
case '-':
|
|
1331
|
+
return !inFlow && Node.atBlank(src, offset + 1, true) ? Type.SEQ_ITEM : Type.PLAIN;
|
|
1332
|
+
case '"':
|
|
1333
|
+
return Type.QUOTE_DOUBLE;
|
|
1334
|
+
case "'":
|
|
1335
|
+
return Type.QUOTE_SINGLE;
|
|
1336
|
+
default:
|
|
1337
|
+
return Type.PLAIN;
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
constructor(orig = {}, {
|
|
1341
|
+
atLineStart,
|
|
1342
|
+
inCollection,
|
|
1343
|
+
inFlow,
|
|
1344
|
+
indent,
|
|
1345
|
+
lineStart,
|
|
1346
|
+
parent
|
|
1347
|
+
} = {}) {
|
|
1348
|
+
/**
|
|
1349
|
+
* Parses a node from the source
|
|
1350
|
+
* @param {ParseContext} overlay
|
|
1351
|
+
* @param {number} start - Index of first non-whitespace character for the node
|
|
1352
|
+
* @returns {?Node} - null if at a document boundary
|
|
1353
|
+
*/
|
|
1354
|
+
_defineProperty(this, "parseNode", (overlay, start) => {
|
|
1355
|
+
if (Node.atDocumentBoundary(this.src, start)) return null;
|
|
1356
|
+
const context = new ParseContext(this, overlay);
|
|
1357
|
+
const {
|
|
1358
|
+
props,
|
|
1359
|
+
type,
|
|
1360
|
+
valueStart
|
|
1361
|
+
} = context.parseProps(start);
|
|
1362
|
+
const node = createNewNode(type, props);
|
|
1363
|
+
let offset = start;
|
|
1364
|
+
try {
|
|
1365
|
+
offset = node.parse(context, valueStart);
|
|
1366
|
+
} catch (error) {
|
|
1367
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
1368
|
+
if (!node.error) node.error = new YAMLSyntaxError(node, msg);
|
|
1369
|
+
}
|
|
1695
1370
|
node.range = new Range(start, offset);
|
|
1696
1371
|
/* istanbul ignore if */
|
|
1697
|
-
|
|
1698
1372
|
if (offset <= start) {
|
|
1699
1373
|
// This should never happen, but if it does, let's make sure to at least
|
|
1700
1374
|
// step one character forward to avoid a busy loop.
|
|
1701
|
-
node.error = new Error(
|
|
1375
|
+
if (!node.error) node.error = new Error(`Node#parse consumed no characters`);
|
|
1702
1376
|
node.error.parseEnd = offset;
|
|
1703
1377
|
node.error.source = node;
|
|
1704
1378
|
node.range.end = start + 1;
|
|
1705
1379
|
}
|
|
1706
|
-
|
|
1707
1380
|
if (context.nodeStartsCollection(node)) {
|
|
1708
1381
|
if (!node.error && !context.atLineStart && context.parent.type === Type.DOCUMENT) {
|
|
1709
1382
|
node.error = new YAMLSyntaxError(node, 'Block collection must not have preceding content here (e.g. directives-end indicator)');
|
|
1710
1383
|
}
|
|
1711
|
-
|
|
1712
|
-
var collection = new Collection(node);
|
|
1384
|
+
const collection = new Collection(node);
|
|
1713
1385
|
offset = collection.parse(new ParseContext(context), offset);
|
|
1714
1386
|
collection.range = new Range(start, offset);
|
|
1715
1387
|
return collection;
|
|
1716
1388
|
}
|
|
1717
|
-
|
|
1718
1389
|
return node;
|
|
1719
1390
|
});
|
|
1720
|
-
|
|
1721
1391
|
this.atLineStart = atLineStart != null ? atLineStart : orig.atLineStart || false;
|
|
1722
1392
|
this.inCollection = inCollection != null ? inCollection : orig.inCollection || false;
|
|
1723
1393
|
this.inFlow = inFlow != null ? inFlow : orig.inFlow || false;
|
|
@@ -1727,177 +1397,108 @@ var ParseContext = /*#__PURE__*/function () {
|
|
|
1727
1397
|
this.root = orig.root;
|
|
1728
1398
|
this.src = orig.src;
|
|
1729
1399
|
}
|
|
1400
|
+
nodeStartsCollection(node) {
|
|
1401
|
+
const {
|
|
1402
|
+
inCollection,
|
|
1403
|
+
inFlow,
|
|
1404
|
+
src
|
|
1405
|
+
} = this;
|
|
1406
|
+
if (inCollection || inFlow) return false;
|
|
1407
|
+
if (node instanceof CollectionItem) return true;
|
|
1408
|
+
// check for implicit key
|
|
1409
|
+
let offset = node.range.end;
|
|
1410
|
+
if (src[offset] === '\n' || src[offset - 1] === '\n') return false;
|
|
1411
|
+
offset = Node.endOfWhiteSpace(src, offset);
|
|
1412
|
+
return src[offset] === ':';
|
|
1413
|
+
}
|
|
1730
1414
|
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
if (src[inEnd] !== '#' && !Node.nextNodeIsIndented(src[inEnd], indentDiff, !noIndicatorAsIndent)) break;
|
|
1771
|
-
this.atLineStart = true;
|
|
1772
|
-
this.lineStart = lineStart;
|
|
1773
|
-
lineHasProps = false;
|
|
1774
|
-
offset = inEnd;
|
|
1775
|
-
} else if (ch === Char.COMMENT) {
|
|
1776
|
-
var end = Node.endOfLine(src, offset + 1);
|
|
1777
|
-
props.push(new Range(offset, end));
|
|
1778
|
-
offset = end;
|
|
1779
|
-
} else {
|
|
1780
|
-
var _end = Node.endOfIdentifier(src, offset + 1);
|
|
1781
|
-
|
|
1782
|
-
if (ch === Char.TAG && src[_end] === ',' && /^[a-zA-Z0-9-]+\.[a-zA-Z0-9-]+,\d\d\d\d(-\d\d){0,2}\/\S/.test(src.slice(offset + 1, _end + 13))) {
|
|
1783
|
-
// Let's presume we're dealing with a YAML 1.0 domain tag here, rather
|
|
1784
|
-
// than an empty but 'foo.bar' private-tagged node in a flow collection
|
|
1785
|
-
// followed without whitespace by a plain string starting with a year
|
|
1786
|
-
// or date divided by something.
|
|
1787
|
-
_end = Node.endOfIdentifier(src, _end + 5);
|
|
1788
|
-
}
|
|
1789
|
-
|
|
1790
|
-
props.push(new Range(offset, _end));
|
|
1791
|
-
lineHasProps = true;
|
|
1792
|
-
offset = Node.endOfWhiteSpace(src, _end);
|
|
1415
|
+
// Anchor and tag are before type, which determines the node implementation
|
|
1416
|
+
// class; hence this intermediate step.
|
|
1417
|
+
parseProps(offset) {
|
|
1418
|
+
const {
|
|
1419
|
+
inFlow,
|
|
1420
|
+
parent,
|
|
1421
|
+
src
|
|
1422
|
+
} = this;
|
|
1423
|
+
const props = [];
|
|
1424
|
+
let lineHasProps = false;
|
|
1425
|
+
offset = this.atLineStart ? Node.endOfIndent(src, offset) : Node.endOfWhiteSpace(src, offset);
|
|
1426
|
+
let ch = src[offset];
|
|
1427
|
+
while (ch === Char.ANCHOR || ch === Char.COMMENT || ch === Char.TAG || ch === '\n') {
|
|
1428
|
+
if (ch === '\n') {
|
|
1429
|
+
let inEnd = offset;
|
|
1430
|
+
let lineStart;
|
|
1431
|
+
do {
|
|
1432
|
+
lineStart = inEnd + 1;
|
|
1433
|
+
inEnd = Node.endOfIndent(src, lineStart);
|
|
1434
|
+
} while (src[inEnd] === '\n');
|
|
1435
|
+
const indentDiff = inEnd - (lineStart + this.indent);
|
|
1436
|
+
const noIndicatorAsIndent = parent.type === Type.SEQ_ITEM && parent.context.atLineStart;
|
|
1437
|
+
if (src[inEnd] !== '#' && !Node.nextNodeIsIndented(src[inEnd], indentDiff, !noIndicatorAsIndent)) break;
|
|
1438
|
+
this.atLineStart = true;
|
|
1439
|
+
this.lineStart = lineStart;
|
|
1440
|
+
lineHasProps = false;
|
|
1441
|
+
offset = inEnd;
|
|
1442
|
+
} else if (ch === Char.COMMENT) {
|
|
1443
|
+
const end = Node.endOfLine(src, offset + 1);
|
|
1444
|
+
props.push(new Range(offset, end));
|
|
1445
|
+
offset = end;
|
|
1446
|
+
} else {
|
|
1447
|
+
let end = Node.endOfIdentifier(src, offset + 1);
|
|
1448
|
+
if (ch === Char.TAG && src[end] === ',' && /^[a-zA-Z0-9-]+\.[a-zA-Z0-9-]+,\d\d\d\d(-\d\d){0,2}\/\S/.test(src.slice(offset + 1, end + 13))) {
|
|
1449
|
+
// Let's presume we're dealing with a YAML 1.0 domain tag here, rather
|
|
1450
|
+
// than an empty but 'foo.bar' private-tagged node in a flow collection
|
|
1451
|
+
// followed without whitespace by a plain string starting with a year
|
|
1452
|
+
// or date divided by something.
|
|
1453
|
+
end = Node.endOfIdentifier(src, end + 5);
|
|
1793
1454
|
}
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
if (lineHasProps && ch === ':' && Node.atBlank(src, offset + 1, true)) offset -= 1;
|
|
1800
|
-
var type = ParseContext.parseType(src, offset, inFlow);
|
|
1801
|
-
return {
|
|
1802
|
-
props: props,
|
|
1803
|
-
type: type,
|
|
1804
|
-
valueStart: offset
|
|
1805
|
-
};
|
|
1806
|
-
}
|
|
1807
|
-
/**
|
|
1808
|
-
* Parses a node from the source
|
|
1809
|
-
* @param {ParseContext} overlay
|
|
1810
|
-
* @param {number} start - Index of first non-whitespace character for the node
|
|
1811
|
-
* @returns {?Node} - null if at a document boundary
|
|
1812
|
-
*/
|
|
1813
|
-
|
|
1814
|
-
}], [{
|
|
1815
|
-
key: "parseType",
|
|
1816
|
-
value: function parseType(src, offset, inFlow) {
|
|
1817
|
-
switch (src[offset]) {
|
|
1818
|
-
case '*':
|
|
1819
|
-
return Type.ALIAS;
|
|
1820
|
-
|
|
1821
|
-
case '>':
|
|
1822
|
-
return Type.BLOCK_FOLDED;
|
|
1823
|
-
|
|
1824
|
-
case '|':
|
|
1825
|
-
return Type.BLOCK_LITERAL;
|
|
1826
|
-
|
|
1827
|
-
case '{':
|
|
1828
|
-
return Type.FLOW_MAP;
|
|
1829
|
-
|
|
1830
|
-
case '[':
|
|
1831
|
-
return Type.FLOW_SEQ;
|
|
1832
|
-
|
|
1833
|
-
case '?':
|
|
1834
|
-
return !inFlow && Node.atBlank(src, offset + 1, true) ? Type.MAP_KEY : Type.PLAIN;
|
|
1835
|
-
|
|
1836
|
-
case ':':
|
|
1837
|
-
return !inFlow && Node.atBlank(src, offset + 1, true) ? Type.MAP_VALUE : Type.PLAIN;
|
|
1838
|
-
|
|
1839
|
-
case '-':
|
|
1840
|
-
return !inFlow && Node.atBlank(src, offset + 1, true) ? Type.SEQ_ITEM : Type.PLAIN;
|
|
1841
|
-
|
|
1842
|
-
case '"':
|
|
1843
|
-
return Type.QUOTE_DOUBLE;
|
|
1844
|
-
|
|
1845
|
-
case "'":
|
|
1846
|
-
return Type.QUOTE_SINGLE;
|
|
1847
|
-
|
|
1848
|
-
default:
|
|
1849
|
-
return Type.PLAIN;
|
|
1455
|
+
props.push(new Range(offset, end));
|
|
1456
|
+
lineHasProps = true;
|
|
1457
|
+
offset = Node.endOfWhiteSpace(src, end);
|
|
1850
1458
|
}
|
|
1459
|
+
ch = src[offset];
|
|
1851
1460
|
}
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1461
|
+
// '- &a : b' has an anchor on an empty node
|
|
1462
|
+
if (lineHasProps && ch === ':' && Node.atBlank(src, offset + 1, true)) offset -= 1;
|
|
1463
|
+
const type = ParseContext.parseType(src, offset, inFlow);
|
|
1464
|
+
return {
|
|
1465
|
+
props,
|
|
1466
|
+
type,
|
|
1467
|
+
valueStart: offset
|
|
1468
|
+
};
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1856
1471
|
|
|
1857
1472
|
// Published as 'yaml/parse-cst'
|
|
1858
1473
|
function parse(src) {
|
|
1859
|
-
|
|
1860
|
-
|
|
1474
|
+
const cr = [];
|
|
1861
1475
|
if (src.indexOf('\r') !== -1) {
|
|
1862
|
-
src = src.replace(/\r\n?/g,
|
|
1476
|
+
src = src.replace(/\r\n?/g, (match, offset) => {
|
|
1863
1477
|
if (match.length > 1) cr.push(offset);
|
|
1864
1478
|
return '\n';
|
|
1865
1479
|
});
|
|
1866
1480
|
}
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
var offset = 0;
|
|
1870
|
-
|
|
1481
|
+
const documents = [];
|
|
1482
|
+
let offset = 0;
|
|
1871
1483
|
do {
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
src
|
|
1484
|
+
const doc = new Document();
|
|
1485
|
+
const context = new ParseContext({
|
|
1486
|
+
src
|
|
1875
1487
|
});
|
|
1876
1488
|
offset = doc.parse(context, offset);
|
|
1877
1489
|
documents.push(doc);
|
|
1878
1490
|
} while (offset < src.length);
|
|
1879
|
-
|
|
1880
|
-
documents.setOrigRanges = function () {
|
|
1491
|
+
documents.setOrigRanges = () => {
|
|
1881
1492
|
if (cr.length === 0) return false;
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
var crOffset = 0;
|
|
1888
|
-
|
|
1889
|
-
for (var _i = 0; _i < documents.length; ++_i) {
|
|
1890
|
-
crOffset = documents[_i].setOrigRanges(cr, crOffset);
|
|
1493
|
+
for (let i = 1; i < cr.length; ++i) cr[i] -= i;
|
|
1494
|
+
let crOffset = 0;
|
|
1495
|
+
for (let i = 0; i < documents.length; ++i) {
|
|
1496
|
+
crOffset = documents[i].setOrigRanges(cr, crOffset);
|
|
1891
1497
|
}
|
|
1892
|
-
|
|
1893
1498
|
cr.splice(0, cr.length);
|
|
1894
1499
|
return true;
|
|
1895
1500
|
};
|
|
1896
|
-
|
|
1897
|
-
documents.toString = function () {
|
|
1898
|
-
return documents.join('...\n');
|
|
1899
|
-
};
|
|
1900
|
-
|
|
1501
|
+
documents.toString = () => documents.join('...\n');
|
|
1901
1502
|
return documents;
|
|
1902
1503
|
}
|
|
1903
1504
|
|