diff options
author | James Maa <jmaa@berkeley.edu> | 2024-05-09 15:42:35 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-09 07:42:35 +0000 |
commit | 13278a5cf67de69678d8c4c5fb97e6eb00c94c11 (patch) | |
tree | 1d77bcf97bb9c6f08c88c9f80ea0da735d5721c2 /ext/js/language | |
parent | 77fa1d0f64b66d6e4fe9c8795c7844206edbcaf2 (diff) |
Update eslint unsafe rule (#887)
* Enable @typescript-eslint/no-unsafe-assignment
* Updates
* Add missing import
* Updates
* Fix types?
* Fix tests
* Address comments
* Move TextProcessorVariant to types
* Update types/ext/translation-internal.d.ts
Co-authored-by: StefanVukovic99 <stefanvukovic44@gmail.com>
Signed-off-by: James Maa <jmaa@berkeley.edu>
---------
Signed-off-by: James Maa <jmaa@berkeley.edu>
Co-authored-by: toasted-nutbread <toasted-nutbread@users.noreply.github.com>
Co-authored-by: StefanVukovic99 <stefanvukovic44@gmail.com>
Diffstat (limited to 'ext/js/language')
-rw-r--r-- | ext/js/language/translator.js | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/ext/js/language/translator.js b/ext/js/language/translator.js index 845d53d5..0d26b2f0 100644 --- a/ext/js/language/translator.js +++ b/ext/js/language/translator.js @@ -289,6 +289,7 @@ export class Translator { return false; } + /** @type {Map<string, number>} */ const frequencyCounter = new Map(); for (const element of array1) { @@ -400,6 +401,7 @@ export class Translator { * @returns {Map<string, import('translation-internal').DatabaseDeinflection[]>} */ _groupDeinflectionsByTerm(deinflections) { + /** @type {Map<string, import('translation-internal').DatabaseDeinflection[]>} */ const result = new Map(); for (const deinflection of deinflections) { const {deinflectedText} = deinflection; @@ -455,7 +457,7 @@ export class Translator { /** @type {import('translation-internal').DatabaseDeinflection[]} */ const deinflections = []; const used = new Set(); - /** @type {Map<string, import('core').SafeAny>} */ + /** @type {import('translation-internal').TextCache} */ const sourceCache = new Map(); // For reusing text processors' outputs for ( @@ -498,14 +500,15 @@ export class Translator { /** * @param {import('language').TextProcessorWithId<unknown>[]} textProcessors - * @param {Map<string, unknown>} processorVariant + * @param {import('translation-internal').TextProcessorVariant} processorVariant * @param {string} text - * @param {Map<string, import('core').SafeAny>} textCache + * @param {import('translation-internal').TextCache} textCache * @returns {string} */ _applyTextProcessors(textProcessors, processorVariant, text, textCache) { for (const {id, textProcessor: {process}} of textProcessors) { const setting = processorVariant.get(id); + let level1 = textCache.get(text); if (!level1) { level1 = new Map(); @@ -522,7 +525,7 @@ export class Translator { text = process(text, setting); level2.set(setting, text); } else { - text = level2.get(setting); + text = level2.get(setting) || ''; } } @@ -681,6 +684,7 @@ export class Translator { /** @type {import('dictionary-database').TermExactRequest[]} */ const termList = []; const targetList = []; + /** @type {Map<string, {groups: import('translator').DictionaryEntryGroup[]}>} */ const targetMap = new Map(); for (const group of groupedDictionaryEntries) { @@ -1362,10 +1366,10 @@ export class Translator { /** * @param {Map<string, unknown[]>} arrayVariants - * @returns {Map<string, unknown>[]} + * @returns {import('translation-internal').TextProcessorVariant[]} */ _getArrayVariants(arrayVariants) { - /** @type {Map<string, unknown>[]} */ + /** @type {import('translation-internal').TextProcessorVariant[]} */ const results = []; const variantKeys = [...arrayVariants.keys()]; const entryVariantLengths = []; @@ -1376,7 +1380,7 @@ export class Translator { const totalVariants = entryVariantLengths.reduce((acc, length) => acc * length, 1); for (let variantIndex = 0; variantIndex < totalVariants; ++variantIndex) { - /** @type {Map<string, unknown>} */ + /** @type {import('translation-internal').TextProcessorVariant}} */ const variant = new Map(); let remainingIndex = variantIndex; @@ -2076,6 +2080,7 @@ export class Translator { * @param {boolean} ascending */ _updateSortFrequencies(dictionaryEntries, dictionary, ascending) { + /** @type {Map<number, number>} */ const frequencyMap = new Map(); for (const dictionaryEntry of dictionaryEntries) { const {definitions, frequencies} = dictionaryEntry; |