DEV: Patch Ruby Ember template compiler to work with recent ember

This commit is contained in:
David Taylor 2022-07-18 10:18:16 +01:00
parent 20fd81c2dc
commit a4c4d3cb50
3 changed files with 40 additions and 3 deletions

View File

@ -6,7 +6,7 @@ require 'json_schemer'
class Theme < ActiveRecord::Base
include GlobalPath
BASE_COMPILER_VERSION = 57
BASE_COMPILER_VERSION = 58
attr_accessor :child_components

View File

@ -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)

View File

@ -17,7 +17,8 @@ class ThemeJavascriptCompiler
node.params.unshift({
type: "NumberLiteral",
value: #{@theme_id},
original: #{@theme_id}
original: #{@theme_id},
loc: { start: {}, end: {} }
})
}
}
@ -58,7 +59,7 @@ class ThemeJavascriptCompiler
def discourse_extension
<<~JS
Ember.HTMLBars.registerPlugin('ast', function() {
module.exports.registerPlugin('ast', function() {
return {
name: 'theme-template-manipulator',
visitor: {