-
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
add Date
and other known globals to unsafe
compress option
#2302
Conversation
@kzc indeed - how did I miss that?! Anyway, now that we are here, I wonder if things like |
Sure, we can add What about the following?
I don't think we should add the various typed Array types, nor should we add Map, Set, WeakMap and WeakSet - in Which of the Error types should we add?
|
Hmm - global (side-effect-free) functions can't be optimised with the current code path, so I'll handle them in a separate PR. As for the objects, I took the controversial step of testing if those mentioned on MDN exist under IE8: EvalError
RangeError
ReferenceError
SyntaxError
TypeError
URIError
Date
JSON |
And since we have |
Your list looks good - I'll update this PR. But I'll leave
|
@kzc good catch & thanks! 😉 |
I thought var global_names = makePredicate("Array Boolean console Error Function Math Number RegExp Object String");
AST_SymbolRef.DEFMETHOD("is_declared", function(compressor) {
return !this.definition().undeclared
|| compressor.option("unsafe") && global_names(this.name);
}); Are you sure you don't want the following included in
|
I'm referring to the fact that adding say $ echo 'console' | uglifyjs -c
console;
$ echo 'console' | uglifyjs -c unsafe
$ echo 'console()' | uglifyjs -c unsafe
console(); But I see your point about eval
isFinite
isNaN
parseFloat
parseInt
decodeURI
decodeURIComponent
encodeURI
encodeURIComponent
escape
unescape Further in https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope: clearInterval
clearTimeout
setInterval
setTimeout |
Indeed, I was aware of that. I see - you wanted an additional optimization for the pure call case. I will incorporate your new list. Any consequences to adding |
Removing say |
There's a problem testing the following the test sandbox:
Those symbols do not exist. Do we include them in |
Can we make a separate test case without |
…l_timeout_and_interval_symbols as they do not exist in the test sandbox.
@alexlamsl Suggestions incorporated. PTAL. |
Regarding #2302 (comment) - all these years I thought these functions would throw on bad input...
So they'd make fine pure functions in another PR. |
Your latest changes LGTM 👍 Most global functions in ES5 are very tolerant - so far I've only found these exceptions: Function(1, 2);
RegExp(1, 2);
Array(NaN); |
Date
to known globals for unsafe
compress optionDate
and other known globals to unsafe
compress option
We missed this one in #2236.
I think
Date
has been in javascript from the start.