@@ -2056,8 +2056,7 @@ def visit_interpolated_regular_expression_node(node)
2056
2056
# ^^^^^^^^^^^^
2057
2057
def visit_interpolated_string_node ( node )
2058
2058
if node . opening &.start_with? ( "<<~" )
2059
- bounds ( node . parts . first . location )
2060
- heredoc = visit_heredoc_node ( node . parts , on_string_content ) { |parts , part | on_string_add ( parts , part ) }
2059
+ heredoc = visit_heredoc_string_node ( node )
2061
2060
2062
2061
bounds ( node . location )
2063
2062
on_string_literal ( heredoc )
@@ -2098,8 +2097,7 @@ def visit_interpolated_symbol_node(node)
2098
2097
# ^^^^^^^^^^^^
2099
2098
def visit_interpolated_x_string_node ( node )
2100
2099
if node . opening . start_with? ( "<<~" )
2101
- bounds ( node . parts . first . location )
2102
- heredoc = visit_heredoc_node ( node . parts , on_xstring_new ) { |parts , part | on_xstring_add ( parts , part ) }
2100
+ heredoc = visit_heredoc_x_string_node ( node )
2103
2101
2104
2102
bounds ( node . location )
2105
2103
on_xstring_literal ( heredoc )
@@ -2827,8 +2825,7 @@ def visit_string_node(node)
2827
2825
bounds ( node . location )
2828
2826
on_CHAR ( "?#{ node . content } " )
2829
2827
elsif opening . start_with? ( "<<~" )
2830
- bounds ( node . location )
2831
- heredoc = visit_heredoc_node ( [ node ] , on_string_content ) { |parts , part | on_string_add ( parts , part ) }
2828
+ heredoc = visit_heredoc_string_node ( node . to_interpolated )
2832
2829
2833
2830
bounds ( node . location )
2834
2831
on_string_literal ( heredoc )
@@ -2841,16 +2838,15 @@ def visit_string_node(node)
2841
2838
end
2842
2839
end
2843
2840
2844
- # Visit a string that is expressed using a <<~ heredoc.
2845
- private def visit_heredoc_node ( parts , base )
2841
+ # Ripper gives back the escaped string content but strips out the common
2842
+ # leading whitespace. Prism gives back the unescaped string content and
2843
+ # a location for the escaped string content. Unfortunately these don't
2844
+ # work well together, so here we need to re-derive the common leading
2845
+ # whitespace.
2846
+ private def visit_heredoc_node_whitespace ( parts )
2846
2847
common_whitespace = nil
2847
2848
dedent_next = true
2848
2849
2849
- # Ripper gives back the escaped string content but strips out the common
2850
- # leading whitespace. Prism gives back the unescaped string content and
2851
- # a location for the escaped string content. Unfortunately these don't
2852
- # work well together, so here we need to re-derive the common leading
2853
- # whitespace.
2854
2850
parts . each do |part |
2855
2851
if part . is_a? ( StringNode )
2856
2852
if dedent_next && !( content = part . content ) . chomp . empty?
@@ -2868,7 +2864,14 @@ def visit_string_node(node)
2868
2864
end
2869
2865
end
2870
2866
2871
- if common_whitespace . nil? || common_whitespace == 0
2867
+ common_whitespace || 0
2868
+ end
2869
+
2870
+ # Visit a string that is expressed using a <<~ heredoc.
2871
+ private def visit_heredoc_node ( parts , base )
2872
+ common_whitespace = visit_heredoc_node_whitespace ( parts )
2873
+
2874
+ if common_whitespace == 0
2872
2875
bounds ( parts . first . location )
2873
2876
2874
2877
string = [ ]
@@ -2910,6 +2913,20 @@ def visit_string_node(node)
2910
2913
end
2911
2914
end
2912
2915
2916
+ private def visit_heredoc_string_node ( node )
2917
+ bounds ( node . location )
2918
+ visit_heredoc_node ( node . parts , on_string_content ) do |parts , part |
2919
+ on_string_add ( parts , part )
2920
+ end
2921
+ end
2922
+
2923
+ private def visit_heredoc_x_string_node ( node )
2924
+ bounds ( node . location )
2925
+ visit_heredoc_node ( node . parts , on_xstring_new ) do |parts , part |
2926
+ on_xstring_add ( parts , part )
2927
+ end
2928
+ end
2929
+
2913
2930
# super(foo)
2914
2931
# ^^^^^^^^^^
2915
2932
def visit_super_node ( node )
@@ -3078,8 +3095,7 @@ def visit_x_string_node(node)
3078
3095
bounds ( node . location )
3079
3096
on_xstring_literal ( on_xstring_new )
3080
3097
elsif node . opening . start_with? ( "<<~" )
3081
- bounds ( node . location )
3082
- heredoc = visit_heredoc_node ( [ node ] , on_xstring_new ) { |parts , part | on_xstring_add ( parts , part ) }
3098
+ heredoc = visit_heredoc_x_string_node ( node . to_interpolated )
3083
3099
3084
3100
bounds ( node . location )
3085
3101
on_xstring_literal ( heredoc )
0 commit comments