Skip to content

Commit

Permalink
Fixes optional handling for class-level comments (JS) and interfaces …
Browse files Browse the repository at this point in the history
…(TS)
  • Loading branch information
martin-traverse committed Jul 24, 2024
1 parent 0a0cdb6 commit b38a668
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions cli/targets/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,14 @@ function toJsType(field) {
return type;
}

function handleOptionalFields(jsType, field) {

if (field.optional && !field.map && !field.repeated && (field.resolvedType instanceof Type || config["null-defaults"]) || field.partOf)
return jsType + "|null|undefined";
else
return jsType
}

function buildType(ref, type) {

if (config.comments) {
Expand All @@ -366,8 +374,7 @@ function buildType(ref, type) {
var prop = util.safeProp(field.name); // either .name or ["name"]
prop = prop.substring(1, prop.charAt(0) === "[" ? prop.length - 1 : prop.length);
var jsType = toJsType(field);
if (field.optional)
jsType = jsType + "|null";
jsType = handleOptionalFields(jsType, field);
typeDef.push("@property {" + jsType + "} " + (field.optional ? "[" + prop + "]" : prop) + " " + (field.comment || type.name + " " + field.name));
});
push("");
Expand All @@ -394,8 +401,7 @@ function buildType(ref, type) {
if (config.comments) {
push("");
var jsType = toJsType(field);
if (field.optional && !field.map && !field.repeated && (field.resolvedType instanceof Type || config["null-defaults"]) || field.partOf)
jsType = jsType + "|null|undefined";
jsType = handleOptionalFields(jsType, field);
pushComment([
field.comment || type.name + " " + field.name + ".",
"@member {" + jsType + "} " + field.name,
Expand Down

0 comments on commit b38a668

Please sign in to comment.