diff --git a/lib/sassc/embedded.rb b/lib/sassc/embedded.rb index 92c4163..d6597bf 100644 --- a/lib/sassc/embedded.rb +++ b/lib/sassc/embedded.rb @@ -315,11 +315,6 @@ def canonicalize(url, context) canonical_url = resolve_file_url(path, parent_path, context.from_import) return unless canonical_url - # Temporarily disable FileImporter optimization - # https://github.com/sass/dart-sass/issues/2208 - # - # @canonical_urls[url] = canonical_url - # return nil @canonical_urls[url] = canonical_url return end diff --git a/test/custom_importer_test.rb b/test/custom_importer_test.rb index dfb556c..1e4ce52 100644 --- a/test/custom_importer_test.rb +++ b/test/custom_importer_test.rb @@ -37,6 +37,16 @@ def imports(_path, parent_path) end end + class ParentDirImporter < Importer + def imports(path, parent_path) + if path.include?('path') + Import.new('path.scss', source: "a { from: #{File.basename(File.dirname(parent_path))}; }") + else + Import.new(path) + end + end + end + def test_custom_importer_works temp_file('styles2.scss', '.hi { color: $var1; }') temp_file('fonts.scss', '.font { color: $var1; }') @@ -87,6 +97,33 @@ def test_custom_importer_works_for_file_in_parent_dir CSS end + # regression test for https://github.com/sass/dart-sass/issues/2208 + def test_custom_importer_works_for_imports_with_same_name + temp_dir('sub1') + temp_dir('sub1/sub2') + temp_file('sub1/test.scss', '@import "path";') + temp_file('sub1/sub2/test.scss', '@import "path";') + + data = <<~SCSS + @import "sub1/test"; + @import "sub1/sub2/test"; + SCSS + + engine = Engine.new(data, { + importer: ParentDirImporter + }) + + assert_equal <<~CSS, engine.render + a { + from: sub1; + } + + a { + from: sub2; + } + CSS + end + def test_dependency_list base = Dir.pwd