class Sprockets::ES6Module

Constants

MODULE_METHODS
VERSION

Public Class Methods

call(input) click to toggle source
# File lib/sprockets/es6module.rb, line 18
def self.call(input)
  instance.call(input)
end
instance() click to toggle source
# File lib/sprockets/es6module.rb, line 14
def self.instance
  @instance ||= new
end
new(type = :amd, options = {}) click to toggle source
# File lib/sprockets/es6module.rb, line 22
def initialize(type = :amd, options = {})
  @method = MODULE_METHODS[type]

  raise "Unsupported method `#{type}`. Available types are: #{MODULE_METHODS.keys.inspect}" unless @method

  @options = options.dup.merge(strict: false).freeze

  @cache_key = [
    self.class.name,
    Esperanto::VERSION,
    VERSION,
    @method
  ].freeze
end

Public Instance Methods

call(input) click to toggle source
# File lib/sprockets/es6module.rb, line 37
def call(input)
  data = Sprockets::ES6.new(blacklist: ['es6.modules', 'useStrict']).call(input)

  module_name = input[:name]
  options = @options.merge(amdName: module_name)
  result = input[:cache].fetch(@cache_key + [options, data]) do
    Esperanto.send(@method, data, options)
  end
  result['code']
end