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 authored and GitHub committed 2026-10-17 07:11:19 +00:00
1 parent 195cf18818
commit c0b3cd14b1
2 files changed
+81

No files matched your search

@@ -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];