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

Extending Error is flaky because Error.call returns a new object #40

Open
marijnh opened this issue Nov 10, 2017 · 5 comments
Open

Extending Error is flaky because Error.call returns a new object #40

marijnh opened this issue Nov 10, 2017 · 5 comments
Labels

Comments

@marijnh
Copy link
Contributor

marijnh commented Nov 10, 2017

I.e. let x = {}; Error.call(x) == x produces false, at least on Firefox and Chrome. This is preventing Error subclasses compiled with Bublé from getting stack and message properties, making them rather useless.

Babel works around this by creating a new binding to replace this inside the constructor, storing the result of the super constructor call in that, and returning it at the end. Would that be something that Bublé would be interested in adding? I might be able to create a PR.

@marijnh
Copy link
Contributor Author

marijnh commented Nov 10, 2017

Oh, even with that fix, the resulting instances are not instanceof your class. Even Babel doesn't get that right.

It does work when you directly use class syntax in the browser, so this is a case where compiling down does some damage.

This was referenced Nov 11, 2017
@Rich-Harris
Copy link
Collaborator

Two possible fixes — don't transpile classes (#43), or don't transpile anything (#42). Depends whether we want to continue supporting Node 4. Any thoughts?

@marijnh
Copy link
Contributor Author

marijnh commented Nov 11, 2017

Ah, I wasn't even talking about this causing a problem in the Bublé sources (I hadn't noticed)—rather it was causing trouble in my own projects. But I've fallen back on directly writing the horrible ES5 code needed to create a subclass of Error for now, and I guess I'll just keep doing that until the next geological era when I can ship client-side ES6 code. So this isn't blocking me.

@adrianheine
Copy link
Member

As discussed in the babel issue, whether extending builtins is allowed should probably be configurable, right?

@adrianheine
Copy link
Member

As @Andarist pointed out in #93, CompileError already sets message and stack, so this should not be a problem for bublé itself.

@mourner mourner added the bug label Mar 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants