diff --git a/compiler/forget/src/__tests__/fixtures/hir/_bug_logical-expression-object.expect.md b/compiler/forget/src/__tests__/fixtures/hir/_bug_logical-expression-object.expect.md new file mode 100644 index 0000000000..ef157c6d81 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/_bug_logical-expression-object.expect.md @@ -0,0 +1,57 @@ + +## Input + +```javascript +function component(props) { + // The mutable range for a extens the entire body. + // commenting out the last line of InferMutableRanges fixes it. + // my guess of what's going on is that a is aliased into the return value object literal, + // and that alias makes it look like the range of a needs to be extended to that point. + // but what's weird is that the end of a's range doesn't quite extend to the object. + let a = props.a || (props.b && props.c && props.d); + let b = (props.a && props.b && props.c) || props.d; + return { a, b }; +} + +``` + +## Code + +```javascript +function component(props) { + const $ = React.useMemoCache(); + const c_0 = $[0] !== props; + let a; + if (c_0) { + a = props.a || (props.b && props.c && props.d); + const c_2 = $[2] !== props; + let t3; + if (c_2) { + t3 = (props.a && props.b && props.c) || props.d; + $[2] = props; + $[3] = t3; + } else { + t3 = $[3]; + } + $[0] = props; + $[1] = a; + } else { + a = $[1]; + } + const b = t3; + const c_4 = $[4] !== a; + const c_5 = $[5] !== b; + let t6; + if (c_4 || c_5) { + t6 = { a: a, b: b }; + $[4] = a; + $[5] = b; + $[6] = t6; + } else { + t6 = $[6]; + } + return t6; +} + +``` + \ No newline at end of file diff --git a/compiler/forget/src/__tests__/fixtures/hir/_bug_logical-expression-object.js b/compiler/forget/src/__tests__/fixtures/hir/_bug_logical-expression-object.js new file mode 100644 index 0000000000..aaa317d920 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/_bug_logical-expression-object.js @@ -0,0 +1,10 @@ +function component(props) { + // The mutable range for a extens the entire body. + // commenting out the last line of InferMutableRanges fixes it. + // my guess of what's going on is that a is aliased into the return value object literal, + // and that alias makes it look like the range of a needs to be extended to that point. + // but what's weird is that the end of a's range doesn't quite extend to the object. + let a = props.a || (props.b && props.c && props.d); + let b = (props.a && props.b && props.c) || props.d; + return { a, b }; +} diff --git a/compiler/forget/src/__tests__/fixtures/hir/component.expect.md b/compiler/forget/src/__tests__/fixtures/hir/component.expect.md index 28db298e0d..6adcc0b3df 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/component.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/component.expect.md @@ -55,10 +55,7 @@ function Component(props) { } for (let i = 0; i < items.length; i = i + 1, i) { const item = items.at(i); - if (item == null) { - } else { - } - if (seen.has(item)) { + if (item == null || seen.has(item)) { continue; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/logical-expression.expect.md b/compiler/forget/src/__tests__/fixtures/hir/logical-expression.expect.md index f51073915b..9871544bba 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/logical-expression.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/logical-expression.expect.md @@ -2,14 +2,10 @@ ## Input ```javascript -// @only function component(props) { let a = props.a || (props.b && props.c && props.d); let b = (props.a && props.b && props.c) || props.d; - return { a, b }; - // let b = props.c || props.d; - // let c = props.e ?? props.f; - // return ((a && b) || c) ?? null; + return a ?? b; } ``` @@ -17,33 +13,33 @@ function component(props) { ## Code ```javascript -// @only function component(props) { const $ = React.useMemoCache(); const c_0 = $[0] !== props; - let a; + let t1; if (c_0) { - a = props.a || (props.b && props.c && props.d); - const c_2 = $[2] !== props; - let t3; - if (c_2) { - t3 = (props.a && props.b && props.c) || props.d; - $[2] = props; - $[3] = t3; - } else { - t3 = $[3]; - } + t1 = props.a || (props.b && props.c && props.d); $[0] = props; - $[1] = a; + $[1] = t1; } else { - a = $[1]; + t1 = $[1]; + } + const a = t1; + const c_2 = $[2] !== props; + let t3; + if (c_2) { + t3 = (props.a && props.b && props.c) || props.d; + $[2] = props; + $[3] = t3; + } else { + t3 = $[3]; } const b = t3; const c_4 = $[4] !== a; const c_5 = $[5] !== b; let t6; if (c_4 || c_5) { - t6 = { a: a, b: b }; + t6 = a ?? b; $[4] = a; $[5] = b; $[6] = t6; diff --git a/compiler/forget/src/__tests__/fixtures/hir/logical-expression.js b/compiler/forget/src/__tests__/fixtures/hir/logical-expression.js index 60d684e3a1..f44ae74635 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/logical-expression.js +++ b/compiler/forget/src/__tests__/fixtures/hir/logical-expression.js @@ -1,9 +1,5 @@ -// @only function component(props) { let a = props.a || (props.b && props.c && props.d); let b = (props.a && props.b && props.c) || props.d; - return { a, b }; - // let b = props.c || props.d; - // let c = props.e ?? props.f; - // return ((a && b) || c) ?? null; + return a ?? b; }