cdk8s-operator 0.1.407 → 0.1.409
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 +4 -4
- package/lib/operator.js +3 -3
- 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 +6 -6
- 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,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var PlainValue = require('./PlainValue-
|
|
3
|
+
var PlainValue = require('./PlainValue-516d5bc2.js');
|
|
4
4
|
|
|
5
5
|
function addCommentBefore(str, indent, comment) {
|
|
6
6
|
if (!comment) return str;
|
|
@@ -15,7 +15,6 @@ class Node {}
|
|
|
15
15
|
|
|
16
16
|
function toJSON(value, arg, ctx) {
|
|
17
17
|
if (Array.isArray(value)) return value.map((v, i) => toJSON(v, String(i), ctx));
|
|
18
|
-
|
|
19
18
|
if (value && typeof value.toJSON === 'function') {
|
|
20
19
|
const anchor = ctx && ctx.anchors && ctx.anchors.get(value);
|
|
21
20
|
if (anchor) ctx.onCreate = res => {
|
|
@@ -26,7 +25,6 @@ function toJSON(value, arg, ctx) {
|
|
|
26
25
|
if (anchor && ctx.onCreate) ctx.onCreate(res);
|
|
27
26
|
return res;
|
|
28
27
|
}
|
|
29
|
-
|
|
30
28
|
if ((!ctx || !ctx.keep) && typeof value === 'bigint') return Number(value);
|
|
31
29
|
return value;
|
|
32
30
|
}
|
|
@@ -36,23 +34,18 @@ class Scalar extends Node {
|
|
|
36
34
|
super();
|
|
37
35
|
this.value = value;
|
|
38
36
|
}
|
|
39
|
-
|
|
40
37
|
toJSON(arg, ctx) {
|
|
41
38
|
return ctx && ctx.keep ? this.value : toJSON(this.value, arg, ctx);
|
|
42
39
|
}
|
|
43
|
-
|
|
44
40
|
toString() {
|
|
45
41
|
return String(this.value);
|
|
46
42
|
}
|
|
47
|
-
|
|
48
43
|
}
|
|
49
44
|
|
|
50
45
|
function collectionFromPath(schema, path, value) {
|
|
51
46
|
let v = value;
|
|
52
|
-
|
|
53
47
|
for (let i = path.length - 1; i >= 0; --i) {
|
|
54
48
|
const k = path[i];
|
|
55
|
-
|
|
56
49
|
if (Number.isInteger(k) && k >= 0) {
|
|
57
50
|
const a = [];
|
|
58
51
|
a[k] = v;
|
|
@@ -68,21 +61,17 @@ function collectionFromPath(schema, path, value) {
|
|
|
68
61
|
v = o;
|
|
69
62
|
}
|
|
70
63
|
}
|
|
71
|
-
|
|
72
64
|
return schema.createNode(v, false);
|
|
73
|
-
}
|
|
74
|
-
|
|
65
|
+
}
|
|
75
66
|
|
|
67
|
+
// null, undefined, or an empty non-string iterable (e.g. [])
|
|
76
68
|
const isEmptyPath = path => path == null || typeof path === 'object' && path[Symbol.iterator]().next().done;
|
|
77
69
|
class Collection extends Node {
|
|
78
70
|
constructor(schema) {
|
|
79
71
|
super();
|
|
80
|
-
|
|
81
72
|
PlainValue._defineProperty(this, "items", []);
|
|
82
|
-
|
|
83
73
|
this.schema = schema;
|
|
84
74
|
}
|
|
85
|
-
|
|
86
75
|
addIn(path, value) {
|
|
87
76
|
if (isEmptyPath(path)) this.add(value);else {
|
|
88
77
|
const [key, ...rest] = path;
|
|
@@ -90,18 +79,15 @@ class Collection extends Node {
|
|
|
90
79
|
if (node instanceof Collection) node.addIn(rest, value);else if (node === undefined && this.schema) this.set(key, collectionFromPath(this.schema, rest, value));else throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
|
|
91
80
|
}
|
|
92
81
|
}
|
|
93
|
-
|
|
94
82
|
deleteIn([key, ...rest]) {
|
|
95
83
|
if (rest.length === 0) return this.delete(key);
|
|
96
84
|
const node = this.get(key, true);
|
|
97
85
|
if (node instanceof Collection) return node.deleteIn(rest);else throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
|
|
98
86
|
}
|
|
99
|
-
|
|
100
87
|
getIn([key, ...rest], keepScalar) {
|
|
101
88
|
const node = this.get(key, true);
|
|
102
89
|
if (rest.length === 0) return !keepScalar && node instanceof Scalar ? node.value : node;else return node instanceof Collection ? node.getIn(rest, keepScalar) : undefined;
|
|
103
90
|
}
|
|
104
|
-
|
|
105
91
|
hasAllNullValues() {
|
|
106
92
|
return this.items.every(node => {
|
|
107
93
|
if (!node || node.type !== 'PAIR') return false;
|
|
@@ -109,13 +95,11 @@ class Collection extends Node {
|
|
|
109
95
|
return n == null || n instanceof Scalar && n.value == null && !n.commentBefore && !n.comment && !n.tag;
|
|
110
96
|
});
|
|
111
97
|
}
|
|
112
|
-
|
|
113
98
|
hasIn([key, ...rest]) {
|
|
114
99
|
if (rest.length === 0) return this.has(key);
|
|
115
100
|
const node = this.get(key, true);
|
|
116
101
|
return node instanceof Collection ? node.hasIn(rest) : false;
|
|
117
102
|
}
|
|
118
|
-
|
|
119
103
|
setIn([key, ...rest], value) {
|
|
120
104
|
if (rest.length === 0) {
|
|
121
105
|
this.set(key, value);
|
|
@@ -123,15 +107,13 @@ class Collection extends Node {
|
|
|
123
107
|
const node = this.get(key, true);
|
|
124
108
|
if (node instanceof Collection) node.setIn(rest, value);else if (node === undefined && this.schema) this.set(key, collectionFromPath(this.schema, rest, value));else throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
|
|
125
109
|
}
|
|
126
|
-
}
|
|
110
|
+
}
|
|
127
111
|
|
|
112
|
+
// overridden in implementations
|
|
128
113
|
/* istanbul ignore next */
|
|
129
|
-
|
|
130
|
-
|
|
131
114
|
toJSON() {
|
|
132
115
|
return null;
|
|
133
116
|
}
|
|
134
|
-
|
|
135
117
|
toString(ctx, {
|
|
136
118
|
blockItem,
|
|
137
119
|
flowChars,
|
|
@@ -156,7 +138,6 @@ class Collection extends Node {
|
|
|
156
138
|
let hasItemWithNewLine = false;
|
|
157
139
|
const nodes = this.items.reduce((nodes, item, i) => {
|
|
158
140
|
let comment;
|
|
159
|
-
|
|
160
141
|
if (item) {
|
|
161
142
|
if (!chompKeep && item.spaceBefore) nodes.push({
|
|
162
143
|
type: 'comment',
|
|
@@ -171,7 +152,6 @@ class Collection extends Node {
|
|
|
171
152
|
if (item.comment) comment = item.comment;
|
|
172
153
|
if (inFlow && (!chompKeep && item.spaceBefore || item.commentBefore || item.comment || item.key && (item.key.commentBefore || item.key.comment) || item.value && (item.value.commentBefore || item.value.comment))) hasItemWithNewLine = true;
|
|
173
154
|
}
|
|
174
|
-
|
|
175
155
|
chompKeep = false;
|
|
176
156
|
let str = stringify(item, ctx, () => comment = null, () => chompKeep = true);
|
|
177
157
|
if (inFlow && !hasItemWithNewLine && str.includes('\n')) hasItemWithNewLine = true;
|
|
@@ -185,7 +165,6 @@ class Collection extends Node {
|
|
|
185
165
|
return nodes;
|
|
186
166
|
}, []);
|
|
187
167
|
let str;
|
|
188
|
-
|
|
189
168
|
if (nodes.length === 0) {
|
|
190
169
|
str = flowChars.start + flowChars.end;
|
|
191
170
|
} else if (inFlow) {
|
|
@@ -194,14 +173,11 @@ class Collection extends Node {
|
|
|
194
173
|
end
|
|
195
174
|
} = flowChars;
|
|
196
175
|
const strings = nodes.map(n => n.str);
|
|
197
|
-
|
|
198
176
|
if (hasItemWithNewLine || strings.reduce((sum, str) => sum + str.length + 2, 2) > Collection.maxFlowStringSingleLineLength) {
|
|
199
177
|
str = start;
|
|
200
|
-
|
|
201
178
|
for (const s of strings) {
|
|
202
179
|
str += s ? `\n${indentStep}${indent}${s}` : '\n';
|
|
203
180
|
}
|
|
204
|
-
|
|
205
181
|
str += `\n${indent}${end}`;
|
|
206
182
|
} else {
|
|
207
183
|
str = `${start} ${strings.join(' ')} ${end}`;
|
|
@@ -209,20 +185,15 @@ class Collection extends Node {
|
|
|
209
185
|
} else {
|
|
210
186
|
const strings = nodes.map(blockItem);
|
|
211
187
|
str = strings.shift();
|
|
212
|
-
|
|
213
188
|
for (const s of strings) str += s ? `\n${indent}${s}` : '\n';
|
|
214
189
|
}
|
|
215
|
-
|
|
216
190
|
if (this.comment) {
|
|
217
191
|
str += '\n' + this.comment.replace(/^/gm, `${indent}#`);
|
|
218
192
|
if (onComment) onComment();
|
|
219
193
|
} else if (chompKeep && onChompKeep) onChompKeep();
|
|
220
|
-
|
|
221
194
|
return str;
|
|
222
195
|
}
|
|
223
|
-
|
|
224
196
|
}
|
|
225
|
-
|
|
226
197
|
PlainValue._defineProperty(Collection, "maxFlowStringSingleLineLength", 60);
|
|
227
198
|
|
|
228
199
|
function asItemIndex(key) {
|
|
@@ -230,47 +201,38 @@ function asItemIndex(key) {
|
|
|
230
201
|
if (idx && typeof idx === 'string') idx = Number(idx);
|
|
231
202
|
return Number.isInteger(idx) && idx >= 0 ? idx : null;
|
|
232
203
|
}
|
|
233
|
-
|
|
234
204
|
class YAMLSeq extends Collection {
|
|
235
205
|
add(value) {
|
|
236
206
|
this.items.push(value);
|
|
237
207
|
}
|
|
238
|
-
|
|
239
208
|
delete(key) {
|
|
240
209
|
const idx = asItemIndex(key);
|
|
241
210
|
if (typeof idx !== 'number') return false;
|
|
242
211
|
const del = this.items.splice(idx, 1);
|
|
243
212
|
return del.length > 0;
|
|
244
213
|
}
|
|
245
|
-
|
|
246
214
|
get(key, keepScalar) {
|
|
247
215
|
const idx = asItemIndex(key);
|
|
248
216
|
if (typeof idx !== 'number') return undefined;
|
|
249
217
|
const it = this.items[idx];
|
|
250
218
|
return !keepScalar && it instanceof Scalar ? it.value : it;
|
|
251
219
|
}
|
|
252
|
-
|
|
253
220
|
has(key) {
|
|
254
221
|
const idx = asItemIndex(key);
|
|
255
222
|
return typeof idx === 'number' && idx < this.items.length;
|
|
256
223
|
}
|
|
257
|
-
|
|
258
224
|
set(key, value) {
|
|
259
225
|
const idx = asItemIndex(key);
|
|
260
226
|
if (typeof idx !== 'number') throw new Error(`Expected a valid index, not ${key}.`);
|
|
261
227
|
this.items[idx] = value;
|
|
262
228
|
}
|
|
263
|
-
|
|
264
229
|
toJSON(_, ctx) {
|
|
265
230
|
const seq = [];
|
|
266
231
|
if (ctx && ctx.onCreate) ctx.onCreate(seq);
|
|
267
232
|
let i = 0;
|
|
268
|
-
|
|
269
233
|
for (const item of this.items) seq.push(toJSON(item, String(i++), ctx));
|
|
270
|
-
|
|
271
234
|
return seq;
|
|
272
235
|
}
|
|
273
|
-
|
|
274
236
|
toString(ctx, onComment, onChompKeep) {
|
|
275
237
|
if (!ctx) return JSON.stringify(this);
|
|
276
238
|
return super.toString(ctx, {
|
|
@@ -283,7 +245,6 @@ class YAMLSeq extends Collection {
|
|
|
283
245
|
itemIndent: (ctx.indent || '') + ' '
|
|
284
246
|
}, onComment, onChompKeep);
|
|
285
247
|
}
|
|
286
|
-
|
|
287
248
|
}
|
|
288
249
|
|
|
289
250
|
const stringifyKey = (key, jsKey, ctx) => {
|
|
@@ -300,7 +261,6 @@ const stringifyKey = (key, jsKey, ctx) => {
|
|
|
300
261
|
});
|
|
301
262
|
return JSON.stringify(jsKey);
|
|
302
263
|
};
|
|
303
|
-
|
|
304
264
|
class Pair extends Node {
|
|
305
265
|
constructor(key, value = null) {
|
|
306
266
|
super();
|
|
@@ -308,11 +268,9 @@ class Pair extends Node {
|
|
|
308
268
|
this.value = value;
|
|
309
269
|
this.type = Pair.Type.PAIR;
|
|
310
270
|
}
|
|
311
|
-
|
|
312
271
|
get commentBefore() {
|
|
313
272
|
return this.key instanceof Node ? this.key.commentBefore : undefined;
|
|
314
273
|
}
|
|
315
|
-
|
|
316
274
|
set commentBefore(cb) {
|
|
317
275
|
if (this.key == null) this.key = new Scalar(null);
|
|
318
276
|
if (this.key instanceof Node) this.key.commentBefore = cb;else {
|
|
@@ -320,10 +278,8 @@ class Pair extends Node {
|
|
|
320
278
|
throw new Error(msg);
|
|
321
279
|
}
|
|
322
280
|
}
|
|
323
|
-
|
|
324
281
|
addToJSMap(ctx, map) {
|
|
325
282
|
const key = toJSON(this.key, '', ctx);
|
|
326
|
-
|
|
327
283
|
if (map instanceof Map) {
|
|
328
284
|
const value = toJSON(this.value, key, ctx);
|
|
329
285
|
map.set(key, value);
|
|
@@ -339,15 +295,12 @@ class Pair extends Node {
|
|
|
339
295
|
configurable: true
|
|
340
296
|
});else map[stringKey] = value;
|
|
341
297
|
}
|
|
342
|
-
|
|
343
298
|
return map;
|
|
344
299
|
}
|
|
345
|
-
|
|
346
300
|
toJSON(_, ctx) {
|
|
347
301
|
const pair = ctx && ctx.mapAsMap ? new Map() : {};
|
|
348
302
|
return this.addToJSMap(ctx, pair);
|
|
349
303
|
}
|
|
350
|
-
|
|
351
304
|
toString(ctx, onComment, onChompKeep) {
|
|
352
305
|
if (!ctx || !ctx.doc) return JSON.stringify(this);
|
|
353
306
|
const {
|
|
@@ -360,18 +313,15 @@ class Pair extends Node {
|
|
|
360
313
|
value
|
|
361
314
|
} = this;
|
|
362
315
|
let keyComment = key instanceof Node && key.comment;
|
|
363
|
-
|
|
364
316
|
if (simpleKeys) {
|
|
365
317
|
if (keyComment) {
|
|
366
318
|
throw new Error('With simple keys, key nodes cannot have comments');
|
|
367
319
|
}
|
|
368
|
-
|
|
369
320
|
if (key instanceof Collection) {
|
|
370
321
|
const msg = 'With simple keys, collection cannot be used as a key value';
|
|
371
322
|
throw new Error(msg);
|
|
372
323
|
}
|
|
373
324
|
}
|
|
374
|
-
|
|
375
325
|
let explicitKey = !simpleKeys && (!key || keyComment || (key instanceof Node ? key instanceof Collection || key.type === PlainValue.Type.BLOCK_FOLDED || key.type === PlainValue.Type.BLOCK_LITERAL : typeof key === 'object'));
|
|
376
326
|
const {
|
|
377
327
|
doc,
|
|
@@ -386,70 +336,54 @@ class Pair extends Node {
|
|
|
386
336
|
let chompKeep = false;
|
|
387
337
|
let str = stringify(key, ctx, () => keyComment = null, () => chompKeep = true);
|
|
388
338
|
str = addComment(str, ctx.indent, keyComment);
|
|
389
|
-
|
|
390
339
|
if (!explicitKey && str.length > 1024) {
|
|
391
340
|
if (simpleKeys) throw new Error('With simple keys, single line scalar must not span more than 1024 characters');
|
|
392
341
|
explicitKey = true;
|
|
393
342
|
}
|
|
394
|
-
|
|
395
343
|
if (ctx.allNullValues && !simpleKeys) {
|
|
396
344
|
if (this.comment) {
|
|
397
345
|
str = addComment(str, ctx.indent, this.comment);
|
|
398
346
|
if (onComment) onComment();
|
|
399
347
|
} else if (chompKeep && !keyComment && onChompKeep) onChompKeep();
|
|
400
|
-
|
|
401
348
|
return ctx.inFlow && !explicitKey ? str : `? ${str}`;
|
|
402
349
|
}
|
|
403
|
-
|
|
404
350
|
str = explicitKey ? `? ${str}\n${indent}:` : `${str}:`;
|
|
405
|
-
|
|
406
351
|
if (this.comment) {
|
|
407
352
|
// expected (but not strictly required) to be a single-line comment
|
|
408
353
|
str = addComment(str, ctx.indent, this.comment);
|
|
409
354
|
if (onComment) onComment();
|
|
410
355
|
}
|
|
411
|
-
|
|
412
356
|
let vcb = '';
|
|
413
357
|
let valueComment = null;
|
|
414
|
-
|
|
415
358
|
if (value instanceof Node) {
|
|
416
359
|
if (value.spaceBefore) vcb = '\n';
|
|
417
|
-
|
|
418
360
|
if (value.commentBefore) {
|
|
419
361
|
const cs = value.commentBefore.replace(/^/gm, `${ctx.indent}#`);
|
|
420
362
|
vcb += `\n${cs}`;
|
|
421
363
|
}
|
|
422
|
-
|
|
423
364
|
valueComment = value.comment;
|
|
424
365
|
} else if (value && typeof value === 'object') {
|
|
425
366
|
value = doc.schema.createNode(value, true);
|
|
426
367
|
}
|
|
427
|
-
|
|
428
368
|
ctx.implicitKey = false;
|
|
429
369
|
if (!explicitKey && !this.comment && value instanceof Scalar) ctx.indentAtStart = str.length + 1;
|
|
430
370
|
chompKeep = false;
|
|
431
|
-
|
|
432
371
|
if (!indentSeq && indentSize >= 2 && !ctx.inFlow && !explicitKey && value instanceof YAMLSeq && value.type !== PlainValue.Type.FLOW_SEQ && !value.tag && !doc.anchors.getName(value)) {
|
|
433
372
|
// If indentSeq === false, consider '- ' as part of indentation where possible
|
|
434
373
|
ctx.indent = ctx.indent.substr(2);
|
|
435
374
|
}
|
|
436
|
-
|
|
437
375
|
const valueStr = stringify(value, ctx, () => valueComment = null, () => chompKeep = true);
|
|
438
376
|
let ws = ' ';
|
|
439
|
-
|
|
440
377
|
if (vcb || this.comment) {
|
|
441
378
|
ws = `${vcb}\n${ctx.indent}`;
|
|
442
379
|
} else if (!explicitKey && value instanceof Collection) {
|
|
443
380
|
const flow = valueStr[0] === '[' || valueStr[0] === '{';
|
|
444
381
|
if (!flow || valueStr.includes('\n')) ws = `\n${ctx.indent}`;
|
|
445
382
|
} else if (valueStr[0] === '\n') ws = '';
|
|
446
|
-
|
|
447
383
|
if (chompKeep && !valueComment && onChompKeep) onChompKeep();
|
|
448
384
|
return addComment(str + ws + valueStr, ctx.indent, valueComment);
|
|
449
385
|
}
|
|
450
|
-
|
|
451
386
|
}
|
|
452
|
-
|
|
453
387
|
PlainValue._defineProperty(Pair, "Type", {
|
|
454
388
|
PAIR: 'PAIR',
|
|
455
389
|
MERGE_PAIR: 'MERGE_PAIR'
|
|
@@ -461,22 +395,18 @@ const getAliasCount = (node, anchors) => {
|
|
|
461
395
|
return anchor.count * anchor.aliasCount;
|
|
462
396
|
} else if (node instanceof Collection) {
|
|
463
397
|
let count = 0;
|
|
464
|
-
|
|
465
398
|
for (const item of node.items) {
|
|
466
399
|
const c = getAliasCount(item, anchors);
|
|
467
400
|
if (c > count) count = c;
|
|
468
401
|
}
|
|
469
|
-
|
|
470
402
|
return count;
|
|
471
403
|
} else if (node instanceof Pair) {
|
|
472
404
|
const kc = getAliasCount(node.key, anchors);
|
|
473
405
|
const vc = getAliasCount(node.value, anchors);
|
|
474
406
|
return Math.max(kc, vc);
|
|
475
407
|
}
|
|
476
|
-
|
|
477
408
|
return 1;
|
|
478
409
|
};
|
|
479
|
-
|
|
480
410
|
class Alias extends Node {
|
|
481
411
|
static stringify({
|
|
482
412
|
range,
|
|
@@ -493,17 +423,14 @@ class Alias extends Node {
|
|
|
493
423
|
const msg = doc.anchors.getName(source) ? 'Alias node must be after source node' : 'Source node not found for alias node';
|
|
494
424
|
throw new Error(`${msg} [${range}]`);
|
|
495
425
|
}
|
|
496
|
-
|
|
497
426
|
constructor(source) {
|
|
498
427
|
super();
|
|
499
428
|
this.source = source;
|
|
500
429
|
this.type = PlainValue.Type.ALIAS;
|
|
501
430
|
}
|
|
502
|
-
|
|
503
431
|
set tag(t) {
|
|
504
432
|
throw new Error('Alias nodes cannot have tags');
|
|
505
433
|
}
|
|
506
|
-
|
|
507
434
|
toJSON(arg, ctx) {
|
|
508
435
|
if (!ctx) return toJSON(this.source, arg, ctx);
|
|
509
436
|
const {
|
|
@@ -512,45 +439,37 @@ class Alias extends Node {
|
|
|
512
439
|
} = ctx;
|
|
513
440
|
const anchor = anchors.get(this.source);
|
|
514
441
|
/* istanbul ignore if */
|
|
515
|
-
|
|
516
442
|
if (!anchor || anchor.res === undefined) {
|
|
517
443
|
const msg = 'This should not happen: Alias anchor was not resolved?';
|
|
518
444
|
if (this.cstNode) throw new PlainValue.YAMLReferenceError(this.cstNode, msg);else throw new ReferenceError(msg);
|
|
519
445
|
}
|
|
520
|
-
|
|
521
446
|
if (maxAliasCount >= 0) {
|
|
522
447
|
anchor.count += 1;
|
|
523
448
|
if (anchor.aliasCount === 0) anchor.aliasCount = getAliasCount(this.source, anchors);
|
|
524
|
-
|
|
525
449
|
if (anchor.count * anchor.aliasCount > maxAliasCount) {
|
|
526
450
|
const msg = 'Excessive alias count indicates a resource exhaustion attack';
|
|
527
451
|
if (this.cstNode) throw new PlainValue.YAMLReferenceError(this.cstNode, msg);else throw new ReferenceError(msg);
|
|
528
452
|
}
|
|
529
453
|
}
|
|
530
|
-
|
|
531
454
|
return anchor.res;
|
|
532
|
-
}
|
|
533
|
-
// Object output.
|
|
534
|
-
|
|
455
|
+
}
|
|
535
456
|
|
|
457
|
+
// Only called when stringifying an alias mapping key while constructing
|
|
458
|
+
// Object output.
|
|
536
459
|
toString(ctx) {
|
|
537
460
|
return Alias.stringify(this, ctx);
|
|
538
461
|
}
|
|
539
|
-
|
|
540
462
|
}
|
|
541
|
-
|
|
542
463
|
PlainValue._defineProperty(Alias, "default", true);
|
|
543
464
|
|
|
544
465
|
function findPair(items, key) {
|
|
545
466
|
const k = key instanceof Scalar ? key.value : key;
|
|
546
|
-
|
|
547
467
|
for (const it of items) {
|
|
548
468
|
if (it instanceof Pair) {
|
|
549
469
|
if (it.key === key || it.key === k) return it;
|
|
550
470
|
if (it.key && it.key.value === k) return it;
|
|
551
471
|
}
|
|
552
472
|
}
|
|
553
|
-
|
|
554
473
|
return undefined;
|
|
555
474
|
}
|
|
556
475
|
class YAMLMap extends Collection {
|
|
@@ -558,7 +477,6 @@ class YAMLMap extends Collection {
|
|
|
558
477
|
if (!pair) pair = new Pair(pair);else if (!(pair instanceof Pair)) pair = new Pair(pair.key || pair, pair.value);
|
|
559
478
|
const prev = findPair(this.items, pair.key);
|
|
560
479
|
const sortEntries = this.schema && this.schema.sortMapEntries;
|
|
561
|
-
|
|
562
480
|
if (prev) {
|
|
563
481
|
if (overwrite) prev.value = pair.value;else throw new Error(`Key ${pair.key} already set`);
|
|
564
482
|
} else if (sortEntries) {
|
|
@@ -568,51 +486,41 @@ class YAMLMap extends Collection {
|
|
|
568
486
|
this.items.push(pair);
|
|
569
487
|
}
|
|
570
488
|
}
|
|
571
|
-
|
|
572
489
|
delete(key) {
|
|
573
490
|
const it = findPair(this.items, key);
|
|
574
491
|
if (!it) return false;
|
|
575
492
|
const del = this.items.splice(this.items.indexOf(it), 1);
|
|
576
493
|
return del.length > 0;
|
|
577
494
|
}
|
|
578
|
-
|
|
579
495
|
get(key, keepScalar) {
|
|
580
496
|
const it = findPair(this.items, key);
|
|
581
497
|
const node = it && it.value;
|
|
582
498
|
return !keepScalar && node instanceof Scalar ? node.value : node;
|
|
583
499
|
}
|
|
584
|
-
|
|
585
500
|
has(key) {
|
|
586
501
|
return !!findPair(this.items, key);
|
|
587
502
|
}
|
|
588
|
-
|
|
589
503
|
set(key, value) {
|
|
590
504
|
this.add(new Pair(key, value), true);
|
|
591
505
|
}
|
|
506
|
+
|
|
592
507
|
/**
|
|
593
508
|
* @param {*} arg ignored
|
|
594
509
|
* @param {*} ctx Conversion context, originally set in Document#toJSON()
|
|
595
510
|
* @param {Class} Type If set, forces the returned collection type
|
|
596
511
|
* @returns {*} Instance of Type, Map, or Object
|
|
597
512
|
*/
|
|
598
|
-
|
|
599
|
-
|
|
600
513
|
toJSON(_, ctx, Type) {
|
|
601
514
|
const map = Type ? new Type() : ctx && ctx.mapAsMap ? new Map() : {};
|
|
602
515
|
if (ctx && ctx.onCreate) ctx.onCreate(map);
|
|
603
|
-
|
|
604
516
|
for (const item of this.items) item.addToJSMap(ctx, map);
|
|
605
|
-
|
|
606
517
|
return map;
|
|
607
518
|
}
|
|
608
|
-
|
|
609
519
|
toString(ctx, onComment, onChompKeep) {
|
|
610
520
|
if (!ctx) return JSON.stringify(this);
|
|
611
|
-
|
|
612
521
|
for (const item of this.items) {
|
|
613
522
|
if (!(item instanceof Pair)) throw new Error(`Map items must all be pairs; found ${JSON.stringify(item)} instead`);
|
|
614
523
|
}
|
|
615
|
-
|
|
616
524
|
return super.toString(ctx, {
|
|
617
525
|
blockItem: n => n.str,
|
|
618
526
|
flowChars: {
|
|
@@ -623,7 +531,6 @@ class YAMLMap extends Collection {
|
|
|
623
531
|
itemIndent: ctx.indent || ''
|
|
624
532
|
}, onComment, onChompKeep);
|
|
625
533
|
}
|
|
626
|
-
|
|
627
534
|
}
|
|
628
535
|
|
|
629
536
|
const MERGE_KEY = '<<';
|
|
@@ -631,36 +538,32 @@ class Merge extends Pair {
|
|
|
631
538
|
constructor(pair) {
|
|
632
539
|
if (pair instanceof Pair) {
|
|
633
540
|
let seq = pair.value;
|
|
634
|
-
|
|
635
541
|
if (!(seq instanceof YAMLSeq)) {
|
|
636
542
|
seq = new YAMLSeq();
|
|
637
543
|
seq.items.push(pair.value);
|
|
638
544
|
seq.range = pair.value.range;
|
|
639
545
|
}
|
|
640
|
-
|
|
641
546
|
super(pair.key, seq);
|
|
642
547
|
this.range = pair.range;
|
|
643
548
|
} else {
|
|
644
549
|
super(new Scalar(MERGE_KEY), new YAMLSeq());
|
|
645
550
|
}
|
|
646
|
-
|
|
647
551
|
this.type = Pair.Type.MERGE_PAIR;
|
|
648
|
-
}
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
// If the value associated with a merge key is a single mapping node, each of
|
|
649
555
|
// its key/value pairs is inserted into the current mapping, unless the key
|
|
650
556
|
// already exists in it. If the value associated with the merge key is a
|
|
651
557
|
// sequence, then this sequence is expected to contain mapping nodes and each
|
|
652
558
|
// of these nodes is merged in turn according to its order in the sequence.
|
|
653
559
|
// Keys in mapping nodes earlier in the sequence override keys specified in
|
|
654
560
|
// later mapping nodes. -- http://yaml.org/type/merge.html
|
|
655
|
-
|
|
656
|
-
|
|
657
561
|
addToJSMap(ctx, map) {
|
|
658
562
|
for (const {
|
|
659
563
|
source
|
|
660
564
|
} of this.value.items) {
|
|
661
565
|
if (!(source instanceof YAMLMap)) throw new Error('Merge sources must be maps');
|
|
662
566
|
const srcMap = source.toJSON(null, ctx, Map);
|
|
663
|
-
|
|
664
567
|
for (const [key, value] of srcMap) {
|
|
665
568
|
if (map instanceof Map) {
|
|
666
569
|
if (!map.has(key)) map.set(key, value);
|
|
@@ -676,10 +579,8 @@ class Merge extends Pair {
|
|
|
676
579
|
}
|
|
677
580
|
}
|
|
678
581
|
}
|
|
679
|
-
|
|
680
582
|
return map;
|
|
681
583
|
}
|
|
682
|
-
|
|
683
584
|
toString(ctx, onComment) {
|
|
684
585
|
const seq = this.value;
|
|
685
586
|
if (seq.items.length > 1) return super.toString(ctx, onComment);
|
|
@@ -688,7 +589,6 @@ class Merge extends Pair {
|
|
|
688
589
|
this.value = seq;
|
|
689
590
|
return str;
|
|
690
591
|
}
|
|
691
|
-
|
|
692
592
|
}
|
|
693
593
|
|
|
694
594
|
const binaryOptions = {
|
|
@@ -717,6 +617,7 @@ const strOptions = {
|
|
|
717
617
|
}
|
|
718
618
|
};
|
|
719
619
|
|
|
620
|
+
// falls back to string on no match
|
|
720
621
|
function resolveScalar(str, tags, scalarFallback) {
|
|
721
622
|
for (const {
|
|
722
623
|
format,
|
|
@@ -725,7 +626,6 @@ function resolveScalar(str, tags, scalarFallback) {
|
|
|
725
626
|
} of tags) {
|
|
726
627
|
if (test) {
|
|
727
628
|
const match = str.match(test);
|
|
728
|
-
|
|
729
629
|
if (match) {
|
|
730
630
|
let res = resolve.apply(null, match);
|
|
731
631
|
if (!(res instanceof Scalar)) res = new Scalar(res);
|
|
@@ -734,29 +634,27 @@ function resolveScalar(str, tags, scalarFallback) {
|
|
|
734
634
|
}
|
|
735
635
|
}
|
|
736
636
|
}
|
|
737
|
-
|
|
738
637
|
if (scalarFallback) str = scalarFallback(str);
|
|
739
638
|
return new Scalar(str);
|
|
740
639
|
}
|
|
741
640
|
|
|
742
641
|
const FOLD_FLOW = 'flow';
|
|
743
642
|
const FOLD_BLOCK = 'block';
|
|
744
|
-
const FOLD_QUOTED = 'quoted';
|
|
745
|
-
// returns index of last newline in more-indented block
|
|
643
|
+
const FOLD_QUOTED = 'quoted';
|
|
746
644
|
|
|
645
|
+
// presumes i+1 is at the start of a line
|
|
646
|
+
// returns index of last newline in more-indented block
|
|
747
647
|
const consumeMoreIndentedLines = (text, i) => {
|
|
748
648
|
let ch = text[i + 1];
|
|
749
|
-
|
|
750
649
|
while (ch === ' ' || ch === '\t') {
|
|
751
650
|
do {
|
|
752
651
|
ch = text[i += 1];
|
|
753
652
|
} while (ch && ch !== '\n');
|
|
754
|
-
|
|
755
653
|
ch = text[i + 1];
|
|
756
654
|
}
|
|
757
|
-
|
|
758
655
|
return i;
|
|
759
656
|
};
|
|
657
|
+
|
|
760
658
|
/**
|
|
761
659
|
* Tries to keep input at up to `lineWidth` characters, splitting only on spaces
|
|
762
660
|
* not followed by newlines or spaces unless `mode` is `'quoted'`. Lines are
|
|
@@ -777,8 +675,6 @@ const consumeMoreIndentedLines = (text, i) => {
|
|
|
777
675
|
* @param {function} options.onFold Called once if any line of text exceeds
|
|
778
676
|
* lineWidth characters
|
|
779
677
|
*/
|
|
780
|
-
|
|
781
|
-
|
|
782
678
|
function foldFlowLines(text, indent, mode, {
|
|
783
679
|
indentAtStart,
|
|
784
680
|
lineWidth = 80,
|
|
@@ -792,47 +688,37 @@ function foldFlowLines(text, indent, mode, {
|
|
|
792
688
|
const folds = [];
|
|
793
689
|
const escapedFolds = {};
|
|
794
690
|
let end = lineWidth - indent.length;
|
|
795
|
-
|
|
796
691
|
if (typeof indentAtStart === 'number') {
|
|
797
692
|
if (indentAtStart > lineWidth - Math.max(2, minContentWidth)) folds.push(0);else end = lineWidth - indentAtStart;
|
|
798
693
|
}
|
|
799
|
-
|
|
800
694
|
let split = undefined;
|
|
801
695
|
let prev = undefined;
|
|
802
696
|
let overflow = false;
|
|
803
697
|
let i = -1;
|
|
804
698
|
let escStart = -1;
|
|
805
699
|
let escEnd = -1;
|
|
806
|
-
|
|
807
700
|
if (mode === FOLD_BLOCK) {
|
|
808
701
|
i = consumeMoreIndentedLines(text, i);
|
|
809
702
|
if (i !== -1) end = i + endStep;
|
|
810
703
|
}
|
|
811
|
-
|
|
812
704
|
for (let ch; ch = text[i += 1];) {
|
|
813
705
|
if (mode === FOLD_QUOTED && ch === '\\') {
|
|
814
706
|
escStart = i;
|
|
815
|
-
|
|
816
707
|
switch (text[i + 1]) {
|
|
817
708
|
case 'x':
|
|
818
709
|
i += 3;
|
|
819
710
|
break;
|
|
820
|
-
|
|
821
711
|
case 'u':
|
|
822
712
|
i += 5;
|
|
823
713
|
break;
|
|
824
|
-
|
|
825
714
|
case 'U':
|
|
826
715
|
i += 9;
|
|
827
716
|
break;
|
|
828
|
-
|
|
829
717
|
default:
|
|
830
718
|
i += 1;
|
|
831
719
|
}
|
|
832
|
-
|
|
833
720
|
escEnd = i;
|
|
834
721
|
}
|
|
835
|
-
|
|
836
722
|
if (ch === '\n') {
|
|
837
723
|
if (mode === FOLD_BLOCK) i = consumeMoreIndentedLines(text, i);
|
|
838
724
|
end = i + endStep;
|
|
@@ -843,7 +729,6 @@ function foldFlowLines(text, indent, mode, {
|
|
|
843
729
|
const next = text[i + 1];
|
|
844
730
|
if (next && next !== ' ' && next !== '\n' && next !== '\t') split = i;
|
|
845
731
|
}
|
|
846
|
-
|
|
847
732
|
if (i >= end) {
|
|
848
733
|
if (split) {
|
|
849
734
|
folds.push(split);
|
|
@@ -855,11 +740,10 @@ function foldFlowLines(text, indent, mode, {
|
|
|
855
740
|
prev = ch;
|
|
856
741
|
ch = text[i += 1];
|
|
857
742
|
overflow = true;
|
|
858
|
-
}
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
743
|
+
}
|
|
744
|
+
// Account for newline escape, but don't break preceding escape
|
|
745
|
+
const j = i > escEnd + 1 ? i - 2 : escStart - 1;
|
|
746
|
+
// Bail out if lineWidth & minContentWidth are shorter than an escape string
|
|
863
747
|
if (escapedFolds[j]) return text;
|
|
864
748
|
folds.push(j);
|
|
865
749
|
escapedFolds[j] = true;
|
|
@@ -870,15 +754,12 @@ function foldFlowLines(text, indent, mode, {
|
|
|
870
754
|
}
|
|
871
755
|
}
|
|
872
756
|
}
|
|
873
|
-
|
|
874
757
|
prev = ch;
|
|
875
758
|
}
|
|
876
|
-
|
|
877
759
|
if (overflow && onOverflow) onOverflow();
|
|
878
760
|
if (folds.length === 0) return text;
|
|
879
761
|
if (onFold) onFold();
|
|
880
762
|
let res = text.slice(0, folds[0]);
|
|
881
|
-
|
|
882
763
|
for (let i = 0; i < folds.length; ++i) {
|
|
883
764
|
const fold = folds[i];
|
|
884
765
|
const end = folds[i + 1] || text.length;
|
|
@@ -887,7 +768,6 @@ function foldFlowLines(text, indent, mode, {
|
|
|
887
768
|
res += `\n${indent}${text.slice(fold + 1, end)}`;
|
|
888
769
|
}
|
|
889
770
|
}
|
|
890
|
-
|
|
891
771
|
return res;
|
|
892
772
|
}
|
|
893
773
|
|
|
@@ -895,18 +775,16 @@ const getFoldOptions = ({
|
|
|
895
775
|
indentAtStart
|
|
896
776
|
}) => indentAtStart ? Object.assign({
|
|
897
777
|
indentAtStart
|
|
898
|
-
}, strOptions.fold) : strOptions.fold;
|
|
899
|
-
// presume that's starting a new document.
|
|
900
|
-
|
|
778
|
+
}, strOptions.fold) : strOptions.fold;
|
|
901
779
|
|
|
780
|
+
// Also checks for lines starting with %, as parsing the output as YAML 1.1 will
|
|
781
|
+
// presume that's starting a new document.
|
|
902
782
|
const containsDocumentMarker = str => /^(%|---|\.\.\.)/m.test(str);
|
|
903
|
-
|
|
904
783
|
function lineLengthOverLimit(str, lineWidth, indentLength) {
|
|
905
784
|
if (!lineWidth || lineWidth < 0) return false;
|
|
906
785
|
const limit = lineWidth - indentLength;
|
|
907
786
|
const strLen = str.length;
|
|
908
787
|
if (strLen <= limit) return false;
|
|
909
|
-
|
|
910
788
|
for (let i = 0, start = 0; i < strLen; ++i) {
|
|
911
789
|
if (str[i] === '\n') {
|
|
912
790
|
if (i - start > limit) return true;
|
|
@@ -914,10 +792,8 @@ function lineLengthOverLimit(str, lineWidth, indentLength) {
|
|
|
914
792
|
if (strLen - start <= limit) return false;
|
|
915
793
|
}
|
|
916
794
|
}
|
|
917
|
-
|
|
918
795
|
return true;
|
|
919
796
|
}
|
|
920
|
-
|
|
921
797
|
function doubleQuotedString(value, ctx) {
|
|
922
798
|
const {
|
|
923
799
|
implicitKey
|
|
@@ -931,7 +807,6 @@ function doubleQuotedString(value, ctx) {
|
|
|
931
807
|
const indent = ctx.indent || (containsDocumentMarker(value) ? ' ' : '');
|
|
932
808
|
let str = '';
|
|
933
809
|
let start = 0;
|
|
934
|
-
|
|
935
810
|
for (let i = 0, ch = json[i]; ch; ch = json[++i]) {
|
|
936
811
|
if (ch === ' ' && json[i + 1] === '\\' && json[i + 2] === 'n') {
|
|
937
812
|
// space before newline needs to be escaped to not be folded
|
|
@@ -940,85 +815,67 @@ function doubleQuotedString(value, ctx) {
|
|
|
940
815
|
start = i;
|
|
941
816
|
ch = '\\';
|
|
942
817
|
}
|
|
943
|
-
|
|
944
818
|
if (ch === '\\') switch (json[i + 1]) {
|
|
945
819
|
case 'u':
|
|
946
820
|
{
|
|
947
821
|
str += json.slice(start, i);
|
|
948
822
|
const code = json.substr(i + 2, 4);
|
|
949
|
-
|
|
950
823
|
switch (code) {
|
|
951
824
|
case '0000':
|
|
952
825
|
str += '\\0';
|
|
953
826
|
break;
|
|
954
|
-
|
|
955
827
|
case '0007':
|
|
956
828
|
str += '\\a';
|
|
957
829
|
break;
|
|
958
|
-
|
|
959
830
|
case '000b':
|
|
960
831
|
str += '\\v';
|
|
961
832
|
break;
|
|
962
|
-
|
|
963
833
|
case '001b':
|
|
964
834
|
str += '\\e';
|
|
965
835
|
break;
|
|
966
|
-
|
|
967
836
|
case '0085':
|
|
968
837
|
str += '\\N';
|
|
969
838
|
break;
|
|
970
|
-
|
|
971
839
|
case '00a0':
|
|
972
840
|
str += '\\_';
|
|
973
841
|
break;
|
|
974
|
-
|
|
975
842
|
case '2028':
|
|
976
843
|
str += '\\L';
|
|
977
844
|
break;
|
|
978
|
-
|
|
979
845
|
case '2029':
|
|
980
846
|
str += '\\P';
|
|
981
847
|
break;
|
|
982
|
-
|
|
983
848
|
default:
|
|
984
849
|
if (code.substr(0, 2) === '00') str += '\\x' + code.substr(2);else str += json.substr(i, 6);
|
|
985
850
|
}
|
|
986
|
-
|
|
987
851
|
i += 5;
|
|
988
852
|
start = i + 1;
|
|
989
853
|
}
|
|
990
854
|
break;
|
|
991
|
-
|
|
992
855
|
case 'n':
|
|
993
856
|
if (implicitKey || json[i + 2] === '"' || json.length < minMultiLineLength) {
|
|
994
857
|
i += 1;
|
|
995
858
|
} else {
|
|
996
859
|
// folding will eat first newline
|
|
997
860
|
str += json.slice(start, i) + '\n\n';
|
|
998
|
-
|
|
999
861
|
while (json[i + 2] === '\\' && json[i + 3] === 'n' && json[i + 4] !== '"') {
|
|
1000
862
|
str += '\n';
|
|
1001
863
|
i += 2;
|
|
1002
864
|
}
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
865
|
+
str += indent;
|
|
866
|
+
// space after newline needs to be escaped to not be folded
|
|
1006
867
|
if (json[i + 2] === ' ') str += '\\';
|
|
1007
868
|
i += 1;
|
|
1008
869
|
start = i + 1;
|
|
1009
870
|
}
|
|
1010
|
-
|
|
1011
871
|
break;
|
|
1012
|
-
|
|
1013
872
|
default:
|
|
1014
873
|
i += 1;
|
|
1015
874
|
}
|
|
1016
875
|
}
|
|
1017
|
-
|
|
1018
876
|
str = start ? str + json.slice(start) : json;
|
|
1019
877
|
return implicitKey ? str : foldFlowLines(str, indent, FOLD_QUOTED, getFoldOptions(ctx));
|
|
1020
878
|
}
|
|
1021
|
-
|
|
1022
879
|
function singleQuotedString(value, ctx) {
|
|
1023
880
|
if (ctx.implicitKey) {
|
|
1024
881
|
if (/\n/.test(value)) return doubleQuotedString(value, ctx);
|
|
@@ -1026,12 +883,10 @@ function singleQuotedString(value, ctx) {
|
|
|
1026
883
|
// single quoted string can't have leading or trailing whitespace around newline
|
|
1027
884
|
if (/[ \t]\n|\n[ \t]/.test(value)) return doubleQuotedString(value, ctx);
|
|
1028
885
|
}
|
|
1029
|
-
|
|
1030
886
|
const indent = ctx.indent || (containsDocumentMarker(value) ? ' ' : '');
|
|
1031
887
|
const res = "'" + value.replace(/'/g, "''").replace(/\n+/g, `$&\n${indent}`) + "'";
|
|
1032
888
|
return ctx.implicitKey ? res : foldFlowLines(res, indent, FOLD_FLOW, getFoldOptions(ctx));
|
|
1033
889
|
}
|
|
1034
|
-
|
|
1035
890
|
function blockString({
|
|
1036
891
|
comment,
|
|
1037
892
|
type,
|
|
@@ -1042,10 +897,8 @@ function blockString({
|
|
|
1042
897
|
if (/\n[\t ]+$/.test(value) || /^\s*$/.test(value)) {
|
|
1043
898
|
return doubleQuotedString(value, ctx);
|
|
1044
899
|
}
|
|
1045
|
-
|
|
1046
900
|
const indent = ctx.indent || (ctx.forceBlockIndent || containsDocumentMarker(value) ? ' ' : '');
|
|
1047
901
|
const indentSize = indent ? '2' : '1'; // root is at -1
|
|
1048
|
-
|
|
1049
902
|
const literal = type === PlainValue.Type.BLOCK_FOLDED ? false : type === PlainValue.Type.BLOCK_LITERAL ? true : !lineLengthOverLimit(value, strOptions.fold.lineWidth, indent.length);
|
|
1050
903
|
let header = literal ? '|' : '>';
|
|
1051
904
|
if (!value) return header + '\n';
|
|
@@ -1053,21 +906,17 @@ function blockString({
|
|
|
1053
906
|
let wsEnd = '';
|
|
1054
907
|
value = value.replace(/[\n\t ]*$/, ws => {
|
|
1055
908
|
const n = ws.indexOf('\n');
|
|
1056
|
-
|
|
1057
909
|
if (n === -1) {
|
|
1058
910
|
header += '-'; // strip
|
|
1059
911
|
} else if (value === ws || n !== ws.length - 1) {
|
|
1060
912
|
header += '+'; // keep
|
|
1061
|
-
|
|
1062
913
|
if (onChompKeep) onChompKeep();
|
|
1063
914
|
}
|
|
1064
|
-
|
|
1065
915
|
wsEnd = ws.replace(/\n$/, '');
|
|
1066
916
|
return '';
|
|
1067
917
|
}).replace(/^[\n ]*/, ws => {
|
|
1068
918
|
if (ws.indexOf(' ') !== -1) header += indentSize;
|
|
1069
919
|
const m = ws.match(/ +$/);
|
|
1070
|
-
|
|
1071
920
|
if (m) {
|
|
1072
921
|
wsStart = ws.slice(0, -m[0].length);
|
|
1073
922
|
return m[0];
|
|
@@ -1078,26 +927,21 @@ function blockString({
|
|
|
1078
927
|
});
|
|
1079
928
|
if (wsEnd) wsEnd = wsEnd.replace(/\n+(?!\n|$)/g, `$&${indent}`);
|
|
1080
929
|
if (wsStart) wsStart = wsStart.replace(/\n+/g, `$&${indent}`);
|
|
1081
|
-
|
|
1082
930
|
if (comment) {
|
|
1083
931
|
header += ' #' + comment.replace(/ ?[\r\n]+/g, ' ');
|
|
1084
932
|
if (onComment) onComment();
|
|
1085
933
|
}
|
|
1086
|
-
|
|
1087
934
|
if (!value) return `${header}${indentSize}\n${indent}${wsEnd}`;
|
|
1088
|
-
|
|
1089
935
|
if (literal) {
|
|
1090
936
|
value = value.replace(/\n+/g, `$&${indent}`);
|
|
1091
937
|
return `${header}\n${indent}${wsStart}${value}${wsEnd}`;
|
|
1092
938
|
}
|
|
1093
|
-
|
|
1094
939
|
value = value.replace(/\n+/g, '\n$&').replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, '$1$2') // more-indented lines aren't folded
|
|
1095
940
|
// ^ ind.line ^ empty ^ capture next empty lines only at end of indent
|
|
1096
941
|
.replace(/\n+/g, `$&${indent}`);
|
|
1097
942
|
const body = foldFlowLines(`${wsStart}${value}${wsEnd}`, indent, FOLD_BLOCK, strOptions.fold);
|
|
1098
943
|
return `${header}\n${indent}${body}`;
|
|
1099
944
|
}
|
|
1100
|
-
|
|
1101
945
|
function plainString(item, ctx, onComment, onChompKeep) {
|
|
1102
946
|
const {
|
|
1103
947
|
comment,
|
|
@@ -1110,11 +954,9 @@ function plainString(item, ctx, onComment, onChompKeep) {
|
|
|
1110
954
|
indent,
|
|
1111
955
|
inFlow
|
|
1112
956
|
} = ctx;
|
|
1113
|
-
|
|
1114
957
|
if (implicitKey && /[\n[\]{},]/.test(value) || inFlow && /[[\]{},]/.test(value)) {
|
|
1115
958
|
return doubleQuotedString(value, ctx);
|
|
1116
959
|
}
|
|
1117
|
-
|
|
1118
960
|
if (!value || /^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(value)) {
|
|
1119
961
|
// not allowed:
|
|
1120
962
|
// - empty string, '-' or '?'
|
|
@@ -1124,21 +966,18 @@ function plainString(item, ctx, onComment, onChompKeep) {
|
|
|
1124
966
|
// - end with ' ' or ':'
|
|
1125
967
|
return implicitKey || inFlow || value.indexOf('\n') === -1 ? value.indexOf('"') !== -1 && value.indexOf("'") === -1 ? singleQuotedString(value, ctx) : doubleQuotedString(value, ctx) : blockString(item, ctx, onComment, onChompKeep);
|
|
1126
968
|
}
|
|
1127
|
-
|
|
1128
969
|
if (!implicitKey && !inFlow && type !== PlainValue.Type.PLAIN && value.indexOf('\n') !== -1) {
|
|
1129
970
|
// Where allowed & type not set explicitly, prefer block style for multiline strings
|
|
1130
971
|
return blockString(item, ctx, onComment, onChompKeep);
|
|
1131
972
|
}
|
|
1132
|
-
|
|
1133
973
|
if (indent === '' && containsDocumentMarker(value)) {
|
|
1134
974
|
ctx.forceBlockIndent = true;
|
|
1135
975
|
return blockString(item, ctx, onComment, onChompKeep);
|
|
1136
976
|
}
|
|
1137
|
-
|
|
1138
|
-
|
|
977
|
+
const str = value.replace(/\n+/g, `$&\n${indent}`);
|
|
978
|
+
// Verify that output will be parsed as a string, as e.g. plain numbers and
|
|
1139
979
|
// booleans get parsed with those types in v1.2 (e.g. '42', 'true' & '0.9e-3'),
|
|
1140
980
|
// and others in v1.1.
|
|
1141
|
-
|
|
1142
981
|
if (actualString) {
|
|
1143
982
|
const {
|
|
1144
983
|
tags
|
|
@@ -1146,17 +985,13 @@ function plainString(item, ctx, onComment, onChompKeep) {
|
|
|
1146
985
|
const resolved = resolveScalar(str, tags, tags.scalarFallback).value;
|
|
1147
986
|
if (typeof resolved !== 'string') return doubleQuotedString(value, ctx);
|
|
1148
987
|
}
|
|
1149
|
-
|
|
1150
988
|
const body = implicitKey ? str : foldFlowLines(str, indent, FOLD_FLOW, getFoldOptions(ctx));
|
|
1151
|
-
|
|
1152
989
|
if (comment && !inFlow && (body.indexOf('\n') !== -1 || comment.indexOf('\n') !== -1)) {
|
|
1153
990
|
if (onComment) onComment();
|
|
1154
991
|
return addCommentBefore(body, indent, comment);
|
|
1155
992
|
}
|
|
1156
|
-
|
|
1157
993
|
return body;
|
|
1158
994
|
}
|
|
1159
|
-
|
|
1160
995
|
function stringifyString(item, ctx, onComment, onChompKeep) {
|
|
1161
996
|
const {
|
|
1162
997
|
defaultType
|
|
@@ -1169,34 +1004,27 @@ function stringifyString(item, ctx, onComment, onChompKeep) {
|
|
|
1169
1004
|
type,
|
|
1170
1005
|
value
|
|
1171
1006
|
} = item;
|
|
1172
|
-
|
|
1173
1007
|
if (typeof value !== 'string') {
|
|
1174
1008
|
value = String(value);
|
|
1175
1009
|
item = Object.assign({}, item, {
|
|
1176
1010
|
value
|
|
1177
1011
|
});
|
|
1178
1012
|
}
|
|
1179
|
-
|
|
1180
1013
|
const _stringify = _type => {
|
|
1181
1014
|
switch (_type) {
|
|
1182
1015
|
case PlainValue.Type.BLOCK_FOLDED:
|
|
1183
1016
|
case PlainValue.Type.BLOCK_LITERAL:
|
|
1184
1017
|
return blockString(item, ctx, onComment, onChompKeep);
|
|
1185
|
-
|
|
1186
1018
|
case PlainValue.Type.QUOTE_DOUBLE:
|
|
1187
1019
|
return doubleQuotedString(value, ctx);
|
|
1188
|
-
|
|
1189
1020
|
case PlainValue.Type.QUOTE_SINGLE:
|
|
1190
1021
|
return singleQuotedString(value, ctx);
|
|
1191
|
-
|
|
1192
1022
|
case PlainValue.Type.PLAIN:
|
|
1193
1023
|
return plainString(item, ctx, onComment, onChompKeep);
|
|
1194
|
-
|
|
1195
1024
|
default:
|
|
1196
1025
|
return null;
|
|
1197
1026
|
}
|
|
1198
1027
|
};
|
|
1199
|
-
|
|
1200
1028
|
if (type !== PlainValue.Type.QUOTE_DOUBLE && /[\x00-\x08\x0b-\x1f\x7f-\x9f]/.test(value)) {
|
|
1201
1029
|
// force double quotes on control characters
|
|
1202
1030
|
type = PlainValue.Type.QUOTE_DOUBLE;
|
|
@@ -1204,14 +1032,11 @@ function stringifyString(item, ctx, onComment, onChompKeep) {
|
|
|
1204
1032
|
// should not happen; blocks are not valid inside flow containers
|
|
1205
1033
|
type = PlainValue.Type.QUOTE_DOUBLE;
|
|
1206
1034
|
}
|
|
1207
|
-
|
|
1208
1035
|
let res = _stringify(type);
|
|
1209
|
-
|
|
1210
1036
|
if (res === null) {
|
|
1211
1037
|
res = _stringify(defaultType);
|
|
1212
1038
|
if (res === null) throw new Error(`Unsupported default string type ${defaultType}`);
|
|
1213
1039
|
}
|
|
1214
|
-
|
|
1215
1040
|
return res;
|
|
1216
1041
|
}
|
|
1217
1042
|
|
|
@@ -1224,57 +1049,44 @@ function stringifyNumber({
|
|
|
1224
1049
|
if (typeof value === 'bigint') return String(value);
|
|
1225
1050
|
if (!isFinite(value)) return isNaN(value) ? '.nan' : value < 0 ? '-.inf' : '.inf';
|
|
1226
1051
|
let n = JSON.stringify(value);
|
|
1227
|
-
|
|
1228
1052
|
if (!format && minFractionDigits && (!tag || tag === 'tag:yaml.org,2002:float') && /^\d/.test(n)) {
|
|
1229
1053
|
let i = n.indexOf('.');
|
|
1230
|
-
|
|
1231
1054
|
if (i < 0) {
|
|
1232
1055
|
i = n.length;
|
|
1233
1056
|
n += '.';
|
|
1234
1057
|
}
|
|
1235
|
-
|
|
1236
1058
|
let d = minFractionDigits - (n.length - i - 1);
|
|
1237
|
-
|
|
1238
1059
|
while (d-- > 0) n += '0';
|
|
1239
1060
|
}
|
|
1240
|
-
|
|
1241
1061
|
return n;
|
|
1242
1062
|
}
|
|
1243
1063
|
|
|
1244
1064
|
function checkFlowCollectionEnd(errors, cst) {
|
|
1245
1065
|
let char, name;
|
|
1246
|
-
|
|
1247
1066
|
switch (cst.type) {
|
|
1248
1067
|
case PlainValue.Type.FLOW_MAP:
|
|
1249
1068
|
char = '}';
|
|
1250
1069
|
name = 'flow map';
|
|
1251
1070
|
break;
|
|
1252
|
-
|
|
1253
1071
|
case PlainValue.Type.FLOW_SEQ:
|
|
1254
1072
|
char = ']';
|
|
1255
1073
|
name = 'flow sequence';
|
|
1256
1074
|
break;
|
|
1257
|
-
|
|
1258
1075
|
default:
|
|
1259
1076
|
errors.push(new PlainValue.YAMLSemanticError(cst, 'Not a flow collection!?'));
|
|
1260
1077
|
return;
|
|
1261
1078
|
}
|
|
1262
|
-
|
|
1263
1079
|
let lastItem;
|
|
1264
|
-
|
|
1265
1080
|
for (let i = cst.items.length - 1; i >= 0; --i) {
|
|
1266
1081
|
const item = cst.items[i];
|
|
1267
|
-
|
|
1268
1082
|
if (!item || item.type !== PlainValue.Type.COMMENT) {
|
|
1269
1083
|
lastItem = item;
|
|
1270
1084
|
break;
|
|
1271
1085
|
}
|
|
1272
1086
|
}
|
|
1273
|
-
|
|
1274
1087
|
if (lastItem && lastItem.char !== char) {
|
|
1275
1088
|
const msg = `Expected ${name} to end with ${char}`;
|
|
1276
1089
|
let err;
|
|
1277
|
-
|
|
1278
1090
|
if (typeof lastItem.offset === 'number') {
|
|
1279
1091
|
err = new PlainValue.YAMLSemanticError(cst, msg);
|
|
1280
1092
|
err.offset = lastItem.offset + 1;
|
|
@@ -1282,13 +1094,11 @@ function checkFlowCollectionEnd(errors, cst) {
|
|
|
1282
1094
|
err = new PlainValue.YAMLSemanticError(lastItem, msg);
|
|
1283
1095
|
if (lastItem.range && lastItem.range.end) err.offset = lastItem.range.end - lastItem.range.start;
|
|
1284
1096
|
}
|
|
1285
|
-
|
|
1286
1097
|
errors.push(err);
|
|
1287
1098
|
}
|
|
1288
1099
|
}
|
|
1289
1100
|
function checkFlowCommentSpace(errors, comment) {
|
|
1290
1101
|
const prev = comment.context.src[comment.range.start - 1];
|
|
1291
|
-
|
|
1292
1102
|
if (prev !== '\n' && prev !== '\t' && prev !== ' ') {
|
|
1293
1103
|
const msg = 'Comments must be separated from other tokens by white space characters';
|
|
1294
1104
|
errors.push(new PlainValue.YAMLSemanticError(comment, msg));
|
|
@@ -1306,14 +1116,12 @@ function resolveComments(collection, comments) {
|
|
|
1306
1116
|
comment
|
|
1307
1117
|
} of comments) {
|
|
1308
1118
|
let item = collection.items[before];
|
|
1309
|
-
|
|
1310
1119
|
if (!item) {
|
|
1311
1120
|
if (comment !== undefined) {
|
|
1312
1121
|
if (collection.comment) collection.comment += '\n' + comment;else collection.comment = comment;
|
|
1313
1122
|
}
|
|
1314
1123
|
} else {
|
|
1315
1124
|
if (afterKey && item.value) item = item.value;
|
|
1316
|
-
|
|
1317
1125
|
if (comment === undefined) {
|
|
1318
1126
|
if (afterKey || !item.commentBefore) item.spaceBefore = true;
|
|
1319
1127
|
} else {
|
|
@@ -1341,45 +1149,37 @@ function resolveTagHandle(doc, node) {
|
|
|
1341
1149
|
suffix
|
|
1342
1150
|
} = node.tag;
|
|
1343
1151
|
let prefix = doc.tagPrefixes.find(p => p.handle === handle);
|
|
1344
|
-
|
|
1345
1152
|
if (!prefix) {
|
|
1346
1153
|
const dtp = doc.getDefaults().tagPrefixes;
|
|
1347
1154
|
if (dtp) prefix = dtp.find(p => p.handle === handle);
|
|
1348
1155
|
if (!prefix) throw new PlainValue.YAMLSemanticError(node, `The ${handle} tag handle is non-default and was not declared.`);
|
|
1349
1156
|
}
|
|
1350
|
-
|
|
1351
1157
|
if (!suffix) throw new PlainValue.YAMLSemanticError(node, `The ${handle} tag has no suffix.`);
|
|
1352
|
-
|
|
1353
1158
|
if (handle === '!' && (doc.version || doc.options.version) === '1.0') {
|
|
1354
1159
|
if (suffix[0] === '^') {
|
|
1355
1160
|
doc.warnings.push(new PlainValue.YAMLWarning(node, 'YAML 1.0 ^ tag expansion is not supported'));
|
|
1356
1161
|
return suffix;
|
|
1357
1162
|
}
|
|
1358
|
-
|
|
1359
1163
|
if (/[:/]/.test(suffix)) {
|
|
1360
1164
|
// word/foo -> tag:word.yaml.org,2002:foo
|
|
1361
1165
|
const vocab = suffix.match(/^([a-z0-9-]+)\/(.*)/i);
|
|
1362
1166
|
return vocab ? `tag:${vocab[1]}.yaml.org,2002:${vocab[2]}` : `tag:${suffix}`;
|
|
1363
1167
|
}
|
|
1364
1168
|
}
|
|
1365
|
-
|
|
1366
1169
|
return prefix.prefix + decodeURIComponent(suffix);
|
|
1367
1170
|
}
|
|
1368
|
-
|
|
1369
1171
|
function resolveTagName(doc, node) {
|
|
1370
1172
|
const {
|
|
1371
1173
|
tag,
|
|
1372
1174
|
type
|
|
1373
1175
|
} = node;
|
|
1374
1176
|
let nonSpecific = false;
|
|
1375
|
-
|
|
1376
1177
|
if (tag) {
|
|
1377
1178
|
const {
|
|
1378
1179
|
handle,
|
|
1379
1180
|
suffix,
|
|
1380
1181
|
verbatim
|
|
1381
1182
|
} = tag;
|
|
1382
|
-
|
|
1383
1183
|
if (verbatim) {
|
|
1384
1184
|
if (verbatim !== '!' && verbatim !== '!!') return verbatim;
|
|
1385
1185
|
const msg = `Verbatim tags aren't resolved, so ${verbatim} is invalid.`;
|
|
@@ -1394,25 +1194,20 @@ function resolveTagName(doc, node) {
|
|
|
1394
1194
|
}
|
|
1395
1195
|
}
|
|
1396
1196
|
}
|
|
1397
|
-
|
|
1398
1197
|
switch (type) {
|
|
1399
1198
|
case PlainValue.Type.BLOCK_FOLDED:
|
|
1400
1199
|
case PlainValue.Type.BLOCK_LITERAL:
|
|
1401
1200
|
case PlainValue.Type.QUOTE_DOUBLE:
|
|
1402
1201
|
case PlainValue.Type.QUOTE_SINGLE:
|
|
1403
1202
|
return PlainValue.defaultTags.STR;
|
|
1404
|
-
|
|
1405
1203
|
case PlainValue.Type.FLOW_MAP:
|
|
1406
1204
|
case PlainValue.Type.MAP:
|
|
1407
1205
|
return PlainValue.defaultTags.MAP;
|
|
1408
|
-
|
|
1409
1206
|
case PlainValue.Type.FLOW_SEQ:
|
|
1410
1207
|
case PlainValue.Type.SEQ:
|
|
1411
1208
|
return PlainValue.defaultTags.SEQ;
|
|
1412
|
-
|
|
1413
1209
|
case PlainValue.Type.PLAIN:
|
|
1414
1210
|
return nonSpecific ? PlainValue.defaultTags.STR : null;
|
|
1415
|
-
|
|
1416
1211
|
default:
|
|
1417
1212
|
return null;
|
|
1418
1213
|
}
|
|
@@ -1423,7 +1218,6 @@ function resolveByTagName(doc, node, tagName) {
|
|
|
1423
1218
|
tags
|
|
1424
1219
|
} = doc.schema;
|
|
1425
1220
|
const matchWithTest = [];
|
|
1426
|
-
|
|
1427
1221
|
for (const tag of tags) {
|
|
1428
1222
|
if (tag.tag === tagName) {
|
|
1429
1223
|
if (tag.test) matchWithTest.push(tag);else {
|
|
@@ -1432,12 +1226,10 @@ function resolveByTagName(doc, node, tagName) {
|
|
|
1432
1226
|
}
|
|
1433
1227
|
}
|
|
1434
1228
|
}
|
|
1435
|
-
|
|
1436
1229
|
const str = resolveString(doc, node);
|
|
1437
1230
|
if (typeof str === 'string' && matchWithTest.length > 0) return resolveScalar(str, matchWithTest, tags.scalarFallback);
|
|
1438
1231
|
return null;
|
|
1439
1232
|
}
|
|
1440
|
-
|
|
1441
1233
|
function getFallbackTagName({
|
|
1442
1234
|
type
|
|
1443
1235
|
}) {
|
|
@@ -1445,31 +1237,30 @@ function getFallbackTagName({
|
|
|
1445
1237
|
case PlainValue.Type.FLOW_MAP:
|
|
1446
1238
|
case PlainValue.Type.MAP:
|
|
1447
1239
|
return PlainValue.defaultTags.MAP;
|
|
1448
|
-
|
|
1449
1240
|
case PlainValue.Type.FLOW_SEQ:
|
|
1450
1241
|
case PlainValue.Type.SEQ:
|
|
1451
1242
|
return PlainValue.defaultTags.SEQ;
|
|
1452
|
-
|
|
1453
1243
|
default:
|
|
1454
1244
|
return PlainValue.defaultTags.STR;
|
|
1455
1245
|
}
|
|
1456
1246
|
}
|
|
1457
|
-
|
|
1458
1247
|
function resolveTag(doc, node, tagName) {
|
|
1459
1248
|
try {
|
|
1460
1249
|
const res = resolveByTagName(doc, node, tagName);
|
|
1461
|
-
|
|
1462
1250
|
if (res) {
|
|
1463
1251
|
if (tagName && node.tag) res.tag = tagName;
|
|
1464
1252
|
return res;
|
|
1465
1253
|
}
|
|
1466
1254
|
} catch (error) {
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1255
|
+
if (error instanceof PlainValue.YAMLError) {
|
|
1256
|
+
if (!error.source) error.source = node;
|
|
1257
|
+
doc.errors.push(error);
|
|
1258
|
+
} else {
|
|
1259
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
1260
|
+
doc.errors.push(new PlainValue.YAMLSemanticError(node, msg));
|
|
1261
|
+
}
|
|
1470
1262
|
return null;
|
|
1471
1263
|
}
|
|
1472
|
-
|
|
1473
1264
|
try {
|
|
1474
1265
|
const fallback = getFallbackTagName(node);
|
|
1475
1266
|
if (!fallback) throw new Error(`The tag ${tagName} is unavailable`);
|
|
@@ -1493,7 +1284,6 @@ const isCollectionItem = node => {
|
|
|
1493
1284
|
} = node;
|
|
1494
1285
|
return type === PlainValue.Type.MAP_KEY || type === PlainValue.Type.MAP_VALUE || type === PlainValue.Type.SEQ_ITEM;
|
|
1495
1286
|
};
|
|
1496
|
-
|
|
1497
1287
|
function resolveNodeProps(errors, node) {
|
|
1498
1288
|
const comments = {
|
|
1499
1289
|
before: [],
|
|
@@ -1502,7 +1292,6 @@ function resolveNodeProps(errors, node) {
|
|
|
1502
1292
|
let hasAnchor = false;
|
|
1503
1293
|
let hasTag = false;
|
|
1504
1294
|
const props = isCollectionItem(node.context.parent) ? node.context.parent.props.concat(node.props) : node.props;
|
|
1505
|
-
|
|
1506
1295
|
for (const {
|
|
1507
1296
|
start,
|
|
1508
1297
|
end
|
|
@@ -1514,7 +1303,6 @@ function resolveNodeProps(errors, node) {
|
|
|
1514
1303
|
const msg = 'Comments must be separated from other tokens by white space characters';
|
|
1515
1304
|
errors.push(new PlainValue.YAMLSemanticError(node, msg));
|
|
1516
1305
|
}
|
|
1517
|
-
|
|
1518
1306
|
const {
|
|
1519
1307
|
header,
|
|
1520
1308
|
valueRange
|
|
@@ -1523,69 +1311,57 @@ function resolveNodeProps(errors, node) {
|
|
|
1523
1311
|
cc.push(node.context.src.slice(start + 1, end));
|
|
1524
1312
|
break;
|
|
1525
1313
|
}
|
|
1526
|
-
// Actual anchor & tag resolution is handled by schema, here we just complain
|
|
1527
1314
|
|
|
1315
|
+
// Actual anchor & tag resolution is handled by schema, here we just complain
|
|
1528
1316
|
case PlainValue.Char.ANCHOR:
|
|
1529
1317
|
if (hasAnchor) {
|
|
1530
1318
|
const msg = 'A node can have at most one anchor';
|
|
1531
1319
|
errors.push(new PlainValue.YAMLSemanticError(node, msg));
|
|
1532
1320
|
}
|
|
1533
|
-
|
|
1534
1321
|
hasAnchor = true;
|
|
1535
1322
|
break;
|
|
1536
|
-
|
|
1537
1323
|
case PlainValue.Char.TAG:
|
|
1538
1324
|
if (hasTag) {
|
|
1539
1325
|
const msg = 'A node can have at most one tag';
|
|
1540
1326
|
errors.push(new PlainValue.YAMLSemanticError(node, msg));
|
|
1541
1327
|
}
|
|
1542
|
-
|
|
1543
1328
|
hasTag = true;
|
|
1544
1329
|
break;
|
|
1545
1330
|
}
|
|
1546
1331
|
}
|
|
1547
|
-
|
|
1548
1332
|
return {
|
|
1549
1333
|
comments,
|
|
1550
1334
|
hasAnchor,
|
|
1551
1335
|
hasTag
|
|
1552
1336
|
};
|
|
1553
1337
|
}
|
|
1554
|
-
|
|
1555
1338
|
function resolveNodeValue(doc, node) {
|
|
1556
1339
|
const {
|
|
1557
1340
|
anchors,
|
|
1558
1341
|
errors,
|
|
1559
1342
|
schema
|
|
1560
1343
|
} = doc;
|
|
1561
|
-
|
|
1562
1344
|
if (node.type === PlainValue.Type.ALIAS) {
|
|
1563
1345
|
const name = node.rawValue;
|
|
1564
1346
|
const src = anchors.getNode(name);
|
|
1565
|
-
|
|
1566
1347
|
if (!src) {
|
|
1567
1348
|
const msg = `Aliased anchor not found: ${name}`;
|
|
1568
1349
|
errors.push(new PlainValue.YAMLReferenceError(node, msg));
|
|
1569
1350
|
return null;
|
|
1570
|
-
}
|
|
1571
|
-
|
|
1351
|
+
}
|
|
1572
1352
|
|
|
1353
|
+
// Lazy resolution for circular references
|
|
1573
1354
|
const res = new Alias(src);
|
|
1574
|
-
|
|
1575
1355
|
anchors._cstAliases.push(res);
|
|
1576
|
-
|
|
1577
1356
|
return res;
|
|
1578
1357
|
}
|
|
1579
|
-
|
|
1580
1358
|
const tagName = resolveTagName(doc, node);
|
|
1581
1359
|
if (tagName) return resolveTag(doc, node, tagName);
|
|
1582
|
-
|
|
1583
1360
|
if (node.type !== PlainValue.Type.PLAIN) {
|
|
1584
1361
|
const msg = `Failed to resolve ${node.type} node here`;
|
|
1585
1362
|
errors.push(new PlainValue.YAMLSyntaxError(node, msg));
|
|
1586
1363
|
return null;
|
|
1587
1364
|
}
|
|
1588
|
-
|
|
1589
1365
|
try {
|
|
1590
1366
|
const str = resolveString(doc, node);
|
|
1591
1367
|
return resolveScalar(str, schema.tags, schema.tags.scalarFallback);
|
|
@@ -1594,9 +1370,9 @@ function resolveNodeValue(doc, node) {
|
|
|
1594
1370
|
errors.push(error);
|
|
1595
1371
|
return null;
|
|
1596
1372
|
}
|
|
1597
|
-
}
|
|
1598
|
-
|
|
1373
|
+
}
|
|
1599
1374
|
|
|
1375
|
+
// sets node.resolved on success
|
|
1600
1376
|
function resolveNode(doc, node) {
|
|
1601
1377
|
if (!node) return null;
|
|
1602
1378
|
if (node.error) doc.errors.push(node.error);
|
|
@@ -1605,43 +1381,36 @@ function resolveNode(doc, node) {
|
|
|
1605
1381
|
hasAnchor,
|
|
1606
1382
|
hasTag
|
|
1607
1383
|
} = resolveNodeProps(doc.errors, node);
|
|
1608
|
-
|
|
1609
1384
|
if (hasAnchor) {
|
|
1610
1385
|
const {
|
|
1611
1386
|
anchors
|
|
1612
1387
|
} = doc;
|
|
1613
1388
|
const name = node.anchor;
|
|
1614
|
-
const prev = anchors.getNode(name);
|
|
1389
|
+
const prev = anchors.getNode(name);
|
|
1390
|
+
// At this point, aliases for any preceding node with the same anchor
|
|
1615
1391
|
// name have already been resolved, so it may safely be renamed.
|
|
1616
|
-
|
|
1617
|
-
|
|
1392
|
+
if (prev) anchors.map[anchors.newName(name)] = prev;
|
|
1393
|
+
// During parsing, we need to store the CST node in anchors.map as
|
|
1618
1394
|
// anchors need to be available during resolution to allow for
|
|
1619
1395
|
// circular references.
|
|
1620
|
-
|
|
1621
1396
|
anchors.map[name] = node;
|
|
1622
1397
|
}
|
|
1623
|
-
|
|
1624
1398
|
if (node.type === PlainValue.Type.ALIAS && (hasAnchor || hasTag)) {
|
|
1625
1399
|
const msg = 'An alias node must not specify any properties';
|
|
1626
1400
|
doc.errors.push(new PlainValue.YAMLSemanticError(node, msg));
|
|
1627
1401
|
}
|
|
1628
|
-
|
|
1629
1402
|
const res = resolveNodeValue(doc, node);
|
|
1630
|
-
|
|
1631
1403
|
if (res) {
|
|
1632
1404
|
res.range = [node.range.start, node.range.end];
|
|
1633
1405
|
if (doc.options.keepCstNodes) res.cstNode = node;
|
|
1634
1406
|
if (doc.options.keepNodeTypes) res.type = node.type;
|
|
1635
1407
|
const cb = comments.before.join('\n');
|
|
1636
|
-
|
|
1637
1408
|
if (cb) {
|
|
1638
1409
|
res.commentBefore = res.commentBefore ? `${res.commentBefore}\n${cb}` : cb;
|
|
1639
1410
|
}
|
|
1640
|
-
|
|
1641
1411
|
const ca = comments.after.join('\n');
|
|
1642
1412
|
if (ca) res.comment = res.comment ? `${res.comment}\n${ca}` : ca;
|
|
1643
1413
|
}
|
|
1644
|
-
|
|
1645
1414
|
return node.resolved = res;
|
|
1646
1415
|
}
|
|
1647
1416
|
|
|
@@ -1651,7 +1420,6 @@ function resolveMap(doc, cst) {
|
|
|
1651
1420
|
doc.errors.push(new PlainValue.YAMLSyntaxError(cst, msg));
|
|
1652
1421
|
return null;
|
|
1653
1422
|
}
|
|
1654
|
-
|
|
1655
1423
|
const {
|
|
1656
1424
|
comments,
|
|
1657
1425
|
items
|
|
@@ -1660,13 +1428,11 @@ function resolveMap(doc, cst) {
|
|
|
1660
1428
|
map.items = items;
|
|
1661
1429
|
resolveComments(map, comments);
|
|
1662
1430
|
let hasCollectionKey = false;
|
|
1663
|
-
|
|
1664
1431
|
for (let i = 0; i < items.length; ++i) {
|
|
1665
1432
|
const {
|
|
1666
1433
|
key: iKey
|
|
1667
1434
|
} = items[i];
|
|
1668
1435
|
if (iKey instanceof Collection) hasCollectionKey = true;
|
|
1669
|
-
|
|
1670
1436
|
if (doc.schema.merge && iKey && iKey.value === MERGE_KEY) {
|
|
1671
1437
|
items[i] = new Merge(items[i]);
|
|
1672
1438
|
const sources = items[i].value.items;
|
|
@@ -1681,7 +1447,6 @@ function resolveMap(doc, cst) {
|
|
|
1681
1447
|
if (type === PlainValue.Type.MAP || type === PlainValue.Type.FLOW_MAP) return false;
|
|
1682
1448
|
return error = 'Merge nodes aliases can only point to maps';
|
|
1683
1449
|
}
|
|
1684
|
-
|
|
1685
1450
|
return error = 'Merge nodes can only have Alias nodes as values';
|
|
1686
1451
|
});
|
|
1687
1452
|
if (error) doc.errors.push(new PlainValue.YAMLSemanticError(cst, error));
|
|
@@ -1690,7 +1455,6 @@ function resolveMap(doc, cst) {
|
|
|
1690
1455
|
const {
|
|
1691
1456
|
key: jKey
|
|
1692
1457
|
} = items[j];
|
|
1693
|
-
|
|
1694
1458
|
if (iKey === jKey || iKey && jKey && Object.prototype.hasOwnProperty.call(iKey, 'value') && iKey.value === jKey.value) {
|
|
1695
1459
|
const msg = `Map keys must be unique; "${iKey}" is repeated`;
|
|
1696
1460
|
doc.errors.push(new PlainValue.YAMLSemanticError(cst, msg));
|
|
@@ -1699,16 +1463,13 @@ function resolveMap(doc, cst) {
|
|
|
1699
1463
|
}
|
|
1700
1464
|
}
|
|
1701
1465
|
}
|
|
1702
|
-
|
|
1703
1466
|
if (hasCollectionKey && !doc.options.mapAsMap) {
|
|
1704
1467
|
const warn = 'Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.';
|
|
1705
1468
|
doc.warnings.push(new PlainValue.YAMLWarning(cst, warn));
|
|
1706
1469
|
}
|
|
1707
|
-
|
|
1708
1470
|
cst.resolved = map;
|
|
1709
1471
|
return map;
|
|
1710
1472
|
}
|
|
1711
|
-
|
|
1712
1473
|
const valueHasPairComment = ({
|
|
1713
1474
|
context: {
|
|
1714
1475
|
lineStart,
|
|
@@ -1723,42 +1484,33 @@ const valueHasPairComment = ({
|
|
|
1723
1484
|
} = props[0];
|
|
1724
1485
|
if (node && start > node.valueRange.start) return false;
|
|
1725
1486
|
if (src[start] !== PlainValue.Char.COMMENT) return false;
|
|
1726
|
-
|
|
1727
1487
|
for (let i = lineStart; i < start; ++i) if (src[i] === '\n') return false;
|
|
1728
|
-
|
|
1729
1488
|
return true;
|
|
1730
1489
|
};
|
|
1731
|
-
|
|
1732
1490
|
function resolvePairComment(item, pair) {
|
|
1733
1491
|
if (!valueHasPairComment(item)) return;
|
|
1734
1492
|
const comment = item.getPropValue(0, PlainValue.Char.COMMENT, true);
|
|
1735
1493
|
let found = false;
|
|
1736
1494
|
const cb = pair.value.commentBefore;
|
|
1737
|
-
|
|
1738
1495
|
if (cb && cb.startsWith(comment)) {
|
|
1739
1496
|
pair.value.commentBefore = cb.substr(comment.length + 1);
|
|
1740
1497
|
found = true;
|
|
1741
1498
|
} else {
|
|
1742
1499
|
const cc = pair.value.comment;
|
|
1743
|
-
|
|
1744
1500
|
if (!item.node && cc && cc.startsWith(comment)) {
|
|
1745
1501
|
pair.value.comment = cc.substr(comment.length + 1);
|
|
1746
1502
|
found = true;
|
|
1747
1503
|
}
|
|
1748
1504
|
}
|
|
1749
|
-
|
|
1750
1505
|
if (found) pair.comment = comment;
|
|
1751
1506
|
}
|
|
1752
|
-
|
|
1753
1507
|
function resolveBlockMapItems(doc, cst) {
|
|
1754
1508
|
const comments = [];
|
|
1755
1509
|
const items = [];
|
|
1756
1510
|
let key = undefined;
|
|
1757
1511
|
let keyStart = null;
|
|
1758
|
-
|
|
1759
1512
|
for (let i = 0; i < cst.items.length; ++i) {
|
|
1760
1513
|
const item = cst.items[i];
|
|
1761
|
-
|
|
1762
1514
|
switch (item.type) {
|
|
1763
1515
|
case PlainValue.Type.BLANK_LINE:
|
|
1764
1516
|
comments.push({
|
|
@@ -1766,7 +1518,6 @@ function resolveBlockMapItems(doc, cst) {
|
|
|
1766
1518
|
before: items.length
|
|
1767
1519
|
});
|
|
1768
1520
|
break;
|
|
1769
|
-
|
|
1770
1521
|
case PlainValue.Type.COMMENT:
|
|
1771
1522
|
comments.push({
|
|
1772
1523
|
afterKey: !!key,
|
|
@@ -1774,26 +1525,21 @@ function resolveBlockMapItems(doc, cst) {
|
|
|
1774
1525
|
comment: item.comment
|
|
1775
1526
|
});
|
|
1776
1527
|
break;
|
|
1777
|
-
|
|
1778
1528
|
case PlainValue.Type.MAP_KEY:
|
|
1779
1529
|
if (key !== undefined) items.push(new Pair(key));
|
|
1780
1530
|
if (item.error) doc.errors.push(item.error);
|
|
1781
1531
|
key = resolveNode(doc, item.node);
|
|
1782
1532
|
keyStart = null;
|
|
1783
1533
|
break;
|
|
1784
|
-
|
|
1785
1534
|
case PlainValue.Type.MAP_VALUE:
|
|
1786
1535
|
{
|
|
1787
1536
|
if (key === undefined) key = null;
|
|
1788
1537
|
if (item.error) doc.errors.push(item.error);
|
|
1789
|
-
|
|
1790
1538
|
if (!item.context.atLineStart && item.node && item.node.type === PlainValue.Type.MAP && !item.node.context.atLineStart) {
|
|
1791
1539
|
const msg = 'Nested mappings are not allowed in compact mappings';
|
|
1792
1540
|
doc.errors.push(new PlainValue.YAMLSemanticError(item.node, msg));
|
|
1793
1541
|
}
|
|
1794
|
-
|
|
1795
1542
|
let valueNode = item.node;
|
|
1796
|
-
|
|
1797
1543
|
if (!valueNode && item.props.length > 0) {
|
|
1798
1544
|
// Comments on an empty mapping value need to be preserved, so we
|
|
1799
1545
|
// need to construct a minimal empty node here to use instead of the
|
|
@@ -1812,44 +1558,35 @@ function resolveBlockMapItems(doc, cst) {
|
|
|
1812
1558
|
start: pos,
|
|
1813
1559
|
end: pos
|
|
1814
1560
|
};
|
|
1815
|
-
|
|
1816
1561
|
if (typeof item.range.origStart === 'number') {
|
|
1817
1562
|
const origPos = item.range.origStart + 1;
|
|
1818
1563
|
valueNode.range.origStart = valueNode.range.origEnd = origPos;
|
|
1819
1564
|
valueNode.valueRange.origStart = valueNode.valueRange.origEnd = origPos;
|
|
1820
1565
|
}
|
|
1821
1566
|
}
|
|
1822
|
-
|
|
1823
1567
|
const pair = new Pair(key, resolveNode(doc, valueNode));
|
|
1824
1568
|
resolvePairComment(item, pair);
|
|
1825
1569
|
items.push(pair);
|
|
1826
|
-
|
|
1827
1570
|
if (key && typeof keyStart === 'number') {
|
|
1828
1571
|
if (item.range.start > keyStart + 1024) doc.errors.push(getLongKeyError(cst, key));
|
|
1829
1572
|
}
|
|
1830
|
-
|
|
1831
1573
|
key = undefined;
|
|
1832
1574
|
keyStart = null;
|
|
1833
1575
|
}
|
|
1834
1576
|
break;
|
|
1835
|
-
|
|
1836
1577
|
default:
|
|
1837
1578
|
if (key !== undefined) items.push(new Pair(key));
|
|
1838
1579
|
key = resolveNode(doc, item);
|
|
1839
1580
|
keyStart = item.range.start;
|
|
1840
1581
|
if (item.error) doc.errors.push(item.error);
|
|
1841
|
-
|
|
1842
1582
|
next: for (let j = i + 1;; ++j) {
|
|
1843
1583
|
const nextItem = cst.items[j];
|
|
1844
|
-
|
|
1845
1584
|
switch (nextItem && nextItem.type) {
|
|
1846
1585
|
case PlainValue.Type.BLANK_LINE:
|
|
1847
1586
|
case PlainValue.Type.COMMENT:
|
|
1848
1587
|
continue next;
|
|
1849
|
-
|
|
1850
1588
|
case PlainValue.Type.MAP_VALUE:
|
|
1851
1589
|
break next;
|
|
1852
|
-
|
|
1853
1590
|
default:
|
|
1854
1591
|
{
|
|
1855
1592
|
const msg = 'Implicit map keys need to be followed by map values';
|
|
@@ -1858,47 +1595,38 @@ function resolveBlockMapItems(doc, cst) {
|
|
|
1858
1595
|
}
|
|
1859
1596
|
}
|
|
1860
1597
|
}
|
|
1861
|
-
|
|
1862
1598
|
if (item.valueRangeContainsNewline) {
|
|
1863
1599
|
const msg = 'Implicit map keys need to be on a single line';
|
|
1864
1600
|
doc.errors.push(new PlainValue.YAMLSemanticError(item, msg));
|
|
1865
1601
|
}
|
|
1866
|
-
|
|
1867
1602
|
}
|
|
1868
1603
|
}
|
|
1869
|
-
|
|
1870
1604
|
if (key !== undefined) items.push(new Pair(key));
|
|
1871
1605
|
return {
|
|
1872
1606
|
comments,
|
|
1873
1607
|
items
|
|
1874
1608
|
};
|
|
1875
1609
|
}
|
|
1876
|
-
|
|
1877
1610
|
function resolveFlowMapItems(doc, cst) {
|
|
1878
1611
|
const comments = [];
|
|
1879
1612
|
const items = [];
|
|
1880
1613
|
let key = undefined;
|
|
1881
1614
|
let explicitKey = false;
|
|
1882
1615
|
let next = '{';
|
|
1883
|
-
|
|
1884
1616
|
for (let i = 0; i < cst.items.length; ++i) {
|
|
1885
1617
|
const item = cst.items[i];
|
|
1886
|
-
|
|
1887
1618
|
if (typeof item.char === 'string') {
|
|
1888
1619
|
const {
|
|
1889
1620
|
char,
|
|
1890
1621
|
offset
|
|
1891
1622
|
} = item;
|
|
1892
|
-
|
|
1893
1623
|
if (char === '?' && key === undefined && !explicitKey) {
|
|
1894
1624
|
explicitKey = true;
|
|
1895
1625
|
next = ':';
|
|
1896
1626
|
continue;
|
|
1897
1627
|
}
|
|
1898
|
-
|
|
1899
1628
|
if (char === ':') {
|
|
1900
1629
|
if (key === undefined) key = null;
|
|
1901
|
-
|
|
1902
1630
|
if (next === ':') {
|
|
1903
1631
|
next = ',';
|
|
1904
1632
|
continue;
|
|
@@ -1908,25 +1636,21 @@ function resolveFlowMapItems(doc, cst) {
|
|
|
1908
1636
|
if (key === undefined && char !== ',') key = null;
|
|
1909
1637
|
explicitKey = false;
|
|
1910
1638
|
}
|
|
1911
|
-
|
|
1912
1639
|
if (key !== undefined) {
|
|
1913
1640
|
items.push(new Pair(key));
|
|
1914
1641
|
key = undefined;
|
|
1915
|
-
|
|
1916
1642
|
if (char === ',') {
|
|
1917
1643
|
next = ':';
|
|
1918
1644
|
continue;
|
|
1919
1645
|
}
|
|
1920
1646
|
}
|
|
1921
1647
|
}
|
|
1922
|
-
|
|
1923
1648
|
if (char === '}') {
|
|
1924
1649
|
if (i === cst.items.length - 1) continue;
|
|
1925
1650
|
} else if (char === next) {
|
|
1926
1651
|
next = ':';
|
|
1927
1652
|
continue;
|
|
1928
1653
|
}
|
|
1929
|
-
|
|
1930
1654
|
const msg = `Flow map contains an unexpected ${char}`;
|
|
1931
1655
|
const err = new PlainValue.YAMLSyntaxError(cst, msg);
|
|
1932
1656
|
err.offset = offset;
|
|
@@ -1953,7 +1677,6 @@ function resolveFlowMapItems(doc, cst) {
|
|
|
1953
1677
|
explicitKey = false;
|
|
1954
1678
|
}
|
|
1955
1679
|
}
|
|
1956
|
-
|
|
1957
1680
|
checkFlowCollectionEnd(doc.errors, cst);
|
|
1958
1681
|
if (key !== undefined) items.push(new Pair(key));
|
|
1959
1682
|
return {
|
|
@@ -1968,7 +1691,6 @@ function resolveSeq(doc, cst) {
|
|
|
1968
1691
|
doc.errors.push(new PlainValue.YAMLSyntaxError(cst, msg));
|
|
1969
1692
|
return null;
|
|
1970
1693
|
}
|
|
1971
|
-
|
|
1972
1694
|
const {
|
|
1973
1695
|
comments,
|
|
1974
1696
|
items
|
|
@@ -1976,60 +1698,48 @@ function resolveSeq(doc, cst) {
|
|
|
1976
1698
|
const seq = new YAMLSeq();
|
|
1977
1699
|
seq.items = items;
|
|
1978
1700
|
resolveComments(seq, comments);
|
|
1979
|
-
|
|
1980
1701
|
if (!doc.options.mapAsMap && items.some(it => it instanceof Pair && it.key instanceof Collection)) {
|
|
1981
1702
|
const warn = 'Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.';
|
|
1982
1703
|
doc.warnings.push(new PlainValue.YAMLWarning(cst, warn));
|
|
1983
1704
|
}
|
|
1984
|
-
|
|
1985
1705
|
cst.resolved = seq;
|
|
1986
1706
|
return seq;
|
|
1987
1707
|
}
|
|
1988
|
-
|
|
1989
1708
|
function resolveBlockSeqItems(doc, cst) {
|
|
1990
1709
|
const comments = [];
|
|
1991
1710
|
const items = [];
|
|
1992
|
-
|
|
1993
1711
|
for (let i = 0; i < cst.items.length; ++i) {
|
|
1994
1712
|
const item = cst.items[i];
|
|
1995
|
-
|
|
1996
1713
|
switch (item.type) {
|
|
1997
1714
|
case PlainValue.Type.BLANK_LINE:
|
|
1998
1715
|
comments.push({
|
|
1999
1716
|
before: items.length
|
|
2000
1717
|
});
|
|
2001
1718
|
break;
|
|
2002
|
-
|
|
2003
1719
|
case PlainValue.Type.COMMENT:
|
|
2004
1720
|
comments.push({
|
|
2005
1721
|
comment: item.comment,
|
|
2006
1722
|
before: items.length
|
|
2007
1723
|
});
|
|
2008
1724
|
break;
|
|
2009
|
-
|
|
2010
1725
|
case PlainValue.Type.SEQ_ITEM:
|
|
2011
1726
|
if (item.error) doc.errors.push(item.error);
|
|
2012
1727
|
items.push(resolveNode(doc, item.node));
|
|
2013
|
-
|
|
2014
1728
|
if (item.hasProps) {
|
|
2015
1729
|
const msg = 'Sequence items cannot have tags or anchors before the - indicator';
|
|
2016
1730
|
doc.errors.push(new PlainValue.YAMLSemanticError(item, msg));
|
|
2017
1731
|
}
|
|
2018
|
-
|
|
2019
1732
|
break;
|
|
2020
|
-
|
|
2021
1733
|
default:
|
|
2022
1734
|
if (item.error) doc.errors.push(item.error);
|
|
2023
1735
|
doc.errors.push(new PlainValue.YAMLSyntaxError(item, `Unexpected ${item.type} node in sequence`));
|
|
2024
1736
|
}
|
|
2025
1737
|
}
|
|
2026
|
-
|
|
2027
1738
|
return {
|
|
2028
1739
|
comments,
|
|
2029
1740
|
items
|
|
2030
1741
|
};
|
|
2031
1742
|
}
|
|
2032
|
-
|
|
2033
1743
|
function resolveFlowSeqItems(doc, cst) {
|
|
2034
1744
|
const comments = [];
|
|
2035
1745
|
const items = [];
|
|
@@ -2038,16 +1748,13 @@ function resolveFlowSeqItems(doc, cst) {
|
|
|
2038
1748
|
let keyStart = null;
|
|
2039
1749
|
let next = '[';
|
|
2040
1750
|
let prevItem = null;
|
|
2041
|
-
|
|
2042
1751
|
for (let i = 0; i < cst.items.length; ++i) {
|
|
2043
1752
|
const item = cst.items[i];
|
|
2044
|
-
|
|
2045
1753
|
if (typeof item.char === 'string') {
|
|
2046
1754
|
const {
|
|
2047
1755
|
char,
|
|
2048
1756
|
offset
|
|
2049
1757
|
} = item;
|
|
2050
|
-
|
|
2051
1758
|
if (char !== ':' && (explicitKey || key !== undefined)) {
|
|
2052
1759
|
if (explicitKey && key === undefined) key = next ? items.pop() : null;
|
|
2053
1760
|
items.push(new Pair(key));
|
|
@@ -2055,7 +1762,6 @@ function resolveFlowSeqItems(doc, cst) {
|
|
|
2055
1762
|
key = undefined;
|
|
2056
1763
|
keyStart = null;
|
|
2057
1764
|
}
|
|
2058
|
-
|
|
2059
1765
|
if (char === next) {
|
|
2060
1766
|
next = null;
|
|
2061
1767
|
} else if (!next && char === '?') {
|
|
@@ -2063,21 +1769,18 @@ function resolveFlowSeqItems(doc, cst) {
|
|
|
2063
1769
|
} else if (next !== '[' && char === ':' && key === undefined) {
|
|
2064
1770
|
if (next === ',') {
|
|
2065
1771
|
key = items.pop();
|
|
2066
|
-
|
|
2067
1772
|
if (key instanceof Pair) {
|
|
2068
1773
|
const msg = 'Chaining flow sequence pairs is invalid';
|
|
2069
1774
|
const err = new PlainValue.YAMLSemanticError(cst, msg);
|
|
2070
1775
|
err.offset = offset;
|
|
2071
1776
|
doc.errors.push(err);
|
|
2072
1777
|
}
|
|
2073
|
-
|
|
2074
1778
|
if (!explicitKey && typeof keyStart === 'number') {
|
|
2075
1779
|
const keyEnd = item.range ? item.range.start : item.offset;
|
|
2076
1780
|
if (keyEnd > keyStart + 1024) doc.errors.push(getLongKeyError(cst, key));
|
|
2077
1781
|
const {
|
|
2078
1782
|
src
|
|
2079
1783
|
} = prevItem.context;
|
|
2080
|
-
|
|
2081
1784
|
for (let i = keyStart; i < keyEnd; ++i) if (src[i] === '\n') {
|
|
2082
1785
|
const msg = 'Implicit keys of flow sequence pairs need to be on a single line';
|
|
2083
1786
|
doc.errors.push(new PlainValue.YAMLSemanticError(prevItem, msg));
|
|
@@ -2087,7 +1790,6 @@ function resolveFlowSeqItems(doc, cst) {
|
|
|
2087
1790
|
} else {
|
|
2088
1791
|
key = null;
|
|
2089
1792
|
}
|
|
2090
|
-
|
|
2091
1793
|
keyStart = null;
|
|
2092
1794
|
explicitKey = false;
|
|
2093
1795
|
next = null;
|
|
@@ -2112,9 +1814,7 @@ function resolveFlowSeqItems(doc, cst) {
|
|
|
2112
1814
|
const msg = `Expected a ${next} in flow sequence`;
|
|
2113
1815
|
doc.errors.push(new PlainValue.YAMLSemanticError(item, msg));
|
|
2114
1816
|
}
|
|
2115
|
-
|
|
2116
1817
|
const value = resolveNode(doc, item);
|
|
2117
|
-
|
|
2118
1818
|
if (key === undefined) {
|
|
2119
1819
|
items.push(value);
|
|
2120
1820
|
prevItem = item;
|
|
@@ -2122,12 +1822,10 @@ function resolveFlowSeqItems(doc, cst) {
|
|
|
2122
1822
|
items.push(new Pair(key, value));
|
|
2123
1823
|
key = undefined;
|
|
2124
1824
|
}
|
|
2125
|
-
|
|
2126
1825
|
keyStart = item.range.start;
|
|
2127
1826
|
next = ',';
|
|
2128
1827
|
}
|
|
2129
1828
|
}
|
|
2130
|
-
|
|
2131
1829
|
checkFlowCollectionEnd(doc.errors, cst);
|
|
2132
1830
|
if (key !== undefined) items.push(new Pair(key));
|
|
2133
1831
|
return {
|