Class: DeadCodeTerminator::Ast

Inherits:
Object
  • Object
show all
Defined in:
lib/dead_code_terminator/ast.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#astObject (readonly)

Returns the value of attribute ast.



5
6
7
# File 'lib/dead_code_terminator/ast.rb', line 5

def ast
  @ast
end

#bufObject (readonly)

Returns the value of attribute buf.



5
6
7
# File 'lib/dead_code_terminator/ast.rb', line 5

def buf
  @buf
end

#condObject (readonly)

Returns the value of attribute cond.



5
6
7
# File 'lib/dead_code_terminator/ast.rb', line 5

def cond
  @cond
end

#else_branchObject (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

#envObject (readonly)

Returns the value of attribute env.



5
6
7
# File 'lib/dead_code_terminator/ast.rb', line 5

def env
  @env
end

#then_branchObject (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

#processObject



17
18
19
# File 'lib/dead_code_terminator/ast.rb', line 17

def process
  static_if_branch ? [erase_before_args, erase_after_args] : []
end