-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fix(es/compat): Handle private names from class properties pass #8090
Conversation
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.
swc-bump:
- swc_ecma_compat_es2020
- swc_ecma_compat_es2022
class Foo { | ||
test() { | ||
var _this_y, _this_y1; | ||
_this_y === null || _this_y === void 0 ? void 0 : _class_private_field_get._(_this_y1 = this?.y, _x); |
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.
This is still broken. What's _this_y
isn't assigned, this?.y
still remains in the call args.
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.
It was a problem with the target ES version.
I added tests to show the result per the target ES version
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.
All of the outputs only show the assignment happening in the call arg, after the conditional has already early short-circuited:
_this_y === null || _this_y === void 0 ? void 0 : _class_private_field_get._(_this_y1 = (_this = this) === null || _this === void 0 ? void 0 : _this.y, _x);
The private names transform itself needs to handle optional chaining. We did the same thing in Babel, essentially reimplmementing it in both trasnformers.
test() { | ||
var _this; | ||
var _this_y, _this_y1; | ||
_this_y === null || _this_y === void 0 ? void 0 : _class_private_field_get(_this_y1 = (_this = this) === null || _this === void 0 ? void 0 : _this.y, _x); |
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'm not sure where our miscommunication is coming from, but this is still incorrect.
- _this_y === null || _this_y === void 0 ? void 0 : _class_private_field_get(_this_y1 = (_this = this) === null || _this === void 0 ? void 0 : _this.y, _x);
+ (_this = this) === null || _this === void 0 ? void 0 : _class_private_field_get(_this.y, _x);
var _x = /*#__PURE__*/ new WeakMap(); | ||
class Foo { | ||
test() { | ||
var _this, _this_y; |
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.
This is not ideal
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.
@jridgewell But let's fix correctness issues first.
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.
swc-bump:
- swc_ecma_compat_es2020
- swc_ecma_compat_es2022
@@ -5,10 +5,9 @@ import { _ as _class_private_field_set } from "@swc/helpers/_/_class_private_fie | |||
var _fieldFunc = /*#__PURE__*/ new WeakMap(), _fieldFunc2 = /*#__PURE__*/ new WeakMap(); | |||
class A { | |||
test() { | |||
var _class_private_field_get1; | |||
var _this_getInstance; | |||
var _this, _this1, _ref, _this_getInstance; |
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.
Previous output seems wrong
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.
Automated review comment generated by auto-rebase script
Description:
Related issue: