Crate tree_sitter_typescript

Source
Expand description

This crate provides TypeScript and TSX language support for the tree-sitter parsing library.

Typically, you will use the LANGUAGE_TYPESCRIPT constant to add this language to a tree-sitter Parser, and then use the parser to parse some code:

use tree_sitter::Parser;

let code = r#"
function double(x: number): number {
    return x * 2;
}
"#;
let mut parser = Parser::new();
let language = tree_sitter_typescript::LANGUAGE_TYPESCRIPT;
parser
    .set_language(&language.into())
    .expect("Error loading TypeScript parser");
let tree = parser.parse(code, None).unwrap();
assert!(!tree.root_node().has_error());

Constantsยง

HIGHLIGHTS_QUERY
The syntax highlighting query for TypeScript.
LANGUAGE_TSX
The tree-sitter LanguageFn for TSX.
LANGUAGE_TYPESCRIPT
The tree-sitter LanguageFn for TypeScript.
LOCALS_QUERY
The local-variable syntax highlighting query for TypeScript.
TAGS_QUERY
The symbol tagging query for TypeScript.
TSX_NODE_TYPES
The content of the node-types.json file for TSX.
TYPESCRIPT_NODE_TYPES
The content of the node-types.json file for TypeScript.