Skip to content

Commit

Permalink
[INTERNAL] lib/processors/jsdoc: allow enum definitions using const
Browse files Browse the repository at this point in the history
The JSDoc toolkit classifies 'enum' not as a 'kind' of its own. Instead,
symbols of a different kind (e.g. 'member' or 'constant') are
additionally flagged with 'symbol.isEnum = true'.

The UI5 plugin and template so far only expected symbols of kind
'member' to be flagged with 'isEnum'. With the support of ES6+ syntax,
using a 'const' declaration also makes sense when defining enums.
JSDoc creates a symbol of kind 'constant' in that case, which needs
to be understood by the UI5 plugin and template.

Cherry picked from SAP/openui5@0236e016a
  • Loading branch information
codeworrior committed Nov 30, 2023
1 parent 25b44a7 commit f956cde
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/processors/jsdoc/lib/ui5/plugin.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2923,7 +2923,7 @@ exports.handlers = {
};
}

if ( doclet.kind === 'member' && doclet.isEnum && Array.isArray(doclet.properties) ) {
if ( (doclet.kind === 'member' || doclet.kind === 'constant') && doclet.isEnum && Array.isArray(doclet.properties) ) {
// determine unique enum identifier from key set
let enumID = doclet.properties.map(function(prop) {
return prop.name;
Expand Down
8 changes: 4 additions & 4 deletions lib/processors/jsdoc/lib/ui5/template/publish.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ function isModuleExport($) {
}

function isaClass($) {
return /^(namespace|interface|class|typedef)$/.test($.kind) || ($.kind === 'member' && $.isEnum )/* isNonEmptyNamespace($) */;
return /^(namespace|interface|class|typedef)$/.test($.kind) || (($.kind === 'member' || $.kind === 'constant') && $.isEnum )/* isNonEmptyNamespace($) */;
}

function supportsInheritance($) {
Expand All @@ -191,7 +191,7 @@ function supportsInheritance($) {
function isFirstClassSymbol($) {
return (
/^(namespace|interface|class|typedef)$/.test($.kind)
|| $.kind === 'member' && $.isEnum
|| ($.kind === 'member' || $.kind === 'constant') && $.isEnum
|| ['function', 'member'].includes($.kind) && isModuleExport($)
)/* isNonEmptyNamespace($) */;
}
Expand Down Expand Up @@ -727,7 +727,7 @@ function getMembersOfKind(data, kind) {
switch (kind) {
case 'property':
fnFilter = function($) {
return $.kind === 'constant' || ($.kind === 'member' && !$.isEnum);
return ($.kind === 'constant' || $.kind === 'member') && !$.isEnum;
};
break;
case 'event':
Expand Down Expand Up @@ -2034,7 +2034,7 @@ function createAPIJSON4Symbol(symbol, omitDefaults) {
}
*/

const kind = (symbol.kind === 'member' && symbol.isEnum) ? "enum" : symbol.kind; // handle pseudo-kind 'enum'
const kind = ((symbol.kind === 'member' || symbol.kind === 'constant') && symbol.isEnum) ? "enum" : symbol.kind; // handle pseudo-kind 'enum'

tag(kind);

Expand Down

0 comments on commit f956cde

Please sign in to comment.