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

Fix get/set conflicting method names. #272

Merged
merged 3 commits into from
Apr 26, 2021
Merged

Fix get/set conflicting method names. #272

merged 3 commits into from
Apr 26, 2021

Conversation

pkwarren
Copy link
Contributor

@pkwarren pkwarren commented Apr 2, 2021

Update the typescript generator to add a suffix '$' to methods which
conflict on the Message base class
('getExtension'/'setExtension'/'getJsPbMessageId'/'setJsPbMessageId').
This will keep the typescript definitions in sync with the generated JS
code from the protoc compiler.

Fixes #271.

Changes

  • Added example getter_name.proto which demonstrates conflicts with both string and bytes types.
  • Added integration test verifying the generated code.
  • Added suffix '$' on getter/setter methods.

Verification

  • Ran 'npm run test' to ensure test passed.
  • Verified that the typescript compiler didn't show any warnings about method conflicts in generated *.d.ts files.

@improbable-prow-robot improbable-prow-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. size/XXL Denotes a PR that changes 600+ lines, ignoring generated files. labels Apr 2, 2021
* optional string extension = 1;
* @return {string}
*/
proto.examplecom.GetterNameConflictMessage.prototype.getExtension$ = function() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you can see the protoc compiler adds $ to get and set functions.

* optional bytes js_pb_message_id = 2;
* @return {!(string|Uint8Array)}
*/
proto.examplecom.GetterNameConflictMessage.prototype.getJsPbMessageId$ = function() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does the same for bytes get/set methods.

printer.printIndentedLn(`get${withUppercase}(): ${exportType}${canBeUndefined ? " | undefined" : ""};`);
printer.printIndentedLn(`set${withUppercase}(value${type === MESSAGE_TYPE ? "?" : ""}: ${exportType}): void;`);
printer.printIndentedLn(`get${jsGetterName(withUppercase)}(): ${exportType}${canBeUndefined ? " | undefined" : ""};`);
printer.printIndentedLn(`set${jsGetterName(withUppercase)}(value${type === MESSAGE_TYPE ? "?" : ""}: ${exportType}): void;`);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to also verify if field presence is enabled, but the TS generation fails. It is possible there might be conflicts with additional methods (hasExtension, etc.) when it is supported.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you were hitting this issue which is now fixed on master.

I've added the presence checks in this commit. Can you add them to this PR please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've rebased to master and pulled in that change - thanks!

@pkwarren
Copy link
Contributor Author

pkwarren commented Apr 2, 2021

/assign @easyCZ

@pkwarren
Copy link
Contributor Author

@MarcusLongmuir - Is there any additional steps I should follow for PR reviews or is assigning @easyCZ still the correct process?

Copy link

@moadz moadz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but @MarcusLongmuir will also be taking a look

@improbable-prow-robot improbable-prow-robot added lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. and removed lgtm Indicates that a PR is ready to be merged. labels Apr 26, 2021
pkwarren and others added 3 commits April 26, 2021 07:55
Update the typescript generator to add a suffix '$' to methods which
conflict on the Message base class
('getExtension'/'setExtension'/'getJsPbMessageId'/'setJsPbMessageId').
This will keep the typescript definitions in sync with the generated JS
code from the protoc compiler.

Fixes #271.
@@ -157,12 +163,12 @@ export function printMessage(fileName: string, exportMap: ExportMap, messageDesc
function printClearIfNotPresent() {
if (!hasClearMethod) {
hasClearMethod = true;
printer.printIndentedLn(`clear${withUppercase}${field.getLabel() === FieldDescriptorProto.Label.LABEL_REPEATED ? "List" : ""}(): void;`);
printer.printIndentedLn(`clear${jsGetterName(withUppercase)}${field.getLabel() === FieldDescriptorProto.Label.LABEL_REPEATED ? "List" : ""}(): void;`);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed that the clear method name didn't match the generated code. This is now fixed as well (and tests updated).

@pkwarren pkwarren requested a review from moadz April 26, 2021 13:11
@improbable-prow-robot improbable-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Apr 26, 2021
@improbable-prow-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: MarcusLongmuir, moadz

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [MarcusLongmuir,moadz]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@MarcusLongmuir MarcusLongmuir merged commit 77d9ada into improbable-eng:master Apr 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 600+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect get/set methods generated for 'extension'/'js_pb_message_id' fields.
5 participants