diff --git a/config/initializers/10-discourse_iife.rb b/config/initializers/10-discourse_iife.rb index 56e6a4cb8cd..73f343071f6 100644 --- a/config/initializers/10-discourse_iife.rb +++ b/config/initializers/10-discourse_iife.rb @@ -1,3 +1,5 @@ require 'discourse_iife' +require 'source_url' -Rails.application.assets.register_preprocessor('application/javascript', DiscourseIIFE) \ No newline at end of file +Rails.application.assets.register_preprocessor('application/javascript', DiscourseIIFE) +Rails.application.assets.register_postprocessor('application/javascript', SourceURL) diff --git a/lib/discourse_iife.rb b/lib/discourse_iife.rb index 80033a11bb1..fa80aa43fdf 100644 --- a/lib/discourse_iife.rb +++ b/lib/discourse_iife.rb @@ -32,7 +32,6 @@ class DiscourseIIFE < Sprockets::Processor .sub("/app/assets/javascripts", "") .sub("/test/javascripts", "") res << "\nwindow.__jshintSrc = window.__jshintSrc || {}; window.__jshintSrc['/assets#{req_path}'] = #{data.to_json};\n" - res << "\n//@ sourceURL=/#{context.logical_path}\n" end res diff --git a/lib/es6_module_transpiler/tilt/es6_module_transpiler_template.rb b/lib/es6_module_transpiler/tilt/es6_module_transpiler_template.rb index d404d42fc62..27776035800 100644 --- a/lib/es6_module_transpiler/tilt/es6_module_transpiler_template.rb +++ b/lib/es6_module_transpiler/tilt/es6_module_transpiler_template.rb @@ -127,7 +127,6 @@ module Tilt req_path = "/assets/#{scope.logical_path}.#{extension}" @output << "\nwindow.__jshintSrc = window.__jshintSrc || {}; window.__jshintSrc['#{req_path}'] = #{data.to_json};\n" - @output << "\n//@ sourceURL=/#{scope.logical_path}\n" end @output diff --git a/lib/source_url.rb b/lib/source_url.rb new file mode 100644 index 00000000000..a5b79ae6afe --- /dev/null +++ b/lib/source_url.rb @@ -0,0 +1,15 @@ +class SourceURL < Tilt::Template + self.default_mime_type = 'application/javascript' + + def prepare + end + + def evaluate(scope, locals, &block) + code = '' + code << 'eval(' + code << data.inspect + code << " + \"\\n//@ sourceURL=/#{scope.logical_path}\"" + code << ");\n" + code + end +end