Skip to content

Commit

Permalink
Add cache_key to BabelProcessor
Browse files Browse the repository at this point in the history
This ensures the cache will be invalidated if the options are changed.
  • Loading branch information
rmacklin committed Sep 23, 2016
1 parent fb6fcc4 commit 9dfe74c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/sprockets/babel_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ def self.call(input)
instance.call(input)
end

def self.cache_key
instance.cache_key
end

attr_reader :cache_key

def initialize(options = {})
@options = options.merge({
'blacklist' => (options['blacklist'] || []) + ['useStrict'],
Expand Down
11 changes: 11 additions & 0 deletions test/test_babel_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,15 @@ def test_caching_takes_filename_into_account
});
JS
end

def test_cache_key
assert Sprockets::BabelProcessor.cache_key

amd_processor_1 = Sprockets::BabelProcessor.new('modules' => 'amd')
amd_processor_2 = Sprockets::BabelProcessor.new('modules' => 'amd')
assert_equal amd_processor_1.cache_key, amd_processor_2.cache_key

system_processor = Sprockets::BabelProcessor.new('modules' => 'system')
refute_equal amd_processor_1.cache_key, system_processor.cache_key
end
end

0 comments on commit 9dfe74c

Please sign in to comment.