fix(javascript): project class definition-time effects through getters

Computed keys and superclass expressions evaluate against the enclosing
getter receiver. Visit those definition-time expressions when collecting
accessor effects, and walk past class/method boundaries in #ownsThis when
the path arrives from heritage or a computed key so receiver writes are
not dropped.

Fixes #9229

Supersedes #9233

Co-Authored-By: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
This commit is contained in:
SahinurDEVandgensokyo-dev authored and Ysopwnable committed 2026-11-14 14:44:47 +01:00
1 parent 4d6262303d
commit 4a42707544
3 files changed
+86 -9

No files matched your search

@@ -393,6 +393,23 @@ const accessorOperands = new WeakMap<
readonly AccessorEffectOperand[]
>();
/** Expressions a definition runs immediately; deferred bodies and class-receiver initializers stay out. */
const definitionTimeExpressions = (node: t.Function | t.Class): t.Node[] => {
if (t.isObjectMethod(node)) return node.computed ? [node.key] : [];
if (!t.isClass(node)) return [];
return [
...(node.superClass == null ? [] : [node.superClass]),
...node.body.body.flatMap((member) =>
(t.isClassMethod(member) ||
t.isClassProperty(member) ||
t.isClassAccessorProperty(member)) &&
member.computed
? [member.key]
: [],
),
];
};
/** Collect invocation operands once; receiver interpretation belongs to the getter owner. */
const accessorEffectOperands = (
method: t.Function,
@@ -406,8 +423,13 @@ const accessorEffectOperands = (
const writeOnly = new WeakSet<t.Node>();
while (pending.length > 0) {
const { node, parent } = pending.pop()!;
// Defining a nested callable does not invoke it.
if (t.isFunction(node) || t.isClass(node)) continue;
// Defining a nested callable does not invoke it, but the definition itself
// evaluates heritage and computed keys against the enclosing receiver.
if (t.isFunction(node) || t.isClass(node)) {
for (const child of definitionTimeExpressions(node).reverse())
pending.push({ node: child, parent: node });
continue;
}
const write = semanticWriteSiteTarget(node);
if (write !== null) {
for (const target of semanticWriteTargets(write)) {