2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-06 10:50:21 +08:00

FIX: 6to5 was renamed to Babel

I can't believe they just pulled the old gem and broke people deploying
our site to production. I get it, your name changed, but don't break
other people's apps with no deprecations.
This commit is contained in:
Robin Ward 2015-03-05 13:08:32 -05:00
parent aeb0fc7559
commit 4691fe35b3
3 changed files with 25 additions and 9 deletions

View file

@ -1,7 +1,22 @@
require 'execjs'
require '6to5'
require 'babel/transpiler'
module Tilt
class Console
def initialize(prefix=nil)
@prefix = prefix || ''
end
def log(msg)
Rails.logger.info("#{@prefix}#{msg}")
end
def error(msg)
Rails.logger.error("#{@prefix}#{msg}")
end
end
class ES6ModuleTranspilerTemplate < Tilt::Template
self.default_mime_type = 'application/javascript'
@ -15,7 +30,7 @@ module Tilt
def self.create_new_context
ctx = V8::Context.new(timeout: 5000)
ctx.eval("var self = this; #{File.read(ES6to5::Source.path)}")
ctx.eval("var self = this; #{File.read(Babel::Transpiler.script_path)}")
ctx.eval("module = {}; exports = {};");
ctx.load("#{Rails.root}/lib/es6_module_transpiler/support/es6-module-transpiler.js")
ctx
@ -64,6 +79,7 @@ module Tilt
klass = self.class
klass.protect do
klass.v8['console'] = Console.new("BABEL: #{scope.logical_path}: ")
@output = klass.v8.eval(generate_source(scope))
end
@ -118,7 +134,7 @@ module Tilt
def generate_source(scope)
js_source = ::JSON.generate(data, quirks_mode: true)
js_source = "to5.transform(#{js_source}, {ast: false, whitelist: ['es6.constants', 'es6.properties.shorthand', 'es6.arrowFunctions', 'es6.blockScoping']})['code']"
js_source = "babel.transform(#{js_source}, {ast: false, whitelist: ['es6.constants', 'es6.properties.shorthand', 'es6.arrowFunctions', 'es6.blockScoping']})['code']"
"new module.exports.Compiler(#{js_source}, '#{module_name(scope.root_path, scope.logical_path)}', #{compiler_options}).#{compiler_method}()"
end