From a25a4ffdc14451c7af74329f62461a65b23fdc81 Mon Sep 17 00:00:00 2001 From: calebmer Date: Sun, 19 Jun 2016 10:48:20 -0400 Subject: [PATCH] Add JSX spread children --- src/plugins/jsx/index.js | 9 + test/fixtures/jsx/basic/21/actual.js | 1 + test/fixtures/jsx/basic/21/expected.json | 273 +++++++++++++++++++++++ 3 files changed, 283 insertions(+) create mode 100644 test/fixtures/jsx/basic/21/actual.js create mode 100644 test/fixtures/jsx/basic/21/expected.json diff --git a/src/plugins/jsx/index.js b/src/plugins/jsx/index.js index ea371a8fab..77d3417329 100644 --- a/src/plugins/jsx/index.js +++ b/src/plugins/jsx/index.js @@ -345,6 +345,15 @@ pp.jsxParseElementAt = function(startPos, startLoc) { break; 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.jsxParseExpressionContainer()); break; diff --git a/test/fixtures/jsx/basic/21/actual.js b/test/fixtures/jsx/basic/21/actual.js new file mode 100644 index 0000000000..f9a1c7e1c3 --- /dev/null +++ b/test/fixtures/jsx/basic/21/actual.js @@ -0,0 +1 @@ +
{...children}{a}{...b}
diff --git a/test/fixtures/jsx/basic/21/expected.json b/test/fixtures/jsx/basic/21/expected.json new file mode 100644 index 0000000000..8a6cfbda2c --- /dev/null +++ b/test/fixtures/jsx/basic/21/expected.json @@ -0,0 +1,273 @@ +{ + "type": "File", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "expression": { + "type": "JSXElement", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "openingElement": { + "type": "JSXOpeningElement", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "attributes": [ + { + "type": "JSXSpreadAttribute", + "start": 5, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "argument": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "name": "c" + } + } + ], + "name": { + "type": "JSXIdentifier", + "start": 1, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "name": "div" + }, + "selfClosing": false + }, + "closingElement": { + "type": "JSXClosingElement", + "start": 35, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 35 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "name": { + "type": "JSXIdentifier", + "start": 37, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 37 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "name": "div" + } + }, + "children": [ + { + "type": "JSXText", + "start": 12, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "extra": null, + "value": " " + }, + { + "type": "JSXSpreadChild", + "start": 13, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "expression": { + "type": "Identifier", + "start": 17, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "name": "children" + } + }, + { + "type": "JSXExpressionContainer", + "start": 26, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "expression": { + "type": "Identifier", + "start": 27, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "name": "a" + } + }, + { + "type": "JSXSpreadChild", + "start": 29, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "expression": { + "type": "Identifier", + "start": 33, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 33 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "name": "b" + } + } + ] + } + } + ], + "directives": [] + }, + "comments": [] +}