dillon1000/react

Commit

[rhir] Represent OptionalMemberExpression as a conditional dependency

--- 

Every `OptionalMemberExpression` rvalue has the form 
`<requiredPath>?.<optionalPath>`. 

``` 

// required = [a], optional: [b, c] 

props.a?.b.c; 

props.a?.b?.c; 

``` 

When calculating reactive dependencies, recall that it is always correct to add 
a subpath of a dependency (e.g. we can always take `props.a` instead of 
`props.a.b` as a dependency). See comments in `DeriveMinimalDependencies` for a 
longer explanation. 

There are two ways we can deal with `OptionalMemberExpression`: 

- We can always truncate a OptionalMemberExpression dependency to its 
`requiredPath`, taking only the required path as a dependency. 

- this is the simpler approach, but it potentially loses granularity. 

e.g. 

``` 

// here, since props.a is already unconditionally accessed, 

// we can safely add props.a.b as a dependency and preserve both 

// nullthrows and the correct dependency set. 

scope @0 { 

let x = []; 

x.push(props.a?.b); 

x.push(props.a.b); 

} 

``` 

(See added test case `reduce-reactive-cond-memberexpr-join` + its comment block 
for a more detailed explanation` 

- (the approach taken by this PR) 

We can add the `requiredPath` as a potentially unconditional access (dependent 
on other control flow) and `requiredPath + optionalPath` as a conditional 
dependency.
Browse files
Changed paths7 files
First-parent comparison
M compiler/forget/src/ReactiveScopes/DeriveMinimalDependencies.ts ModifiedM compiler/forget/src/ReactiveScopes/PropagateScopeDependencies.ts ModifiedA compiler/forget/src/__tests__/fixtures/compiler/cond-deps-conditional-member-expr.expect.md AddedA compiler/forget/src/__tests__/fixtures/compiler/cond-deps-conditional-member-expr.js AddedM compiler/forget/src/__tests__/fixtures/compiler/nested-optional-member-expr.expect.md ModifiedA compiler/forget/src/__tests__/fixtures/compiler/reduce-reactive-cond-memberexpr-join.expect.md AddedA compiler/forget/src/__tests__/fixtures/compiler/reduce-reactive-cond-memberexpr-join.js Added
Patch

Files changed

Rendering syntax-highlighted changes…