Skip to content

Commit 2b01529

Browse files
committed
Support stripping enums
1 parent 0b54105 commit 2b01529

File tree

1 file changed

+12
-2
lines changed
  • packages/protoc-gen-ng/src/output/types

1 file changed

+12
-2
lines changed

packages/protoc-gen-ng/src/output/types/enum.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Proto } from '../../input/proto';
22
import { ProtoEnum } from '../../input/proto-enum';
3-
import { classify, preserveCaseSafe } from '../../utils';
3+
import { classify, preserveCaseSafe, pascalize } from '../../utils';
44
import { Printer } from '../misc/printer';
55

66
export class Enum {
@@ -11,8 +11,18 @@ export class Enum {
1111
) { }
1212

1313
print(printer: Printer) {
14+
let enumName = pascalize(this.protoEnum.name)+"_";
15+
16+
function process(v: {name: string, number: number}) {
17+
if (v.name.startsWith(enumName)) {
18+
v.name = v.name.substring(enumName.length);
19+
}
20+
21+
return `${preserveCaseSafe(v.name)} = ${v.number}`
22+
}
23+
1424
printer.add(`export enum ${classify(this.protoEnum.name)} {
15-
${this.protoEnum.valueList.map(v => `${preserveCaseSafe(v.name)} = ${v.number}`).join(',')}
25+
${this.protoEnum.valueList.map(process).join(',')}
1626
}`);
1727
}
1828

0 commit comments

Comments
 (0)