Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions crates/oxc_semantic/src/jsdoc/parser/jsdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ impl<'a> JSDoc<'a> {
mod test {
use oxc_allocator::Allocator;
use oxc_parser::Parser;
use oxc_span::SourceType;
use oxc_span::{SourceType, Span};

use crate::{Semantic, SemanticBuilder};
use crate::{Semantic, SemanticBuilder, jsdoc::parser::jsdoc_parts::JSDocCommentPart};

fn build_semantic<'a>(allocator: &'a Allocator, source_text: &'a str) -> Semantic<'a> {
let source_type = SourceType::default();
Expand Down Expand Up @@ -323,4 +323,25 @@ line2
let tag = tags.next().unwrap();
assert_eq!(tag.kind.parsed(), "example");
}

#[test]
fn parses_issue_11992() {
let allocator = Allocator::default();
let semantic = build_semantic(
&allocator,
"/**@property [
*/",
);
let jsdoc = semantic.jsdoc().iter_all().next().unwrap();

let mut tags = jsdoc.tags().iter();
assert_eq!(tags.len(), 1);

let tag = tags.next().unwrap();
assert_eq!(
tag.type_name_comment(),
(None, None, JSDocCommentPart::new(" [\n", Span::new(12, 15)))
);
assert_eq!(tag.kind.parsed(), "property");
}
}
11 changes: 8 additions & 3 deletions crates/oxc_semantic/src/jsdoc/parser/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ pub fn find_type_name_range(s: &str) -> Option<(usize, usize)> {

// Everything is a token
if let Some(start) = start {
return Some((start, s.len()));
if bracket == 0 {
return Some((start, s.len()));
}
}

None
Expand Down Expand Up @@ -133,10 +135,13 @@ t9b: number;
("n.n8", Some("n.n8")),
("n[].n9", Some("n[].n9")),
(r#"[ n10 = ["{}", "[]"] ]"#, Some(r#"[ n10 = ["{}", "[]"] ]"#)),
("[n11... c11", Some("[n11... c11")),
("[n12[]\nc12", Some("[n12[]\nc12")),
("[n11... c11]", Some("[n11... c11]")),
("[n12[]\nc12]", Some("[n12[]\nc12]")),
("n12.n12", Some("n12.n12")),
("n13[].n13", Some("n13[].n13")),
// if square brackets are unmatched, `None`
("[n12[]\nc12", None),
("[n12\nc12", None),
] {
assert_eq!(find_type_name_range(actual).map(|(s, e)| &actual[s..e]), expect);
}
Expand Down
Loading