Add TreeCursor.currentFieldName to wasm binding
This commit is contained in:
parent
c90a532d8f
commit
1a33f1a665
4 changed files with 51 additions and 0 deletions
|
|
@ -263,6 +263,34 @@ describe("Tree", () => {
|
|||
assert(!cursor.gotoParent());
|
||||
});
|
||||
|
||||
it('keeps track of the field name associated with each node', () => {
|
||||
tree = parser.parse('a.b();');
|
||||
cursor = tree.walk();
|
||||
cursor.gotoFirstChild();
|
||||
cursor.gotoFirstChild();
|
||||
|
||||
assert.equal(cursor.currentNode().type, 'call_expression');
|
||||
assert.equal(cursor.currentFieldName(), null);
|
||||
|
||||
cursor.gotoFirstChild();
|
||||
assert.equal(cursor.currentNode().type, 'member_expression');
|
||||
assert.equal(cursor.currentFieldName(), 'function');
|
||||
|
||||
cursor.gotoFirstChild();
|
||||
assert.equal(cursor.currentNode().type, 'identifier');
|
||||
assert.equal(cursor.currentFieldName(), 'object');
|
||||
|
||||
cursor.gotoNextSibling();
|
||||
cursor.gotoNextSibling();
|
||||
assert.equal(cursor.currentNode().type, 'property_identifier');
|
||||
assert.equal(cursor.currentFieldName(), 'property');
|
||||
|
||||
cursor.gotoParent();
|
||||
cursor.gotoNextSibling();
|
||||
assert.equal(cursor.currentNode().type, 'arguments');
|
||||
assert.equal(cursor.currentFieldName(), 'arguments');
|
||||
});
|
||||
|
||||
it('returns a cursor that can be reset anywhere in the tree', () => {
|
||||
tree = parser.parse('a * b + c / d');
|
||||
cursor = tree.walk();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue