Safely transform all usages of rest arguments
This commit is contained in:
@@ -121,23 +121,11 @@ export let visitor = {
|
||||
argsId._shadowedFunctionLiteral = path;
|
||||
|
||||
function optimiseCandidate(parent, parentPath, offset) {
|
||||
if (t.isReturnStatement(parentPath.parent) || t.isIdentifier(parentPath.parent.id) || t.isIdentifier(parentPath.parent.left)) {
|
||||
if (parent.property) {
|
||||
parentPath.replaceWith(loadRest({
|
||||
ARGUMENTS: argsId,
|
||||
INDEX: t.numericLiteral(parent.property.value + offset)
|
||||
}));
|
||||
} else {
|
||||
if (offset === 0) return;
|
||||
let newExpr;
|
||||
let prop = parent.property;
|
||||
|
||||
if (t.isLiteral(prop)) {
|
||||
prop.value += offset;
|
||||
prop.raw = String(prop.value);
|
||||
} else { // UnaryExpression, BinaryExpression
|
||||
newExpr = t.binaryExpression("+", prop, t.numericLiteral(offset));
|
||||
parent.property = newExpr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ function t(f, ...items) {
|
||||
function u(f, g, ...items) {
|
||||
var x = f;
|
||||
var y = g;
|
||||
x = items[0];
|
||||
y = items[1];
|
||||
x[12] = items[0];
|
||||
y.prop = items[1];
|
||||
var z = items[2] | 0 || 12;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ function t(f) {
|
||||
function u(f, g) {
|
||||
var x = f;
|
||||
var y = g;
|
||||
x = arguments.length <= 2 ? undefined : arguments[2];
|
||||
y = arguments.length <= 3 ? undefined : arguments[3];
|
||||
x[12] = arguments.length <= 2 ? undefined : arguments[2];
|
||||
y.prop = arguments.length <= 3 ? undefined : arguments[3];
|
||||
var z = (arguments.length <= 4 ? undefined : arguments[4]) | 0 || 12;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user