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

[Feature Request] enable even simpler transformation #4840

Closed
bigopon opened this issue Nov 14, 2016 · 3 comments
Closed

[Feature Request] enable even simpler transformation #4840

bigopon opened this issue Nov 14, 2016 · 3 comments
Labels
Has PR outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Polish 💅 A type of pull request used for our changelog categories

Comments

@bigopon
Copy link

bigopon commented Nov 14, 2016

Please ignore if this already discussed.
Suppose I have a class like this:

class MyClass {
   //....
   // Here I have 100 class methods
}

This will be transformed into:

function MyClass() {}
// 100 times of this repeated: MyClass.prototype

Can we have something like this instead:

var _proto = MyClass.prototype
// 1000 class methods ?
_proto.method1 = () => null;
_proto.method2 = () => null;

// a lot less output code after minification
// var a = MyClass.prototype;
// a.method1 = () => null;
// a.method2 = () => null;

Imagine if we have 20 of classes like this, the amount of prototype repeated will be big, not counted the long class names

Can we have it enhanced in this way ?

@hzoo hzoo added the PR: Polish 💅 A type of pull request used for our changelog categories label Nov 15, 2016
@hzoo
Copy link
Member

hzoo commented Nov 15, 2016

We could do that - it only uses prototype in loose mode btw. It would probably be low priority for us since it's not a bug fix or core feature

@bigopon
Copy link
Author

bigopon commented Nov 15, 2016

I could help with some guideline of where to start, if you are interested.

@hzoo
Copy link
Member

hzoo commented Nov 17, 2016

Yeah sure! - you can also join our slack #development #plugins as well slack.babeljs.io

I would check our CONTRIBUTING.md, https://github.com/thejameskyle/babel-handbook/blob/master/translations/en/plugin-handbook.md, and test with astexplorer (http://astexplorer.net/#/sskXYR4icD/20)

This is going to touch loose mode so there's a loose.js from index.js

if (!node.static) classRef = t.memberExpression(classRef, t.identifier("prototype"));
let methodName = t.memberExpression(classRef, node.key, node.computed || t.isLiteral(node.key));

Looks like that is the place where it's doing a .prototype and creating the A.prototype.a = function a() {};

Instead your want to do a one time addition of var _proto = MyClass.prototype at the top and then change the new methods to be _proto.method = function a() {}

oliverdon added a commit to oliverdon/babel that referenced this issue Mar 28, 2017
oliverdon added a commit to oliverdon/babel that referenced this issue Mar 28, 2017
oliverdon added a commit to oliverdon/babel that referenced this issue Jul 21, 2017
oliverdon added a commit to oliverdon/babel that referenced this issue Jul 21, 2017
oliverdon added a commit to oliverdon/babel that referenced this issue Jul 21, 2017
oliverdon added a commit to oliverdon/babel that referenced this issue Jul 21, 2017
jridgewell pushed a commit to oliverdon/babel that referenced this issue Aug 26, 2017
jridgewell pushed a commit that referenced this issue Aug 27, 2017
* Fix #4840: Alias class prototype for methods in loose mode

* Cleanup
@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
Has PR outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Polish 💅 A type of pull request used for our changelog categories
Projects
None yet
Development

No branches or pull requests

4 participants