refer to parent arguments inside arrow functions - fixes #39
This commit is contained in:
@@ -24,3 +24,32 @@ exports.ArrowFunctionExpression = function (node) {
|
||||
return node;
|
||||
}
|
||||
};
|
||||
|
||||
exports.FunctionDeclaration =
|
||||
exports.FunctionExpression = function (node, parent, opts, generateUid) {
|
||||
var hasArguments = false;
|
||||
var id;
|
||||
|
||||
// traverse the function and find all arrow functions
|
||||
traverse(node, function (node) {
|
||||
if (node.type !== "ArrowFunctionExpression") return;
|
||||
|
||||
traverse(node, function (node, parent) {
|
||||
if (node.type === "Identifier" && node.name === "arguments" &&
|
||||
parent.type !== "MemberExpression") {
|
||||
hasArguments = true;
|
||||
id = id || b.identifier(generateUid("arguments"));
|
||||
return id;
|
||||
}
|
||||
}, ["FunctionDeclaration", "FunctionExpression", "ArrowFunctionExpression"]);
|
||||
|
||||
return false;
|
||||
}, ["FunctionDeclaration", "FunctionExpression"]);
|
||||
|
||||
if (hasArguments) {
|
||||
util.ensureBlock(node);
|
||||
node.body.body.unshift(b.variableDeclaration("var", [
|
||||
b.variableDeclarator(id, b.identifier("arguments"))
|
||||
]));
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user