@@ -455,24 +455,35 @@ def acceptIf(self, node, memo):
455455 children = node .children
456456 ifStat = self .factory .statement ('if' , fs = FS .lsrc , parent = self )
457457 ifStat .expr .walk (children [0 ], memo )
458- ifBlock = self .factory .methodContent (parent = self )
459- ifBlock .walk (node .children [1 ], memo )
458+ if node .children [1 ].type == tokens .BLOCK_SCOPE :
459+ ifBlock = self .factory .methodContent (parent = self )
460+ ifBlock .walk (node .children [1 ], memo )
461+ elif node .children [1 ].type == tokens .EXPR :
462+ ifBlock = self .factory .expr (parent = ifStat )
463+ ifBlock .walk (node .children [1 ], memo )
460464 if len (children ) == 3 :
461465 nextNode = children [2 ]
462466 nextType = nextNode .type
467+
463468 while nextType == tokens .IF :
464469 nextStat = self .factory .statement ('elif' , fs = FS .lsrc , parent = self )
465470 nextStat .expr .walk (nextNode .children [0 ], memo )
466- nextBlock = self .factory .methodContent (parent = self )
471+ if nextNode .children [1 ].type == tokens .BLOCK_SCOPE :
472+ nextBlock = self .factory .methodContent (parent = self )
473+ else :
474+ nextBlock = self .factory .expr (parent = nextStat )
467475 nextBlock .walk (nextNode .children [1 ], memo )
468- try :
469- nextNode = nextNode .children [2 ]
470- nextType = nextNode .type
471- except (IndexError , ):
472- nextType = None
476+ nextNode = nextNode .children [2 ]
477+ nextType = nextNode .type
478+
473479 if nextType == tokens .BLOCK_SCOPE :
474480 self .factory .statement ('else' , fs = FS .lc , parent = self )
475481 self .factory .methodContent (parent = self ).walk (nextNode , memo )
482+ elif nextType == tokens .EXPR :
483+ elseStat = self .factory .statement ('else' , fs = FS .lc , parent = self )
484+ elseBlock = self .factory .expr (parent = elseStat )
485+ elseBlock .walk (nextNode , memo )
486+
476487
477488 def acceptSwitch (self , node , memo ):
478489 """ Accept and process a switch block. """
0 commit comments