-
Notifications
You must be signed in to change notification settings - Fork 47.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compiler] repro for dep merging edge case (non-hir)
ghstack-source-id: 7adf7a76cf0f61695e370d81ec560c3477f8e67c Pull Request resolved: #31035
- Loading branch information
Showing
3 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
...ompiler/reduce-reactive-deps/bug-merge-uncond-optional-chain-and-cond.expect.md
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
import {identity} from 'shared-runtime'; | ||
|
||
/** | ||
* Evaluator failure: | ||
* Found differences in evaluator results | ||
* Non-forget (expected): | ||
* (kind: ok) {} | ||
* [[ (exception in render) TypeError: Cannot read properties of null (reading 'title_text') ]] | ||
* Forget: | ||
* (kind: ok) {} | ||
* {} | ||
*/ | ||
/** | ||
* Very contrived text fixture showing that it's technically incorrect to merge | ||
* a conditional dependency (e.g. dep.path in `cond ? dep.path : ...`) and an | ||
* unconditionally evaluated optional chain (`dep?.path`). | ||
* | ||
* | ||
* when screen is non-null, useFoo returns { title: null } or "(not null)" | ||
* when screen is null, useFoo throws | ||
*/ | ||
function useFoo({screen}: {screen: null | undefined | {title_text: null}}) { | ||
return screen?.title_text != null | ||
? '(not null)' | ||
: identity({title: screen.title_text}); | ||
} | ||
export const FIXTURE_ENTRYPOINT = { | ||
fn: useFoo, | ||
params: [{screen: null}], | ||
sequentialRenders: [{screen: {title_bar: undefined}}, {screen: null}], | ||
}; | ||
|
||
``` | ||
## Code | ||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; | ||
import { identity } from "shared-runtime"; | ||
|
||
/** | ||
* Evaluator failure: | ||
* Found differences in evaluator results | ||
* Non-forget (expected): | ||
* (kind: ok) {} | ||
* [[ (exception in render) TypeError: Cannot read properties of null (reading 'title_text') ]] | ||
* Forget: | ||
* (kind: ok) {} | ||
* {} | ||
*/ | ||
/** | ||
* Very contrived text fixture showing that it's technically incorrect to merge | ||
* a conditional dependency (e.g. dep.path in `cond ? dep.path : ...`) and an | ||
* unconditionally evaluated optional chain (`dep?.path`). | ||
* | ||
* | ||
* when screen is non-null, useFoo returns { title: null } or "(not null)" | ||
* when screen is null, useFoo throws | ||
*/ | ||
function useFoo(t0) { | ||
const $ = _c(2); | ||
const { screen } = t0; | ||
let t1; | ||
if ($[0] !== screen?.title_text) { | ||
t1 = | ||
screen?.title_text != null | ||
? "(not null)" | ||
: identity({ title: screen.title_text }); | ||
$[0] = screen?.title_text; | ||
$[1] = t1; | ||
} else { | ||
t1 = $[1]; | ||
} | ||
return t1; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: useFoo, | ||
params: [{ screen: null }], | ||
sequentialRenders: [{ screen: { title_bar: undefined } }, { screen: null }], | ||
}; | ||
|
||
``` | ||
31 changes: 31 additions & 0 deletions
31
...ests__/fixtures/compiler/reduce-reactive-deps/bug-merge-uncond-optional-chain-and-cond.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import {identity} from 'shared-runtime'; | ||
|
||
/** | ||
* Evaluator failure: | ||
* Found differences in evaluator results | ||
* Non-forget (expected): | ||
* (kind: ok) {} | ||
* [[ (exception in render) TypeError: Cannot read properties of null (reading 'title_text') ]] | ||
* Forget: | ||
* (kind: ok) {} | ||
* {} | ||
*/ | ||
/** | ||
* Very contrived text fixture showing that it's technically incorrect to merge | ||
* a conditional dependency (e.g. dep.path in `cond ? dep.path : ...`) and an | ||
* unconditionally evaluated optional chain (`dep?.path`). | ||
* | ||
* | ||
* when screen is non-null, useFoo returns { title: null } or "(not null)" | ||
* when screen is null, useFoo throws | ||
*/ | ||
function useFoo({screen}: {screen: null | undefined | {title_text: null}}) { | ||
return screen?.title_text != null | ||
? '(not null)' | ||
: identity({title: screen.title_text}); | ||
} | ||
export const FIXTURE_ENTRYPOINT = { | ||
fn: useFoo, | ||
params: [{screen: null}], | ||
sequentialRenders: [{screen: {title_bar: undefined}}, {screen: null}], | ||
}; |
This file contains 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