2
0
mirror of https://github.com/tenrok/BBob.git synced 2026-06-20 20:00:33 +03:00

feat: add start and end positions of tag nodes (#246)

Closes #134

* feat: Add start and end positions of tag nodes

Improves accuracy of row/col error reporting. Now targets the start of the relevant token instead of the end.

* Simplify language for TagNode and Token

* Update static TagNode.create to ingest setStart() logic

improve readability of end pos offset for no attr tags
This commit is contained in:
Steven Chang
2024-08-01 00:42:29 -07:00
committed by GitHub
parent 0beab56d7f
commit 40848747d4
13 changed files with 929 additions and 386 deletions
+12 -2
View File
@@ -1,10 +1,10 @@
import Token, { TYPE_WORD, TYPE_TAG, TYPE_ATTR_NAME, TYPE_ATTR_VALUE, TYPE_SPACE, TYPE_NEW_LINE } from '../src/Token'
import Token, { TYPE_WORD, TYPE_TAG, TYPE_ATTR_NAME, TYPE_ATTR_VALUE, TYPE_SPACE, TYPE_NEW_LINE } from '../src/Token';
describe('Token', () => {
test('isEmpty', () => {
const token = new Token();
expect(token.isEmpty()).toBeTruthy()
expect(token.isEmpty()).toBeTruthy();
});
test('isText', () => {
const token = new Token(TYPE_WORD);
@@ -56,6 +56,16 @@ describe('Token', () => {
expect(token.getColumn()).toBe(14);
});
test('getStartPos', () => {
const token = new Token(TYPE_TAG, 'my-tag', 12, 14, 50);
expect(token.getStart()).toBe(50);
});
test('getEndPos', () => {
const token = new Token(TYPE_TAG, 'my-tag', 12, 14, 50, 60);
expect(token.getEnd()).toBe(60);
});
test('toString', () => {
const tokenEnd = new Token(TYPE_TAG, '/my-tag', 12, 14);