Class: Sprockets::ES6
- Inherits:
-
Object
- Object
- Sprockets::ES6
- Defined in:
- lib/sprockets/es6.rb,
lib/sprockets/es6/version.rb
Constant Summary collapse
- VERSION =
'0.8.2'
Class Method Summary collapse
Instance Method Summary collapse
- #call(input) ⇒ Object
-
#initialize(options = {}) ⇒ ES6
constructor
A new instance of ES6.
Constructor Details
#initialize(options = {}) ⇒ ES6
Returns a new instance of ES6.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/sprockets/es6.rb', line 15 def initialize( = {}) @options = .dup.freeze @cache_key = [ self.class.name, Babel::Transpiler.version, Babel::Transpiler.source_version, VERSION, @options ].freeze end |
Class Method Details
.call(input) ⇒ Object
11 12 13 |
# File 'lib/sprockets/es6.rb', line 11 def self.call(input) instance.call(input) end |
.instance ⇒ Object
7 8 9 |
# File 'lib/sprockets/es6.rb', line 7 def self.instance @instance ||= new end |
Instance Method Details
#call(input) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sprockets/es6.rb', line 27 def call(input) data = input[:data] result = input[:cache].fetch(@cache_key + [input[:filename]] + [data]) do opts = { 'sourceRoot' => input[:load_path], 'moduleRoot' => nil, 'filename' => input[:filename], 'filenameRelative' => input[:environment].split_subpath(input[:load_path], input[:filename]) }.merge(@options) if opts['moduleIds'] && opts['moduleRoot'] opts['moduleId'] ||= File.join(opts['moduleRoot'], input[:name]) elsif opts['moduleIds'] opts['moduleId'] ||= input[:name] end Babel::Transpiler.transform(data, opts) end result['code'] end |