@@ -214,6 +214,7 @@ pub struct Tokenizer<'a> {
214
214
/// ensure that computing the column will give the result in units
215
215
/// of UTF-16 characters.
216
216
current_line_start_position : usize ,
217
+ current_position : usize ,
217
218
current_line_number : u32 ,
218
219
var_or_env_functions : SeenStatus ,
219
220
source_map_url : Option < & ' a str > ,
@@ -234,6 +235,7 @@ impl<'a> Tokenizer<'a> {
234
235
input,
235
236
position : 0 ,
236
237
current_line_start_position : 0 ,
238
+ current_position : 0 ,
237
239
current_line_number : 0 ,
238
240
var_or_env_functions : SeenStatus :: DontCare ,
239
241
source_map_url : None ,
@@ -296,6 +298,7 @@ impl<'a> Tokenizer<'a> {
296
298
ParserState {
297
299
position : self . position ,
298
300
current_line_start_position : self . current_line_start_position ,
301
+ current_position : self . current_position ,
299
302
current_line_number : self . current_line_number ,
300
303
at_start_of : None ,
301
304
}
@@ -305,6 +308,7 @@ impl<'a> Tokenizer<'a> {
305
308
pub fn reset ( & mut self , state : & ParserState ) {
306
309
self . position = state. position ;
307
310
self . current_line_start_position = state. current_line_start_position ;
311
+ self . current_position = state. current_position ;
308
312
self . current_line_number = state. current_line_number ;
309
313
}
310
314
@@ -368,6 +372,7 @@ impl<'a> Tokenizer<'a> {
368
372
debug_assert ! ( b != b'\r' && b != b'\n' && b != b'\x0C' ) ;
369
373
}
370
374
}
375
+ self . current_position = self . current_position . wrapping_add ( n) ;
371
376
self . position += n
372
377
}
373
378
@@ -390,6 +395,7 @@ impl<'a> Tokenizer<'a> {
390
395
// This takes two UTF-16 characters to represent, so we
391
396
// actually have an undercount.
392
397
self . current_line_start_position = self . current_line_start_position . wrapping_sub ( 1 ) ;
398
+ self . current_position = self . current_position . wrapping_add ( 2 ) ;
393
399
self . position += 1 ;
394
400
}
395
401
@@ -415,10 +421,13 @@ impl<'a> Tokenizer<'a> {
415
421
// This takes two UTF-16 characters to represent, so we
416
422
// actually have an undercount.
417
423
self . current_line_start_position = self . current_line_start_position . wrapping_sub ( 1 ) ;
424
+ self . current_position = self . current_position . wrapping_add ( 2 ) ;
418
425
} else if byte & 0xC0 == 0x80 {
419
426
// Note that due to the special case for the 4-byte
420
427
// sequence intro, we must use wrapping add here.
421
428
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 ) ;
422
431
}
423
432
}
424
433
@@ -434,8 +443,10 @@ impl<'a> Tokenizer<'a> {
434
443
let byte = self . next_byte_unchecked ( ) ;
435
444
debug_assert ! ( byte == b'\r' || byte == b'\n' || byte == b'\x0C' ) ;
436
445
self . position += 1 ;
446
+ self . current_position = self . current_position . wrapping_add ( 1 ) ;
437
447
if byte == b'\r' && self . next_byte ( ) == Some ( b'\n' ) {
438
448
self . position += 1 ;
449
+ self . current_position = self . current_position . wrapping_add ( 1 ) ;
439
450
}
440
451
self . current_line_start_position = self . position ;
441
452
self . current_line_number += 1 ;
@@ -454,9 +465,11 @@ impl<'a> Tokenizer<'a> {
454
465
self . position += len_utf8;
455
466
// Note that due to the special case for the 4-byte sequence
456
467
// intro, we must use wrapping add here.
468
+ let len_utf16 = c. len_utf16 ( ) ;
457
469
self . current_line_start_position = self
458
470
. 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) ;
460
473
c
461
474
}
462
475
@@ -1147,12 +1160,16 @@ fn consume_unquoted_url<'a>(tokenizer: &mut Tokenizer<'a>) -> Result<Token<'a>,
1147
1160
}
1148
1161
} ;
1149
1162
match_byte ! { b,
1150
- b' ' | b'\t' => { } ,
1163
+ b' ' | b'\t' => {
1164
+ tokenizer. current_position = tokenizer. current_position. wrapping_add( 1 ) ;
1165
+ } ,
1151
1166
b'\n' | b'\x0C' => {
1152
1167
newlines += 1 ;
1153
1168
last_newline = offset;
1169
+ tokenizer. current_position = tokenizer. current_position. wrapping_add( 1 ) ;
1154
1170
}
1155
1171
b'\r' => {
1172
+ tokenizer. current_position = tokenizer. current_position. wrapping_add( 1 ) ;
1156
1173
if from_start. as_bytes( ) . get( offset + 1 ) != Some ( & b'\n' ) {
1157
1174
newlines += 1 ;
1158
1175
last_newline = offset;
0 commit comments