Skip to content

Commit c478e1f

Browse files
author
Martin Traverse
committed
Add braces to if/else clauses for readability on all code touched by this change
1 parent 258679c commit c478e1f

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

cli/targets/static.js

+20-10
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,12 @@ function toJsType(field, parentIsInterface = false) {
347347
type = "Uint8Array";
348348
break;
349349
default:
350-
if (field.resolve().resolvedType)
350+
if (field.resolve().resolvedType) {
351351
type = exportName(field.resolvedType, asInterface);
352-
else
352+
}
353+
else {
353354
type = "*"; // should not happen
355+
}
354356
break;
355357
}
356358
if (field.map)
@@ -380,36 +382,42 @@ function syntaxForType(type) {
380382
function isExplicitPresence(field, syntax) {
381383

382384
// In proto3, optional fields are explicit
383-
if (syntax === "proto3")
385+
if (syntax === "proto3") {
384386
return field.options != null && field.options["proto3_optional"] === true;
387+
}
385388

386389
// In proto2, fields are explicitly optional if they are not part of a map, array or oneOf group
387-
if (syntax === "proto2")
390+
if (syntax === "proto2") {
388391
return field.optional && !(field.partOf || field.repeated || field.map);
392+
}
389393

390394
throw new Error("Unknown proto syntax: [" + syntax + "]");
391395
}
392396

393397
function isImplicitPresence(field, syntax) {
394398

395399
// In proto3, everything not marked optional has implicit presence (including maps and repeated fields)
396-
if (syntax === "proto3")
400+
if (syntax === "proto3") {
397401
return field.options == null || field.options["proto3_optional"] !== true;
402+
}
398403

399404
// In proto2, nothing has implicit presence
400-
if (syntax === "proto2")
405+
if (syntax === "proto2") {
401406
return false;
407+
}
402408

403409
throw new Error("Unknown proto syntax: [" + syntax + "]");
404410
}
405411

406412
function isOptionalOneOf(oneof, syntax) {
407413

408-
if (syntax === "proto2")
414+
if (syntax === "proto2") {
409415
return false;
416+
}
410417

411-
if (oneof.fieldsArray == null || oneof.fieldsArray.length !== 1)
418+
if (oneof.fieldsArray == null || oneof.fieldsArray.length !== 1) {
412419
return false;
420+
}
413421

414422
var field = oneof.fieldsArray[0];
415423

@@ -482,14 +490,16 @@ function buildType(ref, type) {
482490
// With semantic nulls, fields are nullable if they are explicitly optional or part of a one-of
483491
// Maps, repeated values and fields with implicit defaults are never null after construction
484492
// Members are never undefined, at a minimum they are initialized to null
485-
if (isExplicitPresence(field, syntax) || field.partOf)
493+
if (isExplicitPresence(field, syntax) || field.partOf) {
486494
jsType = jsType + "|null";
495+
}
487496
}
488497
else {
489498
// Without semantic nulls, everything is optional in proto3
490499
// Keep |undefined for backwards compatibility
491-
if (field.optional && !field.map && !field.repeated && (field.resolvedType instanceof Type || config["null-defaults"]) || field.partOf)
500+
if (field.optional && !field.map && !field.repeated && (field.resolvedType instanceof Type || config["null-defaults"]) || field.partOf) {
492501
jsType = jsType + "|null|undefined";
502+
}
493503
}
494504
pushComment([
495505
field.comment || type.name + " " + field.name + ".",

0 commit comments

Comments
 (0)