Skip to content

Commit 3af837c

Browse files
committed
Add support for index imports
1 parent b866ad5 commit 3af837c

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/file.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,8 @@ namespace Sass {
324324
// (2) underscore + given
325325
// (3) underscore + given + extension
326326
// (4) given + extension
327+
// (5) given + _index.scss
328+
// (6) given + _index.sass
327329
std::vector<Include> resolve_includes(const std::string& root, const std::string& file, const std::vector<std::string>& exts)
328330
{
329331
std::string filename = join_paths(root, file);
@@ -351,6 +353,25 @@ namespace Sass {
351353
abs_path = join_paths(root, rel_path);
352354
if (file_exists(abs_path)) includes.push_back({{ rel_path, root }, abs_path });
353355
}
356+
// index files
357+
if (includes.size() == 0) {
358+
// ignore directories that look like @import'able filename
359+
for(auto ext : exts) {
360+
if (ends_with(name, ext)) return includes;
361+
}
362+
// next test underscore index exts
363+
for(auto ext : exts) {
364+
rel_path = join_paths(base, join_paths(name, "_index" + ext));
365+
abs_path = join_paths(root, rel_path);
366+
if (file_exists(abs_path)) includes.push_back({{ rel_path, root }, abs_path });
367+
}
368+
// next test plain index exts
369+
for(auto ext : exts) {
370+
rel_path = join_paths(base, join_paths(name, "index" + ext));
371+
abs_path = join_paths(root, rel_path);
372+
if (file_exists(abs_path)) includes.push_back({{ rel_path, root }, abs_path });
373+
}
374+
}
354375
// nothing found
355376
return includes;
356377
}

0 commit comments

Comments
 (0)