use oxc_allocator::Allocator;
use oxc_parser::{Parser, ParserReturn};
use oxc_span::SourceType;
fn main() -> Result<(), String> {
let source_text = r"
import React from 'react';
/**
* A simple counter component
*/
export const Counter: React.FC = () => {
const [count, setCount] = React.useState(0);
return (
<div>
<p>Count: {count}</p>
<button onClick={() => setCount(count + 1)}>Increment</button>
<button onClick={() => setCount(count - 1)}>Decrement</button>
</div>
)
}";
let allocator = Allocator::default();
let source_type = SourceType::from_path("Counter.tsx").unwrap();
let ParserReturn {
program, errors, panicked, ..
} = Parser::new(&allocator, source_text, source_type).parse();
if panicked {
return Err("Parser panicked".to_string());
}
if !errors.is_empty() {
return Err(format!("Parsing errors: {}", errors.len()));
}
assert!(!program.body.is_empty());
assert_eq!(program.comments.len(), 1);
Ok(())
}