treesitter_types_typescript/lib.rs
1//! Strongly-typed AST types for TypeScript, auto-generated from
2//! [`tree-sitter-typescript`](https://docs.rs/tree-sitter-typescript)'s `node-types.json`.
3//!
4//! This crate is generated by [`treesitter-types`](https://docs.rs/treesitter-types) and is
5//! automatically kept up to date when a new version of the grammar crate is released.
6//!
7//! These types have been tested by parsing the
8//! [TypeScript](https://github.com/microsoft/TypeScript) source code.
9//!
10//! See the [Tree-sitter](https://tree-sitter.github.io/tree-sitter/) project for more
11//! information about the underlying parser framework.
12//!
13//! # Example
14//!
15//! ```
16//! use treesitter_types_typescript::*;
17//!
18//! // A minimal TypeScript hello-world program.
19//! let src = b"\
20//! function greet(name: string): void {
21//! console.log(\"Hello, \" + name + \"!\");
22//! }
23//!
24//! greet(\"World\");
25//! ";
26//!
27//! // Parse the source with tree-sitter and convert into typed AST.
28//! let mut parser = tree_sitter::Parser::new();
29//! parser
30//! .set_language(&tree_sitter_typescript::LANGUAGE_TYPESCRIPT.into())
31//! .unwrap();
32//! let tree = parser.parse(src, None).unwrap();
33//! let program = Program::from_node(tree.root_node(), src).unwrap();
34//!
35//! // The program has two top-level children.
36//! assert_eq!(program.children.len(), 2);
37//!
38//! // 1) The function declaration — `function greet(name: string): void { ... }`.
39//! let ProgramChildren::Statement(stmt) = &program.children[0] else {
40//! panic!("expected a statement");
41//! };
42//! let Statement::Declaration(decl) = stmt.as_ref() else {
43//! panic!("expected a declaration");
44//! };
45//! let Declaration::FunctionDeclaration(func) = decl.as_ref() else {
46//! panic!("expected a function declaration");
47//! };
48//! assert_eq!(func.name.text(), "greet");
49//! assert_eq!(func.parameters.children.len(), 1); // one parameter: `name: string`
50//! assert!(func.return_type.is_some()); // has return type `: void`
51//!
52//! // 2) The call expression — `greet("World");`.
53//! let ProgramChildren::Statement(call_stmt) = &program.children[1] else {
54//! panic!("expected a statement");
55//! };
56//! let Statement::ExpressionStatement(expr) = call_stmt.as_ref() else {
57//! panic!("expected an expression statement");
58//! };
59//! assert_eq!(expr.span.start.row, 4);
60//! ```
61
62pub use tree_sitter_typescript;
63pub use treesitter_types::tree_sitter;
64pub use treesitter_types::{FromNode, LeafNode, ParseError, Span, Spanned};
65
66mod generated;
67pub use generated::*;