Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restrict TS try/catch logic to cases where backtracking is needed #327

Merged
merged 1 commit into from
Nov 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions src/parser/plugins/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1093,10 +1093,10 @@ export function tsParseSubscript(
return;
}

// There are number of things we are going to "maybe" parse, like type arguments on
// tagged template expressions. If any of them fail, walk it back and continue.
const success = tsTryParseAndCatch(() => {
if (match(tt.lessThan)) {
if (match(tt.lessThan)) {
// There are number of things we are going to "maybe" parse, like type arguments on
// tagged template expressions. If any of them fail, walk it back and continue.
const success = tsTryParseAndCatch(() => {
if (!noCalls && atPossibleAsync()) {
// Almost certainly this is a generic async function `async <T>() => ...
// But it might be a call with a type argument `async<T>();`
Expand All @@ -1108,17 +1108,14 @@ export function tsParseSubscript(
tsParseTypeArguments();
if (!noCalls && eat(tt.parenL)) {
parseCallExpressionArguments(tt.parenR);
return;
} else if (match(tt.backQuote)) {
// Tagged template with a type argument.
parseTemplate();
return;
}
});
if (success) {
return;
}
unexpected();
});
if (success) {
return;
}
baseParseSubscript(startPos, noCalls, stopState);
}
Expand Down