3349 Commits

Author SHA1 Message Date
Mihai Bazon
ee669ba878 moved typeof foo == "undefined" ==> foo === undefined under --unsafe
because 43fd45154b (commitcomment-1864505)
2012-09-17 18:49:52 +03:00
Mihai Bazon
e370e3b5a4 fix .undeclared (it's now a function) 2012-09-17 15:06:06 +03:00
Mihai Bazon
6ad414ef28 minor 2012-09-17 14:33:36 +03:00
Mihai Bazon
45a3970ca3 one more test for sequences 2012-09-17 12:53:52 +03:00
Mihai Bazon
92e22c460d possible optimization for AST_Undefined
if undefined is defined, ;-), we replace AST_Undefined nodes to a reference
to the "undefined" variable; in turn the mangler will compress it to a
single letter; this helps at least on jQuery.
2012-09-17 12:27:32 +03:00
Mihai Bazon
14481de0e9 empty block to empty statement: {} ==> ; 2012-09-17 12:03:02 +03:00
Mihai Bazon
07f1d56f69 more smallish optimizations 2012-09-17 11:50:35 +03:00
Mihai Bazon
5e60a60b3b try negating AST_Binary 2012-09-17 11:16:44 +03:00
Mihai Bazon
5d781ec6f8 some cleanup 2012-09-16 18:10:54 +03:00
Mihai Bazon
0f418d654e more sequencesizing (WIP) 2012-09-16 16:29:17 +03:00
Mihai Bazon
21c34a1792 drop unused function 2012-09-16 15:46:47 +03:00
Mihai Bazon
7b6a402916 rewrite handle_if_return
optimizations of if/return/continue seem to be even better now
2012-09-16 15:46:20 +03:00
Mihai Bazon
397bf56d25 other small optimization:
if (foo) continue;
...body...

==>

if (!foo) { ...body ... }

Only when the parent block is the target loop of the `continue` statement.
2012-09-15 16:10:35 +03:00
Mihai Bazon
4e0262bdfb figure out label targets 2012-09-15 16:05:17 +03:00
Mihai Bazon
86c14d0988 join_vars:
var XXX;
for (var YYY; ...)

==>

for (var XXX,YYY; ...)
2012-09-15 10:54:59 +03:00
Mihai Bazon
43fd45154b compress typeof x == "undefined" to x === undefined, which further gets
shortened to x === void 0 (or x === [][0] in unsafe mode)
2012-09-14 19:56:59 +03:00
Mihai Bazon
50d1670e42 minor
when unsafe, compress undefined as [][0]
2012-09-14 19:04:18 +03:00
Mihai Bazon
5e83e7ec17 adding an imaginary "return undefined" can sometimes help
function f() {
  if (foo) return x();
  if (!bar) return y();
}

==>

function f() {
  return foo ? x() : bar ? void 0 : y();
}
2012-09-14 16:26:30 +03:00
Mihai Bazon
924aa58060 more optimizations that v1 does and some cleanups
- a = a + x ==> a+=x
- joining consecutive var statements (hoisting is not always desirable)
- x == false ==> x == 0, x != true ==> x != 1
- x, x ==> x; x = exp(), x ==> x = exp()
- discarding useless break-s
2012-09-14 15:36:38 +03:00
Mihai Bazon
93b973c99d added -m and -c options 2012-09-13 19:45:16 +03:00
Mihai Bazon
d72c1d1293 few more optimizations:
- do multiple passes in tighten_body if it was changed
- transform if (foo) return x; return y; ==> return foo?x:y
- don't optimize !0 as true (use best_of after evaluation of constant expr)

With hoist_vars off we now beat UglifyJS v1 on jQuery-1.8.1
2012-09-13 15:20:57 +03:00
Mihai Bazon
f5027ec1fc minor 2012-09-12 16:29:20 +03:00
Mihai Bazon
a132841fb9 more AST_If optimizations 2012-09-12 16:10:03 +03:00
Mihai Bazon
2b1e4628e0 side effect fixes and small optimization for gzip
prefer to always use > and >= operators (idea from Closure)
2012-09-12 13:41:46 +03:00
Mihai Bazon
2b4093ba83 fixed run-tests and an issue about reversing the condition in AST_If 2012-09-12 13:00:13 +03:00
Mihai Bazon
9a629abe00 minor 2012-09-11 18:37:08 +03:00
Mihai Bazon
8e82d8d94c fixed some mess with symbols/scope
- all symbols now have a `thedef` property which is a SymbolDef object,
  instead of the `uniq` that we had before (pointing to the first occurrence
  of the name as declaration).

- for undeclared symbols we still create a SymbolDef object in the toplevel
  scope but mark it "undeclared"

- we can now call figure_out_scope after squeezing, which is useful in order
  not to mangle names that were dropped by the squeezer
2012-09-11 15:42:28 +03:00
Mihai Bazon
da407d46c6 checkpoint
- discard statements with no side effects (unsafe? could be)
- safer hoist_vars (needs some revamping of scope/mangling)
2012-09-11 13:15:55 +03:00
Mihai Bazon
1579c0fb97 hoist_vars is pretty bad, it seems. cancelled it for now. 2012-09-10 22:40:18 +03:00
Mihai Bazon
6b9aeb5325 adaptive base54 digits depending on char frequency (WIP) 2012-09-10 22:29:18 +03:00
Mihai Bazon
a41e6cfabb more progress on the compressor (WIP) 2012-09-10 16:37:05 +03:00
Mihai Bazon
16b12c6287 fix "file" in the source map 2012-09-10 15:52:53 +03:00
Mihai Bazon
1c8ba35844 minor 2012-09-08 22:51:59 +03:00
Mihai Bazon
5a8e6ce735 fix output for division followed by regexp
( v1 report: https://github.com/mishoo/UglifyJS/pull/458 )
2012-09-08 15:38:58 +03:00
Mihai Bazon
43c75c9248 checkpoint 2012-09-07 18:55:13 +03:00
Mihai Bazon
048d6906ae fix bug (forgot arg name) 2012-09-07 16:02:08 +03:00
Mihai Bazon
919b2733ab always keep declarations found in unreachable code
a few more tests and some cleanups.
2012-09-07 15:18:32 +03:00
Mihai Bazon
b77574ea1c fixed tests (need to drop the toplevel block in "expected" if it's a single statement) 2012-09-07 11:22:01 +03:00
Mihai Bazon
9bb1a84d6b don't duplicate argument names 2012-09-05 18:19:30 +03:00
Mihai Bazon
0afafe64fc declared --stats as boolean 2012-09-05 18:19:24 +03:00
Mihai Bazon
c7b484b64f fix for variable names like toString 2012-09-05 14:31:05 +03:00
Mihai Bazon
0503513dcc support for hoisting declarations
and finally it seems we beat v1 in terms of compression
2012-09-05 13:43:34 +03:00
Mihai Bazon
8633b0073f cleaned up usage of AST_BlockStatement
The following nodes were instances of AST_BlockStatement: AST_Scope,
AST_SwitchBlock, AST_SwitchBranch.  Also, AST_Try, AST_Catch, AST_Finally
were having a body instanceof AST_BlockStatement.

Overloading the meaning of AST_BlockStatement this way turned out to be a
mess; we now have an AST_Block class that is the base class for things
having a block of statements (might or might not be bracketed).  The
`this.body` of AST_Scope, AST_Try, AST_Catch, AST_Finally is now an array of
statements (as they inherit from AST_Block).

Avoiding calling superclass's _walk function in walkers (turns out we walked
a node multiple times).
2012-09-05 11:39:43 +03:00
Mihai Bazon
1b5183dd5e checkpoint 2012-09-04 15:36:14 +03:00
Mihai Bazon
376667a818 more fiddling with boolean expressions, etc.
optimize away while(false), and transform while(true) ==> for(;;).

UNSAFE:

some expressions are optimized away when we're in boolean context and can
determine that the value will always be true or false.  For example:

    x() || true ==> always `true` in boolean context
    x() && false ==> always `false` in boolean context

It's not technically correct to drop these expressions since we drop the
function call too (that might have side effects); on the other hand, I can't
see any legitimate use for such expressions and they might simply indicate a
bug (we do warn about it).
2012-09-04 13:20:28 +03:00
Mihai Bazon
3459c40cf9 if present, the else in an if should always be forced statement 2012-09-04 13:17:13 +03:00
Mihai Bazon
86cfb5be86 boolean and if/exit optimizations 2012-09-03 23:49:57 +03:00
Mihai Bazon
e5f1cec6aa minor 2012-09-03 23:25:30 +03:00
Mihai Bazon
37eecc16a4 more optimizations for ifs/conditionals
(XXX: should add tests before anything else)
2012-09-03 19:38:45 +03:00
Mihai Bazon
f03138daa8 resolve constant expressions 2012-09-03 15:47:15 +03:00