change arguments to array to an additional faster helper method
This commit is contained in:
parent
3447204d97
commit
32f8f9e663
@ -1 +0,0 @@
|
||||
var VARIABLE_NAME = SLICE_KEY.call(arguments, SLICE_ARG);
|
||||
@ -1 +0,0 @@
|
||||
var VARIABLE_NAME = SLICE_KEY.call(arguments);
|
||||
@ -1 +0,0 @@
|
||||
SLICE_KEY.call(arguments);
|
||||
7
lib/6to5/templates/arguments-to-array.js
Normal file
7
lib/6to5/templates/arguments-to-array.js
Normal file
@ -0,0 +1,7 @@
|
||||
(function (args) {
|
||||
var target = new Array(args.length);
|
||||
for (var i = 0; i< args.length; i++) {
|
||||
target[i] = args[i];
|
||||
}
|
||||
return target;
|
||||
})
|
||||
9
lib/6to5/templates/object-spread.js
Normal file
9
lib/6to5/templates/object-spread.js
Normal file
@ -0,0 +1,9 @@
|
||||
(function (target, keys) {
|
||||
var target = {};
|
||||
for (var i in target) {
|
||||
if (keys.indexOf(i) >= 0) continue;
|
||||
if (!Object.prototype.hasOwn.call(target)) continue;
|
||||
target[i] = target[i];
|
||||
}
|
||||
return target;
|
||||
})
|
||||
@ -1 +0,0 @@
|
||||
Array.prototype.slice;
|
||||
@ -12,13 +12,18 @@ exports.Function = function (node, parent, file) {
|
||||
|
||||
t.ensureBlock(node);
|
||||
|
||||
var template = util.template(templateName, {
|
||||
SLICE_KEY: file.addDeclaration("slice"),
|
||||
VARIABLE_NAME: rest,
|
||||
SLICE_ARG: t.literal(node.params.length)
|
||||
});
|
||||
var call = t.callExpression(
|
||||
file.addDeclaration("arguments-to-array"),
|
||||
[t.identifier("arguments")]
|
||||
);
|
||||
|
||||
template.declarations[0].init.arguments[0]._ignoreAliasFunctions = true;
|
||||
if (node.params.length) {
|
||||
call = t.callExpression(t.memberExpression(call, t.identifier("slice")), [t.literal(node.params.length)]);
|
||||
}
|
||||
|
||||
node.body.body.unshift(template);
|
||||
call._ignoreAliasFunctions = true;
|
||||
|
||||
node.body.body.unshift(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(rest, call)
|
||||
]));
|
||||
};
|
||||
|
||||
@ -1,6 +1,14 @@
|
||||
"use strict";
|
||||
|
||||
var _slice = Array.prototype.slice;
|
||||
var _argumentsToArray = function (args) {
|
||||
var target = new Array(args.length);
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
target[i] = args[i];
|
||||
}
|
||||
|
||||
return target;
|
||||
};
|
||||
|
||||
var _classProps = function (child, staticProps, instanceProps) {
|
||||
if (staticProps) Object.defineProperties(child, staticProps);
|
||||
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
|
||||
@ -25,11 +33,11 @@ var Test = (function (Foo) {
|
||||
Foo.prototype.test.call(this);
|
||||
foob(Foo);
|
||||
|
||||
Foo.call.apply(Foo, [this].concat(_slice.call(arguments)));
|
||||
Foo.call.apply(Foo, [this, "test"].concat(_slice.call(arguments)));
|
||||
Foo.call.apply(Foo, [this].concat(_argumentsToArray(arguments)));
|
||||
Foo.call.apply(Foo, [this, "test"].concat(_argumentsToArray(arguments)));
|
||||
|
||||
Foo.prototype.test.call.apply(Foo.prototype, [this].concat(_slice.call(arguments)));
|
||||
Foo.prototype.test.call.apply(Foo.prototype, [this, "test"].concat(_slice.call(arguments)));
|
||||
Foo.prototype.test.call.apply(Foo.prototype, [this].concat(_argumentsToArray(arguments)));
|
||||
Foo.prototype.test.call.apply(Foo.prototype, [this, "test"].concat(_argumentsToArray(arguments)));
|
||||
};
|
||||
|
||||
_extends(Test, Foo);
|
||||
@ -39,8 +47,8 @@ var Test = (function (Foo) {
|
||||
writable: true,
|
||||
value: function () {
|
||||
Foo.foo.call(this);
|
||||
Foo.foo.call.apply(Foo.foo, [this].concat(_slice.call(arguments)));
|
||||
Foo.foo.call.apply(Foo.foo, [this, "test"].concat(_slice.call(arguments)));
|
||||
Foo.foo.call.apply(Foo.foo, [this].concat(_argumentsToArray(arguments)));
|
||||
Foo.foo.call.apply(Foo.foo, [this, "test"].concat(_argumentsToArray(arguments)));
|
||||
}
|
||||
}
|
||||
}, {
|
||||
@ -48,8 +56,8 @@ var Test = (function (Foo) {
|
||||
writable: true,
|
||||
value: function () {
|
||||
Foo.prototype.test.call(this);
|
||||
Foo.prototype.test.call.apply(Foo.prototype.test, [this].concat(_slice.call(arguments)));
|
||||
Foo.prototype.test.call.apply(Foo.prototype.test, [this, "test"].concat(_slice.call(arguments)));
|
||||
Foo.prototype.test.call.apply(Foo.prototype.test, [this].concat(_argumentsToArray(arguments)));
|
||||
Foo.prototype.test.call.apply(Foo.prototype.test, [this, "test"].concat(_argumentsToArray(arguments)));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -1,6 +1,15 @@
|
||||
"use strict";
|
||||
|
||||
var _slice = Array.prototype.slice;
|
||||
var concat = function () {
|
||||
var arrs = _slice.call(arguments);
|
||||
var _arguments = arguments;
|
||||
var _argumentsToArray = function (args) {
|
||||
var target = new Array(args.length);
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
target[i] = args[i];
|
||||
}
|
||||
|
||||
return target;
|
||||
};
|
||||
|
||||
var concat = function () {
|
||||
var arrs = _argumentsToArray(_arguments);
|
||||
};
|
||||
|
||||
@ -1,10 +1,18 @@
|
||||
"use strict";
|
||||
|
||||
var _slice = Array.prototype.slice;
|
||||
var _argumentsToArray = function (args) {
|
||||
var target = new Array(args.length);
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
target[i] = args[i];
|
||||
}
|
||||
|
||||
return target;
|
||||
};
|
||||
|
||||
var t = function (f) {
|
||||
var items = _slice.call(arguments, 1);
|
||||
var items = _argumentsToArray(arguments).slice(1);
|
||||
};
|
||||
|
||||
function t(f) {
|
||||
var items = _slice.call(arguments, 1);
|
||||
var items = _argumentsToArray(arguments).slice(1);
|
||||
}
|
||||
|
||||
@ -1,10 +1,18 @@
|
||||
"use strict";
|
||||
|
||||
var _slice = Array.prototype.slice;
|
||||
var _argumentsToArray = function (args) {
|
||||
var target = new Array(args.length);
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
target[i] = args[i];
|
||||
}
|
||||
|
||||
return target;
|
||||
};
|
||||
|
||||
var t = function () {
|
||||
var items = _slice.call(arguments);
|
||||
var items = _argumentsToArray(arguments);
|
||||
};
|
||||
|
||||
function t() {
|
||||
var items = _slice.call(arguments);
|
||||
var items = _argumentsToArray(arguments);
|
||||
}
|
||||
|
||||
@ -1,8 +1,16 @@
|
||||
"use strict";
|
||||
|
||||
var _slice = Array.prototype.slice;
|
||||
var _argumentsToArray = function (args) {
|
||||
var target = new Array(args.length);
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
target[i] = args[i];
|
||||
}
|
||||
|
||||
return target;
|
||||
};
|
||||
|
||||
function foo() {
|
||||
return bar.apply(null, ["test"].concat(_slice.call(arguments)));
|
||||
return bar.apply(null, ["test"].concat(_argumentsToArray(arguments)));
|
||||
}
|
||||
|
||||
function bar(one, two, three) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
function foo() {
|
||||
var test = customNamespace.slice.call(arguments);
|
||||
var test = customNamespace.argumentsToArray(arguments);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
function foo() {
|
||||
var test = to5Runtime.slice.call(arguments);
|
||||
var test = to5Runtime.argumentsToArray(arguments);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user