-
Notifications
You must be signed in to change notification settings - Fork 11
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
Generated JS parser fails if minified #17
Comments
Strange, it should already work like that - In each subclass of if ("__type__" in data) {
// Object
class_ = namespace[data["__type__"]];
return class_.deserialize(data, memo); Sounds like it fails somewhere along the line, but I can't say where just from your description. |
There are a couple things happening, from what I can tell-- For example, take the serialized The
gets turned into
But the constructor for class
winds up making
Since Even worse, since all constructors are renamed to |
@erezsh I tested your PR and it works great. That's an elegant solution. Thanks for addressing this. I don't consider this your bug, since your un-minified code works and the minifier breaks it. But webpack is too common. |
Fix for issue #17: Renaming classes breaks deserialization
Great. It's now merged, and will be included in the next release. You're right it's not really a bug, but code lives in an ecosystem, and should try to play nice with it, if it can. I am concerned that maybe you'll encounter more errors, because there are other parts of the code that use let tokens_by_type = classify(terminals, (t) => t.pattern.constructor.name); Which is supposed to distinguish between two different classes. But if the constructors are all renamed to the same name, it might create the wrong behavior. |
It's the mechanism that resolves collisions between keywords and variable names. It's not always easy to notice when it goes wrong. Let me know if the new PR solves it - #20 |
I'm including a generated
parser.js
as part of a large web project. Webpack with the Terser plugin is configured to minify all of the javascript. The default (I believe) behavior is to rename all non-top-level classes to one or two-letter names.But serialized data, like this:
includes names of classes as string literals.
When the classes are renamed, the data can no longer be deserialized and an exception is thrown.
Can a dictionary be built that maps the serialized type names to classes without relying on the class names themselves?
The text was updated successfully, but these errors were encountered: