File: rewriter.rb

package info (click to toggle)
ruby-whitequark-parser 3.3.10.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,848 kB
  • sloc: yacc: 40,706; ruby: 20,588; makefile: 12; sh: 8
file content (20 lines) | stat: -rw-r--r-- 680 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# frozen_string_literal: true

class Rewriter < Parser::Rewriter
  def on_if(node)
    # Crude, totally-not-usable-in-the-real-world code to remove optional
    # parens from control keywords.
    #
    # In a perfect test scenario we'd simply make this a no-op, to demonstrate
    # that the bug happens when any rewriter is loaded regardless of whether it
    # actually changes anything but that makes assertions much harder to get
    # right.  It's much easier to just show that the file did, or did not
    # get changed.
    if node.children[0].type == :begin
      replace node.children[0].loc.begin, ' '
      remove node.children[0].loc.end
    end

    super
  end
end