diff --git a/package.json b/package.json index 35086aa25..d0e4b89a0 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,8 @@ "through": "^2.3.8" }, "devDependencies": { + "babel-plugin-transform-es2015-parameters": "^6.23.0", + "babel-plugin-transform-es2015-spread": "^6.22.0", "babylon": "^6.14.1", "mocha": "^2.3.4", "promise": "^7.0.4", diff --git a/test/regression.js b/test/regression.js new file mode 100644 index 000000000..ac5ecba83 --- /dev/null +++ b/test/regression.js @@ -0,0 +1,25 @@ +/** + * Copyright (c) 2017, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * https://raw.github.com/facebook/regenerator/master/LICENSE file. An + * additional grant of patent rights can be found in the PATENTS file in + * the same directory. + */ + +var assert = require("assert"); + +describe("regressions", function() { + it("should correctly hoist arguments", async function () { + function test(fn) { + return async (...args) => { + return fn(...args); + }; + } + const result = []; + await test((arg1, arg2) => { result.push(arg1, arg2); })(1, "foo"); + + assert.deepEqual(result, [1, "foo"]); + }); +}); diff --git a/test/run.js b/test/run.js index e225f9e29..40c55b50c 100644 --- a/test/run.js +++ b/test/run.js @@ -128,6 +128,31 @@ enqueue(convert, [ "./test/async.es5.js" ]); +function convertWithSpread(es6File, es5File, callback) { + var transformOptions = { + presets:[require("regenerator-preset")], + plugins: [ + require("babel-plugin-transform-es2015-spread"), + require("babel-plugin-transform-es2015-parameters") + ] + }; + + fs.readFile(es6File, "utf-8", function(err, es6) { + if (err) { + return callback(err); + } + + var es5 = require("babel-core").transform(es6, transformOptions).code; + + fs.writeFile(es5File, es5, callback); + }); +} + +enqueue(convertWithSpread, [ + "./test/regression.js", + "./test/regression.es5.js" +]); + enqueue(makeMochaCopyFunction("mocha.js")); enqueue(makeMochaCopyFunction("mocha.css")); @@ -137,11 +162,14 @@ if (!semver.eq(process.version, "0.11.7")) { try { require.resolve("browserify"); // Throws if missing. enqueue(bundle, [ - ["./test/runtime.js", - "./test/tests.es5.js", - "./test/tests-node4.es5.js", - "./test/non-native.es5.js", - "./test/async.es5.js"], + [ + "./test/runtime.js", + "./test/tests.es5.js", + "./test/tests-node4.es5.js", + "./test/non-native.es5.js", + "./test/async.es5.js", + "./test/regression.es5.js" + ], "./test/tests.browser.js" ]); } catch (ignored) { @@ -156,6 +184,7 @@ enqueue("mocha", [ "./test/tests-node4.es5.js", "./test/non-native.es5.js", "./test/async.es5.js", + "./test/regression.es5.js", "./test/tests.transform.js" ]);