fix(javascript): preserve getter results on direct property writes

Replacing or deleting a class getter property does not mutate the object it would return. Apply the existing object-accessor write boundary to instance and static getters.

Validation: source mutation regressions and compiled CLI/stdio MCP acceptance preserve literal 1 for all four assignment/deletion cases; check:fast passes.
This commit is contained in:
morluto committed 2026-10-11 08:15:47 +08:00
1 parent bb074d84cb
commit 639b73097b
3 files changed
+35

No files matched your search

@@ -635,6 +635,9 @@ const referencedValues = (
if (t.isClass(node)) {
const [key, ...remaining] = path;
if (key === undefined) return [];
// Replacing or deleting the getter's property does not use the value it
// would return. Only a deeper path can mutate the returned object.
if (effect === "write" && remaining.length === 0) return [];
return classGetterResults(
node,
key === null ? null : String(key),
@@ -646,6 +649,7 @@ const referencedValues = (
if (t.isNewExpression(node)) {
const [key, ...remaining] = path;
if (key === undefined) return [];
if (effect === "write" && remaining.length === 0) return [];
return classCandidates(node.callee, state).flatMap((klass) =>
classGetterResults(
klass,