alexlamsl
f0ff6189be
clean up negate_iife
...
- remove extra tree scanning phase for `negate_iife`
- `negate_iife` now only deals with the narrowest form, i.e. IIFE sitting directly under `AST_SimpleStatement`
- `booleans`, `conditionals` etc. will now take care the rest via more accurate accounting
- `a(); void b();` => `a(); b();`
fixes #1288
closes #1451
2017-02-21 13:29:58 +08:00
alexlamsl
6b3c49e458
improve string concatenation
...
shuffle associative operations to minimise parentheses and aid other uglification efforts
closes #1454
2017-02-21 13:29:57 +08:00
alexlamsl
f584ca8d07
-c sequences=N suboptimal at N expression cutoff
...
N = 2:
a;
b;
c;
d;
was:
a, b;
c;
d;
now:
a, b;
c, d;
fixes #1455
closes #1457
2017-02-21 13:29:57 +08:00
alexlamsl
ae4db00991
tweak do-while loops
...
- `do{...}while(false)` => `{...}`
- clean up `AST_While` logic
closes #1452
2017-02-21 13:29:57 +08:00
alexlamsl
100307ab31
fixes & improvements to [].join()
...
fixes
- [a].join() => "" + a
- ["a", , "b"].join() => "a,,b"
- ["a", null, "b"].join() => "a,,b"
- ["a", undefined, "b"].join() => "a,,b"
improvements
- ["a", "b"].join(null) => "anullb"
- ["a", "b"].join(undefined) => "a,b"
- [a + "b", c].join("") => a + "b" + c
closes #1453
2017-02-21 13:29:57 +08:00
alexlamsl
148047fbbf
drop unused: toplevel, assign-only
...
- assign statement does not count towards variable usage by default
- only works with assignments on the same scope level as declaration
- can be disabled with `unused` set to "keep_assign"
- `toplevel` to drop unused top-level variables and/or functions
- `top_retain` to whitelist top-level exceptions
closes #1450
2017-02-21 13:29:57 +08:00
kzc
d11dca3cf9
fix stray else in compress with conditionals=false
...
closes #1449
2017-02-21 13:29:57 +08:00
alexlamsl
e5badb9541
enable typeof "undefined" for general use
...
move out of unsafe, guard corner case with screw_id8 instead
closes #1446
2017-02-18 19:01:42 +08:00
alexlamsl
11676f9d72
fix crash in unsafe replacement of undefined
...
remove extraneous call to AST_SymbolRef.reference()
closes #1443
2017-02-18 18:58:23 +08:00
Anthony Van de Gejuchte
dd31d12a91
Improve optimizing function() { if(c){return foo} bar();}
...
closes #1437
2017-02-18 18:56:18 +08:00
Alex Lam S.L
0610c020b1
optimise binary operands with evaluate() ( #1427 )
...
- remove call to evaluate() in is_constant() and let nested optimize() does its job instead
- reject RegExp in is_constant() and remove special case logic under collapse_vars
- operands to conditionals optimisation are now always evaluate()-ed
- throw error in constant_value() instead of returning undefined to catch possible bugs, similar to make_node_from_constant()
- optimise binary boolean operators under `evaluate` instead of `conditionals`
2017-01-26 12:16:50 +01:00
Alex Lam S.L
0d7d4918eb
augment evaluate to extract within objects ( #1425 )
...
- gated by `unsafe`
- replaces previous optimisation specific to String.length
- "123"[0] => 1
- [1, 2, 3][0] => 1
- [1, 2, 3].length => 3
- does not apply to objects with overridden prototype functions
2017-01-26 12:14:18 +01:00
alexlamsl
48284844a4
add missing LHS cases which global_defs should avoid
2017-01-19 21:06:28 +01:00
Anthony Van de Gejuchte
79b98a9fe8
Do not overwrite options.comments + cleanup
2016-11-29 20:24:08 +01:00
kzc
fc9804b909
Fix (typeof side_effect()) in boolean context
...
Fixes #1289 with suggestion by @rvanvelzen
2016-10-06 13:50:11 +02:00
alexlamsl
4761d07e0b
Optimize unmodified variables
2016-10-01 11:36:11 +02:00
kzc
25fc02743a
Account for side effects in string + expr optimization
2016-09-01 09:24:56 -04:00
kzc
0bd8053524
implement optimization: (x = 2 * x) ---> (x *= 2)
2016-08-30 08:43:02 -04:00
Richard van Velzen
8430123e9d
Fix negate_iife transform to return a correct tree for nested IIFEs
...
Fix for #1256 , partially reverts d854523783
2016-08-17 11:55:59 +02:00
Anthony Van de Gejuchte
7eb52d2837
Keep const in own scope while compressing
...
- Fixes #1205
- Fix provided by @kzc
2016-07-15 13:20:52 +02:00
kzc
b40d5de69c
Change the default sequences limit to 200 to speed up compress.
...
Has little or no impact on minification size in the majority of
cases but can speed up rollup builds significantly.
This sequences change also has the beneficial side effect of avoiding
"stack size exceeded" errors on very large input files.
The user is free to alter the sequences limit if they are so inclined.
The previous sequences limit was 2000. 20 is often sufficient.
2016-07-01 09:41:31 +02:00
kzc
b7ef7840f3
Allow sequences maximum length to be user configurable.
2016-07-01 09:41:31 +02:00
kzc
02c638209e
Enable --screw-ie8 by default.
...
catch identifier is mangled correctly for ES5 standards-compliant JS engines by default.
Unconditionally use the ie8 if/do-while workaround whether or not --screw-ie8 is enabled.
To support non-standard ie8 javascript use: uglifyjs --support-ie8
2016-06-30 21:49:48 +02:00
kzc
335b72df03
Fix spidermonkey AST (ESTree) export and import, Array holes
...
Fixes : #1156 #1161
Also add test to exercise Uglify after spidermonkey export/import of itself.
2016-06-30 21:44:12 +02:00
kzc
ace8aaa0f4
Fix conditional expressions of form (x ? -1 : -1)
...
Fixes #1154 , #1153
2016-06-21 14:52:13 -04:00
kzc
0c003c92a8
Don't replace undefined, NaN and Infinity within with scope
2016-06-21 10:53:29 +02:00
Anthony Van de Gejuchte
d7971ba0e4
Fix test262 failures related to <, <=, in and instanceof
...
Fixed-by: @kzc
2016-06-15 23:11:08 +02:00
Anthony Van de Gejuchte
ea31da2455
Don't drop unused if scope uses with statement
...
Fix provided by @kzc
2016-06-12 14:30:28 +02:00
kzc
09d5707a8a
collapse_vars: Do not consider RegExp literals to be constants
...
Fixes #1100
2016-05-27 00:03:51 -04:00
kzc
1e390269d4
Optimize if_return for single if/return cases.
...
Fixes #1089
2016-05-24 17:54:08 +02:00
Richard van Velzen
bc49dfd27a
Completely allow evaluating -0
2016-05-24 17:50:29 +02:00
Richard van Velzen
27eedbc302
Never produce -0 when evaluating expressions (like -"")
...
Fix for #1085 . The major case was already there, but more expressions can result in -0.
2016-05-17 22:34:38 +02:00
kzc
5f464b41e2
Simplify iife new fix
...
as suggested by @rvanvelzen.
Added a test for IIFEs in nested contexts.
2016-05-15 19:12:17 -04:00
kzc
bcc1318d4b
Do not apply negate_iife optimization to new expression
2016-05-09 03:19:28 -04:00
Richard van Velzen
4fe630431c
Hoist functions when reversing if (x) return; ... vs. if (!x) ...
...
Fixes #1052
2016-04-23 23:48:33 +02:00
kzc
c55dd5ed74
Add passes compress option. Fix duplicate compress warnings.
2016-04-19 20:05:33 +02:00
Richard van Velzen
4b4528ee05
Prevent endless recursion when evaluating self-referencing consts
...
Fix #1041
2016-04-13 15:03:31 +02:00
Mihai Bazon
b5a7a231f7
Actually limit sequence length.
...
Fix #1038
2016-04-12 14:17:24 +03:00
kzc
3907a5e3b2
Fix warnings for referenced non-hoisted functions.
...
Fixes #1034
Also added `expect_warnings` functionality to test framework.
2016-04-11 18:15:20 +02:00
Mihai Bazon
9317237372
Avoid using inherited hasOwnProperty
...
Fix #1031
2016-04-07 13:16:22 +03:00
kzc
98434258d0
Optimize ternaries with boolean consequent or alternative.
...
Fixes #511
2016-04-02 17:22:12 +02:00
kzc
45ddb9caeb
Speedup unused compress option for already minified code
...
Fixes : #321 #917 #1022
2016-03-28 17:58:50 -04:00
kzc
11b0efdf84
boolean_expression ? true : false --> boolean_expression
2016-02-22 17:59:36 +01:00
kzc
5486b68850
Take operator || precendence into account for AST_If optimization.
...
Fixes #979 .
2016-02-21 12:05:02 -05:00
alexlamsl
6547437725
preserve ThisBinding for side_effects
2016-02-17 19:34:01 +01:00
Richard van Velzen
9662228f6a
Don't compress (0, eval)() to eval()
2016-02-16 19:00:48 +01:00
alexlamsl
31a9b05c96
Preserve ThisBinding in conditionals & collapse_vars
...
Fixes #973
2016-02-16 18:47:49 +01:00
kzc
7c3fee9e31
collapse_vars: avoid replacement across AST_Case nodes to be on safe side even though no issues seen.
2016-01-29 10:35:07 -05:00
kzc
929de2b0de
collapse_vars: fix if/else and ternary operator side effects
2016-01-28 12:17:06 -05:00
kzc
af2472d85e
collapse_vars: fix bug in repeated var defs of same name
2016-01-28 16:48:50 +01:00