Repository: swc-project/swc
File: crates/swc_ecma_parser/src/lexer/mod.rs (Rust)

Code before:
                                pos_offset += 2
                            }
                        }
                        true
                    }
                    b'*' => {
                        let bytes = self.input().as_str().as_bytes();
                        if bytes.get(pos_offset + 1) == Some(&b'/') {
                            // Consume "*/"
                            pos_offset += 2;

                            // Decide trailing / leading
                            let mut is_for_next =
                                had_line_break_before_last || !self.state().can_have_trailing_comment();

                            // If next char is ';' without newline, treat as trailing
                            if !had_line_break_before_last && bytes.get(pos_offset) == Some(&b';') {
                                is_for_next = false;
                            }

                            if self.comments_buffer().is_some() {
                                let s = unsafe {
                                    let cur = self.input().cur_pos();
                                    // Safety: We got slice_start and end from self.input so those are
                                    // valid.
                                    let s = self.input_mut().slice(slice_start, BytePos((pos_offset - 2) as u32));
                                    self.input_mut().reset_to(cur);
                                    s
                                };
                                let cmt = Comment {
                                    kind: CommentKind::Block,
                                    span: Span::new_with_checked(start, BytePos(pos_offset as u32)),
                                    text: self.atom(s),
                                };

                                if is_for_next {
                                    self.comments_buffer_mut().unwrap().push_pending(cmt);
                                } else {
                                    let pos = self.state().prev_hi();
                                    self.comments_buffer_mut()
                                        .unwrap()
                                        .push_comment(BufferedComment {
                                            kind: BufferedCommentKind::Trailing,
                                            pos,
                                            comment: cmt,
                                        });
                                }
                            }

                            false
                        } else {

Review comment (suggestion):
The `slice` method expects absolute `BytePos` values, but `pos_offset` is a relative offset from the current position. This should be `slice_start + BytePos((pos_offset - 2) as u32)` to correctly calculate the end position of the comment text.
```suggestion
                                    let s = self.input_mut().slice(slice_start, slice_start + BytePos((pos_offset - 2) as u32));
```

Code after:
                                pos_offset += 2;
                            }
                        }
                        true
                    }
                    b'*' => {
                        let bytes = self.input().as_str().as_bytes();
                        if bytes.get(pos_offset + 1) == Some(&b'/') {
                            // Consume "*/"
                            pos_offset += 2;

                            // Decide trailing / leading
                            let mut is_for_next =
                                had_line_break_before_last || !self.state().can_have_trailing_comment();

                            // If next char is ';' without newline, treat as trailing
                            if !had_line_break_before_last && bytes.get(pos_offset) == Some(&b';') {
                                is_for_next = false;
                            }

                            if self.comments_buffer().is_some() {
                                let s = unsafe {
                                    let cur = self.input().cur_pos();
                                    // Safety: We got slice_start and end from self.input so those are
                                    // valid.
                                    let s = self.input_mut().slice(slice_start, slice_start + BytePos((pos_offset - 2) as u32));
                                    self.input_mut().reset_to(cur);
                                    s
                                };
                                let cmt = Comment {
                                    kind: CommentKind::Block,
                                    span: Span::new_with_checked(start, slice_start + BytePos(pos_offset as u32)),
                                    text: self.atom(s),
                                };

                                if is_for_next {
                                    self.comments_buffer_mut().unwrap().push_pending(cmt);
                                } else {
                                    let pos = self.state().prev_hi();
                                    self.comments_buffer_mut()
                                        .unwrap()
                                        .push_comment(BufferedComment {
                                            kind: BufferedCommentKind::Trailing,
                                            pos,
                                            comment: cmt,
                                        });
                                }
                            }

                            false
                        } else {