Skip to content

Fix: JSXText node trims whitespace too often #328

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

Merged
merged 5 commits into from
Jul 6, 2024
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
7 changes: 4 additions & 3 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,10 +608,11 @@ module.exports = grammar({
field('close_tag', $.jsx_closing_element),
),

// Should not contain new lines and should not start or end with a space
jsx_text: _ => choice(
/[^{}<>\n& ]([^{}<>\n&]*[^{}<>\n& ])?/,
/\/\/[^\n]*/,
// if there is a newline, only capture if there's non-whitespace-text
token.immediate(/[^{}<>&]*[^{}<>\s\p{Zs}\uFEFF\u2028\u2029\u2060\u200B&][^{}<>&]*/),
// whitespace between jsx_tags should be captured if there's no newline
token.immediate(/[^{}<>\n&]+/),
),

// An entity can be named, numeric (decimal), or numeric (hexadecimal). The
Expand Down
14 changes: 10 additions & 4 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading