mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Broken test for labeled statements
When we convert a LabeledStatement to HIR we can end up emitting "consecutive"
blocks, ie where there are two blocks such that control flow will always go from
from one block to the other, with no other way to reach the second block but
through the first. Example:
```javascript
label: {
foo();
break label;
}
bar();
```
Converts to
```
bb0:
foo()
goto bb1:
bb1:
bar();
...
```
Ideally in this case we would merge these into a single block:
* When debugging, the extra goto makes it look like there is conditional control
flow when there isn't. If the code is consecutive it's easier to understand that
if it's a single block.
* Conversion from HIR -> AST relies on consecutive code all being in a single
block, so this breaks codegen (we never visit the goto target since all gotos
are assumed to be safe to convert to a break or continue).
This PR adds a failing test case, the next PR fixes it.
This commit is contained in:
@@ -10,6 +10,7 @@ function foo(a, b, c) {
|
||||
break label;
|
||||
}
|
||||
}
|
||||
return y;
|
||||
}
|
||||
|
||||
```
|
||||
@@ -18,12 +19,29 @@ function foo(a, b, c) {
|
||||
|
||||
```javascript
|
||||
function foo(a, b, c) {
|
||||
const y = [];
|
||||
if (a) {
|
||||
if (b) {
|
||||
y.push(c);
|
||||
const $ = React.useMemoCache();
|
||||
const c_0 = $[0] !== a;
|
||||
const c_1 = $[1] !== b;
|
||||
const c_2 = $[2] !== c;
|
||||
let y;
|
||||
if (c_0 || c_1 || c_2) {
|
||||
y = [];
|
||||
|
||||
if (a) {
|
||||
if (b) {
|
||||
y.push(c);
|
||||
}
|
||||
}
|
||||
|
||||
$[0] = a;
|
||||
$[1] = b;
|
||||
$[2] = c;
|
||||
$[3] = y;
|
||||
} else {
|
||||
y = $[3];
|
||||
}
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
@@ -6,4 +6,5 @@ function foo(a, b, c) {
|
||||
break label;
|
||||
}
|
||||
}
|
||||
return y;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
function foo(a) {
|
||||
let x = 0;
|
||||
bar: {
|
||||
x = 1;
|
||||
break bar;
|
||||
}
|
||||
return a + x;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
function foo(a) {
|
||||
const x = 0;
|
||||
const x$0 = 1;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
function foo(a) {
|
||||
let x = 0;
|
||||
bar: {
|
||||
x = 1;
|
||||
break bar;
|
||||
}
|
||||
return a + x;
|
||||
}
|
||||
Reference in New Issue
Block a user