1- const Parser = require ( ".." ) ;
1+ /** @type {typeof import('tree-sitter') } */
2+ const Parser = require ( "../index.js" ) ;
23const JavaScript = require ( 'tree-sitter-javascript' ) ;
34const Rust = require ( 'tree-sitter-rust' ) ;
45const assert = require ( 'node:assert' ) ;
56const { beforeEach, describe, it } = require ( 'node:test' ) ;
67
78describe ( "Tree" , ( ) => {
9+ /** @type {import('tree-sitter') } */
810 let parser ;
911
1012 beforeEach ( ( ) => {
@@ -13,7 +15,14 @@ describe("Tree", () => {
1315 } ) ;
1416
1517 describe ( '.edit' , ( ) => {
16- let input , edit
18+ /** @type {string } */
19+ let input ;
20+
21+ /** @type {import('tree-sitter').Edit } */
22+ let edit ;
23+
24+ /** @type {import('tree-sitter').Tree } */
25+ let tree ;
1726
1827 it ( 'updates the positions of existing nodes' , ( ) => {
1928 input = 'abc + cde' ;
@@ -32,7 +41,7 @@ describe("Tree", () => {
3241 assert . equal ( variableNode2 . startIndex , 6 ) ;
3342 assert . equal ( variableNode2 . endIndex , 9 ) ;
3443
35- ( [ input , edit ] = spliceInput ( input , input . indexOf ( 'bc' ) , 0 , ' * ' ) ) ;
44+ [ input , edit ] = spliceInput ( input , input . indexOf ( 'bc' ) , 0 , ' * ' ) ;
3645 assert . equal ( input , 'a * bc + cde' ) ;
3746
3847 tree . edit ( edit ) ;
@@ -59,7 +68,7 @@ describe("Tree", () => {
5968
6069 const variableNode = tree . rootNode . firstChild . firstChild . lastChild ;
6170
62- ( [ input , edit ] = spliceInput ( input , input . indexOf ( 'δ' ) , 0 , '👍 * ' ) ) ;
71+ [ input , edit ] = spliceInput ( input , input . indexOf ( 'δ' ) , 0 , '👍 * ' ) ;
6372 assert . equal ( input , 'αβ👍 * δ + cde' ) ;
6473
6574 tree . edit ( edit ) ;
@@ -78,6 +87,7 @@ describe("Tree", () => {
7887 const inputString = 'abc + def + ghi + jkl + mno' ;
7988 const tree = parser . parse ( inputString ) ;
8089
90+ // @ts -ignore
8191 assert . equal ( tree . getEditedRange ( ) , null )
8292
8393 tree . edit ( {
@@ -98,6 +108,7 @@ describe("Tree", () => {
98108 newEndPosition : { row : 0 , column : 22 }
99109 } ) ;
100110
111+ // @ts -ignore
101112 assert . deepEqual ( tree . getEditedRange ( ) , {
102113 startIndex : 6 ,
103114 endIndex : 23 ,
@@ -148,6 +159,7 @@ describe("Tree", () => {
148159 const tree1 = parser . parse ( "abcdefg + hij" ) ;
149160
150161 assert . throws ( ( ) => {
162+ // @ts -ignore
151163 tree1 . getChangedRanges ( { } ) ;
152164 } , / A r g u m e n t m u s t b e a t r e e / ) ;
153165 } )
@@ -157,22 +169,6 @@ describe("Tree", () => {
157169 it ( "returns a cursor that can be used to walk the tree" , ( ) => {
158170 parser . setLanguage ( Rust ) ;
159171
160- // let mut parser = Parser::new();
161- // parser.set_language(&get_language("rust")).unwrap();
162- //
163- // let tree = parser
164- // .parse(
165- // "
166- // struct Stuff {
167- // a: A,
168- // b: Option<B>,
169- // }
170- // ",
171- // None,
172- // )
173- // .unwrap();
174- //
175-
176172 const tree = parser . parse ( `
177173 struct Stuff {
178174 a: A,
@@ -589,6 +585,10 @@ describe("Tree", () => {
589585 } ) ;
590586} ) ;
591587
588+ /**
589+ * @param {import('tree-sitter').TreeCursor } cursor
590+ * @param {Object } params
591+ */
592592function assertCursorState ( cursor , params ) {
593593 assert . strictEqual ( typeof cursor . nodeIsNamed , 'boolean' ) ;
594594 assert . strictEqual ( typeof cursor . nodeIsMissing , 'boolean' ) ;
@@ -611,6 +611,14 @@ function assertCursorState(cursor, params) {
611611 assert . deepEqual ( node . endIndex , params . endIndex ) ;
612612}
613613
614+ /**
615+ * @param {string } input
616+ * @param {number } startIndex
617+ * @param {number } lengthRemoved
618+ * @param {string } newText
619+ *
620+ * @returns {[string, import('tree-sitter').Edit] }
621+ */
614622function spliceInput ( input , startIndex , lengthRemoved , newText ) {
615623 const oldEndIndex = startIndex + lengthRemoved ;
616624 const newEndIndex = startIndex + newText . length ;
@@ -628,6 +636,9 @@ function spliceInput(input, startIndex, lengthRemoved, newText) {
628636 ] ;
629637}
630638
639+ /**
640+ * @param {string } text
641+ */
631642function getExtent ( text ) {
632643 let row = 0
633644 let index ;
0 commit comments