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

Method parseConstructorDeclaration

src/parser.ts:577–603  ·  view source on GitHub ↗
(classDeclaration: ts.ClassDeclaration, node: ts.ConstructorDeclaration)

Source from the content-addressed store, hash-verified

575 }
576
577 parseConstructorDeclaration(classDeclaration: ts.ClassDeclaration, node: ts.ConstructorDeclaration): syntax.ConstructorDeclaration {
578 let {body, parameters} = node;
579 this.typer.forbidClosure(node as ts.ConstructorDeclaration);
580 let baseCall: syntax.CallArguments | undefined;
581 if (body) {
582 // The super call can only be used as the first statement.
583 const superCall = filterNode(body, (node) => ts.isCallExpression(node) && node.expression.kind == ts.SyntaxKind.SuperKeyword) as ts.CallExpression[];
584 if (superCall.length == 1) {
585 const firstStatement = body.statements[0];
586 if (!ts.isExpressionStatement(firstStatement) ||
587 !ts.isCallExpression(firstStatement.expression) ||
588 superCall[0] != firstStatement.expression) {
589 throw new UnimplementedError(superCall[0], 'The super call must be placed as the first statement in body');
590 }
591 // Convert the super call to C++.
592 baseCall = this.parseArguments(superCall[0], superCall[0]['arguments']);
593 // Remove the super call from body.
594 body = ts.factory.createBlock(body.statements.slice(1));
595 } else if (superCall.length > 1) {
596 throw new UnimplementedError(superCall[1], 'The super call can only be called once');
597 }
598 }
599 return new syntax.ConstructorDeclaration(classDeclaration.name!.text,
600 this.parseParameters(parameters),
601 body ? this.parseStatement(body) as syntax.Block : undefined,
602 baseCall);
603 }
604
605 parseObjectLiteral(node: ts.ObjectLiteralExpression): syntax.ObjectLiteral {
606 const initializers = new Map<string, syntax.Expression>();

Callers 1

parseClassElementMethod · 0.95

Calls 6

parseArgumentsMethod · 0.95
parseParametersMethod · 0.95
parseStatementMethod · 0.95
filterNodeFunction · 0.90
forbidClosureMethod · 0.80
sliceMethod · 0.80

Tested by

no test coverage detected