Skip to content

Commit

Permalink
fix cache check bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcisbee committed Jul 3, 2024
1 parent f76439a commit 0f85f30
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@marcisbee/nanolex",
"version": "0.3.0",
"version": "0.3.1",
"exports": "./src/nanolex.ts"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nanolex",
"version": "0.3.0",
"version": "0.3.1",
"description": "Parser grammar builder",
"main": "./dist/nanolex.js",
"module": "./dist/nanolex.mjs",
Expand Down
9 changes: 6 additions & 3 deletions src/nanolex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,23 @@ export function createToken(
const source = isString
? token.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&")
: token.source;
const _c: Record<string, boolean> = {};
const cache = new Map<string, boolean>();

return {
token,
name,
source,
test(value: string) {
test(value: string): boolean {
if (isString) {
return value === token;
}

// return value.match(token)?.[0] === value;

return (_c[value] ??= value.match(token)?.[0] === value);
let v: boolean;
return cache.has(value)
? cache.get(value)!
: ((v = value.match(token)?.[0] === value), cache.set(value, v), v);

// const regex = new RegExp(`^${this.source}\$`);
// return regex.test(value);
Expand Down

0 comments on commit 0f85f30

Please sign in to comment.