Skip to content

Commit 6b6a134

Browse files
Trombachematipico
andauthored
Fix extra space in fragment (#1064)
* 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 <my.burning@gmail.com>
1 parent 8cae811 commit 6b6a134

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

.changeset/tiny-buses-hide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@astrojs/compiler": patch
3+
---
4+
5+
Fixes a bug caused by having an extra space in the fragment tag in the TSX output

internal/printer/print-to-tsx.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -706,10 +706,7 @@ declare const Astro: Readonly<import('astro').AstroGlobal<%s, typeof %s`, propsI
706706
}
707707
}
708708
if len(n.Attr) == 0 {
709-
endLoc = n.Loc[0].Start + len(n.Data) - 1
710-
}
711-
if endLoc == -1 {
712-
endLoc = 0
709+
endLoc = n.Loc[0].Start + len(n.Data)
713710
}
714711
isSelfClosing := false
715712
hasLeadingSpace := false

packages/compiler/test/tsx/basic.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,15 @@ export default function __AstroComponent_(_props: Record<string, any>): any {}\n
259259
assert.snapshot(code, output, 'expected code to match snapshot');
260260
});
261261

262+
test('fragment with leading linebreak', async () => {
263+
const input = `
264+
<>Test123</>`;
265+
const output = `${TSXPrefix}<Fragment>
266+
<>Test123</>
267+
</Fragment>
268+
export default function __AstroComponent_(_props: Record<string, any>): any {}\n`;
269+
const { code } = await convertToTSX(input, { sourcemap: 'external' });
270+
assert.snapshot(code, output, 'expected code to match snapshot');
271+
});
272+
262273
test.run();

0 commit comments

Comments
 (0)