Registry / serialization / tree-sitter-javascript

tree-sitter-javascript

JSON →
library0.25.0pypypi✓ verified 30d ago

The `tree-sitter-javascript` package provides the JavaScript grammar for the `tree-sitter` parsing library. It allows Python developers to easily load and use the official Tree-sitter JavaScript grammar to parse JavaScript code into concrete syntax trees (CSTs). The current version is 0.25.0, and it follows the release cadence of the upstream Tree-sitter JavaScript grammar, with updates for syntax changes and bug fixes.

pip install tree-sitter-javascript tree-sitter
INSTALL
IMPORT
SIG · TREE-SITTER-JAVASC
T
tree-sitter-javascript
serializationpythonv0.25.0
Install
1.7s avg
Import
49ms
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.25.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.052s · 19.9MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 1.7s · import 0.046s · 21MB
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

language
✓ from tree_sitter_javascript import language

This quickstart demonstrates how to load the JavaScript grammar, create a parser, and parse a simple JavaScript code snippet. It then shows how to access the root node and find a specific node type, such as a function declaration, illustrating basic tree traversal.

import tree_sitter from tree_sitter_javascript import language # 1. Get the JavaScript language object JS_LANGUAGE = language() # 2. Create a parser and set the language parser = tree_sitter.Parser() parser.set_language(JS_LANGUAGE) # 3. Parse some JavaScript code (must be bytes) code = b""" function greet(name) { console.log("Hello, " + name + "!"); } greet("World"); """ tree = parser.parse(code) # 4. Access the root node and explore the tree root_node = tree.root_node print(f"Root node type: {root_node.type}") print(f"Root node content (first 50 chars): {root_node.text.decode('utf8')[:50]}...") # Example: Find the 'function_declaration' node function_node = None for child in root_node.children: if child.type == 'function_declaration': function_node = child break if function_node: function_name_node = function_node.child_by_field_name('name') if function_name_node: print(f"Found function name: {function_name_node.text.decode('utf8')}")
Debug
Known issues
gotchaThe `tree-sitter-javascript` package *provides* the grammar, but it inherently depends on the core `tree-sitter` Python library to function. Many users forget to install `tree-sitter` alongside this grammar package, leading to `ModuleNotFoundError` for `tree_sitter` or issues when trying to instantiate `Parser` objects. Always install both.
fix
Ensure you install both `tree-sitter-javascript` and `tree-sitter`: `pip install tree-sitter-javascript tree-sitter`.
affects: All versions
gotchaThe underlying `tree-sitter` core library (which `tree-sitter-javascript` leverages) is a C extension. While pre-built wheels are available for many common platforms, certain environments (e.g., specific Linux distributions, custom Python builds, or older Python versions) may require a C compiler (like GCC or Clang) during installation. Lack of a compiler can cause installation failures.
fix
Ensure a C compiler is installed and available in your environment before attempting installation. For Debian/Ubuntu: `apt-get install build-essential`. For macOS: `xcode-select --install`.
affects: All versions
breakingWhile the `language()` function provided by `tree-sitter-javascript` is generally stable, major version changes in the upstream `tree-sitter` Python library can introduce breaking API changes for `Parser`, `Tree`, or `Node` objects. Similarly, significant updates to the underlying JavaScript grammar definition (less frequent for the Python binding) could subtly change the structure of the generated ASTs.
fix
It is strongly recommended to pin both the `tree-sitter-javascript` and `tree-sitter` package versions in your `requirements.txt` or project dependencies to ensure consistent behavior across deployments (e.g., `tree-sitter-javascript==0.25.0`, `tree-sitter==0.21.1`).
affects: All versions, especially across major `tree-sitter` updates.
Upgrade
Version history
0.25.0latest on PyPI · released Sep 1, 2025
Audit
Dependencies
tree-sitterrequiredThe core Python `tree-sitter` library is required to create parsers and interact with the grammar.
Agent activity
21 hits · last 30 days
node
18
OpenAI (training)
1
Resources
tree-sitter-javascript — pip install tree-sitter-javascript · libregistry