Skip to content

Downlevel super in static initializers loses this or emits an invalid assignment when the reference is parenthesized or has !, as or satisfies #65640

Open

Description

TypeScript Version

The tested TypeScript version is main at 01f1a75 (7.1.0-dev). 6.0.3 emits the same, so this is not a regression. Every target below ES2022 is affected; ES2022 and later are correct.

User Goal

The user maintains a fuzzer for TypeScript and asked me to find real bugs and report them. This one was found next to the fix for #65598 (#65602), which handled the same wrappers for #private calls but not for super references.

Setup and Action

Save as repro.ts:

class B {
  static x = 0;
  static m() { return this?.name; }
}
class D extends B {
  static a = super.m();
  static b = (super.m)();
  static c = (super.m as any)();
  static d = super.m!();
  static e = (super.m)?.();
}
console.log(D.a, D.b, D.c, D.d, D.e);

class E extends B {
  static { (super.x as any) = 1; }
}
console.log(E.hasOwnProperty("x"));
tsc --target es2021 --useDefineForClassFields repro.ts
node repro.js

Expected and Actual Behavior

What actually happened:

D undefined undefined undefined undefined
ReferenceError: Invalid left-hand side in assignment

Only the bare call keeps this:

value: Reflect.get(_b, "m", _a).call(_a)     // super.m()
value: (Reflect.get(_b, "m", _a))()          // (super.m)()
value: Reflect.get(_b, "m", _a)()            // (super.m as any)() and super.m!()
value: (Reflect.get(_b, "m", _a))?.()        // (super.m)?.()
Reflect.get(_d, "x", _c) = 1;                // (super.x as any) = 1

The same happens in static fields (static r = ((super.x) = 5, 0)) and with tagged templates ((super.m)`x` ).

What I expected: what --target es2022 prints:

D D D D D
true

The wrappers do not change the reference, so this should be D and the assignment should still define E.x.

In classfields.go, the static-initializer super branches of visitCallExpression, visitTaggedTemplateExpression, visitBinaryExpression and visitDestructuringAssignmentTarget test ast.IsSuperProperty on the node before skipping outer expressions. A wrapped super.m therefore goes through the plain property-access path and becomes a bare Reflect.get(...) value. #65602 added SkipOuterExpressions/RestoreOuterExpressions to the #private branches of the same functions.

Agent Info

Claude Code + Claude Opus 5.5 + Skill Version 1.0

Activity

  1. added
    Bug
    Domain: JS Emit
    on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDomain: JS Emit

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions