Commit 9b9537e
committed
Update on "[compiler] Validate against locals being reassigned after render"
Adds a pass which validates that local variables are not reassigned by functions which may be called after render. This is a straightforward forward data-flow analysis, where we:
1. Build up a mapping of context variables in the outer component/hook
2. Find ObjectMethod/FunctionExpressions which may reassign those context variables
3. Propagate aliases of those functions via StoreLocal/LoadLocal
4. Disallow passing those functions with a Freeze effect. This includes JSX arguments, hook arguments, hook return types, etc.
Conceptually, a function that reassigns a local is inherently mutable. Frozen functions must be side-effect free, so these two categories are incompatible and we can use the freeze effect to find all instances of where such functions are disallowed rather than special-casing eg hook calls and JSX.
[ghstack-poisoned]File tree
1 file changed
+9
-13
lines changed- compiler/packages/babel-plugin-react-compiler/src/Validation
1 file changed
+9
-13
lines changedLines changed: 9 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | 8 | | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
| 9 | + | |
17 | 10 | | |
18 | 11 | | |
19 | 12 | | |
20 | 13 | | |
21 | | - | |
22 | 14 | | |
23 | 15 | | |
24 | 16 | | |
| |||
111 | 103 | | |
112 | 104 | | |
113 | 105 | | |
114 | | - | |
115 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
116 | 110 | | |
117 | 111 | | |
118 | 112 | | |
| |||
130 | 124 | | |
131 | 125 | | |
132 | 126 | | |
133 | | - | |
134 | | - | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
135 | 131 | | |
136 | 132 | | |
137 | 133 | | |
| |||
0 commit comments