Skip to content

Commit 40903db

Browse files
committed
fix(cst): Do not drop trailing newline after line comment in block-map if followed by unindented block-seq value (fixes #525)
1 parent 46a816e commit 40903db

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/parse/parser.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,11 @@ export class Parser {
529529
}
530530

531531
if (this.indent >= map.indent) {
532-
const atNextItem = !this.onKeyLine && this.indent === map.indent && it.sep
532+
const atNextItem =
533+
!this.onKeyLine &&
534+
this.indent === map.indent &&
535+
it.sep &&
536+
this.type !== 'seq-item-ind'
533537

534538
// For empty nodes, assign newline-separated not indented empty tokens to following node
535539
let start: SourceToken[] = []

tests/cst.ts

+6
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,9 @@ describe('CST.visit', () => {
195195
expect(visits).toBe(3)
196196
})
197197
})
198+
199+
test('Line comment before unindented block-seq in block-map (eemeli/yaml#525)', () => {
200+
const src = 'a:\n#\n- b'
201+
const [doc] = Array.from(new Parser().parse(src))
202+
expect(CST.stringify(doc)).toBe(src)
203+
})

0 commit comments

Comments
 (0)