Skip to content

Commit

Permalink
[INTERNAL] lib/processors/jsdoc: function result union needs parentheses
Browse files Browse the repository at this point in the history
Otherwise this function which returns either an object or null:
@returns {function(sap.ui.core.Control): ({rows: int, columns:
int}|null)|undefined}

ends up as:
function(sap.ui.core.Control):{rows: int, columns: int} | null |
undefined

Which means the function *always* has an object as result and there
could be null or undefined as *alternative* to the function.

Cherry picked from SAP/openui5@b21d5c95c.
  • Loading branch information
codeworrior committed Jan 27, 2023
1 parent 6eb4ec1 commit aba8edc
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/processors/jsdoc/lib/ui5/plugin.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3164,13 +3164,19 @@ exports.astNodeVisitor = {
typeString += `(${paramTypes.join(", ")})`;
}
if (parsedType.result) {
typeString += `:${toTypeString(parsedType.result)}`;
let resultType = toTypeString(parsedType.result);
// ensure the function result remains belonging together even when a union of the entire function with other types is created
// Example: ensure parentheses around function result in: function(int):({rows: int, columns: int}|null)|undefined
if (parsedType.result.type === "TypeUnion") {
resultType = `(${resultType})`;
}
typeString += `:${resultType}`;
}
types.push(typeString);
// #### END: MODIFIED BY SAP
break;
case TYPES.NameExpression:
types.push(parsedType.name);
types.push(parsedType.name);
break;
case TYPES.NullLiteral:
types.push('null');
Expand Down

0 comments on commit aba8edc

Please sign in to comment.