BundlerMinifier
BundlerMinifier copied to clipboard
ES6 lambda/arrow function minification error
Installed product versions
- Visual Studio: 2017 Professionsal
- This extension: 2.7.386
Description
When I use arrow/lambda functions in JS, the minifier modifies the logic incorrectly.
I use knockout and am filtering an observable array like this:
this.fileCount = ko.computed(function () {
return this.files().filter(f => !f.isComplete() || f.isSuccess()).length;
}, this);
this.uploadCount = ko.computed(function () {
return this.files().filter(f => f.isComplete() && f.isSuccess()).length;
}, this);
The minifier turns this into ultimately the same function, both incorrect:
this.fileCount=ko.computed(function(){return this.files().filter(n=>n.isComplete()&&n.isSuccess()).length},this);
this.uploadCount=ko.computed(function(){return this.files().filter(n=>n.isComplete()&&n.isSuccess()).length},this);
Steps to recreate
- Minify the above code snippet
Current behavior
The logic in the .filter() method is incorrect. It seems like it tries to optimize the calculation, but it does it incorrectly.
Expected behavior
It should keep the original logic, just remove whitespace
Looks like another NUglify issue to me.
As a work around you can write
f => { return (!f.isComplete() || f.isSuccess()); }
This gets minified down to the expected result.
Thanks Sam, I changed it to function notation completely (function(f) { return .... }) and that minified just fine. Figured I would raise it as an issue anyway
Here I'm not able to minify a file with arrow-syntax lambdas at all. It just gives an error "Stack empty". If I change all lambdas to use the full function syntax, then everything works normally.
@andre-ss6 this is most probably your issue https://github.com/xoofx/NUglify/pull/97 Just had the same thing, think ive fixed it