@samitouri / QOS-React-2 / commits / 4b3b498e37

Collect bailouts in BuildHIR::lowerJsxElementName

Lauren Tan committed Jan 20, 2023 at 11:47 UTC 4b3b498e37d70a451697e801a949bb5225c6dcb3
3 files changed +80 -50
compiler/forget/src/HIR/BuildHIR.ts
+21 -2
@@ -1500,8 +1500,27 @@ function lowerJsxElementName(
1500 t.JSXIdentifier | t.JSXMemberExpression | t.JSXNamespacedName
1501 >
1502 ): Place {
1503 - todoInvariant(exprPath.isJSXIdentifier(), "handle non-identifier tags");
1504 - const exprLoc = exprPath.node.loc ?? GeneratedSource;
1503 + const exprNode = exprPath.node;
1504 + const exprLoc = exprNode.loc ?? GeneratedSource;
1505 + if (!exprPath.isJSXIdentifier()) {
1506 + builder.pushError({
1507 + reason: "Handle non-identifier tags",
1508 + severity: ErrorSeverity.Todo,
1509 + nodePath: exprPath,
1510 + });
1511 + const place: Place = buildTemporaryPlace(builder, exprLoc);
1512 + builder.push({
1513 + id: makeInstructionId(0),
1514 + value: {
1515 + kind: "UnsupportedNode",
1516 + node: exprNode,
1517 + loc: exprLoc,
1518 + },
1519 + loc: exprLoc,
1520 + lvalue: { place: { ...place }, kind: InstructionKind.Const },
1521 + });
1522 + return { ...place };
1523 + }
1524 const tag: string = exprPath.node.name;
1525 if (tag.match(/^[A-Z]/)) {
1526 const identifier = builder.resolveIdentifier(exprPath);
compiler/forget/src/__tests__/fixtures/hir/error.todo-kitchensink.expect.md
+58 -48
@@ -25,6 +25,7 @@ function foo([a, b], { c, d, e = "e" }, f = "f", ...args) {
25 <Button {...args}></Button>;
26 <Button xlink:href="localhost:3000"></Button>;
27 <Button haha={1}></Button>;
28 + <DesignSystem.Button />;
29
30 const j = function bar([quz, qux], ...args) {};
31
@@ -148,7 +149,7 @@ function foo([a, b], { c, d, e = "e" }, f = "f", ...args) {
149 | ^^^^^^^^^
150 22 | <Button xlink:href="localhost:3000"></Button>;
151 23 | <Button haha={1}></Button>;
151 - 24 |
152 + 24 | <DesignSystem.Button />;
153
154 [ReactForget] TodoError: Handle non-identifier jsx attribute names
155 20 |
@@ -156,77 +157,86 @@ function foo([a, b], { c, d, e = "e" }, f = "f", ...args) {
157 > 22 | <Button xlink:href="localhost:3000"></Button>;
158 | ^^^^^^^^^^
159 23 | <Button haha={1}></Button>;
159 - 24 |
160 - 25 | const j = function bar([quz, qux], ...args) {};
160 + 24 | <DesignSystem.Button />;
161 + 25 |
162
162 -[ReactForget] TodoError: Handle non identifier params
163 +[ReactForget] TodoError: Handle non-identifier tags
164 + 22 | <Button xlink:href="localhost:3000"></Button>;
165 23 | <Button haha={1}></Button>;
164 - 24 |
165 -> 25 | const j = function bar([quz, qux], ...args) {};
166 +> 24 | <DesignSystem.Button />;
167 + | ^^^^^^^^^^^^^^^^^^^
168 + 25 |
169 + 26 | const j = function bar([quz, qux], ...args) {};
170 + 27 |
171 +
172 +[ReactForget] TodoError: Handle non identifier params
173 + 24 | <DesignSystem.Button />;
174 + 25 |
175 +> 26 | const j = function bar([quz, qux], ...args) {};
176 | ^^^^^^^^^^
167 - 26 |
168 - 27 | for (; i < 3; i += 1) {
169 - 28 | x.push(i);
177 + 27 |
178 + 28 | for (; i < 3; i += 1) {
179 + 29 | x.push(i);
180
181 [ReactForget] TodoError: Handle non identifier params
172 - 23 | <Button haha={1}></Button>;
173 - 24 |
174 -> 25 | const j = function bar([quz, qux], ...args) {};
182 + 24 | <DesignSystem.Button />;
183 + 25 |
184 +> 26 | const j = function bar([quz, qux], ...args) {};
185 | ^^^^^^^
176 - 26 |
177 - 27 | for (; i < 3; i += 1) {
178 - 28 | x.push(i);
186 + 27 |
187 + 28 | for (; i < 3; i += 1) {
188 + 29 | x.push(i);
189
190 [ReactForget] TodoError: Support non-variable initialization in for
181 - 25 | const j = function bar([quz, qux], ...args) {};
182 - 26 |
183 -> 27 | for (; i < 3; i += 1) {
191 + 26 | const j = function bar([quz, qux], ...args) {};
192 + 27 |
193 +> 28 | for (; i < 3; i += 1) {
194 | ^
185 - 28 | x.push(i);
186 - 29 | }
187 - 30 | for (; i < 3; ) {}
195 + 29 | x.push(i);
196 + 30 | }
197 + 31 | for (; i < 3; ) {}
198
199 [ReactForget] TodoError: Support non-variable initialization in for
190 - 28 | x.push(i);
191 - 29 | }
192 -> 30 | for (; i < 3; ) {}
200 + 29 | x.push(i);
201 + 30 | }
202 +> 31 | for (; i < 3; ) {}
203 | ^^^^^^^^^^^^^^^^^^
194 - 31 | for (;;) {}
195 - 32 | }
196 - 33 |
204 + 32 | for (;;) {}
205 + 33 | }
206 + 34 |
207
208 [ReactForget] TodoError: Handle empty for updater
199 - 28 | x.push(i);
200 - 29 | }
201 -> 30 | for (; i < 3; ) {}
209 + 29 | x.push(i);
210 + 30 | }
211 +> 31 | for (; i < 3; ) {}
212 | ^^^^^^^^^^^^^^^^^^
203 - 31 | for (;;) {}
204 - 32 | }
205 - 33 |
213 + 32 | for (;;) {}
214 + 33 | }
215 + 34 |
216
217 [ReactForget] TodoError: Support non-variable initialization in for
208 - 29 | }
209 - 30 | for (; i < 3; ) {}
210 -> 31 | for (;;) {}
218 + 30 | }
219 + 31 | for (; i < 3; ) {}
220 +> 32 | for (;;) {}
221 | ^^^^^^^^^^^
212 - 32 | }
213 - 33 |
222 + 33 | }
223 + 34 |
224
225 [ReactForget] TodoError: Handle empty for updater
216 - 29 | }
217 - 30 | for (; i < 3; ) {}
218 -> 31 | for (;;) {}
226 + 30 | }
227 + 31 | for (; i < 3; ) {}
228 +> 32 | for (;;) {}
229 | ^^^^^^^^^^^
220 - 32 | }
221 - 33 |
230 + 33 | }
231 + 34 |
232
233 [ReactForget] TodoError: ForStatement without test
224 - 29 | }
225 - 30 | for (; i < 3; ) {}
226 -> 31 | for (;;) {}
234 + 30 | }
235 + 31 | for (; i < 3; ) {}
236 +> 32 | for (;;) {}
237 | ^^^^^^^^^^^
228 - 32 | }
229 - 33 |
238 + 33 | }
239 + 34 |
240 ```
241
242
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/error.todo-kitchensink.js
+1
@@ -21,6 +21,7 @@ function foo([a, b], { c, d, e = "e" }, f = "f", ...args) {
21 <Button {...args}></Button>;
22 <Button xlink:href="localhost:3000"></Button>;
23 <Button haha={1}></Button>;
24 + <DesignSystem.Button />;
25
26 const j = function bar([quz, qux], ...args) {};
27