From 7b97138ad1242ab51206f5d35247da3a9ccd905d Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 25 Feb 2020 21:26:56 -0500 Subject: Changed type returned by apiTextParseMecab to avoid using for in --- ext/bg/js/backend.js | 8 ++++---- ext/bg/js/search-query-parser.js | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index 3051a873..717ffac3 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -357,11 +357,11 @@ class Backend { async _onApiTextParseMecab({text, optionsContext}) { const options = await this.getOptions(optionsContext); - const results = {}; + const results = []; const rawResults = await this.mecab.parseText(text); - for (const mecabName in rawResults) { + for (const [mecabName, parsedLines] of Object.entries(rawResults)) { const result = []; - for (const parsedLine of rawResults[mecabName]) { + for (const parsedLine of parsedLines) { for (const {expression, reading, source} of parsedLine) { const term = []; if (expression !== null && reading !== null) { @@ -381,7 +381,7 @@ class Backend { } result.push([{text: '\n'}]); } - results[mecabName] = result; + results.push([mecabName, result]); } return results; } diff --git a/ext/bg/js/search-query-parser.js b/ext/bg/js/search-query-parser.js index 0d4aaa50..11c7baa2 100644 --- a/ext/bg/js/search-query-parser.js +++ b/ext/bg/js/search-query-parser.js @@ -142,11 +142,11 @@ class QueryParser extends TextScanner { } if (this.search.options.parsing.enableMecabParser) { const mecabResults = await apiTextParseMecab(text, this.search.getOptionsContext()); - for (const mecabDictName in mecabResults) { + for (const [mecabDictName, mecabDictResults] of mecabResults) { results.push({ name: `MeCab: ${mecabDictName}`, id: `mecab-${mecabDictName}`, - parsedText: mecabResults[mecabDictName] + parsedText: mecabDictResults }); } } -- cgit v1.2.3