Skip to content

Commit d82f755

Browse files
committed
[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.
1 parent 41984c8 commit d82f755

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function Component() {
2+
const f = () => () => {
3+
global.property = true;
4+
};
5+
f()();
6+
return <div>Ooops</div>;
7+
}

0 commit comments

Comments
 (0)