Class: Opal::Rewriters::Base
- Inherits:
-
Parser::AST::Processor
- Object
- Parser::AST::Processor
- Opal::Rewriters::Base
- Defined in:
- opal/lib/opal/rewriters/base.rb
Direct Known Subclasses
BinaryOperatorAssignment, BlockToIter, BreakFinder, DotJsSyntax, ExplicitWriterReturn, ForRewriter, ForRewriter::LocalVariableAssigns, Hashes::KeyDuplicatesRewriter, JsReservedWords, LogicalOperatorAssignment, OpalEngineCheck, Opal::Rubyspec::FiltersRewriter
Class Method Summary collapse
Instance Method Summary collapse
-
#append_to_body(body, node) ⇒ Object
Appends given +node+ to +body+ node.
-
#prepend_to_body(body, node) ⇒ Object
Prepends given +node+ to +body+ node.
- #s(type, *children) ⇒ Object
Class Method Details
Instance Method Details
#append_to_body(body, node) ⇒ Object
Appends given +node+ to +body+ node.
Supports +body+ to be one of:
- nil - empty body
- s(:begin) / s(:kwbegin) - multiline body
- s(:anything_else) - singleline body
Returns a new body with +node+ injected as a last statement.
52 53 54 55 56 57 58 59 60 |
# File 'opal/lib/opal/rewriters/base.rb', line 52 def append_to_body(body, node) if body.nil? node elsif [:begin, :kwbegin].include?(body.type) body.updated(nil, [*body, node]) else s(:begin, body, node) end end |
#prepend_to_body(body, node) ⇒ Object
Prepends given +node+ to +body+ node.
Supports +body+ to be one of:
- nil - empty body
- s(:begin) / s(:kwbegin) - multiline body
- s(:anything_else) - singleline body
Returns a new body with +node+ injected as a first statement.
33 34 35 36 37 38 39 40 41 |
# File 'opal/lib/opal/rewriters/base.rb', line 33 def prepend_to_body(body, node) if body.nil? node elsif [:begin, :kwbegin].include?(body.type) body.updated(nil, [node, *body]) else s(:begin, node, body) end end |