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

Problem with minifiers #2

Open
rstacruz opened this issue Jul 1, 2013 · 2 comments
Open

Problem with minifiers #2

rstacruz opened this issue Jul 1, 2013 · 2 comments
Labels

Comments

@rstacruz
Copy link

rstacruz commented Jul 1, 2013

When you define a class like so:

_.class({
  initialize: function($name, $age) { ... }
});

...those names will be changed upon minification (say with uglifyjs -m), and will not work as intended anymore.

I don't think there's any easy way to fix this, unfortunately.

@rhysbrettbowen
Copy link

the only way to really fix this is to go down the same route as angularJS and have a separate array that can be defined that holds strings of what each argument should be called. The main problem is then that these properties will be defined on the object at run time and if you try to access them then the minifier may rename those unless you use square brackets notation to access the properties.

I know with Closure compiler you can export symbols to let the compiler know not to rename certain properties, not sure what uglify does though

@Morantron
Copy link
Owner

Hi!

As @rhysbrettbowen commented, AngularJS guys solve this by defining the arguments in a separate array ( so that the annotate function that looks up the function arguments returns this array instead of the actual arguments which are minified and meaningless ). However, having to manually type these arguments for each method adds a lot of boilerplate.

One solution that I think could work is to write a grunt task that needs to be run before minification that fills those arrays automatically.

//before minification
var Person = _.class({
     initialize: function($name, $surname){},
     someMethod: function(self, something){}
});

//after pre-minification task
var Person = _.class({
     initialize: function($name, $surname){},
     someMethod: function(self, something){}
});
Person.prototype.initialize.$args = [ '$name', '$surname' ];
Person.prototype.someMethod.$args = [ 'self', 'something'];

If this works and I'm not missing something, you don't have to worry about these quirks while developing, but only when deploying.

I'll give it a try, thanks for your feedback! =]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants