@@ -70,6 +70,10 @@ pub struct ParserState<'src> {
7070 /// Whether we're currently rendering inside a squiggly heredoc's content.
7171 /// Used to mark nested non-squiggly heredocs so they don't get incorrect indentation.
7272 inside_squiggly_heredoc : bool ,
73+ /// When true, strip blank lines that would otherwise be prepended to an extracted comment
74+ /// block. Used during call-chain element offset jumps, where a trailing-dot blank line in
75+ /// the source must not produce an invalid blank line before a leading-dot comment.
76+ suppress_blank_before_comment : bool ,
7377}
7478
7579impl < ' src > ParserState < ' src > {
@@ -106,9 +110,11 @@ impl<'src> ParserState<'src> {
106110 // Update line number and clear out any comments we might have rendered in e.g. an embexpr
107111 //
108112 // (Ignore this comment extraction, we've already rendered them elsewhere)
109- let _ = self
110- . comments_hash
111- . extract_comments_to_line ( self . current_orig_line_number , end_line) ;
113+ let _ = self . comments_hash . extract_comments_to_line (
114+ self . current_orig_line_number ,
115+ end_line,
116+ false ,
117+ ) ;
112118 self . current_orig_line_number = end_line;
113119
114120 let segments = next_ps. render_to_segments ( ) ;
@@ -329,10 +335,11 @@ impl<'src> ParserState<'src> {
329335 be. push_line_number ( line_number) ;
330336 }
331337
332- if let Some ( ( comments, last_comment_line) ) = self
333- . comments_hash
334- . extract_comments_to_line ( self . current_orig_line_number , line_number)
335- {
338+ if let Some ( ( comments, last_comment_line) ) = self . comments_hash . extract_comments_to_line (
339+ self . current_orig_line_number ,
340+ line_number,
341+ self . suppress_blank_before_comment ,
342+ ) {
336343 self . push_comments ( comments) ;
337344 self . current_orig_line_number =
338345 std:: cmp:: max ( self . current_orig_line_number , last_comment_line) ;
@@ -718,6 +725,7 @@ impl<'src> ParserState<'src> {
718725 spaces_after_last_newline : 0 ,
719726 scopes : vec ! [ vec![ ] ] ,
720727 inside_squiggly_heredoc : false ,
728+ suppress_blank_before_comment : false ,
721729 }
722730 }
723731
@@ -775,6 +783,21 @@ impl<'src> ParserState<'src> {
775783 self . insert_user_newlines = false ;
776784 }
777785
786+ pub ( crate ) fn with_user_newlines_disabled < F > ( & mut self , f : F )
787+ where
788+ F : FnOnce ( & mut ParserState < ' src > ) ,
789+ {
790+ let saved_newlines = self . insert_user_newlines ;
791+ let saved_blank = self . suppress_blank_before_comment ;
792+ self . insert_user_newlines = false ;
793+ self . suppress_blank_before_comment = true ;
794+
795+ f ( self ) ;
796+
797+ self . insert_user_newlines = saved_newlines;
798+ self . suppress_blank_before_comment = saved_blank;
799+ }
800+
778801 pub ( crate ) fn last_token_is_a_newline ( & self ) -> bool {
779802 match self . breakable_entry_stack . last ( ) {
780803 Some ( be) => be. last_token_is_a_newline ( ) ,
0 commit comments