documentation icon indicating copy to clipboard operation
documentation copied to clipboard

Cannot use "require" within @example in TypeScript files

Open rdmurphy opened this issue 6 years ago • 2 comments

If you're reporting a bug, please include input code, output documentation, a description of what you expected to happen, and what happened instead.

  • What version of documentation.js are you using?: 12.0.3
  • How are you running documentation.js (on the CLI, Node.js API, Grunt, other?): CLI

I've attached a repo that reproduces what I'm seeing. I have a function written in TypeScript that includes an @example call in the JSDoc comment. But the only way I can get it to successfully parse (without throwing an error) is if I use import ... from ..., not require(). I don't believe this is an issue when parsing JavaScript. Maybe the TypeScript parser does not understand require, but I'm wanting to document how to use my library in Node.js (so with require()), not TypeScript-parsed JavaScript. 😬

The example repo: https://github.com/rdmurphy/documentation-typescript-require

Thank you!

rdmurphy avatar Jul 31 '19 01:07 rdmurphy

--shallow

cekvenich avatar Aug 20 '19 13:08 cekvenich

The root cause is in detective, which only parses modules with acorn if there's a require() detected.

https://github.com/browserify/detective/blob/master/index.js#L44-L47

I think, long-term, documentation would swap out detective for something that's maintained and modern.

tmcw avatar Sep 09 '19 16:09 tmcw