Skip to content

Commit

Permalink
refactor(yaml): switch array test (#5898)
Browse files Browse the repository at this point in the history
initial commit
  • Loading branch information
timreichen authored Sep 3, 2024
1 parent 890958c commit df562b1
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions yaml/_dumper_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -760,30 +760,30 @@ export class DumperState {
) {
compact = false;
}
if (!Array.isArray(value)) {
if (block && Object.keys(value).length !== 0) {
value = this.stringifyBlockMapping(value, { tag, level, compact });
if (Array.isArray(value)) {
const arrayLevel = !this.arrayIndent && level > 0 ? level - 1 : level;
if (block && value.length !== 0) {
value = this.stringifyBlockSequence(value, {
level: arrayLevel,
compact,
});
if (duplicate) {
value = `&ref_${duplicateIndex}${value}`;
}
} else {
value = this.stringifyFlowMapping(value, { level });
value = this.stringifyFlowSequence(value, { level: arrayLevel });
if (duplicate) {
value = `&ref_${duplicateIndex} ${value}`;
}
}
} else {
const arrayLevel = !this.arrayIndent && level > 0 ? level - 1 : level;
if (block && value.length !== 0) {
value = this.stringifyBlockSequence(value, {
level: arrayLevel,
compact,
});
if (block && Object.keys(value).length !== 0) {
value = this.stringifyBlockMapping(value, { tag, level, compact });
if (duplicate) {
value = `&ref_${duplicateIndex}${value}`;
}
} else {
value = this.stringifyFlowSequence(value, { level: arrayLevel });
value = this.stringifyFlowMapping(value, { level });
if (duplicate) {
value = `&ref_${duplicateIndex} ${value}`;
}
Expand Down

0 comments on commit df562b1

Please sign in to comment.