discourse/app/assets/javascripts/theme-transpiler/theme-hbs-ast-transforms.js
2025-07-14 14:08:56 +01:00

30 lines
804 B
JavaScript
Vendored

function manipulateAstNodeForTheme(node, themeId) {
// Magically add theme id as the first param for each of these helpers)
if (
node.path.head &&
["theme-i18n", "theme-prefix", "theme-setting"].includes(
node.path.head.name
)
) {
if (node.params.length === 1) {
node.params.unshift({
type: "NumberLiteral",
value: themeId,
original: themeId,
loc: { start: {}, end: {} },
});
}
}
}
export default function buildEmberTemplateManipulatorPlugin(themeId) {
return function () {
return {
name: "theme-template-manipulator",
visitor: {
SubExpression: (node) => manipulateAstNodeForTheme(node, themeId),
MustacheStatement: (node) => manipulateAstNodeForTheme(node, themeId),
},
};
};
}