fix(wasm): restore passing in ERROR to descendantsOfType (#4226)
This commit is contained in:
parent
b26b7f8d62
commit
3b67861def
2 changed files with 24 additions and 1 deletions
|
|
@ -416,6 +416,11 @@ export class Node {
|
|||
// Convert the type strings to numeric type symbols
|
||||
const symbols: number[] = [];
|
||||
const typesBySymbol = this.tree.language.types;
|
||||
for (const node_type of types) {
|
||||
if (node_type == "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);
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ describe('Node', () => {
|
|||
tree = parser.parse('x10 + 1000')!;
|
||||
expect(tree.rootNode.children).toHaveLength(1);
|
||||
const sumNode = tree.rootNode.firstChild!.firstChild!;
|
||||
expect(sumNode.children.map(child => child!.type)).toEqual(['identifier', '+', 'number' ]);
|
||||
expect(sumNode.children.map(child => child!.type)).toEqual(['identifier', '+', 'number']);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -449,6 +449,24 @@ describe('Node', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('.descendantsOfType("ERROR")', () => {
|
||||
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;
|
||||
const descendants = errorNode.descendantsOfType('ERROR');
|
||||
expect(
|
||||
descendants.map((node) => node!.startIndex)
|
||||
).toEqual(
|
||||
[4]
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.descendantsOfType', () => {
|
||||
it('finds all descendants of a given type in the given range', () => {
|
||||
tree = parser.parse('a + 1 * b * 2 + c + 3')!;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue