File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -416,6 +416,11 @@ export class Node {
416416 // Convert the type strings to numeric type symbols
417417 const symbols : number [ ] = [ ] ;
418418 const typesBySymbol = this . tree . language . types ;
419+ for ( const node_type of types ) {
420+ if ( node_type == "ERROR" ) {
421+ symbols . push ( 65535 ) ; // Internally, ts_builtin_sym_error is -1, which is UINT_16MAX
422+ }
423+ }
419424 for ( let i = 0 , n = typesBySymbol . length ; i < n ; i ++ ) {
420425 if ( types . includes ( typesBySymbol [ i ] ) ) {
421426 symbols . push ( i ) ;
Original file line number Diff line number Diff line change @@ -63,7 +63,7 @@ describe('Node', () => {
6363 tree = parser . parse ( 'x10 + 1000' ) ! ;
6464 expect ( tree . rootNode . children ) . toHaveLength ( 1 ) ;
6565 const sumNode = tree . rootNode . firstChild ! . firstChild ! ;
66- expect ( sumNode . children . map ( child => child ! . type ) ) . toEqual ( [ 'identifier' , '+' , 'number' ] ) ;
66+ expect ( sumNode . children . map ( child => child ! . type ) ) . toEqual ( [ 'identifier' , '+' , 'number' ] ) ;
6767 } ) ;
6868 } ) ;
6969
@@ -449,6 +449,24 @@ describe('Node', () => {
449449 } ) ;
450450 } ) ;
451451
452+ describe ( '.descendantsOfType("ERROR")' , ( ) => {
453+ it ( 'finds all of the descendants of an ERROR node' , ( ) => {
454+ tree = parser . parse (
455+ `if ({a: 'b'} {c: 'd'}) {
456+ // ^ ERROR
457+ x = function(a) { b; } function(c) { d; }
458+ }`
459+ ) ! ;
460+ const errorNode = tree . rootNode ;
461+ const descendants = errorNode . descendantsOfType ( 'ERROR' ) ;
462+ expect (
463+ descendants . map ( ( node ) => node ! . startIndex )
464+ ) . toEqual (
465+ [ 4 ]
466+ ) ;
467+ } ) ;
468+ } ) ;
469+
452470 describe ( '.descendantsOfType' , ( ) => {
453471 it ( 'finds all descendants of a given type in the given range' , ( ) => {
454472 tree = parser . parse ( 'a + 1 * b * 2 + c + 3' ) ! ;
You can’t perform that action at this time.
0 commit comments