Do not use lookahead when parsing jsx expression containers (#9988)
This commit is contained in:
parent
5661de5908
commit
3f0590de2a
@ -269,7 +269,9 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
let node;
|
let node;
|
||||||
switch (this.state.type) {
|
switch (this.state.type) {
|
||||||
case tt.braceL:
|
case tt.braceL:
|
||||||
node = this.jsxParseExpressionContainer();
|
node = this.startNode();
|
||||||
|
this.next();
|
||||||
|
node = this.jsxParseExpressionContainer(node);
|
||||||
if (node.expression.type === "JSXEmptyExpression") {
|
if (node.expression.type === "JSXEmptyExpression") {
|
||||||
throw this.raise(
|
throw this.raise(
|
||||||
node.start,
|
node.start,
|
||||||
@ -310,10 +312,8 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
|
|
||||||
// Parse JSX spread child
|
// Parse JSX spread child
|
||||||
|
|
||||||
jsxParseSpreadChild(): N.JSXSpreadChild {
|
jsxParseSpreadChild(node: N.JSXSpreadChild): N.JSXSpreadChild {
|
||||||
const node = this.startNode();
|
this.next(); // ellipsis
|
||||||
this.expect(tt.braceL);
|
|
||||||
this.expect(tt.ellipsis);
|
|
||||||
node.expression = this.parseExpression();
|
node.expression = this.parseExpression();
|
||||||
this.expect(tt.braceR);
|
this.expect(tt.braceR);
|
||||||
|
|
||||||
@ -322,9 +322,9 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
|
|
||||||
// Parses JSX expression enclosed into curly brackets.
|
// Parses JSX expression enclosed into curly brackets.
|
||||||
|
|
||||||
jsxParseExpressionContainer(): N.JSXExpressionContainer {
|
jsxParseExpressionContainer(
|
||||||
const node = this.startNode();
|
node: N.JSXExpressionContainer,
|
||||||
this.next();
|
): N.JSXExpressionContainer {
|
||||||
if (this.match(tt.braceR)) {
|
if (this.match(tt.braceR)) {
|
||||||
node.expression = this.jsxParseEmptyExpression();
|
node.expression = this.jsxParseEmptyExpression();
|
||||||
} else {
|
} else {
|
||||||
@ -423,15 +423,17 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
children.push(this.parseExprAtom());
|
children.push(this.parseExprAtom());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case tt.braceL:
|
case tt.braceL: {
|
||||||
if (this.lookahead().type === tt.ellipsis) {
|
const node = this.startNode();
|
||||||
children.push(this.jsxParseSpreadChild());
|
this.next();
|
||||||
|
if (this.match(tt.ellipsis)) {
|
||||||
|
children.push(this.jsxParseSpreadChild(node));
|
||||||
} else {
|
} else {
|
||||||
children.push(this.jsxParseExpressionContainer());
|
children.push(this.jsxParseExpressionContainer(node));
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
// istanbul ignore next - should never happen
|
// istanbul ignore next - should never happen
|
||||||
default:
|
default:
|
||||||
throw this.unexpected();
|
throw this.unexpected();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user