From 40903db981917ba5be113e170af00c8bfd85be92 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Wed, 6 Mar 2024 13:27:51 +0200 Subject: [PATCH] fix(cst): Do not drop trailing newline after line comment in block-map if followed by unindented block-seq value (fixes #525) --- src/parse/parser.ts | 6 +++++- tests/cst.ts | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/parse/parser.ts b/src/parse/parser.ts index 528280fe..fb1453b4 100644 --- a/src/parse/parser.ts +++ b/src/parse/parser.ts @@ -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[] = [] diff --git a/tests/cst.ts b/tests/cst.ts index 7100e8f6..3580c959 100644 --- a/tests/cst.ts +++ b/tests/cst.ts @@ -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) +})