Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transform for static super.name is incorrect when prototype is mutated #46580

Open
evanw opened this issue Oct 29, 2021 · 0 comments
Open

Transform for static super.name is incorrect when prototype is mutated #46580

evanw opened this issue Oct 29, 2021 · 0 comments
Assignees
Labels
Bug A bug in TypeScript
Milestone

Comments

@evanw
Copy link
Contributor

evanw commented Oct 29, 2021

Bug Report

🔎 Search Terms

class static field super prototype setPrototypeOf

🕗 Version & Regression Information

  • The ability to use super inside static appears to have been added in 4.4. This bug existed when the feature was introduced, presumably in Change static fields emits #43114.

⏯ Playground Link

Playground link with relevant code

💻 Code

class A {
  static x = 1
}
class B extends A {
  static y = () => super.x
}
class C {
  static x = 2
}
console.log(B.y())
Object.setPrototypeOf(B, C)
console.log(B.y())

🙁 Actual behavior

When this code is transformed by TypeScript, it outputs 1 1.

🙂 Expected behavior

When this code is run natively, it outputs 1 2.

The code generated by TypeScript currently looks like this:

"use strict";
var _a, _b;
class A {
}
A.x = 1;
class B extends (_b = A) {
}
_a = B;
B.y = () => Reflect.get(_b, "x", _a);
class C {
}
C.x = 2;
console.log(B.y());
Object.setPrototypeOf(B, C);
console.log(B.y());

I expected something like this instead:

"use strict";
var _a;
class A {
}
A.x = 1;
class B extends A {
}
_a = B;
B.y = () => Reflect.get(Object.getPrototypeOf(_a), "x", _a);
class C {
}
C.x = 2;
console.log(B.y());
Object.setPrototypeOf(B, C);
console.log(B.y());
@andrewbranch andrewbranch added the Bug A bug in TypeScript label Nov 1, 2021
@andrewbranch andrewbranch added this to the Backlog milestone Nov 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants