@@ -429,11 +429,7 @@ impl<'a> Lexer<'a> {
429
429
/// Read an escaped character for string literal.
430
430
///
431
431
/// In template literal, we should preserve raw string.
432
- fn read_escaped_char (
433
- & mut self ,
434
- raw : & mut Raw ,
435
- in_template : bool ,
436
- ) -> LexResult < Option < Vec < Char > > > {
432
+ fn read_escaped_char ( & mut self , in_template : bool ) -> LexResult < Option < Vec < Char > > > {
437
433
debug_assert_eq ! ( self . cur( ) , Some ( '\\' ) ) ;
438
434
439
435
let start = self . cur_pos ( ) ;
@@ -447,7 +443,6 @@ impl<'a> Lexer<'a> {
447
443
448
444
macro_rules! push_c_and_ret {
449
445
( $c: expr) => { {
450
- raw. push( c) ;
451
446
$c
452
447
} } ;
453
448
}
@@ -461,35 +456,23 @@ impl<'a> Lexer<'a> {
461
456
'v' => push_c_and_ret ! ( '\u{000b}' ) ,
462
457
'f' => push_c_and_ret ! ( '\u{000c}' ) ,
463
458
'\r' => {
464
- raw. push_str ( "\r " ) ;
465
-
466
459
self . bump ( ) ; // remove '\r'
467
460
468
- if self . eat ( b'\n' ) {
469
- raw. push_str ( "\n " ) ;
470
- }
461
+ self . eat ( b'\n' ) ;
471
462
472
463
return Ok ( None ) ;
473
464
}
474
465
'\n' | '\u{2028}' | '\u{2029}' => {
475
- match c {
476
- '\n' => raw. push_str ( "\n " ) ,
477
- '\u{2028}' => raw. push_str ( "\u{2028} " ) ,
478
- '\u{2029}' => raw. push_str ( "\u{2029} " ) ,
479
- _ => unreachable ! ( ) ,
480
- }
481
466
self . bump ( ) ;
482
467
483
468
return Ok ( None ) ;
484
469
}
485
470
486
471
// read hexadecimal escape sequences
487
472
'x' => {
488
- raw. push_str ( "x" ) ;
489
-
490
473
self . bump ( ) ; // 'x'
491
474
492
- match self . read_int_u32 :: < 16 > ( 2 , raw ) ? {
475
+ match self . read_int_u32 :: < 16 > ( 2 , & mut Raw ( None ) ) ? {
493
476
Some ( val) => return Ok ( Some ( vec ! [ Char :: from( val) ] ) ) ,
494
477
None => self . error (
495
478
start,
@@ -501,15 +484,13 @@ impl<'a> Lexer<'a> {
501
484
}
502
485
503
486
// read unicode escape sequences
504
- 'u' => match self . read_unicode_escape ( raw ) {
487
+ 'u' => match self . read_unicode_escape ( ) {
505
488
Ok ( chars) => return Ok ( Some ( chars) ) ,
506
489
Err ( err) => self . error ( start, err. into_kind ( ) ) ?,
507
490
} ,
508
491
509
492
// octal escape sequences
510
493
'0' ..='7' => {
511
- raw. push ( c) ;
512
-
513
494
self . bump ( ) ;
514
495
515
496
let first_c = if c == '0' {
@@ -550,7 +531,6 @@ impl<'a> Lexer<'a> {
550
531
} ;
551
532
552
533
self . bump( ) ;
553
- raw. push( cur. unwrap( ) ) ;
554
534
}
555
535
_ => return Ok ( Some ( vec![ Char :: from( value as u32 ) ] ) ) ,
556
536
}
@@ -562,10 +542,7 @@ impl<'a> Lexer<'a> {
562
542
563
543
return Ok ( Some ( vec ! [ Char :: from( value as char ) ] ) ) ;
564
544
}
565
- _ => {
566
- raw. push ( c) ;
567
- c
568
- }
545
+ _ => c,
569
546
} ;
570
547
571
548
unsafe {
@@ -860,7 +837,7 @@ impl<'a> Lexer<'a> {
860
837
861
838
has_escape = true ;
862
839
863
- let chars = l. read_unicode_escape ( & mut Raw ( None ) ) ?;
840
+ let chars = l. read_unicode_escape ( ) ?;
864
841
865
842
if let Some ( c) = chars. first ( ) {
866
843
let valid = if first {
@@ -890,24 +867,20 @@ impl<'a> Lexer<'a> {
890
867
} )
891
868
}
892
869
893
- fn read_unicode_escape ( & mut self , raw : & mut Raw ) -> LexResult < Vec < Char > > {
870
+ fn read_unicode_escape ( & mut self ) -> LexResult < Vec < Char > > {
894
871
debug_assert_eq ! ( self . cur( ) , Some ( 'u' ) ) ;
895
872
896
873
let mut chars = vec ! [ ] ;
897
874
let mut is_curly = false ;
898
875
899
876
self . bump ( ) ; // 'u'
900
877
901
- raw. push_str ( "u" ) ;
902
-
903
878
if self . eat ( b'{' ) {
904
879
is_curly = true ;
905
-
906
- raw. push ( '{' ) ;
907
880
}
908
881
909
882
let state = self . input . cur_pos ( ) ;
910
- let c = match self . read_int_u32 :: < 16 > ( if is_curly { 0 } else { 4 } , raw ) {
883
+ let c = match self . read_int_u32 :: < 16 > ( if is_curly { 0 } else { 4 } , & mut Raw ( None ) ) {
911
884
Ok ( Some ( val) ) => {
912
885
if 0x0010_ffff >= val {
913
886
char:: from_u32 ( val)
@@ -985,12 +958,8 @@ impl<'a> Lexer<'a> {
985
958
}
986
959
}
987
960
988
- if is_curly {
989
- if !self . eat ( b'}' ) {
990
- self . error ( state, SyntaxError :: InvalidUnicodeEscape ) ?
991
- }
992
-
993
- raw. push ( '}' ) ;
961
+ if is_curly && !self . eat ( b'}' ) {
962
+ self . error ( state, SyntaxError :: InvalidUnicodeEscape ) ?
994
963
}
995
964
996
965
Ok ( chars)
@@ -1033,9 +1002,7 @@ impl<'a> Lexer<'a> {
1033
1002
} ) ;
1034
1003
}
1035
1004
'\\' => {
1036
- let mut wrapped = Raw ( Some ( Default :: default ( ) ) ) ;
1037
-
1038
- if let Some ( chars) = l. read_escaped_char ( & mut wrapped, false ) ? {
1005
+ if let Some ( chars) = l. read_escaped_char ( false ) ? {
1039
1006
for c in chars {
1040
1007
out. extend ( c) ;
1041
1008
}
@@ -1208,9 +1175,7 @@ impl<'a> Lexer<'a> {
1208
1175
if c == '\\' {
1209
1176
consume_cooked ! ( ) ;
1210
1177
1211
- let mut wrapped = Raw ( None ) ;
1212
-
1213
- match self . read_escaped_char ( & mut wrapped, true ) {
1178
+ match self . read_escaped_char ( true ) {
1214
1179
Ok ( Some ( chars) ) => {
1215
1180
if let Ok ( ref mut cooked) = cooked {
1216
1181
for c in chars {
0 commit comments