@@ -360,8 +360,10 @@ export default class MagicString {
360360 update ( start , end , content , options ) {
361361 if ( typeof content !== 'string' ) throw new TypeError ( 'replacement content must be a string' ) ;
362362
363- while ( start < 0 ) start += this . original . length ;
364- while ( end < 0 ) end += this . original . length ;
363+ if ( this . original . length !== 0 ) {
364+ while ( start < 0 ) start += this . original . length ;
365+ while ( end < 0 ) end += this . original . length ;
366+ }
365367
366368 if ( end > this . original . length ) throw new Error ( 'end is out of bounds' ) ;
367369 if ( start === end )
@@ -469,8 +471,10 @@ export default class MagicString {
469471 }
470472
471473 remove ( start , end ) {
472- while ( start < 0 ) start += this . original . length ;
473- while ( end < 0 ) end += this . original . length ;
474+ if ( this . original . length !== 0 ) {
475+ while ( start < 0 ) start += this . original . length ;
476+ while ( end < 0 ) end += this . original . length ;
477+ }
474478
475479 if ( start === end ) return this ;
476480
@@ -497,8 +501,10 @@ export default class MagicString {
497501 }
498502
499503 reset ( start , end ) {
500- while ( start < 0 ) start += this . original . length ;
501- while ( end < 0 ) end += this . original . length ;
504+ if ( this . original . length !== 0 ) {
505+ while ( start < 0 ) start += this . original . length ;
506+ while ( end < 0 ) end += this . original . length ;
507+ }
502508
503509 if ( start === end ) return this ;
504510
@@ -564,8 +570,10 @@ export default class MagicString {
564570 }
565571
566572 slice ( start = 0 , end = this . original . length ) {
567- while ( start < 0 ) start += this . original . length ;
568- while ( end < 0 ) end += this . original . length ;
573+ if ( this . original . length !== 0 ) {
574+ while ( start < 0 ) start += this . original . length ;
575+ while ( end < 0 ) end += this . original . length ;
576+ }
569577
570578 let result = '' ;
571579
0 commit comments