class Prism::ParseResult::Newlines
variable on every node if we don’t need it.
that case. We do that to avoid storing the extra ‘@newline` instance
re-opening of the various nodes in this file will only be performed in
This file is autoloaded only when `mark_newlines!` is called, so the
newlines for JRuby/TruffleRuby.
MarkNewlinesVisitor, since that visitor is responsible for marking the
Note that the logic in this file should be kept in sync with the Java
we find in the tree that are on those lines.
come back from the parser. We assign these offsets to the first nodes that
In order to keep track of the newlines, we have a list of offsets that
* nodes that are children of statements lists
* unless statements
* if statements
event are:
expression on a new line. The types of expressions that can trigger this
The :line tracepoint event gets fired whenever the Ruby VM encounters an
def initialize(lines)
def initialize(lines) # @type var lines: Integer @lines = Array.new(1 + lines, false) end
def visit_block_node(node)
def visit_block_node(node) old_lines = @lines @lines = Array.new(old_lines.size, false) begin super(node) ensure @lines = old_lines end end
def visit_if_node(node)
def visit_if_node(node) node.newline_flag!(@lines) super(node) end
def visit_statements_node(node)
def visit_statements_node(node) node.body.each do |child| child.newline_flag!(@lines) end super(node) end