From d4460a59db28b7e14803b874b444bd18c99abaa5 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Mon, 20 Feb 2023 21:39:42 +0100 Subject: [PATCH] fix: Use correct argument order when stringifying flow collection comments (fixes #443) --- src/stringify/stringifyCollection.ts | 2 +- tests/doc/comments.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/stringify/stringifyCollection.ts b/src/stringify/stringifyCollection.ts index 326e3afb..7d9e780a 100644 --- a/src/stringify/stringifyCollection.ts +++ b/src/stringify/stringifyCollection.ts @@ -161,7 +161,7 @@ function stringifyFlowCollection( } if (comment) { - str += lineComment(str, commentString(comment), indent) + str += lineComment(str, indent, commentString(comment)) if (onComment) onComment() } return str diff --git a/tests/doc/comments.ts b/tests/doc/comments.ts index 503871fb..e087da04 100644 --- a/tests/doc/comments.ts +++ b/tests/doc/comments.ts @@ -554,6 +554,15 @@ describe('stringify comments', () => { } `) }) + + test('line comment after flow collection (eemeli/yaml#443)', () => { + const doc = YAML.parseDocument(source` + [ value1, value2 ] # comment + `) + expect(String(doc)).toBe(source` + [ value1, value2 ] # comment + `) + }) }) })