1
1
import Visitor from './visitor' ;
2
2
3
- function WhitespaceControl ( ) {
3
+ function WhitespaceControl ( options = { } ) {
4
+ this . options = options ;
4
5
}
5
6
WhitespaceControl . prototype = new Visitor ( ) ;
6
7
7
8
WhitespaceControl . prototype . Program = function ( program ) {
9
+ const doStandalone = ! this . options . ignoreStandalone ;
10
+
8
11
let isRoot = ! this . isRootSeen ;
9
12
this . isRootSeen = true ;
10
13
@@ -31,7 +34,7 @@ WhitespaceControl.prototype.Program = function(program) {
31
34
omitLeft ( body , i , true ) ;
32
35
}
33
36
34
- if ( inlineStandalone ) {
37
+ if ( doStandalone && inlineStandalone ) {
35
38
omitRight ( body , i ) ;
36
39
37
40
if ( omitLeft ( body , i ) ) {
@@ -42,13 +45,13 @@ WhitespaceControl.prototype.Program = function(program) {
42
45
}
43
46
}
44
47
}
45
- if ( openStandalone ) {
48
+ if ( doStandalone && openStandalone ) {
46
49
omitRight ( ( current . program || current . inverse ) . body ) ;
47
50
48
51
// Strip out the previous content node if it's whitespace only
49
52
omitLeft ( body , i ) ;
50
53
}
51
- if ( closeStandalone ) {
54
+ if ( doStandalone && closeStandalone ) {
52
55
// Always strip the next node
53
56
omitRight ( body , i ) ;
54
57
@@ -106,7 +109,8 @@ WhitespaceControl.prototype.BlockStatement = function(block) {
106
109
}
107
110
108
111
// Find standalone else statments
109
- if ( isPrevWhitespace ( program . body )
112
+ if ( ! this . options . ignoreStandalone
113
+ && isPrevWhitespace ( program . body )
110
114
&& isNextWhitespace ( firstInverse . body ) ) {
111
115
omitLeft ( program . body ) ;
112
116
omitRight ( firstInverse . body ) ;
0 commit comments