A platform for community discussion. Free, open, simple.
DEV: Move theme hbs transforms into dedicated file (#33602)
David Taylor2a356130c0d9
diff --git a/app/assets/javascripts/theme-transpiler/theme-hbs-ast-transforms.js b/app/assets/javascripts/theme-transpiler/theme-hbs-ast-transforms.jsnew file mode 100644index 00000000000..b69aca5f487--- /dev/null+++ b/app/assets/javascripts/theme-transpiler/theme-hbs-ast-transforms.js@@ -0,0 +1,30 @@+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),+ },+ };+ };+}diff --git a/app/assets/javascripts/theme-transpiler/transpiler.js b/app/assets/javascripts/theme-transpiler/transpiler.jsindex 962b39c34da..229d36f1327 100644--- a/app/assets/javascripts/theme-transpiler/transpiler.js+++ b/app/assets/javascripts/theme-transpiler/transpiler.js@@ -12,41 +12,13 @@ import { minify as terserMinify } from "terser";import { WidgetHbsCompiler } from "discourse-widget-hbs/lib/widget-hbs-compiler";import { browsers } from "../discourse/config/targets";import { Preprocessor } from "./content-tag";+import buildEmberTemplateManipulatorPlugin from "./theme-hbs-ast-transforms";const thisFallbackPlugin = EmberThisFallback._buildPlugin({enableLogging: false,isTheme: true,}).plugin;-function manipulateAstNodeForTheme(node, themeId) {- // Magically add theme id as the first param for each of these helpers)- if (- node.path.parts &&- ["theme-i18n", "theme-prefix", "theme-setting"].includes(node.path.parts[0])- ) {- if (node.params.length === 1) {- node.params.unshift({- type: "NumberLiteral",- value: themeId,- original: themeId,- loc: { start: {}, end: {} },- });- }- }-}--function buildEmberTemplateManipulatorPlugin(themeId) {- return function () {- return {- name: "theme-template-manipulator",- visitor: {- SubExpression: (node) => manipulateAstNodeForTheme(node, themeId),- MustacheStatement: (node) => manipulateAstNodeForTheme(node, themeId),- },- };- };-}-function buildTemplateCompilerBabelPlugins({ extension, themeId }) {const compiler = { precompile };