protobufjs / protobuf.js

Protocol Buffers for JavaScript & TypeScript.
Other
9.89k stars 1.41k forks source link

Unreadable source code #1124

Open robert-j-webb opened 6 years ago

robert-j-webb commented 6 years ago

Hi, I was debugging an issue where my proto's verification wasn't working, so I started attempting to dive into the way that types are built and what, if anything, that I could do about it.

However, I was pretty quickly stonewalled by this line: https://github.com/dcodeIO/protobuf.js/blob/e8449c4bf1269a2cc423708db6f0b47a383d33f0/src/type.js#L207

It appears that for whatever reason, protobufjs requires running eval on a minified string of JS. Now, this may be for a very good reason, as I'm sure this is a performant library and certain shortcuts have to be made. However, the lack of any comment about what this code is doing or at least the unminified version of the code in comments is completely inexcusable.

I did figure out my issue with my project but for future users of this library, some explanation should be left about this code - preferrably the unminified source.

dcodeIO commented 6 years ago

What the library does there is generating code of encoders and decoders at runtime, specifically tailored for each individual message. A minifier can't handle code in strings like that, so some manual minification has been applied. Might not be the easiest to read at first, but it's not impossible either.

robert-j-webb commented 6 years ago

I see that it does it now! I actually read minified source way more often than I should, although I try to avoid it. Is it possible that we can find the unminified code and throw it in that spot as a comment so that way other users will be able to understand what cleverness is going on here?