diff --git a/lib/6to5/transformation/transformers/es6-rest-parameters.js b/lib/6to5/transformation/transformers/es6-rest-parameters.js index aab79e8103..68dfdd0ae8 100644 --- a/lib/6to5/transformation/transformers/es6-rest-parameters.js +++ b/lib/6to5/transformation/transformers/es6-rest-parameters.js @@ -19,15 +19,17 @@ exports.Function = function (node, parent, file) { var len = file.generateUidIdentifier("len"); var arrKey = key; + var arrLen = len; if (node.params.length) { // this method has additional params, so we need to subtract // the index of the current argument position from the // position in the array that we want to populate arrKey = t.binaryExpression("-", key, start); - } - var arrLen = len; - if (node.params.length) { + // we need to work out the size of the array that we're + // going to store all the rest parameters in, if there + // are less arguments than params then the array can be + // constructed with <1 which will cause an error arrLen = t.conditionalExpression( t.binaryExpression(">", len, start), t.binaryExpression("-", len, start),