@samitouri / QOS-React-1 / commits / 5142affc26

Allow module level "use no forget"

Currently we only allow adding the directive to function bodies, but there may be cases where we want to always opt out an entire module from being compiled by Forget

Lauren Tan committed Feb 15, 2024 at 17:44 UTC 5142affc26d61aa32f2088541e6c93f08f21a79f
4 files changed +43
compiler/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts
+5
@@ -188,6 +188,11 @@ export function compileProgram(
188 program: NodePath<t.Program>,
189 pass: CompilerPass
190 ): void {
191 + // Top level "use no forget", skip this file entirely
192 + if (findUseNoForgetDirective(program.node.directives) != null) {
193 + return;
194 + }
195 +
196 const options = parsePluginOptions(pass.opts);
197 const environment = parseEnvironmentConfig(pass.opts.environment ?? {});
198
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/use-no-forget-module-level.expect.md new
+29
@@ -0,0 +1,29 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +"use no forget";
6 +
7 +export default function foo(x, y) {
8 + if (x) {
9 + return foo(false, y);
10 + }
11 + return [y * 10];
12 +}
13 +
14 +```
15 +
16 +## Code
17 +
18 +```javascript
19 +"use no forget";
20 +
21 +export default function foo(x, y) {
22 + if (x) {
23 + return foo(false, y);
24 + }
25 + return [y * 10];
26 +}
27 +
28 +```
29 +
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/use-no-forget-module-level.js new
+8
@@ -0,0 +1,8 @@
1 +"use no forget";
2 +
3 +export default function foo(x, y) {
4 + if (x) {
5 + return foo(false, y);
6 + }
7 + return [y * 10];
8 +}
compiler/packages/sprout/src/SproutTodoFilter.ts
+1
@@ -384,6 +384,7 @@ const skipFilter = new Set([
384 "useMemo-named-function",
385 "useMemo-return-empty",
386 "useMemo-simple",
387 + "use-no-forget-module-level",
388 // defines multiple functions
389 "alias-while",
390 "babel-existing-react-import",