Commit Graph

128 Commits

Author SHA1 Message Date
Mihai Bazon
9e5dd81f1e a shy attempt to obey width in the beautifier; added bracketize option to always print brackets around if/do/while/for statements; export more options via the CLI 2012-10-02 11:22:38 +03:00
Mihai Bazon
896444482a minor 2012-09-28 11:12:47 +03:00
Mihai Bazon
05e15b1c0c fix mangling
(bug in our code prevented the mangler from using a name that was in use
prior to mangling but not after it)
2012-09-27 00:01:16 +03:00
Mihai Bazon
13278c6649 removed the "squeeze" method (it's now effectively "transform") 2012-09-26 19:52:32 +03:00
Mihai Bazon
15d58f5917 some speedup and more savings from unused vars that have side effects in initialization 2012-09-26 19:05:49 +03:00
Mihai Bazon
78be8f5296 compressor successfully moved to TreeTransformer 2012-09-26 14:27:01 +03:00
Mihai Bazon
a24e7ee976 checkpoint (refactoring, WIP) 2012-09-26 12:16:16 +03:00
Mihai Bazon
e979d01f04 minor 2012-09-26 11:24:04 +03:00
Mihai Bazon
242dd10131 more cleanups 2012-09-25 20:39:15 +03:00
Mihai Bazon
9321d418bc moving code around (refactoring, WIP) 2012-09-25 15:59:27 +03:00
Mihai Bazon
10c7f52074 discard all \uFEFF characters (https://github.com/mishoo/UglifyJS/issues/462) 2012-09-25 15:30:59 +03:00
Mihai Bazon
4201577dd7 started some refactoring (WIP) -- moving squeezer to TreeTransformer 2012-09-25 15:15:47 +03:00
Mihai Bazon
e836e2ae5f minor 2012-09-25 12:48:36 +03:00
Mihai Bazon
ea6d1ea701 it's not safe to assume that property access is side-effect-free
(getters/setters + various browser bugs will trigger side effects; also, an
exception is thrown when the expression is undefined)
2012-09-25 10:32:14 +03:00
Mihai Bazon
368ac8f93c some boolean cleanup 2012-09-25 10:31:03 +03:00
Mihai Bazon
42038fd67f Support input source map
This is useful while compressing generated code; for example compressing JS
compiled by CoffeeScript (assuming you got a source map):

    uglifyjs2 --in-source-map generated.js.map \
              --source-map uglified.js.map \
              -o uglified.js

The above assumes you have a "generated.js.map" file which is the source
mapping between your CoffeeScript and the generated.js (compiled output from
CoffeeScript).  The name of the input file is not present in this example;
it will be fetched from the source map (but it can be passed manually too).

The output will be in "uglified.js" and the output map "uglified.js.map"
will actually map to the original CoffeeScript code, rather than to
generated.js.
2012-09-24 17:02:18 +03:00
Mihai Bazon
4f97da9660 minor tests fix 2012-09-24 10:27:49 +03:00
Mihai Bazon
a83b28503f properly drop mutually-referring declarations that are not otherwise
referenced and have no side effects
2012-09-23 12:47:34 +03:00
Mihai Bazon
76d88b59dc tree transformer api (WIP) 2012-09-22 19:41:09 +03:00
Mihai Bazon
ec7f895b54 log filename in parse errors / compressor warnings 2012-09-21 14:44:25 +03:00
Mihai Bazon
5491e1d7b1 better support for multiple input files:
- use a single AST_Toplevel node for all files
- keep original source filename in the tokens
2012-09-21 14:19:05 +03:00
Mihai Bazon
c4f8c2103f more on detecting side effects 2012-09-21 11:23:44 +03:00
Mihai Bazon
e8da72d304 drop unused variables 2012-09-19 12:27:38 +03:00
Mihai Bazon
d53e1a9931 support -c with no arguments to disable compression entirely 2012-09-19 10:22:36 +03:00
Mihai Bazon
a4d2340c73 fixed label scope/mangling 2012-09-18 19:26:46 +03:00
Mihai Bazon
669874d46b minor 2012-09-18 14:17:23 +03:00
Mihai Bazon
3da0ac4897 support for directives 2012-09-18 13:21:09 +03:00
Mihai Bazon
21968285e8 added AST_NaN (output as 0/0) 2012-09-18 10:53:46 +03:00
Mihai Bazon
d91613b4a8 only do the typeof x == "undefined" optimization if x is a symbol reference and it's declared in scope, or x is not a symbol reference. 2012-09-17 20:02:57 +03:00
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