🔎 Search Terms
Private element, computed key, super call
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play?target=9#code/DYUwLgBAxghgDmArgJxAEwGIHssEEpQgDORANBKkYsGANwBQUwMJEAQhAN70TRYB2RMMkRQwWZAAoAbgEouPXtHhJUmHPkKsAvBGmKAvvSP1+IAO7RmrAMIQQADzAh+aIuwW8oAoSLETJeW4lKxZ3XE8QiCEYMABLKAgAYgAzHAhdABYAJgYo6LBYhIgAbSo4EClJMHltAD4IMAA6VJxZAF08pQMu3kpqSF1YBBR0bDwCYiJJXFlaXkNjekYfLFAm4CwAc0lOCmIBiAM5oA
💻 Code
letcapturedFooAccess,result;classB{constructor(v){capturedFooAccess=v}}newclassCextendsB{constructor(){classA{static #foo =42;static[super((t)=>t.#foo)];};result=capturedFooAccess(A);}}console.log({ result });🙁 Actual behavior
The transformed code throws "Private field '#foo' must be declared in an enclosing class" because the private key IIFE is hoisted before class A.
🙂 Expected behavior
It should print { result: 42 }
The input is already ES2022, TS could have left it as-is.
Additional information about the issue
We can dodge this issue in ES2022 target, but I haven't figured out how to deal with the decorator expression. Either we lost the #foo access or the super() is moved to the scope of the underived class A.
letcapturedFooAccess,result;classB{constructor(v){capturedFooAccess=v}}newclassCextendsB{constructor(){classA{
@(super((t)=>t.#foo),v=>v) #foo =42;};result=capturedFooAccess(A);}}console.log({ result });
🔎 Search Terms
Private element, computed key, super call
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play?target=9#code/DYUwLgBAxghgDmArgJxAEwGIHssEEpQgDORANBKkYsGANwBQUwMJEAQhAN70TRYB2RMMkRQwWZAAoAbgEouPXtHhJUmHPkKsAvBGmKAvvSP1+IAO7RmrAMIQQADzAh+aIuwW8oAoSLETJeW4lKxZ3XE8QiCEYMABLKAgAYgAzHAhdABYAJgYo6LBYhIgAbSo4EClJMHltAD4IMAA6VJxZAF08pQMu3kpqSF1YBBR0bDwCYiJJXFlaXkNjekYfLFAm4CwAc0lOCmIBiAM5oA
💻 Code
🙁 Actual behavior
The transformed code throws "Private field '#foo' must be declared in an enclosing class" because the private key IIFE is hoisted before class
A.🙂 Expected behavior
It should print
{ result: 42 }The input is already ES2022, TS could have left it as-is.
Additional information about the issue
We can dodge this issue in ES2022 target, but I haven't figured out how to deal with the decorator expression. Either we lost the
#fooaccess or thesuper()is moved to the scope of the underived classA.