[compiler] Preserve JSX case semantics in constant propagation#36295
Open
ousamabenyounes wants to merge 1 commit intofacebook:mainfrom
Open
[compiler] Preserve JSX case semantics in constant propagation#36295ousamabenyounes wants to merge 1 commit intofacebook:mainfrom
ousamabenyounes wants to merge 1 commit intofacebook:mainfrom
Conversation
ConstantPropagation rewrote `$X = LoadLocal Comp` into `$X = LoadGlobal base` whenever a component-named local aliased a lowercase global. When the lvalue was used as a simple JSX tag, codegen emitted `<base />` (an intrinsic HTML tag) instead of `<Comp />` (a component reference), silently changing runtime behaviour (fixes facebook#35268). The fix runs a pre-pass that collects Places used as simple JSX tags, then skips the LoadLocal → LoadGlobal rewrite when the lvalue is one of them and the local/global names have different component-vs-intrinsic casing. Member-expression tags (e.g. `<localVar.Stringify />`) and same-casing rewrites (e.g. `const MyLocal = Stringify; <MyLocal />` → `<Stringify />`) are unaffected. Co-Authored-By: Claude <noreply@anthropic.com>
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 #35268.
ConstantPropagation'sLoadLocalcase rewrote$X = LoadLocal Compinto$X = LoadGlobal basewhenever a component-named local aliased a lowercase global. When that lvalue was used as a simple JSX tag, codegen then emitted<base />(treated as an intrinsic HTML element) instead of<Comp />(a component reference), silently changing runtime behaviour.Repro
Before this PR:
After this PR:
Fix
constantPropagationnow runs a pre-pass that collects theIdentifierIdof every Place used as a simple JSX element tag (i.e.<X />, not<x.Y />/<x:y />). In theLoadLocalrewrite step, the pass skips the substitution when:LoadGlobal, andPrimitive constant folding is unaffected. Member-expression JSX tags (e.g.
<localVar.Stringify />) continue to propagate since the JSX-tag Place in that case is thePropertyLoadlvalue, not theLoadLocallvalue. Same-casing rewrites (e.g.const MyLocal = Stringify; <MyLocal />→<Stringify />, as exercised byjsx-local-tag-in-lambda.js) are also unaffected.How did you test this change?
yarn snap— 1720 passed / 1720 (1719 existing + 1 new regression fixturejsx-component-local-aliasing-lowercase-global).yarn workspace babel-plugin-react-compiler lint— clean.yarn flow dom-node— clean.yarn linc/yarn prettier— clean.jsx-lowercase-localvar-memberexpr*,jsx-local-tag-in-lambda,jsx-tag-evaluation-order,const-propagation-into-function-expression-globalfixtures continue to pass unchanged.🤖 Generated with Claude Code