Welcome to the node-tree-sitter wiki, the following documentation will help new developers on common workflows of node-tree-sitter.
Simple Usage:
const Parser = require('tree-sitter');
const JavaScript = require('tree-sitter-javascript');
const parser = new Parser();
parser.setLanguage(JavaScript);
Then you can parse some source code,
const sourceCode = 'let x = 1; console.log(x);';
const tree = parser.parse(sourceCode);
Common API:
root of the tree
tree.rootNode
ProgramNode {
type: program,
startPosition: {row: 0, column: 0},
endPosition: {row: 0, column: 26},
childCount: 2,
}
array type of the children
tree.rootNode.children
[
LexicalDeclarationNode {
type: lexical_declaration,
startPosition: {row: 0, column: 0},
endPosition: {row: 0, column: 10},
childCount: 3,
},
ExpressionStatementNode {
type: expression_statement,
startPosition: {row: 0, column: 11},
endPosition: {row: 0, column: 26},
childCount: 2,
}
]
// please add more helpful api here
(may the developers contribute more docs to help us. thank you.)