def compile(self): tryBody = Block(self.body, self.parent) catchBody = self.compileCatchStatements() elseBody = Block(self.orelse, self.parent) return helper.cleanBlockString( ''' try { %(body)s } catch(e) { var caughtException = true; } if (!caughtException) { %s } ''' ) % (tryBody, catchBody, elseBody)
def compileCatchStatements(self): catchStatements = [] for handler in self.handlers: body = Block(handler.body, self.parent) exceptionType = handler.type if exceptionType is not None: catch = helper.cleanBlockString( ''' if (e.message === '%s') { %s } ''' ) % (exceptionType, body) else: catch = '%s' % body catchStatements.append(catch) return '\n'.join(catchStatements)