@samitouri / QOS-React-2 / commits / ff8868e8d1

Fix self-closing jsx element codegen

We were never emitting self-closing jsx elements because children were never null, we now set children to null if they were empty in the AST.

Joe Savona committed Mar 17, 2023 at 16:18 UTC ff8868e8d151b30d10783cd7b6f3af63a187429e
25 files changed +26 -26
compiler/forget/src/HIR/BuildHIR.ts
+1 -1
@@ -1439,7 +1439,7 @@ function lowerExpression(
1439 kind: "JsxExpression",
1440 tag,
1441 props,
1442 - children,
1442 + children: children.length === 0 ? null : children,
1443 loc: exprLoc,
1444 };
1445 }
compiler/forget/src/__tests__/fixtures/compiler/call.expect.md
+1 -1
@@ -38,7 +38,7 @@ function Component(props) {
38 }
39 let t0;
40 if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
41 - t0 = <div a={a} b={b}></div>;
41 + t0 = <div a={a} b={b} />;
42 $[2] = t0;
43 } else {
44 t0 = $[2];
compiler/forget/src/__tests__/fixtures/compiler/capture-func-passed-to-jsx.expect.md
+1 -1
@@ -59,7 +59,7 @@ function component(a, b) {
59 const c_7 = $[7] !== x;
60 let t3;
61 if (c_7) {
62 - t3 = <Foo x={x}></Foo>;
62 + t3 = <Foo x={x} />;
63 $[7] = x;
64 $[8] = t3;
65 } else {
compiler/forget/src/__tests__/fixtures/compiler/capturing-function-member-expr-call.expect.md
+1 -1
@@ -50,7 +50,7 @@ function component(t27) {
50 const c_5 = $[5] !== hide;
51 let t2;
52 if (c_4 || c_5) {
53 - t2 = <Foo poke={poke} hide={hide}></Foo>;
53 + t2 = <Foo poke={poke} hide={hide} />;
54 $[4] = poke;
55 $[5] = hide;
56 $[6] = t2;
compiler/forget/src/__tests__/fixtures/compiler/concise-arrow-expr.expect.md
+1 -1
@@ -29,7 +29,7 @@ function component() {
29 const c_2 = $[2] !== handler;
30 let t1;
31 if (c_2) {
32 - t1 = <Foo handler={handler}></Foo>;
32 + t1 = <Foo handler={handler} />;
33 $[2] = handler;
34 $[3] = t1;
35 } else {
compiler/forget/src/__tests__/fixtures/compiler/conditional-on-mutable.expect.md
+2 -2
@@ -59,7 +59,7 @@ function ComponentA(props) {
59 const c_4 = $[4] !== b;
60 let t0;
61 if (c_3 || c_4) {
62 - t0 = <Foo a={a} b={b}></Foo>;
62 + t0 = <Foo a={a} b={b} />;
63 $[3] = a;
64 $[4] = b;
65 $[5] = t0;
@@ -94,7 +94,7 @@ function ComponentB(props) {
94 const c_4 = $[4] !== b;
95 let t0;
96 if (c_3 || c_4) {
97 - t0 = <Foo a={a} b={b}></Foo>;
97 + t0 = <Foo a={a} b={b} />;
98 $[3] = a;
99 $[4] = b;
100 $[5] = t0;
compiler/forget/src/__tests__/fixtures/compiler/constructor.expect.md
+1 -1
@@ -37,7 +37,7 @@ function Component(props) {
37 }
38 let t0;
39 if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
40 - t0 = <div a={a} b={b}></div>;
40 + t0 = <div a={a} b={b} />;
41 $[2] = t0;
42 } else {
43 t0 = $[2];
compiler/forget/src/__tests__/fixtures/compiler/controlled-input.expect.md
+1 -1
@@ -30,7 +30,7 @@ function component() {
30 const c_3 = $[3] !== x;
31 let t1;
32 if (c_2 || c_3) {
33 - t1 = <input onChange={handler} value={x}></input>;
33 + t1 = <input onChange={handler} value={x} />;
34 $[2] = handler;
35 $[3] = x;
36 $[4] = t1;
compiler/forget/src/__tests__/fixtures/compiler/escape-analysis-destructured-rest-element.expect.md
+1 -1
@@ -39,7 +39,7 @@ function Component(props) {
39 const c_5 = $[5] !== d;
40 let t0;
41 if (c_4 || c_5) {
42 - t0 = <div b={b} d={d}></div>;
42 + t0 = <div b={b} d={d} />;
43 $[4] = b;
44 $[5] = d;
45 $[6] = t0;
compiler/forget/src/__tests__/fixtures/compiler/independent-across-if.expect.md
+1 -1
@@ -82,7 +82,7 @@ function Component(props) {
82 const c_6 = $[6] !== b;
83 let t0;
84 if (c_5 || c_6) {
85 - t0 = <Foo a={a} b={b}></Foo>;
85 + t0 = <Foo a={a} b={b} />;
86 $[5] = a;
87 $[6] = b;
88 $[7] = t0;
compiler/forget/src/__tests__/fixtures/compiler/independent.expect.md
+1 -1
@@ -63,7 +63,7 @@ function Component(props) {
63 const c_5 = $[5] !== b;
64 let t2;
65 if (c_4 || c_5) {
66 - t2 = <Foo a={a} b={b}></Foo>;
66 + t2 = <Foo a={a} b={b} />;
67 $[4] = a;
68 $[5] = b;
69 $[6] = t2;
compiler/forget/src/__tests__/fixtures/compiler/interdependent-across-if.expect.md
+1 -1
@@ -70,7 +70,7 @@ function Component(props) {
70 const c_6 = $[6] !== b;
71 let t0;
72 if (c_5 || c_6) {
73 - t0 = <Foo a={a} b={b}></Foo>;
73 + t0 = <Foo a={a} b={b} />;
74 $[5] = a;
75 $[6] = b;
76 $[7] = t0;
compiler/forget/src/__tests__/fixtures/compiler/interdependent.expect.md
+1 -1
@@ -58,7 +58,7 @@ function Component(props) {
58 const c_5 = $[5] !== b;
59 let t0;
60 if (c_4 || c_5) {
61 - t0 = <Foo a={a} b={b}></Foo>;
61 + t0 = <Foo a={a} b={b} />;
62 $[4] = a;
63 $[5] = b;
64 $[6] = t0;
compiler/forget/src/__tests__/fixtures/compiler/jsx-member-expression.expect.md
+1 -1
@@ -19,7 +19,7 @@ function Component(props) {
19 const $ = React.unstable_useMemoCache(2);
20 let t0;
21 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
22 - t0 = <Foo.Bar.Baz></Foo.Bar.Baz>;
22 + t0 = <Foo.Bar.Baz />;
23 $[0] = t0;
24 } else {
25 t0 = $[0];
compiler/forget/src/__tests__/fixtures/compiler/jsx-spread.expect.md
+1 -1
@@ -30,7 +30,7 @@ function Component(props) {
30 const c_3 = $[3] !== t1;
31 let t2;
32 if (c_2 || c_3) {
33 - t2 = <Component {...props} {...t1}></Component>;
33 + t2 = <Component {...props} {...t1} />;
34 $[2] = props;
35 $[3] = t1;
36 $[4] = t2;
compiler/forget/src/__tests__/fixtures/compiler/property-assignment.expect.md
+1 -1
@@ -26,7 +26,7 @@ function Component(props) {
26 const y = [];
27 x.y = y;
28
29 - child = <Component data={y}></Component>;
29 + child = <Component data={y} />;
30 x.y.push(props.p0);
31 $[0] = props.p0;
32 $[1] = x;
compiler/forget/src/__tests__/fixtures/compiler/reassignment-conditional.expect.md
+1 -1
@@ -51,7 +51,7 @@ function Component(props) {
51 const c_4 = $[4] !== y;
52 let t1;
53 if (c_3 || c_4) {
54 - t1 = <Component x={x} y={y}></Component>;
54 + t1 = <Component x={x} y={y} />;
55 $[3] = x;
56 $[4] = y;
57 $[5] = t1;
compiler/forget/src/__tests__/fixtures/compiler/reassignment.expect.md
+1 -1
@@ -52,7 +52,7 @@ function Component(props) {
52 const c_6 = $[6] !== y;
53 let t1;
54 if (c_5 || c_6) {
55 - t1 = <Component x={x} y={y}></Component>;
55 + t1 = <Component x={x} y={y} />;
56 $[5] = x;
57 $[6] = y;
58 $[7] = t1;
compiler/forget/src/__tests__/fixtures/compiler/ssa-call-jsx-2.expect.md
+1 -1
@@ -44,7 +44,7 @@ function Component(props) {
44 }
45 let t0;
46 if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
47 - t0 = <div a={a} b={b}></div>;
47 + t0 = <div a={a} b={b} />;
48 $[2] = t0;
49 } else {
50 t0 = $[2];
compiler/forget/src/__tests__/fixtures/compiler/ssa-call-jsx.expect.md
+1 -1
@@ -38,7 +38,7 @@ function Component(props) {
38 }
39 let t0;
40 if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
41 - t0 = <div a={a} b={b}></div>;
41 + t0 = <div a={a} b={b} />;
42 $[2] = t0;
43 } else {
44 t0 = $[2];
compiler/forget/src/__tests__/fixtures/compiler/switch-non-final-default.expect.md
+1 -1
@@ -71,7 +71,7 @@ function Component(props) {
71 const c_4 = $[4] !== x;
72 let t1;
73 if (c_4) {
74 - t1 = <Component data={x}></Component>;
74 + t1 = <Component data={x} />;
75 $[4] = x;
76 $[5] = t1;
77 } else {
compiler/forget/src/__tests__/fixtures/compiler/switch.expect.md
+1 -1
@@ -52,7 +52,7 @@ function Component(props) {
52 const c_3 = $[3] !== x;
53 let t0;
54 if (c_3) {
55 - t0 = <Component data={x}></Component>;
55 + t0 = <Component data={x} />;
56 $[3] = x;
57 $[4] = t0;
58 } else {
compiler/forget/src/__tests__/fixtures/compiler/use-callback-simple.expect.md
+1 -1
@@ -32,7 +32,7 @@ function component() {
32 const c_3 = $[3] !== increment;
33 let t1;
34 if (c_3) {
35 - t1 = <Foo onClick={increment}></Foo>;
35 + t1 = <Foo onClick={increment} />;
36 $[3] = increment;
37 $[4] = t1;
38 } else {
compiler/forget/src/__tests__/fixtures/compiler/useMemo-simple.expect.md
+1 -1
@@ -27,7 +27,7 @@ function component(a) {
27 const c_2 = $[2] !== x;
28 let t1;
29 if (c_2) {
30 - t1 = <Foo x={x}></Foo>;
30 + t1 = <Foo x={x} />;
31 $[2] = x;
32 $[3] = t1;
33 } else {
compiler/forget/src/__tests__/fixtures/disableMemoizeJsxElements/Component.expect.md
+1 -1
@@ -34,7 +34,7 @@ function Component(props) {
34 t0 = $[1];
35 }
36 const onChange = t0;
37 - return <form>{<input onChange={onChange} value={name}></input>}</form>;
37 + return <form>{<input onChange={onChange} value={name} />}</form>;
38 }
39
40 ```