tree-sitter-javascript

repository·master·Indexed 19 days ago

https://github.com/tree-sitter/tree-sitter-javascript

A concrete syntax tree (CST) parser grammar for JavaScript and JSX designed for the tree-sitter incremental parsing engine. It approximates the ECMAScript specification and provides Node.js bindings, including a nodeTypeInfo object for inspecting grammar node metadata.

Tokens
496
Snippets
3
Records
4
Agent score
17%

What's inside tree-sitter-javascript

  1. Use eslint-config-treesitter for ESLint configuration

    master

    To apply the tree-sitter linting rules to your project, import treesitter from eslint-config-treesitter and spread it into your eslint.config.mjs (Flat Config) array. This provides a pre-configured set of rules optimized for tree-sitter based linting.

    import treesitter from 'eslint-config-treesitter';
    
    export default [
      ...treesitter,
    ];
  2. Import the tree-sitter-javascript Node.js bindings

    master

    To use the JavaScript grammar in a Node.js environment, require the tree-sitter-javascript package. The package automatically handles loading the correct prebuilt binary for your platform and architecture using node-gyp-build.

    If you are using Bun, the package is designed to be statically analyzable to support bun build --compile by locating the .node file at build-time.

    const JavaScript = require('tree-sitter-javascript');
  3. Access nodeTypeInfo for JavaScript grammar nodes

    master

    The bindings export a nodeTypeInfo object which contains metadata about the node types defined in the JavaScript grammar. This is useful for inspecting the grammar's structure or understanding available node types programmatically.

    const JavaScript = require('tree-sitter-javascript');
    
    // Access metadata about the grammar's node types
    const typeInfo = JavaScript.nodeTypeInfo;
    console.log(typeInfo);