Module: Sprockets::Babel
- Defined in:
- lib/sprockets/babel.rb,
lib/sprockets/babel/version.rb
Defined Under Namespace
Classes: Console, Template
Constant Summary
collapse
- VERSION =
'0.0.6'
Class Method Summary
collapse
Class Method Details
.context ⇒ Object
94
95
96
97
98
99
100
101
|
# File 'lib/sprockets/babel.rb', line 94
def self.context
@context ||= begin
ctx = V8::Context.new
ctx.eval('var self = this; ' + File.read(::Babel::Transpiler.script_path))
ctx['console'] = Console.new
ctx
end
end
|
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/sprockets/babel.rb', line 81
def self.transform(code, options = {})
modules = options[:modules] || 'inline'
babel_transform = context[:babel][:transform]
result = babel_transform.call(code, options.merge(
'ast' => false,
'modules' => modules == 'inline' ? 'amd' : modules
))
if modules == 'inline'
result['code'] = transform_inline(result['code'], options)
end
result
end
|