UglifyJS version 3.4.2 changes behavior of code.
Closed this issue · 7 comments
Bug report
Uglify version 3.4.9
See this CodePen. It shows how Parsley.js v2.8.1 changes behavior when uglified by recent versions of uglifyjs.
<input type="date" min="2000-01-02" max="2179-06-06" value="2018-11-23">
is invalidated when Parsley.js is uglified by uglifyjs version 3.4.2, but not when uglified by uglifyjs version 3.4.1.
When comparing the uglified files, these are the lines that are different:
Uglified by uglifyjs version 3.4.1
if (this.validateDate && instance._isDateInput()) return arguments[0] = Utils.parse.date(value),
null !== value && this.validateDate.apply(this, arguments);
if (this.validateNumber) return !isNaN(value) && (arguments[0] = parseFloat(value),
this.validateNumber.apply(this, arguments));
Uglified by uglifyjs version 3.4.2
if (this.validateDate && instance._isDateInput()) return null !== (value = Utils.parse.date(value)) && this.validateDate.apply(this, arguments);
if (this.validateNumber) return !isNaN(value) && (value = parseFloat(value), this.validateNumber.apply(this, arguments));
Minified code is not useful for the purposes of a bug report. There's a reason for the issue template. A complete unminified JS input exhibiting the problem is required.
Try disabling the compress
option arguments
and report your findings.
Sorry about not including the input code. Here it comes:
Unminified
function validate(value) {
if (this.validateDate && instance._isDateInput()) {
arguments[0] = Utils.parse.date(arguments[0]);
if (arguments[0] === null) return false;
return this.validateDate.apply(this, arguments);
}
throw 'Validator `' + this.name + '` only handles multiple values';
}
UglifyJS 3.4.1 uglifyjs -c -b
function validate(value) {
if (this.validateDate && instance._isDateInput()) return arguments[0] = Utils.parse.date(value),
null !== value && this.validateDate.apply(this, arguments);
throw "Validator `" + this.name + "` only handles multiple values";
}
UglifyJS 3.4.2 uglifyjs -c -b
function validate(value) {
if (this.validateDate && instance._isDateInput()) return null !== (value = Utils.parse.date(value)) && this.validateDate.apply(this, arguments);
throw "Validator `" + this.name + "` only handles multiple values";
}
UglifyJS 3.4.1 uglifyjs -b
function validate(value) {
if (this.validateDate && instance._isDateInput()) {
arguments[0] = Utils.parse.date(arguments[0]);
if (arguments[0] === null) return false;
return this.validateDate.apply(this, arguments);
}
throw "Validator `" + this.name + "` only handles multiple values";
}
UglifyJS 3.4.2 uglifyjs -b
function validate(value) {
if (this.validateDate && instance._isDateInput()) {
arguments[0] = Utils.parse.date(arguments[0]);
if (arguments[0] === null) return false;
return this.validateDate.apply(this, arguments);
}
throw "Validator `" + this.name + "` only handles multiple values";
}
As you can see, the issue only happens with the -c
flag.
Like I said, use -c arguments=false
. Or switch to terser
.
Sorry, here it is:
UglifyJS 3.4.1 uglifyjs -c arguments=false -b
function validate(value) {
if (this.validateDate && instance._isDateInput()) return arguments[0] = Utils.parse.date(arguments[0]),
null !== arguments[0] && this.validateDate.apply(this, arguments);
throw "Validator `" + this.name + "` only handles multiple values";
}
UglifyJS 3.4.2 uglifyjs -c arguments=false -b
function validate(value) {
if (this.validateDate && instance._isDateInput()) return arguments[0] = Utils.parse.date(arguments[0]),
null !== arguments[0] && this.validateDate.apply(this, arguments);
throw "Validator `" + this.name + "` only handles multiple values";
}
UglifyJS 3.4.1 uglifyjs -c arguments=false
function validate(value){if(this.validateDate&&instance._isDateInput())return arguments[0]=Utils.parse.date(arguments[0]),null!==arguments[0]&&this.validateDate.apply(this,arguments);throw"Validator `"+this.name+"` only handles multiple values"}
UglifyJS 3.4.2 uglifyjs -c arguments=false
function validate(value){if(this.validateDate&&instance._isDateInput())return arguments[0]=Utils.parse.date(arguments[0]),null!==arguments[0]&&this.validateDate.apply(this,arguments);throw"Validator `"+this.name+"` only handles multiple values"}
As you can see, the issue doesn't happen with the -c arguments=false
flag.
I didn't look at your example in detail. If the minified code produces the wrong result then it's probably a bug. I don't know whether uglify-js
is maintained at this point. There are workarounds in any case.