-
Notifications
You must be signed in to change notification settings - Fork 46.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compiler][ez] Patch hoistability for ObjectMethods
Extends #31066 to ObjectMethods (somehow missed this before). '
- Loading branch information
Showing
3 changed files
with
114 additions
and
2 deletions.
There are no files selected for viewing
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
82 changes: 82 additions & 0 deletions
82
...ope-deps-hir-fork/reduce-reactive-deps/infer-objectmethod-cond-access.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,82 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
// @enablePropagateDepsInHIR | ||
import {Stringify} from 'shared-runtime'; | ||
|
||
function Foo({a, shouldReadA}) { | ||
return ( | ||
<Stringify | ||
objectMethod={{ | ||
method() { | ||
if (shouldReadA) return a.b.c; | ||
return null; | ||
}, | ||
}} | ||
shouldInvokeFns={true} | ||
/> | ||
); | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Foo, | ||
params: [{a: null, shouldReadA: true}], | ||
sequentialRenders: [ | ||
{a: null, shouldReadA: true}, | ||
{a: null, shouldReadA: false}, | ||
{a: {b: {c: 4}}, shouldReadA: true}, | ||
], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR | ||
import { Stringify } from "shared-runtime"; | ||
|
||
function Foo(t0) { | ||
const $ = _c(3); | ||
const { a, shouldReadA } = t0; | ||
let t1; | ||
if ($[0] !== shouldReadA || $[1] !== a) { | ||
t1 = ( | ||
<Stringify | ||
objectMethod={{ | ||
method() { | ||
if (shouldReadA) { | ||
return a.b.c; | ||
} | ||
return null; | ||
}, | ||
}} | ||
shouldInvokeFns={true} | ||
/> | ||
); | ||
$[0] = shouldReadA; | ||
$[1] = a; | ||
$[2] = t1; | ||
} else { | ||
t1 = $[2]; | ||
} | ||
return t1; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Foo, | ||
params: [{ a: null, shouldReadA: true }], | ||
sequentialRenders: [ | ||
{ a: null, shouldReadA: true }, | ||
{ a: null, shouldReadA: false }, | ||
{ a: { b: { c: 4 } }, shouldReadA: true }, | ||
], | ||
}; | ||
|
||
``` | ||
### Eval output | ||
(kind: ok) [[ (exception in render) TypeError: Cannot read properties of null (reading 'b') ]] | ||
<div>{"objectMethod":{"method":{"kind":"Function","result":null}},"shouldInvokeFns":true}</div> | ||
<div>{"objectMethod":{"method":{"kind":"Function","result":4}},"shouldInvokeFns":true}</div> |
26 changes: 26 additions & 0 deletions
26
...iler/propagate-scope-deps-hir-fork/reduce-reactive-deps/infer-objectmethod-cond-access.js
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,26 @@ | ||
// @enablePropagateDepsInHIR | ||
import {Stringify} from 'shared-runtime'; | ||
|
||
function Foo({a, shouldReadA}) { | ||
return ( | ||
<Stringify | ||
objectMethod={{ | ||
method() { | ||
if (shouldReadA) return a.b.c; | ||
return null; | ||
}, | ||
}} | ||
shouldInvokeFns={true} | ||
/> | ||
); | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Foo, | ||
params: [{a: null, shouldReadA: true}], | ||
sequentialRenders: [ | ||
{a: null, shouldReadA: true}, | ||
{a: null, shouldReadA: false}, | ||
{a: {b: {c: 4}}, shouldReadA: true}, | ||
], | ||
}; |