* statement => function () { catchAndReturnErrors(return statement); } * statement; statement => function () { catchAndReturnErrors(statement; return statement); }
( parameterNames: ReadonlyArray<string>, statements: ReadonlyArray<Statement>, preserveThis: boolean, catchAndReturnErrors: boolean, )
| 202 | * statement; statement => function () { catchAndReturnErrors(statement; return statement); } |
| 203 | */ |
| 204 | function statementToFunction( |
| 205 | parameterNames: ReadonlyArray<string>, |
| 206 | statements: ReadonlyArray<Statement>, |
| 207 | preserveThis: boolean, |
| 208 | catchAndReturnErrors: boolean, |
| 209 | ) { |
| 210 | const last = statements[statements.length - 1]; |
| 211 | if (last.type !== 'ReturnStatement') { |
| 212 | const expr = statementToExpression(last); |
| 213 | if (expr) { |
| 214 | statements = [...statements.slice(0, -1), { type: 'ReturnStatement', argument: expr }]; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | return codeToFunctionExecutingCode( |
| 219 | parameterNames, |
| 220 | statements, |
| 221 | preserveThis, |
| 222 | catchAndReturnErrors, |
| 223 | ); |
| 224 | } |
| 225 | |
| 226 | export function statementToExpression(stmt: Statement): Expression | undefined { |
| 227 | switch (stmt.type) { |
no test coverage detected