replace slice with a loop in rest parameters
This commit is contained in:
3
lib/6to5/transformation/templates/rest.js
Normal file
3
lib/6to5/transformation/templates/rest.js
Normal file
@@ -0,0 +1,3 @@
|
||||
for (var KEY = START; KEY < ARGUMENTS.length; KEY++) {
|
||||
ARRAY[$__0] = ARGUMENTS[KEY];
|
||||
}
|
||||
@@ -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")
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user