@lumpcode/core 0.0.6 → 0.0.7
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/README.md +2 -2
- package/dist/helpers/executeStepsForContextList/main.d.ts.map +1 -1
- package/dist/helpers/getToDoContextList/main.d.ts +1 -1
- package/dist/helpers/getToDoContextList/main.d.ts.map +1 -1
- package/dist/index.cjs +3024 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3021 -20
- package/dist/index.js.map +1 -1
- package/dist/types/Context.d.ts +2 -2
- package/dist/types/Context.d.ts.map +1 -1
- package/dist/types/HistoryEntry.d.ts +16 -0
- package/dist/types/HistoryEntry.d.ts.map +1 -0
- package/dist/types/PostCommandExecFn.d.ts +1 -0
- package/dist/types/PostCommandExecFn.d.ts.map +1 -1
- package/dist/types/Step.d.ts +1 -1
- package/dist/types/Step.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/historyFile/index.d.ts +2 -0
- package/dist/utils/historyFile/index.d.ts.map +1 -0
- package/dist/utils/historyFile/main.d.ts +15 -0
- package/dist/utils/historyFile/main.d.ts.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/package.json +19 -2
package/dist/index.js
CHANGED
|
@@ -2,9 +2,9 @@ import { exec, spawn } from 'node:child_process';
|
|
|
2
2
|
import { promisify } from 'node:util';
|
|
3
3
|
import * as fs from 'node:fs';
|
|
4
4
|
import * as path from 'node:path';
|
|
5
|
-
import
|
|
6
|
-
import { dirname } from 'path';
|
|
5
|
+
import { extname, dirname } from 'node:path';
|
|
7
6
|
import * as fs$1 from 'node:fs/promises';
|
|
7
|
+
import { readFile, mkdir, writeFile, stat } from 'node:fs/promises';
|
|
8
8
|
import ignore from 'ignore';
|
|
9
9
|
import z from 'zod';
|
|
10
10
|
|
|
@@ -260,6 +260,3014 @@ function formatExecFailureMessage(input) {
|
|
|
260
260
|
return `${label} failed: ${detail}`;
|
|
261
261
|
}
|
|
262
262
|
|
|
263
|
+
/*! js-yaml 5.0.0 https://github.com/nodeca/js-yaml @license MIT */
|
|
264
|
+
//#region src/tag.ts
|
|
265
|
+
var NOT_RESOLVED = Symbol("NOT_RESOLVED");
|
|
266
|
+
var MERGE_KEY = Symbol("MERGE_KEY");
|
|
267
|
+
function defineScalarTag(tagName, options) {
|
|
268
|
+
return {
|
|
269
|
+
tagName,
|
|
270
|
+
nodeKind: "scalar",
|
|
271
|
+
implicit: options.implicit ?? false,
|
|
272
|
+
matchByTagPrefix: options.matchByTagPrefix ?? false,
|
|
273
|
+
implicitFirstChars: options.implicitFirstChars ?? null,
|
|
274
|
+
resolve: options.resolve,
|
|
275
|
+
identify: options.identify ?? null,
|
|
276
|
+
represent: options.represent ?? ((data) => String(data)),
|
|
277
|
+
representTagName: options.representTagName ?? null
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
function defineSequenceTag(tagName, options) {
|
|
281
|
+
return {
|
|
282
|
+
tagName,
|
|
283
|
+
nodeKind: "sequence",
|
|
284
|
+
implicit: false,
|
|
285
|
+
matchByTagPrefix: options.matchByTagPrefix ?? false,
|
|
286
|
+
create: options.create,
|
|
287
|
+
addItem: options.addItem,
|
|
288
|
+
identify: options.identify ?? null,
|
|
289
|
+
represent: options.represent ?? ((data) => data),
|
|
290
|
+
representTagName: options.representTagName ?? null
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
function defineMappingTag(tagName, options) {
|
|
294
|
+
return {
|
|
295
|
+
tagName,
|
|
296
|
+
nodeKind: "mapping",
|
|
297
|
+
implicit: false,
|
|
298
|
+
matchByTagPrefix: options.matchByTagPrefix ?? false,
|
|
299
|
+
create: options.create,
|
|
300
|
+
addPair: options.addPair,
|
|
301
|
+
has: options.has,
|
|
302
|
+
keys: options.keys,
|
|
303
|
+
get: options.get,
|
|
304
|
+
identify: options.identify ?? null,
|
|
305
|
+
represent: options.represent ?? ((data) => data),
|
|
306
|
+
representTagName: options.representTagName ?? null
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
//#endregion
|
|
310
|
+
//#region src/tag/scalar/str.ts
|
|
311
|
+
var strTag = defineScalarTag("tag:yaml.org,2002:str", {
|
|
312
|
+
resolve: (source) => source,
|
|
313
|
+
identify: (data) => typeof data === "string"
|
|
314
|
+
});
|
|
315
|
+
//#endregion
|
|
316
|
+
//#region src/tag/scalar/null_core.ts
|
|
317
|
+
var NULL_VALUES$1 = [
|
|
318
|
+
"",
|
|
319
|
+
"~",
|
|
320
|
+
"null",
|
|
321
|
+
"Null",
|
|
322
|
+
"NULL"
|
|
323
|
+
];
|
|
324
|
+
var nullCoreTag = defineScalarTag("tag:yaml.org,2002:null", {
|
|
325
|
+
implicit: true,
|
|
326
|
+
implicitFirstChars: [
|
|
327
|
+
"",
|
|
328
|
+
"~",
|
|
329
|
+
"n",
|
|
330
|
+
"N"
|
|
331
|
+
],
|
|
332
|
+
resolve: (source) => {
|
|
333
|
+
if (NULL_VALUES$1.indexOf(source) !== -1) return null;
|
|
334
|
+
return NOT_RESOLVED;
|
|
335
|
+
},
|
|
336
|
+
identify: (object) => object === null,
|
|
337
|
+
represent: () => "null"
|
|
338
|
+
});
|
|
339
|
+
//#endregion
|
|
340
|
+
//#region src/tag/scalar/null_json.ts
|
|
341
|
+
var nullJsonTag = defineScalarTag("tag:yaml.org,2002:null", {
|
|
342
|
+
implicit: true,
|
|
343
|
+
implicitFirstChars: ["n"],
|
|
344
|
+
resolve: (source, isExplicit) => {
|
|
345
|
+
if (source === "null" || isExplicit && source === "") return null;
|
|
346
|
+
return NOT_RESOLVED;
|
|
347
|
+
},
|
|
348
|
+
identify: (object) => object === null,
|
|
349
|
+
represent: () => "null"
|
|
350
|
+
});
|
|
351
|
+
//#endregion
|
|
352
|
+
//#region src/tag/scalar/null_yaml11.ts
|
|
353
|
+
var NULL_VALUES = [
|
|
354
|
+
"",
|
|
355
|
+
"~",
|
|
356
|
+
"null",
|
|
357
|
+
"Null",
|
|
358
|
+
"NULL"
|
|
359
|
+
];
|
|
360
|
+
var nullYaml11Tag = defineScalarTag("tag:yaml.org,2002:null", {
|
|
361
|
+
implicit: true,
|
|
362
|
+
implicitFirstChars: [
|
|
363
|
+
"",
|
|
364
|
+
"~",
|
|
365
|
+
"n",
|
|
366
|
+
"N"
|
|
367
|
+
],
|
|
368
|
+
resolve: (source) => {
|
|
369
|
+
if (NULL_VALUES.indexOf(source) !== -1) return null;
|
|
370
|
+
return NOT_RESOLVED;
|
|
371
|
+
},
|
|
372
|
+
identify: (object) => object === null,
|
|
373
|
+
represent: () => "null"
|
|
374
|
+
});
|
|
375
|
+
//#endregion
|
|
376
|
+
//#region src/tag/scalar/bool_core.ts
|
|
377
|
+
var TRUE_VALUES$2 = [
|
|
378
|
+
"true",
|
|
379
|
+
"True",
|
|
380
|
+
"TRUE"
|
|
381
|
+
];
|
|
382
|
+
var FALSE_VALUES$2 = [
|
|
383
|
+
"false",
|
|
384
|
+
"False",
|
|
385
|
+
"FALSE"
|
|
386
|
+
];
|
|
387
|
+
var boolCoreTag = defineScalarTag("tag:yaml.org,2002:bool", {
|
|
388
|
+
implicit: true,
|
|
389
|
+
implicitFirstChars: [
|
|
390
|
+
"t",
|
|
391
|
+
"T",
|
|
392
|
+
"f",
|
|
393
|
+
"F"
|
|
394
|
+
],
|
|
395
|
+
resolve: (source) => {
|
|
396
|
+
if (TRUE_VALUES$2.indexOf(source) !== -1) return true;
|
|
397
|
+
if (FALSE_VALUES$2.indexOf(source) !== -1) return false;
|
|
398
|
+
return NOT_RESOLVED;
|
|
399
|
+
},
|
|
400
|
+
identify: (object) => Object.prototype.toString.call(object) === "[object Boolean]",
|
|
401
|
+
represent: (object) => object ? "true" : "false"
|
|
402
|
+
});
|
|
403
|
+
//#endregion
|
|
404
|
+
//#region src/tag/scalar/bool_json.ts
|
|
405
|
+
var TRUE_VALUES$1 = ["true"];
|
|
406
|
+
var FALSE_VALUES$1 = ["false"];
|
|
407
|
+
var boolJsonTag = defineScalarTag("tag:yaml.org,2002:bool", {
|
|
408
|
+
implicit: true,
|
|
409
|
+
implicitFirstChars: ["t", "f"],
|
|
410
|
+
resolve: (source) => {
|
|
411
|
+
if (TRUE_VALUES$1.indexOf(source) !== -1) return true;
|
|
412
|
+
if (FALSE_VALUES$1.indexOf(source) !== -1) return false;
|
|
413
|
+
return NOT_RESOLVED;
|
|
414
|
+
},
|
|
415
|
+
identify: (object) => Object.prototype.toString.call(object) === "[object Boolean]",
|
|
416
|
+
represent: (object) => object ? "true" : "false"
|
|
417
|
+
});
|
|
418
|
+
//#endregion
|
|
419
|
+
//#region src/tag/scalar/bool_yaml11.ts
|
|
420
|
+
var TRUE_VALUES = [
|
|
421
|
+
"true",
|
|
422
|
+
"True",
|
|
423
|
+
"TRUE",
|
|
424
|
+
"y",
|
|
425
|
+
"Y",
|
|
426
|
+
"yes",
|
|
427
|
+
"Yes",
|
|
428
|
+
"YES",
|
|
429
|
+
"on",
|
|
430
|
+
"On",
|
|
431
|
+
"ON"
|
|
432
|
+
];
|
|
433
|
+
var FALSE_VALUES = [
|
|
434
|
+
"false",
|
|
435
|
+
"False",
|
|
436
|
+
"FALSE",
|
|
437
|
+
"n",
|
|
438
|
+
"N",
|
|
439
|
+
"no",
|
|
440
|
+
"No",
|
|
441
|
+
"NO",
|
|
442
|
+
"off",
|
|
443
|
+
"Off",
|
|
444
|
+
"OFF"
|
|
445
|
+
];
|
|
446
|
+
var boolYaml11Tag = defineScalarTag("tag:yaml.org,2002:bool", {
|
|
447
|
+
implicit: true,
|
|
448
|
+
implicitFirstChars: [
|
|
449
|
+
"y",
|
|
450
|
+
"Y",
|
|
451
|
+
"n",
|
|
452
|
+
"N",
|
|
453
|
+
"t",
|
|
454
|
+
"T",
|
|
455
|
+
"f",
|
|
456
|
+
"F",
|
|
457
|
+
"o",
|
|
458
|
+
"O"
|
|
459
|
+
],
|
|
460
|
+
resolve: (source) => {
|
|
461
|
+
if (TRUE_VALUES.indexOf(source) !== -1) return true;
|
|
462
|
+
if (FALSE_VALUES.indexOf(source) !== -1) return false;
|
|
463
|
+
return NOT_RESOLVED;
|
|
464
|
+
},
|
|
465
|
+
identify: (object) => Object.prototype.toString.call(object) === "[object Boolean]",
|
|
466
|
+
represent: (object) => object ? "true" : "false"
|
|
467
|
+
});
|
|
468
|
+
//#endregion
|
|
469
|
+
//#region src/tag/scalar/int_core.ts
|
|
470
|
+
var YAML_INTEGER_IMPLICIT_PATTERN$1 = /* @__PURE__ */ new RegExp("^(?:0o[0-7]+|0x[0-9a-fA-F]+|[-+]?[0-9]+)$");
|
|
471
|
+
var YAML_INTEGER_EXPLICIT_PATTERN$1 = /* @__PURE__ */ new RegExp("^(?:[-+]?0b[0-1]+|[-+]?0o[0-7]+|[-+]?0x[0-9a-fA-F]+|[-+]?[0-9]+)$");
|
|
472
|
+
function parseYamlInteger$2(source) {
|
|
473
|
+
let value = source;
|
|
474
|
+
let sign = 1;
|
|
475
|
+
if (value[0] === "-" || value[0] === "+") {
|
|
476
|
+
if (value[0] === "-") sign = -1;
|
|
477
|
+
value = value.slice(1);
|
|
478
|
+
}
|
|
479
|
+
if (value.startsWith("0b")) return sign * parseInt(value.slice(2), 2);
|
|
480
|
+
if (value.startsWith("0o")) return sign * parseInt(value.slice(2), 8);
|
|
481
|
+
if (value.startsWith("0x")) return sign * parseInt(value.slice(2), 16);
|
|
482
|
+
return sign * parseInt(value, 10);
|
|
483
|
+
}
|
|
484
|
+
function resolveYamlInteger$2(source, isExplicit) {
|
|
485
|
+
if (isExplicit) {
|
|
486
|
+
if (!YAML_INTEGER_EXPLICIT_PATTERN$1.test(source)) return NOT_RESOLVED;
|
|
487
|
+
} else if (!YAML_INTEGER_IMPLICIT_PATTERN$1.test(source)) return NOT_RESOLVED;
|
|
488
|
+
const result = parseYamlInteger$2(source);
|
|
489
|
+
return Number.isFinite(result) ? result : NOT_RESOLVED;
|
|
490
|
+
}
|
|
491
|
+
var intCoreTag = defineScalarTag("tag:yaml.org,2002:int", {
|
|
492
|
+
implicit: true,
|
|
493
|
+
implicitFirstChars: [
|
|
494
|
+
"-",
|
|
495
|
+
"+",
|
|
496
|
+
..."0123456789"
|
|
497
|
+
],
|
|
498
|
+
resolve: resolveYamlInteger$2,
|
|
499
|
+
identify: (object) => Object.prototype.toString.call(object) === "[object Number]" && object % 1 === 0 && !Object.is(object, -0),
|
|
500
|
+
represent: (object) => object.toString(10)
|
|
501
|
+
});
|
|
502
|
+
//#endregion
|
|
503
|
+
//#region src/tag/scalar/int_json.ts
|
|
504
|
+
var YAML_INTEGER_IMPLICIT_PATTERN = /* @__PURE__ */ new RegExp("^-?(?:0|[1-9][0-9]*)$");
|
|
505
|
+
var YAML_INTEGER_EXPLICIT_PATTERN = /* @__PURE__ */ new RegExp("^(?:[-+]?0b[0-1]+|[-+]?0o[0-7]+|[-+]?0x[0-9a-fA-F]+|[-+]?[0-9]+)$");
|
|
506
|
+
function parseYamlInteger$1(source) {
|
|
507
|
+
let value = source;
|
|
508
|
+
let sign = 1;
|
|
509
|
+
if (value[0] === "-" || value[0] === "+") {
|
|
510
|
+
if (value[0] === "-") sign = -1;
|
|
511
|
+
value = value.slice(1);
|
|
512
|
+
}
|
|
513
|
+
if (value.startsWith("0b")) return sign * parseInt(value.slice(2), 2);
|
|
514
|
+
if (value.startsWith("0o")) return sign * parseInt(value.slice(2), 8);
|
|
515
|
+
if (value.startsWith("0x")) return sign * parseInt(value.slice(2), 16);
|
|
516
|
+
return sign * parseInt(value, 10);
|
|
517
|
+
}
|
|
518
|
+
function resolveYamlInteger$1(source, isExplicit) {
|
|
519
|
+
if (isExplicit) {
|
|
520
|
+
if (!YAML_INTEGER_EXPLICIT_PATTERN.test(source)) return NOT_RESOLVED;
|
|
521
|
+
} else if (!YAML_INTEGER_IMPLICIT_PATTERN.test(source)) return NOT_RESOLVED;
|
|
522
|
+
const result = parseYamlInteger$1(source);
|
|
523
|
+
return Number.isFinite(result) ? result : NOT_RESOLVED;
|
|
524
|
+
}
|
|
525
|
+
var intJsonTag = defineScalarTag("tag:yaml.org,2002:int", {
|
|
526
|
+
implicit: true,
|
|
527
|
+
implicitFirstChars: ["-", ..."0123456789"],
|
|
528
|
+
resolve: resolveYamlInteger$1,
|
|
529
|
+
identify: (object) => Object.prototype.toString.call(object) === "[object Number]" && object % 1 === 0 && !Object.is(object, -0),
|
|
530
|
+
represent: (object) => object.toString(10)
|
|
531
|
+
});
|
|
532
|
+
//#endregion
|
|
533
|
+
//#region src/tag/scalar/int_yaml11.ts
|
|
534
|
+
var YAML_INTEGER_PATTERN = /* @__PURE__ */ new RegExp("^(?:[-+]?0b[0-1_]+|[-+]?0[0-7_]+|[-+]?0x[0-9a-fA-F_]+|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+|[-+]?(?:0|[1-9][0-9_]*))$");
|
|
535
|
+
function parseYamlInteger(source) {
|
|
536
|
+
let value = source.replace(/_/g, "");
|
|
537
|
+
let sign = 1;
|
|
538
|
+
if (value[0] === "-" || value[0] === "+") {
|
|
539
|
+
if (value[0] === "-") sign = -1;
|
|
540
|
+
value = value.slice(1);
|
|
541
|
+
}
|
|
542
|
+
if (value.startsWith("0b")) return sign * parseInt(value.slice(2), 2);
|
|
543
|
+
if (value.startsWith("0x")) return sign * parseInt(value.slice(2), 16);
|
|
544
|
+
if (value.includes(":")) {
|
|
545
|
+
let result = 0;
|
|
546
|
+
for (const part of value.split(":")) result = result * 60 + Number(part);
|
|
547
|
+
return sign * result;
|
|
548
|
+
}
|
|
549
|
+
if (value !== "0" && value[0] === "0") return sign * parseInt(value, 8);
|
|
550
|
+
return sign * parseInt(value, 10);
|
|
551
|
+
}
|
|
552
|
+
function resolveYamlInteger(source) {
|
|
553
|
+
if (!YAML_INTEGER_PATTERN.test(source)) return NOT_RESOLVED;
|
|
554
|
+
const result = parseYamlInteger(source);
|
|
555
|
+
return Number.isFinite(result) ? result : NOT_RESOLVED;
|
|
556
|
+
}
|
|
557
|
+
var intYaml11Tag = defineScalarTag("tag:yaml.org,2002:int", {
|
|
558
|
+
implicit: true,
|
|
559
|
+
implicitFirstChars: [
|
|
560
|
+
"-",
|
|
561
|
+
"+",
|
|
562
|
+
..."0123456789"
|
|
563
|
+
],
|
|
564
|
+
resolve: resolveYamlInteger,
|
|
565
|
+
identify: (object) => Object.prototype.toString.call(object) === "[object Number]" && object % 1 === 0 && !Object.is(object, -0),
|
|
566
|
+
represent: (object) => object.toString(10)
|
|
567
|
+
});
|
|
568
|
+
//#endregion
|
|
569
|
+
//#region src/tag/scalar/float_core.ts
|
|
570
|
+
var YAML_FLOAT_PATTERN$1 = /* @__PURE__ */ new RegExp("^(?:[-+]?[0-9]+(?:\\.[0-9]*)?(?:[eE][-+]?[0-9]+)?|[-+]?\\.[0-9]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");
|
|
571
|
+
var YAML_FLOAT_SPECIAL_PATTERN$1 = /* @__PURE__ */ new RegExp("^(?:[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");
|
|
572
|
+
function resolveYamlFloat$2(source) {
|
|
573
|
+
if (!YAML_FLOAT_PATTERN$1.test(source)) return NOT_RESOLVED;
|
|
574
|
+
let value = source.toLowerCase();
|
|
575
|
+
const sign = value[0] === "-" ? -1 : 1;
|
|
576
|
+
if ("+-".includes(value[0])) value = value.slice(1);
|
|
577
|
+
if (value === ".inf") return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
|
|
578
|
+
if (value === ".nan") return NaN;
|
|
579
|
+
const result = sign * parseFloat(value);
|
|
580
|
+
if (Number.isFinite(result) || YAML_FLOAT_SPECIAL_PATTERN$1.test(source)) return result;
|
|
581
|
+
return NOT_RESOLVED;
|
|
582
|
+
}
|
|
583
|
+
function representYamlFloat$2(object) {
|
|
584
|
+
if (isNaN(object)) return ".nan";
|
|
585
|
+
if (object === Number.POSITIVE_INFINITY) return ".inf";
|
|
586
|
+
if (object === Number.NEGATIVE_INFINITY) return "-.inf";
|
|
587
|
+
if (Object.is(object, -0)) return "-0.0";
|
|
588
|
+
const result = object.toString(10);
|
|
589
|
+
return /^[-+]?[0-9]+e/.test(result) ? result.replace("e", ".e") : result;
|
|
590
|
+
}
|
|
591
|
+
var floatCoreTag = defineScalarTag("tag:yaml.org,2002:float", {
|
|
592
|
+
implicit: true,
|
|
593
|
+
implicitFirstChars: [
|
|
594
|
+
"-",
|
|
595
|
+
"+",
|
|
596
|
+
".",
|
|
597
|
+
..."0123456789"
|
|
598
|
+
],
|
|
599
|
+
resolve: resolveYamlFloat$2,
|
|
600
|
+
identify: (object) => Object.prototype.toString.call(object) === "[object Number]" && (object % 1 !== 0 || Object.is(object, -0)),
|
|
601
|
+
represent: representYamlFloat$2
|
|
602
|
+
});
|
|
603
|
+
//#endregion
|
|
604
|
+
//#region src/tag/scalar/float_json.ts
|
|
605
|
+
var YAML_FLOAT_IMPLICIT_PATTERN = /* @__PURE__ */ new RegExp("^-?(?:0|[1-9][0-9]*)(?:\\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$");
|
|
606
|
+
var YAML_FLOAT_EXPLICIT_PATTERN = /* @__PURE__ */ new RegExp("^(?:[-+]?[0-9]+(?:\\.[0-9]*)?(?:[eE][-+]?[0-9]+)?|[-+]?\\.[0-9]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");
|
|
607
|
+
function resolveYamlFloat$1(source, isExplicit) {
|
|
608
|
+
if (isExplicit) {
|
|
609
|
+
if (!YAML_FLOAT_EXPLICIT_PATTERN.test(source)) return NOT_RESOLVED;
|
|
610
|
+
let value = source.toLowerCase();
|
|
611
|
+
const sign = value[0] === "-" ? -1 : 1;
|
|
612
|
+
if ("+-".includes(value[0])) value = value.slice(1);
|
|
613
|
+
if (value === ".inf") return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
|
|
614
|
+
if (value === ".nan") return NaN;
|
|
615
|
+
const result = sign * parseFloat(value);
|
|
616
|
+
return Number.isFinite(result) ? result : NOT_RESOLVED;
|
|
617
|
+
}
|
|
618
|
+
if (!YAML_FLOAT_IMPLICIT_PATTERN.test(source)) return NOT_RESOLVED;
|
|
619
|
+
const result = Number(source);
|
|
620
|
+
if (Number.isFinite(result)) return result;
|
|
621
|
+
return NOT_RESOLVED;
|
|
622
|
+
}
|
|
623
|
+
function representYamlFloat$1(object) {
|
|
624
|
+
if (isNaN(object)) return ".nan";
|
|
625
|
+
if (object === Number.POSITIVE_INFINITY) return ".inf";
|
|
626
|
+
if (object === Number.NEGATIVE_INFINITY) return "-.inf";
|
|
627
|
+
if (Object.is(object, -0)) return "-0.0";
|
|
628
|
+
const result = object.toString(10);
|
|
629
|
+
return /^[-+]?[0-9]+e/.test(result) ? result.replace("e", ".e") : result;
|
|
630
|
+
}
|
|
631
|
+
var floatJsonTag = defineScalarTag("tag:yaml.org,2002:float", {
|
|
632
|
+
implicit: true,
|
|
633
|
+
implicitFirstChars: ["-", ..."0123456789"],
|
|
634
|
+
resolve: resolveYamlFloat$1,
|
|
635
|
+
identify: (object) => Object.prototype.toString.call(object) === "[object Number]" && (object % 1 !== 0 || Object.is(object, -0)),
|
|
636
|
+
represent: representYamlFloat$1
|
|
637
|
+
});
|
|
638
|
+
//#endregion
|
|
639
|
+
//#region src/tag/scalar/float_yaml11.ts
|
|
640
|
+
var YAML_FLOAT_PATTERN = /* @__PURE__ */ new RegExp("^(?:[-+]?(?:(?:[0-9][0-9_]*)?\\.[0-9_]*)(?:[eE][-+][0-9]+)?|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");
|
|
641
|
+
var YAML_FLOAT_SPECIAL_PATTERN = /* @__PURE__ */ new RegExp("^(?:[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");
|
|
642
|
+
function resolveYamlFloat(source) {
|
|
643
|
+
if (!YAML_FLOAT_PATTERN.test(source)) return NOT_RESOLVED;
|
|
644
|
+
let value = source.toLowerCase().replace(/_/g, "");
|
|
645
|
+
const sign = value[0] === "-" ? -1 : 1;
|
|
646
|
+
if ("+-".includes(value[0])) value = value.slice(1);
|
|
647
|
+
if (value === ".inf") return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
|
|
648
|
+
if (value === ".nan") return NaN;
|
|
649
|
+
let result = 0;
|
|
650
|
+
if (value.includes(":")) {
|
|
651
|
+
for (const part of value.split(":")) result = result * 60 + Number(part);
|
|
652
|
+
result *= sign;
|
|
653
|
+
} else result = sign * parseFloat(value);
|
|
654
|
+
if (Number.isFinite(result) || YAML_FLOAT_SPECIAL_PATTERN.test(source)) return result;
|
|
655
|
+
return NOT_RESOLVED;
|
|
656
|
+
}
|
|
657
|
+
function representYamlFloat(object) {
|
|
658
|
+
if (isNaN(object)) return ".nan";
|
|
659
|
+
if (object === Number.POSITIVE_INFINITY) return ".inf";
|
|
660
|
+
if (object === Number.NEGATIVE_INFINITY) return "-.inf";
|
|
661
|
+
if (Object.is(object, -0)) return "-0.0";
|
|
662
|
+
const result = object.toString(10);
|
|
663
|
+
return /^[-+]?[0-9]+e/.test(result) ? result.replace("e", ".e") : result;
|
|
664
|
+
}
|
|
665
|
+
var floatYaml11Tag = defineScalarTag("tag:yaml.org,2002:float", {
|
|
666
|
+
implicit: true,
|
|
667
|
+
implicitFirstChars: [
|
|
668
|
+
"-",
|
|
669
|
+
"+",
|
|
670
|
+
".",
|
|
671
|
+
..."0123456789"
|
|
672
|
+
],
|
|
673
|
+
resolve: resolveYamlFloat,
|
|
674
|
+
identify: (object) => Object.prototype.toString.call(object) === "[object Number]" && (object % 1 !== 0 || Object.is(object, -0)),
|
|
675
|
+
represent: representYamlFloat
|
|
676
|
+
});
|
|
677
|
+
//#endregion
|
|
678
|
+
//#region src/tag/scalar/merge.ts
|
|
679
|
+
var mergeTag = defineScalarTag("tag:yaml.org,2002:merge", {
|
|
680
|
+
implicit: true,
|
|
681
|
+
implicitFirstChars: ["<"],
|
|
682
|
+
resolve: (source, isExplicit) => {
|
|
683
|
+
if (source === "<<" || isExplicit && source === "") return MERGE_KEY;
|
|
684
|
+
return NOT_RESOLVED;
|
|
685
|
+
}
|
|
686
|
+
});
|
|
687
|
+
//#endregion
|
|
688
|
+
//#region src/tag/scalar/binary.ts
|
|
689
|
+
var BASE64_PATTERN = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
690
|
+
function resolveYamlBinary(source) {
|
|
691
|
+
const input = source.replace(/\s/g, "");
|
|
692
|
+
if (input.length % 4 !== 0 || !BASE64_PATTERN.test(input)) return NOT_RESOLVED;
|
|
693
|
+
const binary = atob(input);
|
|
694
|
+
const result = new Uint8Array(binary.length);
|
|
695
|
+
for (let index = 0; index < binary.length; index++) result[index] = binary.charCodeAt(index);
|
|
696
|
+
return result;
|
|
697
|
+
}
|
|
698
|
+
function representYamlBinary(object) {
|
|
699
|
+
let binary = "";
|
|
700
|
+
for (let index = 0; index < object.length; index++) binary += String.fromCharCode(object[index]);
|
|
701
|
+
return btoa(binary);
|
|
702
|
+
}
|
|
703
|
+
var binaryTag = defineScalarTag("tag:yaml.org,2002:binary", {
|
|
704
|
+
resolve: resolveYamlBinary,
|
|
705
|
+
identify: (object) => Object.prototype.toString.call(object) === "[object Uint8Array]",
|
|
706
|
+
represent: representYamlBinary
|
|
707
|
+
});
|
|
708
|
+
//#endregion
|
|
709
|
+
//#region src/tag/scalar/timestamp.ts
|
|
710
|
+
var YAML_DATE_REGEXP = /* @__PURE__ */ new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$");
|
|
711
|
+
var YAML_TIMESTAMP_REGEXP = /* @__PURE__ */ new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:[Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \\t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?$");
|
|
712
|
+
function resolveYamlTimestamp(source) {
|
|
713
|
+
let match = YAML_DATE_REGEXP.exec(source);
|
|
714
|
+
if (match === null) match = YAML_TIMESTAMP_REGEXP.exec(source);
|
|
715
|
+
if (match === null) return NOT_RESOLVED;
|
|
716
|
+
const year = +match[1];
|
|
717
|
+
const month = +match[2] - 1;
|
|
718
|
+
const day = +match[3];
|
|
719
|
+
if (!match[4]) {
|
|
720
|
+
const date = new Date(Date.UTC(year, month, day));
|
|
721
|
+
if (date.getUTCFullYear() !== year || date.getUTCMonth() !== month || date.getUTCDate() !== day) return NOT_RESOLVED;
|
|
722
|
+
return date;
|
|
723
|
+
}
|
|
724
|
+
const hour = +match[4];
|
|
725
|
+
const minute = +match[5];
|
|
726
|
+
const second = +match[6];
|
|
727
|
+
let fraction = 0;
|
|
728
|
+
if (hour > 23 || minute > 59 || second > 59) return NOT_RESOLVED;
|
|
729
|
+
if (match[7]) {
|
|
730
|
+
let value = match[7].slice(0, 3);
|
|
731
|
+
while (value.length < 3) value += "0";
|
|
732
|
+
fraction = +value;
|
|
733
|
+
}
|
|
734
|
+
const date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
|
|
735
|
+
if (date.getUTCFullYear() !== year || date.getUTCMonth() !== month || date.getUTCDate() !== day) return NOT_RESOLVED;
|
|
736
|
+
if (match[9]) {
|
|
737
|
+
const offsetHour = +match[10];
|
|
738
|
+
const offsetMinute = +(match[11] || 0);
|
|
739
|
+
if (offsetHour > 23 || offsetMinute > 59) return NOT_RESOLVED;
|
|
740
|
+
const offset = (offsetHour * 60 + offsetMinute) * 6e4;
|
|
741
|
+
date.setTime(date.getTime() - (match[9] === "-" ? -offset : offset));
|
|
742
|
+
}
|
|
743
|
+
return date;
|
|
744
|
+
}
|
|
745
|
+
var timestampTag = defineScalarTag("tag:yaml.org,2002:timestamp", {
|
|
746
|
+
implicit: true,
|
|
747
|
+
implicitFirstChars: [..."0123456789"],
|
|
748
|
+
resolve: resolveYamlTimestamp,
|
|
749
|
+
identify: (object) => object instanceof Date,
|
|
750
|
+
represent: (object) => object.toISOString()
|
|
751
|
+
});
|
|
752
|
+
//#endregion
|
|
753
|
+
//#region src/tag/sequence/seq.ts
|
|
754
|
+
var seqTag = defineSequenceTag("tag:yaml.org,2002:seq", {
|
|
755
|
+
create: () => [],
|
|
756
|
+
addItem: (container, item) => {
|
|
757
|
+
container.push(item);
|
|
758
|
+
},
|
|
759
|
+
identify: Array.isArray
|
|
760
|
+
});
|
|
761
|
+
//#endregion
|
|
762
|
+
//#region src/tag/sequence/omap.ts
|
|
763
|
+
var omapTag = defineSequenceTag("tag:yaml.org,2002:omap", {
|
|
764
|
+
create: () => [],
|
|
765
|
+
addItem: (container, item) => {
|
|
766
|
+
if (Object.prototype.toString.call(item) !== "[object Object]") return "cannot resolve an ordered map item";
|
|
767
|
+
const object = item;
|
|
768
|
+
const itemKeys = Object.keys(object);
|
|
769
|
+
if (itemKeys.length !== 1) return "cannot resolve an ordered map item";
|
|
770
|
+
for (const existing of container) if (Object.prototype.hasOwnProperty.call(existing, itemKeys[0])) return "cannot resolve an ordered map item";
|
|
771
|
+
container.push(object);
|
|
772
|
+
return "";
|
|
773
|
+
}
|
|
774
|
+
});
|
|
775
|
+
//#endregion
|
|
776
|
+
//#region src/tag/sequence/pairs.ts
|
|
777
|
+
var pairsTag = defineSequenceTag("tag:yaml.org,2002:pairs", {
|
|
778
|
+
create: () => [],
|
|
779
|
+
addItem: (container, item) => {
|
|
780
|
+
if (item instanceof Map) {
|
|
781
|
+
if (item.size !== 1) return "cannot resolve a pairs item";
|
|
782
|
+
container.push(item.entries().next().value);
|
|
783
|
+
return "";
|
|
784
|
+
}
|
|
785
|
+
if (Object.prototype.toString.call(item) !== "[object Object]") return "cannot resolve a pairs item";
|
|
786
|
+
const object = item;
|
|
787
|
+
const keys = Object.keys(object);
|
|
788
|
+
if (keys.length !== 1) return "cannot resolve a pairs item";
|
|
789
|
+
container.push([keys[0], object[keys[0]]]);
|
|
790
|
+
return "";
|
|
791
|
+
}
|
|
792
|
+
});
|
|
793
|
+
//#endregion
|
|
794
|
+
//#region src/common/object.ts
|
|
795
|
+
function isPlainObject(data) {
|
|
796
|
+
if (data === null || typeof data !== "object" || Array.isArray(data)) return false;
|
|
797
|
+
const prototype = Object.getPrototypeOf(data);
|
|
798
|
+
return prototype === null || prototype === Object.prototype;
|
|
799
|
+
}
|
|
800
|
+
function pick(object, keys) {
|
|
801
|
+
const result = {};
|
|
802
|
+
for (const key of keys) if (object[key] !== void 0) result[key] = object[key];
|
|
803
|
+
return result;
|
|
804
|
+
}
|
|
805
|
+
//#endregion
|
|
806
|
+
//#region src/tag/mapping/map.ts
|
|
807
|
+
var mapTag = defineMappingTag("tag:yaml.org,2002:map", {
|
|
808
|
+
create: () => ({}),
|
|
809
|
+
identify: isPlainObject,
|
|
810
|
+
represent: (o) => {
|
|
811
|
+
const map = /* @__PURE__ */ new Map();
|
|
812
|
+
for (const key of Object.keys(o)) map.set(key, o[key]);
|
|
813
|
+
return map;
|
|
814
|
+
},
|
|
815
|
+
addPair: (container, key, value) => {
|
|
816
|
+
if (key !== null && typeof key === "object") return "object-based map does not support complex keys";
|
|
817
|
+
const normalizedKey = String(key);
|
|
818
|
+
if (normalizedKey === "__proto__") Object.defineProperty(container, normalizedKey, {
|
|
819
|
+
value,
|
|
820
|
+
enumerable: true,
|
|
821
|
+
configurable: true,
|
|
822
|
+
writable: true
|
|
823
|
+
});
|
|
824
|
+
else container[normalizedKey] = value;
|
|
825
|
+
return "";
|
|
826
|
+
},
|
|
827
|
+
has: (container, key) => {
|
|
828
|
+
if (key !== null && typeof key === "object") return false;
|
|
829
|
+
return Object.prototype.hasOwnProperty.call(container, String(key));
|
|
830
|
+
},
|
|
831
|
+
keys: (container) => Object.keys(container),
|
|
832
|
+
get: (container, key) => container[String(key)]
|
|
833
|
+
});
|
|
834
|
+
//#endregion
|
|
835
|
+
//#region src/tag/mapping/set.ts
|
|
836
|
+
var setTag = defineMappingTag("tag:yaml.org,2002:set", {
|
|
837
|
+
create: () => /* @__PURE__ */ new Set(),
|
|
838
|
+
identify: (data) => data instanceof Set,
|
|
839
|
+
represent: (data) => {
|
|
840
|
+
const map = /* @__PURE__ */ new Map();
|
|
841
|
+
for (const key of data) map.set(key, null);
|
|
842
|
+
return map;
|
|
843
|
+
},
|
|
844
|
+
addPair: (container, key, value) => {
|
|
845
|
+
if (value !== null) return "cannot resolve a set item";
|
|
846
|
+
container.add(key);
|
|
847
|
+
return "";
|
|
848
|
+
},
|
|
849
|
+
has: (container, key) => container.has(key),
|
|
850
|
+
keys: (container) => container.keys(),
|
|
851
|
+
get: () => null
|
|
852
|
+
});
|
|
853
|
+
//#endregion
|
|
854
|
+
//#region src/schema.ts
|
|
855
|
+
function createTagDefinitionMap() {
|
|
856
|
+
return {
|
|
857
|
+
scalar: {},
|
|
858
|
+
sequence: {},
|
|
859
|
+
mapping: {}
|
|
860
|
+
};
|
|
861
|
+
}
|
|
862
|
+
function createTagDefinitionListMap() {
|
|
863
|
+
return {
|
|
864
|
+
scalar: [],
|
|
865
|
+
sequence: [],
|
|
866
|
+
mapping: []
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
function compileTags(tags) {
|
|
870
|
+
const result = [];
|
|
871
|
+
for (const tag of tags) {
|
|
872
|
+
let index = result.length;
|
|
873
|
+
for (let previousIndex = 0; previousIndex < result.length; previousIndex++) {
|
|
874
|
+
const previous = result[previousIndex];
|
|
875
|
+
if (previous.nodeKind === tag.nodeKind && previous.tagName === tag.tagName && previous.matchByTagPrefix === tag.matchByTagPrefix) {
|
|
876
|
+
index = previousIndex;
|
|
877
|
+
break;
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
result[index] = tag;
|
|
881
|
+
}
|
|
882
|
+
return result;
|
|
883
|
+
}
|
|
884
|
+
var Schema = class Schema {
|
|
885
|
+
tags;
|
|
886
|
+
implicitScalarTags;
|
|
887
|
+
implicitScalarByFirstChar;
|
|
888
|
+
implicitScalarAnyFirstChar;
|
|
889
|
+
defaultScalarTag;
|
|
890
|
+
defaultSequenceTag;
|
|
891
|
+
defaultMappingTag;
|
|
892
|
+
exact;
|
|
893
|
+
prefix;
|
|
894
|
+
constructor(tags) {
|
|
895
|
+
const compiledTags = compileTags(tags);
|
|
896
|
+
const implicitScalarTags = [];
|
|
897
|
+
const exact = createTagDefinitionMap();
|
|
898
|
+
const prefix = createTagDefinitionListMap();
|
|
899
|
+
for (const tag of compiledTags) {
|
|
900
|
+
if (tag.nodeKind === "scalar" && tag.implicit) {
|
|
901
|
+
if (tag.matchByTagPrefix) throw new Error("Implicit scalar tags cannot match by tag prefix");
|
|
902
|
+
implicitScalarTags.push(tag);
|
|
903
|
+
}
|
|
904
|
+
switch (tag.nodeKind) {
|
|
905
|
+
case "scalar":
|
|
906
|
+
if (tag.matchByTagPrefix) prefix.scalar.push(tag);
|
|
907
|
+
else exact.scalar[tag.tagName] = tag;
|
|
908
|
+
break;
|
|
909
|
+
case "sequence":
|
|
910
|
+
if (tag.matchByTagPrefix) prefix.sequence.push(tag);
|
|
911
|
+
else exact.sequence[tag.tagName] = tag;
|
|
912
|
+
break;
|
|
913
|
+
case "mapping":
|
|
914
|
+
if (tag.matchByTagPrefix) prefix.mapping.push(tag);
|
|
915
|
+
else exact.mapping[tag.tagName] = tag;
|
|
916
|
+
break;
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
const implicitScalarAnyFirstChar = implicitScalarTags.filter((tag) => tag.implicitFirstChars === null);
|
|
920
|
+
const keys = /* @__PURE__ */ new Set();
|
|
921
|
+
for (const tag of implicitScalarTags) if (tag.implicitFirstChars !== null) for (const key of tag.implicitFirstChars) keys.add(key);
|
|
922
|
+
const implicitScalarByFirstChar = /* @__PURE__ */ new Map();
|
|
923
|
+
for (const key of keys) implicitScalarByFirstChar.set(key, implicitScalarTags.filter((tag) => tag.implicitFirstChars === null || tag.implicitFirstChars.indexOf(key) !== -1));
|
|
924
|
+
const defaultScalarTag = exact.scalar["tag:yaml.org,2002:str"];
|
|
925
|
+
if (!defaultScalarTag) throw new Error("schema does not define the default scalar tag (tag:yaml.org,2002:str)");
|
|
926
|
+
this.tags = compiledTags;
|
|
927
|
+
this.implicitScalarTags = implicitScalarTags;
|
|
928
|
+
this.implicitScalarByFirstChar = implicitScalarByFirstChar;
|
|
929
|
+
this.implicitScalarAnyFirstChar = implicitScalarAnyFirstChar;
|
|
930
|
+
this.defaultScalarTag = defaultScalarTag;
|
|
931
|
+
this.defaultSequenceTag = exact.sequence["tag:yaml.org,2002:seq"];
|
|
932
|
+
this.defaultMappingTag = exact.mapping["tag:yaml.org,2002:map"];
|
|
933
|
+
this.exact = exact;
|
|
934
|
+
this.prefix = prefix;
|
|
935
|
+
}
|
|
936
|
+
withTags(...tags) {
|
|
937
|
+
let flatTags = [];
|
|
938
|
+
for (const tag of tags) flatTags = flatTags.concat(tag);
|
|
939
|
+
return new Schema([...this.tags, ...flatTags]);
|
|
940
|
+
}
|
|
941
|
+
};
|
|
942
|
+
var FAILSAFE_SCHEMA = new Schema([
|
|
943
|
+
strTag,
|
|
944
|
+
seqTag,
|
|
945
|
+
mapTag
|
|
946
|
+
]);
|
|
947
|
+
new Schema([
|
|
948
|
+
...FAILSAFE_SCHEMA.tags,
|
|
949
|
+
nullJsonTag,
|
|
950
|
+
boolJsonTag,
|
|
951
|
+
intJsonTag,
|
|
952
|
+
floatJsonTag
|
|
953
|
+
]);
|
|
954
|
+
var CORE_SCHEMA = new Schema([
|
|
955
|
+
...FAILSAFE_SCHEMA.tags,
|
|
956
|
+
nullCoreTag,
|
|
957
|
+
boolCoreTag,
|
|
958
|
+
intCoreTag,
|
|
959
|
+
floatCoreTag
|
|
960
|
+
]);
|
|
961
|
+
var YAML11_SCHEMA = new Schema([
|
|
962
|
+
...FAILSAFE_SCHEMA.tags,
|
|
963
|
+
nullYaml11Tag,
|
|
964
|
+
boolYaml11Tag,
|
|
965
|
+
intYaml11Tag,
|
|
966
|
+
floatYaml11Tag,
|
|
967
|
+
timestampTag,
|
|
968
|
+
mergeTag,
|
|
969
|
+
binaryTag,
|
|
970
|
+
omapTag,
|
|
971
|
+
pairsTag,
|
|
972
|
+
setTag
|
|
973
|
+
]);
|
|
974
|
+
//#endregion
|
|
975
|
+
//#region src/tag/mapping/real_map.ts
|
|
976
|
+
defineMappingTag("tag:yaml.org,2002:map", {
|
|
977
|
+
create: () => /* @__PURE__ */ new Map(),
|
|
978
|
+
addPair: (container, key, value) => {
|
|
979
|
+
container.set(key, value);
|
|
980
|
+
return "";
|
|
981
|
+
},
|
|
982
|
+
has: (container, key) => container.has(key),
|
|
983
|
+
keys: (container) => container.keys(),
|
|
984
|
+
get: (container, key) => container.get(key),
|
|
985
|
+
identify: (data) => data instanceof Map || isPlainObject(data),
|
|
986
|
+
represent: (data) => {
|
|
987
|
+
if (data instanceof Map) return data;
|
|
988
|
+
const map = /* @__PURE__ */ new Map();
|
|
989
|
+
const obj = data;
|
|
990
|
+
for (const key of Object.keys(obj)) map.set(key, obj[key]);
|
|
991
|
+
return map;
|
|
992
|
+
}
|
|
993
|
+
});
|
|
994
|
+
//#endregion
|
|
995
|
+
//#region src/tag/mapping/legacy_map.ts
|
|
996
|
+
function normalizeKey(key) {
|
|
997
|
+
if (Array.isArray(key)) {
|
|
998
|
+
const array = Array.prototype.slice.call(key);
|
|
999
|
+
for (let index = 0; index < array.length; index++) {
|
|
1000
|
+
if (Array.isArray(array[index])) return null;
|
|
1001
|
+
if (typeof array[index] === "object" && Object.prototype.toString.call(array[index]) === "[object Object]") array[index] = "[object Object]";
|
|
1002
|
+
}
|
|
1003
|
+
return String(array);
|
|
1004
|
+
}
|
|
1005
|
+
if (typeof key === "object" && Object.prototype.toString.call(key) === "[object Object]") return "[object Object]";
|
|
1006
|
+
return String(key);
|
|
1007
|
+
}
|
|
1008
|
+
defineMappingTag("tag:yaml.org,2002:map", {
|
|
1009
|
+
create: () => ({}),
|
|
1010
|
+
identify: isPlainObject,
|
|
1011
|
+
represent: (o) => {
|
|
1012
|
+
const map = /* @__PURE__ */ new Map();
|
|
1013
|
+
for (const key of Object.keys(o)) map.set(key, o[key]);
|
|
1014
|
+
return map;
|
|
1015
|
+
},
|
|
1016
|
+
addPair: (container, key, value) => {
|
|
1017
|
+
const normalizedKey = normalizeKey(key);
|
|
1018
|
+
if (normalizedKey === null) return "nested arrays are not supported inside keys";
|
|
1019
|
+
if (normalizedKey === "__proto__") Object.defineProperty(container, normalizedKey, {
|
|
1020
|
+
value,
|
|
1021
|
+
enumerable: true,
|
|
1022
|
+
configurable: true,
|
|
1023
|
+
writable: true
|
|
1024
|
+
});
|
|
1025
|
+
else container[normalizedKey] = value;
|
|
1026
|
+
return "";
|
|
1027
|
+
},
|
|
1028
|
+
has: (container, key) => {
|
|
1029
|
+
const normalizedKey = normalizeKey(key);
|
|
1030
|
+
return normalizedKey !== null && Object.prototype.hasOwnProperty.call(container, normalizedKey);
|
|
1031
|
+
},
|
|
1032
|
+
keys: (container) => Object.keys(container),
|
|
1033
|
+
get: (container, key) => container[String(key)]
|
|
1034
|
+
});
|
|
1035
|
+
//#endregion
|
|
1036
|
+
//#region src/common/snippet.ts
|
|
1037
|
+
var DEFAULT_SNIPPET_OPTIONS = {
|
|
1038
|
+
maxLength: 79,
|
|
1039
|
+
indent: 1,
|
|
1040
|
+
linesBefore: 3,
|
|
1041
|
+
linesAfter: 2
|
|
1042
|
+
};
|
|
1043
|
+
function getLine(buffer, lineStart, lineEnd, position, maxLineLength) {
|
|
1044
|
+
let head = "";
|
|
1045
|
+
let tail = "";
|
|
1046
|
+
const maxHalfLength = Math.floor(maxLineLength / 2) - 1;
|
|
1047
|
+
if (position - lineStart > maxHalfLength) {
|
|
1048
|
+
head = " ... ";
|
|
1049
|
+
lineStart = position - maxHalfLength + head.length;
|
|
1050
|
+
}
|
|
1051
|
+
if (lineEnd - position > maxHalfLength) {
|
|
1052
|
+
tail = " ...";
|
|
1053
|
+
lineEnd = position + maxHalfLength - tail.length;
|
|
1054
|
+
}
|
|
1055
|
+
return {
|
|
1056
|
+
str: head + buffer.slice(lineStart, lineEnd).replace(/\t/g, "→") + tail,
|
|
1057
|
+
pos: position - lineStart + head.length
|
|
1058
|
+
};
|
|
1059
|
+
}
|
|
1060
|
+
function padStart(string, max) {
|
|
1061
|
+
return " ".repeat(Math.max(max - string.length, 0)) + string;
|
|
1062
|
+
}
|
|
1063
|
+
function makeSnippet(mark, options) {
|
|
1064
|
+
if (!mark.buffer) return null;
|
|
1065
|
+
const opts = {
|
|
1066
|
+
...DEFAULT_SNIPPET_OPTIONS,
|
|
1067
|
+
...options
|
|
1068
|
+
};
|
|
1069
|
+
const re = /\r?\n|\r|\0/g;
|
|
1070
|
+
const lineStarts = [0];
|
|
1071
|
+
const lineEnds = [];
|
|
1072
|
+
let match;
|
|
1073
|
+
let foundLineNo = -1;
|
|
1074
|
+
while (match = re.exec(mark.buffer)) {
|
|
1075
|
+
lineEnds.push(match.index);
|
|
1076
|
+
lineStarts.push(match.index + match[0].length);
|
|
1077
|
+
if (mark.position <= match.index && foundLineNo < 0) foundLineNo = lineStarts.length - 2;
|
|
1078
|
+
}
|
|
1079
|
+
if (foundLineNo < 0) foundLineNo = lineStarts.length - 1;
|
|
1080
|
+
let result = "";
|
|
1081
|
+
const lineNoLength = Math.min(mark.line + opts.linesAfter, lineEnds.length).toString().length;
|
|
1082
|
+
const maxLineLength = opts.maxLength - (opts.indent + lineNoLength + 3);
|
|
1083
|
+
for (let i = 1; i <= opts.linesBefore; i++) {
|
|
1084
|
+
if (foundLineNo - i < 0) break;
|
|
1085
|
+
const line = getLine(mark.buffer, lineStarts[foundLineNo - i], lineEnds[foundLineNo - i], mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo - i]), maxLineLength);
|
|
1086
|
+
result = `${" ".repeat(opts.indent)}${padStart((mark.line - i + 1).toString(), lineNoLength)} | ${line.str}\n${result}`;
|
|
1087
|
+
}
|
|
1088
|
+
const line = getLine(mark.buffer, lineStarts[foundLineNo], lineEnds[foundLineNo], mark.position, maxLineLength);
|
|
1089
|
+
result += `${" ".repeat(opts.indent)}${padStart((mark.line + 1).toString(), lineNoLength)} | ${line.str}\n`;
|
|
1090
|
+
result += `${"-".repeat(opts.indent + lineNoLength + 3 + line.pos)}^\n`;
|
|
1091
|
+
for (let i = 1; i <= opts.linesAfter; i++) {
|
|
1092
|
+
if (foundLineNo + i >= lineEnds.length) break;
|
|
1093
|
+
const line = getLine(mark.buffer, lineStarts[foundLineNo + i], lineEnds[foundLineNo + i], mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo + i]), maxLineLength);
|
|
1094
|
+
result += `${" ".repeat(opts.indent)}${padStart((mark.line + i + 1).toString(), lineNoLength)} | ${line.str}\n`;
|
|
1095
|
+
}
|
|
1096
|
+
return result.replace(/\n$/, "");
|
|
1097
|
+
}
|
|
1098
|
+
//#endregion
|
|
1099
|
+
//#region src/common/exception.ts
|
|
1100
|
+
function formatError(exception, compact) {
|
|
1101
|
+
let where = "";
|
|
1102
|
+
if (!exception.mark) return exception.reason;
|
|
1103
|
+
if (exception.mark.name) where += `in "${exception.mark.name}" `;
|
|
1104
|
+
where += `(${exception.mark.line + 1}:${exception.mark.column + 1})`;
|
|
1105
|
+
if (!compact && exception.mark.snippet) where += `\n\n${exception.mark.snippet}`;
|
|
1106
|
+
return `${exception.reason} ${where}`;
|
|
1107
|
+
}
|
|
1108
|
+
var YAMLException = class extends Error {
|
|
1109
|
+
reason;
|
|
1110
|
+
mark;
|
|
1111
|
+
constructor(reason, mark) {
|
|
1112
|
+
super();
|
|
1113
|
+
this.name = "YAMLException";
|
|
1114
|
+
this.reason = reason;
|
|
1115
|
+
this.mark = mark;
|
|
1116
|
+
this.message = formatError(this, false);
|
|
1117
|
+
if (Error.captureStackTrace) Error.captureStackTrace(this, this.constructor);
|
|
1118
|
+
}
|
|
1119
|
+
toString(compact) {
|
|
1120
|
+
return `${this.name}: ${formatError(this, compact)}`;
|
|
1121
|
+
}
|
|
1122
|
+
};
|
|
1123
|
+
function throwErrorAt(source, position, message, filename = "") {
|
|
1124
|
+
let line = 0;
|
|
1125
|
+
let lineStart = 0;
|
|
1126
|
+
for (let index = 0; index < position; index++) {
|
|
1127
|
+
const ch = source.charCodeAt(index);
|
|
1128
|
+
if (ch === 10) {
|
|
1129
|
+
line++;
|
|
1130
|
+
lineStart = index + 1;
|
|
1131
|
+
} else if (ch === 13) {
|
|
1132
|
+
line++;
|
|
1133
|
+
if (source.charCodeAt(index + 1) === 10) index++;
|
|
1134
|
+
lineStart = index + 1;
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
const mark = {
|
|
1138
|
+
name: filename,
|
|
1139
|
+
buffer: source,
|
|
1140
|
+
position,
|
|
1141
|
+
line,
|
|
1142
|
+
column: position - lineStart
|
|
1143
|
+
};
|
|
1144
|
+
mark.snippet = makeSnippet(mark);
|
|
1145
|
+
throw new YAMLException(message, mark);
|
|
1146
|
+
}
|
|
1147
|
+
//#endregion
|
|
1148
|
+
//#region src/parser/parser_scalar.ts
|
|
1149
|
+
var NO_RANGE$3 = -1;
|
|
1150
|
+
function simpleEscapeSequence(c) {
|
|
1151
|
+
switch (c) {
|
|
1152
|
+
case 48: return "\0";
|
|
1153
|
+
case 97: return "\x07";
|
|
1154
|
+
case 98: return "\b";
|
|
1155
|
+
case 116: return " ";
|
|
1156
|
+
case 9: return " ";
|
|
1157
|
+
case 110: return "\n";
|
|
1158
|
+
case 118: return "\v";
|
|
1159
|
+
case 102: return "\f";
|
|
1160
|
+
case 114: return "\r";
|
|
1161
|
+
case 101: return "\x1B";
|
|
1162
|
+
case 32: return " ";
|
|
1163
|
+
case 34: return "\"";
|
|
1164
|
+
case 47: return "/";
|
|
1165
|
+
case 92: return "\\";
|
|
1166
|
+
case 78: return "
";
|
|
1167
|
+
case 95: return "\xA0";
|
|
1168
|
+
case 76: return "\u2028";
|
|
1169
|
+
case 80: return "\u2029";
|
|
1170
|
+
default: return "";
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
var simpleEscapeCheck = new Array(256);
|
|
1174
|
+
var simpleEscapeMap = new Array(256);
|
|
1175
|
+
for (let i = 0; i < 256; i++) {
|
|
1176
|
+
simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
|
|
1177
|
+
simpleEscapeMap[i] = simpleEscapeSequence(i);
|
|
1178
|
+
}
|
|
1179
|
+
function charFromCodepoint(c) {
|
|
1180
|
+
if (c <= 65535) return String.fromCharCode(c);
|
|
1181
|
+
return String.fromCharCode((c - 65536 >> 10) + 55296, (c - 65536 & 1023) + 56320);
|
|
1182
|
+
}
|
|
1183
|
+
function fromHexCode$1(c) {
|
|
1184
|
+
if (c >= 48 && c <= 57) return c - 48;
|
|
1185
|
+
return (c | 32) - 97 + 10;
|
|
1186
|
+
}
|
|
1187
|
+
function escapedHexLen$1(c) {
|
|
1188
|
+
if (c === 120) return 2;
|
|
1189
|
+
if (c === 117) return 4;
|
|
1190
|
+
return 8;
|
|
1191
|
+
}
|
|
1192
|
+
function skipFoldedBreaks(input, position, end) {
|
|
1193
|
+
let breaks = 0;
|
|
1194
|
+
while (position < end) {
|
|
1195
|
+
const ch = input.charCodeAt(position);
|
|
1196
|
+
if (ch === 10) {
|
|
1197
|
+
breaks++;
|
|
1198
|
+
position++;
|
|
1199
|
+
} else if (ch === 13) {
|
|
1200
|
+
breaks++;
|
|
1201
|
+
position++;
|
|
1202
|
+
if (input.charCodeAt(position) === 10) position++;
|
|
1203
|
+
} else if (ch === 32 || ch === 9) position++;
|
|
1204
|
+
else break;
|
|
1205
|
+
}
|
|
1206
|
+
return {
|
|
1207
|
+
position,
|
|
1208
|
+
breaks
|
|
1209
|
+
};
|
|
1210
|
+
}
|
|
1211
|
+
function foldedBreaks(count) {
|
|
1212
|
+
if (count === 1) return " ";
|
|
1213
|
+
return "\n".repeat(count - 1);
|
|
1214
|
+
}
|
|
1215
|
+
function getPlainValue(input, start, end) {
|
|
1216
|
+
let result = "";
|
|
1217
|
+
let position = start;
|
|
1218
|
+
let captureStart = start;
|
|
1219
|
+
let captureEnd = start;
|
|
1220
|
+
while (position < end) {
|
|
1221
|
+
const ch = input.charCodeAt(position);
|
|
1222
|
+
if (ch === 10 || ch === 13) {
|
|
1223
|
+
result += input.slice(captureStart, captureEnd);
|
|
1224
|
+
const fold = skipFoldedBreaks(input, position, end);
|
|
1225
|
+
result += foldedBreaks(fold.breaks);
|
|
1226
|
+
position = captureStart = captureEnd = fold.position;
|
|
1227
|
+
} else {
|
|
1228
|
+
position++;
|
|
1229
|
+
if (ch !== 32 && ch !== 9) captureEnd = position;
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
return result + input.slice(captureStart, captureEnd);
|
|
1233
|
+
}
|
|
1234
|
+
function getSingleQuotedValue(input, start, end) {
|
|
1235
|
+
let result = "";
|
|
1236
|
+
let position = start;
|
|
1237
|
+
let captureStart = start;
|
|
1238
|
+
let captureEnd = start;
|
|
1239
|
+
while (position < end) {
|
|
1240
|
+
const ch = input.charCodeAt(position);
|
|
1241
|
+
if (ch === 39) {
|
|
1242
|
+
result += input.slice(captureStart, position) + "'";
|
|
1243
|
+
position += 2;
|
|
1244
|
+
captureStart = captureEnd = position;
|
|
1245
|
+
} else if (ch === 10 || ch === 13) {
|
|
1246
|
+
result += input.slice(captureStart, captureEnd);
|
|
1247
|
+
const fold = skipFoldedBreaks(input, position, end);
|
|
1248
|
+
result += foldedBreaks(fold.breaks);
|
|
1249
|
+
position = captureStart = captureEnd = fold.position;
|
|
1250
|
+
} else {
|
|
1251
|
+
position++;
|
|
1252
|
+
if (ch !== 32 && ch !== 9) captureEnd = position;
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
return result + input.slice(captureStart, end);
|
|
1256
|
+
}
|
|
1257
|
+
function getDoubleQuotedValue(input, start, end) {
|
|
1258
|
+
let result = "";
|
|
1259
|
+
let position = start;
|
|
1260
|
+
let captureStart = start;
|
|
1261
|
+
let captureEnd = start;
|
|
1262
|
+
while (position < end) {
|
|
1263
|
+
const ch = input.charCodeAt(position);
|
|
1264
|
+
if (ch === 92) {
|
|
1265
|
+
result += input.slice(captureStart, position);
|
|
1266
|
+
position++;
|
|
1267
|
+
const escaped = input.charCodeAt(position);
|
|
1268
|
+
if (escaped === 10 || escaped === 13) position = skipFoldedBreaks(input, position, end).position;
|
|
1269
|
+
else if (escaped < 256 && simpleEscapeCheck[escaped]) {
|
|
1270
|
+
result += simpleEscapeMap[escaped];
|
|
1271
|
+
position++;
|
|
1272
|
+
} else {
|
|
1273
|
+
let hexLength = escapedHexLen$1(escaped);
|
|
1274
|
+
let hexResult = 0;
|
|
1275
|
+
for (; hexLength > 0; hexLength--) {
|
|
1276
|
+
position++;
|
|
1277
|
+
const digit = fromHexCode$1(input.charCodeAt(position));
|
|
1278
|
+
hexResult = (hexResult << 4) + digit;
|
|
1279
|
+
}
|
|
1280
|
+
result += charFromCodepoint(hexResult);
|
|
1281
|
+
position++;
|
|
1282
|
+
}
|
|
1283
|
+
captureStart = captureEnd = position;
|
|
1284
|
+
} else if (ch === 10 || ch === 13) {
|
|
1285
|
+
result += input.slice(captureStart, captureEnd);
|
|
1286
|
+
const fold = skipFoldedBreaks(input, position, end);
|
|
1287
|
+
result += foldedBreaks(fold.breaks);
|
|
1288
|
+
position = captureStart = captureEnd = fold.position;
|
|
1289
|
+
} else {
|
|
1290
|
+
position++;
|
|
1291
|
+
if (ch !== 32 && ch !== 9) captureEnd = position;
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
return result + input.slice(captureStart, end);
|
|
1295
|
+
}
|
|
1296
|
+
function getBlockValue(input, start, end, indent, chomping, folded) {
|
|
1297
|
+
const textIndent = indent < 0 ? 0 : indent;
|
|
1298
|
+
const region = input.slice(start, end).replace(/\r\n?/g, "\n");
|
|
1299
|
+
const lines = region === "" ? [] : (region.endsWith("\n") ? region.slice(0, -1) : region).split("\n");
|
|
1300
|
+
let result = "";
|
|
1301
|
+
let didReadContent = false;
|
|
1302
|
+
let emptyLines = 0;
|
|
1303
|
+
let atMoreIndented = false;
|
|
1304
|
+
for (const line of lines) {
|
|
1305
|
+
let column = 0;
|
|
1306
|
+
while (column < textIndent && line.charCodeAt(column) === 32) column++;
|
|
1307
|
+
if (indent < 0 || column >= line.length) {
|
|
1308
|
+
emptyLines++;
|
|
1309
|
+
continue;
|
|
1310
|
+
}
|
|
1311
|
+
const content = line.slice(textIndent);
|
|
1312
|
+
const first = content.charCodeAt(0);
|
|
1313
|
+
if (folded) if (first === 32 || first === 9) {
|
|
1314
|
+
atMoreIndented = true;
|
|
1315
|
+
result += "\n".repeat(didReadContent ? 1 + emptyLines : emptyLines);
|
|
1316
|
+
} else if (atMoreIndented) {
|
|
1317
|
+
atMoreIndented = false;
|
|
1318
|
+
result += "\n".repeat(emptyLines + 1);
|
|
1319
|
+
} else if (emptyLines === 0) {
|
|
1320
|
+
if (didReadContent) result += " ";
|
|
1321
|
+
} else result += "\n".repeat(emptyLines);
|
|
1322
|
+
else result += "\n".repeat(didReadContent ? 1 + emptyLines : emptyLines);
|
|
1323
|
+
result += content;
|
|
1324
|
+
didReadContent = true;
|
|
1325
|
+
emptyLines = 0;
|
|
1326
|
+
}
|
|
1327
|
+
if (chomping === 3) result += "\n".repeat(didReadContent ? 1 + emptyLines : emptyLines);
|
|
1328
|
+
else if (chomping !== 2) {
|
|
1329
|
+
if (didReadContent) result += "\n";
|
|
1330
|
+
}
|
|
1331
|
+
return result;
|
|
1332
|
+
}
|
|
1333
|
+
function getScalarValue(input, scalar) {
|
|
1334
|
+
if (scalar.valueStart === NO_RANGE$3) return "";
|
|
1335
|
+
const { valueStart, valueEnd } = scalar;
|
|
1336
|
+
if (scalar.fast) return input.slice(valueStart, valueEnd);
|
|
1337
|
+
switch (scalar.style) {
|
|
1338
|
+
case 2: return getSingleQuotedValue(input, valueStart, valueEnd);
|
|
1339
|
+
case 3: return getDoubleQuotedValue(input, valueStart, valueEnd);
|
|
1340
|
+
case 4: return getBlockValue(input, valueStart, valueEnd, scalar.indent, scalar.chomping, false);
|
|
1341
|
+
case 5: return getBlockValue(input, valueStart, valueEnd, scalar.indent, scalar.chomping, true);
|
|
1342
|
+
default: return getPlainValue(input, valueStart, valueEnd);
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
//#endregion
|
|
1346
|
+
//#region src/common/tagname.ts
|
|
1347
|
+
var DEFAULT_TAG_HANDLERS = {
|
|
1348
|
+
"!": "!",
|
|
1349
|
+
"!!": "tag:yaml.org,2002:"
|
|
1350
|
+
};
|
|
1351
|
+
function tagPercentEncode(source) {
|
|
1352
|
+
return encodeURI(source).replace(/!/g, "%21");
|
|
1353
|
+
}
|
|
1354
|
+
function tagNameFull(rawTag, tagHandlers) {
|
|
1355
|
+
if (rawTag.startsWith("!<") && rawTag.endsWith(">")) return decodeURIComponent(rawTag.slice(2, -1));
|
|
1356
|
+
const handleEnd = rawTag.indexOf("!", 1);
|
|
1357
|
+
const handle = handleEnd === -1 ? "!" : rawTag.slice(0, handleEnd + 1);
|
|
1358
|
+
const prefix = tagHandlers?.[handle] ?? DEFAULT_TAG_HANDLERS[handle] ?? handle;
|
|
1359
|
+
return decodeURIComponent(prefix) + decodeURIComponent(rawTag.slice(handle.length));
|
|
1360
|
+
}
|
|
1361
|
+
function tagNameShort(fullTag) {
|
|
1362
|
+
let tag = fullTag;
|
|
1363
|
+
if (tag.charCodeAt(0) === 33) {
|
|
1364
|
+
tag = tag.slice(1);
|
|
1365
|
+
return `!${tagPercentEncode(tag)}`;
|
|
1366
|
+
}
|
|
1367
|
+
if (tag.slice(0, 18) === "tag:yaml.org,2002:") return `!!${tagPercentEncode(tag.slice(18))}`;
|
|
1368
|
+
return `!<${tagPercentEncode(tag)}>`;
|
|
1369
|
+
}
|
|
1370
|
+
//#endregion
|
|
1371
|
+
//#region src/parser/constructor.ts
|
|
1372
|
+
var NO_RANGE$2 = -1;
|
|
1373
|
+
var DEFAULT_CONSTRUCTOR_OPTIONS = {
|
|
1374
|
+
filename: "",
|
|
1375
|
+
schema: CORE_SCHEMA,
|
|
1376
|
+
json: false,
|
|
1377
|
+
maxMergeSeqLength: 20
|
|
1378
|
+
};
|
|
1379
|
+
function eventPosition$1(event) {
|
|
1380
|
+
if ("tagStart" in event && event.tagStart !== NO_RANGE$2) return event.tagStart;
|
|
1381
|
+
if ("anchorStart" in event && event.anchorStart !== NO_RANGE$2) return event.anchorStart;
|
|
1382
|
+
if ("valueStart" in event && event.valueStart !== NO_RANGE$2) return event.valueStart;
|
|
1383
|
+
if ("start" in event) return event.start;
|
|
1384
|
+
return 0;
|
|
1385
|
+
}
|
|
1386
|
+
function throwError$1(state, message) {
|
|
1387
|
+
throwErrorAt(state.source, state.position, message, state.filename);
|
|
1388
|
+
}
|
|
1389
|
+
function lookupTag(exact, prefix, tagName) {
|
|
1390
|
+
const exactTag = exact[tagName];
|
|
1391
|
+
if (exactTag) return exactTag;
|
|
1392
|
+
for (const tag of prefix) if (tagName.startsWith(tag.tagName)) return tag;
|
|
1393
|
+
}
|
|
1394
|
+
function findExplicitTag(state, exact, prefix, tagName, nodeKind) {
|
|
1395
|
+
const tag = lookupTag(exact, prefix, tagName);
|
|
1396
|
+
if (tag) return tag;
|
|
1397
|
+
throwError$1(state, `unknown ${nodeKind} tag !<${tagName}>`);
|
|
1398
|
+
}
|
|
1399
|
+
function constructScalar(state, event) {
|
|
1400
|
+
const source = getScalarValue(state.source, event);
|
|
1401
|
+
const rawTag = event.tagStart === NO_RANGE$2 ? "" : state.source.slice(event.tagStart, event.tagEnd);
|
|
1402
|
+
const strTag = state.schema.defaultScalarTag;
|
|
1403
|
+
if (rawTag !== "") {
|
|
1404
|
+
if (rawTag === "!") return {
|
|
1405
|
+
value: source,
|
|
1406
|
+
tag: strTag
|
|
1407
|
+
};
|
|
1408
|
+
const tagName = tagNameFull(rawTag, state.tagHandlers);
|
|
1409
|
+
const scalarTag = lookupTag(state.schema.exact.scalar, state.schema.prefix.scalar, tagName);
|
|
1410
|
+
if (scalarTag) {
|
|
1411
|
+
const result = scalarTag.resolve(source, true, tagName);
|
|
1412
|
+
if (result === NOT_RESOLVED) throwError$1(state, `cannot resolve a node with !<${tagName}> explicit tag`);
|
|
1413
|
+
return {
|
|
1414
|
+
value: result,
|
|
1415
|
+
tag: scalarTag
|
|
1416
|
+
};
|
|
1417
|
+
}
|
|
1418
|
+
const collectionTagDef = lookupTag(state.schema.exact.mapping, state.schema.prefix.mapping, tagName) ?? lookupTag(state.schema.exact.sequence, state.schema.prefix.sequence, tagName);
|
|
1419
|
+
if (collectionTagDef) {
|
|
1420
|
+
if (source !== "") throwError$1(state, `cannot resolve a node with !<${tagName}> explicit tag`);
|
|
1421
|
+
return {
|
|
1422
|
+
value: collectionTagDef.create(tagName),
|
|
1423
|
+
tag: collectionTagDef
|
|
1424
|
+
};
|
|
1425
|
+
}
|
|
1426
|
+
throwError$1(state, `unknown scalar tag !<${tagName}>`);
|
|
1427
|
+
}
|
|
1428
|
+
if (event.style === 1) {
|
|
1429
|
+
const candidates = state.schema.implicitScalarByFirstChar.get(source.charAt(0)) ?? state.schema.implicitScalarAnyFirstChar;
|
|
1430
|
+
for (const tag of candidates) {
|
|
1431
|
+
const result = tag.resolve(source, false, tag.tagName);
|
|
1432
|
+
if (result !== NOT_RESOLVED) return {
|
|
1433
|
+
value: result,
|
|
1434
|
+
tag
|
|
1435
|
+
};
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
return {
|
|
1439
|
+
value: strTag.resolve(source, false, strTag.tagName),
|
|
1440
|
+
tag: strTag
|
|
1441
|
+
};
|
|
1442
|
+
}
|
|
1443
|
+
function collectionTag(state, event, exact, prefix, defaultTagName, nodeKind) {
|
|
1444
|
+
const rawTag = event.tagStart === NO_RANGE$2 ? "" : state.source.slice(event.tagStart, event.tagEnd);
|
|
1445
|
+
const tagName = rawTag === "" || rawTag === "!" ? defaultTagName : tagNameFull(rawTag, state.tagHandlers);
|
|
1446
|
+
return {
|
|
1447
|
+
tagName,
|
|
1448
|
+
tag: findExplicitTag(state, exact, prefix, tagName, nodeKind)
|
|
1449
|
+
};
|
|
1450
|
+
}
|
|
1451
|
+
function isMappingTag(tag) {
|
|
1452
|
+
return tag.nodeKind === "mapping";
|
|
1453
|
+
}
|
|
1454
|
+
function mergeKeys(state, frame, source, sourceTag) {
|
|
1455
|
+
for (const sourceKey of sourceTag.keys(source)) {
|
|
1456
|
+
if (frame.tag.has(frame.value, sourceKey)) continue;
|
|
1457
|
+
const err = frame.tag.addPair(frame.value, sourceKey, sourceTag.get(source, sourceKey));
|
|
1458
|
+
if (err) throwError$1(state, err);
|
|
1459
|
+
(frame.overridable ??= /* @__PURE__ */ new Set()).add(sourceKey);
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
function mergeSource(state, frame, source, sourceTag) {
|
|
1463
|
+
state.position = frame.keyPosition;
|
|
1464
|
+
if (isMappingTag(sourceTag)) mergeKeys(state, frame, source, sourceTag);
|
|
1465
|
+
else if (sourceTag.nodeKind === "sequence" && Array.isArray(source)) {
|
|
1466
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1467
|
+
for (const element of source) {
|
|
1468
|
+
if (seen.has(element)) continue;
|
|
1469
|
+
seen.add(element);
|
|
1470
|
+
mergeKeys(state, frame, element, frame.tag);
|
|
1471
|
+
}
|
|
1472
|
+
} else throwError$1(state, "cannot merge mappings; the provided source object is unacceptable");
|
|
1473
|
+
}
|
|
1474
|
+
function addMappingValue(state, frame, key, value, tag) {
|
|
1475
|
+
state.position = frame.keyPosition;
|
|
1476
|
+
if (key === MERGE_KEY) {
|
|
1477
|
+
mergeSource(state, frame, value, tag);
|
|
1478
|
+
return;
|
|
1479
|
+
}
|
|
1480
|
+
if (!state.json && frame.tag.has(frame.value, key) && !frame.overridable?.has(key)) throwError$1(state, "duplicated mapping key");
|
|
1481
|
+
const err = frame.tag.addPair(frame.value, key, value);
|
|
1482
|
+
if (err) throwError$1(state, err);
|
|
1483
|
+
frame.overridable?.delete(key);
|
|
1484
|
+
}
|
|
1485
|
+
function addValue(state, value, tag) {
|
|
1486
|
+
const frame = state.frames[state.frames.length - 1];
|
|
1487
|
+
if (frame.kind === "document") {
|
|
1488
|
+
frame.value = value;
|
|
1489
|
+
frame.hasValue = true;
|
|
1490
|
+
} else if (frame.kind === "sequence") {
|
|
1491
|
+
if (frame.merge) {
|
|
1492
|
+
if (!isMappingTag(tag)) throwError$1(state, "cannot merge mappings; the provided source object is unacceptable");
|
|
1493
|
+
if (frame.index >= state.maxMergeSeqLength) throwError$1(state, `merge sequence length exceeded maxMergeSeqLength (${state.maxMergeSeqLength})`);
|
|
1494
|
+
}
|
|
1495
|
+
const err = frame.tag.addItem(frame.value, value, frame.index++);
|
|
1496
|
+
if (err) throwError$1(state, err);
|
|
1497
|
+
} else if (frame.hasKey) {
|
|
1498
|
+
const key = frame.key;
|
|
1499
|
+
frame.key = void 0;
|
|
1500
|
+
frame.hasKey = false;
|
|
1501
|
+
addMappingValue(state, frame, key, value, tag);
|
|
1502
|
+
} else {
|
|
1503
|
+
frame.key = value;
|
|
1504
|
+
frame.keyPosition = state.position;
|
|
1505
|
+
frame.hasKey = true;
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
function storeAnchor(state, event, value, tag) {
|
|
1509
|
+
if (event.anchorStart !== NO_RANGE$2) state.anchors.set(state.source.slice(event.anchorStart, event.anchorEnd), {
|
|
1510
|
+
value,
|
|
1511
|
+
tag
|
|
1512
|
+
});
|
|
1513
|
+
}
|
|
1514
|
+
function constructFromEvents(events, options) {
|
|
1515
|
+
const state = {
|
|
1516
|
+
...DEFAULT_CONSTRUCTOR_OPTIONS,
|
|
1517
|
+
...options,
|
|
1518
|
+
events,
|
|
1519
|
+
documents: [],
|
|
1520
|
+
eventIndex: 0,
|
|
1521
|
+
position: 0,
|
|
1522
|
+
frames: [],
|
|
1523
|
+
anchors: /* @__PURE__ */ new Map(),
|
|
1524
|
+
tagHandlers: Object.create(null)
|
|
1525
|
+
};
|
|
1526
|
+
while (state.eventIndex < state.events.length) {
|
|
1527
|
+
const event = state.events[state.eventIndex++];
|
|
1528
|
+
state.position = eventPosition$1(event);
|
|
1529
|
+
switch (event.type) {
|
|
1530
|
+
case 1:
|
|
1531
|
+
state.anchors = /* @__PURE__ */ new Map();
|
|
1532
|
+
state.tagHandlers = Object.create(null);
|
|
1533
|
+
for (const directive of event.directives) if (directive.kind === "tag") state.tagHandlers[directive.handle] = directive.prefix;
|
|
1534
|
+
state.frames.push({
|
|
1535
|
+
kind: "document",
|
|
1536
|
+
position: state.position,
|
|
1537
|
+
value: void 0,
|
|
1538
|
+
hasValue: false
|
|
1539
|
+
});
|
|
1540
|
+
break;
|
|
1541
|
+
case 4: {
|
|
1542
|
+
const { value, tag } = constructScalar(state, event);
|
|
1543
|
+
storeAnchor(state, event, value, tag);
|
|
1544
|
+
addValue(state, value, tag);
|
|
1545
|
+
break;
|
|
1546
|
+
}
|
|
1547
|
+
case 2: {
|
|
1548
|
+
const definition = collectionTag(state, event, state.schema.exact.sequence, state.schema.prefix.sequence, "tag:yaml.org,2002:seq", "sequence");
|
|
1549
|
+
const value = definition.tag.create(definition.tagName);
|
|
1550
|
+
storeAnchor(state, event, value, definition.tag);
|
|
1551
|
+
const parent = state.frames[state.frames.length - 1];
|
|
1552
|
+
const merge = parent !== void 0 && parent.kind === "mapping" && parent.hasKey && parent.key === MERGE_KEY;
|
|
1553
|
+
state.frames.push({
|
|
1554
|
+
kind: "sequence",
|
|
1555
|
+
position: state.position,
|
|
1556
|
+
value,
|
|
1557
|
+
tag: definition.tag,
|
|
1558
|
+
index: 0,
|
|
1559
|
+
merge
|
|
1560
|
+
});
|
|
1561
|
+
break;
|
|
1562
|
+
}
|
|
1563
|
+
case 3: {
|
|
1564
|
+
const definition = collectionTag(state, event, state.schema.exact.mapping, state.schema.prefix.mapping, "tag:yaml.org,2002:map", "mapping");
|
|
1565
|
+
const value = definition.tag.create(definition.tagName);
|
|
1566
|
+
storeAnchor(state, event, value, definition.tag);
|
|
1567
|
+
state.frames.push({
|
|
1568
|
+
kind: "mapping",
|
|
1569
|
+
position: state.position,
|
|
1570
|
+
value,
|
|
1571
|
+
tag: definition.tag,
|
|
1572
|
+
key: void 0,
|
|
1573
|
+
keyPosition: state.position,
|
|
1574
|
+
hasKey: false,
|
|
1575
|
+
overridable: null
|
|
1576
|
+
});
|
|
1577
|
+
break;
|
|
1578
|
+
}
|
|
1579
|
+
case 5: {
|
|
1580
|
+
const name = state.source.slice(event.anchorStart, event.anchorEnd);
|
|
1581
|
+
const anchor = state.anchors.get(name);
|
|
1582
|
+
if (!anchor) throwError$1(state, `unidentified alias "${name}"`);
|
|
1583
|
+
addValue(state, anchor.value, anchor.tag);
|
|
1584
|
+
break;
|
|
1585
|
+
}
|
|
1586
|
+
case 6: {
|
|
1587
|
+
const frame = state.frames.pop();
|
|
1588
|
+
if (frame.kind === "document") state.documents.push(frame.value);
|
|
1589
|
+
else addValue(state, frame.value, frame.tag);
|
|
1590
|
+
break;
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
return state.documents;
|
|
1595
|
+
}
|
|
1596
|
+
//#endregion
|
|
1597
|
+
//#region src/parser/parser.ts
|
|
1598
|
+
var NO_RANGE$1 = -1;
|
|
1599
|
+
var HAS_OWN = Object.prototype.hasOwnProperty;
|
|
1600
|
+
var CONTEXT_FLOW_IN = 1;
|
|
1601
|
+
var CONTEXT_FLOW_OUT = 2;
|
|
1602
|
+
var CONTEXT_BLOCK_IN = 3;
|
|
1603
|
+
var CONTEXT_BLOCK_OUT = 4;
|
|
1604
|
+
var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
|
|
1605
|
+
var PATTERN_FLOW_INDICATORS = /[,\[\]{}]/;
|
|
1606
|
+
var PATTERN_TAG_HANDLE = /^(?:!|!!|![0-9A-Za-z-]+!)$/;
|
|
1607
|
+
var NS_URI_CHAR = String.raw`(?:%[0-9A-Fa-f]{2}|[0-9A-Za-z\-#;/?:@&=+$,_.!~*'()\[\]])`;
|
|
1608
|
+
var NS_TAG_CHAR = String.raw`(?:%[0-9A-Fa-f]{2}|[0-9A-Za-z\-#;/?:@&=+$.~*'()_])`;
|
|
1609
|
+
var PATTERN_TAG_URI = new RegExp(`^(?:${NS_URI_CHAR})*$`);
|
|
1610
|
+
var PATTERN_TAG_SUFFIX = new RegExp(`^(?:${NS_TAG_CHAR})+$`);
|
|
1611
|
+
var PATTERN_TAG_PREFIX = new RegExp(`^(?:!(?:${NS_URI_CHAR})*|${NS_TAG_CHAR}(?:${NS_URI_CHAR})*)$`);
|
|
1612
|
+
var DEFAULT_PARSER_OPTIONS = {
|
|
1613
|
+
filename: "",
|
|
1614
|
+
maxDepth: 100
|
|
1615
|
+
};
|
|
1616
|
+
function addDocumentEvent(state, explicitStart, explicitEnd) {
|
|
1617
|
+
state.events.push({
|
|
1618
|
+
type: 1,
|
|
1619
|
+
explicitStart,
|
|
1620
|
+
explicitEnd,
|
|
1621
|
+
directives: state.directives
|
|
1622
|
+
});
|
|
1623
|
+
}
|
|
1624
|
+
function addSequenceEvent(state, start, anchorStart, anchorEnd, tagStart, tagEnd, style) {
|
|
1625
|
+
state.events.push({
|
|
1626
|
+
type: 2,
|
|
1627
|
+
start,
|
|
1628
|
+
anchorStart,
|
|
1629
|
+
anchorEnd,
|
|
1630
|
+
tagStart,
|
|
1631
|
+
tagEnd,
|
|
1632
|
+
style
|
|
1633
|
+
});
|
|
1634
|
+
}
|
|
1635
|
+
function addMappingEvent(state, start, anchorStart, anchorEnd, tagStart, tagEnd, style) {
|
|
1636
|
+
state.events.push({
|
|
1637
|
+
type: 3,
|
|
1638
|
+
start,
|
|
1639
|
+
anchorStart,
|
|
1640
|
+
anchorEnd,
|
|
1641
|
+
tagStart,
|
|
1642
|
+
tagEnd,
|
|
1643
|
+
style
|
|
1644
|
+
});
|
|
1645
|
+
}
|
|
1646
|
+
function addScalarEvent(state, valueStart, valueEnd, anchorStart, anchorEnd, tagStart, tagEnd, style, chomping = 1, indent = -1, fast = false) {
|
|
1647
|
+
state.events.push({
|
|
1648
|
+
type: 4,
|
|
1649
|
+
valueStart,
|
|
1650
|
+
valueEnd,
|
|
1651
|
+
anchorStart,
|
|
1652
|
+
anchorEnd,
|
|
1653
|
+
tagStart,
|
|
1654
|
+
tagEnd,
|
|
1655
|
+
style,
|
|
1656
|
+
chomping,
|
|
1657
|
+
indent,
|
|
1658
|
+
fast
|
|
1659
|
+
});
|
|
1660
|
+
}
|
|
1661
|
+
function addAliasEvent(state, anchorStart, anchorEnd) {
|
|
1662
|
+
state.events.push({
|
|
1663
|
+
type: 5,
|
|
1664
|
+
anchorStart,
|
|
1665
|
+
anchorEnd
|
|
1666
|
+
});
|
|
1667
|
+
}
|
|
1668
|
+
function addPopEvent(state) {
|
|
1669
|
+
state.events.push({ type: 6 });
|
|
1670
|
+
}
|
|
1671
|
+
function addEmptyScalarEvent(state) {
|
|
1672
|
+
addScalarEvent(state, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, 1);
|
|
1673
|
+
}
|
|
1674
|
+
function emptyProperties() {
|
|
1675
|
+
return {
|
|
1676
|
+
anchorStart: NO_RANGE$1,
|
|
1677
|
+
anchorEnd: NO_RANGE$1,
|
|
1678
|
+
tagStart: NO_RANGE$1,
|
|
1679
|
+
tagEnd: NO_RANGE$1
|
|
1680
|
+
};
|
|
1681
|
+
}
|
|
1682
|
+
function snapshotState(state) {
|
|
1683
|
+
return {
|
|
1684
|
+
position: state.position,
|
|
1685
|
+
line: state.line,
|
|
1686
|
+
lineStart: state.lineStart,
|
|
1687
|
+
lineIndent: state.lineIndent,
|
|
1688
|
+
firstTabInLine: state.firstTabInLine,
|
|
1689
|
+
eventsLength: state.events.length
|
|
1690
|
+
};
|
|
1691
|
+
}
|
|
1692
|
+
function restoreState(state, snapshot) {
|
|
1693
|
+
state.position = snapshot.position;
|
|
1694
|
+
state.line = snapshot.line;
|
|
1695
|
+
state.lineStart = snapshot.lineStart;
|
|
1696
|
+
state.lineIndent = snapshot.lineIndent;
|
|
1697
|
+
state.firstTabInLine = snapshot.firstTabInLine;
|
|
1698
|
+
state.events.length = snapshot.eventsLength;
|
|
1699
|
+
}
|
|
1700
|
+
function throwError(state, message) {
|
|
1701
|
+
throwErrorAt(state.input.slice(0, state.length), state.position, message, state.filename);
|
|
1702
|
+
}
|
|
1703
|
+
function isEol(c) {
|
|
1704
|
+
return c === 10 || c === 13;
|
|
1705
|
+
}
|
|
1706
|
+
function isWhiteSpace(c) {
|
|
1707
|
+
return c === 9 || c === 32;
|
|
1708
|
+
}
|
|
1709
|
+
function isWsOrEol(c) {
|
|
1710
|
+
return isWhiteSpace(c) || isEol(c);
|
|
1711
|
+
}
|
|
1712
|
+
function isWsOrEolOrEnd(c) {
|
|
1713
|
+
return c === 0 || isWsOrEol(c);
|
|
1714
|
+
}
|
|
1715
|
+
function isFlowIndicator(c) {
|
|
1716
|
+
return c === 44 || c === 91 || c === 93 || c === 123 || c === 125;
|
|
1717
|
+
}
|
|
1718
|
+
function fromDecimalCode(c) {
|
|
1719
|
+
return c >= 48 && c <= 57 ? c - 48 : -1;
|
|
1720
|
+
}
|
|
1721
|
+
function fromHexCode(c) {
|
|
1722
|
+
if (c >= 48 && c <= 57) return c - 48;
|
|
1723
|
+
const lc = c | 32;
|
|
1724
|
+
if (lc >= 97 && lc <= 102) return lc - 97 + 10;
|
|
1725
|
+
return -1;
|
|
1726
|
+
}
|
|
1727
|
+
function escapedHexLen(c) {
|
|
1728
|
+
if (c === 120) return 2;
|
|
1729
|
+
if (c === 117) return 4;
|
|
1730
|
+
if (c === 85) return 8;
|
|
1731
|
+
return 0;
|
|
1732
|
+
}
|
|
1733
|
+
function isSimpleEscape(c) {
|
|
1734
|
+
return c === 48 || c === 97 || c === 98 || c === 116 || c === 9 || c === 110 || c === 118 || c === 102 || c === 114 || c === 101 || c === 32 || c === 34 || c === 47 || c === 92 || c === 78 || c === 95 || c === 76 || c === 80;
|
|
1735
|
+
}
|
|
1736
|
+
function consumeLineBreak(state) {
|
|
1737
|
+
if (state.input.charCodeAt(state.position) === 10) state.position++;
|
|
1738
|
+
else {
|
|
1739
|
+
state.position++;
|
|
1740
|
+
if (state.input.charCodeAt(state.position) === 10) state.position++;
|
|
1741
|
+
}
|
|
1742
|
+
state.line++;
|
|
1743
|
+
state.lineStart = state.position;
|
|
1744
|
+
state.lineIndent = 0;
|
|
1745
|
+
state.firstTabInLine = -1;
|
|
1746
|
+
}
|
|
1747
|
+
function skipSeparationSpace(state, allowComments) {
|
|
1748
|
+
let lineBreaks = 0;
|
|
1749
|
+
let ch = state.input.charCodeAt(state.position);
|
|
1750
|
+
let hasSeparation = state.position === state.lineStart || isWsOrEol(state.input.charCodeAt(state.position - 1));
|
|
1751
|
+
while (ch !== 0) {
|
|
1752
|
+
while (isWhiteSpace(ch)) {
|
|
1753
|
+
hasSeparation = true;
|
|
1754
|
+
if (ch === 9 && state.firstTabInLine === -1) state.firstTabInLine = state.position;
|
|
1755
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1756
|
+
}
|
|
1757
|
+
if (allowComments && hasSeparation && ch === 35) do
|
|
1758
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1759
|
+
while (!isEol(ch) && ch !== 0);
|
|
1760
|
+
if (!isEol(ch)) break;
|
|
1761
|
+
consumeLineBreak(state);
|
|
1762
|
+
lineBreaks++;
|
|
1763
|
+
hasSeparation = true;
|
|
1764
|
+
ch = state.input.charCodeAt(state.position);
|
|
1765
|
+
while (ch === 32) {
|
|
1766
|
+
state.lineIndent++;
|
|
1767
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
return lineBreaks;
|
|
1771
|
+
}
|
|
1772
|
+
function testDocumentSeparator(state, position = state.position) {
|
|
1773
|
+
const ch = state.input.charCodeAt(position);
|
|
1774
|
+
if ((ch === 45 || ch === 46) && ch === state.input.charCodeAt(position + 1) && ch === state.input.charCodeAt(position + 2)) {
|
|
1775
|
+
const following = state.input.charCodeAt(position + 3);
|
|
1776
|
+
return following === 0 || isWsOrEol(following);
|
|
1777
|
+
}
|
|
1778
|
+
return false;
|
|
1779
|
+
}
|
|
1780
|
+
function skipUntilLineEnd(state) {
|
|
1781
|
+
let ch = state.input.charCodeAt(state.position);
|
|
1782
|
+
while (ch !== 0 && !isEol(ch)) ch = state.input.charCodeAt(++state.position);
|
|
1783
|
+
}
|
|
1784
|
+
function checkPrintable(state, start, end) {
|
|
1785
|
+
if (PATTERN_NON_PRINTABLE.test(state.input.slice(start, end))) throwError(state, "the stream contains non-printable characters");
|
|
1786
|
+
}
|
|
1787
|
+
function readTagProperty(state, props, inFlow) {
|
|
1788
|
+
if (state.input.charCodeAt(state.position) !== 33) return false;
|
|
1789
|
+
if (props.tagStart !== NO_RANGE$1) throwError(state, "duplication of a tag property");
|
|
1790
|
+
const start = state.position;
|
|
1791
|
+
let isVerbatim = false;
|
|
1792
|
+
let isNamed = false;
|
|
1793
|
+
let tagHandle = "!";
|
|
1794
|
+
let ch = state.input.charCodeAt(++state.position);
|
|
1795
|
+
if (ch === 60) {
|
|
1796
|
+
isVerbatim = true;
|
|
1797
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1798
|
+
} else if (ch === 33) {
|
|
1799
|
+
isNamed = true;
|
|
1800
|
+
tagHandle = "!!";
|
|
1801
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1802
|
+
}
|
|
1803
|
+
let suffixStart = state.position;
|
|
1804
|
+
let tagName;
|
|
1805
|
+
if (isVerbatim) {
|
|
1806
|
+
while (ch !== 0 && ch !== 62) ch = state.input.charCodeAt(++state.position);
|
|
1807
|
+
if (ch !== 62) throwError(state, "unexpected end of the stream within a verbatim tag");
|
|
1808
|
+
tagName = state.input.slice(suffixStart, state.position);
|
|
1809
|
+
state.position++;
|
|
1810
|
+
} else {
|
|
1811
|
+
while (ch !== 0 && !isWsOrEol(ch) && !(inFlow && isFlowIndicator(ch))) {
|
|
1812
|
+
if (ch === 33) if (!isNamed) {
|
|
1813
|
+
tagHandle = state.input.slice(suffixStart - 1, state.position + 1);
|
|
1814
|
+
if (!PATTERN_TAG_HANDLE.test(tagHandle)) throwError(state, "named tag handle cannot contain such characters");
|
|
1815
|
+
isNamed = true;
|
|
1816
|
+
suffixStart = state.position + 1;
|
|
1817
|
+
} else throwError(state, "tag suffix cannot contain exclamation marks");
|
|
1818
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1819
|
+
}
|
|
1820
|
+
tagName = state.input.slice(suffixStart, state.position);
|
|
1821
|
+
if (PATTERN_FLOW_INDICATORS.test(tagName)) throwError(state, "tag suffix cannot contain flow indicator characters");
|
|
1822
|
+
}
|
|
1823
|
+
if (tagName && !(isVerbatim ? PATTERN_TAG_URI.test(tagName) : PATTERN_TAG_SUFFIX.test(tagName))) throwError(state, `tag name cannot contain such characters: ${tagName}`);
|
|
1824
|
+
if (!isVerbatim && tagHandle !== "!" && tagHandle !== "!!" && !HAS_OWN.call(state.tagHandlers, tagHandle)) throwError(state, `undeclared tag handle "${tagHandle}"`);
|
|
1825
|
+
props.tagStart = start;
|
|
1826
|
+
props.tagEnd = state.position;
|
|
1827
|
+
return true;
|
|
1828
|
+
}
|
|
1829
|
+
function readAnchorProperty(state, props) {
|
|
1830
|
+
if (state.input.charCodeAt(state.position) !== 38) return false;
|
|
1831
|
+
if (props.anchorStart !== NO_RANGE$1) throwError(state, "duplication of an anchor property");
|
|
1832
|
+
state.position++;
|
|
1833
|
+
const start = state.position;
|
|
1834
|
+
while (state.input.charCodeAt(state.position) !== 0 && !isWsOrEol(state.input.charCodeAt(state.position)) && !isFlowIndicator(state.input.charCodeAt(state.position))) state.position++;
|
|
1835
|
+
if (state.position === start) throwError(state, "name of an anchor node must contain at least one character");
|
|
1836
|
+
props.anchorStart = start;
|
|
1837
|
+
props.anchorEnd = state.position;
|
|
1838
|
+
return true;
|
|
1839
|
+
}
|
|
1840
|
+
function readAlias(state, props) {
|
|
1841
|
+
if (state.input.charCodeAt(state.position) !== 42) return false;
|
|
1842
|
+
if (props.anchorStart !== NO_RANGE$1 || props.tagStart !== NO_RANGE$1) throwError(state, "alias node should not have any properties");
|
|
1843
|
+
state.position++;
|
|
1844
|
+
const start = state.position;
|
|
1845
|
+
while (state.input.charCodeAt(state.position) !== 0 && !isWsOrEol(state.input.charCodeAt(state.position)) && !isFlowIndicator(state.input.charCodeAt(state.position))) state.position++;
|
|
1846
|
+
if (state.position === start) throwError(state, "name of an alias node must contain at least one character");
|
|
1847
|
+
addAliasEvent(state, start, state.position);
|
|
1848
|
+
return true;
|
|
1849
|
+
}
|
|
1850
|
+
function readFlowScalarBreak(state, nodeIndent) {
|
|
1851
|
+
skipSeparationSpace(state, false);
|
|
1852
|
+
if (state.lineIndent < nodeIndent) throwError(state, "deficient indentation");
|
|
1853
|
+
}
|
|
1854
|
+
function readSingleQuotedScalar(state, nodeIndent, props) {
|
|
1855
|
+
if (state.input.charCodeAt(state.position) !== 39) return false;
|
|
1856
|
+
state.position++;
|
|
1857
|
+
const start = state.position;
|
|
1858
|
+
let simple = true;
|
|
1859
|
+
while (state.input.charCodeAt(state.position) !== 0) {
|
|
1860
|
+
const ch = state.input.charCodeAt(state.position);
|
|
1861
|
+
if (ch === 39) {
|
|
1862
|
+
if (state.input.charCodeAt(state.position + 1) === 39) {
|
|
1863
|
+
simple = false;
|
|
1864
|
+
state.position += 2;
|
|
1865
|
+
continue;
|
|
1866
|
+
}
|
|
1867
|
+
const end = state.position;
|
|
1868
|
+
state.position++;
|
|
1869
|
+
addScalarEvent(state, start, end, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, 2, 1, -1, simple);
|
|
1870
|
+
return true;
|
|
1871
|
+
}
|
|
1872
|
+
if (isEol(ch)) {
|
|
1873
|
+
simple = false;
|
|
1874
|
+
readFlowScalarBreak(state, nodeIndent);
|
|
1875
|
+
} else if (state.position === state.lineStart && testDocumentSeparator(state)) throwError(state, "unexpected end of the document within a single quoted scalar");
|
|
1876
|
+
else if (ch !== 9 && ch < 32) throwError(state, "expected valid JSON character");
|
|
1877
|
+
else state.position++;
|
|
1878
|
+
}
|
|
1879
|
+
throwError(state, "unexpected end of the stream within a single quoted scalar");
|
|
1880
|
+
}
|
|
1881
|
+
function readDoubleQuotedScalar(state, nodeIndent, props) {
|
|
1882
|
+
if (state.input.charCodeAt(state.position) !== 34) return false;
|
|
1883
|
+
state.position++;
|
|
1884
|
+
const start = state.position;
|
|
1885
|
+
let simple = true;
|
|
1886
|
+
while (state.input.charCodeAt(state.position) !== 0) {
|
|
1887
|
+
const ch = state.input.charCodeAt(state.position);
|
|
1888
|
+
if (ch === 34) {
|
|
1889
|
+
const end = state.position;
|
|
1890
|
+
state.position++;
|
|
1891
|
+
addScalarEvent(state, start, end, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, 3, 1, -1, simple);
|
|
1892
|
+
return true;
|
|
1893
|
+
}
|
|
1894
|
+
if (ch === 92) {
|
|
1895
|
+
simple = false;
|
|
1896
|
+
const escaped = state.input.charCodeAt(++state.position);
|
|
1897
|
+
if (isEol(escaped)) readFlowScalarBreak(state, nodeIndent);
|
|
1898
|
+
else if (isSimpleEscape(escaped)) state.position++;
|
|
1899
|
+
else {
|
|
1900
|
+
let hexLength = escapedHexLen(escaped);
|
|
1901
|
+
if (hexLength === 0) throwError(state, "unknown escape sequence");
|
|
1902
|
+
while (hexLength-- > 0) {
|
|
1903
|
+
state.position++;
|
|
1904
|
+
if (fromHexCode(state.input.charCodeAt(state.position)) < 0) throwError(state, "expected hexadecimal character");
|
|
1905
|
+
}
|
|
1906
|
+
state.position++;
|
|
1907
|
+
}
|
|
1908
|
+
} else if (isEol(ch)) {
|
|
1909
|
+
simple = false;
|
|
1910
|
+
readFlowScalarBreak(state, nodeIndent);
|
|
1911
|
+
} else if (state.position === state.lineStart && testDocumentSeparator(state)) throwError(state, "unexpected end of the document within a double quoted scalar");
|
|
1912
|
+
else if (ch !== 9 && ch < 32) throwError(state, "expected valid JSON character");
|
|
1913
|
+
else state.position++;
|
|
1914
|
+
}
|
|
1915
|
+
throwError(state, "unexpected end of the stream within a double quoted scalar");
|
|
1916
|
+
}
|
|
1917
|
+
function readBlockScalar(state, parentIndent, props) {
|
|
1918
|
+
const ch = state.input.charCodeAt(state.position);
|
|
1919
|
+
let chomping = 1;
|
|
1920
|
+
let indent = -1;
|
|
1921
|
+
let detectedIndent = false;
|
|
1922
|
+
if (ch !== 124 && ch !== 62) return false;
|
|
1923
|
+
const style = ch === 124 ? 4 : 5;
|
|
1924
|
+
state.position++;
|
|
1925
|
+
while (state.input.charCodeAt(state.position) !== 0) {
|
|
1926
|
+
const current = state.input.charCodeAt(state.position);
|
|
1927
|
+
const digit = fromDecimalCode(current);
|
|
1928
|
+
if (current === 43 || current === 45) {
|
|
1929
|
+
if (chomping !== 1) throwError(state, "repeat of a chomping mode identifier");
|
|
1930
|
+
chomping = current === 43 ? 3 : 2;
|
|
1931
|
+
state.position++;
|
|
1932
|
+
} else if (digit >= 0) {
|
|
1933
|
+
if (digit === 0) throwError(state, "bad explicit indentation width of a block scalar; it cannot be less than one");
|
|
1934
|
+
if (detectedIndent) throwError(state, "repeat of an indentation width identifier");
|
|
1935
|
+
indent = parentIndent + digit - 1;
|
|
1936
|
+
detectedIndent = true;
|
|
1937
|
+
state.position++;
|
|
1938
|
+
} else break;
|
|
1939
|
+
}
|
|
1940
|
+
let hadWhitespace = false;
|
|
1941
|
+
while (isWhiteSpace(state.input.charCodeAt(state.position))) {
|
|
1942
|
+
hadWhitespace = true;
|
|
1943
|
+
state.position++;
|
|
1944
|
+
}
|
|
1945
|
+
if (hadWhitespace && state.input.charCodeAt(state.position) === 35) skipUntilLineEnd(state);
|
|
1946
|
+
if (isEol(state.input.charCodeAt(state.position))) consumeLineBreak(state);
|
|
1947
|
+
else if (state.input.charCodeAt(state.position) !== 0) throwError(state, "a line break is expected");
|
|
1948
|
+
let contentIndent = detectedIndent ? indent : -1;
|
|
1949
|
+
let maxLeadingIndent = 0;
|
|
1950
|
+
const valueStart = state.position;
|
|
1951
|
+
let valueEnd = state.position;
|
|
1952
|
+
while (state.input.charCodeAt(state.position) !== 0) {
|
|
1953
|
+
const linePosition = state.position;
|
|
1954
|
+
let column = 0;
|
|
1955
|
+
while (state.input.charCodeAt(linePosition + column) === 32) column++;
|
|
1956
|
+
const first = state.input.charCodeAt(linePosition + column);
|
|
1957
|
+
if (first === 0) {
|
|
1958
|
+
if (contentIndent >= 0) {
|
|
1959
|
+
if (column > contentIndent) valueEnd = linePosition + column;
|
|
1960
|
+
} else if (column > 0) valueEnd = linePosition + column;
|
|
1961
|
+
break;
|
|
1962
|
+
}
|
|
1963
|
+
if (linePosition === state.lineStart && testDocumentSeparator(state, linePosition)) break;
|
|
1964
|
+
if (!detectedIndent && contentIndent === -1 && isEol(first)) maxLeadingIndent = Math.max(maxLeadingIndent, column);
|
|
1965
|
+
if (!detectedIndent && contentIndent === -1 && !isEol(first)) {
|
|
1966
|
+
if (first === 9 && column < parentIndent) {
|
|
1967
|
+
state.position = linePosition + column;
|
|
1968
|
+
throwError(state, "tab characters must not be used in indentation");
|
|
1969
|
+
}
|
|
1970
|
+
if (column < maxLeadingIndent) {
|
|
1971
|
+
state.position = linePosition + column;
|
|
1972
|
+
throwError(state, "bad indentation of a mapping entry");
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
if (contentIndent === -1 && first !== 0 && !isEol(first) && column < parentIndent) {
|
|
1976
|
+
state.lineIndent = column;
|
|
1977
|
+
state.position = linePosition + column;
|
|
1978
|
+
break;
|
|
1979
|
+
}
|
|
1980
|
+
if (!detectedIndent && first !== 0 && !isEol(first) && contentIndent === -1) contentIndent = column;
|
|
1981
|
+
const requiredIndent = contentIndent === -1 ? parentIndent + 1 : contentIndent;
|
|
1982
|
+
if (first !== 0 && !isEol(first) && column < requiredIndent) {
|
|
1983
|
+
state.lineIndent = column;
|
|
1984
|
+
state.position = linePosition + column;
|
|
1985
|
+
break;
|
|
1986
|
+
}
|
|
1987
|
+
skipUntilLineEnd(state);
|
|
1988
|
+
valueEnd = state.position;
|
|
1989
|
+
if (isEol(state.input.charCodeAt(state.position))) {
|
|
1990
|
+
consumeLineBreak(state);
|
|
1991
|
+
valueEnd = state.position;
|
|
1992
|
+
}
|
|
1993
|
+
}
|
|
1994
|
+
checkPrintable(state, valueStart, valueEnd);
|
|
1995
|
+
addScalarEvent(state, valueStart, valueEnd, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, style, chomping, contentIndent);
|
|
1996
|
+
return true;
|
|
1997
|
+
}
|
|
1998
|
+
function canStartPlainScalar(state, nodeContext) {
|
|
1999
|
+
const ch = state.input.charCodeAt(state.position);
|
|
2000
|
+
const inFlow = nodeContext === CONTEXT_FLOW_IN;
|
|
2001
|
+
if (ch === 0 || isWsOrEol(ch) || ch === 35 || ch === 38 || ch === 42 || ch === 33 || ch === 124 || ch === 62 || ch === 39 || ch === 34 || ch === 37 || ch === 64 || ch === 96 || inFlow && isFlowIndicator(ch)) return false;
|
|
2002
|
+
if (ch === 63 || ch === 45) {
|
|
2003
|
+
const following = state.input.charCodeAt(state.position + 1);
|
|
2004
|
+
if (isWsOrEolOrEnd(following) || inFlow && isFlowIndicator(following)) return false;
|
|
2005
|
+
}
|
|
2006
|
+
return true;
|
|
2007
|
+
}
|
|
2008
|
+
function readPlainScalar(state, nodeIndent, nodeContext, props) {
|
|
2009
|
+
if (!canStartPlainScalar(state, nodeContext)) return false;
|
|
2010
|
+
const start = state.position;
|
|
2011
|
+
let end = state.position;
|
|
2012
|
+
let ch = state.input.charCodeAt(state.position);
|
|
2013
|
+
const inFlow = nodeContext === CONTEXT_FLOW_IN;
|
|
2014
|
+
let multiline = false;
|
|
2015
|
+
while (ch !== 0) {
|
|
2016
|
+
if (state.position === state.lineStart && testDocumentSeparator(state)) break;
|
|
2017
|
+
if (ch === 58) {
|
|
2018
|
+
const following = state.input.charCodeAt(state.position + 1);
|
|
2019
|
+
if (isWsOrEolOrEnd(following) || inFlow && isFlowIndicator(following)) break;
|
|
2020
|
+
} else if (ch === 35) {
|
|
2021
|
+
if (isWsOrEol(state.input.charCodeAt(state.position - 1))) break;
|
|
2022
|
+
} else if (inFlow && isFlowIndicator(ch)) break;
|
|
2023
|
+
else if (isEol(ch)) {
|
|
2024
|
+
const savedPosition = state.position;
|
|
2025
|
+
const savedLine = state.line;
|
|
2026
|
+
const savedLineStart = state.lineStart;
|
|
2027
|
+
const savedLineIndent = state.lineIndent;
|
|
2028
|
+
skipSeparationSpace(state, false);
|
|
2029
|
+
if (state.lineIndent >= nodeIndent) {
|
|
2030
|
+
multiline = true;
|
|
2031
|
+
ch = state.input.charCodeAt(state.position);
|
|
2032
|
+
continue;
|
|
2033
|
+
}
|
|
2034
|
+
state.position = savedPosition;
|
|
2035
|
+
state.line = savedLine;
|
|
2036
|
+
state.lineStart = savedLineStart;
|
|
2037
|
+
state.lineIndent = savedLineIndent;
|
|
2038
|
+
break;
|
|
2039
|
+
}
|
|
2040
|
+
if (!isWhiteSpace(ch)) end = state.position + 1;
|
|
2041
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2042
|
+
}
|
|
2043
|
+
if (end === start) return false;
|
|
2044
|
+
checkPrintable(state, start, end);
|
|
2045
|
+
addScalarEvent(state, start, end, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, 1, 1, -1, !multiline);
|
|
2046
|
+
return true;
|
|
2047
|
+
}
|
|
2048
|
+
function skipFlowSeparationSpace(state, nodeIndent) {
|
|
2049
|
+
const startLine = state.line;
|
|
2050
|
+
skipSeparationSpace(state, true);
|
|
2051
|
+
if (state.line > startLine && state.lineIndent < nodeIndent || state.firstTabInLine !== -1 && state.lineIndent < nodeIndent) throwError(state, "deficient indentation");
|
|
2052
|
+
}
|
|
2053
|
+
function readFlowCollection(state, nodeIndent, props) {
|
|
2054
|
+
const ch = state.input.charCodeAt(state.position);
|
|
2055
|
+
const isMapping = ch === 123;
|
|
2056
|
+
const start = state.position;
|
|
2057
|
+
let readNext = true;
|
|
2058
|
+
if (ch !== 91 && ch !== 123) return false;
|
|
2059
|
+
const terminator = isMapping ? 125 : 93;
|
|
2060
|
+
if (isMapping) addMappingEvent(state, start, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, 2);
|
|
2061
|
+
else addSequenceEvent(state, start, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, 2);
|
|
2062
|
+
state.position++;
|
|
2063
|
+
while (state.input.charCodeAt(state.position) !== 0) {
|
|
2064
|
+
skipFlowSeparationSpace(state, nodeIndent);
|
|
2065
|
+
let ch = state.input.charCodeAt(state.position);
|
|
2066
|
+
if (ch === terminator) {
|
|
2067
|
+
state.position++;
|
|
2068
|
+
addPopEvent(state);
|
|
2069
|
+
return true;
|
|
2070
|
+
} else if (!readNext) throwError(state, "missed comma between flow collection entries");
|
|
2071
|
+
else if (ch === 44) throwError(state, "expected the node content, but found ','");
|
|
2072
|
+
let isPair = false;
|
|
2073
|
+
let isExplicitPair = false;
|
|
2074
|
+
if (ch === 63 && isWsOrEol(state.input.charCodeAt(state.position + 1))) {
|
|
2075
|
+
isPair = isExplicitPair = true;
|
|
2076
|
+
state.position += 1;
|
|
2077
|
+
skipFlowSeparationSpace(state, nodeIndent);
|
|
2078
|
+
}
|
|
2079
|
+
const entryLine = state.line;
|
|
2080
|
+
const entryStart = snapshotState(state);
|
|
2081
|
+
const keyWasRead = parseNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
|
|
2082
|
+
skipFlowSeparationSpace(state, nodeIndent);
|
|
2083
|
+
ch = state.input.charCodeAt(state.position);
|
|
2084
|
+
if ((isMapping || isExplicitPair || state.line === entryLine) && ch === 58) {
|
|
2085
|
+
isPair = true;
|
|
2086
|
+
state.position++;
|
|
2087
|
+
skipFlowSeparationSpace(state, nodeIndent);
|
|
2088
|
+
if (!isMapping) {
|
|
2089
|
+
restoreState(state, entryStart);
|
|
2090
|
+
addMappingEvent(state, entryStart.position, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, 2);
|
|
2091
|
+
if (!parseNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true)) addEmptyScalarEvent(state);
|
|
2092
|
+
skipFlowSeparationSpace(state, nodeIndent);
|
|
2093
|
+
state.position++;
|
|
2094
|
+
skipFlowSeparationSpace(state, nodeIndent);
|
|
2095
|
+
} else if (!keyWasRead) addEmptyScalarEvent(state);
|
|
2096
|
+
if (!parseNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true)) addEmptyScalarEvent(state);
|
|
2097
|
+
skipFlowSeparationSpace(state, nodeIndent);
|
|
2098
|
+
if (!isMapping) addPopEvent(state);
|
|
2099
|
+
} else if (isMapping && isPair) {
|
|
2100
|
+
if (!keyWasRead) addEmptyScalarEvent(state);
|
|
2101
|
+
addEmptyScalarEvent(state);
|
|
2102
|
+
} else if (isMapping) addEmptyScalarEvent(state);
|
|
2103
|
+
else if (isPair) {
|
|
2104
|
+
restoreState(state, entryStart);
|
|
2105
|
+
addMappingEvent(state, entryStart.position, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, 2);
|
|
2106
|
+
parseNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
|
|
2107
|
+
addEmptyScalarEvent(state);
|
|
2108
|
+
addPopEvent(state);
|
|
2109
|
+
}
|
|
2110
|
+
ch = state.input.charCodeAt(state.position);
|
|
2111
|
+
if (ch === 44) {
|
|
2112
|
+
readNext = true;
|
|
2113
|
+
state.position++;
|
|
2114
|
+
} else readNext = false;
|
|
2115
|
+
}
|
|
2116
|
+
throwError(state, "unexpected end of the stream within a flow collection");
|
|
2117
|
+
}
|
|
2118
|
+
function readBlockSequence(state, nodeIndent, props) {
|
|
2119
|
+
if (state.firstTabInLine !== -1 || state.input.charCodeAt(state.position) !== 45 || !isWsOrEolOrEnd(state.input.charCodeAt(state.position + 1))) return false;
|
|
2120
|
+
addSequenceEvent(state, state.position, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, 1);
|
|
2121
|
+
while (state.input.charCodeAt(state.position) === 45 && isWsOrEolOrEnd(state.input.charCodeAt(state.position + 1))) {
|
|
2122
|
+
if (state.firstTabInLine !== -1) {
|
|
2123
|
+
state.position = state.firstTabInLine;
|
|
2124
|
+
throwError(state, "tab characters must not be used in indentation");
|
|
2125
|
+
}
|
|
2126
|
+
const entryLine = state.line;
|
|
2127
|
+
state.position++;
|
|
2128
|
+
const hadBreak = skipSeparationSpace(state, true) > 0;
|
|
2129
|
+
if (state.firstTabInLine !== -1 && state.input.charCodeAt(state.position) === 45 && isWsOrEolOrEnd(state.input.charCodeAt(state.position + 1))) throwError(state, "bad indentation of a sequence entry");
|
|
2130
|
+
if (hadBreak && state.lineIndent <= nodeIndent) addEmptyScalarEvent(state);
|
|
2131
|
+
else parseNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
|
|
2132
|
+
skipSeparationSpace(state, true);
|
|
2133
|
+
if (state.lineIndent < nodeIndent || state.position >= state.length) break;
|
|
2134
|
+
if (state.lineIndent > nodeIndent) throwError(state, "bad indentation of a sequence entry");
|
|
2135
|
+
if (state.line === entryLine && state.input.charCodeAt(state.position) === 45 && isWsOrEolOrEnd(state.input.charCodeAt(state.position + 1))) throwError(state, "bad indentation of a sequence entry");
|
|
2136
|
+
}
|
|
2137
|
+
addPopEvent(state);
|
|
2138
|
+
return true;
|
|
2139
|
+
}
|
|
2140
|
+
function readBlockMapping(state, nodeIndent, flowIndent, props) {
|
|
2141
|
+
let atExplicitKey = false;
|
|
2142
|
+
let detected = false;
|
|
2143
|
+
let mappingOpened = false;
|
|
2144
|
+
let pendingExplicitKey = false;
|
|
2145
|
+
if (state.firstTabInLine !== -1) return false;
|
|
2146
|
+
let ch = state.input.charCodeAt(state.position);
|
|
2147
|
+
while (ch !== 0) {
|
|
2148
|
+
if (!atExplicitKey && state.firstTabInLine !== -1) {
|
|
2149
|
+
state.position = state.firstTabInLine;
|
|
2150
|
+
throwError(state, "tab characters must not be used in indentation");
|
|
2151
|
+
}
|
|
2152
|
+
const following = state.input.charCodeAt(state.position + 1);
|
|
2153
|
+
const entryLine = state.line;
|
|
2154
|
+
if ((ch === 63 || ch === 58) && isWsOrEolOrEnd(following)) {
|
|
2155
|
+
if (!mappingOpened) {
|
|
2156
|
+
addMappingEvent(state, state.position, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, 1);
|
|
2157
|
+
mappingOpened = true;
|
|
2158
|
+
}
|
|
2159
|
+
if (ch === 63) {
|
|
2160
|
+
if (atExplicitKey) addEmptyScalarEvent(state);
|
|
2161
|
+
detected = true;
|
|
2162
|
+
atExplicitKey = true;
|
|
2163
|
+
} else if (atExplicitKey) atExplicitKey = false;
|
|
2164
|
+
else {
|
|
2165
|
+
addEmptyScalarEvent(state);
|
|
2166
|
+
detected = true;
|
|
2167
|
+
atExplicitKey = false;
|
|
2168
|
+
}
|
|
2169
|
+
state.position += 1;
|
|
2170
|
+
pendingExplicitKey = true;
|
|
2171
|
+
} else {
|
|
2172
|
+
if (atExplicitKey) {
|
|
2173
|
+
addEmptyScalarEvent(state);
|
|
2174
|
+
atExplicitKey = false;
|
|
2175
|
+
}
|
|
2176
|
+
const beforeKey = snapshotState(state);
|
|
2177
|
+
if (!parseNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) break;
|
|
2178
|
+
if (state.line === entryLine) {
|
|
2179
|
+
ch = state.input.charCodeAt(state.position);
|
|
2180
|
+
while (isWhiteSpace(ch)) ch = state.input.charCodeAt(++state.position);
|
|
2181
|
+
if (ch === 58) {
|
|
2182
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2183
|
+
if (!isWsOrEolOrEnd(ch)) throwError(state, "a whitespace character is expected after the key-value separator within a block mapping");
|
|
2184
|
+
if (!mappingOpened) {
|
|
2185
|
+
restoreState(state, beforeKey);
|
|
2186
|
+
addMappingEvent(state, beforeKey.position, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, 1);
|
|
2187
|
+
mappingOpened = true;
|
|
2188
|
+
parseNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true);
|
|
2189
|
+
ch = state.input.charCodeAt(state.position);
|
|
2190
|
+
while (isWhiteSpace(ch)) ch = state.input.charCodeAt(++state.position);
|
|
2191
|
+
state.position++;
|
|
2192
|
+
}
|
|
2193
|
+
detected = true;
|
|
2194
|
+
atExplicitKey = false;
|
|
2195
|
+
pendingExplicitKey = false;
|
|
2196
|
+
} else if (detected) throwError(state, "expected ':' after a mapping key");
|
|
2197
|
+
else {
|
|
2198
|
+
if (props.anchorStart !== NO_RANGE$1 || props.tagStart !== NO_RANGE$1) {
|
|
2199
|
+
restoreState(state, beforeKey);
|
|
2200
|
+
return false;
|
|
2201
|
+
}
|
|
2202
|
+
return true;
|
|
2203
|
+
}
|
|
2204
|
+
} else if (detected) throwError(state, "can not read a block mapping entry; a multiline key may not be an implicit key");
|
|
2205
|
+
else {
|
|
2206
|
+
if (props.anchorStart !== NO_RANGE$1 || props.tagStart !== NO_RANGE$1) {
|
|
2207
|
+
restoreState(state, beforeKey);
|
|
2208
|
+
return false;
|
|
2209
|
+
}
|
|
2210
|
+
return true;
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
if (parseNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, pendingExplicitKey)) pendingExplicitKey = false;
|
|
2214
|
+
if (!atExplicitKey) {
|
|
2215
|
+
if (pendingExplicitKey) {
|
|
2216
|
+
addEmptyScalarEvent(state);
|
|
2217
|
+
pendingExplicitKey = false;
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
skipSeparationSpace(state, true);
|
|
2221
|
+
ch = state.input.charCodeAt(state.position);
|
|
2222
|
+
if ((state.line === entryLine || state.lineIndent > nodeIndent) && ch !== 0) throwError(state, "bad indentation of a mapping entry");
|
|
2223
|
+
else if (state.lineIndent < nodeIndent) break;
|
|
2224
|
+
}
|
|
2225
|
+
if (!detected) return false;
|
|
2226
|
+
if (atExplicitKey) addEmptyScalarEvent(state);
|
|
2227
|
+
if (mappingOpened) addPopEvent(state);
|
|
2228
|
+
return true;
|
|
2229
|
+
}
|
|
2230
|
+
function parseNode(state, parentIndent, nodeContext, allowToSeek, allowCompact, allowPropertyMapping = true) {
|
|
2231
|
+
if (state.depth >= state.maxDepth) throwError(state, `nesting exceeded maxDepth (${state.maxDepth})`);
|
|
2232
|
+
state.depth++;
|
|
2233
|
+
let indentStatus = 1;
|
|
2234
|
+
let atNewLine = false;
|
|
2235
|
+
let hasContent = false;
|
|
2236
|
+
let propertyStart = null;
|
|
2237
|
+
const props = emptyProperties();
|
|
2238
|
+
let allowBlockScalars = nodeContext === CONTEXT_BLOCK_OUT || nodeContext === CONTEXT_BLOCK_IN;
|
|
2239
|
+
let allowBlockCollections = allowBlockScalars;
|
|
2240
|
+
const allowBlockStyles = allowBlockScalars;
|
|
2241
|
+
if (allowToSeek && skipSeparationSpace(state, true)) {
|
|
2242
|
+
atNewLine = true;
|
|
2243
|
+
if (state.lineIndent > parentIndent) indentStatus = 1;
|
|
2244
|
+
else if (state.lineIndent === parentIndent) indentStatus = 0;
|
|
2245
|
+
else indentStatus = -1;
|
|
2246
|
+
}
|
|
2247
|
+
if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
2248
|
+
state.depth--;
|
|
2249
|
+
return false;
|
|
2250
|
+
}
|
|
2251
|
+
if (indentStatus === 1) while (true) {
|
|
2252
|
+
const ch = state.input.charCodeAt(state.position);
|
|
2253
|
+
const propertyState = snapshotState(state);
|
|
2254
|
+
if (atNewLine && indentStatus !== 1 && (ch === 33 || ch === 38)) break;
|
|
2255
|
+
if (atNewLine && allowBlockStyles && (props.tagStart !== NO_RANGE$1 || props.anchorStart !== NO_RANGE$1) && (ch === 33 || ch === 38)) {
|
|
2256
|
+
const fallbackState = snapshotState(state);
|
|
2257
|
+
const flowIndent = parentIndent + 1;
|
|
2258
|
+
if (readBlockMapping(state, state.position - state.lineStart, flowIndent, props) && state.events[fallbackState.eventsLength]?.type === 3) {
|
|
2259
|
+
state.depth--;
|
|
2260
|
+
return true;
|
|
2261
|
+
}
|
|
2262
|
+
restoreState(state, fallbackState);
|
|
2263
|
+
}
|
|
2264
|
+
if (atNewLine && (ch === 33 && props.tagStart !== NO_RANGE$1 || ch === 38 && props.anchorStart !== NO_RANGE$1)) break;
|
|
2265
|
+
if (!readTagProperty(state, props, nodeContext === CONTEXT_FLOW_IN) && !readAnchorProperty(state, props)) break;
|
|
2266
|
+
if (propertyStart === null) propertyStart = propertyState;
|
|
2267
|
+
if (skipSeparationSpace(state, true)) {
|
|
2268
|
+
atNewLine = true;
|
|
2269
|
+
allowBlockCollections = allowBlockStyles;
|
|
2270
|
+
if (state.lineIndent > parentIndent) indentStatus = 1;
|
|
2271
|
+
else if (state.lineIndent === parentIndent) indentStatus = 0;
|
|
2272
|
+
else indentStatus = -1;
|
|
2273
|
+
} else allowBlockCollections = false;
|
|
2274
|
+
}
|
|
2275
|
+
if (allowBlockCollections) allowBlockCollections = atNewLine || allowCompact;
|
|
2276
|
+
if (indentStatus === 1 || nodeContext === CONTEXT_BLOCK_OUT) {
|
|
2277
|
+
const flowIndent = nodeContext === CONTEXT_FLOW_IN || nodeContext === CONTEXT_FLOW_OUT ? parentIndent : parentIndent + 1;
|
|
2278
|
+
const blockIndent = state.position - state.lineStart;
|
|
2279
|
+
if (indentStatus === 1) if (allowBlockCollections && (readBlockSequence(state, blockIndent, props) || readBlockMapping(state, blockIndent, flowIndent, props)) || readFlowCollection(state, flowIndent, props)) hasContent = true;
|
|
2280
|
+
else {
|
|
2281
|
+
const ch = state.input.charCodeAt(state.position);
|
|
2282
|
+
if (propertyStart !== null && allowPropertyMapping && allowBlockStyles && !allowBlockCollections && ch !== 124 && ch !== 62) {
|
|
2283
|
+
const fallbackState = snapshotState(state);
|
|
2284
|
+
const propertyIndent = propertyStart.position - propertyStart.lineStart;
|
|
2285
|
+
restoreState(state, propertyStart);
|
|
2286
|
+
if (readBlockMapping(state, propertyIndent, flowIndent, emptyProperties()) && state.events[fallbackState.eventsLength]?.type === 3) hasContent = true;
|
|
2287
|
+
else restoreState(state, fallbackState);
|
|
2288
|
+
}
|
|
2289
|
+
if (!hasContent && (allowBlockScalars && readBlockScalar(state, flowIndent, props) || readSingleQuotedScalar(state, flowIndent, props) || readDoubleQuotedScalar(state, flowIndent, props) || readAlias(state, props) || readPlainScalar(state, flowIndent, nodeContext, props))) hasContent = true;
|
|
2290
|
+
}
|
|
2291
|
+
else if (indentStatus === 0) hasContent = allowBlockCollections && readBlockSequence(state, blockIndent, props);
|
|
2292
|
+
}
|
|
2293
|
+
allowBlockScalars = allowBlockScalars && !hasContent;
|
|
2294
|
+
if (!hasContent && (props.anchorStart !== NO_RANGE$1 || props.tagStart !== NO_RANGE$1 || allowBlockScalars)) {
|
|
2295
|
+
addScalarEvent(state, NO_RANGE$1, NO_RANGE$1, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, 1);
|
|
2296
|
+
hasContent = true;
|
|
2297
|
+
}
|
|
2298
|
+
state.depth--;
|
|
2299
|
+
return hasContent || props.anchorStart !== NO_RANGE$1 || props.tagStart !== NO_RANGE$1;
|
|
2300
|
+
}
|
|
2301
|
+
function readDirective(state) {
|
|
2302
|
+
if (state.lineIndent > 0 || state.input.charCodeAt(state.position) !== 37) return false;
|
|
2303
|
+
state.position++;
|
|
2304
|
+
const nameStart = state.position;
|
|
2305
|
+
while (state.input.charCodeAt(state.position) !== 0 && !isWsOrEol(state.input.charCodeAt(state.position))) state.position++;
|
|
2306
|
+
const name = state.input.slice(nameStart, state.position);
|
|
2307
|
+
const args = [];
|
|
2308
|
+
if (name.length === 0) throwError(state, "directive name must not be less than one character in length");
|
|
2309
|
+
while (state.input.charCodeAt(state.position) !== 0 && !isEol(state.input.charCodeAt(state.position))) {
|
|
2310
|
+
while (isWhiteSpace(state.input.charCodeAt(state.position))) state.position++;
|
|
2311
|
+
if (state.input.charCodeAt(state.position) === 35 || isEol(state.input.charCodeAt(state.position)) || state.input.charCodeAt(state.position) === 0) break;
|
|
2312
|
+
const start = state.position;
|
|
2313
|
+
while (state.input.charCodeAt(state.position) !== 0 && !isWsOrEol(state.input.charCodeAt(state.position))) state.position++;
|
|
2314
|
+
args.push(state.input.slice(start, state.position));
|
|
2315
|
+
}
|
|
2316
|
+
if (isEol(state.input.charCodeAt(state.position))) consumeLineBreak(state);
|
|
2317
|
+
if (name === "YAML") {
|
|
2318
|
+
if (state.directives.some((directive) => directive.kind === "yaml")) throwError(state, "duplication of %YAML directive");
|
|
2319
|
+
if (args.length !== 1) throwError(state, "YAML directive accepts exactly one argument");
|
|
2320
|
+
const match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
|
|
2321
|
+
if (match === null) throwError(state, "ill-formed argument of the YAML directive");
|
|
2322
|
+
if (parseInt(match[1], 10) !== 1) throwError(state, "unacceptable YAML version of the document");
|
|
2323
|
+
state.directives.push({
|
|
2324
|
+
kind: "yaml",
|
|
2325
|
+
version: args[0]
|
|
2326
|
+
});
|
|
2327
|
+
} else if (name === "TAG") {
|
|
2328
|
+
if (args.length !== 2) throwError(state, "TAG directive accepts exactly two arguments");
|
|
2329
|
+
const [handle, prefix] = args;
|
|
2330
|
+
if (!PATTERN_TAG_HANDLE.test(handle)) throwError(state, "ill-formed tag handle (first argument) of the TAG directive");
|
|
2331
|
+
if (HAS_OWN.call(state.tagHandlers, handle)) throwError(state, `there is a previously declared suffix for "${handle}" tag handle`);
|
|
2332
|
+
if (!PATTERN_TAG_PREFIX.test(prefix)) throwError(state, "ill-formed tag prefix (second argument) of the TAG directive");
|
|
2333
|
+
state.tagHandlers[handle] = prefix;
|
|
2334
|
+
state.directives.push({
|
|
2335
|
+
kind: "tag",
|
|
2336
|
+
handle,
|
|
2337
|
+
prefix
|
|
2338
|
+
});
|
|
2339
|
+
}
|
|
2340
|
+
return true;
|
|
2341
|
+
}
|
|
2342
|
+
function readDocument(state) {
|
|
2343
|
+
state.directives = [];
|
|
2344
|
+
state.tagHandlers = Object.create(null);
|
|
2345
|
+
let hasDirectives = false;
|
|
2346
|
+
skipSeparationSpace(state, true);
|
|
2347
|
+
while (readDirective(state)) {
|
|
2348
|
+
hasDirectives = true;
|
|
2349
|
+
skipSeparationSpace(state, true);
|
|
2350
|
+
}
|
|
2351
|
+
let explicitStart = false;
|
|
2352
|
+
let explicitEnd = false;
|
|
2353
|
+
let allowCompact = true;
|
|
2354
|
+
if (state.lineIndent === 0 && state.input.charCodeAt(state.position) === 45 && state.input.charCodeAt(state.position + 1) === 45 && state.input.charCodeAt(state.position + 2) === 45 && isWsOrEolOrEnd(state.input.charCodeAt(state.position + 3))) {
|
|
2355
|
+
explicitStart = true;
|
|
2356
|
+
const markerLine = state.line;
|
|
2357
|
+
state.position += 3;
|
|
2358
|
+
skipSeparationSpace(state, true);
|
|
2359
|
+
allowCompact = state.line > markerLine;
|
|
2360
|
+
} else if (hasDirectives) throwError(state, "directives end mark is expected");
|
|
2361
|
+
const documentEventIndex = state.events.length;
|
|
2362
|
+
if (!explicitStart && state.position === state.lineStart && state.input.charCodeAt(state.position) === 46 && testDocumentSeparator(state)) {
|
|
2363
|
+
state.position += 3;
|
|
2364
|
+
skipSeparationSpace(state, true);
|
|
2365
|
+
return;
|
|
2366
|
+
}
|
|
2367
|
+
addDocumentEvent(state, explicitStart, false);
|
|
2368
|
+
if (!parseNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, allowCompact, allowCompact)) addEmptyScalarEvent(state);
|
|
2369
|
+
skipSeparationSpace(state, true);
|
|
2370
|
+
if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
2371
|
+
explicitEnd = state.input.charCodeAt(state.position) === 46;
|
|
2372
|
+
if (explicitEnd) {
|
|
2373
|
+
const markerLine = state.line;
|
|
2374
|
+
state.position += 3;
|
|
2375
|
+
skipSeparationSpace(state, true);
|
|
2376
|
+
if (state.line === markerLine && state.position < state.length) throwError(state, "end of the stream or a document separator is expected");
|
|
2377
|
+
}
|
|
2378
|
+
}
|
|
2379
|
+
const documentEvent = state.events[documentEventIndex];
|
|
2380
|
+
if (documentEvent?.type === 1) documentEvent.explicitEnd = explicitEnd;
|
|
2381
|
+
addPopEvent(state);
|
|
2382
|
+
if (!explicitEnd && state.position < state.length && !(state.position === state.lineStart && testDocumentSeparator(state))) throwError(state, "end of the stream or a document separator is expected");
|
|
2383
|
+
}
|
|
2384
|
+
function parseEvents(input, options) {
|
|
2385
|
+
const length = input.length;
|
|
2386
|
+
const state = {
|
|
2387
|
+
...DEFAULT_PARSER_OPTIONS,
|
|
2388
|
+
...options,
|
|
2389
|
+
input: `${input}\0`,
|
|
2390
|
+
length,
|
|
2391
|
+
position: 0,
|
|
2392
|
+
line: 0,
|
|
2393
|
+
lineStart: 0,
|
|
2394
|
+
lineIndent: 0,
|
|
2395
|
+
firstTabInLine: -1,
|
|
2396
|
+
depth: 0,
|
|
2397
|
+
directives: [],
|
|
2398
|
+
tagHandlers: Object.create(null),
|
|
2399
|
+
events: []
|
|
2400
|
+
};
|
|
2401
|
+
const nullpos = input.indexOf("\0");
|
|
2402
|
+
if (nullpos !== -1) throwErrorAt(input, nullpos, "null byte is not allowed in input", state.filename);
|
|
2403
|
+
if (state.input.charCodeAt(state.position) === 65279) state.position++;
|
|
2404
|
+
while (state.position < state.length) {
|
|
2405
|
+
skipSeparationSpace(state, true);
|
|
2406
|
+
if (state.position >= state.length) break;
|
|
2407
|
+
const documentStart = state.position;
|
|
2408
|
+
readDocument(state);
|
|
2409
|
+
if (state.position === documentStart)
|
|
2410
|
+
/* c8 ignore next */
|
|
2411
|
+
throwError(state, "can not read a document");
|
|
2412
|
+
}
|
|
2413
|
+
return state.events;
|
|
2414
|
+
}
|
|
2415
|
+
//#endregion
|
|
2416
|
+
//#region src/load.ts
|
|
2417
|
+
var DEFAULT_LOAD_OPTIONS = {
|
|
2418
|
+
...DEFAULT_PARSER_OPTIONS,
|
|
2419
|
+
...DEFAULT_CONSTRUCTOR_OPTIONS
|
|
2420
|
+
};
|
|
2421
|
+
function loadDocuments(input, options = {}) {
|
|
2422
|
+
const opts = {
|
|
2423
|
+
...DEFAULT_LOAD_OPTIONS,
|
|
2424
|
+
...options
|
|
2425
|
+
};
|
|
2426
|
+
const source = String(input);
|
|
2427
|
+
const PARSER_OPT_KEYS = Object.keys(DEFAULT_PARSER_OPTIONS);
|
|
2428
|
+
const CONSTRUCTOR_OPT_KEYS = Object.keys(DEFAULT_CONSTRUCTOR_OPTIONS);
|
|
2429
|
+
return constructFromEvents(parseEvents(source, pick(opts, PARSER_OPT_KEYS)), {
|
|
2430
|
+
...pick(opts, CONSTRUCTOR_OPT_KEYS),
|
|
2431
|
+
source
|
|
2432
|
+
});
|
|
2433
|
+
}
|
|
2434
|
+
function load(input, options) {
|
|
2435
|
+
const documents = loadDocuments(input, options);
|
|
2436
|
+
if (documents.length === 0) throw new YAMLException("expected a document, but the input is empty");
|
|
2437
|
+
if (documents.length === 1) return documents[0];
|
|
2438
|
+
throw new YAMLException("expected a single document in the stream, but found more");
|
|
2439
|
+
}
|
|
2440
|
+
//#endregion
|
|
2441
|
+
//#region src/ast/nodes.ts
|
|
2442
|
+
var Style = class {
|
|
2443
|
+
tagged = false;
|
|
2444
|
+
flow = false;
|
|
2445
|
+
singleQuoted = false;
|
|
2446
|
+
doubleQuoted = false;
|
|
2447
|
+
literal = false;
|
|
2448
|
+
folded = false;
|
|
2449
|
+
};
|
|
2450
|
+
//#endregion
|
|
2451
|
+
//#region src/ast/from_js.ts
|
|
2452
|
+
var INVALID = Symbol("INVALID");
|
|
2453
|
+
function buildRepresentTypes(schema) {
|
|
2454
|
+
const defaultTags = new Set([
|
|
2455
|
+
schema.defaultScalarTag,
|
|
2456
|
+
schema.defaultSequenceTag,
|
|
2457
|
+
schema.defaultMappingTag
|
|
2458
|
+
].filter((t) => t !== void 0));
|
|
2459
|
+
const implicitScalars = schema.implicitScalarTags;
|
|
2460
|
+
const explicitTags = schema.tags.filter((t) => !(t.nodeKind === "scalar" && t.implicit) && !defaultTags.has(t));
|
|
2461
|
+
const defaultTagsLast = schema.tags.filter((t) => defaultTags.has(t));
|
|
2462
|
+
return [
|
|
2463
|
+
...implicitScalars.map((tag) => ({
|
|
2464
|
+
tag,
|
|
2465
|
+
implicitTag: true
|
|
2466
|
+
})),
|
|
2467
|
+
...explicitTags.map((tag) => ({
|
|
2468
|
+
tag,
|
|
2469
|
+
implicitTag: false
|
|
2470
|
+
})),
|
|
2471
|
+
...defaultTagsLast.map((tag) => ({
|
|
2472
|
+
tag,
|
|
2473
|
+
implicitTag: true
|
|
2474
|
+
}))
|
|
2475
|
+
];
|
|
2476
|
+
}
|
|
2477
|
+
function matchTag(state, object) {
|
|
2478
|
+
for (let index = 0, length = state.representTypes.length; index < length; index += 1) {
|
|
2479
|
+
const { tag, implicitTag } = state.representTypes[index];
|
|
2480
|
+
if (tag.identify && tag.identify(object)) {
|
|
2481
|
+
let tagName;
|
|
2482
|
+
if (tag.matchByTagPrefix && tag.representTagName) tagName = tag.representTagName(object);
|
|
2483
|
+
else tagName = tag.tagName;
|
|
2484
|
+
return {
|
|
2485
|
+
tag,
|
|
2486
|
+
tagName,
|
|
2487
|
+
implicitTag
|
|
2488
|
+
};
|
|
2489
|
+
}
|
|
2490
|
+
}
|
|
2491
|
+
return null;
|
|
2492
|
+
}
|
|
2493
|
+
function build(state, object) {
|
|
2494
|
+
if (!state.noRefs && object !== null && typeof object === "object") {
|
|
2495
|
+
const existing = state.refs.get(object);
|
|
2496
|
+
if (existing) {
|
|
2497
|
+
if (existing.anchor === void 0) existing.anchor = `ref_${state.refCounter++}`;
|
|
2498
|
+
return {
|
|
2499
|
+
kind: "alias",
|
|
2500
|
+
tag: "",
|
|
2501
|
+
style: new Style(),
|
|
2502
|
+
anchor: existing.anchor
|
|
2503
|
+
};
|
|
2504
|
+
}
|
|
2505
|
+
}
|
|
2506
|
+
const matched = matchTag(state, object);
|
|
2507
|
+
if (!matched) {
|
|
2508
|
+
if (object === void 0) return INVALID;
|
|
2509
|
+
if (state.skipInvalid) return INVALID;
|
|
2510
|
+
throw new YAMLException(`unacceptable kind of an object to dump ${Object.prototype.toString.call(object)}`);
|
|
2511
|
+
}
|
|
2512
|
+
const { tag, tagName, implicitTag } = matched;
|
|
2513
|
+
const nodeTagName = implicitTag ? tagName : tagNameShort(tagName);
|
|
2514
|
+
if (tag.nodeKind === "scalar") {
|
|
2515
|
+
const style = new Style();
|
|
2516
|
+
style.tagged = !implicitTag;
|
|
2517
|
+
return {
|
|
2518
|
+
kind: "scalar",
|
|
2519
|
+
tag: nodeTagName,
|
|
2520
|
+
style,
|
|
2521
|
+
value: tag.represent(object)
|
|
2522
|
+
};
|
|
2523
|
+
}
|
|
2524
|
+
if (tag.nodeKind === "sequence") {
|
|
2525
|
+
const container = tag.represent(object);
|
|
2526
|
+
const style = new Style();
|
|
2527
|
+
style.tagged = !implicitTag;
|
|
2528
|
+
const node = {
|
|
2529
|
+
kind: "sequence",
|
|
2530
|
+
tag: nodeTagName,
|
|
2531
|
+
style,
|
|
2532
|
+
items: []
|
|
2533
|
+
};
|
|
2534
|
+
if (!state.noRefs) state.refs.set(object, node);
|
|
2535
|
+
for (let index = 0, length = container.length; index < length; index += 1) {
|
|
2536
|
+
let item = build(state, container[index]);
|
|
2537
|
+
if (item === INVALID && container[index] === void 0) item = build(state, null);
|
|
2538
|
+
if (item === INVALID) continue;
|
|
2539
|
+
node.items.push(item);
|
|
2540
|
+
}
|
|
2541
|
+
return node;
|
|
2542
|
+
}
|
|
2543
|
+
const map = tag.represent(object);
|
|
2544
|
+
const style = new Style();
|
|
2545
|
+
style.tagged = !implicitTag;
|
|
2546
|
+
const node = {
|
|
2547
|
+
kind: "mapping",
|
|
2548
|
+
tag: nodeTagName,
|
|
2549
|
+
style,
|
|
2550
|
+
items: []
|
|
2551
|
+
};
|
|
2552
|
+
if (!state.noRefs) state.refs.set(object, node);
|
|
2553
|
+
for (const [objectKey, objectValue] of map) {
|
|
2554
|
+
const key = build(state, objectKey);
|
|
2555
|
+
if (key === INVALID) continue;
|
|
2556
|
+
const value = build(state, objectValue);
|
|
2557
|
+
if (value === INVALID) continue;
|
|
2558
|
+
node.items.push({
|
|
2559
|
+
key,
|
|
2560
|
+
value
|
|
2561
|
+
});
|
|
2562
|
+
}
|
|
2563
|
+
return node;
|
|
2564
|
+
}
|
|
2565
|
+
function jsToAst(input, schema, options = {}) {
|
|
2566
|
+
const root = build({
|
|
2567
|
+
representTypes: buildRepresentTypes(schema),
|
|
2568
|
+
noRefs: options.noRefs ?? false,
|
|
2569
|
+
skipInvalid: options.skipInvalid ?? false,
|
|
2570
|
+
refs: /* @__PURE__ */ new Map(),
|
|
2571
|
+
refCounter: 0
|
|
2572
|
+
}, input);
|
|
2573
|
+
return [{
|
|
2574
|
+
contents: root === INVALID ? null : root,
|
|
2575
|
+
directives: []
|
|
2576
|
+
}];
|
|
2577
|
+
}
|
|
2578
|
+
//#endregion
|
|
2579
|
+
//#region src/ast/visit.ts
|
|
2580
|
+
var VISIT_BREAK = Symbol("visit:break");
|
|
2581
|
+
var VISIT_SKIP = Symbol("visit:skip");
|
|
2582
|
+
function visitNode(node, visitor, ctx) {
|
|
2583
|
+
const control = visitor(node, ctx);
|
|
2584
|
+
if (control === VISIT_BREAK) return true;
|
|
2585
|
+
if (control === VISIT_SKIP) return false;
|
|
2586
|
+
const depth = ctx.depth + 1;
|
|
2587
|
+
switch (node.kind) {
|
|
2588
|
+
case "sequence":
|
|
2589
|
+
for (const item of node.items) if (visitNode(item, visitor, {
|
|
2590
|
+
depth,
|
|
2591
|
+
parent: node,
|
|
2592
|
+
isKey: false
|
|
2593
|
+
})) return true;
|
|
2594
|
+
break;
|
|
2595
|
+
case "mapping":
|
|
2596
|
+
for (const { key, value } of node.items) {
|
|
2597
|
+
if (visitNode(key, visitor, {
|
|
2598
|
+
depth,
|
|
2599
|
+
parent: node,
|
|
2600
|
+
isKey: true
|
|
2601
|
+
})) return true;
|
|
2602
|
+
if (visitNode(value, visitor, {
|
|
2603
|
+
depth,
|
|
2604
|
+
parent: node,
|
|
2605
|
+
isKey: false
|
|
2606
|
+
})) return true;
|
|
2607
|
+
}
|
|
2608
|
+
break;
|
|
2609
|
+
}
|
|
2610
|
+
return false;
|
|
2611
|
+
}
|
|
2612
|
+
function visit(documents, visitor) {
|
|
2613
|
+
for (const doc of documents) if (doc.contents && visitNode(doc.contents, visitor, {
|
|
2614
|
+
depth: 0,
|
|
2615
|
+
parent: null,
|
|
2616
|
+
isKey: false
|
|
2617
|
+
})) return;
|
|
2618
|
+
}
|
|
2619
|
+
//#endregion
|
|
2620
|
+
//#region src/ast/presenter.ts
|
|
2621
|
+
var CHAR_BOM = 65279;
|
|
2622
|
+
var CHAR_TAB = 9;
|
|
2623
|
+
var CHAR_LINE_FEED = 10;
|
|
2624
|
+
var CHAR_CARRIAGE_RETURN = 13;
|
|
2625
|
+
var CHAR_SPACE = 32;
|
|
2626
|
+
var CHAR_EXCLAMATION = 33;
|
|
2627
|
+
var CHAR_DOUBLE_QUOTE = 34;
|
|
2628
|
+
var CHAR_SHARP = 35;
|
|
2629
|
+
var CHAR_PERCENT = 37;
|
|
2630
|
+
var CHAR_AMPERSAND = 38;
|
|
2631
|
+
var CHAR_SINGLE_QUOTE = 39;
|
|
2632
|
+
var CHAR_ASTERISK = 42;
|
|
2633
|
+
var CHAR_COMMA = 44;
|
|
2634
|
+
var CHAR_MINUS = 45;
|
|
2635
|
+
var CHAR_COLON = 58;
|
|
2636
|
+
var CHAR_EQUALS = 61;
|
|
2637
|
+
var CHAR_GREATER_THAN = 62;
|
|
2638
|
+
var CHAR_QUESTION = 63;
|
|
2639
|
+
var CHAR_COMMERCIAL_AT = 64;
|
|
2640
|
+
var CHAR_LEFT_SQUARE_BRACKET = 91;
|
|
2641
|
+
var CHAR_RIGHT_SQUARE_BRACKET = 93;
|
|
2642
|
+
var CHAR_GRAVE_ACCENT = 96;
|
|
2643
|
+
var CHAR_LEFT_CURLY_BRACKET = 123;
|
|
2644
|
+
var CHAR_VERTICAL_LINE = 124;
|
|
2645
|
+
var CHAR_RIGHT_CURLY_BRACKET = 125;
|
|
2646
|
+
var ESCAPE_SEQUENCES = {};
|
|
2647
|
+
ESCAPE_SEQUENCES[0] = "\\0";
|
|
2648
|
+
ESCAPE_SEQUENCES[7] = "\\a";
|
|
2649
|
+
ESCAPE_SEQUENCES[8] = "\\b";
|
|
2650
|
+
ESCAPE_SEQUENCES[9] = "\\t";
|
|
2651
|
+
ESCAPE_SEQUENCES[10] = "\\n";
|
|
2652
|
+
ESCAPE_SEQUENCES[11] = "\\v";
|
|
2653
|
+
ESCAPE_SEQUENCES[12] = "\\f";
|
|
2654
|
+
ESCAPE_SEQUENCES[13] = "\\r";
|
|
2655
|
+
ESCAPE_SEQUENCES[27] = "\\e";
|
|
2656
|
+
ESCAPE_SEQUENCES[34] = "\\\"";
|
|
2657
|
+
ESCAPE_SEQUENCES[92] = "\\\\";
|
|
2658
|
+
ESCAPE_SEQUENCES[133] = "\\N";
|
|
2659
|
+
ESCAPE_SEQUENCES[160] = "\\_";
|
|
2660
|
+
ESCAPE_SEQUENCES[8232] = "\\L";
|
|
2661
|
+
ESCAPE_SEQUENCES[8233] = "\\P";
|
|
2662
|
+
var DEFAULT_PRESENTER_OPTIONS = {
|
|
2663
|
+
indent: 2,
|
|
2664
|
+
seqNoIndent: false,
|
|
2665
|
+
seqInlineFirst: true,
|
|
2666
|
+
sortKeys: false,
|
|
2667
|
+
lineWidth: 80,
|
|
2668
|
+
flowBracketPadding: false,
|
|
2669
|
+
flowSkipCommaSpace: false,
|
|
2670
|
+
flowSkipColonSpace: false,
|
|
2671
|
+
quoteFlowKeys: false,
|
|
2672
|
+
quoteStyle: "auto",
|
|
2673
|
+
tagBeforeAnchor: false
|
|
2674
|
+
};
|
|
2675
|
+
function nodeTagShort(node) {
|
|
2676
|
+
return node.style.tagged ? node.tag : tagNameShort(node.tag);
|
|
2677
|
+
}
|
|
2678
|
+
function createPresenterState(options) {
|
|
2679
|
+
const opts = {
|
|
2680
|
+
...DEFAULT_PRESENTER_OPTIONS,
|
|
2681
|
+
...options
|
|
2682
|
+
};
|
|
2683
|
+
return {
|
|
2684
|
+
...opts,
|
|
2685
|
+
defaultScalarTagName: opts.schema.defaultScalarTag.tagName,
|
|
2686
|
+
implicitResolvers: opts.schema.implicitScalarTags
|
|
2687
|
+
};
|
|
2688
|
+
}
|
|
2689
|
+
function encodeNonPrintable(character) {
|
|
2690
|
+
const string = character.toString(16).toUpperCase();
|
|
2691
|
+
const handle = character <= 255 ? "x" : "u";
|
|
2692
|
+
const length = character <= 255 ? 2 : 4;
|
|
2693
|
+
return `\\${handle}${"0".repeat(length - string.length)}${string}`;
|
|
2694
|
+
}
|
|
2695
|
+
function indentString(string, spaces) {
|
|
2696
|
+
const ind = " ".repeat(spaces);
|
|
2697
|
+
let position = 0;
|
|
2698
|
+
let result = "";
|
|
2699
|
+
const length = string.length;
|
|
2700
|
+
while (position < length) {
|
|
2701
|
+
let line;
|
|
2702
|
+
const next = string.indexOf("\n", position);
|
|
2703
|
+
if (next === -1) {
|
|
2704
|
+
line = string.slice(position);
|
|
2705
|
+
position = length;
|
|
2706
|
+
} else {
|
|
2707
|
+
line = string.slice(position, next + 1);
|
|
2708
|
+
position = next + 1;
|
|
2709
|
+
}
|
|
2710
|
+
if (line.length && line !== "\n") result += ind;
|
|
2711
|
+
result += line;
|
|
2712
|
+
}
|
|
2713
|
+
return result;
|
|
2714
|
+
}
|
|
2715
|
+
function generateNextLine(state, level) {
|
|
2716
|
+
return `\n${" ".repeat(state.indent * level)}`;
|
|
2717
|
+
}
|
|
2718
|
+
function scalarLayout(state, level) {
|
|
2719
|
+
const indent = state.indent * Math.max(1, level);
|
|
2720
|
+
return {
|
|
2721
|
+
indent,
|
|
2722
|
+
blockIndent: level === 0 ? state.indent + 1 : state.indent,
|
|
2723
|
+
lineWidth: state.lineWidth === -1 ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent)
|
|
2724
|
+
};
|
|
2725
|
+
}
|
|
2726
|
+
function resolveImplicitTag(state, str) {
|
|
2727
|
+
for (let index = 0, length = state.implicitResolvers.length; index < length; index += 1) {
|
|
2728
|
+
const tagDefinition = state.implicitResolvers[index];
|
|
2729
|
+
if (tagDefinition.resolve(str, false, tagDefinition.tagName) !== NOT_RESOLVED) return tagDefinition.tagName;
|
|
2730
|
+
}
|
|
2731
|
+
return state.defaultScalarTagName;
|
|
2732
|
+
}
|
|
2733
|
+
function isWhitespace(c) {
|
|
2734
|
+
return c === CHAR_SPACE || c === CHAR_TAB;
|
|
2735
|
+
}
|
|
2736
|
+
function startsWithDocumentSeparator(string) {
|
|
2737
|
+
const marker = string.charCodeAt(0);
|
|
2738
|
+
if (marker !== CHAR_MINUS && marker !== 46 || string.charCodeAt(1) !== marker || string.charCodeAt(2) !== marker) return false;
|
|
2739
|
+
if (string.length === 3) return true;
|
|
2740
|
+
const following = string.charCodeAt(3);
|
|
2741
|
+
return isWhitespace(following) || following === CHAR_CARRIAGE_RETURN || following === CHAR_LINE_FEED;
|
|
2742
|
+
}
|
|
2743
|
+
function isPrintable(c) {
|
|
2744
|
+
return c >= 32 && c <= 126 || c >= 161 && c <= 55295 && c !== 8232 && c !== 8233 || c >= 57344 && c <= 65533 && c !== CHAR_BOM || c >= 65536 && c <= 1114111;
|
|
2745
|
+
}
|
|
2746
|
+
function isNsCharOrWhitespace(c) {
|
|
2747
|
+
return isPrintable(c) && c !== CHAR_BOM && c !== CHAR_CARRIAGE_RETURN && c !== CHAR_LINE_FEED;
|
|
2748
|
+
}
|
|
2749
|
+
function isPlainSafe(c, prev, inblock) {
|
|
2750
|
+
const cIsNsCharOrWhitespace = isNsCharOrWhitespace(c);
|
|
2751
|
+
const cIsNsChar = cIsNsCharOrWhitespace && !isWhitespace(c);
|
|
2752
|
+
return (inblock ? cIsNsCharOrWhitespace : cIsNsCharOrWhitespace && c !== CHAR_COMMA && c !== CHAR_LEFT_SQUARE_BRACKET && c !== CHAR_RIGHT_SQUARE_BRACKET && c !== CHAR_LEFT_CURLY_BRACKET && c !== CHAR_RIGHT_CURLY_BRACKET) && c !== CHAR_SHARP && !(prev === CHAR_COLON && !cIsNsChar) || isNsCharOrWhitespace(prev) && !isWhitespace(prev) && c === CHAR_SHARP || prev === CHAR_COLON && cIsNsChar;
|
|
2753
|
+
}
|
|
2754
|
+
function isPlainSafeFirst(c) {
|
|
2755
|
+
return isPrintable(c) && c !== CHAR_BOM && !isWhitespace(c) && c !== CHAR_MINUS && c !== CHAR_QUESTION && c !== CHAR_COLON && c !== CHAR_COMMA && c !== CHAR_LEFT_SQUARE_BRACKET && c !== CHAR_RIGHT_SQUARE_BRACKET && c !== CHAR_LEFT_CURLY_BRACKET && c !== CHAR_RIGHT_CURLY_BRACKET && c !== CHAR_SHARP && c !== CHAR_AMPERSAND && c !== CHAR_ASTERISK && c !== CHAR_EXCLAMATION && c !== CHAR_VERTICAL_LINE && c !== CHAR_EQUALS && c !== CHAR_GREATER_THAN && c !== CHAR_SINGLE_QUOTE && c !== CHAR_DOUBLE_QUOTE && c !== CHAR_PERCENT && c !== CHAR_COMMERCIAL_AT && c !== CHAR_GRAVE_ACCENT;
|
|
2756
|
+
}
|
|
2757
|
+
function isPlainSafeAtStart(string, inblock) {
|
|
2758
|
+
const first = codePointAt(string, 0);
|
|
2759
|
+
if (isPlainSafeFirst(first)) return true;
|
|
2760
|
+
if (string.length > 1 && (first === CHAR_MINUS || first === CHAR_QUESTION || first === CHAR_COLON)) {
|
|
2761
|
+
const second = codePointAt(string, 1);
|
|
2762
|
+
return !isWhitespace(second) && isPlainSafe(second, first, inblock);
|
|
2763
|
+
}
|
|
2764
|
+
return false;
|
|
2765
|
+
}
|
|
2766
|
+
function isPlainSafeLast(c) {
|
|
2767
|
+
return !isWhitespace(c) && c !== CHAR_COLON;
|
|
2768
|
+
}
|
|
2769
|
+
function codePointAt(string, pos) {
|
|
2770
|
+
const first = string.charCodeAt(pos);
|
|
2771
|
+
let second;
|
|
2772
|
+
if (first >= 55296 && first <= 56319 && pos + 1 < string.length) {
|
|
2773
|
+
second = string.charCodeAt(pos + 1);
|
|
2774
|
+
if (second >= 56320 && second <= 57343) return (first - 55296) * 1024 + second - 56320 + 65536;
|
|
2775
|
+
}
|
|
2776
|
+
return first;
|
|
2777
|
+
}
|
|
2778
|
+
function needIndentIndicator(string) {
|
|
2779
|
+
return /^\n* /.test(string);
|
|
2780
|
+
}
|
|
2781
|
+
var STYLE_PLAIN = 1;
|
|
2782
|
+
var STYLE_SINGLE = 2;
|
|
2783
|
+
var STYLE_LITERAL = 3;
|
|
2784
|
+
var STYLE_FOLDED = 4;
|
|
2785
|
+
var STYLE_DOUBLE = 5;
|
|
2786
|
+
function chooseScalarStyle(state, string, layout, singleLineOnly, inblock) {
|
|
2787
|
+
const { blockIndent, lineWidth } = layout;
|
|
2788
|
+
const forceQuote = state.quoteStyle !== "auto";
|
|
2789
|
+
let i;
|
|
2790
|
+
let char = 0;
|
|
2791
|
+
let prevChar = -1;
|
|
2792
|
+
let hasLineBreak = false;
|
|
2793
|
+
let hasFoldableLine = false;
|
|
2794
|
+
const shouldTrackWidth = lineWidth !== -1;
|
|
2795
|
+
let previousLineBreak = -1;
|
|
2796
|
+
let plain = !startsWithDocumentSeparator(string) && isPlainSafeAtStart(string, inblock) && isPlainSafeLast(codePointAt(string, string.length - 1));
|
|
2797
|
+
if (singleLineOnly || forceQuote) for (i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
|
|
2798
|
+
char = codePointAt(string, i);
|
|
2799
|
+
if (!isPrintable(char)) return STYLE_DOUBLE;
|
|
2800
|
+
plain = plain && isPlainSafe(char, prevChar, inblock);
|
|
2801
|
+
prevChar = char;
|
|
2802
|
+
}
|
|
2803
|
+
else {
|
|
2804
|
+
for (i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
|
|
2805
|
+
char = codePointAt(string, i);
|
|
2806
|
+
if (char === CHAR_LINE_FEED) {
|
|
2807
|
+
hasLineBreak = true;
|
|
2808
|
+
if (shouldTrackWidth) {
|
|
2809
|
+
hasFoldableLine = hasFoldableLine || i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ";
|
|
2810
|
+
previousLineBreak = i;
|
|
2811
|
+
}
|
|
2812
|
+
} else if (!isPrintable(char)) return STYLE_DOUBLE;
|
|
2813
|
+
plain = plain && isPlainSafe(char, prevChar, inblock);
|
|
2814
|
+
prevChar = char;
|
|
2815
|
+
}
|
|
2816
|
+
hasFoldableLine = hasFoldableLine || shouldTrackWidth && i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ";
|
|
2817
|
+
}
|
|
2818
|
+
if (!hasLineBreak && !hasFoldableLine) {
|
|
2819
|
+
if (plain && !forceQuote) return STYLE_PLAIN;
|
|
2820
|
+
return state.quoteStyle === "double" ? STYLE_DOUBLE : STYLE_SINGLE;
|
|
2821
|
+
}
|
|
2822
|
+
if (blockIndent > 9 && needIndentIndicator(string)) return STYLE_DOUBLE;
|
|
2823
|
+
return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL;
|
|
2824
|
+
}
|
|
2825
|
+
function renderScalarStyle(string, style, layout) {
|
|
2826
|
+
const { indent, blockIndent, lineWidth } = layout;
|
|
2827
|
+
switch (style) {
|
|
2828
|
+
case STYLE_PLAIN: return encodeFlowBreaks(string, indent);
|
|
2829
|
+
case STYLE_SINGLE: return `'${encodeFlowBreaks(string, indent).replace(/'/g, "''")}'`;
|
|
2830
|
+
case STYLE_LITERAL: return "|" + blockHeader(string, blockIndent) + dropEndingNewline(indentString(string, indent));
|
|
2831
|
+
case STYLE_FOLDED: return ">" + blockHeader(string, blockIndent) + dropEndingNewline(indentString(foldBlockScalar(string, lineWidth), indent));
|
|
2832
|
+
case STYLE_DOUBLE: return `"${escapeString(string)}"`;
|
|
2833
|
+
}
|
|
2834
|
+
}
|
|
2835
|
+
function resolveScalarStyle(state, node, layout, iskey, inblock) {
|
|
2836
|
+
const singleLineOnly = iskey || !inblock;
|
|
2837
|
+
if (node.style.singleQuoted) return STYLE_SINGLE;
|
|
2838
|
+
if (node.style.doubleQuoted) return STYLE_DOUBLE;
|
|
2839
|
+
if (!singleLineOnly) {
|
|
2840
|
+
if (node.style.literal) return STYLE_LITERAL;
|
|
2841
|
+
if (node.style.folded) return STYLE_FOLDED;
|
|
2842
|
+
}
|
|
2843
|
+
const string = node.value;
|
|
2844
|
+
if (string.length === 0) {
|
|
2845
|
+
if (state.quoteStyle === "auto" && (node.style.tagged || resolveImplicitTag(state, string) === node.tag)) return STYLE_PLAIN;
|
|
2846
|
+
return state.quoteStyle === "double" ? STYLE_DOUBLE : STYLE_SINGLE;
|
|
2847
|
+
}
|
|
2848
|
+
const style = chooseScalarStyle(state, string, layout, singleLineOnly, inblock);
|
|
2849
|
+
if (style === STYLE_PLAIN && !node.style.tagged && resolveImplicitTag(state, string) !== node.tag) return STYLE_SINGLE;
|
|
2850
|
+
return style;
|
|
2851
|
+
}
|
|
2852
|
+
function blockHeader(string, indentPerLevel) {
|
|
2853
|
+
const indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) : "";
|
|
2854
|
+
const clip = string[string.length - 1] === "\n";
|
|
2855
|
+
return `${indentIndicator}${clip && (string[string.length - 2] === "\n" || string === "\n") ? "+" : clip ? "" : "-"}\n`;
|
|
2856
|
+
}
|
|
2857
|
+
function encodeFlowBreaks(string, indent) {
|
|
2858
|
+
let nextLF = string.indexOf("\n");
|
|
2859
|
+
if (nextLF === -1) return string;
|
|
2860
|
+
const pad = " ".repeat(indent);
|
|
2861
|
+
let result = string.slice(0, nextLF);
|
|
2862
|
+
const lineRe = /(\n+)([^\n]*)/g;
|
|
2863
|
+
lineRe.lastIndex = nextLF;
|
|
2864
|
+
let match;
|
|
2865
|
+
while (match = lineRe.exec(string)) {
|
|
2866
|
+
const breaks = match[1].length;
|
|
2867
|
+
const line = match[2];
|
|
2868
|
+
result += "\n".repeat(breaks + 1) + pad + line;
|
|
2869
|
+
}
|
|
2870
|
+
return result;
|
|
2871
|
+
}
|
|
2872
|
+
function dropEndingNewline(string) {
|
|
2873
|
+
return string[string.length - 1] === "\n" ? string.slice(0, -1) : string;
|
|
2874
|
+
}
|
|
2875
|
+
function foldBlockScalar(string, width) {
|
|
2876
|
+
const lineRe = /(\n+)([^\n]*)/g;
|
|
2877
|
+
let nextLF = string.indexOf("\n");
|
|
2878
|
+
if (nextLF === -1) nextLF = string.length;
|
|
2879
|
+
lineRe.lastIndex = nextLF;
|
|
2880
|
+
let result = foldLine(string.slice(0, nextLF), width);
|
|
2881
|
+
let prevMoreIndented = string[0] === "\n" || string[0] === " ";
|
|
2882
|
+
let moreIndented;
|
|
2883
|
+
let match;
|
|
2884
|
+
while (match = lineRe.exec(string)) {
|
|
2885
|
+
const prefix = match[1];
|
|
2886
|
+
const line = match[2];
|
|
2887
|
+
moreIndented = line[0] === " ";
|
|
2888
|
+
result += prefix + (!prevMoreIndented && !moreIndented && line !== "" ? "\n" : "") + foldLine(line, width);
|
|
2889
|
+
prevMoreIndented = moreIndented;
|
|
2890
|
+
}
|
|
2891
|
+
return result;
|
|
2892
|
+
}
|
|
2893
|
+
function foldLine(line, width) {
|
|
2894
|
+
if (line === "" || line[0] === " ") return line;
|
|
2895
|
+
const breakRe = / [^ ]/g;
|
|
2896
|
+
let match;
|
|
2897
|
+
let start = 0;
|
|
2898
|
+
let end;
|
|
2899
|
+
let curr = 0;
|
|
2900
|
+
let next = 0;
|
|
2901
|
+
let result = "";
|
|
2902
|
+
while (match = breakRe.exec(line)) {
|
|
2903
|
+
next = match.index;
|
|
2904
|
+
if (next - start > width) {
|
|
2905
|
+
end = curr > start ? curr : next;
|
|
2906
|
+
result += `\n${line.slice(start, end)}`;
|
|
2907
|
+
start = end + 1;
|
|
2908
|
+
}
|
|
2909
|
+
curr = next;
|
|
2910
|
+
}
|
|
2911
|
+
result += "\n";
|
|
2912
|
+
if (line.length - start > width && curr > start) result += `${line.slice(start, curr)}\n${line.slice(curr + 1)}`;
|
|
2913
|
+
else result += line.slice(start);
|
|
2914
|
+
return result.slice(1);
|
|
2915
|
+
}
|
|
2916
|
+
function escapeString(string) {
|
|
2917
|
+
let result = "";
|
|
2918
|
+
let char = 0;
|
|
2919
|
+
for (let i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
|
|
2920
|
+
char = codePointAt(string, i);
|
|
2921
|
+
const escapeSeq = ESCAPE_SEQUENCES[char];
|
|
2922
|
+
if (escapeSeq) {
|
|
2923
|
+
result += escapeSeq;
|
|
2924
|
+
continue;
|
|
2925
|
+
}
|
|
2926
|
+
if (isPrintable(char)) {
|
|
2927
|
+
result += string[i];
|
|
2928
|
+
if (char >= 65536) result += string[i + 1];
|
|
2929
|
+
continue;
|
|
2930
|
+
}
|
|
2931
|
+
result += encodeNonPrintable(char);
|
|
2932
|
+
}
|
|
2933
|
+
return result;
|
|
2934
|
+
}
|
|
2935
|
+
function writeFlowSequence(state, level, node) {
|
|
2936
|
+
let result = "";
|
|
2937
|
+
for (let index = 0, length = node.items.length; index < length; index += 1) {
|
|
2938
|
+
const item = writeNode(state, level, node.items[index], {});
|
|
2939
|
+
if (result !== "") result += `,${!state.flowSkipCommaSpace ? " " : ""}`;
|
|
2940
|
+
result += item;
|
|
2941
|
+
}
|
|
2942
|
+
const pad = state.flowBracketPadding && result !== "" ? " " : "";
|
|
2943
|
+
return `[${pad}${result}${pad}]`;
|
|
2944
|
+
}
|
|
2945
|
+
function writeBlockSequence(state, level, node, compact) {
|
|
2946
|
+
let result = "";
|
|
2947
|
+
for (let index = 0, length = node.items.length; index < length; index += 1) {
|
|
2948
|
+
const item = writeNode(state, level + 1, node.items[index], {
|
|
2949
|
+
block: true,
|
|
2950
|
+
compact: state.seqInlineFirst,
|
|
2951
|
+
isblockseq: true
|
|
2952
|
+
});
|
|
2953
|
+
if (!compact || result !== "") result += generateNextLine(state, level);
|
|
2954
|
+
if (item === "" || CHAR_LINE_FEED === item.charCodeAt(0)) result += "-";
|
|
2955
|
+
else result += "- ";
|
|
2956
|
+
result += item;
|
|
2957
|
+
}
|
|
2958
|
+
return result;
|
|
2959
|
+
}
|
|
2960
|
+
function writeFlowMapping(state, level, node) {
|
|
2961
|
+
let result = "";
|
|
2962
|
+
const items = sortMappingItems(state, node.items);
|
|
2963
|
+
for (const { key, value } of items) {
|
|
2964
|
+
let pairBuffer = "";
|
|
2965
|
+
if (result !== "") pairBuffer += `,${!state.flowSkipCommaSpace ? " " : ""}`;
|
|
2966
|
+
const keyText = writeNode(state, level, key, {});
|
|
2967
|
+
const explicitPair = keyText.length > 1024;
|
|
2968
|
+
if (explicitPair) pairBuffer += "? ";
|
|
2969
|
+
else if (state.quoteFlowKeys) pairBuffer += "\"";
|
|
2970
|
+
const valueText = writeNode(state, level, value, {});
|
|
2971
|
+
const sep = state.flowSkipColonSpace || valueText === "" ? "" : " ";
|
|
2972
|
+
pairBuffer += `${keyText}${state.quoteFlowKeys && !explicitPair ? "\"" : ""}:${sep}${valueText}`;
|
|
2973
|
+
result += pairBuffer;
|
|
2974
|
+
}
|
|
2975
|
+
const pad = state.flowBracketPadding && result !== "" ? " " : "";
|
|
2976
|
+
return `{${pad}${result}${pad}}`;
|
|
2977
|
+
}
|
|
2978
|
+
function sortKeyValue(key) {
|
|
2979
|
+
return key.kind === "scalar" ? key.value : key;
|
|
2980
|
+
}
|
|
2981
|
+
function sortMappingItems(state, items) {
|
|
2982
|
+
if (!state.sortKeys) return items;
|
|
2983
|
+
const copy = items.slice();
|
|
2984
|
+
if (state.sortKeys === true) copy.sort((a, b) => {
|
|
2985
|
+
const x = sortKeyValue(a.key);
|
|
2986
|
+
const y = sortKeyValue(b.key);
|
|
2987
|
+
if (x < y) return -1;
|
|
2988
|
+
if (x > y) return 1;
|
|
2989
|
+
return 0;
|
|
2990
|
+
});
|
|
2991
|
+
else {
|
|
2992
|
+
const fn = state.sortKeys;
|
|
2993
|
+
copy.sort((a, b) => fn(sortKeyValue(a.key), sortKeyValue(b.key)));
|
|
2994
|
+
}
|
|
2995
|
+
return copy;
|
|
2996
|
+
}
|
|
2997
|
+
function writeBlockMapping(state, level, node, compact) {
|
|
2998
|
+
let result = "";
|
|
2999
|
+
const items = sortMappingItems(state, node.items);
|
|
3000
|
+
for (let index = 0, length = items.length; index < length; index += 1) {
|
|
3001
|
+
let pairBuffer = "";
|
|
3002
|
+
if (!compact || result !== "") pairBuffer += generateNextLine(state, level);
|
|
3003
|
+
const { key, value } = items[index];
|
|
3004
|
+
const keyIsBlock = (key.kind === "mapping" || key.kind === "sequence") && !key.style.flow && key.items.length !== 0 || key.kind === "scalar" && (key.style.literal || key.style.folded);
|
|
3005
|
+
const keyText = keyIsBlock ? writeNode(state, level + 1, key, {
|
|
3006
|
+
block: true,
|
|
3007
|
+
compact: true,
|
|
3008
|
+
isblockseq: !cannotBeCompact(state, key, level + 1)
|
|
3009
|
+
}) : writeNode(state, level + 1, key, {
|
|
3010
|
+
block: true,
|
|
3011
|
+
compact: true,
|
|
3012
|
+
iskey: true
|
|
3013
|
+
});
|
|
3014
|
+
const keyHasLineBreak = key.kind === "scalar" && key.value.indexOf("\n") !== -1;
|
|
3015
|
+
const explicitPair = keyIsBlock || keyHasLineBreak || keyText.length > 1024;
|
|
3016
|
+
if (explicitPair) if (keyText && CHAR_LINE_FEED === keyText.charCodeAt(0)) pairBuffer += "?";
|
|
3017
|
+
else pairBuffer += "? ";
|
|
3018
|
+
pairBuffer += keyText;
|
|
3019
|
+
if (explicitPair) pairBuffer += generateNextLine(state, level);
|
|
3020
|
+
const valueText = writeNode(state, level + 1, value, {
|
|
3021
|
+
block: true,
|
|
3022
|
+
compact: explicitPair,
|
|
3023
|
+
isblockseq: explicitPair && !cannotBeCompact(state, value, level + 1)
|
|
3024
|
+
});
|
|
3025
|
+
const keyIsBareProps = key.kind === "scalar" && key.value === "" && keyText !== "" && keyText.charCodeAt(keyText.length - 1) !== CHAR_SINGLE_QUOTE && keyText.charCodeAt(keyText.length - 1) !== CHAR_DOUBLE_QUOTE;
|
|
3026
|
+
const keyColonSep = !explicitPair && (key.kind === "alias" || keyIsBareProps) ? " " : "";
|
|
3027
|
+
if (valueText === "" || CHAR_LINE_FEED === valueText.charCodeAt(0)) pairBuffer += `${keyColonSep}:`;
|
|
3028
|
+
else pairBuffer += `${keyColonSep}: `;
|
|
3029
|
+
pairBuffer += valueText;
|
|
3030
|
+
result += pairBuffer;
|
|
3031
|
+
}
|
|
3032
|
+
return result;
|
|
3033
|
+
}
|
|
3034
|
+
function cannotBeCompact(state, node, level) {
|
|
3035
|
+
return node.style.tagged || node.anchor !== void 0 || state.indent < 2 && level > 0;
|
|
3036
|
+
}
|
|
3037
|
+
function writeNode(state, level, node, ctx) {
|
|
3038
|
+
if (node.kind === "alias") return `*${node.anchor}`;
|
|
3039
|
+
const { block = false, iskey = false, isblockseq = false } = ctx;
|
|
3040
|
+
let compact = ctx.compact ?? false;
|
|
3041
|
+
const hasAnchor = node.anchor !== void 0;
|
|
3042
|
+
if (cannotBeCompact(state, node, level)) compact = false;
|
|
3043
|
+
let body;
|
|
3044
|
+
let shouldPrintTag = node.style.tagged;
|
|
3045
|
+
const useBlockCollection = block && (node.kind === "mapping" || node.kind === "sequence") && !node.style.flow && node.items.length !== 0;
|
|
3046
|
+
if (node.kind === "mapping") if (useBlockCollection) body = writeBlockMapping(state, level, node, compact);
|
|
3047
|
+
else body = writeFlowMapping(state, level, node);
|
|
3048
|
+
else if (node.kind === "sequence") if (useBlockCollection) if (state.seqNoIndent && !isblockseq && level > 0) body = writeBlockSequence(state, level - 1, node, compact);
|
|
3049
|
+
else body = writeBlockSequence(state, level, node, compact);
|
|
3050
|
+
else body = writeFlowSequence(state, level, node);
|
|
3051
|
+
else {
|
|
3052
|
+
const layout = scalarLayout(state, level);
|
|
3053
|
+
const style = resolveScalarStyle(state, node, layout, iskey, block);
|
|
3054
|
+
body = renderScalarStyle(node.value, style, layout);
|
|
3055
|
+
shouldPrintTag = node.style.tagged || style !== STYLE_PLAIN && node.tag !== state.defaultScalarTagName;
|
|
3056
|
+
}
|
|
3057
|
+
if (useBlockCollection && compact && level > 0 && state.indent > 2) body = `${" ".repeat(state.indent - 2)}${body}`;
|
|
3058
|
+
if (shouldPrintTag || hasAnchor) {
|
|
3059
|
+
const props = [];
|
|
3060
|
+
const tag = shouldPrintTag ? nodeTagShort(node) : null;
|
|
3061
|
+
const anchor = hasAnchor ? `&${node.anchor}` : null;
|
|
3062
|
+
if (state.tagBeforeAnchor) {
|
|
3063
|
+
if (tag !== null) props.push(tag);
|
|
3064
|
+
if (anchor !== null) props.push(anchor);
|
|
3065
|
+
} else {
|
|
3066
|
+
if (anchor !== null) props.push(anchor);
|
|
3067
|
+
if (tag !== null) props.push(tag);
|
|
3068
|
+
}
|
|
3069
|
+
const sep = body === "" || body.charCodeAt(0) === CHAR_LINE_FEED ? "" : " ";
|
|
3070
|
+
body = `${props.join(" ")}${sep}${body}`;
|
|
3071
|
+
}
|
|
3072
|
+
return body;
|
|
3073
|
+
}
|
|
3074
|
+
function rootStartsOwnLine(node) {
|
|
3075
|
+
return (node.kind === "sequence" || node.kind === "mapping") && !node.style.flow && node.items.length !== 0 && !node.style.tagged && node.anchor === void 0;
|
|
3076
|
+
}
|
|
3077
|
+
function isOpenEnded(node) {
|
|
3078
|
+
let leaf = node;
|
|
3079
|
+
while ((leaf.kind === "sequence" || leaf.kind === "mapping") && !leaf.style.flow && leaf.items.length !== 0) leaf = leaf.kind === "sequence" ? leaf.items[leaf.items.length - 1] : leaf.items[leaf.items.length - 1].value;
|
|
3080
|
+
if (leaf.kind !== "scalar" || !(leaf.style.literal || leaf.style.folded)) return false;
|
|
3081
|
+
const { value } = leaf;
|
|
3082
|
+
return value.endsWith("\n\n") || value === "\n";
|
|
3083
|
+
}
|
|
3084
|
+
function writeDocumentDirectives(doc) {
|
|
3085
|
+
let result = "";
|
|
3086
|
+
for (const directive of doc.directives) {
|
|
3087
|
+
if (directive.kind === "yaml") {
|
|
3088
|
+
result += `%YAML ${directive.version}\n`;
|
|
3089
|
+
continue;
|
|
3090
|
+
}
|
|
3091
|
+
const { handle, prefix } = directive;
|
|
3092
|
+
result += `%TAG ${handle} ${prefix}\n`;
|
|
3093
|
+
}
|
|
3094
|
+
return result;
|
|
3095
|
+
}
|
|
3096
|
+
function present(documents, options) {
|
|
3097
|
+
const state = createPresenterState(options);
|
|
3098
|
+
let result = "";
|
|
3099
|
+
let previousEnded = false;
|
|
3100
|
+
for (let index = 0; index < documents.length; index += 1) {
|
|
3101
|
+
const doc = documents[index];
|
|
3102
|
+
const directives = writeDocumentDirectives(doc);
|
|
3103
|
+
const hasDirectives = directives !== "";
|
|
3104
|
+
const marker = doc.explicitStart || hasDirectives || index > 0 && !previousEnded;
|
|
3105
|
+
result += directives;
|
|
3106
|
+
if (doc.contents === null) {
|
|
3107
|
+
if (marker) result += "---\n";
|
|
3108
|
+
} else if (marker) {
|
|
3109
|
+
const body = writeNode(state, 0, doc.contents, {
|
|
3110
|
+
block: true,
|
|
3111
|
+
compact: true
|
|
3112
|
+
});
|
|
3113
|
+
const sep = body === "" ? "" : hasDirectives || rootStartsOwnLine(doc.contents) ? "\n" : " ";
|
|
3114
|
+
result += `---${sep}${body}\n`;
|
|
3115
|
+
} else result += writeNode(state, 0, doc.contents, {
|
|
3116
|
+
block: true,
|
|
3117
|
+
compact: true
|
|
3118
|
+
}) + "\n";
|
|
3119
|
+
previousEnded = doc.explicitEnd || doc.contents !== null && isOpenEnded(doc.contents);
|
|
3120
|
+
if (previousEnded) result += "...\n";
|
|
3121
|
+
}
|
|
3122
|
+
return result;
|
|
3123
|
+
}
|
|
3124
|
+
//#endregion
|
|
3125
|
+
//#region src/dump.ts
|
|
3126
|
+
var DEFAULT_DUMP_SCHEMA = YAML11_SCHEMA.withTags({
|
|
3127
|
+
...intYaml11Tag,
|
|
3128
|
+
resolve: (source, isExplicit, tagName) => {
|
|
3129
|
+
const result = intYaml11Tag.resolve(source, isExplicit, tagName);
|
|
3130
|
+
return result === NOT_RESOLVED ? intCoreTag.resolve(source, isExplicit, tagName) : result;
|
|
3131
|
+
}
|
|
3132
|
+
}, {
|
|
3133
|
+
...floatYaml11Tag,
|
|
3134
|
+
resolve: (source, isExplicit, tagName) => {
|
|
3135
|
+
const result = floatYaml11Tag.resolve(source, isExplicit, tagName);
|
|
3136
|
+
return result === NOT_RESOLVED ? floatCoreTag.resolve(source, isExplicit, tagName) : result;
|
|
3137
|
+
}
|
|
3138
|
+
});
|
|
3139
|
+
var DEFAULT_DUMP_OPTIONS = {
|
|
3140
|
+
...DEFAULT_PRESENTER_OPTIONS,
|
|
3141
|
+
schema: DEFAULT_DUMP_SCHEMA,
|
|
3142
|
+
skipInvalid: false,
|
|
3143
|
+
noRefs: false,
|
|
3144
|
+
flowLevel: -1,
|
|
3145
|
+
transform: () => {}
|
|
3146
|
+
};
|
|
3147
|
+
function dump(input, options = {}) {
|
|
3148
|
+
const opts = {
|
|
3149
|
+
...DEFAULT_DUMP_OPTIONS,
|
|
3150
|
+
...options
|
|
3151
|
+
};
|
|
3152
|
+
const documents = jsToAst(input, opts.schema, {
|
|
3153
|
+
noRefs: opts.noRefs,
|
|
3154
|
+
skipInvalid: opts.skipInvalid
|
|
3155
|
+
});
|
|
3156
|
+
if (opts.flowLevel >= 0) visit(documents, (node, ctx) => {
|
|
3157
|
+
if (ctx.depth < opts.flowLevel) return;
|
|
3158
|
+
node.style.flow = true;
|
|
3159
|
+
return VISIT_SKIP;
|
|
3160
|
+
});
|
|
3161
|
+
opts.transform(documents);
|
|
3162
|
+
return present(documents, {
|
|
3163
|
+
...pick(opts, Object.keys(DEFAULT_PRESENTER_OPTIONS)),
|
|
3164
|
+
schema: opts.schema
|
|
3165
|
+
});
|
|
3166
|
+
}
|
|
3167
|
+
|
|
3168
|
+
function historyFormatFromPath(filePath) {
|
|
3169
|
+
const ext = extname(filePath).toLowerCase();
|
|
3170
|
+
if (ext === '.yaml' || ext === '.yml') {
|
|
3171
|
+
return success('yaml');
|
|
3172
|
+
}
|
|
3173
|
+
return failure(`Unsupported history file extension for ${filePath}; expected .yaml or .yml`);
|
|
3174
|
+
}
|
|
3175
|
+
function setLiteralBlockScalars(node, parentKey) {
|
|
3176
|
+
if (!node) {
|
|
3177
|
+
return;
|
|
3178
|
+
}
|
|
3179
|
+
if (node.kind === 'scalar') {
|
|
3180
|
+
const useLiteralBlock = node.value.includes('\n')
|
|
3181
|
+
&& (parentKey === 'prompt' || parentKey === 'commandResult');
|
|
3182
|
+
if (useLiteralBlock) {
|
|
3183
|
+
node.style = new Style();
|
|
3184
|
+
node.style.literal = true;
|
|
3185
|
+
}
|
|
3186
|
+
return;
|
|
3187
|
+
}
|
|
3188
|
+
if (node.kind === 'sequence') {
|
|
3189
|
+
for (const item of node.items) {
|
|
3190
|
+
setLiteralBlockScalars(item);
|
|
3191
|
+
}
|
|
3192
|
+
return;
|
|
3193
|
+
}
|
|
3194
|
+
if (node.kind === 'mapping') {
|
|
3195
|
+
for (const { key, value } of node.items) {
|
|
3196
|
+
const keyName = key.kind === 'scalar' ? key.value : undefined;
|
|
3197
|
+
setLiteralBlockScalars(value, keyName);
|
|
3198
|
+
}
|
|
3199
|
+
}
|
|
3200
|
+
}
|
|
3201
|
+
function dumpHistoryEntries(entries) {
|
|
3202
|
+
if (entries.length === 0) {
|
|
3203
|
+
return '[]\n';
|
|
3204
|
+
}
|
|
3205
|
+
return dump(entries, {
|
|
3206
|
+
schema: YAML11_SCHEMA,
|
|
3207
|
+
lineWidth: 0,
|
|
3208
|
+
noRefs: true,
|
|
3209
|
+
transform(documents) {
|
|
3210
|
+
for (const doc of documents) {
|
|
3211
|
+
setLiteralBlockScalars(doc.contents);
|
|
3212
|
+
}
|
|
3213
|
+
},
|
|
3214
|
+
});
|
|
3215
|
+
}
|
|
3216
|
+
async function readHistoryFile({ filePath, }) {
|
|
3217
|
+
const formatResult = historyFormatFromPath(filePath);
|
|
3218
|
+
if (!formatResult.success) {
|
|
3219
|
+
return formatResult;
|
|
3220
|
+
}
|
|
3221
|
+
try {
|
|
3222
|
+
const content = await readFile(filePath, 'utf-8');
|
|
3223
|
+
const parsed = load(content, { schema: YAML11_SCHEMA });
|
|
3224
|
+
if (!Array.isArray(parsed)) {
|
|
3225
|
+
return failure(`History file ${filePath} must contain a YAML sequence`);
|
|
3226
|
+
}
|
|
3227
|
+
return success(parsed);
|
|
3228
|
+
}
|
|
3229
|
+
catch (error) {
|
|
3230
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
3231
|
+
return failure(`Failed to parse history file ${filePath}: ${detail}`);
|
|
3232
|
+
}
|
|
3233
|
+
}
|
|
3234
|
+
async function writeHistoryFile({ filePath, entries, }) {
|
|
3235
|
+
const formatResult = historyFormatFromPath(filePath);
|
|
3236
|
+
if (!formatResult.success) {
|
|
3237
|
+
return formatResult;
|
|
3238
|
+
}
|
|
3239
|
+
try {
|
|
3240
|
+
await mkdir(dirname(filePath), { recursive: true });
|
|
3241
|
+
await writeFile(filePath, dumpHistoryEntries(entries), 'utf-8');
|
|
3242
|
+
return success(undefined);
|
|
3243
|
+
}
|
|
3244
|
+
catch (error) {
|
|
3245
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
3246
|
+
return failure(`Failed to write history file ${filePath}: ${detail}`);
|
|
3247
|
+
}
|
|
3248
|
+
}
|
|
3249
|
+
async function appendHistoryEntry({ filePath, entry, }) {
|
|
3250
|
+
const formatResult = historyFormatFromPath(filePath);
|
|
3251
|
+
if (!formatResult.success) {
|
|
3252
|
+
return formatResult;
|
|
3253
|
+
}
|
|
3254
|
+
const exists = await stat(filePath).then(() => true).catch(() => false);
|
|
3255
|
+
let entries;
|
|
3256
|
+
if (exists) {
|
|
3257
|
+
const readResult = await readHistoryFile({ filePath });
|
|
3258
|
+
if (!readResult.success) {
|
|
3259
|
+
return readResult;
|
|
3260
|
+
}
|
|
3261
|
+
entries = readResult.data;
|
|
3262
|
+
}
|
|
3263
|
+
else {
|
|
3264
|
+
await mkdir(dirname(filePath), { recursive: true });
|
|
3265
|
+
entries = [];
|
|
3266
|
+
}
|
|
3267
|
+
entries.push(entry);
|
|
3268
|
+
return writeHistoryFile({ filePath, entries });
|
|
3269
|
+
}
|
|
3270
|
+
|
|
263
3271
|
const execAsyncBase = promisify(exec);
|
|
264
3272
|
async function execAsync(command, options) {
|
|
265
3273
|
const { stdout, stderr, hasErrored } = await execAsyncBase(command, { cwd: options?.cwd })
|
|
@@ -367,7 +3375,7 @@ async function collectStepsForContext(params) {
|
|
|
367
3375
|
await walk(subSteps, nextCallHeadIndex);
|
|
368
3376
|
continue;
|
|
369
3377
|
}
|
|
370
|
-
const { commandFn, stepVariables, promptFn, postCommandExecFn, timeoutMillis, } = step;
|
|
3378
|
+
const { commandFn = () => null, stepVariables, promptFn, postCommandExecFn, timeoutMillis, } = step;
|
|
371
3379
|
const prompt = promptFn
|
|
372
3380
|
? await promptFn({
|
|
373
3381
|
context,
|
|
@@ -476,7 +3484,7 @@ async function executeStepsForContextList({ baseBranch, branchFn, lumpVariables,
|
|
|
476
3484
|
continue;
|
|
477
3485
|
}
|
|
478
3486
|
logger.verbose(`step ${JSON.stringify(step)}`);
|
|
479
|
-
const { commandFn, stepVariables, promptFn, postCommandExecFn, continueOnError, timeoutMillis = 1000 * 60 * 30, } = step;
|
|
3487
|
+
const { commandFn = () => null, stepVariables, promptFn, postCommandExecFn, continueOnError, timeoutMillis = 1000 * 60 * 30, } = step;
|
|
480
3488
|
const prompt = promptFn
|
|
481
3489
|
? await promptFn({
|
|
482
3490
|
context,
|
|
@@ -534,6 +3542,7 @@ async function executeStepsForContextList({ baseBranch, branchFn, lumpVariables,
|
|
|
534
3542
|
}
|
|
535
3543
|
const postCommandExecFnInput = {
|
|
536
3544
|
commandResult,
|
|
3545
|
+
commandSucceeded,
|
|
537
3546
|
context,
|
|
538
3547
|
prompt,
|
|
539
3548
|
stepIndex: compositeStepIndex,
|
|
@@ -546,22 +3555,14 @@ async function executeStepsForContextList({ baseBranch, branchFn, lumpVariables,
|
|
|
546
3555
|
const keepHistoryFilePath = getKeepHistoryFilePathFn(context) || '';
|
|
547
3556
|
logger.verbose(`keepHistoryFilePath ${keepHistoryFilePath}`);
|
|
548
3557
|
if (!!command && keepHistoryFilePath.length > 0) {
|
|
549
|
-
const
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
await fs$2.mkdir(dirname(keepHistoryFilePath), { recursive: true });
|
|
553
|
-
await fs$2.writeFile(keepHistoryFilePath, "[]", 'utf-8');
|
|
554
|
-
};
|
|
555
|
-
await makeHistoryFileIfNotExists();
|
|
556
|
-
const historyFileContent = await fs$2.readFile(keepHistoryFilePath, 'utf-8');
|
|
557
|
-
logger.verbose(`historyFileContent ${historyFileContent}`);
|
|
558
|
-
const history = JSON.parse(historyFileContent);
|
|
559
|
-
logger.verbose(`history ${JSON.stringify(history)}`);
|
|
560
|
-
history.push({
|
|
561
|
-
...postCommandExecFnInput,
|
|
3558
|
+
const appendResult = await appendHistoryEntry({
|
|
3559
|
+
filePath: keepHistoryFilePath,
|
|
3560
|
+
entry: postCommandExecFnInput,
|
|
562
3561
|
});
|
|
563
|
-
|
|
564
|
-
|
|
3562
|
+
if (!appendResult.success) {
|
|
3563
|
+
stepWalkFailure = failure({ message: appendResult.data });
|
|
3564
|
+
return;
|
|
3565
|
+
}
|
|
565
3566
|
}
|
|
566
3567
|
if (postCommandExecFn) {
|
|
567
3568
|
await postCommandExecFn(postCommandExecFnInput);
|
|
@@ -937,5 +3938,5 @@ async function runLump(input) {
|
|
|
937
3938
|
});
|
|
938
3939
|
}
|
|
939
3940
|
|
|
940
|
-
export { collectStepsForContext, contextStatus, contextStatusSchema, createConsoleLogger, decision, defaultGitAddCommandFn, defaultGitCommitCommandFn, defaultGitCommitMessageFn, defaultGitPushCommandFn, defaultSetupWorkspaceFn, defaultSetupWorkspaceFnWithWorktree, defaultTeardownWorkspaceFn, defaultTeardownWorkspaceFnWithWorktree, execAsync, execBinary, executeStepsForContextList, failure, formatExecFailureMessage, getCodeBasePaths, getContextStatus, getToDoContextList, noopLogger, resolveSpawnExecutable, runLump, set, shellBestEffort, shellSingleQuote, success, validateContextListNames };
|
|
3941
|
+
export { appendHistoryEntry, collectStepsForContext, contextStatus, contextStatusSchema, createConsoleLogger, decision, defaultGitAddCommandFn, defaultGitCommitCommandFn, defaultGitCommitMessageFn, defaultGitPushCommandFn, defaultSetupWorkspaceFn, defaultSetupWorkspaceFnWithWorktree, defaultTeardownWorkspaceFn, defaultTeardownWorkspaceFnWithWorktree, execAsync, execBinary, executeStepsForContextList, failure, formatExecFailureMessage, getCodeBasePaths, getContextStatus, getToDoContextList, historyFormatFromPath, noopLogger, readHistoryFile, resolveSpawnExecutable, runLump, set, shellBestEffort, shellSingleQuote, success, validateContextListNames, writeHistoryFile };
|
|
941
3942
|
//# sourceMappingURL=index.js.map
|