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

Bailout TaggedTemplateExpressions instead of invariant

Lauren Tan committed Jan 30, 2023 at 10:36 UTC be4058057c9875f078a27f3eadbd88d977c8fcb2
3 files changed +60 -52
compiler/forget/src/HIR/BuildHIR.ts
+4 -4
@@ -1391,7 +1391,8 @@ function lowerExpression(
1391 const expr = exprPath as NodePath<t.TaggedTemplateExpression>;
1392 if (expr.get("quasi").get("expressions").length !== 0) {
1393 builder.errors.push({
1394 - reason: "Unhandled tagged template with interpolations",
1394 + reason:
1395 + "(BuildHIR::lowerAssignment) Handle tagged template with interpolations",
1396 severity: ErrorSeverity.Todo,
1397 nodePath: exprPath,
1398 });
@@ -1401,12 +1402,11 @@ function lowerExpression(
1402 expr.get("quasi").get("quasis").length == 1,
1403 "there should be only one quasi as we don't support interpolations yet"
1404 );
1404 -
1405 const value = expr.get("quasi").get("quasis").at(0)!.node.value;
1406 if (value.raw !== value.cooked) {
1407 builder.errors.push({
1408 reason:
1409 - "Unhandled tagged template where cooked value is different from raw value",
1409 + "(BuildHIR::lowerAssignment) Handle tagged template where cooked value is different from raw value",
1410 severity: ErrorSeverity.Todo,
1411 nodePath: exprPath,
1412 });
@@ -1800,7 +1800,7 @@ function lowerAssignment(
1800 if (!property.isExpression()) {
1801 builder.errors.push({
1802 reason:
1803 - "Expected private name to appear as a non-computed property",
1803 + "(BuildHIR::lowerAssignment) Expected private name to appear as a non-computed property",
1804 severity: ErrorSeverity.InvalidInput,
1805 nodePath: property,
1806 });
compiler/forget/src/__tests__/fixtures/hir/error.todo-kitchensink.expect.md
+50 -46
@@ -32,8 +32,12 @@ function foo([a, b], { c, d, e = "e" }, f = "f", ...args) {
32 for (; i < 3; i += 1) {
33 x.push(i);
34 }
35 - for (; i < 3; ) {}
36 - for (;;) {}
35 + for (; i < 3; ) {
36 + break;
37 + }
38 + for (;;) {
39 + break;
40 + }
41
42 graphql`
43 ${g}
@@ -236,69 +240,69 @@ function foo([a, b], { c, d, e = "e" }, f = "f", ...args) {
240 | ^
241 29 | x.push(i);
242 30 | }
239 - 31 | for (; i < 3; ) {}
243 + 31 | for (; i < 3; ) {
244
245 [ReactForget] TodoError: (BuildHIR::lowerStatement) Handle non-variable initialization in ForStatement
246 29 | x.push(i);
247 30 | }
244 -> 31 | for (; i < 3; ) {}
245 - | ^^^^^^^^^^^^^^^^^^
246 - 32 | for (;;) {}
247 - 33 |
248 - 34 | graphql`
248 +> 31 | for (; i < 3; ) {
249 + | ^
250 + 32 | break;
251 + 33 | }
252 + 34 | for (;;) {
253
254 [ReactForget] TodoError: (BuildHIR::lowerStatement) Handle empty update in ForStatement
255 29 | x.push(i);
256 30 | }
253 -> 31 | for (; i < 3; ) {}
254 - | ^^^^^^^^^^^^^^^^^^
255 - 32 | for (;;) {}
256 - 33 |
257 - 34 | graphql`
257 +> 31 | for (; i < 3; ) {
258 + | ^
259 + 32 | break;
260 + 33 | }
261 + 34 | for (;;) {
262
263 [ReactForget] TodoError: (BuildHIR::lowerStatement) Handle non-variable initialization in ForStatement
260 - 30 | }
261 - 31 | for (; i < 3; ) {}
262 -> 32 | for (;;) {}
263 - | ^^^^^^^^^^^
264 - 33 |
265 - 34 | graphql`
266 - 35 | ${g}
264 + 32 | break;
265 + 33 | }
266 +> 34 | for (;;) {
267 + | ^
268 + 35 | break;
269 + 36 | }
270 + 37 |
271
272 [ReactForget] TodoError: (BuildHIR::lowerStatement) Handle empty update in ForStatement
269 - 30 | }
270 - 31 | for (; i < 3; ) {}
271 -> 32 | for (;;) {}
272 - | ^^^^^^^^^^^
273 - 33 |
274 - 34 | graphql`
275 - 35 | ${g}
273 + 32 | break;
274 + 33 | }
275 +> 34 | for (;;) {
276 + | ^
277 + 35 | break;
278 + 36 | }
279 + 37 |
280
281 [ReactForget] TodoError: (BuildHIR::lowerStatement) Handle empty test in ForStatement
278 - 30 | }
279 - 31 | for (; i < 3; ) {}
280 -> 32 | for (;;) {}
281 - | ^^^^^^^^^^^
282 - 33 |
283 - 34 | graphql`
284 - 35 | ${g}
285 -
286 -[ReactForget] TodoError: Unhandled tagged template with interpolations
287 - 32 | for (;;) {}
288 - 33 |
289 -> 34 | graphql`
282 + 32 | break;
283 + 33 | }
284 +> 34 | for (;;) {
285 | ^
291 - 35 | ${g}
292 - 36 | `;
286 + 35 | break;
287 + 36 | }
288 37 |
289
295 -[ReactForget] TodoError: Unhandled tagged template where cooked value is different from raw value
296 - 36 | `;
290 +[ReactForget] TodoError: (BuildHIR::lowerAssignment) Handle tagged template with interpolations
291 + 36 | }
292 37 |
298 -> 38 | graphql`\\t\n`;
293 +> 38 | graphql`
294 + | ^
295 + 39 | ${g}
296 + 40 | `;
297 + 41 |
298 +
299 +[ReactForget] TodoError: (BuildHIR::lowerAssignment) Handle tagged template where cooked value is different from raw value
300 + 40 | `;
301 + 41 |
302 +> 42 | graphql`\\t\n`;
303 | ^^^^^^^^^^^^^^
300 - 39 | }
301 - 40 |
304 + 43 | }
305 + 44 |
306 ```
307
308
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/error.todo-kitchensink.js
+6 -2
@@ -28,8 +28,12 @@ function foo([a, b], { c, d, e = "e" }, f = "f", ...args) {
28 for (; i < 3; i += 1) {
29 x.push(i);
30 }
31 - for (; i < 3; ) {}
32 - for (;;) {}
31 + for (; i < 3; ) {
32 + break;
33 + }
34 + for (;;) {
35 + break;
36 + }
37
38 graphql`
39 ${g}