diff --git a/src/plugins/jsx/index.js b/src/plugins/jsx/index.js index a0e87c450e..30dcd93e52 100644 --- a/src/plugins/jsx/index.js +++ b/src/plugins/jsx/index.js @@ -302,6 +302,8 @@ pp.jsxParseExpressionContainer = function() { this.next(); if (this.match(tt.braceR)) { node.expression = this.jsxParseEmptyExpression(); + } else if (this.hasPlugin("spreadLoop") && this.match(tt.spreadLoop)) { + node.expression = this.parseSpreadLoop(); } else { node.expression = this.parseExpression(); } diff --git a/src/plugins/spreadLoop.js b/src/plugins/spreadLoop.js index 94290f0bf1..a3aae9aacb 100644 --- a/src/plugins/spreadLoop.js +++ b/src/plugins/spreadLoop.js @@ -45,10 +45,11 @@ export default function(parser) { }; pp.parseSpreadLoop = function(spreadElementType) { - const spreadElement = this.startNode(); + const spreadElement = spreadElementType == null ? null : this.startNode(); const spreadLoop = this.startNode(); const loop = this.startNode(); spreadLoop.loop = this.parseForStatement(loop); + if (spreadElementType == null) return this.finishNode(spreadLoop, "SpreadLoop"); spreadElement.argument = this.finishNode(spreadLoop, "SpreadLoop"); return this.finishNode(spreadElement, spreadElementType); }; diff --git a/test/fixtures/comprehension/array/for/actual.js b/test/fixtures/spread-loop/array/for/actual.js similarity index 100% rename from test/fixtures/comprehension/array/for/actual.js rename to test/fixtures/spread-loop/array/for/actual.js diff --git a/test/fixtures/comprehension/array/for/expected.json b/test/fixtures/spread-loop/array/for/expected.json similarity index 100% rename from test/fixtures/comprehension/array/for/expected.json rename to test/fixtures/spread-loop/array/for/expected.json diff --git a/test/fixtures/comprehension/array/if/actual.js b/test/fixtures/spread-loop/array/if/actual.js similarity index 100% rename from test/fixtures/comprehension/array/if/actual.js rename to test/fixtures/spread-loop/array/if/actual.js diff --git a/test/fixtures/comprehension/array/if/expected.json b/test/fixtures/spread-loop/array/if/expected.json similarity index 100% rename from test/fixtures/comprehension/array/if/expected.json rename to test/fixtures/spread-loop/array/if/expected.json diff --git a/test/fixtures/comprehension/array/kitchen-sink/actual.js b/test/fixtures/spread-loop/array/kitchen-sink/actual.js similarity index 100% rename from test/fixtures/comprehension/array/kitchen-sink/actual.js rename to test/fixtures/spread-loop/array/kitchen-sink/actual.js diff --git a/test/fixtures/comprehension/array/kitchen-sink/expected.json b/test/fixtures/spread-loop/array/kitchen-sink/expected.json similarity index 100% rename from test/fixtures/comprehension/array/kitchen-sink/expected.json rename to test/fixtures/spread-loop/array/kitchen-sink/expected.json diff --git a/test/fixtures/comprehension/array/restructure/actual.js b/test/fixtures/spread-loop/array/restructure/actual.js similarity index 100% rename from test/fixtures/comprehension/array/restructure/actual.js rename to test/fixtures/spread-loop/array/restructure/actual.js diff --git a/test/fixtures/comprehension/array/restructure/expected.json b/test/fixtures/spread-loop/array/restructure/expected.json similarity index 100% rename from test/fixtures/comprehension/array/restructure/expected.json rename to test/fixtures/spread-loop/array/restructure/expected.json diff --git a/test/fixtures/comprehension/array/seqexpr-ish/actual.js b/test/fixtures/spread-loop/array/seqexpr-ish/actual.js similarity index 100% rename from test/fixtures/comprehension/array/seqexpr-ish/actual.js rename to test/fixtures/spread-loop/array/seqexpr-ish/actual.js diff --git a/test/fixtures/comprehension/array/seqexpr-ish/expected.json b/test/fixtures/spread-loop/array/seqexpr-ish/expected.json similarity index 100% rename from test/fixtures/comprehension/array/seqexpr-ish/expected.json rename to test/fixtures/spread-loop/array/seqexpr-ish/expected.json diff --git a/test/fixtures/spread-loop/jsx/basic/actual.js b/test/fixtures/spread-loop/jsx/basic/actual.js new file mode 100644 index 0000000000..19bbb736a4 --- /dev/null +++ b/test/fixtures/spread-loop/jsx/basic/actual.js @@ -0,0 +1,3 @@ +
+ {...for elem e in arr: } +
diff --git a/test/fixtures/spread-loop/jsx/basic/expected.json b/test/fixtures/spread-loop/jsx/basic/expected.json new file mode 100644 index 0000000000..adda63d589 --- /dev/null +++ b/test/fixtures/spread-loop/jsx/basic/expected.json @@ -0,0 +1,372 @@ +{ + "type": "File", + "start": 0, + "end": 57, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 57, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 57, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "expression": { + "type": "JSXElement", + "start": 0, + "end": 57, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "openingElement": { + "type": "JSXOpeningElement", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "attributes": [], + "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": 51, + "end": 57, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "name": { + "type": "JSXIdentifier", + "start": 53, + "end": 56, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 5 + } + }, + "name": "div" + } + }, + "children": [ + { + "type": "JSXText", + "start": 5, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 2, + "column": 2 + } + }, + "extra": null, + "value": "\n " + }, + { + "type": "JSXExpressionContainer", + "start": 8, + "end": 50, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 44 + } + }, + "expression": { + "type": "SpreadLoop", + "start": 9, + "end": 49, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 43 + } + }, + "loop": { + "type": "ForInArrayStatement", + "start": 9, + "end": 49, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 43 + } + }, + "elem": { + "type": "Identifier", + "start": 21, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 16 + }, + "identifierName": "e" + }, + "name": "e" + }, + "body": { + "type": "ExpressionStatement", + "start": 31, + "end": 49, + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 43 + } + }, + "expression": { + "type": "JSXElement", + "start": 31, + "end": 49, + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 43 + } + }, + "openingElement": { + "type": "JSXOpeningElement", + "start": 31, + "end": 49, + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 43 + } + }, + "attributes": [ + { + "type": "JSXAttribute", + "start": 38, + "end": 46, + "loc": { + "start": { + "line": 2, + "column": 32 + }, + "end": { + "line": 2, + "column": 40 + } + }, + "name": { + "type": "JSXIdentifier", + "start": 38, + "end": 42, + "loc": { + "start": { + "line": 2, + "column": 32 + }, + "end": { + "line": 2, + "column": 36 + } + }, + "name": "elem" + }, + "value": { + "type": "JSXExpressionContainer", + "start": 43, + "end": 46, + "loc": { + "start": { + "line": 2, + "column": 37 + }, + "end": { + "line": 2, + "column": 40 + } + }, + "expression": { + "type": "Identifier", + "start": 44, + "end": 45, + "loc": { + "start": { + "line": 2, + "column": 38 + }, + "end": { + "line": 2, + "column": 39 + }, + "identifierName": "e" + }, + "name": "e" + } + } + } + ], + "name": { + "type": "JSXIdentifier", + "start": 32, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "name": "Entry" + }, + "selfClosing": true + }, + "closingElement": null, + "children": [] + } + }, + "array": { + "type": "Identifier", + "start": 26, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 23 + }, + "identifierName": "arr" + }, + "name": "arr" + } + } + } + }, + { + "type": "JSXText", + "start": 50, + "end": 51, + "loc": { + "start": { + "line": 2, + "column": 44 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "extra": null, + "value": "\n" + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/comprehension/object/for/actual.js b/test/fixtures/spread-loop/object/for/actual.js similarity index 100% rename from test/fixtures/comprehension/object/for/actual.js rename to test/fixtures/spread-loop/object/for/actual.js diff --git a/test/fixtures/comprehension/object/for/expected.json b/test/fixtures/spread-loop/object/for/expected.json similarity index 100% rename from test/fixtures/comprehension/object/for/expected.json rename to test/fixtures/spread-loop/object/for/expected.json diff --git a/test/fixtures/comprehension/object/if/actual.js b/test/fixtures/spread-loop/object/if/actual.js similarity index 100% rename from test/fixtures/comprehension/object/if/actual.js rename to test/fixtures/spread-loop/object/if/actual.js diff --git a/test/fixtures/comprehension/object/if/expected.json b/test/fixtures/spread-loop/object/if/expected.json similarity index 100% rename from test/fixtures/comprehension/object/if/expected.json rename to test/fixtures/spread-loop/object/if/expected.json diff --git a/test/fixtures/comprehension/options.json b/test/fixtures/spread-loop/options.json similarity index 100% rename from test/fixtures/comprehension/options.json rename to test/fixtures/spread-loop/options.json