-
Notifications
You must be signed in to change notification settings - Fork 47.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compile] Error on fire outside of effects and ensure correct compila…
…tion Traverse the compiled functions to ensure there are no lingering fires and that all fire calls are inside an effect lambda. --
- Loading branch information
Showing
12 changed files
with
221 additions
and
16 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
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
39 changes: 39 additions & 0 deletions
39
..._/fixtures/compiler/transform-fire/error.invalid-mix-fire-and-no-fire.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,39 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
// @enableFire | ||
import {fire} from 'react'; | ||
|
||
function Component(props) { | ||
const foo = props => { | ||
console.log(props); | ||
}; | ||
useEffect(() => { | ||
function nested() { | ||
fire(foo(props)); | ||
foo(props); | ||
} | ||
|
||
nested(); | ||
}); | ||
|
||
return null; | ||
} | ||
|
||
``` | ||
|
||
|
||
## Error | ||
|
||
``` | ||
9 | function nested() { | ||
10 | fire(foo(props)); | ||
> 11 | foo(props); | ||
| ^^^ InvalidReact: Cannot compile `fire`. All uses of foo must be either used with a fire() call in this effect or not used with a fire() call at all. foo was used with fire() on line 10:10 in this effect (11:11) | ||
12 | } | ||
13 | | ||
14 | nested(); | ||
``` | ||
18 changes: 18 additions & 0 deletions
18
...iler/src/__tests__/fixtures/compiler/transform-fire/error.invalid-mix-fire-and-no-fire.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,18 @@ | ||
// @enableFire | ||
import {fire} from 'react'; | ||
|
||
function Component(props) { | ||
const foo = props => { | ||
console.log(props); | ||
}; | ||
useEffect(() => { | ||
function nested() { | ||
fire(foo(props)); | ||
foo(props); | ||
} | ||
|
||
nested(); | ||
}); | ||
|
||
return null; | ||
} |
38 changes: 38 additions & 0 deletions
38
...tests__/fixtures/compiler/transform-fire/error.invalid-outside-effect.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,38 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
// @enableFire | ||
import {fire, useCallback} from 'react'; | ||
|
||
function Component({props, bar}) { | ||
const foo = () => { | ||
console.log(props); | ||
}; | ||
fire(foo(props)); | ||
|
||
useCallback(() => { | ||
fire(foo(props)); | ||
}, [foo, props]); | ||
|
||
return null; | ||
} | ||
|
||
``` | ||
|
||
|
||
## Error | ||
|
||
``` | ||
6 | console.log(props); | ||
7 | }; | ||
> 8 | fire(foo(props)); | ||
| ^^^^ Invariant: Cannot compile `fire`. Cannot use `fire` outside of a useEffect function (8:8) | ||
Invariant: Cannot compile `fire`. Cannot use `fire` outside of a useEffect function (11:11) | ||
9 | | ||
10 | useCallback(() => { | ||
11 | fire(foo(props)); | ||
``` | ||
15 changes: 15 additions & 0 deletions
15
...t-compiler/src/__tests__/fixtures/compiler/transform-fire/error.invalid-outside-effect.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,15 @@ | ||
// @enableFire | ||
import {fire, useCallback} from 'react'; | ||
|
||
function Component({props, bar}) { | ||
const foo = () => { | ||
console.log(props); | ||
}; | ||
fire(foo(props)); | ||
|
||
useCallback(() => { | ||
fire(foo(props)); | ||
}, [foo, props]); | ||
|
||
return 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
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