diff --git a/lib/6to5/transformation/transform.js b/lib/6to5/transformation/transform.js index d7006f32ce..76e92a5e25 100644 --- a/lib/6to5/transformation/transform.js +++ b/lib/6to5/transformation/transform.js @@ -72,6 +72,7 @@ _.each({ propertyMethodAssignment: require("./transformers/es6-property-method-assignment"), computedPropertyNames: require("./transformers/es6-computed-property-names"), defaultParameters: require("./transformers/es6-default-parameters"), + restParameters: require("./transformers/es6-rest-parameters"), destructuring: require("./transformers/es6-destructuring"), forOf: require("./transformers/es6-for-of"), unicodeRegex: require("./transformers/es6-unicode-regex"), @@ -84,7 +85,6 @@ _.each({ _blockHoist: require("./transformers/_block-hoist"), generators: require("./transformers/es6-generators"), - restParameters: require("./transformers/es6-rest-parameters"), protoToAssign: require("./transformers/optional-proto-to-assign"), diff --git a/lib/6to5/transformation/transformers/es6-rest-parameters.js b/lib/6to5/transformation/transformers/es6-rest-parameters.js index 89bafc063a..dac44731c0 100644 --- a/lib/6to5/transformation/transformers/es6-rest-parameters.js +++ b/lib/6to5/transformation/transformers/es6-rest-parameters.js @@ -41,6 +41,22 @@ exports.Function = function (node, parent, scope, context, file) { ); } + // support patterns + if (t.isPattern(rest)) { + var pattern = rest; + rest = file.generateUidIdentifier("ref", scope); + + // let the destructuring transformer handle this + var restDeclar = t.variableDeclaration("var", [ + t.variableDeclarator(pattern, rest) + ]); + + // retain evaluation position + restDeclar._blockHoist = node.params.length + 1; + + node.body.body.unshift(restDeclar); + } + node.body.body.unshift( util.template("rest", { ARGUMENTS: argsId,