Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add array spread support #385

Merged
merged 1 commit into from
Mar 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 59 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"@babel/parser": "^7.8.4",
"@babel/plugin-transform-modules-commonjs": "^7.8.3",
"@babel/plugin-transform-parameters": "^7.8.4",
"@babel/plugin-transform-spread": "^7.8.3",
"babel-check-duplicated-nodes": "^1.0.0",
"browserify": "^16.5.0",
"mocha": "^7.0.1",
Expand Down
8 changes: 7 additions & 1 deletion packages/regenerator-transform/src/emit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,13 @@ Ep.explodeExpression = function(path, ignoreResult) {
case "ArrayExpression":
return finish(t.arrayExpression(
path.get("elements").map(function(elemPath) {
return explodeViaTempVar(null, elemPath);
if (elemPath.isSpreadElement()) {
return t.spreadElement(
explodeViaTempVar(null, elemPath.get("argument"))
);
} else {
return explodeViaTempVar(null, elemPath);
}
})
));

Expand Down
5 changes: 2 additions & 3 deletions test/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,10 @@ enqueue(convert, [
"./test/class.es5.js"
]);

function convertWithSpread(es6File, es5File, callback) {
function convertWithParamsTransform(es6File, es5File, callback) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really appreciate your attention to detail, such as taking the time to update the test harness so it doesn't accidentally rely on the @babel/plugin-transform-spread transform.

var transformOptions = {
presets:[require("regenerator-preset")],
plugins: [
require("@babel/plugin-transform-spread"),
require("@babel/plugin-transform-parameters")
],
parserOpts: {
Expand Down Expand Up @@ -200,7 +199,7 @@ function convertWithSpread(es6File, es5File, callback) {
});
}

enqueue(convertWithSpread, [
enqueue(convertWithParamsTransform, [
"./test/regression.js",
"./test/regression.es5.js"
]);
Expand Down
18 changes: 18 additions & 0 deletions test/tests.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -2742,4 +2742,22 @@ describe("expressions containing yield subexpressions", function() {
done: true
});
});

it("should work when yield is in an array spread", function() {
function *gen() {
return [0, ...(yield "foo"), 3];
}

var g = gen();

assert.deepEqual(g.next(), {
value: "foo",
done: false,
});

assert.deepEqual(g.next([1, 2]), {
value: [0, 1, 2, 3],
done: true,
});
});
});