Skip to content

Commit

Permalink
Fix infinite loop when a file ends with a short identifier
Browse files Browse the repository at this point in the history
We weren't properly checking for end-of-file when going through the readWord
tree.
  • Loading branch information
alangpierce committed Dec 1, 2018
1 parent 7bac8c6 commit 10b0693
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/parser/tokenizer/readWord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import {TokenType as tt} from "./types";
*/
export default function readWord(): void {
let treePos = 0;
let code;
let code = 0;
let pos = state.pos;
while (true) {
while (pos < input.length) {
code = input.charCodeAt(pos);
if (code < charCodes.lowercaseA || code > charCodes.lowercaseZ) {
break;
Expand Down
4 changes: 4 additions & 0 deletions test/sucrase-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -723,4 +723,8 @@ describe("sucrase", () => {
{transforms: ["typescript"]},
);
});

it("handles a file with only a single identifier", () => {
assertResult("a", "a", {transforms: []});
});
});

0 comments on commit 10b0693

Please sign in to comment.