Don't add duplicate definitions (#889)

This commit is contained in:
toasted-nutbread 2020-10-05 22:50:10 -04:00 committed by GitHub
parent 0cfaa1a5a8
commit 7ce87c51b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -597,7 +597,7 @@ class Translator {
_mergeByGlossary(definitions, glossaryDefinitionGroupMap) { _mergeByGlossary(definitions, glossaryDefinitionGroupMap) {
for (const definition of definitions) { for (const definition of definitions) {
const {expression, reading, dictionary, glossary} = definition; const {expression, reading, dictionary, glossary, id} = definition;
const key = this._createMapKey([dictionary, ...glossary]); const key = this._createMapKey([dictionary, ...glossary]);
let group = glossaryDefinitionGroupMap.get(key); let group = glossaryDefinitionGroupMap.get(key);
@ -605,11 +605,15 @@ class Translator {
group = { group = {
expressions: new Set(), expressions: new Set(),
readings: new Set(), readings: new Set(),
definitions: [] definitions: [],
definitionIds: new Set()
}; };
glossaryDefinitionGroupMap.set(key, group); glossaryDefinitionGroupMap.set(key, group);
} }
const {definitionIds} = group;
if (definitionIds.has(id)) { continue; }
definitionIds.add(id);
group.expressions.add(expression); group.expressions.add(expression);
group.readings.add(reading); group.readings.add(reading);
group.definitions.push(definition); group.definitions.push(definition);