Fix lookahead to not add comments to arrays which are not cloned (#76)
We do not clone arrays in lookahead() but comments were added to leading/trailing arrays during lookahead, leading to leak to the next next() call. Also extracted parsing of JSXSpreadChild to own parse function.
This commit is contained in:
@@ -265,6 +265,18 @@ pp.jsxParseEmptyExpression = function() {
|
||||
return this.finishNodeAt(node, "JSXEmptyExpression", this.start, this.startLoc);
|
||||
};
|
||||
|
||||
// Parse JSX spread child
|
||||
|
||||
pp.jsxParseSpreadChild = function() {
|
||||
let node = this.startNode();
|
||||
this.expect(tt.braceL);
|
||||
this.expect(tt.ellipsis);
|
||||
node.expression = this.parseExpression();
|
||||
this.expect(tt.braceR);
|
||||
|
||||
return this.finishNode(node, "JSXSpreadChild");
|
||||
};
|
||||
|
||||
// Parses JSX expression enclosed into curly brackets.
|
||||
|
||||
|
||||
@@ -346,15 +358,11 @@ pp.jsxParseElementAt = function(startPos, startLoc) {
|
||||
|
||||
case tt.braceL:
|
||||
if (this.lookahead().type === tt.ellipsis) {
|
||||
let node = this.startNode();
|
||||
this.next();
|
||||
this.next();
|
||||
node.expression = this.parseExpression();
|
||||
this.expect(tt.braceR);
|
||||
children.push(this.finishNode(node, "JSXSpreadChild"));
|
||||
break;
|
||||
children.push(this.jsxParseSpreadChild());
|
||||
} else {
|
||||
children.push(this.jsxParseExpressionContainer());
|
||||
}
|
||||
children.push(this.jsxParseExpressionContainer());
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user