diff --git a/3-tidy-up.js b/3-tidy-up.js index b78576b..0bb0d39 100644 --- a/3-tidy-up.js +++ b/3-tidy-up.js @@ -186,16 +186,21 @@ function handleLine(parsedLine) { const glossTree = getGlossTree(sensesWithoutInflectionGlosses); for (const reading of readings) { - let result = lemmaDict[word][reading][pos][String(etymology_number)]; - let etym_num = etymology_number; - while (result && result.glossTree && result.glossTree.size > 0) { - etym_num += 1; - result = lemmaDict[word][reading][pos][String(etym_num)]; + const posDict = lemmaDict[word]?.[reading]?.[pos] || {}; + let etymNum = etymology_number; + let result = posDict[String(etymNum)]; + + while (result?.glossTree?.size > 0) { + etymNum += 1; + result = posDict[String(etymNum)]; } - result = /** @type {LemmaInfo}*/ (ensureNestedObject(lemmaDict, [word, reading, pos, String(etym_num)])); + + result = /** @type {LemmaInfo} */ (ensureNestedObject(lemmaDict, [word, reading, pos, String(etymNum)])); + result.ipa ??= ipa; result.glossTree = glossTree; } + } /**