Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix implementation of JSX spread children #431

Merged
merged 1 commit into from
Mar 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/parser/plugins/jsx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ function jsxParseEmptyExpression(): void {
}

// Parse JSX spread child
// Does not parse the last token.
function jsxParseSpreadChild(): void {
expect(tt.braceL);
expect(tt.ellipsis);
parseExpression();
expect(tt.braceR);
}

// Parses JSX expression enclosed into curly brackets.
Expand Down Expand Up @@ -233,6 +233,7 @@ function jsxParseElementAt(): void {
case tt.braceL:
if (lookaheadType() === tt.ellipsis) {
jsxParseSpreadChild();
nextJSXExprToken();
} else {
jsxParseExpressionContainer();
nextJSXExprToken();
Expand Down
11 changes: 11 additions & 0 deletions test/jsx-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,17 @@ describe("transform JSX", () => {
throws(() => transform("const x = <", {transforms: ["jsx"]}));
});

it("handles spread children", () => {
assertResult(
`
const e = <A>{...b}</A>;
`,
`${JSX_PREFIX}
const e = React.createElement(A, {${devProps(2)}}, ...b);
`,
);
});

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