-
Notifications
You must be signed in to change notification settings - Fork 47.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compiler][fire] Only allow values captured by the effect to be fired
- Loading branch information
Showing
3 changed files
with
85 additions
and
7 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
34 changes: 34 additions & 0 deletions
34
.../src/__tests__/fixtures/compiler/transform-fire/error.invalid-capture.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,34 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
// @enableFire | ||
import {fire} from 'react'; | ||
|
||
function Component(props) { | ||
useEffect(() => { | ||
const log = () => { | ||
console.log(props); | ||
}; | ||
fire(log)(); | ||
}); | ||
|
||
return null; | ||
} | ||
|
||
``` | ||
|
||
|
||
## Error | ||
|
||
``` | ||
7 | console.log(props); | ||
8 | }; | ||
> 9 | fire(log)(); | ||
| ^^^ InvalidReact: Cannot compile `fire`. `fire()` only accepts identifiers defined in the component/hook scope. This value was defined in the useEffect callback. (9:9) | ||
10 | }); | ||
11 | | ||
12 | return null; | ||
``` | ||
13 changes: 13 additions & 0 deletions
13
...in-react-compiler/src/__tests__/fixtures/compiler/transform-fire/error.invalid-capture.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,13 @@ | ||
// @enableFire | ||
import {fire} from 'react'; | ||
|
||
function Component(props) { | ||
useEffect(() => { | ||
const log = () => { | ||
console.log(props); | ||
}; | ||
fire(log)(); | ||
}); | ||
|
||
return null; | ||
} |