Skip to content

Commit

Permalink
fix(cst): Do not drop trailing newline after line comment in block-ma…
Browse files Browse the repository at this point in the history
…p if followed by unindented block-seq value (fixes #525)
  • Loading branch information
eemeli committed Mar 6, 2024
1 parent 46a816e commit 40903db
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/parse/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,11 @@ export class Parser {
}

if (this.indent >= map.indent) {
const atNextItem = !this.onKeyLine && this.indent === map.indent && it.sep
const atNextItem =
!this.onKeyLine &&
this.indent === map.indent &&
it.sep &&
this.type !== 'seq-item-ind'

// For empty nodes, assign newline-separated not indented empty tokens to following node
let start: SourceToken[] = []
Expand Down
6 changes: 6 additions & 0 deletions tests/cst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,9 @@ describe('CST.visit', () => {
expect(visits).toBe(3)
})
})

test('Line comment before unindented block-seq in block-map (eemeli/yaml#525)', () => {
const src = 'a:\n#\n- b'
const [doc] = Array.from(new Parser().parse(src))
expect(CST.stringify(doc)).toBe(src)
})

0 comments on commit 40903db

Please sign in to comment.