feat: add a doclet kind for enums

This commit is contained in:
Jeff Williams 2025-01-12 15:06:45 -08:00
parent b60df463f4
commit 3c68f21f36
No known key found for this signature in database
8 changed files with 22 additions and 10 deletions

View File

@ -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,

View File

@ -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',

View 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

View File

@ -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);
},
},

View File

@ -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' }),

View File

@ -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});

View File

@ -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;
}
});

View File

@ -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();
});