diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2018-06-21 14:10:37 +0800 |
---|---|---|
committer | alexlamsl <alexlamsl@gmail.com> | 2018-06-24 04:00:21 +0800 |
commit | 766a4147d4891a093b550e958268c48104330b52 (patch) | |
tree | 169df532a88775e8128715aff079821934f4ca9b /test/compress/arguments.js | |
parent | 915c7e234d0788b0ef502e2c6343d513474c390a (diff) | |
download | tracifyjs-766a4147d4891a093b550e958268c48104330b52.tar.gz tracifyjs-766a4147d4891a093b550e958268c48104330b52.zip |
enhance `arguments` (#3193)
fixes #3192
Diffstat (limited to 'test/compress/arguments.js')
-rw-r--r-- | test/compress/arguments.js | 134 |
1 files changed, 127 insertions, 7 deletions
diff --git a/test/compress/arguments.js b/test/compress/arguments.js index e8cc690f..04857441 100644 --- a/test/compress/arguments.js +++ b/test/compress/arguments.js @@ -5,7 +5,8 @@ replace_index: { properties: true, } input: { - console.log(arguments && arguments[0]); + var arguments = []; + console.log(arguments[0]); (function() { console.log(arguments[1], arguments["1"], arguments["foo"]); })("bar", 42); @@ -21,7 +22,8 @@ replace_index: { })("bar", 42); } expect: { - console.log(arguments && arguments[0]); + var arguments = []; + console.log(arguments[0]); (function() { console.log(arguments[1], arguments[1], arguments.foo); })("bar", 42); @@ -45,6 +47,37 @@ replace_index: { ] } +replace_index_strict: { + options = { + arguments: true, + evaluate: true, + properties: true, + reduce_vars: true, + } + input: { + "use strict"; + (function() { + console.log(arguments[1], arguments["1"], arguments["foo"]); + })("bar", 42); + (function(a, b) { + console.log(arguments[1], arguments["1"], arguments["foo"]); + })("bar", 42); + } + expect: { + "use strict"; + (function() { + console.log(arguments[1], arguments[1], arguments.foo); + })("bar", 42); + (function(a, b) { + console.log(b, b, arguments.foo); + })("bar", 42); + } + expect_stdout: [ + "42 42 undefined", + "42 42 undefined", + ] +} + replace_index_keep_fargs: { options = { arguments: true, @@ -53,7 +86,8 @@ replace_index_keep_fargs: { properties: true, } input: { - console.log(arguments && arguments[0]); + var arguments = []; + console.log(arguments[0]); (function() { console.log(arguments[1], arguments["1"], arguments["foo"]); })("bar", 42); @@ -69,7 +103,8 @@ replace_index_keep_fargs: { })("bar", 42); } expect: { - console.log(arguments && arguments[0]); + var arguments = []; + console.log(arguments[0]); (function(argument_0, argument_1) { console.log(argument_1, argument_1, arguments.foo); })("bar", 42); @@ -93,6 +128,38 @@ replace_index_keep_fargs: { ] } +replace_index_keep_fargs_strict: { + options = { + arguments: true, + evaluate: true, + keep_fargs: false, + properties: true, + reduce_vars: true, + } + input: { + "use strict"; + (function() { + console.log(arguments[1], arguments["1"], arguments["foo"]); + })("bar", 42); + (function(a, b) { + console.log(arguments[1], arguments["1"], arguments["foo"]); + })("bar", 42); + } + expect: { + "use strict"; + (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); + } + expect_stdout: [ + "42 42 undefined", + "42 42 undefined", + ] +} + modified: { options = { arguments: true, @@ -101,8 +168,10 @@ modified: { (function(a, b) { var c = arguments[0]; var d = arguments[1]; - a = "foo"; + var a = "foo"; b++; + arguments[0] = "moo"; + arguments[1] *= 2; console.log(a, b, c, d, arguments[0], arguments[1]); })("bar", 42); } @@ -110,10 +179,61 @@ modified: { (function(a, b) { var c = a; var d = b; - a = "foo"; + var a = "foo"; b++; + a = "moo"; + b *= 2; console.log(a, b, c, d, a, b); })("bar", 42); } - expect_stdout: "foo 43 bar 42 foo 43" + expect_stdout: "moo 86 bar 42 moo 86" +} + +modified_strict: { + options = { + arguments: true, + reduce_vars: true, + } + input: { + "use strict"; + (function(a, b) { + var c = arguments[0]; + var d = arguments[1]; + var a = "foo"; + b++; + arguments[0] = "moo"; + arguments[1] *= 2; + console.log(a, b, c, d, arguments[0], arguments[1]); + })("bar", 42); + } + expect: { + "use strict"; + (function(a, b) { + var c = arguments[0]; + var d = arguments[1]; + var a = "foo"; + b++; + arguments[0] = "moo"; + arguments[1] *= 2; + console.log(a, b, c, d, arguments[0], arguments[1]); + })("bar", 42); + } + expect_stdout: "foo 43 bar 42 moo 84" +} + +duplicate_argname: { + options = { + arguments: true, + } + input: { + (function(a, b, a) { + console.log(a, b, arguments[0], arguments[1], arguments[2]); + })("foo", 42, "bar"); + } + expect: { + (function(a, b, a) { + console.log(a, b, arguments[0], b, a); + })("foo", 42, "bar"); + } + expect_stdout: "bar 42 foo 42 bar" } |