Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

web-tree-sitter

Package Overview
Dependencies
Maintainers
7
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

web-tree-sitter - npm Package Compare versions

Comparing version 0.20.8 to 0.21.0

4

package.json
{
"name": "web-tree-sitter",
"version": "0.20.8",
"version": "0.21.0",
"description": "Tree-sitter bindings for the web",

@@ -31,2 +31,4 @@ "main": "tree-sitter.js",

"chai": "^4.3.7",
"eslint": ">=8.56.0",
"eslint-config-google": "^0.14.0",
"mocha": "^10.2.0",

@@ -33,0 +35,0 @@ "terser": "^5.16.6"

@@ -1,4 +0,8 @@

Web Tree-sitter
===============
# Web Tree-sitter
[![npmjs.com badge]][npmjs.com]
[npmjs.com]: https://www.npmjs.org/package/web-tree-sitter
[npmjs.com badge]: https://img.shields.io/npm/v/web-tree-sitter.svg?color=%23BF4A4A
WebAssembly bindings to the [Tree-sitter](https://github.com/tree-sitter/tree-sitter) parsing library.

@@ -8,6 +12,6 @@

You can download the the `tree-sitter.js` and `tree-sitter.wasm` files from [the latest GitHub release](https://github.com/tree-sitter/tree-sitter/releases/latest) and load them using a standalone script:
You can download the `tree-sitter.js` and `tree-sitter.wasm` files from [the latest GitHub release](https://github.com/tree-sitter/tree-sitter/releases/latest) and load them using a standalone script:
```html
<script src="/the/path/to/tree-sitter.js"/>
<script src="/the/path/to/tree-sitter.js"></script>

@@ -27,2 +31,10 @@ <script>

You can use this module with [deno](https://deno.land/):
```js
import Parser from "npm:web-tree-sitter";
await Parser.init();
// the library is ready
```
### Basic Usage

@@ -113,3 +125,3 @@

**IMPORTANT**: [emscripten](https://emscripten.org/docs/getting_started/downloads.html) or [docker](https://www.docker.com/) need to be installed.
**IMPORTANT**: [emscripten](https://emscripten.org/docs/getting_started/downloads.html), [docker](https://www.docker.com/), or [podman](https://podman.io) need to be installed.

@@ -122,3 +134,3 @@ First install `tree-sitter-cli` and the tree-sitter language for which to generate `.wasm` (`tree-sitter-javascript` in this example):

Then just use tree-sitter cli tool to generate the `.wasm`.
Then just use tree-sitter cli tool to generate the `.wasm`.

@@ -154,9 +166,9 @@ ```sh

`web-tree-sitter` needs to load the `tree-sitter.wasm` file. By default, it assumes that this file is available in the
`web-tree-sitter` needs to load the `tree-sitter.wasm` file. By default, it assumes that this file is available in the
same path as the JavaScript code. Therefore, if the code is being served from `http://localhost:3000/bundle.js`, then
the wasm file should be at `http://localhost:3000/tree-sitter.wasm`.
For server side frameworks like NextJS, this can be tricky as pages are often served from a path such as
For server side frameworks like NextJS, this can be tricky as pages are often served from a path such as
`http://localhost:3000/_next/static/chunks/pages/index.js`. The loader will therefore look for the wasm file at
`http://localhost:3000/_next/static/chunks/pages/tree-sitter.wasm`. The solution is to pass a `locateFile` function in
`http://localhost:3000/_next/static/chunks/pages/tree-sitter.wasm`. The solution is to pass a `locateFile` function in
the `moduleOptions` argument to `Parser.init()`:

@@ -172,3 +184,3 @@

`locateFile` takes in two parameters, `scriptName`, i.e. the wasm file name, and `scriptDirectory`, i.e. the directory
`locateFile` takes in two parameters, `scriptName`, i.e. the wasm file name, and `scriptDirectory`, i.e. the directory
where the loader expects the script to be. It returns the path where the loader will look for the wasm file. In the NextJS

@@ -180,4 +192,4 @@ case, we want to return just the `scriptName` so that the loader will look at `http://localhost:3000/tree-sitter.wasm`

Most bundlers will notice that the `tree-sitter.js` file is attempting to import `fs`, i.e. node's file system library.
Since this doesn't exist in the browser, the bundlers will get confused. For webpack you can fix this by adding the
Most bundlers will notice that the `tree-sitter.js` file is attempting to import `fs`, i.e. node's file system library.
Since this doesn't exist in the browser, the bundlers will get confused. For webpack you can fix this by adding the
following to your webpack config:

@@ -184,0 +196,0 @@

@@ -58,6 +58,10 @@ declare module 'web-tree-sitter' {

export interface SyntaxNode {
id: number;
typeId: number;
grammarId: number;
tree: Tree;
type: string;
grammarType: string;
text: string;
parseState: number;
nextParseState: number;
startPosition: Point;

@@ -84,2 +88,3 @@ endPosition: Point;

equals(other: SyntaxNode): boolean;
isError(): boolean;
isMissing(): boolean;

@@ -109,2 +114,3 @@ isNamed(): boolean;

nodeTypeId: number;
nodeStateId: number;
nodeText: string;

@@ -120,2 +126,3 @@ nodeId: number;

reset(node: SyntaxNode): void;
resetTo(cursor: TreeCursor): void;
delete(): void;

@@ -127,4 +134,6 @@ currentNode(): SyntaxNode;

gotoFirstChild(): boolean;
gotoLastChild(): boolean;
gotoFirstChildForIndex(index: number): boolean;
gotoNextSibling(): boolean;
gotoPreviousSibling(): boolean;
}

@@ -149,2 +158,3 @@

readonly fieldCount: number;
readonly stateCount: number;
readonly nodeTypeCount: number;

@@ -158,5 +168,18 @@

nodeTypeIsVisible(typeId: number): boolean;
nextState(stateId: number, typeId: number): number;
query(source: string): Query;
lookaheadIterator(stateId: number): LookaheadIterable | null;
}
class LookaheadIterable {
readonly language: Language;
readonly currentTypeId: number;
readonly currentType: string;
delete(): void;
resetState(stateId: number): boolean;
reset(language: Language, stateId: number): boolean;
[Symbol.iterator](): Iterator<string>;
}
interface QueryCapture {

@@ -163,0 +186,0 @@ name: string;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc