Skip to content

Commit

Permalink
Fix off-by-one error in parsing JSX fragments (#275)
Browse files Browse the repository at this point in the history
Fixes #254

`jsxParseOpeningElement` isn't supposed to parse the last token, but was doing
so, and it happened to work in the existing test cases.
  • Loading branch information
alangpierce authored Jun 26, 2018
1 parent de5cb1e commit 5acef1c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/parser/plugins/jsx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ function jsxParseAttribute(): void {
// Does not parse the last token.
function jsxParseOpeningElement(): boolean {
if (match(tt.jsxTagEnd)) {
nextJSXExprToken();
// This is an open-fragment.
return false;
}
Expand Down
24 changes: 24 additions & 0 deletions test/jsx-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,30 @@ describe("transform JSX", () => {
);
});

it("allows empty fragments", () => {
assertResult(
`
const c = <></>;
`,
`
const c = React.createElement(React.Fragment, null);
`,
);
});

it("allows fragments without whitespace", () => {
assertResult(
`
const c = <><a/></>;
`,
`${JSX_PREFIX}
const c = React.createElement(React.Fragment, null, React.createElement('a', {${devProps(
2,
)}}));
`,
);
});

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

0 comments on commit 5acef1c

Please sign in to comment.