Skip to content

[immutability] Detect mutations on for-of iterator variables from props/state #1764

@Rel1cx

Description

@Rel1cx

Background

Per immutability.spec.diff.md, the current immutability rule does not detect mutations on for-of iterator variables, even when the iterated collection comes from props or state.

Current behavior

function Component({ items }) {
  for (const x of items) {
    x.modified = true; // ❌ currently missed
  }
}

Expected behavior

When the right-hand side of a for-of (e.g. items) is identified as coming from props or state, treat the left-hand iterator variable (e.g. x) as an immutable object and flag mutations on it.

References

Priority

P2 — medium implementation cost, covers a common indirect mutation pattern.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions