fix parameters after defaults in arrow functions refering to the wrong arguments - fixes #2682

This commit is contained in:
Sebastian McKenzie 2015-10-30 17:39:57 +00:00
parent e440fef815
commit 5c7f88a5fb
3 changed files with 12 additions and 4 deletions

View File

@ -2,4 +2,6 @@ var some = (count = "30") => {
console.log("count", count);
};
some();
var collect = (since = 0, userid) => {
console.log(userid);
};

View File

@ -4,4 +4,10 @@ var some = function () {
console.log("count", count);
};
some();
var collect = function () {
let since = arguments.length <= 0 || arguments[0] === undefined ? 0 : arguments[0];
let userid = arguments[1];
console.log(userid);
};

View File

@ -16,7 +16,7 @@ let buildDefaultParamAssign = template(`
`);
let buildCutOff = template(`
let $0 = arguments[$1];
let $0 = $1[$2];
`);
function hasDefaults(node) {
@ -131,7 +131,7 @@ export let visitor = {
let param = node.params[i];
if (param._isDefaultPlaceholder) continue;
let declar = buildCutOff(param, t.numberLiteral(i));
let declar = buildCutOff(param, argsIdentifier, t.numberLiteral(i));
declar._blockHoist = node.params.length - i;
body.push(declar);
}