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: generate valid js code for aliased enum values #1801
Conversation
@@ -18,18 +18,20 @@ var Enum = require("./enum"), | |||
* @ignore | |||
*/ | |||
function genValuePartial_fromObject(gen, field, fieldIndex, prop) { | |||
var defaultAlreadyEmitted = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would usually use let
, but it looks like var
is internally consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's the remains of Node 4 support. We probably want a global refactor to make the code more modern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @bcoe and @alexander-fenster,
Firstly, Thanks for developing and maintaining this amazing library.
Second, I use protobuf.js massively in IoT embedded devices without experiencing any issues.
Due to small memory footprint I use embedded Javascript engine - Duktape (ES5/5.1 complaint + some more features from ES6/7).
If it is planned to use modern syntax for feature/bug fixes, I am concerned about Duktape compatibility issues with the new code. In addition, I don't believe there are better protobuf alternatives in Javascript.
In the future, I see 2 options:
- I maintain a forked ES5/5.1 version equivalent to protobuf.js releases (which could be a nightmare)
- You’d also be maintaining another branch for ES5/5.1 syntax.
Requesting your thoughts and guidance on the same.
Thanks!
**User-Facing Changes** Fixed an issue where certain Protobuf enum values would fail to load with a SyntaxError. **Description** Fix was in protobufjs/protobuf.js#1801. Added a unit test to ensure parsing succeeds. Example file containing dummy enum that reproduces the issue before this fix: [dupe_enum.mcap.zip](https://github.com/foxglove/studio/files/9814444/dupe_enum.mcap.zip)
Having an aliased default value in an enum now breaks the generated JS static code:
Fixing that by making sure that the
default:
clause is emitted only once. Updating the tests accordingly.