From 7cf2aae60c9e2e38b7d833ec40ddc7c67bc3ebc7 Mon Sep 17 00:00:00 2001 From: "taotie-bot[bot]" <120676786+taotie-bot[bot]@users.noreply.github.com> Date: Sat, 27 May 2023 22:41:53 +0000 Subject: [PATCH] chore(flags): remove flag test-flag --- src/common.ts | 6 +- src/remove-simple-if-flags.ts | 100 ++++++---------------------------- 2 files changed, 19 insertions(+), 87 deletions(-) diff --git a/src/common.ts b/src/common.ts index 7e7cb9d..caad84c 100644 --- a/src/common.ts +++ b/src/common.ts @@ -1,14 +1,14 @@ // Some typescript symbols export const featureFlag = 'featureFlag' -export function f1(): string { +export function f1() { return 'f1' } -export function f2(): string { +export function f2() { return 'f2' } -export function f3(): string { +export function f3() { return 'f2' } diff --git a/src/remove-simple-if-flags.ts b/src/remove-simple-if-flags.ts index 61c1b02..e474278 100644 --- a/src/remove-simple-if-flags.ts +++ b/src/remove-simple-if-flags.ts @@ -1,99 +1,31 @@ -import { featureFlag, f1, f2 } from './common' - -const context = { - featureFlag: true, - fflag: { - featureFlag: true - }, - data: { - fflag: { - featureFlag: true - } - } -} +import { f1, f2 } from './common' // If feature flag is true (f1) -if (featureFlag) { - f1() -} else { - f2() -} - +f1() // If feature flag is false (f2) -if (!featureFlag) { - f1() -} else { - f2() -} - +f2() // If conditional doesn't have a block wrapper (f1) -if (featureFlag) f1() -else { - f2() -} +f1() // If else conditional doesn't have a block wrapper (f2) -if (!featureFlag) f1() -else f2() +f2() // If there are multiple statements inside the block (f1, f2, f3) -if (featureFlag) { - f1() - f2() - f1() -} else { - f2() - f1() -} - +f1() +f2() +f1() // If there are multiple statements inside the block (inverse) (f2, f1) -if (!featureFlag) { - f1() - f2() - f1() -} else { - f2() - f1() -} - +f2() +f1() // If feature flag within context (f1) -if (context.featureFlag) { - f1() -} else { - f2() -} - +f1() // If feature flag within multiple context (f1) -if (context.fflag.featureFlag) { - f1() -} else { - f2() -} - +f1() // If feature flag within context (inverse) (f2) -if (!context.featureFlag) { - f1() -} else { - f2() -} - +f2() // If feature flag within multiple context (inverse) (f2) -if (!context.fflag.featureFlag) { - f1() -} else { - f2() -} - +f2() // If feature flag within multiple context (f1) -if (context.data.fflag.featureFlag) { - f1() -} else { - f2() -} - +f1() // If feature flag within multiple context (f2) -if (!context.data.fflag.featureFlag) { - f1() -} else { - f2() -} +f2()