Skip to content

Commit

Permalink
Fix extra space in fragment (#1064)
Browse files Browse the repository at this point in the history
* fix: off by on error

* test: add test case for fragment with leading line break

* Create tiny-buses-hide.md

* Update .changeset/tiny-buses-hide.md

---------

Co-authored-by: Emanuele Stoppa <[email protected]>
  • Loading branch information
Trombach and ematipico authored Feb 6, 2025
1 parent 8cae811 commit 6b6a134
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/tiny-buses-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/compiler": patch
---

Fixes a bug caused by having an extra space in the fragment tag in the TSX output
5 changes: 1 addition & 4 deletions internal/printer/print-to-tsx.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,10 +706,7 @@ declare const Astro: Readonly<import('astro').AstroGlobal<%s, typeof %s`, propsI
}
}
if len(n.Attr) == 0 {
endLoc = n.Loc[0].Start + len(n.Data) - 1
}
if endLoc == -1 {
endLoc = 0
endLoc = n.Loc[0].Start + len(n.Data)
}
isSelfClosing := false
hasLeadingSpace := false
Expand Down
11 changes: 11 additions & 0 deletions packages/compiler/test/tsx/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,15 @@ export default function __AstroComponent_(_props: Record<string, any>): any {}\n
assert.snapshot(code, output, 'expected code to match snapshot');
});

test('fragment with leading linebreak', async () => {
const input = `
<>Test123</>`;
const output = `${TSXPrefix}<Fragment>
<>Test123</>
</Fragment>
export default function __AstroComponent_(_props: Record<string, any>): any {}\n`;
const { code } = await convertToTSX(input, { sourcemap: 'external' });
assert.snapshot(code, output, 'expected code to match snapshot');
});

test.run();

0 comments on commit 6b6a134

Please sign in to comment.