@@ -4,6 +4,7 @@ import { printSeparatedItem } from '../slang-printers/print-separated-item.js';
44import { printIndentedGroupOrSpacedDocument } from '../slang-printers/print-indented-group-or-spaced-document.js' ;
55import { isBlockComment } from '../slang-utils/is-comment.js' ;
66import { printVariant } from '../slang-printers/print-variant.js' ;
7+ import { extractVariant } from '../slang-utils/extract-variant.js' ;
78import { SlangNode } from './SlangNode.js' ;
89import { Expression } from './Expression.js' ;
910import { Statement } from './Statement.js' ;
@@ -21,15 +22,15 @@ export class IfStatement extends SlangNode {
2122
2223 condition : Expression ;
2324
24- body : Statement ;
25+ body : Statement [ 'variant' ] ;
2526
2627 elseBranch ?: ElseBranch ;
2728
2829 constructor ( ast : ast . IfStatement , options : ParserOptions < AstNode > ) {
2930 super ( ast ) ;
3031
3132 this . condition = new Expression ( ast . condition , options ) ;
32- this . body = new Statement ( ast . body , options ) ;
33+ this . body = extractVariant ( new Statement ( ast . body , options ) ) ;
3334 if ( ast . elseBranch ) {
3435 this . elseBranch = new ElseBranch ( ast . elseBranch , options ) ;
3536 }
@@ -38,13 +39,13 @@ export class IfStatement extends SlangNode {
3839 }
3940
4041 print ( path : AstPath < IfStatement > , print : PrintFunction ) : Doc {
41- const { kind : bodyKind , comments : bodyComments } = this . body . variant ;
42+ const { kind : bodyKind , comments : bodyComments } = this . body ;
4243 return [
4344 'if (' ,
4445 printSeparatedItem ( path . call ( printVariant ( print ) , 'condition' ) ) ,
4546 ')' ,
4647 printIndentedGroupOrSpacedDocument (
47- path . call ( printVariant ( print ) , 'body' ) ,
48+ path . call ( print , 'body' ) ,
4849 bodyKind !== NonterminalKind . Block ,
4950 // `if` within `if`
5051 { shouldBreak : bodyKind === NonterminalKind . IfStatement }
0 commit comments