npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

tree-sitter-go-types

v0.1.0

Published

Generate Go constants from tree-sitter node-types.json

Downloads

98

Readme

tree-sitter-go-types

Generate Go constants from a tree-sitter grammar's node-types.json.

Replaces hardcoded string literals like "pipeline_chain" with typed constants like NodePipelineChain, giving you compile-time safety and IDE discoverability when working with tree-sitter ASTs in Go.

Install

npm install --save-dev tree-sitter-go-types

Or run directly with npx:

npx tree-sitter-go-types

Usage

Run in a tree-sitter grammar repo root (where src/node-types.json exists):

# Uses defaults: reads src/node-types.json, writes node_types.go
npx tree-sitter-go-types

# Explicit paths and options
npx tree-sitter-go-types -i src/node-types.json -o node_types.go -p my_package

Options

| Flag | Description | Default | |------|-------------|---------| | -i, --input <path> | Path to node-types.json | src/node-types.json | | -o, --output <path> | Output .go file | node_types.go | | -p, --package <name> | Go package name | tree_sitter_<grammar> | | -g, --grammar <name> | Grammar name override | From tree-sitter.json or directory name |

Typical workflow

Add it to your grammar's build step, right after tree-sitter generate:

{
  "scripts": {
    "generate": "tree-sitter generate && npx tree-sitter-go-types"
  }
}

Output

For a PowerShell grammar, the tool generates:

// Code generated by tree-sitter-go-types v0.1.0; DO NOT EDIT.

package tree_sitter_powershell

// Node kind constants for the powershell grammar.
const (
	NodeCommand       = "command"
	NodeCommandName   = "command_name"
	NodePipeline      = "pipeline"
	NodePipelineChain = "pipeline_chain"
	NodeVariable      = "variable"
	// ... 152 constants total
)

// Field name constants for the powershell grammar.
const (
	FieldCommandName = "command_name"
	FieldCondition   = "condition"
	FieldValue       = "value"
	// ...
)

Consumers use the constants instead of string literals:

import ps "github.com/wharflab/tree-sitter-powershell"

if node.Kind() == ps.NodePipelineChain {
    // ...
}

What it reads

The tool reads src/node-types.json, which is auto-generated by tree-sitter generate. It contains the complete schema of named node kinds and their field names. Only named node types (not anonymous tokens like "+" or "if") become constants.

Zero dependencies

The tool is a single JavaScript file with no runtime dependencies. It requires Node.js >= 18.

License

MIT