Alex Lam S.L
d8106b6c63
fix label-related bugs ( #1835 )
...
- deep cloning of `AST_LabeledStatement`
- `L:do{...}while(false)`
- empty statement with label within block
extend `test/ufuzz.js`
- generate labels for blocks & loops
- generate for-in statements
- skip suspicious option search if `minify()` errs
fixes #1833
2017-05-07 00:16:30 +08:00
Alex Lam S.L
7305ba0296
fix unsafe on evaluate of reduce_vars ( #1870 )
...
Determine if variables with non-constant values can escape and be modified.
fixes #1865
2017-05-06 23:40:19 +08:00
Alex Lam S.L
2c21dc5e8e
fix unused on for-in statements ( #1843 )
...
Only need to avoid `var` within the initialisation block.
fixes #1841
2017-05-06 23:34:21 +08:00
Alex Lam S.L
d0faa471db
fix unused on labeled for-loop ( #1831 )
...
fixes #1830
2017-05-06 23:31:22 +08:00
Alex Lam S.L
6ad823d1e8
fix reduce_vars within try-block ( #1818 )
...
Possible partial execution due to exceptions.
2017-05-06 23:28:07 +08:00
Alex Lam S.L
43ad4e9775
fix variable substitution ( #1816 )
...
- let `collapse_vars` take care of value containing any symbols
- improve overhead accounting
2017-05-06 23:26:54 +08:00
Alex Lam S.L
d6fbc365e2
fix LHS cases for NaN & friends ( #1804 )
...
`Infinity = beyond` should not become `1/0 = beyond`
2017-04-09 03:18:14 +08:00
Alex Lam S.L
0479ff0c54
fix a couple of bugs in global_defs ( #1802 )
...
- `optimize()` substituted expression
- compute nested property string correctly
fixes #1801
Miscellaneous
- reset optimisation flags on all node types
2017-04-08 16:46:25 +08:00
Alex Lam S.L
cf72fe552f
fix delete corner cases ( #1799 )
...
- assignment
- boolean
- conditional
- sequence
2017-04-08 14:25:28 +08:00
Alex Lam S.L
c2a1bceb77
fix pure_getters for chained property access ( #1798 )
2017-04-07 17:06:01 +08:00
Alex Lam S.L
e3c9c22c75
fix corner cases with delete ( #1796 )
...
`delete Infinity` returns `false` where as `delete (1/0)` returns `true`
2017-04-07 15:39:59 +08:00
Alex Lam S.L
0f4cd73dcc
introduce "strict" to pure_getters ( #1795 )
2017-04-07 13:31:58 +08:00
Alex Lam S.L
281e882d27
fix reduce_vars on catch variable ( #1794 )
...
Improved catch handling in `figure_out_scope()` means special case treatment of IE8 is no longer valid in `reset_opt_flags()`.
Also fixed recursive assignment in variable definition.
2017-04-07 12:32:56 +08:00
Alex Lam S.L
cc6aa3e5ac
fix incorrect context in variable substitution ( #1791 )
...
`AST_Node.optimize()` is context-aware, so don't cache its results to be used elsewhere.
Also fixed a few cases of AST corruption and beef up safety of `pure_getters`.
2017-04-07 03:42:17 +08:00
Alex Lam S.L
e869779a98
enable inline_script by default ( #1793 )
2017-04-07 00:45:51 +08:00
Alex Lam S.L
06cdb74279
improve pure_getters ( #1786 )
...
- property access to `null` & `undefined` always has side effects
- utilise `reduce_vars` to determine safe property access
- may-be cases treated as side effects unless `unsafe`
2017-04-06 11:18:59 +08:00
Alex Lam S.L
ff289b90a9
implement delayed resolution for reduce_vars ( #1788 )
...
Although it would be nice to enforce `AST_Node` cloning during transformation, that ship has sailed a long time ago.
We now get the assigned value when resolving `AST_SymbolRef` instead of `reset_opt_flags()`, which has the added advantage of improved compressor efficiency.
fixes #1787
2017-04-05 21:06:42 +08:00
Alex Lam S.L
9b6bc67c33
optimise do{...}while(false) ( #1785 )
...
- better heuristics to avoid issues like #1532
- fix `TreeWalker.loopcontrol_target()`
- `continue` cannot refer to `switch` blocks
2017-04-04 23:48:22 +08:00
Alex Lam S.L
951770fc68
exclude mangling of special property names ( #1779 )
...
- `null`
- `true`
- `false`
- numeric literals
2017-04-04 03:50:19 +08:00
Alex Lam S.L
48b3fe9952
fix mangleProperties on identifiers ( #1776 )
...
- fix handling of "-Infinity"
- add test case for "-0"
reverts #1481
2017-04-03 23:17:47 +08:00
Alex Lam S.L
59a4e56bc8
fix mangleProperties of undefined & Infinity ( #1772 )
...
`NaN` already works by the happy accident of `Number.NaN`
fixes #1770
2017-04-03 12:31:05 +08:00
Alex Lam S.L
9469c03ac9
fix corner case in switch ( #1765 )
2017-04-02 17:07:20 +08:00
Alex Lam S.L
d57527697f
avoid confusion of NaN & Infinity with catch symbol of the same name ( #1763 )
...
fixes #1760
fixes #1761
2017-04-02 16:14:09 +08:00
Alex Lam S.L
f7ca4f2297
fix corner cases in switch and undefined ( #1762 )
...
- fix side effects in switch condition for singular blocks
- fix `undefined` confusion with local variable
- gate `OPT(AST_Switch)` with `switches`
fixes #1758
fixes #1759
2017-04-02 14:52:25 +08:00
Alex Lam S.L
ee3fe0f4cd
fix switch branch elimination ( #1752 )
...
Merge unreachable case body with previous fallthrough case
fixes #1750
2017-04-01 17:19:57 +08:00
Alex Lam S.L
257ddc3bdb
improve compression of undefined, NaN & Infinitiy ( #1748 )
...
- migrate transformation logic from `OutputStream` to `Compressor`
- always turn `undefined` into `void 0` (unless `unsafe`)
- always keep `NaN` except when avoiding local variable redefinition
- introduce `keep_infinity` to suppress `1/0` transform, except when avoiding local variable redefinition
supersedes #1723
fixes #1730
2017-04-01 03:02:14 +08:00
Alex Lam S.L
1ddc05725d
combine rules for binary boolean operations ( #1744 )
2017-03-31 18:47:44 +08:00
Alex Lam S.L
a0c3836ba0
sort options in alphabetical order ( #1743 )
...
They started off as functional groups I guess, but given the sheer number of options this is becoming too difficult to read.
2017-03-31 16:41:04 +08:00
Alex Lam S.L
11e9bdc427
fix missing preamble when shebang is absent ( #1742 )
2017-03-31 15:26:57 +08:00
Alex Lam S.L
c595b84032
fix catch symbol mangling ( #1734 )
...
Only need to look up the immediate non-block/catch scope for the same-name special case.
fixes #1733
2017-03-31 02:57:47 +08:00
Alex Lam S.L
7cb1adf455
remove paranthesis for -(x*y) ( #1732 )
2017-03-30 16:09:00 +08:00
Alex Lam S.L
7bea38a05d
optimize try-catch-finally ( #1731 )
...
- eliminate empty blocks
- flatten out if try-block does not throw
2017-03-30 12:16:58 +08:00
Alex Lam S.L
beb9659778
speed up IIFE elimination ( #1728 )
...
- `side_effects` will clean up inner statements, so checking for an empty function body should suffice
- drop side effects when dropping `return` from statement
2017-03-29 23:27:35 +08:00
Alex Lam S.L
f1a833a7aa
speed up equivalent_to() and AST_Switch ( #1727 )
2017-03-29 22:08:26 +08:00
Alex Lam S.L
2e41cd6394
fix missing parentheses around NaN/Infinity shorthands ( #1726 )
...
fixes #1724
fixes #1725
2017-03-29 20:53:03 +08:00
Alex Lam S.L
09f77c7d4d
output optimal representations of NaN & Infinity ( #1723 )
...
- move these optimisations out from `Compressor` to `OutputStream`
- fixes behaviour inconsistency when running uglified code from global or module levels due to redefinition
2017-03-29 18:31:55 +08:00
Alex Lam S.L
fef0bf9ee0
improve beautified output of switch blocks ( #1721 )
2017-03-29 04:40:05 +08:00
Alex Lam S.L
eb48a035e7
fix corner case in unused ( #1718 )
...
When fixing catch-related issue in #1715 , it tries to optimise for duplicate definitions but did not take anonymous functions into account.
Remove such optimisation for now and we can cover this as a more general rule later.
2017-03-29 01:00:21 +08:00
Alex Lam S.L
c909ffb715
fix unused on var of the same name within catch ( #1716 )
...
fixes #1715
2017-03-28 21:25:49 +08:00
Alex Lam S.L
f71f4905b0
fix is_number() on += ( #1714 )
...
fixes #1710
2017-03-28 17:08:16 +08:00
Alex Lam S.L
fb177a6312
drop anonymous function name when overshadowed by other declarations ( #1712 )
...
fixes #1709
2017-03-28 17:02:20 +08:00
Alex Lam S.L
65da9acce6
handle var within catch of the same name ( #1711 )
...
The following code prints `1`:
var a = 1;
!function(){
a = 4;
try{
throw 2;
} catch (a) {
var a = 3;
}
}();
console.log(a);
fixes #1708
2017-03-28 16:42:39 +08:00
Alex Lam S.L
67d0237f73
fix tail trimming of switch blocks ( #1707 )
...
now guarded under `dead_code`
fixes #1705
2017-03-28 03:59:13 +08:00
Alex Lam S.L
984a21704e
fix mangle for variable declared within catch block ( #1706 )
...
fixes #1704
2017-03-28 03:26:35 +08:00
Alex Lam S.L
c526da59a1
has_side_effects() should take AST_Switch.expression into account (#1699 )
...
fixes #1698
2017-03-27 18:09:35 +08:00
Alex Lam S.L
581630e0a7
fix typeof side effects ( #1696 )
...
`statement_to_expression()` drops `typeof` even if it operates on undeclared variables.
Since we now have `drop_side_effect_free()`, replace and remove this deprecated functionality.
2017-03-27 04:37:42 +08:00
Alex Lam S.L
f5952933a0
preserve side effects in switch expression ( #1694 )
...
fixes #1690
2017-03-27 02:32:46 +08:00
Alex Lam S.L
f001e4cb9d
fix cascade on anonymous function reference ( #1693 )
...
Unlike normal variables and even function definitions, these cannot be reassigned, even though assignment expressions would "leak" the assigned value as normal.
2017-03-27 01:58:21 +08:00
Alex Lam S.L
57ce5bd9e0
handle overlapped variable definitions ( #1691 )
...
Process variable definitions with or without assigned values against:
- `arguments`
- named function arguments
- multiple definitions within same scope
Essentially demote variable declarations with no value assignments.
Also fixed invalid use of `AST_VarDef` over `arguments` - should use a member of `AST_SymbolDeclaration` instead.
2017-03-27 01:30:21 +08:00
Alex Lam S.L
861a79ac9f
fix delete related issues in collapse_vars and reduce_vars ( #1689 )
2017-03-26 19:14:30 +08:00