yaml 3.0.0-1 → 3.0.0-2
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/dist/cli.js +2 -2
- package/dist/{directives-DlYEVlkC.d.ts → directives-CGITitH5.d.ts} +568 -587
- package/dist/{directives-CiM56lHW.js → directives-DqP9ea45.js} +374 -239
- package/dist/index.d.ts +179 -174
- package/dist/index.js +3 -3
- package/dist/{line-counter-bmCJ4fGy.js → line-counter-B2FjSv3E.js} +272 -210
- package/dist/{public-api-BTMehGT6.js → public-api-uicovB0N.js} +6 -4
- package/dist/test-events.js +2 -2
- package/dist/util.d.ts +2 -2
- package/dist/util.js +1 -1
- package/package.json +6 -6
- /package/dist/{chunk-pbuEa-1d.js → rolldown-runtime-D7D4PA-g.js} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as __exportAll } from "./
|
|
2
|
-
import { S as Scalar,
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
|
|
2
|
+
import { S as Scalar, _ as YAMLMap, b as stringifyString, f as Pair, g as YAMLSeq, h as YAMLSet, i as Document, m as isNode, p as isCollection$1, t as Directives, u as Alias } from "./directives-DqP9ea45.js";
|
|
3
3
|
//#region src/compose/resolve-block-scalar.ts
|
|
4
4
|
function resolveBlockScalar(ctx, scalar, onError) {
|
|
5
5
|
const start = scalar.offset;
|
|
@@ -78,9 +78,10 @@ function resolveBlockScalar(ctx, scalar, onError) {
|
|
|
78
78
|
value += sep + indent.slice(trimIndent) + content;
|
|
79
79
|
sep = "\n";
|
|
80
80
|
prevMoreIndented = true;
|
|
81
|
-
} else if (content === "")
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
} else if (content === "") {
|
|
82
|
+
if (sep === "\n") value += "\n";
|
|
83
|
+
else sep = "\n";
|
|
84
|
+
} else {
|
|
84
85
|
value += sep + content;
|
|
85
86
|
sep = " ";
|
|
86
87
|
prevMoreIndented = false;
|
|
@@ -271,9 +272,7 @@ function plainValue(source, onError) {
|
|
|
271
272
|
badChar = `block scalar indicator ${source[0]}`;
|
|
272
273
|
break;
|
|
273
274
|
case "@":
|
|
274
|
-
case "`":
|
|
275
|
-
badChar = `reserved character ${source[0]}`;
|
|
276
|
-
break;
|
|
275
|
+
case "`": badChar = `reserved character ${source[0]}`;
|
|
277
276
|
}
|
|
278
277
|
if (badChar) onError(0, "BAD_SCALAR_START", `Plain value cannot start with ${badChar}`);
|
|
279
278
|
return foldLines(source);
|
|
@@ -282,41 +281,40 @@ function singleQuotedValue(source, onError) {
|
|
|
282
281
|
if (source[source.length - 1] !== "'" || source.length === 1) onError(source.length, "MISSING_CHAR", "Missing closing 'quote");
|
|
283
282
|
return foldLines(source.slice(1, -1)).replace(/''/g, "'");
|
|
284
283
|
}
|
|
284
|
+
const CHAR_CR$1 = 13;
|
|
285
|
+
const CHAR_SPACE$1 = 32;
|
|
286
|
+
const CHAR_TAB$1 = 9;
|
|
285
287
|
function foldLines(source) {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
let first, line;
|
|
294
|
-
try {
|
|
295
|
-
first = /* @__PURE__ */ new RegExp("(.*?)(?<![ ])[ ]*\r?\n", "sy");
|
|
296
|
-
line = /* @__PURE__ */ new RegExp("[ ]*(.*?)(?:(?<![ ])[ ]*)?\r?\n", "sy");
|
|
297
|
-
} catch {
|
|
298
|
-
first = /(.*?)[ \t]*\r?\n/sy;
|
|
299
|
-
line = /[ \t]*(.*?)[ \t]*\r?\n/sy;
|
|
300
|
-
}
|
|
301
|
-
let match = first.exec(source);
|
|
302
|
-
if (!match) return source;
|
|
303
|
-
let res = match[1];
|
|
288
|
+
let newLineIndex = source.indexOf("\n");
|
|
289
|
+
if (newLineIndex === -1) return source;
|
|
290
|
+
let end = newLineIndex;
|
|
291
|
+
let cc = source.charCodeAt(end - 1);
|
|
292
|
+
if (cc === CHAR_CR$1) cc = source.charCodeAt(--end - 1);
|
|
293
|
+
while (end > 0 && (cc === CHAR_SPACE$1 || cc === CHAR_TAB$1)) cc = source.charCodeAt(--end - 1);
|
|
294
|
+
let res = source.slice(0, end);
|
|
304
295
|
let sep = " ";
|
|
305
|
-
let pos =
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
296
|
+
let pos = newLineIndex + 1;
|
|
297
|
+
while ((newLineIndex = source.indexOf("\n", pos)) !== -1) {
|
|
298
|
+
let start = pos;
|
|
299
|
+
cc = source.charCodeAt(start);
|
|
300
|
+
while (start < newLineIndex && (cc === CHAR_SPACE$1 || cc === CHAR_TAB$1)) cc = source.charCodeAt(++start);
|
|
301
|
+
end = newLineIndex;
|
|
302
|
+
cc = source.charCodeAt(end - 1);
|
|
303
|
+
if (cc === CHAR_CR$1) cc = source.charCodeAt(--end - 1);
|
|
304
|
+
while (end > start && (cc === CHAR_SPACE$1 || cc === CHAR_TAB$1)) cc = source.charCodeAt(--end - 1);
|
|
305
|
+
if (start === end) {
|
|
306
|
+
if (sep === "\n") res += sep;
|
|
307
|
+
else sep = "\n";
|
|
308
|
+
} else {
|
|
309
|
+
res += sep + source.slice(start, end);
|
|
312
310
|
sep = " ";
|
|
313
311
|
}
|
|
314
|
-
pos =
|
|
312
|
+
pos = newLineIndex + 1;
|
|
315
313
|
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
return res + sep + (
|
|
314
|
+
let start = pos;
|
|
315
|
+
cc = source.charCodeAt(start);
|
|
316
|
+
while (start < source.length && (cc === CHAR_SPACE$1 || cc === CHAR_TAB$1)) cc = source.charCodeAt(++start);
|
|
317
|
+
return res + sep + source.slice(start);
|
|
320
318
|
}
|
|
321
319
|
function doubleQuotedValue(source, onError) {
|
|
322
320
|
let res = "";
|
|
@@ -923,12 +921,26 @@ function isEmpty(ch) {
|
|
|
923
921
|
default: return false;
|
|
924
922
|
}
|
|
925
923
|
}
|
|
926
|
-
const
|
|
924
|
+
const CHAR_TAB = 9;
|
|
925
|
+
const CHAR_LF = 10;
|
|
926
|
+
const CHAR_CR = 13;
|
|
927
|
+
const CHAR_SPACE = 32;
|
|
928
|
+
const CHAR_HASH = 35;
|
|
929
|
+
const CHAR_COLON = 58;
|
|
930
|
+
function isEmptyChar(ch) {
|
|
931
|
+
return Number.isNaN(ch) || ch === CHAR_SPACE || ch === CHAR_LF || ch === CHAR_CR || ch === CHAR_TAB;
|
|
932
|
+
}
|
|
933
|
+
const flowIndicatorCharCodes = /* @__PURE__ */ new Set([
|
|
934
|
+
44,
|
|
935
|
+
91,
|
|
936
|
+
93,
|
|
937
|
+
123,
|
|
938
|
+
125
|
|
939
|
+
]);
|
|
927
940
|
const invalidAnchorChars = /* @__PURE__ */ new Set(" ,[]{}\n\r ");
|
|
928
941
|
const isNotAnchorChar = (ch) => !ch || invalidAnchorChars.has(ch);
|
|
929
942
|
const blockScalarHeader = /([|>][^\s#]*)([ \t]*)((?:.|\r(?!\n))*)$/my;
|
|
930
|
-
const
|
|
931
|
-
const directiveLine = /(%.*?)(?:([ \t]+)(#.*)?)?$/my;
|
|
943
|
+
const directiveLine = /(%(?:[^ \t\n\r]|[ \t](?![\n\r#]))*)([ \t]*)(#.*)?$/my;
|
|
932
944
|
const docMarker = /[-.]{3}(?=[ \n\r\t]|$)(?:([ \t]+)(#.*)?)?/y;
|
|
933
945
|
const emptyLineOrComment = /([ \t]*)(#.*)?$/my;
|
|
934
946
|
const indicator = /(?:(&[^\s,[\]{}]*|!<[^\s>]*>?|!(?:[0-9a-z-#;/?:@&=+$_.!~*'()]|%[0-9a-f]{2})*)|([-?:])(?=[ \n\r\t]|$)|([-?:])(?=[,[\]{}]|$))([ \t]*)/iy;
|
|
@@ -951,7 +963,15 @@ function lex(source) {
|
|
|
951
963
|
const lexer = new Lexer(source);
|
|
952
964
|
const end = source.length;
|
|
953
965
|
let state = "stream";
|
|
954
|
-
while (lexer.pos < end)
|
|
966
|
+
while (lexer.pos < end) switch (state) {
|
|
967
|
+
case "stream":
|
|
968
|
+
state = lexer.stream();
|
|
969
|
+
break;
|
|
970
|
+
case "document":
|
|
971
|
+
state = lexer.document();
|
|
972
|
+
break;
|
|
973
|
+
case "flow": state = lexer.flow();
|
|
974
|
+
}
|
|
955
975
|
return lexer.tokens;
|
|
956
976
|
}
|
|
957
977
|
var Lexer = class {
|
|
@@ -978,17 +998,19 @@ var Lexer = class {
|
|
|
978
998
|
this.source = source;
|
|
979
999
|
}
|
|
980
1000
|
charAt(n) {
|
|
981
|
-
|
|
1001
|
+
const i = this.pos + n;
|
|
1002
|
+
return i < this.source.length ? this.source[i] : void 0;
|
|
982
1003
|
}
|
|
983
1004
|
continueScalar(offset) {
|
|
984
1005
|
if (this.indentNext > 0) {
|
|
985
|
-
|
|
1006
|
+
const len = this.source.length;
|
|
986
1007
|
let indent = 0;
|
|
987
|
-
while (
|
|
988
|
-
|
|
989
|
-
|
|
1008
|
+
while (offset + indent < len && this.source.charCodeAt(offset + indent) === CHAR_SPACE) ++indent;
|
|
1009
|
+
const cc = offset + indent < len ? this.source.charCodeAt(offset + indent) : NaN;
|
|
1010
|
+
if (cc === CHAR_CR) {
|
|
1011
|
+
if (this.source.charCodeAt(indent + offset + 1) === CHAR_LF) return offset + indent + 1;
|
|
990
1012
|
}
|
|
991
|
-
return
|
|
1013
|
+
return cc === CHAR_LF || indent >= this.indentNext ? offset + indent : -1;
|
|
992
1014
|
}
|
|
993
1015
|
docMarker.lastIndex = offset;
|
|
994
1016
|
return docMarker.test(this.source) ? -1 : offset;
|
|
@@ -1043,22 +1065,27 @@ var Lexer = class {
|
|
|
1043
1065
|
}
|
|
1044
1066
|
this.indentValue = this.spaces(false);
|
|
1045
1067
|
if (this.indentNext > this.indentValue && !isEmpty(this.charAt(1))) this.indentNext = this.indentValue;
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
const [
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
this.pos
|
|
1068
|
+
while (true) {
|
|
1069
|
+
const ch = this.source[this.pos];
|
|
1070
|
+
if (ch !== "-" && ch !== "?" && ch !== ":") break;
|
|
1071
|
+
const next = this.source[this.pos + 1];
|
|
1072
|
+
if (next !== void 0 && next !== " " && next !== "\n" && next !== "\r" && next !== " ") break;
|
|
1073
|
+
this.tokens.push(ch);
|
|
1074
|
+
const start = this.pos;
|
|
1075
|
+
this.pos += 1;
|
|
1076
|
+
let sc = this.source.charCodeAt(this.pos);
|
|
1077
|
+
while (sc === CHAR_SPACE || sc === CHAR_TAB) sc = this.source.charCodeAt(++this.pos);
|
|
1078
|
+
if (this.pos > start + 1) this.tokens.push(this.source.slice(start + 1, this.pos));
|
|
1053
1079
|
this.indentNext = this.indentValue + 1;
|
|
1054
|
-
this.indentValue +=
|
|
1080
|
+
this.indentValue += this.pos - start;
|
|
1055
1081
|
}
|
|
1056
1082
|
return "document";
|
|
1057
1083
|
}
|
|
1058
1084
|
document() {
|
|
1059
1085
|
this.spaces(true);
|
|
1060
1086
|
this.indicators();
|
|
1061
|
-
|
|
1087
|
+
const ch = this.charAt(0);
|
|
1088
|
+
switch (ch) {
|
|
1062
1089
|
case "#": this.toLineEnd();
|
|
1063
1090
|
case "\n":
|
|
1064
1091
|
case void 0:
|
|
@@ -1079,7 +1106,7 @@ var Lexer = class {
|
|
|
1079
1106
|
return "document";
|
|
1080
1107
|
case "\"":
|
|
1081
1108
|
case "'":
|
|
1082
|
-
this.quotedScalar();
|
|
1109
|
+
this.quotedScalar(ch);
|
|
1083
1110
|
return "document";
|
|
1084
1111
|
case "|":
|
|
1085
1112
|
case ">":
|
|
@@ -1150,7 +1177,7 @@ var Lexer = class {
|
|
|
1150
1177
|
case "\"":
|
|
1151
1178
|
case "'":
|
|
1152
1179
|
this.flowKey = true;
|
|
1153
|
-
this.quotedScalar();
|
|
1180
|
+
this.quotedScalar(ch);
|
|
1154
1181
|
break;
|
|
1155
1182
|
case ":":
|
|
1156
1183
|
if (this.flowKey) {
|
|
@@ -1192,8 +1219,7 @@ var Lexer = class {
|
|
|
1192
1219
|
}
|
|
1193
1220
|
return hasIndicators;
|
|
1194
1221
|
}
|
|
1195
|
-
quotedScalar() {
|
|
1196
|
-
const quote = this.charAt(0);
|
|
1222
|
+
quotedScalar(quote) {
|
|
1197
1223
|
let end = this.source.indexOf(quote, this.pos + 1);
|
|
1198
1224
|
if (quote === "'") while (end !== -1 && this.source[end + 1] === "'") end = this.source.indexOf("'", end + 2);
|
|
1199
1225
|
else while (end !== -1) {
|
|
@@ -1229,16 +1255,16 @@ var Lexer = class {
|
|
|
1229
1255
|
this.newline();
|
|
1230
1256
|
let nl = this.pos - 1;
|
|
1231
1257
|
let indent = 0;
|
|
1232
|
-
let
|
|
1233
|
-
loop: for (let i = this.pos;
|
|
1234
|
-
case
|
|
1258
|
+
let cc;
|
|
1259
|
+
loop: for (let i = this.pos; cc = this.source.charCodeAt(i); ++i) switch (cc) {
|
|
1260
|
+
case CHAR_SPACE:
|
|
1235
1261
|
indent += 1;
|
|
1236
1262
|
break;
|
|
1237
|
-
case
|
|
1263
|
+
case CHAR_LF:
|
|
1238
1264
|
nl = i;
|
|
1239
1265
|
indent = 0;
|
|
1240
1266
|
break;
|
|
1241
|
-
case
|
|
1267
|
+
case CHAR_CR: if (this.source.charCodeAt(i + 1) === CHAR_LF) break;
|
|
1242
1268
|
default: break loop;
|
|
1243
1269
|
}
|
|
1244
1270
|
if (indent >= this.indentNext) {
|
|
@@ -1252,18 +1278,18 @@ var Lexer = class {
|
|
|
1252
1278
|
if (nl === -1) nl = this.source.length;
|
|
1253
1279
|
}
|
|
1254
1280
|
let i = nl + 1;
|
|
1255
|
-
|
|
1256
|
-
while (
|
|
1257
|
-
if (
|
|
1258
|
-
while (
|
|
1281
|
+
cc = this.source.charCodeAt(i);
|
|
1282
|
+
while (cc === CHAR_SPACE) cc = this.source.charCodeAt(++i);
|
|
1283
|
+
if (cc === CHAR_TAB) {
|
|
1284
|
+
while (cc === CHAR_TAB || cc === CHAR_SPACE || cc === CHAR_CR || cc === CHAR_LF) cc = this.source.charCodeAt(++i);
|
|
1259
1285
|
nl = i - 1;
|
|
1260
1286
|
} else if (!bsKeep) do {
|
|
1261
1287
|
let i = nl - 1;
|
|
1262
|
-
let
|
|
1263
|
-
if (
|
|
1288
|
+
let cc = this.source.charCodeAt(i);
|
|
1289
|
+
if (cc === CHAR_CR) cc = this.source.charCodeAt(--i);
|
|
1264
1290
|
const lastChar = i;
|
|
1265
|
-
while (
|
|
1266
|
-
if (
|
|
1291
|
+
while (cc === CHAR_SPACE) cc = this.source.charCodeAt(--i);
|
|
1292
|
+
if (cc === CHAR_LF && i >= this.pos && i + 1 + indent > lastChar) nl = i;
|
|
1267
1293
|
else break;
|
|
1268
1294
|
} while (true);
|
|
1269
1295
|
this.tokens.push("");
|
|
@@ -1273,27 +1299,33 @@ var Lexer = class {
|
|
|
1273
1299
|
const inFlow = this.flowLevel > 0;
|
|
1274
1300
|
let end = this.pos - 1;
|
|
1275
1301
|
let i = this.pos - 1;
|
|
1276
|
-
let
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1302
|
+
let cc;
|
|
1303
|
+
const len = this.source.length;
|
|
1304
|
+
while (++i < len) {
|
|
1305
|
+
cc = this.source.charCodeAt(i);
|
|
1306
|
+
if (cc === CHAR_COLON) {
|
|
1307
|
+
const next = i + 1 < len ? this.source.charCodeAt(i + 1) : NaN;
|
|
1308
|
+
if (isEmptyChar(next) || inFlow && flowIndicatorCharCodes.has(next)) break;
|
|
1309
|
+
end = i;
|
|
1310
|
+
} else if (isEmptyChar(cc)) {
|
|
1311
|
+
let next = i + 1 < len ? this.source.charCodeAt(i + 1) : NaN;
|
|
1312
|
+
if (cc === CHAR_CR) {
|
|
1313
|
+
if (next === CHAR_LF) {
|
|
1314
|
+
i += 1;
|
|
1315
|
+
cc = CHAR_LF;
|
|
1316
|
+
next = i + 1 < len ? this.source.charCodeAt(i + 1) : NaN;
|
|
1317
|
+
} else end = i;
|
|
1318
|
+
}
|
|
1319
|
+
if (next === CHAR_HASH || inFlow && flowIndicatorCharCodes.has(next)) break;
|
|
1320
|
+
if (cc === CHAR_LF) {
|
|
1321
|
+
const cs = this.continueScalar(i + 1);
|
|
1322
|
+
if (cs === -1) break;
|
|
1323
|
+
i = Math.max(i, cs - 2);
|
|
1324
|
+
}
|
|
1325
|
+
} else {
|
|
1326
|
+
if (inFlow && flowIndicatorCharCodes.has(cc)) break;
|
|
1327
|
+
end = i;
|
|
1293
1328
|
}
|
|
1294
|
-
} else {
|
|
1295
|
-
if (inFlow && flowIndicatorChars.has(ch)) break;
|
|
1296
|
-
end = i;
|
|
1297
1329
|
}
|
|
1298
1330
|
this.tokens.push("");
|
|
1299
1331
|
this.toIndex(end + 1, true);
|
|
@@ -1317,9 +1349,9 @@ var Lexer = class {
|
|
|
1317
1349
|
}
|
|
1318
1350
|
toLineEnd() {
|
|
1319
1351
|
let i = this.pos;
|
|
1320
|
-
let ch = this.source
|
|
1321
|
-
while (ch && ch !==
|
|
1322
|
-
if (this.source
|
|
1352
|
+
let ch = this.source.charCodeAt(i);
|
|
1353
|
+
while (ch && ch !== CHAR_LF) ch = this.source.charCodeAt(++i);
|
|
1354
|
+
if (this.source.charCodeAt(i - 1) === CHAR_CR) --i;
|
|
1323
1355
|
return this.toIndex(i, false);
|
|
1324
1356
|
}
|
|
1325
1357
|
newline() {
|
|
@@ -1329,11 +1361,13 @@ var Lexer = class {
|
|
|
1329
1361
|
else return 0;
|
|
1330
1362
|
}
|
|
1331
1363
|
spaces(allowTabs) {
|
|
1332
|
-
let i = this.pos
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1364
|
+
let i = this.pos;
|
|
1365
|
+
const len = this.source.length;
|
|
1366
|
+
while (i < len) {
|
|
1367
|
+
const cc = this.source.charCodeAt(i);
|
|
1368
|
+
if (cc !== CHAR_SPACE && !(allowTabs && cc === CHAR_TAB)) break;
|
|
1369
|
+
++i;
|
|
1370
|
+
}
|
|
1337
1371
|
const n = i - this.pos;
|
|
1338
1372
|
if (n > 0) {
|
|
1339
1373
|
const s = this.source.substr(this.pos, n);
|
|
@@ -1406,9 +1440,10 @@ function fixFlowSeqItems(fc) {
|
|
|
1406
1440
|
for (const it of fc.items) if (it.sep && !it.value && !includesToken(it.start, "explicit-key-ind") && !includesToken(it.sep, "map-value-ind")) {
|
|
1407
1441
|
if (it.key) it.value = it.key;
|
|
1408
1442
|
delete it.key;
|
|
1409
|
-
if (isFlowToken(it.value))
|
|
1410
|
-
|
|
1411
|
-
|
|
1443
|
+
if (isFlowToken(it.value)) {
|
|
1444
|
+
if (it.value.end) Array.prototype.push.apply(it.value.end, it.sep);
|
|
1445
|
+
else it.value.end = it.sep;
|
|
1446
|
+
} else Array.prototype.push.apply(it.start, it.sep);
|
|
1412
1447
|
delete it.sep;
|
|
1413
1448
|
}
|
|
1414
1449
|
}
|
|
@@ -1607,11 +1642,10 @@ var Parser = class {
|
|
|
1607
1642
|
return;
|
|
1608
1643
|
} else if (it.sep) it.value = token;
|
|
1609
1644
|
else {
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
this.onKeyLine = !it.explicitKey;
|
|
1645
|
+
const item = it;
|
|
1646
|
+
item.key = token;
|
|
1647
|
+
item.sep = [];
|
|
1648
|
+
this.onKeyLine = !item.explicitKey;
|
|
1615
1649
|
return;
|
|
1616
1650
|
}
|
|
1617
1651
|
break;
|
|
@@ -1633,10 +1667,10 @@ var Parser = class {
|
|
|
1633
1667
|
sep: []
|
|
1634
1668
|
});
|
|
1635
1669
|
else if (it.sep) it.value = token;
|
|
1636
|
-
else
|
|
1637
|
-
key
|
|
1638
|
-
sep
|
|
1639
|
-
}
|
|
1670
|
+
else {
|
|
1671
|
+
it.key = token;
|
|
1672
|
+
it.sep = [];
|
|
1673
|
+
}
|
|
1640
1674
|
return;
|
|
1641
1675
|
}
|
|
1642
1676
|
/* istanbul ignore next should not happen */
|
|
@@ -1842,66 +1876,68 @@ var Parser = class {
|
|
|
1842
1876
|
this.onKeyLine = true;
|
|
1843
1877
|
return;
|
|
1844
1878
|
case "map-value-ind":
|
|
1845
|
-
if (it.explicitKey)
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
});
|
|
1867
|
-
else if (includesToken(it.sep, "map-value-ind")) this.stack.push({
|
|
1868
|
-
type: "block-map",
|
|
1869
|
-
offset: this.offset,
|
|
1870
|
-
indent: this.indent,
|
|
1871
|
-
items: [{
|
|
1872
|
-
start,
|
|
1879
|
+
if (it.explicitKey) {
|
|
1880
|
+
if (!it.sep) {
|
|
1881
|
+
if (includesToken(it.start, "newline")) {
|
|
1882
|
+
const item = it;
|
|
1883
|
+
item.key = null;
|
|
1884
|
+
item.sep = [this.sourceToken];
|
|
1885
|
+
} else {
|
|
1886
|
+
const start = getFirstKeyStartProps(it.start);
|
|
1887
|
+
this.stack.push({
|
|
1888
|
+
type: "block-map",
|
|
1889
|
+
offset: this.offset,
|
|
1890
|
+
indent: this.indent,
|
|
1891
|
+
items: [{
|
|
1892
|
+
start,
|
|
1893
|
+
key: null,
|
|
1894
|
+
sep: [this.sourceToken]
|
|
1895
|
+
}]
|
|
1896
|
+
});
|
|
1897
|
+
}
|
|
1898
|
+
} else if (it.value) map.items.push({
|
|
1899
|
+
start: [],
|
|
1873
1900
|
key: null,
|
|
1874
1901
|
sep: [this.sourceToken]
|
|
1875
|
-
}
|
|
1876
|
-
|
|
1877
|
-
else if (isFlowToken(it.key) && !includesToken(it.sep, "newline")) {
|
|
1878
|
-
const start = getFirstKeyStartProps(it.start);
|
|
1879
|
-
const key = it.key;
|
|
1880
|
-
const sep = it.sep;
|
|
1881
|
-
sep.push(this.sourceToken);
|
|
1882
|
-
delete it.key;
|
|
1883
|
-
delete it.sep;
|
|
1884
|
-
this.stack.push({
|
|
1902
|
+
});
|
|
1903
|
+
else if (includesToken(it.sep, "map-value-ind")) this.stack.push({
|
|
1885
1904
|
type: "block-map",
|
|
1886
1905
|
offset: this.offset,
|
|
1887
1906
|
indent: this.indent,
|
|
1888
1907
|
items: [{
|
|
1889
1908
|
start,
|
|
1890
|
-
key,
|
|
1891
|
-
sep
|
|
1909
|
+
key: null,
|
|
1910
|
+
sep: [this.sourceToken]
|
|
1892
1911
|
}]
|
|
1893
1912
|
});
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1913
|
+
else if (isFlowToken(it.key) && !includesToken(it.sep, "newline")) {
|
|
1914
|
+
const start = getFirstKeyStartProps(it.start);
|
|
1915
|
+
const key = it.key;
|
|
1916
|
+
const sep = it.sep;
|
|
1917
|
+
sep.push(this.sourceToken);
|
|
1918
|
+
delete it.key;
|
|
1919
|
+
delete it.sep;
|
|
1920
|
+
this.stack.push({
|
|
1921
|
+
type: "block-map",
|
|
1922
|
+
offset: this.offset,
|
|
1923
|
+
indent: this.indent,
|
|
1924
|
+
items: [{
|
|
1925
|
+
start,
|
|
1926
|
+
key,
|
|
1927
|
+
sep
|
|
1928
|
+
}]
|
|
1929
|
+
});
|
|
1930
|
+
} else if (start.length > 0) it.sep = [
|
|
1931
|
+
...it.sep,
|
|
1932
|
+
...start,
|
|
1933
|
+
this.sourceToken
|
|
1934
|
+
];
|
|
1935
|
+
else it.sep.push(this.sourceToken);
|
|
1936
|
+
} else if (!it.sep) {
|
|
1937
|
+
const item = it;
|
|
1938
|
+
item.key = null;
|
|
1939
|
+
item.sep = [this.sourceToken];
|
|
1940
|
+
} else if (it.value || atNextItem) map.items.push({
|
|
1905
1941
|
start,
|
|
1906
1942
|
key: null,
|
|
1907
1943
|
sep: [this.sourceToken]
|
|
@@ -1933,10 +1969,9 @@ var Parser = class {
|
|
|
1933
1969
|
this.onKeyLine = true;
|
|
1934
1970
|
} else if (it.sep) this.stack.push(fs);
|
|
1935
1971
|
else {
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
});
|
|
1972
|
+
const item = it;
|
|
1973
|
+
item.key = fs;
|
|
1974
|
+
item.sep = [];
|
|
1940
1975
|
this.onKeyLine = true;
|
|
1941
1976
|
}
|
|
1942
1977
|
return;
|
|
@@ -1954,7 +1989,7 @@ var Parser = class {
|
|
|
1954
1989
|
});
|
|
1955
1990
|
return;
|
|
1956
1991
|
}
|
|
1957
|
-
} else if (atMapIndent) map.items.push({ start });
|
|
1992
|
+
} else if (atMapIndent && (it.sep || it.explicitKey || start.length > 0)) map.items.push({ start });
|
|
1958
1993
|
this.stack.push(bv);
|
|
1959
1994
|
return;
|
|
1960
1995
|
}
|
|
@@ -2033,10 +2068,10 @@ var Parser = class {
|
|
|
2033
2068
|
sep: [this.sourceToken]
|
|
2034
2069
|
});
|
|
2035
2070
|
else if (it.sep) it.sep.push(this.sourceToken);
|
|
2036
|
-
else
|
|
2037
|
-
key
|
|
2038
|
-
sep
|
|
2039
|
-
}
|
|
2071
|
+
else {
|
|
2072
|
+
it.key = null;
|
|
2073
|
+
it.sep = [this.sourceToken];
|
|
2074
|
+
}
|
|
2040
2075
|
return;
|
|
2041
2076
|
case "space":
|
|
2042
2077
|
case "comment":
|
|
@@ -2058,10 +2093,10 @@ var Parser = class {
|
|
|
2058
2093
|
sep: []
|
|
2059
2094
|
});
|
|
2060
2095
|
else if (it.sep) this.stack.push(fs);
|
|
2061
|
-
else
|
|
2062
|
-
key
|
|
2063
|
-
sep
|
|
2064
|
-
}
|
|
2096
|
+
else {
|
|
2097
|
+
it.key = fs;
|
|
2098
|
+
it.sep = [];
|
|
2099
|
+
}
|
|
2065
2100
|
return;
|
|
2066
2101
|
}
|
|
2067
2102
|
case "flow-map-end":
|
|
@@ -2223,7 +2258,8 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, parentIn
|
|
|
2223
2258
|
let comma = null;
|
|
2224
2259
|
let found = null;
|
|
2225
2260
|
let start = null;
|
|
2226
|
-
|
|
2261
|
+
let token;
|
|
2262
|
+
for (token of tokens) {
|
|
2227
2263
|
if (reqSpace) {
|
|
2228
2264
|
if (token.type !== "space" && token.type !== "newline" && token.type !== "comma") onError(token.offset, "MISSING_CHAR", "Tags and anchors must be separated from the next token by white space");
|
|
2229
2265
|
reqSpace = false;
|
|
@@ -2293,8 +2329,7 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, parentIn
|
|
|
2293
2329
|
hasSpace = false;
|
|
2294
2330
|
}
|
|
2295
2331
|
}
|
|
2296
|
-
const
|
|
2297
|
-
const end = last ? last.offset + last.source.length : offset;
|
|
2332
|
+
const end = token ? token.offset + token.source.length : offset;
|
|
2298
2333
|
if (reqSpace && next && next.type !== "space" && next.type !== "newline" && next.type !== "comma" && (next.type !== "scalar" || next.source !== "")) onError(next.offset, "MISSING_CHAR", "Tags and anchors must be separated from the next token by white space");
|
|
2299
2334
|
if (tab && (atNewline && tab.indent <= parentIndent || next?.type === "block-map" || next?.type === "block-seq")) onError(tab, "TAB_AS_INDENT", "Tabs are not allowed as indentation");
|
|
2300
2335
|
return {
|
|
@@ -2348,7 +2383,7 @@ function flowIndentCheck(indent, fc, onError) {
|
|
|
2348
2383
|
//#region src/compose/resolve-block-map.ts
|
|
2349
2384
|
const startColMsg = "All mapping items must start at the same column";
|
|
2350
2385
|
function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError, tag) {
|
|
2351
|
-
const map = new (tag?.nodeClass ?? YAMLMap)(ctx.schema);
|
|
2386
|
+
const map = new ((tag?.nodeClass) ?? YAMLMap)(ctx.schema);
|
|
2352
2387
|
if (ctx.atRoot) ctx.atRoot = false;
|
|
2353
2388
|
let offset = bm.offset;
|
|
2354
2389
|
let commentEnd = null;
|
|
@@ -2370,8 +2405,10 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError, ta
|
|
|
2370
2405
|
}
|
|
2371
2406
|
if (!keyProps.anchor && !keyProps.tag && !sep) {
|
|
2372
2407
|
commentEnd = keyProps.end;
|
|
2373
|
-
if (keyProps.comment)
|
|
2374
|
-
|
|
2408
|
+
if (keyProps.comment) {
|
|
2409
|
+
if (map.comment) map.comment += "\n" + keyProps.comment;
|
|
2410
|
+
else map.comment = keyProps.comment;
|
|
2411
|
+
}
|
|
2375
2412
|
continue;
|
|
2376
2413
|
}
|
|
2377
2414
|
if (keyProps.newlineAfterProp || containsNewline(key)) onError(key ?? start[start.length - 1], "MULTILINE_IMPLICIT_KEY", "Implicit keys need to be on a single line");
|
|
@@ -2414,8 +2451,10 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError, ta
|
|
|
2414
2451
|
}
|
|
2415
2452
|
} else {
|
|
2416
2453
|
if (implicitKey) onError(keyNode.range, "MISSING_CHAR", "Implicit map keys need to be followed by map values");
|
|
2417
|
-
if (valueProps.comment)
|
|
2418
|
-
|
|
2454
|
+
if (valueProps.comment) {
|
|
2455
|
+
if (keyNode.comment) keyNode.comment += "\n" + valueProps.comment;
|
|
2456
|
+
else keyNode.comment = valueProps.comment;
|
|
2457
|
+
}
|
|
2419
2458
|
if (map instanceof YAMLSet) map.add(keyNode);
|
|
2420
2459
|
else {
|
|
2421
2460
|
const pair = new Pair(keyNode);
|
|
@@ -2435,7 +2474,7 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError, ta
|
|
|
2435
2474
|
//#endregion
|
|
2436
2475
|
//#region src/compose/resolve-block-seq.ts
|
|
2437
2476
|
function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError, tag) {
|
|
2438
|
-
const seq = new (tag?.nodeClass ?? YAMLSeq)(ctx.schema);
|
|
2477
|
+
const seq = new ((tag?.nodeClass) ?? YAMLSeq)(ctx.schema);
|
|
2439
2478
|
if (ctx.atRoot) ctx.atRoot = false;
|
|
2440
2479
|
if (ctx.atKey) ctx.atKey = false;
|
|
2441
2480
|
let offset = bs.offset;
|
|
@@ -2449,12 +2488,15 @@ function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError, ta
|
|
|
2449
2488
|
parentIndent: bs.indent,
|
|
2450
2489
|
startOnNewline: true
|
|
2451
2490
|
});
|
|
2452
|
-
if (!props.found)
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2491
|
+
if (!props.found) {
|
|
2492
|
+
if (props.anchor || props.tag || value) {
|
|
2493
|
+
if (value?.type === "block-seq") onError(props.end, "BAD_INDENT", "All sequence items must start at the same column");
|
|
2494
|
+
else onError(offset, "MISSING_CHAR", "Sequence item without - indicator");
|
|
2495
|
+
} else {
|
|
2496
|
+
commentEnd = props.end;
|
|
2497
|
+
if (props.comment) seq.comment = props.comment;
|
|
2498
|
+
continue;
|
|
2499
|
+
}
|
|
2458
2500
|
}
|
|
2459
2501
|
const node = value ? composeNode(ctx, value, props, onError) : composeEmptyNode(ctx, props.end, start, null, props, onError);
|
|
2460
2502
|
if (ctx.schema.compat) flowIndentCheck(bs.indent, value, onError);
|
|
@@ -2499,8 +2541,10 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
|
|
|
2499
2541
|
if (!props.anchor && !props.tag && !sep && !value) {
|
|
2500
2542
|
if (i === 0 && props.comma) onError(props.comma, "UNEXPECTED_TOKEN", `Unexpected , in ${fcName}`);
|
|
2501
2543
|
else if (i < fc.items.length - 1) onError(props.start, "UNEXPECTED_TOKEN", `Unexpected empty item in ${fcName}`);
|
|
2502
|
-
if (props.comment)
|
|
2503
|
-
|
|
2544
|
+
if (props.comment) {
|
|
2545
|
+
if (coll.comment) coll.comment += "\n" + props.comment;
|
|
2546
|
+
else coll.comment = props.comment;
|
|
2547
|
+
}
|
|
2504
2548
|
offset = props.end;
|
|
2505
2549
|
continue;
|
|
2506
2550
|
}
|
|
@@ -2562,13 +2606,17 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
|
|
|
2562
2606
|
}
|
|
2563
2607
|
if (props.start < valueProps.found.offset - 1024) onError(valueProps.found, "KEY_OVER_1024_CHARS", "The : indicator must be at most 1024 chars after the start of an implicit flow sequence key");
|
|
2564
2608
|
}
|
|
2565
|
-
} else if (value)
|
|
2566
|
-
|
|
2609
|
+
} else if (value) {
|
|
2610
|
+
if ("source" in value && value.source?.[0] === ":") onError(value, "MISSING_CHAR", `Missing space after : in ${fcName}`);
|
|
2611
|
+
else onError(valueProps.start, "MISSING_CHAR", `Missing , or : between ${fcName} items`);
|
|
2612
|
+
}
|
|
2567
2613
|
const valueNode = value ? composeNode(ctx, value, valueProps, onError) : valueProps.found ? composeEmptyNode(ctx, valueProps.end, sep, null, valueProps, onError) : null;
|
|
2568
2614
|
if (valueNode) {
|
|
2569
2615
|
if (isBlock(value)) onError(valueNode.range, "BLOCK_IN_FLOW", blockMsg);
|
|
2570
|
-
} else if (valueProps.comment)
|
|
2571
|
-
|
|
2616
|
+
} else if (valueProps.comment) {
|
|
2617
|
+
if (keyNode.comment) keyNode.comment += "\n" + valueProps.comment;
|
|
2618
|
+
else keyNode.comment = valueProps.comment;
|
|
2619
|
+
}
|
|
2572
2620
|
const pair = new Pair(keyNode, valueNode);
|
|
2573
2621
|
if (ctx.options.keepSourceTokens) pair.srcToken = collItem;
|
|
2574
2622
|
if (isMap) {
|
|
@@ -2603,8 +2651,10 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
|
|
|
2603
2651
|
}
|
|
2604
2652
|
if (ee.length > 0) {
|
|
2605
2653
|
const end = resolveEnd(ee, cePos, ctx.options.strict, onError);
|
|
2606
|
-
if (end.comment)
|
|
2607
|
-
|
|
2654
|
+
if (end.comment) {
|
|
2655
|
+
if (coll.comment) coll.comment += "\n" + end.comment;
|
|
2656
|
+
else coll.comment = end.comment;
|
|
2657
|
+
}
|
|
2608
2658
|
coll.range = [
|
|
2609
2659
|
fc.offset,
|
|
2610
2660
|
cePos,
|
|
@@ -2689,9 +2739,11 @@ function composeScalar(ctx, token, tagToken, onError) {
|
|
|
2689
2739
|
function findScalarTagByName(schema, value, tagName, tagToken, onError) {
|
|
2690
2740
|
if (tagName === "!") return schema.scalar;
|
|
2691
2741
|
const matchWithTest = [];
|
|
2692
|
-
for (const tag of schema.tags) if (!tag.collection && tag.tag === tagName)
|
|
2693
|
-
|
|
2694
|
-
|
|
2742
|
+
for (const tag of schema.tags) if (!tag.collection && tag.tag === tagName) {
|
|
2743
|
+
if (tag.default && tag.test) matchWithTest.push(tag);
|
|
2744
|
+
else return tag;
|
|
2745
|
+
}
|
|
2746
|
+
for (const tag of matchWithTest) if (tag.test?.(value)) return tag;
|
|
2695
2747
|
const kt = schema.knownTags[tagName];
|
|
2696
2748
|
if (kt && !kt.collection) {
|
|
2697
2749
|
schema.tags.push(Object.assign({}, kt, {
|
|
@@ -2703,10 +2755,16 @@ function findScalarTagByName(schema, value, tagName, tagToken, onError) {
|
|
|
2703
2755
|
onError(tagToken, "TAG_RESOLVE_FAILED", `Unresolved tag: ${tagName}`, tagName !== "tag:yaml.org,2002:str");
|
|
2704
2756
|
return schema.scalar;
|
|
2705
2757
|
}
|
|
2758
|
+
const schemaTagsWithTest = /* @__PURE__ */ new WeakMap();
|
|
2706
2759
|
function findScalarTagByTest({ atKey, directives, schema }, value, token, onError) {
|
|
2707
|
-
|
|
2760
|
+
let schemaTags = schemaTagsWithTest.get(schema);
|
|
2761
|
+
if (!schemaTags) {
|
|
2762
|
+
schemaTags = schema.tags.filter((t) => t.test !== void 0 && (t.default === true || t.default === "key"));
|
|
2763
|
+
schemaTagsWithTest.set(schema, schemaTags);
|
|
2764
|
+
}
|
|
2765
|
+
const tag = schemaTags.find((t) => (t.default === true || atKey && t.default === "key") && t.test?.(value)) ?? schema.scalar;
|
|
2708
2766
|
if (schema.compat) {
|
|
2709
|
-
const compat = schema.compat.find((tag) => tag.default && tag.test?.
|
|
2767
|
+
const compat = schema.compat.find((tag) => tag.default && tag.test?.(value)) ?? schema.scalar;
|
|
2710
2768
|
if (tag.tag !== compat.tag) onError(token, "TAG_RESOLVE_FAILED", `Value may be parsed as either ${directives.tagString(tag.tag)} or ${directives.tagString(compat.tag)}`, true);
|
|
2711
2769
|
}
|
|
2712
2770
|
return tag;
|
|
@@ -2776,8 +2834,10 @@ function composeNode(ctx, token, props, onError) {
|
|
|
2776
2834
|
if (anchor && node.anchor === "") onError(anchor, "BAD_ALIAS", "Anchor cannot be an empty string");
|
|
2777
2835
|
if (atKey && ctx.options.stringKeys && (!(node instanceof Scalar) || typeof node.value !== "string" || node.tag && node.tag !== "tag:yaml.org,2002:str")) onError(tag ?? token, "NON_STRING_KEY", "With stringKeys, all keys must be strings");
|
|
2778
2836
|
if (spaceBefore) node.spaceBefore = true;
|
|
2779
|
-
if (comment)
|
|
2780
|
-
|
|
2837
|
+
if (comment) {
|
|
2838
|
+
if (token.type === "scalar" && token.source === "") node.comment = comment;
|
|
2839
|
+
else node.commentBefore = comment;
|
|
2840
|
+
}
|
|
2781
2841
|
if (ctx.options.keepSourceTokens && isSrcToken) node.srcToken = token;
|
|
2782
2842
|
return node;
|
|
2783
2843
|
}
|
|
@@ -2816,7 +2876,8 @@ function composeAlias({ options }, { offset, source, end }, onError) {
|
|
|
2816
2876
|
//#endregion
|
|
2817
2877
|
//#region src/compose/compose-doc.ts
|
|
2818
2878
|
function composeDoc(options, directives, { offset, start, value, end }, onError) {
|
|
2819
|
-
const
|
|
2879
|
+
const opts = Object.assign({ _directives: directives }, options);
|
|
2880
|
+
const doc = new Document(void 0, opts);
|
|
2820
2881
|
const ctx = {
|
|
2821
2882
|
atKey: false,
|
|
2822
2883
|
atRoot: true,
|
|
@@ -3027,7 +3088,8 @@ var Composer = class {
|
|
|
3027
3088
|
this.docs.push(this.doc);
|
|
3028
3089
|
this.doc = null;
|
|
3029
3090
|
} else if (forceDoc) {
|
|
3030
|
-
const
|
|
3091
|
+
const opts = Object.assign({ _directives: this.directives }, this.options);
|
|
3092
|
+
const doc = new Document(void 0, opts);
|
|
3031
3093
|
if (this.atDirectives) this.onError(endOffset, "MISSING_CHAR", "Missing directives-end indicator line");
|
|
3032
3094
|
doc.range = [
|
|
3033
3095
|
0,
|