11import Visitor from './visitor' ;
22
3- function WhitespaceControl ( ) {
3+ function WhitespaceControl ( options = { } ) {
4+ this . options = options ;
45}
56WhitespaceControl . prototype = new Visitor ( ) ;
67
78WhitespaceControl . prototype . Program = function ( program ) {
9+ const doStandalone = ! this . options . ignoreStandalone ;
10+
811 let isRoot = ! this . isRootSeen ;
912 this . isRootSeen = true ;
1013
@@ -31,7 +34,7 @@ WhitespaceControl.prototype.Program = function(program) {
3134 omitLeft ( body , i , true ) ;
3235 }
3336
34- if ( inlineStandalone ) {
37+ if ( doStandalone && inlineStandalone ) {
3538 omitRight ( body , i ) ;
3639
3740 if ( omitLeft ( body , i ) ) {
@@ -42,13 +45,13 @@ WhitespaceControl.prototype.Program = function(program) {
4245 }
4346 }
4447 }
45- if ( openStandalone ) {
48+ if ( doStandalone && openStandalone ) {
4649 omitRight ( ( current . program || current . inverse ) . body ) ;
4750
4851 // Strip out the previous content node if it's whitespace only
4952 omitLeft ( body , i ) ;
5053 }
51- if ( closeStandalone ) {
54+ if ( doStandalone && closeStandalone ) {
5255 // Always strip the next node
5356 omitRight ( body , i ) ;
5457
@@ -106,7 +109,8 @@ WhitespaceControl.prototype.BlockStatement = function(block) {
106109 }
107110
108111 // Find standalone else statments
109- if ( isPrevWhitespace ( program . body )
112+ if ( ! this . options . ignoreStandalone
113+ && isPrevWhitespace ( program . body )
110114 && isNextWhitespace ( firstInverse . body ) ) {
111115 omitLeft ( program . body ) ;
112116 omitRight ( firstInverse . body ) ;
0 commit comments