Preserve nested Platform write targets in Babel preset - #58252
Open
OskarEichler wants to merge 2 commits into
Open
Preserve nested Platform write targets in Babel preset#58252OskarEichler wants to merge 2 commits into
OskarEichler wants to merge 2 commits into
Conversation
Contributor
Author
|
A second pass found that the ancestor walk treated every expression nested anywhere under an assignment LHS as a write. That incorrectly prevented inlining ordinary reads such as |
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:
The React Native Babel preset replaces
Platform.OSwith a string literal even when the member expression is nested inside a destructuring assignment target. Direct and nestedfor...in/for...oftargets are affected as well; direct loop targets can make Babel abort because a string literal is not a valid assignment target.Walk the member expression's ancestors and preserve it whenever the containing expression is the left side of an assignment or loop, or the argument of an update/delete operation. This prevents invalid generated syntax and keeps write semantics intact. Metro has a parallel transform, so companion Metro PR #1890 applies the same guard there.
Changelog:
[GENERAL] [FIXED] - Preserve nested Platform.OS write targets in the Babel preset.
Test Plan:
for...inandfor...oftargets.git diff --checkpass.No public API or intended read-transform behavior changes.