Skip to content

Commit

Permalink
Fix TS parsing bug when seeing a generics-like expression (#438)
Browse files Browse the repository at this point in the history
Fixes #408

If we see `a<b>`, we were already looking at the next token to see if it's an
open-paren (meaning this is a function call with a type argument) or a backtick
(meaning this is a tagged template literal with a type argument), but we weren't
properly bailing out if it was neither of those, which put the parser in a bad
state.
  • Loading branch information
alangpierce committed Mar 18, 2019
1 parent ce7c020 commit 36b9d76
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/parser/plugins/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,8 @@ export function tsParseSubscript(startPos: number, noCalls: boolean, stopState:
} else if (match(tt.backQuote)) {
// Tagged template with a type argument.
parseTemplate();
} else {
unexpected();
}

if (state.error) {
Expand Down
11 changes: 11 additions & 0 deletions test/typescript-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,17 @@ describe("typescript transform", () => {
);
});

it("properly handles comparison operators that look like JSX or generics (#408)", () => {
assertTypeScriptResult(
`
a < b > c
`,
`"use strict";
a < b > c
`,
);
});

it("elides type-only exports", () => {
assertTypeScriptImportResult(
`
Expand Down

0 comments on commit 36b9d76

Please sign in to comment.