Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(semantic/jsdoc): Add Span for JSDoc, JSDocTag #2815

Merged
merged 17 commits into from
Mar 26, 2024
Merged
Prev Previous commit
Next Next commit
Add span for jsdoc
  • Loading branch information
leaysgur committed Mar 25, 2024
commit 9a5669b1da8341e7100c0967a575de235d0d8b90
3 changes: 2 additions & 1 deletion crates/oxc_semantic/src/jsdoc/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ impl<'a> JSDocBuilder<'a> {
}

// Remove the very first `*`
Some(JSDoc::new(&comment_content[1..]))
let jsdoc_span = Span::new(comment_span.start + 1, comment_span.end);
Some(JSDoc::new(&comment_content[1..], jsdoc_span))
Boshen marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
6 changes: 4 additions & 2 deletions crates/oxc_semantic/src/jsdoc/parser/jsdoc.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
use oxc_span::Span;
use super::jsdoc_tag::JSDocTag;
use super::parse::parse_jsdoc;
use std::cell::OnceCell;

#[derive(Debug, Clone)]
pub struct JSDoc<'a> {
raw: &'a str,
pub span: Span,
/// Cached+parsed JSDoc comment and tags
cached: OnceCell<(String, Vec<JSDocTag<'a>>)>,
}

impl<'a> JSDoc<'a> {
/// comment_content: Inside of /*HERE*/, not include `/*`
pub fn new(comment_content: &'a str) -> JSDoc<'a> {
Self { raw: comment_content, cached: OnceCell::new() }
pub fn new(comment_content: &'a str, span: Span) -> JSDoc<'a> {
Self { raw: comment_content, span, cached: OnceCell::new() }
}

pub fn comment(&self) -> &str {
Expand Down