mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
feat: add a doclet kind for enums
This commit is contained in:
parent
b60df463f4
commit
3c68f21f36
@ -45,7 +45,7 @@ const CLASSDESC_TAG = '@classdesc';
|
||||
const DEFAULT_SCOPE = SCOPE.NAMES.STATIC;
|
||||
const DESCRIPTION_TAG = '@description';
|
||||
// TODO: `class` should be on this list, right? What are the implications of adding it?
|
||||
const GLOBAL_KINDS = ['constant', 'function', 'member', 'typedef'];
|
||||
const GLOBAL_KINDS = ['constant', 'enum', 'function', 'member', 'typedef'];
|
||||
const ON_CHANGE_OPTIONS = {
|
||||
ignoreDetached: true,
|
||||
pathAsArray: true,
|
||||
|
||||
@ -331,15 +331,13 @@ export const DOCLET_SCHEMA = {
|
||||
inherited: true,
|
||||
},
|
||||
},
|
||||
isEnum: {
|
||||
type: BOOLEAN,
|
||||
},
|
||||
// what kind of symbol is this?
|
||||
kind: {
|
||||
type: STRING,
|
||||
enum: [
|
||||
'class',
|
||||
'constant',
|
||||
'enum',
|
||||
'event',
|
||||
'external',
|
||||
'file',
|
||||
|
||||
@ -595,7 +595,7 @@ export class Parser extends EventEmitter {
|
||||
const doclets = this.resolvePropertyParents(e.code.node.parent);
|
||||
|
||||
doclets.forEach((doclet) => {
|
||||
if (doclet?.isEnum) {
|
||||
if (doclet.kind === 'enum') {
|
||||
doclet.properties = doclet.properties || [];
|
||||
|
||||
// members of an enum inherit the enum's type
|
||||
|
||||
@ -184,8 +184,9 @@ export const getTags = (env) => ({
|
||||
enum: {
|
||||
canHaveType: true,
|
||||
onTagged(doclet, tag) {
|
||||
doclet.kind ??= 'member';
|
||||
doclet.isEnum = true;
|
||||
if (!doclet.kind) {
|
||||
util.setDocletKindToTitle(doclet, tag);
|
||||
}
|
||||
util.setDocletTypeToValueType(doclet, tag);
|
||||
},
|
||||
},
|
||||
|
||||
@ -565,7 +565,7 @@ export function getMembers(data) {
|
||||
externals: find(data, { kind: 'external' }),
|
||||
events: find(data, { kind: 'event' }),
|
||||
globals: find(data, {
|
||||
kind: ['member', 'function', 'constant', 'typedef'],
|
||||
kind: ['enum', 'member', 'function', 'constant', 'typedef'],
|
||||
memberof: { isUndefined: true },
|
||||
}),
|
||||
mixins: find(data, { kind: 'mixin' }),
|
||||
|
||||
@ -145,6 +145,17 @@
|
||||
<?js }); ?></dl>
|
||||
<?js } ?>
|
||||
|
||||
<?js
|
||||
var enums = self.find({kind: 'enum', memberof: isGlobalPage ? {isUndefined: true} : doc.longname});
|
||||
if (enums && enums.length && enums.forEach) {
|
||||
?>
|
||||
<h3 class="subsection-title">Enums</h3>
|
||||
|
||||
<?js enums.forEach(function(e) { ?>
|
||||
<?js= self.partial('members.tmpl', e) ?>
|
||||
<?js }); ?>
|
||||
<?js } ?>
|
||||
|
||||
<?js
|
||||
var members = self.find({kind: 'member', memberof: isGlobalPage ? {isUndefined: true} : doc.longname});
|
||||
|
||||
|
||||
@ -49,7 +49,7 @@
|
||||
props.hasName = true;
|
||||
}
|
||||
|
||||
if (typeof prop.defaultvalue !== 'undefined' && !data.isEnum) {
|
||||
if (typeof prop.defaultvalue !== 'undefined' && !data.kind === 'enum') {
|
||||
props.hasDefault = true;
|
||||
}
|
||||
});
|
||||
|
||||
@ -13,11 +13,13 @@
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
describe('@enum tag', () => {
|
||||
const docSet = jsdoc.getDocSetFromFile('test/fixtures/enumtag.js');
|
||||
const tristate = docSet.getByLongname('TriState')[0];
|
||||
|
||||
it('When a symbol has an @enum tag, it has a properties array.', () => {
|
||||
it('When a symbol has an @enum tag, it has the kind `enum` and a properties array.', () => {
|
||||
expect(tristate.kind).toBe('enum');
|
||||
expect(tristate.properties).toBeArray();
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user