Class: DeadCodeTerminator::Ast
- Inherits:
-
Object
- Object
- DeadCodeTerminator::Ast
- Defined in:
- lib/dead_code_terminator/ast.rb
Instance Attribute Summary collapse
-
#ast ⇒ Object
readonly
Returns the value of attribute ast.
-
#buf ⇒ Object
readonly
Returns the value of attribute buf.
-
#cond ⇒ Object
readonly
Returns the value of attribute cond.
-
#else_branch ⇒ Object
readonly
Returns the value of attribute else_branch.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#then_branch ⇒ Object
readonly
Returns the value of attribute then_branch.
Instance Method Summary collapse
-
#initialize(env:, ast:) ⇒ Ast
constructor
A new instance of Ast.
- #process ⇒ Object
Constructor Details
#initialize(env:, ast:) ⇒ Ast
Returns a new instance of Ast.
7 8 9 10 11 12 13 14 15 |
# File 'lib/dead_code_terminator/ast.rb', line 7 def initialize(env:, ast:) @env = env @ast = ast @buf = @ast.loc.expression.source_buffer @cond, @then_branch, @else_branch = @ast.children # handle single brackets around: `if (ENV['X'])` @cond = @cond.children[0] if (@cond.type == :begin) && (@cond.children.size == 1) end |
Instance Attribute Details
#ast ⇒ Object (readonly)
Returns the value of attribute ast.
5 6 7 |
# File 'lib/dead_code_terminator/ast.rb', line 5 def ast @ast end |
#buf ⇒ Object (readonly)
Returns the value of attribute buf.
5 6 7 |
# File 'lib/dead_code_terminator/ast.rb', line 5 def buf @buf end |
#cond ⇒ Object (readonly)
Returns the value of attribute cond.
5 6 7 |
# File 'lib/dead_code_terminator/ast.rb', line 5 def cond @cond end |
#else_branch ⇒ Object (readonly)
Returns the value of attribute else_branch.
5 6 7 |
# File 'lib/dead_code_terminator/ast.rb', line 5 def else_branch @else_branch end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
5 6 7 |
# File 'lib/dead_code_terminator/ast.rb', line 5 def env @env end |
#then_branch ⇒ Object (readonly)
Returns the value of attribute then_branch.
5 6 7 |
# File 'lib/dead_code_terminator/ast.rb', line 5 def then_branch @then_branch end |
Instance Method Details
#process ⇒ Object
17 18 19 |
# File 'lib/dead_code_terminator/ast.rb', line 17 def process static_if_branch ? [erase_before_args, erase_after_args] : [] end |