From 60f898e43367371098fe42d69c19f53c885c098a Mon Sep 17 00:00:00 2001 From: Joe Savona Date: Thu, 26 Jun 2025 17:07:45 -0700 Subject: [PATCH] [compiler] Repro for missed case of global mutation I realized a pattern of global mutations that we don't currently detect (both in the old and new inference models). If you hide the mutation inside a function returned from another function, we lose track of it: ```js const f = () => () => { global.property = true; }; f()(); ``` Roughly speaking, we need to track that if the return value of `f` is mutated, that it should count as triggering some effects. Right now we encode the idea that a function specifically can have side effects if it is mutated, but other values don't have a way to represent this. I'm thinking that we change the shape of the `Create` effect a bit, and allow room for an optional "mutation effects" array. Then, InferMutationAliasingRanges can visit these effects like it does when trying to find transitive function effects. --- .../error.invalid-assign-global-in-function-factory.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-assign-global-in-function-factory.js diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-assign-global-in-function-factory.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-assign-global-in-function-factory.js new file mode 100644 index 0000000000..83b332297f --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-assign-global-in-function-factory.js @@ -0,0 +1,7 @@ +function Component() { + const f = () => () => { + global.property = true; + }; + f()(); + return
Ooops
; +}