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

Writing generators in ES2015 #767

Closed
jamesallardice opened this Issue Mar 2, 2015 · 1 comment

Comments

Projects
None yet
2 participants
@jamesallardice
Contributor

jamesallardice commented Mar 2, 2015

It could be nice to have the ability to write generators in ES2015 class syntax. For example:

import { Base } from 'yeoman-generator';

export default class MyGenerator extends Base {
  constructor( ...args ) {
    super(...args);
  }
  someMethod() {
    console.log('Do something');
  }
}

This is not currently possible because methods defined in the above way are non-enumerable properties of the constructor prototype and the Base generator will only find those that are enumerable:

var methods = Object.keys(Object.getPrototypeOf(this));

This appears like it could be easily fixed by using Object.getOwnPropertyNames instead of Object.keys but I'm unsure if it's something that can or should change as I guess it could affect any existing generators that rely upon non-enumerable properties on the object passed to Base.extend for example.

@SBoudrias

This comment has been minimized.

Show comment
Hide comment
@SBoudrias

SBoudrias Mar 2, 2015

Member

I don't think this will cause any major break. Feel free to send a PR with this fix.

Member

SBoudrias commented Mar 2, 2015

I don't think this will cause any major break. Feel free to send a PR with this fix.

jamesallardice added a commit to jamesallardice/generator that referenced this issue Mar 3, 2015

Allow the Base generator to find non-enumerable methods
This adds the possibility of writing generators with ES2015 class
syntax. Fixes yeoman#767.

jamesallardice added a commit to jamesallardice/generator that referenced this issue Mar 3, 2015

Allow the Base generator to find non-enumerable methods
This adds the possibility of writing generators with ES2015 class
syntax. Fixes yeoman#767.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment