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

privateMethod use keyword cause runtime error when translate to es5 #8948

Closed
zxt5105515 opened this issue May 13, 2024 · 1 comment · Fixed by #8949
Closed

privateMethod use keyword cause runtime error when translate to es5 #8948

zxt5105515 opened this issue May 13, 2024 · 1 comment · Fixed by #8949
Assignees
Labels
Milestone

Comments

@zxt5105515
Copy link

Describe the bug

when translate to es5, privateMethod use keyword such as '#switch' '#new' will translate to such

 _class_private_method_get(this, _switch, _switch).call(this);

WeakSet and function name are both _switch ,will cause
TypeError: _class_private_method_get(...).call is not a function

Input code

class TestCls{
    foo(){
        this.#bar()    
        this.#switch()    
    }
    #switch(){
        console.log("#switch called")
    }

    #bar(){
        console.log("#bar called")
    }
}
export {TestCls}

let a = new TestCls
a.foo()

Config

{
  "module": {
    "type": "commonjs" 
  },
  "jsc": { 
    "target": "es5", 
    "parser": {
      
      "syntax": "ecmascript",
      
      "jsx": false,
      
      "decorators": true,
      
      "dynamicImport": true,
      
      
    },

    "minify": {} 
  },
    
  
  "minify": false 
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.3.100&code=H4sIAAAAAAAAA0vOSSwuVghJLS5xzimu5lIAgrT8fA1NCBMESjIyi%2FWUkxKLNDRBXDTx4vLMkuQMJKlaMAkXR5iTnJ9XnJ%2BTqpeTn66hBJVXSE7MyUlNUdKEaoXoBduFSyNQEl1XLVdqRUF%2BUYlCNdQfQINyUksUEhVsFfJSy2G%2B40rUA3sNAKLByCDzAAAA&config=H4sIAAAAAAAAA1WPSw7DIAwF9zkF8rrbdtE79BAWdSIifrKJVBTl7iUE0maH3xsz8jooBbNoeKq1PMsQkYX4nEsi2Sf8lARIOxTNJia49XaWvRrRCtVoOxpIyBOluiX3hoMNQajjLXPGmzH%2FC3VwkUnkCu4o%2BsnSVTc0JbjwXmrZDkk50qF%2FwA%2FqsvNjMPLqm4kXGrYvhlQioBQBAAA%3D

SWC Info output

No response

Expected behavior

no runtime error

Actual behavior

var _switch = new WeakSet(), _bar = new WeakSet();
var TestCls = function() {
    "use strict";
    function TestCls() {
        _class_call_check(this, TestCls);
        _class_private_method_init(this, _switch);
        _class_private_method_init(this, _bar);
    }
    _create_class(TestCls, [
        {
            key: "foo",
            value: function foo() {
                _class_private_method_get(this, _bar, bar).call(this);
                _class_private_method_get(this, _switch, _switch).call(this);
            }
        }
    ]);
    return TestCls;
}();
function _switch() {
    console.log("#switch called");
}
function bar() {
    console.log("#bar called");
}
var a = new TestCls;
a.foo();

Version

1.5.5

Additional context

No response

@kdy1 kdy1 self-assigned this May 13, 2024
@kdy1 kdy1 added this to the Planned milestone May 13, 2024
kdy1 pushed a commit that referenced this issue May 13, 2024
**Description:**

Following development should follow babel/babel#16261 to avoid separate `WeakMap` for each individual private method


**Related issue:**

 - Closes #8948.
@kdy1 kdy1 modified the milestones: Planned, v1.5.6 May 14, 2024
@swc-bot
Copy link
Collaborator

swc-bot commented Jun 13, 2024

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.

@swc-project swc-project locked as resolved and limited conversation to collaborators Jun 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

3 participants