mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
More precise error for canonical reassignment in a value block
These examples previously errored all the way in codegen, when we detected that a value block (eg a `while` test expression) was declaring a new variable. We now detect this in LeaveSSA and error. The actual fix is a bit tricky, we'd need to add a new declaration in the nearest block scope (or selectively not DCE the declaration if its reassigned in just this way).
This commit is contained in:
@@ -137,6 +137,12 @@ export function leaveSSA(fn: HIRFunction): void {
|
||||
originalLVal === undefined ||
|
||||
originalLVal.lvalue === value.lvalue // in case this was pre-declared for the `for` initializer
|
||||
) {
|
||||
if (originalLVal === undefined && block.kind !== "block") {
|
||||
CompilerError.invariant(
|
||||
`TODO: Handle reassignment in a value block where the original declaration was removed by dead code elimination (DCE)`,
|
||||
value.lvalue.place.loc
|
||||
);
|
||||
}
|
||||
declarations.set(value.lvalue.place.identifier.name, {
|
||||
lvalue: value.lvalue,
|
||||
place: value.lvalue.place,
|
||||
@@ -170,6 +176,12 @@ export function leaveSSA(fn: HIRFunction): void {
|
||||
originalLVal === undefined ||
|
||||
originalLVal.lvalue === value.lvalue
|
||||
) {
|
||||
if (originalLVal === undefined && block.kind !== "block") {
|
||||
CompilerError.invariant(
|
||||
`TODO: Handle reassignment in a value block where the original declaration was removed by dead code elimination (DCE)`,
|
||||
place.loc
|
||||
);
|
||||
}
|
||||
declarations.set(place.identifier.name, {
|
||||
lvalue: value.lvalue,
|
||||
place,
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ function f(reader) {
|
||||
## Error
|
||||
|
||||
```
|
||||
[ReactForget] Todo: (CodegenReactiveFunction::codegenInstructionValue) Cannot declare variables in a value block, tried to declare 'value'
|
||||
[ReactForget] Invariant: TODO: Handle reassignment in a value block where the original declaration was removed by dead code elimination (DCE) (6:6)
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user