Skip to content

Commit 70a8db3

Browse files
authored
fix: Do not double newlines for empty map values (#642)
1 parent 92821f2 commit 70a8db3

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/stringify/stringifyPair.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export function stringifyPair(
127127
ws += `\n${indentComment(cs, ctx.indent)}`
128128
}
129129
if (valueStr === '' && !ctx.inFlow) {
130-
if (ws === '\n') ws = '\n\n'
130+
if (ws === '\n' && valueComment) ws = '\n\n'
131131
} else {
132132
ws += `\n${ctx.indent}`
133133
}

tests/doc/stringify.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,19 @@ z:
398398
'{\n a:\n #c\n ,\n b:\n}\n'
399399
)
400400
})
401+
402+
test('Single newline after key with empty value', () => {
403+
const src = source`
404+
map:
405+
item:
406+
407+
anothermap:
408+
anotheritem:
409+
410+
`
411+
const doc = YAML.parseDocument(src)
412+
expect(String(doc)).toBe(src)
413+
})
401414
})
402415

403416
describe('properties on collections in block mapping', () => {

0 commit comments

Comments
 (0)