-
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] Expect component props annotations to be potential objects
Summary: We now expect that candidate components that have Flow or TS type annotations on their first parameters have annotations that are potentially objects--this lets us reject compiling functions that explicitly take e.g. `number` as a parameter. ghstack-source-id: 03622a68d62bb7a4029dd8cf228e62b290b6dd7b Pull Request resolved: #29866
- Loading branch information
Showing
3 changed files
with
104 additions
and
2 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
39 changes: 39 additions & 0 deletions
39
...act-compiler/src/__tests__/fixtures/compiler/infer-no-component-annot.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 | ||
// @compilationMode(infer) | ||
import { useIdentity, identity } from "shared-runtime"; | ||
|
||
function Component(fakeProps: number) { | ||
const x = useIdentity(fakeProps); | ||
return identity(x); | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [42], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
// @compilationMode(infer) | ||
import { useIdentity, identity } from "shared-runtime"; | ||
|
||
function Component(fakeProps: number) { | ||
const x = useIdentity(fakeProps); | ||
return identity(x); | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [42], | ||
}; | ||
|
||
``` | ||
### Eval output | ||
(kind: ok) 42 |
12 changes: 12 additions & 0 deletions
12
...s/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-no-component-annot.ts
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,12 @@ | ||
// @compilationMode(infer) | ||
import { useIdentity, identity } from "shared-runtime"; | ||
|
||
function Component(fakeProps: number) { | ||
const x = useIdentity(fakeProps); | ||
return identity(x); | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [42], | ||
}; |