-
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.
Update on "[compiler] Validate type configs for hooks/non-hooks"
Alternative to #30868. The goal is to ensure that the types coming out of moduleTypeProvider are valid wrt to hook typing. If something is named like a hook, then it must be typed as a hook (or don't type it). [ghstack-poisoned]
- Loading branch information
1 parent
0a8bea2
commit c37ac41
Showing
8 changed files
with
180 additions
and
59 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
25 changes: 25 additions & 0 deletions
25
...ures/compiler/error.invalid-type-provider-hook-name-not-typed-as-hook.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,25 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
import {useHookNotTypedAsHook} from 'ReactCompilerTest'; | ||
|
||
function Component() { | ||
return useHookNotTypedAsHook(); | ||
} | ||
|
||
``` | ||
|
||
|
||
## Error | ||
|
||
``` | ||
2 | | ||
3 | function Component() { | ||
> 4 | return useHookNotTypedAsHook(); | ||
| ^^^^^^^^^^^^^^^^^^^^^ InvalidConfig: Invalid type configuration for module. Expected type for `import {useHookNotTypedAsHook} from 'ReactCompilerTest'` to be a hook based on the exported name (4:4) | ||
5 | } | ||
6 | | ||
``` | ||
5 changes: 5 additions & 0 deletions
5
...rc/__tests__/fixtures/compiler/error.invalid-type-provider-hook-name-not-typed-as-hook.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,5 @@ | ||
import {useHookNotTypedAsHook} from 'ReactCompilerTest'; | ||
|
||
function Component() { | ||
return useHookNotTypedAsHook(); | ||
} |
25 changes: 25 additions & 0 deletions
25
...compiler/error.invalid-type-provider-hooklike-module-default-not-hook.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,25 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
import foo from 'useDefaultExportNotTypedAsHook'; | ||
|
||
function Component() { | ||
return <div>{foo()}</div>; | ||
} | ||
|
||
``` | ||
|
||
|
||
## Error | ||
|
||
``` | ||
2 | | ||
3 | function Component() { | ||
> 4 | return <div>{foo()}</div>; | ||
| ^^^ InvalidConfig: Invalid type configuration for module. Expected type for `import ... from 'useDefaultExportNotTypedAsHook'` to be a hook based on the module name (4:4) | ||
5 | } | ||
6 | | ||
``` | ||
5 changes: 5 additions & 0 deletions
5
...tests__/fixtures/compiler/error.invalid-type-provider-hooklike-module-default-not-hook.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,5 @@ | ||
import foo from 'useDefaultExportNotTypedAsHook'; | ||
|
||
function Component() { | ||
return <div>{foo()}</div>; | ||
} |
25 changes: 25 additions & 0 deletions
25
...tures/compiler/error.invalid-type-provider-nonhook-name-typed-as-hook.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,25 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
import {notAhookTypedAsHook} from 'ReactCompilerTest'; | ||
|
||
function Component() { | ||
return <div>{notAhookTypedAsHook()}</div>; | ||
} | ||
|
||
``` | ||
|
||
|
||
## Error | ||
|
||
``` | ||
2 | | ||
3 | function Component() { | ||
> 4 | return <div>{notAhookTypedAsHook()}</div>; | ||
| ^^^^^^^^^^^^^^^^^^^ InvalidConfig: Invalid type configuration for module. Expected type for `import {notAhookTypedAsHook} from 'ReactCompilerTest'` not to be a hook based on the exported name (4:4) | ||
5 | } | ||
6 | | ||
``` | ||
5 changes: 5 additions & 0 deletions
5
...src/__tests__/fixtures/compiler/error.invalid-type-provider-nonhook-name-typed-as-hook.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,5 @@ | ||
import {notAhookTypedAsHook} from 'ReactCompilerTest'; | ||
|
||
function Component() { | ||
return <div>{notAhookTypedAsHook()}</div>; | ||
} |
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