File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -436,7 +436,7 @@ export class Bundle {
436436 if ( this . intro ) {
437437 this . intro
438438 = indentStr
439- + this . intro . replace ( / ^ [ ^ \n ] / gm, ( match , index ) => {
439+ + this . intro . replace ( / ^ [ ^ \r \ n] / gm, ( match , index ) => {
440440 return index > 0 ? indentStr + match : match
441441 } )
442442 }
Original file line number Diff line number Diff line change @@ -514,9 +514,13 @@ export class MagicString {
514514 chunk . intro = indentPiece ( chunk . intro )
515515
516516 if ( chunk . edited ) {
517- if ( ! isExcluded [ charIndex ] ) {
517+ if ( ! isExcluded [ chunk . start ] ) {
518518 chunk . content = indentPiece ( chunk . content )
519519 }
520+ else if ( chunk . content ) {
521+ // excluded content is left as is, but still decides whether what follows starts a line
522+ shouldIndentNextCharacter = chunk . content [ chunk . content . length - 1 ] === '\n'
523+ }
520524 }
521525 else if ( options . exclude ) {
522526 charIndex = chunk . start
Original file line number Diff line number Diff line change @@ -107,5 +107,13 @@ describe('bundle', () => {
107107 const b = new Bundle ( )
108108 assert . strictEqual ( b . indent ( '' ) , b )
109109 } )
110+
111+ it ( 'should not indent the carriage return of a blank CRLF line in the intro' , ( ) => {
112+ const b = new Bundle ( { intro : 'a\r\n\r\nb\n' } )
113+ b . addSource ( new MagicString ( 'x' ) )
114+
115+ b . indent ( ' ' )
116+ assert . equal ( b . toString ( ) , ' a\r\n\r\n b\n x' )
117+ } )
110118 } )
111119} )
Original file line number Diff line number Diff line change @@ -96,6 +96,15 @@ describe('magicString', () => {
9696 assert . equal ( s . toString ( ) , ' abc\n>>def' )
9797 } )
9898
99+ it ( 'should not indent an excluded edited chunk that was moved' , ( ) => {
100+ const s = new MagicString ( 'abc\ndef' )
101+ s . overwrite ( 4 , 7 , 'X\nY' )
102+ s . move ( 4 , 7 , 0 )
103+
104+ s . indent ( ' ' , { exclude : [ [ 4 , 7 ] ] } )
105+ assert . equal ( s . toString ( ) , 'X\nYabc\n' )
106+ } )
107+
99108 it ( 'should not indent excluded edited content' , ( ) => {
100109 const s = new MagicString ( 'abc\ndef\nghi' )
101110 s . overwrite ( 4 , 7 , 'XXX' )
You can’t perform that action at this time.
0 commit comments