Skip to content

Clone ObjectMethod before toExpression in preset (#58424) - #58424

Closed
vzaidman wants to merge 2 commits into
mainfrom
export-D119305530
Closed

Clone ObjectMethod before toExpression in preset (#58424)#58424
vzaidman wants to merge 2 commits into
mainfrom
export-D119305530

Conversation

@vzaidman

@vzaidman vzaidman commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Summary:

The React Native Babel preset replaces Platform.select({...}) with the selected property during production transforms. When the selected property is an object method, converting it to an expression mutates the node in place. Since the replacement is computed before the purity check, bailing out on an impure sibling leaves the mutated method behind, producing invalid output. Clone the method before converting it.

Also assess purity on the property itself: an ObjectMethod has no value, so checking the value treated every method as impure and skipped inlining.

Changelog:

[GENERAL] [FIXED] - Fix Platform.select inlining producing invalid output for object methods when discarding impure initializers is skipped

Reviewed By: GijsWeterings

Differential Revision: D119305530

…oad the correct commit data.

Differential Revision: D119065685
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 9, 2026
@facebook-github-tools facebook-github-tools Bot added p: Facebook Partner: Facebook Partner labels Sep 9, 2026
@meta-codesync

meta-codesync Bot commented Sep 9, 2026

Copy link
Copy Markdown

@vzaidman has exported this pull request. If you are a Meta employee, you can view the originating Diff in D119305530.

Summary:
Pull Request resolved: #58424

The React Native Babel preset replaces `Platform.select({...})` with the selected property during production transforms. When the selected property is an object method, converting it to an expression mutates the node in place. Since the replacement is computed before the purity check, bailing out on an impure sibling leaves the mutated method behind, producing invalid output. Clone the method before converting it.

Also assess purity on the property itself: an `ObjectMethod` has no value, so checking the value treated every method as impure and skipped inlining.

## Changelog:

[GENERAL] [FIXED] - Fix Platform.select inlining producing invalid output for object methods when discarding impure initializers is skipped

Reviewed By: GijsWeterings

Differential Revision: D119305530
@meta-codesync meta-codesync Bot changed the title Clone ObjectMethod before toExpression in preset Clone ObjectMethod before toExpression in preset (#58424) Sep 9, 2026
@meta-codesync meta-codesync Bot closed this in 88748a7 Sep 9, 2026
@meta-codesync meta-codesync Bot added the Merged This PR has been merged. label Sep 9, 2026
@meta-codesync

meta-codesync Bot commented Sep 9, 2026

Copy link
Copy Markdown

This pull request has been merged in 88748a7.

@facebook-github-tools

Copy link
Copy Markdown

This pull request has been reverted by c1ad8ae.

shashikant-panchal pushed a commit to shashikant-panchal/react-native that referenced this pull request Sep 10, 2026
Summary:
Pull Request resolved: react#58424

The React Native Babel preset replaces `Platform.select({...})` with the selected property during production transforms. When the selected property is an object method, converting it to an expression mutates the node in place. Since the replacement is computed before the purity check, bailing out on an impure sibling leaves the mutated method behind, producing invalid output. Clone the method before converting it.

Also assess purity on the property itself: an `ObjectMethod` has no value, so checking the value treated every method as impure and skipped inlining.

## Changelog:

[GENERAL] [FIXED] - Fix Platform.select inlining producing invalid output for object methods when discarding impure initializers is skipped

Reviewed By: GijsWeterings

Differential Revision: D119305530

fbshipit-source-id: dd30a94e91ed8a024377acf4230698439eef8b1b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner Reverted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant