MCPcopy Create free account
hub / github.com/compilets/compilets / parseFunctionExpression

Method parseFunctionExpression

src/parser.ts:466–496  ·  view source on GitHub ↗
(node: ts.FunctionExpression | ts.ArrowFunction)

Source from the content-addressed store, hash-verified

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));

Callers 1

parseExpressionMethod · 0.95

Calls 6

parseStatementMethod · 0.95
parseExpressionMethod · 0.95
filterMethod · 0.80
hasObjectMethod · 0.80
parseNodeTypeMethod · 0.80

Tested by

no test coverage detected