dead-code.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. dead_code_1: {
  2. options = {
  3. dead_code: true
  4. };
  5. input: {
  6. function f() {
  7. a();
  8. b();
  9. x = 10;
  10. return;
  11. if (x) {
  12. y();
  13. }
  14. }
  15. }
  16. expect: {
  17. function f() {
  18. a();
  19. b();
  20. x = 10;
  21. return;
  22. }
  23. }
  24. }
  25. dead_code_2_should_warn: {
  26. options = {
  27. dead_code: true
  28. };
  29. input: {
  30. function f() {
  31. g();
  32. x = 10;
  33. throw "foo";
  34. // completely discarding the `if` would introduce some
  35. // bugs. UglifyJS v1 doesn't deal with this issue; in v2
  36. // we copy any declarations to the upper scope.
  37. if (x) {
  38. y();
  39. var x;
  40. function g(){};
  41. // but nested declarations should not be kept.
  42. (function(){
  43. var q;
  44. function y(){};
  45. })();
  46. }
  47. }
  48. }
  49. expect: {
  50. function f() {
  51. g();
  52. x = 10;
  53. throw "foo";
  54. var x;
  55. function g(){};
  56. }
  57. }
  58. }
  59. dead_code_constant_boolean_should_warn_more: {
  60. options = {
  61. dead_code : true,
  62. loops : true,
  63. booleans : true,
  64. conditionals : true,
  65. evaluate : true
  66. };
  67. input: {
  68. while (!((foo && bar) || (x + "0"))) {
  69. console.log("unreachable");
  70. var foo;
  71. function bar() {}
  72. }
  73. for (var x = 10; x && (y || x) && (!typeof x); ++x) {
  74. asdf();
  75. foo();
  76. var moo;
  77. }
  78. }
  79. expect: {
  80. var foo;
  81. function bar() {}
  82. // nothing for the while
  83. // as for the for, it should keep:
  84. var x = 10;
  85. var moo;
  86. }
  87. }