()
| 30 | } |
| 31 | |
| 32 | override execute(): null { |
| 33 | const checkBody = this.tcb.env.config.checkControlFlowBodies; |
| 34 | |
| 35 | // 1. Render try body |
| 36 | const tryBodyScope = this.scope.createChildScope( |
| 37 | this.scope, |
| 38 | null, |
| 39 | checkBody ? this.block.children : [], |
| 40 | null, |
| 41 | ); |
| 42 | const tryBlockStr = `{\n${getStatementsBlock(tryBodyScope.render())}}`; |
| 43 | |
| 44 | // 2. Render catch clause if there are error blocks |
| 45 | if (this.block.errorBlocks.length > 0) { |
| 46 | // Create an inner block where we execute the chain of error branches |
| 47 | const innerCatchStatements = this.generateCatchBranch(0); |
| 48 | const catchBlockStr = `{\n${getStatementsBlock(innerCatchStatements)}}`; |
| 49 | |
| 50 | const tryStatement = new TcbExpr(`try ${tryBlockStr} catch (err) ${catchBlockStr}`); |
| 51 | this.scope.addStatement(tryStatement); |
| 52 | } else { |
| 53 | this.scope.addStatement(new TcbExpr(tryBlockStr)); |
| 54 | } |
| 55 | return null; |
| 56 | } |
| 57 | |
| 58 | private generateCatchBranch(index: number): TcbExpr[] { |
| 59 | const errorBlock = this.block.errorBlocks[index]; |
nothing calls this directly
no test coverage detected