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