-
-
Notifications
You must be signed in to change notification settings - Fork 501
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(parser): add module and struct level documentation (#5831)
- Loading branch information
Showing
3 changed files
with
168 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use oxc_allocator::Allocator; | ||
use oxc_parser::{Parser, ParserReturn}; | ||
use oxc_span::SourceType; | ||
|
||
fn main() { | ||
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> | ||
) | ||
}"; | ||
|
||
// Memory arena where AST nodes get stored | ||
let allocator = Allocator::default(); | ||
// Infers TypeScript + JSX + ESM modules | ||
let source_type = SourceType::from_path("Counter.tsx").unwrap(); | ||
|
||
let ParserReturn { | ||
program, // AST | ||
errors, // Syntax errors | ||
panicked, // Parser encountered an error it couldn't recover from | ||
trivias, // Comments, whitespace, etc. | ||
} = Parser::new(&allocator, source_text, source_type).parse(); | ||
|
||
assert!(!panicked); | ||
assert!(errors.is_empty()); | ||
assert!(!program.body.is_empty()); | ||
assert_eq!(trivias.comments().count(), 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters