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’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

Merged
merged 107 commits into from
Nov 2, 2023

Conversation

kdy1
Copy link
Member

@kdy1 kdy1 commented Oct 10, 2023

@kdy1 kdy1 added this to the Planned milestone Oct 10, 2023
@kdy1 kdy1 requested a review from jridgewell October 10, 2023 07:11
@kdy1 kdy1 self-assigned this Oct 10, 2023
@kdy1 kdy1 marked this pull request as ready for review October 10, 2023 07:11
kodiakhq[bot]
kodiakhq bot previously approved these changes Oct 10, 2023
Copy link
Member Author

@kdy1 kdy1 left a 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);
Copy link
Contributor

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.

Copy link
Member Author

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

kodiakhq[bot]
kodiakhq bot previously approved these changes Oct 11, 2023
kodiakhq[bot]
kodiakhq bot previously approved these changes Oct 11, 2023
kodiakhq[bot]
kodiakhq bot previously approved these changes Oct 11, 2023
@kdy1 kdy1 requested a review from jridgewell October 11, 2023 04:52
Copy link
Contributor

@jridgewell jridgewell left a 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.

kodiakhq[bot]
kodiakhq bot previously approved these changes Oct 11, 2023
kodiakhq[bot]
kodiakhq bot previously approved these changes Oct 12, 2023
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);
Copy link
Contributor

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);

kodiakhq[bot]
kodiakhq bot previously approved these changes Oct 19, 2023
var _x = /*#__PURE__*/ new WeakMap();
class Foo {
test() {
var _this, _this_y;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not ideal

Copy link
Member Author

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.

Copy link
Member Author

@kdy1 kdy1 left a 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

@kdy1 kdy1 marked this pull request as ready for review October 30, 2023 02:37
kodiakhq[bot]
kodiakhq bot previously approved these changes Oct 30, 2023
@@ -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;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous output seems wrong

jridgewell
jridgewell previously approved these changes Nov 2, 2023
@kdy1 kdy1 dismissed stale reviews from jridgewell and kodiakhq[bot] via dcc3aa9 November 2, 2023 21:39
@kdy1 kdy1 enabled auto-merge (squash) November 2, 2023 21:39
Copy link
Collaborator

@swc-bot swc-bot left a 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

@kdy1 kdy1 merged commit 83a5a0c into swc-project:main Nov 2, 2023
278 checks passed
@kdy1 kdy1 deleted the issue-7561 branch November 2, 2023 22:18
@kdy1 kdy1 modified the milestones: Planned, v1.3.96 Nov 3, 2023
@swc-project swc-project locked as resolved and limited conversation to collaborators Dec 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Private property after an optional chain transforms into nonsense code
3 participants