From 13278a5cf67de69678d8c4c5fb97e6eb00c94c11 Mon Sep 17 00:00:00 2001 From: James Maa Date: Thu, 9 May 2024 15:42:35 +0800 Subject: 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 Signed-off-by: James Maa --------- Signed-off-by: James Maa Co-authored-by: toasted-nutbread Co-authored-by: StefanVukovic99 --- ext/js/language/translator.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'ext/js/language/translator.js') 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} */ const frequencyCounter = new Map(); for (const element of array1) { @@ -400,6 +401,7 @@ export class Translator { * @returns {Map} */ _groupDeinflectionsByTerm(deinflections) { + /** @type {Map} */ 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} */ + /** @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[]} textProcessors - * @param {Map} processorVariant + * @param {import('translation-internal').TextProcessorVariant} processorVariant * @param {string} text - * @param {Map} 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} */ const targetMap = new Map(); for (const group of groupedDictionaryEntries) { @@ -1362,10 +1366,10 @@ export class Translator { /** * @param {Map} arrayVariants - * @returns {Map[]} + * @returns {import('translation-internal').TextProcessorVariant[]} */ _getArrayVariants(arrayVariants) { - /** @type {Map[]} */ + /** @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} */ + /** @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} */ const frequencyMap = new Map(); for (const dictionaryEntry of dictionaryEntries) { const {definitions, frequencies} = dictionaryEntry; -- cgit v1.2.3