(node: ts.FunctionExpression | ts.ArrowFunction)
| 464 | } |
| 465 | |
| 466 | parseFunctionExpression(node: ts.FunctionExpression | ts.ArrowFunction): syntax.FunctionExpression { |
| 467 | const {body, parameters, modifiers, asteriskToken, exclamationToken, questionToken, typeParameters} = node; |
| 468 | if (asteriskToken) |
| 469 | throw new UnimplementedError(node, 'Generator is not supported'); |
| 470 | if (questionToken) |
| 471 | throw new UnimplementedError(node, 'Question token in function is not supported'); |
| 472 | if (exclamationToken) |
| 473 | throw new UnimplementedError(node, 'Exclamation token in function is not supported'); |
| 474 | if (typeParameters) |
| 475 | throw new UnimplementedError(node, 'Generic function is not supported'); |
| 476 | if (modifiers?.find(m => m.kind == ts.SyntaxKind.AsyncKeyword)) |
| 477 | throw new UnimplementedError(node, 'Async function is not supported'); |
| 478 | let cppBody: undefined | syntax.Block; |
| 479 | if (body) { |
| 480 | if (ts.isBlock(body)) { |
| 481 | cppBody = this.parseStatement(body) as syntax.Block; |
| 482 | } else { |
| 483 | // Arrow function may use expression as body, convert it to block. |
| 484 | cppBody = new syntax.Block([ |
| 485 | new syntax.ReturnStatement(this.parseExpression(body)), |
| 486 | ]); |
| 487 | } |
| 488 | } |
| 489 | const closure = this.typer.getCapturedIdentifiers(node) |
| 490 | .map(n => this.parseExpression(n)) |
| 491 | .filter(e => e.type.hasObject()); |
| 492 | return new syntax.FunctionExpression(this.typer.parseNodeType(node) as syntax.FunctionType, |
| 493 | parameters.map(this.parseParameterDeclaration.bind(this)), |
| 494 | closure, |
| 495 | cppBody); |
| 496 | } |
| 497 | |
| 498 | parseParameters(parameters: ts.NodeArray<ts.ParameterDeclaration> | ts.ParameterDeclaration[]): syntax.ParameterDeclaration[] { |
| 499 | return parameters.map(this.parseParameterDeclaration.bind(this)); |
no test coverage detected