From 9dfe74c15b68090941efdfeba8a1f0711aa0a8c7 Mon Sep 17 00:00:00 2001 From: Richard Macklin Date: Fri, 23 Sep 2016 01:00:05 -0700 Subject: [PATCH] Add cache_key to BabelProcessor This ensures the cache will be invalidated if the options are changed. --- lib/sprockets/babel_processor.rb | 6 ++++++ test/test_babel_processor.rb | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/sprockets/babel_processor.rb b/lib/sprockets/babel_processor.rb index c0c140831..e3bebc959 100644 --- a/lib/sprockets/babel_processor.rb +++ b/lib/sprockets/babel_processor.rb @@ -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'], diff --git a/test/test_babel_processor.rb b/test/test_babel_processor.rb index 7277e35ec..4d8f72442 100644 --- a/test/test_babel_processor.rb +++ b/test/test_babel_processor.rb @@ -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