-
Notifications
You must be signed in to change notification settings - Fork 350
Description
I first used Uglify with simply compress and mangle true, but got into an issue with the arguments field being used after the function argument variable was reused and changed.
Original config:
uglify: {
options: {
compress: true,
mangle: true,
sourceMap: true,
sourceMapIncludeSources: true,
},
target: {
src: '<%= paths.src.js %>',
dest: '<%= paths.dest.jsMin %>'
}
},
Original code:
_dropAction: function(event) {
event.preventDefault();
// check acceptable file type
const fileItems = event.originalEvent.dataTransfer.items;
if (fileItems != null) {
for (let fileItem of fileItems) {
if (!this.checkType(fileItem.type)) {
this.showError_('File type is not allowed: ' + fileItem.type);
return;
}
}
}
exWidget._dropAction.apply(this, arguments);
},
Original result:
_dropAction: function (A) {
A.preventDefault();
A = A.originalEvent.dataTransfer.items;
if (null != A)
for (var e of A)
if (!this.checkType(e.type))
return void this.showError_("File type is not allowed: " + e.type);
t._dropAction.apply(this, arguments)
}
Then I tried to change it at the compress level and the file was somewhat different, but the problematic code was unchanged. I then added keep_fargs to mangle and I got very different results. Now the function argument wasn't replaced but it was still re-using the variable
Config:
uglify: {
options: {
compress: { "keep_fargs" : "true" },
mangle: { "keep_fargs" : "true" },
sourceMap: true,
sourceMapIncludeSources: true,
},
target: {
src: '<%= paths.src.js %>',
dest: '<%= paths.dest.jsMin %>'
}
},
Here is that output where we can see that event is being re-assigned on the 3rd line to some items. Finally at the end of the function, arguments is being passed with now incorrect content:
_dropAction: function(event) {
event.preventDefault();
event = event.originalEvent.dataTransfer.items;
if (null != event)
for (var A of event)
if (!this.checkType(A.type))
return void this.showError_("File type is not allowed: " + A.type);
e._dropAction.apply(this, arguments)
},
Finally after perusing on Github I tried the following config:
uglify: {
options: {
compress: {
keep_fargs : true
},
mangle: {
keep_fargs : true
},
sourceMap: true,
sourceMapIncludeSources: true,
},
target: {
src: '<%= paths.src.js %>',
dest: '<%= paths.dest.jsMin %>'
}
},
and now nothing is compressed or mangled at all.
So I'm very confused and even wondering if the 2nd result is a bug with UglifyJS or not, or I am totally misconfiguring this thing.
Thanks