From 0aa6d6ba50171bce7199b5e408c05bc9336ed88e Mon Sep 17 00:00:00 2001 From: Victor Fan Date: Tue, 22 Nov 2022 17:13:39 -0800 Subject: [PATCH] booleanParams need thenElse too (#1318) --- spec/params/params.spec.ts | 8 ++++---- src/params/types.ts | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/spec/params/params.spec.ts b/spec/params/params.spec.ts index d440d3038..fe96a8b91 100644 --- a/spec/params/params.spec.ts +++ b/spec/params/params.spec.ts @@ -277,13 +277,13 @@ describe("Params as CEL", () => { const booleanExpr = params.defineBoolean("BOOL"); const cmpExpr = params.defineInt("A").cmp("!=", params.defineInt("B")); - expect(booleanExpr.then("asdf", "jkl;").toCEL()).to.equal( + expect(booleanExpr.thenElse("asdf", "jkl;").toCEL()).to.equal( '{{ params.BOOL ? "asdf" : "jkl;" }}' ); - expect(booleanExpr.then(-11, 22).toCEL()).to.equal("{{ params.BOOL ? -11 : 22 }}"); - expect(booleanExpr.then(false, true).toCEL()).to.equal("{{ params.BOOL ? false : true }}"); + expect(booleanExpr.thenElse(-11, 22).toCEL()).to.equal("{{ params.BOOL ? -11 : 22 }}"); + expect(booleanExpr.thenElse(false, true).toCEL()).to.equal("{{ params.BOOL ? false : true }}"); expect( - booleanExpr.then(params.defineString("FOO"), params.defineString("BAR")).toCEL() + booleanExpr.thenElse(params.defineString("FOO"), params.defineString("BAR")).toCEL() ).to.equal("{{ params.BOOL ? params.FOO : params.BAR }}"); expect(cmpExpr.thenElse("asdf", "jkl;").toCEL()).to.equal( '{{ params.A != params.B ? "asdf" : "jkl;" }}' diff --git a/src/params/types.ts b/src/params/types.ts index bd96e62e8..ff367e8be 100644 --- a/src/params/types.ts +++ b/src/params/types.ts @@ -452,7 +452,15 @@ export class BooleanParam extends Param { return !!process.env[this.name] && process.env[this.name] === "true"; } + /** @deprecated */ then(ifTrue: T | Expression, ifFalse: T | Expression) { + return this.thenElse(ifTrue, ifFalse); + } + + thenElse( + ifTrue: T | Expression, + ifFalse: T | Expression + ) { return new TernaryExpression(this, ifTrue, ifFalse); } }