From 1b0a00002507c20ea9f9f1f6ca3b564e935d6acd Mon Sep 17 00:00:00 2001 From: Blake Kostner Date: Tue, 20 Feb 2024 15:17:07 -0700 Subject: [PATCH] fix: update handlebars or statement variable usage (#34) Seems I found a bug where logic in `#or` does not work. --- src/handlebars.test.ts | 11 +++++++++++ src/handlebars.ts | 4 ++-- tsconfig.json | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/handlebars.test.ts b/src/handlebars.test.ts index 6f36cf1..c79c4ab 100644 --- a/src/handlebars.test.ts +++ b/src/handlebars.test.ts @@ -39,4 +39,15 @@ describe.concurrent("handlebars", () => { expect(result).toEqual(" services:"); }); + + it("allows statements in block", async (ctx) => { + const template = Handlebars.compile( + "{{#or POSTGRES_VERSION KAFKA_USAGE}}{{#if POSTGRES_VERSION}}POSTGRES{{/if}}{{#if KAFKA_USAGE}}KAFKA{{/if}}{{/or}}" + ); + const result = template({ + POSTGRES_VERSION: "14" + }); + + expect(result).toEqual("POSTGRES"); + }); }); diff --git a/src/handlebars.ts b/src/handlebars.ts index a580adb..dbeed8f 100644 --- a/src/handlebars.ts +++ b/src/handlebars.ts @@ -7,11 +7,11 @@ Handlebars.registerHelper("or", function (...params) { for (const value of params) { if (value) { - return options.fn(); + return options.fn(this); } } - return options.inverse(); + return options.inverse(this); }); export default Handlebars; diff --git a/tsconfig.json b/tsconfig.json index 76db3f6..3db7bc6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,10 +2,10 @@ "compilerOptions": { "esModuleInterop": true, "module": "commonjs", - "noImplicitAny": true, + "noImplicitAny": false, "outDir": "./dist", "rootDir": "./src", - "strict": true, + "strict": false, "target": "es6" }, "exclude": ["node_modules", "**/*.test.ts"]