@samitouri / QOS-React / commits / 7d11445d8e
Fork 0

The library for web and native user interfaces.

Revamp compilation modes

We currently have multiple flags for targeting which functions to compile, but they are actually mutually exclusive. This PR consolidates to a single `compilationMode: 'annotation' | 'infer' | 'all'` flag: * Annotation compiles only functions that explicitly opt-in with "use forget" * Infer compiles explicitly opted-in functions (via "use forget") as well as any known/inferred components or hooks: * Component declarations * Component or hook-like functions (same rules as the ESLint plugin but with an extra check for whether it uses JSX or calls a hook) * All compiles all top-level functions. We should get rid of this in a follow-up and make tests use infer mode by default, and add explicit opt-ins where necessary. In all modes, "use no forget" always takes precedence and can be used to opt-out. The default mode is now "infer".

Joe Savona committed Aug 29, 2023 at 22:09 UTC 7d11445d8e3145d69ca1352bd21bad0ed15fd141
45 files changed +739 -734
compiler/crates/forget_hermes_parser/tests/fixtures/codegen-instrument-forget-gating-test.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @instrumentForget @forgetDirective @gating
1 +// @instrumentForget @compilationMode(annotation) @gating
2
3 function Bar(props) {
4 "use forget";
compiler/crates/forget_hermes_parser/tests/fixtures/codegen-instrument-forget-test.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @instrumentForget @forgetDirective
1 +// @instrumentForget @compilationMode(annotation)
2
3 function Bar(props) {
4 "use forget";
compiler/crates/forget_hermes_parser/tests/fixtures/gating-test-export-default-function.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @gating @forgetDirective
1 +// @gating @compilationMode(annotation)
2 export default function Bar(props) {
3 "use forget";
4 return <div>{props.bar}</div>;
compiler/crates/forget_hermes_parser/tests/fixtures/gating-test-export-function-and-default.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @gating @forgetDirective
1 +// @gating @compilationMode(annotation)
2 export default function Bar(props) {
3 "use forget";
4 return <div>{props.bar}</div>;
compiler/crates/forget_hermes_parser/tests/fixtures/gating-test-export-function.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @gating @forgetDirective
1 +// @gating @compilationMode(annotation)
2 export function Bar(props) {
3 "use forget";
4 return <div>{props.bar}</div>;
compiler/crates/forget_hermes_parser/tests/fixtures/gating-test.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @gating @forgetDirective
1 +// @gating @compilationMode(annotation)
2 function Bar(props) {
3 "use forget";
4 return <div>{props.bar}</div>;
compiler/crates/forget_hermes_parser/tests/snapshots/parser_test__fixtures@codegen-instrument-forget-gating-test.js.snap
+101 -101
@@ -4,7 +4,7 @@ expression: "format!(\"Input:\\n{input}\\n\\nOutput:\\n{output}\")"
4 input_file: crates/forget_hermes_parser/tests/fixtures/codegen-instrument-forget-gating-test.js
5 ---
6 Input:
7 -// @instrumentForget @forgetDirective @gating
7 +// @instrumentForget @compilationMode(annotation) @gating
8
9 function Bar(props) {
10 "use forget";
@@ -33,8 +33,8 @@ Output:
33 "typeAnnotation": null,
34 "loc": null,
35 "range": [
36 - 56,
37 - 59
36 + 68,
37 + 71
38 ]
39 },
40 "params": [
@@ -44,8 +44,8 @@ Output:
44 "typeAnnotation": null,
45 "loc": null,
46 "range": [
47 - 60,
48 - 65
47 + 72,
48 + 77
49 ]
50 }
51 ],
@@ -59,15 +59,15 @@ Output:
59 "value": "use forget",
60 "loc": null,
61 "range": [
62 - 71,
63 - 83
62 + 83,
63 + 95
64 ]
65 },
66 "directive": null,
67 "loc": null,
68 "range": [
69 - 71,
70 - 84
69 + 83,
70 + 96
71 ]
72 },
73 {
@@ -81,16 +81,16 @@ Output:
81 "name": "div",
82 "loc": null,
83 "range": [
84 - 95,
85 - 98
84 + 107,
85 + 110
86 ]
87 },
88 "attributes": [],
89 "selfClosing": false,
90 "loc": null,
91 "range": [
92 - 94,
93 - 99
92 + 106,
93 + 111
94 ]
95 },
96 "children": [
@@ -104,8 +104,8 @@ Output:
104 "typeAnnotation": null,
105 "loc": null,
106 "range": [
107 - 100,
108 - 105
107 + 112,
108 + 117
109 ]
110 },
111 "property": {
@@ -114,21 +114,21 @@ Output:
114 "typeAnnotation": null,
115 "loc": null,
116 "range": [
117 - 106,
118 - 109
117 + 118,
118 + 121
119 ]
120 },
121 "computed": false,
122 "loc": null,
123 "range": [
124 - 100,
125 - 109
124 + 112,
125 + 121
126 ]
127 },
128 "loc": null,
129 "range": [
130 - 99,
131 - 110
130 + 111,
131 + 122
132 ]
133 }
134 ],
@@ -139,46 +139,46 @@ Output:
139 "name": "div",
140 "loc": null,
141 "range": [
142 - 112,
143 - 115
142 + 124,
143 + 127
144 ]
145 },
146 "loc": null,
147 "range": [
148 - 110,
149 - 116
148 + 122,
149 + 128
150 ]
151 },
152 "loc": null,
153 "range": [
154 - 94,
155 - 116
154 + 106,
155 + 128
156 ]
157 },
158 "loc": null,
159 "range": [
160 - 87,
161 - 117
160 + 99,
161 + 129
162 ]
163 }
164 ],
165 "loc": null,
166 "range": [
167 - 67,
168 - 119
167 + 79,
168 + 131
169 ]
170 },
171 "generator": false,
172 "async": false,
173 "loc": null,
174 "range": [
175 - 47,
176 - 119
175 + 59,
176 + 131
177 ],
178 "loc": null,
179 "range": [
180 - 47,
181 - 119
180 + 59,
181 + 131
182 ]
183 },
184 {
@@ -189,8 +189,8 @@ Output:
189 "typeAnnotation": null,
190 "loc": null,
191 "range": [
192 - 130,
193 - 138
192 + 142,
193 + 150
194 ]
195 },
196 "params": [
@@ -200,8 +200,8 @@ Output:
200 "typeAnnotation": null,
201 "loc": null,
202 "range": [
203 - 139,
204 - 144
203 + 151,
204 + 156
205 ]
206 }
207 ],
@@ -219,16 +219,16 @@ Output:
219 "name": "Bar",
220 "loc": null,
221 "range": [
222 - 158,
223 - 161
222 + 170,
223 + 173
224 ]
225 },
226 "attributes": [],
227 "selfClosing": false,
228 "loc": null,
229 "range": [
230 - 157,
231 - 162
230 + 169,
231 + 174
232 ]
233 },
234 "children": [
@@ -242,8 +242,8 @@ Output:
242 "typeAnnotation": null,
243 "loc": null,
244 "range": [
245 - 163,
246 - 168
245 + 175,
246 + 180
247 ]
248 },
249 "property": {
@@ -252,21 +252,21 @@ Output:
252 "typeAnnotation": null,
253 "loc": null,
254 "range": [
255 - 169,
256 - 177
255 + 181,
256 + 189
257 ]
258 },
259 "computed": false,
260 "loc": null,
261 "range": [
262 - 163,
263 - 177
262 + 175,
263 + 189
264 ]
265 },
266 "loc": null,
267 "range": [
268 - 162,
269 - 178
268 + 174,
269 + 190
270 ]
271 }
272 ],
@@ -277,46 +277,46 @@ Output:
277 "name": "Bar",
278 "loc": null,
279 "range": [
280 - 180,
281 - 183
280 + 192,
281 + 195
282 ]
283 },
284 "loc": null,
285 "range": [
286 - 178,
287 - 184
286 + 190,
287 + 196
288 ]
289 },
290 "loc": null,
291 "range": [
292 - 157,
293 - 184
292 + 169,
293 + 196
294 ]
295 },
296 "loc": null,
297 "range": [
298 - 150,
299 - 185
298 + 162,
299 + 197
300 ]
301 }
302 ],
303 "loc": null,
304 "range": [
305 - 146,
306 - 187
305 + 158,
306 + 199
307 ]
308 },
309 "generator": false,
310 "async": false,
311 "loc": null,
312 "range": [
313 - 121,
314 - 187
313 + 133,
314 + 199
315 ],
316 "loc": null,
317 "range": [
318 - 121,
319 - 187
318 + 133,
319 + 199
320 ]
321 },
322 {
@@ -327,8 +327,8 @@ Output:
327 "typeAnnotation": null,
328 "loc": null,
329 "range": [
330 - 198,
331 - 201
330 + 210,
331 + 213
332 ]
333 },
334 "params": [
@@ -338,8 +338,8 @@ Output:
338 "typeAnnotation": null,
339 "loc": null,
340 "range": [
341 - 202,
342 - 207
341 + 214,
342 + 219
343 ]
344 }
345 ],
@@ -353,15 +353,15 @@ Output:
353 "value": "use forget",
354 "loc": null,
355 "range": [
356 - 213,
357 - 225
356 + 225,
357 + 237
358 ]
359 },
360 "directive": null,
361 "loc": null,
362 "range": [
363 - 213,
364 - 226
363 + 225,
364 + 238
365 ]
366 },
367 {
@@ -375,16 +375,16 @@ Output:
375 "name": "Foo",
376 "loc": null,
377 "range": [
378 - 237,
379 - 240
378 + 249,
379 + 252
380 ]
381 },
382 "attributes": [],
383 "selfClosing": false,
384 "loc": null,
385 "range": [
386 - 236,
387 - 241
386 + 248,
387 + 253
388 ]
389 },
390 "children": [
@@ -398,8 +398,8 @@ Output:
398 "typeAnnotation": null,
399 "loc": null,
400 "range": [
401 - 242,
402 - 247
401 + 254,
402 + 259
403 ]
404 },
405 "property": {
@@ -408,21 +408,21 @@ Output:
408 "typeAnnotation": null,
409 "loc": null,
410 "range": [
411 - 248,
412 - 251
411 + 260,
412 + 263
413 ]
414 },
415 "computed": false,
416 "loc": null,
417 "range": [
418 - 242,
419 - 251
418 + 254,
419 + 263
420 ]
421 },
422 "loc": null,
423 "range": [
424 - 241,
425 - 252
424 + 253,
425 + 264
426 ]
427 }
428 ],
@@ -433,53 +433,53 @@ Output:
433 "name": "Foo",
434 "loc": null,
435 "range": [
436 - 254,
437 - 257
436 + 266,
437 + 269
438 ]
439 },
440 "loc": null,
441 "range": [
442 - 252,
443 - 258
442 + 264,
443 + 270
444 ]
445 },
446 "loc": null,
447 "range": [
448 - 236,
449 - 258
448 + 248,
449 + 270
450 ]
451 },
452 "loc": null,
453 "range": [
454 - 229,
455 - 259
454 + 241,
455 + 271
456 ]
457 }
458 ],
459 "loc": null,
460 "range": [
461 - 209,
462 - 261
461 + 221,
462 + 273
463 ]
464 },
465 "generator": false,
466 "async": false,
467 "loc": null,
468 "range": [
469 - 189,
470 - 261
469 + 201,
470 + 273
471 ],
472 "loc": null,
473 "range": [
474 - 189,
475 - 261
474 + 201,
475 + 273
476 ]
477 }
478 ],
479 "sourceType": "script",
480 "loc": null,
481 "range": [
482 - 47,
483 - 261
482 + 59,
483 + 273
484 ]
485 }
compiler/crates/forget_hermes_parser/tests/snapshots/parser_test__fixtures@codegen-instrument-forget-test.js.snap
+101 -101
@@ -4,7 +4,7 @@ expression: "format!(\"Input:\\n{input}\\n\\nOutput:\\n{output}\")"
4 input_file: crates/forget_hermes_parser/tests/fixtures/codegen-instrument-forget-test.js
5 ---
6 Input:
7 -// @instrumentForget @forgetDirective
7 +// @instrumentForget @compilationMode(annotation)
8
9 function Bar(props) {
10 "use forget";
@@ -33,8 +33,8 @@ Output:
33 "typeAnnotation": null,
34 "loc": null,
35 "range": [
36 - 48,
37 - 51
36 + 60,
37 + 63
38 ]
39 },
40 "params": [
@@ -44,8 +44,8 @@ Output:
44 "typeAnnotation": null,
45 "loc": null,
46 "range": [
47 - 52,
48 - 57
47 + 64,
48 + 69
49 ]
50 }
51 ],
@@ -59,15 +59,15 @@ Output:
59 "value": "use forget",
60 "loc": null,
61 "range": [
62 - 63,
63 - 75
62 + 75,
63 + 87
64 ]
65 },
66 "directive": null,
67 "loc": null,
68 "range": [
69 - 63,
70 - 76
69 + 75,
70 + 88
71 ]
72 },
73 {
@@ -81,16 +81,16 @@ Output:
81 "name": "div",
82 "loc": null,
83 "range": [
84 - 87,
85 - 90
84 + 99,
85 + 102
86 ]
87 },
88 "attributes": [],
89 "selfClosing": false,
90 "loc": null,
91 "range": [
92 - 86,
93 - 91
92 + 98,
93 + 103
94 ]
95 },
96 "children": [
@@ -104,8 +104,8 @@ Output:
104 "typeAnnotation": null,
105 "loc": null,
106 "range": [
107 - 92,
108 - 97
107 + 104,
108 + 109
109 ]
110 },
111 "property": {
@@ -114,21 +114,21 @@ Output:
114 "typeAnnotation": null,
115 "loc": null,
116 "range": [
117 - 98,
118 - 101
117 + 110,
118 + 113
119 ]
120 },
121 "computed": false,
122 "loc": null,
123 "range": [
124 - 92,
125 - 101
124 + 104,
125 + 113
126 ]
127 },
128 "loc": null,
129 "range": [
130 - 91,
131 - 102
130 + 103,
131 + 114
132 ]
133 }
134 ],
@@ -139,46 +139,46 @@ Output:
139 "name": "div",
140 "loc": null,
141 "range": [
142 - 104,
143 - 107
142 + 116,
143 + 119
144 ]
145 },
146 "loc": null,
147 "range": [
148 - 102,
149 - 108
148 + 114,
149 + 120
150 ]
151 },
152 "loc": null,
153 "range": [
154 - 86,
155 - 108
154 + 98,
155 + 120
156 ]
157 },
158 "loc": null,
159 "range": [
160 - 79,
161 - 109
160 + 91,
161 + 121
162 ]
163 }
164 ],
165 "loc": null,
166 "range": [
167 - 59,
168 - 111
167 + 71,
168 + 123
169 ]
170 },
171 "generator": false,
172 "async": false,
173 "loc": null,
174 "range": [
175 - 39,
176 - 111
175 + 51,
176 + 123
177 ],
178 "loc": null,
179 "range": [
180 - 39,
181 - 111
180 + 51,
181 + 123
182 ]
183 },
184 {
@@ -189,8 +189,8 @@ Output:
189 "typeAnnotation": null,
190 "loc": null,
191 "range": [
192 - 122,
193 - 130
192 + 134,
193 + 142
194 ]
195 },
196 "params": [
@@ -200,8 +200,8 @@ Output:
200 "typeAnnotation": null,
201 "loc": null,
202 "range": [
203 - 131,
204 - 136
203 + 143,
204 + 148
205 ]
206 }
207 ],
@@ -219,16 +219,16 @@ Output:
219 "name": "Bar",
220 "loc": null,
221 "range": [
222 - 150,
223 - 153
222 + 162,
223 + 165
224 ]
225 },
226 "attributes": [],
227 "selfClosing": false,
228 "loc": null,
229 "range": [
230 - 149,
231 - 154
230 + 161,
231 + 166
232 ]
233 },
234 "children": [
@@ -242,8 +242,8 @@ Output:
242 "typeAnnotation": null,
243 "loc": null,
244 "range": [
245 - 155,
246 - 160
245 + 167,
246 + 172
247 ]
248 },
249 "property": {
@@ -252,21 +252,21 @@ Output:
252 "typeAnnotation": null,
253 "loc": null,
254 "range": [
255 - 161,
256 - 169
255 + 173,
256 + 181
257 ]
258 },
259 "computed": false,
260 "loc": null,
261 "range": [
262 - 155,
263 - 169
262 + 167,
263 + 181
264 ]
265 },
266 "loc": null,
267 "range": [
268 - 154,
269 - 170
268 + 166,
269 + 182
270 ]
271 }
272 ],
@@ -277,46 +277,46 @@ Output:
277 "name": "Bar",
278 "loc": null,
279 "range": [
280 - 172,
281 - 175
280 + 184,
281 + 187
282 ]
283 },
284 "loc": null,
285 "range": [
286 - 170,
287 - 176
286 + 182,
287 + 188
288 ]
289 },
290 "loc": null,
291 "range": [
292 - 149,
293 - 176
292 + 161,
293 + 188
294 ]
295 },
296 "loc": null,
297 "range": [
298 - 142,
299 - 177
298 + 154,
299 + 189
300 ]
301 }
302 ],
303 "loc": null,
304 "range": [
305 - 138,
306 - 179
305 + 150,
306 + 191
307 ]
308 },
309 "generator": false,
310 "async": false,
311 "loc": null,
312 "range": [
313 - 113,
314 - 179
313 + 125,
314 + 191
315 ],
316 "loc": null,
317 "range": [
318 - 113,
319 - 179
318 + 125,
319 + 191
320 ]
321 },
322 {
@@ -327,8 +327,8 @@ Output:
327 "typeAnnotation": null,
328 "loc": null,
329 "range": [
330 - 190,
331 - 193
330 + 202,
331 + 205
332 ]
333 },
334 "params": [
@@ -338,8 +338,8 @@ Output:
338 "typeAnnotation": null,
339 "loc": null,
340 "range": [
341 - 194,
342 - 199
341 + 206,
342 + 211
343 ]
344 }
345 ],
@@ -353,15 +353,15 @@ Output:
353 "value": "use forget",
354 "loc": null,
355 "range": [
356 - 205,
357 - 217
356 + 217,
357 + 229
358 ]
359 },
360 "directive": null,
361 "loc": null,
362 "range": [
363 - 205,
364 - 218
363 + 217,
364 + 230
365 ]
366 },
367 {
@@ -375,16 +375,16 @@ Output:
375 "name": "Foo",
376 "loc": null,
377 "range": [
378 - 229,
379 - 232
378 + 241,
379 + 244
380 ]
381 },
382 "attributes": [],
383 "selfClosing": false,
384 "loc": null,
385 "range": [
386 - 228,
387 - 233
386 + 240,
387 + 245
388 ]
389 },
390 "children": [
@@ -398,8 +398,8 @@ Output:
398 "typeAnnotation": null,
399 "loc": null,
400 "range": [
401 - 234,
402 - 239
401 + 246,
402 + 251
403 ]
404 },
405 "property": {
@@ -408,21 +408,21 @@ Output:
408 "typeAnnotation": null,
409 "loc": null,
410 "range": [
411 - 240,
412 - 243
411 + 252,
412 + 255
413 ]
414 },
415 "computed": false,
416 "loc": null,
417 "range": [
418 - 234,
419 - 243
418 + 246,
419 + 255
420 ]
421 },
422 "loc": null,
423 "range": [
424 - 233,
425 - 244
424 + 245,
425 + 256
426 ]
427 }
428 ],
@@ -433,53 +433,53 @@ Output:
433 "name": "Foo",
434 "loc": null,
435 "range": [
436 - 246,
437 - 249
436 + 258,
437 + 261
438 ]
439 },
440 "loc": null,
441 "range": [
442 - 244,
443 - 250
442 + 256,
443 + 262
444 ]
445 },
446 "loc": null,
447 "range": [
448 - 228,
449 - 250
448 + 240,
449 + 262
450 ]
451 },
452 "loc": null,
453 "range": [
454 - 221,
455 - 251
454 + 233,
455 + 263
456 ]
457 }
458 ],
459 "loc": null,
460 "range": [
461 - 201,
462 - 253
461 + 213,
462 + 265
463 ]
464 },
465 "generator": false,
466 "async": false,
467 "loc": null,
468 "range": [
469 - 181,
470 - 253
469 + 193,
470 + 265
471 ],
472 "loc": null,
473 "range": [
474 - 181,
475 - 253
474 + 193,
475 + 265
476 ]
477 }
478 ],
479 "sourceType": "script",
480 "loc": null,
481 "range": [
482 - 39,
483 - 253
482 + 51,
483 + 265
484 ]
485 }
compiler/crates/forget_hermes_parser/tests/snapshots/parser_test__fixtures@gating-test-export-default-function.js.snap
+103 -103
@@ -4,7 +4,7 @@ expression: "format!(\"Input:\\n{input}\\n\\nOutput:\\n{output}\")"
4 input_file: crates/forget_hermes_parser/tests/fixtures/gating-test-export-default-function.js
5 ---
6 Input:
7 -// @gating @forgetDirective
7 +// @gating @compilationMode(annotation)
8 export default function Bar(props) {
9 "use forget";
10 return <div>{props.bar}</div>;
@@ -34,8 +34,8 @@ Output:
34 "typeAnnotation": null,
35 "loc": null,
36 "range": [
37 - 52,
38 - 55
37 + 64,
38 + 67
39 ]
40 },
41 "params": [
@@ -45,8 +45,8 @@ Output:
45 "typeAnnotation": null,
46 "loc": null,
47 "range": [
48 - 56,
49 - 61
48 + 68,
49 + 73
50 ]
51 }
52 ],
@@ -60,15 +60,15 @@ Output:
60 "value": "use forget",
61 "loc": null,
62 "range": [
63 - 67,
64 - 79
63 + 79,
64 + 91
65 ]
66 },
67 "directive": null,
68 "loc": null,
69 "range": [
70 - 67,
71 - 80
70 + 79,
71 + 92
72 ]
73 },
74 {
@@ -82,16 +82,16 @@ Output:
82 "name": "div",
83 "loc": null,
84 "range": [
85 - 91,
86 - 94
85 + 103,
86 + 106
87 ]
88 },
89 "attributes": [],
90 "selfClosing": false,
91 "loc": null,
92 "range": [
93 - 90,
94 - 95
93 + 102,
94 + 107
95 ]
96 },
97 "children": [
@@ -105,8 +105,8 @@ Output:
105 "typeAnnotation": null,
106 "loc": null,
107 "range": [
108 - 96,
109 - 101
108 + 108,
109 + 113
110 ]
111 },
112 "property": {
@@ -115,21 +115,21 @@ Output:
115 "typeAnnotation": null,
116 "loc": null,
117 "range": [
118 - 102,
119 - 105
118 + 114,
119 + 117
120 ]
121 },
122 "computed": false,
123 "loc": null,
124 "range": [
125 - 96,
126 - 105
125 + 108,
126 + 117
127 ]
128 },
129 "loc": null,
130 "range": [
131 - 95,
132 - 106
131 + 107,
132 + 118
133 ]
134 }
135 ],
@@ -140,52 +140,52 @@ Output:
140 "name": "div",
141 "loc": null,
142 "range": [
143 - 108,
144 - 111
143 + 120,
144 + 123
145 ]
146 },
147 "loc": null,
148 "range": [
149 - 106,
150 - 112
149 + 118,
150 + 124
151 ]
152 },
153 "loc": null,
154 "range": [
155 - 90,
156 - 112
155 + 102,
156 + 124
157 ]
158 },
159 "loc": null,
160 "range": [
161 - 83,
162 - 113
161 + 95,
162 + 125
163 ]
164 }
165 ],
166 "loc": null,
167 "range": [
168 - 63,
169 - 115
168 + 75,
169 + 127
170 ]
171 },
172 "generator": false,
173 "async": false,
174 "loc": null,
175 "range": [
176 - 43,
177 - 115
176 + 55,
177 + 127
178 ],
179 "loc": null,
180 "range": [
181 - 43,
182 - 115
181 + 55,
182 + 127
183 ]
184 },
185 "loc": null,
186 "range": [
187 - 28,
188 - 115
187 + 40,
188 + 127
189 ]
190 },
191 {
@@ -196,8 +196,8 @@ Output:
196 "typeAnnotation": null,
197 "loc": null,
198 "range": [
199 - 126,
200 - 134
199 + 138,
200 + 146
201 ]
202 },
203 "params": [
@@ -207,8 +207,8 @@ Output:
207 "typeAnnotation": null,
208 "loc": null,
209 "range": [
210 - 135,
211 - 140
210 + 147,
211 + 152
212 ]
213 }
214 ],
@@ -226,16 +226,16 @@ Output:
226 "name": "Bar",
227 "loc": null,
228 "range": [
229 - 154,
230 - 157
229 + 166,
230 + 169
231 ]
232 },
233 "attributes": [],
234 "selfClosing": false,
235 "loc": null,
236 "range": [
237 - 153,
238 - 158
237 + 165,
238 + 170
239 ]
240 },
241 "children": [
@@ -249,8 +249,8 @@ Output:
249 "typeAnnotation": null,
250 "loc": null,
251 "range": [
252 - 159,
253 - 164
252 + 171,
253 + 176
254 ]
255 },
256 "property": {
@@ -259,21 +259,21 @@ Output:
259 "typeAnnotation": null,
260 "loc": null,
261 "range": [
262 - 165,
263 - 173
262 + 177,
263 + 185
264 ]
265 },
266 "computed": false,
267 "loc": null,
268 "range": [
269 - 159,
270 - 173
269 + 171,
270 + 185
271 ]
272 },
273 "loc": null,
274 "range": [
275 - 158,
276 - 174
275 + 170,
276 + 186
277 ]
278 }
279 ],
@@ -284,46 +284,46 @@ Output:
284 "name": "Bar",
285 "loc": null,
286 "range": [
287 - 176,
288 - 179
287 + 188,
288 + 191
289 ]
290 },
291 "loc": null,
292 "range": [
293 - 174,
294 - 180
293 + 186,
294 + 192
295 ]
296 },
297 "loc": null,
298 "range": [
299 - 153,
300 - 180
299 + 165,
300 + 192
301 ]
302 },
303 "loc": null,
304 "range": [
305 - 146,
306 - 181
305 + 158,
306 + 193
307 ]
308 }
309 ],
310 "loc": null,
311 "range": [
312 - 142,
313 - 183
312 + 154,
313 + 195
314 ]
315 },
316 "generator": false,
317 "async": false,
318 "loc": null,
319 "range": [
320 - 117,
321 - 183
320 + 129,
321 + 195
322 ],
323 "loc": null,
324 "range": [
325 - 117,
326 - 183
325 + 129,
326 + 195
327 ]
328 },
329 {
@@ -334,8 +334,8 @@ Output:
334 "typeAnnotation": null,
335 "loc": null,
336 "range": [
337 - 194,
338 - 197
337 + 206,
338 + 209
339 ]
340 },
341 "params": [
@@ -345,8 +345,8 @@ Output:
345 "typeAnnotation": null,
346 "loc": null,
347 "range": [
348 - 198,
349 - 203
348 + 210,
349 + 215
350 ]
351 }
352 ],
@@ -360,15 +360,15 @@ Output:
360 "value": "use forget",
361 "loc": null,
362 "range": [
363 - 209,
364 - 221
363 + 221,
364 + 233
365 ]
366 },
367 "directive": null,
368 "loc": null,
369 "range": [
370 - 209,
371 - 222
370 + 221,
371 + 234
372 ]
373 },
374 {
@@ -382,16 +382,16 @@ Output:
382 "name": "Foo",
383 "loc": null,
384 "range": [
385 - 233,
386 - 236
385 + 245,
386 + 248
387 ]
388 },
389 "attributes": [],
390 "selfClosing": false,
391 "loc": null,
392 "range": [
393 - 232,
394 - 237
393 + 244,
394 + 249
395 ]
396 },
397 "children": [
@@ -405,8 +405,8 @@ Output:
405 "typeAnnotation": null,
406 "loc": null,
407 "range": [
408 - 238,
409 - 243
408 + 250,
409 + 255
410 ]
411 },
412 "property": {
@@ -415,21 +415,21 @@ Output:
415 "typeAnnotation": null,
416 "loc": null,
417 "range": [
418 - 244,
419 - 247
418 + 256,
419 + 259
420 ]
421 },
422 "computed": false,
423 "loc": null,
424 "range": [
425 - 238,
426 - 247
425 + 250,
426 + 259
427 ]
428 },
429 "loc": null,
430 "range": [
431 - 237,
432 - 248
431 + 249,
432 + 260
433 ]
434 }
435 ],
@@ -440,53 +440,53 @@ Output:
440 "name": "Foo",
441 "loc": null,
442 "range": [
443 - 250,
444 - 253
443 + 262,
444 + 265
445 ]
446 },
447 "loc": null,
448 "range": [
449 - 248,
450 - 254
449 + 260,
450 + 266
451 ]
452 },
453 "loc": null,
454 "range": [
455 - 232,
456 - 254
455 + 244,
456 + 266
457 ]
458 },
459 "loc": null,
460 "range": [
461 - 225,
462 - 255
461 + 237,
462 + 267
463 ]
464 }
465 ],
466 "loc": null,
467 "range": [
468 - 205,
469 - 257
468 + 217,
469 + 269
470 ]
471 },
472 "generator": false,
473 "async": false,
474 "loc": null,
475 "range": [
476 - 185,
477 - 257
476 + 197,
477 + 269
478 ],
479 "loc": null,
480 "range": [
481 - 185,
482 - 257
481 + 197,
482 + 269
483 ]
484 }
485 ],
486 "sourceType": "script",
487 "loc": null,
488 "range": [
489 - 28,
490 - 257
489 + 40,
490 + 269
491 ]
492 }
compiler/crates/forget_hermes_parser/tests/snapshots/parser_test__fixtures@gating-test-export-function-and-default.js.snap
+105 -105
@@ -4,7 +4,7 @@ expression: "format!(\"Input:\\n{input}\\n\\nOutput:\\n{output}\")"
4 input_file: crates/forget_hermes_parser/tests/fixtures/gating-test-export-function-and-default.js
5 ---
6 Input:
7 -// @gating @forgetDirective
7 +// @gating @compilationMode(annotation)
8 export default function Bar(props) {
9 "use forget";
10 return <div>{props.bar}</div>;
@@ -34,8 +34,8 @@ Output:
34 "typeAnnotation": null,
35 "loc": null,
36 "range": [
37 - 52,
38 - 55
37 + 64,
38 + 67
39 ]
40 },
41 "params": [
@@ -45,8 +45,8 @@ Output:
45 "typeAnnotation": null,
46 "loc": null,
47 "range": [
48 - 56,
49 - 61
48 + 68,
49 + 73
50 ]
51 }
52 ],
@@ -60,15 +60,15 @@ Output:
60 "value": "use forget",
61 "loc": null,
62 "range": [
63 - 67,
64 - 79
63 + 79,
64 + 91
65 ]
66 },
67 "directive": null,
68 "loc": null,
69 "range": [
70 - 67,
71 - 80
70 + 79,
71 + 92
72 ]
73 },
74 {
@@ -82,16 +82,16 @@ Output:
82 "name": "div",
83 "loc": null,
84 "range": [
85 - 91,
86 - 94
85 + 103,
86 + 106
87 ]
88 },
89 "attributes": [],
90 "selfClosing": false,
91 "loc": null,
92 "range": [
93 - 90,
94 - 95
93 + 102,
94 + 107
95 ]
96 },
97 "children": [
@@ -105,8 +105,8 @@ Output:
105 "typeAnnotation": null,
106 "loc": null,
107 "range": [
108 - 96,
109 - 101
108 + 108,
109 + 113
110 ]
111 },
112 "property": {
@@ -115,21 +115,21 @@ Output:
115 "typeAnnotation": null,
116 "loc": null,
117 "range": [
118 - 102,
119 - 105
118 + 114,
119 + 117
120 ]
121 },
122 "computed": false,
123 "loc": null,
124 "range": [
125 - 96,
126 - 105
125 + 108,
126 + 117
127 ]
128 },
129 "loc": null,
130 "range": [
131 - 95,
132 - 106
131 + 107,
132 + 118
133 ]
134 }
135 ],
@@ -140,52 +140,52 @@ Output:
140 "name": "div",
141 "loc": null,
142 "range": [
143 - 108,
144 - 111
143 + 120,
144 + 123
145 ]
146 },
147 "loc": null,
148 "range": [
149 - 106,
150 - 112
149 + 118,
150 + 124
151 ]
152 },
153 "loc": null,
154 "range": [
155 - 90,
156 - 112
155 + 102,
156 + 124
157 ]
158 },
159 "loc": null,
160 "range": [
161 - 83,
162 - 113
161 + 95,
162 + 125
163 ]
164 }
165 ],
166 "loc": null,
167 "range": [
168 - 63,
169 - 115
168 + 75,
169 + 127
170 ]
171 },
172 "generator": false,
173 "async": false,
174 "loc": null,
175 "range": [
176 - 43,
177 - 115
176 + 55,
177 + 127
178 ],
179 "loc": null,
180 "range": [
181 - 43,
182 - 115
181 + 55,
182 + 127
183 ]
184 },
185 "loc": null,
186 "range": [
187 - 28,
188 - 115
187 + 40,
188 + 127
189 ]
190 },
191 {
@@ -196,8 +196,8 @@ Output:
196 "typeAnnotation": null,
197 "loc": null,
198 "range": [
199 - 126,
200 - 134
199 + 138,
200 + 146
201 ]
202 },
203 "params": [
@@ -207,8 +207,8 @@ Output:
207 "typeAnnotation": null,
208 "loc": null,
209 "range": [
210 - 135,
211 - 140
210 + 147,
211 + 152
212 ]
213 }
214 ],
@@ -226,16 +226,16 @@ Output:
226 "name": "Bar",
227 "loc": null,
228 "range": [
229 - 154,
230 - 157
229 + 166,
230 + 169
231 ]
232 },
233 "attributes": [],
234 "selfClosing": false,
235 "loc": null,
236 "range": [
237 - 153,
238 - 158
237 + 165,
238 + 170
239 ]
240 },
241 "children": [
@@ -249,8 +249,8 @@ Output:
249 "typeAnnotation": null,
250 "loc": null,
251 "range": [
252 - 159,
253 - 164
252 + 171,
253 + 176
254 ]
255 },
256 "property": {
@@ -259,21 +259,21 @@ Output:
259 "typeAnnotation": null,
260 "loc": null,
261 "range": [
262 - 165,
263 - 173
262 + 177,
263 + 185
264 ]
265 },
266 "computed": false,
267 "loc": null,
268 "range": [
269 - 159,
270 - 173
269 + 171,
270 + 185
271 ]
272 },
273 "loc": null,
274 "range": [
275 - 158,
276 - 174
275 + 170,
276 + 186
277 ]
278 }
279 ],
@@ -284,46 +284,46 @@ Output:
284 "name": "Bar",
285 "loc": null,
286 "range": [
287 - 176,
288 - 179
287 + 188,
288 + 191
289 ]
290 },
291 "loc": null,
292 "range": [
293 - 174,
294 - 180
293 + 186,
294 + 192
295 ]
296 },
297 "loc": null,
298 "range": [
299 - 153,
300 - 180
299 + 165,
300 + 192
301 ]
302 },
303 "loc": null,
304 "range": [
305 - 146,
306 - 181
305 + 158,
306 + 193
307 ]
308 }
309 ],
310 "loc": null,
311 "range": [
312 - 142,
313 - 183
312 + 154,
313 + 195
314 ]
315 },
316 "generator": false,
317 "async": false,
318 "loc": null,
319 "range": [
320 - 117,
321 - 183
320 + 129,
321 + 195
322 ],
323 "loc": null,
324 "range": [
325 - 117,
326 - 183
325 + 129,
326 + 195
327 ]
328 },
329 {
@@ -336,8 +336,8 @@ Output:
336 "typeAnnotation": null,
337 "loc": null,
338 "range": [
339 - 201,
340 - 204
339 + 213,
340 + 216
341 ]
342 },
343 "params": [
@@ -347,8 +347,8 @@ Output:
347 "typeAnnotation": null,
348 "loc": null,
349 "range": [
350 - 205,
351 - 210
350 + 217,
351 + 222
352 ]
353 }
354 ],
@@ -362,15 +362,15 @@ Output:
362 "value": "use forget",
363 "loc": null,
364 "range": [
365 - 216,
366 - 228
365 + 228,
366 + 240
367 ]
368 },
369 "directive": null,
370 "loc": null,
371 "range": [
372 - 216,
373 - 229
372 + 228,
373 + 241
374 ]
375 },
376 {
@@ -384,16 +384,16 @@ Output:
384 "name": "Foo",
385 "loc": null,
386 "range": [
387 - 240,
388 - 243
387 + 252,
388 + 255
389 ]
390 },
391 "attributes": [],
392 "selfClosing": false,
393 "loc": null,
394 "range": [
395 - 239,
396 - 244
395 + 251,
396 + 256
397 ]
398 },
399 "children": [
@@ -407,8 +407,8 @@ Output:
407 "typeAnnotation": null,
408 "loc": null,
409 "range": [
410 - 245,
411 - 250
410 + 257,
411 + 262
412 ]
413 },
414 "property": {
@@ -417,21 +417,21 @@ Output:
417 "typeAnnotation": null,
418 "loc": null,
419 "range": [
420 - 251,
421 - 254
420 + 263,
421 + 266
422 ]
423 },
424 "computed": false,
425 "loc": null,
426 "range": [
427 - 245,
428 - 254
427 + 257,
428 + 266
429 ]
430 },
431 "loc": null,
432 "range": [
433 - 244,
434 - 255
433 + 256,
434 + 267
435 ]
436 }
437 ],
@@ -442,61 +442,61 @@ Output:
442 "name": "Foo",
443 "loc": null,
444 "range": [
445 - 257,
446 - 260
445 + 269,
446 + 272
447 ]
448 },
449 "loc": null,
450 "range": [
451 - 255,
452 - 261
451 + 267,
452 + 273
453 ]
454 },
455 "loc": null,
456 "range": [
457 - 239,
458 - 261
457 + 251,
458 + 273
459 ]
460 },
461 "loc": null,
462 "range": [
463 - 232,
464 - 262
463 + 244,
464 + 274
465 ]
466 }
467 ],
468 "loc": null,
469 "range": [
470 - 212,
471 - 264
470 + 224,
471 + 276
472 ]
473 },
474 "generator": false,
475 "async": false,
476 "loc": null,
477 "range": [
478 - 192,
479 - 264
478 + 204,
479 + 276
480 ],
481 "loc": null,
482 "range": [
483 - 192,
484 - 264
483 + 204,
484 + 276
485 ]
486 },
487 "specifiers": [],
488 "source": null,
489 "loc": null,
490 "range": [
491 - 185,
492 - 264
491 + 197,
492 + 276
493 ]
494 }
495 ],
496 "sourceType": "script",
497 "loc": null,
498 "range": [
499 - 28,
500 - 264
499 + 40,
500 + 276
501 ]
502 }
compiler/crates/forget_hermes_parser/tests/snapshots/parser_test__fixtures@gating-test-export-function.js.snap
+107 -107
@@ -4,7 +4,7 @@ expression: "format!(\"Input:\\n{input}\\n\\nOutput:\\n{output}\")"
4 input_file: crates/forget_hermes_parser/tests/fixtures/gating-test-export-function.js
5 ---
6 Input:
7 -// @gating @forgetDirective
7 +// @gating @compilationMode(annotation)
8 export function Bar(props) {
9 "use forget";
10 return <div>{props.bar}</div>;
@@ -34,8 +34,8 @@ Output:
34 "typeAnnotation": null,
35 "loc": null,
36 "range": [
37 - 44,
38 - 47
37 + 56,
38 + 59
39 ]
40 },
41 "params": [
@@ -45,8 +45,8 @@ Output:
45 "typeAnnotation": null,
46 "loc": null,
47 "range": [
48 - 48,
49 - 53
48 + 60,
49 + 65
50 ]
51 }
52 ],
@@ -60,15 +60,15 @@ Output:
60 "value": "use forget",
61 "loc": null,
62 "range": [
63 - 59,
64 - 71
63 + 71,
64 + 83
65 ]
66 },
67 "directive": null,
68 "loc": null,
69 "range": [
70 - 59,
71 - 72
70 + 71,
71 + 84
72 ]
73 },
74 {
@@ -82,16 +82,16 @@ Output:
82 "name": "div",
83 "loc": null,
84 "range": [
85 - 83,
86 - 86
85 + 95,
86 + 98
87 ]
88 },
89 "attributes": [],
90 "selfClosing": false,
91 "loc": null,
92 "range": [
93 - 82,
94 - 87
93 + 94,
94 + 99
95 ]
96 },
97 "children": [
@@ -105,8 +105,8 @@ Output:
105 "typeAnnotation": null,
106 "loc": null,
107 "range": [
108 - 88,
109 - 93
108 + 100,
109 + 105
110 ]
111 },
112 "property": {
@@ -115,21 +115,21 @@ Output:
115 "typeAnnotation": null,
116 "loc": null,
117 "range": [
118 - 94,
119 - 97
118 + 106,
119 + 109
120 ]
121 },
122 "computed": false,
123 "loc": null,
124 "range": [
125 - 88,
126 - 97
125 + 100,
126 + 109
127 ]
128 },
129 "loc": null,
130 "range": [
131 - 87,
132 - 98
131 + 99,
132 + 110
133 ]
134 }
135 ],
@@ -140,54 +140,54 @@ Output:
140 "name": "div",
141 "loc": null,
142 "range": [
143 - 100,
144 - 103
143 + 112,
144 + 115
145 ]
146 },
147 "loc": null,
148 "range": [
149 - 98,
150 - 104
149 + 110,
150 + 116
151 ]
152 },
153 "loc": null,
154 "range": [
155 - 82,
156 - 104
155 + 94,
156 + 116
157 ]
158 },
159 "loc": null,
160 "range": [
161 - 75,
162 - 105
161 + 87,
162 + 117
163 ]
164 }
165 ],
166 "loc": null,
167 "range": [
168 - 55,
169 - 107
168 + 67,
169 + 119
170 ]
171 },
172 "generator": false,
173 "async": false,
174 "loc": null,
175 "range": [
176 - 35,
177 - 107
176 + 47,
177 + 119
178 ],
179 "loc": null,
180 "range": [
181 - 35,
182 - 107
181 + 47,
182 + 119
183 ]
184 },
185 "specifiers": [],
186 "source": null,
187 "loc": null,
188 "range": [
189 - 28,
190 - 107
189 + 40,
190 + 119
191 ]
192 },
193 {
@@ -200,8 +200,8 @@ Output:
200 "typeAnnotation": null,
201 "loc": null,
202 "range": [
203 - 125,
204 - 133
203 + 137,
204 + 145
205 ]
206 },
207 "params": [
@@ -211,8 +211,8 @@ Output:
211 "typeAnnotation": null,
212 "loc": null,
213 "range": [
214 - 134,
215 - 139
214 + 146,
215 + 151
216 ]
217 }
218 ],
@@ -230,16 +230,16 @@ Output:
230 "name": "Bar",
231 "loc": null,
232 "range": [
233 - 153,
234 - 156
233 + 165,
234 + 168
235 ]
236 },
237 "attributes": [],
238 "selfClosing": false,
239 "loc": null,
240 "range": [
241 - 152,
242 - 157
241 + 164,
242 + 169
243 ]
244 },
245 "children": [
@@ -253,8 +253,8 @@ Output:
253 "typeAnnotation": null,
254 "loc": null,
255 "range": [
256 - 158,
257 - 163
256 + 170,
257 + 175
258 ]
259 },
260 "property": {
@@ -263,21 +263,21 @@ Output:
263 "typeAnnotation": null,
264 "loc": null,
265 "range": [
266 - 164,
267 - 172
266 + 176,
267 + 184
268 ]
269 },
270 "computed": false,
271 "loc": null,
272 "range": [
273 - 158,
274 - 172
273 + 170,
274 + 184
275 ]
276 },
277 "loc": null,
278 "range": [
279 - 157,
280 - 173
279 + 169,
280 + 185
281 ]
282 }
283 ],
@@ -288,54 +288,54 @@ Output:
288 "name": "Bar",
289 "loc": null,
290 "range": [
291 - 175,
292 - 178
291 + 187,
292 + 190
293 ]
294 },
295 "loc": null,
296 "range": [
297 - 173,
298 - 179
297 + 185,
298 + 191
299 ]
300 },
301 "loc": null,
302 "range": [
303 - 152,
304 - 179
303 + 164,
304 + 191
305 ]
306 },
307 "loc": null,
308 "range": [
309 - 145,
310 - 180
309 + 157,
310 + 192
311 ]
312 }
313 ],
314 "loc": null,
315 "range": [
316 - 141,
317 - 182
316 + 153,
317 + 194
318 ]
319 },
320 "generator": false,
321 "async": false,
322 "loc": null,
323 "range": [
324 - 116,
325 - 182
324 + 128,
325 + 194
326 ],
327 "loc": null,
328 "range": [
329 - 116,
330 - 182
329 + 128,
330 + 194
331 ]
332 },
333 "specifiers": [],
334 "source": null,
335 "loc": null,
336 "range": [
337 - 109,
338 - 182
337 + 121,
338 + 194
339 ]
340 },
341 {
@@ -348,8 +348,8 @@ Output:
348 "typeAnnotation": null,
349 "loc": null,
350 "range": [
351 - 200,
352 - 203
351 + 212,
352 + 215
353 ]
354 },
355 "params": [
@@ -359,8 +359,8 @@ Output:
359 "typeAnnotation": null,
360 "loc": null,
361 "range": [
362 - 204,
363 - 209
362 + 216,
363 + 221
364 ]
365 }
366 ],
@@ -374,15 +374,15 @@ Output:
374 "value": "use forget",
375 "loc": null,
376 "range": [
377 - 215,
378 - 227
377 + 227,
378 + 239
379 ]
380 },
381 "directive": null,
382 "loc": null,
383 "range": [
384 - 215,
385 - 228
384 + 227,
385 + 240
386 ]
387 },
388 {
@@ -396,16 +396,16 @@ Output:
396 "name": "Foo",
397 "loc": null,
398 "range": [
399 - 239,
400 - 242
399 + 251,
400 + 254
401 ]
402 },
403 "attributes": [],
404 "selfClosing": false,
405 "loc": null,
406 "range": [
407 - 238,
408 - 243
407 + 250,
408 + 255
409 ]
410 },
411 "children": [
@@ -419,8 +419,8 @@ Output:
419 "typeAnnotation": null,
420 "loc": null,
421 "range": [
422 - 244,
423 - 249
422 + 256,
423 + 261
424 ]
425 },
426 "property": {
@@ -429,21 +429,21 @@ Output:
429 "typeAnnotation": null,
430 "loc": null,
431 "range": [
432 - 250,
433 - 253
432 + 262,
433 + 265
434 ]
435 },
436 "computed": false,
437 "loc": null,
438 "range": [
439 - 244,
440 - 253
439 + 256,
440 + 265
441 ]
442 },
443 "loc": null,
444 "range": [
445 - 243,
446 - 254
445 + 255,
446 + 266
447 ]
448 }
449 ],
@@ -454,61 +454,61 @@ Output:
454 "name": "Foo",
455 "loc": null,
456 "range": [
457 - 256,
458 - 259
457 + 268,
458 + 271
459 ]
460 },
461 "loc": null,
462 "range": [
463 - 254,
464 - 260
463 + 266,
464 + 272
465 ]
466 },
467 "loc": null,
468 "range": [
469 - 238,
470 - 260
469 + 250,
470 + 272
471 ]
472 },
473 "loc": null,
474 "range": [
475 - 231,
476 - 261
475 + 243,
476 + 273
477 ]
478 }
479 ],
480 "loc": null,
481 "range": [
482 - 211,
483 - 263
482 + 223,
483 + 275
484 ]
485 },
486 "generator": false,
487 "async": false,
488 "loc": null,
489 "range": [
490 - 191,
491 - 263
490 + 203,
491 + 275
492 ],
493 "loc": null,
494 "range": [
495 - 191,
496 - 263
495 + 203,
496 + 275
497 ]
498 },
499 "specifiers": [],
500 "source": null,
501 "loc": null,
502 "range": [
503 - 184,
504 - 263
503 + 196,
504 + 275
505 ]
506 }
507 ],
508 "sourceType": "script",
509 "loc": null,
510 "range": [
511 - 28,
512 - 263
511 + 40,
512 + 275
513 ]
514 }
compiler/crates/forget_hermes_parser/tests/snapshots/parser_test__fixtures@gating-test.js.snap
+101 -101
@@ -4,7 +4,7 @@ expression: "format!(\"Input:\\n{input}\\n\\nOutput:\\n{output}\")"
4 input_file: crates/forget_hermes_parser/tests/fixtures/gating-test.js
5 ---
6 Input:
7 -// @gating @forgetDirective
7 +// @gating @compilationMode(annotation)
8 function Bar(props) {
9 "use forget";
10 return <div>{props.bar}</div>;
@@ -32,8 +32,8 @@ Output:
32 "typeAnnotation": null,
33 "loc": null,
34 "range": [
35 - 37,
36 - 40
35 + 49,
36 + 52
37 ]
38 },
39 "params": [
@@ -43,8 +43,8 @@ Output:
43 "typeAnnotation": null,
44 "loc": null,
45 "range": [
46 - 41,
47 - 46
46 + 53,
47 + 58
48 ]
49 }
50 ],
@@ -58,15 +58,15 @@ Output:
58 "value": "use forget",
59 "loc": null,
60 "range": [
61 - 52,
62 - 64
61 + 64,
62 + 76
63 ]
64 },
65 "directive": null,
66 "loc": null,
67 "range": [
68 - 52,
69 - 65
68 + 64,
69 + 77
70 ]
71 },
72 {
@@ -80,16 +80,16 @@ Output:
80 "name": "div",
81 "loc": null,
82 "range": [
83 - 76,
84 - 79
83 + 88,
84 + 91
85 ]
86 },
87 "attributes": [],
88 "selfClosing": false,
89 "loc": null,
90 "range": [
91 - 75,
92 - 80
91 + 87,
92 + 92
93 ]
94 },
95 "children": [
@@ -103,8 +103,8 @@ Output:
103 "typeAnnotation": null,
104 "loc": null,
105 "range": [
106 - 81,
107 - 86
106 + 93,
107 + 98
108 ]
109 },
110 "property": {
@@ -113,21 +113,21 @@ Output:
113 "typeAnnotation": null,
114 "loc": null,
115 "range": [
116 - 87,
117 - 90
116 + 99,
117 + 102
118 ]
119 },
120 "computed": false,
121 "loc": null,
122 "range": [
123 - 81,
124 - 90
123 + 93,
124 + 102
125 ]
126 },
127 "loc": null,
128 "range": [
129 - 80,
130 - 91
129 + 92,
130 + 103
131 ]
132 }
133 ],
@@ -138,46 +138,46 @@ Output:
138 "name": "div",
139 "loc": null,
140 "range": [
141 - 93,
142 - 96
141 + 105,
142 + 108
143 ]
144 },
145 "loc": null,
146 "range": [
147 - 91,
148 - 97
147 + 103,
148 + 109
149 ]
150 },
151 "loc": null,
152 "range": [
153 - 75,
154 - 97
153 + 87,
154 + 109
155 ]
156 },
157 "loc": null,
158 "range": [
159 - 68,
160 - 98
159 + 80,
160 + 110
161 ]
162 }
163 ],
164 "loc": null,
165 "range": [
166 - 48,
167 - 100
166 + 60,
167 + 112
168 ]
169 },
170 "generator": false,
171 "async": false,
172 "loc": null,
173 "range": [
174 - 28,
175 - 100
174 + 40,
175 + 112
176 ],
177 "loc": null,
178 "range": [
179 - 28,
180 - 100
179 + 40,
180 + 112
181 ]
182 },
183 {
@@ -188,8 +188,8 @@ Output:
188 "typeAnnotation": null,
189 "loc": null,
190 "range": [
191 - 111,
192 - 119
191 + 123,
192 + 131
193 ]
194 },
195 "params": [
@@ -199,8 +199,8 @@ Output:
199 "typeAnnotation": null,
200 "loc": null,
201 "range": [
202 - 120,
203 - 125
202 + 132,
203 + 137
204 ]
205 }
206 ],
@@ -218,16 +218,16 @@ Output:
218 "name": "Bar",
219 "loc": null,
220 "range": [
221 - 139,
222 - 142
221 + 151,
222 + 154
223 ]
224 },
225 "attributes": [],
226 "selfClosing": false,
227 "loc": null,
228 "range": [
229 - 138,
230 - 143
229 + 150,
230 + 155
231 ]
232 },
233 "children": [
@@ -241,8 +241,8 @@ Output:
241 "typeAnnotation": null,
242 "loc": null,
243 "range": [
244 - 144,
245 - 149
244 + 156,
245 + 161
246 ]
247 },
248 "property": {
@@ -251,21 +251,21 @@ Output:
251 "typeAnnotation": null,
252 "loc": null,
253 "range": [
254 - 150,
255 - 158
254 + 162,
255 + 170
256 ]
257 },
258 "computed": false,
259 "loc": null,
260 "range": [
261 - 144,
262 - 158
261 + 156,
262 + 170
263 ]
264 },
265 "loc": null,
266 "range": [
267 - 143,
268 - 159
267 + 155,
268 + 171
269 ]
270 }
271 ],
@@ -276,46 +276,46 @@ Output:
276 "name": "Bar",
277 "loc": null,
278 "range": [
279 - 161,
280 - 164
279 + 173,
280 + 176
281 ]
282 },
283 "loc": null,
284 "range": [
285 - 159,
286 - 165
285 + 171,
286 + 177
287 ]
288 },
289 "loc": null,
290 "range": [
291 - 138,
292 - 165
291 + 150,
292 + 177
293 ]
294 },
295 "loc": null,
296 "range": [
297 - 131,
298 - 166
297 + 143,
298 + 178
299 ]
300 }
301 ],
302 "loc": null,
303 "range": [
304 - 127,
305 - 168
304 + 139,
305 + 180
306 ]
307 },
308 "generator": false,
309 "async": false,
310 "loc": null,
311 "range": [
312 - 102,
313 - 168
312 + 114,
313 + 180
314 ],
315 "loc": null,
316 "range": [
317 - 102,
318 - 168
317 + 114,
318 + 180
319 ]
320 },
321 {
@@ -326,8 +326,8 @@ Output:
326 "typeAnnotation": null,
327 "loc": null,
328 "range": [
329 - 179,
330 - 182
329 + 191,
330 + 194
331 ]
332 },
333 "params": [
@@ -337,8 +337,8 @@ Output:
337 "typeAnnotation": null,
338 "loc": null,
339 "range": [
340 - 183,
341 - 188
340 + 195,
341 + 200
342 ]
343 }
344 ],
@@ -352,15 +352,15 @@ Output:
352 "value": "use forget",
353 "loc": null,
354 "range": [
355 - 194,
356 - 206
355 + 206,
356 + 218
357 ]
358 },
359 "directive": null,
360 "loc": null,
361 "range": [
362 - 194,
363 - 207
362 + 206,
363 + 219
364 ]
365 },
366 {
@@ -374,16 +374,16 @@ Output:
374 "name": "Foo",
375 "loc": null,
376 "range": [
377 - 218,
378 - 221
377 + 230,
378 + 233
379 ]
380 },
381 "attributes": [],
382 "selfClosing": false,
383 "loc": null,
384 "range": [
385 - 217,
386 - 222
385 + 229,
386 + 234
387 ]
388 },
389 "children": [
@@ -397,8 +397,8 @@ Output:
397 "typeAnnotation": null,
398 "loc": null,
399 "range": [
400 - 223,
401 - 228
400 + 235,
401 + 240
402 ]
403 },
404 "property": {
@@ -407,21 +407,21 @@ Output:
407 "typeAnnotation": null,
408 "loc": null,
409 "range": [
410 - 229,
411 - 232
410 + 241,
411 + 244
412 ]
413 },
414 "computed": false,
415 "loc": null,
416 "range": [
417 - 223,
418 - 232
417 + 235,
418 + 244
419 ]
420 },
421 "loc": null,
422 "range": [
423 - 222,
424 - 233
423 + 234,
424 + 245
425 ]
426 }
427 ],
@@ -432,53 +432,53 @@ Output:
432 "name": "Foo",
433 "loc": null,
434 "range": [
435 - 235,
436 - 238
435 + 247,
436 + 250
437 ]
438 },
439 "loc": null,
440 "range": [
441 - 233,
442 - 239
441 + 245,
442 + 251
443 ]
444 },
445 "loc": null,
446 "range": [
447 - 217,
448 - 239
447 + 229,
448 + 251
449 ]
450 },
451 "loc": null,
452 "range": [
453 - 210,
454 - 240
453 + 222,
454 + 252
455 ]
456 }
457 ],
458 "loc": null,
459 "range": [
460 - 190,
461 - 242
460 + 202,
461 + 254
462 ]
463 },
464 "generator": false,
465 "async": false,
466 "loc": null,
467 "range": [
468 - 170,
469 - 242
468 + 182,
469 + 254
470 ],
471 "loc": null,
472 "range": [
473 - 170,
474 - 242
473 + 182,
474 + 254
475 ]
476 }
477 ],
478 "sourceType": "script",
479 "loc": null,
480 "range": [
481 - 28,
482 - 242
481 + 40,
482 + 254
483 ]
484 }
compiler/packages/babel-plugin-react-forget/src/Entrypoint/Options.ts
+26 -17
@@ -24,11 +24,6 @@ export type InstrumentForgetOptions = {
24 };
25
26 export type PluginOptions = {
27 - /**
28 - * Enable to make Forget only compile functions containing the 'use forget' directive.
29 - */
30 - enableOnlyOnUseForgetDirective: boolean;
31 -
27 environment: EnvironmentConfig | null;
28
29 logger: Logger | null;
@@ -89,27 +84,41 @@ export type PluginOptions = {
84 noEmit: boolean;
85
86 /**
92 - * Enable to make Forget only compile components written in ReactScript syntax
93 - * and parsed by hermes-parser.
87 + * Determines the strategy for determining which functions to compile. Note that regardless of
88 + * which mode is enabled, a component can be opted out by adding the string literal
89 + * `"use no forget"` at the top of the function body, eg.:
90 *
91 + * ```
92 + * function ComponentYouWantToSkipCompilation(props) {
93 + * "use no forget";
94 + * ...
95 + * }
96 + * ```
97 */
96 - enableOnlyOnReactScript: boolean;
97 -
98 - /**
99 - * Enable to make Forget infer which components to compile, based on the same rules
100 - * that React's ESLint rules use to detect components.
101 - */
102 - enableInferReactFunctions: boolean;
98 + compilationMode: CompilationMode;
99 };
100
101 +export type CompilationMode =
102 + // Compiles functions annotated with "use forget" or component/hook-like functions.
103 + // This latter includes:
104 + // * Components declared with component syntax.
105 + // * Functions which can be inferred to be a component or hook:
106 + // - Be named like a hook or component. This logic matches the ESLint rule.
107 + // - *and* create JSX and/or call a hook. This is an additional check to help prevent
108 + // false positives, since compilation has a greater impact than linting.
109 + // This is the default mode
110 + | "infer"
111 + // Compile only functions which are explicitly annotated with "use forget"
112 + | "annotation"
113 + // Compile all top-level functions
114 + | "all";
115 +
116 export type Logger = {
117 logEvent(name: string, data: any): void;
118 };
119
120 export const defaultOptions: PluginOptions = {
110 - enableOnlyOnReactScript: false,
111 - enableOnlyOnUseForgetDirective: false,
112 - enableInferReactFunctions: false,
121 + compilationMode: "infer",
122 panicOnBailout: true,
123 environment: null,
124 logger: null,
compiler/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts
+28 -18
@@ -15,6 +15,7 @@ import {
15 } from "../CompilerError";
16 import { GeneratedSource } from "../HIR";
17 import { isComponentDeclaration } from "../Utils/ComponentDeclaration";
18 +import { assertExhaustive } from "../Utils/utils";
19 import { insertGatedFunctionDeclaration } from "./Gating";
20 import {
21 addImportsToProgram,
@@ -315,29 +316,38 @@ function shouldVisitNode(
316 pass: CompilerPass
317 ): boolean {
318 if (fn.node.body.type === "BlockStatement") {
318 - const shouldSkip = hasAnyUseNoForgetDirectives(fn.node.body.directives);
319 - if (shouldSkip) {
319 + // Opt-outs disable compilation regardless of mode
320 + if (hasAnyUseNoForgetDirectives(fn.node.body.directives)) {
321 return false;
322 }
322 - }
323 -
324 - if (pass.opts.enableOnlyOnReactScript && fn.isFunctionDeclaration()) {
325 - return isComponentDeclaration(fn.node);
326 - }
327 -
328 - if (pass.opts.enableOnlyOnUseForgetDirective) {
329 - const body = fn.get("body");
330 - if (body.isBlockStatement()) {
331 - return hasAnyUseForgetDirectives(body.node.directives);
323 + // Otherwise opt-ins enable compilation regardless of mode
324 + if (hasAnyUseForgetDirectives(fn.node.body.directives)) {
325 + return true;
326 }
327 }
334 -
335 - if (pass.opts.enableInferReactFunctions) {
336 - const isReactLike = isReactFunctionLike(fn);
337 - return isReactLike;
328 + switch (pass.opts.compilationMode) {
329 + case "annotation": {
330 + // opt-ins are checked above
331 + return false;
332 + }
333 + case "infer": {
334 + return (
335 + // Component declarations are known components
336 + (fn.isFunctionDeclaration() && isComponentDeclaration(fn.node)) ||
337 + // Otherwise check if this is a component or hook-like function
338 + isReactFunctionLike(fn)
339 + );
340 + }
341 + case "all": {
342 + return fn.scope.getProgramParent() === fn.scope.parent;
343 + }
344 + default: {
345 + assertExhaustive(
346 + pass.opts.compilationMode,
347 + `Unexpected compilationMode '${pass.opts.compilationMode}'`
348 + );
349 + }
350 }
339 -
340 - return fn.scope.getProgramParent() === fn.scope.parent;
351 }
352
353 function log(error: CompilerError, filename: string | null): void {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/codegen-instrument-forget-gating-test.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @instrumentForget @forgetDirective @gating
5 +// @instrumentForget @compilationMode(annotation) @gating
6
7 function Bar(props) {
8 "use forget";
@@ -25,7 +25,7 @@ function Foo(props) {
25 ```javascript
26 import { isForgetEnabled_Fixtures } from "ReactForgetFeatureFlag";
27 import { useRenderCounter } from "react-forget-runtime";
28 -import { unstable_useMemoCache as useMemoCache } from "react"; // @instrumentForget @forgetDirective @gating
28 +import { unstable_useMemoCache as useMemoCache } from "react"; // @instrumentForget @compilationMode(annotation) @gating
29
30 function Bar_uncompiled(props) {
31 "use forget";
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/codegen-instrument-forget-gating-test.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @instrumentForget @forgetDirective @gating
1 +// @instrumentForget @compilationMode(annotation) @gating
2
3 function Bar(props) {
4 "use forget";
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/codegen-instrument-forget-test.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @instrumentForget @forgetDirective
5 +// @instrumentForget @compilationMode(annotation)
6
7 function Bar(props) {
8 "use forget";
@@ -24,7 +24,7 @@ function Foo(props) {
24
25 ```javascript
26 import { useRenderCounter } from "react-forget-runtime";
27 -import { unstable_useMemoCache as useMemoCache } from "react"; // @instrumentForget @forgetDirective
27 +import { unstable_useMemoCache as useMemoCache } from "react"; // @instrumentForget @compilationMode(annotation)
28
29 function Bar(props) {
30 if (__DEV__) useRenderCounter("Bar");
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/codegen-instrument-forget-test.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @instrumentForget @forgetDirective
1 +// @instrumentForget @compilationMode(annotation)
2
3 function Bar(props) {
4 "use forget";
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/component-declaration-basic.flow.expect.md renamed
+1 -1
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @reactScriptDirective
5 +// @flow @compilationMode(infer)
6 export default component Foo(bar: number) {
7 return <Bar bar={bar} />;
8 }
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/component-declaration-basic.flow.js renamed
+1 -1
@@ -1,4 +1,4 @@
1 -// @reactScriptDirective
1 +// @flow @compilationMode(infer)
2 export default component Foo(bar: number) {
3 return <Bar bar={bar} />;
4 }
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo.infer-function-assignment.expect.md
+1 -1
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @enableInferReactFunctions
5 +// @compilationMode(infer)
6 const Component = (props) => {
7 return <div />;
8 };
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo.infer-function-assignment.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @enableInferReactFunctions
1 +// @compilationMode(infer)
2 const Component = (props) => {
3 return <div />;
4 };
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/gating-test-export-default-function.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @gating @forgetDirective
5 +// @gating @compilationMode(annotation)
6 export default function Bar(props) {
7 "use forget";
8 return <div>{props.bar}</div>;
@@ -23,7 +23,7 @@ function Foo(props) {
23
24 ```javascript
25 import { isForgetEnabled_Fixtures } from "ReactForgetFeatureFlag";
26 -import { unstable_useMemoCache as useMemoCache } from "react"; // @gating @forgetDirective
26 +import { unstable_useMemoCache as useMemoCache } from "react"; // @gating @compilationMode(annotation)
27 function Bar_uncompiled(props) {
28 "use forget";
29 return <div>{props.bar}</div>;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/gating-test-export-default-function.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @gating @forgetDirective
1 +// @gating @compilationMode(annotation)
2 export default function Bar(props) {
3 "use forget";
4 return <div>{props.bar}</div>;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/gating-test-export-function-and-default.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @gating @forgetDirective
5 +// @gating @compilationMode(annotation)
6 export default function Bar(props) {
7 "use forget";
8 return <div>{props.bar}</div>;
@@ -23,7 +23,7 @@ export function Foo(props) {
23
24 ```javascript
25 import { isForgetEnabled_Fixtures } from "ReactForgetFeatureFlag";
26 -import { unstable_useMemoCache as useMemoCache } from "react"; // @gating @forgetDirective
26 +import { unstable_useMemoCache as useMemoCache } from "react"; // @gating @compilationMode(annotation)
27 function Bar_uncompiled(props) {
28 "use forget";
29 return <div>{props.bar}</div>;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/gating-test-export-function-and-default.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @gating @forgetDirective
1 +// @gating @compilationMode(annotation)
2 export default function Bar(props) {
3 "use forget";
4 return <div>{props.bar}</div>;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/gating-test-export-function.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @gating @forgetDirective
5 +// @gating @compilationMode(annotation)
6 export function Bar(props) {
7 "use forget";
8 return <div>{props.bar}</div>;
@@ -23,7 +23,7 @@ export function Foo(props) {
23
24 ```javascript
25 import { isForgetEnabled_Fixtures } from "ReactForgetFeatureFlag";
26 -import { unstable_useMemoCache as useMemoCache } from "react"; // @gating @forgetDirective
26 +import { unstable_useMemoCache as useMemoCache } from "react"; // @gating @compilationMode(annotation)
27 function Bar_uncompiled(props) {
28 "use forget";
29 return <div>{props.bar}</div>;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/gating-test-export-function.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @gating @forgetDirective
1 +// @gating @compilationMode(annotation)
2 export function Bar(props) {
3 "use forget";
4 return <div>{props.bar}</div>;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/gating-test.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @gating @forgetDirective
5 +// @gating @compilationMode(annotation)
6 function Bar(props) {
7 "use forget";
8 return <div>{props.bar}</div>;
@@ -23,7 +23,7 @@ function Foo(props) {
23
24 ```javascript
25 import { isForgetEnabled_Fixtures } from "ReactForgetFeatureFlag";
26 -import { unstable_useMemoCache as useMemoCache } from "react"; // @gating @forgetDirective
26 +import { unstable_useMemoCache as useMemoCache } from "react"; // @gating @compilationMode(annotation)
27 function Bar_uncompiled(props) {
28 "use forget";
29 return <div>{props.bar}</div>;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/gating-test.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @gating @forgetDirective
1 +// @gating @compilationMode(annotation)
2 function Bar(props) {
3 "use forget";
4 return <div>{props.bar}</div>;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/infer-function-React-memo.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @enableInferReactFunctions
5 +// @compilationMode(infer)
6 React.memo((props) => {
7 return <div />;
8 });
@@ -12,7 +12,7 @@ React.memo((props) => {
12 ## Code
13
14 ```javascript
15 -// @enableInferReactFunctions
15 +// @compilationMode(infer)
16 React.memo((props) => {
17 return <div />;
18 });
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/infer-function-React-memo.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @enableInferReactFunctions
1 +// @compilationMode(infer)
2 React.memo((props) => {
3 return <div />;
4 });
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/infer-function-forwardRef.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @enableInferReactFunctions
5 +// @compilationMode(infer)
6 React.forwardRef((props) => {
7 return <div />;
8 });
@@ -12,7 +12,7 @@ React.forwardRef((props) => {
12 ## Code
13
14 ```javascript
15 -// @enableInferReactFunctions
15 +// @compilationMode(infer)
16 React.forwardRef((props) => {
17 return <div />;
18 });
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/infer-function-forwardRef.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @enableInferReactFunctions
1 +// @compilationMode(infer)
2 React.forwardRef((props) => {
3 return <div />;
4 });
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/infer-functions-component-with-hook-call.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @enableInferReactFunctions
5 +// @compilationMode(infer)
6 function Component(props) {
7 const [state, _] = useState(null);
8 return [state];
@@ -13,7 +13,7 @@ function Component(props) {
13 ## Code
14
15 ```javascript
16 -import { unstable_useMemoCache as useMemoCache } from "react"; // @enableInferReactFunctions
16 +import { unstable_useMemoCache as useMemoCache } from "react"; // @compilationMode(infer)
17 function Component(props) {
18 const $ = useMemoCache(2);
19 const [state] = useState(null);
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/infer-functions-component-with-hook-call.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @enableInferReactFunctions
1 +// @compilationMode(infer)
2 function Component(props) {
3 const [state, _] = useState(null);
4 return [state];
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/infer-functions-component-with-jsx.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @enableInferReactFunctions
5 +// @compilationMode(infer)
6 function Component(props) {
7 return <div />;
8 }
@@ -12,7 +12,7 @@ function Component(props) {
12 ## Code
13
14 ```javascript
15 -import { unstable_useMemoCache as useMemoCache } from "react"; // @enableInferReactFunctions
15 +import { unstable_useMemoCache as useMemoCache } from "react"; // @compilationMode(infer)
16 function Component(props) {
17 const $ = useMemoCache(1);
18 let t0;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/infer-functions-component-with-jsx.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @enableInferReactFunctions
1 +// @compilationMode(infer)
2 function Component(props) {
3 return <div />;
4 }
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/infer-functions-hook-with-hook-call.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @enableInferReactFunctions
5 +// @compilationMode(infer)
6 function useStateValue(props) {
7 const [state, _] = useState(null);
8 return [state];
@@ -13,7 +13,7 @@ function useStateValue(props) {
13 ## Code
14
15 ```javascript
16 -import { unstable_useMemoCache as useMemoCache } from "react"; // @enableInferReactFunctions
16 +import { unstable_useMemoCache as useMemoCache } from "react"; // @compilationMode(infer)
17 function useStateValue(props) {
18 const $ = useMemoCache(2);
19 const [state] = useState(null);
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/infer-functions-hook-with-hook-call.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @enableInferReactFunctions
1 +// @compilationMode(infer)
2 function useStateValue(props) {
3 const [state, _] = useState(null);
4 return [state];
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/infer-functions-hook-with-jsx.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @enableInferReactFunctions
5 +// @compilationMode(infer)
6 function useDiv(props) {
7 return <div />;
8 }
@@ -12,7 +12,7 @@ function useDiv(props) {
12 ## Code
13
14 ```javascript
15 -import { unstable_useMemoCache as useMemoCache } from "react"; // @enableInferReactFunctions
15 +import { unstable_useMemoCache as useMemoCache } from "react"; // @compilationMode(infer)
16 function useDiv(props) {
17 const $ = useMemoCache(1);
18 let t0;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/infer-functions-hook-with-jsx.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @enableInferReactFunctions
1 +// @compilationMode(infer)
2 function useDiv(props) {
3 return <div />;
4 }
compiler/packages/eslint-plugin-react-forget/src/rules/ReactForgetDiagnostics.ts
+1 -1
@@ -55,7 +55,7 @@ function isReportableDiagnostic(
55
56 const COMPILER_OPTIONS: Partial<PluginOptions> = {
57 noEmit: true,
58 - enableOnlyOnUseForgetDirective: true,
58 + compilationMode: "annotation",
59 panicOnBailout: false,
60 environment: {
61 validateHooksUsage: true,
compiler/packages/fixture-test-utils/src/compiler-utils.ts
+19 -33
@@ -1,14 +1,10 @@
1 +import assert from "assert";
2 import type { runReactForgetBabelPlugin as RunReactForgetBabelPlugin } from "babel-plugin-react-forget/src/Babel/RunReactForgetBabelPlugin";
3 +import { CompilationMode } from "babel-plugin-react-forget/src/Entrypoint";
4 import type { Effect, ValueKind } from "babel-plugin-react-forget/src/HIR";
5
4 -const FlowPragmas = [/\/\/\s@flow$/gm, /\*\s@flow$/gm];
5 -
6 export function parseLanguage(source: string): "flow" | "typescript" {
7 - let useFlow = false;
8 - for (const flowPragma of FlowPragmas) {
9 - useFlow ||= !!source.match(flowPragma);
10 - }
11 - return useFlow ? "flow" : "typescript";
7 + return source.indexOf("@flow") !== -1 ? "flow" : "typescript";
8 }
9
10 export function transformFixtureInput(
@@ -21,7 +17,6 @@ export function transformFixtureInput(
17 const firstLine = input.substring(0, input.indexOf("\n"));
18
19 let language = parseLanguage(firstLine);
24 - let enableOnlyOnUseForgetDirective = false;
20 let gating = null;
21 let instrumentForget = null;
22 let panicOnBailout = true;
@@ -32,12 +27,23 @@ export function transformFixtureInput(
27 let validateRefAccessDuringRender = true;
28 let validateNoSetStateInRender = true;
29 let enableEmitFreeze = null;
35 - let enableOnlyOnReactScript = false;
36 - let enableInferReactFunctions = false;
30 + let compilationMode: CompilationMode = "all";
31
38 - if (firstLine.indexOf("@forgetDirective") !== -1) {
39 - enableOnlyOnUseForgetDirective = true;
32 + if (firstLine.indexOf("@compilationMode(annotation)") !== -1) {
33 + assert(
34 + compilationMode === "all",
35 + "Cannot set @compilationMode(..) more than once"
36 + );
37 + compilationMode = "annotation";
38 + }
39 + if (firstLine.indexOf("@compilationMode(infer)") !== -1) {
40 + assert(
41 + compilationMode === "all",
42 + "Cannot set @compilationMode(..) more than once"
43 + );
44 + compilationMode = "infer";
45 }
46 +
47 if (firstLine.includes("@gating")) {
48 gating = {
49 source: "ReactForgetFeatureFlag",
@@ -77,24 +83,6 @@ export function transformFixtureInput(
83 importSpecifierName: "makeReadOnly",
84 };
85 }
80 - if (firstLine.indexOf("@reactScriptDirective") !== -1) {
81 - enableOnlyOnReactScript = true;
82 - language = "flow";
83 - }
84 - if (firstLine.indexOf("@enableInferReactFunctions") !== -1) {
85 - enableInferReactFunctions = true;
86 - }
87 - if (
88 - [
89 - enableInferReactFunctions,
90 - enableOnlyOnReactScript,
91 - enableOnlyOnUseForgetDirective,
92 - ].filter((x) => x === true).length > 1
93 - ) {
94 - throw new Error(
95 - "Cannot enable more than one of @enableInferReactFunctions, @enableOnlyOnReactScript, and @enableOnlyOnUseForgetDirective at once"
96 - );
97 - }
86
87 return pluginFn(
88 input,
@@ -124,9 +112,7 @@ export function transformFixtureInput(
112 enableEmitFreeze,
113 assertValidMutableRanges: true,
114 },
127 - enableOnlyOnUseForgetDirective,
128 - enableOnlyOnReactScript,
129 - enableInferReactFunctions,
115 + compilationMode,
116 logger: null,
117 gating,
118 instrumentForget,
compiler/packages/sprout/src/SproutTodoFilter.ts
+1 -1
@@ -411,7 +411,7 @@ const skipFilter = new Set([
411 "fbt-call",
412 "fbt-call-complex-param-value",
413 "fbt-template-string-same-scope",
414 - "reactscript-basic.flow",
414 + "component-declaration-basic.flow",
415
416 // TODO: we probably want to always skip these
417 "rules-of-hooks/rules-of-hooks-0592bd574811",