Skip to content

Commit

Permalink
fix(semantic/jsdoc): panic on parsing type_name_comment. (#4632)
Browse files Browse the repository at this point in the history
fixes #4627
  • Loading branch information
rzvxa committed Aug 5, 2024
1 parent 94440ad commit 0d2c41a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions crates/oxc_semantic/src/jsdoc/parser/jsdoc_tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,15 @@ impl<'a> JSDocTag<'a> {
let (type_part, name_comment_content, span_start) =
match utils::find_type_range(self.body_raw) {
Some((t_start, t_end)) => {
// +1 for whitespace
let c_start = self.body_raw.len().min(t_end + 1);
let c_start = {
let mut c_start = t_end;
// +1 if whitespace
if self.body_raw.as_bytes()[c_start] == b' ' {
c_start += 1;
}
c_start
};

(
Some(JSDocTagTypePart::new(
&self.body_raw[t_start..t_end],
Expand Down Expand Up @@ -454,6 +461,7 @@ c7 */",
Some(("n14", "[n14]")),
("- opt", " - opt "),
),
("/** @param {t15}ƒa */", Some(("t15", "{t15}")), Some(("ƒa", "ƒa")), ("", " ")),
] {
let allocator = Allocator::default();
let semantic = build_semantic(&allocator, source_text);
Expand Down

0 comments on commit 0d2c41a

Please sign in to comment.