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

Allow extending untranspiled classes #8656

Merged
merged 1 commit into from Mar 16, 2020

Conversation

nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Sep 9, 2018

Q                       A
Fixed Issues? Fixes #7022
Patch: Bug Fix?
Major: Breaking Change? Yes?[1]
Minor: New Feature? y
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

Prev: #7081

This PR allows transpiled classes to extends untranspiled classes. This can happen, for example, when a dependency is transpiled using Babel and extends an user-provided class.
Example: Oblosys/react-lifecycle-visualizer#4

The new helper only allows extending native classes when Reflect.construct is natively supported. Some envs (e.g. Node 4) have partial support for classes but don't provide Reflect.construct: in this case users need to ensure that every class (also in their dependencies) is transpiled, like it was before.

[1] If someone sets .constructor to something else, the new helper won't work. e.g.

class A {}
class B extends A {}

B.prototype.constructor = A;

console.log(new B() instanceof A); // true
console.log(new B() instanceof B); // false, should be true

A workaround to avoid the breaking change could be to only use the Reflect-based version of the helper only if Function.toString.call(SuperClass).slice(0, 5) === "class", but in those cases this.constructor still can't be modified.

@nicolo-ribaudo nicolo-ribaudo added PR: New Feature 🚀 A type of pull request used for our changelog categories Spec: Classes labels Sep 9, 2018
@babel-bot
Copy link
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/9056/

@aminsol
Copy link

aminsol commented Jun 28, 2019

Any update? I have posted a question on StackOverflow which I think is related to this:
StackOverflow Question

minrk added a commit to executablebooks/thebe that referenced this pull request Aug 6, 2019
babel can't transpile classes that extend native classes

babel/babel#8656
minrk added a commit to executablebooks/thebe that referenced this pull request Aug 6, 2019
babel can't transpile classes that extend native classes

babel/babel#8656
minrk added a commit to executablebooks/thebe that referenced this pull request Aug 6, 2019
babel can't transpile classes that extend native classes

babel/babel#8656
@1Jesper1
Copy link

Merge please.

@vzaidman
Copy link

Hey!
Can I help in merging this one somehow?

@ntulele
Copy link

ntulele commented Dec 31, 2019

+1 for getting this merged - thanks!

@vzaidman
Copy link

vzaidman commented Jan 1, 2020

great!

@JLHwung JLHwung self-requested a review January 2, 2020 23:24
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jun 16, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 16, 2020
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 PR: New Feature 🚀 A type of pull request used for our changelog categories PR: Ready For Review Spec: Classes
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

How to fix this:Error in mounted hook: "TypeError: Class constructor Base cannot be invoked without 'new'"
8 participants