MCPcopy Create free account
hub / github.com/microsoft/typescript-go / parseTryStatement

Method parseTryStatement

internal/parser/parser.go:1476–1495  ·  view source on GitHub ↗

TODO: Review for error recovery

()

Source from the content-addressed store, hash-verified

1474
1475// TODO: Review for error recovery
1476func (p *Parser) parseTryStatement() *ast.Node {
1477 pos := p.nodePos()
1478 jsdoc := p.jsdocScannerInfo()
1479 p.parseExpected(ast.KindTryKeyword)
1480 tryBlock := p.parseBlock(false /*ignoreMissingOpenBrace*/, nil)
1481 var catchClause *ast.Node
1482 if p.token == ast.KindCatchKeyword {
1483 catchClause = p.parseCatchClause()
1484 }
1485 // If we don't have a catch clause, then we must have a finally clause. Try to parse
1486 // one out no matter what.
1487 var finallyBlock *ast.Node
1488 if catchClause == nil || p.token == ast.KindFinallyKeyword {
1489 p.parseExpectedWithDiagnostic(ast.KindFinallyKeyword, diagnostics.X_catch_or_finally_expected, true /*shouldAdvance*/)
1490 finallyBlock = p.parseBlock(false /*ignoreMissingOpenBrace*/, nil)
1491 }
1492 result := p.finishNode(p.factory.NewTryStatement(tryBlock, catchClause, finallyBlock), pos)
1493 p.withJSDoc(result, jsdoc)
1494 return result
1495}
1496
1497func (p *Parser) parseCatchClause() *ast.Node {
1498 pos := p.nodePos()

Callers 1

parseStatementMethod · 0.95

Calls 9

nodePosMethod · 0.95
jsdocScannerInfoMethod · 0.95
parseExpectedMethod · 0.95
parseBlockMethod · 0.95
parseCatchClauseMethod · 0.95
finishNodeMethod · 0.95
withJSDocMethod · 0.95
NewTryStatementMethod · 0.80

Tested by

no test coverage detected