Class: Johnson::Visitors::EcmaVisitor

Inherits:
Object
  • Object
show all
Defined in:
lib/johnson/ext.rb

Instance Method Summary collapse

Instance Method Details

#visit_FallThrough(o) ⇒ Object



33
34
35
# File 'lib/johnson/ext.rb', line 33

def visit_FallThrough(o)
  o.value
end

#visit_SourceElements(o) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/johnson/ext.rb', line 13

def visit_SourceElements(o)
  newline = o.value.length > 0 ? "\n" : ' '
  (@depth == 0 ? '' : "{#{newline}") +
    indent {
      o.value.map { |x|
        code = x.accept(self)
        semi = case x
               when Nodes::FallThrough
                ""
               when Nodes::Function, Nodes::While, Nodes::If, Nodes::Try, Nodes::Switch, Nodes::Case, Nodes::Default, Nodes::For, Nodes::ForIn
                 code =~ /\}\Z/ ? '' : ';'
               else
                 ';'
               end
        "#{indent}#{code}#{semi}"
      }.join("\n")
    } +
    (@depth == 0 ? '' : "#{newline}}")
end