@@ -590,38 +590,50 @@ protected override CatchBlock VisitCatchBlock(CatchBlock node)
590590
591591 Expression VisitConditional ( ConditionalExpression node , bool shouldReturn )
592592 {
593- Expression test , ifTrue , ifFalse ;
594593 if ( IsInline ( node ) )
595594 {
596- test = VisitGroup ( node . Test , node . NodeType ) ;
595+ Expression test = VisitGroup ( node . Test , node . NodeType ) ;
597596 Write ( " ? " ) ;
598- ifTrue = VisitGroup ( node . IfTrue , node . NodeType ) ;
597+ Expression ifTrue = VisitGroup ( node . IfTrue , node . NodeType ) ;
599598 Write ( " : " ) ;
600- ifFalse = VisitGroup ( node . IfFalse , node . NodeType ) ;
599+ Expression ifFalse = VisitGroup ( node . IfFalse , node . NodeType ) ;
601600 return node . Update ( test , ifTrue , ifFalse ) ;
602601 }
603602 else
604603 {
604+ return VisitConditionalBlock ( node , shouldReturn ) ;
605+ }
606+ }
607+
608+ Expression VisitConditionalBlock ( ConditionalExpression node , bool shouldReturn , bool chain = false )
609+ {
610+ if ( chain )
611+ WriteNextLine ( "else if (" ) ;
612+ else
605613 WriteNextLine ( "if (" ) ;
606- var position = GetPosition ( ) ;
607- test = Visit ( node . Test ) ;
608- var debug = CreateDebugInfo ( position ) ;
609- Write ( ")" ) ;
610- Indent ( ) ;
611- ifTrue = VisitBody ( node . IfTrue , shouldReturn ) ;
612- Outdent ( ) ;
613- ifFalse = node . IfFalse ;
614- if ( node . Type == typeof ( void ) && node . IfFalse . NodeType != ExpressionType . Default )
614+ var position = GetPosition ( ) ;
615+ Expression test = Visit ( node . Test ) ;
616+ var debug = CreateDebugInfo ( position ) ;
617+ Write ( ")" ) ;
618+ Indent ( ) ;
619+ Expression ifTrue = VisitBody ( node . IfTrue , shouldReturn ) ;
620+ Outdent ( ) ;
621+ Expression ifFalse = node . IfFalse ;
622+ if ( node . Type == typeof ( void ) && node . IfFalse . NodeType != ExpressionType . Default )
623+ {
624+ if ( node . IfFalse . NodeType == ExpressionType . Conditional )
625+ ifFalse = VisitConditionalBlock ( ( ConditionalExpression ) node . IfFalse , shouldReturn , true ) ;
626+ else
615627 {
616628 WriteNextLine ( "else" ) ;
617629 Indent ( ) ;
618630 ifFalse = VisitBody ( node . IfFalse , shouldReturn ) ;
619631 Outdent ( ) ;
620632 }
621- return Expression . Block (
622- debug ,
623- Expression . Condition ( test , ifTrue , ifFalse ) ) ;
624633 }
634+ return Expression . Block (
635+ debug ,
636+ Expression . Condition ( test , ifTrue , ifFalse ) ) ;
625637 }
626638
627639 protected override Expression VisitConditional ( ConditionalExpression node )
0 commit comments