Skip to content

Commit 1a73bd2

Browse files
domu1deJohannesMeierSE
authored andcommitted
Fix rule registry mutability issue with multiple language keys (#87)
When registering rules with a `languageKey` array, the rule registry was storing the original array by reference. This led to issues when `removeRule` modified the array in place. This behavior caused problems in contexts where rules are removed and re-registered during initialization — such as in classes or functions —because the original `languageKey` array had already been altered. This PR resolves the issue by creating a shallow copy of the `languageKey` array during rule registration to ensure immutability and prevent side effects during rule lifecycle operations.
1 parent cff6c83 commit 1a73bd2

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

packages/typir/src/utils/rule-registration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export class RuleRegistry<RuleType, LanguageType> implements TypeGraphListener {
103103
addRule(rule: RuleType, givenOptions?: Partial<RuleOptions>): void {
104104
const newOptions = this.getRuleOptions(givenOptions);
105105
const languageKeyUndefined: boolean = newOptions.languageKey === undefined;
106-
const languageKeys: string[] = toArray(newOptions.languageKey);
106+
const languageKeys: string[] = toArray(newOptions.languageKey, { newArray: true });
107107

108108
const existingOptions = this.ruleToOptions.get(rule);
109109
const diffOptions: RuleOptions = {

0 commit comments

Comments
 (0)