Skip to content

Commit 99be62f

Browse files
jackschuamaanq
andauthored
fix: jsx_text node trims whitespace too often
Co-authored-by: Amaan Qureshi <amaanq12@gmail.com>
1 parent 12e4537 commit 99be62f

File tree

4 files changed

+2778
-2785
lines changed

4 files changed

+2778
-2785
lines changed

grammar.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -608,10 +608,11 @@ module.exports = grammar({
608608
field('close_tag', $.jsx_closing_element),
609609
),
610610

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

617618
// An entity can be named, numeric (decimal), or numeric (hexadecimal). The

src/grammar.json

Lines changed: 10 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)