tree-sitter / node-tree-sitter

Node.js bindings for tree-sitter
https://www.npmjs.com/package/tree-sitter
MIT License
649 stars 114 forks source link

Add text accessors for nodes and tree cursors #20

Closed maxbrunsfeld closed 6 years ago

maxbrunsfeld commented 6 years ago

This adds a .text property to syntax nodes so that you can conveniently access their text without having to manually slice the source string using the node's startIndex and endIndex.

I was originally hesitant to add this because it was trivially achievable already and I wasn't sure if all applications would want to retain the source string in memory after parsing, but it seems like most users probably want this.

Closes https://github.com/tree-sitter/node-tree-sitter/issues/22