diff --git a/packages/protobuf-test/extra/name-clash.proto b/packages/protobuf-test/extra/name-clash.proto index 64bc2dc5b..d3c343d2d 100644 --- a/packages/protobuf-test/extra/name-clash.proto +++ b/packages/protobuf-test/extra/name-clash.proto @@ -107,6 +107,16 @@ message case { message return { } +// reserved object property +message constructor { +} +message toString { +} +message toJSON { +} +message valueOf { +} + // used by runtime message Message { } diff --git a/packages/protobuf-test/src/gen/js/extra/name-clash_pb.d.ts b/packages/protobuf-test/src/gen/js/extra/name-clash_pb.d.ts index 201c35324..03dc5994d 100644 --- a/packages/protobuf-test/src/gen/js/extra/name-clash_pb.d.ts +++ b/packages/protobuf-test/src/gen/js/extra/name-clash_pb.d.ts @@ -523,6 +523,84 @@ export declare class return$ extends Message$1 { static equals(a: return$ | PlainMessage$1 | undefined, b: return$ | PlainMessage$1 | undefined): boolean; } +/** + * reserved object property + * + * @generated from message spec.constructor + */ +export declare class constructor extends Message$1 { + constructor(data?: PartialMessage$1); + + static readonly runtime: typeof proto3; + static readonly typeName = "spec.constructor"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): constructor; + + static fromJson(jsonValue: JsonValue, options?: Partial): constructor; + + static fromJsonString(jsonString: string, options?: Partial): constructor; + + static equals(a: constructor | PlainMessage$1 | undefined, b: constructor | PlainMessage$1 | undefined): boolean; +} + +/** + * @generated from message spec.toString + */ +export declare class toString extends Message$1 { + constructor(data?: PartialMessage$1); + + static readonly runtime: typeof proto3; + static readonly typeName = "spec.toString"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): toString; + + static fromJson(jsonValue: JsonValue, options?: Partial): toString; + + static fromJsonString(jsonString: string, options?: Partial): toString; + + static equals(a: toString | PlainMessage$1 | undefined, b: toString | PlainMessage$1 | undefined): boolean; +} + +/** + * @generated from message spec.toJSON + */ +export declare class toJSON extends Message$1 { + constructor(data?: PartialMessage$1); + + static readonly runtime: typeof proto3; + static readonly typeName = "spec.toJSON"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): toJSON; + + static fromJson(jsonValue: JsonValue, options?: Partial): toJSON; + + static fromJsonString(jsonString: string, options?: Partial): toJSON; + + static equals(a: toJSON | PlainMessage$1 | undefined, b: toJSON | PlainMessage$1 | undefined): boolean; +} + +/** + * @generated from message spec.valueOf + */ +export declare class valueOf extends Message$1 { + constructor(data?: PartialMessage$1); + + static readonly runtime: typeof proto3; + static readonly typeName = "spec.valueOf"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): valueOf; + + static fromJson(jsonValue: JsonValue, options?: Partial): valueOf; + + static fromJsonString(jsonString: string, options?: Partial): valueOf; + + static equals(a: valueOf | PlainMessage$1 | undefined, b: valueOf | PlainMessage$1 | undefined): boolean; +} + /** * used by runtime * diff --git a/packages/protobuf-test/src/gen/js/extra/name-clash_pb.js b/packages/protobuf-test/src/gen/js/extra/name-clash_pb.js index 953178d80..be50f8120 100644 --- a/packages/protobuf-test/src/gen/js/extra/name-clash_pb.js +++ b/packages/protobuf-test/src/gen/js/extra/name-clash_pb.js @@ -202,6 +202,40 @@ export const return$ = proto3.makeMessageType( {localName: "return$"}, ); +/** + * reserved object property + * + * @generated from message spec.constructor + */ +export const constructor = proto3.makeMessageType( + "spec.constructor", + [], +); + +/** + * @generated from message spec.toString + */ +export const toString = proto3.makeMessageType( + "spec.toString", + [], +); + +/** + * @generated from message spec.toJSON + */ +export const toJSON = proto3.makeMessageType( + "spec.toJSON", + [], +); + +/** + * @generated from message spec.valueOf + */ +export const valueOf = proto3.makeMessageType( + "spec.valueOf", + [], +); + /** * used by runtime * diff --git a/packages/protobuf-test/src/gen/ts/extra/name-clash_pb.ts b/packages/protobuf-test/src/gen/ts/extra/name-clash_pb.ts index 59bd43873..7f9bf7f38 100644 --- a/packages/protobuf-test/src/gen/ts/extra/name-clash_pb.ts +++ b/packages/protobuf-test/src/gen/ts/extra/name-clash_pb.ts @@ -713,6 +713,132 @@ export class return$ extends Message$1 { } } +/** + * reserved object property + * + * @generated from message spec.constructor + */ +export class constructor extends Message$1 { + constructor(data?: PartialMessage$1) { + super(); + proto3.util.initPartial(data, this); + } + + static readonly runtime: typeof proto3 = proto3; + static readonly typeName = "spec.constructor"; + static readonly fields: FieldList = proto3.util.newFieldList(() => [ + ]); + + static fromBinary(bytes: Uint8Array, options?: Partial): constructor { + return new constructor().fromBinary(bytes, options); + } + + static fromJson(jsonValue: JsonValue, options?: Partial): constructor { + return new constructor().fromJson(jsonValue, options); + } + + static fromJsonString(jsonString: string, options?: Partial): constructor { + return new constructor().fromJsonString(jsonString, options); + } + + static equals(a: constructor | PlainMessage$1 | undefined, b: constructor | PlainMessage$1 | undefined): boolean { + return proto3.util.equals(constructor, a, b); + } +} + +/** + * @generated from message spec.toString + */ +export class toString extends Message$1 { + constructor(data?: PartialMessage$1) { + super(); + proto3.util.initPartial(data, this); + } + + static readonly runtime: typeof proto3 = proto3; + static readonly typeName = "spec.toString"; + static readonly fields: FieldList = proto3.util.newFieldList(() => [ + ]); + + static fromBinary(bytes: Uint8Array, options?: Partial): toString { + return new toString().fromBinary(bytes, options); + } + + static fromJson(jsonValue: JsonValue, options?: Partial): toString { + return new toString().fromJson(jsonValue, options); + } + + static fromJsonString(jsonString: string, options?: Partial): toString { + return new toString().fromJsonString(jsonString, options); + } + + static equals(a: toString | PlainMessage$1 | undefined, b: toString | PlainMessage$1 | undefined): boolean { + return proto3.util.equals(toString, a, b); + } +} + +/** + * @generated from message spec.toJSON + */ +export class toJSON extends Message$1 { + constructor(data?: PartialMessage$1) { + super(); + proto3.util.initPartial(data, this); + } + + static readonly runtime: typeof proto3 = proto3; + static readonly typeName = "spec.toJSON"; + static readonly fields: FieldList = proto3.util.newFieldList(() => [ + ]); + + static fromBinary(bytes: Uint8Array, options?: Partial): toJSON { + return new toJSON().fromBinary(bytes, options); + } + + static fromJson(jsonValue: JsonValue, options?: Partial): toJSON { + return new toJSON().fromJson(jsonValue, options); + } + + static fromJsonString(jsonString: string, options?: Partial): toJSON { + return new toJSON().fromJsonString(jsonString, options); + } + + static equals(a: toJSON | PlainMessage$1 | undefined, b: toJSON | PlainMessage$1 | undefined): boolean { + return proto3.util.equals(toJSON, a, b); + } +} + +/** + * @generated from message spec.valueOf + */ +export class valueOf extends Message$1 { + constructor(data?: PartialMessage$1) { + super(); + proto3.util.initPartial(data, this); + } + + static readonly runtime: typeof proto3 = proto3; + static readonly typeName = "spec.valueOf"; + static readonly fields: FieldList = proto3.util.newFieldList(() => [ + ]); + + static fromBinary(bytes: Uint8Array, options?: Partial): valueOf { + return new valueOf().fromBinary(bytes, options); + } + + static fromJson(jsonValue: JsonValue, options?: Partial): valueOf { + return new valueOf().fromJson(jsonValue, options); + } + + static fromJsonString(jsonString: string, options?: Partial): valueOf { + return new valueOf().fromJsonString(jsonString, options); + } + + static equals(a: valueOf | PlainMessage$1 | undefined, b: valueOf | PlainMessage$1 | undefined): boolean { + return proto3.util.equals(valueOf, a, b); + } +} + /** * used by runtime * diff --git a/packages/protobuf/src/private/names.ts b/packages/protobuf/src/private/names.ts index 019177dfc..7a954ee58 100644 --- a/packages/protobuf/src/private/names.ts +++ b/packages/protobuf/src/private/names.ts @@ -53,12 +53,7 @@ export function localName( const pkg = desc.file.proto.package; const offset = pkg.length > 0 ? pkg.length + 1 : 0; const name = desc.typeName.substring(offset).replace(/\./g, "_"); - // For services, we only care about safe identifiers, not safe object properties, - // but we have shipped v1 with a bug that respected object properties, and we - // do not want to introduce a breaking change, so we continue to escape for - // safe object properties. - // See https://github.com/bufbuild/protobuf-es/pull/391 - return safeObjectProperty(safeIdentifier(name)); + return safeIdentifier(name); } case "enum_value": { const sharedPrefix = desc.parent.sharedPrefix;