Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Do not use lookahead when parsing jsx expression containers #9988

Merged
merged 1 commit into from May 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 15 additions & 13 deletions packages/babel-parser/src/plugins/jsx/index.js
Expand Up @@ -269,7 +269,9 @@ export default (superClass: Class<Parser>): Class<Parser> =>
let node;
switch (this.state.type) {
case tt.braceL:
node = this.jsxParseExpressionContainer();
node = this.startNode();
this.next();
node = this.jsxParseExpressionContainer(node);
if (node.expression.type === "JSXEmptyExpression") {
throw this.raise(
node.start,
Expand Down Expand Up @@ -310,10 +312,8 @@ export default (superClass: Class<Parser>): Class<Parser> =>

// Parse JSX spread child

jsxParseSpreadChild(): N.JSXSpreadChild {
const node = this.startNode();
this.expect(tt.braceL);
this.expect(tt.ellipsis);
jsxParseSpreadChild(node: N.JSXSpreadChild): N.JSXSpreadChild {
this.next(); // ellipsis
node.expression = this.parseExpression();
this.expect(tt.braceR);

Expand All @@ -322,9 +322,9 @@ export default (superClass: Class<Parser>): Class<Parser> =>

// Parses JSX expression enclosed into curly brackets.

jsxParseExpressionContainer(): N.JSXExpressionContainer {
const node = this.startNode();
this.next();
jsxParseExpressionContainer(
node: N.JSXExpressionContainer,
): N.JSXExpressionContainer {
if (this.match(tt.braceR)) {
node.expression = this.jsxParseEmptyExpression();
} else {
Expand Down Expand Up @@ -423,15 +423,17 @@ export default (superClass: Class<Parser>): Class<Parser> =>
children.push(this.parseExprAtom());
break;

case tt.braceL:
if (this.lookahead().type === tt.ellipsis) {
children.push(this.jsxParseSpreadChild());
case tt.braceL: {
const node = this.startNode();
this.next();
if (this.match(tt.ellipsis)) {
children.push(this.jsxParseSpreadChild(node));
} else {
children.push(this.jsxParseExpressionContainer());
children.push(this.jsxParseExpressionContainer(node));
}

break;

}
// istanbul ignore next - should never happen
default:
throw this.unexpected();
Expand Down