@@ -1164,6 +1164,22 @@ describe('magicString', () => {
11641164 assert . throws ( ( ) => s . update ( 0 , 1 , [ ] ) , TypeError )
11651165 } )
11661166
1167+ it ( 'should throw when start is greater than end' , ( ) => {
1168+ const s = new MagicString ( 'problems = 99' )
1169+ assert . throws ( ( ) => s . update ( 9 , 5 , 'x' ) , / e n d m u s t b e g r e a t e r t h a n s t a r t \( s t a r t : 9 , e n d : 5 \) / )
1170+ } )
1171+
1172+ it ( 'should report the resolved indices when a negative start lands past end' , ( ) => {
1173+ const s = new MagicString ( 'problems = 99' )
1174+ // -1 resolves to 12, which is past `end`
1175+ assert . throws ( ( ) => s . update ( - 1 , 5 , 'x' ) , / e n d m u s t b e g r e a t e r t h a n s t a r t \( s t a r t : 1 2 , e n d : 5 \) / )
1176+ } )
1177+
1178+ it ( 'should throw error when using negative indices with empty string' , ( ) => {
1179+ const s = new MagicString ( '' )
1180+ assert . throws ( ( ) => s . update ( - 2 , - 1 , 'x' ) , / C h a r a c t e r i s o u t o f b o u n d s / )
1181+ } )
1182+
11671183 it ( 'replaces interior inserts with overwrite option' , ( ) => {
11681184 const s = new MagicString ( 'abcdefghijkl' )
11691185
@@ -1365,6 +1381,12 @@ describe('magicString', () => {
13651381 const s = new MagicString ( '' )
13661382 assert . throws ( ( ) => s . remove ( - 2 , - 1 ) , / C h a r a c t e r i s o u t o f b o u n d s / )
13671383 } )
1384+
1385+ it ( 'should report the resolved indices when a negative start lands past end' , ( ) => {
1386+ const s = new MagicString ( 'problems = 99' )
1387+ // -1 resolves to 12, which is past `end`
1388+ assert . throws ( ( ) => s . remove ( - 1 , 5 ) , / e n d m u s t b e g r e a t e r t h a n s t a r t \( s t a r t : 1 2 , e n d : 5 \) / )
1389+ } )
13681390 } )
13691391
13701392 describe ( 'reset' , ( ) => {
0 commit comments