@@ -269,9 +269,8 @@ class ReplaceSource extends Source {
269
269
}
270
270
271
271
// Insert replacement content splitted into chunks by lines
272
- const regexp = / [ ^ \n ] + \n ? | \n / g;
273
272
const { content, name } = repls [ i ] ;
274
- let match = regexp . exec ( content ) ;
273
+ let matches = splitIntoLines ( content ) ;
275
274
let replacementNameIndex = nameIndex ;
276
275
if ( sourceIndex >= 0 && name ) {
277
276
let globalIndex = nameMapping . get ( name ) ;
@@ -282,8 +281,8 @@ class ReplaceSource extends Source {
282
281
}
283
282
replacementNameIndex = globalIndex ;
284
283
}
285
- while ( match !== null ) {
286
- const contentLine = match [ 0 ] ;
284
+ for ( let m = 0 ; m < matches . length ; m ++ ) {
285
+ const contentLine = matches [ m ] ;
287
286
onChunk (
288
287
contentLine ,
289
288
line ,
@@ -300,8 +299,7 @@ class ReplaceSource extends Source {
300
299
// Only the first chunk has name assigned
301
300
replacementNameIndex = - 1 ;
302
301
303
- match = regexp . exec ( content ) ;
304
- if ( match === null && ! contentLine . endsWith ( "\n" ) ) {
302
+ if ( m === matches . length - 1 && ! contentLine . endsWith ( "\n" ) ) {
305
303
if ( generatedColumnOffsetLine === line ) {
306
304
generatedColumnOffset += contentLine . length ;
307
305
} else {
@@ -418,10 +416,9 @@ class ReplaceSource extends Source {
418
416
419
417
// Insert remaining replacements content splitted into chunks by lines
420
418
let line = generatedLine + generatedLineOffset ;
421
- const regexp = / [ ^ \n ] + \n ? | \n / g;
422
- let match = regexp . exec ( remainer ) ;
423
- while ( match !== null ) {
424
- const contentLine = match [ 0 ] ;
419
+ let matches = splitIntoLines ( remainer ) ;
420
+ for ( let m = 0 ; m < matches . length ; m ++ ) {
421
+ const contentLine = matches [ m ] ;
425
422
onChunk (
426
423
contentLine ,
427
424
line ,
@@ -433,8 +430,7 @@ class ReplaceSource extends Source {
433
430
- 1
434
431
) ;
435
432
436
- match = regexp . exec ( remainer ) ;
437
- if ( match === null && ! contentLine . endsWith ( "\n" ) ) {
433
+ if ( m === matches . length - 1 && ! contentLine . endsWith ( "\n" ) ) {
438
434
if ( generatedColumnOffsetLine === line ) {
439
435
generatedColumnOffset += contentLine . length ;
440
436
} else {
0 commit comments