@@ -240,6 +240,8 @@ namespace Sass {
240240 if (char * contents = read_file (resolved)) {
241241 add_source (path, resolved, contents);
242242 style_sheets[path] = 0 ;
243+ size_t i = queue.size () - 1 ;
244+ process_queue_entry (queue[i], i);
243245 return path;
244246 }
245247 return std::string (" " );
@@ -268,6 +270,8 @@ namespace Sass {
268270 if (char * contents = read_file (resolved[0 ].abs_path )) {
269271 add_source (base_file, resolved[0 ].abs_path , contents);
270272 style_sheets[base_file] = 0 ;
273+ size_t i = queue.size () - 1 ;
274+ process_queue_entry (queue[i], i);
271275 return base_file;
272276 }
273277 }
@@ -300,28 +304,34 @@ namespace Sass {
300304 return sass_strdup (output.c_str ());
301305 }
302306
307+ void Context::process_queue_entry (Sass_Queued& entry, size_t i)
308+ {
309+ if (style_sheets[queue[i].load_path ]) return ;
310+ Sass_Import_Entry import = sass_make_import (
311+ queue[i].load_path .c_str (),
312+ queue[i].abs_path .c_str (),
313+ 0 , 0
314+ );
315+ import_stack.push_back (import );
316+ // keep a copy of the path around (for parser states)
317+ strings.push_back (sass_strdup (queue[i].abs_path .c_str ()));
318+ ParserState pstate (strings.back (), queue[i].source , i);
319+ Parser p (Parser::from_c_str (queue[i].source , *this , pstate));
320+ Block* ast = p.parse ();
321+ sass_delete_import (import_stack.back ());
322+ import_stack.pop_back ();
323+ // ToDo: we store by load_path, which can lead
324+ // to duplicates if importer reports the same path
325+ // Maybe we should add an error for duplicates!?
326+ style_sheets[queue[i].load_path ] = ast;
327+ }
328+
303329 Block* Context::parse_file ()
304330 {
305331 Block* root = 0 ;
306332 for (size_t i = 0 ; i < queue.size (); ++i) {
307- Sass_Import_Entry import = sass_make_import (
308- queue[i].load_path .c_str (),
309- queue[i].abs_path .c_str (),
310- 0 , 0
311- );
312- import_stack.push_back (import );
313- // keep a copy of the path around (for parser states)
314- strings.push_back (sass_strdup (queue[i].abs_path .c_str ()));
315- ParserState pstate (strings.back (), queue[i].source , i);
316- Parser p (Parser::from_c_str (queue[i].source , *this , pstate));
317- Block* ast = p.parse ();
318- sass_delete_import (import_stack.back ());
319- import_stack.pop_back ();
320- if (i == 0 ) root = ast;
321- // ToDo: we store by load_path, which can lead
322- // to duplicates if importer reports the same path
323- // Maybe we should add an error for duplicates!?
324- style_sheets[queue[i].load_path ] = ast;
333+ process_queue_entry (queue[i], i);
334+ if (i == 0 ) root = style_sheets[queue[i].load_path ];
325335 }
326336 if (root == 0 ) return 0 ;
327337
@@ -368,6 +378,8 @@ namespace Sass {
368378 return parse_file ();
369379 }
370380 add_source (input_path, input_path, source_c_str);
381+ size_t idx = queue.size () - 1 ;
382+ process_queue_entry (queue[idx], idx);
371383 return parse_file ();
372384 }
373385
0 commit comments