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

Support literal enum of strings #662

Closed
ngryman opened this issue Jan 25, 2017 · 8 comments
Closed

Support literal enum of strings #662

ngryman opened this issue Jan 25, 2017 · 8 comments
Milestone

Comments

@ngryman
Copy link

ngryman commented Jan 25, 2017

Hey,

Would you consider supporting @param enum of strings like those in this proposal: jsdoc/jsdoc#629.

Thanks!

@tmcw
Copy link
Member

tmcw commented Jan 26, 2017

Yep, we already support the examples given that issue, with the exception that

/**
 * @param {MediaType} mediaType - Type of the media
 */
function foo(mediaType){};
/**
 * @type {('MP4'|'WEBM')} MediaType - Allowed media types
 */

Should have @typedef instead of @type for the custom type definition (@type is used to declare the type of an attached value, rather than a type definition.

Feel free to file an issue if you see the existing support lacking in any way!

@tmcw tmcw closed this as completed Jan 26, 2017
@ngryman
Copy link
Author

ngryman commented Jan 26, 2017

Thanks for your answer.

I should have elaborated a bit more. I'm talking about literal, in-place or anonymous enums without any reference to existing type. I don't know the name for this 🤣. But I know that some other tools support it. It's really convenient for simple one place enums.

This currently crashes:

/**
 * @param {('pre'|'post')} [order='pre'] Traversal mode
 * or
 * @param {'pre'|'post'} [order='pre'] Traversal mode
 */
Output
> documentation build lib/*.js --format md --output docs/api.md

/Users/ngryman/Projects/arbre/node_modules/documentation/lib/commands/build.js:67
      throw err;
      ^

Error: Unknown type StringLiteralType
    at formatType (/Users/ngryman/Projects/arbre/node_modules/documentation/lib/output/util/format_type.js:174:11)
    at commaList (/Users/ngryman/Projects/arbre/node_modules/documentation/lib/output/util/format_type.js:60:22)
    at formatType (/Users/ngryman/Projects/arbre/node_modules/documentation/lib/output/util/format_type.js:125:12)
    at formatType (/Users/ngryman/Projects/arbre/node_modules/documentation/lib/output/util/format_type.js:166:30)
    at /Users/ngryman/Projects/arbre/node_modules/documentation/lib/output/markdown_ast.js:48:41
    at Array.map (native)
    at paramList (/Users/ngryman/Projects/arbre/node_modules/documentation/lib/output/markdown_ast.js:43:51)
    at paramSection (/Users/ngryman/Projects/arbre/node_modules/documentation/lib/output/markdown_ast.js:66:9)
    at generate (/Users/ngryman/Projects/arbre/node_modules/documentation/lib/output/markdown_ast.js:175:13)
    at /Users/ngryman/Projects/arbre/node_modules/documentation/lib/output/markdown_ast.js:194:26

This works by misinterpreting pre and post as types:

/**
 * @param {pre|post} [order='pre'] Traversal mode
 */

EDIT: I edited the title to try to be more precise.

@ngryman ngryman changed the title Support enum of strings Support literal enum of strings Jan 26, 2017
@tmcw
Copy link
Member

tmcw commented Jan 26, 2017

What version of documentation.js are you using? That input also works for me, and we've supported StringLiteralType since v4.0.0-beta.18

@tmcw tmcw reopened this Jan 26, 2017
@ngryman
Copy link
Author

ngryman commented Jan 26, 2017

I'm using 4.0.0-beta.18. Here is the offending repo for more informations: https://github.com/arbrejs/arbre.

@tmcw
Copy link
Member

tmcw commented Jan 29, 2017

Should that repository fail on npm run docs? I've tried that, and it works properly:

~/src〉g clone https://github.com/arbrejs/arbre.git
Cloning into 'arbre'...
remote: Counting objects: 107, done.
remote: Total 107 (delta 0), reused 0 (delta 0), pack-reused 107
Receiving objects: 100% (107/107), 76.08 KiB | 0 bytes/s, done.
Resolving deltas: 100% (13/13), done.
~/src〉cd arbre
~/src/arbre〉yarn
yarn install v0.17.9
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
[4/4] 📃  Building fresh packages...
$ npm run build -s
'default' is not exported by node_modules/tree-morph/index.cjs
✨  Done in 21.67s.
~/src/arbre〉npm run docs

> [email protected] docs /Users/tmcw/src/arbre
> documentation build lib/*.js --format md --output docs/api.md

@ngryman
Copy link
Author

ngryman commented Jan 30, 2017

Yes sorry I didn't push the crashing jsdoc code. I've pushed it in the documentation-bug branch if you want.
Basically you can just quote {pre|post} values in lib/walk.js so documentation parses it as strings not types.

@tmcw tmcw added this to the beta20 milestone Apr 12, 2017
@tmcw
Copy link
Member

tmcw commented Apr 12, 2017

✨ I can confirm that the issue is present in documentation.js < beta.18 and fixed in beta.18 and beyond.

Partly this is due to semver, unfortunately: specifying ^4.0.0-beta.18 gets 4.0.0-beta9. I'm going to get out of this mess ASAP and just release 4.0.0.

Going to write a testcase for this problem and close with that PR.

@Mouvedia
Copy link

Mouvedia commented Sep 3, 2020

Is #629 fixed?
If so you should edit one of the answers on https://stackoverflow.com/q/19093935/248058

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

No branches or pull requests

3 participants