@@ -179,6 +179,20 @@ namespace Sass {
179179
180180 }
181181
182+ void Parser::import_single_file (Import* imp, string import_path) {
183+
184+ if (!unquote (import_path).substr (0 , 7 ).compare (" http://" ) ||
185+ !unquote (import_path).substr (0 , 8 ).compare (" https://" ) ||
186+ !unquote (import_path).substr (0 , 2 ).compare (" //" ))
187+ {
188+ imp->urls ().push_back (new (ctx.mem ) String_Quoted (pstate, import_path));
189+ }
190+ else {
191+ add_single_file (imp, import_path);
192+ }
193+
194+ }
195+
182196 Import* Parser::parse_import ()
183197 {
184198 lex< kwd_import >();
@@ -188,21 +202,18 @@ namespace Sass {
188202 while (lex< block_comment >());
189203 if (lex< quoted_string >()) {
190204 string import_path (lexed);
191-
192- // struct Sass_Options opt = sass_context_get_options(ctx)
193- Sass_C_Import_Callback importer = ctx.importer ;
194- // custom importer
195- if (importer) {
196- Sass_Import* current = ctx.import_stack .back ();
197- Sass_C_Import_Fn fn = sass_import_get_function (importer);
198- void * cookie = sass_import_get_cookie (importer);
199- // create a new import entry
200- string inc_path = unquote (import_path);
201- struct Sass_Import ** includes = fn (
202- inc_path.c_str (),
203- sass_import_get_path (current),
204- cookie);
205- if (includes) {
205+ bool has_custom_import = false ;
206+ Sass_Import* current = ctx.import_stack .back ();
207+ const char * cur_path = sass_import_get_path (current);
208+ string load_path = unquote (import_path);
209+ for (auto importer : ctx.c_importers ) {
210+ if (has_custom_import) break ;
211+ Sass_C_Importer fn = sass_importer_get_function (importer);
212+ // int priority = sass_importer_get_priority(importer);
213+ void * cookie = sass_importer_get_cookie (importer);
214+ if (struct Sass_Import ** includes =
215+ fn (load_path.c_str (), cur_path, cookie)
216+ ) {
206217 struct Sass_Import ** list = includes;
207218 while (*includes) {
208219 struct Sass_Import * include = *includes;
@@ -211,38 +222,32 @@ namespace Sass {
211222 size_t line = sass_import_get_error_line (include);
212223 size_t column = sass_import_get_error_column (include);
213224 const char * message = sass_import_get_error_message (include);
214- // char *srcmap = sass_import_take_srcmap(include);
215225 if (message) {
216226 if (line == string::npos && column == string::npos) error (message, pstate);
217227 else error (message, ParserState (message, source, Position (line, column)));
218228 } else if (source) {
219229 if (file) {
220- ctx.add_source (file, inc_path , source);
230+ ctx.add_source (file, load_path , source);
221231 imp->files ().push_back (file);
222232 } else {
223- ctx.add_source (inc_path, inc_path , source);
224- imp->files ().push_back (inc_path );
233+ ctx.add_source (load_path, load_path , source);
234+ imp->files ().push_back (load_path );
225235 }
226236 } else if (file) {
227- add_single_file (imp, file);
237+ import_single_file (imp, file);
228238 }
229239 ++includes;
230240 }
231241 // deallocate returned memory
232242 sass_delete_import_list (list);
233- // parse next import
234- continue ;
243+ // break import chain
244+ has_custom_import = true ;
235245 }
236246 }
237247
238- if (!unquote (import_path).substr (0 , 7 ).compare (" http://" ) ||
239- !unquote (import_path).substr (0 , 8 ).compare (" https://" ) ||
240- !unquote (import_path).substr (0 , 2 ).compare (" //" ))
241- {
242- imp->urls ().push_back (new (ctx.mem ) String_Quoted (pstate, import_path));
243- }
244- else {
245- add_single_file (imp, import_path);
248+ if (!has_custom_import) {
249+ // push single file import
250+ import_single_file (imp, import_path);
246251 }
247252
248253 }
0 commit comments