Skip to content
Merged
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
14 changes: 14 additions & 0 deletions crates/oxc_semantic/examples/semantic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use oxc_span::SourceType;

fn main() -> std::io::Result<()> {
let name = env::args().nth(1).unwrap_or_else(|| "test.js".to_string());
let show_symbols = env::args().skip(1).any(|arg| arg == "--symbols");
let path = Path::new(&name);
let source_text = Arc::new(std::fs::read_to_string(path)?);
let source_type = SourceType::from_path(path).unwrap();
Expand Down Expand Up @@ -48,5 +49,18 @@ fn main() -> std::io::Result<()> {
println!("Semantic analysis failed:\n\n{error_message}",);
}

if show_symbols {
let scoping = semantic.semantic.scoping();
for symbol_id in scoping.symbol_ids() {
let name = scoping.symbol_name(symbol_id);
let flags = scoping.symbol_flags(symbol_id);
println!("Symbol: {name}, ID: {symbol_id:?}, Flags: {flags:?}");
for reference_id in scoping.get_resolved_reference_ids(symbol_id) {
let reference = scoping.get_reference(*reference_id);
println!(" Reference ID: {reference_id:?}, Flags: {:?}", reference.flags());
}
}
}

Ok(())
}
Loading