Skip to content

Instantly share code, notes, and snippets.

@leaysgur
Created June 13, 2024 00:22
Show Gist options
  • Save leaysgur/bcb748daa665d1615eabda6967366d05 to your computer and use it in GitHub Desktop.
Save leaysgur/bcb748daa665d1615eabda6967366d05 to your computer and use it in GitHub Desktop.
[package]
name = "oxc-jsdoc"
version = "0.1.0"
edition = "2021"
# Latest version is 0.14.0, but could not compile...
[dependencies]
oxc_allocator = "0.12.5"
oxc_parser = "0.12.5"
oxc_span = "0.12.5"
oxc_semantic = "0.12.5"
use oxc_allocator::Allocator;
use oxc_parser::Parser;
use oxc_semantic::SemanticBuilder;
use oxc_span::SourceType;
const SOURCE_TEXT: &str = r#"
/**
* Greet someone.
* @param {string} name Name to greet.
* @returns {void} Just print a message.
*/
function greet(name) {
console.log(`Hello, ${name}`);
}
"#;
fn main() -> std::io::Result<()> {
let allocator = Allocator::default();
let source_type = SourceType::default();
let ret = Parser::new(&allocator, SOURCE_TEXT, source_type).parse();
let program = allocator.alloc(ret.program);
let semantic_ret = SemanticBuilder::new(SOURCE_TEXT, source_type)
.with_trivias(ret.trivias)
.build(program);
for node in semantic_ret.semantic.nodes().iter() {
if let Some(jsdocs) = semantic_ret.semantic.jsdoc().get_all_by_node(node) {
for jsdoc in jsdocs {
println!("🍀 Comment:");
println!("{}", jsdoc.comment().parsed());
println!("🍀 Tags:");
for tag in jsdoc.tags() {
println!("- {tag:?}");
}
}
}
}
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment