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

tree-sitter

Package Overview
Dependencies
Maintainers
9
Versions
195
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tree-sitter - npm Package Compare versions

Comparing version 0.20.6 to 0.21.0

prebuilds/darwin-arm64/tree-sitter.node

281

index.js

@@ -1,14 +0,5 @@

let binding;
try {
binding = require('./build/Release/tree_sitter_runtime_binding');
} catch (e) {
try {
binding = require('./build/Debug/tree_sitter_runtime_binding');
} catch (_) {
throw e;
}
}
const binding = require('node-gyp-build')(__dirname);
const {Query, Parser, NodeMethods, Tree, TreeCursor, LookaheadIterator} = binding;
const util = require('util')
const {Query, Parser, NodeMethods, Tree, TreeCursor} = binding;
const util = require('util');

@@ -19,3 +10,3 @@ /*

const {rootNode, edit} = Tree.prototype;
const {rootNode, rootNodeWithOffset, edit} = Tree.prototype;

@@ -40,5 +31,9 @@ Object.defineProperty(Tree.prototype, 'rootNode', {

// we don't want to error on this
configurable: true
configurable: true
});
Tree.prototype.rootNodeWithOffset = function(offset_bytes, offset_extent) {
return unmarshalNode(rootNodeWithOffset.call(this, offset_bytes, offset_extent.row, offset_extent.column), this);
}
Tree.prototype.edit = function(arg) {

@@ -80,5 +75,5 @@ if (this instanceof Tree && edit) {

get type() {
get id() {
marshalNode(this);
return NodeMethods.type(this.tree);
return NodeMethods.id(this.tree);
}

@@ -91,2 +86,22 @@

get grammarId() {
marshalNode(this);
return NodeMethods.grammarId(this.tree);
}
get type() {
marshalNode(this);
return NodeMethods.type(this.tree);
}
get grammarType() {
marshalNode(this);
return NodeMethods.grammarType(this.tree);
}
get isExtra() {
marshalNode(this);
return NodeMethods.isExtra(this.tree);
}
get isNamed() {

@@ -97,2 +112,22 @@ marshalNode(this);

get isMissing() {
marshalNode(this);
return NodeMethods.isMissing(this.tree);
}
get hasChanges() {
marshalNode(this);
return NodeMethods.hasChanges(this.tree);
}
get hasError() {
marshalNode(this);
return NodeMethods.hasError(this.tree);
}
get isError() {
marshalNode(this);
return NodeMethods.isError(this.tree);
}
get text() {

@@ -189,15 +224,15 @@ return this.tree.getText(this);

hasChanges() {
get parseState() {
marshalNode(this);
return NodeMethods.hasChanges(this.tree);
return NodeMethods.parseState(this.tree);
}
hasError() {
get nextParseState() {
marshalNode(this);
return NodeMethods.hasError(this.tree);
return NodeMethods.nextParseState(this.tree);
}
isMissing() {
get descendantCount() {
marshalNode(this);
return NodeMethods.isMissing(this.tree);
return NodeMethods.descendantCount(this.tree);
}

@@ -220,2 +255,27 @@

childForFieldName(fieldName) {
marshalNode(this);
return unmarshalNode(NodeMethods.childForFieldName(this.tree, fieldName), this.tree);
}
childForFieldId(fieldId) {
marshalNode(this);
return unmarshalNode(NodeMethods.childForFieldId(this.tree, fieldId), this.tree);
}
fieldNameForChild(childIndex) {
marshalNode(this);
return NodeMethods.fieldNameForChild(this.tree, childIndex);
}
childrenForFieldName(fieldName) {
marshalNode(this);
return unmarshalNodes(NodeMethods.childrenForFieldName(this.tree, fieldName), this.tree);
}
childrenForFieldId(fieldId) {
marshalNode(this);
return unmarshalNodes(NodeMethods.childrenForFieldId(this.tree, fieldId), this.tree);
}
firstChildForIndex(index) {

@@ -271,2 +331,3 @@ marshalNode(this);

cursor.tree = this.tree;
unmarshalNode(cursor.currentNode, this.tree);
return cursor;

@@ -294,3 +355,3 @@ }

Parser.prototype.getLanguage = function(language) {
Parser.prototype.getLanguage = function(_language) {
return this[languageSymbol] || null;

@@ -303,3 +364,3 @@ };

const inputString = input;
input = (offset, position) => inputString.slice(offset)
input = (offset, _position) => inputString.slice(offset)
getText = getTextFromString

@@ -315,3 +376,4 @@ } else {

bufferSize,
includedRanges)
includedRanges,
)
: undefined;

@@ -331,3 +393,3 @@

const {startPosition, endPosition, currentNode, reset} = TreeCursor.prototype;
const {startPosition, endPosition, currentNode} = TreeCursor.prototype;

@@ -369,9 +431,2 @@ Object.defineProperties(TreeCursor.prototype, {

TreeCursor.prototype.reset = function(node) {
marshalNode(node);
if (this instanceof TreeCursor && reset) {
reset.call(this);
}
}
/*

@@ -423,6 +478,9 @@ * Query

let isPositive = true;
let matchAll = true;
let captureName;
switch (operator) {
case 'any-not-eq?':
case 'not-eq?':
isPositive = false;
case 'any-eq?':
case 'eq?':

@@ -435,24 +493,36 @@ if (stepsLength !== 3) throw new Error(

);
matchAll = !operator.startsWith('any-');
if (steps[THIRD] === PREDICATE_STEP_TYPE.CAPTURE) {
const captureName1 = steps[SECOND + 1];
const captureName2 = steps[THIRD + 1];
predicates[i].push(function(captures) {
let node1, node2
const captureName2 = steps[THIRD + 1];
predicates[i].push(function (captures) {
let nodes_1 = [];
let nodes_2 = [];
for (const c of captures) {
if (c.name === captureName1) node1 = c.node;
if (c.name === captureName2) node2 = c.node;
if (c.name === captureName1) nodes_1.push(c.node);
if (c.name === captureName2) nodes_2.push(c.node);
}
if (node1 === undefined || node2 === undefined) return true;
return (node1.text === node2.text) === isPositive;
let compare = (n1, n2, positive) => {
return positive ?
n1.text === n2.text :
n1.text !== n2.text;
};
return matchAll
? nodes_1.every(n1 => nodes_2.some(n2 => compare(n1, n2, isPositive)))
: nodes_1.some(n1 => nodes_2.some(n2 => compare(n1, n2, isPositive)));
});
} else {
const captureName = steps[SECOND + 1];
const stringValue = steps[THIRD + 1];
predicates[i].push(function(captures) {
captureName = steps[SECOND + 1];
const stringValue = steps[THIRD + 1];
let matches = (n) => n.text === stringValue;
let doesNotMatch = (n) => n.text !== stringValue;
predicates[i].push(function (captures) {
let nodes = [];
for (const c of captures) {
if (c.name === captureName) {
return (c.node.text === stringValue) === isPositive;
};
if (c.name === captureName) nodes.push(c.node);
}
return true;
let test = isPositive ? matches : doesNotMatch;
return matchAll
? nodes.every(test)
: nodes.some(test);
});

@@ -462,2 +532,6 @@ }

case 'any-not-match?':
case 'not-match?':
isPositive = false;
case 'any-match?':
case 'match?':

@@ -473,10 +547,20 @@ if (stepsLength !== 3) throw new Error(

);
const captureName = steps[SECOND + 1];
captureName = steps[SECOND + 1];
const regex = new RegExp(steps[THIRD + 1]);
predicates[i].push(function(captures) {
matchAll = !operator.startsWith('any-');
predicates[i].push(function (captures) {
const nodes = [];
for (const c of captures) {
if (c.name === captureName) return regex.test(c.node.text);
if (c.name === captureName) nodes.push(c.node.text);
}
return true;
});
let test = (text, positive) => {
return positive ?
regex.test(text) :
!regex.test(text);
};
if (nodes.length === 0) return !isPositive;
return matchAll
? nodes.every(text => test(text, isPositive))
: nodes.some(text => test(text, isPositive))
});
break;

@@ -508,2 +592,29 @@

case 'not-any-of?':
isPositive = false;
case 'any-of?':
if (stepsLength < 2) throw new Error(
`Wrong number of arguments to \`#${operator}\` predicate. Expected at least 1. Got ${stepsLength - 1}.`
);
if (steps[SECOND] !== PREDICATE_STEP_TYPE.CAPTURE) throw new Error(
`First argument of \`#${operator}\` predicate must be a capture. Got "${steps[1].value}".`
);
stringValues = [];
for (let k = THIRD; k < 2 * stepsLength; k += 2) {
if (steps[k] !== PREDICATE_STEP_TYPE.STRING) throw new Error(
`Arguments to \`#${operator}\` predicate must be a strings.".`
);
stringValues.push(steps[k + 1]);
}
captureName = steps[SECOND + 1];
predicates[i].push(function (captures) {
const nodes = [];
for (const c of captures) {
if (c.name === captureName) nodes.push(c.node.text);
}
if (nodes.length === 0) return !isPositive;
return nodes.every(text => stringValues.includes(text)) === isPositive;
});
break;
default:

@@ -521,9 +632,20 @@ throw new Error(`Unknown query predicate \`#${steps[FIRST + 1]}\``);

Query.prototype.matches = function(rootNode, startPosition = ZERO_POINT, endPosition = ZERO_POINT) {
marshalNode(rootNode);
const [returnedMatches, returnedNodes] = _matches.call(this, rootNode.tree,
Query.prototype.matches = function(
node,
{
startPosition = ZERO_POINT,
endPosition = ZERO_POINT,
startIndex = 0,
endIndex = 0,
matchLimit = 0xFFFFFFFF,
maxStartDepth = 0xFFFFFFFF
} = {}
) {
marshalNode(node);
const [returnedMatches, returnedNodes] = _matches.call(this, node.tree,
startPosition.row, startPosition.column,
endPosition.row, endPosition.column
endPosition.row, endPosition.column,
startIndex, endIndex, matchLimit, maxStartDepth
);
const nodes = unmarshalNodes(returnedNodes, rootNode.tree);
const nodes = unmarshalNodes(returnedNodes, node.tree);
const results = [];

@@ -560,9 +682,20 @@

Query.prototype.captures = function(rootNode, startPosition = ZERO_POINT, endPosition = ZERO_POINT) {
marshalNode(rootNode);
const [returnedMatches, returnedNodes] = _captures.call(this, rootNode.tree,
Query.prototype.captures = function(
node,
{
startPosition = ZERO_POINT,
endPosition = ZERO_POINT,
startIndex = 0,
endIndex = 0,
matchLimit = 0xFFFFFFFF,
maxStartDepth = 0xFFFFFFFF
} = {}
) {
marshalNode(node);
const [returnedMatches, returnedNodes] = _captures.call(this, node.tree,
startPosition.row, startPosition.column,
endPosition.row, endPosition.column
endPosition.row, endPosition.column,
startIndex, endIndex, matchLimit, maxStartDepth
);
const nodes = unmarshalNodes(returnedNodes, rootNode.tree);
const nodes = unmarshalNodes(returnedNodes, node.tree);
const results = [];

@@ -601,2 +734,19 @@

/*
* LookaheadIterator
*/
LookaheadIterator.prototype[Symbol.iterator] = function() {
const self = this;
return {
next() {
if (self._next()) {
return {done: false, value: self.currentType};
}
return {done: true, value: ''};
},
};
}
/*
* Other functions

@@ -617,3 +767,3 @@ */

}
return result.substr(0, goalLength);
return result.slice(0, goalLength);
}

@@ -757,3 +907,3 @@

function camelCase(name, upperCase) {
name = name.replace(/_(\w)/g, (match, letter) => letter.toUpperCase());
name = name.replace(/_(\w)/g, (_match, letter) => letter.toUpperCase());
if (upperCase) name = name[0].toUpperCase() + name.slice(1);

@@ -768,1 +918,2 @@ return name;

module.exports.TreeCursor = TreeCursor;
module.exports.LookaheadIterator = LookaheadIterator;
{
"name": "tree-sitter",
"version": "0.20.6",
"version": "0.21.0",
"description": "Incremental parsers for node",
"author": "Max Brunsfeld",
"contributors": [
"Segev Finer",
"Boris Verkhovskiy",
"Amaan Qureshi"
],
"license": "MIT",

@@ -12,27 +17,46 @@ "repository": {

"keywords": [
"parser",
"lexer"
"incremental",
"parsing",
"tree-sitter"
],
"main": "index.js",
"types": "tree-sitter.d.ts",
"files": [
"binding.gyp",
"tree-sitter.d.ts",
"prebuilds/*",
"src/*",
"vendor/tree-sitter/lib/include/*",
"vendor/tree-sitter/lib/src/*"
],
"dependencies": {
"nan": "^2.18.0",
"prebuild-install": "^7.1.1"
"node-addon-api": "^7.1.0",
"node-gyp-build": "^4.8.0"
},
"devDependencies": {
"@types/node": "^20.5.9",
"chai": "^4.3.8",
"jest": "^24.0.0",
"@types/node": "^20.11.16",
"chai": "^4.3.10",
"mocha": "^8.4.0",
"node-gyp": "^9.4.0",
"prebuild": "^12.0.0",
"tree-sitter-javascript": "https://github.com/tree-sitter/tree-sitter-javascript.git#master"
"node-gyp": "^10.0.1",
"prebuildify": "^6.0.0",
"tmp": "^0.2.1",
"tree-sitter-c": "github:amaanq/tree-sitter-c#napi",
"tree-sitter-embedded-template": "github:tree-sitter/tree-sitter-embedded-template#napi",
"tree-sitter-html": "github:amaanq/tree-sitter-html#napi",
"tree-sitter-java": "github:amaanq/tree-sitter-java#napi",
"tree-sitter-javascript": "github:amaanq/tree-sitter-javascript#napi",
"tree-sitter-json": "github:tree-sitter/tree-sitter-json#napi",
"tree-sitter-python": "github:amaanq/tree-sitter-python#napi",
"tree-sitter-ruby": "github:tree-sitter/tree-sitter-ruby#napi",
"tree-sitter-rust": "github:amaanq/tree-sitter-rust#napi"
},
"scripts": {
"install": "prebuild-install || node-gyp rebuild",
"build": "node-gyp build",
"prebuild": "prebuild -t 10.0.0 -t 12.0.0 -t 14.0.0 -t 16.0.0 -t 18.0.0 -t 20.0.0 --strip && prebuild -r electron -t 3.0.0 -t 4.0.0 -t 5.0.0 -t 20.0.0 -t 21.0.0 -t 22.0.0 -t 23.0.0 -t 24.0.0 -t 25.0.0 --strip",
"prebuild:upload": "prebuild --upload-all",
"test": "mocha && jest"
"install": "node-gyp-build",
"build": "prebuildify --napi --strip",
"rebuild": "node-gyp rebuild",
"test": "mocha"
},
"publishConfig": {
"access": "public"
}
}
declare module "tree-sitter" {
class Parser {
parse(input: string | Parser.Input | Parser.InputReader, oldTree?: Parser.Tree, options?: { bufferSize?: number, includedRanges?: Parser.Range[] }): Parser.Tree;
parse(input: string | Parser.Input, oldTree?: Parser.Tree, options?: Parser.Options): Parser.Tree;
getIncludedRanges(): Parser.Range[];
getTimeoutMicros(): number;
setTimeoutMicros(timeout: number): void;
reset(): void;
getLanguage(): any;
setLanguage(language: any): void;
setLanguage(language?: any): void;
getLogger(): Parser.Logger;
setLogger(logFunc: Parser.Logger): void;
printDotGraphs(enabled: boolean): void;
setLogger(logFunc?: Parser.Logger | false | null): void;
printDotGraphs(enabled?: boolean, fd?: number): void;
}
namespace Parser {
export type Options = {
bufferSize?: number, includedRanges?: Range[];
};
export type Point = {

@@ -35,13 +43,8 @@ row: number;

message: string,
params: {[param: string]: string},
params: { [param: string]: string },
type: "parse" | "lex"
) => void;
export interface InputReader {
(index: any, position: Point): string;
}
export interface Input {
seek(index: number): void;
read(): any;
(index: number, position?: Point): string | null;
}

@@ -51,6 +54,16 @@

tree: Tree;
id: number;
typeId: number;
grammarId: number;
type: string;
typeId: string;
grammarType: string;
isNamed: boolean;
isMissing: boolean;
isExtra: boolean;
hasChanges: boolean;
hasError: boolean;
isError: boolean;
text: string;
parseState: number;
nextParseState: number;
startPosition: Point;

@@ -73,9 +86,12 @@ endPosition: Point;

previousNamedSibling: SyntaxNode | null;
descendantCount: number;
hasChanges(): boolean;
hasError(): boolean;
isMissing(): boolean;
toString(): string;
child(index: number): SyntaxNode | null;
namedChild(index: number): SyntaxNode | null;
childForFieldName(fieldName: string): SyntaxNode | null;
childForFieldId(fieldId: number): SyntaxNode | null;
fieldNameForChild(childIndex: number): string | null;
childrenForFieldName(fieldName: string): Array<SyntaxNode>;
childrenForFieldId(fieldId: number): Array<SyntaxNode>;
firstChildForIndex(index: number): SyntaxNode | null;

@@ -100,2 +116,4 @@ firstNamedChildForIndex(index: number): SyntaxNode | null;

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

@@ -110,8 +128,16 @@ nodeIsNamed: boolean;

readonly currentFieldName: string;
readonly currentFieldId: number;
readonly currentDepth: number;
readonly currentDescendantIndex: number;
reset(node: SyntaxNode): void
reset(node: SyntaxNode): void;
resetTo(cursor: TreeCursor): void;
gotoParent(): boolean;
gotoFirstChild(): boolean;
gotoFirstChildForIndex(index: number): boolean;
gotoLastChild(): boolean;
gotoFirstChildForIndex(goalIndex: number): boolean;
gotoFirstChildForPosition(goalPosition: Point): boolean;
gotoNextSibling(): boolean;
gotoPreviousSibling(): boolean;
gotoDescendant(goalDescendantIndex: number): void;
}

@@ -122,21 +148,37 @@

rootNodeWithOffset(offsetBytes: number, offsetExtent: Point): SyntaxNode;
edit(delta: Edit): Tree;
walk(): TreeCursor;
getChangedRanges(other: Tree): Range[];
getIncludedRanges(): Range[];
getEditedRange(other: Tree): Range;
printDotGraph(): void;
printDotGraph(fd?: number): void;
}
export interface QueryCapture {
name: string;
text?: string;
node: SyntaxNode;
setProperties?: { [prop: string]: string | null };
assertedProperties?: { [prop: string]: string | null };
refutedProperties?: { [prop: string]: string | null };
}
export interface QueryMatch {
pattern: number,
captures: QueryCapture[],
pattern: number;
captures: QueryCapture[];
}
export interface QueryCapture {
name: string,
text?: string,
node: SyntaxNode,
setProperties?: {[prop: string]: string | null},
assertedProperties?: {[prop: string]: string | null},
refutedProperties?: {[prop: string]: string | null},
export type QueryOptions = {
startPosition?: Point;
endPosition?: Point;
startIndex?: number;
endIndex?: number;
matchLimit?: number;
maxStartDepth?: number;
};
export interface PredicateResult {
operator: string;
operands: { name: string; type: string }[];
}

@@ -149,8 +191,25 @@

readonly refutedProperties: any[];
readonly matchLimit: number;
constructor(language: any, source: string | Buffer);
matches(rootNode: SyntaxNode, startPosition?: Point, endPosition?: Point): QueryMatch[];
captures(rootNode: SyntaxNode, startPosition?: Point, endPosition?: Point): QueryCapture[];
captures(node: SyntaxNode, options?: QueryOptions): QueryCapture[];
matches(node: SyntaxNode, options?: QueryOptions): QueryMatch[];
disableCapture(captureName: string): void;
disablePattern(patternIndex: number): void;
isPatternGuaranteedAtStep(byteOffset: number): boolean;
isPatternRooted(patternIndex: number): boolean;
isPatternNonLocal(patternIndex: number): boolean;
startIndexForPattern(patternIndex: number): number;
didExceedMatchLimit(): boolean;
}
export class LookaheadIterable {
readonly currentTypeId: number;
readonly currentType: string;
reset(language: any, stateId: number): boolean;
resetState(stateId: number): boolean;
[Symbol.iterator](): Iterator<string>;
}
}

@@ -157,0 +216,0 @@

@@ -1,3 +0,2 @@

Subdirectories
--------------
## Subdirectories

@@ -4,0 +3,0 @@ * [`src`](./src) - C source code for the Tree-sitter library

# tree-sitter
[![Build Status](https://github.com/tree-sitter/tree-sitter/workflows/CI/badge.svg)](https://github.com/tree-sitter/tree-sitter/actions)
[![Build status](https://ci.appveyor.com/api/projects/status/vtmbd6i92e97l55w/branch/master?svg=true)](https://ci.appveyor.com/project/maxbrunsfeld/tree-sitter/branch/master)
[![DOI](https://zenodo.org/badge/14164618.svg)](https://zenodo.org/badge/latestdoi/14164618)

@@ -6,0 +4,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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