Skip to content

fix: use immutable visited Set copy in resolveNestedTemplates#174

Open
JuliaKalder wants to merge 1 commit into
mainfrom
fix/issue-164
Open

fix: use immutable visited Set copy in resolveNestedTemplates#174
JuliaKalder wants to merge 1 commit into
mainfrom
fix/issue-164

Conversation

@JuliaKalder
Copy link
Copy Markdown
Owner

Summary

  • Replace the mutable visited.add() / visited.delete() pattern in resolveNestedTemplates with an immutable copy: new Set([...visited, nestedTemplate.id]) passed to the recursive call.
  • Remove the visited.delete() call entirely — no mutation of the caller's Set occurs at any point.
  • Update the JSDoc for the visited parameter to state it is treated as immutable.

Why

The original code mutated the caller's visited Set around each recursive call. If the recursive call threw (e.g., due to a circular-reference error deeper in the chain), the visited.delete() cleanup was skipped, leaving the Set in a dirty state for any subsequent sibling iterations in the same call frame.

The immutable-copy pattern eliminates the mutation entirely: each recursive frame gets its own snapshot of the ancestor set, and a throw propagates cleanly without any side-effects on the parent frame's Set.

Fixes #164

Test plan

  • All existing tests pass (npm test — 96/96 pass, including the resolveNestedTemplates circular-reference suite)
  • No new failing tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[LOW] resolveNestedTemplates: visited Set parameter mutated and left dirty on circular-reference throw

1 participant