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

Issue with RequestError having static name property #169

Open
GavinMeierSonos opened this issue May 14, 2024 · 2 comments
Open

Issue with RequestError having static name property #169

GavinMeierSonos opened this issue May 14, 2024 · 2 comments

Comments

@GavinMeierSonos
Copy link

Hard to say if this is a rollup issue or if this is a valid concern but the fix would be easy to implement.

When transpiling into esm. There is an issue with name being defined as a static value on the RequestError instead of just having it defined in the in the constructor. It throws an error saying that read only property name cannot be reassigned.

Happy to open a PR if this would be approved since it wouldn't impact any existing functionality and it does seem odd to define a static field on a class that is defined on the prototype. The fix would be to move the name assignment to the constructor after the super is called.

@yusukebe
Copy link
Member

Hi @GavinMeierSonos

Can you share the details to understand more easily or share the project to reproduce it?

@HelloWorld017
Copy link

When this module is transpiled using swc, the output contain things like this:

let _getResponseCache;
var _class, _body, _init;
var RequestError = (_class = class extends Error {
    constructor(message, options){
        super(message, options);
    }
}, _class.name = "RequestError", _class);

And when it is evaluated in strict mode, following error occurs.

TypeError: Cannot assign to read only property 'name' of function 'class extends Error {
     constructor(message, options){
         super(message, options);
     }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants