fix(javascript): exclude class member keys from lexical reads

Classify noncomputed class member keys and private names at the shared reference owner, avoiding false reads and closure captures. Preserve computed keys and initializer/body reads.

Validation: regression controls, fresh public CLI/MCP workflows and complete exact-head CI passed.

Fixes #3310.
This commit is contained in:
Kshitiz Jain
2026-10-17 12:41:19 +05:30
committed by GitHub
parent 195cf18818
commit c0b3cd14b1
2 changed files with 81 additions and 0 deletions
@@ -725,11 +725,24 @@ const isNonReferenceKey = (node: t.Identifier, parent: t.Node): boolean =>
parent.key === node &&
!parent.computed &&
!(t.isObjectProperty(parent) && parent.shorthand)) ||
isNoncomputedClassMemberKey(node, parent) ||
t.isPrivateName(parent) ||
(t.isExportSpecifier(parent) && parent.exported === node) ||
t.isLabeledStatement(parent) ||
t.isBreakStatement(parent) ||
t.isContinueStatement(parent);
/** A noncomputed class member name is a property key, never a lexical read. */
const isNoncomputedClassMemberKey = (
node: t.Identifier,
parent: t.Node,
): boolean =>
(t.isClassMethod(parent) ||
t.isClassProperty(parent) ||
t.isTSDeclareMethod(parent)) &&
parent.key === node &&
!parent.computed;
const patternNames = (pattern: t.Node): string[] => {
if (t.isTSParameterProperty(pattern)) return patternNames(pattern.parameter);
if (t.isIdentifier(pattern)) return [pattern.name];