Richard van Velzen
e98119496a
Add support for somewhat preserving line numbers.
...
Usage: uglifyjs2 -b "beautify=0,preserve_line=1" /path/to/js
ref #46
2012-11-14 15:30:18 +02:00
Mihai Bazon
bdfcbf496b
better solution for the last test in constant switch folding
2012-11-14 12:21:43 +02:00
Mihai Bazon
dba8da4800
optimize constant switch blocks
...
ref. mishoo/UglifyJS#441
2012-11-14 12:06:07 +02:00
Mihai Bazon
60c0f40250
Merge branch 'optimize_concat' of https://github.com/rvanvelzen/UglifyJS2 into rvanvelzen-optimize_concat
2012-11-13 14:38:55 +02:00
Mihai Bazon
e02771a5f2
don't change order in binary expressions if both operands have side effects
2012-11-13 14:32:07 +02:00
Richard van Velzen
f96f796f71
Add simple optimization for empty-string concats.
...
ref. #43
2012-11-12 15:41:03 +01:00
Mihai Bazon
53355bdb24
fix invalid AST produced by dropping unused variable
...
close #44
2012-11-12 13:23:57 +02:00
Dan Wolff
b49230ab8d
convert x.toString() to ""+x instead of x+""
...
In some places this can save one byte in whitespace, e.g. after return.
Example:
function f(arg) {
// return""+arg - no space between return and ""
return arg.toString();
}
2012-11-11 15:53:34 +02:00
Mihai Bazon
1e5e13ed81
AST_LabelRef no longer inherits from AST_SymbolRef
2012-11-08 15:39:14 +02:00
Mihai Bazon
e312c5c2a7
fix API breakage
...
close #36 , #38
2012-11-08 12:31:28 +02:00
Mihai Bazon
1a5fd3e052
optimization for if/break as first statement in a loop body
...
for(...; x; ...) if (y) break; → for(...; x&&!y; ...);
similarly for `while` and some combinations (i.e. the `break` appears in the
`else` clause, etc.)
2012-11-08 11:43:14 +02:00
Mihai Bazon
46be3f2bf1
fix another small regression
...
we do need parens here: `new (foo.bar().baz)`, but not here: `new foo.bar.baz`
2012-11-07 13:31:43 +02:00
Mihai Bazon
80da21dab4
fix regression from 5346fb94 (shouldn't parenthesize i++ in x[i++])
2012-11-07 13:02:51 +02:00
Mihai Bazon
5276a4a873
add AST_Accessor and AST_SymbolAccessor node types
...
AST_Accessor will represent the function for a setter or getter. Since they
are not mangleable, and they should not introduce a name in scope, we have a
new node for their name (AST_SymbolAccessor) which doesn't inherit from
AST_SymbolDeclaration.
fix #37
2012-11-07 12:43:27 +02:00
Mihai Bazon
a1ae0c8609
parenthesize property access when it's the expression in New
...
refs #35
2012-11-07 12:26:33 +02:00
Mihai Bazon
a90c1aeafe
further fix for parens around New (refs #35 )
2012-11-07 11:49:06 +02:00
Mihai Bazon
ff388a8d2d
parenthesize a Call expression when its parent is New
...
fix #35
2012-11-07 11:36:15 +02:00
Mihai Bazon
5346fb94bb
add proper parens around unary expressions
...
fix #34
2012-11-07 11:23:50 +02:00
Mihai Bazon
a4f6d46118
add option to mangle names even if eval/with is in use
...
(for more fair comparison to Closure compiler)
2012-11-06 18:19:51 +02:00
Mihai Bazon
ffccb233e5
convert while into for
2012-11-05 16:01:20 +02:00
Mihai Bazon
fba0c1aafe
minor
2012-11-05 16:01:09 +02:00
Mihai Bazon
774f2ded94
minor optimization
...
for `==` or `!=` against a constant, prefer to display the constant first.
should help a bit after gzip, i.e.:
typeof foo=="undefined"
^^^^^^ ^^^^^^^^^^^^^
vs:
"undefined"==typeof foo
^^^^^^^^^^^^^^^^^^^ (longer sequence that could repeat)
idea stolen from closure.
2012-11-05 13:13:06 +02:00
Mihai Bazon
85af942d64
print final semicolon
...
close #28
2012-11-05 13:09:39 +02:00
Mihai Bazon
8413787efc
use a Dictionary object instead of plain object for hashes
...
to mitigate the `__proto__` issue
related to #30
2012-11-02 10:58:45 +02:00
Mihai Bazon
cf409800be
it's safe to negate expression in !EXP only in boolean context
...
#kendo
2012-11-01 15:49:05 +02:00
Mihai Bazon
18270dd9f3
added unsafe_comps for negating <= with >
...
since it has the potential to break code, let's keep it disabled by default
2012-11-01 15:14:56 +02:00
Mihai Bazon
d4c25c571b
fix compressing UnaryPrefix
...
only try negating the expression if the operator is `!`
#kendo
2012-11-01 13:35:08 +02:00
Mihai Bazon
abe0ebbf02
don't move expressions containing the binary in operator into the for initializer
...
(opera can't parse it)
close #25
2012-10-30 14:50:47 +02:00
Mihai Bazon
cb3cafa14d
cripple scope to make IE happy :-(
...
close #24
2012-10-25 18:52:35 +03:00
Mihai Bazon
70fd2b1f33
fix for if (...) return; else return ...;
...
(it was assumed that the first `return` always contains a value)
close #22
2012-10-24 09:33:32 +03:00
Mihai Bazon
30faaf13ed
more sequence optimizations (lift some sequences above binary/unary expressions so that we can avoid parens)
2012-10-22 11:58:06 +03:00
Mihai Bazon
fc8314e810
minor fix for dropping unused definitions.
...
function f(x, y) {
var g = function() { return h() };
var h = function() { return g() };
return x + y;
}
now compresses to `function f(x, y) { return x + y }`
2012-10-19 12:57:29 +03:00
Mihai Bazon
afb7faa6fa
more optimizations for some break/continue cases
2012-10-18 15:14:57 +03:00
Mihai Bazon
253bd8559b
more small optimizations
...
(unlikely to help for hand-written code)
2012-10-17 21:57:08 +03:00
Mihai Bazon
6a099fba66
define aborts on AST_If: true if both branches abort
2012-10-17 16:17:14 +03:00
Mihai Bazon
a21f3c6cdd
employ a better parser for command-line arguments
...
to support passing commas in strings in for example:
uglifyjs2 -cd TEST="'a,b'" <<EOF
console.log(TEST);
EOF
→ console.log("a,b")
close #14
2012-10-17 15:56:45 +03:00
Mihai Bazon
8f66458598
the sort option is broken anyway, removed it
...
we need to mangle names from outermost to innermost scope; mangling names
from inner scopes before we got to the outer scope won't work correctly,
therefore sorting doesn't make sense.
2012-10-17 15:24:47 +03:00
Mihai Bazon
6472f9410e
add semicolons option in the code generator (default: true)
...
pass `false` to separate statements with newlines instead of semicolons
2012-10-17 14:52:08 +03:00
Mihai Bazon
8957b3a694
fix small glitches in source map generation
2012-10-16 15:54:12 +03:00
Mihai Bazon
fcc0229087
drop unused function arguments
...
also add test for "drop_unused" (the last one fails for now)
2012-10-13 15:04:44 +03:00
Mihai Bazon
b071c9d079
add parens to AST_Seq whose parent is AST_Unary
2012-10-13 14:32:08 +03:00
Mihai Bazon
851b48e4a3
fix compressing benchmark.js (it tried to evaluate a statement)
...
the following code in benchmark.js triggered the issue:
support.decompilation = Function(
'return (' + (function(x) { return { 'x': '' + (1 + x) + '', 'y': 0 }; }) + ')'
)()(0).x === '1';
technically that could be resolved into a constant expression, but seems
it's being used here for browser bugs detection :-\
2012-10-13 12:57:10 +03:00
Mihai Bazon
708abb1ab1
minor
2012-10-13 12:42:01 +03:00
Mihai Bazon
370d3e0917
fix regression from fb5c01c073
...
is_digit takes a char code now, not a string
2012-10-13 12:24:27 +03:00
Mihai Bazon
b51fe0dcc3
fix end tokens in spidermonkey ast import
2012-10-13 11:37:58 +03:00
Mihai Bazon
8149be551e
minor
2012-10-12 14:55:54 +03:00
Mihai Bazon
1b6f8d463f
remove the $self hack
...
operations are destructive anyway, so there's no point to clone the nodes in
the transformer. speed++
2012-10-12 11:07:35 +03:00
Mihai Bazon
72cb5328ee
fix in_boolean_context() (two tests were broken)
2012-10-12 10:49:41 +03:00
Mihai Bazon
fc39553714
use AST_Lambda for object setters/getters
...
so that the optimization that drops the name if unused doesn't apply.
close #12
2012-10-12 10:11:01 +03:00
Mihai Bazon
d9d67317b1
fix pos in syntax error exception
2012-10-11 15:25:38 +03:00