MCPcopy Create free account
hub / github.com/babel/babel / parseTryStatement

Function parseTryStatement

packages/babel-parser/src/parser/statement.ts:1074–1109  ·  view source on GitHub ↗
(
    this: Parser,
    node: Undone<N.TryStatement>,
  )

Source from the content-addressed store, hash-verified

1072 }
1073
1074 parseTryStatement(
1075 this: Parser,
1076 node: Undone<N.TryStatement>,
1077 ): N.TryStatement {
1078 this.next();
1079
1080 node.block = this.parseBlock();
1081 node.handler = null;
1082
1083 if (this.match(tt._catch)) {
1084 const clause = this.startNode<N.CatchClause>();
1085 this.next();
1086 if (this.match(tt.parenL)) {
1087 this.expect(tt.parenL);
1088 clause.param = this.parseCatchClauseParam();
1089 this.expect(tt.parenR);
1090 } else {
1091 clause.param = null;
1092 this.scope.enter(ScopeFlag.OTHER);
1093 }
1094
1095 // Parse the catch clause's body.
1096 clause.body = this.parseBlock(false, false);
1097
1098 this.scope.exit();
1099 node.handler = this.finishNode(clause, "CatchClause");
1100 }
1101
1102 node.finalizer = this.eat(tt._finally) ? this.parseBlock() : null;
1103
1104 if (!node.handler && !node.finalizer) {
1105 this.raise(Errors.NoCatchOrFinally, node);
1106 }
1107
1108 return this.finishNode(node, "TryStatement");
1109 }
1110
1111 // https://tc39.es/ecma262/#prod-VariableStatement
1112 // https://tc39.es/ecma262/#prod-LexicalDeclaration

Callers

nothing calls this directly

Calls 7

nextMethod · 0.80
parseBlockMethod · 0.80
matchMethod · 0.80
parseCatchClauseParamMethod · 0.80
finishNodeMethod · 0.80
enterMethod · 0.45
exitMethod · 0.45

Tested by

no test coverage detected