mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
fix(semantic): Should return nearest JSDoc (#2490)
Follow up #2437 ( 🙇🏻 )
This commit is contained in:
parent
ef5713d600
commit
04f4621ed8
2 changed files with 32 additions and 1 deletions
|
|
@ -258,6 +258,36 @@ mod test {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_all_by_span_order() {
|
||||
let allocator = Allocator::default();
|
||||
let source_text = r"
|
||||
/**c0*/
|
||||
function foo() {}
|
||||
|
||||
/**c1*/
|
||||
/* noop */
|
||||
/**c2*/
|
||||
// noop
|
||||
/**c3*/
|
||||
const x = () => {};
|
||||
";
|
||||
let symbol = "const x = () => {};";
|
||||
let jsdocs = get_jsdoc(&allocator, source_text, symbol, None);
|
||||
|
||||
assert!(jsdocs.is_some());
|
||||
let jsdocs = jsdocs.unwrap();
|
||||
assert_eq!(jsdocs.len(), 3);
|
||||
|
||||
// Should be [farthest, ..., nearest]
|
||||
let mut iter = jsdocs.iter();
|
||||
let c1 = iter.next().unwrap();
|
||||
assert!(c1.comment.contains("c1"));
|
||||
let _c2 = iter.next().unwrap();
|
||||
let c3 = iter.next().unwrap();
|
||||
assert!(c3.comment.contains("c3"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_all_jsdoc() {
|
||||
let allocator = Allocator::default();
|
||||
|
|
|
|||
|
|
@ -39,7 +39,8 @@ impl<'a> JSDoc<'a> {
|
|||
};
|
||||
|
||||
// If flagged, at least 1 JSDoc is attached
|
||||
jsdocs.first().cloned()
|
||||
// If multiple JSDocs are attached, return the last = nearest
|
||||
jsdocs.last().cloned()
|
||||
}
|
||||
|
||||
pub fn get_all_by_node<'b>(&'b self, node: &AstNode<'a>) -> Option<Vec<JSDocComment<'a>>> {
|
||||
|
|
|
|||
Loading…
Reference in a new issue