Convert value block terminal invariant to todo
Joe Savona committed
Dec 12, 2023 at 16:52 UTC
873a286029b86a9696b4f4fae9e465e8ace6d44f
7 files changed
+103
-19
compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/BuildReactiveFunction.ts
+24
-18
@@ -940,12 +940,14 @@ class Driver {
940
case "optional": {
941
const test = this.visitValueBlock(terminal.test, terminal.loc);
942
const testBlock = this.cx.ir.blocks.get(test.block)!;
943
- CompilerError.invariant(testBlock.terminal.kind === "branch", {
944
- reason: `Unexpected terminal kind '${testBlock.terminal.kind}' for optional call test block`,
945
- description: null,
946
- loc: testBlock.terminal.loc,
947
- suggestions: null,
948
- });
943
+ if (testBlock.terminal.kind !== "branch") {
944
+ CompilerError.throwTodo({
945
+ reason: `Unexpected terminal kind '${testBlock.terminal.kind}' for optional test block`,
946
+ description: null,
947
+ loc: testBlock.terminal.loc,
948
+ suggestions: null,
949
+ });
950
+ }
951
const consequent = this.visitValueBlock(
952
testBlock.terminal.consequent,
953
terminal.loc
@@ -980,12 +982,14 @@ class Driver {
982
case "logical": {
983
const test = this.visitValueBlock(terminal.test, terminal.loc);
984
const testBlock = this.cx.ir.blocks.get(test.block)!;
983
- CompilerError.invariant(testBlock.terminal.kind === "branch", {
984
- reason: `Unexpected terminal kind '${testBlock.terminal.kind}' for logical test block`,
985
- description: null,
986
- loc: testBlock.terminal.loc,
987
- suggestions: null,
988
- });
985
+ if (testBlock.terminal.kind !== "branch") {
986
+ CompilerError.throwTodo({
987
+ reason: `Unexpected terminal kind '${testBlock.terminal.kind}' for logical test block`,
988
+ description: null,
989
+ loc: testBlock.terminal.loc,
990
+ suggestions: null,
991
+ });
992
+ }
993
994
const leftFinal = this.visitValueBlock(
995
testBlock.terminal.consequent,
@@ -1026,12 +1030,14 @@ class Driver {
1030
case "ternary": {
1031
const test = this.visitValueBlock(terminal.test, terminal.loc);
1032
const testBlock = this.cx.ir.blocks.get(test.block)!;
1029
- CompilerError.invariant(testBlock.terminal.kind === "branch", {
1030
- reason: `Unexpected terminal kind '${testBlock.terminal.kind}' for ternary test block`,
1031
- description: null,
1032
- loc: testBlock.terminal.loc,
1033
- suggestions: null,
1034
- });
1033
+ if (testBlock.terminal.kind !== "branch") {
1034
+ CompilerError.throwTodo({
1035
+ reason: `Unexpected terminal kind '${testBlock.terminal.kind}' for ternary test block`,
1036
+ description: null,
1037
+ loc: testBlock.terminal.loc,
1038
+ suggestions: null,
1039
+ });
1040
+ }
1041
const consequent = this.visitValueBlock(
1042
testBlock.terminal.consequent,
1043
terminal.loc
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-optional-call-chain-in-logical-expr.expect.md
renamed
+1
-1
@@ -20,7 +20,7 @@ export const FIXTURE_ENTRYPONT = {
20
## Error
21
22
```
23
-[ReactForget] Invariant: Unexpected terminal kind 'optional' for logical test block (5:5)
23
+[ReactForget] Todo: Unexpected terminal kind 'optional' for logical test block (5:5)
24
```
25
26
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-optional-call-chain-in-logical-expr.ts
renamed
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-optional-call-chain-in-optional.expect.md
new
+28
@@ -0,0 +1,28 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+function useFoo(props: { value: { x: string; y: string } | null }) {
6
+ const value = props.value;
7
+ return createArray(value?.x, value?.y)?.join(", ");
8
+}
9
+
10
+function createArray<T>(...args: Array<T>): Array<T> {
11
+ return args;
12
+}
13
+
14
+export const FIXTURE_ENTRYPONT = {
15
+ fn: useFoo,
16
+ props: [{ value: null }],
17
+};
18
+
19
+```
20
+
21
+
22
+## Error
23
+
24
+```
25
+[ReactForget] Todo: Unexpected terminal kind 'optional' for optional test block (3:3)
26
+```
27
+
28
+
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-optional-call-chain-in-optional.ts
new
+13
@@ -0,0 +1,13 @@
1
+function useFoo(props: { value: { x: string; y: string } | null }) {
2
+ const value = props.value;
3
+ return createArray(value?.x, value?.y)?.join(", ");
4
+}
5
+
6
+function createArray<T>(...args: Array<T>): Array<T> {
7
+ return args;
8
+}
9
+
10
+export const FIXTURE_ENTRYPONT = {
11
+ fn: useFoo,
12
+ props: [{ value: null }],
13
+};
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-optional-call-chain-in-ternary.expect.md
new
+26
@@ -0,0 +1,26 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+import { useNoAlias } from "shared-runtime";
6
+
7
+function useFoo(props: { value: { x: string; y: string } | null }) {
8
+ const value = props.value;
9
+ return useNoAlias(value?.x, value?.y) ? {} : null;
10
+}
11
+
12
+export const FIXTURE_ENTRYPONT = {
13
+ fn: useFoo,
14
+ props: [{ value: null }],
15
+};
16
+
17
+```
18
+
19
+
20
+## Error
21
+
22
+```
23
+[ReactForget] Todo: Unexpected terminal kind 'optional' for ternary test block (5:5)
24
+```
25
+
26
+
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-optional-call-chain-in-ternary.ts
new
+11
@@ -0,0 +1,11 @@
1
+import { useNoAlias } from "shared-runtime";
2
+
3
+function useFoo(props: { value: { x: string; y: string } | null }) {
4
+ const value = props.value;
5
+ return useNoAlias(value?.x, value?.y) ? {} : null;
6
+}
7
+
8
+export const FIXTURE_ENTRYPONT = {
9
+ fn: useFoo,
10
+ props: [{ value: null }],
11
+};