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:
parent
88d57b58a4
commit
59ea034df2
@ -107,9 +107,17 @@ function hasRest(node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function optimiseIndexGetter(path, argsId, offset) {
|
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({
|
path.parentPath.replaceWith(loadRest({
|
||||||
ARGUMENTS: argsId,
|
ARGUMENTS: argsId,
|
||||||
INDEX: t.numericLiteral(path.parent.property.value + offset)
|
INDEX: index,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
var t = function (f) {
|
var t = function (f) {
|
||||||
arguments[0];
|
arguments.length <= 1 ? undefined : arguments[1];
|
||||||
arguments[arguments.length - 1];
|
arguments.length <= arguments.length - 1 - 1 + 1 ? undefined : arguments[arguments.length - 1 - 1 + 1];
|
||||||
};
|
};
|
||||||
|
|
||||||
function t(f) {
|
function t(f) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user