fix(compiler): preserve HTML entities in JSX text by correctly detecting non-empty lines#717
fix(compiler): preserve HTML entities in JSX text by correctly detecting non-empty lines#717everettbu wants to merge 1 commit into
Conversation
…ing non-empty lines
Greptile SummaryMirror of facebook/react#36050. This PR fixes the
Confidence Score: 4/5
Important Files Changed
Prompt To Fix All With AIThis is a comment left during a code review.
Path: compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts
Line: 3566
Comment:
**Behavioral difference from Babel's reference implementation with `\u00A0`**
This change diverges from the Babel reference implementation (`cleanJSXElementLiteralChild`), which uses `lines[i].match(/[^ \t]/)`. The code comment on line 3557-3558 still references that Babel implementation.
`trim()` removes all Unicode whitespace (including `\u00A0`, `\u2003`, `\uFEFF`, etc.), while the original regex `/[^ \t]/` only considers literal space and tab as "empty" characters. This means a line containing only `\u00A0` (from an ` ` entity) would be detected as "non-empty" by the old regex but "empty" by `trim()`, which could affect `lastNonEmptyLine` and therefore whether a trailing space separator is appended.
In practice this is an unlikely edge case (a line containing *only* ` ` with no other content), but it's worth noting the semantic difference since the comment says this is "adapted from Babel."
How can I resolve this? If you propose a fix, please make it concise.Last reviewed commit: 8d7d13a |
|
|
||
| for (let i = 0; i < lines.length; i++) { | ||
| if (lines[i].match(/[^ \t]/)) { | ||
| if (lines[i].trim().length > 0) { |
There was a problem hiding this comment.
Behavioral difference from Babel's reference implementation with \u00A0
This change diverges from the Babel reference implementation (cleanJSXElementLiteralChild), which uses lines[i].match(/[^ \t]/). The code comment on line 3557-3558 still references that Babel implementation.
trim() removes all Unicode whitespace (including \u00A0, \u2003, \uFEFF, etc.), while the original regex /[^ \t]/ only considers literal space and tab as "empty" characters. This means a line containing only \u00A0 (from an entity) would be detected as "non-empty" by the old regex but "empty" by trim(), which could affect lastNonEmptyLine and therefore whether a trailing space separator is appended.
In practice this is an unlikely edge case (a line containing only with no other content), but it's worth noting the semantic difference since the comment says this is "adapted from Babel."
Prompt To Fix With AI
This is a comment left during a code review.
Path: compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts
Line: 3566
Comment:
**Behavioral difference from Babel's reference implementation with `\u00A0`**
This change diverges from the Babel reference implementation (`cleanJSXElementLiteralChild`), which uses `lines[i].match(/[^ \t]/)`. The code comment on line 3557-3558 still references that Babel implementation.
`trim()` removes all Unicode whitespace (including `\u00A0`, `\u2003`, `\uFEFF`, etc.), while the original regex `/[^ \t]/` only considers literal space and tab as "empty" characters. This means a line containing only `\u00A0` (from an ` ` entity) would be detected as "non-empty" by the old regex but "empty" by `trim()`, which could affect `lastNonEmptyLine` and therefore whether a trailing space separator is appended.
In practice this is an unlikely edge case (a line containing *only* ` ` with no other content), but it's worth noting the semantic difference since the comment says this is "adapted from Babel."
How can I resolve this? If you propose a fix, please make it concise.|
Upstream PR was closed or merged. Code is synced via branch mirror. |
Mirror of facebook/react#36050
Original author: MorikawaSouma