treesitter-types-typescript 1.0.0

Pre-generated strongly-typed AST types for TypeScript (tree-sitter-typescript)
Documentation
//! Strongly-typed AST types for TypeScript, auto-generated from
//! [`tree-sitter-typescript`](https://docs.rs/tree-sitter-typescript)'s `node-types.json`.
//!
//! This crate is generated by [`treesitter-types`](https://docs.rs/treesitter-types) and is
//! automatically kept up to date when a new version of the grammar crate is released.
//!
//! These types have been tested by parsing the
//! [TypeScript](https://github.com/microsoft/TypeScript) source code.
//!
//! See the [Tree-sitter](https://tree-sitter.github.io/tree-sitter/) project for more
//! information about the underlying parser framework.
//!
//! # Example
//!
//! ```
//! use treesitter_types_typescript::*;
//!
//! // A minimal TypeScript hello-world program.
//! let src = b"\
//! function greet(name: string): void {
//!     console.log(\"Hello, \" + name + \"!\");
//! }
//!
//! greet(\"World\");
//! ";
//!
//! // Parse the source with tree-sitter and convert into typed AST.
//! let mut parser = tree_sitter::Parser::new();
//! parser
//!     .set_language(&tree_sitter_typescript::LANGUAGE_TYPESCRIPT.into())
//!     .unwrap();
//! let tree = parser.parse(src, None).unwrap();
//! let program = Program::from_node(tree.root_node(), src).unwrap();
//!
//! // The program has two top-level children.
//! assert_eq!(program.children.len(), 2);
//!
//! // 1) The function declaration — `function greet(name: string): void { ... }`.
//! let ProgramChildren::Statement(stmt) = &program.children[0] else {
//!     panic!("expected a statement");
//! };
//! let Statement::Declaration(decl) = stmt.as_ref() else {
//!     panic!("expected a declaration");
//! };
//! let Declaration::FunctionDeclaration(func) = decl.as_ref() else {
//!     panic!("expected a function declaration");
//! };
//! assert_eq!(func.name.text(), "greet");
//! assert_eq!(func.parameters.children.len(), 1); // one parameter: `name: string`
//! assert!(func.return_type.is_some());            // has return type `: void`
//!
//! // 2) The call expression — `greet("World");`.
//! let ProgramChildren::Statement(call_stmt) = &program.children[1] else {
//!     panic!("expected a statement");
//! };
//! let Statement::ExpressionStatement(expr) = call_stmt.as_ref() else {
//!     panic!("expected an expression statement");
//! };
//! assert_eq!(expr.span.start.row, 4);
//! ```

pub use tree_sitter_typescript;
pub use treesitter_types::tree_sitter;
pub use treesitter_types::{FromNode, LeafNode, ParseError, Span, Spanned};

mod generated;
pub use generated::*;