mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Support unused conditional/logical expressions assigned to variable
I noticed some instances of this error when running forget on an internal product. I previously fixed the case if a logical/conditional used only for side effects (not assigned to a variable) but the new cases were assigned to an unused variable. I double-checked and we’ve actually fixed all the steps after these invariants so we can just remove them and support these cases.
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
*/
|
||||
|
||||
import invariant from "invariant";
|
||||
import { CompilerError } from "../CompilerError";
|
||||
import {
|
||||
BasicBlock,
|
||||
BlockId,
|
||||
@@ -826,12 +825,6 @@ class Driver {
|
||||
testBlock.terminal.alternate,
|
||||
terminal.loc
|
||||
);
|
||||
if (leftFinal.place.identifier !== right.place.identifier) {
|
||||
CompilerError.todo(
|
||||
"TODO: Support LogicalExpression whose value is unused",
|
||||
leftFinal.place.loc
|
||||
);
|
||||
}
|
||||
const value: ReactiveLogicalValue = {
|
||||
kind: "LogicalExpression",
|
||||
operator: terminal.operator,
|
||||
@@ -869,12 +862,6 @@ class Driver {
|
||||
alternate: alternate.value,
|
||||
loc: terminal.loc,
|
||||
};
|
||||
if (consequent.place.identifier !== alternate.place.identifier) {
|
||||
CompilerError.todo(
|
||||
"TODO: Support ConditionalExpression whose value is unused",
|
||||
consequent.place.loc
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
place: { ...consequent.place },
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
function Component(props) {
|
||||
// unused!
|
||||
const obj = makeObject();
|
||||
const obj2 = makeObject();
|
||||
const _ = (obj.a ?? obj2.b) || props.c;
|
||||
return null;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
function Component(props) {
|
||||
const obj = makeObject();
|
||||
const obj2 = makeObject();
|
||||
(obj.a ?? obj2.b) || props.c;
|
||||
return null;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
function Component(props) {
|
||||
// unused!
|
||||
const obj = makeObject();
|
||||
const obj2 = makeObject();
|
||||
const _ = (obj.a ?? obj2.b) || props.c;
|
||||
return null;
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
function Component(props) {
|
||||
// unused!
|
||||
const obj = makeObject();
|
||||
const _ = obj.a?.b?.(props.c);
|
||||
return null;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
function Component(props) {
|
||||
const obj = makeObject();
|
||||
obj.a?.b?.(props.c);
|
||||
return null;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
function Component(props) {
|
||||
// unused!
|
||||
const obj = makeObject();
|
||||
const _ = obj.a?.b?.(props.c);
|
||||
return null;
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
function Component(props) {
|
||||
// unused!
|
||||
const obj = makeObject();
|
||||
const _ = obj.a ? props.b : props.c;
|
||||
return null;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
function Component(props) {
|
||||
const obj = makeObject();
|
||||
obj.a ? props.b : props.c;
|
||||
return null;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
function Component(props) {
|
||||
// unused!
|
||||
const obj = makeObject();
|
||||
const _ = obj.a ? props.b : props.c;
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user