Skip to content

Commit

Permalink
Fix infinite loop on incomplete JSX (#296)
Browse files Browse the repository at this point in the history
Fixes #294
  • Loading branch information
alangpierce authored Jul 6, 2018
1 parent 71d74c4 commit 9b75b41
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/parser/plugins/jsx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ function jsxReadString(quote: number): void {
function jsxReadWord(): void {
let ch: number;
do {
if (state.pos > input.length) {
unexpected(null, "Unexpectedly reached the end of input.");
}
ch = input.charCodeAt(++state.pos);
} while (isIdentifierChar(ch) || ch === charCodes.dash);
finishToken(tt.jsxName);
Expand Down
8 changes: 7 additions & 1 deletion test/jsx-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {Transform} from "../src";
import {throws} from "assert";

import {transform, Transform} from "../src";
import {IMPORT_DEFAULT_PREFIX, JSX_PREFIX} from "./prefixes";
import * as util from "./util";

Expand Down Expand Up @@ -466,6 +468,10 @@ describe("transform JSX", () => {
);
});

it("does not infinite loop on incomplete JSX", () => {
throws(() => transform("const x = <", {transforms: ["jsx"]}));
});

describe("with production true", () => {
it("handles no props", () => {
assertResult(
Expand Down

0 comments on commit 9b75b41

Please # to comment.