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:
Daniel Tschinder 2016-07-17 11:08:25 +02:00 committed by GitHub
parent 97325592fa
commit 88d7e2012c
2 changed files with 17 additions and 10 deletions

View File

@ -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:

View File

@ -166,9 +166,8 @@ export default class Tokenizer {
if (!this.isLookahead) {
this.state.tokens.push(comment);
this.state.comments.push(comment);
this.addComment(comment);
}
this.addComment(comment);
}
skipBlockComment() {