Repository navigation
Conversation
Collaborator
|
Thanks, but since the fix has landed upstream in PR welcome if you'd like to do that. |
robhogan
requested changes
Oct 11, 2026
robhogan
left a comment
Collaborator
There was a problem hiding this comment.
As above - tests are good but a Babel bump brings in the fix more cleanly
cpruijsen
force-pushed
the
fix/issue-1927-0bfb831a
branch
from
October 12, 2026 13:34
7a0e041 to
ef3d8e8
Compare
robhogan
approved these changes
Oct 12, 2026
This branch has not been deployed
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
constant-folding-pluginno longer folds an expression that references a binding declared by an object or array pattern.The plugin trusts
path.evaluate(). For a destructured binding,evaluate()resolves to the whole init of the declarator and reports the result as confident (babel/babel#18238). The fold is then wrong, with no error, and only in release builds:The change in
packages/metro-transform-plugins/src/constant-folding-plugin.jsadds anIdentifiervisitor to the existing unsafe-traversal check, which already rejects calls and assignments.path.traverse()does not visit the root node, so the check also runs on a bare identifier at the root, for example the test of a conditional.The issue suggests rejecting non-finite numeric results instead. That does not catch the string coercion or wrong-branch cases, and it breaks the existing
NaN ?? x()fold, so this change rejects the destructured reference and does not inspect the value. The cost: a fold through a destructured binding with a safe literal init (const {a} = {a: 1}; a + 2) no longer happens.Fixes #1927
Changelog: [Fix] Fix constant folding of expressions that reference destructured bindings (emitted
0 / 0,"[object Object]1"or the wrong branch in release builds)Test plan
Four new cases in
constant-folding-plugin-test.js(arithmetic, NaN, conditional, logical) fail onmainand pass with this change. The rest of themetro-transform-pluginstests pass unchanged.