Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Use ternary operator for conditional assignments #394

Merged
merged 2 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions integration/angular/simple-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,8 @@ export const SimpleMessage = {

fromJSON(object: any): SimpleMessage {
const message = { ...baseSimpleMessage } as SimpleMessage;
if (object.numberField !== undefined && object.numberField !== null) {
message.numberField = Number(object.numberField);
} else {
message.numberField = 0;
}
message.numberField =
object.numberField !== undefined && object.numberField !== null ? Number(object.numberField) : 0;
return message;
},

Expand Down
38 changes: 13 additions & 25 deletions integration/avoid-import-conflicts/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,11 @@ export const Simple = {

fromJSON(object: any): Simple {
const message = { ...baseSimple } as Simple;
if (object.name !== undefined && object.name !== null) {
message.name = String(object.name);
} else {
message.name = '';
}
if (object.otherSimple !== undefined && object.otherSimple !== null) {
message.otherSimple = Simple2.fromJSON(object.otherSimple);
} else {
message.otherSimple = undefined;
}
message.name = object.name !== undefined && object.name !== null ? String(object.name) : '';
message.otherSimple =
object.otherSimple !== undefined && object.otherSimple !== null
? Simple2.fromJSON(object.otherSimple)
: undefined;
return message;
},

Expand All @@ -118,11 +113,10 @@ export const Simple = {
fromPartial(object: DeepPartial<Simple>): Simple {
const message = { ...baseSimple } as Simple;
message.name = object.name ?? '';
if (object.otherSimple !== undefined && object.otherSimple !== null) {
message.otherSimple = Simple2.fromPartial(object.otherSimple);
} else {
message.otherSimple = undefined;
}
message.otherSimple =
object.otherSimple !== undefined && object.otherSimple !== null
? Simple2.fromPartial(object.otherSimple)
: undefined;
return message;
},
};
Expand Down Expand Up @@ -163,16 +157,10 @@ export const SimpleEnums = {

fromJSON(object: any): SimpleEnums {
const message = { ...baseSimpleEnums } as SimpleEnums;
if (object.localEnum !== undefined && object.localEnum !== null) {
message.localEnum = simpleEnumFromJSON(object.localEnum);
} else {
message.localEnum = 0;
}
if (object.importEnum !== undefined && object.importEnum !== null) {
message.importEnum = simpleEnumFromJSON3(object.importEnum);
} else {
message.importEnum = 0;
}
message.localEnum =
object.localEnum !== undefined && object.localEnum !== null ? simpleEnumFromJSON(object.localEnum) : 0;
message.importEnum =
object.importEnum !== undefined && object.importEnum !== null ? simpleEnumFromJSON3(object.importEnum) : 0;
return message;
},

Expand Down
12 changes: 2 additions & 10 deletions integration/avoid-import-conflicts/simple2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,8 @@ export const Simple = {

fromJSON(object: any): Simple {
const message = { ...baseSimple } as Simple;
if (object.name !== undefined && object.name !== null) {
message.name = String(object.name);
} else {
message.name = '';
}
if (object.age !== undefined && object.age !== null) {
message.age = Number(object.age);
} else {
message.age = 0;
}
message.name = object.name !== undefined && object.name !== null ? String(object.name) : '';
message.age = object.age !== undefined && object.age !== null ? Number(object.age) : 0;
return message;
},

Expand Down
12 changes: 2 additions & 10 deletions integration/barrel-imports/bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,8 @@ export const Bar = {

fromJSON(object: any): Bar {
const message = { ...baseBar } as Bar;
if (object.name !== undefined && object.name !== null) {
message.name = String(object.name);
} else {
message.name = '';
}
if (object.age !== undefined && object.age !== null) {
message.age = Number(object.age);
} else {
message.age = 0;
}
message.name = object.name !== undefined && object.name !== null ? String(object.name) : '';
message.age = object.age !== undefined && object.age !== null ? Number(object.age) : 0;
return message;
},

Expand Down
18 changes: 3 additions & 15 deletions integration/barrel-imports/foo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,8 @@ export const Foo = {

fromJSON(object: any): Foo {
const message = { ...baseFoo } as Foo;
if (object.name !== undefined && object.name !== null) {
message.name = String(object.name);
} else {
message.name = '';
}
if (object.bar !== undefined && object.bar !== null) {
message.bar = Bar.fromJSON(object.bar);
} else {
message.bar = undefined;
}
message.name = object.name !== undefined && object.name !== null ? String(object.name) : '';
message.bar = object.bar !== undefined && object.bar !== null ? Bar.fromJSON(object.bar) : undefined;
return message;
},

Expand All @@ -67,11 +59,7 @@ export const Foo = {
fromPartial(object: DeepPartial<Foo>): Foo {
const message = { ...baseFoo } as Foo;
message.name = object.name ?? '';
if (object.bar !== undefined && object.bar !== null) {
message.bar = Bar.fromPartial(object.bar);
} else {
message.bar = undefined;
}
message.bar = object.bar !== undefined && object.bar !== null ? Bar.fromPartial(object.bar) : undefined;
return message;
},
};
Expand Down
55 changes: 10 additions & 45 deletions integration/batching-with-context/batching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,16 +306,8 @@ export const BatchMapQueryResponse_EntitiesEntry = {

fromJSON(object: any): BatchMapQueryResponse_EntitiesEntry {
const message = { ...baseBatchMapQueryResponse_EntitiesEntry } as BatchMapQueryResponse_EntitiesEntry;
if (object.key !== undefined && object.key !== null) {
message.key = String(object.key);
} else {
message.key = '';
}
if (object.value !== undefined && object.value !== null) {
message.value = Entity.fromJSON(object.value);
} else {
message.value = undefined;
}
message.key = object.key !== undefined && object.key !== null ? String(object.key) : '';
message.value = object.value !== undefined && object.value !== null ? Entity.fromJSON(object.value) : undefined;
return message;
},

Expand All @@ -329,11 +321,7 @@ export const BatchMapQueryResponse_EntitiesEntry = {
fromPartial(object: DeepPartial<BatchMapQueryResponse_EntitiesEntry>): BatchMapQueryResponse_EntitiesEntry {
const message = { ...baseBatchMapQueryResponse_EntitiesEntry } as BatchMapQueryResponse_EntitiesEntry;
message.key = object.key ?? '';
if (object.value !== undefined && object.value !== null) {
message.value = Entity.fromPartial(object.value);
} else {
message.value = undefined;
}
message.value = object.value !== undefined && object.value !== null ? Entity.fromPartial(object.value) : undefined;
return message;
},
};
Expand Down Expand Up @@ -368,11 +356,7 @@ export const GetOnlyMethodRequest = {

fromJSON(object: any): GetOnlyMethodRequest {
const message = { ...baseGetOnlyMethodRequest } as GetOnlyMethodRequest;
if (object.id !== undefined && object.id !== null) {
message.id = String(object.id);
} else {
message.id = '';
}
message.id = object.id !== undefined && object.id !== null ? String(object.id) : '';
return message;
},

Expand Down Expand Up @@ -419,11 +403,7 @@ export const GetOnlyMethodResponse = {

fromJSON(object: any): GetOnlyMethodResponse {
const message = { ...baseGetOnlyMethodResponse } as GetOnlyMethodResponse;
if (object.entity !== undefined && object.entity !== null) {
message.entity = Entity.fromJSON(object.entity);
} else {
message.entity = undefined;
}
message.entity = object.entity !== undefined && object.entity !== null ? Entity.fromJSON(object.entity) : undefined;
return message;
},

Expand All @@ -435,11 +415,8 @@ export const GetOnlyMethodResponse = {

fromPartial(object: DeepPartial<GetOnlyMethodResponse>): GetOnlyMethodResponse {
const message = { ...baseGetOnlyMethodResponse } as GetOnlyMethodResponse;
if (object.entity !== undefined && object.entity !== null) {
message.entity = Entity.fromPartial(object.entity);
} else {
message.entity = undefined;
}
message.entity =
object.entity !== undefined && object.entity !== null ? Entity.fromPartial(object.entity) : undefined;
return message;
},
};
Expand Down Expand Up @@ -474,11 +451,7 @@ export const WriteMethodRequest = {

fromJSON(object: any): WriteMethodRequest {
const message = { ...baseWriteMethodRequest } as WriteMethodRequest;
if (object.id !== undefined && object.id !== null) {
message.id = String(object.id);
} else {
message.id = '';
}
message.id = object.id !== undefined && object.id !== null ? String(object.id) : '';
return message;
},

Expand Down Expand Up @@ -569,16 +542,8 @@ export const Entity = {

fromJSON(object: any): Entity {
const message = { ...baseEntity } as Entity;
if (object.id !== undefined && object.id !== null) {
message.id = String(object.id);
} else {
message.id = '';
}
if (object.name !== undefined && object.name !== null) {
message.name = String(object.name);
} else {
message.name = '';
}
message.id = object.id !== undefined && object.id !== null ? String(object.id) : '';
message.name = object.name !== undefined && object.name !== null ? String(object.name) : '';
return message;
},

Expand Down
55 changes: 10 additions & 45 deletions integration/batching/batching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,16 +304,8 @@ export const BatchMapQueryResponse_EntitiesEntry = {

fromJSON(object: any): BatchMapQueryResponse_EntitiesEntry {
const message = { ...baseBatchMapQueryResponse_EntitiesEntry } as BatchMapQueryResponse_EntitiesEntry;
if (object.key !== undefined && object.key !== null) {
message.key = String(object.key);
} else {
message.key = '';
}
if (object.value !== undefined && object.value !== null) {
message.value = Entity.fromJSON(object.value);
} else {
message.value = undefined;
}
message.key = object.key !== undefined && object.key !== null ? String(object.key) : '';
message.value = object.value !== undefined && object.value !== null ? Entity.fromJSON(object.value) : undefined;
return message;
},

Expand All @@ -327,11 +319,7 @@ export const BatchMapQueryResponse_EntitiesEntry = {
fromPartial(object: DeepPartial<BatchMapQueryResponse_EntitiesEntry>): BatchMapQueryResponse_EntitiesEntry {
const message = { ...baseBatchMapQueryResponse_EntitiesEntry } as BatchMapQueryResponse_EntitiesEntry;
message.key = object.key ?? '';
if (object.value !== undefined && object.value !== null) {
message.value = Entity.fromPartial(object.value);
} else {
message.value = undefined;
}
message.value = object.value !== undefined && object.value !== null ? Entity.fromPartial(object.value) : undefined;
return message;
},
};
Expand Down Expand Up @@ -366,11 +354,7 @@ export const GetOnlyMethodRequest = {

fromJSON(object: any): GetOnlyMethodRequest {
const message = { ...baseGetOnlyMethodRequest } as GetOnlyMethodRequest;
if (object.id !== undefined && object.id !== null) {
message.id = String(object.id);
} else {
message.id = '';
}
message.id = object.id !== undefined && object.id !== null ? String(object.id) : '';
return message;
},

Expand Down Expand Up @@ -417,11 +401,7 @@ export const GetOnlyMethodResponse = {

fromJSON(object: any): GetOnlyMethodResponse {
const message = { ...baseGetOnlyMethodResponse } as GetOnlyMethodResponse;
if (object.entity !== undefined && object.entity !== null) {
message.entity = Entity.fromJSON(object.entity);
} else {
message.entity = undefined;
}
message.entity = object.entity !== undefined && object.entity !== null ? Entity.fromJSON(object.entity) : undefined;
return message;
},

Expand All @@ -433,11 +413,8 @@ export const GetOnlyMethodResponse = {

fromPartial(object: DeepPartial<GetOnlyMethodResponse>): GetOnlyMethodResponse {
const message = { ...baseGetOnlyMethodResponse } as GetOnlyMethodResponse;
if (object.entity !== undefined && object.entity !== null) {
message.entity = Entity.fromPartial(object.entity);
} else {
message.entity = undefined;
}
message.entity =
object.entity !== undefined && object.entity !== null ? Entity.fromPartial(object.entity) : undefined;
return message;
},
};
Expand Down Expand Up @@ -472,11 +449,7 @@ export const WriteMethodRequest = {

fromJSON(object: any): WriteMethodRequest {
const message = { ...baseWriteMethodRequest } as WriteMethodRequest;
if (object.id !== undefined && object.id !== null) {
message.id = String(object.id);
} else {
message.id = '';
}
message.id = object.id !== undefined && object.id !== null ? String(object.id) : '';
return message;
},

Expand Down Expand Up @@ -567,16 +540,8 @@ export const Entity = {

fromJSON(object: any): Entity {
const message = { ...baseEntity } as Entity;
if (object.id !== undefined && object.id !== null) {
message.id = String(object.id);
} else {
message.id = '';
}
if (object.name !== undefined && object.name !== null) {
message.name = String(object.name);
} else {
message.name = '';
}
message.id = object.id !== undefined && object.id !== null ? String(object.id) : '';
message.name = object.name !== undefined && object.name !== null ? String(object.name) : '';
return message;
},

Expand Down
6 changes: 1 addition & 5 deletions integration/bytes-as-base64/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ const baseMessage: object = {};
export const Message = {
fromJSON(object: any): Message {
const message = { ...baseMessage } as Message;
if (object.data !== undefined && object.data !== null) {
message.data = bytesFromBase64(object.data);
} else {
message.data = new Uint8Array();
}
message.data = object.data !== undefined && object.data !== null ? bytesFromBase64(object.data) : new Uint8Array();
return message;
},

Expand Down
7 changes: 2 additions & 5 deletions integration/bytes-node/point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,8 @@ export const Point = {

fromJSON(object: any): Point {
const message = { ...basePoint } as Point;
if (object.data !== undefined && object.data !== null) {
message.data = Buffer.from(bytesFromBase64(object.data));
} else {
message.data = Buffer.alloc(0);
}
message.data =
object.data !== undefined && object.data !== null ? Buffer.from(bytesFromBase64(object.data)) : Buffer.alloc(0);
return message;
},

Expand Down
9 changes: 4 additions & 5 deletions integration/const-enum/const-enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,10 @@ export const DividerData = {

fromJSON(object: any): DividerData {
const message = { ...baseDividerData } as DividerData;
if (object.type !== undefined && object.type !== null) {
message.type = dividerData_DividerTypeFromJSON(object.type);
} else {
message.type = DividerData_DividerType.DOUBLE;
}
message.type =
object.type !== undefined && object.type !== null
? dividerData_DividerTypeFromJSON(object.type)
: DividerData_DividerType.DOUBLE;
return message;
},

Expand Down
Loading