@node-core/utils 7.2.0 → 7.2.1
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/lib/ci/build-types/test_build.js +3 -3
- package/lib/ci/failure_aggregator.js +2 -2
- package/lib/ci/run_ci.js +3 -2
- package/lib/cli.js +6 -6
- package/lib/figures.js +6 -6
- package/lib/update-v8/backport.js +3 -4
- package/lib/verbosity.js +2 -4
- package/node_modules/@listr2/{prompt-adapter-enquirer → prompt-adapter-inquirer}/README.md +4 -4
- package/node_modules/@listr2/prompt-adapter-inquirer/dist/index.d.mts +21 -0
- package/node_modules/@listr2/prompt-adapter-inquirer/dist/index.mjs +46 -0
- package/node_modules/@listr2/prompt-adapter-inquirer/node_modules/@inquirer/type/LICENSE +22 -0
- package/node_modules/@listr2/prompt-adapter-inquirer/node_modules/@inquirer/type/dist/index.d.ts +2 -0
- package/node_modules/@listr2/prompt-adapter-inquirer/node_modules/@inquirer/type/dist/index.js +2 -0
- package/node_modules/@listr2/prompt-adapter-inquirer/node_modules/@inquirer/type/dist/inquirer.d.ts +35 -0
- package/node_modules/@listr2/prompt-adapter-inquirer/node_modules/@inquirer/type/dist/inquirer.js +1 -0
- package/node_modules/@listr2/prompt-adapter-inquirer/node_modules/@inquirer/type/dist/utils.d.ts +34 -0
- package/node_modules/@listr2/prompt-adapter-inquirer/node_modules/@inquirer/type/dist/utils.js +2 -0
- package/node_modules/@listr2/prompt-adapter-inquirer/node_modules/@inquirer/type/package.json +88 -0
- package/node_modules/@listr2/{prompt-adapter-enquirer → prompt-adapter-inquirer}/package.json +25 -20
- package/node_modules/{log-update/node_modules/ansi-escapes → ansi-escapes}/base.d.ts +48 -3
- package/node_modules/{log-update/node_modules/ansi-escapes → ansi-escapes}/base.js +58 -19
- package/node_modules/{log-update/node_modules/ansi-escapes → ansi-escapes}/package.json +1 -1
- package/node_modules/{log-update/node_modules/ansi-escapes → ansi-escapes}/readme.md +36 -1
- package/node_modules/ansi-regex/index.js +9 -4
- package/node_modules/ansi-regex/package.json +1 -1
- package/node_modules/ansi-regex/readme.md +6 -0
- package/node_modules/ansi-styles/index.d.ts +12 -12
- package/node_modules/ansi-styles/index.js +3 -3
- package/node_modules/ansi-styles/package.json +4 -4
- package/node_modules/cli-truncate/index.d.ts +3 -3
- package/node_modules/cli-truncate/index.js +40 -14
- package/node_modules/cli-truncate/node_modules/string-width/index.js +133 -15
- package/node_modules/cli-truncate/node_modules/string-width/package.json +4 -4
- package/node_modules/cli-truncate/node_modules/string-width/readme.md +1 -1
- package/node_modules/cli-truncate/package.json +7 -7
- package/node_modules/cli-truncate/readme.md +2 -3
- package/node_modules/ghauth/.github/dependabot.yml +11 -3
- package/node_modules/ghauth/.github/workflows/depsound.yml +33 -0
- package/node_modules/ghauth/.github/workflows/test-and-release.yml +4 -4
- package/node_modules/ghauth/CHANGELOG.md +60 -0
- package/node_modules/ghauth/package.json +30 -6
- package/node_modules/js-yaml/README.md +20 -187
- package/node_modules/js-yaml/dist/browser/js-yaml.esm.min.mjs +1008 -946
- package/node_modules/js-yaml/dist/browser/js-yaml.esm.min.mjs.map +1 -1
- package/node_modules/js-yaml/dist/browser/js-yaml.umd.min.js +29 -23
- package/node_modules/js-yaml/dist/browser/js-yaml.umd.min.js.map +1 -1
- package/node_modules/js-yaml/dist/js-yaml.cjs.js +1043 -583
- package/node_modules/js-yaml/dist/js-yaml.cjs.js.map +1 -1
- package/node_modules/js-yaml/dist/js-yaml.d.ts +877 -133
- package/node_modules/js-yaml/dist/js-yaml.mjs +995 -556
- package/node_modules/js-yaml/dist/js-yaml.mjs.map +1 -1
- package/node_modules/js-yaml/package.json +8 -7
- package/node_modules/listr2/dist/{index.d.cts → index.d.mts} +90 -60
- package/node_modules/listr2/dist/{index.js → index.mjs} +496 -373
- package/node_modules/listr2/node_modules/string-width/index.d.ts +39 -0
- package/node_modules/listr2/node_modules/string-width/index.js +207 -0
- package/node_modules/listr2/node_modules/string-width/package.json +65 -0
- package/node_modules/listr2/node_modules/string-width/readme.md +66 -0
- package/node_modules/listr2/node_modules/wrap-ansi/index.d.ts +1 -1
- package/node_modules/listr2/node_modules/wrap-ansi/index.js +544 -116
- package/node_modules/listr2/node_modules/wrap-ansi/package.json +10 -13
- package/node_modules/listr2/node_modules/wrap-ansi/readme.md +2 -0
- package/node_modules/listr2/package.json +16 -19
- package/node_modules/log-update/index.d.ts +64 -1
- package/node_modules/log-update/index.js +268 -18
- package/node_modules/log-update/node_modules/string-width/index.d.ts +39 -0
- package/node_modules/log-update/node_modules/string-width/index.js +207 -0
- package/node_modules/log-update/node_modules/string-width/package.json +65 -0
- package/node_modules/log-update/node_modules/string-width/readme.md +66 -0
- package/node_modules/log-update/node_modules/wrap-ansi/index.d.ts +1 -1
- package/node_modules/log-update/node_modules/wrap-ansi/index.js +544 -116
- package/node_modules/log-update/node_modules/wrap-ansi/package.json +10 -13
- package/node_modules/log-update/node_modules/wrap-ansi/readme.md +2 -0
- package/node_modules/log-update/package.json +14 -12
- package/node_modules/log-update/readme.md +61 -0
- package/node_modules/slice-ansi/index.d.ts +2 -2
- package/node_modules/slice-ansi/index.js +260 -112
- package/node_modules/slice-ansi/package.json +10 -9
- package/node_modules/slice-ansi/readme.md +3 -2
- package/node_modules/slice-ansi/tokenize-ansi.js +752 -0
- package/node_modules/smol-toml/README.md +205 -191
- package/node_modules/smol-toml/dist/date.d.ts +0 -1
- package/node_modules/smol-toml/dist/date.js +0 -1
- package/node_modules/smol-toml/dist/error.d.ts +0 -1
- package/node_modules/smol-toml/dist/error.js +0 -1
- package/node_modules/smol-toml/dist/extract.js +32 -65
- package/node_modules/smol-toml/dist/index.cjs +302 -288
- package/node_modules/smol-toml/dist/index.d.ts +0 -1
- package/node_modules/smol-toml/dist/index.js +0 -1
- package/node_modules/smol-toml/dist/parse.d.ts +1 -3
- package/node_modules/smol-toml/dist/parse.js +22 -21
- package/node_modules/smol-toml/dist/primitive.js +75 -76
- package/node_modules/smol-toml/dist/stringify.d.ts +0 -1
- package/node_modules/smol-toml/dist/stringify.js +43 -30
- package/node_modules/smol-toml/dist/struct.js +90 -93
- package/node_modules/smol-toml/dist/util.d.ts +1 -1
- package/node_modules/smol-toml/dist/util.js +36 -39
- package/node_modules/smol-toml/package.json +6 -6
- package/node_modules/strip-ansi/index.js +5 -0
- package/node_modules/strip-ansi/package.json +5 -5
- package/package.json +3 -5
- package/node_modules/@listr2/prompt-adapter-enquirer/dist/index.cjs +0 -127
- package/node_modules/@listr2/prompt-adapter-enquirer/dist/index.d.cts +0 -152
- package/node_modules/@listr2/prompt-adapter-enquirer/dist/index.d.ts +0 -152
- package/node_modules/@listr2/prompt-adapter-enquirer/dist/index.js +0 -92
- package/node_modules/chalk/package.json +0 -92
- package/node_modules/chalk/readme.md +0 -331
- package/node_modules/chalk/source/index.d.ts +0 -437
- package/node_modules/chalk/source/index.js +0 -261
- package/node_modules/chalk/source/utilities.js +0 -33
- package/node_modules/chalk/source/vendor/ansi-styles/index.d.ts +0 -299
- package/node_modules/chalk/source/vendor/ansi-styles/index.js +0 -261
- package/node_modules/chalk/source/vendor/supports-color/browser.d.ts +0 -1
- package/node_modules/chalk/source/vendor/supports-color/browser.js +0 -32
- package/node_modules/chalk/source/vendor/supports-color/index.d.ts +0 -55
- package/node_modules/chalk/source/vendor/supports-color/index.js +0 -206
- package/node_modules/colorette/LICENSE.md +0 -7
- package/node_modules/colorette/README.md +0 -134
- package/node_modules/colorette/index.cjs +0 -218
- package/node_modules/colorette/index.d.ts +0 -93
- package/node_modules/colorette/index.js +0 -150
- package/node_modules/colorette/package.json +0 -40
- package/node_modules/eventemitter3/LICENSE +0 -21
- package/node_modules/eventemitter3/README.md +0 -94
- package/node_modules/eventemitter3/dist/eventemitter3.esm.js +0 -347
- package/node_modules/eventemitter3/dist/eventemitter3.esm.min.js +0 -1
- package/node_modules/eventemitter3/dist/eventemitter3.esm.min.js.map +0 -1
- package/node_modules/eventemitter3/dist/eventemitter3.umd.js +0 -355
- package/node_modules/eventemitter3/dist/eventemitter3.umd.min.js +0 -1
- package/node_modules/eventemitter3/dist/eventemitter3.umd.min.js.map +0 -1
- package/node_modules/eventemitter3/index.d.ts +0 -135
- package/node_modules/eventemitter3/index.js +0 -336
- package/node_modules/eventemitter3/index.mjs +0 -4
- package/node_modules/eventemitter3/package.json +0 -67
- package/node_modules/figures/index.d.ts +0 -279
- package/node_modules/figures/index.js +0 -292
- package/node_modules/figures/package.json +0 -49
- package/node_modules/figures/readme.md +0 -337
- package/node_modules/listr2/dist/index.cjs +0 -2189
- package/node_modules/listr2/dist/index.d.ts +0 -1528
- package/node_modules/rfdc/.github/workflows/ci.yml +0 -21
- package/node_modules/rfdc/LICENSE +0 -15
- package/node_modules/rfdc/default.js +0 -3
- package/node_modules/rfdc/index.d.ts +0 -13
- package/node_modules/rfdc/index.js +0 -198
- package/node_modules/rfdc/index.test-d.ts +0 -13
- package/node_modules/rfdc/package.json +0 -73
- package/node_modules/rfdc/readme.md +0 -181
- package/node_modules/rfdc/test/index.js +0 -306
- package/node_modules/smol-toml/dist/date.d.ts.map +0 -1
- package/node_modules/smol-toml/dist/date.js.map +0 -1
- package/node_modules/smol-toml/dist/error.d.ts.map +0 -1
- package/node_modules/smol-toml/dist/error.js.map +0 -1
- package/node_modules/smol-toml/dist/extract.js.map +0 -1
- package/node_modules/smol-toml/dist/index.cjs.map +0 -1
- package/node_modules/smol-toml/dist/index.d.ts.map +0 -1
- package/node_modules/smol-toml/dist/index.js.map +0 -1
- package/node_modules/smol-toml/dist/parse.d.ts.map +0 -1
- package/node_modules/smol-toml/dist/parse.js.map +0 -1
- package/node_modules/smol-toml/dist/primitive.d.ts +0 -29
- package/node_modules/smol-toml/dist/primitive.d.ts.map +0 -1
- package/node_modules/smol-toml/dist/primitive.js.map +0 -1
- package/node_modules/smol-toml/dist/stringify.d.ts.map +0 -1
- package/node_modules/smol-toml/dist/stringify.js.map +0 -1
- package/node_modules/smol-toml/dist/struct.js.map +0 -1
- package/node_modules/smol-toml/dist/util.d.ts.map +0 -1
- package/node_modules/smol-toml/dist/util.js.map +0 -1
- package/node_modules/smol-toml/src/date.ts +0 -152
- package/node_modules/smol-toml/src/error.ts +0 -77
- package/node_modules/smol-toml/src/extract.ts +0 -113
- package/node_modules/smol-toml/src/index.ts +0 -42
- package/node_modules/smol-toml/src/parse.ts +0 -184
- package/node_modules/smol-toml/src/primitive.ts +0 -249
- package/node_modules/smol-toml/src/stringify.ts +0 -191
- package/node_modules/smol-toml/src/struct.ts +0 -202
- package/node_modules/smol-toml/src/util.ts +0 -106
- /package/node_modules/@listr2/{prompt-adapter-enquirer → prompt-adapter-inquirer}/LICENSE +0 -0
- /package/node_modules/{log-update/node_modules/ansi-escapes → ansi-escapes}/index.d.ts +0 -0
- /package/node_modules/{log-update/node_modules/ansi-escapes → ansi-escapes}/index.js +0 -0
- /package/node_modules/{chalk → ansi-escapes}/license +0 -0
- /package/node_modules/{figures → listr2/node_modules/string-width}/license +0 -0
- /package/node_modules/log-update/node_modules/{ansi-escapes → string-width}/license +0 -0
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
/*! js-yaml 5.
|
|
1
|
+
/*! js-yaml 5.4.1 https://github.com/nodeca/js-yaml @license MIT */
|
|
2
2
|
//#region src/tag.ts
|
|
3
|
+
/**
|
|
4
|
+
* Returned by a scalar resolver when the source does not match its tag.
|
|
5
|
+
*
|
|
6
|
+
* @category Tags
|
|
7
|
+
*/
|
|
3
8
|
var NOT_RESOLVED = Symbol("NOT_RESOLVED");
|
|
4
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Create a normalized scalar tag definition.
|
|
11
|
+
*
|
|
12
|
+
* @category Tags
|
|
13
|
+
*/
|
|
5
14
|
function defineScalarTag(tagName, options) {
|
|
6
15
|
return {
|
|
7
16
|
tagName,
|
|
@@ -10,11 +19,16 @@ function defineScalarTag(tagName, options) {
|
|
|
10
19
|
matchByTagPrefix: options.matchByTagPrefix ?? false,
|
|
11
20
|
implicitFirstChars: options.implicitFirstChars ?? null,
|
|
12
21
|
resolve: options.resolve,
|
|
13
|
-
identify: options.identify
|
|
22
|
+
identify: options.identify,
|
|
14
23
|
represent: options.represent ?? ((data) => String(data)),
|
|
15
|
-
representTagName: options.representTagName ??
|
|
24
|
+
representTagName: options.representTagName ?? (() => tagName)
|
|
16
25
|
};
|
|
17
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Create a normalized sequence tag definition.
|
|
29
|
+
*
|
|
30
|
+
* @category Tags
|
|
31
|
+
*/
|
|
18
32
|
function defineSequenceTag(tagName, options) {
|
|
19
33
|
const carrierIsResult = options.finalize === void 0;
|
|
20
34
|
return {
|
|
@@ -26,11 +40,16 @@ function defineSequenceTag(tagName, options) {
|
|
|
26
40
|
addItem: options.addItem,
|
|
27
41
|
finalize: options.finalize ?? ((carrier) => carrier),
|
|
28
42
|
carrierIsResult,
|
|
29
|
-
identify: options.identify
|
|
43
|
+
identify: options.identify,
|
|
30
44
|
represent: options.represent ?? ((data) => data),
|
|
31
|
-
representTagName: options.representTagName ??
|
|
45
|
+
representTagName: options.representTagName ?? (() => tagName)
|
|
32
46
|
};
|
|
33
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Create a normalized mapping tag definition.
|
|
50
|
+
*
|
|
51
|
+
* @category Tags
|
|
52
|
+
*/
|
|
34
53
|
function defineMappingTag(tagName, options) {
|
|
35
54
|
const carrierIsResult = options.finalize === void 0;
|
|
36
55
|
return {
|
|
@@ -45,13 +64,14 @@ function defineMappingTag(tagName, options) {
|
|
|
45
64
|
get: options.get,
|
|
46
65
|
finalize: options.finalize ?? ((carrier) => carrier),
|
|
47
66
|
carrierIsResult,
|
|
48
|
-
identify: options.identify
|
|
67
|
+
identify: options.identify,
|
|
49
68
|
represent: options.represent ?? ((data) => data),
|
|
50
|
-
representTagName: options.representTagName ??
|
|
69
|
+
representTagName: options.representTagName ?? (() => tagName)
|
|
51
70
|
};
|
|
52
71
|
}
|
|
53
72
|
//#endregion
|
|
54
73
|
//#region src/tag/scalar/str.ts
|
|
74
|
+
/** @category Tags */
|
|
55
75
|
var strTag = defineScalarTag("tag:yaml.org,2002:str", {
|
|
56
76
|
resolve: (source) => source,
|
|
57
77
|
identify: (data) => typeof data === "string"
|
|
@@ -65,6 +85,7 @@ var NULL_VALUES$1 = [
|
|
|
65
85
|
"Null",
|
|
66
86
|
"NULL"
|
|
67
87
|
];
|
|
88
|
+
/** @category Tags */
|
|
68
89
|
var nullCoreTag = defineScalarTag("tag:yaml.org,2002:null", {
|
|
69
90
|
implicit: true,
|
|
70
91
|
implicitFirstChars: [
|
|
@@ -82,6 +103,7 @@ var nullCoreTag = defineScalarTag("tag:yaml.org,2002:null", {
|
|
|
82
103
|
});
|
|
83
104
|
//#endregion
|
|
84
105
|
//#region src/tag/scalar/null_json.ts
|
|
106
|
+
/** @category Tags */
|
|
85
107
|
var nullJsonTag = defineScalarTag("tag:yaml.org,2002:null", {
|
|
86
108
|
implicit: true,
|
|
87
109
|
implicitFirstChars: ["n"],
|
|
@@ -101,6 +123,7 @@ var NULL_VALUES = [
|
|
|
101
123
|
"Null",
|
|
102
124
|
"NULL"
|
|
103
125
|
];
|
|
126
|
+
/** @category Tags */
|
|
104
127
|
var nullYaml11Tag = defineScalarTag("tag:yaml.org,2002:null", {
|
|
105
128
|
implicit: true,
|
|
106
129
|
implicitFirstChars: [
|
|
@@ -128,6 +151,7 @@ var FALSE_VALUES$2 = [
|
|
|
128
151
|
"False",
|
|
129
152
|
"FALSE"
|
|
130
153
|
];
|
|
154
|
+
/** @category Tags */
|
|
131
155
|
var boolCoreTag = defineScalarTag("tag:yaml.org,2002:bool", {
|
|
132
156
|
implicit: true,
|
|
133
157
|
implicitFirstChars: [
|
|
@@ -148,6 +172,7 @@ var boolCoreTag = defineScalarTag("tag:yaml.org,2002:bool", {
|
|
|
148
172
|
//#region src/tag/scalar/bool_json.ts
|
|
149
173
|
var TRUE_VALUES$1 = ["true"];
|
|
150
174
|
var FALSE_VALUES$1 = ["false"];
|
|
175
|
+
/** @category Tags */
|
|
151
176
|
var boolJsonTag = defineScalarTag("tag:yaml.org,2002:bool", {
|
|
152
177
|
implicit: true,
|
|
153
178
|
implicitFirstChars: ["t", "f"],
|
|
@@ -187,6 +212,7 @@ var FALSE_VALUES = [
|
|
|
187
212
|
"Off",
|
|
188
213
|
"OFF"
|
|
189
214
|
];
|
|
215
|
+
/** @category Tags */
|
|
190
216
|
var boolYaml11Tag = defineScalarTag("tag:yaml.org,2002:bool", {
|
|
191
217
|
implicit: true,
|
|
192
218
|
implicitFirstChars: [
|
|
@@ -232,6 +258,7 @@ function resolveYamlInteger$2(source, isExplicit) {
|
|
|
232
258
|
const result = parseYamlInteger$2(source);
|
|
233
259
|
return Number.isFinite(result) ? result : NOT_RESOLVED;
|
|
234
260
|
}
|
|
261
|
+
/** @category Tags */
|
|
235
262
|
var intCoreTag = defineScalarTag("tag:yaml.org,2002:int", {
|
|
236
263
|
implicit: true,
|
|
237
264
|
implicitFirstChars: [
|
|
@@ -266,6 +293,7 @@ function resolveYamlInteger$1(source, isExplicit) {
|
|
|
266
293
|
const result = parseYamlInteger$1(source);
|
|
267
294
|
return Number.isFinite(result) ? result : NOT_RESOLVED;
|
|
268
295
|
}
|
|
296
|
+
/** @category Tags */
|
|
269
297
|
var intJsonTag = defineScalarTag("tag:yaml.org,2002:int", {
|
|
270
298
|
implicit: true,
|
|
271
299
|
implicitFirstChars: ["-", ..."0123456789"],
|
|
@@ -298,6 +326,7 @@ function resolveYamlInteger(source) {
|
|
|
298
326
|
const result = parseYamlInteger(source);
|
|
299
327
|
return Number.isFinite(result) ? result : NOT_RESOLVED;
|
|
300
328
|
}
|
|
329
|
+
/** @category Tags */
|
|
301
330
|
var intYaml11Tag = defineScalarTag("tag:yaml.org,2002:int", {
|
|
302
331
|
implicit: true,
|
|
303
332
|
implicitFirstChars: [
|
|
@@ -332,6 +361,7 @@ function representYamlFloat$2(object) {
|
|
|
332
361
|
const result = object.toString(10);
|
|
333
362
|
return /^[-+]?[0-9]+e/.test(result) ? result.replace("e", ".e") : result;
|
|
334
363
|
}
|
|
364
|
+
/** @category Tags */
|
|
335
365
|
var floatCoreTag = defineScalarTag("tag:yaml.org,2002:float", {
|
|
336
366
|
implicit: true,
|
|
337
367
|
implicitFirstChars: [
|
|
@@ -372,6 +402,7 @@ function representYamlFloat$1(object) {
|
|
|
372
402
|
const result = object.toString(10);
|
|
373
403
|
return /^[-+]?[0-9]+e/.test(result) ? result.replace("e", ".e") : result;
|
|
374
404
|
}
|
|
405
|
+
/** @category Tags */
|
|
375
406
|
var floatJsonTag = defineScalarTag("tag:yaml.org,2002:float", {
|
|
376
407
|
implicit: true,
|
|
377
408
|
implicitFirstChars: ["-", ..."0123456789"],
|
|
@@ -406,6 +437,7 @@ function representYamlFloat(object) {
|
|
|
406
437
|
const result = object.toString(10);
|
|
407
438
|
return /^[-+]?[0-9]+e/.test(result) ? result.replace("e", ".e") : result;
|
|
408
439
|
}
|
|
440
|
+
/** @category Tags */
|
|
409
441
|
var floatYaml11Tag = defineScalarTag("tag:yaml.org,2002:float", {
|
|
410
442
|
implicit: true,
|
|
411
443
|
implicitFirstChars: [
|
|
@@ -420,13 +452,20 @@ var floatYaml11Tag = defineScalarTag("tag:yaml.org,2002:float", {
|
|
|
420
452
|
});
|
|
421
453
|
//#endregion
|
|
422
454
|
//#region src/tag/scalar/merge.ts
|
|
455
|
+
/**
|
|
456
|
+
* Enables merge keys in {@link CORE_SCHEMA} when added with
|
|
457
|
+
* {@link Schema.withTags}.
|
|
458
|
+
*
|
|
459
|
+
* @category Tags
|
|
460
|
+
*/
|
|
423
461
|
var mergeTag = defineScalarTag("tag:yaml.org,2002:merge", {
|
|
424
462
|
implicit: true,
|
|
425
463
|
implicitFirstChars: ["<"],
|
|
426
464
|
resolve: (source, isExplicit) => {
|
|
427
|
-
if (source === "<<" || isExplicit && source === "") return
|
|
465
|
+
if (source === "<<" || isExplicit && source === "") return "<<";
|
|
428
466
|
return NOT_RESOLVED;
|
|
429
|
-
}
|
|
467
|
+
},
|
|
468
|
+
identify: () => false
|
|
430
469
|
});
|
|
431
470
|
//#endregion
|
|
432
471
|
//#region src/tag/scalar/binary.ts
|
|
@@ -444,6 +483,11 @@ function representYamlBinary(object) {
|
|
|
444
483
|
for (let index = 0; index < object.length; index++) binary += String.fromCharCode(object[index]);
|
|
445
484
|
return btoa(binary);
|
|
446
485
|
}
|
|
486
|
+
/**
|
|
487
|
+
* The `!!binary` tag, represented as a `Uint8Array`.
|
|
488
|
+
*
|
|
489
|
+
* @category Tags
|
|
490
|
+
*/
|
|
447
491
|
var binaryTag = defineScalarTag("tag:yaml.org,2002:binary", {
|
|
448
492
|
resolve: resolveYamlBinary,
|
|
449
493
|
identify: (object) => Object.prototype.toString.call(object) === "[object Uint8Array]",
|
|
@@ -491,6 +535,11 @@ function resolveYamlTimestamp(source) {
|
|
|
491
535
|
}
|
|
492
536
|
return date;
|
|
493
537
|
}
|
|
538
|
+
/**
|
|
539
|
+
* The YAML 1.1 `!!timestamp` tag, represented as a JavaScript `Date`.
|
|
540
|
+
*
|
|
541
|
+
* @category Tags
|
|
542
|
+
*/
|
|
494
543
|
var timestampTag = defineScalarTag("tag:yaml.org,2002:timestamp", {
|
|
495
544
|
implicit: true,
|
|
496
545
|
implicitFirstChars: [..."0123456789"],
|
|
@@ -500,6 +549,7 @@ var timestampTag = defineScalarTag("tag:yaml.org,2002:timestamp", {
|
|
|
500
549
|
});
|
|
501
550
|
//#endregion
|
|
502
551
|
//#region src/tag/sequence/seq.ts
|
|
552
|
+
/** @category Tags */
|
|
503
553
|
var seqTag = defineSequenceTag("tag:yaml.org,2002:seq", {
|
|
504
554
|
create: () => [],
|
|
505
555
|
addItem: (container, item) => {
|
|
@@ -521,6 +571,28 @@ function pick(object, keys) {
|
|
|
521
571
|
}
|
|
522
572
|
//#endregion
|
|
523
573
|
//#region src/tag/sequence/omap.ts
|
|
574
|
+
/**
|
|
575
|
+
* Provided only for YAML 1.1 compatibility and supported by the loader only.
|
|
576
|
+
* JavaScript has no dedicated class to represent this type, so it cannot be
|
|
577
|
+
* identified and dumped.
|
|
578
|
+
*
|
|
579
|
+
* ```yaml
|
|
580
|
+
* !!omap
|
|
581
|
+
* - one: 1
|
|
582
|
+
* - two: 2
|
|
583
|
+
* ```
|
|
584
|
+
*
|
|
585
|
+
* is loaded as
|
|
586
|
+
*
|
|
587
|
+
* ```javascript
|
|
588
|
+
* [
|
|
589
|
+
* { one: 1 },
|
|
590
|
+
* { two: 2 }
|
|
591
|
+
* ]
|
|
592
|
+
* ```
|
|
593
|
+
*
|
|
594
|
+
* @category Tags
|
|
595
|
+
*/
|
|
524
596
|
var omapTag = defineSequenceTag("tag:yaml.org,2002:omap", {
|
|
525
597
|
create: () => ({
|
|
526
598
|
list: [],
|
|
@@ -541,10 +613,33 @@ var omapTag = defineSequenceTag("tag:yaml.org,2002:omap", {
|
|
|
541
613
|
carrier.list.push(item);
|
|
542
614
|
return "";
|
|
543
615
|
},
|
|
544
|
-
finalize: (carrier) => carrier.list
|
|
616
|
+
finalize: (carrier) => carrier.list,
|
|
617
|
+
identify: () => false
|
|
545
618
|
});
|
|
546
619
|
//#endregion
|
|
547
620
|
//#region src/tag/sequence/pairs.ts
|
|
621
|
+
/**
|
|
622
|
+
* Provided only for YAML 1.1 compatibility and supported by the loader only.
|
|
623
|
+
* JavaScript has no dedicated class to represent this type, so it cannot be
|
|
624
|
+
* identified and dumped.
|
|
625
|
+
*
|
|
626
|
+
* ```yaml
|
|
627
|
+
* !!pairs
|
|
628
|
+
* - one: 1
|
|
629
|
+
* - two: 2
|
|
630
|
+
* ```
|
|
631
|
+
*
|
|
632
|
+
* is loaded as
|
|
633
|
+
*
|
|
634
|
+
* ```javascript
|
|
635
|
+
* [
|
|
636
|
+
* ['one', 1],
|
|
637
|
+
* ['two', 2]
|
|
638
|
+
* ]
|
|
639
|
+
* ```
|
|
640
|
+
*
|
|
641
|
+
* @category Tags
|
|
642
|
+
*/
|
|
548
643
|
var pairsTag = defineSequenceTag("tag:yaml.org,2002:pairs", {
|
|
549
644
|
create: () => [],
|
|
550
645
|
addItem: (container, item) => {
|
|
@@ -559,10 +654,32 @@ var pairsTag = defineSequenceTag("tag:yaml.org,2002:pairs", {
|
|
|
559
654
|
if (keys.length !== 1) return "cannot resolve a pairs item";
|
|
560
655
|
container.push([keys[0], object[keys[0]]]);
|
|
561
656
|
return "";
|
|
562
|
-
}
|
|
657
|
+
},
|
|
658
|
+
identify: () => false
|
|
563
659
|
});
|
|
564
660
|
//#endregion
|
|
565
661
|
//#region src/tag/mapping/map.ts
|
|
662
|
+
/**
|
|
663
|
+
* This is the default mapping implementation. It uses `{}` objects and has only
|
|
664
|
+
* partial functionality due to language limitations. This choice was made
|
|
665
|
+
* because users expect to get JavaScript objects, and it was left unchanged to
|
|
666
|
+
* avoid too many breaking changes in the v5 release.
|
|
667
|
+
*
|
|
668
|
+
* Side effects:
|
|
669
|
+
*
|
|
670
|
+
* - `Object.hasOwn()` checks or `for...of` loops are required for safe use (to
|
|
671
|
+
* avoid falling through to prototypes).
|
|
672
|
+
* - Only scalar string keys are supported properly.
|
|
673
|
+
* - Other scalar keys, such as `null` and numbers, are converted to strings.
|
|
674
|
+
* This is historical behaviour, and it can cause side effects such as
|
|
675
|
+
* problems with `!!merge`.
|
|
676
|
+
*
|
|
677
|
+
* Note that non-string scalar keys may be deprecated in future versions.
|
|
678
|
+
*
|
|
679
|
+
* Ideally, use {@link realMapTag} instead.
|
|
680
|
+
*
|
|
681
|
+
* @category Tags
|
|
682
|
+
*/
|
|
566
683
|
var mapTag = defineMappingTag("tag:yaml.org,2002:map", {
|
|
567
684
|
create: () => ({}),
|
|
568
685
|
identify: isPlainObject,
|
|
@@ -596,6 +713,11 @@ var mapTag = defineMappingTag("tag:yaml.org,2002:map", {
|
|
|
596
713
|
});
|
|
597
714
|
//#endregion
|
|
598
715
|
//#region src/tag/mapping/set.ts
|
|
716
|
+
/**
|
|
717
|
+
* The YAML 1.1 `!!set` tag, represented as a JavaScript `Set`.
|
|
718
|
+
*
|
|
719
|
+
* @category Tags
|
|
720
|
+
*/
|
|
599
721
|
var setTag = defineMappingTag("tag:yaml.org,2002:set", {
|
|
600
722
|
create: () => /* @__PURE__ */ new Set(),
|
|
601
723
|
identify: (data) => data instanceof Set,
|
|
@@ -644,13 +766,42 @@ function compileTags(tags) {
|
|
|
644
766
|
}
|
|
645
767
|
return result;
|
|
646
768
|
}
|
|
769
|
+
/**
|
|
770
|
+
* Controls tag resolution when loading and type selection when dumping.
|
|
771
|
+
*
|
|
772
|
+
* @category Schemas
|
|
773
|
+
*/
|
|
647
774
|
var Schema = class Schema {
|
|
648
775
|
tags;
|
|
776
|
+
/** @internal */
|
|
649
777
|
implicitScalarTags;
|
|
778
|
+
/**
|
|
779
|
+
* Dispatch implicit scalar resolvers by `source.charAt(0)`. Each bucket holds
|
|
780
|
+
* the resolvers that may match that key, in schema order; a key absent from
|
|
781
|
+
* the map uses
|
|
782
|
+
* {@link Schema.implicitScalarAnyFirstChar}
|
|
783
|
+
* (resolvers that declared no first-char constraint, so they apply to any
|
|
784
|
+
* first character).
|
|
785
|
+
*/
|
|
650
786
|
implicitScalarByFirstChar;
|
|
651
787
|
implicitScalarAnyFirstChar;
|
|
788
|
+
/**
|
|
789
|
+
* The default scalar tag (`!!str`), resolved once so the composer's fallback
|
|
790
|
+
* for unresolved plain scalars avoids a keyed lookup per scalar.
|
|
791
|
+
*
|
|
792
|
+
* @internal
|
|
793
|
+
*/
|
|
652
794
|
defaultScalarTag;
|
|
795
|
+
/**
|
|
796
|
+
* The default container tags (`!!seq` / `!!map`), used by the dumper: when a
|
|
797
|
+
* value is identified by its default tag, the tag is implicit and not
|
|
798
|
+
* printed. Undefined if the schema does not define them (then such values
|
|
799
|
+
* can't be dumped).
|
|
800
|
+
*
|
|
801
|
+
* @internal
|
|
802
|
+
*/
|
|
653
803
|
defaultSequenceTag;
|
|
804
|
+
/** @internal */
|
|
654
805
|
defaultMappingTag;
|
|
655
806
|
exact;
|
|
656
807
|
prefix;
|
|
@@ -696,17 +847,74 @@ var Schema = class Schema {
|
|
|
696
847
|
this.exact = exact;
|
|
697
848
|
this.prefix = prefix;
|
|
698
849
|
}
|
|
850
|
+
/** @internal */
|
|
851
|
+
lookupScalarTag(tagName) {
|
|
852
|
+
const exactTag = this.exact.scalar[tagName];
|
|
853
|
+
if (exactTag) return exactTag;
|
|
854
|
+
for (const tag of this.prefix.scalar) if (tagName.startsWith(tag.tagName)) return tag;
|
|
855
|
+
}
|
|
856
|
+
/** @internal */
|
|
857
|
+
lookupSequenceTag(tagName) {
|
|
858
|
+
const exactTag = this.exact.sequence[tagName];
|
|
859
|
+
if (exactTag) return exactTag;
|
|
860
|
+
for (const tag of this.prefix.sequence) if (tagName.startsWith(tag.tagName)) return tag;
|
|
861
|
+
}
|
|
862
|
+
/** @internal */
|
|
863
|
+
lookupMappingTag(tagName) {
|
|
864
|
+
const exactTag = this.exact.mapping[tagName];
|
|
865
|
+
if (exactTag) return exactTag;
|
|
866
|
+
for (const tag of this.prefix.mapping) if (tagName.startsWith(tag.tagName)) return tag;
|
|
867
|
+
}
|
|
868
|
+
/** @internal */
|
|
869
|
+
resolveImplicitScalarTag(source) {
|
|
870
|
+
const candidates = this.implicitScalarByFirstChar.get(source.charAt(0)) ?? this.implicitScalarAnyFirstChar;
|
|
871
|
+
for (const tag of candidates) {
|
|
872
|
+
const value = tag.resolve(source, false, tag.tagName);
|
|
873
|
+
if (value !== NOT_RESOLVED) return {
|
|
874
|
+
value,
|
|
875
|
+
tag
|
|
876
|
+
};
|
|
877
|
+
}
|
|
878
|
+
const tag = this.defaultScalarTag;
|
|
879
|
+
return {
|
|
880
|
+
value: tag.resolve(source, false, tag.tagName),
|
|
881
|
+
tag
|
|
882
|
+
};
|
|
883
|
+
}
|
|
884
|
+
/**
|
|
885
|
+
* Creates a new schema with the specified tags added. If a tag already
|
|
886
|
+
* exists, it is replaced by the specified tag.
|
|
887
|
+
*
|
|
888
|
+
* @example
|
|
889
|
+
*
|
|
890
|
+
* ```javascript
|
|
891
|
+
* import { CORE_SCHEMA, mergeTag, realMapTag } from 'js-yaml'
|
|
892
|
+
*
|
|
893
|
+
* const schema = CORE_SCHEMA.withTags(mergeTag, realMapTag)
|
|
894
|
+
* ```
|
|
895
|
+
*/
|
|
699
896
|
withTags(...tags) {
|
|
700
897
|
let flatTags = [];
|
|
701
898
|
for (const tag of tags) flatTags = flatTags.concat(tag);
|
|
702
899
|
return new Schema([...this.tags, ...flatTags]);
|
|
703
900
|
}
|
|
704
901
|
};
|
|
902
|
+
/**
|
|
903
|
+
* The YAML 1.2 Failsafe Schema: strings, sequences, and mappings.
|
|
904
|
+
*
|
|
905
|
+
* @category Schemas
|
|
906
|
+
*/
|
|
705
907
|
var FAILSAFE_SCHEMA = new Schema([
|
|
706
908
|
strTag,
|
|
707
909
|
seqTag,
|
|
708
910
|
mapTag
|
|
709
911
|
]);
|
|
912
|
+
/**
|
|
913
|
+
* The YAML 1.2 JSON Schema. It uses JSON scalar forms while retaining YAML
|
|
914
|
+
* collection syntax.
|
|
915
|
+
*
|
|
916
|
+
* @category Schemas
|
|
917
|
+
*/
|
|
710
918
|
var JSON_SCHEMA = new Schema([
|
|
711
919
|
...FAILSAFE_SCHEMA.tags,
|
|
712
920
|
nullJsonTag,
|
|
@@ -714,6 +922,25 @@ var JSON_SCHEMA = new Schema([
|
|
|
714
922
|
intJsonTag,
|
|
715
923
|
floatJsonTag
|
|
716
924
|
]);
|
|
925
|
+
/**
|
|
926
|
+
* The default schema for the loaders. Note, {@link CORE_SCHEMA} comes
|
|
927
|
+
* without the `!!merge` tag. You can easily enable it if needed.
|
|
928
|
+
*
|
|
929
|
+
* @example
|
|
930
|
+
* Enable {@link mergeTag}:
|
|
931
|
+
*
|
|
932
|
+
* ```javascript
|
|
933
|
+
* import { load, CORE_SCHEMA, mergeTag } from 'js-yaml'
|
|
934
|
+
*
|
|
935
|
+
* try {
|
|
936
|
+
* load(data, { schema: CORE_SCHEMA.withTags(mergeTag) })
|
|
937
|
+
* } catch (e) {
|
|
938
|
+
* console.error(e)
|
|
939
|
+
* }
|
|
940
|
+
* ```
|
|
941
|
+
*
|
|
942
|
+
* @category Schemas
|
|
943
|
+
*/
|
|
717
944
|
var CORE_SCHEMA = new Schema([
|
|
718
945
|
...FAILSAFE_SCHEMA.tags,
|
|
719
946
|
nullCoreTag,
|
|
@@ -721,6 +948,11 @@ var CORE_SCHEMA = new Schema([
|
|
|
721
948
|
intCoreTag,
|
|
722
949
|
floatCoreTag
|
|
723
950
|
]);
|
|
951
|
+
/**
|
|
952
|
+
* YAML 1.1-compatible schema.
|
|
953
|
+
*
|
|
954
|
+
* @category Schemas
|
|
955
|
+
*/
|
|
724
956
|
var YAML11_SCHEMA = new Schema([
|
|
725
957
|
...FAILSAFE_SCHEMA.tags,
|
|
726
958
|
nullYaml11Tag,
|
|
@@ -734,8 +966,60 @@ var YAML11_SCHEMA = new Schema([
|
|
|
734
966
|
pairsTag,
|
|
735
967
|
setTag
|
|
736
968
|
]);
|
|
969
|
+
/**
|
|
970
|
+
* The dumper schema for maximum compatibility. It combines all supported type
|
|
971
|
+
* variants from YAML 1.1 and YAML 1.2 so strings matching any of them are
|
|
972
|
+
* quoted. This makes the generated YAML more compatible with other parsers.
|
|
973
|
+
*
|
|
974
|
+
* The schema is based on YAML 1.1, but extends `!!int` and `!!float` to accept
|
|
975
|
+
* both YAML 1.1 and Core Schema forms, since Core Schema supports some forms
|
|
976
|
+
* that YAML 1.1 does not.
|
|
977
|
+
*
|
|
978
|
+
* @category Schemas
|
|
979
|
+
*/
|
|
980
|
+
var DUMP_SCHEMA = YAML11_SCHEMA.withTags({
|
|
981
|
+
...intYaml11Tag,
|
|
982
|
+
resolve: (source, isExplicit, tagName) => {
|
|
983
|
+
const result = intYaml11Tag.resolve(source, isExplicit, tagName);
|
|
984
|
+
return result === NOT_RESOLVED ? intCoreTag.resolve(source, isExplicit, tagName) : result;
|
|
985
|
+
}
|
|
986
|
+
}, {
|
|
987
|
+
...floatYaml11Tag,
|
|
988
|
+
resolve: (source, isExplicit, tagName) => {
|
|
989
|
+
const result = floatYaml11Tag.resolve(source, isExplicit, tagName);
|
|
990
|
+
return result === NOT_RESOLVED ? floatCoreTag.resolve(source, isExplicit, tagName) : result;
|
|
991
|
+
}
|
|
992
|
+
});
|
|
737
993
|
//#endregion
|
|
738
994
|
//#region src/tag/mapping/real_map.ts
|
|
995
|
+
/**
|
|
996
|
+
* Recommended when non-string keys are actually needed. It uses native
|
|
997
|
+
* JavaScript `Map` objects, so keys keep their constructed types instead of
|
|
998
|
+
* being converted to strings.
|
|
999
|
+
*
|
|
1000
|
+
* It is not the default to avoid widespread breaking changes in existing
|
|
1001
|
+
* projects. `Map` has a different access API and does not pass deep equality
|
|
1002
|
+
* checks against `{}`-based fixtures. Alongside the other changes in v5,
|
|
1003
|
+
* making it the default was considered too disruptive.
|
|
1004
|
+
*
|
|
1005
|
+
* If these differences are acceptable for your project, we recommend using
|
|
1006
|
+
* {@link realMapTag} to guarantee the absence of problems and side effects.
|
|
1007
|
+
*
|
|
1008
|
+
* @example
|
|
1009
|
+
* Enable {@link realMapTag}:
|
|
1010
|
+
*
|
|
1011
|
+
* ```javascript
|
|
1012
|
+
* import { load, CORE_SCHEMA, realMapTag } from 'js-yaml'
|
|
1013
|
+
*
|
|
1014
|
+
* try {
|
|
1015
|
+
* load(data, { schema: CORE_SCHEMA.withTags(realMapTag) })
|
|
1016
|
+
* } catch (e) {
|
|
1017
|
+
* console.error(e)
|
|
1018
|
+
* }
|
|
1019
|
+
* ```
|
|
1020
|
+
*
|
|
1021
|
+
* @category Tags
|
|
1022
|
+
*/
|
|
739
1023
|
var realMapTag = defineMappingTag("tag:yaml.org,2002:map", {
|
|
740
1024
|
create: () => /* @__PURE__ */ new Map(),
|
|
741
1025
|
addPair: (container, key, value) => {
|
|
@@ -768,6 +1052,13 @@ function normalizeKey(key) {
|
|
|
768
1052
|
if (typeof key === "object" && Object.prototype.toString.call(key) === "[object Object]") return "[object Object]";
|
|
769
1053
|
return String(key);
|
|
770
1054
|
}
|
|
1055
|
+
/**
|
|
1056
|
+
* This implementation exists solely to reproduce v4 behavior exactly. Its use
|
|
1057
|
+
* is strongly discouraged. If complex or non-string keys are needed, use
|
|
1058
|
+
* {@link realMapTag} instead.
|
|
1059
|
+
*
|
|
1060
|
+
* @category Tags
|
|
1061
|
+
*/
|
|
771
1062
|
var legacyMapTag = defineMappingTag("tag:yaml.org,2002:map", {
|
|
772
1063
|
create: () => ({}),
|
|
773
1064
|
identify: isPlainObject,
|
|
@@ -872,9 +1163,19 @@ function formatError(exception, compact) {
|
|
|
872
1163
|
if (!compact && exception.mark.snippet) where += `\n\n${exception.mark.snippet}`;
|
|
873
1164
|
return `${exception.reason} ${where}`;
|
|
874
1165
|
}
|
|
875
|
-
|
|
1166
|
+
/**
|
|
1167
|
+
* A YAML error. Unlike an ordinary `Error`, it adds a source snippet showing
|
|
1168
|
+
* the location of the problem to the error message, when available.
|
|
1169
|
+
*
|
|
1170
|
+
* @category Main
|
|
1171
|
+
*/
|
|
1172
|
+
var YAMLException = class YAMLException extends Error {
|
|
876
1173
|
reason;
|
|
877
1174
|
mark;
|
|
1175
|
+
/**
|
|
1176
|
+
* Optional `mark` contains source snippet data. Usually, use
|
|
1177
|
+
* {@link YAMLException.throwAt} instead of passing it directly.
|
|
1178
|
+
*/
|
|
878
1179
|
constructor(reason, mark) {
|
|
879
1180
|
super();
|
|
880
1181
|
this.name = "YAMLException";
|
|
@@ -883,52 +1184,71 @@ var YAMLException = class extends Error {
|
|
|
883
1184
|
this.message = formatError(this, false);
|
|
884
1185
|
if (Error.captureStackTrace) Error.captureStackTrace(this, this.constructor);
|
|
885
1186
|
}
|
|
1187
|
+
/**
|
|
1188
|
+
* Returns the formatted error, omitting the source snippet in compact mode.
|
|
1189
|
+
*/
|
|
886
1190
|
toString(compact) {
|
|
887
1191
|
return `${this.name}: ${formatError(this, compact)}`;
|
|
888
1192
|
}
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
1193
|
+
/**
|
|
1194
|
+
* Builds a YAMLException with a source snippet and throws it. `source` is
|
|
1195
|
+
* the raw input text; `position` is an offset into it.
|
|
1196
|
+
*/
|
|
1197
|
+
static throwAt(source, position, message, filename = "") {
|
|
1198
|
+
let line = 0;
|
|
1199
|
+
let lineStart = 0;
|
|
1200
|
+
for (let index = 0; index < position; index++) {
|
|
1201
|
+
const ch = source.charCodeAt(index);
|
|
1202
|
+
if (ch === 10) {
|
|
1203
|
+
line++;
|
|
1204
|
+
lineStart = index + 1;
|
|
1205
|
+
} else if (ch === 13) {
|
|
1206
|
+
line++;
|
|
1207
|
+
if (source.charCodeAt(index + 1) === 10) index++;
|
|
1208
|
+
lineStart = index + 1;
|
|
1209
|
+
}
|
|
902
1210
|
}
|
|
1211
|
+
const mark = {
|
|
1212
|
+
name: filename,
|
|
1213
|
+
buffer: source,
|
|
1214
|
+
position,
|
|
1215
|
+
line,
|
|
1216
|
+
column: position - lineStart
|
|
1217
|
+
};
|
|
1218
|
+
mark.snippet = makeSnippet(mark);
|
|
1219
|
+
throw new YAMLException(message, mark);
|
|
903
1220
|
}
|
|
904
|
-
|
|
905
|
-
name: filename,
|
|
906
|
-
buffer: source,
|
|
907
|
-
position,
|
|
908
|
-
line,
|
|
909
|
-
column: position - lineStart
|
|
910
|
-
};
|
|
911
|
-
mark.snippet = makeSnippet(mark);
|
|
912
|
-
throw new YAMLException(message, mark);
|
|
913
|
-
}
|
|
1221
|
+
};
|
|
914
1222
|
//#endregion
|
|
915
1223
|
//#region src/parser/events.ts
|
|
916
|
-
|
|
917
|
-
var
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
var
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
1224
|
+
/** @category Events */
|
|
1225
|
+
var EVENT_ID = {
|
|
1226
|
+
DOCUMENT: 1,
|
|
1227
|
+
SEQUENCE: 2,
|
|
1228
|
+
MAPPING: 3,
|
|
1229
|
+
SCALAR: 4,
|
|
1230
|
+
ALIAS: 5,
|
|
1231
|
+
POP: 6
|
|
1232
|
+
};
|
|
1233
|
+
/** @category Nodes */
|
|
1234
|
+
var SCALAR_STYLE = {
|
|
1235
|
+
PLAIN: 1,
|
|
1236
|
+
SINGLE_QUOTED: 2,
|
|
1237
|
+
DOUBLE_QUOTED: 3,
|
|
1238
|
+
LITERAL_BLOCK: 4,
|
|
1239
|
+
FOLDED_BLOCK: 5
|
|
1240
|
+
};
|
|
1241
|
+
/** @category Nodes */
|
|
1242
|
+
var COLLECTION_STYLE = {
|
|
1243
|
+
BLOCK: 1,
|
|
1244
|
+
FLOW: 2
|
|
1245
|
+
};
|
|
1246
|
+
/** @category Nodes */
|
|
1247
|
+
var CHOMPING_MODE = {
|
|
1248
|
+
CLIP: 1,
|
|
1249
|
+
STRIP: 2,
|
|
1250
|
+
KEEP: 3
|
|
1251
|
+
};
|
|
932
1252
|
//#endregion
|
|
933
1253
|
//#region src/parser/parser_scalar.ts
|
|
934
1254
|
var NO_RANGE$3 = -1;
|
|
@@ -1109,21 +1429,26 @@ function getBlockValue(input, start, end, indent, chomping, folded) {
|
|
|
1109
1429
|
didReadContent = true;
|
|
1110
1430
|
emptyLines = 0;
|
|
1111
1431
|
}
|
|
1112
|
-
if (chomping ===
|
|
1113
|
-
else if (chomping !==
|
|
1432
|
+
if (chomping === CHOMPING_MODE.KEEP) result += "\n".repeat(didReadContent ? 1 + emptyLines : emptyLines);
|
|
1433
|
+
else if (chomping !== CHOMPING_MODE.STRIP) {
|
|
1114
1434
|
if (didReadContent) result += "\n";
|
|
1115
1435
|
}
|
|
1116
1436
|
return result;
|
|
1117
1437
|
}
|
|
1438
|
+
/**
|
|
1439
|
+
* Decodes the scalar referenced by event offsets in `input`.
|
|
1440
|
+
*
|
|
1441
|
+
* @category Events
|
|
1442
|
+
*/
|
|
1118
1443
|
function getScalarValue(input, scalar) {
|
|
1119
1444
|
if (scalar.valueStart === NO_RANGE$3) return "";
|
|
1120
1445
|
const { valueStart, valueEnd } = scalar;
|
|
1121
1446
|
if (scalar.fast) return input.slice(valueStart, valueEnd);
|
|
1122
1447
|
switch (scalar.style) {
|
|
1123
|
-
case
|
|
1124
|
-
case
|
|
1125
|
-
case
|
|
1126
|
-
case
|
|
1448
|
+
case SCALAR_STYLE.SINGLE_QUOTED: return getSingleQuotedValue(input, valueStart, valueEnd);
|
|
1449
|
+
case SCALAR_STYLE.DOUBLE_QUOTED: return getDoubleQuotedValue(input, valueStart, valueEnd);
|
|
1450
|
+
case SCALAR_STYLE.LITERAL_BLOCK: return getBlockValue(input, valueStart, valueEnd, scalar.indent, scalar.chomping, false);
|
|
1451
|
+
case SCALAR_STYLE.FOLDED_BLOCK: return getBlockValue(input, valueStart, valueEnd, scalar.indent, scalar.chomping, true);
|
|
1127
1452
|
default: return getPlainValue(input, valueStart, valueEnd);
|
|
1128
1453
|
}
|
|
1129
1454
|
}
|
|
@@ -1155,6 +1480,7 @@ function tagNameShort(fullTag) {
|
|
|
1155
1480
|
//#endregion
|
|
1156
1481
|
//#region src/parser/constructor.ts
|
|
1157
1482
|
var NO_RANGE$2 = -1;
|
|
1483
|
+
var MERGE_TAG_NAME = "tag:yaml.org,2002:merge";
|
|
1158
1484
|
var DEFAULT_CONSTRUCTOR_OPTIONS = {
|
|
1159
1485
|
filename: "",
|
|
1160
1486
|
schema: CORE_SCHEMA,
|
|
@@ -1170,26 +1496,16 @@ function eventPosition$1(event) {
|
|
|
1170
1496
|
return 0;
|
|
1171
1497
|
}
|
|
1172
1498
|
function throwError$1(state, message) {
|
|
1173
|
-
|
|
1499
|
+
YAMLException.throwAt(state.source, state.position, message, state.filename);
|
|
1174
1500
|
}
|
|
1175
1501
|
function finalizeCollection(state, position, tag, carrier) {
|
|
1176
1502
|
try {
|
|
1177
1503
|
return tag.finalize(carrier);
|
|
1178
1504
|
} catch (error) {
|
|
1179
1505
|
if (error instanceof YAMLException) throw error;
|
|
1180
|
-
|
|
1506
|
+
YAMLException.throwAt(state.source, position, error instanceof Error ? error.message : String(error), state.filename);
|
|
1181
1507
|
}
|
|
1182
1508
|
}
|
|
1183
|
-
function lookupTag(exact, prefix, tagName) {
|
|
1184
|
-
const exactTag = exact[tagName];
|
|
1185
|
-
if (exactTag) return exactTag;
|
|
1186
|
-
for (const tag of prefix) if (tagName.startsWith(tag.tagName)) return tag;
|
|
1187
|
-
}
|
|
1188
|
-
function findExplicitTag(state, exact, prefix, tagName, nodeKind) {
|
|
1189
|
-
const tag = lookupTag(exact, prefix, tagName);
|
|
1190
|
-
if (tag) return tag;
|
|
1191
|
-
throwError$1(state, `unknown ${nodeKind} tag !<${tagName}>`);
|
|
1192
|
-
}
|
|
1193
1509
|
function constructScalar(state, event) {
|
|
1194
1510
|
const source = getScalarValue(state.source, event);
|
|
1195
1511
|
const rawTag = event.tagStart === NO_RANGE$2 ? "" : state.source.slice(event.tagStart, event.tagEnd);
|
|
@@ -1200,7 +1516,7 @@ function constructScalar(state, event) {
|
|
|
1200
1516
|
tag: strTag
|
|
1201
1517
|
};
|
|
1202
1518
|
const tagName = tagNameFull(rawTag, state.tagHandlers);
|
|
1203
|
-
const scalarTag =
|
|
1519
|
+
const scalarTag = state.schema.lookupScalarTag(tagName);
|
|
1204
1520
|
if (scalarTag) {
|
|
1205
1521
|
const result = scalarTag.resolve(source, true, tagName);
|
|
1206
1522
|
if (result === NOT_RESOLVED) throwError$1(state, `cannot resolve a node with !<${tagName}> explicit tag`);
|
|
@@ -1209,7 +1525,7 @@ function constructScalar(state, event) {
|
|
|
1209
1525
|
tag: scalarTag
|
|
1210
1526
|
};
|
|
1211
1527
|
}
|
|
1212
|
-
const collectionTagDef =
|
|
1528
|
+
const collectionTagDef = state.schema.lookupMappingTag(tagName) ?? state.schema.lookupSequenceTag(tagName);
|
|
1213
1529
|
if (collectionTagDef) {
|
|
1214
1530
|
if (source !== "") throwError$1(state, `cannot resolve a node with !<${tagName}> explicit tag`);
|
|
1215
1531
|
const carrier = collectionTagDef.create(tagName);
|
|
@@ -1220,50 +1536,49 @@ function constructScalar(state, event) {
|
|
|
1220
1536
|
}
|
|
1221
1537
|
throwError$1(state, `unknown scalar tag !<${tagName}>`);
|
|
1222
1538
|
}
|
|
1223
|
-
if (event.style ===
|
|
1224
|
-
const candidates = state.schema.implicitScalarByFirstChar.get(source.charAt(0)) ?? state.schema.implicitScalarAnyFirstChar;
|
|
1225
|
-
for (const tag of candidates) {
|
|
1226
|
-
const result = tag.resolve(source, false, tag.tagName);
|
|
1227
|
-
if (result !== NOT_RESOLVED) return {
|
|
1228
|
-
value: result,
|
|
1229
|
-
tag
|
|
1230
|
-
};
|
|
1231
|
-
}
|
|
1232
|
-
}
|
|
1539
|
+
if (event.style === SCALAR_STYLE.PLAIN) return state.schema.resolveImplicitScalarTag(source);
|
|
1233
1540
|
return {
|
|
1234
1541
|
value: strTag.resolve(source, false, strTag.tagName),
|
|
1235
1542
|
tag: strTag
|
|
1236
1543
|
};
|
|
1237
1544
|
}
|
|
1238
|
-
function
|
|
1545
|
+
function collectionTagName(state, event, defaultTagName) {
|
|
1239
1546
|
const rawTag = event.tagStart === NO_RANGE$2 ? "" : state.source.slice(event.tagStart, event.tagEnd);
|
|
1240
|
-
|
|
1241
|
-
return {
|
|
1242
|
-
tagName,
|
|
1243
|
-
tag: findExplicitTag(state, exact, prefix, tagName, nodeKind)
|
|
1244
|
-
};
|
|
1547
|
+
return rawTag === "" || rawTag === "!" ? defaultTagName : tagNameFull(rawTag, state.tagHandlers);
|
|
1245
1548
|
}
|
|
1246
1549
|
function isMappingTag(tag) {
|
|
1247
1550
|
return tag.nodeKind === "mapping";
|
|
1248
1551
|
}
|
|
1552
|
+
function chargeMergeWork(state) {
|
|
1553
|
+
state.totalMergeKeys++;
|
|
1554
|
+
if (state.maxTotalMergeKeys !== -1 && state.totalMergeKeys > state.maxTotalMergeKeys) throwError$1(state, `merge keys exceeded maxTotalMergeKeys (${state.maxTotalMergeKeys})`);
|
|
1555
|
+
}
|
|
1249
1556
|
function mergeKeys(state, frame, source, sourceTag) {
|
|
1557
|
+
chargeMergeWork(state);
|
|
1250
1558
|
for (const sourceKey of sourceTag.keys(source)) {
|
|
1251
|
-
|
|
1559
|
+
chargeMergeWork(state);
|
|
1252
1560
|
if (frame.tag.has(frame.value, sourceKey)) continue;
|
|
1253
1561
|
const err = frame.tag.addPair(frame.value, sourceKey, sourceTag.get(source, sourceKey));
|
|
1254
1562
|
if (err) throwError$1(state, err);
|
|
1255
|
-
|
|
1563
|
+
frame.overridable ??= /* @__PURE__ */ new Set();
|
|
1564
|
+
frame.overridable.add(sourceKey);
|
|
1256
1565
|
}
|
|
1257
1566
|
}
|
|
1258
1567
|
function mergeSource(state, frame, source, sourceTag) {
|
|
1259
1568
|
state.position = frame.keyPosition;
|
|
1260
1569
|
if (isMappingTag(sourceTag)) mergeKeys(state, frame, source, sourceTag);
|
|
1261
|
-
else if (sourceTag.nodeKind === "sequence" && Array.isArray(source))
|
|
1262
|
-
|
|
1570
|
+
else if (sourceTag.nodeKind === "sequence" && Array.isArray(source)) {
|
|
1571
|
+
if (source.length > 100) throwError$1(state, "abnormal merge sequence size");
|
|
1572
|
+
for (const element of source) {
|
|
1573
|
+
const elementTag = state.nodeTags.get(element);
|
|
1574
|
+
if (!elementTag) throwError$1(state, "cannot merge mappings; the provided source object is unacceptable");
|
|
1575
|
+
mergeKeys(state, frame, element, elementTag);
|
|
1576
|
+
}
|
|
1577
|
+
} else throwError$1(state, "cannot merge mappings; the provided source object is unacceptable");
|
|
1263
1578
|
}
|
|
1264
1579
|
function addMappingValue(state, frame, key, value, tag) {
|
|
1265
1580
|
state.position = frame.keyPosition;
|
|
1266
|
-
if (
|
|
1581
|
+
if (frame.keyIsMerge) {
|
|
1267
1582
|
mergeSource(state, frame, value, tag);
|
|
1268
1583
|
return;
|
|
1269
1584
|
}
|
|
@@ -1278,9 +1593,7 @@ function addValue(state, value, tag) {
|
|
|
1278
1593
|
frame.value = value;
|
|
1279
1594
|
frame.hasValue = true;
|
|
1280
1595
|
} else if (frame.kind === "sequence") {
|
|
1281
|
-
if (
|
|
1282
|
-
if (!isMappingTag(tag)) throwError$1(state, "cannot merge mappings; the provided source object is unacceptable");
|
|
1283
|
-
}
|
|
1596
|
+
if (isMappingTag(tag)) state.nodeTags.set(value, tag);
|
|
1284
1597
|
const err = frame.tag.addItem(frame.value, value, frame.index++);
|
|
1285
1598
|
if (err) throwError$1(state, err);
|
|
1286
1599
|
} else if (frame.hasKey) {
|
|
@@ -1292,6 +1605,7 @@ function addValue(state, value, tag) {
|
|
|
1292
1605
|
frame.key = value;
|
|
1293
1606
|
frame.keyPosition = state.position;
|
|
1294
1607
|
frame.hasKey = true;
|
|
1608
|
+
frame.keyIsMerge = tag.tagName === MERGE_TAG_NAME;
|
|
1295
1609
|
}
|
|
1296
1610
|
}
|
|
1297
1611
|
function storeAnchor(state, event, value, tag, isValueFinal) {
|
|
@@ -1306,6 +1620,12 @@ function storeAnchor(state, event, value, tag, isValueFinal) {
|
|
|
1306
1620
|
}
|
|
1307
1621
|
return null;
|
|
1308
1622
|
}
|
|
1623
|
+
/**
|
|
1624
|
+
* Constructs JavaScript documents directly from parser events, without an
|
|
1625
|
+
* intermediate AST.
|
|
1626
|
+
*
|
|
1627
|
+
* @category Events
|
|
1628
|
+
*/
|
|
1309
1629
|
function constructFromEvents(events, options) {
|
|
1310
1630
|
const state = {
|
|
1311
1631
|
...DEFAULT_CONSTRUCTOR_OPTIONS,
|
|
@@ -1316,6 +1636,7 @@ function constructFromEvents(events, options) {
|
|
|
1316
1636
|
position: 0,
|
|
1317
1637
|
frames: [],
|
|
1318
1638
|
anchors: /* @__PURE__ */ new Map(),
|
|
1639
|
+
nodeTags: /* @__PURE__ */ new Map(),
|
|
1319
1640
|
tagHandlers: Object.create(null),
|
|
1320
1641
|
totalMergeKeys: 0,
|
|
1321
1642
|
aliasCount: 0
|
|
@@ -1324,8 +1645,9 @@ function constructFromEvents(events, options) {
|
|
|
1324
1645
|
const event = state.events[state.eventIndex++];
|
|
1325
1646
|
state.position = eventPosition$1(event);
|
|
1326
1647
|
switch (event.type) {
|
|
1327
|
-
case
|
|
1648
|
+
case EVENT_ID.DOCUMENT:
|
|
1328
1649
|
state.anchors = /* @__PURE__ */ new Map();
|
|
1650
|
+
state.nodeTags = /* @__PURE__ */ new Map();
|
|
1329
1651
|
state.aliasCount = 0;
|
|
1330
1652
|
state.tagHandlers = Object.create(null);
|
|
1331
1653
|
for (const directive of event.directives) if (directive.kind === "tag") state.tagHandlers[directive.handle] = directive.prefix;
|
|
@@ -1336,47 +1658,49 @@ function constructFromEvents(events, options) {
|
|
|
1336
1658
|
hasValue: false
|
|
1337
1659
|
});
|
|
1338
1660
|
break;
|
|
1339
|
-
case
|
|
1661
|
+
case EVENT_ID.SCALAR: {
|
|
1340
1662
|
const { value, tag } = constructScalar(state, event);
|
|
1341
1663
|
storeAnchor(state, event, value, tag, true);
|
|
1342
1664
|
addValue(state, value, tag);
|
|
1343
1665
|
break;
|
|
1344
1666
|
}
|
|
1345
|
-
case
|
|
1346
|
-
const
|
|
1347
|
-
const
|
|
1348
|
-
|
|
1349
|
-
const
|
|
1350
|
-
const
|
|
1667
|
+
case EVENT_ID.SEQUENCE: {
|
|
1668
|
+
const tagName = collectionTagName(state, event, "tag:yaml.org,2002:seq");
|
|
1669
|
+
const tag = state.schema.lookupSequenceTag(tagName);
|
|
1670
|
+
if (!tag) throwError$1(state, `unknown sequence tag !<${tagName}>`);
|
|
1671
|
+
const value = tag.create(tagName);
|
|
1672
|
+
const anchor = storeAnchor(state, event, value, tag, tag.carrierIsResult);
|
|
1351
1673
|
state.frames.push({
|
|
1352
1674
|
kind: "sequence",
|
|
1353
1675
|
position: state.position,
|
|
1354
1676
|
value,
|
|
1355
|
-
tag
|
|
1677
|
+
tag,
|
|
1356
1678
|
anchor,
|
|
1357
|
-
index: 0
|
|
1358
|
-
merge
|
|
1679
|
+
index: 0
|
|
1359
1680
|
});
|
|
1360
1681
|
break;
|
|
1361
1682
|
}
|
|
1362
|
-
case
|
|
1363
|
-
const
|
|
1364
|
-
const
|
|
1365
|
-
|
|
1683
|
+
case EVENT_ID.MAPPING: {
|
|
1684
|
+
const tagName = collectionTagName(state, event, "tag:yaml.org,2002:map");
|
|
1685
|
+
const tag = state.schema.lookupMappingTag(tagName);
|
|
1686
|
+
if (!tag) throwError$1(state, `unknown mapping tag !<${tagName}>`);
|
|
1687
|
+
const value = tag.create(tagName);
|
|
1688
|
+
const anchor = storeAnchor(state, event, value, tag, tag.carrierIsResult);
|
|
1366
1689
|
state.frames.push({
|
|
1367
1690
|
kind: "mapping",
|
|
1368
1691
|
position: state.position,
|
|
1369
1692
|
value,
|
|
1370
|
-
tag
|
|
1693
|
+
tag,
|
|
1371
1694
|
anchor,
|
|
1372
1695
|
key: void 0,
|
|
1373
1696
|
keyPosition: state.position,
|
|
1374
1697
|
hasKey: false,
|
|
1698
|
+
keyIsMerge: false,
|
|
1375
1699
|
overridable: null
|
|
1376
1700
|
});
|
|
1377
1701
|
break;
|
|
1378
1702
|
}
|
|
1379
|
-
case
|
|
1703
|
+
case EVENT_ID.ALIAS: {
|
|
1380
1704
|
if (state.maxAliases !== -1 && ++state.aliasCount > state.maxAliases) throwError$1(state, `aliases exceeded maxAliases (${state.maxAliases})`);
|
|
1381
1705
|
const name = state.source.slice(event.anchorStart, event.anchorEnd);
|
|
1382
1706
|
const anchor = state.anchors.get(name);
|
|
@@ -1385,7 +1709,7 @@ function constructFromEvents(events, options) {
|
|
|
1385
1709
|
addValue(state, anchor.value, anchor.tag);
|
|
1386
1710
|
break;
|
|
1387
1711
|
}
|
|
1388
|
-
case
|
|
1712
|
+
case EVENT_ID.POP: {
|
|
1389
1713
|
const frame = state.frames.pop();
|
|
1390
1714
|
if (frame.kind === "mapping" && frame.hasKey) {
|
|
1391
1715
|
state.position = frame.keyPosition;
|
|
@@ -1428,7 +1752,7 @@ var DEFAULT_PARSER_OPTIONS = {
|
|
|
1428
1752
|
};
|
|
1429
1753
|
function addDocumentEvent(state, explicitStart, explicitEnd) {
|
|
1430
1754
|
state.events.push({
|
|
1431
|
-
type:
|
|
1755
|
+
type: EVENT_ID.DOCUMENT,
|
|
1432
1756
|
explicitStart,
|
|
1433
1757
|
explicitEnd,
|
|
1434
1758
|
directives: state.directives
|
|
@@ -1436,7 +1760,7 @@ function addDocumentEvent(state, explicitStart, explicitEnd) {
|
|
|
1436
1760
|
}
|
|
1437
1761
|
function addSequenceEvent(state, start, anchorStart, anchorEnd, tagStart, tagEnd, style) {
|
|
1438
1762
|
state.events.push({
|
|
1439
|
-
type:
|
|
1763
|
+
type: EVENT_ID.SEQUENCE,
|
|
1440
1764
|
start,
|
|
1441
1765
|
anchorStart,
|
|
1442
1766
|
anchorEnd,
|
|
@@ -1447,7 +1771,7 @@ function addSequenceEvent(state, start, anchorStart, anchorEnd, tagStart, tagEnd
|
|
|
1447
1771
|
}
|
|
1448
1772
|
function addMappingEvent(state, start, anchorStart, anchorEnd, tagStart, tagEnd, style) {
|
|
1449
1773
|
state.events.push({
|
|
1450
|
-
type:
|
|
1774
|
+
type: EVENT_ID.MAPPING,
|
|
1451
1775
|
start,
|
|
1452
1776
|
anchorStart,
|
|
1453
1777
|
anchorEnd,
|
|
@@ -1458,18 +1782,18 @@ function addMappingEvent(state, start, anchorStart, anchorEnd, tagStart, tagEnd,
|
|
|
1458
1782
|
}
|
|
1459
1783
|
function insertFlowPairMappingEvent(state, snapshot) {
|
|
1460
1784
|
state.events.splice(snapshot.eventsLength, 0, {
|
|
1461
|
-
type:
|
|
1785
|
+
type: EVENT_ID.MAPPING,
|
|
1462
1786
|
start: snapshot.position,
|
|
1463
1787
|
anchorStart: NO_RANGE$1,
|
|
1464
1788
|
anchorEnd: NO_RANGE$1,
|
|
1465
1789
|
tagStart: NO_RANGE$1,
|
|
1466
1790
|
tagEnd: NO_RANGE$1,
|
|
1467
|
-
style:
|
|
1791
|
+
style: COLLECTION_STYLE.FLOW
|
|
1468
1792
|
});
|
|
1469
1793
|
}
|
|
1470
|
-
function addScalarEvent(state, valueStart, valueEnd, anchorStart, anchorEnd, tagStart, tagEnd, style, chomping =
|
|
1794
|
+
function addScalarEvent(state, valueStart, valueEnd, anchorStart, anchorEnd, tagStart, tagEnd, style, chomping = CHOMPING_MODE.CLIP, indent = -1, fast = false) {
|
|
1471
1795
|
state.events.push({
|
|
1472
|
-
type:
|
|
1796
|
+
type: EVENT_ID.SCALAR,
|
|
1473
1797
|
valueStart,
|
|
1474
1798
|
valueEnd,
|
|
1475
1799
|
anchorStart,
|
|
@@ -1484,16 +1808,16 @@ function addScalarEvent(state, valueStart, valueEnd, anchorStart, anchorEnd, tag
|
|
|
1484
1808
|
}
|
|
1485
1809
|
function addAliasEvent(state, anchorStart, anchorEnd) {
|
|
1486
1810
|
state.events.push({
|
|
1487
|
-
type:
|
|
1811
|
+
type: EVENT_ID.ALIAS,
|
|
1488
1812
|
anchorStart,
|
|
1489
1813
|
anchorEnd
|
|
1490
1814
|
});
|
|
1491
1815
|
}
|
|
1492
1816
|
function addPopEvent(state) {
|
|
1493
|
-
state.events.push({ type:
|
|
1817
|
+
state.events.push({ type: EVENT_ID.POP });
|
|
1494
1818
|
}
|
|
1495
1819
|
function addEmptyScalarEvent(state) {
|
|
1496
|
-
addScalarEvent(state, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1,
|
|
1820
|
+
addScalarEvent(state, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, SCALAR_STYLE.PLAIN);
|
|
1497
1821
|
}
|
|
1498
1822
|
function emptyProperties() {
|
|
1499
1823
|
return {
|
|
@@ -1522,7 +1846,7 @@ function restoreState(state, snapshot) {
|
|
|
1522
1846
|
state.events.length = snapshot.eventsLength;
|
|
1523
1847
|
}
|
|
1524
1848
|
function throwError(state, message) {
|
|
1525
|
-
|
|
1849
|
+
YAMLException.throwAt(state.input.slice(0, state.length), state.position, message, state.filename);
|
|
1526
1850
|
}
|
|
1527
1851
|
function isEol(c) {
|
|
1528
1852
|
return c === 10 || c === 13;
|
|
@@ -1601,6 +1925,24 @@ function testDocumentSeparator(state, position = state.position) {
|
|
|
1601
1925
|
}
|
|
1602
1926
|
return false;
|
|
1603
1927
|
}
|
|
1928
|
+
function skipByteOrderMark(state) {
|
|
1929
|
+
if (state.position === state.lineStart && state.input.charCodeAt(state.position) === 65279) {
|
|
1930
|
+
state.position++;
|
|
1931
|
+
state.lineStart = state.position;
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
function testDocumentBoundary(state) {
|
|
1935
|
+
if (state.position !== state.lineStart) return false;
|
|
1936
|
+
if (testDocumentSeparator(state)) return true;
|
|
1937
|
+
if (state.input.charCodeAt(state.position) !== 65279) return false;
|
|
1938
|
+
const snapshot = snapshotState(state);
|
|
1939
|
+
skipByteOrderMark(state);
|
|
1940
|
+
skipSeparationSpace(state, true);
|
|
1941
|
+
const ch = state.input.charCodeAt(state.position);
|
|
1942
|
+
const result = state.position === state.lineStart && (ch === 37 || ch === 45 && testDocumentSeparator(state));
|
|
1943
|
+
restoreState(state, snapshot);
|
|
1944
|
+
return result;
|
|
1945
|
+
}
|
|
1604
1946
|
function skipUntilLineEnd(state) {
|
|
1605
1947
|
let ch = state.input.charCodeAt(state.position);
|
|
1606
1948
|
while (ch !== 0 && !isEol(ch)) ch = state.input.charCodeAt(++state.position);
|
|
@@ -1690,7 +2032,7 @@ function readSingleQuotedScalar(state, nodeIndent, props) {
|
|
|
1690
2032
|
}
|
|
1691
2033
|
const end = state.position;
|
|
1692
2034
|
state.position++;
|
|
1693
|
-
addScalarEvent(state, start, end, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd,
|
|
2035
|
+
addScalarEvent(state, start, end, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, SCALAR_STYLE.SINGLE_QUOTED, CHOMPING_MODE.CLIP, -1, simple);
|
|
1694
2036
|
return true;
|
|
1695
2037
|
}
|
|
1696
2038
|
if (isEol(ch)) {
|
|
@@ -1712,7 +2054,7 @@ function readDoubleQuotedScalar(state, nodeIndent, props) {
|
|
|
1712
2054
|
if (ch === 34) {
|
|
1713
2055
|
const end = state.position;
|
|
1714
2056
|
state.position++;
|
|
1715
|
-
addScalarEvent(state, start, end, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd,
|
|
2057
|
+
addScalarEvent(state, start, end, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, SCALAR_STYLE.DOUBLE_QUOTED, CHOMPING_MODE.CLIP, -1, simple);
|
|
1716
2058
|
return true;
|
|
1717
2059
|
}
|
|
1718
2060
|
if (ch === 92) {
|
|
@@ -1740,18 +2082,18 @@ function readDoubleQuotedScalar(state, nodeIndent, props) {
|
|
|
1740
2082
|
}
|
|
1741
2083
|
function readBlockScalar(state, parentIndent, props) {
|
|
1742
2084
|
const ch = state.input.charCodeAt(state.position);
|
|
1743
|
-
let chomping =
|
|
2085
|
+
let chomping = CHOMPING_MODE.CLIP;
|
|
1744
2086
|
let indent = -1;
|
|
1745
2087
|
let detectedIndent = false;
|
|
1746
2088
|
if (ch !== 124 && ch !== 62) return false;
|
|
1747
|
-
const style = ch === 124 ?
|
|
2089
|
+
const style = ch === 124 ? SCALAR_STYLE.LITERAL_BLOCK : SCALAR_STYLE.FOLDED_BLOCK;
|
|
1748
2090
|
state.position++;
|
|
1749
2091
|
while (state.input.charCodeAt(state.position) !== 0) {
|
|
1750
2092
|
const current = state.input.charCodeAt(state.position);
|
|
1751
2093
|
const digit = fromDecimalCode(current);
|
|
1752
2094
|
if (current === 43 || current === 45) {
|
|
1753
|
-
if (chomping !==
|
|
1754
|
-
chomping = current === 43 ?
|
|
2095
|
+
if (chomping !== CHOMPING_MODE.CLIP) throwError(state, "repeat of a chomping mode identifier");
|
|
2096
|
+
chomping = current === 43 ? CHOMPING_MODE.KEEP : CHOMPING_MODE.STRIP;
|
|
1755
2097
|
state.position++;
|
|
1756
2098
|
} else if (digit >= 0) {
|
|
1757
2099
|
if (digit === 0) throwError(state, "bad explicit indentation width of a block scalar; it cannot be less than one");
|
|
@@ -1784,7 +2126,7 @@ function readBlockScalar(state, parentIndent, props) {
|
|
|
1784
2126
|
} else if (column > 0) valueEnd = linePosition + column;
|
|
1785
2127
|
break;
|
|
1786
2128
|
}
|
|
1787
|
-
if (
|
|
2129
|
+
if (testDocumentBoundary(state)) break;
|
|
1788
2130
|
if (!detectedIndent && contentIndent === -1 && isEol(first)) maxLeadingIndent = Math.max(maxLeadingIndent, column);
|
|
1789
2131
|
if (!detectedIndent && contentIndent === -1 && !isEol(first)) {
|
|
1790
2132
|
if (first === 9 && column < parentIndent) {
|
|
@@ -1837,7 +2179,7 @@ function readPlainScalar(state, nodeIndent, nodeContext, props) {
|
|
|
1837
2179
|
const inFlow = nodeContext === CONTEXT_FLOW_IN;
|
|
1838
2180
|
let multiline = false;
|
|
1839
2181
|
while (ch !== 0) {
|
|
1840
|
-
if (
|
|
2182
|
+
if (testDocumentBoundary(state)) break;
|
|
1841
2183
|
if (ch === 58) {
|
|
1842
2184
|
const following = state.input.charCodeAt(state.position + 1);
|
|
1843
2185
|
if (isWsOrEolOrEnd(following) || inFlow && isFlowIndicator(following)) break;
|
|
@@ -1866,7 +2208,7 @@ function readPlainScalar(state, nodeIndent, nodeContext, props) {
|
|
|
1866
2208
|
}
|
|
1867
2209
|
if (end === start) return false;
|
|
1868
2210
|
checkPrintable(state, start, end);
|
|
1869
|
-
addScalarEvent(state, start, end, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd,
|
|
2211
|
+
addScalarEvent(state, start, end, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, SCALAR_STYLE.PLAIN, CHOMPING_MODE.CLIP, -1, !multiline);
|
|
1870
2212
|
return true;
|
|
1871
2213
|
}
|
|
1872
2214
|
function skipFlowSeparationSpace(state, nodeIndent) {
|
|
@@ -1881,8 +2223,8 @@ function readFlowCollection(state, nodeIndent, props) {
|
|
|
1881
2223
|
let readNext = true;
|
|
1882
2224
|
if (ch !== 91 && ch !== 123) return false;
|
|
1883
2225
|
const terminator = isMapping ? 125 : 93;
|
|
1884
|
-
if (isMapping) addMappingEvent(state, start, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd,
|
|
1885
|
-
else addSequenceEvent(state, start, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd,
|
|
2226
|
+
if (isMapping) addMappingEvent(state, start, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, COLLECTION_STYLE.FLOW);
|
|
2227
|
+
else addSequenceEvent(state, start, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, COLLECTION_STYLE.FLOW);
|
|
1886
2228
|
state.position++;
|
|
1887
2229
|
while (state.input.charCodeAt(state.position) !== 0) {
|
|
1888
2230
|
skipFlowSeparationSpace(state, nodeIndent);
|
|
@@ -1936,7 +2278,7 @@ function readFlowCollection(state, nodeIndent, props) {
|
|
|
1936
2278
|
}
|
|
1937
2279
|
function readBlockSequence(state, nodeIndent, props) {
|
|
1938
2280
|
if (state.firstTabInLine !== -1 || state.input.charCodeAt(state.position) !== 45 || !isWsOrEolOrEnd(state.input.charCodeAt(state.position + 1))) return false;
|
|
1939
|
-
addSequenceEvent(state, state.position, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd,
|
|
2281
|
+
addSequenceEvent(state, state.position, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, COLLECTION_STYLE.BLOCK);
|
|
1940
2282
|
while (state.input.charCodeAt(state.position) === 45 && isWsOrEolOrEnd(state.input.charCodeAt(state.position + 1))) {
|
|
1941
2283
|
if (state.firstTabInLine !== -1) {
|
|
1942
2284
|
state.position = state.firstTabInLine;
|
|
@@ -1972,7 +2314,7 @@ function readBlockMapping(state, nodeIndent, flowIndent, props) {
|
|
|
1972
2314
|
const entryLine = state.line;
|
|
1973
2315
|
if ((ch === 63 || ch === 58) && isWsOrEolOrEnd(following)) {
|
|
1974
2316
|
if (!mappingOpened) {
|
|
1975
|
-
addMappingEvent(state, state.position, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd,
|
|
2317
|
+
addMappingEvent(state, state.position, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, COLLECTION_STYLE.BLOCK);
|
|
1976
2318
|
mappingOpened = true;
|
|
1977
2319
|
}
|
|
1978
2320
|
if (ch === 63) {
|
|
@@ -2002,7 +2344,7 @@ function readBlockMapping(state, nodeIndent, flowIndent, props) {
|
|
|
2002
2344
|
if (!isWsOrEolOrEnd(ch)) throwError(state, "a whitespace character is expected after the key-value separator within a block mapping");
|
|
2003
2345
|
if (!mappingOpened) {
|
|
2004
2346
|
restoreState(state, beforeKey);
|
|
2005
|
-
addMappingEvent(state, beforeKey.position, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd,
|
|
2347
|
+
addMappingEvent(state, beforeKey.position, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, COLLECTION_STYLE.BLOCK);
|
|
2006
2348
|
mappingOpened = true;
|
|
2007
2349
|
parseNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true);
|
|
2008
2350
|
ch = state.input.charCodeAt(state.position);
|
|
@@ -2070,7 +2412,7 @@ function parseNode(state, parentIndent, nodeContext, allowToSeek, allowCompact,
|
|
|
2070
2412
|
if (atNewLine && allowBlockStyles && (props.tagStart !== NO_RANGE$1 || props.anchorStart !== NO_RANGE$1) && (ch === 33 || ch === 38)) {
|
|
2071
2413
|
const fallbackState = snapshotState(state);
|
|
2072
2414
|
const flowIndent = parentIndent + 1;
|
|
2073
|
-
if (readBlockMapping(state, state.position - state.lineStart, flowIndent, props) && state.events[fallbackState.eventsLength]?.type ===
|
|
2415
|
+
if (readBlockMapping(state, state.position - state.lineStart, flowIndent, props) && state.events[fallbackState.eventsLength]?.type === EVENT_ID.MAPPING) {
|
|
2074
2416
|
state.depth--;
|
|
2075
2417
|
return true;
|
|
2076
2418
|
}
|
|
@@ -2098,7 +2440,7 @@ function parseNode(state, parentIndent, nodeContext, allowToSeek, allowCompact,
|
|
|
2098
2440
|
const fallbackState = snapshotState(state);
|
|
2099
2441
|
const propertyIndent = propertyStart.position - propertyStart.lineStart;
|
|
2100
2442
|
restoreState(state, propertyStart);
|
|
2101
|
-
if (readBlockMapping(state, propertyIndent, flowIndent, emptyProperties()) && state.events[fallbackState.eventsLength]?.type ===
|
|
2443
|
+
if (readBlockMapping(state, propertyIndent, flowIndent, emptyProperties()) && state.events[fallbackState.eventsLength]?.type === EVENT_ID.MAPPING) hasContent = true;
|
|
2102
2444
|
else restoreState(state, fallbackState);
|
|
2103
2445
|
}
|
|
2104
2446
|
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;
|
|
@@ -2107,7 +2449,7 @@ function parseNode(state, parentIndent, nodeContext, allowToSeek, allowCompact,
|
|
|
2107
2449
|
}
|
|
2108
2450
|
allowBlockScalars = allowBlockScalars && !hasContent;
|
|
2109
2451
|
if (!hasContent && (props.anchorStart !== NO_RANGE$1 || props.tagStart !== NO_RANGE$1 || allowBlockScalars)) {
|
|
2110
|
-
addScalarEvent(state, NO_RANGE$1, NO_RANGE$1, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd,
|
|
2452
|
+
addScalarEvent(state, NO_RANGE$1, NO_RANGE$1, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, SCALAR_STYLE.PLAIN);
|
|
2111
2453
|
hasContent = true;
|
|
2112
2454
|
}
|
|
2113
2455
|
state.depth--;
|
|
@@ -2192,10 +2534,15 @@ function readDocument(state) {
|
|
|
2192
2534
|
}
|
|
2193
2535
|
}
|
|
2194
2536
|
const documentEvent = state.events[documentEventIndex];
|
|
2195
|
-
if (documentEvent?.type ===
|
|
2537
|
+
if (documentEvent?.type === EVENT_ID.DOCUMENT) documentEvent.explicitEnd = explicitEnd;
|
|
2196
2538
|
addPopEvent(state);
|
|
2197
|
-
if (!explicitEnd && state.position < state.length && !(state
|
|
2539
|
+
if (!explicitEnd && state.position < state.length && !testDocumentBoundary(state)) throwError(state, "end of the stream or a document separator is expected");
|
|
2198
2540
|
}
|
|
2541
|
+
/**
|
|
2542
|
+
* Parses YAML into a flat event stream referencing source text by offsets.
|
|
2543
|
+
*
|
|
2544
|
+
* @category Events
|
|
2545
|
+
*/
|
|
2199
2546
|
function parseEvents(input, options) {
|
|
2200
2547
|
const length = input.length;
|
|
2201
2548
|
const state = {
|
|
@@ -2214,9 +2561,9 @@ function parseEvents(input, options) {
|
|
|
2214
2561
|
events: []
|
|
2215
2562
|
};
|
|
2216
2563
|
const nullpos = input.indexOf("\0");
|
|
2217
|
-
if (nullpos !== -1)
|
|
2218
|
-
if (state.input.charCodeAt(state.position) === 65279) state.position++;
|
|
2564
|
+
if (nullpos !== -1) YAMLException.throwAt(input, nullpos, "null byte is not allowed in input", state.filename);
|
|
2219
2565
|
while (state.position < state.length) {
|
|
2566
|
+
skipByteOrderMark(state);
|
|
2220
2567
|
skipSeparationSpace(state, true);
|
|
2221
2568
|
if (state.position >= state.length) break;
|
|
2222
2569
|
const documentStart = state.position;
|
|
@@ -2254,6 +2601,36 @@ function loadAll(input, iteratorOrOptions, options) {
|
|
|
2254
2601
|
if (iterator === null) return documents;
|
|
2255
2602
|
for (const document of documents) iterator(document);
|
|
2256
2603
|
}
|
|
2604
|
+
/**
|
|
2605
|
+
* Parses `string` as a single YAML document. Throws {@link YAMLException} on
|
|
2606
|
+
* error. This function does not understand multi-document or empty sources; it
|
|
2607
|
+
* throws an exception on those.
|
|
2608
|
+
*
|
|
2609
|
+
* > [!NOTE]
|
|
2610
|
+
* > 1. When processing untrusted input, see the
|
|
2611
|
+
* > [security considerations](../docs/safety.md).
|
|
2612
|
+
* > 2. All exceptions MUST be caught, not just {@link YAMLException}.
|
|
2613
|
+
* > 3. The default {@link CORE_SCHEMA} comes without the `!!merge` tag. You can
|
|
2614
|
+
* > easily enable it if needed.
|
|
2615
|
+
* > 4. The default {@link mapTag} is `{}`-object based, with known limitations
|
|
2616
|
+
* > (see description). For full compatibility use {@link realMapTag}
|
|
2617
|
+
* > instead (it uses native JS `Map`).
|
|
2618
|
+
*
|
|
2619
|
+
* @example
|
|
2620
|
+
* Enable {@link mergeTag} and {@link realMapTag}:
|
|
2621
|
+
*
|
|
2622
|
+
* ```javascript
|
|
2623
|
+
* import { load, CORE_SCHEMA, mergeTag, realMapTag } from 'js-yaml'
|
|
2624
|
+
*
|
|
2625
|
+
* try {
|
|
2626
|
+
* load(data, { schema: CORE_SCHEMA.withTags(mergeTag, realMapTag) })
|
|
2627
|
+
* } catch (e) {
|
|
2628
|
+
* console.error(e)
|
|
2629
|
+
* }
|
|
2630
|
+
* ```
|
|
2631
|
+
*
|
|
2632
|
+
* @category Main
|
|
2633
|
+
*/
|
|
2257
2634
|
function load(input, options) {
|
|
2258
2635
|
const documents = loadDocuments(input, options);
|
|
2259
2636
|
if (documents.length === 0) throw new YAMLException("expected a document, but the input is empty");
|
|
@@ -2261,16 +2638,6 @@ function load(input, options) {
|
|
|
2261
2638
|
throw new YAMLException("expected a single document in the stream, but found more");
|
|
2262
2639
|
}
|
|
2263
2640
|
//#endregion
|
|
2264
|
-
//#region src/ast/nodes.ts
|
|
2265
|
-
var Style = class {
|
|
2266
|
-
tagged = false;
|
|
2267
|
-
flow = false;
|
|
2268
|
-
singleQuoted = false;
|
|
2269
|
-
doubleQuoted = false;
|
|
2270
|
-
literal = false;
|
|
2271
|
-
folded = false;
|
|
2272
|
-
};
|
|
2273
|
-
//#endregion
|
|
2274
2641
|
//#region src/ast/from_js.ts
|
|
2275
2642
|
var INVALID = Symbol("INVALID");
|
|
2276
2643
|
function buildRepresentTypes(schema) {
|
|
@@ -2300,9 +2667,9 @@ function buildRepresentTypes(schema) {
|
|
|
2300
2667
|
function matchTag(state, object) {
|
|
2301
2668
|
for (let index = 0, length = state.representTypes.length; index < length; index += 1) {
|
|
2302
2669
|
const { tag, implicitTag } = state.representTypes[index];
|
|
2303
|
-
if (tag.identify
|
|
2670
|
+
if (tag.identify(object)) {
|
|
2304
2671
|
let tagName;
|
|
2305
|
-
if (tag.matchByTagPrefix
|
|
2672
|
+
if (tag.matchByTagPrefix) tagName = tag.representTagName(object);
|
|
2306
2673
|
else tagName = tag.tagName;
|
|
2307
2674
|
return {
|
|
2308
2675
|
tag,
|
|
@@ -2320,8 +2687,6 @@ function build(state, object) {
|
|
|
2320
2687
|
if (existing.anchor === void 0) existing.anchor = `ref_${state.refCounter++}`;
|
|
2321
2688
|
return {
|
|
2322
2689
|
kind: "alias",
|
|
2323
|
-
tag: "",
|
|
2324
|
-
style: new Style(),
|
|
2325
2690
|
anchor: existing.anchor
|
|
2326
2691
|
};
|
|
2327
2692
|
}
|
|
@@ -2334,24 +2699,20 @@ function build(state, object) {
|
|
|
2334
2699
|
}
|
|
2335
2700
|
const { tag, tagName, implicitTag } = matched;
|
|
2336
2701
|
const nodeTagName = implicitTag ? tagName : tagNameShort(tagName);
|
|
2337
|
-
if (tag.nodeKind === "scalar") {
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
value: tag.represent(object)
|
|
2345
|
-
};
|
|
2346
|
-
}
|
|
2702
|
+
if (tag.nodeKind === "scalar") return {
|
|
2703
|
+
kind: "scalar",
|
|
2704
|
+
tag: nodeTagName,
|
|
2705
|
+
tagged: !implicitTag,
|
|
2706
|
+
style: SCALAR_STYLE.PLAIN,
|
|
2707
|
+
value: tag.represent(object)
|
|
2708
|
+
};
|
|
2347
2709
|
if (tag.nodeKind === "sequence") {
|
|
2348
2710
|
const container = tag.represent(object);
|
|
2349
|
-
const style = new Style();
|
|
2350
|
-
style.tagged = !implicitTag;
|
|
2351
2711
|
const node = {
|
|
2352
2712
|
kind: "sequence",
|
|
2353
2713
|
tag: nodeTagName,
|
|
2354
|
-
|
|
2714
|
+
tagged: !implicitTag,
|
|
2715
|
+
style: COLLECTION_STYLE.BLOCK,
|
|
2355
2716
|
items: []
|
|
2356
2717
|
};
|
|
2357
2718
|
if (!state.noRefs) state.refs.set(object, node);
|
|
@@ -2364,12 +2725,11 @@ function build(state, object) {
|
|
|
2364
2725
|
return node;
|
|
2365
2726
|
}
|
|
2366
2727
|
const map = tag.represent(object);
|
|
2367
|
-
const style = new Style();
|
|
2368
|
-
style.tagged = !implicitTag;
|
|
2369
2728
|
const node = {
|
|
2370
2729
|
kind: "mapping",
|
|
2371
2730
|
tag: nodeTagName,
|
|
2372
|
-
|
|
2731
|
+
tagged: !implicitTag,
|
|
2732
|
+
style: COLLECTION_STYLE.BLOCK,
|
|
2373
2733
|
items: []
|
|
2374
2734
|
};
|
|
2375
2735
|
if (!state.noRefs) state.refs.set(object, node);
|
|
@@ -2385,6 +2745,13 @@ function build(state, object) {
|
|
|
2385
2745
|
}
|
|
2386
2746
|
return node;
|
|
2387
2747
|
}
|
|
2748
|
+
/**
|
|
2749
|
+
* Convert JS object to AST. A JS value is one YAML document. An unrepresentable
|
|
2750
|
+
* root becomes an empty document, which the presenter renders as an empty
|
|
2751
|
+
* string.
|
|
2752
|
+
*
|
|
2753
|
+
* @category AST
|
|
2754
|
+
*/
|
|
2388
2755
|
function jsToAst(input, schema, options = {}) {
|
|
2389
2756
|
const root = build({
|
|
2390
2757
|
representTypes: buildRepresentTypes(schema),
|
|
@@ -2400,7 +2767,17 @@ function jsToAst(input, schema, options = {}) {
|
|
|
2400
2767
|
}
|
|
2401
2768
|
//#endregion
|
|
2402
2769
|
//#region src/ast/visit.ts
|
|
2770
|
+
/**
|
|
2771
|
+
* Return from a visitor to stop the whole traversal.
|
|
2772
|
+
*
|
|
2773
|
+
* @category AST
|
|
2774
|
+
*/
|
|
2403
2775
|
var VISIT_BREAK = Symbol("visit:break");
|
|
2776
|
+
/**
|
|
2777
|
+
* Return from a visitor to skip the current node's children.
|
|
2778
|
+
*
|
|
2779
|
+
* @category AST
|
|
2780
|
+
*/
|
|
2404
2781
|
var VISIT_SKIP = Symbol("visit:skip");
|
|
2405
2782
|
function visitNode(node, visitor, ctx) {
|
|
2406
2783
|
const control = visitor(node, ctx);
|
|
@@ -2432,6 +2809,12 @@ function visitNode(node, visitor, ctx) {
|
|
|
2432
2809
|
}
|
|
2433
2810
|
return false;
|
|
2434
2811
|
}
|
|
2812
|
+
/**
|
|
2813
|
+
* Walk every node in the documents, calling {@link Visitor} once per
|
|
2814
|
+
* node (pre-order).
|
|
2815
|
+
*
|
|
2816
|
+
* @category AST
|
|
2817
|
+
*/
|
|
2435
2818
|
function visit(documents, visitor) {
|
|
2436
2819
|
for (const doc of documents) if (doc.contents && visitNode(doc.contents, visitor, {
|
|
2437
2820
|
depth: 0,
|
|
@@ -2440,247 +2823,194 @@ function visit(documents, visitor) {
|
|
|
2440
2823
|
})) return;
|
|
2441
2824
|
}
|
|
2442
2825
|
//#endregion
|
|
2443
|
-
//#region src/ast/
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
var
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
var CHAR_QUESTION = 63;
|
|
2462
|
-
var CHAR_COMMERCIAL_AT = 64;
|
|
2463
|
-
var CHAR_LEFT_SQUARE_BRACKET = 91;
|
|
2464
|
-
var CHAR_RIGHT_SQUARE_BRACKET = 93;
|
|
2465
|
-
var CHAR_GRAVE_ACCENT = 96;
|
|
2466
|
-
var CHAR_LEFT_CURLY_BRACKET = 123;
|
|
2467
|
-
var CHAR_VERTICAL_LINE = 124;
|
|
2468
|
-
var CHAR_RIGHT_CURLY_BRACKET = 125;
|
|
2469
|
-
var ESCAPE_SEQUENCES = {};
|
|
2470
|
-
ESCAPE_SEQUENCES[0] = "\\0";
|
|
2471
|
-
ESCAPE_SEQUENCES[7] = "\\a";
|
|
2472
|
-
ESCAPE_SEQUENCES[8] = "\\b";
|
|
2473
|
-
ESCAPE_SEQUENCES[9] = "\\t";
|
|
2474
|
-
ESCAPE_SEQUENCES[10] = "\\n";
|
|
2475
|
-
ESCAPE_SEQUENCES[11] = "\\v";
|
|
2476
|
-
ESCAPE_SEQUENCES[12] = "\\f";
|
|
2477
|
-
ESCAPE_SEQUENCES[13] = "\\r";
|
|
2478
|
-
ESCAPE_SEQUENCES[27] = "\\e";
|
|
2479
|
-
ESCAPE_SEQUENCES[34] = "\\\"";
|
|
2480
|
-
ESCAPE_SEQUENCES[92] = "\\\\";
|
|
2481
|
-
ESCAPE_SEQUENCES[133] = "\\N";
|
|
2482
|
-
ESCAPE_SEQUENCES[160] = "\\_";
|
|
2483
|
-
ESCAPE_SEQUENCES[8232] = "\\L";
|
|
2484
|
-
ESCAPE_SEQUENCES[8233] = "\\P";
|
|
2485
|
-
var DEFAULT_PRESENTER_OPTIONS = {
|
|
2486
|
-
indent: 2,
|
|
2487
|
-
seqNoIndent: false,
|
|
2488
|
-
seqInlineFirst: true,
|
|
2489
|
-
sortKeys: false,
|
|
2490
|
-
lineWidth: 80,
|
|
2491
|
-
flowBracketPadding: false,
|
|
2492
|
-
flowSkipCommaSpace: false,
|
|
2493
|
-
flowSkipColonSpace: false,
|
|
2494
|
-
quoteFlowKeys: false,
|
|
2495
|
-
quoteStyle: "single",
|
|
2496
|
-
forceQuotes: false,
|
|
2497
|
-
tagBeforeAnchor: false
|
|
2826
|
+
//#region src/ast/styler_defaults.ts
|
|
2827
|
+
function hasBit(mask, bit) {
|
|
2828
|
+
return (mask & 1 << bit) !== 0;
|
|
2829
|
+
}
|
|
2830
|
+
/**
|
|
2831
|
+
* Default scalar styling rules in application order.
|
|
2832
|
+
* See [Scalar styling](../../docs/scalar_styling.md) for usage details.
|
|
2833
|
+
*
|
|
2834
|
+
* @category AST
|
|
2835
|
+
*/
|
|
2836
|
+
var DEFAULT_SCALAR_STYLE_RULES = {
|
|
2837
|
+
applyQuoteFlowKeysOption,
|
|
2838
|
+
doubleQuoteForInvisibles,
|
|
2839
|
+
doubleQuoteWhitespaceOnly,
|
|
2840
|
+
applyForceQuotesOption,
|
|
2841
|
+
tryLongOrMultilineAsBlock,
|
|
2842
|
+
quoteInvalidPlain,
|
|
2843
|
+
fallbackToDoubleQuoted
|
|
2498
2844
|
};
|
|
2499
|
-
function
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
}
|
|
2519
|
-
function
|
|
2520
|
-
|
|
2845
|
+
function _preferredQuotedStyle(layout) {
|
|
2846
|
+
if (layout.presenterOptions.quoteStyle === "single" && hasBit(layout.allowedStylesMask, SCALAR_STYLE.SINGLE_QUOTED)) return SCALAR_STYLE.SINGLE_QUOTED;
|
|
2847
|
+
return SCALAR_STYLE.DOUBLE_QUOTED;
|
|
2848
|
+
}
|
|
2849
|
+
function applyQuoteFlowKeysOption(layout) {
|
|
2850
|
+
if (!layout.presenterOptions.quoteFlowKeys) return;
|
|
2851
|
+
if (!layout.isKey || !layout.flowOnly || layout.style !== SCALAR_STYLE.PLAIN) return;
|
|
2852
|
+
layout.style = SCALAR_STYLE.DOUBLE_QUOTED;
|
|
2853
|
+
}
|
|
2854
|
+
function doubleQuoteForInvisibles(layout) {
|
|
2855
|
+
if (layout.style === SCALAR_STYLE.PLAIN && /[\t\x7F-\xA0\u2028\u2029\uFEFF\uFFFE\uFFFF]/.test(layout.node.value)) layout.style = SCALAR_STYLE.DOUBLE_QUOTED;
|
|
2856
|
+
}
|
|
2857
|
+
function doubleQuoteWhitespaceOnly(layout) {
|
|
2858
|
+
if (layout.style === SCALAR_STYLE.PLAIN && /^\s+$/.test(layout.node.value)) layout.style = SCALAR_STYLE.DOUBLE_QUOTED;
|
|
2859
|
+
}
|
|
2860
|
+
function applyForceQuotesOption(layout) {
|
|
2861
|
+
if (!layout.presenterOptions.forceQuotes) return;
|
|
2862
|
+
if (layout.isKey || layout.style !== SCALAR_STYLE.PLAIN) return;
|
|
2863
|
+
layout.style = layout.node.value.includes("\n") ? SCALAR_STYLE.DOUBLE_QUOTED : _preferredQuotedStyle(layout);
|
|
2864
|
+
}
|
|
2865
|
+
function tryLongOrMultilineAsBlock(layout) {
|
|
2866
|
+
if (layout.style !== SCALAR_STYLE.PLAIN || layout.isKey) return;
|
|
2867
|
+
const value = layout.node.value;
|
|
2868
|
+
const multiline = value.indexOf("\n") !== -1;
|
|
2869
|
+
if (!hasBit(layout.allowedStylesMask, SCALAR_STYLE.LITERAL_BLOCK)) {
|
|
2870
|
+
if (multiline) layout.style = SCALAR_STYLE.DOUBLE_QUOTED;
|
|
2871
|
+
return;
|
|
2872
|
+
}
|
|
2873
|
+
const w = layout.presenterOptions.lineWidth;
|
|
2874
|
+
if (w === -1) {
|
|
2875
|
+
if (multiline) layout.style = SCALAR_STYLE.LITERAL_BLOCK;
|
|
2876
|
+
return;
|
|
2877
|
+
}
|
|
2878
|
+
const availableWidth = Math.max(Math.min(w, 40), w - layout.shiftOfContent);
|
|
2521
2879
|
let position = 0;
|
|
2522
|
-
let
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
line = string.slice(position, next + 1);
|
|
2532
|
-
position = next + 1;
|
|
2533
|
-
}
|
|
2534
|
-
if (line.length && line !== "\n") result += ind;
|
|
2535
|
-
result += line;
|
|
2880
|
+
let shouldFold = false;
|
|
2881
|
+
while (position <= value.length) {
|
|
2882
|
+
let lineEnd = value.length;
|
|
2883
|
+
const nextLineBreak = value.indexOf("\n", position);
|
|
2884
|
+
if (nextLineBreak !== -1) lineEnd = nextLineBreak;
|
|
2885
|
+
const line = value.slice(position, lineEnd);
|
|
2886
|
+
if (line.length > availableWidth && line[0] !== " " && / [^ \t]/.test(line)) shouldFold = true;
|
|
2887
|
+
if (nextLineBreak === -1) break;
|
|
2888
|
+
position = nextLineBreak + 1;
|
|
2536
2889
|
}
|
|
2537
|
-
|
|
2890
|
+
if (shouldFold) layout.style = SCALAR_STYLE.FOLDED_BLOCK;
|
|
2891
|
+
else if (multiline) layout.style = SCALAR_STYLE.LITERAL_BLOCK;
|
|
2538
2892
|
}
|
|
2539
|
-
function
|
|
2540
|
-
|
|
2893
|
+
function quoteInvalidPlain(layout) {
|
|
2894
|
+
if (layout.style === SCALAR_STYLE.PLAIN && !hasBit(layout.allowedStylesMask, SCALAR_STYLE.PLAIN)) layout.style = _preferredQuotedStyle(layout);
|
|
2541
2895
|
}
|
|
2542
|
-
function
|
|
2543
|
-
|
|
2544
|
-
return {
|
|
2545
|
-
indent,
|
|
2546
|
-
blockIndent: level === 0 ? state.indent + 1 : state.indent,
|
|
2547
|
-
lineWidth: state.lineWidth === -1 ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent)
|
|
2548
|
-
};
|
|
2896
|
+
function fallbackToDoubleQuoted(layout) {
|
|
2897
|
+
if (!hasBit(layout.allowedStylesMask, layout.style)) layout.style = SCALAR_STYLE.DOUBLE_QUOTED;
|
|
2549
2898
|
}
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2899
|
+
//#endregion
|
|
2900
|
+
//#region src/ast/scalar_styler.ts
|
|
2901
|
+
function setBit(mask, bit) {
|
|
2902
|
+
return mask | 1 << bit;
|
|
2903
|
+
}
|
|
2904
|
+
var SRC_C_PRINTABLE = "[\\x09\\x0A\\x0D\\x20-\\x7E\\x85\\xA0-\\uD7FF\\uE000-\\uFFFD\\u{10000}-\\u{10FFFF}]";
|
|
2905
|
+
var SRC_B_CHAR = "[\\n\\r]";
|
|
2906
|
+
var SRC_C_BYTE_ORDER_MARK = "\\uFEFF";
|
|
2907
|
+
var SRC_S_WHITE = "[ \\t]";
|
|
2908
|
+
var SRC_NB_CHAR = `(?:(?!(?:${SRC_B_CHAR}|${SRC_C_BYTE_ORDER_MARK}))${SRC_C_PRINTABLE})`;
|
|
2909
|
+
var SRC_NS_CHAR = `(?:(?!${SRC_S_WHITE})${SRC_NB_CHAR})`;
|
|
2910
|
+
var SRC_NB_JSON = "[\\x09\\x20-\\uD7FF\\uE000-\\uFFFF\\u{10000}-\\u{10FFFF}]";
|
|
2911
|
+
var SRC_C_INDICATOR = "[-?:,\\[\\]{}#&*!|>'\"%@`]";
|
|
2912
|
+
var SRC_C_FLOW_INDICATOR = "[,\\[\\]{}]";
|
|
2913
|
+
var SRC_NS_PLAIN_SAFE_FLOW_OUT = SRC_NS_CHAR;
|
|
2914
|
+
var SRC_NS_PLAIN_SAFE_FLOW_IN = `(?:(?!${SRC_C_FLOW_INDICATOR})${SRC_NS_CHAR})`;
|
|
2915
|
+
var SRC_NS_PLAIN_FIRST_FLOW_OUT = `(?:(?:(?!${SRC_C_INDICATOR})${SRC_NS_CHAR})|[?:-](?=${SRC_NS_PLAIN_SAFE_FLOW_OUT}))`;
|
|
2916
|
+
var SRC_NS_PLAIN_FIRST_FLOW_IN = `(?:(?:(?!${SRC_C_INDICATOR})${SRC_NS_CHAR})|[?:-](?=${SRC_NS_PLAIN_SAFE_FLOW_IN}))`;
|
|
2917
|
+
var SRC_NS_PLAIN_CHAR_FLOW_OUT = `(?:(?:(?![:#])${SRC_NS_PLAIN_SAFE_FLOW_OUT})|:(?=${SRC_NS_PLAIN_SAFE_FLOW_OUT}))#*`;
|
|
2918
|
+
var SRC_NS_PLAIN_CHAR_FLOW_IN = `(?:(?:(?![:#])${SRC_NS_PLAIN_SAFE_FLOW_IN})|:(?=${SRC_NS_PLAIN_SAFE_FLOW_IN}))#*`;
|
|
2919
|
+
var SRC_NB_NS_PLAIN_IN_LINE_FLOW_OUT = `(?:${SRC_S_WHITE}*${SRC_NS_PLAIN_CHAR_FLOW_OUT})*`;
|
|
2920
|
+
var SRC_NB_NS_PLAIN_IN_LINE_FLOW_IN = `(?:${SRC_S_WHITE}*${SRC_NS_PLAIN_CHAR_FLOW_IN})*`;
|
|
2921
|
+
var SRC_NS_PLAIN_ONE_LINE_FLOW_OUT = `${SRC_NS_PLAIN_FIRST_FLOW_OUT}#*${SRC_NB_NS_PLAIN_IN_LINE_FLOW_OUT}`;
|
|
2922
|
+
var SRC_NS_PLAIN_ONE_LINE_FLOW_IN = `${SRC_NS_PLAIN_FIRST_FLOW_IN}#*${SRC_NB_NS_PLAIN_IN_LINE_FLOW_IN}`;
|
|
2923
|
+
var SRC_NS_PLAIN_ONE_LINE_BLOCK_KEY = SRC_NS_PLAIN_ONE_LINE_FLOW_OUT;
|
|
2924
|
+
var SRC_NS_PLAIN_ONE_LINE_FLOW_KEY = SRC_NS_PLAIN_ONE_LINE_FLOW_IN;
|
|
2925
|
+
var SRC_S_NS_PLAIN_NEXT_LINE_FLOW_OUT = `\\n+${SRC_NS_PLAIN_CHAR_FLOW_OUT}${SRC_NB_NS_PLAIN_IN_LINE_FLOW_OUT}`;
|
|
2926
|
+
var SRC_S_NS_PLAIN_NEXT_LINE_FLOW_IN = `\\n+${SRC_NS_PLAIN_CHAR_FLOW_IN}${SRC_NB_NS_PLAIN_IN_LINE_FLOW_IN}`;
|
|
2927
|
+
var SRC_NS_PLAIN_MULTI_LINE_FLOW_OUT = `${SRC_NS_PLAIN_ONE_LINE_FLOW_OUT}(?:${SRC_S_NS_PLAIN_NEXT_LINE_FLOW_OUT})*`;
|
|
2928
|
+
var SRC_NS_PLAIN_MULTI_LINE_FLOW_IN = `${SRC_NS_PLAIN_ONE_LINE_FLOW_IN}(?:${SRC_S_NS_PLAIN_NEXT_LINE_FLOW_IN})*`;
|
|
2929
|
+
var NS_PLAIN_FLOW_OUT = new RegExp(`^(?:${SRC_NS_PLAIN_MULTI_LINE_FLOW_OUT})$`, "u");
|
|
2930
|
+
var NS_PLAIN_FLOW_IN = new RegExp(`^(?:${SRC_NS_PLAIN_MULTI_LINE_FLOW_IN})$`, "u");
|
|
2931
|
+
var NS_PLAIN_BLOCK_KEY = new RegExp(`^(?:${SRC_NS_PLAIN_ONE_LINE_BLOCK_KEY})$`, "u");
|
|
2932
|
+
var NS_PLAIN_FLOW_KEY = new RegExp(`^(?:${SRC_NS_PLAIN_ONE_LINE_FLOW_KEY})$`, "u");
|
|
2933
|
+
var NB_SINGLE_ONE_LINE = new RegExp(`^(?:${SRC_NB_JSON})*$`, "u");
|
|
2934
|
+
var NB_SINGLE_MULTI_LINE = new RegExp(`^(?:${SRC_NB_JSON}|\\n)*$`, "u");
|
|
2935
|
+
var BLOCK_SCALAR_CONTENT = new RegExp(`^(?:${SRC_NB_CHAR}|\\n)*$`, "u");
|
|
2936
|
+
var C_FORBIDDEN_FIRST_LINE = /^(?:---|\.\.\.)(?=$|[ \t\n\r])/;
|
|
2937
|
+
var C_FORBIDDEN_CONTENT = /^(?:---|\.\.\.)(?=$|[ \t\n\r])/m;
|
|
2938
|
+
function canUsePlain(layout) {
|
|
2939
|
+
const str = layout.node.value;
|
|
2940
|
+
if (str !== "") {
|
|
2941
|
+
if (!(layout.isKey ? layout.flowOnly ? NS_PLAIN_FLOW_KEY : NS_PLAIN_BLOCK_KEY : layout.flowOnly ? NS_PLAIN_FLOW_IN : NS_PLAIN_FLOW_OUT).test(str)) return false;
|
|
2942
|
+
if (layout.shiftOfFirstLine === 0 && C_FORBIDDEN_FIRST_LINE.test(str)) return false;
|
|
2943
|
+
if (layout.shiftOfContent === 0) {
|
|
2944
|
+
const firstLineBreak = str.indexOf("\n");
|
|
2945
|
+
if (firstLineBreak !== -1) {
|
|
2946
|
+
const content = str.slice(firstLineBreak + 1);
|
|
2947
|
+
if (C_FORBIDDEN_CONTENT.test(content)) return false;
|
|
2948
|
+
}
|
|
2949
|
+
}
|
|
2554
2950
|
}
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
return
|
|
2559
|
-
}
|
|
2560
|
-
function startsWithDocumentSeparator(string) {
|
|
2561
|
-
const marker = string.charCodeAt(0);
|
|
2562
|
-
if (marker !== CHAR_MINUS && marker !== 46 || string.charCodeAt(1) !== marker || string.charCodeAt(2) !== marker) return false;
|
|
2563
|
-
if (string.length === 3) return true;
|
|
2564
|
-
const following = string.charCodeAt(3);
|
|
2565
|
-
return isWhitespace(following) || following === CHAR_CARRIAGE_RETURN || following === CHAR_LINE_FEED;
|
|
2566
|
-
}
|
|
2567
|
-
function isPrintable(c) {
|
|
2568
|
-
return c >= 32 && c <= 126 || c >= 161 && c <= 55295 && c !== 8232 && c !== 8233 || c >= 57344 && c <= 65533 && c !== CHAR_BOM || c >= 65536 && c <= 1114111;
|
|
2951
|
+
const resolvedTag = layout.presenterOptions.schema.resolveImplicitScalarTag(str).tag.tagName;
|
|
2952
|
+
if (!layout.node.tagged && resolvedTag !== layout.node.tag) return false;
|
|
2953
|
+
if (!layout.node.tagged && str === "=" && resolvedTag === layout.presenterOptions.schema.defaultScalarTag.tagName) return false;
|
|
2954
|
+
return true;
|
|
2569
2955
|
}
|
|
2570
|
-
function
|
|
2571
|
-
|
|
2956
|
+
function canUseSingleQuoted(layout) {
|
|
2957
|
+
const str = layout.node.value;
|
|
2958
|
+
if (!(layout.isKey ? NB_SINGLE_ONE_LINE : NB_SINGLE_MULTI_LINE).test(str)) return false;
|
|
2959
|
+
if (/[ \t]\n|\n[ \t]/.test(str)) return false;
|
|
2960
|
+
if (!layout.isKey && layout.shiftOfContent === 0) {
|
|
2961
|
+
const firstLineBreak = str.indexOf("\n");
|
|
2962
|
+
if (firstLineBreak !== -1 && C_FORBIDDEN_CONTENT.test(str.slice(firstLineBreak + 1))) return false;
|
|
2963
|
+
}
|
|
2964
|
+
return true;
|
|
2572
2965
|
}
|
|
2573
|
-
function
|
|
2574
|
-
|
|
2575
|
-
const
|
|
2576
|
-
|
|
2966
|
+
function canUseBlock(layout) {
|
|
2967
|
+
if (layout.flowOnly || !BLOCK_SCALAR_CONTENT.test(layout.node.value)) return false;
|
|
2968
|
+
const contentIndent = layout.shiftOfContent - layout.shiftOfParent;
|
|
2969
|
+
if (contentIndent < 1) return false;
|
|
2970
|
+
if (contentIndent > 9 && /^\n* /.test(layout.node.value)) return false;
|
|
2971
|
+
if (layout.shiftOfContent === 0 && C_FORBIDDEN_CONTENT.test(layout.node.value)) return false;
|
|
2972
|
+
return true;
|
|
2577
2973
|
}
|
|
2578
|
-
function
|
|
2579
|
-
|
|
2974
|
+
function detectAllowedStyles(layout) {
|
|
2975
|
+
let mask = setBit(0, SCALAR_STYLE.DOUBLE_QUOTED);
|
|
2976
|
+
if (canUsePlain(layout)) mask = setBit(mask, SCALAR_STYLE.PLAIN);
|
|
2977
|
+
if (canUseSingleQuoted(layout)) mask = setBit(mask, SCALAR_STYLE.SINGLE_QUOTED);
|
|
2978
|
+
if (canUseBlock(layout)) mask = setBit(setBit(mask, SCALAR_STYLE.LITERAL_BLOCK), SCALAR_STYLE.FOLDED_BLOCK);
|
|
2979
|
+
layout.allowedStylesMask = mask;
|
|
2580
2980
|
}
|
|
2581
|
-
function
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2981
|
+
function renderScalar(layout) {
|
|
2982
|
+
switch (layout.style) {
|
|
2983
|
+
case SCALAR_STYLE.PLAIN: return renderPlain(layout);
|
|
2984
|
+
case SCALAR_STYLE.SINGLE_QUOTED: return renderSingleQuoted(layout);
|
|
2985
|
+
case SCALAR_STYLE.LITERAL_BLOCK: return renderLiteralBlock(layout);
|
|
2986
|
+
case SCALAR_STYLE.FOLDED_BLOCK: return renderFoldedBlock(layout);
|
|
2987
|
+
case SCALAR_STYLE.DOUBLE_QUOTED: return renderDoubleQuoted(layout);
|
|
2587
2988
|
}
|
|
2588
|
-
return false;
|
|
2589
2989
|
}
|
|
2590
|
-
function
|
|
2591
|
-
return
|
|
2990
|
+
function renderPlain(layout) {
|
|
2991
|
+
return encodeFlowBreaks(layout.node.value, layout.shiftOfContent);
|
|
2592
2992
|
}
|
|
2593
|
-
function
|
|
2594
|
-
|
|
2595
|
-
let second;
|
|
2596
|
-
if (first >= 55296 && first <= 56319 && pos + 1 < string.length) {
|
|
2597
|
-
second = string.charCodeAt(pos + 1);
|
|
2598
|
-
if (second >= 56320 && second <= 57343) return (first - 55296) * 1024 + second - 56320 + 65536;
|
|
2599
|
-
}
|
|
2600
|
-
return first;
|
|
2993
|
+
function renderSingleQuoted(layout) {
|
|
2994
|
+
return `'${encodeFlowBreaks(layout.node.value, layout.shiftOfContent).replace(/'/g, "''")}'`;
|
|
2601
2995
|
}
|
|
2602
|
-
function
|
|
2603
|
-
|
|
2996
|
+
function renderLiteralBlock(layout) {
|
|
2997
|
+
const value = layout.node.value;
|
|
2998
|
+
return "|" + blockHeader(value, layout.shiftOfParent, layout.shiftOfContent) + dropEndingNewline(indentString(value, layout.shiftOfContent));
|
|
2604
2999
|
}
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
const { blockIndent, lineWidth } = layout;
|
|
2612
|
-
let i;
|
|
2613
|
-
let char = 0;
|
|
2614
|
-
let prevChar = -1;
|
|
2615
|
-
let hasLineBreak = false;
|
|
2616
|
-
let hasFoldableLine = false;
|
|
2617
|
-
const shouldTrackWidth = lineWidth !== -1;
|
|
2618
|
-
let previousLineBreak = -1;
|
|
2619
|
-
let plain = !startsWithDocumentSeparator(string) && isPlainSafeAtStart(string, inblock) && isPlainSafeLast(codePointAt(string, string.length - 1));
|
|
2620
|
-
if (singleLineOnly || forceQuote) for (i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
|
|
2621
|
-
char = codePointAt(string, i);
|
|
2622
|
-
if (!isPrintable(char)) return STYLE_DOUBLE;
|
|
2623
|
-
plain = plain && isPlainSafe(char, prevChar, inblock);
|
|
2624
|
-
prevChar = char;
|
|
2625
|
-
}
|
|
2626
|
-
else {
|
|
2627
|
-
for (i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
|
|
2628
|
-
char = codePointAt(string, i);
|
|
2629
|
-
if (char === CHAR_LINE_FEED) {
|
|
2630
|
-
hasLineBreak = true;
|
|
2631
|
-
if (shouldTrackWidth) {
|
|
2632
|
-
hasFoldableLine = hasFoldableLine || i - previousLineBreak - 1 > lineWidth && !isMoreIndented(string[previousLineBreak + 1]);
|
|
2633
|
-
previousLineBreak = i;
|
|
2634
|
-
}
|
|
2635
|
-
} else if (!isPrintable(char)) return STYLE_DOUBLE;
|
|
2636
|
-
plain = plain && isPlainSafe(char, prevChar, inblock);
|
|
2637
|
-
prevChar = char;
|
|
2638
|
-
}
|
|
2639
|
-
hasFoldableLine = hasFoldableLine || shouldTrackWidth && i - previousLineBreak - 1 > lineWidth && !isMoreIndented(string[previousLineBreak + 1]);
|
|
2640
|
-
}
|
|
2641
|
-
if (!hasLineBreak && !hasFoldableLine) {
|
|
2642
|
-
if (plain && !forceQuote) return STYLE_PLAIN;
|
|
2643
|
-
return state.quoteStyle === "double" ? STYLE_DOUBLE : STYLE_SINGLE;
|
|
2644
|
-
}
|
|
2645
|
-
if (blockIndent > 9 && needIndentIndicator(string)) return STYLE_DOUBLE;
|
|
2646
|
-
return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL;
|
|
2647
|
-
}
|
|
2648
|
-
function renderScalarStyle(string, style, layout) {
|
|
2649
|
-
const { indent, blockIndent, lineWidth } = layout;
|
|
2650
|
-
switch (style) {
|
|
2651
|
-
case STYLE_PLAIN: return encodeFlowBreaks(string, indent);
|
|
2652
|
-
case STYLE_SINGLE: return `'${encodeFlowBreaks(string, indent).replace(/'/g, "''")}'`;
|
|
2653
|
-
case STYLE_LITERAL: return "|" + blockHeader(string, blockIndent) + dropEndingNewline(indentString(string, indent));
|
|
2654
|
-
case STYLE_FOLDED: return ">" + blockHeader(string, blockIndent) + dropEndingNewline(indentString(foldBlockScalar(string, lineWidth), indent));
|
|
2655
|
-
case STYLE_DOUBLE: return `"${escapeString(string)}"`;
|
|
2656
|
-
}
|
|
2657
|
-
}
|
|
2658
|
-
function resolveScalarStyle(state, node, layout, iskey, inblock) {
|
|
2659
|
-
const singleLineOnly = iskey || !inblock;
|
|
2660
|
-
if (node.style.singleQuoted) return STYLE_SINGLE;
|
|
2661
|
-
if (node.style.doubleQuoted) return STYLE_DOUBLE;
|
|
2662
|
-
if (!singleLineOnly) {
|
|
2663
|
-
if (node.style.literal) return STYLE_LITERAL;
|
|
2664
|
-
if (node.style.folded) return STYLE_FOLDED;
|
|
2665
|
-
}
|
|
2666
|
-
const string = node.value;
|
|
2667
|
-
if (string.length === 0) {
|
|
2668
|
-
if (node.style.tagged || resolveImplicitTag(state, string) === node.tag) return STYLE_PLAIN;
|
|
2669
|
-
return state.quoteStyle === "double" ? STYLE_DOUBLE : STYLE_SINGLE;
|
|
2670
|
-
}
|
|
2671
|
-
const style = chooseScalarStyle(state, string, layout, singleLineOnly, state.forceQuotes && !iskey, inblock);
|
|
2672
|
-
if (style === STYLE_PLAIN && !node.style.tagged && resolveImplicitTag(state, string) !== node.tag) return state.quoteStyle === "double" ? STYLE_DOUBLE : STYLE_SINGLE;
|
|
2673
|
-
return style;
|
|
2674
|
-
}
|
|
2675
|
-
function blockHeader(string, indentPerLevel) {
|
|
2676
|
-
const indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) : "";
|
|
2677
|
-
const clip = string[string.length - 1] === "\n";
|
|
2678
|
-
return `${indentIndicator}${clip && (string[string.length - 2] === "\n" || string === "\n") ? "+" : clip ? "" : "-"}\n`;
|
|
3000
|
+
function renderFoldedBlock(layout) {
|
|
3001
|
+
const value = layout.node.value;
|
|
3002
|
+
const w = layout.presenterOptions.lineWidth;
|
|
3003
|
+
let availableWidth = Infinity;
|
|
3004
|
+
if (w !== -1) availableWidth = Math.max(Math.min(w, 40), w - layout.shiftOfContent);
|
|
3005
|
+
return ">" + blockHeader(value, layout.shiftOfParent, layout.shiftOfContent) + dropEndingNewline(indentString(foldBlockScalar(value, availableWidth), layout.shiftOfContent));
|
|
2679
3006
|
}
|
|
2680
|
-
function
|
|
3007
|
+
function renderDoubleQuoted(layout) {
|
|
3008
|
+
return `"${escapeString(layout.node.value)}"`;
|
|
3009
|
+
}
|
|
3010
|
+
function encodeFlowBreaks(string, shiftOfContent) {
|
|
2681
3011
|
let nextLF = string.indexOf("\n");
|
|
2682
3012
|
if (nextLF === -1) return string;
|
|
2683
|
-
const pad = " ".repeat(
|
|
3013
|
+
const pad = " ".repeat(shiftOfContent);
|
|
2684
3014
|
let result = string.slice(0, nextLF);
|
|
2685
3015
|
const lineRe = /(\n+)([^\n]*)/g;
|
|
2686
3016
|
lineRe.lastIndex = nextLF;
|
|
@@ -2692,30 +3022,40 @@ function encodeFlowBreaks(string, indent) {
|
|
|
2692
3022
|
}
|
|
2693
3023
|
return result;
|
|
2694
3024
|
}
|
|
3025
|
+
function indentString(string, spaces) {
|
|
3026
|
+
const indent = " ".repeat(spaces);
|
|
3027
|
+
let position = 0;
|
|
3028
|
+
let result = "";
|
|
3029
|
+
const length = string.length;
|
|
3030
|
+
while (position < length) {
|
|
3031
|
+
let line;
|
|
3032
|
+
const next = string.indexOf("\n", position);
|
|
3033
|
+
if (next === -1) {
|
|
3034
|
+
line = string.slice(position);
|
|
3035
|
+
position = length;
|
|
3036
|
+
} else {
|
|
3037
|
+
line = string.slice(position, next + 1);
|
|
3038
|
+
position = next + 1;
|
|
3039
|
+
}
|
|
3040
|
+
if (line.length && line !== "\n") result += indent;
|
|
3041
|
+
result += line;
|
|
3042
|
+
}
|
|
3043
|
+
return result;
|
|
3044
|
+
}
|
|
3045
|
+
function needIndentIndicator(string) {
|
|
3046
|
+
return /^\n* /.test(string);
|
|
3047
|
+
}
|
|
3048
|
+
function blockHeader(string, shiftOfParent, shiftOfContent) {
|
|
3049
|
+
const indentIndicator = needIndentIndicator(string) ? String(shiftOfContent - shiftOfParent) : "";
|
|
3050
|
+
const clip = string[string.length - 1] === "\n";
|
|
3051
|
+
return `${indentIndicator}${clip && (string[string.length - 2] === "\n" || string === "\n") ? "+" : clip ? "" : "-"}\n`;
|
|
3052
|
+
}
|
|
2695
3053
|
function dropEndingNewline(string) {
|
|
2696
3054
|
return string[string.length - 1] === "\n" ? string.slice(0, -1) : string;
|
|
2697
3055
|
}
|
|
2698
3056
|
function isMoreIndented(char) {
|
|
2699
3057
|
return char === " " || char === " ";
|
|
2700
3058
|
}
|
|
2701
|
-
function foldBlockScalar(string, width) {
|
|
2702
|
-
const lineRe = /(\n+)([^\n]*)/g;
|
|
2703
|
-
let nextLF = string.indexOf("\n");
|
|
2704
|
-
if (nextLF === -1) nextLF = string.length;
|
|
2705
|
-
lineRe.lastIndex = nextLF;
|
|
2706
|
-
let result = foldLine(string.slice(0, nextLF), width);
|
|
2707
|
-
let prevMoreIndented = string[0] === "\n" || isMoreIndented(string[0]);
|
|
2708
|
-
let moreIndented;
|
|
2709
|
-
let match;
|
|
2710
|
-
while (match = lineRe.exec(string)) {
|
|
2711
|
-
const prefix = match[1];
|
|
2712
|
-
const line = match[2];
|
|
2713
|
-
moreIndented = line !== "" && isMoreIndented(line[0]);
|
|
2714
|
-
result += prefix + (!prevMoreIndented && !moreIndented && line !== "" ? "\n" : "") + foldLine(line, width);
|
|
2715
|
-
prevMoreIndented = moreIndented;
|
|
2716
|
-
}
|
|
2717
|
-
return result;
|
|
2718
|
-
}
|
|
2719
3059
|
function foldLine(line, width) {
|
|
2720
3060
|
if (line === "" || isMoreIndented(line[0])) return line;
|
|
2721
3061
|
const breakRe = / [^ \t]/g;
|
|
@@ -2739,43 +3079,119 @@ function foldLine(line, width) {
|
|
|
2739
3079
|
else result += line.slice(start);
|
|
2740
3080
|
return result.slice(1);
|
|
2741
3081
|
}
|
|
2742
|
-
function
|
|
2743
|
-
|
|
2744
|
-
let
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
result += encodeNonPrintable(char);
|
|
3082
|
+
function foldBlockScalar(string, width) {
|
|
3083
|
+
const lineRe = /(\n+)([^\n]*)/g;
|
|
3084
|
+
let nextLF = string.indexOf("\n");
|
|
3085
|
+
if (nextLF === -1) nextLF = string.length;
|
|
3086
|
+
lineRe.lastIndex = nextLF;
|
|
3087
|
+
let result = foldLine(string.slice(0, nextLF), width);
|
|
3088
|
+
let prevMoreIndented = string[0] === "\n" || isMoreIndented(string[0]);
|
|
3089
|
+
let moreIndented;
|
|
3090
|
+
let match;
|
|
3091
|
+
while (match = lineRe.exec(string)) {
|
|
3092
|
+
const prefix = match[1];
|
|
3093
|
+
const line = match[2];
|
|
3094
|
+
moreIndented = line !== "" && isMoreIndented(line[0]);
|
|
3095
|
+
result += prefix + (!prevMoreIndented && !moreIndented && line !== "" ? "\n" : "") + foldLine(line, width);
|
|
3096
|
+
prevMoreIndented = moreIndented;
|
|
2758
3097
|
}
|
|
2759
3098
|
return result;
|
|
2760
3099
|
}
|
|
3100
|
+
var CHARACTERS_TO_ESCAPE = /["\\\x00-\x1F\x7F-\xA0\u2028\u2029\uD800-\uDFFF\uFEFF\uFFFE\uFFFF]/gu;
|
|
3101
|
+
function escapeCharacter(character) {
|
|
3102
|
+
switch (character) {
|
|
3103
|
+
case "\0": return "\\0";
|
|
3104
|
+
case "\x07": return "\\a";
|
|
3105
|
+
case "\b": return "\\b";
|
|
3106
|
+
case " ": return "\\t";
|
|
3107
|
+
case "\n": return "\\n";
|
|
3108
|
+
case "\v": return "\\v";
|
|
3109
|
+
case "\f": return "\\f";
|
|
3110
|
+
case "\r": return "\\r";
|
|
3111
|
+
case "\x1B": return "\\e";
|
|
3112
|
+
case "\"": return "\\\"";
|
|
3113
|
+
case "\\": return "\\\\";
|
|
3114
|
+
case "
": return "\\N";
|
|
3115
|
+
case "\xA0": return "\\_";
|
|
3116
|
+
case "\u2028": return "\\L";
|
|
3117
|
+
case "\u2029": return "\\P";
|
|
3118
|
+
}
|
|
3119
|
+
const code = character.charCodeAt(0);
|
|
3120
|
+
const hex = code.toString(16).toUpperCase();
|
|
3121
|
+
if (code <= 255) return `\\x${"0".repeat(2 - hex.length)}${hex}`;
|
|
3122
|
+
return `\\u${"0".repeat(4 - hex.length)}${hex}`;
|
|
3123
|
+
}
|
|
3124
|
+
function escapeString(string) {
|
|
3125
|
+
return string.replace(CHARACTERS_TO_ESCAPE, escapeCharacter);
|
|
3126
|
+
}
|
|
3127
|
+
//#endregion
|
|
3128
|
+
//#region src/ast/presenter.ts
|
|
3129
|
+
var CHAR_LINE_FEED = 10;
|
|
3130
|
+
var DEFAULT_PRESENTER_OPTIONS = {
|
|
3131
|
+
indent: 2,
|
|
3132
|
+
seqNoIndent: false,
|
|
3133
|
+
seqInlineFirst: true,
|
|
3134
|
+
lineWidth: 80,
|
|
3135
|
+
flowBracketPadding: false,
|
|
3136
|
+
flowSkipCommaSpace: false,
|
|
3137
|
+
flowSkipColonSpace: false,
|
|
3138
|
+
quoteFlowKeys: false,
|
|
3139
|
+
quoteStyle: "single",
|
|
3140
|
+
forceQuotes: false,
|
|
3141
|
+
scalarStyleRules: Object.keys(DEFAULT_SCALAR_STYLE_RULES).map((name) => Reflect.get(DEFAULT_SCALAR_STYLE_RULES, name)),
|
|
3142
|
+
tagBeforeAnchor: false
|
|
3143
|
+
};
|
|
3144
|
+
function nodeTagShort(node) {
|
|
3145
|
+
return node.tagged ? node.tag : tagNameShort(node.tag);
|
|
3146
|
+
}
|
|
3147
|
+
function createPresenterState(options) {
|
|
3148
|
+
const opts = {
|
|
3149
|
+
...DEFAULT_PRESENTER_OPTIONS,
|
|
3150
|
+
...options
|
|
3151
|
+
};
|
|
3152
|
+
if (opts.flowSkipColonSpace) opts.quoteFlowKeys = true;
|
|
3153
|
+
return {
|
|
3154
|
+
...opts,
|
|
3155
|
+
defaultScalarTagName: opts.schema.defaultScalarTag.tagName,
|
|
3156
|
+
openEnded: false
|
|
3157
|
+
};
|
|
3158
|
+
}
|
|
3159
|
+
function generateNextLine(state, level) {
|
|
3160
|
+
return `\n${" ".repeat(state.indent * level)}`;
|
|
3161
|
+
}
|
|
3162
|
+
function scalarLayout(state, node, parent, level, isKey, flowOnly) {
|
|
3163
|
+
return {
|
|
3164
|
+
node,
|
|
3165
|
+
parent,
|
|
3166
|
+
level,
|
|
3167
|
+
isKey,
|
|
3168
|
+
flowOnly,
|
|
3169
|
+
shiftOfParent: level === 0 ? -1 : state.indent * (level - 1),
|
|
3170
|
+
shiftOfContent: state.indent * Math.max(1, level),
|
|
3171
|
+
shiftOfFirstLine: level === 0 ? 0 : state.indent * level,
|
|
3172
|
+
presenterOptions: state,
|
|
3173
|
+
allowedStylesMask: 0,
|
|
3174
|
+
style: node.style
|
|
3175
|
+
};
|
|
3176
|
+
}
|
|
2761
3177
|
function writeFlowSequence(state, level, node) {
|
|
2762
3178
|
let result = "";
|
|
2763
3179
|
for (let index = 0, length = node.items.length; index < length; index += 1) {
|
|
2764
|
-
const item = writeNode(state, level, node.items[index], {});
|
|
2765
|
-
if (
|
|
3180
|
+
const item = writeNode(state, level, node.items[index], node, {}).text;
|
|
3181
|
+
if (index > 0) result += `,${!state.flowSkipCommaSpace ? " " : ""}`;
|
|
2766
3182
|
result += item;
|
|
2767
3183
|
}
|
|
2768
|
-
const pad = state.flowBracketPadding &&
|
|
3184
|
+
const pad = state.flowBracketPadding && node.items.length > 0 ? " " : "";
|
|
2769
3185
|
return `[${pad}${result}${pad}]`;
|
|
2770
3186
|
}
|
|
2771
3187
|
function writeBlockSequence(state, level, node, compact) {
|
|
2772
3188
|
let result = "";
|
|
2773
3189
|
for (let index = 0, length = node.items.length; index < length; index += 1) {
|
|
2774
|
-
const item = writeNode(state, level + 1, node.items[index], {
|
|
3190
|
+
const item = writeNode(state, level + 1, node.items[index], node, {
|
|
2775
3191
|
block: true,
|
|
2776
3192
|
compact: state.seqInlineFirst,
|
|
2777
3193
|
isblockseq: true
|
|
2778
|
-
});
|
|
3194
|
+
}).text;
|
|
2779
3195
|
if (!compact || result !== "") result += generateNextLine(state, level);
|
|
2780
3196
|
if (item === "" || CHAR_LINE_FEED === item.charCodeAt(0)) result += "-";
|
|
2781
3197
|
else result += "- ";
|
|
@@ -2785,70 +3201,51 @@ function writeBlockSequence(state, level, node, compact) {
|
|
|
2785
3201
|
}
|
|
2786
3202
|
function writeFlowMapping(state, level, node) {
|
|
2787
3203
|
let result = "";
|
|
2788
|
-
const
|
|
2789
|
-
for (const { key, value } of items) {
|
|
3204
|
+
for (const { key, value } of node.items) {
|
|
2790
3205
|
let pairBuffer = "";
|
|
2791
3206
|
if (result !== "") pairBuffer += `,${!state.flowSkipCommaSpace ? " " : ""}`;
|
|
2792
|
-
const
|
|
2793
|
-
const
|
|
2794
|
-
|
|
2795
|
-
else if (state.quoteFlowKeys) pairBuffer += "\"";
|
|
2796
|
-
const valueText = writeNode(state, level, value, {});
|
|
3207
|
+
const keyRender = writeNode(state, level, key, node, { iskey: true });
|
|
3208
|
+
const keyText = keyRender.text;
|
|
3209
|
+
const valueText = writeNode(state, level, value, node, {}).text;
|
|
2797
3210
|
const sep = state.flowSkipColonSpace || valueText === "" ? "" : " ";
|
|
2798
|
-
|
|
3211
|
+
const keyIsBareProps = key.kind === "scalar" && keyRender.noBody && (key.tagged || key.anchor !== void 0);
|
|
3212
|
+
const keyColonSep = key.kind === "alias" || keyIsBareProps ? " " : "";
|
|
3213
|
+
pairBuffer += `${keyText}${keyColonSep}:${sep}${valueText}`;
|
|
2799
3214
|
result += pairBuffer;
|
|
2800
3215
|
}
|
|
2801
3216
|
const pad = state.flowBracketPadding && result !== "" ? " " : "";
|
|
2802
3217
|
return `{${pad}${result}${pad}}`;
|
|
2803
3218
|
}
|
|
2804
|
-
function sortKeyValue(key) {
|
|
2805
|
-
return key.kind === "scalar" ? key.value : key;
|
|
2806
|
-
}
|
|
2807
|
-
function sortMappingItems(state, items) {
|
|
2808
|
-
if (!state.sortKeys) return items;
|
|
2809
|
-
const copy = items.slice();
|
|
2810
|
-
if (state.sortKeys === true) copy.sort((a, b) => {
|
|
2811
|
-
const x = sortKeyValue(a.key);
|
|
2812
|
-
const y = sortKeyValue(b.key);
|
|
2813
|
-
if (x < y) return -1;
|
|
2814
|
-
if (x > y) return 1;
|
|
2815
|
-
return 0;
|
|
2816
|
-
});
|
|
2817
|
-
else {
|
|
2818
|
-
const fn = state.sortKeys;
|
|
2819
|
-
copy.sort((a, b) => fn(sortKeyValue(a.key), sortKeyValue(b.key)));
|
|
2820
|
-
}
|
|
2821
|
-
return copy;
|
|
2822
|
-
}
|
|
2823
3219
|
function writeBlockMapping(state, level, node, compact) {
|
|
2824
3220
|
let result = "";
|
|
2825
|
-
|
|
2826
|
-
for (let index = 0, length = items.length; index < length; index += 1) {
|
|
3221
|
+
for (let index = 0, length = node.items.length; index < length; index += 1) {
|
|
2827
3222
|
let pairBuffer = "";
|
|
2828
3223
|
if (!compact || result !== "") pairBuffer += generateNextLine(state, level);
|
|
2829
|
-
const { key, value } = items[index];
|
|
2830
|
-
const keyIsBlock = (key.kind === "mapping" || key.kind === "sequence") &&
|
|
2831
|
-
const
|
|
3224
|
+
const { key, value } = node.items[index];
|
|
3225
|
+
const keyIsBlock = (key.kind === "mapping" || key.kind === "sequence") && key.style === COLLECTION_STYLE.BLOCK && key.items.length !== 0 || key.kind === "scalar" && (key.style === SCALAR_STYLE.LITERAL_BLOCK || key.style === SCALAR_STYLE.FOLDED_BLOCK);
|
|
3226
|
+
const keyRender = keyIsBlock ? writeNode(state, level + 1, key, node, {
|
|
2832
3227
|
block: true,
|
|
2833
3228
|
compact: true,
|
|
2834
3229
|
isblockseq: !cannotBeCompact(state, key, level + 1)
|
|
2835
|
-
}) : writeNode(state, level + 1, key, {
|
|
3230
|
+
}) : writeNode(state, level + 1, key, node, {
|
|
2836
3231
|
block: true,
|
|
2837
3232
|
compact: true,
|
|
2838
3233
|
iskey: true
|
|
2839
3234
|
});
|
|
3235
|
+
const keyText = keyRender.text;
|
|
2840
3236
|
const keyHasLineBreak = key.kind === "scalar" && key.value.indexOf("\n") !== -1;
|
|
2841
|
-
const
|
|
3237
|
+
const keyIsTooLong = keyText.length > 1024 && /^[\s\S]{1025}/u.test(keyText);
|
|
3238
|
+
const explicitPair = keyIsBlock || keyHasLineBreak || keyIsTooLong;
|
|
2842
3239
|
if (explicitPair) if (keyText && CHAR_LINE_FEED === keyText.charCodeAt(0)) pairBuffer += "?";
|
|
2843
3240
|
else pairBuffer += "? ";
|
|
2844
3241
|
pairBuffer += keyText;
|
|
2845
3242
|
if (explicitPair) pairBuffer += generateNextLine(state, level);
|
|
2846
|
-
const valueText = writeNode(state, level + 1, value, {
|
|
3243
|
+
const valueText = writeNode(state, level + 1, value, node, {
|
|
2847
3244
|
block: true,
|
|
2848
3245
|
compact: explicitPair,
|
|
2849
3246
|
isblockseq: explicitPair && !cannotBeCompact(state, value, level + 1)
|
|
2850
|
-
});
|
|
2851
|
-
const keyIsBareProps = key.kind === "scalar" &&
|
|
3247
|
+
}).text;
|
|
3248
|
+
const keyIsBareProps = key.kind === "scalar" && keyRender.noBody && (key.tagged || key.anchor !== void 0);
|
|
2852
3249
|
const keyColonSep = !explicitPair && (key.kind === "alias" || keyIsBareProps) ? " " : "";
|
|
2853
3250
|
if (valueText === "" || CHAR_LINE_FEED === valueText.charCodeAt(0)) pairBuffer += `${keyColonSep}:`;
|
|
2854
3251
|
else pairBuffer += `${keyColonSep}: `;
|
|
@@ -2858,29 +3255,41 @@ function writeBlockMapping(state, level, node, compact) {
|
|
|
2858
3255
|
return result;
|
|
2859
3256
|
}
|
|
2860
3257
|
function cannotBeCompact(state, node, level) {
|
|
2861
|
-
|
|
3258
|
+
if (node.kind === "alias") return true;
|
|
3259
|
+
return node.tagged || node.anchor !== void 0 || state.indent < 2 && level > 0;
|
|
2862
3260
|
}
|
|
2863
|
-
function writeNode(state, level, node, ctx) {
|
|
2864
|
-
if (node.kind === "alias")
|
|
3261
|
+
function writeNode(state, level, node, parent, ctx) {
|
|
3262
|
+
if (node.kind === "alias") {
|
|
3263
|
+
state.openEnded = false;
|
|
3264
|
+
return {
|
|
3265
|
+
text: `*${node.anchor}`,
|
|
3266
|
+
noBody: false
|
|
3267
|
+
};
|
|
3268
|
+
}
|
|
2865
3269
|
const { block = false, iskey = false, isblockseq = false } = ctx;
|
|
2866
3270
|
let compact = ctx.compact ?? false;
|
|
2867
3271
|
const hasAnchor = node.anchor !== void 0;
|
|
2868
3272
|
if (cannotBeCompact(state, node, level)) compact = false;
|
|
2869
3273
|
let body;
|
|
2870
|
-
let shouldPrintTag = node.
|
|
2871
|
-
const useBlockCollection = block && (node.kind === "mapping" || node.kind === "sequence") &&
|
|
3274
|
+
let shouldPrintTag = node.tagged;
|
|
3275
|
+
const useBlockCollection = block && (node.kind === "mapping" || node.kind === "sequence") && node.style === COLLECTION_STYLE.BLOCK && node.items.length !== 0;
|
|
2872
3276
|
if (node.kind === "mapping") if (useBlockCollection) body = writeBlockMapping(state, level, node, compact);
|
|
2873
3277
|
else body = writeFlowMapping(state, level, node);
|
|
2874
3278
|
else if (node.kind === "sequence") if (useBlockCollection) if (state.seqNoIndent && !isblockseq && level > 0) body = writeBlockSequence(state, level - 1, node, compact);
|
|
2875
3279
|
else body = writeBlockSequence(state, level, node, compact);
|
|
2876
3280
|
else body = writeFlowSequence(state, level, node);
|
|
2877
3281
|
else {
|
|
2878
|
-
const layout = scalarLayout(state, level);
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
3282
|
+
const layout = scalarLayout(state, node, parent, level, iskey, !block);
|
|
3283
|
+
detectAllowedStyles(layout);
|
|
3284
|
+
for (const rule of state.scalarStyleRules) rule(layout);
|
|
3285
|
+
body = renderScalar(layout);
|
|
3286
|
+
state.openEnded = (layout.style === SCALAR_STYLE.LITERAL_BLOCK || layout.style === SCALAR_STYLE.FOLDED_BLOCK) && (node.value === "\n" || node.value.endsWith("\n\n"));
|
|
3287
|
+
shouldPrintTag = node.tagged || body === "" && layout.flowOnly && parent?.kind === "sequence" && !hasAnchor || layout.style !== SCALAR_STYLE.PLAIN && node.tag !== state.defaultScalarTagName;
|
|
3288
|
+
}
|
|
3289
|
+
if ((node.kind === "mapping" || node.kind === "sequence") && !useBlockCollection) state.openEnded = false;
|
|
2883
3290
|
if (useBlockCollection && compact && level > 0 && state.indent > 2) body = `${" ".repeat(state.indent - 2)}${body}`;
|
|
3291
|
+
const noBody = body === "";
|
|
3292
|
+
let text = body;
|
|
2884
3293
|
if (shouldPrintTag || hasAnchor) {
|
|
2885
3294
|
const props = [];
|
|
2886
3295
|
const tag = shouldPrintTag ? nodeTagShort(node) : null;
|
|
@@ -2893,19 +3302,15 @@ function writeNode(state, level, node, ctx) {
|
|
|
2893
3302
|
if (tag !== null) props.push(tag);
|
|
2894
3303
|
}
|
|
2895
3304
|
const sep = body === "" || body.charCodeAt(0) === CHAR_LINE_FEED ? "" : " ";
|
|
2896
|
-
|
|
3305
|
+
text = `${props.join(" ")}${sep}${body}`;
|
|
2897
3306
|
}
|
|
2898
|
-
return
|
|
3307
|
+
return {
|
|
3308
|
+
text,
|
|
3309
|
+
noBody
|
|
3310
|
+
};
|
|
2899
3311
|
}
|
|
2900
3312
|
function rootStartsOwnLine(node) {
|
|
2901
|
-
return (node.kind === "sequence" || node.kind === "mapping") &&
|
|
2902
|
-
}
|
|
2903
|
-
function isOpenEnded(node) {
|
|
2904
|
-
let leaf = node;
|
|
2905
|
-
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;
|
|
2906
|
-
if (leaf.kind !== "scalar" || !(leaf.style.literal || leaf.style.folded)) return false;
|
|
2907
|
-
const { value } = leaf;
|
|
2908
|
-
return value.endsWith("\n\n") || value === "\n";
|
|
3313
|
+
return (node.kind === "sequence" || node.kind === "mapping") && node.style === COLLECTION_STYLE.BLOCK && node.items.length !== 0 && !node.tagged && node.anchor === void 0;
|
|
2909
3314
|
}
|
|
2910
3315
|
function writeDocumentDirectives(doc) {
|
|
2911
3316
|
let result = "";
|
|
@@ -2919,12 +3324,18 @@ function writeDocumentDirectives(doc) {
|
|
|
2919
3324
|
}
|
|
2920
3325
|
return result;
|
|
2921
3326
|
}
|
|
3327
|
+
/**
|
|
3328
|
+
* Build YAML from AST.
|
|
3329
|
+
*
|
|
3330
|
+
* @category AST
|
|
3331
|
+
*/
|
|
2922
3332
|
function present(documents, options) {
|
|
2923
3333
|
const state = createPresenterState(options);
|
|
2924
3334
|
let result = "";
|
|
2925
3335
|
let previousEnded = false;
|
|
2926
3336
|
for (let index = 0; index < documents.length; index += 1) {
|
|
2927
3337
|
const doc = documents[index];
|
|
3338
|
+
state.openEnded = false;
|
|
2928
3339
|
const directives = writeDocumentDirectives(doc);
|
|
2929
3340
|
const hasDirectives = directives !== "";
|
|
2930
3341
|
const marker = doc.explicitStart || hasDirectives || index > 0 && !previousEnded;
|
|
@@ -2932,44 +3343,47 @@ function present(documents, options) {
|
|
|
2932
3343
|
if (doc.contents === null) {
|
|
2933
3344
|
if (marker) result += "---\n";
|
|
2934
3345
|
} else if (marker) {
|
|
2935
|
-
const body = writeNode(state, 0, doc.contents, {
|
|
3346
|
+
const body = writeNode(state, 0, doc.contents, null, {
|
|
2936
3347
|
block: true,
|
|
2937
3348
|
compact: true
|
|
2938
|
-
});
|
|
3349
|
+
}).text;
|
|
2939
3350
|
const sep = body === "" ? "" : hasDirectives || rootStartsOwnLine(doc.contents) ? "\n" : " ";
|
|
2940
3351
|
result += `---${sep}${body}\n`;
|
|
2941
|
-
} else result += writeNode(state, 0, doc.contents, {
|
|
3352
|
+
} else result += writeNode(state, 0, doc.contents, null, {
|
|
2942
3353
|
block: true,
|
|
2943
3354
|
compact: true
|
|
2944
|
-
}) + "\n";
|
|
2945
|
-
previousEnded = doc.explicitEnd ||
|
|
3355
|
+
}).text + "\n";
|
|
3356
|
+
previousEnded = doc.explicitEnd || state.openEnded;
|
|
2946
3357
|
if (previousEnded) result += "...\n";
|
|
2947
3358
|
}
|
|
2948
3359
|
return result;
|
|
2949
3360
|
}
|
|
2950
3361
|
//#endregion
|
|
2951
3362
|
//#region src/dump.ts
|
|
2952
|
-
var DEFAULT_DUMP_SCHEMA = YAML11_SCHEMA.withTags({
|
|
2953
|
-
...intYaml11Tag,
|
|
2954
|
-
resolve: (source, isExplicit, tagName) => {
|
|
2955
|
-
const result = intYaml11Tag.resolve(source, isExplicit, tagName);
|
|
2956
|
-
return result === NOT_RESOLVED ? intCoreTag.resolve(source, isExplicit, tagName) : result;
|
|
2957
|
-
}
|
|
2958
|
-
}, {
|
|
2959
|
-
...floatYaml11Tag,
|
|
2960
|
-
resolve: (source, isExplicit, tagName) => {
|
|
2961
|
-
const result = floatYaml11Tag.resolve(source, isExplicit, tagName);
|
|
2962
|
-
return result === NOT_RESOLVED ? floatCoreTag.resolve(source, isExplicit, tagName) : result;
|
|
2963
|
-
}
|
|
2964
|
-
});
|
|
2965
3363
|
var DEFAULT_DUMP_OPTIONS = {
|
|
2966
3364
|
...DEFAULT_PRESENTER_OPTIONS,
|
|
2967
|
-
schema:
|
|
3365
|
+
schema: DUMP_SCHEMA,
|
|
2968
3366
|
skipInvalid: false,
|
|
2969
3367
|
noRefs: false,
|
|
2970
3368
|
flowLevel: -1,
|
|
3369
|
+
sortKeys: false,
|
|
2971
3370
|
transform: () => {}
|
|
2972
3371
|
};
|
|
3372
|
+
function defaultCompareFn(a, b) {
|
|
3373
|
+
const x = String(a);
|
|
3374
|
+
const y = String(b);
|
|
3375
|
+
if (x < y) return -1;
|
|
3376
|
+
if (x > y) return 1;
|
|
3377
|
+
return 0;
|
|
3378
|
+
}
|
|
3379
|
+
/**
|
|
3380
|
+
* Serializes JS object as a YAML document. By default it can dump every
|
|
3381
|
+
* supported YAML type, so it throws an exception if you try to dump regexps or
|
|
3382
|
+
* functions. However, you can disable exceptions by setting the
|
|
3383
|
+
* {@link DumpOptions.skipInvalid} option to `true`.
|
|
3384
|
+
*
|
|
3385
|
+
* @category Main
|
|
3386
|
+
*/
|
|
2973
3387
|
function dump(input, options = {}) {
|
|
2974
3388
|
const opts = {
|
|
2975
3389
|
...DEFAULT_DUMP_OPTIONS,
|
|
@@ -2981,9 +3395,16 @@ function dump(input, options = {}) {
|
|
|
2981
3395
|
});
|
|
2982
3396
|
if (opts.flowLevel >= 0) visit(documents, (node, ctx) => {
|
|
2983
3397
|
if (ctx.depth < opts.flowLevel) return;
|
|
2984
|
-
node.
|
|
3398
|
+
if (node.kind === "sequence" || node.kind === "mapping") node.style = COLLECTION_STYLE.FLOW;
|
|
2985
3399
|
return VISIT_SKIP;
|
|
2986
3400
|
});
|
|
3401
|
+
if (opts.sortKeys) {
|
|
3402
|
+
const compareFn = opts.sortKeys === true ? defaultCompareFn : opts.sortKeys;
|
|
3403
|
+
visit(documents, (node) => {
|
|
3404
|
+
if (node.kind !== "mapping") return;
|
|
3405
|
+
node.items.sort((a, b) => compareFn(a.key.kind === "scalar" ? a.key.value : "", b.key.kind === "scalar" ? b.key.value : ""));
|
|
3406
|
+
});
|
|
3407
|
+
}
|
|
2987
3408
|
opts.transform(documents);
|
|
2988
3409
|
return present(documents, {
|
|
2989
3410
|
...pick(opts, Object.keys(DEFAULT_PRESENTER_OPTIONS)),
|
|
@@ -3006,57 +3427,38 @@ function rawTag(state, event) {
|
|
|
3006
3427
|
function anchorName(state, event) {
|
|
3007
3428
|
return event.anchorStart === NO_RANGE ? void 0 : state.source.slice(event.anchorStart, event.anchorEnd);
|
|
3008
3429
|
}
|
|
3009
|
-
function implicitScalarTagName(state, source) {
|
|
3010
|
-
const { schema } = state;
|
|
3011
|
-
const candidates = schema.implicitScalarByFirstChar.get(source.charAt(0)) ?? schema.implicitScalarAnyFirstChar;
|
|
3012
|
-
for (const tag of candidates) if (tag.resolve(source, false, tag.tagName) !== NOT_RESOLVED) return tag.tagName;
|
|
3013
|
-
return schema.defaultScalarTag.tagName;
|
|
3014
|
-
}
|
|
3015
3430
|
function buildScalar(state, event) {
|
|
3016
3431
|
const value = getScalarValue(state.source, event);
|
|
3017
3432
|
const raw = rawTag(state, event);
|
|
3018
|
-
const style = new Style();
|
|
3019
|
-
switch (event.style) {
|
|
3020
|
-
case 2:
|
|
3021
|
-
style.singleQuoted = true;
|
|
3022
|
-
break;
|
|
3023
|
-
case 3:
|
|
3024
|
-
style.doubleQuoted = true;
|
|
3025
|
-
break;
|
|
3026
|
-
case 4:
|
|
3027
|
-
style.literal = true;
|
|
3028
|
-
break;
|
|
3029
|
-
case 5:
|
|
3030
|
-
style.folded = true;
|
|
3031
|
-
break;
|
|
3032
|
-
}
|
|
3033
3433
|
let tag;
|
|
3434
|
+
let tagged = false;
|
|
3034
3435
|
if (raw !== "") {
|
|
3035
|
-
|
|
3436
|
+
tagged = true;
|
|
3036
3437
|
tag = raw;
|
|
3037
|
-
} else if (event.style ===
|
|
3438
|
+
} else if (event.style === SCALAR_STYLE.PLAIN) tag = state.schema.resolveImplicitScalarTag(value).tag.tagName;
|
|
3038
3439
|
else tag = state.schema.defaultScalarTag.tagName;
|
|
3039
3440
|
return {
|
|
3040
3441
|
kind: "scalar",
|
|
3041
3442
|
tag,
|
|
3042
|
-
|
|
3443
|
+
tagged,
|
|
3444
|
+
style: event.style,
|
|
3043
3445
|
anchor: anchorName(state, event),
|
|
3044
3446
|
value
|
|
3045
3447
|
};
|
|
3046
3448
|
}
|
|
3047
3449
|
function buildCollection(state, event, defaultTagName) {
|
|
3048
3450
|
const raw = rawTag(state, event);
|
|
3049
|
-
const style = new Style();
|
|
3050
|
-
if (event.style === 2) style.flow = true;
|
|
3051
3451
|
let tag;
|
|
3452
|
+
let tagged = false;
|
|
3052
3453
|
if (raw === "") tag = defaultTagName;
|
|
3053
3454
|
else {
|
|
3054
3455
|
tag = raw;
|
|
3055
|
-
|
|
3456
|
+
tagged = true;
|
|
3056
3457
|
}
|
|
3057
3458
|
return {
|
|
3058
3459
|
tag,
|
|
3059
|
-
|
|
3460
|
+
tagged,
|
|
3461
|
+
style: event.style,
|
|
3060
3462
|
anchor: anchorName(state, event)
|
|
3061
3463
|
};
|
|
3062
3464
|
}
|
|
@@ -3072,6 +3474,11 @@ function addNode(state, node) {
|
|
|
3072
3474
|
frame.key = null;
|
|
3073
3475
|
} else frame.key = node;
|
|
3074
3476
|
}
|
|
3477
|
+
/**
|
|
3478
|
+
* Builds an AST from parser events
|
|
3479
|
+
*
|
|
3480
|
+
* @category AST
|
|
3481
|
+
*/
|
|
3075
3482
|
function eventsToAst(events, options) {
|
|
3076
3483
|
const state = {
|
|
3077
3484
|
source: options.source,
|
|
@@ -3085,7 +3492,7 @@ function eventsToAst(events, options) {
|
|
|
3085
3492
|
const event = events[state.eventIndex++];
|
|
3086
3493
|
state.position = eventPosition(event);
|
|
3087
3494
|
switch (event.type) {
|
|
3088
|
-
case
|
|
3495
|
+
case EVENT_ID.DOCUMENT: {
|
|
3089
3496
|
const doc = {
|
|
3090
3497
|
contents: null,
|
|
3091
3498
|
explicitStart: event.explicitStart,
|
|
@@ -3098,14 +3505,15 @@ function eventsToAst(events, options) {
|
|
|
3098
3505
|
});
|
|
3099
3506
|
break;
|
|
3100
3507
|
}
|
|
3101
|
-
case
|
|
3508
|
+
case EVENT_ID.SCALAR:
|
|
3102
3509
|
addNode(state, buildScalar(state, event));
|
|
3103
3510
|
break;
|
|
3104
|
-
case
|
|
3105
|
-
const { tag, style, anchor } = buildCollection(state, event, "tag:yaml.org,2002:seq");
|
|
3511
|
+
case EVENT_ID.SEQUENCE: {
|
|
3512
|
+
const { tag, tagged, style, anchor } = buildCollection(state, event, "tag:yaml.org,2002:seq");
|
|
3106
3513
|
const node = {
|
|
3107
3514
|
kind: "sequence",
|
|
3108
3515
|
tag,
|
|
3516
|
+
tagged,
|
|
3109
3517
|
style,
|
|
3110
3518
|
anchor,
|
|
3111
3519
|
items: []
|
|
@@ -3116,11 +3524,12 @@ function eventsToAst(events, options) {
|
|
|
3116
3524
|
});
|
|
3117
3525
|
break;
|
|
3118
3526
|
}
|
|
3119
|
-
case
|
|
3120
|
-
const { tag, style, anchor } = buildCollection(state, event, "tag:yaml.org,2002:map");
|
|
3527
|
+
case EVENT_ID.MAPPING: {
|
|
3528
|
+
const { tag, tagged, style, anchor } = buildCollection(state, event, "tag:yaml.org,2002:map");
|
|
3121
3529
|
const node = {
|
|
3122
3530
|
kind: "mapping",
|
|
3123
3531
|
tag,
|
|
3532
|
+
tagged,
|
|
3124
3533
|
style,
|
|
3125
3534
|
anchor,
|
|
3126
3535
|
items: []
|
|
@@ -3132,17 +3541,13 @@ function eventsToAst(events, options) {
|
|
|
3132
3541
|
});
|
|
3133
3542
|
break;
|
|
3134
3543
|
}
|
|
3135
|
-
case
|
|
3136
|
-
const name = state.source.slice(event.anchorStart, event.anchorEnd);
|
|
3544
|
+
case EVENT_ID.ALIAS:
|
|
3137
3545
|
addNode(state, {
|
|
3138
3546
|
kind: "alias",
|
|
3139
|
-
|
|
3140
|
-
style: new Style(),
|
|
3141
|
-
anchor: name
|
|
3547
|
+
anchor: state.source.slice(event.anchorStart, event.anchorEnd)
|
|
3142
3548
|
});
|
|
3143
3549
|
break;
|
|
3144
|
-
|
|
3145
|
-
case 6: {
|
|
3550
|
+
case EVENT_ID.POP: {
|
|
3146
3551
|
const frame = state.frames.pop();
|
|
3147
3552
|
if (frame.kind === "mapping" && frame.key) throw new Error("incomplete mapping pair in event stream");
|
|
3148
3553
|
if (frame.kind === "document") state.documents.push(frame.doc);
|
|
@@ -3154,6 +3559,40 @@ function eventsToAst(events, options) {
|
|
|
3154
3559
|
return state.documents;
|
|
3155
3560
|
}
|
|
3156
3561
|
//#endregion
|
|
3157
|
-
|
|
3562
|
+
//#region src/index.ts
|
|
3563
|
+
/** @deprecated Use `EVENT_ID.DOCUMENT` instead. @internal */
|
|
3564
|
+
var EVENT_DOCUMENT = EVENT_ID.DOCUMENT;
|
|
3565
|
+
/** @deprecated Use `EVENT_ID.SEQUENCE` instead. @internal */
|
|
3566
|
+
var EVENT_SEQUENCE = EVENT_ID.SEQUENCE;
|
|
3567
|
+
/** @deprecated Use `EVENT_ID.MAPPING` instead. @internal */
|
|
3568
|
+
var EVENT_MAPPING = EVENT_ID.MAPPING;
|
|
3569
|
+
/** @deprecated Use `EVENT_ID.SCALAR` instead. @internal */
|
|
3570
|
+
var EVENT_SCALAR = EVENT_ID.SCALAR;
|
|
3571
|
+
/** @deprecated Use `EVENT_ID.ALIAS` instead. @internal */
|
|
3572
|
+
var EVENT_ALIAS = EVENT_ID.ALIAS;
|
|
3573
|
+
/** @deprecated Use `EVENT_ID.POP` instead. @internal */
|
|
3574
|
+
var EVENT_POP = EVENT_ID.POP;
|
|
3575
|
+
/** @deprecated Use `SCALAR_STYLE.PLAIN` instead. @internal */
|
|
3576
|
+
var SCALAR_STYLE_PLAIN = SCALAR_STYLE.PLAIN;
|
|
3577
|
+
/** @deprecated Use `SCALAR_STYLE.SINGLE_QUOTED` instead. @internal */
|
|
3578
|
+
var SCALAR_STYLE_SINGLE_QUOTED = SCALAR_STYLE.SINGLE_QUOTED;
|
|
3579
|
+
/** @deprecated Use `SCALAR_STYLE.DOUBLE_QUOTED` instead. @internal */
|
|
3580
|
+
var SCALAR_STYLE_DOUBLE_QUOTED = SCALAR_STYLE.DOUBLE_QUOTED;
|
|
3581
|
+
/** @deprecated Use `SCALAR_STYLE.LITERAL_BLOCK` instead. @internal */
|
|
3582
|
+
var SCALAR_STYLE_LITERAL_BLOCK = SCALAR_STYLE.LITERAL_BLOCK;
|
|
3583
|
+
/** @deprecated Use `SCALAR_STYLE.FOLDED_BLOCK` instead. @internal */
|
|
3584
|
+
var SCALAR_STYLE_FOLDED_BLOCK = SCALAR_STYLE.FOLDED_BLOCK;
|
|
3585
|
+
/** @deprecated Use `COLLECTION_STYLE.BLOCK` instead. @internal */
|
|
3586
|
+
var COLLECTION_STYLE_BLOCK = COLLECTION_STYLE.BLOCK;
|
|
3587
|
+
/** @deprecated Use `COLLECTION_STYLE.FLOW` instead. @internal */
|
|
3588
|
+
var COLLECTION_STYLE_FLOW = COLLECTION_STYLE.FLOW;
|
|
3589
|
+
/** @deprecated Use `CHOMPING_MODE.CLIP` instead. @internal */
|
|
3590
|
+
var CHOMPING_CLIP = CHOMPING_MODE.CLIP;
|
|
3591
|
+
/** @deprecated Use `CHOMPING_MODE.STRIP` instead. @internal */
|
|
3592
|
+
var CHOMPING_STRIP = CHOMPING_MODE.STRIP;
|
|
3593
|
+
/** @deprecated Use `CHOMPING_MODE.KEEP` instead. @internal */
|
|
3594
|
+
var CHOMPING_KEEP = CHOMPING_MODE.KEEP;
|
|
3595
|
+
//#endregion
|
|
3596
|
+
export { CHOMPING_CLIP, CHOMPING_KEEP, CHOMPING_MODE, CHOMPING_STRIP, COLLECTION_STYLE, COLLECTION_STYLE_BLOCK, COLLECTION_STYLE_FLOW, CORE_SCHEMA, DEFAULT_SCALAR_STYLE_RULES, DUMP_SCHEMA, EVENT_ALIAS, EVENT_DOCUMENT, EVENT_ID, EVENT_MAPPING, EVENT_POP, EVENT_SCALAR, EVENT_SEQUENCE, FAILSAFE_SCHEMA, JSON_SCHEMA, NOT_RESOLVED, SCALAR_STYLE, SCALAR_STYLE_DOUBLE_QUOTED, SCALAR_STYLE_FOLDED_BLOCK, SCALAR_STYLE_LITERAL_BLOCK, SCALAR_STYLE_PLAIN, SCALAR_STYLE_SINGLE_QUOTED, Schema, VISIT_BREAK, VISIT_SKIP, YAML11_SCHEMA, YAMLException, binaryTag, boolCoreTag, boolJsonTag, boolYaml11Tag, constructFromEvents, defineMappingTag, defineScalarTag, defineSequenceTag, dump, eventsToAst, floatCoreTag, floatJsonTag, floatYaml11Tag, getScalarValue, intCoreTag, intJsonTag, intYaml11Tag, jsToAst, legacyMapTag, load, loadAll, mapTag, mergeTag, nullCoreTag, nullJsonTag, nullYaml11Tag, omapTag, pairsTag, parseEvents, present, realMapTag, seqTag, setTag, strTag, timestampTag, visit };
|
|
3158
3597
|
|
|
3159
3598
|
//# sourceMappingURL=js-yaml.mjs.map
|