heavenshell / vim-jsdoc

Generate JSDoc to your JavaScript code.
BSD 3-Clause "New" or "Revised" License
452 stars 44 forks source link

ES6 class support #44

Closed meetwudi closed 8 years ago

meetwudi commented 8 years ago

ES6 is now very popular and I think it is reasonable to support both function and class class definition. Is it in the plan? If not, I could investigate how to implement this. :)

heavenshell commented 8 years ago

What should we generate from class signature. Could you show me example?

And sorry I'm not familiar with ES6. What do you mean about function class. Could you show me example of function class signature and expected behavior?

ryanoasis commented 8 years ago

I think @tjwudi is referring to arrow function expressions: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

Classes: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes

heavenshell commented 8 years ago

@ryanoasis Thx. Arrow function has been supported.

classes

I want to know what JSDoc.vim should generate.

Currently JSDoc generate like following.

/**
 *
 *
 * @return {undefined}
 */
class Foo {
}
Reewr commented 8 years ago

@heavenshell

With the JSDoc 3.4.0 (latest version on NPM), I was able to parse the following into a class

/**
 * Description
 */
class Foo {

  /**
   * @param {string} foo description
   * @param {string} bar description
   * @return {Foo}
   */
  constructor(foo, bar) {
    this.foo = foo;
    this.bar = bar;
  }
}

JSDoc will in this case correctly pick up the constructor (@return {Foo} on the constructor is probably not necessary). If the class has no constructor, JSDoc will make a constructor without arguments.

I have not tried your plugin yet as I just found it, but I am currently installing it. What happens if you have the following:

class Foo extends Bar {

}

Will JSDoc.vim find out that it Foo extends bar and add @extends Bar?

heavenshell commented 8 years ago

@Reewr Nice. Thanks for suggestion. I'll start improve this issue. BTW Pull requests are very welcome :smile:

JSDoc will in this case correctly pick up the constructor (@return {Foo} on the constructor is probably not necessary). If the class has no constructor, JSDoc will make a constructor without arguments.

I think describing return {Foo} at constructor is strange. You know constructor always returns it self.

Will JSDoc.vim find out that it Foo extends bar and add @extends Bar?

Currently not. But I think it should be generate like following.

/**
 * Foo
 *
 * @extend Bar
 */
class Foo extends Bar {
  /**
   * @param {string} foo description
   * @param {string} bar description
   */
  constructor(foo, bar) {
    this.foo = foo;
    this.bar = bar;
  }
}

What do you think?

Reewr commented 8 years ago

That's great. I've used this plugin somewhat now and I found it to be really useful.

What do you think?

I think it looks good.

Will you also support for static functions in classes?

class Foo {
  /**
   * Description
   *
   * @static
   * @param {string} foo description
   * @returns {string} description
   */
  static fooStatic(foo) {}
}

I would help you out with a pull request, but I've just started using Vim and absolutely no clue on how VimL works yet.

heavenshell commented 8 years ago

Will you also support for static functions in classes?

OK, I'll start improve static function after this issue solve. I'll add it to my todo list. Stay tuned.

I would help you out with a pull request, but I've just started using Vim and absolutely no clue on how VimL works yet.

Don't mind :smile_cat:

heavenshell commented 8 years ago

bfac691e27545194270f62b55036785ea7209947 support class and static.

/**
 * Foo
 */
class Foo {
  /**
   * foo
   *
   * @static
   * @param {} bar
   * @param {} baz
   * @returns {undefined}
   */
  static foo(bar, baz) { } // static method
}