[compiler] extend AlignObjectMethodScopes to also merge FunctionExpression object properties#36286
Open
sleitor wants to merge 1 commit intofacebook:mainfrom
Open
[compiler] extend AlignObjectMethodScopes to also merge FunctionExpression object properties#36286sleitor wants to merge 1 commit intofacebook:mainfrom
sleitor wants to merge 1 commit intofacebook:mainfrom
Conversation
…ssion object properties Previously, AlignObjectMethodScopes only merged scopes for ObjectMethod (method shorthand) values with their parent ObjectExpression scope. This caused FunctionExpression (arrow functions and named function expressions) used as object properties to receive separate reactive scopes, resulting in inconsistent memoization: method shorthands memoized the whole object as a unit, while function expressions caused the object to be split across separate per-function cache slots. The fix is minimal: track FunctionExpression lvalues in objectMethodDecls alongside ObjectMethod lvalues in findScopesToMerge(). When the outer ObjectExpression iterates its operands it will then union FunctionExpression scopes with the ObjectExpression scope, ensuring all object properties— regardless of whether they are written as method shorthand or function expression—share the same reactive scope and are memoized consistently. Two new fixtures demonstrate the fix: - bug-inconsistent-memoization-object-fn-expression: pure arrow/named fn props - bug-inconsistent-memoization-object-mixed-properties: mixed method+fn props Existing snapshots updated: - object-shorthand-method-1: was 5 slots (split), now 3 slots (unified) - merge-consecutive-scopes-objects: onClick arrow fn now merged into parent scope Fixes facebook#36151
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.
Previously,
AlignObjectMethodScopesonly merged scopes for ObjectMethod (method shorthand) values with their parent ObjectExpression scope. This caused FunctionExpression (arrow functions and named function expressions) used as object properties to receive separate reactive scopes, resulting in inconsistent memoization.The fix tracks FunctionExpression lvalues in
objectMethodDeclsalongside ObjectMethod lvalues infindScopesToMerge(). When the outer ObjectExpression iterates its operands it will then union FunctionExpression scopes with the ObjectExpression scope.Two new fixtures and updated snapshots demonstrate the fix.
Fixes #36151