[compiler] preserve JSXText HTML entity references during whitespace normalization#35974
Open
sleitor wants to merge 1 commit intofacebook:mainfrom
Open
[compiler] preserve JSXText HTML entity references during whitespace normalization#35974sleitor wants to merge 1 commit intofacebook:mainfrom
sleitor wants to merge 1 commit intofacebook:mainfrom
Conversation
…normalization HTML entity references such as &facebook#32; are decoded to their character value by Babel before the compiler sees the JSXText node. trimJsxText() normalises whitespace by checking for non-space/tab characters, so a node whose raw source was purely entity-encoded whitespace (e.g. '&facebook#32;') would be trimmed to null and silently dropped from the output. Fix: when trimJsxText returns null, fall back to trimming the raw source text (exprPath.node.extra.raw). Because the raw form contains non-whitespace characters ('&', '#', digits, ';'), trimJsxText('&facebook#32;') returns '&facebook#32;' which is then emitted as a JSX string expression {"&facebook#32;"} and decoded correctly by the standard JSX transform at runtime. Fixes facebook#35971
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.
Summary
Fixes #35971
HTML entity references such as
 are decoded to their character value by Babel before the compiler sees theJSXTextnode.trimJsxText()normalises whitespace by checking for non-space/tab characters, so a node whose raw source was purely entity-encoded whitespace (e.g. ) would be trimmed tonulland silently dropped from the output.Root Cause
Babel parses
 as aJSXTextnode withvalue: ' '(decoded space) andextra.raw: ' '. ThetrimJsxTextfunction only sees the decoded value' ', which contains no non-whitespace characters, so it returnsnull— causing the entity to be dropped.Fix
When
trimJsxTextreturnsnullfor the decoded value, fall back to trimming the raw source text (exprPath.node.extra.raw). Since the raw form contains non-whitespace characters (&,#, digits,;),trimJsxText(' ')returns' ', which is emitted as a JSX string expression{" "}and decoded correctly by the standard JSX transform at runtime.Test
Added a fixture
jsx-html-entity-preservedthat verifies is preserved as{" "}in the compiled output. All 1720 existing compiler snapshot tests continue to pass.