File tree Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -258,11 +258,7 @@ class Node {
258258 }
259259
260260 equals ( other ) {
261- if ( this === other ) return true ;
262- for ( let i = 0 ; i < 5 ; i ++ ) {
263- if ( this [ i ] !== other [ i ] ) return false ;
264- }
265- return true ;
261+ return this . id === other . id ;
266262 }
267263
268264 child ( index ) {
Original file line number Diff line number Diff line change @@ -388,4 +388,24 @@ describe("Node", () => {
388388 assert . throws ( ( ) => number . closest ( { a : 1 } ) , / A r g u m e n t m u s t b e a s t r i n g o r a r r a y o f s t r i n g s / )
389389 } ) ;
390390 } ) ;
391+
392+ describe ( '.equals(other)' , ( ) => {
393+ it ( 'returns true if the nodes are the same' , ( ) => {
394+ tree = parser . parse ( '1 + 2' ) ;
395+
396+ const sumNode = tree . rootNode . firstChild . firstChild ;
397+ const node1 = sumNode . firstChild ;
398+ const node2 = sumNode . firstChild ;
399+ assert ( node1 . equals ( node2 ) ) ;
400+ } ) ;
401+
402+ it ( 'returns false if the nodes are not the same' , ( ) => {
403+ tree = parser . parse ( '1 + 2' ) ;
404+
405+ const sumNode = tree . rootNode . firstChild . firstChild ;
406+ const node1 = sumNode . firstChild ;
407+ const node2 = node1 . nextSibling ;
408+ assert ( ! node1 . equals ( node2 ) ) ;
409+ } ) ;
410+ } ) ;
391411} ) ;
You can’t perform that action at this time.
0 commit comments