diff --git a/lib/binding_web/binding.js b/lib/binding_web/binding.js index d5c33856..e01addaf 100644 --- a/lib/binding_web/binding.js +++ b/lib/binding_web/binding.js @@ -501,6 +501,11 @@ class Node { // Convert the type strings to numeric type symbols. const symbols = []; const typesBySymbol = this.tree.language.types; + for (let i = 0; i < types.length; i++) { + if (types[i] == "ERROR") { + symbols.push(65535); // Internally, ts_builtin_sym_error is -1, which is UINT_16MAX + } + } for (let i = 0, n = typesBySymbol.length; i < n; i++) { if (types.includes(typesBySymbol[i])) { symbols.push(i); diff --git a/lib/binding_web/test/node-test.js b/lib/binding_web/test/node-test.js index 3aa76383..aa2e4bde 100644 --- a/lib/binding_web/test/node-test.js +++ b/lib/binding_web/test/node-test.js @@ -494,6 +494,23 @@ describe('Node', () => { }); }); + describe('.descendantsOfType("ERROR", null, null)', () => { + it('finds all of the descendants of an ERROR node', () => { + tree = parser.parse( + `if ({a: 'b'} {c: 'd'}) { + // ^ ERROR + x = function(a) { b; } function(c) { d; } + }` + ); + const errorNode = tree.rootNode; + let descendants = errorNode.descendantsOfType('ERROR', null, null); + assert.deepEqual( + descendants.map((node) => node.startIndex), + [4], + ); + }); + }); + describe('.descendantsOfType(type, min, max)', () => { it('finds all of the descendants of the given type in the given range', () => { tree = parser.parse('a + 1 * b * 2 + c + 3');