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

test(es/compat): Add a test for optional chaining with loose mode #7726

Merged
merged 3 commits into from
Jul 31, 2023

Conversation

komyg
Copy link
Contributor

@komyg komyg commented Jul 28, 2023

Description:
Fix: #7559

Related issue (if exists):
#7561

@komyg
Copy link
Contributor Author

komyg commented Jul 28, 2023

Hey @kdy1, I've added a test for this transformation in loose mode.

However, the generated code is different. In the loose mode, I get this:

 class Foo {
     #x;
     test() {
         this == null ? void 0 : this.y.#x;
     }
 }

Instead of what we were getting without the loose mode:

class Foo {
    #x;
    test() {
        this === null || this === void 0 ? void 0 : this.y.#x;
    }
}

Is the loose output correct, if so I can update the test to reflect that.

However, please note that in the original issue, @jridgewell said that the problem was that we were not transforming the #x private field correctly. The expected output (according to him) is:

var id = 0;
function _class_private_field_loose_key(name) {
    return "__private_" + id++ + "_" + name;
}
var _x = _class_private_field_loose_key("_x");
class Foo {
    test() {
        this?.y[_x];
    }
    //…
}

@komyg komyg marked this pull request as ready for review July 31, 2023 13:59
@komyg
Copy link
Contributor Author

komyg commented Jul 31, 2023

Great, @kdy1!

I would like to merge this test if you agree. Could you review the PR, please?

Copy link
Member

@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:

  • dbg-swc

@kdy1 kdy1 changed the title Added tests test(es/compat): Add a test for optional chaining with loose mode Jul 31, 2023
@kdy1 kdy1 enabled auto-merge (squash) July 31, 2023 15:44
@kdy1 kdy1 merged commit 216c4f1 into swc-project:main Jul 31, 2023
127 checks passed
@komyg komyg deleted the fix/7559/optiona-chaining-loose branch July 31, 2023 15:45
@kdy1 kdy1 modified the milestones: Planned, v1.3.76 Aug 9, 2023
@swc-project swc-project locked as resolved and limited conversation to collaborators Sep 9, 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 not transformed after optional chain when using loose mode
2 participants