Skip to content

Commit

Permalink
fix: update handlebars or statement variable usage (#34)
Browse files Browse the repository at this point in the history
Seems I found a bug where logic in `#or` does not work.
  • Loading branch information
btkostner authored Feb 20, 2024
1 parent e0c95e7 commit 1b0a000
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src/handlebars.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});
4 changes: 2 additions & 2 deletions src/handlebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit 1b0a000

Please sign in to comment.