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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: False positive TDZ check in class computed property keys #16386

Open
1 task
magic-akari opened this issue Mar 26, 2024 · 4 comments 路 May be fixed by #16429
Open
1 task

[Bug]: False positive TDZ check in class computed property keys #16386

magic-akari opened this issue Mar 26, 2024 · 4 comments 路 May be fixed by #16429

Comments

@magic-akari
Copy link
Contributor

magic-akari commented Mar 26, 2024

馃捇

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

let foo;
class A {
  static x = 42;
  static [foo = () => A.x];
}
console.log(foo());

Configuration file name

No response

Configuration

No response

Current and expected behavior

expected behavior:
42

current behavior:
throws at runtime

Uncaught ReferenceError: Class "A" cannot be referenced in computed property keys.

Environment

Playground: https://babeljs.io/repl#?browsers=defaults%2C%20not%20ie%2011%2C%20not%20ie_mob%2011&build=&builtIns=false&corejs=3.21&spec=false&loose=false&code_lz=DYUwLgBAZg9jDcAoAxsAhgZwxAghA3ohBBmGmAJbIQAeEAvBACwBMSxp5VEA2rDAwgAKAJQMAfLgB0NALpIAvihgA7DDFBTgMAOZD-okUiA&debug=false&forceAllTransforms=false&modules=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=env%2Creact%2Cstage-2&prettier=true&targets=&version=7.24.3&externalPlugins=&assumptions=%7B%7D

Possible solution

No response

Additional context

swc-project/swc#8776

@babel-bot
Copy link
Collaborator

Hey @magic-akari! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Mar 26, 2024

How I opened the bug report in swc but didn't see that it was a bug in Babel is a mystery. Thank you!

@magic-akari
Copy link
Contributor Author

Off topic: I noticed a discussion on TDZ here:
https://docs.google.com/presentation/d/1c-rhSUTQVNWD4DWgkNiC9tt50BruWDi7yRPllPHnff8/edit#slide=id.gc6f90357f_0_0
However, there is no mention of Class TDZ.

I can envision the consequences of eliminating the let/const TDZ check, but I am unsure about the necessity of Class TDZ. What is your perspective on this issue?

@nicolo-ribaudo
Copy link
Member

@magic-akari Classes cannot be hoisted like function because they have side effects in computed keys and static fields, so they are very similar to let. The author of that presentation might bring it back as a proper proposal in the future -- if it happens I'll make sure to mention class :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants