From 46a9d409144ae5f8e131756f6ed78aa4b088a3f2 Mon Sep 17 00:00:00 2001 From: Lauren Tan Date: Fri, 31 Mar 2023 11:15:51 -0400 Subject: [PATCH] [babel] Invoke gating module as a call expression MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- compiler/forget/src/Babel/BabelPlugin.ts | 6 +++++- .../compiler/arrow-function-expr-gating-test.expect.md | 2 +- .../compiler/gating-test-export-default-function.expect.md | 4 ++-- .../gating-test-export-function-and-default.expect.md | 4 ++-- .../fixtures/compiler/gating-test-export-function.expect.md | 4 ++-- .../src/__tests__/fixtures/compiler/gating-test.expect.md | 4 ++-- .../compiler/multi-arrow-expr-export-gating-test.expect.md | 6 ++++-- .../compiler/multi-arrow-expr-gating-test.expect.md | 4 ++-- 8 files changed, 20 insertions(+), 14 deletions(-) diff --git a/compiler/forget/src/Babel/BabelPlugin.ts b/compiler/forget/src/Babel/BabelPlugin.ts index 1bdbcb7791..02145b931c 100644 --- a/compiler/forget/src/Babel/BabelPlugin.ts +++ b/compiler/forget/src/Babel/BabelPlugin.ts @@ -237,7 +237,11 @@ function buildTest(ids: { return t.variableDeclaration("const", [ t.variableDeclarator( ids.original, - t.conditionalExpression(testId, ids.compiled, ids.uncompiled) + t.conditionalExpression( + t.callExpression(testId, []), + ids.compiled, + ids.uncompiled + ) ), ]); } diff --git a/compiler/forget/src/__tests__/fixtures/compiler/arrow-function-expr-gating-test.expect.md b/compiler/forget/src/__tests__/fixtures/compiler/arrow-function-expr-gating-test.expect.md index dccc5c361f..e99b6cfe5c 100644 --- a/compiler/forget/src/__tests__/fixtures/compiler/arrow-function-expr-gating-test.expect.md +++ b/compiler/forget/src/__tests__/fixtures/compiler/arrow-function-expr-gating-test.expect.md @@ -29,7 +29,7 @@ function ErrorView_forget(error, _retry) { } return t0; } -const ErrorView = isForgetEnabled ? ErrorView_forget : ErrorView_uncompiled; +const ErrorView = isForgetEnabled() ? ErrorView_forget : ErrorView_uncompiled; export default ErrorView; diff --git a/compiler/forget/src/__tests__/fixtures/compiler/gating-test-export-default-function.expect.md b/compiler/forget/src/__tests__/fixtures/compiler/gating-test-export-default-function.expect.md index 8ce6c365f5..01bdb0e693 100644 --- a/compiler/forget/src/__tests__/fixtures/compiler/gating-test-export-default-function.expect.md +++ b/compiler/forget/src/__tests__/fixtures/compiler/gating-test-export-default-function.expect.md @@ -40,7 +40,7 @@ function Bar_forget(props) { } return t0; } -const Bar = isForgetEnabled ? Bar_forget : Bar_uncompiled; +const Bar = isForgetEnabled() ? Bar_forget : Bar_uncompiled; export default Bar; function NoForget(props) { @@ -64,7 +64,7 @@ function Foo_forget(props) { } return t0; } -const Foo = isForgetEnabled ? Foo_forget : Foo_uncompiled; +const Foo = isForgetEnabled() ? Foo_forget : Foo_uncompiled; ``` \ No newline at end of file diff --git a/compiler/forget/src/__tests__/fixtures/compiler/gating-test-export-function-and-default.expect.md b/compiler/forget/src/__tests__/fixtures/compiler/gating-test-export-function-and-default.expect.md index e4bfcfe42e..ff90b9a097 100644 --- a/compiler/forget/src/__tests__/fixtures/compiler/gating-test-export-function-and-default.expect.md +++ b/compiler/forget/src/__tests__/fixtures/compiler/gating-test-export-function-and-default.expect.md @@ -40,7 +40,7 @@ function Bar_forget(props) { } return t0; } -const Bar = isForgetEnabled ? Bar_forget : Bar_uncompiled; +const Bar = isForgetEnabled() ? Bar_forget : Bar_uncompiled; export default Bar; function NoForget(props) { @@ -64,7 +64,7 @@ function Foo_forget(props) { } return t0; } -export const Foo = isForgetEnabled ? Foo_forget : Foo_uncompiled; +export const Foo = isForgetEnabled() ? Foo_forget : Foo_uncompiled; ``` \ No newline at end of file diff --git a/compiler/forget/src/__tests__/fixtures/compiler/gating-test-export-function.expect.md b/compiler/forget/src/__tests__/fixtures/compiler/gating-test-export-function.expect.md index 81b8dd9e8e..f7a01ac2f7 100644 --- a/compiler/forget/src/__tests__/fixtures/compiler/gating-test-export-function.expect.md +++ b/compiler/forget/src/__tests__/fixtures/compiler/gating-test-export-function.expect.md @@ -40,7 +40,7 @@ function Bar_forget(props) { } return t0; } -export const Bar = isForgetEnabled ? Bar_forget : Bar_uncompiled; +export const Bar = isForgetEnabled() ? Bar_forget : Bar_uncompiled; export function NoForget(props) { return {props.noForget}; @@ -63,7 +63,7 @@ function Foo_forget(props) { } return t0; } -export const Foo = isForgetEnabled ? Foo_forget : Foo_uncompiled; +export const Foo = isForgetEnabled() ? Foo_forget : Foo_uncompiled; ``` \ No newline at end of file diff --git a/compiler/forget/src/__tests__/fixtures/compiler/gating-test.expect.md b/compiler/forget/src/__tests__/fixtures/compiler/gating-test.expect.md index 19260edb97..19af7f0224 100644 --- a/compiler/forget/src/__tests__/fixtures/compiler/gating-test.expect.md +++ b/compiler/forget/src/__tests__/fixtures/compiler/gating-test.expect.md @@ -40,7 +40,7 @@ function Bar_forget(props) { } return t0; } -const Bar = isForgetEnabled ? Bar_forget : Bar_uncompiled; +const Bar = isForgetEnabled() ? Bar_forget : Bar_uncompiled; function NoForget(props) { return {props.noForget}; @@ -63,7 +63,7 @@ function Foo_forget(props) { } return t0; } -const Foo = isForgetEnabled ? Foo_forget : Foo_uncompiled; +const Foo = isForgetEnabled() ? Foo_forget : Foo_uncompiled; ``` \ No newline at end of file diff --git a/compiler/forget/src/__tests__/fixtures/compiler/multi-arrow-expr-export-gating-test.expect.md b/compiler/forget/src/__tests__/fixtures/compiler/multi-arrow-expr-export-gating-test.expect.md index d1a156bdb0..df0fdabf93 100644 --- a/compiler/forget/src/__tests__/fixtures/compiler/multi-arrow-expr-export-gating-test.expect.md +++ b/compiler/forget/src/__tests__/fixtures/compiler/multi-arrow-expr-export-gating-test.expect.md @@ -34,7 +34,7 @@ function ErrorView_forget(error, _retry) { } return t0; } -const ErrorView = isForgetEnabled ? ErrorView_forget : ErrorView_uncompiled; +const ErrorView = isForgetEnabled() ? ErrorView_forget : ErrorView_uncompiled; function Renderer_uncompiled(props) { return ( @@ -73,7 +73,9 @@ function Renderer_forget(props) { } return t2; } -export const Renderer = isForgetEnabled ? Renderer_forget : Renderer_uncompiled; +export const Renderer = isForgetEnabled() + ? Renderer_forget + : Renderer_uncompiled; ``` \ No newline at end of file diff --git a/compiler/forget/src/__tests__/fixtures/compiler/multi-arrow-expr-gating-test.expect.md b/compiler/forget/src/__tests__/fixtures/compiler/multi-arrow-expr-gating-test.expect.md index 1280c71e59..b3439994c4 100644 --- a/compiler/forget/src/__tests__/fixtures/compiler/multi-arrow-expr-gating-test.expect.md +++ b/compiler/forget/src/__tests__/fixtures/compiler/multi-arrow-expr-gating-test.expect.md @@ -36,7 +36,7 @@ function ErrorView_forget(error, _retry) { } return t0; } -const ErrorView = isForgetEnabled ? ErrorView_forget : ErrorView_uncompiled; +const ErrorView = isForgetEnabled() ? ErrorView_forget : ErrorView_uncompiled; function Renderer_uncompiled(props) { return ( @@ -75,7 +75,7 @@ function Renderer_forget(props) { } return t2; } -const Renderer = isForgetEnabled ? Renderer_forget : Renderer_uncompiled; +const Renderer = isForgetEnabled() ? Renderer_forget : Renderer_uncompiled; export default Renderer; ```