Skip to content

Commit

Permalink
Add regression test for sass/dart-sass#2208
Browse files Browse the repository at this point in the history
  • Loading branch information
ntkme committed Apr 4, 2024
1 parent 16c375c commit bb85b47
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
5 changes: 0 additions & 5 deletions lib/sassc/embedded.rb
Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions test/custom_importer_test.rb
Expand Up @@ -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; }')
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit bb85b47

Please sign in to comment.