Skip to content

[compiler] extend AlignObjectMethodScopes to also merge FunctionExpression object properties#36286

Open
sleitor wants to merge 1 commit intofacebook:mainfrom
sleitor:fix-36151
Open

[compiler] extend AlignObjectMethodScopes to also merge FunctionExpression object properties#36286
sleitor wants to merge 1 commit intofacebook:mainfrom
sleitor:fix-36151

Conversation

@sleitor
Copy link
Copy Markdown
Contributor

@sleitor sleitor commented Apr 16, 2026

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.

The fix tracks 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.

Two new fixtures and updated snapshots demonstrate the fix.

Fixes #36151

…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
@meta-cla meta-cla bot added the CLA Signed label Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Compiler Bug]: Inconsistent memoization strategy for object with method shorthand vs function properties

2 participants