-
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.
[compiler] Run compiler pipeline on 'use no forget'
This PR updates the babel plugin to continue the compilation pipeline as normal on components/hooks that have been opted out using a directive. Instead, we no longer emit the compiled function when the directive is present. Previously, we would skip over the entire pipeline. By continuing to enter the pipeline, we'll be able to detect if there are unused directives. The end result is: - (no change) 'use forget' will always opt into compilation - (new) 'use no forget' will opt out of compilation but continue to log errors without throwing them. This means that a Program containing multiple functions (some of which are opted out) will continue to compile correctly ghstack-source-id: 895dc051a5fec06c3c22dea9debb66fa8086f2a2 Pull Request resolved: #30720
- Loading branch information
Showing
11 changed files
with
212 additions
and
154 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
38 changes: 38 additions & 0 deletions
38
...ixtures/compiler/error.use-no-forget-multiple-with-eslint-suppression.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 | ||
import {useRef} from 'react'; | ||
|
||
const useControllableState = options => {}; | ||
function NoopComponent() {} | ||
|
||
function Component() { | ||
'use no forget'; | ||
const ref = useRef(null); | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
ref.current = 'bad'; | ||
return <button ref={ref} />; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [], | ||
}; | ||
|
||
``` | ||
|
||
|
||
## Error | ||
|
||
``` | ||
7 | 'use no forget'; | ||
8 | const ref = useRef(null); | ||
> 9 | // eslint-disable-next-line react-hooks/rules-of-hooks | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ InvalidReact: React Compiler has skipped optimizing this component because one or more React ESLint rules were disabled. React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior. eslint-disable-next-line react-hooks/rules-of-hooks (9:9) | ||
10 | ref.current = 'bad'; | ||
11 | return <button ref={ref} />; | ||
12 | } | ||
``` | ||
File renamed without changes.
35 changes: 35 additions & 0 deletions
35
...tests__/fixtures/compiler/error.use-no-forget-with-eslint-suppression.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,35 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
import {useRef} from 'react'; | ||
|
||
function Component() { | ||
'use no forget'; | ||
const ref = useRef(null); | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
ref.current = 'bad'; | ||
return <button ref={ref} />; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [], | ||
}; | ||
|
||
``` | ||
|
||
|
||
## Error | ||
|
||
``` | ||
4 | 'use no forget'; | ||
5 | const ref = useRef(null); | ||
> 6 | // eslint-disable-next-line react-hooks/rules-of-hooks | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ InvalidReact: React Compiler has skipped optimizing this component because one or more React ESLint rules were disabled. React Compiler only works when your components follow all the rules of React, disabling them may result in unexpected or incorrect behavior. eslint-disable-next-line react-hooks/rules-of-hooks (6:6) | ||
7 | ref.current = 'bad'; | ||
8 | return <button ref={ref} />; | ||
9 | } | ||
``` | ||
File renamed without changes.
49 changes: 0 additions & 49 deletions
49
...ts__/fixtures/compiler/use-no-forget-multiple-with-eslint-suppression.expect.md
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.