Class: TEALrb::Rewriters::CommentRewriter

Inherits:
Rewriter
  • Object
show all
Defined in:
lib/tealrb/rewriters.rb

Instance Attribute Summary

Attributes inherited from Rewriter

#contract

Instance Method Summary collapse

Methods inherited from Rewriter

#rewrite

Instance Method Details

#process(_) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/tealrb/rewriters.rb', line 17

def process(_)
  @comments.each do |comment|
    line = @source_rewriter.source_buffer.source_lines[comment.loc.expression.line - 1].strip

    next unless comment.inline? && comment.text[%r{^#\s*//}]

    inline_comment = line[/^#/].nil?
    content = comment.text.sub('# ', '')
    content.sub!('//', '')

    replace comment.loc.expression, "; comment(%q(#{content}), inline: #{inline_comment})"
  end
end