chore(dotnet): simplify enum generation (2) (#6628)

This commit is contained in:
Pavel Feldman 2021-05-17 22:28:14 -07:00 committed by GitHub
parent debffa7476
commit 1e6f899c82
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -606,12 +606,11 @@ function renderMethod(member, parent, name, out) {
* *
* @param {Documentation.Type} type * @param {Documentation.Type} type
* @param {Documentation.Class|Documentation.Type} parent * @param {Documentation.Class|Documentation.Type} parent
* @param {generateNameCallback} generateNameCallback * @param {function(Documentation.Type): string} generateNameCallback
* @callback generateNameCallback * @param {boolean=} optional
* @param {Documentation.Type} t
* @returns {string} * @returns {string}
*/ */
function translateType(type, parent, generateNameCallback = t => t.name) { function translateType(type, parent, generateNameCallback = t => t.name, optional = false) {
// a few special cases we can fix automatically // a few special cases we can fix automatically
if (type.expression === '[null]|[Error]') if (type.expression === '[null]|[Error]')
return 'void'; return 'void';
@ -620,7 +619,7 @@ function translateType(type, parent, generateNameCallback = t => t.name) {
if (type.union) { if (type.union) {
if (type.union[0].name === 'null' && type.union.length === 2) if (type.union[0].name === 'null' && type.union.length === 2)
return translateType(type.union[1], parent, generateNameCallback); return translateType(type.union[1], parent, generateNameCallback, true);
if (type.expression === '[string]|[Buffer]') if (type.expression === '[string]|[Buffer]')
return `byte[]`; // TODO: make sure we implement extension methods for this! return `byte[]`; // TODO: make sure we implement extension methods for this!
@ -636,7 +635,7 @@ function translateType(type, parent, generateNameCallback = t => t.name) {
// Regular primitive enums are named in the markdown. // Regular primitive enums are named in the markdown.
if (type.name) { if (type.name) {
enumTypes.set(type.name, type.union.map(t => t.name)); enumTypes.set(type.name, type.union.map(t => t.name));
return type.name; return optional ? type.name + '?' : type.name;
} }
return null; return null;
} }