mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
More concise output for labeled blocks
This commit is contained in:
@@ -125,11 +125,12 @@ function codegenBlock(cx: Context, block: ReactiveBlock): t.BlockStatement {
|
||||
break;
|
||||
}
|
||||
if (item.label !== null) {
|
||||
const block =
|
||||
statement.type === "BlockStatement" && statement.body.length === 1
|
||||
? statement.body[0]
|
||||
: statement;
|
||||
statements.push(
|
||||
t.labeledStatement(
|
||||
t.identifier(codegenLabel(item.label)),
|
||||
statement
|
||||
)
|
||||
t.labeledStatement(t.identifier(codegenLabel(item.label)), block)
|
||||
);
|
||||
} else if (statement.type === "BlockStatement") {
|
||||
statements.push(...statement.body);
|
||||
|
||||
@@ -19,12 +19,10 @@ function foo(a, b, c) {
|
||||
|
||||
```javascript
|
||||
function foo(a, b, c) {
|
||||
bb1: {
|
||||
if (a) {
|
||||
while (b) {
|
||||
if (c) {
|
||||
break bb1;
|
||||
}
|
||||
bb1: if (a) {
|
||||
while (b) {
|
||||
if (c) {
|
||||
break bb1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,31 +43,27 @@ function Component(props) {
|
||||
```javascript
|
||||
function Component(props) {
|
||||
let x = 0;
|
||||
bb1: {
|
||||
if (props.a) {
|
||||
x = 1;
|
||||
bb1: if (props.a) {
|
||||
x = 1;
|
||||
} else {
|
||||
if (props.b) {
|
||||
x = 3;
|
||||
} else {
|
||||
if (props.b) {
|
||||
x = 3;
|
||||
} else {
|
||||
break bb1;
|
||||
}
|
||||
break bb1;
|
||||
}
|
||||
}
|
||||
bb10: {
|
||||
bb12: switch (props.c) {
|
||||
case "a": {
|
||||
x = 4;
|
||||
break bb12;
|
||||
}
|
||||
case "b": {
|
||||
break bb10;
|
||||
}
|
||||
case "c": {
|
||||
}
|
||||
default: {
|
||||
x = 6;
|
||||
}
|
||||
bb10: bb12: switch (props.c) {
|
||||
case "a": {
|
||||
x = 4;
|
||||
break bb12;
|
||||
}
|
||||
case "b": {
|
||||
break bb10;
|
||||
}
|
||||
case "c": {
|
||||
}
|
||||
default: {
|
||||
x = 6;
|
||||
}
|
||||
}
|
||||
if (props.d) {
|
||||
|
||||
@@ -29,15 +29,13 @@ function foo(a, b, c, d) {
|
||||
let y;
|
||||
if (c_0 || c_1 || c_2 || c_3) {
|
||||
y = [];
|
||||
bb1: {
|
||||
if (a) {
|
||||
if (b) {
|
||||
y.push(c);
|
||||
break bb1;
|
||||
}
|
||||
|
||||
y.push(d);
|
||||
bb1: if (a) {
|
||||
if (b) {
|
||||
y.push(c);
|
||||
break bb1;
|
||||
}
|
||||
|
||||
y.push(d);
|
||||
}
|
||||
$[0] = a;
|
||||
$[1] = b;
|
||||
|
||||
+7
-9
@@ -23,15 +23,13 @@ function Component(props) {
|
||||
```javascript
|
||||
function Component(props) {
|
||||
let t18 = undefined;
|
||||
bb8: {
|
||||
switch (props.key) {
|
||||
case "key": {
|
||||
t18 = props.value;
|
||||
break bb8;
|
||||
}
|
||||
default: {
|
||||
t18 = props.defaultValue;
|
||||
}
|
||||
bb8: switch (props.key) {
|
||||
case "key": {
|
||||
t18 = props.value;
|
||||
break bb8;
|
||||
}
|
||||
default: {
|
||||
t18 = props.defaultValue;
|
||||
}
|
||||
}
|
||||
const x = t18;
|
||||
|
||||
Reference in New Issue
Block a user