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] Infer deps configuration (facebook#31616)
Adds a way to configure how we insert deps for experimental purposes. ``` [ { module: 'react', imported: 'useEffect', numRequiredArgs: 1, }, { module: 'MyExperimentalEffectHooks', imported: 'useExperimentalEffect', numRequiredArgs: 2, }, ] ``` would insert dependencies for calls of `useEffect` imported from `react` if they have 1 argument and calls of useExperimentalEffect` from `MyExperimentalEffectHooks` if they have 2 arguments. The pushed dep array is appended to the arg list.
- Loading branch information
Showing
9 changed files
with
168 additions
and
22 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
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
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
61 changes: 61 additions & 0 deletions
61
...act-compiler/src/__tests__/fixtures/compiler/infer-deps-custom-config.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,61 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
// @inferEffectDependencies | ||
import {print, useSpecialEffect} from 'shared-runtime'; | ||
|
||
function CustomConfig({propVal}) { | ||
// Insertion | ||
useSpecialEffect(() => print(propVal), [propVal]); | ||
// No insertion | ||
useSpecialEffect(() => print(propVal), [propVal], [propVal]); | ||
} | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; // @inferEffectDependencies | ||
import { print, useSpecialEffect } from "shared-runtime"; | ||
|
||
function CustomConfig(t0) { | ||
const $ = _c(7); | ||
const { propVal } = t0; | ||
let t1; | ||
let t2; | ||
if ($[0] !== propVal) { | ||
t1 = () => print(propVal); | ||
t2 = [propVal]; | ||
$[0] = propVal; | ||
$[1] = t1; | ||
$[2] = t2; | ||
} else { | ||
t1 = $[1]; | ||
t2 = $[2]; | ||
} | ||
useSpecialEffect(t1, t2, [propVal]); | ||
let t3; | ||
let t4; | ||
let t5; | ||
if ($[3] !== propVal) { | ||
t3 = () => print(propVal); | ||
t4 = [propVal]; | ||
t5 = [propVal]; | ||
$[3] = propVal; | ||
$[4] = t3; | ||
$[5] = t4; | ||
$[6] = t5; | ||
} else { | ||
t3 = $[4]; | ||
t4 = $[5]; | ||
t5 = $[6]; | ||
} | ||
useSpecialEffect(t3, t4, t5); | ||
} | ||
|
||
``` | ||
### Eval output | ||
(kind: exception) Fixture not implemented |
9 changes: 9 additions & 0 deletions
9
...s/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-deps-custom-config.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,9 @@ | ||
// @inferEffectDependencies | ||
import {print, useSpecialEffect} from 'shared-runtime'; | ||
|
||
function CustomConfig({propVal}) { | ||
// Insertion | ||
useSpecialEffect(() => print(propVal), [propVal]); | ||
// No insertion | ||
useSpecialEffect(() => print(propVal), [propVal], [propVal]); | ||
} |
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
2 changes: 2 additions & 0 deletions
2
.../babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-effect-dependencies.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
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
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