File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1043,6 +1043,9 @@ export default class MagicString {
10431043 * Returns true if the resulting source is empty (disregarding white space).
10441044 */
10451045 isEmpty ( ) : boolean {
1046+ // mirrors toString(): the string-level intro and outro bookend the chunks
1047+ if ( this . intro . length && this . intro . trim ( ) )
1048+ return false
10461049 let chunk : Chunk | null = this . firstChunk
10471050 while ( chunk ) {
10481051 if (
@@ -1054,6 +1057,8 @@ export default class MagicString {
10541057 }
10551058 chunk = chunk . next
10561059 }
1060+ if ( this . outro . length && this . outro . trim ( ) )
1061+ return false
10571062 return true
10581063 }
10591064
Original file line number Diff line number Diff line change @@ -1882,6 +1882,22 @@ describe('magicString', () => {
18821882
18831883 assert . equal ( s . isEmpty ( ) , true )
18841884 } )
1885+
1886+ it ( 'should count content appended or prepended to the string' , ( ) => {
1887+ assert . equal ( new MagicString ( '' ) . append ( 'X' ) . isEmpty ( ) , false )
1888+ assert . equal ( new MagicString ( '' ) . prepend ( 'Y' ) . isEmpty ( ) , false )
1889+
1890+ const s = new MagicString ( 'abc' )
1891+ s . remove ( 0 , 3 )
1892+ s . append ( '!' )
1893+ assert . equal ( s . toString ( ) , '!' )
1894+ assert . equal ( s . isEmpty ( ) , false )
1895+ } )
1896+
1897+ it ( 'should still disregard whitespace appended or prepended to the string' , ( ) => {
1898+ const s = new MagicString ( '' ) . prepend ( ' ' ) . append ( ' ' )
1899+ assert . equal ( s . isEmpty ( ) , true )
1900+ } )
18851901 } )
18861902
18871903 describe ( 'length' , ( ) => {
You can’t perform that action at this time.
0 commit comments