-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Bug: collapse_vars break zone.js (var missing) #2437
Comments
Thanks for the report - investigating. |
repro: $ cat cv.js
function foo() {
bar();
}
function bar() {
if (xhrDesc) {
var req = new XMLHttpRequest();
var result = !!req.onreadystatechange;
Object.defineProperty(XMLHttpRequest.prototype, 'onreadystatechange', xhrDesc || {});
return result;
}
else {
var req = new XMLHttpRequest();
var detectFunc = function () { };
req.onreadystatechange = detectFunc;
var result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc;
req.onreadystatechange = null;
return result;
}
}
foo(); $ bin/uglifyjs cv.js -c toplevel -b
!function() {
!function() {
if (xhrDesc) return result = !!(req = new XMLHttpRequest()).onreadystatechange,
Object.defineProperty(XMLHttpRequest.prototype, "onreadystatechange", xhrDesc || {}),
result;
var detectFunc = function() {};
(req = new XMLHttpRequest()).onreadystatechange = detectFunc;
var result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc;
req.onreadystatechange = null;
}();
}(); |
- avoid issues with identity reference due to deep cloning fixes mishoo#2437
@alexlamsl If
$ cat cv2.js
function bar() {
if (xhrDesc) {
var req = new XMLHttpRequest();
var result = !!req.onreadystatechange;
Object.defineProperty(XMLHttpRequest.prototype, 'onreadystatechange', xhrDesc || {});
return result;
}
else {
var req = new XMLHttpRequest();
var detectFunc = function () { };
req.onreadystatechange = detectFunc;
var result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc;
req.onreadystatechange = null;
return result;
}
}
function foo() {
bar();
}
foo(); $ bin/uglifyjs cv2.js -c toplevel -b
!function() {
!function() {
if (xhrDesc) return result = !!(req = new XMLHttpRequest()).onreadystatechange,
Object.defineProperty(XMLHttpRequest.prototype, "onreadystatechange", xhrDesc || {}),
result;
var req = new XMLHttpRequest(), detectFunc = function() {};
req.onreadystatechange = detectFunc;
var result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc;
req.onreadystatechange = null;
}();
}(); |
To temporarily work around this bug in compress: {
reduce_vars: false
} or from the command line:
or lock in an earlier version of uglify in your project. |
@kzc when you swap the order of |
- avoid issues with identity reference due to deep cloning fixes mishoo#2437
- avoid issues with identity reference due to deep cloning fixes mishoo#2437
Hi,
it seems that
uglify-js
(3.1.7) breakszone.js
(0.8.18, ES5 input), when using collapse_vars. (Which is only enabled by default when using the JS API, but not on the command line?)Unfortunately, I didn't manage to get a nice minimal reproduction snippet, as zone.js is pretty large and the issue disappears when I'm trying a the innermost 2 functions.
JavaScript input
npm install zone.js@0.8.18
<!DOCTYPE html><html><script type="text/javascript" src="zone.min.js"></script></html>
The
uglifyjs
CLI command executed orminify()
options used.uglifyjs --beautify -c collapse_vars=true node_modules/zone.js/dist/zone.js -o zone.min.js
uglifyjs --beautify -c collapse_vars=false node_modules/zone.js/dist/zone.js -o zone.min.js
JavaScript output or error produced.
zone.min.js, lines 1128 to 1157:
The text was updated successfully, but these errors were encountered: