refactor(yaml): switch array test (#5898)

initial commit
This commit is contained in:
Tim Reichen 2024-09-04 00:42:24 +02:00 committed by GitHub
parent 890958ca48
commit df562b1d28
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -760,19 +760,7 @@ export class DumperState {
) { ) {
compact = false; compact = false;
} }
if (!Array.isArray(value)) { if (Array.isArray(value)) {
if (block && Object.keys(value).length !== 0) {
value = this.stringifyBlockMapping(value, { tag, level, compact });
if (duplicate) {
value = `&ref_${duplicateIndex}${value}`;
}
} else {
value = this.stringifyFlowMapping(value, { level });
if (duplicate) {
value = `&ref_${duplicateIndex} ${value}`;
}
}
} else {
const arrayLevel = !this.arrayIndent && level > 0 ? level - 1 : level; const arrayLevel = !this.arrayIndent && level > 0 ? level - 1 : level;
if (block && value.length !== 0) { if (block && value.length !== 0) {
value = this.stringifyBlockSequence(value, { value = this.stringifyBlockSequence(value, {
@ -788,6 +776,18 @@ export class DumperState {
value = `&ref_${duplicateIndex} ${value}`; value = `&ref_${duplicateIndex} ${value}`;
} }
} }
} else {
if (block && Object.keys(value).length !== 0) {
value = this.stringifyBlockMapping(value, { tag, level, compact });
if (duplicate) {
value = `&ref_${duplicateIndex}${value}`;
}
} else {
value = this.stringifyFlowMapping(value, { level });
if (duplicate) {
value = `&ref_${duplicateIndex} ${value}`;
}
}
} }
} else if (typeof value === "string") { } else if (typeof value === "string") {
if (tag !== "?") { if (tag !== "?") {