Skip to content

Commit bebfc9c

Browse files
committed
fix(tsrx-prettier-plugin): keep a comment run to one space
A space-rendering comment after a sibling printed both the source space before the comment and {" "} after it. Once the comment is gone those are two spaces. The space at the end of the children is that run's one space, so the literal space before the comment is dropped.
1 parent b9aeb07 commit bebfc9c

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

‎packages/tsrx-prettier-plugin/src/jsx.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,10 @@ function printJsxChildren(path, options, print, whitespace, isFacebookTranslatio
502502
// breaks, so the space goes there, where it prints as `{" "}`.
503503
if (run.after === 'boundary') {
504504
if (outerAfter) after = whitespace;
505-
if (outerBefore && run.before === 'boundary') before = '';
505+
// That `{" "}` is the run's one space. A literal space before
506+
// the comment would stay on its line and render again once
507+
// the comment is gone.
508+
if (outerBefore && (run.before === 'boundary' || before === ' ')) before = '';
506509
} else if (outerBefore) {
507510
before = whitespace;
508511
}

‎packages/tsrx-prettier-plugin/tests/tsrx.test.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ const b = (
611611
`export function App() @{
612612
<>
613613
<div>
614-
<b>t</b> /* c */{" "}
614+
<b>t</b>/* c */{" "}
615615
</div>
616616
<div>
617617
{" "}

0 commit comments

Comments
 (0)