Add ContextMutation variant of FunctionEffect
ghstack-source-id: f3da80ed22acd916db0cecad9f2b80ba4c01c6eb Pull Request resolved: https://github.com/facebook/react-forget/pull/2879
Joe Savona committed
Apr 19, 2024 at 17:44 UTC
f7a643c7b25e5932da85b2755282375311fadede
2 files changed
+22
-7
compiler/packages/babel-plugin-react-forget/src/HIR/HIR.ts
+11
-4
@@ -284,10 +284,17 @@ export type HIRFunction = {
284
directives: Array<string>;
285
};
286
287
-export type FunctionEffect = {
288
- kind: "GlobalMutation";
289
- error: CompilerErrorDetailOptions;
290
-};
287
+export type FunctionEffect =
288
+ | {
289
+ kind: "GlobalMutation";
290
+ error: CompilerErrorDetailOptions;
291
+ }
292
+ | {
293
+ kind: "ContextMutation";
294
+ places: Array<Place>;
295
+ effect: Effect;
296
+ loc: SourceLocation;
297
+ };
298
299
/*
300
* Each reactive scope may have its own control-flow, so the instructions form
compiler/packages/babel-plugin-react-forget/src/Inference/InferReferenceEffects.ts
+11
-3
@@ -237,12 +237,20 @@ export default function inferReferenceEffects(
237
if (!options.isFunctionExpression) {
238
functionEffects.forEach((eff) => {
239
switch (eff.kind) {
240
- case "GlobalMutation":
240
+ case "GlobalMutation": {
241
CompilerError.throw(eff.error);
242
+ }
243
+ case "ContextMutation": {
244
+ CompilerError.throw({
245
+ severity: ErrorSeverity.Invariant,
246
+ reason: `Unexpected ContextMutation in top-level function effects`,
247
+ loc: eff.loc,
248
+ });
249
+ }
250
default:
251
assertExhaustive(
244
- eff.kind,
245
- `Unexpected function effect kind \`${eff.kind}\``
252
+ eff,
253
+ `Unexpected function effect kind \`${(eff as any).kind}\``
254
);
255
}
256
});