@@ -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
@@ -368,6 +372,7 @@ impl<'a> Tokenizer<'a> {
368372 debug_assert ! ( b != b'\r' && b != b'\n' && b != b'\x0C' ) ;
369373 }
370374 }
375+ self . current_position = self . current_position . wrapping_add ( n) ;
371376 self . position += n
372377 }
373378
@@ -390,6 +395,7 @@ impl<'a> Tokenizer<'a> {
390395 // This takes two UTF-16 characters to represent, so we
391396 // actually have an undercount.
392397 self . current_line_start_position = self . current_line_start_position . wrapping_sub ( 1 ) ;
398+ self . current_position = self . current_position . wrapping_add ( 2 ) ;
393399 self . position += 1 ;
394400 }
395401
@@ -415,10 +421,13 @@ impl<'a> Tokenizer<'a> {
415421 // This takes two UTF-16 characters to represent, so we
416422 // actually have an undercount.
417423 self . current_line_start_position = self . current_line_start_position . wrapping_sub ( 1 ) ;
424+ self . current_position = self . current_position . wrapping_add ( 2 ) ;
418425 } else if byte & 0xC0 == 0x80 {
419426 // Note that due to the special case for the 4-byte
420427 // sequence intro, we must use wrapping add here.
421428 self . current_line_start_position = self . current_line_start_position . wrapping_add ( 1 ) ;
429+ } else {
430+ self . current_position = self . current_position . wrapping_add ( 1 ) ;
422431 }
423432 }
424433
@@ -434,8 +443,10 @@ impl<'a> Tokenizer<'a> {
434443 let byte = self . next_byte_unchecked ( ) ;
435444 debug_assert ! ( byte == b'\r' || byte == b'\n' || byte == b'\x0C' ) ;
436445 self . position += 1 ;
446+ self . current_position = self . current_position . wrapping_add ( 1 ) ;
437447 if byte == b'\r' && self . next_byte ( ) == Some ( b'\n' ) {
438448 self . position += 1 ;
449+ self . current_position = self . current_position . wrapping_add ( 1 ) ;
439450 }
440451 self . current_line_start_position = self . position ;
441452 self . current_line_number += 1 ;
@@ -454,9 +465,11 @@ impl<'a> Tokenizer<'a> {
454465 self . position += len_utf8;
455466 // Note that due to the special case for the 4-byte sequence
456467 // intro, we must use wrapping add here.
468+ let len_utf16 = c. len_utf16 ( ) ;
457469 self . current_line_start_position = self
458470 . current_line_start_position
459- . wrapping_add ( len_utf8 - c. len_utf16 ( ) ) ;
471+ . wrapping_add ( len_utf8 - len_utf16) ;
472+ self . current_position = self . current_position . wrapping_add ( len_utf16) ;
460473 c
461474 }
462475
@@ -1147,12 +1160,16 @@ fn consume_unquoted_url<'a>(tokenizer: &mut Tokenizer<'a>) -> Result<Token<'a>,
11471160 }
11481161 } ;
11491162 match_byte ! { b,
1150- b' ' | b'\t' => { } ,
1163+ b' ' | b'\t' => {
1164+ tokenizer. current_position = tokenizer. current_position. wrapping_add( 1 ) ;
1165+ } ,
11511166 b'\n' | b'\x0C' => {
11521167 newlines += 1 ;
11531168 last_newline = offset;
1169+ tokenizer. current_position = tokenizer. current_position. wrapping_add( 1 ) ;
11541170 }
11551171 b'\r' => {
1172+ tokenizer. current_position = tokenizer. current_position. wrapping_add( 1 ) ;
11561173 if from_start. as_bytes( ) . get( offset + 1 ) != Some ( & b'\n' ) {
11571174 newlines += 1 ;
11581175 last_newline = offset;
0 commit comments