From e75f9c724b8b9464656710bf63615e23f7630281 Mon Sep 17 00:00:00 2001 From: Erika <3019731+Princesseuh@users.noreply.github.com> Date: Tue, 26 Dec 2023 14:56:34 -0500 Subject: [PATCH] fix: regression with self-closing tags text (#394) * fix: regression with self-closing tags text * chore: changeset --- .changeset/smart-bats-attack.md | 5 +++++ src/printer/index.ts | 2 +- test/fixtures/other/clean-self-closing/input.astro | 8 ++++++++ test/fixtures/other/clean-self-closing/output.astro | 8 ++++++++ test/tests/other.test.ts | 2 ++ 5 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 .changeset/smart-bats-attack.md create mode 100644 test/fixtures/other/clean-self-closing/input.astro create mode 100644 test/fixtures/other/clean-self-closing/output.astro diff --git a/.changeset/smart-bats-attack.md b/.changeset/smart-bats-attack.md new file mode 100644 index 0000000..d588541 --- /dev/null +++ b/.changeset/smart-bats-attack.md @@ -0,0 +1,5 @@ +--- +'prettier-plugin-astro': patch +--- + +Fix `
` tags sometimes causing additional spaces to appear diff --git a/src/printer/index.ts b/src/printer/index.ts index 0935c78..9e6e928 100644 --- a/src/printer/index.ts +++ b/src/printer/index.ts @@ -351,7 +351,7 @@ function splitTextToDocs(node: TextNode): Doc[] { const textLines = text.split(/[\t\n\f\r ]+/); - let docs = join(line, textLines); + let docs = join(line, textLines).filter((doc) => doc !== ''); if (startsWithLinebreak(text)) { docs[0] = hardline; diff --git a/test/fixtures/other/clean-self-closing/input.astro b/test/fixtures/other/clean-self-closing/input.astro new file mode 100644 index 0000000..8c1a038 --- /dev/null +++ b/test/fixtures/other/clean-self-closing/input.astro @@ -0,0 +1,8 @@ +

+ test test test
+ test test test test test test test test test test test test test test
+ test test test test test test test test test test test test test test
+ test test test test test test test test test test test test test test test + test test test test test test test test test test test test test
+ test test test test test test test test test test test test test test +

diff --git a/test/fixtures/other/clean-self-closing/output.astro b/test/fixtures/other/clean-self-closing/output.astro new file mode 100644 index 0000000..020b238 --- /dev/null +++ b/test/fixtures/other/clean-self-closing/output.astro @@ -0,0 +1,8 @@ +

+ test test test
+ test test test test test test test test test test test test test test
+ test test test test test test test test test test test test test test
+ test test test test test test test test test test test test test test test test + test test test test test test test test test test test test
+ test test test test test test test test test test test test test test +

diff --git a/test/tests/other.test.ts b/test/tests/other.test.ts index de8aca7..eacb641 100644 --- a/test/tests/other.test.ts +++ b/test/tests/other.test.ts @@ -81,6 +81,8 @@ test('Can format nested comment', files, 'other/nested-comment'); test('Format binary expressions', files, 'other/binary-expression'); +test('Format self-closing tags without additional content', files, 'other/clean-self-closing'); + test('Format directives', files, 'other/directive'); test('Format slots', files, 'other/slots');