Skip to content

Commit 26b95ec

Browse files
committed
clear cache before parsing
1 parent 2327dde commit 26b95ec

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

src/main.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { ArrayResultError, isArrayResult } from "./array_result.ts";
1616
import { loadCustomDictionary } from "./dictionary.ts";
1717
import { checkLocalStorage, setIgnoreError } from "./local_storage.ts";
1818
import { translate } from "./mod.ts";
19-
import { clearCache } from "./parser/parser_lib.ts";
2019
import { settings } from "./settings.ts";
2120
import {
2221
loadFromElements,
@@ -219,7 +218,6 @@ function main(): void {
219218
confirmButton.addEventListener("click", () => {
220219
loadFromElements();
221220
updateLabel();
222-
clearCache();
223221
settingsDialogBox.close();
224222
});
225223
cancelButton.addEventListener("click", () => {
@@ -271,7 +269,6 @@ function main(): void {
271269
try {
272270
loadCustomDictionary(value);
273271
setIgnoreError(DICTIONARY_KEY, value);
274-
clearCache();
275272
customDictionaryDialogBox.close();
276273
} catch (error) {
277274
const errors = flattenError(error);

src/mod.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { translate as rawTranslate } from "./translator/translator.ts";
88

99
export { ArrayResultError, type ArrayResultOptions } from "./array_result.ts";
1010
export { loadCustomDictionary } from "./dictionary.ts";
11-
export { clearCache } from "./parser/parser_lib.ts";
1211
export {
1312
defaultSettings,
1413
type RedundancySettings,

src/parser/parser_lib.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ type InnerParser<T> = (input: Input) => ParserResult<T>;
1010
let source = "";
1111
const allMemo: Set<WeakRef<SourceMemo<unknown>>> = new Set();
1212

13-
export function clearCache(): void {
13+
function clearCache(): void {
1414
for (const memo of allMemo) {
1515
const ref = memo.deref();
1616
if (ref == null) {
@@ -68,9 +68,11 @@ export class Parser<T> {
6868
);
6969
}
7070
generateParser(): (source: string) => ArrayResult<T> {
71-
return (input) =>
72-
this.rawParser({ source: input, position: 0 })
71+
return (input) => {
72+
clearCache();
73+
return this.rawParser({ source: input, position: 0 })
7374
.map(({ value }) => value);
75+
};
7476
}
7577
map<U>(mapper: (value: T) => U): Parser<U> {
7678
return new Parser((input) =>

0 commit comments

Comments
 (0)