-
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
Uncaught ReferenceError: Invalid left-hand side expression in postfix operation on 2.8.0 #1516
Comments
Yes. It is broken. 2.7.5 still works though. |
Same issue here, was able to fix by setting |
Please provide a repro. |
👍 We're using grunt-contrib-uglify which is bringing this in automatically. |
We ended up adding uglify 2.7.5 to our package.json, which is then used by webpack, so everything works again. |
To fix the issue we'd need a short javascript program that exhibits the error when uglified. Please also provide the uglify options used. |
Sucks, we had this issue just now! |
It's reproducible on Facebook's https://github.com/zertosh/invariant/blob/master/invariant.js#L43
Via Webpack, we have our |
@graulund I just ran "use strict";
var NODE_ENV = process.env.NODE_ENV, invariant = function(condition, format, a, b, c, d, e, f) {
if ("production" !== NODE_ENV && void 0 === format) {
throw new Error("invariant requires an error message argument");
}
if (!condition) {
var error;
if (void 0 === format) {
error = new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");
} else {
var args = [ a, b, c, d, e, f ], argIndex = 0;
error = new Error(format.replace(/%s/g, function() {
return args[argIndex++];
})), error.name = "Invariant Violation";
}
throw error.framesToPop = 1, error;
}
}; I don't use Webpack, but have they specified some other |
Still not reproducible:
|
You're right, it's not reproducible for me over CLI either. It must be something in Webpack's UglifyJs wrapper, then? |
|
That's a possibility. Some options may not be propagated using the lower level API. No issue with the uglify minify() API AFAICT:
|
@graulund Maybe it would be useful to debug against uglifyjs-webpack-plugin if someone can provide a small project. You can control Uglify version against that plugin (it's the same as in webpack core). |
I had to fix this immediately for
|
We are using function createXMLHTTPObject() {
var XMLHttpFactories = [];
XMLHttpFactories.push(function () {
return new XMLHttpRequest();
});
XMLHttpFactories.push(function () {
return new ActiveXObject("Msxml2.XMLHTTP");
});
XMLHttpFactories.push(function () {
return new ActiveXObject("Msxml3.XMLHTTP");
});
XMLHttpFactories.push(function () {
return new ActiveXObject("Microsoft.XMLHTTP");
});
var xmlHttp = false;
for (var i = 0; i < XMLHttpFactories.length; i++) {
try {
xmlHttp = XMLHttpFactories[i]();
}
catch (e) {
continue;
}
break;
}
return xmlHttp;
} Running it through grunt-contrib-uglify, we get this: function b() {
var a = [];
a.push(function () {
return new XMLHttpRequest
}), a.push(function () {
return new ActiveXObject("Msxml2.XMLHTTP")
}), a.push(function () {
return new ActiveXObject("Msxml3.XMLHTTP")
}), a.push(function () {
return new ActiveXObject("Microsoft.XMLHTTP")
});
for (; 0 < a.length; 0++) {
try {
!1 = a[0]()
} catch (b) {
continue
}
break
}
return !1
} The issue resides in the for-loop, specifically Apologies if this is the wrong place to comment and we should rather bug grunt-contrib-uglify, but I figured since you supply the functionality, you might want to be aware :-) |
The entry point of moment js is a good sample of the problem
|
@baumanno I cannot reproduce this on CLI: $ uglifyjs test.js -c warnings=false -b bracketize
function createXMLHTTPObject() {
var XMLHttpFactories = [];
XMLHttpFactories.push(function() {
return new XMLHttpRequest();
}), XMLHttpFactories.push(function() {
return new ActiveXObject("Msxml2.XMLHTTP");
}), XMLHttpFactories.push(function() {
return new ActiveXObject("Msxml3.XMLHTTP");
}), XMLHttpFactories.push(function() {
return new ActiveXObject("Microsoft.XMLHTTP");
});
for (var xmlHttp = !1, i = 0; i < XMLHttpFactories.length; i++) {
try {
xmlHttp = XMLHttpFactories[i]();
} catch (e) {
continue;
}
break;
}
return xmlHttp;
}
$ uglifyjs test.js -mc warnings=false -b bracketize
function createXMLHTTPObject() {
var t = [];
t.push(function() {
return new XMLHttpRequest();
}), t.push(function() {
return new ActiveXObject("Msxml2.XMLHTTP");
}), t.push(function() {
return new ActiveXObject("Msxml3.XMLHTTP");
}), t.push(function() {
return new ActiveXObject("Microsoft.XMLHTTP");
});
for (var e = !1, n = 0; n < t.length; n++) {
try {
e = t[n]();
} catch (t) {
continue;
}
break;
}
return e;
} ... where Would be nice to know what additional options |
My guess is that it's the new @alexlamsl I would advise defaulting that to |
We have this error in Create React App end-to-end test suite. I can't give you the exact place where it errors because our logs are not verbose enough, but I suspect the earlier example with Our options: compress: {
screw_ie8: true,
warnings: false
},
mangle: {
screw_ie8: true
},
output: {
comments: false,
screw_ie8: true
},
sourceMap: true We also replace Hope this helps somewhat! |
Looking into the code where they minify with Uglify... this is what they use to minify, using the API. function minify(output, fileName, mangle, uglifyOpts) {
var uglify = require('uglify-js');
var ast;
try{
ast = uglify.parse(output.source, { filename: fileName });
} catch(e){
throw new Error(e);
}
ast.figure_out_scope();
ast = ast.transform(uglify.Compressor(uglifyOpts.compress));
ast.figure_out_scope();
if (mangle !== false)
ast.mangle_names();
var sourceMap;
if (output.sourceMap) {
if (typeof output.sourceMap === 'string')
output.sourceMap = JSON.parse(output.sourceMap);
var sourceMapIn = output.sourceMap;
sourceMap = uglify.SourceMap({
file: fileName,
orig: sourceMapIn
});
if (uglifyOpts.sourceMapIncludeSources && sourceMapIn && Array.isArray(sourceMapIn.sourcesContent)) {
sourceMapIn.sourcesContent.forEach(function(content, idx) {
sourceMap.get().setSourceContent(sourceMapIn.sources[idx], content);
});
}
} https://github.com/systemjs/builder/blob/f988373a164c9a5c868afc1e57664706d6f2ab79/lib/output.js#L74 This is probably a |
@mishoo I should probably do that, though I'm still scratching my head as to why I can't reproduce any of these using |
Also, I just wanted to note that we all appreciate your amazing work on Uglify. Mishaps like this happen, but it’s vitally important that you folks keep innovating to make our builds smaller. ❤️ If someone got burned by this in production, they should use a lockfile. |
@maxired your example doesn't seem to break on CLI either: $ uglifyjs test.js -c warnings=false -b bracketize
function Moment(config) {
copyConfig(this, config), this._d = new Date(null != config._d ? config._d.getTime() : NaN),
this.isValid() || (this._d = new Date(NaN)), updateInProgress === !1 && (updateInProgress = !0,
hooks.updateOffset(this), updateInProgress = !1);
}
$ uglifyjs test.js -mc warnings=false -b bracketize
function Moment(e) {
copyConfig(this, e), this._d = new Date(null != e._d ? e._d.getTime() : NaN), this.isValid() || (this._d = new Date(NaN)),
updateInProgress === !1 && (updateInProgress = !0, hooks.updateOffset(this), updateInProgress = !1);
} |
Please test and report if there are any further issues. |
OK, I can confirm |
Can you |
Thanks a lot for the quick fix @alexlamsl |
@hinok thanks for the work - I'll look into it now. |
@gaearon |
Thank a lot for the quick fix, it works! Not sure it could help, but I found that the problem for my uglification was in a Running
|
@rap2hpoutre yep. The |
Thank you for the quick turnaround! We got bitten by way of |
I suspect that diff --git a/tasks/lib/uglify.js b/tasks/lib/uglify.js
index 7a16066..97b74a1 100644
--- a/tasks/lib/uglify.js
+++ b/tasks/lib/uglify.js
@@ -98,7 +98,7 @@ exports.init = function(grunt) {
options.compress.screw_ie8 = false;
}
var compressor = UglifyJS.Compressor(options.compress);
- topLevel = topLevel.transform(compressor);
+ topLevel = compressor.compress(topLevel);
// Need to figure out scope again after source being altered
if (options.expression === false) { Similarly, diff --git a/src/index.js b/src/index.js
index 9155801..92e6d5c 100644
--- a/src/index.js
+++ b/src/index.js
@@ -87,7 +87,7 @@ class UglifyJsPlugin {
const compress = uglify.Compressor(options.compress || {
warnings: false
}); // eslint-disable-line new-cap
- ast = ast.transform(compress);
+ ast = compress.compress(ast);
}
if(options.mangle !== false) {
ast.figure_out_scope(options.mangle || {}); @bebraw Can you confirm this? Edit: independently confirmed. |
@kzc Ah, I see what could go wrong there. |
This broke us too. |
All upstream I verified that if |
|
Ideally all downstream |
Modules like webpack and grunt-contrib-uglify still uses `ast.transform(compressor)` before `Compressor.compress(ast)` was introduced. Workaround this compatibility issue by deactivating `reduce_vars` in such case. fixes mishoo#1516
Modules like webpack and grunt-contrib-uglify still uses `ast.transform(compressor)` before `Compressor.compress(ast)` was introduced. Workaround this compatibility issue by deactivating `reduce_vars` in such case. fixes mishoo#1516
Modules like webpack and grunt-contrib-uglify still uses `ast.transform(compressor)` before `Compressor.compress(ast)` was introduced. Workaround this compatibility issue by deactivating `reduce_vars` in such case. Also fix use case with omitted `options` when calling `Compressor()`. fixes mishoo#1516
Modules like webpack and grunt-contrib-uglify still uses `ast.transform(compressor)` before `Compressor.compress(ast)` was introduced. Workaround this compatibility issue by deactivating `reduce_vars` in such case. Also fix use case with omitted `options` when calling `Compressor()`. fixes #1516
How Can I update uglify-js@2.8.0. to uglify-js@2.8.1? |
Hi,
we've received
Uncaught ReferenceError: Invalid left-hand side expression in postfix operation
on version 2.8.0 for all our js projects where we use uglify-js (webpack and browserify bundlers).Do you have some other reports about this issue?
The text was updated successfully, but these errors were encountered: