@@ -42,6 +42,7 @@ impl CharToByteMapper {
4242 Self { char_to_byte }
4343 }
4444
45+ #[ inline]
4546 fn char_to_byte ( & self , char_offset : u32 ) -> Option < u32 > {
4647 self . char_to_byte . get ( char_offset as usize ) . copied ( )
4748 }
@@ -283,32 +284,28 @@ impl BindingMagicString<'_> {
283284
284285 #[ napi]
285286 pub fn prepend_left < ' s > ( & ' s mut self , this : This < ' s > , index : u32 , content : String ) -> This < ' s > {
286- let byte_index =
287- self . char_to_byte_mapper . char_to_byte ( index) . expect ( "Invalid character index" ) ;
287+ let byte_index = self . char_to_byte_mapper . char_to_byte ( index) . expect ( "Invalid character index" ) ;
288288 self . inner . prepend_left ( byte_index, content) ;
289289 this
290290 }
291291
292292 #[ napi]
293293 pub fn prepend_right < ' s > ( & ' s mut self , this : This < ' s > , index : u32 , content : String ) -> This < ' s > {
294- let byte_index =
295- self . char_to_byte_mapper . char_to_byte ( index) . expect ( "Invalid character index" ) ;
294+ let byte_index = self . char_to_byte_mapper . char_to_byte ( index) . expect ( "Invalid character index" ) ;
296295 self . inner . prepend_right ( byte_index, content) ;
297296 this
298297 }
299298
300299 #[ napi]
301300 pub fn append_left < ' s > ( & ' s mut self , this : This < ' s > , index : u32 , content : String ) -> This < ' s > {
302- let byte_index =
303- self . char_to_byte_mapper . char_to_byte ( index) . expect ( "Invalid character index" ) ;
301+ let byte_index = self . char_to_byte_mapper . char_to_byte ( index) . expect ( "Invalid character index" ) ;
304302 self . inner . append_left ( byte_index, content) ;
305303 this
306304 }
307305
308306 #[ napi]
309307 pub fn append_right < ' s > ( & ' s mut self , this : This < ' s > , index : u32 , content : String ) -> This < ' s > {
310- let byte_index =
311- self . char_to_byte_mapper . char_to_byte ( index) . expect ( "Invalid character index" ) ;
308+ let byte_index = self . char_to_byte_mapper . char_to_byte ( index) . expect ( "Invalid character index" ) ;
312309 self . inner . append_right ( byte_index, content) ;
313310 this
314311 }
@@ -323,8 +320,7 @@ impl BindingMagicString<'_> {
323320 ) -> napi:: Result < This < ' s > > {
324321 let start_byte =
325322 self . char_to_byte_mapper . char_to_byte ( start) . expect ( "Invalid start character index" ) ;
326- let end_byte =
327- self . char_to_byte_mapper . char_to_byte ( end) . expect ( "Invalid end character index" ) ;
323+ let end_byte = self . char_to_byte_mapper . char_to_byte ( end) . expect ( "Invalid end character index" ) ;
328324 self
329325 . inner
330326 . update_with (
@@ -349,10 +345,12 @@ impl BindingMagicString<'_> {
349345 }
350346
351347 #[ napi]
352- #[ expect( clippy:: cast_possible_truncation, reason = "files are < 4GB" ) ]
353348 pub fn length ( & self ) -> u32 {
354349 // MagicString::len() returns usize (length of generated output)
355- self . inner . len ( ) as u32
350+ #[ expect( clippy:: cast_possible_truncation, reason = "files are < 4GB" ) ]
351+ {
352+ self . inner . len ( ) as u32
353+ }
356354 }
357355
358356 #[ napi]
@@ -364,8 +362,7 @@ impl BindingMagicString<'_> {
364362 pub fn remove < ' s > ( & ' s mut self , this : This < ' s > , start : u32 , end : u32 ) -> napi:: Result < This < ' s > > {
365363 let start_byte =
366364 self . char_to_byte_mapper . char_to_byte ( start) . expect ( "Invalid start character index" ) ;
367- let end_byte =
368- self . char_to_byte_mapper . char_to_byte ( end) . expect ( "Invalid end character index" ) ;
365+ let end_byte = self . char_to_byte_mapper . char_to_byte ( end) . expect ( "Invalid end character index" ) ;
369366 self . inner . remove ( start_byte, end_byte) . map_err ( napi:: Error :: from_reason) ?;
370367 Ok ( this)
371368 }
@@ -380,8 +377,7 @@ impl BindingMagicString<'_> {
380377 ) -> napi:: Result < This < ' s > > {
381378 let start_byte =
382379 self . char_to_byte_mapper . char_to_byte ( start) . expect ( "Invalid start character index" ) ;
383- let end_byte =
384- self . char_to_byte_mapper . char_to_byte ( end) . expect ( "Invalid end character index" ) ;
380+ let end_byte = self . char_to_byte_mapper . char_to_byte ( end) . expect ( "Invalid end character index" ) ;
385381 self . inner . update ( start_byte, end_byte, content) . map_err ( napi:: Error :: from_reason) ?;
386382 Ok ( this)
387383 }
@@ -396,10 +392,8 @@ impl BindingMagicString<'_> {
396392 ) -> napi:: Result < This < ' s > > {
397393 let start_byte =
398394 self . char_to_byte_mapper . char_to_byte ( start) . expect ( "Invalid start character index" ) ;
399- let end_byte =
400- self . char_to_byte_mapper . char_to_byte ( end) . expect ( "Invalid end character index" ) ;
401- let to_byte =
402- self . char_to_byte_mapper . char_to_byte ( to) . expect ( "Invalid to character index" ) ;
395+ let end_byte = self . char_to_byte_mapper . char_to_byte ( end) . expect ( "Invalid end character index" ) ;
396+ let to_byte = self . char_to_byte_mapper . char_to_byte ( to) . expect ( "Invalid to character index" ) ;
403397 self . inner . relocate ( start_byte, end_byte, to_byte) . map_err ( napi:: Error :: from_reason) ?;
404398 Ok ( this)
405399 }
@@ -491,8 +485,7 @@ impl BindingMagicString<'_> {
491485 pub fn snip ( & self , start : u32 , end : u32 ) -> napi:: Result < Self > {
492486 let start_byte =
493487 self . char_to_byte_mapper . char_to_byte ( start) . expect ( "Invalid start character index" ) ;
494- let end_byte =
495- self . char_to_byte_mapper . char_to_byte ( end) . expect ( "Invalid end character index" ) ;
488+ let end_byte = self . char_to_byte_mapper . char_to_byte ( end) . expect ( "Invalid end character index" ) ;
496489 Ok ( Self {
497490 inner : self . inner . snip ( start_byte, end_byte) . map_err ( napi:: Error :: from_reason) ?,
498491 char_to_byte_mapper : self . char_to_byte_mapper . clone ( ) ,
@@ -503,22 +496,20 @@ impl BindingMagicString<'_> {
503496 /// This undoes any modifications made to that range.
504497 /// Supports negative indices (counting from the end).
505498 #[ napi]
506- #[ expect(
507- clippy:: cast_sign_loss,
508- clippy:: cast_possible_truncation,
509- reason = "indices are non-negative after normalize_index and files are < 4GB"
510- ) ]
511499 pub fn reset < ' s > ( & ' s mut self , this : This < ' s > , start : i64 , end : i64 ) -> napi:: Result < This < ' s > > {
512500 // Handle negative indices (matching original magic-string behavior)
513501 let start = self . char_to_byte_mapper . normalize_index ( start) ;
514502 let end = self . char_to_byte_mapper . normalize_index ( end) ;
515503
516504 // Convert character indices to byte indices
505+ // indices are non-negative after normalize_index and files are < 4GB
506+ #[ expect( clippy:: cast_sign_loss, clippy:: cast_possible_truncation) ]
517507 let start_byte = self
518508 . char_to_byte_mapper
519509 . char_to_byte ( start as u32 )
520510 . ok_or_else ( || napi:: Error :: from_reason ( "Character is out of bounds" ) ) ?;
521511
512+ #[ expect( clippy:: cast_sign_loss, clippy:: cast_possible_truncation) ]
522513 let end_byte = self
523514 . char_to_byte_mapper
524515 . char_to_byte ( end as u32 )
@@ -531,11 +522,6 @@ impl BindingMagicString<'_> {
531522 /// Returns the content between the specified original character positions.
532523 /// Supports negative indices (counting from the end).
533524 #[ napi]
534- #[ expect(
535- clippy:: cast_sign_loss,
536- clippy:: cast_possible_truncation,
537- reason = "indices are non-negative after normalize_index and files are < 4GB"
538- ) ]
539525 pub fn slice ( & self , start : Option < i64 > , end : Option < i64 > ) -> napi:: Result < String > {
540526 let start = start. unwrap_or ( 0 ) ;
541527
@@ -547,8 +533,12 @@ impl BindingMagicString<'_> {
547533 let end = self . char_to_byte_mapper . normalize_index ( end) ;
548534
549535 // Convert character indices to byte indices
536+ // indices are non-negative after normalize_index and files are < 4GB
537+ #[ expect( clippy:: cast_possible_truncation) ]
550538 let source_len = self . inner . source ( ) . len ( ) as u32 ;
539+ #[ expect( clippy:: cast_sign_loss, clippy:: cast_possible_truncation) ]
551540 let start_byte = self . char_to_byte_mapper . char_to_byte ( start as u32 ) . unwrap_or ( source_len) ;
541+ #[ expect( clippy:: cast_sign_loss, clippy:: cast_possible_truncation) ]
552542 let end_byte = self . char_to_byte_mapper . char_to_byte ( end as u32 ) . unwrap_or ( source_len) ;
553543
554544 self . inner . slice ( start_byte, Some ( end_byte) ) . map_err ( napi:: Error :: from_reason)
0 commit comments