Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Commit

Permalink
Fix lookahead to not add comments to arrays which are not cloned (#76)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
danez authored Jul 17, 2016
1 parent 9732559 commit 88d7e20
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
24 changes: 16 additions & 8 deletions src/plugins/jsx/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.


Expand Down Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions src/tokenizer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 88d7e20

Please sign in to comment.