Module: Evilution::AST::HeredocSpan Private
- Defined in:
- lib/evilution/ast/heredoc_span.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Computes the byte-length needed for a mutation whose target range contains
heredoc anchors (<<~MARKER / <<-MARKER / <<MARKER).
Prism reports a heredoc anchor's location as the inline range of just
<<~MARKER — the body lines and the closing terminator live in closing_loc
which is on a later line. An operator that builds a byte edit from the
anchor's inline range (e.g. argument_removal using
node.arguments.location) covers the anchor but leaves the body+terminator
in place, producing an orphaned heredoc fragment that the parser rejects.
extend_length walks the supplied AST node for heredoc descendants whose
anchor falls inside [offset, offset + length) and returns a length wide
enough to also cover those descendants' closing_loc.end_offset — so the
mutation's replacement replaces the heredoc body and terminator along with
the anchor.
Class Method Summary collapse
Class Method Details
.extend_length(node:, offset:, length:) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/evilution/ast/heredoc_span.rb', line 25 def extend_length(node:, offset:, length:) return length if node.nil? end_offset = offset + length max_end = end_offset Walker.new(offset, end_offset) do |closing_end| max_end = closing_end if closing_end > max_end end.visit(node) max_end - offset end |