From db14f9afabc6f3045e8d2ebb7db3558d310d59e7 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 25 Jan 2024 19:48:34 +0100 Subject: [PATCH] Inject {} at the end of the helper calls --- packages/string-templates/src/helpers/list.js | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/packages/string-templates/src/helpers/list.js b/packages/string-templates/src/helpers/list.js index 92f5ee03ce..739d8b50be 100644 --- a/packages/string-templates/src/helpers/list.js +++ b/packages/string-templates/src/helpers/list.js @@ -15,24 +15,14 @@ module.exports.getHelperList = () => { } for (let collection of constructed) { for (let [key, func] of Object.entries(collection)) { - helpers[key] = func + // Handlebars injects the hbs options to the helpers by default. We are adding an empty {} as a last parameter to simulate it + helpers[key] = (...props) => func(...props, {}) } } for (let key of Object.keys(externalHandlebars.addedHelpers)) { helpers[key] = externalHandlebars.addedHelpers[key] } - helpers = adjustJsHelpers(helpers) Object.freeze(helpers) return helpers } - -// Some helpers depend on handlebars injecting some parameters. This function adjust the helpers when required -function adjustJsHelpers(helpers) { - const result = { ...helpers } - - result.avg = function (...params) { - return helpers.avg(...params, {}) - } - return result -}