-
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for explicit modifier (#144)
- Loading branch information
1 parent
77719af
commit f2dd996
Showing
8 changed files
with
162 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
load("@rules_proto//proto:defs.bzl", "proto_library") | ||
load("//:index.bzl", "ts_proto_library") | ||
|
||
|
||
SRCS = glob(["**/*.proto"]) | ||
|
||
proto_library( | ||
name = "protos", | ||
srcs = SRCS, | ||
) | ||
|
||
ts_proto_library( | ||
name = "explicit_override", | ||
outs = [ | ||
src.replace(".proto", ".ts") | ||
for src in SRCS | ||
], | ||
features = ["explicit_override"], | ||
deps = [":protos"], | ||
visibility = ["//test/explicit_override:__pkg__"] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
syntax = "proto3"; | ||
|
||
message ExplicitOverrideMessage { | ||
uint32 example = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
load("//tools:diff_and_update.bzl", "diff_and_update") | ||
load("@npm//@bazel/jasmine:index.bzl", "jasmine_node_test") | ||
load("@npm//@bazel/typescript:index.bzl", "ts_project") | ||
|
||
diff_and_update( | ||
name = "diff_explicit_override", | ||
srcs = [ | ||
"//test/_/explicit_override:explicit_override.ts", | ||
], | ||
checked = [ "explicit_override.ts" ] | ||
) | ||
|
||
ts_project( | ||
name = "explicit_override", | ||
srcs = glob(["*.ts"]), | ||
tsconfig = { | ||
"compilerOptions": { | ||
"target": "ES2020", | ||
"module": "CommonJS", | ||
"noImplicitAny": True, | ||
"noImplicitOverride": True | ||
}, | ||
}, | ||
deps = [ | ||
"@npm//@types/jasmine", | ||
"@npm//@types/node", | ||
"@npm//@types/google-protobuf", | ||
"@npm//google-protobuf", | ||
"@npm//@grpc/grpc-js", | ||
], | ||
) | ||
|
||
jasmine_node_test( | ||
name = "test", | ||
deps = [ | ||
":explicit_override", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { ExplicitOverrideMessage } from './explicit_override'; | ||
|
||
describe('Explicit Override', () => { | ||
it('should compile with noImplicitOverride', () => { | ||
const message = new ExplicitOverrideMessage({ | ||
example: 1, | ||
}); | ||
|
||
expect(message.example).toEqual(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* Generated by the protoc-gen-ts. DO NOT EDIT! | ||
* compiler version: 3.19.1 | ||
* source: test/_/explicit_override/explicit_override.proto | ||
* git: https://github.com/thesayyn/protoc-gen-ts */ | ||
import * as pb_1 from "google-protobuf"; | ||
export class ExplicitOverrideMessage extends pb_1.Message { | ||
#one_of_decls: number[][] = []; | ||
constructor(data?: any[] | { | ||
example?: number; | ||
}) { | ||
super(); | ||
pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); | ||
if (!Array.isArray(data) && typeof data == "object") { | ||
if ("example" in data && data.example != undefined) { | ||
this.example = data.example; | ||
} | ||
} | ||
} | ||
get example() { | ||
return pb_1.Message.getField(this, 1) as number; | ||
} | ||
set example(value: number) { | ||
pb_1.Message.setField(this, 1, value); | ||
} | ||
static fromObject(data: { | ||
example?: number; | ||
}): ExplicitOverrideMessage { | ||
const message = new ExplicitOverrideMessage({}); | ||
if (data.example != null) { | ||
message.example = data.example; | ||
} | ||
return message; | ||
} | ||
toObject() { | ||
const data: { | ||
example?: number; | ||
} = {}; | ||
if (this.example != null) { | ||
data.example = this.example; | ||
} | ||
return data; | ||
} | ||
serialize(): Uint8Array; | ||
serialize(w: pb_1.BinaryWriter): void; | ||
serialize(w?: pb_1.BinaryWriter): Uint8Array | void { | ||
const writer = w || new pb_1.BinaryWriter(); | ||
if (this.example !== undefined) | ||
writer.writeUint32(1, this.example); | ||
if (!w) | ||
return writer.getResultBuffer(); | ||
} | ||
static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ExplicitOverrideMessage { | ||
const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new ExplicitOverrideMessage(); | ||
while (reader.nextField()) { | ||
if (reader.isEndGroup()) | ||
break; | ||
switch (reader.getFieldNumber()) { | ||
case 1: | ||
message.example = reader.readUint32(); | ||
break; | ||
default: reader.skipField(); | ||
} | ||
} | ||
return message; | ||
} | ||
serializeBinary(): Uint8Array { | ||
return this.serialize(); | ||
} | ||
static override deserializeBinary(bytes: Uint8Array): ExplicitOverrideMessage { | ||
return ExplicitOverrideMessage.deserialize(bytes); | ||
} | ||
} |