You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Change the minified version of undefined to 1..u #591
This returns undefined, and it’s two bytes shorter than void 0 (it’s also 5 bytes shorter than undefined). The . operator has a higher priority than the void operator, so it’s safe. A plugin could also replace all instances of void 0 in other code with 1..u.
Doesn't seem like a good idea since everything would break if someone did Object.prototype.u = 4. We could hoist the definition with a var u = void 0; at the top of the file if there are more than a couple references to undefined though.
Reacted by Alberto Leal, Dannii Willis and Jed Fox
@loganfsmyth If you think it’s likely that someone is going to do that, then it could be changed to any other valid character. 1..µ only takes up one more byte in UTF-8.
A little brain-dump for @loganfsmyth's hoisting suggestion...
Remember that undefined is the default value for a variable, so this could be shorter at var u; or let u; (although I guess it would be more robust to use const u = void 0)
Also, there may be opportunities to piggy-back on a list of other variables declared, so could be as little as 2 additional characters. e.g. if a and b are already defined in a var a,b; declaration, then we only add ,u to get var a,b,u;
Or, if you want to use const for robustness, you place the const immediately after an uninitialised variable declaration: var a,b;const u=a;
One other thing I'll add, inserting a new variable is potentially iffy, we'll need to know whether the file being minified is a <script> or not, since that would potentially be creating a new global variable.
This is already brought up in #25 (comment) (last point).
Agree that adding new variables to toplevel isn't safe enough. But this requirement is something that has come up earlier - in minify-builtins, we solve it by inserting this new variable in certain parent scopes (function/block && NOT program) based on number of usages. The same thing can be done for void 0.
I'll close this as duplicate of #25 as it's easy to refer to that issue for new features as it is in a single place. Feel free to discuss here or comment to reopen if necessary.
Activity
loganfsmyth commentedon Jun 20, 2017
Doesn't seem like a good idea since everything would break if someone did
Object.prototype.u = 4. We could hoist the definition with avar u = void 0;at the top of the file if there are more than a couple references toundefinedthough.j-f1 commentedon Jun 20, 2017
@loganfsmyth If you think it’s likely that someone is going to do that, then it could be changed to any other valid character.
1..µonly takes up one more byte in UTF-8.loganfsmyth commentedon Jun 20, 2017
Right, but it still means your exposing your code to the potential for deliberate breakage that wouldn't be present otherwise.
ashsearle commentedon Jul 5, 2017
A little brain-dump for @loganfsmyth's hoisting suggestion...
Remember that
undefinedis the default value for a variable, so this could be shorter atvar u;orlet u;(although I guess it would be more robust to useconst u = void 0)Also, there may be opportunities to piggy-back on a list of other variables declared, so could be as little as 2 additional characters. e.g. if
aandbare already defined in avar a,b;declaration, then we only add,uto getvar a,b,u;Or, if you want to use
constfor robustness, you place theconstimmediately after an uninitialised variable declaration:var a,b;const u=a;loganfsmyth commentedon Jul 5, 2017
Hah, good call about not needing
=void 0;:POne other thing I'll add, inserting a new variable is potentially iffy, we'll need to know whether the file being minified is a
<script>or not, since that would potentially be creating a new global variable.boopathi commentedon Aug 22, 2017
This is already brought up in #25 (comment) (last point).
Agree that adding new variables to toplevel isn't safe enough. But this requirement is something that has come up earlier - in minify-builtins, we solve it by inserting this new variable in certain parent scopes (function/block && NOT program) based on number of usages. The same thing can be done for
void 0.For example,
can be transformed to
instead of hoisting
_void0to program.I'll close this as duplicate of #25 as it's easy to refer to that issue for new features as it is in a single place. Feel free to discuss here or comment to reopen if necessary.