Skip to content

Commit

Permalink
Do not use lookahead when parsing jsx expression containers (#9988)
Browse files Browse the repository at this point in the history
  • Loading branch information
danez committed May 17, 2019
1 parent 5661de5 commit 3f0590d
Showing 1 changed file with 15 additions and 13 deletions.
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

0 comments on commit 3f0590d

Please sign in to comment.