Skip to content

Expand compact option to support JSX-style whitespace stripping#1151

Open
meyer wants to merge 2 commits intowithastro:mainfrom
meyer:meyer/jsx-whitespace
Open

Expand compact option to support JSX-style whitespace stripping#1151
meyer wants to merge 2 commits intowithastro:mainfrom
meyer:meyer/jsx-whitespace

Conversation

@meyer
Copy link
Copy Markdown

@meyer meyer commented Feb 28, 2026

Changes

In this PR I’ve expanded the compact option to support a new string value, "jsx". This allows users to enable JSX style whitespace stripping in Astro. Handy for folks like me who often pair Astro and React. No more mental shift when jumping between components… all my JSX code looks and behaves the same way. If you all are more curious about rationale, please let me know, I’ve got more to say about the topic but didn’t want to clog up the PR description.

The JSX spec unfortunately doesn’t specify how whitespace is dealt with in JSX, but JS tooling has landed on Babel’s whitespace handling as a kind of standard.

The implementation is based on esbuild’s JSX whitespace handling, which is an exact implementation of TypeScript’s JSX whitespace handling, which in turn is an implementation of Babel’s whitespace handling.

I did this work with some serious assistance from Claude Code + Opus, but I have read each line of code and gone through the tests as well.

While working on this I (well, claude 🫣) noticed that minify tests weren’t running due to a missing test.run(). That has been fixed in this PR, as well as the missing test.run() calls from a few other test files (second commit).

Testing

New tests added

Docs

withastro/docs#13326

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Feb 28, 2026

🦋 Changeset detected

Latest commit: 88866a5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@astrojs/compiler Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@meyer meyer changed the title Expand compressHTML to support JSX-style whitespace stripping Expand compact option to support JSX-style whitespace stripping Feb 28, 2026
@meyer meyer force-pushed the meyer/jsx-whitespace branch 2 times, most recently from 738cf91 to 5c167e6 Compare March 1, 2026 00:20

const (
CompactNone CompactMode = iota
CompactDefault // standard whitespace collapsing
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

i have no strong opinions on naming, feel free to bikeshed

@meyer meyer force-pushed the meyer/jsx-whitespace branch from 5c167e6 to 88866a5 Compare March 1, 2026 00:31
assert.match(result, output);
});

test.run();
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

unintentional omissions? lmk if this is intentional and i’ll remove the commit that adds them

@meyer meyer marked this pull request as ready for review March 1, 2026 00:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant