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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Babel-transpiled class can't extend from native class #6299

Closed
fatcerberus opened this issue Sep 25, 2017 · 5 comments
Closed

Babel-transpiled class can't extend from native class #6299

fatcerberus opened this issue Sep 25, 2017 · 5 comments
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@fatcerberus
Copy link

I'm not sure if this is even possible to fix, but I figured I'd report it just in case. 馃槄

Supposing one is running under an ES6-supporting engine and there is a class which is not subject to transpilation:

class C {}

If the class below is transpiled with Babel and then executed:

class D extends C {}

The result is a TypeError, constructor cannot be called without new. For example, I saw this when I tried to transpile my game with Babel before running it:

TypeError: Class constructor cannot be called without the new keyword
   at Thread (#/game_modules/thread.js:98:14)
   at DayNightEngine (@/scripts/inGameClock.js:27:9)
   at game (@/scripts/main.js:53:2)

Background: My game engine, miniSphere, was previously based on Duktape, which mainly supports ES5.1. In order to support ES6 in my toolchain, I integrated Babel into the default build process. As I'm now in the process of switching over to ChakraCore, my standard library has been refactored to export true ES6 classes; however there is still Babelized code in the wild that I would like to maintain backward compatibility with, assuming that's possible.

@babel-bot
Copy link
Collaborator

Hey @fatcerberus! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

@loganfsmyth
Copy link
Member

loganfsmyth commented Sep 25, 2017

Gonna dup this with #4480.

Unfortunately fixing this is not at all easy, and it's impossible to do in an entirely spec-compliant way. We've had a few suggested solutions, but none that are particularly nice implementation-wise. Usually the expectation is that if a library publishes code with ES6-native classes, users using that library should also have Babel set up to not compile classes.

If you're trying to upgrade an existing library, I'd say changing from ES5-style classes to ES6-style classes is 100% a breaking change that requires a major-version upgrade. Seems like that is what you're saying you are doing with "my standard library has been refactored to export true ES6 classes".

@fatcerberus
Copy link
Author

馃憤

Yes, my current work is already planned as a major version bump (4.8 -> 5.0) and I've even already made breaking API changes. I just figured if I could allow people to keep the transpile() step in their build scripts for the next version that would be nice, but if it's not possible I can live without the BC. Thanks for the quick response! 馃槂

@loganfsmyth
Copy link
Member

No problem. Yeah, we've been trying to push everyone in the community to use https://github.com/babel/babel-preset-env because that way it's super easy to say "compile for Node" and get native classes to solve this problem.

@fatcerberus
Copy link
Author

I definitely agree there. Unfortunately babel-standalone doesn't yet support env 鈽癸笍
babel/babel-standalone#86

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 4, 2018
@lock lock bot locked as resolved and limited conversation to collaborators May 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

3 participants