-
Notifications
You must be signed in to change notification settings - Fork 48.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(babel-plugin-react-compiler): support satisfies operator #32742
Merged
mofeiZ
merged 6 commits into
facebook:main
from
rodrigofariow:babel-plugin-react-compiler-support-satisfies-operator
Mar 28, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7e051b0
feat(babel-plugin-react-compiler): support satisfies operator
rodrigo-faria-cartrack d0dbe7f
refactor: add tests for satisfies operator
rodrigo-faria-cartrack 3227d39
refactor: add tests for satisfies operator for arrays
rodrigo-faria-cartrack 472e40c
chore: format code
rodrigo-faria-cartrack 1c815c2
feat: add support for satisfies operator in CodegenReactiveFunction
rodrigo-faria-cartrack 29beb05
refactor(compiler): properly support satisfies operator in type cast …
rodrigo-faria-cartrack File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
71 changes: 71 additions & 0 deletions
71
...__/fixtures/compiler/type-annotations/type-annotation-satisfies-array.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,71 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
// @enableUseTypeAnnotations | ||
function Component(props: {id: number}) { | ||
const x = makeArray(props.id) satisfies number[]; | ||
const y = x.at(0); | ||
return y; | ||
} | ||
|
||
function makeArray<T>(x: T): Array<T> { | ||
return [x]; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{id: 42}], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; // @enableUseTypeAnnotations | ||
function Component(props) { | ||
const $ = _c(4); | ||
let t0; | ||
if ($[0] !== props.id) { | ||
t0 = makeArray(props.id); | ||
$[0] = props.id; | ||
$[1] = t0; | ||
} else { | ||
t0 = $[1]; | ||
} | ||
const x = t0 satisfies number[]; | ||
let t1; | ||
if ($[2] !== x) { | ||
t1 = x.at(0); | ||
$[2] = x; | ||
$[3] = t1; | ||
} else { | ||
t1 = $[3]; | ||
} | ||
const y = t1; | ||
return y; | ||
} | ||
|
||
function makeArray(x) { | ||
const $ = _c(2); | ||
let t0; | ||
if ($[0] !== x) { | ||
t0 = [x]; | ||
$[0] = x; | ||
$[1] = t0; | ||
} else { | ||
t0 = $[1]; | ||
} | ||
return t0; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{ id: 42 }], | ||
}; | ||
|
||
``` | ||
|
||
### Eval output | ||
(kind: ok) 42 |
15 changes: 15 additions & 0 deletions
15
...piler/src/__tests__/fixtures/compiler/type-annotations/type-annotation-satisfies-array.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,15 @@ | ||
// @enableUseTypeAnnotations | ||
function Component(props: {id: number}) { | ||
const x = makeArray(props.id) satisfies number[]; | ||
const y = x.at(0); | ||
return y; | ||
} | ||
|
||
function makeArray<T>(x: T): Array<T> { | ||
return [x]; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{id: 42}], | ||
}; |
41 changes: 41 additions & 0 deletions
41
..._/fixtures/compiler/type-annotations/type-annotation-satisfies-number.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,41 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
// @enableUseTypeAnnotations | ||
import {identity} from 'shared-runtime'; | ||
|
||
function Component(props: {id: number}) { | ||
const x = identity(props.id); | ||
const y = x satisfies number; | ||
return y; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{id: 42}], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
// @enableUseTypeAnnotations | ||
import { identity } from "shared-runtime"; | ||
|
||
function Component(props) { | ||
const x = identity(props.id); | ||
const y = x satisfies number; | ||
return y; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{ id: 42 }], | ||
}; | ||
|
||
``` | ||
|
||
### Eval output | ||
(kind: ok) 42 |
13 changes: 13 additions & 0 deletions
13
...iler/src/__tests__/fixtures/compiler/type-annotations/type-annotation-satisfies-number.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,13 @@ | ||
// @enableUseTypeAnnotations | ||
import {identity} from 'shared-runtime'; | ||
|
||
function Component(props: {id: number}) { | ||
const x = identity(props.id); | ||
const y = x satisfies number; | ||
return y; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{id: 42}], | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to make it so that it wouldn't be possible to have a 'satisfies' annotation kind when the annotation was
t.FlowType
.Hence why I opted for this slightly more complex union FYI @mofeiZ