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

When extending a generator, methods on the superclass are ignored #1065

Closed
rictic opened this issue Apr 13, 2018 · 1 comment
Closed

When extending a generator, methods on the superclass are ignored #1065

rictic opened this issue Apr 13, 2018 · 1 comment

Comments

@rictic
Copy link

rictic commented Apr 13, 2018

Consider this code:

const Generator = require('yeoman-generator');
class BaseGenerator extends Generator {
  prompting() {
    // customised prompt
  }
}

class MyGenerator extends BaseGenerator {
  // implements other methods but does not implement prompting
}

This does not work, BaseGenerator's prompting method is not called when MyGenerator is run. The fix is to do:

class MyGenerator extends BaseGenerator {
  prompting() {
    return super.prompting();
  }
}

It looks like the reason for this is that method names are only counted if they're on the prototype of the generator directly. I'd argue that this is pretty surprising behavior, but it seems like it was done fairly deliberately, perhaps for historical reasons?

@SBoudrias
Copy link
Member

Yes, this is the way it is for mainly historical reason. That's how it was initially implemented. The documentation state this behavior:

In other words, each function on the object returned by Object.getPrototypeOf(Generator) will be automatically run.
http://yeoman.io/authoring/running-context.html

I don't think we'll consider changing this behavior now, but I hope this clarifies the behavior. Let us know if you need further help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants