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
|
@@ -0,0 +1,751 @@
|
|
|
1
|
+
const Char = {
|
|
2
|
+
ANCHOR: '&',
|
|
3
|
+
COMMENT: '#',
|
|
4
|
+
TAG: '!',
|
|
5
|
+
DIRECTIVES_END: '-',
|
|
6
|
+
DOCUMENT_END: '.'
|
|
7
|
+
};
|
|
8
|
+
const Type = {
|
|
9
|
+
ALIAS: 'ALIAS',
|
|
10
|
+
BLANK_LINE: 'BLANK_LINE',
|
|
11
|
+
BLOCK_FOLDED: 'BLOCK_FOLDED',
|
|
12
|
+
BLOCK_LITERAL: 'BLOCK_LITERAL',
|
|
13
|
+
COMMENT: 'COMMENT',
|
|
14
|
+
DIRECTIVE: 'DIRECTIVE',
|
|
15
|
+
DOCUMENT: 'DOCUMENT',
|
|
16
|
+
FLOW_MAP: 'FLOW_MAP',
|
|
17
|
+
FLOW_SEQ: 'FLOW_SEQ',
|
|
18
|
+
MAP: 'MAP',
|
|
19
|
+
MAP_KEY: 'MAP_KEY',
|
|
20
|
+
MAP_VALUE: 'MAP_VALUE',
|
|
21
|
+
PLAIN: 'PLAIN',
|
|
22
|
+
QUOTE_DOUBLE: 'QUOTE_DOUBLE',
|
|
23
|
+
QUOTE_SINGLE: 'QUOTE_SINGLE',
|
|
24
|
+
SEQ: 'SEQ',
|
|
25
|
+
SEQ_ITEM: 'SEQ_ITEM'
|
|
26
|
+
};
|
|
27
|
+
const defaultTagPrefix = 'tag:yaml.org,2002:';
|
|
28
|
+
const defaultTags = {
|
|
29
|
+
MAP: 'tag:yaml.org,2002:map',
|
|
30
|
+
SEQ: 'tag:yaml.org,2002:seq',
|
|
31
|
+
STR: 'tag:yaml.org,2002:str'
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
function findLineStarts(src) {
|
|
35
|
+
const ls = [0];
|
|
36
|
+
let offset = src.indexOf('\n');
|
|
37
|
+
while (offset !== -1) {
|
|
38
|
+
offset += 1;
|
|
39
|
+
ls.push(offset);
|
|
40
|
+
offset = src.indexOf('\n', offset);
|
|
41
|
+
}
|
|
42
|
+
return ls;
|
|
43
|
+
}
|
|
44
|
+
function getSrcInfo(cst) {
|
|
45
|
+
let lineStarts, src;
|
|
46
|
+
if (typeof cst === 'string') {
|
|
47
|
+
lineStarts = findLineStarts(cst);
|
|
48
|
+
src = cst;
|
|
49
|
+
} else {
|
|
50
|
+
if (Array.isArray(cst)) cst = cst[0];
|
|
51
|
+
if (cst && cst.context) {
|
|
52
|
+
if (!cst.lineStarts) cst.lineStarts = findLineStarts(cst.context.src);
|
|
53
|
+
lineStarts = cst.lineStarts;
|
|
54
|
+
src = cst.context.src;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
lineStarts,
|
|
59
|
+
src
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @typedef {Object} LinePos - One-indexed position in the source
|
|
65
|
+
* @property {number} line
|
|
66
|
+
* @property {number} col
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Determine the line/col position matching a character offset.
|
|
71
|
+
*
|
|
72
|
+
* Accepts a source string or a CST document as the second parameter. With
|
|
73
|
+
* the latter, starting indices for lines are cached in the document as
|
|
74
|
+
* `lineStarts: number[]`.
|
|
75
|
+
*
|
|
76
|
+
* Returns a one-indexed `{ line, col }` location if found, or
|
|
77
|
+
* `undefined` otherwise.
|
|
78
|
+
*
|
|
79
|
+
* @param {number} offset
|
|
80
|
+
* @param {string|Document|Document[]} cst
|
|
81
|
+
* @returns {?LinePos}
|
|
82
|
+
*/
|
|
83
|
+
function getLinePos(offset, cst) {
|
|
84
|
+
if (typeof offset !== 'number' || offset < 0) return null;
|
|
85
|
+
const {
|
|
86
|
+
lineStarts,
|
|
87
|
+
src
|
|
88
|
+
} = getSrcInfo(cst);
|
|
89
|
+
if (!lineStarts || !src || offset > src.length) return null;
|
|
90
|
+
for (let i = 0; i < lineStarts.length; ++i) {
|
|
91
|
+
const start = lineStarts[i];
|
|
92
|
+
if (offset < start) {
|
|
93
|
+
return {
|
|
94
|
+
line: i,
|
|
95
|
+
col: offset - lineStarts[i - 1] + 1
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
if (offset === start) return {
|
|
99
|
+
line: i + 1,
|
|
100
|
+
col: 1
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
const line = lineStarts.length;
|
|
104
|
+
return {
|
|
105
|
+
line,
|
|
106
|
+
col: offset - lineStarts[line - 1] + 1
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Get a specified line from the source.
|
|
112
|
+
*
|
|
113
|
+
* Accepts a source string or a CST document as the second parameter. With
|
|
114
|
+
* the latter, starting indices for lines are cached in the document as
|
|
115
|
+
* `lineStarts: number[]`.
|
|
116
|
+
*
|
|
117
|
+
* Returns the line as a string if found, or `null` otherwise.
|
|
118
|
+
*
|
|
119
|
+
* @param {number} line One-indexed line number
|
|
120
|
+
* @param {string|Document|Document[]} cst
|
|
121
|
+
* @returns {?string}
|
|
122
|
+
*/
|
|
123
|
+
function getLine(line, cst) {
|
|
124
|
+
const {
|
|
125
|
+
lineStarts,
|
|
126
|
+
src
|
|
127
|
+
} = getSrcInfo(cst);
|
|
128
|
+
if (!lineStarts || !(line >= 1) || line > lineStarts.length) return null;
|
|
129
|
+
const start = lineStarts[line - 1];
|
|
130
|
+
let end = lineStarts[line]; // undefined for last line; that's ok for slice()
|
|
131
|
+
while (end && end > start && src[end - 1] === '\n') --end;
|
|
132
|
+
return src.slice(start, end);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Pretty-print the starting line from the source indicated by the range `pos`
|
|
137
|
+
*
|
|
138
|
+
* Trims output to `maxWidth` chars while keeping the starting column visible,
|
|
139
|
+
* using `…` at either end to indicate dropped characters.
|
|
140
|
+
*
|
|
141
|
+
* Returns a two-line string (or `null`) with `\n` as separator; the second line
|
|
142
|
+
* will hold appropriately indented `^` marks indicating the column range.
|
|
143
|
+
*
|
|
144
|
+
* @param {Object} pos
|
|
145
|
+
* @param {LinePos} pos.start
|
|
146
|
+
* @param {LinePos} [pos.end]
|
|
147
|
+
* @param {string|Document|Document[]*} cst
|
|
148
|
+
* @param {number} [maxWidth=80]
|
|
149
|
+
* @returns {?string}
|
|
150
|
+
*/
|
|
151
|
+
function getPrettyContext({
|
|
152
|
+
start,
|
|
153
|
+
end
|
|
154
|
+
}, cst, maxWidth = 80) {
|
|
155
|
+
let src = getLine(start.line, cst);
|
|
156
|
+
if (!src) return null;
|
|
157
|
+
let {
|
|
158
|
+
col
|
|
159
|
+
} = start;
|
|
160
|
+
if (src.length > maxWidth) {
|
|
161
|
+
if (col <= maxWidth - 10) {
|
|
162
|
+
src = src.substr(0, maxWidth - 1) + '…';
|
|
163
|
+
} else {
|
|
164
|
+
const halfWidth = Math.round(maxWidth / 2);
|
|
165
|
+
if (src.length > col + halfWidth) src = src.substr(0, col + halfWidth - 1) + '…';
|
|
166
|
+
col -= src.length - maxWidth;
|
|
167
|
+
src = '…' + src.substr(1 - maxWidth);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
let errLen = 1;
|
|
171
|
+
let errEnd = '';
|
|
172
|
+
if (end) {
|
|
173
|
+
if (end.line === start.line && col + (end.col - start.col) <= maxWidth + 1) {
|
|
174
|
+
errLen = end.col - start.col;
|
|
175
|
+
} else {
|
|
176
|
+
errLen = Math.min(src.length + 1, maxWidth) - col;
|
|
177
|
+
errEnd = '…';
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
const offset = col > 1 ? ' '.repeat(col - 1) : '';
|
|
181
|
+
const err = '^'.repeat(errLen);
|
|
182
|
+
return `${src}\n${offset}${err}${errEnd}`;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
class Range {
|
|
186
|
+
static copy(orig) {
|
|
187
|
+
return new Range(orig.start, orig.end);
|
|
188
|
+
}
|
|
189
|
+
constructor(start, end) {
|
|
190
|
+
this.start = start;
|
|
191
|
+
this.end = end || start;
|
|
192
|
+
}
|
|
193
|
+
isEmpty() {
|
|
194
|
+
return typeof this.start !== 'number' || !this.end || this.end <= this.start;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Set `origStart` and `origEnd` to point to the original source range for
|
|
199
|
+
* this node, which may differ due to dropped CR characters.
|
|
200
|
+
*
|
|
201
|
+
* @param {number[]} cr - Positions of dropped CR characters
|
|
202
|
+
* @param {number} offset - Starting index of `cr` from the last call
|
|
203
|
+
* @returns {number} - The next offset, matching the one found for `origStart`
|
|
204
|
+
*/
|
|
205
|
+
setOrigRange(cr, offset) {
|
|
206
|
+
const {
|
|
207
|
+
start,
|
|
208
|
+
end
|
|
209
|
+
} = this;
|
|
210
|
+
if (cr.length === 0 || end <= cr[0]) {
|
|
211
|
+
this.origStart = start;
|
|
212
|
+
this.origEnd = end;
|
|
213
|
+
return offset;
|
|
214
|
+
}
|
|
215
|
+
let i = offset;
|
|
216
|
+
while (i < cr.length) {
|
|
217
|
+
if (cr[i] > start) break;else ++i;
|
|
218
|
+
}
|
|
219
|
+
this.origStart = start + i;
|
|
220
|
+
const nextOffset = i;
|
|
221
|
+
while (i < cr.length) {
|
|
222
|
+
// if end was at \n, it should now be at \r
|
|
223
|
+
if (cr[i] >= end) break;else ++i;
|
|
224
|
+
}
|
|
225
|
+
this.origEnd = end + i;
|
|
226
|
+
return nextOffset;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** Root class of all nodes */
|
|
231
|
+
class Node {
|
|
232
|
+
static addStringTerminator(src, offset, str) {
|
|
233
|
+
if (str[str.length - 1] === '\n') return str;
|
|
234
|
+
const next = Node.endOfWhiteSpace(src, offset);
|
|
235
|
+
return next >= src.length || src[next] === '\n' ? str + '\n' : str;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// ^(---|...)
|
|
239
|
+
static atDocumentBoundary(src, offset, sep) {
|
|
240
|
+
const ch0 = src[offset];
|
|
241
|
+
if (!ch0) return true;
|
|
242
|
+
const prev = src[offset - 1];
|
|
243
|
+
if (prev && prev !== '\n') return false;
|
|
244
|
+
if (sep) {
|
|
245
|
+
if (ch0 !== sep) return false;
|
|
246
|
+
} else {
|
|
247
|
+
if (ch0 !== Char.DIRECTIVES_END && ch0 !== Char.DOCUMENT_END) return false;
|
|
248
|
+
}
|
|
249
|
+
const ch1 = src[offset + 1];
|
|
250
|
+
const ch2 = src[offset + 2];
|
|
251
|
+
if (ch1 !== ch0 || ch2 !== ch0) return false;
|
|
252
|
+
const ch3 = src[offset + 3];
|
|
253
|
+
return !ch3 || ch3 === '\n' || ch3 === '\t' || ch3 === ' ';
|
|
254
|
+
}
|
|
255
|
+
static endOfIdentifier(src, offset) {
|
|
256
|
+
let ch = src[offset];
|
|
257
|
+
const isVerbatim = ch === '<';
|
|
258
|
+
const notOk = isVerbatim ? ['\n', '\t', ' ', '>'] : ['\n', '\t', ' ', '[', ']', '{', '}', ','];
|
|
259
|
+
while (ch && notOk.indexOf(ch) === -1) ch = src[offset += 1];
|
|
260
|
+
if (isVerbatim && ch === '>') offset += 1;
|
|
261
|
+
return offset;
|
|
262
|
+
}
|
|
263
|
+
static endOfIndent(src, offset) {
|
|
264
|
+
let ch = src[offset];
|
|
265
|
+
while (ch === ' ') ch = src[offset += 1];
|
|
266
|
+
return offset;
|
|
267
|
+
}
|
|
268
|
+
static endOfLine(src, offset) {
|
|
269
|
+
let ch = src[offset];
|
|
270
|
+
while (ch && ch !== '\n') ch = src[offset += 1];
|
|
271
|
+
return offset;
|
|
272
|
+
}
|
|
273
|
+
static endOfWhiteSpace(src, offset) {
|
|
274
|
+
let ch = src[offset];
|
|
275
|
+
while (ch === '\t' || ch === ' ') ch = src[offset += 1];
|
|
276
|
+
return offset;
|
|
277
|
+
}
|
|
278
|
+
static startOfLine(src, offset) {
|
|
279
|
+
let ch = src[offset - 1];
|
|
280
|
+
if (ch === '\n') return offset;
|
|
281
|
+
while (ch && ch !== '\n') ch = src[offset -= 1];
|
|
282
|
+
return offset + 1;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* End of indentation, or null if the line's indent level is not more
|
|
287
|
+
* than `indent`
|
|
288
|
+
*
|
|
289
|
+
* @param {string} src
|
|
290
|
+
* @param {number} indent
|
|
291
|
+
* @param {number} lineStart
|
|
292
|
+
* @returns {?number}
|
|
293
|
+
*/
|
|
294
|
+
static endOfBlockIndent(src, indent, lineStart) {
|
|
295
|
+
const inEnd = Node.endOfIndent(src, lineStart);
|
|
296
|
+
if (inEnd > lineStart + indent) {
|
|
297
|
+
return inEnd;
|
|
298
|
+
} else {
|
|
299
|
+
const wsEnd = Node.endOfWhiteSpace(src, inEnd);
|
|
300
|
+
const ch = src[wsEnd];
|
|
301
|
+
if (!ch || ch === '\n') return wsEnd;
|
|
302
|
+
}
|
|
303
|
+
return null;
|
|
304
|
+
}
|
|
305
|
+
static atBlank(src, offset, endAsBlank) {
|
|
306
|
+
const ch = src[offset];
|
|
307
|
+
return ch === '\n' || ch === '\t' || ch === ' ' || endAsBlank && !ch;
|
|
308
|
+
}
|
|
309
|
+
static nextNodeIsIndented(ch, indentDiff, indicatorAsIndent) {
|
|
310
|
+
if (!ch || indentDiff < 0) return false;
|
|
311
|
+
if (indentDiff > 0) return true;
|
|
312
|
+
return indicatorAsIndent && ch === '-';
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// should be at line or string end, or at next non-whitespace char
|
|
316
|
+
static normalizeOffset(src, offset) {
|
|
317
|
+
const ch = src[offset];
|
|
318
|
+
return !ch ? offset : ch !== '\n' && src[offset - 1] === '\n' ? offset - 1 : Node.endOfWhiteSpace(src, offset);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// fold single newline into space, multiple newlines to N - 1 newlines
|
|
322
|
+
// presumes src[offset] === '\n'
|
|
323
|
+
static foldNewline(src, offset, indent) {
|
|
324
|
+
let inCount = 0;
|
|
325
|
+
let error = false;
|
|
326
|
+
let fold = '';
|
|
327
|
+
let ch = src[offset + 1];
|
|
328
|
+
while (ch === ' ' || ch === '\t' || ch === '\n') {
|
|
329
|
+
switch (ch) {
|
|
330
|
+
case '\n':
|
|
331
|
+
inCount = 0;
|
|
332
|
+
offset += 1;
|
|
333
|
+
fold += '\n';
|
|
334
|
+
break;
|
|
335
|
+
case '\t':
|
|
336
|
+
if (inCount <= indent) error = true;
|
|
337
|
+
offset = Node.endOfWhiteSpace(src, offset + 2) - 1;
|
|
338
|
+
break;
|
|
339
|
+
case ' ':
|
|
340
|
+
inCount += 1;
|
|
341
|
+
offset += 1;
|
|
342
|
+
break;
|
|
343
|
+
}
|
|
344
|
+
ch = src[offset + 1];
|
|
345
|
+
}
|
|
346
|
+
if (!fold) fold = ' ';
|
|
347
|
+
if (ch && inCount <= indent) error = true;
|
|
348
|
+
return {
|
|
349
|
+
fold,
|
|
350
|
+
offset,
|
|
351
|
+
error
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
constructor(type, props, context) {
|
|
355
|
+
Object.defineProperty(this, 'context', {
|
|
356
|
+
value: context || null,
|
|
357
|
+
writable: true
|
|
358
|
+
});
|
|
359
|
+
this.error = null;
|
|
360
|
+
this.range = null;
|
|
361
|
+
this.valueRange = null;
|
|
362
|
+
this.props = props || [];
|
|
363
|
+
this.type = type;
|
|
364
|
+
this.value = null;
|
|
365
|
+
}
|
|
366
|
+
getPropValue(idx, key, skipKey) {
|
|
367
|
+
if (!this.context) return null;
|
|
368
|
+
const {
|
|
369
|
+
src
|
|
370
|
+
} = this.context;
|
|
371
|
+
const prop = this.props[idx];
|
|
372
|
+
return prop && src[prop.start] === key ? src.slice(prop.start + (skipKey ? 1 : 0), prop.end) : null;
|
|
373
|
+
}
|
|
374
|
+
get anchor() {
|
|
375
|
+
for (let i = 0; i < this.props.length; ++i) {
|
|
376
|
+
const anchor = this.getPropValue(i, Char.ANCHOR, true);
|
|
377
|
+
if (anchor != null) return anchor;
|
|
378
|
+
}
|
|
379
|
+
return null;
|
|
380
|
+
}
|
|
381
|
+
get comment() {
|
|
382
|
+
const comments = [];
|
|
383
|
+
for (let i = 0; i < this.props.length; ++i) {
|
|
384
|
+
const comment = this.getPropValue(i, Char.COMMENT, true);
|
|
385
|
+
if (comment != null) comments.push(comment);
|
|
386
|
+
}
|
|
387
|
+
return comments.length > 0 ? comments.join('\n') : null;
|
|
388
|
+
}
|
|
389
|
+
commentHasRequiredWhitespace(start) {
|
|
390
|
+
const {
|
|
391
|
+
src
|
|
392
|
+
} = this.context;
|
|
393
|
+
if (this.header && start === this.header.end) return false;
|
|
394
|
+
if (!this.valueRange) return false;
|
|
395
|
+
const {
|
|
396
|
+
end
|
|
397
|
+
} = this.valueRange;
|
|
398
|
+
return start !== end || Node.atBlank(src, end - 1);
|
|
399
|
+
}
|
|
400
|
+
get hasComment() {
|
|
401
|
+
if (this.context) {
|
|
402
|
+
const {
|
|
403
|
+
src
|
|
404
|
+
} = this.context;
|
|
405
|
+
for (let i = 0; i < this.props.length; ++i) {
|
|
406
|
+
if (src[this.props[i].start] === Char.COMMENT) return true;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
return false;
|
|
410
|
+
}
|
|
411
|
+
get hasProps() {
|
|
412
|
+
if (this.context) {
|
|
413
|
+
const {
|
|
414
|
+
src
|
|
415
|
+
} = this.context;
|
|
416
|
+
for (let i = 0; i < this.props.length; ++i) {
|
|
417
|
+
if (src[this.props[i].start] !== Char.COMMENT) return true;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
return false;
|
|
421
|
+
}
|
|
422
|
+
get includesTrailingLines() {
|
|
423
|
+
return false;
|
|
424
|
+
}
|
|
425
|
+
get jsonLike() {
|
|
426
|
+
const jsonLikeTypes = [Type.FLOW_MAP, Type.FLOW_SEQ, Type.QUOTE_DOUBLE, Type.QUOTE_SINGLE];
|
|
427
|
+
return jsonLikeTypes.indexOf(this.type) !== -1;
|
|
428
|
+
}
|
|
429
|
+
get rangeAsLinePos() {
|
|
430
|
+
if (!this.range || !this.context) return undefined;
|
|
431
|
+
const start = getLinePos(this.range.start, this.context.root);
|
|
432
|
+
if (!start) return undefined;
|
|
433
|
+
const end = getLinePos(this.range.end, this.context.root);
|
|
434
|
+
return {
|
|
435
|
+
start,
|
|
436
|
+
end
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
get rawValue() {
|
|
440
|
+
if (!this.valueRange || !this.context) return null;
|
|
441
|
+
const {
|
|
442
|
+
start,
|
|
443
|
+
end
|
|
444
|
+
} = this.valueRange;
|
|
445
|
+
return this.context.src.slice(start, end);
|
|
446
|
+
}
|
|
447
|
+
get tag() {
|
|
448
|
+
for (let i = 0; i < this.props.length; ++i) {
|
|
449
|
+
const tag = this.getPropValue(i, Char.TAG, false);
|
|
450
|
+
if (tag != null) {
|
|
451
|
+
if (tag[1] === '<') {
|
|
452
|
+
return {
|
|
453
|
+
verbatim: tag.slice(2, -1)
|
|
454
|
+
};
|
|
455
|
+
} else {
|
|
456
|
+
// eslint-disable-next-line no-unused-vars
|
|
457
|
+
const [_, handle, suffix] = tag.match(/^(.*!)([^!]*)$/);
|
|
458
|
+
return {
|
|
459
|
+
handle,
|
|
460
|
+
suffix
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
return null;
|
|
466
|
+
}
|
|
467
|
+
get valueRangeContainsNewline() {
|
|
468
|
+
if (!this.valueRange || !this.context) return false;
|
|
469
|
+
const {
|
|
470
|
+
start,
|
|
471
|
+
end
|
|
472
|
+
} = this.valueRange;
|
|
473
|
+
const {
|
|
474
|
+
src
|
|
475
|
+
} = this.context;
|
|
476
|
+
for (let i = start; i < end; ++i) {
|
|
477
|
+
if (src[i] === '\n') return true;
|
|
478
|
+
}
|
|
479
|
+
return false;
|
|
480
|
+
}
|
|
481
|
+
parseComment(start) {
|
|
482
|
+
const {
|
|
483
|
+
src
|
|
484
|
+
} = this.context;
|
|
485
|
+
if (src[start] === Char.COMMENT) {
|
|
486
|
+
const end = Node.endOfLine(src, start + 1);
|
|
487
|
+
const commentRange = new Range(start, end);
|
|
488
|
+
this.props.push(commentRange);
|
|
489
|
+
return end;
|
|
490
|
+
}
|
|
491
|
+
return start;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Populates the `origStart` and `origEnd` values of all ranges for this
|
|
496
|
+
* node. Extended by child classes to handle descendant nodes.
|
|
497
|
+
*
|
|
498
|
+
* @param {number[]} cr - Positions of dropped CR characters
|
|
499
|
+
* @param {number} offset - Starting index of `cr` from the last call
|
|
500
|
+
* @returns {number} - The next offset, matching the one found for `origStart`
|
|
501
|
+
*/
|
|
502
|
+
setOrigRanges(cr, offset) {
|
|
503
|
+
if (this.range) offset = this.range.setOrigRange(cr, offset);
|
|
504
|
+
if (this.valueRange) this.valueRange.setOrigRange(cr, offset);
|
|
505
|
+
this.props.forEach(prop => prop.setOrigRange(cr, offset));
|
|
506
|
+
return offset;
|
|
507
|
+
}
|
|
508
|
+
toString() {
|
|
509
|
+
const {
|
|
510
|
+
context: {
|
|
511
|
+
src
|
|
512
|
+
},
|
|
513
|
+
range,
|
|
514
|
+
value
|
|
515
|
+
} = this;
|
|
516
|
+
if (value != null) return value;
|
|
517
|
+
const str = src.slice(range.start, range.end);
|
|
518
|
+
return Node.addStringTerminator(src, range.end, str);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
class YAMLError extends Error {
|
|
523
|
+
constructor(name, source, message) {
|
|
524
|
+
if (!message || !(source instanceof Node)) throw new Error(`Invalid arguments for new ${name}`);
|
|
525
|
+
super();
|
|
526
|
+
this.name = name;
|
|
527
|
+
this.message = message;
|
|
528
|
+
this.source = source;
|
|
529
|
+
}
|
|
530
|
+
makePretty() {
|
|
531
|
+
if (!this.source) return;
|
|
532
|
+
this.nodeType = this.source.type;
|
|
533
|
+
const cst = this.source.context && this.source.context.root;
|
|
534
|
+
if (typeof this.offset === 'number') {
|
|
535
|
+
this.range = new Range(this.offset, this.offset + 1);
|
|
536
|
+
const start = cst && getLinePos(this.offset, cst);
|
|
537
|
+
if (start) {
|
|
538
|
+
const end = {
|
|
539
|
+
line: start.line,
|
|
540
|
+
col: start.col + 1
|
|
541
|
+
};
|
|
542
|
+
this.linePos = {
|
|
543
|
+
start,
|
|
544
|
+
end
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
delete this.offset;
|
|
548
|
+
} else {
|
|
549
|
+
this.range = this.source.range;
|
|
550
|
+
this.linePos = this.source.rangeAsLinePos;
|
|
551
|
+
}
|
|
552
|
+
if (this.linePos) {
|
|
553
|
+
const {
|
|
554
|
+
line,
|
|
555
|
+
col
|
|
556
|
+
} = this.linePos.start;
|
|
557
|
+
this.message += ` at line ${line}, column ${col}`;
|
|
558
|
+
const ctx = cst && getPrettyContext(this.linePos, cst);
|
|
559
|
+
if (ctx) this.message += `:\n\n${ctx}\n`;
|
|
560
|
+
}
|
|
561
|
+
delete this.source;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
class YAMLReferenceError extends YAMLError {
|
|
565
|
+
constructor(source, message) {
|
|
566
|
+
super('YAMLReferenceError', source, message);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
class YAMLSemanticError extends YAMLError {
|
|
570
|
+
constructor(source, message) {
|
|
571
|
+
super('YAMLSemanticError', source, message);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
class YAMLSyntaxError extends YAMLError {
|
|
575
|
+
constructor(source, message) {
|
|
576
|
+
super('YAMLSyntaxError', source, message);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
class YAMLWarning extends YAMLError {
|
|
580
|
+
constructor(source, message) {
|
|
581
|
+
super('YAMLWarning', source, message);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
function _defineProperty(e, r, t) {
|
|
586
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
587
|
+
value: t,
|
|
588
|
+
enumerable: !0,
|
|
589
|
+
configurable: !0,
|
|
590
|
+
writable: !0
|
|
591
|
+
}) : e[r] = t, e;
|
|
592
|
+
}
|
|
593
|
+
function _toPrimitive(t, r) {
|
|
594
|
+
if ("object" != typeof t || !t) return t;
|
|
595
|
+
var e = t[Symbol.toPrimitive];
|
|
596
|
+
if (void 0 !== e) {
|
|
597
|
+
var i = e.call(t, r || "default");
|
|
598
|
+
if ("object" != typeof i) return i;
|
|
599
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
600
|
+
}
|
|
601
|
+
return ("string" === r ? String : Number)(t);
|
|
602
|
+
}
|
|
603
|
+
function _toPropertyKey(t) {
|
|
604
|
+
var i = _toPrimitive(t, "string");
|
|
605
|
+
return "symbol" == typeof i ? i : i + "";
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
class PlainValue extends Node {
|
|
609
|
+
static endOfLine(src, start, inFlow) {
|
|
610
|
+
let ch = src[start];
|
|
611
|
+
let offset = start;
|
|
612
|
+
while (ch && ch !== '\n') {
|
|
613
|
+
if (inFlow && (ch === '[' || ch === ']' || ch === '{' || ch === '}' || ch === ',')) break;
|
|
614
|
+
const next = src[offset + 1];
|
|
615
|
+
if (ch === ':' && (!next || next === '\n' || next === '\t' || next === ' ' || inFlow && next === ',')) break;
|
|
616
|
+
if ((ch === ' ' || ch === '\t') && next === '#') break;
|
|
617
|
+
offset += 1;
|
|
618
|
+
ch = next;
|
|
619
|
+
}
|
|
620
|
+
return offset;
|
|
621
|
+
}
|
|
622
|
+
get strValue() {
|
|
623
|
+
if (!this.valueRange || !this.context) return null;
|
|
624
|
+
let {
|
|
625
|
+
start,
|
|
626
|
+
end
|
|
627
|
+
} = this.valueRange;
|
|
628
|
+
const {
|
|
629
|
+
src
|
|
630
|
+
} = this.context;
|
|
631
|
+
let ch = src[end - 1];
|
|
632
|
+
while (start < end && (ch === '\n' || ch === '\t' || ch === ' ')) ch = src[--end - 1];
|
|
633
|
+
let str = '';
|
|
634
|
+
for (let i = start; i < end; ++i) {
|
|
635
|
+
const ch = src[i];
|
|
636
|
+
if (ch === '\n') {
|
|
637
|
+
const {
|
|
638
|
+
fold,
|
|
639
|
+
offset
|
|
640
|
+
} = Node.foldNewline(src, i, -1);
|
|
641
|
+
str += fold;
|
|
642
|
+
i = offset;
|
|
643
|
+
} else if (ch === ' ' || ch === '\t') {
|
|
644
|
+
// trim trailing whitespace
|
|
645
|
+
const wsStart = i;
|
|
646
|
+
let next = src[i + 1];
|
|
647
|
+
while (i < end && (next === ' ' || next === '\t')) {
|
|
648
|
+
i += 1;
|
|
649
|
+
next = src[i + 1];
|
|
650
|
+
}
|
|
651
|
+
if (next !== '\n') str += i > wsStart ? src.slice(wsStart, i + 1) : ch;
|
|
652
|
+
} else {
|
|
653
|
+
str += ch;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
const ch0 = src[start];
|
|
657
|
+
switch (ch0) {
|
|
658
|
+
case '\t':
|
|
659
|
+
{
|
|
660
|
+
const msg = 'Plain value cannot start with a tab character';
|
|
661
|
+
const errors = [new YAMLSemanticError(this, msg)];
|
|
662
|
+
return {
|
|
663
|
+
errors,
|
|
664
|
+
str
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
case '@':
|
|
668
|
+
case '`':
|
|
669
|
+
{
|
|
670
|
+
const msg = `Plain value cannot start with reserved character ${ch0}`;
|
|
671
|
+
const errors = [new YAMLSemanticError(this, msg)];
|
|
672
|
+
return {
|
|
673
|
+
errors,
|
|
674
|
+
str
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
default:
|
|
678
|
+
return str;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
parseBlockValue(start) {
|
|
682
|
+
const {
|
|
683
|
+
indent,
|
|
684
|
+
inFlow,
|
|
685
|
+
src
|
|
686
|
+
} = this.context;
|
|
687
|
+
let offset = start;
|
|
688
|
+
let valueEnd = start;
|
|
689
|
+
for (let ch = src[offset]; ch === '\n'; ch = src[offset]) {
|
|
690
|
+
if (Node.atDocumentBoundary(src, offset + 1)) break;
|
|
691
|
+
const end = Node.endOfBlockIndent(src, indent, offset + 1);
|
|
692
|
+
if (end === null || src[end] === '#') break;
|
|
693
|
+
if (src[end] === '\n') {
|
|
694
|
+
offset = end;
|
|
695
|
+
} else {
|
|
696
|
+
valueEnd = PlainValue.endOfLine(src, end, inFlow);
|
|
697
|
+
offset = valueEnd;
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
if (this.valueRange.isEmpty()) this.valueRange.start = start;
|
|
701
|
+
this.valueRange.end = valueEnd;
|
|
702
|
+
return valueEnd;
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
/**
|
|
706
|
+
* Parses a plain value from the source
|
|
707
|
+
*
|
|
708
|
+
* Accepted forms are:
|
|
709
|
+
* ```
|
|
710
|
+
* #comment
|
|
711
|
+
*
|
|
712
|
+
* first line
|
|
713
|
+
*
|
|
714
|
+
* first line #comment
|
|
715
|
+
*
|
|
716
|
+
* first line
|
|
717
|
+
* block
|
|
718
|
+
* lines
|
|
719
|
+
*
|
|
720
|
+
* #comment
|
|
721
|
+
* block
|
|
722
|
+
* lines
|
|
723
|
+
* ```
|
|
724
|
+
* where block lines are empty or have an indent level greater than `indent`.
|
|
725
|
+
*
|
|
726
|
+
* @param {ParseContext} context
|
|
727
|
+
* @param {number} start - Index of first character
|
|
728
|
+
* @returns {number} - Index of the character after this scalar, may be `\n`
|
|
729
|
+
*/
|
|
730
|
+
parse(context, start) {
|
|
731
|
+
this.context = context;
|
|
732
|
+
const {
|
|
733
|
+
inFlow,
|
|
734
|
+
src
|
|
735
|
+
} = context;
|
|
736
|
+
let offset = start;
|
|
737
|
+
const ch = src[offset];
|
|
738
|
+
if (ch && ch !== '#' && ch !== '\n') {
|
|
739
|
+
offset = PlainValue.endOfLine(src, start, inFlow);
|
|
740
|
+
}
|
|
741
|
+
this.valueRange = new Range(start, offset);
|
|
742
|
+
offset = Node.endOfWhiteSpace(src, offset);
|
|
743
|
+
offset = this.parseComment(offset);
|
|
744
|
+
if (!this.hasComment || this.valueRange.isEmpty()) {
|
|
745
|
+
offset = this.parseBlockValue(offset);
|
|
746
|
+
}
|
|
747
|
+
return offset;
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
export { Char as C, Node as N, PlainValue as P, Range as R, Type as T, YAMLSyntaxError as Y, _defineProperty as _, YAMLWarning as a, YAMLSemanticError as b, YAMLError as c, defaultTagPrefix as d, defaultTags as e, YAMLReferenceError as f };
|