From 6696d5fcf4a1f2fac7e5c371224037abb6d9ae9f Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Fri, 31 Oct 2014 11:42:09 +1100 Subject: [PATCH 1/2] fix rest parameters in arrow functions containing wrong arguments reference - fixes #11 --- lib/6to5/transformers/_alias-functions.js | 2 ++ lib/6to5/transformers/rest-parameters.js | 9 +++++++-- .../rest-parameters/arrow-functions/actual.js | 3 +++ .../rest-parameters/arrow-functions/expected.js | 5 +++++ 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/transformation/rest-parameters/arrow-functions/actual.js create mode 100644 test/fixtures/transformation/rest-parameters/arrow-functions/expected.js diff --git a/lib/6to5/transformers/_alias-functions.js b/lib/6to5/transformers/_alias-functions.js index 7021c28efe..b31a148bc2 100644 --- a/lib/6to5/transformers/_alias-functions.js +++ b/lib/6to5/transformers/_alias-functions.js @@ -35,6 +35,8 @@ var go = function (getBody, node, file) { } } + if (node._ignoreAliasFunctions) return; + var getId; if (node.type === "Identifier" && node.name === "arguments") { diff --git a/lib/6to5/transformers/rest-parameters.js b/lib/6to5/transformers/rest-parameters.js index 9ad33b58c4..43046d40db 100644 --- a/lib/6to5/transformers/rest-parameters.js +++ b/lib/6to5/transformers/rest-parameters.js @@ -11,9 +11,14 @@ exports.Function = function (node, parent, file) { if (node.params.length) templateName += "-arg"; util.ensureBlock(node); - node.body.body.unshift(util.template(templateName, { + + var template = util.template(templateName, { SLICE_KEY: file.addDeclaration("slice"), VARIABLE_NAME: rest, SLICE_ARG: b.literal(node.params.length) - })); + }); + + template.declarations[0].init.arguments[0]._ignoreAliasFunctions = true; + + node.body.body.unshift(template); }; diff --git a/test/fixtures/transformation/rest-parameters/arrow-functions/actual.js b/test/fixtures/transformation/rest-parameters/arrow-functions/actual.js new file mode 100644 index 0000000000..4a130fad8d --- /dev/null +++ b/test/fixtures/transformation/rest-parameters/arrow-functions/actual.js @@ -0,0 +1,3 @@ +var concat = (...arrs) => { + +}; diff --git a/test/fixtures/transformation/rest-parameters/arrow-functions/expected.js b/test/fixtures/transformation/rest-parameters/arrow-functions/expected.js new file mode 100644 index 0000000000..ede93ea6e7 --- /dev/null +++ b/test/fixtures/transformation/rest-parameters/arrow-functions/expected.js @@ -0,0 +1,5 @@ +"use strict"; +var _slice = Array.prototype.slice; +var concat = function () { + var arrs = _slice.call(arguments); +}; From 6f8cbf0ad11f7d5579a97a25e30cb076cc54441e Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Fri, 31 Oct 2014 11:43:36 +1100 Subject: [PATCH 2/2] v1.10.8 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d93e6307e2..a1dab4a3be 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "6to5", "description": "Turn ES6 code into readable vanilla ES5 with source maps", - "version": "1.10.7", + "version": "1.10.8", "author": "Sebastian McKenzie ", "homepage": "https://github.com/sebmck/6to5", "repository": {