Expand compact option to support JSX-style whitespace stripping#1151
Open
meyer wants to merge 2 commits intowithastro:mainfrom
Open
Expand compact option to support JSX-style whitespace stripping#1151meyer wants to merge 2 commits intowithastro:mainfrom
compact option to support JSX-style whitespace stripping#1151meyer wants to merge 2 commits intowithastro:mainfrom
Conversation
🦋 Changeset detectedLatest commit: 88866a5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
compressHTML to support JSX-style whitespace strippingcompact option to support JSX-style whitespace stripping
738cf91 to
5c167e6
Compare
meyer
commented
Mar 1, 2026
|
|
||
| const ( | ||
| CompactNone CompactMode = iota | ||
| CompactDefault // standard whitespace collapsing |
Author
There was a problem hiding this comment.
i have no strong opinions on naming, feel free to bikeshed
5c167e6 to
88866a5
Compare
meyer
commented
Mar 1, 2026
| assert.match(result, output); | ||
| }); | ||
|
|
||
| test.run(); |
Author
There was a problem hiding this comment.
unintentional omissions? lmk if this is intentional and i’ll remove the commit that adds them
This was referenced Mar 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
In this PR I’ve expanded the
compactoption 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 missingtest.run()calls from a few other test files (second commit).Testing
New tests added
Docs
withastro/docs#13326