-
Notifications
You must be signed in to change notification settings - Fork 49.2k
compiler: fix for calls on builtin jsx/function types #29624
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
Merged
josephsavona
merged 3 commits into
gh/josephsavona/19/base
from
gh/josephsavona/19/head
May 28, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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
61 changes: 61 additions & 0 deletions
61
...ugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbt-to-string.expect.md
This file contains hidden or 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,61 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
import fbt from "fbt"; | ||
|
||
function Component(props) { | ||
const element = ( | ||
<fbt desc={"Dialog to show to user"}> | ||
Hello <fbt:param name="user name">{props.name}</fbt:param> | ||
</fbt> | ||
); | ||
return element.toString(); | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{ name: "Jason" }], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; | ||
import fbt from "fbt"; | ||
|
||
function Component(props) { | ||
const $ = _c(4); | ||
let t0; | ||
if ($[0] !== props.name) { | ||
t0 = fbt._("Hello {user name}", [fbt._param("user name", props.name)], { | ||
hk: "2zEDKF", | ||
}); | ||
$[0] = props.name; | ||
$[1] = t0; | ||
} else { | ||
t0 = $[1]; | ||
} | ||
const element = t0; | ||
let t1; | ||
if ($[2] !== element) { | ||
t1 = element.toString(); | ||
$[2] = element; | ||
$[3] = t1; | ||
} else { | ||
t1 = $[3]; | ||
} | ||
return t1; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{ name: "Jason" }], | ||
}; | ||
|
||
``` | ||
|
||
### Eval output | ||
(kind: ok) "Hello Jason" |
15 changes: 15 additions & 0 deletions
15
...packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbt-to-string.js
This file contains hidden or 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 @@ | ||
import fbt from "fbt"; | ||
|
||
function Component(props) { | ||
const element = ( | ||
<fbt desc={"Dialog to show to user"}> | ||
Hello <fbt:param name="user name">{props.name}</fbt:param> | ||
</fbt> | ||
); | ||
return element.toString(); | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{ name: "Jason" }], | ||
}; |
92 changes: 92 additions & 0 deletions
92
...tests__/fixtures/compiler/function-expression-prototype-call-mutating.expect.md
This file contains hidden or 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,92 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
import { useMemo } from "react"; | ||
import { ValidateMemoization } from "shared-runtime"; | ||
|
||
function Component(props) { | ||
const a = useMemo(() => { | ||
const a = []; | ||
const f = function () { | ||
a.push(props.name); | ||
}; | ||
f.call(); | ||
return a; | ||
}, [props.name]); | ||
return <ValidateMemoization inputs={[props.name]} output={a} />; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{ name: "Jason" }], | ||
sequentialRenders: [ | ||
{ name: "Lauren" }, | ||
{ name: "Lauren" }, | ||
{ name: "Jason" }, | ||
], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; | ||
import { useMemo } from "react"; | ||
import { ValidateMemoization } from "shared-runtime"; | ||
|
||
function Component(props) { | ||
const $ = _c(7); | ||
let t0; | ||
let a; | ||
if ($[0] !== props.name) { | ||
a = []; | ||
const f = function () { | ||
a.push(props.name); | ||
}; | ||
|
||
f.call(); | ||
$[0] = props.name; | ||
$[1] = a; | ||
} else { | ||
a = $[1]; | ||
} | ||
t0 = a; | ||
const a_0 = t0; | ||
let t1; | ||
if ($[2] !== props.name) { | ||
t1 = [props.name]; | ||
$[2] = props.name; | ||
$[3] = t1; | ||
} else { | ||
t1 = $[3]; | ||
} | ||
let t2; | ||
if ($[4] !== t1 || $[5] !== a_0) { | ||
t2 = <ValidateMemoization inputs={t1} output={a_0} />; | ||
$[4] = t1; | ||
$[5] = a_0; | ||
$[6] = t2; | ||
} else { | ||
t2 = $[6]; | ||
} | ||
return t2; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{ name: "Jason" }], | ||
sequentialRenders: [ | ||
{ name: "Lauren" }, | ||
{ name: "Lauren" }, | ||
{ name: "Jason" }, | ||
], | ||
}; | ||
|
||
``` | ||
|
||
### Eval output | ||
(kind: ok) <div>{"inputs":["Lauren"],"output":["Lauren"]}</div> | ||
<div>{"inputs":["Lauren"],"output":["Lauren"]}</div> | ||
<div>{"inputs":["Jason"],"output":["Jason"]}</div> |
24 changes: 24 additions & 0 deletions
24
...t-compiler/src/__tests__/fixtures/compiler/function-expression-prototype-call-mutating.js
This file contains hidden or 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,24 @@ | ||
import { useMemo } from "react"; | ||
import { ValidateMemoization } from "shared-runtime"; | ||
|
||
function Component(props) { | ||
const a = useMemo(() => { | ||
const a = []; | ||
const f = function () { | ||
a.push(props.name); | ||
}; | ||
f.call(); | ||
return a; | ||
}, [props.name]); | ||
return <ValidateMemoization inputs={[props.name]} output={a} />; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{ name: "Jason" }], | ||
sequentialRenders: [ | ||
{ name: "Lauren" }, | ||
{ name: "Lauren" }, | ||
{ name: "Jason" }, | ||
], | ||
}; |
55 changes: 55 additions & 0 deletions
55
...er/src/__tests__/fixtures/compiler/function-expression-prototype-call.expect.md
This file contains hidden or 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,55 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
function Component(props) { | ||
const f = function () { | ||
return <div>{props.name}</div>; | ||
}; | ||
return f.call(); | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{ name: "Jason" }], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; | ||
function Component(props) { | ||
const $ = _c(4); | ||
let t0; | ||
if ($[0] !== props.name) { | ||
t0 = function () { | ||
return <div>{props.name}</div>; | ||
}; | ||
$[0] = props.name; | ||
$[1] = t0; | ||
} else { | ||
t0 = $[1]; | ||
} | ||
const f = t0; | ||
let t1; | ||
if ($[2] !== f) { | ||
t1 = f.call(); | ||
$[2] = f; | ||
$[3] = t1; | ||
} else { | ||
t1 = $[3]; | ||
} | ||
return t1; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{ name: "Jason" }], | ||
}; | ||
|
||
``` | ||
|
||
### Eval output | ||
(kind: ok) <div>Jason</div> |
11 changes: 11 additions & 0 deletions
11
...ugin-react-compiler/src/__tests__/fixtures/compiler/function-expression-prototype-call.js
This file contains hidden or 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,11 @@ | ||
function Component(props) { | ||
const f = function () { | ||
return <div>{props.name}</div>; | ||
}; | ||
return f.call(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. failed previously because |
||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{ name: "Jason" }], | ||
}; |
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.
failed previously because element has the inferred type BuiltInJsx, which didn't have a shape definition