-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tokenizer): add line info to tokenizer
- Loading branch information
1 parent
e0e3d5e
commit 4a89828
Showing
6 changed files
with
112 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
packages/abell/src/vite-plugin-abell/compiler/tokenizer.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { describe, expect, test } from 'vitest'; | ||
import tokenize from './generic-tokenizer.js'; | ||
import { tokenSchema } from './token-schema.js'; | ||
|
||
describe('tokenize', () => { | ||
test("should return token that matches abell's schema", () => { | ||
const abellCode = ` | ||
<h1>{{ 2 + 3 }}</h1> | ||
{{ | ||
/* @declaration */ | ||
const a = 3; | ||
const b = 9; | ||
}} | ||
`; | ||
const tokens = tokenize(abellCode, tokenSchema, 'default'); | ||
expect(tokens).toMatchInlineSnapshot(` | ||
[ | ||
{ | ||
"text": " | ||
<h1>", | ||
"type": "default", | ||
}, | ||
{ | ||
"col": 9, | ||
"line": 2, | ||
"matches": [], | ||
"pos": 9, | ||
"text": "{{", | ||
"type": "BLOCK_START", | ||
}, | ||
{ | ||
"text": " 2 + 3 ", | ||
"type": "default", | ||
}, | ||
{ | ||
"col": 18, | ||
"line": 2, | ||
"matches": [], | ||
"pos": 18, | ||
"text": "}}", | ||
"type": "BLOCK_END", | ||
}, | ||
{ | ||
"text": "</h1> | ||
", | ||
"type": "default", | ||
}, | ||
{ | ||
"col": 5, | ||
"line": 3, | ||
"matches": [], | ||
"pos": 30, | ||
"text": "{{", | ||
"type": "BLOCK_START", | ||
}, | ||
{ | ||
"text": " | ||
/* @declaration */ | ||
const a = 3; | ||
const b = 9; | ||
", | ||
"type": "default", | ||
}, | ||
{ | ||
"col": 5, | ||
"line": 7, | ||
"matches": [], | ||
"pos": 100, | ||
"text": "}}", | ||
"type": "BLOCK_END", | ||
}, | ||
{ | ||
"text": " | ||
", | ||
"type": "default", | ||
}, | ||
] | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.