@@ -224,7 +224,7 @@ class Stringifier {
224
224
out += this . toSource ( node ) ;
225
225
if ( needCurly ) {
226
226
out += '\n' ;
227
- out += spaces ;
227
+ out += spaces . slice ( 0 , - 2 ) ;
228
228
out += '}' ;
229
229
}
230
230
return out ;
@@ -566,7 +566,10 @@ class Stringifier {
566
566
const { body, directives} = node ;
567
567
const spaces = this . spaces ;
568
568
let out = '' ;
569
- out += ' {' ;
569
+ if ( this . parentType !== 'Program' ) {
570
+ out += ' ' ;
571
+ }
572
+ out += '{' ;
570
573
this . numSpaces ++ ;
571
574
// Handle Directive/DirectiveLiteral like 'use strict';
572
575
if ( directives && directives . length ) {
@@ -575,7 +578,7 @@ class Stringifier {
575
578
}
576
579
out += this . generateTypeChecks ( node ) ;
577
580
if ( body . length ) {
578
- if ( out . length === 2 ) { // 2 is ' {'
581
+ if ( out [ out . length - 1 ] === '{' ) {
579
582
out += '\n' ;
580
583
}
581
584
// out += '/*'+out.length+'*/';
@@ -632,16 +635,26 @@ class Stringifier {
632
635
*/
633
636
IfStatement ( node ) {
634
637
const { alternate, consequent, test} = node ;
635
- const spaces = this . spaces ;
636
638
let out = '' ;
637
- //if (this.parentType !== "IfStatement")
638
- //{
639
- out += spaces ;
640
- //}
639
+ if ( this . forceCurly ) {
640
+ out += this . spaces ;
641
+ } else {
642
+ if ( this . parentType === 'BlockStatement' ) {
643
+ out += this . spaces ;
644
+ } else if ( this . parentType === 'IfStatement' ) {
645
+ out += ' ' ;
646
+ }
647
+ }
641
648
out += `if (${ this . toSource ( test ) } )` ;
642
649
out += this . toSourceCurly ( consequent ) ;
643
650
if ( alternate ) {
651
+ if ( this . forceCurly ) {
652
+ this . numSpaces ++ ;
653
+ }
644
654
out += ` else${ this . toSourceCurly ( alternate ) } ` ;
655
+ if ( this . forceCurly ) {
656
+ this . numSpaces -- ;
657
+ }
645
658
}
646
659
return out ;
647
660
}
0 commit comments