From 995f4b0528430c6d37e03e0726fbd22ea8273cf7 Mon Sep 17 00:00:00 2001 From: Mofei Zhang Date: Wed, 6 Dec 2023 13:20:50 -0500 Subject: [PATCH] [bugfix] Fix constant propagation to ObjectMethods --- .../src/Optimization/ConstantPropagation.ts | 1 + ...d.expect.md => constant-prop-to-object-method.expect.md} | 6 ++++-- ...n-object-method.js => constant-prop-to-object-method.js} | 0 compiler/packages/sprout/src/SproutTodoFilter.ts | 1 - 4 files changed, 5 insertions(+), 3 deletions(-) rename compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/{bug-context-vars-in-object-method.expect.md => constant-prop-to-object-method.expect.md} (91%) rename compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/{bug-context-vars-in-object-method.js => constant-prop-to-object-method.js} (100%) diff --git a/compiler/packages/babel-plugin-react-forget/src/Optimization/ConstantPropagation.ts b/compiler/packages/babel-plugin-react-forget/src/Optimization/ConstantPropagation.ts index 1f873cdb98..6c5c263059 100644 --- a/compiler/packages/babel-plugin-react-forget/src/Optimization/ConstantPropagation.ts +++ b/compiler/packages/babel-plugin-react-forget/src/Optimization/ConstantPropagation.ts @@ -434,6 +434,7 @@ function evaluateInstruction( } return placeValue; } + case "ObjectMethod": case "FunctionExpression": { constantPropagationImpl(value.loweredFunc.func, constants); return null; diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/bug-context-vars-in-object-method.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/constant-prop-to-object-method.expect.md similarity index 91% rename from compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/bug-context-vars-in-object-method.expect.md rename to compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/constant-prop-to-object-method.expect.md index 6e16d5eceb..f058d6f81e 100644 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/bug-context-vars-in-object-method.expect.md +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/constant-prop-to-object-method.expect.md @@ -33,7 +33,7 @@ function Foo() { if ($[0] === Symbol.for("react.memo_cache_sentinel")) { const x = { foo() { - return identity(CONSTANT); + return identity(1); }, }; @@ -51,4 +51,6 @@ export const FIXTURE_ENTRYPOINT = { }; ``` - \ No newline at end of file + +### Eval output +(kind: ok) 1 \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/bug-context-vars-in-object-method.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/constant-prop-to-object-method.js similarity index 100% rename from compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/bug-context-vars-in-object-method.js rename to compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/constant-prop-to-object-method.js diff --git a/compiler/packages/sprout/src/SproutTodoFilter.ts b/compiler/packages/sprout/src/SproutTodoFilter.ts index 62f8ce2d88..7990cc08ea 100644 --- a/compiler/packages/sprout/src/SproutTodoFilter.ts +++ b/compiler/packages/sprout/src/SproutTodoFilter.ts @@ -515,7 +515,6 @@ const skipFilter = new Set([ "bug-jsx-memberexpr-tag-in-lambda", "bug-invalid-code-when-bailout", "component-syntax-ref-gating.flow", - "bug-context-vars-in-object-method", // 'react-forget-runtime' not yet supported "flag-enable-emit-hook-guards",