-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Custom importers cause out of order chained imports. #1381
Custom importers cause out of order chained imports. #1381
Conversation
Thanks for the test case @nowells. I've taken a quick look into it and it's certainly weird. |
After some digging around the issue appears to be related to peculiar
My guess is this is a bug in how LibSass handles this kind of multiple import syntax. |
With a little more digging it looks like LibSass is changing the order of imports. Multiple imports
Single import
|
@xzyfer the bug is certainly in libsass, when I apply this diff and build my tests pass (but 2 media query tests fail, clearly this is not what we want to do, but wanted to show that the disconnect in the immediate call_importers and deferred to_import handling is what is causing our issue here) diff --git a/src/parser.cpp b/src/parser.cpp
index 8e18e3d..83f4230 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -285,10 +285,12 @@ namespace Sass {
Import* Parser::parse_import()
{
Import* imp = SASS_MEMORY_NEW(ctx.mem, Import, pstate);
- std::vector<std::pair<std::string,Function_Call*>> to_import;
bool first = true;
do {
while (lex< block_comment >());
+
+ std::vector<std::pair<std::string,Function_Call*>> to_import;
+
if (lex< quoted_string >()) {
if (!ctx.call_importers(unquote(std::string(lexed)), path, pstate, imp))
{
@@ -322,6 +324,15 @@ namespace Sass {
if (first) error("@import directive requires a url or quoted path", pstate);
else error("expecting another url or quoted path in @import list", pstate);
}
+
+ for(auto location : to_import) {
+ if (location.second) {
+ imp->urls().push_back(location.second);
+ } else {
+ ctx.import_url(imp, location.first, path);
+ }
+ }
+
first = false;
} while (lex_css< exactly<','> >());
@@ -330,14 +341,6 @@ namespace Sass {
imp->media_queries(media_queries);
}
- for(auto location : to_import) {
- if (location.second) {
- imp->urls().push_back(location.second);
- } else {
- ctx.import_url(imp, location.first, path);
- }
- }
-
return imp;
}
I believe this is because we should really be having |
I came to the same conclusion last night. The correct patch is a little
|
@xzyfer ❤️ 🎆 awesome! Thanks for spending the time to track this down! I look forward to seeing the proper fix so I can learn how to solve this properly myself next time around! |
When using the following syntax with a custom importer ```css @import "foo", "bar"; ``` Paths that are matched by a custom importer get pushed into the queue ahead of those that don't. This means if `bar` is matched by a custom importer the import order will be changed to `"bar", "foo"` instead of the intended `"foo", "bar"`. This can easily break user code. See sass/node-sass#1381 for an example
LibSass PR sass/libsass#1921 |
This test should pass now that #1416 has been merged. |
Custom importers cause out of order chained imports.
I added a failing test case to demonstrate a bug in the current
importers
.This error appears when you have custom
importers
defined, when a file has a chained import where the first import references a file not handled by the custom importer, and the second import is handled by the custom importer, the import order is broken.