avoid exceptions for control flow (#9974)
* avoid exceptions for control flow * review feedback: remove conditional because we know it is "<" * drop tsTryParseTypeArguments method
This commit is contained in:
committed by
Nicolò Ribaudo
parent
f5b8140580
commit
9c06e4ed4d
@@ -1442,6 +1442,9 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
startPos: number,
|
||||
startLoc: Position,
|
||||
): ?N.ArrowFunctionExpression {
|
||||
if (!this.isRelational("<")) {
|
||||
return undefined;
|
||||
}
|
||||
const res: ?N.ArrowFunctionExpression = this.tsTryParseAndCatch(() => {
|
||||
const node: N.ArrowFunctionExpression = this.startNodeAt(
|
||||
startPos,
|
||||
@@ -2204,8 +2207,10 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
const returnType = this.tsParseTypeOrTypePredicateAnnotation(
|
||||
tt.colon,
|
||||
);
|
||||
if (this.canInsertSemicolon()) this.unexpected();
|
||||
if (!this.match(tt.arrow)) this.unexpected();
|
||||
if (this.canInsertSemicolon() || !this.match(tt.arrow)) {
|
||||
this.state = state;
|
||||
return undefined;
|
||||
}
|
||||
node.returnType = returnType;
|
||||
} catch (err) {
|
||||
if (err instanceof SyntaxError) {
|
||||
@@ -2438,10 +2443,12 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
jsxParseOpeningElementAfterName(
|
||||
node: N.JSXOpeningElement,
|
||||
): N.JSXOpeningElement {
|
||||
const typeArguments = this.tsTryParseAndCatch(() =>
|
||||
this.tsParseTypeArguments(),
|
||||
);
|
||||
if (typeArguments) node.typeParameters = typeArguments;
|
||||
if (this.isRelational("<")) {
|
||||
const typeArguments = this.tsTryParseAndCatch(() =>
|
||||
this.tsParseTypeArguments(),
|
||||
);
|
||||
if (typeArguments) node.typeParameters = typeArguments;
|
||||
}
|
||||
return super.jsxParseOpeningElementAfterName(node);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user