Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/rotten-elephants-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/compiler': patch
---

[TSX] fix compiler crash when file only contains an unamed fragment
5 changes: 4 additions & 1 deletion internal/printer/print-to-tsx.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,12 +421,15 @@ declare const Astro: Readonly<import('astro').AstroGlobal<%s>>`, props.Ident)
if len(n.Attr) == 0 {
endLoc = n.Loc[0].Start + len(n.Data) - 1
}
if endLoc == -1 {
endLoc = 0
}
Comment on lines +424 to +426
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the problem!

isSelfClosing := false
tmpLoc := endLoc
if len(p.sourcetext) > tmpLoc {
for i := 0; i < len(p.sourcetext[tmpLoc:]); i++ {
c := p.sourcetext[endLoc : endLoc+1][0]
if c == '/' && p.sourcetext[endLoc+1:][0] == '>' {
if c == '/' && len(p.sourcetext) > endLoc+1 && p.sourcetext[endLoc+1:][0] == '>' {
isSelfClosing = true
break
} else if c == '>' {
Expand Down
10 changes: 10 additions & 0 deletions packages/compiler/test/tsx/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,14 @@ export default function __AstroComponent_(_props: Record<string, any>): any {}\n
assert.snapshot(code, output, `expected code to match snapshot`);
});

test('fragment with no name', async () => {
const input = '<>+0123456789</>';
const output = `<Fragment>
<>+0123456789</>
</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();