refactor(js): misc fixes & tidying

This commit is contained in:
Amaan Qureshi 2024-04-09 21:44:37 -04:00
parent abc7910381
commit 96d18408a3
7 changed files with 80 additions and 94 deletions

View file

@ -244,62 +244,47 @@ describe('Tree', () => {
endIndex: 13,
});
{
const copy = tree.walk();
copy.resetTo(cursor);
const copy = tree.walk();
copy.resetTo(cursor);
assert(copy.gotoPreviousSibling());
assertCursorState(copy, {
nodeType: '+',
nodeIsNamed: false,
startPosition: {row: 0, column: 6},
endPosition: {row: 0, column: 7},
startIndex: 6,
endIndex: 7,
});
assert(copy.gotoPreviousSibling());
assertCursorState(copy, {
nodeType: '+',
nodeIsNamed: false,
startPosition: {row: 0, column: 6},
endPosition: {row: 0, column: 7},
startIndex: 6,
endIndex: 7,
});
assert(copy.gotoPreviousSibling());
assertCursorState(copy, {
nodeType: 'binary_expression',
nodeIsNamed: true,
startPosition: {row: 0, column: 0},
endPosition: {row: 0, column: 5},
startIndex: 0,
endIndex: 5,
});
assert(copy.gotoPreviousSibling());
assertCursorState(copy, {
nodeType: 'binary_expression',
nodeIsNamed: true,
startPosition: {row: 0, column: 0},
endPosition: {row: 0, column: 5},
startIndex: 0,
endIndex: 5,
});
assert(copy.gotoLastChild());
assertCursorState(copy, {
nodeType: 'identifier',
nodeIsNamed: true,
startPosition: {row: 0, column: 4},
endPosition: {row: 0, column: 5},
startIndex: 4,
endIndex: 5,
});
assert(copy.gotoLastChild());
assertCursorState(copy, {
nodeType: 'identifier',
nodeIsNamed: true,
startPosition: {row: 0, column: 4},
endPosition: {row: 0, column: 5},
startIndex: 4,
endIndex: 5,
});
assert(copy.gotoParent());
assert(copy.gotoParent());
assert.equal(copy.nodeType, 'binary_expression');
assert(copy.gotoParent());
assert.equal(copy.nodeType, 'expression_statement');
assert(copy.gotoParent());
assert.equal(copy.nodeType, 'program');
assert(!copy.gotoParent());
}
// const childIndex = cursor.gotoFirstChildForIndex(12);
// assertCursorState(cursor, {
// nodeType: 'identifier',
// nodeIsNamed: true,
// startPosition: {row: 0, column: 12},
// endPosition: {row: 0, column: 13},
// startIndex: 12,
// endIndex: 13
// });
// assert.equal(childIndex, 2);
// assert(!cursor.gotoNextSibling());
// assert(cursor.gotoParent());
assert(copy.gotoParent());
assert(copy.gotoParent());
assert.equal(copy.nodeType, 'binary_expression');
assert(copy.gotoParent());
assert.equal(copy.nodeType, 'expression_statement');
assert(copy.gotoParent());
assert.equal(copy.nodeType, 'program');
assert(!copy.gotoParent());
assert(cursor.gotoParent());
assert.equal(cursor.nodeType, 'binary_expression');
@ -414,7 +399,7 @@ function spliceInput(input, startIndex, lengthRemoved, newText) {
function getExtent(text) {
let row = 0;
let index;
for (index = 0; index != -1; index = text.indexOf('\n', index)) {
for (index = 0; index !== -1; index = text.indexOf('\n', index)) {
index++;
row++;
}