-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Uninitialized class property is defined with value "void 0" in es2015 #8000
Comments
You can run this code in modern browsers with native class support. class Base {
data = 1;
}
class Foo extends Base {
data;
}
console.log(new Foo().data); // undefined TypeScript support class field syntax before it is standardized. This is why But you should not rely on the behavior of target default value. |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Describe the bug
When transpiling to
es2015
, swc initializes an uninitialized class property toundefined
:When
es2022
is used, it does not initialize the property:Similarly, tsc and esbuild skip the initialization.
Input code
Config
Playground link
https://play.swc.rs/?version=1.3.87&code=H4sIAAAAAAAAA0vOSSwuVnBKLE5VqOZSUEhJLEm0UsgrzU1KLVKwVTDkquXiSq0oyC8qUUgGq3TLz1dIrShJzUtB0gXRpwjTyFULABjS7aVWAAAA&config=H4sIAAAAAAAAA1VPSQ7CMAy85xWRzxwACQ78gUdEwa2Csil2JaKqfydpk0Jv9iye8SykhDdpeMi5jGWJKhGmfS8IZc%2FqUxDgHJF0MpHh1FmmSg3KEq7QsjHAKo3I1YV0PV9uzQE2BMLuaJgz3gz5P1MHFxMSHYVVqvxo8ZgoWiq48JpWsv1S%2B24N7vAT9bD9MBh6dienCcXyBbnuEC8XAQAA
SWC Info output
No response
Expected behavior
Skip the initialization of uninitialized class properties when target is
es2015
-2021
output.It's not initializing to
undefined
when target ises2022
.Actual behavior
By setting the uninitialized property's value to
undefined
, it overrides the property value set in the base class.Version
1.3.87
Additional context
Related issue: #3232
The text was updated successfully, but these errors were encountered: