Skip to content

[compiler] Infer optional dependencies (behind feature flag)#30819

Merged
josephsavona merged 10 commits intogh/josephsavona/53/basefrom
gh/josephsavona/53/head
Aug 28, 2024
Merged

[compiler] Infer optional dependencies (behind feature flag)#30819
josephsavona merged 10 commits intogh/josephsavona/53/basefrom
gh/josephsavona/53/head

Conversation

@josephsavona
Copy link
Member

@josephsavona josephsavona commented Aug 26, 2024

Stack from ghstack (oldest at bottom):

Adds a new feature flag, @enableOptionalDependencies which when enabled allows PropagateScopeDeps and DeriveMinimalDeps to infer optional dependency paths (a?.b).

In PropagateScopeDeps we look for specific safe patterns of nested optional member expressions:

  • <variable> "." / "?." <property>
  • or <nested> "." / "?." <property>

When we find this pattern we record a dependency on the overall chain, so for example in a?.b.c?.d.map() we would record a dependency on a?.b.c?.d (because the outer .map() portion doesn't match the above structure). If the structure doesn't match - for example with a?.b?.[foo(bar)]?.z - then we fall back to the existing behavior which treats everything after the initial portion as conditional (for that last example we'd continue to record a as the dep).

The other portion is DeriveMinimalDeps, which now represents optional access/dependency states and updates the merge logic to handle them. The order of precedence is unconditional > optional > conditional.

Note: the flag is off by default, but i tried enabling it for all fixtures and the results were all either unchanged or had correct optional deps inferred. I'll also try running it internally with the flag enabled, but i think we can proceed with review and fix-forward any issues identified from that testing.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed React Core Team Opened by a member of the React Core Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants