(isAsync bool, allowReturnTypeInArrowFunction bool)
| 4466 | } |
| 4467 | |
| 4468 | func (p *Parser) parseArrowFunctionExpressionBody(isAsync bool, allowReturnTypeInArrowFunction bool) *ast.Node { |
| 4469 | if p.token == ast.KindOpenBraceToken { |
| 4470 | return p.parseFunctionBlock(core.IfElse(isAsync, ParseFlagsAwait, ParseFlagsNone), nil /*diagnosticMessage*/) |
| 4471 | } |
| 4472 | if p.token != ast.KindSemicolonToken && p.token != ast.KindFunctionKeyword && p.token != ast.KindClassKeyword && p.isStartOfStatement() && !p.isStartOfExpressionStatement() { |
| 4473 | // Check if we got a plain statement (i.e. no expression-statements, no function/class expressions/declarations) |
| 4474 | // |
| 4475 | // Here we try to recover from a potential error situation in the case where the |
| 4476 | // user meant to supply a block. For example, if the user wrote: |
| 4477 | // |
| 4478 | // a => |
| 4479 | // let v = 0; |
| 4480 | // } |
| 4481 | // |
| 4482 | // they may be missing an open brace. Check to see if that's the case so we can |
| 4483 | // try to recover better. If we don't do this, then the next close curly we see may end |
| 4484 | // up preemptively closing the containing construct. |
| 4485 | // |
| 4486 | // Note: even when 'IgnoreMissingOpenBrace' is passed, parseBody will still error. |
| 4487 | return p.parseFunctionBlock(ParseFlagsIgnoreMissingOpenBrace|core.IfElse(isAsync, ParseFlagsAwait, ParseFlagsNone), nil /*diagnosticMessage*/) |
| 4488 | } |
| 4489 | saveContextFlags := p.contextFlags |
| 4490 | p.setContextFlags(ast.NodeFlagsAwaitContext, isAsync) |
| 4491 | p.setContextFlags(ast.NodeFlagsYieldContext, false) |
| 4492 | node := p.parseAssignmentExpressionOrHigherWorker(allowReturnTypeInArrowFunction) |
| 4493 | p.contextFlags = saveContextFlags |
| 4494 | return node |
| 4495 | } |
| 4496 | |
| 4497 | func (p *Parser) isStartOfExpressionStatement() bool { |
| 4498 | // As per the grammar, none of '{' or 'function' or 'class' can start an expression statement. |
no test coverage detected