Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix extra space in fragment #1064

Merged
merged 4 commits into from
Feb 6, 2025
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/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();
Loading