Skip to content

Commit 53949b0

Browse files
authored
Merge pull request tree-sitter#819 from joelspadin/equals-fix
web binding: fix equals()
2 parents 2bf9c01 + 7ef73b2 commit 53949b0

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

lib/binding_web/binding.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff 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) {

lib/binding_web/test/node-test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,4 +388,24 @@ describe("Node", () => {
388388
assert.throws(() => number.closest({a: 1}), /Argument must be a string or array of strings/)
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
});

0 commit comments

Comments
 (0)