diff --git a/yaml/_dumper_state.ts b/yaml/_dumper_state.ts index 615e39866404..3a6f1f8c791e 100644 --- a/yaml/_dumper_state.ts +++ b/yaml/_dumper_state.ts @@ -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}`; }