-
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
incorrectly minifying q 8.12 library #153
Comments
I'm sorry, I don't understand this report. Can you be more specific as to what exactly do you find broken? |
Lines 685 - 687 of the original code are: object = valueOf(object);
// assimilate thenables, CommonJS/Promises/A
if (isPromiseAlike(object)) Uglify transforms that to: if (n = t(n), v(n)) { The problem is that the call to function t(n) {
return "[object StopIteration]" === he(n) || n instanceof se;
}
function isStopIteration(exception) {
return (
object_toString(exception) === "[object StopIteration]" ||
exception instanceof QReturnValue
);
} It should have emitted a call to function l(n) {
return d(n) ? n.valueOf() : n;
} Unchecking the |
If you use the following to compress:
(I used Here's what happens. In the output (mq.js) at line 242, code looks like this: }, void 0, function t() {
return n;
}); That's the }, void 0, function valueOf() {
return object;
}); So minification is correct. The original code is wrong, of course, because that's not a function declaration—it's a function expression instead, and so the |
You're misunderstanding the original code. The It looks like Uglify is incorrectly making the |
Ah, I understand.. And you are right — but UglifyJS behaves this way to be compliant with this quirk in Internet Explorer. AFAIK, in IE the function expression on line 738 will take precedence in that scope and override the outer A simple solution would be for you to rename the function at line 738. |
I was wondering if that was the case, but unchecking I didn't write the original library, and I don't know if it works in IEs that have that bug. |
Or (sorry, I forgot, this was recently added) — another solution would be to pass |
Ah, |
For anyone else having this issue, just use Q v0.9+, which doesn't have the problem in the first place |
Previously: Without `--screw-ie`, UglifyJS would always leak names of function expressions into the containing scope, as if they were function declarations. That was to emulate IE<9 behavior. Code relying on this IE bug would continue to work properly after mangling, although it would only work in IE (since other engines don't share the bug). Sometimes this broke legitimage code (see #153 and #155). With `--screw-ie` the names would not be leaked into the current scope, working properly in legit cases; but still it broke legit code when running in IE<9 (see #24). Currently: Regardless of the `--screw-ie` setting, the names will not be leaked. Code relying on the IE bug will not work properly after mangling. <evil laughter here> Without `--screw-ie`: a hack has been added to the mangler to avoid using the same name for a function expression and some other variable in the same scope. This keeps legit code working, at the (negligible, indeed) cost of one more identifier. With `--screw-ie` you allow the mangler to name function expressions with the same identifier as another variable in scope. After mangling code might break in IE<9. Oh man, the commit message is longer than the patch. Fix #153, #155
changes in 2.3.2 also caused this issue for me (SLak's link HabitRPG/habitica#920). pinning to 2.3.1 fixed |
@lefnire's issue is caused by transforming Fixed by derbyjs/racer#130 |
@SLaks heh, sorry about that. The transformation is valid, so that's why it's doing it unconditionally. BTW, I see in a comment there “Uglify can't parse a naked function. Executing it allows Uglify to parse it properly”. It's not a parser issue, it's in the JS spec. (“naked” functions must have a name, otherwise it's a syntax error; I suspect that is the problem). |
Uglify is in the right here; you've saved one character. The fundamental problem there is that Racer wants to uglify an expression (function expression), whereas Uglify is designed to uglify statements (and function declaration statements must have names). Should Uglify have a function to uglify expressions rather than statements? |
Well, UglifyJS is designed to uglify programs, and a JS program is a sequence of statements. But yeah, we could have an option to parse expressions. |
the following file https://github.com/kriskowal/q/blob/76afd7b7abaad30cbfee394c72227d9dc06154e6/q.js when run through uglify generates a
which is the equivalent of
which is not the correct as the line called by this
should instead evaluate to code produced for the function valueOf;
The text was updated successfully, but these errors were encountered: