diff --git a/compiler/forget/src/ReactiveScopes/BuildReactiveFunction.ts b/compiler/forget/src/ReactiveScopes/BuildReactiveFunction.ts index 3d5427f212..2935b6c164 100644 --- a/compiler/forget/src/ReactiveScopes/BuildReactiveFunction.ts +++ b/compiler/forget/src/ReactiveScopes/BuildReactiveFunction.ts @@ -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 }, diff --git a/compiler/forget/src/__tests__/fixtures/compiler/unused-logical-assigned-to-variable.expect.md b/compiler/forget/src/__tests__/fixtures/compiler/unused-logical-assigned-to-variable.expect.md new file mode 100644 index 0000000000..f5a49dd240 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/compiler/unused-logical-assigned-to-variable.expect.md @@ -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; +} + +``` + \ No newline at end of file diff --git a/compiler/forget/src/__tests__/fixtures/compiler/unused-logical-assigned-to-variable.js b/compiler/forget/src/__tests__/fixtures/compiler/unused-logical-assigned-to-variable.js new file mode 100644 index 0000000000..509d7069cd --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/compiler/unused-logical-assigned-to-variable.js @@ -0,0 +1,7 @@ +function Component(props) { + // unused! + const obj = makeObject(); + const obj2 = makeObject(); + const _ = (obj.a ?? obj2.b) || props.c; + return null; +} diff --git a/compiler/forget/src/__tests__/fixtures/compiler/unused-optional-method-assigned-to-variable.expect.md b/compiler/forget/src/__tests__/fixtures/compiler/unused-optional-method-assigned-to-variable.expect.md new file mode 100644 index 0000000000..ca0a6c9433 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/compiler/unused-optional-method-assigned-to-variable.expect.md @@ -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; +} + +``` + \ No newline at end of file diff --git a/compiler/forget/src/__tests__/fixtures/compiler/unused-optional-method-assigned-to-variable.js b/compiler/forget/src/__tests__/fixtures/compiler/unused-optional-method-assigned-to-variable.js new file mode 100644 index 0000000000..250da966e1 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/compiler/unused-optional-method-assigned-to-variable.js @@ -0,0 +1,6 @@ +function Component(props) { + // unused! + const obj = makeObject(); + const _ = obj.a?.b?.(props.c); + return null; +} diff --git a/compiler/forget/src/__tests__/fixtures/compiler/unused-ternary-assigned-to-variable.expect.md b/compiler/forget/src/__tests__/fixtures/compiler/unused-ternary-assigned-to-variable.expect.md new file mode 100644 index 0000000000..374d8d9103 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/compiler/unused-ternary-assigned-to-variable.expect.md @@ -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; +} + +``` + \ No newline at end of file diff --git a/compiler/forget/src/__tests__/fixtures/compiler/unused-ternary-assigned-to-variable.js b/compiler/forget/src/__tests__/fixtures/compiler/unused-ternary-assigned-to-variable.js new file mode 100644 index 0000000000..957a723f57 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/compiler/unused-ternary-assigned-to-variable.js @@ -0,0 +1,6 @@ +function Component(props) { + // unused! + const obj = makeObject(); + const _ = obj.a ? props.b : props.c; + return null; +}