}
function is_arguments(def) {
- if (def.name != "arguments") return false;
- if (!def.scope.uses_arguments) return false;
- var orig = def.orig;
- return orig.length == 1 && orig[0] instanceof AST_SymbolFunarg;
+ return def.name == "arguments" && def.scope.uses_arguments;
}
function is_funarg(def) {
}
if (!sym) {
sym = self.def_global(node);
- } else if (name == "arguments"
- && sym.orig[0] instanceof AST_SymbolFunarg
- && !(sym.orig[1] instanceof AST_SymbolFunarg)
- && !(sym.scope instanceof AST_Arrow)) {
+ } else if (name == "arguments" && is_arguments(sym)) {
var parent = tw.parent();
if (parent instanceof AST_Assign && parent.left === node
|| parent instanceof AST_Unary && unary_side_effects[parent.operator]) {
node.reference(options);
return true;
}
+ if (node instanceof AST_VarDef) {
+ if (node.value && node.name.name == "arguments") {
+ var sym = node.name.scope.resolve().find_variable("arguments");
+ if (sym && is_arguments(sym)) sym.scope.uses_arguments = 3;
+ }
+ return;
+ }
});
self.walk(tw);
}
}));
+ function is_arguments(sym) {
+ return sym.orig[0] instanceof AST_SymbolFunarg
+ && !(sym.orig[1] instanceof AST_SymbolFunarg || sym.orig[2] instanceof AST_SymbolFunarg)
+ && !(sym.scope instanceof AST_Arrow);
+ }
+
function redefine(node, scope) {
var name = node.name;
var old_def = node.thedef;
var arguments;
console.log(arguments[1], arguments["1"], arguments["foo"]);
})("bar", 42);
+ (function() {
+ var arguments = {
+ 1: "foo",
+ foo: "bar",
+ };
+ console.log(arguments[1], arguments["1"], arguments["foo"]);
+ })("bar", 42);
}
expect: {
var arguments = [];
(function(arguments) {
console.log(arguments[1], arguments[1], arguments.foo);
})("bar", 42);
- (function() {
+ (function(argument_0, argument_1) {
var arguments;
+ console.log(argument_1, argument_1, arguments.foo);
+ })("bar", 42);
+ (function() {
+ var arguments = {
+ 1: "foo",
+ foo: "bar",
+ };
console.log(arguments[1], arguments[1], arguments.foo);
})("bar", 42);
}
"42 42 undefined",
"a a undefined",
"42 42 undefined",
+ "foo foo bar",
]
}
}
expect_stdout: "PASS"
}
+
+issue_4480: {
+ options = {
+ evaluate: true,
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ var a = function f(b) {
+ b = "FAIL";
+ arguments[0] = "PASS";
+ var arguments = 0;
+ console.log(b);
+ }(a);
+ }
+ expect: {
+ var a = function(b) {
+ b = "FAIL";
+ arguments[0] = "PASS";
+ var arguments = 0;
+ console.log(b);
+ }(a);
+ }
+ expect_stdout: "PASS"
+}
]
}
-replace_index: {
- options = {
- arguments: true,
- evaluate: true,
- keep_fargs: false,
- properties: true,
- }
- input: {
- var arguments = [];
- console.log(arguments[0]);
- (function() {
- console.log(arguments[1], arguments["1"], arguments["foo"]);
- })("bar", 42);
- (function(a, b) {
- console.log(arguments[1], arguments["1"], arguments["foo"]);
- })("bar", 42);
- (function(arguments) {
- console.log(arguments[1], arguments["1"], arguments["foo"]);
- })("bar", 42);
- (function() {
- var arguments;
- console.log(arguments[1], arguments["1"], arguments["foo"]);
- })("bar", 42);
- }
- expect: {
- var arguments = [];
- console.log(arguments[0]);
- (function(argument_0, argument_1) {
- console.log(argument_1, argument_1, arguments.foo);
- })("bar", 42);
- (function(a, b) {
- console.log(b, b, arguments.foo);
- })("bar", 42);
- (function(arguments) {
- console.log(arguments[1], arguments[1], arguments.foo);
- })("bar", 42);
- (function() {
- var arguments;
- console.log(arguments[1], arguments[1], arguments.foo);
- })("bar", 42);
- }
- expect_stdout: [
- "undefined",
- "42 42 undefined",
- "42 42 undefined",
- "a a undefined",
- "42 42 undefined",
- ]
-}
-
replace_index_strict: {
options = {
arguments: true,