forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
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 compilationMode:infer object method edge case (f…
…acebook#32055) Fix for facebook#31180
- Loading branch information
Showing
3 changed files
with
84 additions
and
0 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
63 changes: 63 additions & 0 deletions
63
...t-compiler/src/__tests__/fixtures/compiler/infer-nested-object-method.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,63 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
// @compilationMode(infer) | ||
|
||
import {Stringify} from 'shared-runtime'; | ||
|
||
function Test() { | ||
const context = { | ||
testFn() { | ||
// if it is an arrow function its work | ||
return () => 'test'; // it will break compile if returns an arrow fn | ||
}, | ||
}; | ||
|
||
return <Stringify value={context} shouldInvokeFns={true} />; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Test, | ||
params: [{}], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; // @compilationMode(infer) | ||
|
||
import { Stringify } from "shared-runtime"; | ||
|
||
function Test() { | ||
const $ = _c(1); | ||
let t0; | ||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) { | ||
const context = { | ||
testFn() { | ||
return _temp; | ||
}, | ||
}; | ||
|
||
t0 = <Stringify value={context} shouldInvokeFns={true} />; | ||
$[0] = t0; | ||
} else { | ||
t0 = $[0]; | ||
} | ||
return t0; | ||
} | ||
function _temp() { | ||
return "test"; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Test, | ||
params: [{}], | ||
}; | ||
|
||
``` | ||
### Eval output | ||
(kind: ok) <div>{"value":{"testFn":{"kind":"Function","result":{"kind":"Function","result":"test"}}},"shouldInvokeFns":true}</div> |
19 changes: 19 additions & 0 deletions
19
...abel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-nested-object-method.jsx
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,19 @@ | ||
// @compilationMode(infer) | ||
|
||
import {Stringify} from 'shared-runtime'; | ||
|
||
function Test() { | ||
const context = { | ||
testFn() { | ||
// if it is an arrow function its work | ||
return () => 'test'; // it will break compile if returns an arrow fn | ||
}, | ||
}; | ||
|
||
return <Stringify value={context} shouldInvokeFns={true} />; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Test, | ||
params: [{}], | ||
}; |