Class: Sprockets::ES6Module
- Inherits:
-
Object
- Object
- Sprockets::ES6Module
- Defined in:
- lib/sprockets/es6module.rb,
lib/sprockets/es6module/version.rb
Constant Summary collapse
- MODULE_METHODS =
{ amd: 'to_amd', common: 'to_cjs', umd: 'to_umd' }
- VERSION =
'0.0.2'
Class Method Summary collapse
Instance Method Summary collapse
- #call(input) ⇒ Object
-
#initialize(type = :amd, options = {}) ⇒ ES6Module
constructor
A new instance of ES6Module.
Constructor Details
#initialize(type = :amd, options = {}) ⇒ ES6Module
Returns a new instance of ES6Module.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/sprockets/es6module.rb', line 22 def initialize(type = :amd, = {}) @method = MODULE_METHODS[type] raise "Unsupported method `#{type}`. Available types are: #{MODULE_METHODS.keys.inspect}" unless @method = .dup.merge(strict: false).freeze @cache_key = [ self.class.name, Esperanto::VERSION, VERSION, @method ].freeze end |
Class Method Details
.call(input) ⇒ Object
18 19 20 |
# File 'lib/sprockets/es6module.rb', line 18 def self.call(input) instance.call(input) end |
.instance ⇒ Object
14 15 16 |
# File 'lib/sprockets/es6module.rb', line 14 def self.instance @instance ||= new end |
Instance Method Details
#call(input) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sprockets/es6module.rb', line 37 def call(input) data = Sprockets::ES6.new(blacklist: ['es6.modules', 'useStrict']).call(input) module_name = input[:name] = .merge(amdName: module_name) result = input[:cache].fetch(@cache_key + [, data]) do Esperanto.send(@method, data, ) end result['code'] end |