diff --git a/src/parser/plugins/jsx/index.ts b/src/parser/plugins/jsx/index.ts index 531a8fbe..2166b834 100644 --- a/src/parser/plugins/jsx/index.ts +++ b/src/parser/plugins/jsx/index.ts @@ -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; } diff --git a/test/jsx-test.ts b/test/jsx-test.ts index e3e3a1e2..b47b2c38 100644 --- a/test/jsx-test.ts +++ b/test/jsx-test.ts @@ -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 = <>; + `, + `${JSX_PREFIX} + const c = React.createElement(React.Fragment, null, React.createElement('a', {${devProps( + 2, + )}})); + `, + ); + }); + describe("with production true", () => { it("handles no props", () => { assertResult(