Support expressions in rest arg access

The current implementation assumes a numeric literal although it just
checks the base type.
This commit is contained in:
Amjad Masad 2016-01-06 17:07:05 -08:00
parent 88d57b58a4
commit 59ea034df2
2 changed files with 11 additions and 3 deletions

View File

@ -107,9 +107,17 @@ function hasRest(node) {
}
function optimiseIndexGetter(path, argsId, offset) {
let index;
if (t.isNumericLiteral(path.parent.property)) {
index = t.numericLiteral(path.parent.property.value + offset);
} else {
index = t.binaryExpression("+", path.parent.property, t.numericLiteral(offset));
}
path.parentPath.replaceWith(loadRest({
ARGUMENTS: argsId,
INDEX: t.numericLiteral(path.parent.property.value + offset)
INDEX: index,
}));
}

View File

@ -1,6 +1,6 @@
var t = function (f) {
arguments[0];
arguments[arguments.length - 1];
arguments.length <= 1 ? undefined : arguments[1];
arguments.length <= arguments.length - 1 - 1 + 1 ? undefined : arguments[arguments.length - 1 - 1 + 1];
};
function t(f) {