Only set alternate/consequent if terminal is goto

This commit is contained in:
Eli White
2025-02-05 16:45:39 -08:00
parent ea122af36e
commit 4e2c3a9068
4 changed files with 17 additions and 5 deletions
@@ -632,7 +632,7 @@ const EnvironmentConfigSchema = z.object({
* // output
* const x = b;
*/
enableTernaryConstantPropagation: z.boolean().default(false),
enableTernaryConstantPropagation: z.boolean().default(true),
});
export type EnvironmentConfig = z.infer<typeof EnvironmentConfigSchema>;
@@ -190,8 +190,20 @@ function applyConstantPropagation(
loc: terminal.loc,
};
fn.body.blocks.get(branchBlock.terminal.consequent)!.kind = 'block';
fn.body.blocks.get(branchBlock.terminal.alternate)!.kind = 'block';
block.kind = 'block';
const consequent = fn.body.blocks.get(
branchBlock.terminal.consequent,
)!;
const alternate = fn.body.blocks.get(branchBlock.terminal.alternate)!;
if (consequent.terminal.kind === 'goto') {
consequent.kind = 'block';
}
if (alternate.terminal.kind === 'goto') {
alternate.kind = 'block';
}
}
break;
@@ -216,7 +216,7 @@ export function alignReactiveScopesToBlockScopesHIR(fn: HIRFunction): void {
if (node == null) {
// Transition from block->value block, derive the outer block range
CompilerError.invariant(fallthrough !== null, {
reason: `Expected a fallthrough for value block`,
reason: `Expected a fallthrough for value block ${terminal.id}`,
loc: terminal.loc,
});
const fallthroughBlock = fn.body.blocks.get(fallthrough)!;
@@ -4,7 +4,7 @@ import {Stringify} from 'shared-runtime';
function foo() {
let _b;
const b = true;
_b = !b ? 'bar' : 'baz';
_b = !b ? 'bar' : false ? 'foo' : 'baz';
return (
<Stringify