remove arguments-to-array helper

This commit is contained in:
Sebastian McKenzie
2014-11-25 23:56:38 +11:00
parent d184bc93b9
commit 1a1e6bc3ba
10 changed files with 27 additions and 81 deletions

View File

@@ -22,7 +22,6 @@ File.declarations = [
"tagged-template-literal",
"interop-require",
"to-array",
"arguments-to-array",
"object-spread",
"has-own",
"slice"
@@ -81,14 +80,11 @@ File.normaliseOptions = function (opts) {
File.prototype.toArray = function (node) {
if (t.isArrayExpression(node)) {
return node;
} else if (t.isIdentifier(node) && node.name === "arguments") {
return t.callExpression(t.memberExpression(this.addDeclaration("slice"), t.identifier("call")), [node]);
} else {
return t.callExpression(this.addDeclaration("to-array"), [node]);
}
var templateName = "to-array";
if (t.isIdentifier(node) && node.name === "arguments") {
templateName = "arguments-to-array";
}
return t.callExpression(this.addDeclaration(templateName), [node]);
};
File.prototype.getModuleFormatter = function (type) {

View File

@@ -1,7 +0,0 @@
(function (args) {
var target = new Array(args.length);
for (var i = 0; i< args.length; i++) {
target[i] = args[i];
}
return target;
})

View File

@@ -8,13 +8,10 @@ exports.Function = function (node, parent, file) {
t.ensureBlock(node);
var call = t.callExpression(
file.addDeclaration("arguments-to-array"),
[t.identifier("arguments")]
);
var call = file.toArray(t.identifier("arguments"));
if (node.params.length) {
call = t.callExpression(t.memberExpression(call, t.identifier("slice")), [t.literal(node.params.length)]);
call.arguments.push(t.literal(node.params.length));
}
call._ignoreAliasFunctions = true;