No commit activity in last 3 years
No release in over 3 years
Statically remove dead conditional branches, acts like webpack's DefinePlugin and minifier
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 2.5.0.0
 Project Readme

DeadCodeTerminator

ci gem codecov

This acts like webpack's DefinePlugin with minification pass. It allows to eliminate dead code statically, which can be required by regulations.

value = if ENV['FLAG']
  :then_branch
else
  value2 = unless ENV['PRODUCTION']
    :then_branch
  else
    ENV['RUNTIME'] ? :else1 : :else2
  end
end
# returns a valid ruby code string back with statically evaluated conditions
DeadCodeTerminator.strip(string, env: { "PRODUCTION" => true, "FLAG" => false })
value = 


  value2 = 


    ENV['RUNTIME'] ? :else1 : :else2

 

Note: it keeps precise code locations (including whitespaces and line-breaks). So if you have hotfix patches from upstream - they'll be applied without conflicts. Backtrace line numbers are also preserved and can point to original code.

Other examples can be found in specs

TODO

  • builtin file tree processing

License

The gem is available as open source under the terms of the MIT License.