DEV: Apply theme template transforms to colocated components (#18704)

This commit is contained in:
David Taylor 2022-10-21 19:05:34 +01:00 committed by GitHub
parent c937b6dd36
commit cc439cf412
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -232,7 +232,7 @@ class ThemeJavascriptCompiler
transpiler = DiscourseJsProcessor::Transpiler.new
@output_tree << ["#{original_filename}.js", <<~JS]
if ('define' in window) {
#{transpiler.perform(script, "", name).strip}
#{transpiler.perform(script, "", name, theme_id: @theme_id).strip}
}
JS
rescue MiniRacer::RuntimeError, DiscourseJsProcessor::TranspileError => ex

View File

@ -110,6 +110,15 @@ RSpec.describe ThemeJavascriptCompiler do
expect(compiler.raw_content).to include("setComponentTemplate")
end
it "applies theme AST transforms to colocated components" do
compiler = ThemeJavascriptCompiler.new(12345678910, 'my theme name')
compiler.append_tree(
{ "discourse/components/mycomponent.hbs" => '{{theme-i18n "my_translation_key"}}' }
)
template_compiled_line = compiler.raw_content.lines.find { |l| l.include?('"block":') }
expect(template_compiled_line).to include("12345678910")
end
it "prints error when default export missing" do
compiler.append_tree(
{