{"id":1749,"library":"tree-sitter-javascript","title":"Tree-sitter JavaScript Grammar","description":"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.","status":"active","version":"0.25.0","language":"python","source_language":"en","source_url":"https://github.com/tree-sitter/tree-sitter-javascript","tags":["syntax-tree","parser","javascript","tree-sitter","grammar","ast"],"install":[{"cmd":"pip install tree-sitter-javascript tree-sitter","lang":"bash","label":"Install with core library"}],"dependencies":[{"reason":"The core Python `tree-sitter` library is required to create parsers and interact with the grammar.","package":"tree-sitter","optional":false}],"imports":[{"symbol":"language","correct":"from tree_sitter_javascript import language"}],"quickstart":{"code":"import tree_sitter\nfrom tree_sitter_javascript import language\n\n# 1. Get the JavaScript language object\nJS_LANGUAGE = language()\n\n# 2. Create a parser and set the language\nparser = tree_sitter.Parser()\nparser.set_language(JS_LANGUAGE)\n\n# 3. Parse some JavaScript code (must be bytes)\ncode = b\"\"\"\nfunction greet(name) {\n  console.log(\"Hello, \" + name + \"!\");\n}\ngreet(\"World\");\n\"\"\"\ntree = parser.parse(code)\n\n# 4. Access the root node and explore the tree\nroot_node = tree.root_node\n\nprint(f\"Root node type: {root_node.type}\")\nprint(f\"Root node content (first 50 chars): {root_node.text.decode('utf8')[:50]}...\")\n\n# Example: Find the 'function_declaration' node\nfunction_node = None\nfor child in root_node.children:\n    if child.type == 'function_declaration':\n        function_node = child\n        break\n\nif function_node:\n    function_name_node = function_node.child_by_field_name('name')\n    if function_name_node:\n        print(f\"Found function name: {function_name_node.text.decode('utf8')}\")\n","lang":"python","description":"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."},"warnings":[{"fix":"Ensure you install both `tree-sitter-javascript` and `tree-sitter`: `pip install tree-sitter-javascript tree-sitter`.","message":"The `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.","severity":"gotcha","affected_versions":"All versions"},{"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`.","message":"The 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.","severity":"gotcha","affected_versions":"All versions"},{"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`).","message":"While 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.","severity":"breaking","affected_versions":"All versions, especially across major `tree-sitter` updates."}],"env_vars":null,"search_vec":"'0.25.0':52 'allow':24 'ast':84 'bug':73 'cadenc':58 'chang':71 'code':42 'concret':44 'csts':47 'current':49 'develop':26 'easili':28 'fix':74 'follow':55 'grammar':5,15,38,66,83 'javascript':4,10,14,37,41,65,79 'librari':22 'load':29 'offici':33 'packag':11 'pars':21,40 'parser':78 'provid':12 'python':25 'releas':57 'sitter':3,9,20,36,64,82 'syntax':45,70,76 'syntax-tre':75 'tree':2,8,19,35,46,63,77,81 'tree-sitt':1,18,34,62,80 'tree-sitter-javascript':7 'updat':68 'upstream':61 'use':31 'version':50","created_at":"2026-04-09T04:01:28.733905+00:00","updated_at":"2026-04-09T04:01:28.733905+00:00","problems":{"verify_error":"error: Failed to parse: `tree-sitter-javascript tree-sitter`\n  Caused by: Expected one of `@`, `(`, `<`, `=`, `>`, `~`, `!`, `;`, found `t`\ntree-sitter-javascript tree-sitter\n                       ^"},"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.25.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/tree-sitter/tree-sitter-javascript","docs":null,"changelog":null,"pypi":"https://pypi.org/project/tree-sitter-javascript/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-27","next_check":"2026-07-05","install_tag":null}}