A platform for community discussion. Free, open, simple.
DEV: Patch Ruby Ember template compiler to work with recent ember
David Taylora4c4d3cb50e9
diff --git a/app/models/theme.rb b/app/models/theme.rbindex 5d54677311e..923415ecf1d 100644--- a/app/models/theme.rb+++ b/app/models/theme.rb@@ -6,7 +6,7 @@ require 'json_schemer'class Theme < ActiveRecord::Baseinclude GlobalPath- BASE_COMPILER_VERSION = 57+ BASE_COMPILER_VERSION = 58attr_accessor :child_componentsdiff --git a/lib/freedom_patches/barber_ember_precompiler.rb b/lib/freedom_patches/barber_ember_precompiler.rbnew file mode 100644index 00000000000..aa148dd6740--- /dev/null+++ b/lib/freedom_patches/barber_ember_precompiler.rb@@ -0,0 +1,36 @@+# frozen_string_literal: true++# Eventually we aim to move away from using Barber to precompile assets.+# These overrides unblock us moving to more recent ember versions in the meantime++module BarberEmberPrecompilerFreedomPatch+ # Use the template compiler JS from node_modules+ def ember_template_precompiler+ @ember ||= File.new("app/assets/javascripts/node_modules/ember-source/dist/ember-template-compiler.js")+ end++ # Apply a couple of extra shims for more recent ember-template-compilers+ def source_fixes+ shims = super++ shims << <<~JS+ module = {exports:{}}++ console = {+ log: function(){},+ warn: function(){},+ error: function(){}+ };+ JS++ shims+ end++ # Recent ember-template-compilers fail if `option` is null+ def compile(template, options = nil)+ options = {} if options.nil?+ super(template, options)+ end+end++Barber::Ember::Precompiler.prepend(BarberEmberPrecompilerFreedomPatch)diff --git a/lib/theme_javascript_compiler.rb b/lib/theme_javascript_compiler.rbindex b029041e539..d25bbb6d5a8 100644--- a/lib/theme_javascript_compiler.rb+++ b/lib/theme_javascript_compiler.rb@@ -17,7 +17,8 @@ class ThemeJavascriptCompilernode.params.unshift({type: "NumberLiteral",value: #{@theme_id},- original: #{@theme_id}+ original: #{@theme_id},+ loc: { start: {}, end: {} }})}}@@ -58,7 +59,7 @@ class ThemeJavascriptCompilerdef discourse_extension<<~JS- Ember.HTMLBars.registerPlugin('ast', function() {+ module.exports.registerPlugin('ast', function() {return {name: 'theme-template-manipulator',visitor: {