Skip to content

Commit 923c398

Browse files
feat: implement SyntaxNode.toJSON
1 parent a1c869e commit 923c398

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,15 @@ class SyntaxNode {
239239
return NodeMethods.toString(this.tree);
240240
}
241241

242+
toJSON() {
243+
return {
244+
type: this.type,
245+
startPosition: this.startPosition,
246+
endPosition: this.endPosition,
247+
childCount: this.childCount,
248+
}
249+
}
250+
242251
child(index) {
243252
marshalNode(this);
244253
return unmarshalNode(NodeMethods.child(this.tree, index), this.tree);

tree-sitter.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,11 @@ declare module "tree-sitter" {
340340
*/
341341
toString(): string;
342342

343+
/**
344+
* Convert this node to its JSON representation
345+
*/
346+
toJSON(): object;
347+
343348
/**
344349
* Get the node's child at the given index, where zero represents the first child.
345350
*

0 commit comments

Comments
 (0)