@@ -214,6 +214,7 @@ pub struct Tokenizer<'a> {
214214 /// ensure that computing the column will give the result in units
215215 /// of UTF-16 characters.
216216 current_line_start_position : usize ,
217+ current_position : usize ,
217218 current_line_number : u32 ,
218219 var_or_env_functions : SeenStatus ,
219220 source_map_url : Option < & ' a str > ,
@@ -234,6 +235,7 @@ impl<'a> Tokenizer<'a> {
234235 input,
235236 position : 0 ,
236237 current_line_start_position : 0 ,
238+ current_position : 0 ,
237239 current_line_number : 0 ,
238240 var_or_env_functions : SeenStatus :: DontCare ,
239241 source_map_url : None ,
@@ -296,6 +298,7 @@ impl<'a> Tokenizer<'a> {
296298 ParserState {
297299 position : self . position ,
298300 current_line_start_position : self . current_line_start_position ,
301+ current_position : self . current_position ,
299302 current_line_number : self . current_line_number ,
300303 at_start_of : None ,
301304 }
@@ -305,6 +308,7 @@ impl<'a> Tokenizer<'a> {
305308 pub fn reset ( & mut self , state : & ParserState ) {
306309 self . position = state. position ;
307310 self . current_line_start_position = state. current_line_start_position ;
311+ self . current_position = state. current_position ;
308312 self . current_line_number = state. current_line_number ;
309313 }
310314
@@ -370,6 +374,7 @@ impl<'a> Tokenizer<'a> {
370374 debug_assert ! ( b != b'\r' && b != b'\n' && b != b'\x0C' ) ;
371375 }
372376 }
377+ self . current_position = self . current_position . wrapping_add ( n) ;
373378 self . position += n
374379 }
375380
@@ -392,6 +397,7 @@ impl<'a> Tokenizer<'a> {
392397 // This takes two UTF-16 characters to represent, so we
393398 // actually have an undercount.
394399 self . current_line_start_position = self . current_line_start_position . wrapping_sub ( 1 ) ;
400+ self . current_position = self . current_position . wrapping_add ( 2 ) ;
395401 self . position += 1 ;
396402 }
397403
@@ -417,10 +423,13 @@ impl<'a> Tokenizer<'a> {
417423 // This takes two UTF-16 characters to represent, so we
418424 // actually have an undercount.
419425 self . current_line_start_position = self . current_line_start_position . wrapping_sub ( 1 ) ;
426+ self . current_position = self . current_position . wrapping_add ( 2 ) ;
420427 } else if byte & 0xC0 == 0x80 {
421428 // Note that due to the special case for the 4-byte
422429 // sequence intro, we must use wrapping add here.
423430 self . current_line_start_position = self . current_line_start_position . wrapping_add ( 1 ) ;
431+ } else {
432+ self . current_position = self . current_position . wrapping_add ( 1 ) ;
424433 }
425434 }
426435
@@ -439,8 +448,10 @@ impl<'a> Tokenizer<'a> {
439448 let byte = self . next_byte_unchecked ( ) ;
440449 debug_assert ! ( byte == b'\r' || byte == b'\n' || byte == b'\x0C' ) ;
441450 self . position += 1 ;
451+ self . current_position = self . current_position . wrapping_add ( 1 ) ;
442452 if byte == b'\r' && self . next_byte ( ) == Some ( b'\n' ) {
443453 self . position += 1 ;
454+ self . current_position = self . current_position . wrapping_add ( 1 ) ;
444455 }
445456 self . current_line_start_position = self . position ;
446457 self . current_line_number += 1 ;
@@ -459,9 +470,11 @@ impl<'a> Tokenizer<'a> {
459470 self . position += len_utf8;
460471 // Note that due to the special case for the 4-byte sequence
461472 // intro, we must use wrapping add here.
473+ let len_utf16 = c. len_utf16 ( ) ;
462474 self . current_line_start_position = self
463475 . current_line_start_position
464- . wrapping_add ( len_utf8 - c. len_utf16 ( ) ) ;
476+ . wrapping_add ( len_utf8 - len_utf16) ;
477+ self . current_position = self . current_position . wrapping_add ( len_utf16) ;
465478 c
466479 }
467480
@@ -1151,12 +1164,16 @@ fn consume_unquoted_url<'a>(tokenizer: &mut Tokenizer<'a>) -> Result<Token<'a>,
11511164 }
11521165 } ;
11531166 match_byte ! { b,
1154- b' ' | b'\t' => { } ,
1167+ b' ' | b'\t' => {
1168+ tokenizer. current_position = tokenizer. current_position. wrapping_add( 1 ) ;
1169+ } ,
11551170 b'\n' | b'\x0C' => {
11561171 newlines += 1 ;
11571172 last_newline = offset;
1173+ tokenizer. current_position = tokenizer. current_position. wrapping_add( 1 ) ;
11581174 }
11591175 b'\r' => {
1176+ tokenizer. current_position = tokenizer. current_position. wrapping_add( 1 ) ;
11601177 if from_start. as_bytes( ) . get( offset + 1 ) != Some ( & b'\n' ) {
11611178 newlines += 1 ;
11621179 last_newline = offset;
0 commit comments