Skip to content

Commit

Permalink
fix(protoc-gen-ng): old typescript compability
Browse files Browse the repository at this point in the history
  • Loading branch information
Grubana committed Sep 29, 2021
1 parent e95366c commit cd288cf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class EnumMessageField implements MessageField {
if (this.isArray) {
printer.add(`${this.attributeName}: (this.${this.attributeName} || []).map(v => ${this.notRepeatedDataType}[v]),`);
} else {
printer.add(`${this.attributeName}: ${this.oneOf || this.messageField.proto3Optional ? `this.${this.attributeName} === undefined ? null : ` : ''}${this.notRepeatedDataType}[this.${this.attributeName} ?? 0],`);
printer.add(`${this.attributeName}: ${this.oneOf || this.messageField.proto3Optional ? `this.${this.attributeName} === undefined ? null : ` : ''}${this.notRepeatedDataType}[this.${this.attributeName} === null || this.${this.attributeName} === undefined ? 0 : this.${this.attributeName}],`);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ export class NumberMessageField implements MessageField {
if (this.isArray) {
printer.add(`${this.attributeName}: (this.${this.attributeName} || []).slice(),`);
} else {
printer.add(`${this.attributeName}: this.${this.attributeName}${this.oneOf || this.messageField.proto3Optional ? ' ?? null' : ''},`);
if (this.oneOf || this.messageField.proto3Optional){
printer.add(`${this.attributeName}: this.${this.attributeName} === null || this.${this.attributeName} === undefined ? null : this.${this.attributeName},`);
} else {
printer.add(`${this.attributeName}: this.${this.attributeName},`);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ export class StringMessageField implements MessageField {
if (this.isArray) {
printer.add(`${this.attributeName}: (this.${this.attributeName} || []).slice(),`);
} else {
printer.add(`${this.attributeName}: this.${this.attributeName}${this.oneOf || this.messageField.proto3Optional ? ' ?? null' : ''},`);
if (this.oneOf || this.messageField.proto3Optional){
printer.add(`${this.attributeName}: this.${this.attributeName} === null || this.${this.attributeName} === undefined ? null : this.${this.attributeName},`);
} else {
printer.add(`${this.attributeName}: this.${this.attributeName},`);
}
}
}

Expand Down

0 comments on commit cd288cf

Please sign in to comment.