replace slice with a loop in rest parameters

This commit is contained in:
Sebastian McKenzie
2015-01-06 17:05:52 +11:00
parent 7439247095
commit 4c9e39afa1
17 changed files with 58 additions and 33 deletions

View File

@@ -0,0 +1,3 @@
for (var KEY = START; KEY < ARGUMENTS.length; KEY++) {
ARRAY[$__0] = ARGUMENTS[KEY];
}

View File

@@ -1,6 +1,7 @@
var t = require("../../types");
var util = require("../../util");
var t = require("../../types");
exports.Function = function (node, parent, file) {
exports.Function = function (node, parent, file, scope) {
if (!node.rest) return;
var rest = node.rest;
@@ -8,15 +9,19 @@ exports.Function = function (node, parent, file) {
t.ensureBlock(node);
var call = file.toArray(t.identifier("arguments"));
var argsId = t.identifier("arguments");
argsId._ignoreAliasFunctions = true;
if (node.params.length) {
call.arguments.push(t.literal(node.params.length));
}
node.body.body.unshift(
t.variableDeclaration("var", [
t.variableDeclarator(rest, t.arrayExpression([]))
]),
call._ignoreAliasFunctions = true;
node.body.body.unshift(t.variableDeclaration("var", [
t.variableDeclarator(rest, call)
]));
util.template("rest", {
ARGUMENTS: argsId,
START: t.literal(node.params.length),
ARRAY: rest,
KEY: file.generateUidIdentifier("key")
})
);
};