Wikunia / brackets-FuncDocr

FuncDocr generates JS/PHPDoc annotations for your functions
101 stars 14 forks source link

Support ES6 Default Parameters #78

Open stowball opened 8 years ago

stowball commented 8 years ago

In ES6, you can specify default parameters for functions as described here: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/default_parameters

Sublime and DocBlockr support them well. For example:

/**
 * [description]
 * @param  {Number} maxPosts [description]
 * @param  {String} filter   [description]
 * @return {[type]}          [description]
 */
export default function (maxPosts = 2, filter = '') {
}

/**
 * [description]
 * @param  {Number} options.maxPosts [description]
 * @param  {String} options.filter   [description]
 * @return {[type]}                  [description]
 */
export default function ({maxPosts = 2, filter = ''}) {
}

/**
 * [description]
 * @param  {Number} options.maxPosts [description]
 * @param  {String} options.filter   [description]
 * @return {[type]}                  [description]
 */
export default function ({maxPosts = 2, filter = ''} = {}) {
}

whereas, FuncDocr for the same will produce:

/**
 * [[Description]]
 * @param {[[Type]]} maxPosts = 2 [[Description]]
 * @param {[[Type]]} filter = ''  [[Description]]
 */
export default function (maxPosts = 2, filter = '') {
}

export default function ({maxPosts = 2, filter = ''}) {
}

export default function ({maxPosts = 2, filter = ''} = {}) {
}

Default parameters can also be arrays, functions and more, but I haven't had a need for anything else yet so can't tell you how they're documented.

Wikunia commented 8 years ago

Okay, never ever used it :D I'll have a look! Thanks for the issue ;)