Class: Opal::Rewriters::OpalEngineCheck

Inherits:
Base
  • Object
show all
Defined in:
opal/lib/opal/rewriters/opal_engine_check.rb

Constant Summary collapse

RUBY_ENGINE_CHECK =
s(:send, s(:const, nil, :RUBY_ENGINE),
  :==, s(:str, 'opal')
)
RUBY_ENGINE_CHECK_NOT =
s(:send, s(:const, nil, :RUBY_ENGINE),
  :!=, s(:str, 'opal')
)
RUBY_PLATFORM_CHECK =
s(:send, s(:const, nil, :RUBY_PLATFORM),
  :==, s(:str, 'opal')
)
RUBY_PLATFORM_CHECK_NOT =
s(:send, s(:const, nil, :RUBY_PLATFORM),
  :!=, s(:str, 'opal')
)

Constants inherited from Base

Base::DUMMY_LOCATION

Instance Attribute Summary

Attributes inherited from Base

#current_node

Instance Method Summary collapse

Methods inherited from Base

#append_to_body, #begin_with_stmts, #error, #prepend_to_body, #process, #s, s, #stmts_of

Instance Method Details

#on_if(node) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
# File 'opal/lib/opal/rewriters/opal_engine_check.rb', line 8

def on_if(node)
  test, true_body, false_body = *node.children

  if skip_check_present?(test)
    process(true_body || s(:nil))
  elsif skip_check_present_not?(test)
    process(false_body || s(:nil))
  else
    super
  end
end

#skip_check_present?(test) ⇒ Boolean

Returns:

  • (Boolean)

20
21
22
# File 'opal/lib/opal/rewriters/opal_engine_check.rb', line 20

def skip_check_present?(test)
  test == RUBY_ENGINE_CHECK || test == RUBY_PLATFORM_CHECK
end

#skip_check_present_not?(test) ⇒ Boolean

Returns:

  • (Boolean)

24
25
26
# File 'opal/lib/opal/rewriters/opal_engine_check.rb', line 24

def skip_check_present_not?(test)
  test == RUBY_ENGINE_CHECK_NOT || test == RUBY_PLATFORM_CHECK_NOT
end