From b98e87aa633944d3b28ba2f4ad1fd18b13c93b0f Mon Sep 17 00:00:00 2001 From: Lauren Tan Date: Thu, 19 Jan 2023 11:37:48 -0500 Subject: [PATCH] Use BabelPlugin in hir-test --- compiler/forget/src/Babel/BabelPlugin.ts | 9 ++-- .../src/Babel/RunReactForgetBabelPlugin.ts | 40 ++++++++++++++++ .../_bug_expression-with-assignment.expect.md | 1 + .../alias-nested-member-path-mutate.expect.md | 2 + .../hir/alias-nested-member-path.expect.md | 5 -- .../fixtures/hir/alias-while.expect.md | 7 --- ...-variations-complex-lvalue-array.expect.md | 1 - ...gnment-variations-complex-lvalue.expect.md | 7 +-- .../src/__tests__/fixtures/hir/call.expect.md | 9 ---- .../hir/capturing-function-1.expect.md | 8 +--- .../capturing-function-within-block.expect.md | 8 +--- .../hir/capturing-member-expr.expect.md | 8 +--- .../capturing-nested-member-call.expect.md | 14 +----- ...ested-member-expr-in-nested-func.expect.md | 14 +----- .../capturing-nested-member-expr.expect.md | 14 +----- ...apturing-var-in-nested-func-decl.expect.md | 9 +--- ...pturing-variable-in-nested-block.expect.md | 8 +--- ...ring-variable-in-nested-function.expect.md | 8 +--- .../chained-assignment-expressions.expect.md | 12 ++--- .../fixtures/hir/component.expect.md | 10 ---- .../fixtures/hir/conditional-break.expect.md | 32 +++++-------- .../hir/conditional-on-mutable.expect.md | 25 ---------- .../hir/constant-propagation-for.expect.md | 3 -- .../hir/constant-propagation-phi.expect.md | 3 +- .../hir/constant-propagation-while.expect.md | 3 -- .../hir/constant-propagation.expect.md | 2 + .../fixtures/hir/constructor.expect.md | 8 ---- .../hir/dependencies-outputs.expect.md | 4 +- .../fixtures/hir/dependencies.expect.md | 4 -- .../hir/destructuring-assignment.expect.md | 1 + .../fixtures/hir/destructuring.expect.md | 1 + .../fixtures/hir/extend-scopes-if.expect.md | 2 - .../fixtures/hir/frozen-after-alias.expect.md | 10 ---- .../fixtures/hir/hook-call.expect.md | 14 ------ .../hir/hooks-freeze-arguments.expect.md | 10 ---- ...reeze-possibly-mutable-arguments.expect.md | 13 ----- .../hir/independent-across-if.expect.md | 38 ++++++--------- .../fixtures/hir/independent.expect.md | 29 ++++------- ...endently-memoize-object-property.expect.md | 7 +-- .../hir/infer-phi-primitive.expect.md | 2 - .../hir/interdependent-across-if.expect.md | 29 ++++------- .../fixtures/hir/interdependent.expect.md | 26 ++++------ .../fixtures/hir/inverted-if.expect.md | 3 -- .../__tests__/fixtures/hir/issue852.expect.md | 5 +- ...ue933-disjoint-set-infinite-loop.expect.md | 2 +- .../fixtures/hir/jsx-fragment.expect.md | 5 -- .../fixtures/hir/logical-expression.expect.md | 38 --------------- .../hir/method-call-computed.expect.md | 5 -- .../hir/method-call-fn-call.expect.md | 4 +- .../fixtures/hir/method-call.expect.md | 3 -- .../hir/mutable-lifetime-loops.expect.md | 14 ------ .../mutable-lifetime-with-aliasing.expect.md | 14 ++---- .../hir/mutable-liverange-loop.expect.md | 16 ------- .../obj-literal-cached-in-if-else.expect.md | 15 +----- ...bj-literal-mutated-after-if-else.expect.md | 11 +---- .../hir/obj-mutated-after-if-else.expect.md | 3 -- .../fixtures/hir/object-properties.expect.md | 1 + ...ng-scopes-shadowing-within-block.expect.md | 9 ---- .../overlapping-scopes-within-block.expect.md | 4 -- .../hir/primitive-alias-mutate.expect.md | 2 - .../hir/prop-capturing-function-1.expect.md | 9 +--- .../hir/property-assignment.expect.md | 4 +- .../hir/reactive-scope-grouping.expect.md | 3 -- .../fixtures/hir/reactive-scopes-if.expect.md | 7 --- .../fixtures/hir/reactive-scopes.expect.md | 5 -- .../hir/reassignment-conditional.expect.md | 9 ---- .../reassignment-separate-scopes.expect.md | 16 ------- .../fixtures/hir/reassignment.expect.md | 5 -- .../fixtures/hir/reverse-postorder.expect.md | 6 --- .../fixtures/hir/simple-alias.expect.md | 6 --- .../fixtures/hir/simple-function-1.expect.md | 2 - .../fixtures/hir/simple-scope.expect.md | 1 - .../__tests__/fixtures/hir/simple.expect.md | 5 -- .../hir/ssa-arrayexpression.expect.md | 1 - .../fixtures/hir/ssa-call-jsx-2.expect.md | 10 +--- .../fixtures/hir/ssa-call-jsx.expect.md | 9 ---- .../hir/ssa-complex-multiple-if.expect.md | 2 + .../hir/ssa-complex-single-if.expect.md | 2 + .../hir/ssa-for-trivial-update.expect.md | 3 -- .../__tests__/fixtures/hir/ssa-for.expect.md | 3 -- .../fixtures/hir/ssa-if-else.expect.md | 1 + .../fixtures/hir/ssa-multiple-phis.expect.md | 1 + .../ssa-nested-loops-no-reassign.expect.md | 2 +- .../hir/ssa-nested-partial-phi.expect.md | 4 -- .../ssa-nested-partial-reassignment.expect.md | 3 -- .../fixtures/hir/ssa-newexpression.expect.md | 5 -- .../hir/ssa-objectexpression-phi.expect.md | 7 +-- .../hir/ssa-objectexpression.expect.md | 6 +-- ...a-property-alias-alias-mutate-if.expect.md | 2 - .../hir/ssa-property-alias-if.expect.md | 7 --- .../ssa-property-alias-mutate-if.expect.md | 2 - ...-property-alias-mutate-inside-if.expect.md | 6 +-- .../hir/ssa-property-alias-mutate.expect.md | 3 +- .../fixtures/hir/ssa-property-call.expect.md | 5 +- .../hir/ssa-property-mutate-2.expect.md | 2 +- .../hir/ssa-property-mutate-alias.expect.md | 2 +- .../hir/ssa-property-mutate.expect.md | 2 +- .../fixtures/hir/ssa-property.expect.md | 3 -- .../fixtures/hir/ssa-return.expect.md | 1 + .../fixtures/hir/ssa-shadowing.expect.md | 6 --- .../fixtures/hir/ssa-sibling-phis.expect.md | 1 + .../fixtures/hir/ssa-simple-phi.expect.md | 2 + .../fixtures/hir/ssa-single-if.expect.md | 1 + .../fixtures/hir/ssa-switch.expect.md | 7 ++- .../fixtures/hir/ssa-throw.expect.md | 1 + .../hir/ssa-while-no-reassign.expect.md | 1 - .../fixtures/hir/ssa-while.expect.md | 3 -- .../fixtures/hir/store-via-call.expect.md | 1 - .../fixtures/hir/store-via-new.expect.md | 1 - .../hir/switch-non-final-default.expect.md | 12 ----- .../hir/switch-with-fallthrough.expect.md | 6 --- .../__tests__/fixtures/hir/switch.expect.md | 8 ---- .../hir/transitive-alias-fields.expect.md | 1 + .../hir/type-binary-operator.expect.md | 3 -- .../fixtures/hir/type-field-load.expect.md | 5 +- .../type-test-field-load-binary-op.expect.md | 11 +---- .../hir/type-test-field-store.expect.md | 2 - .../hir/type-test-polymorphic.expect.md | 5 +- .../type-test-return-type-inference.expect.md | 3 -- .../hir/unconditional-break-label.expect.md | 1 + .../hir/while-conditional-continue.expect.md | 1 + .../fixtures/hir/while-property.expect.md | 3 -- compiler/forget/src/__tests__/hir-test.ts | 48 +++++-------------- compiler/forget/src/index.ts | 11 ++--- 124 files changed, 188 insertions(+), 742 deletions(-) create mode 100644 compiler/forget/src/Babel/RunReactForgetBabelPlugin.ts diff --git a/compiler/forget/src/Babel/BabelPlugin.ts b/compiler/forget/src/Babel/BabelPlugin.ts index fe68898c3a..12dfb82184 100644 --- a/compiler/forget/src/Babel/BabelPlugin.ts +++ b/compiler/forget/src/Babel/BabelPlugin.ts @@ -8,22 +8,23 @@ /// import type * as BabelCore from "@babel/core"; -import type { PluginObj } from "@babel/core"; import jsx from "@babel/plugin-syntax-jsx"; import { compile } from "../CompilerPipeline"; /** * The React Forget Babel Plugin - * @param {*} babel + * @param {*} _babel * @returns */ -export default function (babel: typeof BabelCore): PluginObj { +export default function ReactForgetBabelPlugin( + _babel: typeof BabelCore +): BabelCore.PluginObj { return { name: "react-forget", inherits: jsx, visitor: { FunctionDeclaration: { - enter(fn, pass) { + enter(fn, _pass) { if (fn.scope.getProgramParent() !== fn.scope.parent) { return; } diff --git a/compiler/forget/src/Babel/RunReactForgetBabelPlugin.ts b/compiler/forget/src/Babel/RunReactForgetBabelPlugin.ts new file mode 100644 index 0000000000..4971a9ced9 --- /dev/null +++ b/compiler/forget/src/Babel/RunReactForgetBabelPlugin.ts @@ -0,0 +1,40 @@ +import type * as BabelCore from "@babel/core"; +import { transformFromAstSync } from "@babel/core"; +import * as parser from "@babel/parser"; +import invariant from "invariant"; +import prettier from "prettier"; +import ReactForgetBabelPlugin from "./BabelPlugin"; + +type ReactForgetBabelPluginResult = { + ast: BabelCore.BabelFileResult["ast"]; + code: string; + map: BabelCore.BabelFileResult["map"]; +}; + +export default function runReactForgetBabelPlugin( + text: string, + file: string +): ReactForgetBabelPluginResult { + const ast = parser.parse(text, { + sourceFilename: file, + plugins: ["typescript", "jsx"], + }); + const result = transformFromAstSync(ast, text, { + filename: file, + highlightCode: false, + retainLines: true, + plugins: [ReactForgetBabelPlugin], + }); + invariant( + result?.code != null, + `Expected BabelPluginReactForget to codegen successfully, got: ${result}` + ); + return { + ast: result.ast, + code: prettier.format(result.code, { + semi: true, + parser: "babel-ts", + }), + map: result.map, + }; +} diff --git a/compiler/forget/src/__tests__/fixtures/hir/_bug_expression-with-assignment.expect.md b/compiler/forget/src/__tests__/fixtures/hir/_bug_expression-with-assignment.expect.md index 5aef9100c0..6f12db3046 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/_bug_expression-with-assignment.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/_bug_expression-with-assignment.expect.md @@ -16,6 +16,7 @@ function f() { ```javascript function f() { const x = 1; + const x$0 = 2; 4; return 6; diff --git a/compiler/forget/src/__tests__/fixtures/hir/alias-nested-member-path-mutate.expect.md b/compiler/forget/src/__tests__/fixtures/hir/alias-nested-member-path-mutate.expect.md index 93183c72e4..c63453d5f4 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/alias-nested-member-path-mutate.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/alias-nested-member-path-mutate.expect.md @@ -20,8 +20,10 @@ function component() { const z = []; const y = {}; y.z = z; + const x = {}; x.y = y; + mutate(x.y.z); } diff --git a/compiler/forget/src/__tests__/fixtures/hir/alias-nested-member-path.expect.md b/compiler/forget/src/__tests__/fixtures/hir/alias-nested-member-path.expect.md index 7ace2cdec6..0c334b707d 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/alias-nested-member-path.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/alias-nested-member-path.expect.md @@ -25,10 +25,8 @@ function component() { } else { z = $[0]; } - const c_1 = $[1] !== z; let y; - if (c_1) { y = {}; y.z = z; @@ -37,10 +35,8 @@ function component() { } else { y = $[2]; } - const c_3 = $[3] !== y; let x; - if (c_3) { x = {}; x.y = y; @@ -49,7 +45,6 @@ function component() { } else { x = $[4]; } - return x; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/alias-while.expect.md b/compiler/forget/src/__tests__/fixtures/hir/alias-while.expect.md index 837819c87c..983b62fdcb 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/alias-while.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/alias-while.expect.md @@ -36,7 +36,6 @@ function foo(cond) { a = {}; b = {}; c = {}; - while (cond) { const z = a; a = b; @@ -44,7 +43,6 @@ function foo(cond) { c = z; mutate(a, b); } - $[0] = cond; $[1] = a; $[2] = b; @@ -54,17 +52,12 @@ function foo(cond) { b = $[2]; c = $[3]; } - a; b; c; return a; } -``` -## Code - -```javascript function mutate(x, y) {} ``` diff --git a/compiler/forget/src/__tests__/fixtures/hir/assignment-variations-complex-lvalue-array.expect.md b/compiler/forget/src/__tests__/fixtures/hir/assignment-variations-complex-lvalue-array.expect.md index dad0b2d4a6..e28968752c 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/assignment-variations-complex-lvalue-array.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/assignment-variations-complex-lvalue-array.expect.md @@ -25,7 +25,6 @@ function foo() { } else { a = $[0]; } - return a; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/assignment-variations-complex-lvalue.expect.md b/compiler/forget/src/__tests__/fixtures/hir/assignment-variations-complex-lvalue.expect.md index 52ee4eef1f..cf1a8dd7f8 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/assignment-variations-complex-lvalue.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/assignment-variations-complex-lvalue.expect.md @@ -18,18 +18,13 @@ function g() { const $ = React.useMemoCache(); let x; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { - x = { - y: { - z: 1, - }, - }; + x = { y: { z: 1 } }; x.y.z = x.y.z + 1; x.y.z = x.y.z * 2; $[0] = x; } else { x = $[0]; } - return x; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/call.expect.md b/compiler/forget/src/__tests__/fixtures/hir/call.expect.md index 7875dd9fed..a7c6bca8b9 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/call.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/call.expect.md @@ -20,10 +20,6 @@ function Component(props) { ```javascript function foo() {} -``` -## Code - -```javascript function Component(props) { const $ = React.useMemoCache(); let a; @@ -32,9 +28,7 @@ function Component(props) { a = []; b = {}; foo(a, b); - const _ =
; - foo(b); $[0] = a; $[1] = b; @@ -42,11 +36,9 @@ function Component(props) { a = $[0]; b = $[1]; } - const c_2 = $[2] !== a; const c_3 = $[3] !== b; let t4; - if (c_2 || c_3) { t4 =
; $[2] = a; @@ -55,7 +47,6 @@ function Component(props) { } else { t4 = $[4]; } - return t4; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/capturing-function-1.expect.md b/compiler/forget/src/__tests__/fixtures/hir/capturing-function-1.expect.md index 55a6c2fd94..55731a3efc 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/capturing-function-1.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/capturing-function-1.expect.md @@ -20,29 +20,23 @@ function component(a) { const c_0 = $[0] !== a; let z; if (c_0) { - z = { - a: a, - }; + z = { a: a }; $[0] = a; $[1] = z; } else { z = $[1]; } - const c_2 = $[2] !== z; let x; - if (c_2) { x = function () { z; }; - $[2] = z; $[3] = x; } else { x = $[3]; } - return x; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/capturing-function-within-block.expect.md b/compiler/forget/src/__tests__/fixtures/hir/capturing-function-within-block.expect.md index 1c56b9b6ef..13e76bc544 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/capturing-function-within-block.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/capturing-function-within-block.expect.md @@ -23,30 +23,24 @@ function component(a) { const c_0 = $[0] !== a; let z; if (c_0) { - z = { - a: a, - }; + z = { a: a }; $[0] = a; $[1] = z; } else { z = $[1]; } - const x = undefined; const c_2 = $[2] !== z; let x$0; - if (c_2) { x$0 = function () { z; }; - $[2] = z; $[3] = x$0; } else { x$0 = $[3]; } - return x$0; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/capturing-member-expr.expect.md b/compiler/forget/src/__tests__/fixtures/hir/capturing-member-expr.expect.md index 30973ce532..7c0f284d27 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/capturing-member-expr.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/capturing-member-expr.expect.md @@ -20,29 +20,23 @@ function component(a) { const c_0 = $[0] !== a; let z; if (c_0) { - z = { - a: a, - }; + z = { a: a }; $[0] = a; $[1] = z; } else { z = $[1]; } - const c_2 = $[2] !== z.a; let x; - if (c_2) { x = function () { z.a; }; - $[2] = z.a; $[3] = x; } else { x = $[3]; } - return x; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/capturing-nested-member-call.expect.md b/compiler/forget/src/__tests__/fixtures/hir/capturing-nested-member-call.expect.md index 9d9edbbcea..97ca8ed82d 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/capturing-nested-member-call.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/capturing-nested-member-call.expect.md @@ -20,42 +20,32 @@ function component(a) { const c_0 = $[0] !== a; let t1; if (c_0) { - t1 = { - a: a, - }; + t1 = { a: a }; $[0] = a; $[1] = t1; } else { t1 = $[1]; } - const c_2 = $[2] !== t1; let z; - if (c_2) { - z = { - a: t1, - }; + z = { a: t1 }; $[2] = t1; $[3] = z; } else { z = $[3]; } - const c_4 = $[4] !== z.a.a; let x; - if (c_4) { x = function () { z.a.a(); }; - $[4] = z.a.a; $[5] = x; } else { x = $[5]; } - return x; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/capturing-nested-member-expr-in-nested-func.expect.md b/compiler/forget/src/__tests__/fixtures/hir/capturing-nested-member-expr-in-nested-func.expect.md index 8709b47cbb..c151e82a6a 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/capturing-nested-member-expr-in-nested-func.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/capturing-nested-member-expr-in-nested-func.expect.md @@ -22,44 +22,34 @@ function component(a) { const c_0 = $[0] !== a; let t1; if (c_0) { - t1 = { - a: a, - }; + t1 = { a: a }; $[0] = a; $[1] = t1; } else { t1 = $[1]; } - const c_2 = $[2] !== t1; let z; - if (c_2) { - z = { - a: t1, - }; + z = { a: t1 }; $[2] = t1; $[3] = z; } else { z = $[3]; } - const c_4 = $[4] !== z.a.a; let x; - if (c_4) { x = function () { (function () { z.a.a; })(); }; - $[4] = z.a.a; $[5] = x; } else { x = $[5]; } - return x; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/capturing-nested-member-expr.expect.md b/compiler/forget/src/__tests__/fixtures/hir/capturing-nested-member-expr.expect.md index 98a8386391..6fd615e2a8 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/capturing-nested-member-expr.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/capturing-nested-member-expr.expect.md @@ -20,42 +20,32 @@ function component(a) { const c_0 = $[0] !== a; let t1; if (c_0) { - t1 = { - a: a, - }; + t1 = { a: a }; $[0] = a; $[1] = t1; } else { t1 = $[1]; } - const c_2 = $[2] !== t1; let z; - if (c_2) { - z = { - a: t1, - }; + z = { a: t1 }; $[2] = t1; $[3] = z; } else { z = $[3]; } - const c_4 = $[4] !== z.a.a; let x; - if (c_4) { x = function () { z.a.a; }; - $[4] = z.a.a; $[5] = x; } else { x = $[5]; } - return x; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/capturing-var-in-nested-func-decl.expect.md b/compiler/forget/src/__tests__/fixtures/hir/capturing-var-in-nested-func-decl.expect.md index fb87164eb9..cff1ce6de2 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/capturing-var-in-nested-func-decl.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/capturing-var-in-nested-func-decl.expect.md @@ -23,33 +23,26 @@ function component(a) { const c_0 = $[0] !== a; let z; if (c_0) { - z = { - a: a, - }; + z = { a: a }; $[0] = a; $[1] = z; } else { z = $[1]; } - const c_2 = $[2] !== z; let x; - if (c_2) { x = function () { function t() { z; } - t(); }; - $[2] = z; $[3] = x; } else { x = $[3]; } - return x; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/capturing-variable-in-nested-block.expect.md b/compiler/forget/src/__tests__/fixtures/hir/capturing-variable-in-nested-block.expect.md index 791e0d085f..06ecba3213 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/capturing-variable-in-nested-block.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/capturing-variable-in-nested-block.expect.md @@ -22,31 +22,25 @@ function component(a) { const c_0 = $[0] !== a; let z; if (c_0) { - z = { - a: a, - }; + z = { a: a }; $[0] = a; $[1] = z; } else { z = $[1]; } - const c_2 = $[2] !== z; let x; - if (c_2) { x = function () { { z; } }; - $[2] = z; $[3] = x; } else { x = $[3]; } - return x; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/capturing-variable-in-nested-function.expect.md b/compiler/forget/src/__tests__/fixtures/hir/capturing-variable-in-nested-function.expect.md index 33e214a5a9..82dd3c4091 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/capturing-variable-in-nested-function.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/capturing-variable-in-nested-function.expect.md @@ -22,31 +22,25 @@ function component(a) { const c_0 = $[0] !== a; let z; if (c_0) { - z = { - a: a, - }; + z = { a: a }; $[0] = a; $[1] = z; } else { z = $[1]; } - const c_2 = $[2] !== z; let x; - if (c_2) { x = function () { (function () { z; })(); }; - $[2] = z; $[3] = x; } else { x = $[3]; } - return x; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/chained-assignment-expressions.expect.md b/compiler/forget/src/__tests__/fixtures/hir/chained-assignment-expressions.expect.md index 8629728d77..5fe3218d8a 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/chained-assignment-expressions.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/chained-assignment-expressions.expect.md @@ -17,15 +17,9 @@ function foo() { ```javascript function foo() { - const x = { - x: 0, - }; - const y = { - z: 0, - }; - const z = { - z: 0, - }; + const x = { x: 0 }; + const y = { z: 0 }; + const z = { z: 0 }; x.x = x.x + (y.y = y.y * 1); z.z = z.z + (y.y = y.y * (x.x = x.x & 3)); return z; diff --git a/compiler/forget/src/__tests__/fixtures/hir/component.expect.md b/compiler/forget/src/__tests__/fixtures/hir/component.expect.md index 46382a4f92..28db298e0d 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/component.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/component.expect.md @@ -46,7 +46,6 @@ function Component(props) { const seen = new Set(); const c_3 = $[3] !== maxItems; let max; - if (c_3) { max = Math.max(0, maxItems); $[3] = maxItems; @@ -54,26 +53,21 @@ function Component(props) { } else { max = $[4]; } - for (let i = 0; i < items.length; i = i + 1, i) { const item = items.at(i); - if (item == null) { } else { } - if (seen.has(item)) { continue; } seen.add(item); renderedItems.push(
{item}
); - if (renderedItems.length >= max) { break; } } - $[0] = maxItems; $[1] = items; $[2] = renderedItems; @@ -84,7 +78,6 @@ function Component(props) { const count = renderedItems.length; const c_5 = $[5] !== count; let t6; - if (c_5) { t6 =

{count} Items

; $[5] = count; @@ -92,11 +85,9 @@ function Component(props) { } else { t6 = $[6]; } - const c_7 = $[7] !== t6; const c_8 = $[8] !== renderedItems; let t9; - if (c_7 || c_8) { t9 = (
@@ -110,7 +101,6 @@ function Component(props) { } else { t9 = $[9]; } - return t9; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/conditional-break.expect.md b/compiler/forget/src/__tests__/fixtures/hir/conditional-break.expect.md index 5d02d80260..3492311ea1 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/conditional-break.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/conditional-break.expect.md @@ -61,6 +61,9 @@ function Component(props) { ## Code ```javascript +/** + * props.b does *not* influence `a` + */ function Component(props) { const $ = React.useMemoCache(); const c_0 = $[0] !== props.a; @@ -70,7 +73,6 @@ function Component(props) { if (c_0 || c_1 || c_2) { a_DEBUG = []; a_DEBUG.push(props.a); - if (props.b) { return null; } @@ -83,14 +85,12 @@ function Component(props) { } else { a_DEBUG = $[3]; } - return a_DEBUG; } -``` -## Code - -```javascript +/** + * props.b *does* influence `a` + */ function Component(props) { const $ = React.useMemoCache(); const c_0 = $[0] !== props.a; @@ -101,7 +101,6 @@ function Component(props) { if (c_0 || c_1 || c_2 || c_3) { a = []; a.push(props.a); - if (props.b) { a.push(props.c); } @@ -115,14 +114,12 @@ function Component(props) { } else { a = $[4]; } - return a; } -``` -## Code - -```javascript +/** + * props.b *does* influence `a`, but only in a way that is never observable + */ function Component(props) { const $ = React.useMemoCache(); const c_0 = $[0] !== props.a; @@ -133,7 +130,6 @@ function Component(props) { if (c_0 || c_1 || c_2 || c_3) { a = []; a.push(props.a); - if (props.b) { a.push(props.c); return null; @@ -148,14 +144,12 @@ function Component(props) { } else { a = $[4]; } - return a; } -``` -## Code - -```javascript +/** + * props.b *does* influence `a` + */ function Component(props) { const $ = React.useMemoCache(); const c_0 = $[0] !== props.a; @@ -166,7 +160,6 @@ function Component(props) { if (c_0 || c_1 || c_2 || c_3) { a = []; a.push(props.a); - if (props.b) { a.push(props.c); return a; @@ -181,7 +174,6 @@ function Component(props) { } else { a = $[4]; } - return a; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/conditional-on-mutable.expect.md b/compiler/forget/src/__tests__/fixtures/hir/conditional-on-mutable.expect.md index bc9eacd80e..00db775091 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/conditional-on-mutable.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/conditional-on-mutable.expect.md @@ -43,15 +43,12 @@ function Component(props) { if (c_0 || c_1 || c_2) { a = []; const b = []; - if (b) { a.push(props.p0); } - if (props.p1) { b.push(props.p2); } - $[0] = props.p0; $[1] = props.p1; $[2] = props.p2; @@ -59,11 +56,9 @@ function Component(props) { } else { a = $[3]; } - const c_4 = $[4] !== a; const c_5 = $[5] !== b; let t6; - if (c_4 || c_5) { t6 = ; $[4] = a; @@ -72,14 +67,9 @@ function Component(props) { } else { t6 = $[6]; } - return t6; } -``` -## Code - -```javascript function Component(props) { const $ = React.useMemoCache(); const c_0 = $[0] !== props.p0; @@ -89,15 +79,12 @@ function Component(props) { if (c_0 || c_1 || c_2) { a = []; const b = []; - if (mayMutate(b)) { a.push(props.p0); } - if (props.p1) { b.push(props.p2); } - $[0] = props.p0; $[1] = props.p1; $[2] = props.p2; @@ -105,11 +92,9 @@ function Component(props) { } else { a = $[3]; } - const c_4 = $[4] !== a; const c_5 = $[5] !== b; let t6; - if (c_4 || c_5) { t6 = ; $[4] = a; @@ -118,20 +103,10 @@ function Component(props) { } else { t6 = $[6]; } - return t6; } -``` -## Code - -```javascript function Foo() {} - -``` -## Code - -```javascript function mayMutate() {} ``` diff --git a/compiler/forget/src/__tests__/fixtures/hir/constant-propagation-for.expect.md b/compiler/forget/src/__tests__/fixtures/hir/constant-propagation-for.expect.md index 4d0088d6d0..97beb373f4 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/constant-propagation-for.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/constant-propagation-for.expect.md @@ -20,16 +20,13 @@ function foo() { let y; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { y = 0; - for (const x = 100; 10, false; 100) { y = y + 1; } - $[0] = y; } else { y = $[0]; } - return y; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/constant-propagation-phi.expect.md b/compiler/forget/src/__tests__/fixtures/hir/constant-propagation-phi.expect.md index ce35bca27c..aa96bdf0a9 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/constant-propagation-phi.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/constant-propagation-phi.expect.md @@ -27,15 +27,16 @@ function foo(a, b, c) { if (a) { 2; 1; + const x$1 = 1; x$0 = x$1; } else { 0; 1; + const x$2 = 1; x$0 = x$2; } - 1; true; return b; diff --git a/compiler/forget/src/__tests__/fixtures/hir/constant-propagation-while.expect.md b/compiler/forget/src/__tests__/fixtures/hir/constant-propagation-while.expect.md index 14e13bb501..5af38847a7 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/constant-propagation-while.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/constant-propagation-while.expect.md @@ -22,16 +22,13 @@ function foo() { let y; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { y = 0; - while ((10, false)) { y = y + 1; } - $[0] = y; } else { y = $[0]; } - return y; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/constant-propagation.expect.md b/compiler/forget/src/__tests__/fixtures/hir/constant-propagation.expect.md index 41f6c41049..b017f72463 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/constant-propagation.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/constant-propagation.expect.md @@ -34,7 +34,9 @@ function foo() { const e = 9; const f = 3; const g = -6; + console.log("foo"); + const h = -6; const i = -6; const j = -6; diff --git a/compiler/forget/src/__tests__/fixtures/hir/constructor.expect.md b/compiler/forget/src/__tests__/fixtures/hir/constructor.expect.md index 88aee2fd22..b1435869fc 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/constructor.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/constructor.expect.md @@ -20,10 +20,6 @@ function Component(props) { ```javascript function Foo() {} -``` -## Code - -```javascript function Component(props) { const $ = React.useMemoCache(); let a; @@ -34,7 +30,6 @@ function Component(props) { new Foo(a, b); const _ =
; - new Foo(b); $[0] = a; $[1] = b; @@ -42,11 +37,9 @@ function Component(props) { a = $[0]; b = $[1]; } - const c_2 = $[2] !== a; const c_3 = $[3] !== b; let t4; - if (c_2 || c_3) { t4 =
; $[2] = a; @@ -55,7 +48,6 @@ function Component(props) { } else { t4 = $[4]; } - return t4; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/dependencies-outputs.expect.md b/compiler/forget/src/__tests__/fixtures/hir/dependencies-outputs.expect.md index 437c6b09d7..273250bbbd 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/dependencies-outputs.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/dependencies-outputs.expect.md @@ -33,14 +33,12 @@ function foo(a, b) { } else { x = $[1]; } -
{x}
; - const y = []; + const y = []; if (x.length) { y.push(x); } - if (b) { y.push(b); } diff --git a/compiler/forget/src/__tests__/fixtures/hir/dependencies.expect.md b/compiler/forget/src/__tests__/fixtures/hir/dependencies.expect.md index 80cc7fb571..930ad3cb32 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/dependencies.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/dependencies.expect.md @@ -32,22 +32,18 @@ function foo(x, y, z) { let items2; if (c_0 || c_1) { items2 = []; - if (x) { items2.push(y); } - $[0] = x; $[1] = y; $[2] = items2; } else { items2 = $[2]; } - if (y) { items.push(x); } - return items2; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/destructuring-assignment.expect.md b/compiler/forget/src/__tests__/fixtures/hir/destructuring-assignment.expect.md index c24172b80b..67a7954a80 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/destructuring-assignment.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/destructuring-assignment.expect.md @@ -32,6 +32,7 @@ function foo(a, b, c) { const o = undefined; const d$0 = a[0]; const g$1 = a[1][0].e.f; + const n$2 = b.l.m[0][0]; const o$3 = b.o; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/destructuring.expect.md b/compiler/forget/src/__tests__/fixtures/hir/destructuring.expect.md index c8f7a270c2..2c26bd28c9 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/destructuring.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/destructuring.expect.md @@ -27,6 +27,7 @@ function foo(a, b, c) { function foo(a, b, c) { const d = a[0]; const f = a[1][0].e.f; + const n = b.l.m[0][0]; const o = b.o; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/extend-scopes-if.expect.md b/compiler/forget/src/__tests__/fixtures/hir/extend-scopes-if.expect.md index 78e8d64821..a65a60c09e 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/extend-scopes-if.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/extend-scopes-if.expect.md @@ -31,11 +31,9 @@ function foo(a, b, c) { } } } - if (a.length) { return a; } - return null; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/frozen-after-alias.expect.md b/compiler/forget/src/__tests__/fixtures/hir/frozen-after-alias.expect.md index e147a25e98..b282163c2e 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/frozen-after-alias.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/frozen-after-alias.expect.md @@ -26,22 +26,12 @@ function Component() { } else { a = $[0]; } - const b = a; useFreeze(a); foo(b); } -``` -## Code - -```javascript function useFreeze() {} - -``` -## Code - -```javascript function foo(x) {} ``` diff --git a/compiler/forget/src/__tests__/fixtures/hir/hook-call.expect.md b/compiler/forget/src/__tests__/fixtures/hir/hook-call.expect.md index 9f773630bc..bcc9d40e84 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/hook-call.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/hook-call.expect.md @@ -23,17 +23,8 @@ function Component(props) { ```javascript function useFreeze() {} - -``` -## Code - -```javascript function foo() {} -``` -## Code - -```javascript function Component(props) { const $ = React.useMemoCache(); let x; @@ -43,10 +34,8 @@ function Component(props) { } else { x = $[0]; } - const c_1 = $[1] !== x; let y; - if (c_1) { y = useFreeze(x); $[1] = x; @@ -54,12 +43,10 @@ function Component(props) { } else { y = $[2]; } - foo(y, x); const c_3 = $[3] !== x; const c_4 = $[4] !== y; let t5; - if (c_3 || c_4) { t5 = ( @@ -73,7 +60,6 @@ function Component(props) { } else { t5 = $[5]; } - return t5; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/hooks-freeze-arguments.expect.md b/compiler/forget/src/__tests__/fixtures/hir/hooks-freeze-arguments.expect.md index 651745652e..c8b1542e5a 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/hooks-freeze-arguments.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/hooks-freeze-arguments.expect.md @@ -27,23 +27,13 @@ function Component() { } else { a = $[0]; } - useFreeze(a); useFreeze(a); call(a); return a; } -``` -## Code - -```javascript function useFreeze(x) {} - -``` -## Code - -```javascript function call(x) {} ``` diff --git a/compiler/forget/src/__tests__/fixtures/hir/hooks-freeze-possibly-mutable-arguments.expect.md b/compiler/forget/src/__tests__/fixtures/hir/hooks-freeze-possibly-mutable-arguments.expect.md index 650f508f2c..bf39ec4bf7 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/hooks-freeze-possibly-mutable-arguments.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/hooks-freeze-possibly-mutable-arguments.expect.md @@ -35,23 +35,19 @@ function Component(props) { let a$0; if (c_0 || c_1) { a$0 = undefined; - if (cond) { const a$1 = x; a$0 = a$1; } else { let a$2; - if ($[3] === Symbol.for("react.memo_cache_sentinel")) { a$2 = []; $[3] = a$2; } else { a$2 = $[3]; } - a$0 = a$2; } - $[0] = cond; $[1] = x; $[2] = a$0; @@ -65,16 +61,7 @@ function Component(props) { return a$0; } -``` -## Code - -```javascript function useFreeze(x) {} - -``` -## Code - -```javascript function call(x) {} ``` diff --git a/compiler/forget/src/__tests__/fixtures/hir/independent-across-if.expect.md b/compiler/forget/src/__tests__/fixtures/hir/independent-across-if.expect.md index dbff0a93aa..45e3e57a78 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/independent-across-if.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/independent-across-if.expect.md @@ -37,29 +37,24 @@ function Component(props) { ```javascript function compute() {} - -``` -## Code - -```javascript function mutate() {} - -``` -## Code - -```javascript function foo() {} - -``` -## Code - -```javascript function Foo() {} -``` -## Code - -```javascript +/** + * Should produce 3 scopes: + * + * a: inputs=props.a & props.c; outputs=a + * a = compute(props.a); + * if (props.c) + * mutate(a) + * b: inputs=props.b & props.c; outputs=b + * b = compute(props.b); + * if (props.c) + * mutate(b) + * return: inputs=a, b outputs=return + * return = + */ function Component(props) { const $ = React.useMemoCache(); const c_0 = $[0] !== props.a; @@ -69,12 +64,10 @@ function Component(props) { if (c_0 || c_1 || c_2) { a = compute(props.a); const b = compute(props.b); - if (props.c) { mutate(a); mutate(b); } - $[0] = props.a; $[1] = props.b; $[2] = props.c; @@ -82,11 +75,9 @@ function Component(props) { } else { a = $[3]; } - const c_4 = $[4] !== a; const c_5 = $[5] !== b; let t6; - if (c_4 || c_5) { t6 = ; $[4] = a; @@ -95,7 +86,6 @@ function Component(props) { } else { t6 = $[6]; } - return t6; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/independent.expect.md b/compiler/forget/src/__tests__/fixtures/hir/independent.expect.md index 91341ae450..d75aadfb5c 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/independent.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/independent.expect.md @@ -27,6 +27,16 @@ function Foo() {} ## Code ```javascript +/** + * Should produce 3 scopes: + * + * a: inputs=props.a, outputs=a + * a = compute(props.a); + * b: inputs=props.b, outputs=b + * b = compute(props.b); + * return: inputs=a, b outputs=return + * return = + */ function Component(props) { const $ = React.useMemoCache(); const c_0 = $[0] !== props.a; @@ -38,10 +48,8 @@ function Component(props) { } else { a = $[1]; } - const c_2 = $[2] !== props.b; let b; - if (c_2) { b = compute(props.b); $[2] = props.b; @@ -49,11 +57,9 @@ function Component(props) { } else { b = $[3]; } - const c_4 = $[4] !== a; const c_5 = $[5] !== b; let t6; - if (c_4 || c_5) { t6 = ; $[4] = a; @@ -62,26 +68,11 @@ function Component(props) { } else { t6 = $[6]; } - return t6; } -``` -## Code - -```javascript function compute() {} - -``` -## Code - -```javascript function foo() {} - -``` -## Code - -```javascript function Foo() {} ``` diff --git a/compiler/forget/src/__tests__/fixtures/hir/independently-memoize-object-property.expect.md b/compiler/forget/src/__tests__/fixtures/hir/independently-memoize-object-property.expect.md index dd957db470..05014d499d 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/independently-memoize-object-property.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/independently-memoize-object-property.expect.md @@ -22,13 +22,10 @@ function foo(a, b, c) { const c_2 = $[2] !== c; let x; if (c_0 || c_1 || c_2) { - x = { - a: a, - }; + x = { a: a }; const c_4 = $[4] !== b; const c_5 = $[5] !== c; let t6; - if (c_4 || c_5) { t6 = [b, c]; $[4] = b; @@ -37,7 +34,6 @@ function foo(a, b, c) { } else { t6 = $[6]; } - x.y = t6; $[0] = a; $[1] = b; @@ -46,7 +42,6 @@ function foo(a, b, c) { } else { x = $[3]; } - return x; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/infer-phi-primitive.expect.md b/compiler/forget/src/__tests__/fixtures/hir/infer-phi-primitive.expect.md index 9065975ca8..e00fdab235 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/infer-phi-primitive.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/infer-phi-primitive.expect.md @@ -26,7 +26,6 @@ function foo(a, b) { let x$0; if (c_0) { x$0 = undefined; - if (a) { const x$1 = 1; x$0 = x$1; @@ -34,7 +33,6 @@ function foo(a, b) { const x$2 = 2; x$0 = x$2; } - $[0] = a; $[1] = x$0; } else { diff --git a/compiler/forget/src/__tests__/fixtures/hir/interdependent-across-if.expect.md b/compiler/forget/src/__tests__/fixtures/hir/interdependent-across-if.expect.md index 45817e4551..62646e2447 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/interdependent-across-if.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/interdependent-across-if.expect.md @@ -31,23 +31,19 @@ function Component(props) { ```javascript function compute() {} - -``` -## Code - -```javascript function foo() {} - -``` -## Code - -```javascript function Foo() {} -``` -## Code - -```javascript +/** + * Should produce 1 scope: + * + * return: inputs=props.a & props.b & props.c; outputs=return + * const a = compute(props.a); + * const b = compute(props.b); + * if (props.c) + * foo(a, b); + * return = + */ function Component(props) { const $ = React.useMemoCache(); const c_0 = $[0] !== props.a; @@ -58,11 +54,9 @@ function Component(props) { if (c_0 || c_1 || c_2) { a = compute(props.a); b = compute(props.b); - if (props.c) { foo(a, b); } - $[0] = props.a; $[1] = props.b; $[2] = props.c; @@ -72,11 +66,9 @@ function Component(props) { a = $[3]; b = $[4]; } - const c_5 = $[5] !== a; const c_6 = $[6] !== b; let t7; - if (c_5 || c_6) { t7 = ; $[5] = a; @@ -85,7 +77,6 @@ function Component(props) { } else { t7 = $[7]; } - return t7; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/interdependent.expect.md b/compiler/forget/src/__tests__/fixtures/hir/interdependent.expect.md index 2791b5dca5..e0bc030839 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/interdependent.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/interdependent.expect.md @@ -27,6 +27,15 @@ function Foo() {} ## Code ```javascript +/** + * Should produce 1 scope: + * + * return: inputs=props.a & props.b; outputs=return + * const a = compute(props.a); + * const b = compute(props.b); + * foo(a, b); + * return = + */ function Component(props) { const $ = React.useMemoCache(); const c_0 = $[0] !== props.a; @@ -45,11 +54,9 @@ function Component(props) { a = $[2]; b = $[3]; } - const c_4 = $[4] !== a; const c_5 = $[5] !== b; let t6; - if (c_4 || c_5) { t6 = ; $[4] = a; @@ -58,26 +65,11 @@ function Component(props) { } else { t6 = $[6]; } - return t6; } -``` -## Code - -```javascript function compute() {} - -``` -## Code - -```javascript function foo() {} - -``` -## Code - -```javascript function Foo() {} ``` diff --git a/compiler/forget/src/__tests__/fixtures/hir/inverted-if.expect.md b/compiler/forget/src/__tests__/fixtures/hir/inverted-if.expect.md index 2bb8951bb4..6aae4f609f 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/inverted-if.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/inverted-if.expect.md @@ -28,7 +28,6 @@ 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); @@ -37,7 +36,6 @@ function foo(a, b, c, d) { y.push(d); } - $[0] = a; $[1] = b; $[2] = c; @@ -46,7 +44,6 @@ function foo(a, b, c, d) { } else { y = $[4]; } - return y; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/issue852.expect.md b/compiler/forget/src/__tests__/fixtures/hir/issue852.expect.md index 3e78fbddfa..15329c963d 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/issue852.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/issue852.expect.md @@ -19,16 +19,13 @@ function Component(c) { const c_0 = $[0] !== c; let x; if (c_0) { - x = { - c: c, - }; + x = { c: c }; mutate(x); $[0] = c; $[1] = x; } else { x = $[1]; } - const a = x; const b = a; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/issue933-disjoint-set-infinite-loop.expect.md b/compiler/forget/src/__tests__/fixtures/hir/issue933-disjoint-set-infinite-loop.expect.md index defe9e62a3..092dea78df 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/issue933-disjoint-set-infinite-loop.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/issue933-disjoint-set-infinite-loop.expect.md @@ -16,6 +16,7 @@ function MyApp(props) { ## Code ```javascript +// This caused an infinite loop in the compiler function MyApp(props) { const $ = React.useMemoCache(); let y; @@ -28,7 +29,6 @@ function MyApp(props) { } else { y = $[0]; } - return y; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/jsx-fragment.expect.md b/compiler/forget/src/__tests__/fixtures/hir/jsx-fragment.expect.md index 6b67ad9c65..caa5b712d2 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/jsx-fragment.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/jsx-fragment.expect.md @@ -27,10 +27,8 @@ function Foo(props) { } else { t0 = $[0]; } - const c_1 = $[1] !== t0; let t2; - if (c_1) { t2 =
{t0}
; $[1] = t0; @@ -38,11 +36,9 @@ function Foo(props) { } else { t2 = $[2]; } - const c_3 = $[3] !== props.greeting; const c_4 = $[4] !== t2; let t5; - if (c_3 || c_4) { t5 = ( <> @@ -56,7 +52,6 @@ function Foo(props) { } else { t5 = $[5]; } - return t5; } 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 5399b2e5c1..7d6a05470e 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/logical-expression.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/logical-expression.expect.md @@ -31,41 +31,30 @@ function And() { } else { t0 = $[0]; } - const c_1 = $[1] !== t0; let t2; - if (c_1) { t2 = undefined; - if (t0) { let t3; - if ($[3] === Symbol.for("react.memo_cache_sentinel")) { t3 = g(); $[3] = t3; } else { t3 = $[3]; } - t2 = t3; } else { t2 = t0; } - $[1] = t0; $[2] = t2; } else { t2 = $[2]; } - return t2; } -``` -## Code - -```javascript function Or() { const $ = React.useMemoCache(); let t0; @@ -75,41 +64,30 @@ function Or() { } else { t0 = $[0]; } - const c_1 = $[1] !== t0; let t2; - if (c_1) { t2 = undefined; - if (t0) { t2 = t0; } else { let t3; - if ($[3] === Symbol.for("react.memo_cache_sentinel")) { t3 = g(); $[3] = t3; } else { t3 = $[3]; } - t2 = t3; } - $[1] = t0; $[2] = t2; } else { t2 = $[2]; } - return t2; } -``` -## Code - -```javascript function QuestionQuestion(props) { const $ = React.useMemoCache(); let t0; @@ -119,47 +97,31 @@ function QuestionQuestion(props) { } else { t0 = $[0]; } - const c_1 = $[1] !== t0; let t2; - if (c_1) { t2 = undefined; - if (t0 != null) { t2 = t0; } else { let t3; - if ($[3] === Symbol.for("react.memo_cache_sentinel")) { t3 = g(); $[3] = t3; } else { t3 = $[3]; } - t2 = t3; } - $[1] = t0; $[2] = t2; } else { t2 = $[2]; } - return t2; } -``` -## Code - -```javascript function f() {} - -``` -## Code - -```javascript function g() {} ``` diff --git a/compiler/forget/src/__tests__/fixtures/hir/method-call-computed.expect.md b/compiler/forget/src/__tests__/fixtures/hir/method-call-computed.expect.md index ada6bcb228..9503e94845 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/method-call-computed.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/method-call-computed.expect.md @@ -32,10 +32,8 @@ function foo(a, b, c) { } else { x = $[1]; } - const c_2 = $[2] !== a; let y; - if (c_2) { y = makeObject(a); $[2] = a; @@ -43,7 +41,6 @@ function foo(a, b, c) { } else { y = $[3]; } -
{x} {y} @@ -52,7 +49,6 @@ function foo(a, b, c) { const c_5 = $[5] !== y.method; const c_6 = $[6] !== b; let z; - if (c_4 || c_5 || c_6) { z = x[y.method](b); $[4] = x; @@ -62,7 +58,6 @@ function foo(a, b, c) { } else { z = $[7]; } - return z; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/method-call-fn-call.expect.md b/compiler/forget/src/__tests__/fixtures/hir/method-call-fn-call.expect.md index 891a0a2134..358aa0face 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/method-call-fn-call.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/method-call-fn-call.expect.md @@ -29,14 +29,13 @@ function foo(a, b, c) { } else { x = $[1]; } -
{x}
; + const method = x.method; const c_2 = $[2] !== method; const c_3 = $[3] !== x; const c_4 = $[4] !== b; let y; - if (c_2 || c_3 || c_4) { y = method.call(x, b); $[2] = method; @@ -46,7 +45,6 @@ function foo(a, b, c) { } else { y = $[5]; } - return y; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/method-call.expect.md b/compiler/forget/src/__tests__/fixtures/hir/method-call.expect.md index 8221e84c9d..7e34d67561 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/method-call.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/method-call.expect.md @@ -28,12 +28,10 @@ function foo(a, b, c) { } else { x = $[1]; } -
{x}
; const c_2 = $[2] !== x; const c_3 = $[3] !== b; let y; - if (c_2 || c_3) { y = x.foo(b); $[2] = x; @@ -42,7 +40,6 @@ function foo(a, b, c) { } else { y = $[4]; } - return y; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-loops.expect.md b/compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-loops.expect.md index 6103ab43b7..92ebe9cdbb 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-loops.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-loops.expect.md @@ -43,17 +43,8 @@ function Component(props) { ```javascript function mutate(x, y) {} - -``` -## Code - -```javascript function cond(x) {} -``` -## Code - -```javascript function Component(props) { let a = {}; let b = {}; @@ -74,21 +65,16 @@ function Component(props) { b$1 = b; c$2 = c; d$3 = d; - if (cond(a)) { break; } } - if (a$0) { } - if (b$1) { } - if (c$2) { } - if (d$3) { } diff --git a/compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-with-aliasing.expect.md b/compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-with-aliasing.expect.md index 1f692e05ab..543ada01da 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-with-aliasing.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-with-aliasing.expect.md @@ -40,32 +40,24 @@ function Component(props) { ```javascript function mutate(x, y) {} -``` -## Code - -```javascript function Component(props) { const a = {}; const b = [a]; const c = {}; - const d = { - c: c, - }; + const d = { c: c }; + const x = {}; x.b = b; + const y = mutate(x, d); if (a) { } - if (b) { } - if (c) { } - if (d) { } - if (y) { } diff --git a/compiler/forget/src/__tests__/fixtures/hir/mutable-liverange-loop.expect.md b/compiler/forget/src/__tests__/fixtures/hir/mutable-liverange-loop.expect.md index 76e3d9e06a..fd81cf825d 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/mutable-liverange-loop.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/mutable-liverange-loop.expect.md @@ -38,17 +38,8 @@ function Component(props) { ```javascript function mutate() {} - -``` -## Code - -```javascript function cond() {} -``` -## Code - -```javascript function Component(props) { const $ = React.useMemoCache(); const a = {}; @@ -60,26 +51,19 @@ function Component(props) { } else { c = $[0]; } - const d = {}; - while (true) { mutate(a, b); - if (cond(a)) { break; } } - if (a) { } - if (b) { } - if (c) { } - if (d) { } diff --git a/compiler/forget/src/__tests__/fixtures/hir/obj-literal-cached-in-if-else.expect.md b/compiler/forget/src/__tests__/fixtures/hir/obj-literal-cached-in-if-else.expect.md index de9a4db5de..5927fc3de3 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/obj-literal-cached-in-if-else.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/obj-literal-cached-in-if-else.expect.md @@ -26,46 +26,35 @@ function foo(a, b, c, d) { let x$0; if (c_0 || c_1) { x$0 = undefined; - if (someVal) { const c_3 = $[3] !== b; let x$1; - if (c_3) { - x$1 = { - b: b, - }; + x$1 = { b: b }; $[3] = b; $[4] = x$1; } else { x$1 = $[4]; } - x$0 = x$1; } else { const c_5 = $[5] !== c; let x$2; - if (c_5) { - x$2 = { - c: c, - }; + x$2 = { c: c }; $[5] = c; $[6] = x$2; } else { x$2 = $[6]; } - x$0 = x$2; } - $[0] = b; $[1] = c; $[2] = x$0; } else { x$0 = $[2]; } - return x$0; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/obj-literal-mutated-after-if-else.expect.md b/compiler/forget/src/__tests__/fixtures/hir/obj-literal-mutated-after-if-else.expect.md index a3df518a3f..853a25b354 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/obj-literal-mutated-after-if-else.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/obj-literal-mutated-after-if-else.expect.md @@ -27,19 +27,13 @@ function foo(a, b, c, d) { let x$0; if (c_0 || c_1) { x$0 = undefined; - if (someVal) { - const x$1 = { - b: b, - }; + const x$1 = { b: b }; x$0 = x$1; } else { - const x$2 = { - c: c, - }; + const x$2 = { c: c }; x$0 = x$2; } - x$0.f = 1; $[0] = b; $[1] = c; @@ -47,7 +41,6 @@ function foo(a, b, c, d) { } else { x$0 = $[2]; } - return x$0; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/obj-mutated-after-if-else.expect.md b/compiler/forget/src/__tests__/fixtures/hir/obj-mutated-after-if-else.expect.md index d1aaa70beb..228e117e1c 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/obj-mutated-after-if-else.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/obj-mutated-after-if-else.expect.md @@ -26,7 +26,6 @@ function foo(a, b, c, d) { let x$0; if (c_0) { x$0 = undefined; - if (a) { const x$1 = someObj(); x$0 = x$1; @@ -34,14 +33,12 @@ function foo(a, b, c, d) { const x$2 = someObj(); x$0 = x$2; } - x$0.f = 1; $[0] = a; $[1] = x$0; } else { x$0 = $[1]; } - return x$0; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/object-properties.expect.md b/compiler/forget/src/__tests__/fixtures/hir/object-properties.expect.md index a4ef23ff50..269425b77b 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/object-properties.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/object-properties.expect.md @@ -19,6 +19,7 @@ function foo(a, b, c) { const x = a.x; const y = b.c.d; y.z = c.d.e; + foo(a.b.c); [a.b.c]; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-shadowing-within-block.expect.md b/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-shadowing-within-block.expect.md index 3036392f48..8ae89b74ff 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-shadowing-within-block.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-shadowing-within-block.expect.md @@ -28,29 +28,23 @@ function foo(a, b, c) { let x; if (c_0 || c_1 || c_2) { x = []; - if (a) { const c_4 = $[4] !== b; const c_5 = $[5] !== c; let y; - if (c_4 || c_5) { y = []; - if (b) { y.push(c); } - $[4] = b; $[5] = c; $[6] = y; } else { y = $[6]; } - const c_7 = $[7] !== y; let t8; - if (c_7) { t8 =
{y}
; $[7] = y; @@ -58,10 +52,8 @@ function foo(a, b, c) { } else { t8 = $[8]; } - x.push(t8); } - $[0] = a; $[1] = b; $[2] = c; @@ -69,7 +61,6 @@ function foo(a, b, c) { } else { x = $[3]; } - return x; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-within-block.expect.md b/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-within-block.expect.md index 2f72eea03e..b03e2a204a 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-within-block.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-within-block.expect.md @@ -28,17 +28,14 @@ function foo(a, b, c) { let x; if (c_0 || c_1 || c_2) { x = []; - if (a) { const y = []; - if (b) { y.push(c); } x.push(y); } - $[0] = a; $[1] = b; $[2] = c; @@ -46,7 +43,6 @@ function foo(a, b, c) { } else { x = $[3]; } - return x; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/primitive-alias-mutate.expect.md b/compiler/forget/src/__tests__/fixtures/hir/primitive-alias-mutate.expect.md index 47a727bf64..9b48a260e8 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/primitive-alias-mutate.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/primitive-alias-mutate.expect.md @@ -26,7 +26,6 @@ function component(a) { let x$0; if (c_0) { x$0 = undefined; - if (a) { const x$1 = "bar"; x$0 = x$1; @@ -34,7 +33,6 @@ function component(a) { const x$2 = "baz"; x$0 = x$2; } - $[0] = a; $[1] = x$0; } else { diff --git a/compiler/forget/src/__tests__/fixtures/hir/prop-capturing-function-1.expect.md b/compiler/forget/src/__tests__/fixtures/hir/prop-capturing-function-1.expect.md index 65467a6482..01329599b1 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/prop-capturing-function-1.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/prop-capturing-function-1.expect.md @@ -21,31 +21,24 @@ function component(a, b) { const c_1 = $[1] !== b; let z; if (c_0 || c_1) { - z = { - a: a, - b: b, - }; + z = { a: a, b: b }; $[0] = a; $[1] = b; $[2] = z; } else { z = $[2]; } - const c_3 = $[3] !== z; let x; - if (c_3) { x = function () { z; }; - $[3] = z; $[4] = x; } else { x = $[4]; } - return x; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/property-assignment.expect.md b/compiler/forget/src/__tests__/fixtures/hir/property-assignment.expect.md index 872f78c2d3..ca51d65bf2 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/property-assignment.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/property-assignment.expect.md @@ -25,6 +25,7 @@ function Component(props) { x = {}; const y = []; x.y = y; + child = ; x.y.push(props.p0); $[0] = props.p0; @@ -34,11 +35,9 @@ function Component(props) { x = $[1]; child = $[2]; } - const c_3 = $[3] !== x; const c_4 = $[4] !== child; let t5; - if (c_3 || c_4) { t5 = {child}; $[3] = x; @@ -47,7 +46,6 @@ function Component(props) { } else { t5 = $[5]; } - return t5; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/reactive-scope-grouping.expect.md b/compiler/forget/src/__tests__/fixtures/hir/reactive-scope-grouping.expect.md index c0dc033d54..f69dd9ddd3 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/reactive-scope-grouping.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/reactive-scope-grouping.expect.md @@ -23,7 +23,6 @@ function foo() { if ($[0] === Symbol.for("react.memo_cache_sentinel")) { x = {}; let y; - if ($[1] === Symbol.for("react.memo_cache_sentinel")) { y = []; const z = {}; @@ -32,13 +31,11 @@ function foo() { } else { y = $[1]; } - x.y = y; $[0] = x; } else { x = $[0]; } - return x; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/reactive-scopes-if.expect.md b/compiler/forget/src/__tests__/fixtures/hir/reactive-scopes-if.expect.md index 3964d0967c..e2bf8d322a 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/reactive-scopes-if.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/reactive-scopes-if.expect.md @@ -27,11 +27,9 @@ function foo(a, b, c) { let x; if (c_0 || c_1 || c_2) { x = []; - if (a) { const c_4 = $[4] !== b; let y; - if (c_4) { y = []; y.push(b); @@ -40,10 +38,8 @@ function foo(a, b, c) { } else { y = $[5]; } - const c_6 = $[6] !== y; let t7; - if (c_6) { t7 =
{y}
; $[6] = y; @@ -51,12 +47,10 @@ function foo(a, b, c) { } else { t7 = $[7]; } - x.push(t7); } else { x.push(c); } - $[0] = a; $[1] = b; $[2] = c; @@ -64,7 +58,6 @@ function foo(a, b, c) { } else { x = $[3]; } - return x; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/reactive-scopes.expect.md b/compiler/forget/src/__tests__/fixtures/hir/reactive-scopes.expect.md index 548d0b3588..bc91a20009 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/reactive-scopes.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/reactive-scopes.expect.md @@ -25,23 +25,19 @@ function f(a, b) { let x; if (c_0 || c_1) { x = []; - if (a.length === 1) { if (b) { x.push(b); } } - $[0] = a.length; $[1] = b; $[2] = x; } else { x = $[2]; } - const c_3 = $[3] !== x; let t4; - if (c_3) { t4 =
{x}
; $[3] = x; @@ -49,7 +45,6 @@ function f(a, b) { } else { t4 = $[4]; } - return t4; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/reassignment-conditional.expect.md b/compiler/forget/src/__tests__/fixtures/hir/reassignment-conditional.expect.md index 192366c7f1..95aac57679 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/reassignment-conditional.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/reassignment-conditional.expect.md @@ -34,27 +34,21 @@ function Component(props) { } else { x = $[1]; } - const y = x; const c_2 = $[2] !== props.p1; let x$0; - if (c_2) { x$0 = x; - if (props.p1) { let x$1; - if ($[4] === Symbol.for("react.memo_cache_sentinel")) { x$1 = []; $[4] = x$1; } else { x$1 = $[4]; } - x$0 = x$1; } - $[2] = props.p1; $[3] = x$0; } else { @@ -62,12 +56,10 @@ function Component(props) { } const _ = ; - y.push(props.p2); const c_5 = $[5] !== x$0; const c_6 = $[6] !== y; let t7; - if (c_5 || c_6) { t7 = ; $[5] = x$0; @@ -76,7 +68,6 @@ function Component(props) { } else { t7 = $[7]; } - return t7; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/reassignment-separate-scopes.expect.md b/compiler/forget/src/__tests__/fixtures/hir/reassignment-separate-scopes.expect.md index b698615d46..053ee9f94f 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/reassignment-separate-scopes.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/reassignment-separate-scopes.expect.md @@ -39,20 +39,16 @@ function foo(a, b, c) { let x; if (c_0) { x = []; - if (a) { x.push(a); } - $[0] = a; $[1] = x; } else { x = $[1]; } - const c_2 = $[2] !== x; let y; - if (c_2) { y =
{x}
; $[2] = x; @@ -60,19 +56,15 @@ function foo(a, b, c) { } else { y = $[3]; } - const c_4 = $[4] !== b; const c_5 = $[5] !== c; let x$0; - if (c_4 || c_5) { x$0 = undefined; - bb3: switch (b) { case 0: { const c_7 = $[7] !== b; let x$1; - if (c_7) { x$1 = []; x$1.push(b); @@ -81,15 +73,12 @@ function foo(a, b, c) { } else { x$1 = $[8]; } - x$0 = x$1; break bb3; } - default: { const c_9 = $[9] !== c; let x$2; - if (c_9) { x$2 = []; x$2.push(c); @@ -98,22 +87,18 @@ function foo(a, b, c) { } else { x$2 = $[10]; } - x$0 = x$2; } } - $[4] = b; $[5] = c; $[6] = x$0; } else { x$0 = $[6]; } - const c_11 = $[11] !== y; const c_12 = $[12] !== x$0; let t13; - if (c_11 || c_12) { t13 = (
@@ -127,7 +112,6 @@ function foo(a, b, c) { } else { t13 = $[13]; } - return t13; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/reassignment.expect.md b/compiler/forget/src/__tests__/fixtures/hir/reassignment.expect.md index 9616cbc707..015b228019 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/reassignment.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/reassignment.expect.md @@ -30,14 +30,12 @@ function Component(props) { x.push(props.p0); y = x; let x$0; - if ($[3] === Symbol.for("react.memo_cache_sentinel")) { x$0 = []; $[3] = x$0; } else { x$0 = $[3]; } - const _ = ; y.push(props.p1); @@ -47,11 +45,9 @@ function Component(props) { } else { y = $[2]; } - const c_4 = $[4] !== x$0; const c_5 = $[5] !== y; let t6; - if (c_4 || c_5) { t6 = ; $[4] = x$0; @@ -60,7 +56,6 @@ function Component(props) { } else { t6 = $[6]; } - return t6; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/reverse-postorder.expect.md b/compiler/forget/src/__tests__/fixtures/hir/reverse-postorder.expect.md index 412c9c06e1..bd40755ff0 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/reverse-postorder.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/reverse-postorder.expect.md @@ -49,7 +49,6 @@ function Component(props) { let x$0; if (c_0 || c_1 || c_2 || c_3 || c_4 || c_5 || c_6 || c_7) { x$0 = undefined; - bb1: if (props.cond) { switch (props.test) { case 0: { @@ -57,16 +56,13 @@ function Component(props) { x$0 = x$1; break bb1; } - case 1: { const x$2 = props.v1; x$0 = x$2; break bb1; } - case 2: { } - default: { const x$3 = props.v2; x$0 = x$3; @@ -81,7 +77,6 @@ function Component(props) { x$0 = x$5; } } - $[0] = props.cond; $[1] = props.test; $[2] = props.v0; @@ -94,7 +89,6 @@ function Component(props) { } else { x$0 = $[8]; } - x$0; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/simple-alias.expect.md b/compiler/forget/src/__tests__/fixtures/hir/simple-alias.expect.md index 14db17ae82..edc162220c 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/simple-alias.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/simple-alias.expect.md @@ -20,11 +20,6 @@ function foo() { ```javascript function mutate() {} - -``` -## Code - -```javascript function foo() { const $ = React.useMemoCache(); const a = {}; @@ -40,7 +35,6 @@ function foo() { } else { c$2 = $[0]; } - return c$2; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/simple-function-1.expect.md b/compiler/forget/src/__tests__/fixtures/hir/simple-function-1.expect.md index ab30c7cab7..6459f3e25e 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/simple-function-1.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/simple-function-1.expect.md @@ -21,12 +21,10 @@ function component() { x = function (a) { a.foo(); }; - $[0] = x; } else { x = $[0]; } - return x; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/simple-scope.expect.md b/compiler/forget/src/__tests__/fixtures/hir/simple-scope.expect.md index f3c225ef69..dd8692150e 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/simple-scope.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/simple-scope.expect.md @@ -23,7 +23,6 @@ function foo(a) { } else { x = $[1]; } - return x; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/simple.expect.md b/compiler/forget/src/__tests__/fixtures/hir/simple.expect.md index 1ab184d43e..9f2778594f 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/simple.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/simple.expect.md @@ -19,7 +19,6 @@ function foo(x, y) { if (x) { const c_0 = $[0] !== y; let t1; - if (c_0) { t1 = foo(false, y); $[0] = y; @@ -27,19 +26,15 @@ function foo(x, y) { } else { t1 = $[1]; } - return t1; } - let t2; - if ($[2] === Symbol.for("react.memo_cache_sentinel")) { t2 = [y * 10]; $[2] = t2; } else { t2 = $[2]; } - return t2; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-arrayexpression.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-arrayexpression.expect.md index d83c1ecaaf..32f1c45619 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-arrayexpression.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-arrayexpression.expect.md @@ -25,7 +25,6 @@ function Component(props) { } else { x = $[0]; } - return x; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx-2.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx-2.expect.md index 36bb3a0b05..b7941f12d3 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx-2.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx-2.expect.md @@ -21,12 +21,9 @@ function Component(props) { ## Code ```javascript +// @Pass runMutableRangeAnalysis function foo() {} -``` -## Code - -```javascript function Component(props) { const $ = React.useMemoCache(); let a; @@ -36,14 +33,12 @@ function Component(props) { b = {}; foo(a, b); let t2; - if ($[2] === Symbol.for("react.memo_cache_sentinel")) { t2 = foo(); $[2] = t2; } else { t2 = $[2]; } - if (t2) { const _ =
; } @@ -55,11 +50,9 @@ function Component(props) { a = $[0]; b = $[1]; } - const c_3 = $[3] !== a; const c_4 = $[4] !== b; let t5; - if (c_3 || c_4) { t5 =
; $[3] = a; @@ -68,7 +61,6 @@ function Component(props) { } else { t5 = $[5]; } - return t5; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx.expect.md index c86c062d4c..6983f45d60 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx.expect.md @@ -20,10 +20,6 @@ function Component(props) { ```javascript function foo() {} -``` -## Code - -```javascript function Component(props) { const $ = React.useMemoCache(); let a; @@ -32,9 +28,7 @@ function Component(props) { a = []; b = {}; foo(a, b); - const _ =
; - foo(a, b); $[0] = a; $[1] = b; @@ -42,11 +36,9 @@ function Component(props) { a = $[0]; b = $[1]; } - const c_2 = $[2] !== a; const c_3 = $[3] !== b; let t4; - if (c_2 || c_3) { t4 =
; $[2] = a; @@ -55,7 +47,6 @@ function Component(props) { } else { t4 = $[4]; } - return t4; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-complex-multiple-if.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-complex-multiple-if.expect.md index 51a1a7bb6d..c906c69d4d 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-complex-multiple-if.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-complex-multiple-if.expect.md @@ -25,9 +25,11 @@ function foo() { const y = 2; 2; true; + const x$0 = 3; 3; false; + const y$1 = x$0; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-complex-single-if.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-complex-single-if.expect.md index 36536ef8b0..5f5a449489 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-complex-single-if.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-complex-single-if.expect.md @@ -22,7 +22,9 @@ function foo() { const y = 2; 2; true; + const x$0 = 3; + const y$1 = x$0; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-for-trivial-update.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-for-trivial-update.expect.md index cf1117bda3..ed66fd2fc2 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-for-trivial-update.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-for-trivial-update.expect.md @@ -20,16 +20,13 @@ function foo() { let x; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { x = 1; - for (const i = 0; 10, true; 0) { x = x + 1; } - $[0] = x; } else { x = $[0]; } - return x; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-for.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-for.expect.md index 97ad5c7fa4..61ba326665 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-for.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-for.expect.md @@ -20,16 +20,13 @@ function foo() { let x; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { x = 1; - for (let i = 0; i < 10; i = i + 1, i) { x = x + 1; } - $[0] = x; } else { x = $[0]; } - return x; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-if-else.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-if-else.expect.md index e2d85a9748..f48d8f744e 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-if-else.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-if-else.expect.md @@ -21,6 +21,7 @@ function foo() { function foo() { const x = 1; const y = 2; + const z = 3; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-multiple-phis.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-multiple-phis.expect.md index 8f21aabe5b..706f80dc12 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-multiple-phis.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-multiple-phis.expect.md @@ -31,6 +31,7 @@ function foo(a, b, c, d) { const x = 0; true; true; + const x$0 = a; x$0; return x$0; diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-nested-loops-no-reassign.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-nested-loops-no-reassign.expect.md index 9bf8eb777a..42b723ab2b 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-nested-loops-no-reassign.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-nested-loops-no-reassign.expect.md @@ -20,6 +20,7 @@ function foo(a, b, c) { ## Code ```javascript +// @xonly function foo(a, b, c) { const x = 0; while (a) { @@ -30,7 +31,6 @@ function foo(a, b, c) { } } } - return x; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-phi.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-phi.expect.md index 58dfcb4265..9ac41d2f64 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-phi.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-phi.expect.md @@ -23,21 +23,17 @@ function foo(a, b, c) { if (b) { const c_0 = $[0] !== c; let x$0; - if (c_0) { x$0 = x; - if (c) { const x$1 = c; x$0 = x$1; } - $[0] = c; $[1] = x$0; } else { x$0 = $[1]; } - x$0; } } diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-reassignment.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-reassignment.expect.md index 6608a9cb35..263f51ae5d 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-reassignment.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-reassignment.expect.md @@ -29,7 +29,6 @@ function foo(a, b, c, d, e) { let x$0; if (c_0 || c_1 || c_2 || c_3) { x$0 = x; - if (a) { const x$1 = b; x$0 = x$1; @@ -39,7 +38,6 @@ function foo(a, b, c, d, e) { x$0 = x$2; } } - $[0] = a; $[1] = b; $[2] = c; @@ -48,7 +46,6 @@ function foo(a, b, c, d, e) { } else { x$0 = $[4]; } - return x$0; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-newexpression.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-newexpression.expect.md index b2859997a7..f59417d9ad 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-newexpression.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-newexpression.expect.md @@ -18,10 +18,6 @@ function Component(props) { ```javascript function Foo() {} -``` -## Code - -```javascript function Component(props) { const $ = React.useMemoCache(); let c; @@ -33,7 +29,6 @@ function Component(props) { } else { c = $[0]; } - return c; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-objectexpression-phi.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-objectexpression-phi.expect.md index 4cb2eb8d72..0482d025f0 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-objectexpression-phi.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-objectexpression-phi.expect.md @@ -27,18 +27,15 @@ function foo() { const y = 2; 1; false; + const y$0 = 3; let t; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { - t = { - x: x, - y: y$0, - }; + t = { x: x, y: y$0 }; $[0] = t; } else { t = $[0]; } - return t; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-objectexpression.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-objectexpression.expect.md index 9fb9f2cf6c..675c949954 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-objectexpression.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-objectexpression.expect.md @@ -20,15 +20,11 @@ function Component(props) { const b = 2; let x; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { - x = { - a: a, - b: b, - }; + x = { a: a, b: b }; $[0] = x; } else { x = $[0]; } - return x; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-alias-mutate-if.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-alias-mutate-if.expect.md index 5c2d6d1e1b..ede87c99b2 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-alias-mutate-if.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-alias-mutate-if.expect.md @@ -28,7 +28,6 @@ function foo(a) { if (c_0) { const b = {}; x = b; - if (a) { const y = {}; x.y = y; @@ -43,7 +42,6 @@ function foo(a) { } else { x = $[1]; } - return x; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-if.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-if.expect.md index 37012a61be..4cf3e7a0d0 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-if.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-if.expect.md @@ -25,37 +25,30 @@ function foo(a) { let x; if (c_0) { x = {}; - if (a) { let y; - if ($[2] === Symbol.for("react.memo_cache_sentinel")) { y = {}; $[2] = y; } else { y = $[2]; } - x.y = y; } else { let z; - if ($[3] === Symbol.for("react.memo_cache_sentinel")) { z = {}; $[3] = z; } else { z = $[3]; } - x.z = z; } - $[0] = a; $[1] = x; } else { x = $[1]; } - return x; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate-if.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate-if.expect.md index 334996f51d..a2fa814f16 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate-if.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate-if.expect.md @@ -26,7 +26,6 @@ function foo(a) { let x; if (c_0) { x = {}; - if (a) { const y = {}; x.y = y; @@ -41,7 +40,6 @@ function foo(a) { } else { x = $[1]; } - return x; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate-inside-if.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate-inside-if.expect.md index 6838f886ae..922fe2c39a 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate-inside-if.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate-inside-if.expect.md @@ -26,30 +26,26 @@ function foo(a) { let x; if (c_0) { x = {}; - if (a) { const y = {}; x.y = y; + mutate(y); } else { let z; - if ($[2] === Symbol.for("react.memo_cache_sentinel")) { z = {}; $[2] = z; } else { z = $[2]; } - x.z = z; } - $[0] = a; $[1] = x; } else { x = $[1]; } - return x; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate.expect.md index 42321ee411..620ef9d95d 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate.expect.md @@ -24,14 +24,15 @@ function foo() { if ($[0] === Symbol.for("react.memo_cache_sentinel")) { const a = {}; const x = a; + y = {}; y.x = x; + mutate(a); $[0] = y; } else { y = $[0]; } - return y; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-call.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-call.expect.md index cd3a8503a3..3d3671006d 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-call.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-call.expect.md @@ -19,15 +19,12 @@ function foo() { let y; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { const x = []; - y = { - x: x, - }; + y = { x: x }; y.x.push([]); $[0] = y; } else { y = $[0]; } - return y; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-mutate-2.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-mutate-2.expect.md index f150c10e12..8d7e9e3d15 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-mutate-2.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-mutate-2.expect.md @@ -22,12 +22,12 @@ function foo() { const x = []; y = {}; y.x = x; + mutate(x); $[0] = y; } else { y = $[0]; } - return y; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-mutate-alias.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-mutate-alias.expect.md index c7ac5a8947..cd7b97b9c5 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-mutate-alias.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-mutate-alias.expect.md @@ -26,12 +26,12 @@ function foo() { y = a; const x = []; y.x = x; + mutate(a); $[0] = y; } else { y = $[0]; } - return y; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-mutate.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-mutate.expect.md index 17e871aefa..f1d23244f4 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-property-mutate.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-property-mutate.expect.md @@ -22,12 +22,12 @@ function foo() { const x = []; y = {}; y.x = x; + mutate(y); $[0] = y; } else { y = $[0]; } - return y; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-property.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-property.expect.md index 5dc6c74d75..a6b039de63 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-property.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-property.expect.md @@ -23,10 +23,8 @@ function foo() { } else { x = $[0]; } - const c_1 = $[1] !== x; let y; - if (c_1) { y = {}; y.x = x; @@ -35,7 +33,6 @@ function foo() { } else { y = $[2]; } - return y; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-return.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-return.expect.md index 882100b4e7..c3d920a035 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-return.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-return.expect.md @@ -20,6 +20,7 @@ function foo() { const x = 1; 1; true; + const x$0 = 2; return x$0; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-shadowing.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-shadowing.expect.md index 3f59ef5659..baf5937428 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-shadowing.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-shadowing.expect.md @@ -22,10 +22,6 @@ function Foo(cond) { ```javascript function log() {} -``` -## Code - -```javascript function Foo(cond) { const $ = React.useMemoCache(); const str = ""; @@ -33,7 +29,6 @@ function Foo(cond) { let str$0; if (c_0) { str$0 = str; - if (cond) { const str_0 = "other test"; log(str_0); @@ -41,7 +36,6 @@ function Foo(cond) { const str$1 = "fallthrough test"; str$0 = str$1; } - $[0] = cond; $[1] = str$0; } else { diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-sibling-phis.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-sibling-phis.expect.md index 3a04168405..cd80d386d6 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-sibling-phis.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-sibling-phis.expect.md @@ -31,6 +31,7 @@ function foo(a, b, c, d) { const x = 0; true; true; + const x$0 = a; x$0; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-simple-phi.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-simple-phi.expect.md index 831138f944..34bc4817c7 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-simple-phi.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-simple-phi.expect.md @@ -23,7 +23,9 @@ function foo() { const y = 2; 1; true; + const y$0 = 1; + const x = y$0; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-single-if.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-single-if.expect.md index 90104e0236..fccc8db799 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-single-if.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-single-if.expect.md @@ -19,6 +19,7 @@ function foo() { function foo() { const x = 1; const y = 2; + const z = 3; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-switch.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-switch.expect.md index 3ae69bd698..b7235930ec 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-switch.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-switch.expect.md @@ -35,29 +35,28 @@ function foo() { let x$0; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { x$0 = undefined; - bb1: switch (x) { case true: { 1; + const x$1 = 2; x$0 = x$1; break bb1; } - case false: { 2; + const x$2 = 3; x$0 = x$2; break bb1; } - default: { 3; + const x$3 = 4; x$0 = x$3; } } - $[0] = x$0; } else { x$0 = $[0]; diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-throw.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-throw.expect.md index 442cc287dc..649ec96602 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-throw.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-throw.expect.md @@ -19,6 +19,7 @@ function foo() { const x = 1; 1; true; + const x$0 = 2; throw x$0; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-while-no-reassign.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-while-no-reassign.expect.md index fd2cd0ae03..61b8af9b58 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-while-no-reassign.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-while-no-reassign.expect.md @@ -22,7 +22,6 @@ function foo() { 1; 2; } - return x; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-while.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-while.expect.md index 609b5bd489..4df32596fb 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/ssa-while.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-while.expect.md @@ -21,16 +21,13 @@ function foo() { let x; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { x = 1; - while (x < 10) { x = x + 1; } - $[0] = x; } else { x = $[0]; } - return x; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/store-via-call.expect.md b/compiler/forget/src/__tests__/fixtures/hir/store-via-call.expect.md index 21dbeb1062..6fd054bc21 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/store-via-call.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/store-via-call.expect.md @@ -25,7 +25,6 @@ function foo() { } else { x = $[0]; } - return x; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/store-via-new.expect.md b/compiler/forget/src/__tests__/fixtures/hir/store-via-new.expect.md index 82a5b680ec..011d021b2e 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/store-via-new.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/store-via-new.expect.md @@ -25,7 +25,6 @@ function Foo() { } else { x = $[0]; } - return x; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/switch-non-final-default.expect.md b/compiler/forget/src/__tests__/fixtures/hir/switch-non-final-default.expect.md index cf9fddbb82..f74bef2326 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/switch-non-final-default.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/switch-non-final-default.expect.md @@ -40,47 +40,38 @@ function Component(props) { x = []; const y = undefined; let y$0 = y; - bb1: switch (props.p0) { case 1: { break bb1; } - case true: { x.push(props.p2); let y$1; - if ($[3] === Symbol.for("react.memo_cache_sentinel")) { y$1 = []; $[3] = y$1; } else { y$1 = $[3]; } - y$0 = y$1; break bb1; } - default: { break bb1; } - case false: { const y$2 = x; y$0 = y$2; } } - $[0] = props.p0; $[1] = props.p2; $[2] = x; } else { x = $[2]; } - const c_4 = $[4] !== x; let child; - if (c_4) { child = ; $[4] = x; @@ -88,12 +79,10 @@ function Component(props) { } else { child = $[5]; } - y$0.push(props.p4); const c_6 = $[6] !== y$0; const c_7 = $[7] !== child; let t8; - if (c_6 || c_7) { t8 = {child}; $[6] = y$0; @@ -102,7 +91,6 @@ function Component(props) { } else { t8 = $[8]; } - return t8; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/switch-with-fallthrough.expect.md b/compiler/forget/src/__tests__/fixtures/hir/switch-with-fallthrough.expect.md index ff95fe5002..1fe980f5e6 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/switch-with-fallthrough.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/switch-with-fallthrough.expect.md @@ -41,29 +41,23 @@ function foo(x) { case 0: { const y$0 = 0; } - case 1: { const y$1 = 1; break bb1; } - case 2: { break bb1; } - case 3: { const y$2 = 3; break bb1; } - case 4: { const y$3 = 4; } - case 5: { const y$4 = 5; } - default: { const y$5 = 0; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/switch.expect.md b/compiler/forget/src/__tests__/fixtures/hir/switch.expect.md index c9b86b3e34..334cec3a31 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/switch.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/switch.expect.md @@ -36,20 +36,17 @@ function Component(props) { x = []; const y = undefined; let y$0 = y; - switch (props.p0) { case true: { x.push(props.p2); x.push(props.p3); const y$1 = []; } - case false: { const y$2 = x; y$0 = y$2; } } - $[0] = props.p0; $[1] = props.p2; $[2] = props.p3; @@ -57,10 +54,8 @@ function Component(props) { } else { x = $[3]; } - const c_4 = $[4] !== x; let child; - if (c_4) { child = ; $[4] = x; @@ -68,12 +63,10 @@ function Component(props) { } else { child = $[5]; } - y$0.push(props.p4); const c_6 = $[6] !== y$0; const c_7 = $[7] !== child; let t8; - if (c_6 || c_7) { t8 = {child}; $[6] = y$0; @@ -82,7 +75,6 @@ function Component(props) { } else { t8 = $[8]; } - return t8; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/transitive-alias-fields.expect.md b/compiler/forget/src/__tests__/fixtures/hir/transitive-alias-fields.expect.md index 5d540b365e..10dbab2dcd 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/transitive-alias-fields.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/transitive-alias-fields.expect.md @@ -28,6 +28,7 @@ function component() { x.y = y; p.y = x.y; q.y = p.y; + mutate(q); } diff --git a/compiler/forget/src/__tests__/fixtures/hir/type-binary-operator.expect.md b/compiler/forget/src/__tests__/fixtures/hir/type-binary-operator.expect.md index 420043600c..e4a585eaa3 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/type-binary-operator.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/type-binary-operator.expect.md @@ -24,16 +24,13 @@ function component() { } else { a = $[0]; } - let b; - if ($[1] === Symbol.for("react.memo_cache_sentinel")) { b = someOther(); $[1] = b; } else { b = $[1]; } - if (a > b) { const m = {}; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/type-field-load.expect.md b/compiler/forget/src/__tests__/fixtures/hir/type-field-load.expect.md index 7fc092019f..a093a2bc2c 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/type-field-load.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/type-field-load.expect.md @@ -16,14 +16,11 @@ function component() { const $ = React.useMemoCache(); let x; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { - x = { - t: 1, - }; + x = { t: 1 }; $[0] = x; } else { x = $[0]; } - const p = x.t; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/type-test-field-load-binary-op.expect.md b/compiler/forget/src/__tests__/fixtures/hir/type-test-field-load-binary-op.expect.md index e5fc36fb50..6af4d7a98b 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/type-test-field-load-binary-op.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/type-test-field-load-binary-op.expect.md @@ -27,35 +27,26 @@ function component() { } else { t0 = $[0]; } - let t1; - if ($[1] === Symbol.for("react.memo_cache_sentinel")) { t1 = makeSomePrimitive(); $[1] = t1; } else { t1 = $[1]; } - const c_2 = $[2] !== t0; const c_3 = $[3] !== t1; let x; - if (c_2 || c_3) { - x = { - u: t0, - v: t1, - }; + x = { u: t0, v: t1 }; $[2] = t0; $[3] = t1; $[4] = x; } else { x = $[4]; } - const u = x.u; const v = x.v; - if (u > v) { } diff --git a/compiler/forget/src/__tests__/fixtures/hir/type-test-field-store.expect.md b/compiler/forget/src/__tests__/fixtures/hir/type-test-field-store.expect.md index be26203e25..d1729012c9 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/type-test-field-store.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/type-test-field-store.expect.md @@ -20,14 +20,12 @@ function component() { if ($[0] === Symbol.for("react.memo_cache_sentinel")) { x = {}; let q; - if ($[1] === Symbol.for("react.memo_cache_sentinel")) { q = {}; $[1] = q; } else { q = $[1]; } - x.t = q; $[0] = x; } else { diff --git a/compiler/forget/src/__tests__/fixtures/hir/type-test-polymorphic.expect.md b/compiler/forget/src/__tests__/fixtures/hir/type-test-polymorphic.expect.md index 3ee1f43ab4..69c7e8552b 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/type-test-polymorphic.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/type-test-polymorphic.expect.md @@ -30,23 +30,20 @@ function component() { } else { p = $[0]; } - p + p; let o; - if ($[1] === Symbol.for("react.memo_cache_sentinel")) { o = {}; $[1] = o; } else { o = $[1]; } - const c_2 = $[2] !== o; let x; - if (c_2) { x = {}; x.t = p; + const z = x.t; x.t = o; $[2] = o; diff --git a/compiler/forget/src/__tests__/fixtures/hir/type-test-return-type-inference.expect.md b/compiler/forget/src/__tests__/fixtures/hir/type-test-return-type-inference.expect.md index 59ade258b2..b7b036b3bc 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/type-test-return-type-inference.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/type-test-return-type-inference.expect.md @@ -26,16 +26,13 @@ function component() { } else { x = $[0]; } - let y; - if ($[1] === Symbol.for("react.memo_cache_sentinel")) { y = foo(); $[1] = y; } else { y = $[1]; } - if (x > y) { const z = {}; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/unconditional-break-label.expect.md b/compiler/forget/src/__tests__/fixtures/hir/unconditional-break-label.expect.md index 2da34c5e4b..ffaa70d6e3 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/unconditional-break-label.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/unconditional-break-label.expect.md @@ -18,6 +18,7 @@ function foo(a) { ```javascript function foo(a) { const x = 0; + const x$0 = 1; return a + x$0; } diff --git a/compiler/forget/src/__tests__/fixtures/hir/while-conditional-continue.expect.md b/compiler/forget/src/__tests__/fixtures/hir/while-conditional-continue.expect.md index 6d77095113..822a79e840 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/while-conditional-continue.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/while-conditional-continue.expect.md @@ -23,6 +23,7 @@ function foo(a, b, c, d) { if (b) { continue; } + c(); } diff --git a/compiler/forget/src/__tests__/fixtures/hir/while-property.expect.md b/compiler/forget/src/__tests__/fixtures/hir/while-property.expect.md index 41e5bb34da..5e52a42d7c 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/while-property.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/while-property.expect.md @@ -22,18 +22,15 @@ function foo(a, b) { let x; if (c_0 || c_1) { x = 0; - while (a.b.c) { x = x + b; } - $[0] = a.b.c; $[1] = b; $[2] = x; } else { x = $[2]; } - return x; } diff --git a/compiler/forget/src/__tests__/hir-test.ts b/compiler/forget/src/__tests__/hir-test.ts index 808556f8b8..36b13ae3dd 100644 --- a/compiler/forget/src/__tests__/hir-test.ts +++ b/compiler/forget/src/__tests__/hir-test.ts @@ -7,16 +7,16 @@ "use strict"; -import generate from "@babel/generator"; -import * as parser from "@babel/parser"; -import traverse from "@babel/traverse"; import { wasmFolder } from "@hpcc-js/wasm"; import path from "path"; -import prettier from "prettier"; -import { compile } from "../CompilerPipeline"; +import runReactForgetBabelPlugin from "../Babel/RunReactForgetBabelPlugin"; import { toggleLogging } from "../Utils/logger"; import generateTestsFromFixtures from "./test-utils/generateTestsFromFixtures"; +type TestOutput = { + js: string; +}; + function wrapWithTripleBackticks(s: string, ext?: string) { return `\`\`\`${ext ?? ""} ${s} @@ -46,13 +46,13 @@ describe("React Forget (HIR version)", () => { } } - let items: Array | null = null; + let items: Array = []; let error: Error | null = null; if (options.debug) { toggleLogging(options.debug); } try { - items = transform(input, file); + items.push({ js: runReactForgetBabelPlugin(input, file).code }); } catch (e) { error = e; } @@ -91,6 +91,10 @@ ${outputs.join("\n")} }); function formatErrorOutput(error: Error): string { + // Babel outputs absolute paths of the filename in the error mesage, which means fixtures will + // contain paths that only pertain to your local machine. Strip it just here because that info + // is still useful in real world usage of the Babel plugin. + error.message = error.message.replace(/^\/.*?:\s/, ""); return ` ## Error @@ -107,33 +111,3 @@ ${wrapWithTripleBackticks(js, "javascript")} `.trim(); }); } - -type TestOutput = { - js: string; -}; - -function transform(text: string, file: string): Array { - const items: Array = []; - const ast = parser.parse(text, { - sourceFilename: file, - plugins: ["typescript", "jsx"], - }); - traverse(ast, { - FunctionDeclaration: { - enter(nodePath) { - if (nodePath.scope.getProgramParent() !== nodePath.scope.parent) { - return; - } - - const ast = compile(nodePath); - - const text = prettier.format(generate(ast).code.replace("\n\n", "\n"), { - semi: true, - parser: "babel-ts", - }); - items.push({ js: text }); - }, - }, - }); - return items; -} diff --git a/compiler/forget/src/index.ts b/compiler/forget/src/index.ts index 431faf1d9f..c161bb7b64 100644 --- a/compiler/forget/src/index.ts +++ b/compiler/forget/src/index.ts @@ -5,14 +5,11 @@ * LICENSE file in the root directory of this source tree. */ -import BabelPlugin from "./Babel/BabelPlugin"; - -declare global { - var __DEV__: boolean | null | undefined; -} - +export { default as BabelPlugin } from "./Babel/BabelPlugin"; export { compile, run } from "./CompilerPipeline"; export { printHIR } from "./HIR"; export { printReactiveFunction } from "./ReactiveScopes"; -export default BabelPlugin; +declare global { + var __DEV__: boolean | null | undefined; +}