Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -3563,7 +3563,7 @@ function trimJsxText(original: string): string | null {
let lastNonEmptyLine = 0;

for (let i = 0; i < lines.length; i++) {
if (lines[i].match(/[^ \t]/)) {
if (lines[i].trim().length > 0) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 &nbsp; 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 &nbsp; 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 `&nbsp;` 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* `&nbsp;` 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.

Fix in Claude Code Fix in Codex

lastNonEmptyLine = i;
}
}
Expand Down
Loading