mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Elide empty if alternate blocks in codegen
This commit is contained in:
@@ -385,13 +385,16 @@ function codegenTerminal(
|
||||
);
|
||||
}
|
||||
case "if": {
|
||||
return t.ifStatement(
|
||||
codegenPlace(cx, terminal.test),
|
||||
codegenBlock(cx, terminal.consequent),
|
||||
terminal.alternate !== null
|
||||
? codegenBlock(cx, terminal.alternate)
|
||||
: null
|
||||
);
|
||||
const test = codegenPlace(cx, terminal.test);
|
||||
const consequent = codegenBlock(cx, terminal.consequent);
|
||||
let alternate: t.Statement | null = null;
|
||||
if (terminal.alternate !== null) {
|
||||
const block = codegenBlock(cx, terminal.alternate);
|
||||
if (block.body.length !== 0) {
|
||||
alternate = block;
|
||||
}
|
||||
}
|
||||
return t.ifStatement(test, consequent, alternate);
|
||||
}
|
||||
case "return": {
|
||||
const value = codegenPlace(cx, terminal.value);
|
||||
|
||||
@@ -23,7 +23,6 @@ function foo(a, b, c) {
|
||||
```javascript
|
||||
function foo(a, b, c) {
|
||||
if (a) {
|
||||
} else {
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,6 @@ function Component(props) {
|
||||
}
|
||||
} else {
|
||||
if (props.cond2) {
|
||||
} else {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-40
@@ -147,124 +147,84 @@ function MyComponent() {
|
||||
// Is valid but hard to compute by brute-forcing
|
||||
function MyComponent() {
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
if (c) {
|
||||
} else {
|
||||
}
|
||||
|
||||
useHook();
|
||||
|
||||
Reference in New Issue
Block a user