-
Notifications
You must be signed in to change notification settings - Fork 47k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compiler] Add todo fixtures for local reassignment in an async callback
ghstack-source-id: eca878f62a2149af76a72b59acd1820d0df86f30 Pull Request resolved: #30109
- Loading branch information
1 parent
4c9a2d2
commit 00775d9
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
...tures/compiler/todo.invalid-reassign-local-variable-in-async-callback.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,58 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
function Component() { | ||
let value = null; | ||
const reassign = async () => { | ||
await foo().then((result) => { | ||
// Reassigning a local variable in an async function is *always* mutating | ||
// after render, so this should error regardless of where this ends up | ||
// getting called | ||
value = result; | ||
}); | ||
}; | ||
|
||
const onClick = async () => { | ||
await reassign(); | ||
}; | ||
return <div onClick={onClick}>Click</div>; | ||
} | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; | ||
function Component() { | ||
const $ = _c(2); | ||
let value; | ||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) { | ||
value = null; | ||
$[0] = value; | ||
} else { | ||
value = $[0]; | ||
} | ||
let t0; | ||
if ($[1] === Symbol.for("react.memo_cache_sentinel")) { | ||
const reassign = async () => { | ||
await foo().then((result) => { | ||
value = result; | ||
}); | ||
}; | ||
|
||
const onClick = async () => { | ||
await reassign(); | ||
}; | ||
|
||
t0 = <div onClick={onClick}>Click</div>; | ||
$[1] = t0; | ||
} else { | ||
t0 = $[1]; | ||
} | ||
return t0; | ||
} | ||
|
||
``` | ||
16 changes: 16 additions & 0 deletions
16
...src/__tests__/fixtures/compiler/todo.invalid-reassign-local-variable-in-async-callback.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,16 @@ | ||
function Component() { | ||
let value = null; | ||
const reassign = async () => { | ||
await foo().then((result) => { | ||
// Reassigning a local variable in an async function is *always* mutating | ||
// after render, so this should error regardless of where this ends up | ||
// getting called | ||
value = result; | ||
}); | ||
}; | ||
|
||
const onClick = async () => { | ||
await reassign(); | ||
}; | ||
return <div onClick={onClick}>Click</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