diff --git a/Gemfile b/Gemfile index 1726d715cdb..71286aeaa14 100644 --- a/Gemfile +++ b/Gemfile @@ -107,7 +107,7 @@ gem 'ember-rails' gem 'ember-source', '1.9.0.beta.4' gem 'handlebars-source', '2.0.0' gem 'barber' -gem '6to5' +gem 'babel-transpiler' gem 'message_bus' gem 'rails_multisite', path: 'vendor/gems/rails_multisite' diff --git a/Gemfile.lock b/Gemfile.lock index d2d90ac99f3..0658e42a347 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -6,10 +6,6 @@ PATH GEM remote: https://rubygems.org/ specs: - 6to5 (0.5.0) - 6to5-source (>= 1.14, < 4) - execjs (~> 2.0) - 6to5-source (3.3.7) CFPropertyList (2.2.8) actionmailer (4.1.8) actionpack (= 4.1.8) @@ -45,6 +41,10 @@ GEM activerecord (>= 2.3.0) rake (>= 0.8.7) arel (5.0.1.20140414130214) + babel-source (4.6.6) + babel-transpiler (0.6.0) + babel-source (>= 4.0, < 5) + execjs (~> 2.0) barber (0.5.0) ember-source execjs @@ -458,10 +458,10 @@ PLATFORMS ruby DEPENDENCIES - 6to5 actionpack-action_caching active_model_serializers (~> 0.8.0) annotate + babel-transpiler barber better_errors binding_of_caller 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 54f96a52fec..c11daa489a8 100644 --- a/lib/es6_module_transpiler/tilt/es6_module_transpiler_template.rb +++ b/lib/es6_module_transpiler/tilt/es6_module_transpiler_template.rb @@ -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