diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2018-03-02 11:22:09 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-02 11:22:09 +0800 |
commit | a75a046abbc1f93fbb2235c99a1fc1d543faf9e9 (patch) | |
tree | 96b5276f6ae63de5038ee133bd30633e80743bc2 /test | |
parent | 38f2b4579fc2c8f7fa4e31b544dc93be9dcb031e (diff) | |
download | tracifyjs-a75a046abbc1f93fbb2235c99a1fc1d543faf9e9.tar.gz tracifyjs-a75a046abbc1f93fbb2235c99a1fc1d543faf9e9.zip |
compress `arguments[index]` (#2967)
- always replace with existing parameter
- only introduce new parameter if `keep_fargs` is disabled
Diffstat (limited to 'test')
-rw-r--r-- | test/compress/arguments.js | 119 | ||||
-rw-r--r-- | test/compress/hoist_props.js | 12 |
2 files changed, 125 insertions, 6 deletions
diff --git a/test/compress/arguments.js b/test/compress/arguments.js new file mode 100644 index 00000000..e8cc690f --- /dev/null +++ b/test/compress/arguments.js @@ -0,0 +1,119 @@ +replace_index: { + options = { + arguments: true, + evaluate: true, + properties: true, + } + input: { + console.log(arguments && 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: { + console.log(arguments && arguments[0]); + (function() { + console.log(arguments[1], arguments[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_keep_fargs: { + options = { + arguments: true, + evaluate: true, + keep_fargs: false, + properties: true, + } + input: { + console.log(arguments && 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: { + console.log(arguments && 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", + ] +} + +modified: { + options = { + arguments: true, + } + input: { + (function(a, b) { + var c = arguments[0]; + var d = arguments[1]; + a = "foo"; + b++; + console.log(a, b, c, d, arguments[0], arguments[1]); + })("bar", 42); + } + expect: { + (function(a, b) { + var c = a; + var d = b; + a = "foo"; + b++; + console.log(a, b, c, d, a, b); + })("bar", 42); + } + expect_stdout: "foo 43 bar 42 foo 43" +} diff --git a/test/compress/hoist_props.js b/test/compress/hoist_props.js index 03867f78..26887af2 100644 --- a/test/compress/hoist_props.js +++ b/test/compress/hoist_props.js @@ -239,14 +239,14 @@ name_collision_2: { input: { var o = { p: 1, - 0: function(x) { + "+": function(x) { return x; }, - 1: function(x) { + "-": function(x) { return x + 1; } }, o__$0 = 2, o__$1 = 3; - console.log(o.p === o.p, o[0](4), o[1](5), o__$0, o__$1); + console.log(o.p === o.p, o["+"](4), o["-"](5), o__$0, o__$1); } expect: { var o_p = 1, @@ -273,14 +273,14 @@ name_collision_3: { input: { var o = { p: 1, - 0: function(x) { + "+": function(x) { return x; }, - 1: function(x) { + "-": function(x) { return x + 1; } }, o__$0 = 2, o__$1 = 3; - console.log(o.p === o.p, o[0](4), o[1](5)); + console.log(o.p === o.p, o["+"](4), o["-"](5)); } expect: { var o_p = 1, |