[babel] Add option to specify a gatingModule
Sathya Gunasekaran committed
Mar 6, 2023 at 19:53 UTC
3cd31a11fbf9b502996a26316be9849b624a02d2
2 files changed
+21
compiler/forget/src/Babel/PluginOptions.ts
+20
@@ -16,6 +16,25 @@ export type PluginOptions = {
16
environment: Partial<EnvironmentOptions> | null;
17
18
logger: Logger | null;
19
+
20
+ /**
21
+ * Specifying a `gatingModule`, makes Forget compile and emit a separate
22
+ * version of the function gated by importing an `isForgetEnabled` from the
23
+ * specified `gatingModule`.
24
+ *
25
+ * For example:
26
+ * gatingModule: 'ReactForgetFeatureFlag'
27
+ *
28
+ * produces:
29
+ * import isForgetEnabled from ReactForgetFeatureFlag
30
+ *
31
+ * Foo_forget() {}
32
+ *
33
+ * Foo_uncompiled() {}
34
+ *
35
+ * var Foo = isForgetEnabled ? Foo_forget : Foo_uncompiled;
36
+ */
37
+ gatingModule: string | null;
38
};
39
40
export type Logger = {
@@ -26,6 +45,7 @@ export const defaultOptions: PluginOptions = {
45
enableOnlyOnUseForgetDirective: false,
46
environment: null,
47
logger: null,
48
+ gatingModule: null,
49
} as const;
50
51
export function parsePluginOptions(obj: unknown): PluginOptions {
compiler/forget/src/__tests__/hir-test.ts
+1
@@ -77,6 +77,7 @@ describe("React Forget (HIR version)", () => {
77
]),
78
},
79
logger: null,
80
+ gatingModule: null,
81
}).code,
82
});
83
} catch (e) {