@@ -347,10 +347,12 @@ function toJsType(field, parentIsInterface = false) {
347
347
type = "Uint8Array" ;
348
348
break ;
349
349
default :
350
- if ( field . resolve ( ) . resolvedType )
350
+ if ( field . resolve ( ) . resolvedType ) {
351
351
type = exportName ( field . resolvedType , asInterface ) ;
352
- else
352
+ }
353
+ else {
353
354
type = "*" ; // should not happen
355
+ }
354
356
break ;
355
357
}
356
358
if ( field . map )
@@ -380,36 +382,42 @@ function syntaxForType(type) {
380
382
function isExplicitPresence ( field , syntax ) {
381
383
382
384
// In proto3, optional fields are explicit
383
- if ( syntax === "proto3" )
385
+ if ( syntax === "proto3" ) {
384
386
return field . options != null && field . options [ "proto3_optional" ] === true ;
387
+ }
385
388
386
389
// 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" ) {
388
391
return field . optional && ! ( field . partOf || field . repeated || field . map ) ;
392
+ }
389
393
390
394
throw new Error ( "Unknown proto syntax: [" + syntax + "]" ) ;
391
395
}
392
396
393
397
function isImplicitPresence ( field , syntax ) {
394
398
395
399
// In proto3, everything not marked optional has implicit presence (including maps and repeated fields)
396
- if ( syntax === "proto3" )
400
+ if ( syntax === "proto3" ) {
397
401
return field . options == null || field . options [ "proto3_optional" ] !== true ;
402
+ }
398
403
399
404
// In proto2, nothing has implicit presence
400
- if ( syntax === "proto2" )
405
+ if ( syntax === "proto2" ) {
401
406
return false ;
407
+ }
402
408
403
409
throw new Error ( "Unknown proto syntax: [" + syntax + "]" ) ;
404
410
}
405
411
406
412
function isOptionalOneOf ( oneof , syntax ) {
407
413
408
- if ( syntax === "proto2" )
414
+ if ( syntax === "proto2" ) {
409
415
return false ;
416
+ }
410
417
411
- if ( oneof . fieldsArray == null || oneof . fieldsArray . length !== 1 )
418
+ if ( oneof . fieldsArray == null || oneof . fieldsArray . length !== 1 ) {
412
419
return false ;
420
+ }
413
421
414
422
var field = oneof . fieldsArray [ 0 ] ;
415
423
@@ -482,14 +490,16 @@ function buildType(ref, type) {
482
490
// With semantic nulls, fields are nullable if they are explicitly optional or part of a one-of
483
491
// Maps, repeated values and fields with implicit defaults are never null after construction
484
492
// 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 ) {
486
494
jsType = jsType + "|null" ;
495
+ }
487
496
}
488
497
else {
489
498
// Without semantic nulls, everything is optional in proto3
490
499
// 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 ) {
492
501
jsType = jsType + "|null|undefined" ;
502
+ }
493
503
}
494
504
pushComment ( [
495
505
field . comment || type . name + " " + field . name + "." ,
0 commit comments