-
-
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
feat: unify class properties transform in ts and js #3766
Conversation
One major difference would be class exprs where ts transform uses a sequence expr while js transform uses a iife. This should be fixed. |
60f00e9
to
7f34729
Compare
Ah, I've encountered with microsoft/TypeScript#45995 |
78e1ac2
to
0e740e9
Compare
Here's some observerations about initialized order of parameter properties:
I originally would like to choose route 3, but consider private properties class A {
a = 123
#a = 456
constructor(public b) {
console.log(this.#a)
}
}
class A {
a
constructor(b) {
this.b = b
this.a = 123
this.#a = 456
console.log(this.#a)
}
} This would generate many useless boilerplate, but at least it's consisent and doesn't break current tests. Hopefully not many people would use private properties in TypeScript. |
Hmm... Yeah I think your decision is right although I'm a bit confused by other tools. |
Oh, and ts has same bug I fixed in previous pr |
d9b45e7
to
d2f44d2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't review fully yet.
I will do it soon, but I think I found a bug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much!
swc-bump:
- swc_ecma_transforms_base --breaking
@@ -1,3 +1,3 @@ | |||
class C { | |||
} | |||
console.log(C.f1, C.f2, C.f3), console.log(C.f1, C.f2, C.f3), C.f1 = 1, C.f2 = 2, C.f3 = 3; | |||
C.f1 = 1, console.log(C.f1, C.f2, C.f3), C.f2 = 2, console.log(C.f1, C.f2, C.f3), C.f3 = 3; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const a = 1;
class C {
static f1 = 1;
static {
console.log(C.f1, C.f2, C.f3)
}
static f2 = 2;
static {
console.log(C.f1, C.f2, C.f3)
}
static f3 = 3;
}
and output of original file is
1 undefined undefined
1 2 undefined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, it's correct.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the original output is wrong
Description:
And also expose an
use_define_for_class_fields
somewhereBREAKING CHANGE:
It will break rust users
It won't be possible to use [[Set]] for pulibc fields and preserve private fields.
It will be a break change for ts users who want es2022/esnext output, but this is aligned with babel behaviour. And consider tsc doesn't have target env and would set
useDefineForPublicFields
to true in es2022, this shall also be aligned with tsc.Related issue (if exists):
closes #3827, closes #3389, closes #3317, closes #3228, supersedes #3764