@@ -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
@@ -370,6 +374,7 @@ impl<'a> Tokenizer<'a> {
370
374
debug_assert ! ( b != b'\r' && b != b'\n' && b != b'\x0C' ) ;
371
375
}
372
376
}
377
+ self . current_position = self . current_position . wrapping_add ( n) ;
373
378
self . position += n
374
379
}
375
380
@@ -392,6 +397,7 @@ impl<'a> Tokenizer<'a> {
392
397
// This takes two UTF-16 characters to represent, so we
393
398
// actually have an undercount.
394
399
self . current_line_start_position = self . current_line_start_position . wrapping_sub ( 1 ) ;
400
+ self . current_position = self . current_position . wrapping_add ( 2 ) ;
395
401
self . position += 1 ;
396
402
}
397
403
@@ -417,10 +423,13 @@ impl<'a> Tokenizer<'a> {
417
423
// This takes two UTF-16 characters to represent, so we
418
424
// actually have an undercount.
419
425
self . current_line_start_position = self . current_line_start_position . wrapping_sub ( 1 ) ;
426
+ self . current_position = self . current_position . wrapping_add ( 2 ) ;
420
427
} else if byte & 0xC0 == 0x80 {
421
428
// Note that due to the special case for the 4-byte
422
429
// sequence intro, we must use wrapping add here.
423
430
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 ) ;
424
433
}
425
434
}
426
435
@@ -439,8 +448,10 @@ impl<'a> Tokenizer<'a> {
439
448
let byte = self . next_byte_unchecked ( ) ;
440
449
debug_assert ! ( byte == b'\r' || byte == b'\n' || byte == b'\x0C' ) ;
441
450
self . position += 1 ;
451
+ self . current_position = self . current_position . wrapping_add ( 1 ) ;
442
452
if byte == b'\r' && self . next_byte ( ) == Some ( b'\n' ) {
443
453
self . position += 1 ;
454
+ self . current_position = self . current_position . wrapping_add ( 1 ) ;
444
455
}
445
456
self . current_line_start_position = self . position ;
446
457
self . current_line_number += 1 ;
@@ -459,9 +470,11 @@ impl<'a> Tokenizer<'a> {
459
470
self . position += len_utf8;
460
471
// Note that due to the special case for the 4-byte sequence
461
472
// intro, we must use wrapping add here.
473
+ let len_utf16 = c. len_utf16 ( ) ;
462
474
self . current_line_start_position = self
463
475
. 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) ;
465
478
c
466
479
}
467
480
@@ -1151,12 +1164,16 @@ fn consume_unquoted_url<'a>(tokenizer: &mut Tokenizer<'a>) -> Result<Token<'a>,
1151
1164
}
1152
1165
} ;
1153
1166
match_byte ! { b,
1154
- b' ' | b'\t' => { } ,
1167
+ b' ' | b'\t' => {
1168
+ tokenizer. current_position = tokenizer. current_position. wrapping_add( 1 ) ;
1169
+ } ,
1155
1170
b'\n' | b'\x0C' => {
1156
1171
newlines += 1 ;
1157
1172
last_newline = offset;
1173
+ tokenizer. current_position = tokenizer. current_position. wrapping_add( 1 ) ;
1158
1174
}
1159
1175
b'\r' => {
1176
+ tokenizer. current_position = tokenizer. current_position. wrapping_add( 1 ) ;
1160
1177
if from_start. as_bytes( ) . get( offset + 1 ) != Some ( & b'\n' ) {
1161
1178
newlines += 1 ;
1162
1179
last_newline = offset;
0 commit comments