Skip to content

Commit

Permalink
fix(tranformer): Intersect type instead of merge
Browse files Browse the repository at this point in the history
  • Loading branch information
fdrault committed Aug 6, 2024
1 parent 4f7f42e commit 049ef3b
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/rules/transformer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TranslationEntry } from "../translation/generate-template-data";
import { intersection } from "../translation/set";

export type AddPlaceholderTransformer = {
addPlaceholder: {
Expand All @@ -17,12 +18,11 @@ export function applyAddPlaceholderTransformer(
transformer: AddPlaceholderTransformer,
entry: TranslationEntry
): TranslationEntry {
const previousType =
entry.interpolations.get(transformer.addPlaceholder.name) ?? [];
entry.interpolations.set(
transformer.addPlaceholder.name,
previousType.concat(transformer.addPlaceholder.type)
);
const previousType = new Set(entry.interpolations.get(transformer.addPlaceholder.name) ?? []);
const placeholderType = new Set(transformer.addPlaceholder.type);
const intersectType =
previousType.size > 0 ? intersection(previousType, placeholderType) : placeholderType;
entry.interpolations.set(transformer.addPlaceholder.name, Array.from(intersectType));
return entry;
}

Expand All @@ -31,11 +31,11 @@ export function applyAddMatchedPlaceholderTransformer(
placeholder: string,
entry: TranslationEntry
): TranslationEntry {
const previousType = entry.interpolations.get(placeholder) ?? [];
entry.interpolations.set(
placeholder,
previousType.concat(transformer.addMatchedPlaceholder.type)
);
const previousType = new Set(entry.interpolations.get(placeholder) ?? []);
const placeholderType = new Set(transformer.addMatchedPlaceholder.type);
const intersectType =
previousType.size > 0 ? intersection(previousType, placeholderType) : placeholderType;
entry.interpolations.set(placeholder, Array.from(intersectType));
return entry;
}

Expand Down

0 comments on commit 049ef3b

Please sign in to comment.