Mihai Bazon [Tue, 25 Sep 2012 09:48:36 +0000 (12:48 +0300)]
minor
Mihai Bazon [Tue, 25 Sep 2012 07:32:14 +0000 (10:32 +0300)]
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)
Mihai Bazon [Tue, 25 Sep 2012 07:31:03 +0000 (10:31 +0300)]
some boolean cleanup
Mihai Bazon [Mon, 24 Sep 2012 14:02:18 +0000 (17:02 +0300)]
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.
Mihai Bazon [Mon, 24 Sep 2012 07:27:49 +0000 (10:27 +0300)]
minor tests fix
Mihai Bazon [Sun, 23 Sep 2012 09:47:34 +0000 (12:47 +0300)]
properly drop mutually-referring declarations that are not otherwise
referenced and have no side effects
Mihai Bazon [Sat, 22 Sep 2012 10:32:32 +0000 (13:32 +0300)]
tree transformer api (WIP)
Mihai Bazon [Fri, 21 Sep 2012 11:38:52 +0000 (14:38 +0300)]
log filename in parse errors / compressor warnings
Mihai Bazon [Fri, 21 Sep 2012 11:19:05 +0000 (14:19 +0300)]
better support for multiple input files:
- use a single AST_Toplevel node for all files
- keep original source filename in the tokens
Mihai Bazon [Fri, 21 Sep 2012 08:23:44 +0000 (11:23 +0300)]
more on detecting side effects
Mihai Bazon [Wed, 19 Sep 2012 09:27:38 +0000 (12:27 +0300)]
drop unused variables
Mihai Bazon [Wed, 19 Sep 2012 07:22:36 +0000 (10:22 +0300)]
support -c with no arguments to disable compression entirely
Mihai Bazon [Tue, 18 Sep 2012 16:26:46 +0000 (19:26 +0300)]
fixed label scope/mangling
Mihai Bazon [Tue, 18 Sep 2012 11:17:23 +0000 (14:17 +0300)]
minor
Mihai Bazon [Tue, 18 Sep 2012 10:21:09 +0000 (13:21 +0300)]
support for directives
Mihai Bazon [Tue, 18 Sep 2012 07:53:46 +0000 (10:53 +0300)]
added AST_NaN (output as 0/0)
Mihai Bazon [Mon, 17 Sep 2012 17:02:14 +0000 (20:02 +0300)]
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.
Mihai Bazon [Mon, 17 Sep 2012 15:49:52 +0000 (18:49 +0300)]
moved `typeof foo == "undefined"` ==> `foo === undefined` under `--unsafe`
because https://github.com/mishoo/UglifyJS2/commit/
43fd45154bac89b89330e13bd1f167e2a927a23c#commitcomment-
1864505
Mihai Bazon [Mon, 17 Sep 2012 12:06:06 +0000 (15:06 +0300)]
fix .undeclared (it's now a function)
Mihai Bazon [Mon, 17 Sep 2012 11:33:36 +0000 (14:33 +0300)]
minor
Mihai Bazon [Mon, 17 Sep 2012 09:53:52 +0000 (12:53 +0300)]
one more test for sequences
Mihai Bazon [Mon, 17 Sep 2012 09:24:21 +0000 (12:24 +0300)]
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.
Mihai Bazon [Mon, 17 Sep 2012 09:03:02 +0000 (12:03 +0300)]
empty block to empty statement: {} ==> ;
Mihai Bazon [Mon, 17 Sep 2012 08:50:35 +0000 (11:50 +0300)]
more smallish optimizations
Mihai Bazon [Mon, 17 Sep 2012 08:16:44 +0000 (11:16 +0300)]
try negating AST_Binary
Mihai Bazon [Sun, 16 Sep 2012 15:05:15 +0000 (18:05 +0300)]
some cleanup
Mihai Bazon [Sun, 16 Sep 2012 13:29:17 +0000 (16:29 +0300)]
more sequencesizing (WIP)
Mihai Bazon [Sun, 16 Sep 2012 12:46:47 +0000 (15:46 +0300)]
drop unused function
Mihai Bazon [Sun, 16 Sep 2012 12:46:20 +0000 (15:46 +0300)]
rewrite handle_if_return
optimizations of if/return/continue seem to be even better now
Mihai Bazon [Sat, 15 Sep 2012 13:06:09 +0000 (16:06 +0300)]
other small optimization:
if (foo) continue;
...body...
==>
if (!foo) { ...body ... }
Only when the parent block is the target loop of the `continue` statement.
Mihai Bazon [Sat, 15 Sep 2012 13:05:01 +0000 (16:05 +0300)]
figure out label targets
Mihai Bazon [Sat, 15 Sep 2012 07:54:59 +0000 (10:54 +0300)]
join_vars:
var XXX;
for (var YYY; ...)
==>
for (var XXX,YYY; ...)
Mihai Bazon [Fri, 14 Sep 2012 16:56:59 +0000 (19:56 +0300)]
compress typeof x == "undefined" to x === undefined, which further gets
shortened to x === void 0 (or x === [][0] in unsafe mode)
Mihai Bazon [Fri, 14 Sep 2012 16:04:18 +0000 (19:04 +0300)]
minor
when unsafe, compress undefined as [][0]
Mihai Bazon [Fri, 14 Sep 2012 13:26:30 +0000 (16:26 +0300)]
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();
}
Mihai Bazon [Fri, 14 Sep 2012 12:36:38 +0000 (15:36 +0300)]
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
Mihai Bazon [Thu, 13 Sep 2012 16:45:16 +0000 (19:45 +0300)]
added -m and -c options
Mihai Bazon [Thu, 13 Sep 2012 12:20:57 +0000 (15:20 +0300)]
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
Mihai Bazon [Wed, 12 Sep 2012 13:29:20 +0000 (16:29 +0300)]
minor
Mihai Bazon [Wed, 12 Sep 2012 13:10:03 +0000 (16:10 +0300)]
more AST_If optimizations
Mihai Bazon [Wed, 12 Sep 2012 10:23:24 +0000 (13:23 +0300)]
side effect fixes and small optimization for gzip
prefer to always use > and >= operators (idea from Closure)
Mihai Bazon [Wed, 12 Sep 2012 10:00:13 +0000 (13:00 +0300)]
fixed run-tests and an issue about reversing the condition in AST_If
Mihai Bazon [Tue, 11 Sep 2012 15:37:08 +0000 (18:37 +0300)]
minor
Mihai Bazon [Tue, 11 Sep 2012 12:42:28 +0000 (15:42 +0300)]
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
Mihai Bazon [Tue, 11 Sep 2012 10:15:55 +0000 (13:15 +0300)]
checkpoint
- discard statements with no side effects (unsafe? could be)
- safer hoist_vars (needs some revamping of scope/mangling)
Mihai Bazon [Mon, 10 Sep 2012 19:40:18 +0000 (22:40 +0300)]
hoist_vars is pretty bad, it seems. cancelled it for now.
Mihai Bazon [Mon, 10 Sep 2012 15:25:52 +0000 (18:25 +0300)]
adaptive base54 digits depending on char frequency (WIP)
Mihai Bazon [Mon, 10 Sep 2012 12:54:17 +0000 (15:54 +0300)]
more progress on the compressor (WIP)
Mihai Bazon [Mon, 10 Sep 2012 12:52:53 +0000 (15:52 +0300)]
fix "file" in the source map
Mihai Bazon [Sat, 8 Sep 2012 14:03:09 +0000 (17:03 +0300)]
minor
Mihai Bazon [Sat, 8 Sep 2012 12:38:58 +0000 (15:38 +0300)]
fix output for division followed by regexp
( v1 report: https://github.com/mishoo/UglifyJS/pull/458 )
Mihai Bazon [Fri, 7 Sep 2012 15:55:13 +0000 (18:55 +0300)]
checkpoint
Mihai Bazon [Fri, 7 Sep 2012 13:02:08 +0000 (16:02 +0300)]
fix bug (forgot arg name)
Mihai Bazon [Fri, 7 Sep 2012 12:18:32 +0000 (15:18 +0300)]
always keep declarations found in unreachable code
a few more tests and some cleanups.
Mihai Bazon [Fri, 7 Sep 2012 08:22:01 +0000 (11:22 +0300)]
fixed tests (need to drop the toplevel block in "expected" if it's a single statement)
Mihai Bazon [Wed, 5 Sep 2012 15:19:30 +0000 (18:19 +0300)]
don't duplicate argument names
Mihai Bazon [Wed, 5 Sep 2012 15:19:24 +0000 (18:19 +0300)]
declared `--stats` as boolean
Mihai Bazon [Wed, 5 Sep 2012 11:31:05 +0000 (14:31 +0300)]
fix for variable names like `toString`
Mihai Bazon [Wed, 5 Sep 2012 10:43:34 +0000 (13:43 +0300)]
support for hoisting declarations
and finally it seems we beat v1 in terms of compression
Mihai Bazon [Wed, 5 Sep 2012 08:31:02 +0000 (11:31 +0300)]
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).
Mihai Bazon [Tue, 4 Sep 2012 12:36:14 +0000 (15:36 +0300)]
checkpoint
Mihai Bazon [Tue, 4 Sep 2012 10:20:28 +0000 (13:20 +0300)]
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).
Mihai Bazon [Tue, 4 Sep 2012 10:17:13 +0000 (13:17 +0300)]
if present, the `else` in an `if` should always be forced statement
Mihai Bazon [Mon, 3 Sep 2012 20:49:57 +0000 (23:49 +0300)]
boolean and if/exit optimizations
Mihai Bazon [Mon, 3 Sep 2012 16:43:46 +0000 (19:43 +0300)]
minor
Mihai Bazon [Mon, 3 Sep 2012 16:38:45 +0000 (19:38 +0300)]
more optimizations for ifs/conditionals
(XXX: should add tests before anything else)
Mihai Bazon [Mon, 3 Sep 2012 12:47:15 +0000 (15:47 +0300)]
resolve constant expressions
Mihai Bazon [Mon, 3 Sep 2012 09:39:02 +0000 (12:39 +0300)]
jumps, try and definitions are statements too
Mihai Bazon [Mon, 3 Sep 2012 09:11:44 +0000 (12:11 +0300)]
an AST_If is too a StatementWithBody
Mihai Bazon [Mon, 3 Sep 2012 09:05:10 +0000 (12:05 +0300)]
a LabeledStatement should be in fact a StatementWithBody
This fixes output for:
if (foo) {
moo: if (bar) {
break moo;
}
} else {
baz();
}
(the labeled statement must be outputted inside brackets)
Mihai Bazon [Mon, 3 Sep 2012 09:03:45 +0000 (12:03 +0300)]
declare boolean options
Mihai Bazon [Mon, 3 Sep 2012 08:05:59 +0000 (11:05 +0300)]
switch branches must be declared `required` so that the compressor doesn't
replace nodes with a single statement.
looks stable for now, though mess begins to sink in. need to review the AST
hierarchy.
Mihai Bazon [Mon, 3 Sep 2012 07:26:23 +0000 (10:26 +0300)]
Reverting "minor perf. improvements"
Revert "minor perf. improvements"
This reverts commit
24bfd55a22afd791d4a97694641831cfbd27fb14.
broke the parser somehow; too early to optimize, let's get the other stuff running.
Mihai Bazon [Mon, 3 Sep 2012 07:14:15 +0000 (10:14 +0300)]
add -b
Mihai Bazon [Sun, 2 Sep 2012 11:32:00 +0000 (14:32 +0300)]
add source mappings for more node types; started CLI utility
Mihai Bazon [Sun, 2 Sep 2012 08:11:39 +0000 (11:11 +0300)]
minor perf. improvements
Mihai Bazon [Wed, 29 Aug 2012 16:39:19 +0000 (19:39 +0300)]
started support for generating source maps (WIP)
plugged in @fitzgen's source-map library
Mihai Bazon [Wed, 29 Aug 2012 16:26:48 +0000 (19:26 +0300)]
don't mangle names of setters/getters
Mihai Bazon [Wed, 29 Aug 2012 08:18:05 +0000 (11:18 +0300)]
update with link to discussion about Esprima vs. UglifyJS speed
Mihai Bazon [Tue, 28 Aug 2012 12:39:53 +0000 (15:39 +0300)]
docstring for AST_StatementWithBody
Mihai Bazon [Tue, 28 Aug 2012 12:38:35 +0000 (15:38 +0300)]
fix output for arrays containing undefined values
[1,,2,] ==> [1,,2] instead of [1,undefined,2]
Mihai Bazon [Tue, 28 Aug 2012 12:29:58 +0000 (15:29 +0300)]
fix code generator for this case:
if (foo) {
with (bar)
if (baz)
x();
} else y();
(the compressor removes the brackets since the consequent consists of a
single statement, but the codegen must include the brackets because
otherwise the `else` would refer to the inner `if`)
Mihai Bazon [Mon, 27 Aug 2012 09:29:53 +0000 (12:29 +0300)]
added README
Mihai Bazon [Mon, 27 Aug 2012 08:48:07 +0000 (11:48 +0300)]
minor
Mihai Bazon [Mon, 27 Aug 2012 08:01:27 +0000 (11:01 +0300)]
update (c) years
Mihai Bazon [Mon, 27 Aug 2012 08:00:26 +0000 (11:00 +0300)]
minor
Mihai Bazon [Mon, 27 Aug 2012 08:00:22 +0000 (11:00 +0300)]
fix compressing `a,b; return c;` into `return a,b,c;`
Mihai Bazon [Mon, 27 Aug 2012 07:59:33 +0000 (10:59 +0300)]
added print_to_string helper method
Mihai Bazon [Thu, 23 Aug 2012 07:39:33 +0000 (10:39 +0300)]
fix current_col and force a newline every 32K (support options.max_line_len)
Mihai Bazon [Wed, 22 Aug 2012 18:28:59 +0000 (21:28 +0300)]
added license
Mihai Bazon [Wed, 22 Aug 2012 12:21:58 +0000 (15:21 +0300)]
wrote more of the compressor and added some tests
Mihai Bazon [Wed, 22 Aug 2012 10:20:05 +0000 (13:20 +0300)]
fix output for certain edge cases
the statements if, for, do, while and with might have an AST_EmptyStatement
as body; if that's the case, we need to make sure that the semicolon gets in
the output.
Mihai Bazon [Tue, 21 Aug 2012 17:06:57 +0000 (20:06 +0300)]
declare some properties in the node constructor so that they're copied in clone
Mihai Bazon [Tue, 21 Aug 2012 13:27:57 +0000 (16:27 +0300)]
hint that brackets may be required in AST_BlockStatement
Mihai Bazon [Tue, 21 Aug 2012 12:45:05 +0000 (15:45 +0300)]
cleaned up some mess and started the actual compressor
Mihai Bazon [Tue, 21 Aug 2012 09:55:56 +0000 (12:55 +0300)]
some reorganization
(moved pretty much everything that relates to scope in scope.js, added a
module for NodeJS that can be used with require() and exports everything.)
Mihai Bazon [Tue, 21 Aug 2012 09:37:05 +0000 (12:37 +0300)]
handle labels properly
(they can't be handled the same way as variables in a scope)
Mihai Bazon [Tue, 21 Aug 2012 08:53:19 +0000 (11:53 +0300)]
warn about unreferenced symbols
Mihai Bazon [Tue, 21 Aug 2012 08:38:49 +0000 (11:38 +0300)]
more fixes:
- added walker for AST_ObjectProperty
- handle redefinitions properly (only mangle one symbol, make them all point
to a single definition)
DynarchLIB seems to run fine after mangling + compressed output.
Mihai Bazon [Mon, 20 Aug 2012 14:19:30 +0000 (17:19 +0300)]
added mangler and other stuff