diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2018-01-03 17:18:38 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-03 17:18:38 +0800 |
commit | 14778e049b12e131fc05ddacff9cda56dfede77d (patch) | |
tree | 61364a11fba69abf8f1362c30937361c071aa157 /test | |
parent | 446fb0198bd737c8d34035cc40932ed24ca83bbb (diff) | |
download | tracifyjs-14778e049b12e131fc05ddacff9cda56dfede77d.tar.gz tracifyjs-14778e049b12e131fc05ddacff9cda56dfede77d.zip |
fix `reduce_vars` on `AST_Defun` (#2708)
Diffstat (limited to 'test')
-rw-r--r-- | test/compress/reduce_vars.js | 238 | ||||
-rw-r--r-- | test/compress/typeof.js | 2 |
2 files changed, 239 insertions, 1 deletions
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index 058e9dde..e370e5be 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -4999,3 +4999,241 @@ var_if: { } } } + +defun_assign: { + options = { + reduce_vars: true, + toplevel: true, + } + input: { + console.log(typeof a); + a = 42; + console.log(typeof a); + function a() {} + console.log(typeof a); + } + expect: { + console.log(typeof a); + a = 42; + console.log(typeof a); + function a() {} + console.log(typeof a); + } + expect_stdout: [ + "function", + "number", + "number", + ] +} + +defun_var_1: { + options = { + evaluate: true, + reduce_vars: true, + toplevel: true, + typeofs: true, + unused: true, + } + input: { + var a = 42, b; + function a() {} + function b() {} + console.log(typeof a, typeof b); + } + expect: { + var a = 42; + function a() {} + console.log(typeof a, "function"); + } + expect_stdout: "number function" +} + +defun_var_2: { + options = { + evaluate: true, + reduce_vars: true, + toplevel: true, + typeofs: true, + unused: true, + } + input: { + function a() {} + function b() {} + var a = 42, b; + console.log(typeof a, typeof b); + } + expect: { + function a() {} + var a = 42; + console.log(typeof a, "function"); + } + expect_stdout: "number function" +} + +defun_var_3: { + options = { + evaluate: true, + reduce_vars: true, + toplevel: true, + typeofs: true, + unused: true, + } + input: { + function a() {} + function b() {} + console.log(typeof a, typeof b); + var a = 42, b; + } + expect: { + function a() {} + console.log(typeof a, "function"); + var a = 42; + } + expect_stdout: "function function" +} + +defun_catch_1: { + options = { + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + function a() {} + try { + throw 42; + } catch (a) { + console.log(a); + } + } + expect: { + try { + throw 42; + } catch (a) { + console.log(a); + } + } + expect_stdout: "42" +} + +defun_catch_2: { + options = { + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + try { + function a() {} + throw 42; + } catch (a) { + console.log(a); + } + } + expect: { + try { + throw 42; + } catch (a) { + console.log(a); + } + } + expect_stdout: "42" +} + +defun_catch_3: { + options = { + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + try { + throw 42; + function a() {} + } catch (a) { + console.log(a); + } + } + expect: { + try { + throw 42; + } catch (a) { + console.log(a); + } + } + expect_stdout: "42" +} + +defun_catch_4: { + options = { + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + try { + throw 42; + } catch (a) { + function a() {} + console.log(a); + } + } + expect: { + try { + throw 42; + } catch (a) { + function a() {} + console.log(a); + } + } + expect_stdout: true +} + +defun_catch_5: { + options = { + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + try { + throw 42; + } catch (a) { + console.log(a); + function a() {} + } + } + expect: { + try { + throw 42; + } catch (a) { + console.log(a); + function a() {} + } + } + expect_stdout: true +} + +defun_catch_6: { + options = { + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + try { + throw 42; + } catch (a) { + console.log(a); + } + function a() {} + } + expect: { + try { + throw 42; + } catch (a) { + console.log(a); + } + } + expect_stdout: "42" +} diff --git a/test/compress/typeof.js b/test/compress/typeof.js index 180e5451..9eaf05e4 100644 --- a/test/compress/typeof.js +++ b/test/compress/typeof.js @@ -100,7 +100,7 @@ typeof_defun_1: { g = 42; console.log("YES"); "function" == typeof g && g(); - h(); + "function" == typeof h && h(); } expect_stdout: [ "YES", |