@node-core/utils 7.1.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/components/metadata.js +2 -1
- 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/prepare_security.js +20 -21
- package/lib/request.js +1 -1
- package/lib/update-v8/backport.js +3 -4
- package/lib/utils.js +4 -2
- 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 -9
- 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/isexe/LICENSE.md +0 -55
- package/node_modules/isexe/README.md +0 -80
- package/node_modules/isexe/dist/commonjs/index.d.ts +0 -14
- package/node_modules/isexe/dist/commonjs/index.d.ts.map +0 -1
- package/node_modules/isexe/dist/commonjs/index.js +0 -56
- package/node_modules/isexe/dist/commonjs/index.js.map +0 -1
- package/node_modules/isexe/dist/commonjs/index.min.js +0 -2
- package/node_modules/isexe/dist/commonjs/index.min.js.map +0 -7
- package/node_modules/isexe/dist/commonjs/options.d.ts +0 -32
- package/node_modules/isexe/dist/commonjs/options.d.ts.map +0 -1
- package/node_modules/isexe/dist/commonjs/options.js +0 -3
- package/node_modules/isexe/dist/commonjs/options.js.map +0 -1
- package/node_modules/isexe/dist/commonjs/package.json +0 -3
- package/node_modules/isexe/dist/commonjs/posix.d.ts +0 -18
- package/node_modules/isexe/dist/commonjs/posix.d.ts.map +0 -1
- package/node_modules/isexe/dist/commonjs/posix.js +0 -67
- package/node_modules/isexe/dist/commonjs/posix.js.map +0 -1
- package/node_modules/isexe/dist/commonjs/win32.d.ts +0 -18
- package/node_modules/isexe/dist/commonjs/win32.d.ts.map +0 -1
- package/node_modules/isexe/dist/commonjs/win32.js +0 -63
- package/node_modules/isexe/dist/commonjs/win32.js.map +0 -1
- package/node_modules/isexe/dist/esm/index.d.ts +0 -14
- package/node_modules/isexe/dist/esm/index.d.ts.map +0 -1
- package/node_modules/isexe/dist/esm/index.js +0 -16
- package/node_modules/isexe/dist/esm/index.js.map +0 -1
- package/node_modules/isexe/dist/esm/index.min.js +0 -2
- package/node_modules/isexe/dist/esm/index.min.js.map +0 -7
- package/node_modules/isexe/dist/esm/options.d.ts +0 -32
- package/node_modules/isexe/dist/esm/options.d.ts.map +0 -1
- package/node_modules/isexe/dist/esm/options.js +0 -2
- package/node_modules/isexe/dist/esm/options.js.map +0 -1
- package/node_modules/isexe/dist/esm/package.json +0 -3
- package/node_modules/isexe/dist/esm/posix.d.ts +0 -18
- package/node_modules/isexe/dist/esm/posix.d.ts.map +0 -1
- package/node_modules/isexe/dist/esm/posix.js +0 -62
- package/node_modules/isexe/dist/esm/posix.js.map +0 -1
- package/node_modules/isexe/dist/esm/win32.d.ts +0 -18
- package/node_modules/isexe/dist/esm/win32.d.ts.map +0 -1
- package/node_modules/isexe/dist/esm/win32.js +0 -58
- package/node_modules/isexe/dist/esm/win32.js.map +0 -1
- package/node_modules/isexe/package.json +0 -78
- 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/which/LICENSE +0 -15
- package/node_modules/which/README.md +0 -51
- package/node_modules/which/bin/which.js +0 -52
- package/node_modules/which/lib/index.js +0 -111
- package/node_modules/which/package.json +0 -52
- /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,10 +1,19 @@
|
|
|
1
|
-
/*! js-yaml 5.
|
|
1
|
+
/*! js-yaml 5.4.1 https://github.com/nodeca/js-yaml @license MIT */
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
//#region src/tag.ts
|
|
4
|
+
/**
|
|
5
|
+
* Returned by a scalar resolver when the source does not match its tag.
|
|
6
|
+
*
|
|
7
|
+
* @category Tags
|
|
8
|
+
*/
|
|
4
9
|
var NOT_RESOLVED = Symbol("NOT_RESOLVED");
|
|
5
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Create a normalized scalar tag definition.
|
|
12
|
+
*
|
|
13
|
+
* @category Tags
|
|
14
|
+
*/
|
|
6
15
|
function defineScalarTag(tagName, options) {
|
|
7
|
-
var _options$implicit, _options$matchByTagPr, _options$implicitFirs, _options$
|
|
16
|
+
var _options$implicit, _options$matchByTagPr, _options$implicitFirs, _options$represent, _options$representTag;
|
|
8
17
|
return {
|
|
9
18
|
tagName,
|
|
10
19
|
nodeKind: "scalar",
|
|
@@ -12,13 +21,18 @@ function defineScalarTag(tagName, options) {
|
|
|
12
21
|
matchByTagPrefix: (_options$matchByTagPr = options.matchByTagPrefix) !== null && _options$matchByTagPr !== void 0 ? _options$matchByTagPr : false,
|
|
13
22
|
implicitFirstChars: (_options$implicitFirs = options.implicitFirstChars) !== null && _options$implicitFirs !== void 0 ? _options$implicitFirs : null,
|
|
14
23
|
resolve: options.resolve,
|
|
15
|
-
identify:
|
|
24
|
+
identify: options.identify,
|
|
16
25
|
represent: (_options$represent = options.represent) !== null && _options$represent !== void 0 ? _options$represent : ((data) => String(data)),
|
|
17
|
-
representTagName: (_options$representTag = options.representTagName) !== null && _options$representTag !== void 0 ? _options$representTag :
|
|
26
|
+
representTagName: (_options$representTag = options.representTagName) !== null && _options$representTag !== void 0 ? _options$representTag : (() => tagName)
|
|
18
27
|
};
|
|
19
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Create a normalized sequence tag definition.
|
|
31
|
+
*
|
|
32
|
+
* @category Tags
|
|
33
|
+
*/
|
|
20
34
|
function defineSequenceTag(tagName, options) {
|
|
21
|
-
var _options$matchByTagPr2, _options$finalize, _options$
|
|
35
|
+
var _options$matchByTagPr2, _options$finalize, _options$represent2, _options$representTag2;
|
|
22
36
|
const carrierIsResult = options.finalize === void 0;
|
|
23
37
|
return {
|
|
24
38
|
tagName,
|
|
@@ -29,13 +43,18 @@ function defineSequenceTag(tagName, options) {
|
|
|
29
43
|
addItem: options.addItem,
|
|
30
44
|
finalize: (_options$finalize = options.finalize) !== null && _options$finalize !== void 0 ? _options$finalize : ((carrier) => carrier),
|
|
31
45
|
carrierIsResult,
|
|
32
|
-
identify:
|
|
46
|
+
identify: options.identify,
|
|
33
47
|
represent: (_options$represent2 = options.represent) !== null && _options$represent2 !== void 0 ? _options$represent2 : ((data) => data),
|
|
34
|
-
representTagName: (_options$representTag2 = options.representTagName) !== null && _options$representTag2 !== void 0 ? _options$representTag2 :
|
|
48
|
+
representTagName: (_options$representTag2 = options.representTagName) !== null && _options$representTag2 !== void 0 ? _options$representTag2 : (() => tagName)
|
|
35
49
|
};
|
|
36
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Create a normalized mapping tag definition.
|
|
53
|
+
*
|
|
54
|
+
* @category Tags
|
|
55
|
+
*/
|
|
37
56
|
function defineMappingTag(tagName, options) {
|
|
38
|
-
var _options$matchByTagPr3, _options$finalize2, _options$
|
|
57
|
+
var _options$matchByTagPr3, _options$finalize2, _options$represent3, _options$representTag3;
|
|
39
58
|
const carrierIsResult = options.finalize === void 0;
|
|
40
59
|
return {
|
|
41
60
|
tagName,
|
|
@@ -49,13 +68,14 @@ function defineMappingTag(tagName, options) {
|
|
|
49
68
|
get: options.get,
|
|
50
69
|
finalize: (_options$finalize2 = options.finalize) !== null && _options$finalize2 !== void 0 ? _options$finalize2 : ((carrier) => carrier),
|
|
51
70
|
carrierIsResult,
|
|
52
|
-
identify:
|
|
71
|
+
identify: options.identify,
|
|
53
72
|
represent: (_options$represent3 = options.represent) !== null && _options$represent3 !== void 0 ? _options$represent3 : ((data) => data),
|
|
54
|
-
representTagName: (_options$representTag3 = options.representTagName) !== null && _options$representTag3 !== void 0 ? _options$representTag3 :
|
|
73
|
+
representTagName: (_options$representTag3 = options.representTagName) !== null && _options$representTag3 !== void 0 ? _options$representTag3 : (() => tagName)
|
|
55
74
|
};
|
|
56
75
|
}
|
|
57
76
|
//#endregion
|
|
58
77
|
//#region src/tag/scalar/str.ts
|
|
78
|
+
/** @category Tags */
|
|
59
79
|
var strTag = defineScalarTag("tag:yaml.org,2002:str", {
|
|
60
80
|
resolve: (source) => source,
|
|
61
81
|
identify: (data) => typeof data === "string"
|
|
@@ -69,6 +89,7 @@ var NULL_VALUES$1 = [
|
|
|
69
89
|
"Null",
|
|
70
90
|
"NULL"
|
|
71
91
|
];
|
|
92
|
+
/** @category Tags */
|
|
72
93
|
var nullCoreTag = defineScalarTag("tag:yaml.org,2002:null", {
|
|
73
94
|
implicit: true,
|
|
74
95
|
implicitFirstChars: [
|
|
@@ -86,6 +107,7 @@ var nullCoreTag = defineScalarTag("tag:yaml.org,2002:null", {
|
|
|
86
107
|
});
|
|
87
108
|
//#endregion
|
|
88
109
|
//#region src/tag/scalar/null_json.ts
|
|
110
|
+
/** @category Tags */
|
|
89
111
|
var nullJsonTag = defineScalarTag("tag:yaml.org,2002:null", {
|
|
90
112
|
implicit: true,
|
|
91
113
|
implicitFirstChars: ["n"],
|
|
@@ -105,6 +127,7 @@ var NULL_VALUES = [
|
|
|
105
127
|
"Null",
|
|
106
128
|
"NULL"
|
|
107
129
|
];
|
|
130
|
+
/** @category Tags */
|
|
108
131
|
var nullYaml11Tag = defineScalarTag("tag:yaml.org,2002:null", {
|
|
109
132
|
implicit: true,
|
|
110
133
|
implicitFirstChars: [
|
|
@@ -132,6 +155,7 @@ var FALSE_VALUES$2 = [
|
|
|
132
155
|
"False",
|
|
133
156
|
"FALSE"
|
|
134
157
|
];
|
|
158
|
+
/** @category Tags */
|
|
135
159
|
var boolCoreTag = defineScalarTag("tag:yaml.org,2002:bool", {
|
|
136
160
|
implicit: true,
|
|
137
161
|
implicitFirstChars: [
|
|
@@ -152,6 +176,7 @@ var boolCoreTag = defineScalarTag("tag:yaml.org,2002:bool", {
|
|
|
152
176
|
//#region src/tag/scalar/bool_json.ts
|
|
153
177
|
var TRUE_VALUES$1 = ["true"];
|
|
154
178
|
var FALSE_VALUES$1 = ["false"];
|
|
179
|
+
/** @category Tags */
|
|
155
180
|
var boolJsonTag = defineScalarTag("tag:yaml.org,2002:bool", {
|
|
156
181
|
implicit: true,
|
|
157
182
|
implicitFirstChars: ["t", "f"],
|
|
@@ -191,6 +216,7 @@ var FALSE_VALUES = [
|
|
|
191
216
|
"Off",
|
|
192
217
|
"OFF"
|
|
193
218
|
];
|
|
219
|
+
/** @category Tags */
|
|
194
220
|
var boolYaml11Tag = defineScalarTag("tag:yaml.org,2002:bool", {
|
|
195
221
|
implicit: true,
|
|
196
222
|
implicitFirstChars: [
|
|
@@ -236,6 +262,7 @@ function resolveYamlInteger$2(source, isExplicit) {
|
|
|
236
262
|
const result = parseYamlInteger$2(source);
|
|
237
263
|
return Number.isFinite(result) ? result : NOT_RESOLVED;
|
|
238
264
|
}
|
|
265
|
+
/** @category Tags */
|
|
239
266
|
var intCoreTag = defineScalarTag("tag:yaml.org,2002:int", {
|
|
240
267
|
implicit: true,
|
|
241
268
|
implicitFirstChars: [
|
|
@@ -270,6 +297,7 @@ function resolveYamlInteger$1(source, isExplicit) {
|
|
|
270
297
|
const result = parseYamlInteger$1(source);
|
|
271
298
|
return Number.isFinite(result) ? result : NOT_RESOLVED;
|
|
272
299
|
}
|
|
300
|
+
/** @category Tags */
|
|
273
301
|
var intJsonTag = defineScalarTag("tag:yaml.org,2002:int", {
|
|
274
302
|
implicit: true,
|
|
275
303
|
implicitFirstChars: ["-", ..."0123456789"],
|
|
@@ -302,6 +330,7 @@ function resolveYamlInteger(source) {
|
|
|
302
330
|
const result = parseYamlInteger(source);
|
|
303
331
|
return Number.isFinite(result) ? result : NOT_RESOLVED;
|
|
304
332
|
}
|
|
333
|
+
/** @category Tags */
|
|
305
334
|
var intYaml11Tag = defineScalarTag("tag:yaml.org,2002:int", {
|
|
306
335
|
implicit: true,
|
|
307
336
|
implicitFirstChars: [
|
|
@@ -336,6 +365,7 @@ function representYamlFloat$2(object) {
|
|
|
336
365
|
const result = object.toString(10);
|
|
337
366
|
return /^[-+]?[0-9]+e/.test(result) ? result.replace("e", ".e") : result;
|
|
338
367
|
}
|
|
368
|
+
/** @category Tags */
|
|
339
369
|
var floatCoreTag = defineScalarTag("tag:yaml.org,2002:float", {
|
|
340
370
|
implicit: true,
|
|
341
371
|
implicitFirstChars: [
|
|
@@ -376,6 +406,7 @@ function representYamlFloat$1(object) {
|
|
|
376
406
|
const result = object.toString(10);
|
|
377
407
|
return /^[-+]?[0-9]+e/.test(result) ? result.replace("e", ".e") : result;
|
|
378
408
|
}
|
|
409
|
+
/** @category Tags */
|
|
379
410
|
var floatJsonTag = defineScalarTag("tag:yaml.org,2002:float", {
|
|
380
411
|
implicit: true,
|
|
381
412
|
implicitFirstChars: ["-", ..."0123456789"],
|
|
@@ -410,6 +441,7 @@ function representYamlFloat(object) {
|
|
|
410
441
|
const result = object.toString(10);
|
|
411
442
|
return /^[-+]?[0-9]+e/.test(result) ? result.replace("e", ".e") : result;
|
|
412
443
|
}
|
|
444
|
+
/** @category Tags */
|
|
413
445
|
var floatYaml11Tag = defineScalarTag("tag:yaml.org,2002:float", {
|
|
414
446
|
implicit: true,
|
|
415
447
|
implicitFirstChars: [
|
|
@@ -424,13 +456,20 @@ var floatYaml11Tag = defineScalarTag("tag:yaml.org,2002:float", {
|
|
|
424
456
|
});
|
|
425
457
|
//#endregion
|
|
426
458
|
//#region src/tag/scalar/merge.ts
|
|
459
|
+
/**
|
|
460
|
+
* Enables merge keys in {@link CORE_SCHEMA} when added with
|
|
461
|
+
* {@link Schema.withTags}.
|
|
462
|
+
*
|
|
463
|
+
* @category Tags
|
|
464
|
+
*/
|
|
427
465
|
var mergeTag = defineScalarTag("tag:yaml.org,2002:merge", {
|
|
428
466
|
implicit: true,
|
|
429
467
|
implicitFirstChars: ["<"],
|
|
430
468
|
resolve: (source, isExplicit) => {
|
|
431
|
-
if (source === "<<" || isExplicit && source === "") return
|
|
469
|
+
if (source === "<<" || isExplicit && source === "") return "<<";
|
|
432
470
|
return NOT_RESOLVED;
|
|
433
|
-
}
|
|
471
|
+
},
|
|
472
|
+
identify: () => false
|
|
434
473
|
});
|
|
435
474
|
//#endregion
|
|
436
475
|
//#region src/tag/scalar/binary.ts
|
|
@@ -448,6 +487,11 @@ function representYamlBinary(object) {
|
|
|
448
487
|
for (let index = 0; index < object.length; index++) binary += String.fromCharCode(object[index]);
|
|
449
488
|
return btoa(binary);
|
|
450
489
|
}
|
|
490
|
+
/**
|
|
491
|
+
* The `!!binary` tag, represented as a `Uint8Array`.
|
|
492
|
+
*
|
|
493
|
+
* @category Tags
|
|
494
|
+
*/
|
|
451
495
|
var binaryTag = defineScalarTag("tag:yaml.org,2002:binary", {
|
|
452
496
|
resolve: resolveYamlBinary,
|
|
453
497
|
identify: (object) => Object.prototype.toString.call(object) === "[object Uint8Array]",
|
|
@@ -495,6 +539,11 @@ function resolveYamlTimestamp(source) {
|
|
|
495
539
|
}
|
|
496
540
|
return date;
|
|
497
541
|
}
|
|
542
|
+
/**
|
|
543
|
+
* The YAML 1.1 `!!timestamp` tag, represented as a JavaScript `Date`.
|
|
544
|
+
*
|
|
545
|
+
* @category Tags
|
|
546
|
+
*/
|
|
498
547
|
var timestampTag = defineScalarTag("tag:yaml.org,2002:timestamp", {
|
|
499
548
|
implicit: true,
|
|
500
549
|
implicitFirstChars: [..."0123456789"],
|
|
@@ -504,6 +553,7 @@ var timestampTag = defineScalarTag("tag:yaml.org,2002:timestamp", {
|
|
|
504
553
|
});
|
|
505
554
|
//#endregion
|
|
506
555
|
//#region src/tag/sequence/seq.ts
|
|
556
|
+
/** @category Tags */
|
|
507
557
|
var seqTag = defineSequenceTag("tag:yaml.org,2002:seq", {
|
|
508
558
|
create: () => [],
|
|
509
559
|
addItem: (container, item) => {
|
|
@@ -525,6 +575,28 @@ function pick(object, keys) {
|
|
|
525
575
|
}
|
|
526
576
|
//#endregion
|
|
527
577
|
//#region src/tag/sequence/omap.ts
|
|
578
|
+
/**
|
|
579
|
+
* Provided only for YAML 1.1 compatibility and supported by the loader only.
|
|
580
|
+
* JavaScript has no dedicated class to represent this type, so it cannot be
|
|
581
|
+
* identified and dumped.
|
|
582
|
+
*
|
|
583
|
+
* ```yaml
|
|
584
|
+
* !!omap
|
|
585
|
+
* - one: 1
|
|
586
|
+
* - two: 2
|
|
587
|
+
* ```
|
|
588
|
+
*
|
|
589
|
+
* is loaded as
|
|
590
|
+
*
|
|
591
|
+
* ```javascript
|
|
592
|
+
* [
|
|
593
|
+
* { one: 1 },
|
|
594
|
+
* { two: 2 }
|
|
595
|
+
* ]
|
|
596
|
+
* ```
|
|
597
|
+
*
|
|
598
|
+
* @category Tags
|
|
599
|
+
*/
|
|
528
600
|
var omapTag = defineSequenceTag("tag:yaml.org,2002:omap", {
|
|
529
601
|
create: () => ({
|
|
530
602
|
list: [],
|
|
@@ -545,10 +617,33 @@ var omapTag = defineSequenceTag("tag:yaml.org,2002:omap", {
|
|
|
545
617
|
carrier.list.push(item);
|
|
546
618
|
return "";
|
|
547
619
|
},
|
|
548
|
-
finalize: (carrier) => carrier.list
|
|
620
|
+
finalize: (carrier) => carrier.list,
|
|
621
|
+
identify: () => false
|
|
549
622
|
});
|
|
550
623
|
//#endregion
|
|
551
624
|
//#region src/tag/sequence/pairs.ts
|
|
625
|
+
/**
|
|
626
|
+
* Provided only for YAML 1.1 compatibility and supported by the loader only.
|
|
627
|
+
* JavaScript has no dedicated class to represent this type, so it cannot be
|
|
628
|
+
* identified and dumped.
|
|
629
|
+
*
|
|
630
|
+
* ```yaml
|
|
631
|
+
* !!pairs
|
|
632
|
+
* - one: 1
|
|
633
|
+
* - two: 2
|
|
634
|
+
* ```
|
|
635
|
+
*
|
|
636
|
+
* is loaded as
|
|
637
|
+
*
|
|
638
|
+
* ```javascript
|
|
639
|
+
* [
|
|
640
|
+
* ['one', 1],
|
|
641
|
+
* ['two', 2]
|
|
642
|
+
* ]
|
|
643
|
+
* ```
|
|
644
|
+
*
|
|
645
|
+
* @category Tags
|
|
646
|
+
*/
|
|
552
647
|
var pairsTag = defineSequenceTag("tag:yaml.org,2002:pairs", {
|
|
553
648
|
create: () => [],
|
|
554
649
|
addItem: (container, item) => {
|
|
@@ -563,10 +658,32 @@ var pairsTag = defineSequenceTag("tag:yaml.org,2002:pairs", {
|
|
|
563
658
|
if (keys.length !== 1) return "cannot resolve a pairs item";
|
|
564
659
|
container.push([keys[0], object[keys[0]]]);
|
|
565
660
|
return "";
|
|
566
|
-
}
|
|
661
|
+
},
|
|
662
|
+
identify: () => false
|
|
567
663
|
});
|
|
568
664
|
//#endregion
|
|
569
665
|
//#region src/tag/mapping/map.ts
|
|
666
|
+
/**
|
|
667
|
+
* This is the default mapping implementation. It uses `{}` objects and has only
|
|
668
|
+
* partial functionality due to language limitations. This choice was made
|
|
669
|
+
* because users expect to get JavaScript objects, and it was left unchanged to
|
|
670
|
+
* avoid too many breaking changes in the v5 release.
|
|
671
|
+
*
|
|
672
|
+
* Side effects:
|
|
673
|
+
*
|
|
674
|
+
* - `Object.hasOwn()` checks or `for...of` loops are required for safe use (to
|
|
675
|
+
* avoid falling through to prototypes).
|
|
676
|
+
* - Only scalar string keys are supported properly.
|
|
677
|
+
* - Other scalar keys, such as `null` and numbers, are converted to strings.
|
|
678
|
+
* This is historical behaviour, and it can cause side effects such as
|
|
679
|
+
* problems with `!!merge`.
|
|
680
|
+
*
|
|
681
|
+
* Note that non-string scalar keys may be deprecated in future versions.
|
|
682
|
+
*
|
|
683
|
+
* Ideally, use {@link realMapTag} instead.
|
|
684
|
+
*
|
|
685
|
+
* @category Tags
|
|
686
|
+
*/
|
|
570
687
|
var mapTag = defineMappingTag("tag:yaml.org,2002:map", {
|
|
571
688
|
create: () => ({}),
|
|
572
689
|
identify: isPlainObject,
|
|
@@ -600,6 +717,11 @@ var mapTag = defineMappingTag("tag:yaml.org,2002:map", {
|
|
|
600
717
|
});
|
|
601
718
|
//#endregion
|
|
602
719
|
//#region src/tag/mapping/set.ts
|
|
720
|
+
/**
|
|
721
|
+
* The YAML 1.1 `!!set` tag, represented as a JavaScript `Set`.
|
|
722
|
+
*
|
|
723
|
+
* @category Tags
|
|
724
|
+
*/
|
|
603
725
|
var setTag = defineMappingTag("tag:yaml.org,2002:set", {
|
|
604
726
|
create: () => /* @__PURE__ */ new Set(),
|
|
605
727
|
identify: (data) => data instanceof Set,
|
|
@@ -656,6 +778,29 @@ function _defineProperty(e, r, t) {
|
|
|
656
778
|
}) : e[r] = t, e;
|
|
657
779
|
}
|
|
658
780
|
//#endregion
|
|
781
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/objectSpread2.js
|
|
782
|
+
function ownKeys(e, r) {
|
|
783
|
+
var t = Object.keys(e);
|
|
784
|
+
if (Object.getOwnPropertySymbols) {
|
|
785
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
786
|
+
r && (o = o.filter(function(r) {
|
|
787
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
788
|
+
})), t.push.apply(t, o);
|
|
789
|
+
}
|
|
790
|
+
return t;
|
|
791
|
+
}
|
|
792
|
+
function _objectSpread2(e) {
|
|
793
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
794
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
795
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
|
|
796
|
+
_defineProperty(e, r, t[r]);
|
|
797
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
|
|
798
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
799
|
+
});
|
|
800
|
+
}
|
|
801
|
+
return e;
|
|
802
|
+
}
|
|
803
|
+
//#endregion
|
|
659
804
|
//#region src/schema.ts
|
|
660
805
|
function createTagDefinitionMap() {
|
|
661
806
|
return {
|
|
@@ -686,15 +831,64 @@ function compileTags(tags) {
|
|
|
686
831
|
}
|
|
687
832
|
return result;
|
|
688
833
|
}
|
|
834
|
+
/**
|
|
835
|
+
* Controls tag resolution when loading and type selection when dumping.
|
|
836
|
+
*
|
|
837
|
+
* @category Schemas
|
|
838
|
+
*/
|
|
689
839
|
var Schema = class Schema {
|
|
690
840
|
constructor(tags) {
|
|
691
841
|
_defineProperty(this, "tags", void 0);
|
|
692
|
-
_defineProperty(
|
|
693
|
-
|
|
842
|
+
_defineProperty(
|
|
843
|
+
this,
|
|
844
|
+
/** @internal */
|
|
845
|
+
"implicitScalarTags",
|
|
846
|
+
void 0
|
|
847
|
+
);
|
|
848
|
+
_defineProperty(
|
|
849
|
+
this,
|
|
850
|
+
/**
|
|
851
|
+
* Dispatch implicit scalar resolvers by `source.charAt(0)`. Each bucket holds
|
|
852
|
+
* the resolvers that may match that key, in schema order; a key absent from
|
|
853
|
+
* the map uses
|
|
854
|
+
* {@link Schema.implicitScalarAnyFirstChar}
|
|
855
|
+
* (resolvers that declared no first-char constraint, so they apply to any
|
|
856
|
+
* first character).
|
|
857
|
+
*/
|
|
858
|
+
"implicitScalarByFirstChar",
|
|
859
|
+
void 0
|
|
860
|
+
);
|
|
694
861
|
_defineProperty(this, "implicitScalarAnyFirstChar", void 0);
|
|
695
|
-
_defineProperty(
|
|
696
|
-
|
|
697
|
-
|
|
862
|
+
_defineProperty(
|
|
863
|
+
this,
|
|
864
|
+
/**
|
|
865
|
+
* The default scalar tag (`!!str`), resolved once so the composer's fallback
|
|
866
|
+
* for unresolved plain scalars avoids a keyed lookup per scalar.
|
|
867
|
+
*
|
|
868
|
+
* @internal
|
|
869
|
+
*/
|
|
870
|
+
"defaultScalarTag",
|
|
871
|
+
void 0
|
|
872
|
+
);
|
|
873
|
+
_defineProperty(
|
|
874
|
+
this,
|
|
875
|
+
/**
|
|
876
|
+
* The default container tags (`!!seq` / `!!map`), used by the dumper: when a
|
|
877
|
+
* value is identified by its default tag, the tag is implicit and not
|
|
878
|
+
* printed. Undefined if the schema does not define them (then such values
|
|
879
|
+
* can't be dumped).
|
|
880
|
+
*
|
|
881
|
+
* @internal
|
|
882
|
+
*/
|
|
883
|
+
"defaultSequenceTag",
|
|
884
|
+
void 0
|
|
885
|
+
);
|
|
886
|
+
_defineProperty(
|
|
887
|
+
this,
|
|
888
|
+
/** @internal */
|
|
889
|
+
"defaultMappingTag",
|
|
890
|
+
void 0
|
|
891
|
+
);
|
|
698
892
|
_defineProperty(this, "exact", void 0);
|
|
699
893
|
_defineProperty(this, "prefix", void 0);
|
|
700
894
|
const compiledTags = compileTags(tags);
|
|
@@ -738,17 +932,75 @@ var Schema = class Schema {
|
|
|
738
932
|
this.exact = exact;
|
|
739
933
|
this.prefix = prefix;
|
|
740
934
|
}
|
|
935
|
+
/** @internal */
|
|
936
|
+
lookupScalarTag(tagName) {
|
|
937
|
+
const exactTag = this.exact.scalar[tagName];
|
|
938
|
+
if (exactTag) return exactTag;
|
|
939
|
+
for (const tag of this.prefix.scalar) if (tagName.startsWith(tag.tagName)) return tag;
|
|
940
|
+
}
|
|
941
|
+
/** @internal */
|
|
942
|
+
lookupSequenceTag(tagName) {
|
|
943
|
+
const exactTag = this.exact.sequence[tagName];
|
|
944
|
+
if (exactTag) return exactTag;
|
|
945
|
+
for (const tag of this.prefix.sequence) if (tagName.startsWith(tag.tagName)) return tag;
|
|
946
|
+
}
|
|
947
|
+
/** @internal */
|
|
948
|
+
lookupMappingTag(tagName) {
|
|
949
|
+
const exactTag = this.exact.mapping[tagName];
|
|
950
|
+
if (exactTag) return exactTag;
|
|
951
|
+
for (const tag of this.prefix.mapping) if (tagName.startsWith(tag.tagName)) return tag;
|
|
952
|
+
}
|
|
953
|
+
/** @internal */
|
|
954
|
+
resolveImplicitScalarTag(source) {
|
|
955
|
+
var _this$implicitScalarB;
|
|
956
|
+
const candidates = (_this$implicitScalarB = this.implicitScalarByFirstChar.get(source.charAt(0))) !== null && _this$implicitScalarB !== void 0 ? _this$implicitScalarB : this.implicitScalarAnyFirstChar;
|
|
957
|
+
for (const tag of candidates) {
|
|
958
|
+
const value = tag.resolve(source, false, tag.tagName);
|
|
959
|
+
if (value !== NOT_RESOLVED) return {
|
|
960
|
+
value,
|
|
961
|
+
tag
|
|
962
|
+
};
|
|
963
|
+
}
|
|
964
|
+
const tag = this.defaultScalarTag;
|
|
965
|
+
return {
|
|
966
|
+
value: tag.resolve(source, false, tag.tagName),
|
|
967
|
+
tag
|
|
968
|
+
};
|
|
969
|
+
}
|
|
970
|
+
/**
|
|
971
|
+
* Creates a new schema with the specified tags added. If a tag already
|
|
972
|
+
* exists, it is replaced by the specified tag.
|
|
973
|
+
*
|
|
974
|
+
* @example
|
|
975
|
+
*
|
|
976
|
+
* ```javascript
|
|
977
|
+
* import { CORE_SCHEMA, mergeTag, realMapTag } from 'js-yaml'
|
|
978
|
+
*
|
|
979
|
+
* const schema = CORE_SCHEMA.withTags(mergeTag, realMapTag)
|
|
980
|
+
* ```
|
|
981
|
+
*/
|
|
741
982
|
withTags(...tags) {
|
|
742
983
|
let flatTags = [];
|
|
743
984
|
for (const tag of tags) flatTags = flatTags.concat(tag);
|
|
744
985
|
return new Schema([...this.tags, ...flatTags]);
|
|
745
986
|
}
|
|
746
987
|
};
|
|
988
|
+
/**
|
|
989
|
+
* The YAML 1.2 Failsafe Schema: strings, sequences, and mappings.
|
|
990
|
+
*
|
|
991
|
+
* @category Schemas
|
|
992
|
+
*/
|
|
747
993
|
var FAILSAFE_SCHEMA = new Schema([
|
|
748
994
|
strTag,
|
|
749
995
|
seqTag,
|
|
750
996
|
mapTag
|
|
751
997
|
]);
|
|
998
|
+
/**
|
|
999
|
+
* The YAML 1.2 JSON Schema. It uses JSON scalar forms while retaining YAML
|
|
1000
|
+
* collection syntax.
|
|
1001
|
+
*
|
|
1002
|
+
* @category Schemas
|
|
1003
|
+
*/
|
|
752
1004
|
var JSON_SCHEMA = new Schema([
|
|
753
1005
|
...FAILSAFE_SCHEMA.tags,
|
|
754
1006
|
nullJsonTag,
|
|
@@ -756,6 +1008,25 @@ var JSON_SCHEMA = new Schema([
|
|
|
756
1008
|
intJsonTag,
|
|
757
1009
|
floatJsonTag
|
|
758
1010
|
]);
|
|
1011
|
+
/**
|
|
1012
|
+
* The default schema for the loaders. Note, {@link CORE_SCHEMA} comes
|
|
1013
|
+
* without the `!!merge` tag. You can easily enable it if needed.
|
|
1014
|
+
*
|
|
1015
|
+
* @example
|
|
1016
|
+
* Enable {@link mergeTag}:
|
|
1017
|
+
*
|
|
1018
|
+
* ```javascript
|
|
1019
|
+
* import { load, CORE_SCHEMA, mergeTag } from 'js-yaml'
|
|
1020
|
+
*
|
|
1021
|
+
* try {
|
|
1022
|
+
* load(data, { schema: CORE_SCHEMA.withTags(mergeTag) })
|
|
1023
|
+
* } catch (e) {
|
|
1024
|
+
* console.error(e)
|
|
1025
|
+
* }
|
|
1026
|
+
* ```
|
|
1027
|
+
*
|
|
1028
|
+
* @category Schemas
|
|
1029
|
+
*/
|
|
759
1030
|
var CORE_SCHEMA = new Schema([
|
|
760
1031
|
...FAILSAFE_SCHEMA.tags,
|
|
761
1032
|
nullCoreTag,
|
|
@@ -763,6 +1034,11 @@ var CORE_SCHEMA = new Schema([
|
|
|
763
1034
|
intCoreTag,
|
|
764
1035
|
floatCoreTag
|
|
765
1036
|
]);
|
|
1037
|
+
/**
|
|
1038
|
+
* YAML 1.1-compatible schema.
|
|
1039
|
+
*
|
|
1040
|
+
* @category Schemas
|
|
1041
|
+
*/
|
|
766
1042
|
var YAML11_SCHEMA = new Schema([
|
|
767
1043
|
...FAILSAFE_SCHEMA.tags,
|
|
768
1044
|
nullYaml11Tag,
|
|
@@ -776,8 +1052,54 @@ var YAML11_SCHEMA = new Schema([
|
|
|
776
1052
|
pairsTag,
|
|
777
1053
|
setTag
|
|
778
1054
|
]);
|
|
1055
|
+
/**
|
|
1056
|
+
* The dumper schema for maximum compatibility. It combines all supported type
|
|
1057
|
+
* variants from YAML 1.1 and YAML 1.2 so strings matching any of them are
|
|
1058
|
+
* quoted. This makes the generated YAML more compatible with other parsers.
|
|
1059
|
+
*
|
|
1060
|
+
* The schema is based on YAML 1.1, but extends `!!int` and `!!float` to accept
|
|
1061
|
+
* both YAML 1.1 and Core Schema forms, since Core Schema supports some forms
|
|
1062
|
+
* that YAML 1.1 does not.
|
|
1063
|
+
*
|
|
1064
|
+
* @category Schemas
|
|
1065
|
+
*/
|
|
1066
|
+
var DUMP_SCHEMA = YAML11_SCHEMA.withTags(_objectSpread2(_objectSpread2({}, intYaml11Tag), {}, { resolve: (source, isExplicit, tagName) => {
|
|
1067
|
+
const result = intYaml11Tag.resolve(source, isExplicit, tagName);
|
|
1068
|
+
return result === NOT_RESOLVED ? intCoreTag.resolve(source, isExplicit, tagName) : result;
|
|
1069
|
+
} }), _objectSpread2(_objectSpread2({}, floatYaml11Tag), {}, { resolve: (source, isExplicit, tagName) => {
|
|
1070
|
+
const result = floatYaml11Tag.resolve(source, isExplicit, tagName);
|
|
1071
|
+
return result === NOT_RESOLVED ? floatCoreTag.resolve(source, isExplicit, tagName) : result;
|
|
1072
|
+
} }));
|
|
779
1073
|
//#endregion
|
|
780
1074
|
//#region src/tag/mapping/real_map.ts
|
|
1075
|
+
/**
|
|
1076
|
+
* Recommended when non-string keys are actually needed. It uses native
|
|
1077
|
+
* JavaScript `Map` objects, so keys keep their constructed types instead of
|
|
1078
|
+
* being converted to strings.
|
|
1079
|
+
*
|
|
1080
|
+
* It is not the default to avoid widespread breaking changes in existing
|
|
1081
|
+
* projects. `Map` has a different access API and does not pass deep equality
|
|
1082
|
+
* checks against `{}`-based fixtures. Alongside the other changes in v5,
|
|
1083
|
+
* making it the default was considered too disruptive.
|
|
1084
|
+
*
|
|
1085
|
+
* If these differences are acceptable for your project, we recommend using
|
|
1086
|
+
* {@link realMapTag} to guarantee the absence of problems and side effects.
|
|
1087
|
+
*
|
|
1088
|
+
* @example
|
|
1089
|
+
* Enable {@link realMapTag}:
|
|
1090
|
+
*
|
|
1091
|
+
* ```javascript
|
|
1092
|
+
* import { load, CORE_SCHEMA, realMapTag } from 'js-yaml'
|
|
1093
|
+
*
|
|
1094
|
+
* try {
|
|
1095
|
+
* load(data, { schema: CORE_SCHEMA.withTags(realMapTag) })
|
|
1096
|
+
* } catch (e) {
|
|
1097
|
+
* console.error(e)
|
|
1098
|
+
* }
|
|
1099
|
+
* ```
|
|
1100
|
+
*
|
|
1101
|
+
* @category Tags
|
|
1102
|
+
*/
|
|
781
1103
|
var realMapTag = defineMappingTag("tag:yaml.org,2002:map", {
|
|
782
1104
|
create: () => /* @__PURE__ */ new Map(),
|
|
783
1105
|
addPair: (container, key, value) => {
|
|
@@ -810,6 +1132,13 @@ function normalizeKey(key) {
|
|
|
810
1132
|
if (typeof key === "object" && Object.prototype.toString.call(key) === "[object Object]") return "[object Object]";
|
|
811
1133
|
return String(key);
|
|
812
1134
|
}
|
|
1135
|
+
/**
|
|
1136
|
+
* This implementation exists solely to reproduce v4 behavior exactly. Its use
|
|
1137
|
+
* is strongly discouraged. If complex or non-string keys are needed, use
|
|
1138
|
+
* {@link realMapTag} instead.
|
|
1139
|
+
*
|
|
1140
|
+
* @category Tags
|
|
1141
|
+
*/
|
|
813
1142
|
var legacyMapTag = defineMappingTag("tag:yaml.org,2002:map", {
|
|
814
1143
|
create: () => ({}),
|
|
815
1144
|
identify: isPlainObject,
|
|
@@ -842,29 +1171,6 @@ var legacyMapTag = defineMappingTag("tag:yaml.org,2002:map", {
|
|
|
842
1171
|
}
|
|
843
1172
|
});
|
|
844
1173
|
//#endregion
|
|
845
|
-
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/objectSpread2.js
|
|
846
|
-
function ownKeys(e, r) {
|
|
847
|
-
var t = Object.keys(e);
|
|
848
|
-
if (Object.getOwnPropertySymbols) {
|
|
849
|
-
var o = Object.getOwnPropertySymbols(e);
|
|
850
|
-
r && (o = o.filter(function(r) {
|
|
851
|
-
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
852
|
-
})), t.push.apply(t, o);
|
|
853
|
-
}
|
|
854
|
-
return t;
|
|
855
|
-
}
|
|
856
|
-
function _objectSpread2(e) {
|
|
857
|
-
for (var r = 1; r < arguments.length; r++) {
|
|
858
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
|
859
|
-
r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
|
|
860
|
-
_defineProperty(e, r, t[r]);
|
|
861
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
|
|
862
|
-
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
863
|
-
});
|
|
864
|
-
}
|
|
865
|
-
return e;
|
|
866
|
-
}
|
|
867
|
-
//#endregion
|
|
868
1174
|
//#region src/common/snippet.ts
|
|
869
1175
|
var DEFAULT_SNIPPET_OPTIONS = {
|
|
870
1176
|
maxLength: 79,
|
|
@@ -934,7 +1240,17 @@ function formatError(exception, compact) {
|
|
|
934
1240
|
if (!compact && exception.mark.snippet) where += `\n\n${exception.mark.snippet}`;
|
|
935
1241
|
return `${exception.reason} ${where}`;
|
|
936
1242
|
}
|
|
937
|
-
|
|
1243
|
+
/**
|
|
1244
|
+
* A YAML error. Unlike an ordinary `Error`, it adds a source snippet showing
|
|
1245
|
+
* the location of the problem to the error message, when available.
|
|
1246
|
+
*
|
|
1247
|
+
* @category Main
|
|
1248
|
+
*/
|
|
1249
|
+
var YAMLException = class YAMLException extends Error {
|
|
1250
|
+
/**
|
|
1251
|
+
* Optional `mark` contains source snippet data. Usually, use
|
|
1252
|
+
* {@link YAMLException.throwAt} instead of passing it directly.
|
|
1253
|
+
*/
|
|
938
1254
|
constructor(reason, mark) {
|
|
939
1255
|
super();
|
|
940
1256
|
_defineProperty(this, "reason", void 0);
|
|
@@ -945,52 +1261,71 @@ var YAMLException = class extends Error {
|
|
|
945
1261
|
this.message = formatError(this, false);
|
|
946
1262
|
if (Error.captureStackTrace) Error.captureStackTrace(this, this.constructor);
|
|
947
1263
|
}
|
|
1264
|
+
/**
|
|
1265
|
+
* Returns the formatted error, omitting the source snippet in compact mode.
|
|
1266
|
+
*/
|
|
948
1267
|
toString(compact) {
|
|
949
1268
|
return `${this.name}: ${formatError(this, compact)}`;
|
|
950
1269
|
}
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
1270
|
+
/**
|
|
1271
|
+
* Builds a YAMLException with a source snippet and throws it. `source` is
|
|
1272
|
+
* the raw input text; `position` is an offset into it.
|
|
1273
|
+
*/
|
|
1274
|
+
static throwAt(source, position, message, filename = "") {
|
|
1275
|
+
let line = 0;
|
|
1276
|
+
let lineStart = 0;
|
|
1277
|
+
for (let index = 0; index < position; index++) {
|
|
1278
|
+
const ch = source.charCodeAt(index);
|
|
1279
|
+
if (ch === 10) {
|
|
1280
|
+
line++;
|
|
1281
|
+
lineStart = index + 1;
|
|
1282
|
+
} else if (ch === 13) {
|
|
1283
|
+
line++;
|
|
1284
|
+
if (source.charCodeAt(index + 1) === 10) index++;
|
|
1285
|
+
lineStart = index + 1;
|
|
1286
|
+
}
|
|
964
1287
|
}
|
|
1288
|
+
const mark = {
|
|
1289
|
+
name: filename,
|
|
1290
|
+
buffer: source,
|
|
1291
|
+
position,
|
|
1292
|
+
line,
|
|
1293
|
+
column: position - lineStart
|
|
1294
|
+
};
|
|
1295
|
+
mark.snippet = makeSnippet(mark);
|
|
1296
|
+
throw new YAMLException(message, mark);
|
|
965
1297
|
}
|
|
966
|
-
|
|
967
|
-
name: filename,
|
|
968
|
-
buffer: source,
|
|
969
|
-
position,
|
|
970
|
-
line,
|
|
971
|
-
column: position - lineStart
|
|
972
|
-
};
|
|
973
|
-
mark.snippet = makeSnippet(mark);
|
|
974
|
-
throw new YAMLException(message, mark);
|
|
975
|
-
}
|
|
1298
|
+
};
|
|
976
1299
|
//#endregion
|
|
977
1300
|
//#region src/parser/events.ts
|
|
978
|
-
|
|
979
|
-
var
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
var
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
1301
|
+
/** @category Events */
|
|
1302
|
+
var EVENT_ID = {
|
|
1303
|
+
DOCUMENT: 1,
|
|
1304
|
+
SEQUENCE: 2,
|
|
1305
|
+
MAPPING: 3,
|
|
1306
|
+
SCALAR: 4,
|
|
1307
|
+
ALIAS: 5,
|
|
1308
|
+
POP: 6
|
|
1309
|
+
};
|
|
1310
|
+
/** @category Nodes */
|
|
1311
|
+
var SCALAR_STYLE = {
|
|
1312
|
+
PLAIN: 1,
|
|
1313
|
+
SINGLE_QUOTED: 2,
|
|
1314
|
+
DOUBLE_QUOTED: 3,
|
|
1315
|
+
LITERAL_BLOCK: 4,
|
|
1316
|
+
FOLDED_BLOCK: 5
|
|
1317
|
+
};
|
|
1318
|
+
/** @category Nodes */
|
|
1319
|
+
var COLLECTION_STYLE = {
|
|
1320
|
+
BLOCK: 1,
|
|
1321
|
+
FLOW: 2
|
|
1322
|
+
};
|
|
1323
|
+
/** @category Nodes */
|
|
1324
|
+
var CHOMPING_MODE = {
|
|
1325
|
+
CLIP: 1,
|
|
1326
|
+
STRIP: 2,
|
|
1327
|
+
KEEP: 3
|
|
1328
|
+
};
|
|
994
1329
|
//#endregion
|
|
995
1330
|
//#region src/parser/parser_scalar.ts
|
|
996
1331
|
var NO_RANGE$3 = -1;
|
|
@@ -1171,21 +1506,26 @@ function getBlockValue(input, start, end, indent, chomping, folded) {
|
|
|
1171
1506
|
didReadContent = true;
|
|
1172
1507
|
emptyLines = 0;
|
|
1173
1508
|
}
|
|
1174
|
-
if (chomping ===
|
|
1175
|
-
else if (chomping !==
|
|
1509
|
+
if (chomping === CHOMPING_MODE.KEEP) result += "\n".repeat(didReadContent ? 1 + emptyLines : emptyLines);
|
|
1510
|
+
else if (chomping !== CHOMPING_MODE.STRIP) {
|
|
1176
1511
|
if (didReadContent) result += "\n";
|
|
1177
1512
|
}
|
|
1178
1513
|
return result;
|
|
1179
1514
|
}
|
|
1515
|
+
/**
|
|
1516
|
+
* Decodes the scalar referenced by event offsets in `input`.
|
|
1517
|
+
*
|
|
1518
|
+
* @category Events
|
|
1519
|
+
*/
|
|
1180
1520
|
function getScalarValue(input, scalar) {
|
|
1181
1521
|
if (scalar.valueStart === NO_RANGE$3) return "";
|
|
1182
1522
|
const { valueStart, valueEnd } = scalar;
|
|
1183
1523
|
if (scalar.fast) return input.slice(valueStart, valueEnd);
|
|
1184
1524
|
switch (scalar.style) {
|
|
1185
|
-
case
|
|
1186
|
-
case
|
|
1187
|
-
case
|
|
1188
|
-
case
|
|
1525
|
+
case SCALAR_STYLE.SINGLE_QUOTED: return getSingleQuotedValue(input, valueStart, valueEnd);
|
|
1526
|
+
case SCALAR_STYLE.DOUBLE_QUOTED: return getDoubleQuotedValue(input, valueStart, valueEnd);
|
|
1527
|
+
case SCALAR_STYLE.LITERAL_BLOCK: return getBlockValue(input, valueStart, valueEnd, scalar.indent, scalar.chomping, false);
|
|
1528
|
+
case SCALAR_STYLE.FOLDED_BLOCK: return getBlockValue(input, valueStart, valueEnd, scalar.indent, scalar.chomping, true);
|
|
1189
1529
|
default: return getPlainValue(input, valueStart, valueEnd);
|
|
1190
1530
|
}
|
|
1191
1531
|
}
|
|
@@ -1218,6 +1558,7 @@ function tagNameShort(fullTag) {
|
|
|
1218
1558
|
//#endregion
|
|
1219
1559
|
//#region src/parser/constructor.ts
|
|
1220
1560
|
var NO_RANGE$2 = -1;
|
|
1561
|
+
var MERGE_TAG_NAME = "tag:yaml.org,2002:merge";
|
|
1221
1562
|
var DEFAULT_CONSTRUCTOR_OPTIONS = {
|
|
1222
1563
|
filename: "",
|
|
1223
1564
|
schema: CORE_SCHEMA,
|
|
@@ -1233,38 +1574,28 @@ function eventPosition$1(event) {
|
|
|
1233
1574
|
return 0;
|
|
1234
1575
|
}
|
|
1235
1576
|
function throwError$1(state, message) {
|
|
1236
|
-
|
|
1577
|
+
YAMLException.throwAt(state.source, state.position, message, state.filename);
|
|
1237
1578
|
}
|
|
1238
1579
|
function finalizeCollection(state, position, tag, carrier) {
|
|
1239
1580
|
try {
|
|
1240
1581
|
return tag.finalize(carrier);
|
|
1241
1582
|
} catch (error) {
|
|
1242
1583
|
if (error instanceof YAMLException) throw error;
|
|
1243
|
-
|
|
1584
|
+
YAMLException.throwAt(state.source, position, error instanceof Error ? error.message : String(error), state.filename);
|
|
1244
1585
|
}
|
|
1245
1586
|
}
|
|
1246
|
-
function lookupTag(exact, prefix, tagName) {
|
|
1247
|
-
const exactTag = exact[tagName];
|
|
1248
|
-
if (exactTag) return exactTag;
|
|
1249
|
-
for (const tag of prefix) if (tagName.startsWith(tag.tagName)) return tag;
|
|
1250
|
-
}
|
|
1251
|
-
function findExplicitTag(state, exact, prefix, tagName, nodeKind) {
|
|
1252
|
-
const tag = lookupTag(exact, prefix, tagName);
|
|
1253
|
-
if (tag) return tag;
|
|
1254
|
-
throwError$1(state, `unknown ${nodeKind} tag !<${tagName}>`);
|
|
1255
|
-
}
|
|
1256
1587
|
function constructScalar(state, event) {
|
|
1257
1588
|
const source = getScalarValue(state.source, event);
|
|
1258
1589
|
const rawTag = event.tagStart === NO_RANGE$2 ? "" : state.source.slice(event.tagStart, event.tagEnd);
|
|
1259
1590
|
const strTag = state.schema.defaultScalarTag;
|
|
1260
1591
|
if (rawTag !== "") {
|
|
1261
|
-
var
|
|
1592
|
+
var _state$schema$lookupM;
|
|
1262
1593
|
if (rawTag === "!") return {
|
|
1263
1594
|
value: source,
|
|
1264
1595
|
tag: strTag
|
|
1265
1596
|
};
|
|
1266
1597
|
const tagName = tagNameFull(rawTag, state.tagHandlers);
|
|
1267
|
-
const scalarTag =
|
|
1598
|
+
const scalarTag = state.schema.lookupScalarTag(tagName);
|
|
1268
1599
|
if (scalarTag) {
|
|
1269
1600
|
const result = scalarTag.resolve(source, true, tagName);
|
|
1270
1601
|
if (result === NOT_RESOLVED) throwError$1(state, `cannot resolve a node with !<${tagName}> explicit tag`);
|
|
@@ -1273,7 +1604,7 @@ function constructScalar(state, event) {
|
|
|
1273
1604
|
tag: scalarTag
|
|
1274
1605
|
};
|
|
1275
1606
|
}
|
|
1276
|
-
const collectionTagDef = (
|
|
1607
|
+
const collectionTagDef = (_state$schema$lookupM = state.schema.lookupMappingTag(tagName)) !== null && _state$schema$lookupM !== void 0 ? _state$schema$lookupM : state.schema.lookupSequenceTag(tagName);
|
|
1277
1608
|
if (collectionTagDef) {
|
|
1278
1609
|
if (source !== "") throwError$1(state, `cannot resolve a node with !<${tagName}> explicit tag`);
|
|
1279
1610
|
const carrier = collectionTagDef.create(tagName);
|
|
@@ -1284,53 +1615,51 @@ function constructScalar(state, event) {
|
|
|
1284
1615
|
}
|
|
1285
1616
|
throwError$1(state, `unknown scalar tag !<${tagName}>`);
|
|
1286
1617
|
}
|
|
1287
|
-
if (event.style ===
|
|
1288
|
-
var _state$schema$implici;
|
|
1289
|
-
const candidates = (_state$schema$implici = state.schema.implicitScalarByFirstChar.get(source.charAt(0))) !== null && _state$schema$implici !== void 0 ? _state$schema$implici : state.schema.implicitScalarAnyFirstChar;
|
|
1290
|
-
for (const tag of candidates) {
|
|
1291
|
-
const result = tag.resolve(source, false, tag.tagName);
|
|
1292
|
-
if (result !== NOT_RESOLVED) return {
|
|
1293
|
-
value: result,
|
|
1294
|
-
tag
|
|
1295
|
-
};
|
|
1296
|
-
}
|
|
1297
|
-
}
|
|
1618
|
+
if (event.style === SCALAR_STYLE.PLAIN) return state.schema.resolveImplicitScalarTag(source);
|
|
1298
1619
|
return {
|
|
1299
1620
|
value: strTag.resolve(source, false, strTag.tagName),
|
|
1300
1621
|
tag: strTag
|
|
1301
1622
|
};
|
|
1302
1623
|
}
|
|
1303
|
-
function
|
|
1624
|
+
function collectionTagName(state, event, defaultTagName) {
|
|
1304
1625
|
const rawTag = event.tagStart === NO_RANGE$2 ? "" : state.source.slice(event.tagStart, event.tagEnd);
|
|
1305
|
-
|
|
1306
|
-
return {
|
|
1307
|
-
tagName,
|
|
1308
|
-
tag: findExplicitTag(state, exact, prefix, tagName, nodeKind)
|
|
1309
|
-
};
|
|
1626
|
+
return rawTag === "" || rawTag === "!" ? defaultTagName : tagNameFull(rawTag, state.tagHandlers);
|
|
1310
1627
|
}
|
|
1311
1628
|
function isMappingTag(tag) {
|
|
1312
1629
|
return tag.nodeKind === "mapping";
|
|
1313
1630
|
}
|
|
1631
|
+
function chargeMergeWork(state) {
|
|
1632
|
+
state.totalMergeKeys++;
|
|
1633
|
+
if (state.maxTotalMergeKeys !== -1 && state.totalMergeKeys > state.maxTotalMergeKeys) throwError$1(state, `merge keys exceeded maxTotalMergeKeys (${state.maxTotalMergeKeys})`);
|
|
1634
|
+
}
|
|
1314
1635
|
function mergeKeys(state, frame, source, sourceTag) {
|
|
1636
|
+
chargeMergeWork(state);
|
|
1315
1637
|
for (const sourceKey of sourceTag.keys(source)) {
|
|
1316
1638
|
var _frame$overridable;
|
|
1317
|
-
|
|
1639
|
+
chargeMergeWork(state);
|
|
1318
1640
|
if (frame.tag.has(frame.value, sourceKey)) continue;
|
|
1319
1641
|
const err = frame.tag.addPair(frame.value, sourceKey, sourceTag.get(source, sourceKey));
|
|
1320
1642
|
if (err) throwError$1(state, err);
|
|
1321
|
-
(
|
|
1643
|
+
(_frame$overridable = frame.overridable) !== null && _frame$overridable !== void 0 || (frame.overridable = /* @__PURE__ */ new Set());
|
|
1644
|
+
frame.overridable.add(sourceKey);
|
|
1322
1645
|
}
|
|
1323
1646
|
}
|
|
1324
1647
|
function mergeSource(state, frame, source, sourceTag) {
|
|
1325
1648
|
state.position = frame.keyPosition;
|
|
1326
1649
|
if (isMappingTag(sourceTag)) mergeKeys(state, frame, source, sourceTag);
|
|
1327
|
-
else if (sourceTag.nodeKind === "sequence" && Array.isArray(source))
|
|
1328
|
-
|
|
1650
|
+
else if (sourceTag.nodeKind === "sequence" && Array.isArray(source)) {
|
|
1651
|
+
if (source.length > 100) throwError$1(state, "abnormal merge sequence size");
|
|
1652
|
+
for (const element of source) {
|
|
1653
|
+
const elementTag = state.nodeTags.get(element);
|
|
1654
|
+
if (!elementTag) throwError$1(state, "cannot merge mappings; the provided source object is unacceptable");
|
|
1655
|
+
mergeKeys(state, frame, element, elementTag);
|
|
1656
|
+
}
|
|
1657
|
+
} else throwError$1(state, "cannot merge mappings; the provided source object is unacceptable");
|
|
1329
1658
|
}
|
|
1330
1659
|
function addMappingValue(state, frame, key, value, tag) {
|
|
1331
1660
|
var _frame$overridable2, _frame$overridable3;
|
|
1332
1661
|
state.position = frame.keyPosition;
|
|
1333
|
-
if (
|
|
1662
|
+
if (frame.keyIsMerge) {
|
|
1334
1663
|
mergeSource(state, frame, value, tag);
|
|
1335
1664
|
return;
|
|
1336
1665
|
}
|
|
@@ -1345,9 +1674,7 @@ function addValue(state, value, tag) {
|
|
|
1345
1674
|
frame.value = value;
|
|
1346
1675
|
frame.hasValue = true;
|
|
1347
1676
|
} else if (frame.kind === "sequence") {
|
|
1348
|
-
if (
|
|
1349
|
-
if (!isMappingTag(tag)) throwError$1(state, "cannot merge mappings; the provided source object is unacceptable");
|
|
1350
|
-
}
|
|
1677
|
+
if (isMappingTag(tag)) state.nodeTags.set(value, tag);
|
|
1351
1678
|
const err = frame.tag.addItem(frame.value, value, frame.index++);
|
|
1352
1679
|
if (err) throwError$1(state, err);
|
|
1353
1680
|
} else if (frame.hasKey) {
|
|
@@ -1359,6 +1686,7 @@ function addValue(state, value, tag) {
|
|
|
1359
1686
|
frame.key = value;
|
|
1360
1687
|
frame.keyPosition = state.position;
|
|
1361
1688
|
frame.hasKey = true;
|
|
1689
|
+
frame.keyIsMerge = tag.tagName === MERGE_TAG_NAME;
|
|
1362
1690
|
}
|
|
1363
1691
|
}
|
|
1364
1692
|
function storeAnchor(state, event, value, tag, isValueFinal) {
|
|
@@ -1373,6 +1701,12 @@ function storeAnchor(state, event, value, tag, isValueFinal) {
|
|
|
1373
1701
|
}
|
|
1374
1702
|
return null;
|
|
1375
1703
|
}
|
|
1704
|
+
/**
|
|
1705
|
+
* Constructs JavaScript documents directly from parser events, without an
|
|
1706
|
+
* intermediate AST.
|
|
1707
|
+
*
|
|
1708
|
+
* @category Events
|
|
1709
|
+
*/
|
|
1376
1710
|
function constructFromEvents(events, options) {
|
|
1377
1711
|
const state = _objectSpread2(_objectSpread2(_objectSpread2({}, DEFAULT_CONSTRUCTOR_OPTIONS), options), {}, {
|
|
1378
1712
|
events,
|
|
@@ -1381,6 +1715,7 @@ function constructFromEvents(events, options) {
|
|
|
1381
1715
|
position: 0,
|
|
1382
1716
|
frames: [],
|
|
1383
1717
|
anchors: /* @__PURE__ */ new Map(),
|
|
1718
|
+
nodeTags: /* @__PURE__ */ new Map(),
|
|
1384
1719
|
tagHandlers: Object.create(null),
|
|
1385
1720
|
totalMergeKeys: 0,
|
|
1386
1721
|
aliasCount: 0
|
|
@@ -1389,8 +1724,9 @@ function constructFromEvents(events, options) {
|
|
|
1389
1724
|
const event = state.events[state.eventIndex++];
|
|
1390
1725
|
state.position = eventPosition$1(event);
|
|
1391
1726
|
switch (event.type) {
|
|
1392
|
-
case
|
|
1727
|
+
case EVENT_ID.DOCUMENT:
|
|
1393
1728
|
state.anchors = /* @__PURE__ */ new Map();
|
|
1729
|
+
state.nodeTags = /* @__PURE__ */ new Map();
|
|
1394
1730
|
state.aliasCount = 0;
|
|
1395
1731
|
state.tagHandlers = Object.create(null);
|
|
1396
1732
|
for (const directive of event.directives) if (directive.kind === "tag") state.tagHandlers[directive.handle] = directive.prefix;
|
|
@@ -1401,47 +1737,49 @@ function constructFromEvents(events, options) {
|
|
|
1401
1737
|
hasValue: false
|
|
1402
1738
|
});
|
|
1403
1739
|
break;
|
|
1404
|
-
case
|
|
1740
|
+
case EVENT_ID.SCALAR: {
|
|
1405
1741
|
const { value, tag } = constructScalar(state, event);
|
|
1406
1742
|
storeAnchor(state, event, value, tag, true);
|
|
1407
1743
|
addValue(state, value, tag);
|
|
1408
1744
|
break;
|
|
1409
1745
|
}
|
|
1410
|
-
case
|
|
1411
|
-
const
|
|
1412
|
-
const
|
|
1413
|
-
|
|
1414
|
-
const
|
|
1415
|
-
const
|
|
1746
|
+
case EVENT_ID.SEQUENCE: {
|
|
1747
|
+
const tagName = collectionTagName(state, event, "tag:yaml.org,2002:seq");
|
|
1748
|
+
const tag = state.schema.lookupSequenceTag(tagName);
|
|
1749
|
+
if (!tag) throwError$1(state, `unknown sequence tag !<${tagName}>`);
|
|
1750
|
+
const value = tag.create(tagName);
|
|
1751
|
+
const anchor = storeAnchor(state, event, value, tag, tag.carrierIsResult);
|
|
1416
1752
|
state.frames.push({
|
|
1417
1753
|
kind: "sequence",
|
|
1418
1754
|
position: state.position,
|
|
1419
1755
|
value,
|
|
1420
|
-
tag
|
|
1756
|
+
tag,
|
|
1421
1757
|
anchor,
|
|
1422
|
-
index: 0
|
|
1423
|
-
merge
|
|
1758
|
+
index: 0
|
|
1424
1759
|
});
|
|
1425
1760
|
break;
|
|
1426
1761
|
}
|
|
1427
|
-
case
|
|
1428
|
-
const
|
|
1429
|
-
const
|
|
1430
|
-
|
|
1762
|
+
case EVENT_ID.MAPPING: {
|
|
1763
|
+
const tagName = collectionTagName(state, event, "tag:yaml.org,2002:map");
|
|
1764
|
+
const tag = state.schema.lookupMappingTag(tagName);
|
|
1765
|
+
if (!tag) throwError$1(state, `unknown mapping tag !<${tagName}>`);
|
|
1766
|
+
const value = tag.create(tagName);
|
|
1767
|
+
const anchor = storeAnchor(state, event, value, tag, tag.carrierIsResult);
|
|
1431
1768
|
state.frames.push({
|
|
1432
1769
|
kind: "mapping",
|
|
1433
1770
|
position: state.position,
|
|
1434
1771
|
value,
|
|
1435
|
-
tag
|
|
1772
|
+
tag,
|
|
1436
1773
|
anchor,
|
|
1437
1774
|
key: void 0,
|
|
1438
1775
|
keyPosition: state.position,
|
|
1439
1776
|
hasKey: false,
|
|
1777
|
+
keyIsMerge: false,
|
|
1440
1778
|
overridable: null
|
|
1441
1779
|
});
|
|
1442
1780
|
break;
|
|
1443
1781
|
}
|
|
1444
|
-
case
|
|
1782
|
+
case EVENT_ID.ALIAS: {
|
|
1445
1783
|
if (state.maxAliases !== -1 && ++state.aliasCount > state.maxAliases) throwError$1(state, `aliases exceeded maxAliases (${state.maxAliases})`);
|
|
1446
1784
|
const name = state.source.slice(event.anchorStart, event.anchorEnd);
|
|
1447
1785
|
const anchor = state.anchors.get(name);
|
|
@@ -1450,7 +1788,7 @@ function constructFromEvents(events, options) {
|
|
|
1450
1788
|
addValue(state, anchor.value, anchor.tag);
|
|
1451
1789
|
break;
|
|
1452
1790
|
}
|
|
1453
|
-
case
|
|
1791
|
+
case EVENT_ID.POP: {
|
|
1454
1792
|
const frame = state.frames.pop();
|
|
1455
1793
|
if (frame.kind === "mapping" && frame.hasKey) {
|
|
1456
1794
|
state.position = frame.keyPosition;
|
|
@@ -1493,7 +1831,7 @@ var DEFAULT_PARSER_OPTIONS = {
|
|
|
1493
1831
|
};
|
|
1494
1832
|
function addDocumentEvent(state, explicitStart, explicitEnd) {
|
|
1495
1833
|
state.events.push({
|
|
1496
|
-
type:
|
|
1834
|
+
type: EVENT_ID.DOCUMENT,
|
|
1497
1835
|
explicitStart,
|
|
1498
1836
|
explicitEnd,
|
|
1499
1837
|
directives: state.directives
|
|
@@ -1501,7 +1839,7 @@ function addDocumentEvent(state, explicitStart, explicitEnd) {
|
|
|
1501
1839
|
}
|
|
1502
1840
|
function addSequenceEvent(state, start, anchorStart, anchorEnd, tagStart, tagEnd, style) {
|
|
1503
1841
|
state.events.push({
|
|
1504
|
-
type:
|
|
1842
|
+
type: EVENT_ID.SEQUENCE,
|
|
1505
1843
|
start,
|
|
1506
1844
|
anchorStart,
|
|
1507
1845
|
anchorEnd,
|
|
@@ -1512,7 +1850,7 @@ function addSequenceEvent(state, start, anchorStart, anchorEnd, tagStart, tagEnd
|
|
|
1512
1850
|
}
|
|
1513
1851
|
function addMappingEvent(state, start, anchorStart, anchorEnd, tagStart, tagEnd, style) {
|
|
1514
1852
|
state.events.push({
|
|
1515
|
-
type:
|
|
1853
|
+
type: EVENT_ID.MAPPING,
|
|
1516
1854
|
start,
|
|
1517
1855
|
anchorStart,
|
|
1518
1856
|
anchorEnd,
|
|
@@ -1523,18 +1861,18 @@ function addMappingEvent(state, start, anchorStart, anchorEnd, tagStart, tagEnd,
|
|
|
1523
1861
|
}
|
|
1524
1862
|
function insertFlowPairMappingEvent(state, snapshot) {
|
|
1525
1863
|
state.events.splice(snapshot.eventsLength, 0, {
|
|
1526
|
-
type:
|
|
1864
|
+
type: EVENT_ID.MAPPING,
|
|
1527
1865
|
start: snapshot.position,
|
|
1528
1866
|
anchorStart: NO_RANGE$1,
|
|
1529
1867
|
anchorEnd: NO_RANGE$1,
|
|
1530
1868
|
tagStart: NO_RANGE$1,
|
|
1531
1869
|
tagEnd: NO_RANGE$1,
|
|
1532
|
-
style:
|
|
1870
|
+
style: COLLECTION_STYLE.FLOW
|
|
1533
1871
|
});
|
|
1534
1872
|
}
|
|
1535
|
-
function addScalarEvent(state, valueStart, valueEnd, anchorStart, anchorEnd, tagStart, tagEnd, style, chomping =
|
|
1873
|
+
function addScalarEvent(state, valueStart, valueEnd, anchorStart, anchorEnd, tagStart, tagEnd, style, chomping = CHOMPING_MODE.CLIP, indent = -1, fast = false) {
|
|
1536
1874
|
state.events.push({
|
|
1537
|
-
type:
|
|
1875
|
+
type: EVENT_ID.SCALAR,
|
|
1538
1876
|
valueStart,
|
|
1539
1877
|
valueEnd,
|
|
1540
1878
|
anchorStart,
|
|
@@ -1549,16 +1887,16 @@ function addScalarEvent(state, valueStart, valueEnd, anchorStart, anchorEnd, tag
|
|
|
1549
1887
|
}
|
|
1550
1888
|
function addAliasEvent(state, anchorStart, anchorEnd) {
|
|
1551
1889
|
state.events.push({
|
|
1552
|
-
type:
|
|
1890
|
+
type: EVENT_ID.ALIAS,
|
|
1553
1891
|
anchorStart,
|
|
1554
1892
|
anchorEnd
|
|
1555
1893
|
});
|
|
1556
1894
|
}
|
|
1557
1895
|
function addPopEvent(state) {
|
|
1558
|
-
state.events.push({ type:
|
|
1896
|
+
state.events.push({ type: EVENT_ID.POP });
|
|
1559
1897
|
}
|
|
1560
1898
|
function addEmptyScalarEvent(state) {
|
|
1561
|
-
addScalarEvent(state, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1,
|
|
1899
|
+
addScalarEvent(state, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, NO_RANGE$1, SCALAR_STYLE.PLAIN);
|
|
1562
1900
|
}
|
|
1563
1901
|
function emptyProperties() {
|
|
1564
1902
|
return {
|
|
@@ -1587,7 +1925,7 @@ function restoreState(state, snapshot) {
|
|
|
1587
1925
|
state.events.length = snapshot.eventsLength;
|
|
1588
1926
|
}
|
|
1589
1927
|
function throwError(state, message) {
|
|
1590
|
-
|
|
1928
|
+
YAMLException.throwAt(state.input.slice(0, state.length), state.position, message, state.filename);
|
|
1591
1929
|
}
|
|
1592
1930
|
function isEol(c) {
|
|
1593
1931
|
return c === 10 || c === 13;
|
|
@@ -1666,6 +2004,24 @@ function testDocumentSeparator(state, position = state.position) {
|
|
|
1666
2004
|
}
|
|
1667
2005
|
return false;
|
|
1668
2006
|
}
|
|
2007
|
+
function skipByteOrderMark(state) {
|
|
2008
|
+
if (state.position === state.lineStart && state.input.charCodeAt(state.position) === 65279) {
|
|
2009
|
+
state.position++;
|
|
2010
|
+
state.lineStart = state.position;
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
function testDocumentBoundary(state) {
|
|
2014
|
+
if (state.position !== state.lineStart) return false;
|
|
2015
|
+
if (testDocumentSeparator(state)) return true;
|
|
2016
|
+
if (state.input.charCodeAt(state.position) !== 65279) return false;
|
|
2017
|
+
const snapshot = snapshotState(state);
|
|
2018
|
+
skipByteOrderMark(state);
|
|
2019
|
+
skipSeparationSpace(state, true);
|
|
2020
|
+
const ch = state.input.charCodeAt(state.position);
|
|
2021
|
+
const result = state.position === state.lineStart && (ch === 37 || ch === 45 && testDocumentSeparator(state));
|
|
2022
|
+
restoreState(state, snapshot);
|
|
2023
|
+
return result;
|
|
2024
|
+
}
|
|
1669
2025
|
function skipUntilLineEnd(state) {
|
|
1670
2026
|
let ch = state.input.charCodeAt(state.position);
|
|
1671
2027
|
while (ch !== 0 && !isEol(ch)) ch = state.input.charCodeAt(++state.position);
|
|
@@ -1755,7 +2111,7 @@ function readSingleQuotedScalar(state, nodeIndent, props) {
|
|
|
1755
2111
|
}
|
|
1756
2112
|
const end = state.position;
|
|
1757
2113
|
state.position++;
|
|
1758
|
-
addScalarEvent(state, start, end, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd,
|
|
2114
|
+
addScalarEvent(state, start, end, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, SCALAR_STYLE.SINGLE_QUOTED, CHOMPING_MODE.CLIP, -1, simple);
|
|
1759
2115
|
return true;
|
|
1760
2116
|
}
|
|
1761
2117
|
if (isEol(ch)) {
|
|
@@ -1777,7 +2133,7 @@ function readDoubleQuotedScalar(state, nodeIndent, props) {
|
|
|
1777
2133
|
if (ch === 34) {
|
|
1778
2134
|
const end = state.position;
|
|
1779
2135
|
state.position++;
|
|
1780
|
-
addScalarEvent(state, start, end, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd,
|
|
2136
|
+
addScalarEvent(state, start, end, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, SCALAR_STYLE.DOUBLE_QUOTED, CHOMPING_MODE.CLIP, -1, simple);
|
|
1781
2137
|
return true;
|
|
1782
2138
|
}
|
|
1783
2139
|
if (ch === 92) {
|
|
@@ -1805,18 +2161,18 @@ function readDoubleQuotedScalar(state, nodeIndent, props) {
|
|
|
1805
2161
|
}
|
|
1806
2162
|
function readBlockScalar(state, parentIndent, props) {
|
|
1807
2163
|
const ch = state.input.charCodeAt(state.position);
|
|
1808
|
-
let chomping =
|
|
2164
|
+
let chomping = CHOMPING_MODE.CLIP;
|
|
1809
2165
|
let indent = -1;
|
|
1810
2166
|
let detectedIndent = false;
|
|
1811
2167
|
if (ch !== 124 && ch !== 62) return false;
|
|
1812
|
-
const style = ch === 124 ?
|
|
2168
|
+
const style = ch === 124 ? SCALAR_STYLE.LITERAL_BLOCK : SCALAR_STYLE.FOLDED_BLOCK;
|
|
1813
2169
|
state.position++;
|
|
1814
2170
|
while (state.input.charCodeAt(state.position) !== 0) {
|
|
1815
2171
|
const current = state.input.charCodeAt(state.position);
|
|
1816
2172
|
const digit = fromDecimalCode(current);
|
|
1817
2173
|
if (current === 43 || current === 45) {
|
|
1818
|
-
if (chomping !==
|
|
1819
|
-
chomping = current === 43 ?
|
|
2174
|
+
if (chomping !== CHOMPING_MODE.CLIP) throwError(state, "repeat of a chomping mode identifier");
|
|
2175
|
+
chomping = current === 43 ? CHOMPING_MODE.KEEP : CHOMPING_MODE.STRIP;
|
|
1820
2176
|
state.position++;
|
|
1821
2177
|
} else if (digit >= 0) {
|
|
1822
2178
|
if (digit === 0) throwError(state, "bad explicit indentation width of a block scalar; it cannot be less than one");
|
|
@@ -1849,7 +2205,7 @@ function readBlockScalar(state, parentIndent, props) {
|
|
|
1849
2205
|
} else if (column > 0) valueEnd = linePosition + column;
|
|
1850
2206
|
break;
|
|
1851
2207
|
}
|
|
1852
|
-
if (
|
|
2208
|
+
if (testDocumentBoundary(state)) break;
|
|
1853
2209
|
if (!detectedIndent && contentIndent === -1 && isEol(first)) maxLeadingIndent = Math.max(maxLeadingIndent, column);
|
|
1854
2210
|
if (!detectedIndent && contentIndent === -1 && !isEol(first)) {
|
|
1855
2211
|
if (first === 9 && column < parentIndent) {
|
|
@@ -1902,7 +2258,7 @@ function readPlainScalar(state, nodeIndent, nodeContext, props) {
|
|
|
1902
2258
|
const inFlow = nodeContext === CONTEXT_FLOW_IN;
|
|
1903
2259
|
let multiline = false;
|
|
1904
2260
|
while (ch !== 0) {
|
|
1905
|
-
if (
|
|
2261
|
+
if (testDocumentBoundary(state)) break;
|
|
1906
2262
|
if (ch === 58) {
|
|
1907
2263
|
const following = state.input.charCodeAt(state.position + 1);
|
|
1908
2264
|
if (isWsOrEolOrEnd(following) || inFlow && isFlowIndicator(following)) break;
|
|
@@ -1931,7 +2287,7 @@ function readPlainScalar(state, nodeIndent, nodeContext, props) {
|
|
|
1931
2287
|
}
|
|
1932
2288
|
if (end === start) return false;
|
|
1933
2289
|
checkPrintable(state, start, end);
|
|
1934
|
-
addScalarEvent(state, start, end, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd,
|
|
2290
|
+
addScalarEvent(state, start, end, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, SCALAR_STYLE.PLAIN, CHOMPING_MODE.CLIP, -1, !multiline);
|
|
1935
2291
|
return true;
|
|
1936
2292
|
}
|
|
1937
2293
|
function skipFlowSeparationSpace(state, nodeIndent) {
|
|
@@ -1946,8 +2302,8 @@ function readFlowCollection(state, nodeIndent, props) {
|
|
|
1946
2302
|
let readNext = true;
|
|
1947
2303
|
if (ch !== 91 && ch !== 123) return false;
|
|
1948
2304
|
const terminator = isMapping ? 125 : 93;
|
|
1949
|
-
if (isMapping) addMappingEvent(state, start, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd,
|
|
1950
|
-
else addSequenceEvent(state, start, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd,
|
|
2305
|
+
if (isMapping) addMappingEvent(state, start, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, COLLECTION_STYLE.FLOW);
|
|
2306
|
+
else addSequenceEvent(state, start, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, COLLECTION_STYLE.FLOW);
|
|
1951
2307
|
state.position++;
|
|
1952
2308
|
while (state.input.charCodeAt(state.position) !== 0) {
|
|
1953
2309
|
skipFlowSeparationSpace(state, nodeIndent);
|
|
@@ -2001,7 +2357,7 @@ function readFlowCollection(state, nodeIndent, props) {
|
|
|
2001
2357
|
}
|
|
2002
2358
|
function readBlockSequence(state, nodeIndent, props) {
|
|
2003
2359
|
if (state.firstTabInLine !== -1 || state.input.charCodeAt(state.position) !== 45 || !isWsOrEolOrEnd(state.input.charCodeAt(state.position + 1))) return false;
|
|
2004
|
-
addSequenceEvent(state, state.position, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd,
|
|
2360
|
+
addSequenceEvent(state, state.position, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, COLLECTION_STYLE.BLOCK);
|
|
2005
2361
|
while (state.input.charCodeAt(state.position) === 45 && isWsOrEolOrEnd(state.input.charCodeAt(state.position + 1))) {
|
|
2006
2362
|
if (state.firstTabInLine !== -1) {
|
|
2007
2363
|
state.position = state.firstTabInLine;
|
|
@@ -2037,7 +2393,7 @@ function readBlockMapping(state, nodeIndent, flowIndent, props) {
|
|
|
2037
2393
|
const entryLine = state.line;
|
|
2038
2394
|
if ((ch === 63 || ch === 58) && isWsOrEolOrEnd(following)) {
|
|
2039
2395
|
if (!mappingOpened) {
|
|
2040
|
-
addMappingEvent(state, state.position, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd,
|
|
2396
|
+
addMappingEvent(state, state.position, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, COLLECTION_STYLE.BLOCK);
|
|
2041
2397
|
mappingOpened = true;
|
|
2042
2398
|
}
|
|
2043
2399
|
if (ch === 63) {
|
|
@@ -2067,7 +2423,7 @@ function readBlockMapping(state, nodeIndent, flowIndent, props) {
|
|
|
2067
2423
|
if (!isWsOrEolOrEnd(ch)) throwError(state, "a whitespace character is expected after the key-value separator within a block mapping");
|
|
2068
2424
|
if (!mappingOpened) {
|
|
2069
2425
|
restoreState(state, beforeKey);
|
|
2070
|
-
addMappingEvent(state, beforeKey.position, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd,
|
|
2426
|
+
addMappingEvent(state, beforeKey.position, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, COLLECTION_STYLE.BLOCK);
|
|
2071
2427
|
mappingOpened = true;
|
|
2072
2428
|
parseNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true);
|
|
2073
2429
|
ch = state.input.charCodeAt(state.position);
|
|
@@ -2136,7 +2492,7 @@ function parseNode(state, parentIndent, nodeContext, allowToSeek, allowCompact,
|
|
|
2136
2492
|
var _state$events$fallbac;
|
|
2137
2493
|
const fallbackState = snapshotState(state);
|
|
2138
2494
|
const flowIndent = parentIndent + 1;
|
|
2139
|
-
if (readBlockMapping(state, state.position - state.lineStart, flowIndent, props) && ((_state$events$fallbac = state.events[fallbackState.eventsLength]) === null || _state$events$fallbac === void 0 ? void 0 : _state$events$fallbac.type) ===
|
|
2495
|
+
if (readBlockMapping(state, state.position - state.lineStart, flowIndent, props) && ((_state$events$fallbac = state.events[fallbackState.eventsLength]) === null || _state$events$fallbac === void 0 ? void 0 : _state$events$fallbac.type) === EVENT_ID.MAPPING) {
|
|
2140
2496
|
state.depth--;
|
|
2141
2497
|
return true;
|
|
2142
2498
|
}
|
|
@@ -2165,7 +2521,7 @@ function parseNode(state, parentIndent, nodeContext, allowToSeek, allowCompact,
|
|
|
2165
2521
|
const fallbackState = snapshotState(state);
|
|
2166
2522
|
const propertyIndent = propertyStart.position - propertyStart.lineStart;
|
|
2167
2523
|
restoreState(state, propertyStart);
|
|
2168
|
-
if (readBlockMapping(state, propertyIndent, flowIndent, emptyProperties()) && ((_state$events$fallbac2 = state.events[fallbackState.eventsLength]) === null || _state$events$fallbac2 === void 0 ? void 0 : _state$events$fallbac2.type) ===
|
|
2524
|
+
if (readBlockMapping(state, propertyIndent, flowIndent, emptyProperties()) && ((_state$events$fallbac2 = state.events[fallbackState.eventsLength]) === null || _state$events$fallbac2 === void 0 ? void 0 : _state$events$fallbac2.type) === EVENT_ID.MAPPING) hasContent = true;
|
|
2169
2525
|
else restoreState(state, fallbackState);
|
|
2170
2526
|
}
|
|
2171
2527
|
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;
|
|
@@ -2174,7 +2530,7 @@ function parseNode(state, parentIndent, nodeContext, allowToSeek, allowCompact,
|
|
|
2174
2530
|
}
|
|
2175
2531
|
allowBlockScalars = allowBlockScalars && !hasContent;
|
|
2176
2532
|
if (!hasContent && (props.anchorStart !== NO_RANGE$1 || props.tagStart !== NO_RANGE$1 || allowBlockScalars)) {
|
|
2177
|
-
addScalarEvent(state, NO_RANGE$1, NO_RANGE$1, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd,
|
|
2533
|
+
addScalarEvent(state, NO_RANGE$1, NO_RANGE$1, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, SCALAR_STYLE.PLAIN);
|
|
2178
2534
|
hasContent = true;
|
|
2179
2535
|
}
|
|
2180
2536
|
state.depth--;
|
|
@@ -2259,10 +2615,15 @@ function readDocument(state) {
|
|
|
2259
2615
|
}
|
|
2260
2616
|
}
|
|
2261
2617
|
const documentEvent = state.events[documentEventIndex];
|
|
2262
|
-
if ((documentEvent === null || documentEvent === void 0 ? void 0 : documentEvent.type) ===
|
|
2618
|
+
if ((documentEvent === null || documentEvent === void 0 ? void 0 : documentEvent.type) === EVENT_ID.DOCUMENT) documentEvent.explicitEnd = explicitEnd;
|
|
2263
2619
|
addPopEvent(state);
|
|
2264
|
-
if (!explicitEnd && state.position < state.length && !(state
|
|
2620
|
+
if (!explicitEnd && state.position < state.length && !testDocumentBoundary(state)) throwError(state, "end of the stream or a document separator is expected");
|
|
2265
2621
|
}
|
|
2622
|
+
/**
|
|
2623
|
+
* Parses YAML into a flat event stream referencing source text by offsets.
|
|
2624
|
+
*
|
|
2625
|
+
* @category Events
|
|
2626
|
+
*/
|
|
2266
2627
|
function parseEvents(input, options) {
|
|
2267
2628
|
const length = input.length;
|
|
2268
2629
|
const state = _objectSpread2(_objectSpread2(_objectSpread2({}, DEFAULT_PARSER_OPTIONS), options), {}, {
|
|
@@ -2279,9 +2640,9 @@ function parseEvents(input, options) {
|
|
|
2279
2640
|
events: []
|
|
2280
2641
|
});
|
|
2281
2642
|
const nullpos = input.indexOf("\0");
|
|
2282
|
-
if (nullpos !== -1)
|
|
2283
|
-
if (state.input.charCodeAt(state.position) === 65279) state.position++;
|
|
2643
|
+
if (nullpos !== -1) YAMLException.throwAt(input, nullpos, "null byte is not allowed in input", state.filename);
|
|
2284
2644
|
while (state.position < state.length) {
|
|
2645
|
+
skipByteOrderMark(state);
|
|
2285
2646
|
skipSeparationSpace(state, true);
|
|
2286
2647
|
if (state.position >= state.length) break;
|
|
2287
2648
|
const documentStart = state.position;
|
|
@@ -2310,6 +2671,36 @@ function loadAll(input, iteratorOrOptions, options) {
|
|
|
2310
2671
|
if (iterator === null) return documents;
|
|
2311
2672
|
for (const document of documents) iterator(document);
|
|
2312
2673
|
}
|
|
2674
|
+
/**
|
|
2675
|
+
* Parses `string` as a single YAML document. Throws {@link YAMLException} on
|
|
2676
|
+
* error. This function does not understand multi-document or empty sources; it
|
|
2677
|
+
* throws an exception on those.
|
|
2678
|
+
*
|
|
2679
|
+
* > [!NOTE]
|
|
2680
|
+
* > 1. When processing untrusted input, see the
|
|
2681
|
+
* > [security considerations](../docs/safety.md).
|
|
2682
|
+
* > 2. All exceptions MUST be caught, not just {@link YAMLException}.
|
|
2683
|
+
* > 3. The default {@link CORE_SCHEMA} comes without the `!!merge` tag. You can
|
|
2684
|
+
* > easily enable it if needed.
|
|
2685
|
+
* > 4. The default {@link mapTag} is `{}`-object based, with known limitations
|
|
2686
|
+
* > (see description). For full compatibility use {@link realMapTag}
|
|
2687
|
+
* > instead (it uses native JS `Map`).
|
|
2688
|
+
*
|
|
2689
|
+
* @example
|
|
2690
|
+
* Enable {@link mergeTag} and {@link realMapTag}:
|
|
2691
|
+
*
|
|
2692
|
+
* ```javascript
|
|
2693
|
+
* import { load, CORE_SCHEMA, mergeTag, realMapTag } from 'js-yaml'
|
|
2694
|
+
*
|
|
2695
|
+
* try {
|
|
2696
|
+
* load(data, { schema: CORE_SCHEMA.withTags(mergeTag, realMapTag) })
|
|
2697
|
+
* } catch (e) {
|
|
2698
|
+
* console.error(e)
|
|
2699
|
+
* }
|
|
2700
|
+
* ```
|
|
2701
|
+
*
|
|
2702
|
+
* @category Main
|
|
2703
|
+
*/
|
|
2313
2704
|
function load(input, options) {
|
|
2314
2705
|
const documents = loadDocuments(input, options);
|
|
2315
2706
|
if (documents.length === 0) throw new YAMLException("expected a document, but the input is empty");
|
|
@@ -2317,18 +2708,6 @@ function load(input, options) {
|
|
|
2317
2708
|
throw new YAMLException("expected a single document in the stream, but found more");
|
|
2318
2709
|
}
|
|
2319
2710
|
//#endregion
|
|
2320
|
-
//#region src/ast/nodes.ts
|
|
2321
|
-
var Style = class {
|
|
2322
|
-
constructor() {
|
|
2323
|
-
_defineProperty(this, "tagged", false);
|
|
2324
|
-
_defineProperty(this, "flow", false);
|
|
2325
|
-
_defineProperty(this, "singleQuoted", false);
|
|
2326
|
-
_defineProperty(this, "doubleQuoted", false);
|
|
2327
|
-
_defineProperty(this, "literal", false);
|
|
2328
|
-
_defineProperty(this, "folded", false);
|
|
2329
|
-
}
|
|
2330
|
-
};
|
|
2331
|
-
//#endregion
|
|
2332
2711
|
//#region src/ast/from_js.ts
|
|
2333
2712
|
var INVALID = Symbol("INVALID");
|
|
2334
2713
|
function buildRepresentTypes(schema) {
|
|
@@ -2358,9 +2737,9 @@ function buildRepresentTypes(schema) {
|
|
|
2358
2737
|
function matchTag(state, object) {
|
|
2359
2738
|
for (let index = 0, length = state.representTypes.length; index < length; index += 1) {
|
|
2360
2739
|
const { tag, implicitTag } = state.representTypes[index];
|
|
2361
|
-
if (tag.identify
|
|
2740
|
+
if (tag.identify(object)) {
|
|
2362
2741
|
let tagName;
|
|
2363
|
-
if (tag.matchByTagPrefix
|
|
2742
|
+
if (tag.matchByTagPrefix) tagName = tag.representTagName(object);
|
|
2364
2743
|
else tagName = tag.tagName;
|
|
2365
2744
|
return {
|
|
2366
2745
|
tag,
|
|
@@ -2378,8 +2757,6 @@ function build(state, object) {
|
|
|
2378
2757
|
if (existing.anchor === void 0) existing.anchor = `ref_${state.refCounter++}`;
|
|
2379
2758
|
return {
|
|
2380
2759
|
kind: "alias",
|
|
2381
|
-
tag: "",
|
|
2382
|
-
style: new Style(),
|
|
2383
2760
|
anchor: existing.anchor
|
|
2384
2761
|
};
|
|
2385
2762
|
}
|
|
@@ -2392,24 +2769,20 @@ function build(state, object) {
|
|
|
2392
2769
|
}
|
|
2393
2770
|
const { tag, tagName, implicitTag } = matched;
|
|
2394
2771
|
const nodeTagName = implicitTag ? tagName : tagNameShort(tagName);
|
|
2395
|
-
if (tag.nodeKind === "scalar") {
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
value: tag.represent(object)
|
|
2403
|
-
};
|
|
2404
|
-
}
|
|
2772
|
+
if (tag.nodeKind === "scalar") return {
|
|
2773
|
+
kind: "scalar",
|
|
2774
|
+
tag: nodeTagName,
|
|
2775
|
+
tagged: !implicitTag,
|
|
2776
|
+
style: SCALAR_STYLE.PLAIN,
|
|
2777
|
+
value: tag.represent(object)
|
|
2778
|
+
};
|
|
2405
2779
|
if (tag.nodeKind === "sequence") {
|
|
2406
2780
|
const container = tag.represent(object);
|
|
2407
|
-
const style = new Style();
|
|
2408
|
-
style.tagged = !implicitTag;
|
|
2409
2781
|
const node = {
|
|
2410
2782
|
kind: "sequence",
|
|
2411
2783
|
tag: nodeTagName,
|
|
2412
|
-
|
|
2784
|
+
tagged: !implicitTag,
|
|
2785
|
+
style: COLLECTION_STYLE.BLOCK,
|
|
2413
2786
|
items: []
|
|
2414
2787
|
};
|
|
2415
2788
|
if (!state.noRefs) state.refs.set(object, node);
|
|
@@ -2422,12 +2795,11 @@ function build(state, object) {
|
|
|
2422
2795
|
return node;
|
|
2423
2796
|
}
|
|
2424
2797
|
const map = tag.represent(object);
|
|
2425
|
-
const style = new Style();
|
|
2426
|
-
style.tagged = !implicitTag;
|
|
2427
2798
|
const node = {
|
|
2428
2799
|
kind: "mapping",
|
|
2429
2800
|
tag: nodeTagName,
|
|
2430
|
-
|
|
2801
|
+
tagged: !implicitTag,
|
|
2802
|
+
style: COLLECTION_STYLE.BLOCK,
|
|
2431
2803
|
items: []
|
|
2432
2804
|
};
|
|
2433
2805
|
if (!state.noRefs) state.refs.set(object, node);
|
|
@@ -2443,6 +2815,13 @@ function build(state, object) {
|
|
|
2443
2815
|
}
|
|
2444
2816
|
return node;
|
|
2445
2817
|
}
|
|
2818
|
+
/**
|
|
2819
|
+
* Convert JS object to AST. A JS value is one YAML document. An unrepresentable
|
|
2820
|
+
* root becomes an empty document, which the presenter renders as an empty
|
|
2821
|
+
* string.
|
|
2822
|
+
*
|
|
2823
|
+
* @category AST
|
|
2824
|
+
*/
|
|
2446
2825
|
function jsToAst(input, schema, options = {}) {
|
|
2447
2826
|
var _options$noRefs, _options$skipInvalid;
|
|
2448
2827
|
const root = build({
|
|
@@ -2459,7 +2838,17 @@ function jsToAst(input, schema, options = {}) {
|
|
|
2459
2838
|
}
|
|
2460
2839
|
//#endregion
|
|
2461
2840
|
//#region src/ast/visit.ts
|
|
2841
|
+
/**
|
|
2842
|
+
* Return from a visitor to stop the whole traversal.
|
|
2843
|
+
*
|
|
2844
|
+
* @category AST
|
|
2845
|
+
*/
|
|
2462
2846
|
var VISIT_BREAK = Symbol("visit:break");
|
|
2847
|
+
/**
|
|
2848
|
+
* Return from a visitor to skip the current node's children.
|
|
2849
|
+
*
|
|
2850
|
+
* @category AST
|
|
2851
|
+
*/
|
|
2463
2852
|
var VISIT_SKIP = Symbol("visit:skip");
|
|
2464
2853
|
function visitNode(node, visitor, ctx) {
|
|
2465
2854
|
const control = visitor(node, ctx);
|
|
@@ -2491,6 +2880,12 @@ function visitNode(node, visitor, ctx) {
|
|
|
2491
2880
|
}
|
|
2492
2881
|
return false;
|
|
2493
2882
|
}
|
|
2883
|
+
/**
|
|
2884
|
+
* Walk every node in the documents, calling {@link Visitor} once per
|
|
2885
|
+
* node (pre-order).
|
|
2886
|
+
*
|
|
2887
|
+
* @category AST
|
|
2888
|
+
*/
|
|
2494
2889
|
function visit(documents, visitor) {
|
|
2495
2890
|
for (const doc of documents) if (doc.contents && visitNode(doc.contents, visitor, {
|
|
2496
2891
|
depth: 0,
|
|
@@ -2499,243 +2894,194 @@ function visit(documents, visitor) {
|
|
|
2499
2894
|
})) return;
|
|
2500
2895
|
}
|
|
2501
2896
|
//#endregion
|
|
2502
|
-
//#region src/ast/
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
var
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
var CHAR_QUESTION = 63;
|
|
2521
|
-
var CHAR_COMMERCIAL_AT = 64;
|
|
2522
|
-
var CHAR_LEFT_SQUARE_BRACKET = 91;
|
|
2523
|
-
var CHAR_RIGHT_SQUARE_BRACKET = 93;
|
|
2524
|
-
var CHAR_GRAVE_ACCENT = 96;
|
|
2525
|
-
var CHAR_LEFT_CURLY_BRACKET = 123;
|
|
2526
|
-
var CHAR_VERTICAL_LINE = 124;
|
|
2527
|
-
var CHAR_RIGHT_CURLY_BRACKET = 125;
|
|
2528
|
-
var ESCAPE_SEQUENCES = {};
|
|
2529
|
-
ESCAPE_SEQUENCES[0] = "\\0";
|
|
2530
|
-
ESCAPE_SEQUENCES[7] = "\\a";
|
|
2531
|
-
ESCAPE_SEQUENCES[8] = "\\b";
|
|
2532
|
-
ESCAPE_SEQUENCES[9] = "\\t";
|
|
2533
|
-
ESCAPE_SEQUENCES[10] = "\\n";
|
|
2534
|
-
ESCAPE_SEQUENCES[11] = "\\v";
|
|
2535
|
-
ESCAPE_SEQUENCES[12] = "\\f";
|
|
2536
|
-
ESCAPE_SEQUENCES[13] = "\\r";
|
|
2537
|
-
ESCAPE_SEQUENCES[27] = "\\e";
|
|
2538
|
-
ESCAPE_SEQUENCES[34] = "\\\"";
|
|
2539
|
-
ESCAPE_SEQUENCES[92] = "\\\\";
|
|
2540
|
-
ESCAPE_SEQUENCES[133] = "\\N";
|
|
2541
|
-
ESCAPE_SEQUENCES[160] = "\\_";
|
|
2542
|
-
ESCAPE_SEQUENCES[8232] = "\\L";
|
|
2543
|
-
ESCAPE_SEQUENCES[8233] = "\\P";
|
|
2544
|
-
var DEFAULT_PRESENTER_OPTIONS = {
|
|
2545
|
-
indent: 2,
|
|
2546
|
-
seqNoIndent: false,
|
|
2547
|
-
seqInlineFirst: true,
|
|
2548
|
-
sortKeys: false,
|
|
2549
|
-
lineWidth: 80,
|
|
2550
|
-
flowBracketPadding: false,
|
|
2551
|
-
flowSkipCommaSpace: false,
|
|
2552
|
-
flowSkipColonSpace: false,
|
|
2553
|
-
quoteFlowKeys: false,
|
|
2554
|
-
quoteStyle: "single",
|
|
2555
|
-
forceQuotes: false,
|
|
2556
|
-
tagBeforeAnchor: false
|
|
2897
|
+
//#region src/ast/styler_defaults.ts
|
|
2898
|
+
function hasBit(mask, bit) {
|
|
2899
|
+
return (mask & 1 << bit) !== 0;
|
|
2900
|
+
}
|
|
2901
|
+
/**
|
|
2902
|
+
* Default scalar styling rules in application order.
|
|
2903
|
+
* See [Scalar styling](../../docs/scalar_styling.md) for usage details.
|
|
2904
|
+
*
|
|
2905
|
+
* @category AST
|
|
2906
|
+
*/
|
|
2907
|
+
var DEFAULT_SCALAR_STYLE_RULES = {
|
|
2908
|
+
applyQuoteFlowKeysOption,
|
|
2909
|
+
doubleQuoteForInvisibles,
|
|
2910
|
+
doubleQuoteWhitespaceOnly,
|
|
2911
|
+
applyForceQuotesOption,
|
|
2912
|
+
tryLongOrMultilineAsBlock,
|
|
2913
|
+
quoteInvalidPlain,
|
|
2914
|
+
fallbackToDoubleQuoted
|
|
2557
2915
|
};
|
|
2558
|
-
function
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2916
|
+
function _preferredQuotedStyle(layout) {
|
|
2917
|
+
if (layout.presenterOptions.quoteStyle === "single" && hasBit(layout.allowedStylesMask, SCALAR_STYLE.SINGLE_QUOTED)) return SCALAR_STYLE.SINGLE_QUOTED;
|
|
2918
|
+
return SCALAR_STYLE.DOUBLE_QUOTED;
|
|
2919
|
+
}
|
|
2920
|
+
function applyQuoteFlowKeysOption(layout) {
|
|
2921
|
+
if (!layout.presenterOptions.quoteFlowKeys) return;
|
|
2922
|
+
if (!layout.isKey || !layout.flowOnly || layout.style !== SCALAR_STYLE.PLAIN) return;
|
|
2923
|
+
layout.style = SCALAR_STYLE.DOUBLE_QUOTED;
|
|
2924
|
+
}
|
|
2925
|
+
function doubleQuoteForInvisibles(layout) {
|
|
2926
|
+
if (layout.style === SCALAR_STYLE.PLAIN && /[\t\x7F-\xA0\u2028\u2029\uFEFF\uFFFE\uFFFF]/.test(layout.node.value)) layout.style = SCALAR_STYLE.DOUBLE_QUOTED;
|
|
2927
|
+
}
|
|
2928
|
+
function doubleQuoteWhitespaceOnly(layout) {
|
|
2929
|
+
if (layout.style === SCALAR_STYLE.PLAIN && /^\s+$/.test(layout.node.value)) layout.style = SCALAR_STYLE.DOUBLE_QUOTED;
|
|
2930
|
+
}
|
|
2931
|
+
function applyForceQuotesOption(layout) {
|
|
2932
|
+
if (!layout.presenterOptions.forceQuotes) return;
|
|
2933
|
+
if (layout.isKey || layout.style !== SCALAR_STYLE.PLAIN) return;
|
|
2934
|
+
layout.style = layout.node.value.includes("\n") ? SCALAR_STYLE.DOUBLE_QUOTED : _preferredQuotedStyle(layout);
|
|
2935
|
+
}
|
|
2936
|
+
function tryLongOrMultilineAsBlock(layout) {
|
|
2937
|
+
if (layout.style !== SCALAR_STYLE.PLAIN || layout.isKey) return;
|
|
2938
|
+
const value = layout.node.value;
|
|
2939
|
+
const multiline = value.indexOf("\n") !== -1;
|
|
2940
|
+
if (!hasBit(layout.allowedStylesMask, SCALAR_STYLE.LITERAL_BLOCK)) {
|
|
2941
|
+
if (multiline) layout.style = SCALAR_STYLE.DOUBLE_QUOTED;
|
|
2942
|
+
return;
|
|
2943
|
+
}
|
|
2944
|
+
const w = layout.presenterOptions.lineWidth;
|
|
2945
|
+
if (w === -1) {
|
|
2946
|
+
if (multiline) layout.style = SCALAR_STYLE.LITERAL_BLOCK;
|
|
2947
|
+
return;
|
|
2948
|
+
}
|
|
2949
|
+
const availableWidth = Math.max(Math.min(w, 40), w - layout.shiftOfContent);
|
|
2576
2950
|
let position = 0;
|
|
2577
|
-
let
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
line = string.slice(position, next + 1);
|
|
2587
|
-
position = next + 1;
|
|
2588
|
-
}
|
|
2589
|
-
if (line.length && line !== "\n") result += ind;
|
|
2590
|
-
result += line;
|
|
2951
|
+
let shouldFold = false;
|
|
2952
|
+
while (position <= value.length) {
|
|
2953
|
+
let lineEnd = value.length;
|
|
2954
|
+
const nextLineBreak = value.indexOf("\n", position);
|
|
2955
|
+
if (nextLineBreak !== -1) lineEnd = nextLineBreak;
|
|
2956
|
+
const line = value.slice(position, lineEnd);
|
|
2957
|
+
if (line.length > availableWidth && line[0] !== " " && / [^ \t]/.test(line)) shouldFold = true;
|
|
2958
|
+
if (nextLineBreak === -1) break;
|
|
2959
|
+
position = nextLineBreak + 1;
|
|
2591
2960
|
}
|
|
2592
|
-
|
|
2961
|
+
if (shouldFold) layout.style = SCALAR_STYLE.FOLDED_BLOCK;
|
|
2962
|
+
else if (multiline) layout.style = SCALAR_STYLE.LITERAL_BLOCK;
|
|
2593
2963
|
}
|
|
2594
|
-
function
|
|
2595
|
-
|
|
2964
|
+
function quoteInvalidPlain(layout) {
|
|
2965
|
+
if (layout.style === SCALAR_STYLE.PLAIN && !hasBit(layout.allowedStylesMask, SCALAR_STYLE.PLAIN)) layout.style = _preferredQuotedStyle(layout);
|
|
2596
2966
|
}
|
|
2597
|
-
function
|
|
2598
|
-
|
|
2599
|
-
return {
|
|
2600
|
-
indent,
|
|
2601
|
-
blockIndent: level === 0 ? state.indent + 1 : state.indent,
|
|
2602
|
-
lineWidth: state.lineWidth === -1 ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent)
|
|
2603
|
-
};
|
|
2967
|
+
function fallbackToDoubleQuoted(layout) {
|
|
2968
|
+
if (!hasBit(layout.allowedStylesMask, layout.style)) layout.style = SCALAR_STYLE.DOUBLE_QUOTED;
|
|
2604
2969
|
}
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2970
|
+
//#endregion
|
|
2971
|
+
//#region src/ast/scalar_styler.ts
|
|
2972
|
+
function setBit(mask, bit) {
|
|
2973
|
+
return mask | 1 << bit;
|
|
2974
|
+
}
|
|
2975
|
+
var SRC_C_PRINTABLE = "[\\x09\\x0A\\x0D\\x20-\\x7E\\x85\\xA0-\\uD7FF\\uE000-\\uFFFD\\u{10000}-\\u{10FFFF}]";
|
|
2976
|
+
var SRC_B_CHAR = "[\\n\\r]";
|
|
2977
|
+
var SRC_C_BYTE_ORDER_MARK = "\\uFEFF";
|
|
2978
|
+
var SRC_S_WHITE = "[ \\t]";
|
|
2979
|
+
var SRC_NB_CHAR = `(?:(?!(?:${SRC_B_CHAR}|${SRC_C_BYTE_ORDER_MARK}))${SRC_C_PRINTABLE})`;
|
|
2980
|
+
var SRC_NS_CHAR = `(?:(?!${SRC_S_WHITE})${SRC_NB_CHAR})`;
|
|
2981
|
+
var SRC_NB_JSON = "[\\x09\\x20-\\uD7FF\\uE000-\\uFFFF\\u{10000}-\\u{10FFFF}]";
|
|
2982
|
+
var SRC_C_INDICATOR = "[-?:,\\[\\]{}#&*!|>'\"%@`]";
|
|
2983
|
+
var SRC_C_FLOW_INDICATOR = "[,\\[\\]{}]";
|
|
2984
|
+
var SRC_NS_PLAIN_SAFE_FLOW_OUT = SRC_NS_CHAR;
|
|
2985
|
+
var SRC_NS_PLAIN_SAFE_FLOW_IN = `(?:(?!${SRC_C_FLOW_INDICATOR})${SRC_NS_CHAR})`;
|
|
2986
|
+
var SRC_NS_PLAIN_FIRST_FLOW_OUT = `(?:(?:(?!${SRC_C_INDICATOR})${SRC_NS_CHAR})|[?:-](?=${SRC_NS_PLAIN_SAFE_FLOW_OUT}))`;
|
|
2987
|
+
var SRC_NS_PLAIN_FIRST_FLOW_IN = `(?:(?:(?!${SRC_C_INDICATOR})${SRC_NS_CHAR})|[?:-](?=${SRC_NS_PLAIN_SAFE_FLOW_IN}))`;
|
|
2988
|
+
var SRC_NS_PLAIN_CHAR_FLOW_OUT = `(?:(?:(?![:#])${SRC_NS_PLAIN_SAFE_FLOW_OUT})|:(?=${SRC_NS_PLAIN_SAFE_FLOW_OUT}))#*`;
|
|
2989
|
+
var SRC_NS_PLAIN_CHAR_FLOW_IN = `(?:(?:(?![:#])${SRC_NS_PLAIN_SAFE_FLOW_IN})|:(?=${SRC_NS_PLAIN_SAFE_FLOW_IN}))#*`;
|
|
2990
|
+
var SRC_NB_NS_PLAIN_IN_LINE_FLOW_OUT = `(?:${SRC_S_WHITE}*${SRC_NS_PLAIN_CHAR_FLOW_OUT})*`;
|
|
2991
|
+
var SRC_NB_NS_PLAIN_IN_LINE_FLOW_IN = `(?:${SRC_S_WHITE}*${SRC_NS_PLAIN_CHAR_FLOW_IN})*`;
|
|
2992
|
+
var SRC_NS_PLAIN_ONE_LINE_FLOW_OUT = `${SRC_NS_PLAIN_FIRST_FLOW_OUT}#*${SRC_NB_NS_PLAIN_IN_LINE_FLOW_OUT}`;
|
|
2993
|
+
var SRC_NS_PLAIN_ONE_LINE_FLOW_IN = `${SRC_NS_PLAIN_FIRST_FLOW_IN}#*${SRC_NB_NS_PLAIN_IN_LINE_FLOW_IN}`;
|
|
2994
|
+
var SRC_NS_PLAIN_ONE_LINE_BLOCK_KEY = SRC_NS_PLAIN_ONE_LINE_FLOW_OUT;
|
|
2995
|
+
var SRC_NS_PLAIN_ONE_LINE_FLOW_KEY = SRC_NS_PLAIN_ONE_LINE_FLOW_IN;
|
|
2996
|
+
var SRC_S_NS_PLAIN_NEXT_LINE_FLOW_OUT = `\\n+${SRC_NS_PLAIN_CHAR_FLOW_OUT}${SRC_NB_NS_PLAIN_IN_LINE_FLOW_OUT}`;
|
|
2997
|
+
var SRC_S_NS_PLAIN_NEXT_LINE_FLOW_IN = `\\n+${SRC_NS_PLAIN_CHAR_FLOW_IN}${SRC_NB_NS_PLAIN_IN_LINE_FLOW_IN}`;
|
|
2998
|
+
var SRC_NS_PLAIN_MULTI_LINE_FLOW_OUT = `${SRC_NS_PLAIN_ONE_LINE_FLOW_OUT}(?:${SRC_S_NS_PLAIN_NEXT_LINE_FLOW_OUT})*`;
|
|
2999
|
+
var SRC_NS_PLAIN_MULTI_LINE_FLOW_IN = `${SRC_NS_PLAIN_ONE_LINE_FLOW_IN}(?:${SRC_S_NS_PLAIN_NEXT_LINE_FLOW_IN})*`;
|
|
3000
|
+
var NS_PLAIN_FLOW_OUT = new RegExp(`^(?:${SRC_NS_PLAIN_MULTI_LINE_FLOW_OUT})$`, "u");
|
|
3001
|
+
var NS_PLAIN_FLOW_IN = new RegExp(`^(?:${SRC_NS_PLAIN_MULTI_LINE_FLOW_IN})$`, "u");
|
|
3002
|
+
var NS_PLAIN_BLOCK_KEY = new RegExp(`^(?:${SRC_NS_PLAIN_ONE_LINE_BLOCK_KEY})$`, "u");
|
|
3003
|
+
var NS_PLAIN_FLOW_KEY = new RegExp(`^(?:${SRC_NS_PLAIN_ONE_LINE_FLOW_KEY})$`, "u");
|
|
3004
|
+
var NB_SINGLE_ONE_LINE = new RegExp(`^(?:${SRC_NB_JSON})*$`, "u");
|
|
3005
|
+
var NB_SINGLE_MULTI_LINE = new RegExp(`^(?:${SRC_NB_JSON}|\\n)*$`, "u");
|
|
3006
|
+
var BLOCK_SCALAR_CONTENT = new RegExp(`^(?:${SRC_NB_CHAR}|\\n)*$`, "u");
|
|
3007
|
+
var C_FORBIDDEN_FIRST_LINE = /^(?:---|\.\.\.)(?=$|[ \t\n\r])/;
|
|
3008
|
+
var C_FORBIDDEN_CONTENT = /^(?:---|\.\.\.)(?=$|[ \t\n\r])/m;
|
|
3009
|
+
function canUsePlain(layout) {
|
|
3010
|
+
const str = layout.node.value;
|
|
3011
|
+
if (str !== "") {
|
|
3012
|
+
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;
|
|
3013
|
+
if (layout.shiftOfFirstLine === 0 && C_FORBIDDEN_FIRST_LINE.test(str)) return false;
|
|
3014
|
+
if (layout.shiftOfContent === 0) {
|
|
3015
|
+
const firstLineBreak = str.indexOf("\n");
|
|
3016
|
+
if (firstLineBreak !== -1) {
|
|
3017
|
+
const content = str.slice(firstLineBreak + 1);
|
|
3018
|
+
if (C_FORBIDDEN_CONTENT.test(content)) return false;
|
|
3019
|
+
}
|
|
3020
|
+
}
|
|
2609
3021
|
}
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
return
|
|
2614
|
-
}
|
|
2615
|
-
function startsWithDocumentSeparator(string) {
|
|
2616
|
-
const marker = string.charCodeAt(0);
|
|
2617
|
-
if (marker !== CHAR_MINUS && marker !== 46 || string.charCodeAt(1) !== marker || string.charCodeAt(2) !== marker) return false;
|
|
2618
|
-
if (string.length === 3) return true;
|
|
2619
|
-
const following = string.charCodeAt(3);
|
|
2620
|
-
return isWhitespace(following) || following === CHAR_CARRIAGE_RETURN || following === CHAR_LINE_FEED;
|
|
2621
|
-
}
|
|
2622
|
-
function isPrintable(c) {
|
|
2623
|
-
return c >= 32 && c <= 126 || c >= 161 && c <= 55295 && c !== 8232 && c !== 8233 || c >= 57344 && c <= 65533 && c !== CHAR_BOM || c >= 65536 && c <= 1114111;
|
|
3022
|
+
const resolvedTag = layout.presenterOptions.schema.resolveImplicitScalarTag(str).tag.tagName;
|
|
3023
|
+
if (!layout.node.tagged && resolvedTag !== layout.node.tag) return false;
|
|
3024
|
+
if (!layout.node.tagged && str === "=" && resolvedTag === layout.presenterOptions.schema.defaultScalarTag.tagName) return false;
|
|
3025
|
+
return true;
|
|
2624
3026
|
}
|
|
2625
|
-
function
|
|
2626
|
-
|
|
3027
|
+
function canUseSingleQuoted(layout) {
|
|
3028
|
+
const str = layout.node.value;
|
|
3029
|
+
if (!(layout.isKey ? NB_SINGLE_ONE_LINE : NB_SINGLE_MULTI_LINE).test(str)) return false;
|
|
3030
|
+
if (/[ \t]\n|\n[ \t]/.test(str)) return false;
|
|
3031
|
+
if (!layout.isKey && layout.shiftOfContent === 0) {
|
|
3032
|
+
const firstLineBreak = str.indexOf("\n");
|
|
3033
|
+
if (firstLineBreak !== -1 && C_FORBIDDEN_CONTENT.test(str.slice(firstLineBreak + 1))) return false;
|
|
3034
|
+
}
|
|
3035
|
+
return true;
|
|
2627
3036
|
}
|
|
2628
|
-
function
|
|
2629
|
-
|
|
2630
|
-
const
|
|
2631
|
-
|
|
3037
|
+
function canUseBlock(layout) {
|
|
3038
|
+
if (layout.flowOnly || !BLOCK_SCALAR_CONTENT.test(layout.node.value)) return false;
|
|
3039
|
+
const contentIndent = layout.shiftOfContent - layout.shiftOfParent;
|
|
3040
|
+
if (contentIndent < 1) return false;
|
|
3041
|
+
if (contentIndent > 9 && /^\n* /.test(layout.node.value)) return false;
|
|
3042
|
+
if (layout.shiftOfContent === 0 && C_FORBIDDEN_CONTENT.test(layout.node.value)) return false;
|
|
3043
|
+
return true;
|
|
2632
3044
|
}
|
|
2633
|
-
function
|
|
2634
|
-
|
|
3045
|
+
function detectAllowedStyles(layout) {
|
|
3046
|
+
let mask = setBit(0, SCALAR_STYLE.DOUBLE_QUOTED);
|
|
3047
|
+
if (canUsePlain(layout)) mask = setBit(mask, SCALAR_STYLE.PLAIN);
|
|
3048
|
+
if (canUseSingleQuoted(layout)) mask = setBit(mask, SCALAR_STYLE.SINGLE_QUOTED);
|
|
3049
|
+
if (canUseBlock(layout)) mask = setBit(setBit(mask, SCALAR_STYLE.LITERAL_BLOCK), SCALAR_STYLE.FOLDED_BLOCK);
|
|
3050
|
+
layout.allowedStylesMask = mask;
|
|
2635
3051
|
}
|
|
2636
|
-
function
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
3052
|
+
function renderScalar(layout) {
|
|
3053
|
+
switch (layout.style) {
|
|
3054
|
+
case SCALAR_STYLE.PLAIN: return renderPlain(layout);
|
|
3055
|
+
case SCALAR_STYLE.SINGLE_QUOTED: return renderSingleQuoted(layout);
|
|
3056
|
+
case SCALAR_STYLE.LITERAL_BLOCK: return renderLiteralBlock(layout);
|
|
3057
|
+
case SCALAR_STYLE.FOLDED_BLOCK: return renderFoldedBlock(layout);
|
|
3058
|
+
case SCALAR_STYLE.DOUBLE_QUOTED: return renderDoubleQuoted(layout);
|
|
2642
3059
|
}
|
|
2643
|
-
return false;
|
|
2644
3060
|
}
|
|
2645
|
-
function
|
|
2646
|
-
return
|
|
3061
|
+
function renderPlain(layout) {
|
|
3062
|
+
return encodeFlowBreaks(layout.node.value, layout.shiftOfContent);
|
|
2647
3063
|
}
|
|
2648
|
-
function
|
|
2649
|
-
|
|
2650
|
-
let second;
|
|
2651
|
-
if (first >= 55296 && first <= 56319 && pos + 1 < string.length) {
|
|
2652
|
-
second = string.charCodeAt(pos + 1);
|
|
2653
|
-
if (second >= 56320 && second <= 57343) return (first - 55296) * 1024 + second - 56320 + 65536;
|
|
2654
|
-
}
|
|
2655
|
-
return first;
|
|
3064
|
+
function renderSingleQuoted(layout) {
|
|
3065
|
+
return `'${encodeFlowBreaks(layout.node.value, layout.shiftOfContent).replace(/'/g, "''")}'`;
|
|
2656
3066
|
}
|
|
2657
|
-
function
|
|
2658
|
-
|
|
3067
|
+
function renderLiteralBlock(layout) {
|
|
3068
|
+
const value = layout.node.value;
|
|
3069
|
+
return "|" + blockHeader(value, layout.shiftOfParent, layout.shiftOfContent) + dropEndingNewline(indentString(value, layout.shiftOfContent));
|
|
2659
3070
|
}
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
let prevChar = -1;
|
|
2670
|
-
let hasLineBreak = false;
|
|
2671
|
-
let hasFoldableLine = false;
|
|
2672
|
-
const shouldTrackWidth = lineWidth !== -1;
|
|
2673
|
-
let previousLineBreak = -1;
|
|
2674
|
-
let plain = !startsWithDocumentSeparator(string) && isPlainSafeAtStart(string, inblock) && isPlainSafeLast(codePointAt(string, string.length - 1));
|
|
2675
|
-
if (singleLineOnly || forceQuote) for (i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
|
|
2676
|
-
char = codePointAt(string, i);
|
|
2677
|
-
if (!isPrintable(char)) return STYLE_DOUBLE;
|
|
2678
|
-
plain = plain && isPlainSafe(char, prevChar, inblock);
|
|
2679
|
-
prevChar = char;
|
|
2680
|
-
}
|
|
2681
|
-
else {
|
|
2682
|
-
for (i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
|
|
2683
|
-
char = codePointAt(string, i);
|
|
2684
|
-
if (char === CHAR_LINE_FEED) {
|
|
2685
|
-
hasLineBreak = true;
|
|
2686
|
-
if (shouldTrackWidth) {
|
|
2687
|
-
hasFoldableLine = hasFoldableLine || i - previousLineBreak - 1 > lineWidth && !isMoreIndented(string[previousLineBreak + 1]);
|
|
2688
|
-
previousLineBreak = i;
|
|
2689
|
-
}
|
|
2690
|
-
} else if (!isPrintable(char)) return STYLE_DOUBLE;
|
|
2691
|
-
plain = plain && isPlainSafe(char, prevChar, inblock);
|
|
2692
|
-
prevChar = char;
|
|
2693
|
-
}
|
|
2694
|
-
hasFoldableLine = hasFoldableLine || shouldTrackWidth && i - previousLineBreak - 1 > lineWidth && !isMoreIndented(string[previousLineBreak + 1]);
|
|
2695
|
-
}
|
|
2696
|
-
if (!hasLineBreak && !hasFoldableLine) {
|
|
2697
|
-
if (plain && !forceQuote) return STYLE_PLAIN;
|
|
2698
|
-
return state.quoteStyle === "double" ? STYLE_DOUBLE : STYLE_SINGLE;
|
|
2699
|
-
}
|
|
2700
|
-
if (blockIndent > 9 && needIndentIndicator(string)) return STYLE_DOUBLE;
|
|
2701
|
-
return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL;
|
|
2702
|
-
}
|
|
2703
|
-
function renderScalarStyle(string, style, layout) {
|
|
2704
|
-
const { indent, blockIndent, lineWidth } = layout;
|
|
2705
|
-
switch (style) {
|
|
2706
|
-
case STYLE_PLAIN: return encodeFlowBreaks(string, indent);
|
|
2707
|
-
case STYLE_SINGLE: return `'${encodeFlowBreaks(string, indent).replace(/'/g, "''")}'`;
|
|
2708
|
-
case STYLE_LITERAL: return "|" + blockHeader(string, blockIndent) + dropEndingNewline(indentString(string, indent));
|
|
2709
|
-
case STYLE_FOLDED: return ">" + blockHeader(string, blockIndent) + dropEndingNewline(indentString(foldBlockScalar(string, lineWidth), indent));
|
|
2710
|
-
case STYLE_DOUBLE: return `"${escapeString(string)}"`;
|
|
2711
|
-
}
|
|
2712
|
-
}
|
|
2713
|
-
function resolveScalarStyle(state, node, layout, iskey, inblock) {
|
|
2714
|
-
const singleLineOnly = iskey || !inblock;
|
|
2715
|
-
if (node.style.singleQuoted) return STYLE_SINGLE;
|
|
2716
|
-
if (node.style.doubleQuoted) return STYLE_DOUBLE;
|
|
2717
|
-
if (!singleLineOnly) {
|
|
2718
|
-
if (node.style.literal) return STYLE_LITERAL;
|
|
2719
|
-
if (node.style.folded) return STYLE_FOLDED;
|
|
2720
|
-
}
|
|
2721
|
-
const string = node.value;
|
|
2722
|
-
if (string.length === 0) {
|
|
2723
|
-
if (node.style.tagged || resolveImplicitTag(state, string) === node.tag) return STYLE_PLAIN;
|
|
2724
|
-
return state.quoteStyle === "double" ? STYLE_DOUBLE : STYLE_SINGLE;
|
|
2725
|
-
}
|
|
2726
|
-
const style = chooseScalarStyle(state, string, layout, singleLineOnly, state.forceQuotes && !iskey, inblock);
|
|
2727
|
-
if (style === STYLE_PLAIN && !node.style.tagged && resolveImplicitTag(state, string) !== node.tag) return state.quoteStyle === "double" ? STYLE_DOUBLE : STYLE_SINGLE;
|
|
2728
|
-
return style;
|
|
2729
|
-
}
|
|
2730
|
-
function blockHeader(string, indentPerLevel) {
|
|
2731
|
-
const indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) : "";
|
|
2732
|
-
const clip = string[string.length - 1] === "\n";
|
|
2733
|
-
return `${indentIndicator}${clip && (string[string.length - 2] === "\n" || string === "\n") ? "+" : clip ? "" : "-"}\n`;
|
|
3071
|
+
function renderFoldedBlock(layout) {
|
|
3072
|
+
const value = layout.node.value;
|
|
3073
|
+
const w = layout.presenterOptions.lineWidth;
|
|
3074
|
+
let availableWidth = Infinity;
|
|
3075
|
+
if (w !== -1) availableWidth = Math.max(Math.min(w, 40), w - layout.shiftOfContent);
|
|
3076
|
+
return ">" + blockHeader(value, layout.shiftOfParent, layout.shiftOfContent) + dropEndingNewline(indentString(foldBlockScalar(value, availableWidth), layout.shiftOfContent));
|
|
3077
|
+
}
|
|
3078
|
+
function renderDoubleQuoted(layout) {
|
|
3079
|
+
return `"${escapeString(layout.node.value)}"`;
|
|
2734
3080
|
}
|
|
2735
|
-
function encodeFlowBreaks(string,
|
|
3081
|
+
function encodeFlowBreaks(string, shiftOfContent) {
|
|
2736
3082
|
let nextLF = string.indexOf("\n");
|
|
2737
3083
|
if (nextLF === -1) return string;
|
|
2738
|
-
const pad = " ".repeat(
|
|
3084
|
+
const pad = " ".repeat(shiftOfContent);
|
|
2739
3085
|
let result = string.slice(0, nextLF);
|
|
2740
3086
|
const lineRe = /(\n+)([^\n]*)/g;
|
|
2741
3087
|
lineRe.lastIndex = nextLF;
|
|
@@ -2747,30 +3093,40 @@ function encodeFlowBreaks(string, indent) {
|
|
|
2747
3093
|
}
|
|
2748
3094
|
return result;
|
|
2749
3095
|
}
|
|
3096
|
+
function indentString(string, spaces) {
|
|
3097
|
+
const indent = " ".repeat(spaces);
|
|
3098
|
+
let position = 0;
|
|
3099
|
+
let result = "";
|
|
3100
|
+
const length = string.length;
|
|
3101
|
+
while (position < length) {
|
|
3102
|
+
let line;
|
|
3103
|
+
const next = string.indexOf("\n", position);
|
|
3104
|
+
if (next === -1) {
|
|
3105
|
+
line = string.slice(position);
|
|
3106
|
+
position = length;
|
|
3107
|
+
} else {
|
|
3108
|
+
line = string.slice(position, next + 1);
|
|
3109
|
+
position = next + 1;
|
|
3110
|
+
}
|
|
3111
|
+
if (line.length && line !== "\n") result += indent;
|
|
3112
|
+
result += line;
|
|
3113
|
+
}
|
|
3114
|
+
return result;
|
|
3115
|
+
}
|
|
3116
|
+
function needIndentIndicator(string) {
|
|
3117
|
+
return /^\n* /.test(string);
|
|
3118
|
+
}
|
|
3119
|
+
function blockHeader(string, shiftOfParent, shiftOfContent) {
|
|
3120
|
+
const indentIndicator = needIndentIndicator(string) ? String(shiftOfContent - shiftOfParent) : "";
|
|
3121
|
+
const clip = string[string.length - 1] === "\n";
|
|
3122
|
+
return `${indentIndicator}${clip && (string[string.length - 2] === "\n" || string === "\n") ? "+" : clip ? "" : "-"}\n`;
|
|
3123
|
+
}
|
|
2750
3124
|
function dropEndingNewline(string) {
|
|
2751
3125
|
return string[string.length - 1] === "\n" ? string.slice(0, -1) : string;
|
|
2752
3126
|
}
|
|
2753
3127
|
function isMoreIndented(char) {
|
|
2754
3128
|
return char === " " || char === " ";
|
|
2755
3129
|
}
|
|
2756
|
-
function foldBlockScalar(string, width) {
|
|
2757
|
-
const lineRe = /(\n+)([^\n]*)/g;
|
|
2758
|
-
let nextLF = string.indexOf("\n");
|
|
2759
|
-
if (nextLF === -1) nextLF = string.length;
|
|
2760
|
-
lineRe.lastIndex = nextLF;
|
|
2761
|
-
let result = foldLine(string.slice(0, nextLF), width);
|
|
2762
|
-
let prevMoreIndented = string[0] === "\n" || isMoreIndented(string[0]);
|
|
2763
|
-
let moreIndented;
|
|
2764
|
-
let match;
|
|
2765
|
-
while (match = lineRe.exec(string)) {
|
|
2766
|
-
const prefix = match[1];
|
|
2767
|
-
const line = match[2];
|
|
2768
|
-
moreIndented = line !== "" && isMoreIndented(line[0]);
|
|
2769
|
-
result += prefix + (!prevMoreIndented && !moreIndented && line !== "" ? "\n" : "") + foldLine(line, width);
|
|
2770
|
-
prevMoreIndented = moreIndented;
|
|
2771
|
-
}
|
|
2772
|
-
return result;
|
|
2773
|
-
}
|
|
2774
3130
|
function foldLine(line, width) {
|
|
2775
3131
|
if (line === "" || isMoreIndented(line[0])) return line;
|
|
2776
3132
|
const breakRe = / [^ \t]/g;
|
|
@@ -2794,43 +3150,115 @@ function foldLine(line, width) {
|
|
|
2794
3150
|
else result += line.slice(start);
|
|
2795
3151
|
return result.slice(1);
|
|
2796
3152
|
}
|
|
2797
|
-
function
|
|
2798
|
-
|
|
2799
|
-
let
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
result += encodeNonPrintable(char);
|
|
3153
|
+
function foldBlockScalar(string, width) {
|
|
3154
|
+
const lineRe = /(\n+)([^\n]*)/g;
|
|
3155
|
+
let nextLF = string.indexOf("\n");
|
|
3156
|
+
if (nextLF === -1) nextLF = string.length;
|
|
3157
|
+
lineRe.lastIndex = nextLF;
|
|
3158
|
+
let result = foldLine(string.slice(0, nextLF), width);
|
|
3159
|
+
let prevMoreIndented = string[0] === "\n" || isMoreIndented(string[0]);
|
|
3160
|
+
let moreIndented;
|
|
3161
|
+
let match;
|
|
3162
|
+
while (match = lineRe.exec(string)) {
|
|
3163
|
+
const prefix = match[1];
|
|
3164
|
+
const line = match[2];
|
|
3165
|
+
moreIndented = line !== "" && isMoreIndented(line[0]);
|
|
3166
|
+
result += prefix + (!prevMoreIndented && !moreIndented && line !== "" ? "\n" : "") + foldLine(line, width);
|
|
3167
|
+
prevMoreIndented = moreIndented;
|
|
2813
3168
|
}
|
|
2814
3169
|
return result;
|
|
2815
3170
|
}
|
|
3171
|
+
var CHARACTERS_TO_ESCAPE = /["\\\x00-\x1F\x7F-\xA0\u2028\u2029\uD800-\uDFFF\uFEFF\uFFFE\uFFFF]/gu;
|
|
3172
|
+
function escapeCharacter(character) {
|
|
3173
|
+
switch (character) {
|
|
3174
|
+
case "\0": return "\\0";
|
|
3175
|
+
case "\x07": return "\\a";
|
|
3176
|
+
case "\b": return "\\b";
|
|
3177
|
+
case " ": return "\\t";
|
|
3178
|
+
case "\n": return "\\n";
|
|
3179
|
+
case "\v": return "\\v";
|
|
3180
|
+
case "\f": return "\\f";
|
|
3181
|
+
case "\r": return "\\r";
|
|
3182
|
+
case "\x1B": return "\\e";
|
|
3183
|
+
case "\"": return "\\\"";
|
|
3184
|
+
case "\\": return "\\\\";
|
|
3185
|
+
case "
": return "\\N";
|
|
3186
|
+
case "\xA0": return "\\_";
|
|
3187
|
+
case "\u2028": return "\\L";
|
|
3188
|
+
case "\u2029": return "\\P";
|
|
3189
|
+
}
|
|
3190
|
+
const code = character.charCodeAt(0);
|
|
3191
|
+
const hex = code.toString(16).toUpperCase();
|
|
3192
|
+
if (code <= 255) return `\\x${"0".repeat(2 - hex.length)}${hex}`;
|
|
3193
|
+
return `\\u${"0".repeat(4 - hex.length)}${hex}`;
|
|
3194
|
+
}
|
|
3195
|
+
function escapeString(string) {
|
|
3196
|
+
return string.replace(CHARACTERS_TO_ESCAPE, escapeCharacter);
|
|
3197
|
+
}
|
|
3198
|
+
//#endregion
|
|
3199
|
+
//#region src/ast/presenter.ts
|
|
3200
|
+
var CHAR_LINE_FEED = 10;
|
|
3201
|
+
var DEFAULT_PRESENTER_OPTIONS = {
|
|
3202
|
+
indent: 2,
|
|
3203
|
+
seqNoIndent: false,
|
|
3204
|
+
seqInlineFirst: true,
|
|
3205
|
+
lineWidth: 80,
|
|
3206
|
+
flowBracketPadding: false,
|
|
3207
|
+
flowSkipCommaSpace: false,
|
|
3208
|
+
flowSkipColonSpace: false,
|
|
3209
|
+
quoteFlowKeys: false,
|
|
3210
|
+
quoteStyle: "single",
|
|
3211
|
+
forceQuotes: false,
|
|
3212
|
+
scalarStyleRules: Object.keys(DEFAULT_SCALAR_STYLE_RULES).map((name) => Reflect.get(DEFAULT_SCALAR_STYLE_RULES, name)),
|
|
3213
|
+
tagBeforeAnchor: false
|
|
3214
|
+
};
|
|
3215
|
+
function nodeTagShort(node) {
|
|
3216
|
+
return node.tagged ? node.tag : tagNameShort(node.tag);
|
|
3217
|
+
}
|
|
3218
|
+
function createPresenterState(options) {
|
|
3219
|
+
const opts = _objectSpread2(_objectSpread2({}, DEFAULT_PRESENTER_OPTIONS), options);
|
|
3220
|
+
if (opts.flowSkipColonSpace) opts.quoteFlowKeys = true;
|
|
3221
|
+
return _objectSpread2(_objectSpread2({}, opts), {}, {
|
|
3222
|
+
defaultScalarTagName: opts.schema.defaultScalarTag.tagName,
|
|
3223
|
+
openEnded: false
|
|
3224
|
+
});
|
|
3225
|
+
}
|
|
3226
|
+
function generateNextLine(state, level) {
|
|
3227
|
+
return `\n${" ".repeat(state.indent * level)}`;
|
|
3228
|
+
}
|
|
3229
|
+
function scalarLayout(state, node, parent, level, isKey, flowOnly) {
|
|
3230
|
+
return {
|
|
3231
|
+
node,
|
|
3232
|
+
parent,
|
|
3233
|
+
level,
|
|
3234
|
+
isKey,
|
|
3235
|
+
flowOnly,
|
|
3236
|
+
shiftOfParent: level === 0 ? -1 : state.indent * (level - 1),
|
|
3237
|
+
shiftOfContent: state.indent * Math.max(1, level),
|
|
3238
|
+
shiftOfFirstLine: level === 0 ? 0 : state.indent * level,
|
|
3239
|
+
presenterOptions: state,
|
|
3240
|
+
allowedStylesMask: 0,
|
|
3241
|
+
style: node.style
|
|
3242
|
+
};
|
|
3243
|
+
}
|
|
2816
3244
|
function writeFlowSequence(state, level, node) {
|
|
2817
3245
|
let result = "";
|
|
2818
3246
|
for (let index = 0, length = node.items.length; index < length; index += 1) {
|
|
2819
|
-
const item = writeNode(state, level, node.items[index], {});
|
|
2820
|
-
if (
|
|
3247
|
+
const item = writeNode(state, level, node.items[index], node, {}).text;
|
|
3248
|
+
if (index > 0) result += `,${!state.flowSkipCommaSpace ? " " : ""}`;
|
|
2821
3249
|
result += item;
|
|
2822
3250
|
}
|
|
2823
|
-
const pad = state.flowBracketPadding &&
|
|
3251
|
+
const pad = state.flowBracketPadding && node.items.length > 0 ? " " : "";
|
|
2824
3252
|
return `[${pad}${result}${pad}]`;
|
|
2825
3253
|
}
|
|
2826
3254
|
function writeBlockSequence(state, level, node, compact) {
|
|
2827
3255
|
let result = "";
|
|
2828
3256
|
for (let index = 0, length = node.items.length; index < length; index += 1) {
|
|
2829
|
-
const item = writeNode(state, level + 1, node.items[index], {
|
|
3257
|
+
const item = writeNode(state, level + 1, node.items[index], node, {
|
|
2830
3258
|
block: true,
|
|
2831
3259
|
compact: state.seqInlineFirst,
|
|
2832
3260
|
isblockseq: true
|
|
2833
|
-
});
|
|
3261
|
+
}).text;
|
|
2834
3262
|
if (!compact || result !== "") result += generateNextLine(state, level);
|
|
2835
3263
|
if (item === "" || CHAR_LINE_FEED === item.charCodeAt(0)) result += "-";
|
|
2836
3264
|
else result += "- ";
|
|
@@ -2840,70 +3268,51 @@ function writeBlockSequence(state, level, node, compact) {
|
|
|
2840
3268
|
}
|
|
2841
3269
|
function writeFlowMapping(state, level, node) {
|
|
2842
3270
|
let result = "";
|
|
2843
|
-
const
|
|
2844
|
-
for (const { key, value } of items) {
|
|
3271
|
+
for (const { key, value } of node.items) {
|
|
2845
3272
|
let pairBuffer = "";
|
|
2846
3273
|
if (result !== "") pairBuffer += `,${!state.flowSkipCommaSpace ? " " : ""}`;
|
|
2847
|
-
const
|
|
2848
|
-
const
|
|
2849
|
-
|
|
2850
|
-
else if (state.quoteFlowKeys) pairBuffer += "\"";
|
|
2851
|
-
const valueText = writeNode(state, level, value, {});
|
|
3274
|
+
const keyRender = writeNode(state, level, key, node, { iskey: true });
|
|
3275
|
+
const keyText = keyRender.text;
|
|
3276
|
+
const valueText = writeNode(state, level, value, node, {}).text;
|
|
2852
3277
|
const sep = state.flowSkipColonSpace || valueText === "" ? "" : " ";
|
|
2853
|
-
|
|
3278
|
+
const keyIsBareProps = key.kind === "scalar" && keyRender.noBody && (key.tagged || key.anchor !== void 0);
|
|
3279
|
+
const keyColonSep = key.kind === "alias" || keyIsBareProps ? " " : "";
|
|
3280
|
+
pairBuffer += `${keyText}${keyColonSep}:${sep}${valueText}`;
|
|
2854
3281
|
result += pairBuffer;
|
|
2855
3282
|
}
|
|
2856
3283
|
const pad = state.flowBracketPadding && result !== "" ? " " : "";
|
|
2857
3284
|
return `{${pad}${result}${pad}}`;
|
|
2858
3285
|
}
|
|
2859
|
-
function sortKeyValue(key) {
|
|
2860
|
-
return key.kind === "scalar" ? key.value : key;
|
|
2861
|
-
}
|
|
2862
|
-
function sortMappingItems(state, items) {
|
|
2863
|
-
if (!state.sortKeys) return items;
|
|
2864
|
-
const copy = items.slice();
|
|
2865
|
-
if (state.sortKeys === true) copy.sort((a, b) => {
|
|
2866
|
-
const x = sortKeyValue(a.key);
|
|
2867
|
-
const y = sortKeyValue(b.key);
|
|
2868
|
-
if (x < y) return -1;
|
|
2869
|
-
if (x > y) return 1;
|
|
2870
|
-
return 0;
|
|
2871
|
-
});
|
|
2872
|
-
else {
|
|
2873
|
-
const fn = state.sortKeys;
|
|
2874
|
-
copy.sort((a, b) => fn(sortKeyValue(a.key), sortKeyValue(b.key)));
|
|
2875
|
-
}
|
|
2876
|
-
return copy;
|
|
2877
|
-
}
|
|
2878
3286
|
function writeBlockMapping(state, level, node, compact) {
|
|
2879
3287
|
let result = "";
|
|
2880
|
-
|
|
2881
|
-
for (let index = 0, length = items.length; index < length; index += 1) {
|
|
3288
|
+
for (let index = 0, length = node.items.length; index < length; index += 1) {
|
|
2882
3289
|
let pairBuffer = "";
|
|
2883
3290
|
if (!compact || result !== "") pairBuffer += generateNextLine(state, level);
|
|
2884
|
-
const { key, value } = items[index];
|
|
2885
|
-
const keyIsBlock = (key.kind === "mapping" || key.kind === "sequence") &&
|
|
2886
|
-
const
|
|
3291
|
+
const { key, value } = node.items[index];
|
|
3292
|
+
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);
|
|
3293
|
+
const keyRender = keyIsBlock ? writeNode(state, level + 1, key, node, {
|
|
2887
3294
|
block: true,
|
|
2888
3295
|
compact: true,
|
|
2889
3296
|
isblockseq: !cannotBeCompact(state, key, level + 1)
|
|
2890
|
-
}) : writeNode(state, level + 1, key, {
|
|
3297
|
+
}) : writeNode(state, level + 1, key, node, {
|
|
2891
3298
|
block: true,
|
|
2892
3299
|
compact: true,
|
|
2893
3300
|
iskey: true
|
|
2894
3301
|
});
|
|
3302
|
+
const keyText = keyRender.text;
|
|
2895
3303
|
const keyHasLineBreak = key.kind === "scalar" && key.value.indexOf("\n") !== -1;
|
|
2896
|
-
const
|
|
3304
|
+
const keyIsTooLong = keyText.length > 1024 && /^[\s\S]{1025}/u.test(keyText);
|
|
3305
|
+
const explicitPair = keyIsBlock || keyHasLineBreak || keyIsTooLong;
|
|
2897
3306
|
if (explicitPair) if (keyText && CHAR_LINE_FEED === keyText.charCodeAt(0)) pairBuffer += "?";
|
|
2898
3307
|
else pairBuffer += "? ";
|
|
2899
3308
|
pairBuffer += keyText;
|
|
2900
3309
|
if (explicitPair) pairBuffer += generateNextLine(state, level);
|
|
2901
|
-
const valueText = writeNode(state, level + 1, value, {
|
|
3310
|
+
const valueText = writeNode(state, level + 1, value, node, {
|
|
2902
3311
|
block: true,
|
|
2903
3312
|
compact: explicitPair,
|
|
2904
3313
|
isblockseq: explicitPair && !cannotBeCompact(state, value, level + 1)
|
|
2905
|
-
});
|
|
2906
|
-
const keyIsBareProps = key.kind === "scalar" &&
|
|
3314
|
+
}).text;
|
|
3315
|
+
const keyIsBareProps = key.kind === "scalar" && keyRender.noBody && (key.tagged || key.anchor !== void 0);
|
|
2907
3316
|
const keyColonSep = !explicitPair && (key.kind === "alias" || keyIsBareProps) ? " " : "";
|
|
2908
3317
|
if (valueText === "" || CHAR_LINE_FEED === valueText.charCodeAt(0)) pairBuffer += `${keyColonSep}:`;
|
|
2909
3318
|
else pairBuffer += `${keyColonSep}: `;
|
|
@@ -2913,30 +3322,42 @@ function writeBlockMapping(state, level, node, compact) {
|
|
|
2913
3322
|
return result;
|
|
2914
3323
|
}
|
|
2915
3324
|
function cannotBeCompact(state, node, level) {
|
|
2916
|
-
|
|
3325
|
+
if (node.kind === "alias") return true;
|
|
3326
|
+
return node.tagged || node.anchor !== void 0 || state.indent < 2 && level > 0;
|
|
2917
3327
|
}
|
|
2918
|
-
function writeNode(state, level, node, ctx) {
|
|
3328
|
+
function writeNode(state, level, node, parent, ctx) {
|
|
2919
3329
|
var _ctx$compact;
|
|
2920
|
-
if (node.kind === "alias")
|
|
3330
|
+
if (node.kind === "alias") {
|
|
3331
|
+
state.openEnded = false;
|
|
3332
|
+
return {
|
|
3333
|
+
text: `*${node.anchor}`,
|
|
3334
|
+
noBody: false
|
|
3335
|
+
};
|
|
3336
|
+
}
|
|
2921
3337
|
const { block = false, iskey = false, isblockseq = false } = ctx;
|
|
2922
3338
|
let compact = (_ctx$compact = ctx.compact) !== null && _ctx$compact !== void 0 ? _ctx$compact : false;
|
|
2923
3339
|
const hasAnchor = node.anchor !== void 0;
|
|
2924
3340
|
if (cannotBeCompact(state, node, level)) compact = false;
|
|
2925
3341
|
let body;
|
|
2926
|
-
let shouldPrintTag = node.
|
|
2927
|
-
const useBlockCollection = block && (node.kind === "mapping" || node.kind === "sequence") &&
|
|
3342
|
+
let shouldPrintTag = node.tagged;
|
|
3343
|
+
const useBlockCollection = block && (node.kind === "mapping" || node.kind === "sequence") && node.style === COLLECTION_STYLE.BLOCK && node.items.length !== 0;
|
|
2928
3344
|
if (node.kind === "mapping") if (useBlockCollection) body = writeBlockMapping(state, level, node, compact);
|
|
2929
3345
|
else body = writeFlowMapping(state, level, node);
|
|
2930
3346
|
else if (node.kind === "sequence") if (useBlockCollection) if (state.seqNoIndent && !isblockseq && level > 0) body = writeBlockSequence(state, level - 1, node, compact);
|
|
2931
3347
|
else body = writeBlockSequence(state, level, node, compact);
|
|
2932
3348
|
else body = writeFlowSequence(state, level, node);
|
|
2933
3349
|
else {
|
|
2934
|
-
const layout = scalarLayout(state, level);
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
3350
|
+
const layout = scalarLayout(state, node, parent, level, iskey, !block);
|
|
3351
|
+
detectAllowedStyles(layout);
|
|
3352
|
+
for (const rule of state.scalarStyleRules) rule(layout);
|
|
3353
|
+
body = renderScalar(layout);
|
|
3354
|
+
state.openEnded = (layout.style === SCALAR_STYLE.LITERAL_BLOCK || layout.style === SCALAR_STYLE.FOLDED_BLOCK) && (node.value === "\n" || node.value.endsWith("\n\n"));
|
|
3355
|
+
shouldPrintTag = node.tagged || body === "" && layout.flowOnly && (parent === null || parent === void 0 ? void 0 : parent.kind) === "sequence" && !hasAnchor || layout.style !== SCALAR_STYLE.PLAIN && node.tag !== state.defaultScalarTagName;
|
|
3356
|
+
}
|
|
3357
|
+
if ((node.kind === "mapping" || node.kind === "sequence") && !useBlockCollection) state.openEnded = false;
|
|
2939
3358
|
if (useBlockCollection && compact && level > 0 && state.indent > 2) body = `${" ".repeat(state.indent - 2)}${body}`;
|
|
3359
|
+
const noBody = body === "";
|
|
3360
|
+
let text = body;
|
|
2940
3361
|
if (shouldPrintTag || hasAnchor) {
|
|
2941
3362
|
const props = [];
|
|
2942
3363
|
const tag = shouldPrintTag ? nodeTagShort(node) : null;
|
|
@@ -2949,19 +3370,15 @@ function writeNode(state, level, node, ctx) {
|
|
|
2949
3370
|
if (tag !== null) props.push(tag);
|
|
2950
3371
|
}
|
|
2951
3372
|
const sep = body === "" || body.charCodeAt(0) === CHAR_LINE_FEED ? "" : " ";
|
|
2952
|
-
|
|
3373
|
+
text = `${props.join(" ")}${sep}${body}`;
|
|
2953
3374
|
}
|
|
2954
|
-
return
|
|
3375
|
+
return {
|
|
3376
|
+
text,
|
|
3377
|
+
noBody
|
|
3378
|
+
};
|
|
2955
3379
|
}
|
|
2956
3380
|
function rootStartsOwnLine(node) {
|
|
2957
|
-
return (node.kind === "sequence" || node.kind === "mapping") &&
|
|
2958
|
-
}
|
|
2959
|
-
function isOpenEnded(node) {
|
|
2960
|
-
let leaf = node;
|
|
2961
|
-
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;
|
|
2962
|
-
if (leaf.kind !== "scalar" || !(leaf.style.literal || leaf.style.folded)) return false;
|
|
2963
|
-
const { value } = leaf;
|
|
2964
|
-
return value.endsWith("\n\n") || value === "\n";
|
|
3381
|
+
return (node.kind === "sequence" || node.kind === "mapping") && node.style === COLLECTION_STYLE.BLOCK && node.items.length !== 0 && !node.tagged && node.anchor === void 0;
|
|
2965
3382
|
}
|
|
2966
3383
|
function writeDocumentDirectives(doc) {
|
|
2967
3384
|
let result = "";
|
|
@@ -2975,12 +3392,18 @@ function writeDocumentDirectives(doc) {
|
|
|
2975
3392
|
}
|
|
2976
3393
|
return result;
|
|
2977
3394
|
}
|
|
3395
|
+
/**
|
|
3396
|
+
* Build YAML from AST.
|
|
3397
|
+
*
|
|
3398
|
+
* @category AST
|
|
3399
|
+
*/
|
|
2978
3400
|
function present(documents, options) {
|
|
2979
3401
|
const state = createPresenterState(options);
|
|
2980
3402
|
let result = "";
|
|
2981
3403
|
let previousEnded = false;
|
|
2982
3404
|
for (let index = 0; index < documents.length; index += 1) {
|
|
2983
3405
|
const doc = documents[index];
|
|
3406
|
+
state.openEnded = false;
|
|
2984
3407
|
const directives = writeDocumentDirectives(doc);
|
|
2985
3408
|
const hasDirectives = directives !== "";
|
|
2986
3409
|
const marker = doc.explicitStart || hasDirectives || index > 0 && !previousEnded;
|
|
@@ -2988,37 +3411,46 @@ function present(documents, options) {
|
|
|
2988
3411
|
if (doc.contents === null) {
|
|
2989
3412
|
if (marker) result += "---\n";
|
|
2990
3413
|
} else if (marker) {
|
|
2991
|
-
const body = writeNode(state, 0, doc.contents, {
|
|
3414
|
+
const body = writeNode(state, 0, doc.contents, null, {
|
|
2992
3415
|
block: true,
|
|
2993
3416
|
compact: true
|
|
2994
|
-
});
|
|
3417
|
+
}).text;
|
|
2995
3418
|
const sep = body === "" ? "" : hasDirectives || rootStartsOwnLine(doc.contents) ? "\n" : " ";
|
|
2996
3419
|
result += `---${sep}${body}\n`;
|
|
2997
|
-
} else result += writeNode(state, 0, doc.contents, {
|
|
3420
|
+
} else result += writeNode(state, 0, doc.contents, null, {
|
|
2998
3421
|
block: true,
|
|
2999
3422
|
compact: true
|
|
3000
|
-
}) + "\n";
|
|
3001
|
-
previousEnded = doc.explicitEnd ||
|
|
3423
|
+
}).text + "\n";
|
|
3424
|
+
previousEnded = doc.explicitEnd || state.openEnded;
|
|
3002
3425
|
if (previousEnded) result += "...\n";
|
|
3003
3426
|
}
|
|
3004
3427
|
return result;
|
|
3005
3428
|
}
|
|
3006
3429
|
//#endregion
|
|
3007
3430
|
//#region src/dump.ts
|
|
3008
|
-
var DEFAULT_DUMP_SCHEMA = YAML11_SCHEMA.withTags(_objectSpread2(_objectSpread2({}, intYaml11Tag), {}, { resolve: (source, isExplicit, tagName) => {
|
|
3009
|
-
const result = intYaml11Tag.resolve(source, isExplicit, tagName);
|
|
3010
|
-
return result === NOT_RESOLVED ? intCoreTag.resolve(source, isExplicit, tagName) : result;
|
|
3011
|
-
} }), _objectSpread2(_objectSpread2({}, floatYaml11Tag), {}, { resolve: (source, isExplicit, tagName) => {
|
|
3012
|
-
const result = floatYaml11Tag.resolve(source, isExplicit, tagName);
|
|
3013
|
-
return result === NOT_RESOLVED ? floatCoreTag.resolve(source, isExplicit, tagName) : result;
|
|
3014
|
-
} }));
|
|
3015
3431
|
var DEFAULT_DUMP_OPTIONS = _objectSpread2(_objectSpread2({}, DEFAULT_PRESENTER_OPTIONS), {}, {
|
|
3016
|
-
schema:
|
|
3432
|
+
schema: DUMP_SCHEMA,
|
|
3017
3433
|
skipInvalid: false,
|
|
3018
3434
|
noRefs: false,
|
|
3019
3435
|
flowLevel: -1,
|
|
3436
|
+
sortKeys: false,
|
|
3020
3437
|
transform: () => {}
|
|
3021
3438
|
});
|
|
3439
|
+
function defaultCompareFn(a, b) {
|
|
3440
|
+
const x = String(a);
|
|
3441
|
+
const y = String(b);
|
|
3442
|
+
if (x < y) return -1;
|
|
3443
|
+
if (x > y) return 1;
|
|
3444
|
+
return 0;
|
|
3445
|
+
}
|
|
3446
|
+
/**
|
|
3447
|
+
* Serializes JS object as a YAML document. By default it can dump every
|
|
3448
|
+
* supported YAML type, so it throws an exception if you try to dump regexps or
|
|
3449
|
+
* functions. However, you can disable exceptions by setting the
|
|
3450
|
+
* {@link DumpOptions.skipInvalid} option to `true`.
|
|
3451
|
+
*
|
|
3452
|
+
* @category Main
|
|
3453
|
+
*/
|
|
3022
3454
|
function dump(input, options = {}) {
|
|
3023
3455
|
const opts = _objectSpread2(_objectSpread2({}, DEFAULT_DUMP_OPTIONS), options);
|
|
3024
3456
|
const documents = jsToAst(input, opts.schema, {
|
|
@@ -3027,9 +3459,16 @@ function dump(input, options = {}) {
|
|
|
3027
3459
|
});
|
|
3028
3460
|
if (opts.flowLevel >= 0) visit(documents, (node, ctx) => {
|
|
3029
3461
|
if (ctx.depth < opts.flowLevel) return;
|
|
3030
|
-
node.
|
|
3462
|
+
if (node.kind === "sequence" || node.kind === "mapping") node.style = COLLECTION_STYLE.FLOW;
|
|
3031
3463
|
return VISIT_SKIP;
|
|
3032
3464
|
});
|
|
3465
|
+
if (opts.sortKeys) {
|
|
3466
|
+
const compareFn = opts.sortKeys === true ? defaultCompareFn : opts.sortKeys;
|
|
3467
|
+
visit(documents, (node) => {
|
|
3468
|
+
if (node.kind !== "mapping") return;
|
|
3469
|
+
node.items.sort((a, b) => compareFn(a.key.kind === "scalar" ? a.key.value : "", b.key.kind === "scalar" ? b.key.value : ""));
|
|
3470
|
+
});
|
|
3471
|
+
}
|
|
3033
3472
|
opts.transform(documents);
|
|
3034
3473
|
return present(documents, _objectSpread2(_objectSpread2({}, pick(opts, Object.keys(DEFAULT_PRESENTER_OPTIONS))), {}, { schema: opts.schema }));
|
|
3035
3474
|
}
|
|
@@ -3049,58 +3488,38 @@ function rawTag(state, event) {
|
|
|
3049
3488
|
function anchorName(state, event) {
|
|
3050
3489
|
return event.anchorStart === NO_RANGE ? void 0 : state.source.slice(event.anchorStart, event.anchorEnd);
|
|
3051
3490
|
}
|
|
3052
|
-
function implicitScalarTagName(state, source) {
|
|
3053
|
-
var _schema$implicitScala;
|
|
3054
|
-
const { schema } = state;
|
|
3055
|
-
const candidates = (_schema$implicitScala = schema.implicitScalarByFirstChar.get(source.charAt(0))) !== null && _schema$implicitScala !== void 0 ? _schema$implicitScala : schema.implicitScalarAnyFirstChar;
|
|
3056
|
-
for (const tag of candidates) if (tag.resolve(source, false, tag.tagName) !== NOT_RESOLVED) return tag.tagName;
|
|
3057
|
-
return schema.defaultScalarTag.tagName;
|
|
3058
|
-
}
|
|
3059
3491
|
function buildScalar(state, event) {
|
|
3060
3492
|
const value = getScalarValue(state.source, event);
|
|
3061
3493
|
const raw = rawTag(state, event);
|
|
3062
|
-
const style = new Style();
|
|
3063
|
-
switch (event.style) {
|
|
3064
|
-
case 2:
|
|
3065
|
-
style.singleQuoted = true;
|
|
3066
|
-
break;
|
|
3067
|
-
case 3:
|
|
3068
|
-
style.doubleQuoted = true;
|
|
3069
|
-
break;
|
|
3070
|
-
case 4:
|
|
3071
|
-
style.literal = true;
|
|
3072
|
-
break;
|
|
3073
|
-
case 5:
|
|
3074
|
-
style.folded = true;
|
|
3075
|
-
break;
|
|
3076
|
-
}
|
|
3077
3494
|
let tag;
|
|
3495
|
+
let tagged = false;
|
|
3078
3496
|
if (raw !== "") {
|
|
3079
|
-
|
|
3497
|
+
tagged = true;
|
|
3080
3498
|
tag = raw;
|
|
3081
|
-
} else if (event.style ===
|
|
3499
|
+
} else if (event.style === SCALAR_STYLE.PLAIN) tag = state.schema.resolveImplicitScalarTag(value).tag.tagName;
|
|
3082
3500
|
else tag = state.schema.defaultScalarTag.tagName;
|
|
3083
3501
|
return {
|
|
3084
3502
|
kind: "scalar",
|
|
3085
3503
|
tag,
|
|
3086
|
-
|
|
3504
|
+
tagged,
|
|
3505
|
+
style: event.style,
|
|
3087
3506
|
anchor: anchorName(state, event),
|
|
3088
3507
|
value
|
|
3089
3508
|
};
|
|
3090
3509
|
}
|
|
3091
3510
|
function buildCollection(state, event, defaultTagName) {
|
|
3092
3511
|
const raw = rawTag(state, event);
|
|
3093
|
-
const style = new Style();
|
|
3094
|
-
if (event.style === 2) style.flow = true;
|
|
3095
3512
|
let tag;
|
|
3513
|
+
let tagged = false;
|
|
3096
3514
|
if (raw === "") tag = defaultTagName;
|
|
3097
3515
|
else {
|
|
3098
3516
|
tag = raw;
|
|
3099
|
-
|
|
3517
|
+
tagged = true;
|
|
3100
3518
|
}
|
|
3101
3519
|
return {
|
|
3102
3520
|
tag,
|
|
3103
|
-
|
|
3521
|
+
tagged,
|
|
3522
|
+
style: event.style,
|
|
3104
3523
|
anchor: anchorName(state, event)
|
|
3105
3524
|
};
|
|
3106
3525
|
}
|
|
@@ -3116,6 +3535,11 @@ function addNode(state, node) {
|
|
|
3116
3535
|
frame.key = null;
|
|
3117
3536
|
} else frame.key = node;
|
|
3118
3537
|
}
|
|
3538
|
+
/**
|
|
3539
|
+
* Builds an AST from parser events
|
|
3540
|
+
*
|
|
3541
|
+
* @category AST
|
|
3542
|
+
*/
|
|
3119
3543
|
function eventsToAst(events, options) {
|
|
3120
3544
|
const state = {
|
|
3121
3545
|
source: options.source,
|
|
@@ -3129,7 +3553,7 @@ function eventsToAst(events, options) {
|
|
|
3129
3553
|
const event = events[state.eventIndex++];
|
|
3130
3554
|
state.position = eventPosition(event);
|
|
3131
3555
|
switch (event.type) {
|
|
3132
|
-
case
|
|
3556
|
+
case EVENT_ID.DOCUMENT: {
|
|
3133
3557
|
const doc = {
|
|
3134
3558
|
contents: null,
|
|
3135
3559
|
explicitStart: event.explicitStart,
|
|
@@ -3142,14 +3566,15 @@ function eventsToAst(events, options) {
|
|
|
3142
3566
|
});
|
|
3143
3567
|
break;
|
|
3144
3568
|
}
|
|
3145
|
-
case
|
|
3569
|
+
case EVENT_ID.SCALAR:
|
|
3146
3570
|
addNode(state, buildScalar(state, event));
|
|
3147
3571
|
break;
|
|
3148
|
-
case
|
|
3149
|
-
const { tag, style, anchor } = buildCollection(state, event, "tag:yaml.org,2002:seq");
|
|
3572
|
+
case EVENT_ID.SEQUENCE: {
|
|
3573
|
+
const { tag, tagged, style, anchor } = buildCollection(state, event, "tag:yaml.org,2002:seq");
|
|
3150
3574
|
const node = {
|
|
3151
3575
|
kind: "sequence",
|
|
3152
3576
|
tag,
|
|
3577
|
+
tagged,
|
|
3153
3578
|
style,
|
|
3154
3579
|
anchor,
|
|
3155
3580
|
items: []
|
|
@@ -3160,11 +3585,12 @@ function eventsToAst(events, options) {
|
|
|
3160
3585
|
});
|
|
3161
3586
|
break;
|
|
3162
3587
|
}
|
|
3163
|
-
case
|
|
3164
|
-
const { tag, style, anchor } = buildCollection(state, event, "tag:yaml.org,2002:map");
|
|
3588
|
+
case EVENT_ID.MAPPING: {
|
|
3589
|
+
const { tag, tagged, style, anchor } = buildCollection(state, event, "tag:yaml.org,2002:map");
|
|
3165
3590
|
const node = {
|
|
3166
3591
|
kind: "mapping",
|
|
3167
3592
|
tag,
|
|
3593
|
+
tagged,
|
|
3168
3594
|
style,
|
|
3169
3595
|
anchor,
|
|
3170
3596
|
items: []
|
|
@@ -3176,17 +3602,13 @@ function eventsToAst(events, options) {
|
|
|
3176
3602
|
});
|
|
3177
3603
|
break;
|
|
3178
3604
|
}
|
|
3179
|
-
case
|
|
3180
|
-
const name = state.source.slice(event.anchorStart, event.anchorEnd);
|
|
3605
|
+
case EVENT_ID.ALIAS:
|
|
3181
3606
|
addNode(state, {
|
|
3182
3607
|
kind: "alias",
|
|
3183
|
-
|
|
3184
|
-
style: new Style(),
|
|
3185
|
-
anchor: name
|
|
3608
|
+
anchor: state.source.slice(event.anchorStart, event.anchorEnd)
|
|
3186
3609
|
});
|
|
3187
3610
|
break;
|
|
3188
|
-
|
|
3189
|
-
case 6: {
|
|
3611
|
+
case EVENT_ID.POP: {
|
|
3190
3612
|
const frame = state.frames.pop();
|
|
3191
3613
|
if (frame.kind === "mapping" && frame.key) throw new Error("incomplete mapping pair in event stream");
|
|
3192
3614
|
if (frame.kind === "document") state.documents.push(frame.doc);
|
|
@@ -3198,29 +3620,67 @@ function eventsToAst(events, options) {
|
|
|
3198
3620
|
return state.documents;
|
|
3199
3621
|
}
|
|
3200
3622
|
//#endregion
|
|
3623
|
+
//#region src/index.ts
|
|
3624
|
+
/** @deprecated Use `EVENT_ID.DOCUMENT` instead. @internal */
|
|
3625
|
+
var EVENT_DOCUMENT = EVENT_ID.DOCUMENT;
|
|
3626
|
+
/** @deprecated Use `EVENT_ID.SEQUENCE` instead. @internal */
|
|
3627
|
+
var EVENT_SEQUENCE = EVENT_ID.SEQUENCE;
|
|
3628
|
+
/** @deprecated Use `EVENT_ID.MAPPING` instead. @internal */
|
|
3629
|
+
var EVENT_MAPPING = EVENT_ID.MAPPING;
|
|
3630
|
+
/** @deprecated Use `EVENT_ID.SCALAR` instead. @internal */
|
|
3631
|
+
var EVENT_SCALAR = EVENT_ID.SCALAR;
|
|
3632
|
+
/** @deprecated Use `EVENT_ID.ALIAS` instead. @internal */
|
|
3633
|
+
var EVENT_ALIAS = EVENT_ID.ALIAS;
|
|
3634
|
+
/** @deprecated Use `EVENT_ID.POP` instead. @internal */
|
|
3635
|
+
var EVENT_POP = EVENT_ID.POP;
|
|
3636
|
+
/** @deprecated Use `SCALAR_STYLE.PLAIN` instead. @internal */
|
|
3637
|
+
var SCALAR_STYLE_PLAIN = SCALAR_STYLE.PLAIN;
|
|
3638
|
+
/** @deprecated Use `SCALAR_STYLE.SINGLE_QUOTED` instead. @internal */
|
|
3639
|
+
var SCALAR_STYLE_SINGLE_QUOTED = SCALAR_STYLE.SINGLE_QUOTED;
|
|
3640
|
+
/** @deprecated Use `SCALAR_STYLE.DOUBLE_QUOTED` instead. @internal */
|
|
3641
|
+
var SCALAR_STYLE_DOUBLE_QUOTED = SCALAR_STYLE.DOUBLE_QUOTED;
|
|
3642
|
+
/** @deprecated Use `SCALAR_STYLE.LITERAL_BLOCK` instead. @internal */
|
|
3643
|
+
var SCALAR_STYLE_LITERAL_BLOCK = SCALAR_STYLE.LITERAL_BLOCK;
|
|
3644
|
+
/** @deprecated Use `SCALAR_STYLE.FOLDED_BLOCK` instead. @internal */
|
|
3645
|
+
var SCALAR_STYLE_FOLDED_BLOCK = SCALAR_STYLE.FOLDED_BLOCK;
|
|
3646
|
+
/** @deprecated Use `COLLECTION_STYLE.BLOCK` instead. @internal */
|
|
3647
|
+
var COLLECTION_STYLE_BLOCK = COLLECTION_STYLE.BLOCK;
|
|
3648
|
+
/** @deprecated Use `COLLECTION_STYLE.FLOW` instead. @internal */
|
|
3649
|
+
var COLLECTION_STYLE_FLOW = COLLECTION_STYLE.FLOW;
|
|
3650
|
+
/** @deprecated Use `CHOMPING_MODE.CLIP` instead. @internal */
|
|
3651
|
+
var CHOMPING_CLIP = CHOMPING_MODE.CLIP;
|
|
3652
|
+
/** @deprecated Use `CHOMPING_MODE.STRIP` instead. @internal */
|
|
3653
|
+
var CHOMPING_STRIP = CHOMPING_MODE.STRIP;
|
|
3654
|
+
/** @deprecated Use `CHOMPING_MODE.KEEP` instead. @internal */
|
|
3655
|
+
var CHOMPING_KEEP = CHOMPING_MODE.KEEP;
|
|
3656
|
+
//#endregion
|
|
3201
3657
|
exports.CHOMPING_CLIP = CHOMPING_CLIP;
|
|
3202
3658
|
exports.CHOMPING_KEEP = CHOMPING_KEEP;
|
|
3659
|
+
exports.CHOMPING_MODE = CHOMPING_MODE;
|
|
3203
3660
|
exports.CHOMPING_STRIP = CHOMPING_STRIP;
|
|
3661
|
+
exports.COLLECTION_STYLE = COLLECTION_STYLE;
|
|
3204
3662
|
exports.COLLECTION_STYLE_BLOCK = COLLECTION_STYLE_BLOCK;
|
|
3205
3663
|
exports.COLLECTION_STYLE_FLOW = COLLECTION_STYLE_FLOW;
|
|
3206
3664
|
exports.CORE_SCHEMA = CORE_SCHEMA;
|
|
3665
|
+
exports.DEFAULT_SCALAR_STYLE_RULES = DEFAULT_SCALAR_STYLE_RULES;
|
|
3666
|
+
exports.DUMP_SCHEMA = DUMP_SCHEMA;
|
|
3207
3667
|
exports.EVENT_ALIAS = EVENT_ALIAS;
|
|
3208
3668
|
exports.EVENT_DOCUMENT = EVENT_DOCUMENT;
|
|
3669
|
+
exports.EVENT_ID = EVENT_ID;
|
|
3209
3670
|
exports.EVENT_MAPPING = EVENT_MAPPING;
|
|
3210
3671
|
exports.EVENT_POP = EVENT_POP;
|
|
3211
3672
|
exports.EVENT_SCALAR = EVENT_SCALAR;
|
|
3212
3673
|
exports.EVENT_SEQUENCE = EVENT_SEQUENCE;
|
|
3213
3674
|
exports.FAILSAFE_SCHEMA = FAILSAFE_SCHEMA;
|
|
3214
3675
|
exports.JSON_SCHEMA = JSON_SCHEMA;
|
|
3215
|
-
exports.MERGE_KEY = MERGE_KEY;
|
|
3216
3676
|
exports.NOT_RESOLVED = NOT_RESOLVED;
|
|
3677
|
+
exports.SCALAR_STYLE = SCALAR_STYLE;
|
|
3217
3678
|
exports.SCALAR_STYLE_DOUBLE_QUOTED = SCALAR_STYLE_DOUBLE_QUOTED;
|
|
3218
3679
|
exports.SCALAR_STYLE_FOLDED_BLOCK = SCALAR_STYLE_FOLDED_BLOCK;
|
|
3219
3680
|
exports.SCALAR_STYLE_LITERAL_BLOCK = SCALAR_STYLE_LITERAL_BLOCK;
|
|
3220
3681
|
exports.SCALAR_STYLE_PLAIN = SCALAR_STYLE_PLAIN;
|
|
3221
3682
|
exports.SCALAR_STYLE_SINGLE_QUOTED = SCALAR_STYLE_SINGLE_QUOTED;
|
|
3222
3683
|
exports.Schema = Schema;
|
|
3223
|
-
exports.Style = Style;
|
|
3224
3684
|
exports.VISIT_BREAK = VISIT_BREAK;
|
|
3225
3685
|
exports.VISIT_SKIP = VISIT_SKIP;
|
|
3226
3686
|
exports.YAML11_SCHEMA = YAML11_SCHEMA;
|