From 0d2c41a2cb532c77dbe83d60387f58ae0a5f082c Mon Sep 17 00:00:00 2001 From: rzvxa <3788964+rzvxa@users.noreply.github.com> Date: Mon, 5 Aug 2024 01:17:53 +0000 Subject: [PATCH] fix(semantic/jsdoc): panic on parsing `type_name_comment`. (#4632) fixes #4627 --- crates/oxc_semantic/src/jsdoc/parser/jsdoc_tag.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/oxc_semantic/src/jsdoc/parser/jsdoc_tag.rs b/crates/oxc_semantic/src/jsdoc/parser/jsdoc_tag.rs index 2eea5187b7941..2fde414755287 100644 --- a/crates/oxc_semantic/src/jsdoc/parser/jsdoc_tag.rs +++ b/crates/oxc_semantic/src/jsdoc/parser/jsdoc_tag.rs @@ -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], @@ -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);