diff --git a/src/plugins/jsx/index.js b/src/plugins/jsx/index.js index 18b92e9fac..6bc98d396e 100644 --- a/src/plugins/jsx/index.js +++ b/src/plugins/jsx/index.js @@ -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: diff --git a/src/tokenizer/index.js b/src/tokenizer/index.js index 1cd5b5c1fc..f787acb1b5 100644 --- a/src/tokenizer/index.js +++ b/src/tokenizer/index.js @@ -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() {