Skip to content

Commit

Permalink
Merge pull request #4 from StileEducation/fix/helper-hash-options
Browse files Browse the repository at this point in the history
Fix Hash Options
  • Loading branch information
pekevski authored Jan 30, 2024
2 parents f283ea7 + 89f10ad commit 022e73a
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/expressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,22 @@ export const resolveHelper = (
const params: Array<Babel.Expression> = expression.params.map(resolveExpression);

// Handlebars helpers always take an options argument as the last parameter
params.push(
Babel.objectExpression(
expression.hash.pairs.map((pair) => {
return Babel.objectProperty(
Babel.stringLiteral(pair.key),
resolveExpression(pair.value)
)
})
// The parameter always has a key called hash :/
const hash = Babel.objectExpression(
expression.hash.pairs.map((pair) => {
return Babel.objectProperty(
Babel.stringLiteral(pair.key),
resolveExpression(pair.value)
)
})
);
const options = Babel.objectExpression([
Babel.objectProperty(
Babel.stringLiteral("hash"),
hash
)
)
]);
params.push(options);
return Babel.callExpression(Babel.identifier(expression.path.original?.toString() ?? 'undefined'), params)
}

Expand Down

0 comments on commit 022e73a

Please sign in to comment.