jonschlinkert / parse-comments

Parse JavaScript code comments. Works with block and line comments, and should work with CSS, LESS, SASS, or any language with the same comment formats.
https://github.com/jonschlinkert
MIT License
66 stars 23 forks source link

code.context is an empty object #15

Open tunnckoCore opened 5 years ago

tunnckoCore commented 5 years ago

Hey @jonschlinkert :)

The comment's code.context is an empty object when using export default, arrow function.

/**
 * Foobar 1 with default export arrow function and typescript
 * and empty code.context
 *
 * @param  {string} `commit` a commit message
 * @api public
 */

export default (commit: string): Commit => {};

/**
 * Foobar 2 with default export arrow function JS
 * and empty code.context
 *
 * @param  {string} `commit` a commit message
 * @api public
 */

export default (commit) => {};

/**
 * Foobar 3 with default export named function and typescript
 *
 * @param  {string} `commit` a commit message
 * @api public
 */

export default function foobar(commit: string): Commit {}

/**
 * Foobar 4 with default export named function javascript
 *
 * @param  {string} `commit` a commit message
 * @api public
 */

export default function foobar(commit) {}

/**
 * Foobar 5 with default export arrow function and typescript
 *
 * @param  {string} `commit` a commit message
 * @api public
 */

module.exports = (commit: string): Commit => {};

/**
 * Foobar 6 with default export arrow function JS
 *
 * @param  {string} `commit` a commit message
 * @api public
 */

module.exports = (commit) => {};

/**
 * Foobar 7 with default export named function and typescript
 *
 * @param  {string} `commit` a commit message
 * @api public
 */

module.exports = function foobar(commit: string): Commit {};

/**
 * Foobar 8 with default export named function javascript
 *
 * @param  {string} `commit` a commit message
 * @api public
 */

module.exports = function foobar(commit) {};
jonschlinkert commented 5 years ago

It’s because it’s typescript. I’d take a pr to add support!

Sent from my iPhone

On Sep 20, 2019, at 10:15 PM, Charlike Mike Reagent notifications@github.com wrote:

Hey @jonschlinkert :)

The comment's code.context is an empty object when using export default, doesn't matter it is name or arrow function`

/**

  • Foobar
  • @param {string} commit a commit message
  • @api public */

export default foobar(commit: string): Commit {}

/**

  • Foobar
  • @param {string} commit a commit message
  • @api public */ export default (commit: string): Commit => {} It is working when export function.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

tunnckoCore commented 5 years ago

It's not. The Foobar 2 example don't have types. But okay, cool :)

So far so good, api docs generation in 50 lines :D Just playing around with PoC to test how the latest parse-commits works. And it's great :tada:

2019-09-21-061926_1280x1024_scrot 2019-09-21-062241_1280x1024_scrot

jonschlinkert commented 5 years ago

Nice! That’s awesome!

Sent from my iPhone

On Sep 20, 2019, at 11:24 PM, Charlike Mike Reagent notifications@github.com wrote:

It's not. The Foobar 2 example don't have types. But okay, cool :)

So far so good, api docs generation in 50 lines :D Just playing around with PoC to test how the latest parse-commits works. And it's great :)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

tunnckoCore commented 4 years ago

Another example is object methods

{
  use: () => {},
  use() {},
  use: foo
}

Also, the code.value is an empty string.