[compiler] Todo for for-await loops
ghstack-source-id: 13f11edfbef2af2e2a9ab876c18b0a4013a3eae0 Pull Request resolved: https://github.com/facebook/react/pull/29118
Joe Savona committed
May 16, 2024 at 17:44 UTC
477a3d1ef5207370df611856702b7d796d478ec1
3 files changed
+49
compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts
+10
@@ -1008,6 +1008,16 @@ function lowerStatement(
1008
const initBlock = builder.reserve("loop");
1009
const testBlock = builder.reserve("loop");
1010
1011
+ if (stmt.node.await) {
1012
+ builder.errors.push({
1013
+ reason: `(BuildHIR::lowerStatement) Handle for-await loops`,
1014
+ severity: ErrorSeverity.Todo,
1015
+ loc: stmt.node.loc ?? null,
1016
+ suggestions: null,
1017
+ });
1018
+ return;
1019
+ }
1020
+
1021
const loopBlock = builder.enter("block", (_blockId) => {
1022
return builder.loop(label, initBlock.id, continuationBlock.id, () => {
1023
const body = stmt.get("body");
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-for-await-loops.expect.md
new
+32
@@ -0,0 +1,32 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+async function Component({ items }) {
6
+ const x = [];
7
+ for await (const item of items) {
8
+ x.push(item);
9
+ }
10
+ return x;
11
+}
12
+
13
+```
14
+
15
+
16
+## Error
17
+
18
+```
19
+ 1 | async function Component({ items }) {
20
+ 2 | const x = [];
21
+> 3 | for await (const item of items) {
22
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23
+> 4 | x.push(item);
24
+ | ^^^^^^^^^^^^^^^^^
25
+> 5 | }
26
+ | ^^^^ Todo: (BuildHIR::lowerStatement) Handle for-await loops (3:5)
27
+ 6 | return x;
28
+ 7 | }
29
+ 8 |
30
+```
31
+
32
+
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-for-await-loops.js
new
+7
@@ -0,0 +1,7 @@
1
+async function Component({ items }) {
2
+ const x = [];
3
+ for await (const item of items) {
4
+ x.push(item);
5
+ }
6
+ return x;
7
+}