mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Fixing nested ternaries
This commit is contained in:
@@ -189,9 +189,17 @@ function runWithEnvironment(
|
||||
|
||||
assertConsistentIdentifiers(hir);
|
||||
|
||||
const wasTernaryConstantPropagationEnabled =
|
||||
env.config.enableTernaryConstantPropagation;
|
||||
env.config.enableTernaryConstantPropagation = false;
|
||||
constantPropagation(hir);
|
||||
log({kind: 'hir', name: 'ConstantPropagation', value: hir});
|
||||
|
||||
env.config.enableTernaryConstantPropagation =
|
||||
wasTernaryConstantPropagationEnabled;
|
||||
constantPropagation(hir);
|
||||
log({kind: 'hir', name: 'ConstantPropagationTernary', value: hir});
|
||||
|
||||
inferTypes(hir);
|
||||
log({kind: 'hir', name: 'InferTypes', value: hir});
|
||||
|
||||
|
||||
+8
-1
@@ -182,6 +182,7 @@ function applyConstantPropagation(
|
||||
*/
|
||||
branchBlock.terminal.consequent
|
||||
: branchBlock.terminal.alternate;
|
||||
block.kind = 'block';
|
||||
block.terminal = {
|
||||
kind: 'goto',
|
||||
variant: GotoVariant.Break,
|
||||
@@ -190,7 +191,13 @@ function applyConstantPropagation(
|
||||
loc: terminal.loc,
|
||||
};
|
||||
|
||||
block.kind = 'block';
|
||||
const fallthrough = fn.body.blocks.get(
|
||||
branchBlock.terminal.fallthrough,
|
||||
);
|
||||
|
||||
if (fallthrough?.terminal.kind == 'goto') {
|
||||
fallthrough.kind = 'block';
|
||||
}
|
||||
|
||||
const consequent = fn.body.blocks.get(
|
||||
branchBlock.terminal.consequent,
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import {Stringify} from 'shared-runtime';
|
||||
function foo() {
|
||||
let _b;
|
||||
const b = true;
|
||||
_b = !b ? 'bar' : false ? 'foo' : 'baz';
|
||||
_b = !b ? 'bar' : 'baz';
|
||||
|
||||
return (
|
||||
<Stringify
|
||||
|
||||
+5
-3
@@ -22,12 +22,14 @@ import { c as _c } from "react/compiler-runtime";
|
||||
function Foo(props) {
|
||||
const $ = _c(1);
|
||||
let x;
|
||||
let t0;
|
||||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
true ? (x = []) : (x = {});
|
||||
$[0] = x;
|
||||
t0 = [];
|
||||
$[0] = t0;
|
||||
} else {
|
||||
x = $[0];
|
||||
t0 = $[0];
|
||||
}
|
||||
x = t0;
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user