@samitouri / QOS-React-2 / commits / 9eb9071aed

[typer] Add type inference for unary expr

Sathya Gunasekaran committed Jan 25, 2023 at 11:11 UTC 9eb9071aedebd6c282c64c341de13978db370106
2 files changed +11 -20
compiler/forget/src/TypeInference/InferTypes.ts
+5
@@ -103,6 +103,11 @@ function generateTypeEquation(instr: Instruction): Array<TypeEquation> {
103 break;
104 }
105
106 + case "UnaryExpression": {
107 + add(left, { kind: "Primitive" });
108 + break;
109 + }
110 +
111 case "Identifier": {
112 add(left, value.identifier.type);
113 break;
compiler/forget/src/__tests__/fixtures/hir/unary-expr.expect.md
+6 -20
@@ -93,28 +93,14 @@ function component(a) {
93 } else {
94 f = $[15];
95 }
96 - const c_16 = $[16] !== z;
97 - const c_17 = $[17] !== p;
98 - const c_18 = $[18] !== q;
99 - const c_19 = $[19] !== n;
100 - const c_20 = $[20] !== m;
101 - const c_21 = $[21] !== e;
102 - const c_22 = $[22] !== f;
103 - let t23;
104 - if (c_16 || c_17 || c_18 || c_19 || c_20 || c_21 || c_22) {
105 - t23 = { z: z, p: p, q: q, n: n, m: m, e: e, f: f };
106 - $[16] = z;
107 - $[17] = p;
108 - $[18] = q;
109 - $[19] = n;
110 - $[20] = m;
111 - $[21] = e;
112 - $[22] = f;
113 - $[23] = t23;
96 + let t16;
97 + if ($[16] === Symbol.for("react.memo_cache_sentinel")) {
98 + t16 = { z: z, p: p, q: q, n: n, m: m, e: e, f: f };
99 + $[16] = t16;
100 } else {
115 - t23 = $[23];
101 + t16 = $[16];
102 }
117 - return t23;
103 + return t16;
104 }
105
106 ```