1- /** @type {typeof import('tree-sitter') } */
2- const Parser = require ( "../index.js" ) ;
1+ /// <reference path="../tree-sitter.d.ts" />
2+ /** @type {typeof import("tree-sitter") } */
3+ const Parser = require ( "../index" ) ;
34
45const C = require ( 'tree-sitter-c' ) ;
56const EmbeddedTemplate = require ( 'tree-sitter-embedded-template' ) ;
@@ -64,17 +65,15 @@ describe("Node", () => {
6465 ` ) ;
6566
6667 const classNode = tree . rootNode . firstChild ;
67- // @ts -ignore
6868 assert . deepEqual ( classNode . fields , [ 'bodyNode' , 'decoratorNodes' , 'nameNode' ] )
6969
70- // @ts -ignore
7170 const methodNode = classNode . bodyNode . firstNamedChild ;
7271 assert . equal ( methodNode . constructor . name , 'MethodDefinitionNode' ) ;
7372 assert . equal ( methodNode . nameNode . text , 'b' ) ;
7473 assert . deepEqual ( methodNode . fields , [ 'bodyNode' , 'decoratorNodes' , 'nameNode' , 'parametersNode' ] )
7574
7675 const decoratorNodes = methodNode . decoratorNodes ;
77- assert . deepEqual ( decoratorNodes . map ( _ => _ . text ) , [ '@autobind' , '@something' ] )
76+ assert . deepEqual ( decoratorNodes . map ( n => n . text ) , [ '@autobind' , '@something' ] )
7877
7978 const paramsNode = methodNode . parametersNode ;
8079 assert . equal ( paramsNode . constructor . name , 'FormalParametersNode' ) ;
@@ -707,14 +706,14 @@ describe("Node", () => {
707706
708707 describe ( ".text" , ( ) => {
709708 Object . entries ( {
710- '.parse(String)' : ( parser , src ) => parser . parse ( src ) ,
711- '.parse(Function)' : ( parser , src ) =>
712- parser . parse ( offset => src . substr ( offset , 4 ) ) ,
709+ '.parse(String)' : ( /** @type { import('tree-sitter') } */ parser , /** @type { string } */ src ) => parser . parse ( src ) ,
710+ '.parse(Function)' : ( /** @type { import('tree-sitter') } */ parser , /** @type { string } */ src ) =>
711+ parser . parse ( offset => src . substring ( offset , offset + 4 ) ) ,
713712 } ) . forEach ( ( [ method , parse ] ) =>
714713 it ( `returns the text of a node generated by ${ method } ` , async ( ) => {
715714 const src = "α0 / b👎c👎"
716715 const [ numeratorSrc , denominatorSrc ] = src . split ( / \s * \/ \s + / )
717- const tree = await parse ( parser , src )
716+ const tree = parse ( parser , src )
718717 const quotientNode = tree . rootNode . firstChild . firstChild ;
719718 const [ numerator , slash , denominator ] = quotientNode . children ;
720719
@@ -921,10 +920,8 @@ describe("Node", () => {
921920 it ( "shouldn't segfault when accessing properties on the prototype" , ( ) => {
922921 const tree = parser . parse ( '2 + 2' ) ;
923922 const nodePrototype = Object . getPrototypeOf ( tree . rootNode ) ;
924- // const nodePrototype = tree.rootNode.__proto__;
925923
926924 const properties = [
927- "type" ,
928925 "typeId" ,
929926 "isNamed" ,
930927 "isMissing" ,
@@ -950,6 +947,9 @@ describe("Node", () => {
950947 "previousSibling" ,
951948 "previousNamedSibling" ,
952949 ] ;
950+ if ( nodePrototype . constructor . name === "SyntaxNode" ) {
951+ assert . throws ( ( ) => { nodePrototype . type ; } , TypeError )
952+ }
953953 for ( const property of properties ) {
954954 assert . throws ( ( ) => { nodePrototype [ property ] ; } , TypeError )
955955 }
0 commit comments