@interslavic/odometer
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -1,2 +0,2 @@ | ||
import { Replacement } from './index'; | ||
import { Replacement } from './Replacement'; | ||
export declare class Intermediate<ContextClass = unknown> { | ||
@@ -13,3 +13,3 @@ readonly value: string; | ||
absorb(other: Intermediate<ContextClass>): this; | ||
replacements(): IterableIterator<Replacement<ContextClass>>; | ||
chain(): IterableIterator<Intermediate<ContextClass>>; | ||
} |
@@ -27,3 +27,3 @@ "use strict"; | ||
absorb(other) { | ||
if (this.value !== other.value) { | ||
if (this.equals(other)) { | ||
throw new Error(`Cannot merge different intermediates: ${this.value} and ${other.value}`); | ||
@@ -40,9 +40,7 @@ } | ||
} | ||
*replacements() { | ||
*chain() { | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias | ||
let item = this; | ||
while (item) { | ||
if (item.via) { | ||
yield item.via; | ||
} | ||
yield item; | ||
item = item.parent; | ||
@@ -49,0 +47,0 @@ } |
@@ -13,5 +13,6 @@ "use strict"; | ||
const intermediatesCache = new IntermediatesCache_1.IntermediatesCache(); | ||
let intermediates = values.map((v) => new Intermediate_1.Intermediate(v, record)); | ||
let intermediates = values.map((v) => { | ||
return intermediatesCache.resolve(new Intermediate_1.Intermediate(v, record)); | ||
}); | ||
let nextIntermediates = []; | ||
let applied = false; | ||
let rule; | ||
@@ -22,12 +23,11 @@ let value; | ||
nextIntermediates = []; | ||
applied = false; | ||
for (value of intermediates) { | ||
if (rule.appliesTo(value)) { | ||
rule.apply(value, nextIntermediates); | ||
applied = true; | ||
} | ||
} | ||
if (applied) { | ||
if (nextIntermediates.length > 0) { | ||
intermediates = nextIntermediates; | ||
} | ||
rule.intermediatesCache = null; | ||
} | ||
@@ -34,0 +34,0 @@ return { variants: intermediates }; |
@@ -29,9 +29,11 @@ "use strict"; | ||
: replacerFn(intermediate.value); | ||
let newIntermediate = new Intermediate_1.Intermediate(newValue, intermediate, variant); | ||
if (this.intermediatesCache) { | ||
newIntermediate = this.intermediatesCache.resolve(newIntermediate); | ||
if (newValue !== intermediate.value) { | ||
let newIntermediate = new Intermediate_1.Intermediate(newValue, intermediate, variant); | ||
if (this.intermediatesCache) { | ||
newIntermediate = this.intermediatesCache.resolve(newIntermediate); | ||
} | ||
if (!results.includes(newIntermediate)) { | ||
results.push(newIntermediate); | ||
} | ||
} | ||
if (!results.includes(newIntermediate)) { | ||
results.push(newIntermediate); | ||
} | ||
} | ||
@@ -38,0 +40,0 @@ return results; |
{ | ||
"name": "@interslavic/odometer", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Utilities to flavorize dictionary entries and calculate a smarter distance between languages.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
23042