(asyncToken?: KeywordToken, decorators?: DecoratorNode[])
| 505 | // funcdef: 'def' NAME parameters ['->' test] ':' suite |
| 506 | // parameters: '(' [typedargslist] ')' |
| 507 | private _parseFunctionDef(asyncToken?: KeywordToken, decorators?: DecoratorNode[]): FunctionNode { |
| 508 | let defToken = this._getKeywordToken(KeywordType.Def); |
| 509 | |
| 510 | let nameToken = this._getTokenIfIdentifier(); |
| 511 | if (!nameToken) { |
| 512 | this._addError('Expected function name after "def"', defToken); |
| 513 | nameToken = new IdentifierToken(0, 0, ''); |
| 514 | } |
| 515 | |
| 516 | if (!this._consumeTokenIfType(TokenType.OpenParenthesis)) { |
| 517 | this._addError('Expected "("', this._peekToken()); |
| 518 | } |
| 519 | |
| 520 | let paramList = this._parseVarArgsList(TokenType.CloseParenthesis, true); |
| 521 | |
| 522 | if (!this._consumeTokenIfType(TokenType.CloseParenthesis)) { |
| 523 | this._addError('Expected ")"', this._peekToken()); |
| 524 | } |
| 525 | |
| 526 | let returnType: ExpressionNode | undefined; |
| 527 | if (this._consumeTokenIfType(TokenType.Arrow)) { |
| 528 | returnType = this._parseTestExpression(); |
| 529 | } |
| 530 | |
| 531 | let suite = this._parseSuite(); |
| 532 | |
| 533 | let functionNode = new FunctionNode(defToken, new NameNode(nameToken), suite); |
| 534 | if (asyncToken) { |
| 535 | functionNode.isAsync = true; |
| 536 | functionNode.extend(asyncToken); |
| 537 | } |
| 538 | functionNode.parameters = paramList; |
| 539 | if (decorators) { |
| 540 | functionNode.decorators = decorators; |
| 541 | if (decorators.length > 0) { |
| 542 | functionNode.extend(decorators[0]); |
| 543 | } |
| 544 | } |
| 545 | if (returnType) { |
| 546 | functionNode.returnTypeAnnotation = this._parseTypeAnnotation(returnType); |
| 547 | functionNode.extend(functionNode.returnTypeAnnotation.rawExpression); |
| 548 | } |
| 549 | |
| 550 | return functionNode; |
| 551 | } |
| 552 | |
| 553 | // typedargslist: ( |
| 554 | // tfpdef ['=' test] (',' tfpdef ['=' test])* |
no test coverage detected