@@ -209,6 +209,7 @@ pub struct Tokenizer<'a> {
209209 current_line_number : u32 ,
210210 var_functions : SeenStatus ,
211211 viewport_percentages : SeenStatus ,
212+ source_map_url : Option < & ' a str > ,
212213}
213214
214215#[ derive( Copy , Clone , PartialEq , Eq ) ]
@@ -234,6 +235,7 @@ impl<'a> Tokenizer<'a> {
234235 current_line_number : first_line_number,
235236 var_functions : SeenStatus :: DontCare ,
236237 viewport_percentages : SeenStatus :: DontCare ,
238+ source_map_url : None ,
237239 }
238240 }
239241
@@ -300,6 +302,11 @@ impl<'a> Tokenizer<'a> {
300302 }
301303 }
302304
305+ #[ inline]
306+ pub fn current_source_map_url ( & self ) -> Option < & ' a str > {
307+ self . source_map_url
308+ }
309+
303310 #[ inline]
304311 pub fn state ( & self ) -> ParserState {
305312 ParserState {
@@ -507,7 +514,9 @@ fn next_token<'a>(tokenizer: &mut Tokenizer<'a>) -> Result<Token<'a>, ()> {
507514 }
508515 b'/' => {
509516 if tokenizer. starts_with( b"/*" ) {
510- Comment ( consume_comment( tokenizer) )
517+ let contents = consume_comment( tokenizer) ;
518+ check_for_source_map( tokenizer, contents) ;
519+ Comment ( contents)
511520 } else {
512521 tokenizer. advance( 1 ) ;
513522 Delim ( '/' )
@@ -594,6 +603,20 @@ fn consume_whitespace<'a>(tokenizer: &mut Tokenizer<'a>, newline: bool, is_cr: b
594603}
595604
596605
606+ // Check for a sourceMappingURL comment and update the tokenizer appropriately.
607+ fn check_for_source_map < ' a > ( tokenizer : & mut Tokenizer < ' a > , contents : & ' a str ) {
608+ let directive = "# sourceMappingURL=" ;
609+ let directive_old = "@ sourceMappingURL=" ;
610+
611+ // If there is a source map directive, extract the URL.
612+ if contents. starts_with ( directive) || contents. starts_with ( directive_old) {
613+ let contents = & contents[ directive. len ( ) ..] ;
614+ tokenizer. source_map_url = contents. split ( |c| {
615+ c == ' ' || c == '\t' || c == '\x0C' || c == '\r' || c == '\n'
616+ } ) . next ( )
617+ }
618+ }
619+
597620fn consume_comment < ' a > ( tokenizer : & mut Tokenizer < ' a > ) -> & ' a str {
598621 tokenizer. advance ( 2 ) ; // consume "/*"
599622 let start_position = tokenizer. position ( ) ;
0 commit comments