Skip to content

Commit 823fd7c

Browse files
committed
feat: interpreter cache
1 parent b6bf740 commit 823fd7c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

interpreter.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,19 @@ import type {
77
} from "./types.ts";
88

99
export class Interpreter implements Runtime {
10+
_cache: Map<string, AstTemplate> = new Map();
11+
1012
execute(
1113
text: string,
1214
parameters: FormatParameters,
1315
decorateValue?: (value: FormatParameterValue) => unknown,
1416
): string {
15-
return this.executeAst(parse(text), parameters, decorateValue);
17+
let ast = this._cache.get(text);
18+
if (!ast) {
19+
ast = parse(text);
20+
this._cache.set(text, ast);
21+
}
22+
return this.executeAst(ast, parameters, decorateValue);
1623
}
1724

1825
executeAst(

0 commit comments

Comments
 (0)