@samitouri / QOS-React-2 / commits / 46a9d40914

[babel] Invoke gating module as a call expression

This is incredibly obvious in hindsight, but for exposure logging to work correctly we need to *call* the underlying `MobileConfig.getBool` function at the callsite – otherwise the bool is evaluated once (and only once) when the module is loaded. Tested internally and verified that in dogfooding the exposure logging was working correctly

Lauren Tan committed Mar 31, 2023 at 11:15 UTC 46a9d409144ae5f8e131756f6ed78aa4b088a3f2
8 files changed +20 -14
compiler/forget/src/Babel/BabelPlugin.ts
+5 -1
@@ -237,7 +237,11 @@ function buildTest(ids: {
237 return t.variableDeclaration("const", [
238 t.variableDeclarator(
239 ids.original,
240 - t.conditionalExpression(testId, ids.compiled, ids.uncompiled)
240 + t.conditionalExpression(
241 + t.callExpression(testId, []),
242 + ids.compiled,
243 + ids.uncompiled
244 + )
245 ),
246 ]);
247 }
compiler/forget/src/__tests__/fixtures/compiler/arrow-function-expr-gating-test.expect.md
+1 -1
@@ -29,7 +29,7 @@ function ErrorView_forget(error, _retry) {
29 }
30 return t0;
31 }
32 -const ErrorView = isForgetEnabled ? ErrorView_forget : ErrorView_uncompiled;
32 +const ErrorView = isForgetEnabled() ? ErrorView_forget : ErrorView_uncompiled;
33
34 export default ErrorView;
35
compiler/forget/src/__tests__/fixtures/compiler/gating-test-export-default-function.expect.md
+2 -2
@@ -40,7 +40,7 @@ function Bar_forget(props) {
40 }
41 return t0;
42 }
43 -const Bar = isForgetEnabled ? Bar_forget : Bar_uncompiled;
43 +const Bar = isForgetEnabled() ? Bar_forget : Bar_uncompiled;
44 export default Bar;
45
46 function NoForget(props) {
@@ -64,7 +64,7 @@ function Foo_forget(props) {
64 }
65 return t0;
66 }
67 -const Foo = isForgetEnabled ? Foo_forget : Foo_uncompiled;
67 +const Foo = isForgetEnabled() ? Foo_forget : Foo_uncompiled;
68
69 ```
70
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/gating-test-export-function-and-default.expect.md
+2 -2
@@ -40,7 +40,7 @@ function Bar_forget(props) {
40 }
41 return t0;
42 }
43 -const Bar = isForgetEnabled ? Bar_forget : Bar_uncompiled;
43 +const Bar = isForgetEnabled() ? Bar_forget : Bar_uncompiled;
44 export default Bar;
45
46 function NoForget(props) {
@@ -64,7 +64,7 @@ function Foo_forget(props) {
64 }
65 return t0;
66 }
67 -export const Foo = isForgetEnabled ? Foo_forget : Foo_uncompiled;
67 +export const Foo = isForgetEnabled() ? Foo_forget : Foo_uncompiled;
68
69 ```
70
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/gating-test-export-function.expect.md
+2 -2
@@ -40,7 +40,7 @@ function Bar_forget(props) {
40 }
41 return t0;
42 }
43 -export const Bar = isForgetEnabled ? Bar_forget : Bar_uncompiled;
43 +export const Bar = isForgetEnabled() ? Bar_forget : Bar_uncompiled;
44
45 export function NoForget(props) {
46 return <Bar>{props.noForget}</Bar>;
@@ -63,7 +63,7 @@ function Foo_forget(props) {
63 }
64 return t0;
65 }
66 -export const Foo = isForgetEnabled ? Foo_forget : Foo_uncompiled;
66 +export const Foo = isForgetEnabled() ? Foo_forget : Foo_uncompiled;
67
68 ```
69
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/gating-test.expect.md
+2 -2
@@ -40,7 +40,7 @@ function Bar_forget(props) {
40 }
41 return t0;
42 }
43 -const Bar = isForgetEnabled ? Bar_forget : Bar_uncompiled;
43 +const Bar = isForgetEnabled() ? Bar_forget : Bar_uncompiled;
44
45 function NoForget(props) {
46 return <Bar>{props.noForget}</Bar>;
@@ -63,7 +63,7 @@ function Foo_forget(props) {
63 }
64 return t0;
65 }
66 -const Foo = isForgetEnabled ? Foo_forget : Foo_uncompiled;
66 +const Foo = isForgetEnabled() ? Foo_forget : Foo_uncompiled;
67
68 ```
69
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/multi-arrow-expr-export-gating-test.expect.md
+4 -2
@@ -34,7 +34,7 @@ function ErrorView_forget(error, _retry) {
34 }
35 return t0;
36 }
37 -const ErrorView = isForgetEnabled ? ErrorView_forget : ErrorView_uncompiled;
37 +const ErrorView = isForgetEnabled() ? ErrorView_forget : ErrorView_uncompiled;
38 function Renderer_uncompiled(props) {
39 return (
40 <Foo>
@@ -73,7 +73,9 @@ function Renderer_forget(props) {
73 }
74 return t2;
75 }
76 -export const Renderer = isForgetEnabled ? Renderer_forget : Renderer_uncompiled;
76 +export const Renderer = isForgetEnabled()
77 + ? Renderer_forget
78 + : Renderer_uncompiled;
79
80 ```
81
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/multi-arrow-expr-gating-test.expect.md
+2 -2
@@ -36,7 +36,7 @@ function ErrorView_forget(error, _retry) {
36 }
37 return t0;
38 }
39 -const ErrorView = isForgetEnabled ? ErrorView_forget : ErrorView_uncompiled;
39 +const ErrorView = isForgetEnabled() ? ErrorView_forget : ErrorView_uncompiled;
40 function Renderer_uncompiled(props) {
41 return (
42 <Foo>
@@ -75,7 +75,7 @@ function Renderer_forget(props) {
75 }
76 return t2;
77 }
78 -const Renderer = isForgetEnabled ? Renderer_forget : Renderer_uncompiled;
78 +const Renderer = isForgetEnabled() ? Renderer_forget : Renderer_uncompiled;
79 export default Renderer;
80
81 ```