Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function moustacheToExpression(expr: AST.MustacheStatement): AST.Expression {
if (expr.path.type === "PathExpression") {
if (expr.params.length === 0 && expr.hash.pairs.length === 0) {
debug("converting", expr.path.original, "to path");
return expr.path;
} else {
debug("converting", expr.path.original, "to sexpr");
return builders.sexpr(expr.path, expr.params, expr.hash);
}
} else {
debug("preserving literal", expr.path.original, "as literal");
return expr.path;
}
}
function moustacheToStringExpression(stringExpression: StringAST): AST.Expression {
if (stringExpression!.type === "ConcatStatement") {
return builders.sexpr(
builders.path(CONCAT_HELPER_NAME),
(stringExpression as AST.ConcatStatement).parts.reduce(
(arr, val) => {
if (val.type === "TextNode") {
arr.push(builders.string(val.chars));
} else {
arr.push(val.path);
}
return arr;
},
new Array()));
} else {
return moustacheToExpression(stringExpression as AST.MustacheStatement);
}
}
export function classnamesSubexpr(rewrite: IndexedClassRewrite<style>, element: TemplateElement): AST.SubExpression {
return builders.sexpr(
builders.path(CLASSNAMES_HELPER_NAME),
constructArgs(rewrite, element),
);
}
</style>