Alex Lam S.L
957c54bc87
introduce unsafe_regexp ( #1970 )
...
fixes #1964
2017-05-19 10:10:09 +08:00
Alex Lam S.L
a8c67ea353
fix bugs with getter/setter ( #1926 )
...
- `reduce_vars`
- `side_effects`
- property access for object
- `AST_SymbolAccessor` as key names
enhance `test/ufuzz.js`
- add object getter & setter
- property assignment to setter
- avoid infinite recursion in setter
- fix & adjust assignment operators
- 50% `=`
- 25% `+=`
- 2.5% each for the rest
- avoid "Invalid array length"
- fix `console.log()`
- bypass getter
- curb recursive reference
- deprecate `-E`, always report runtime errors
2017-05-15 18:22:43 +08:00
Alex Lam S.L
f631d6437a
avoid arguments and eval in reduce_vars ( #1924 )
...
fixes #1922
2017-05-12 12:45:38 +08:00
Alex Lam S.L
aa7e8783f8
fix invalid transform on const ( #1919 )
...
- preserve (re)assignment to `const` for runtime error
- suppress `cascade` on `const`, as runtime behaviour is ill-defined
2017-05-12 05:04:28 +08:00
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
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
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
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
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
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
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
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
Alex Lam S.L
e76fb354eb
fix cascade on delete operator ( #1687 )
...
Conditions including strict mode would make `delete` return `true` or `false`, and are too complex to be evaluated by the compressor.
Suppress assignment folding into said operator.
fixes #1685
2017-03-26 18:08:44 +08:00
Alex Lam S.L
3276740779
fallthrough should not execute case expression ( #1683 )
...
- de-duplicate trailing cases only, avoid all potential side-effects
- enable switch statement fuzzing
fixes #1680
2017-03-26 16:52:38 +08:00
kzc
5509e51098
optimize conditional when condition symbol matches consequent ( #1684 )
2017-03-26 16:36:33 +08:00
Alex Lam S.L
94f84727ce
suppress switch branch de-duplication upon side effects ( #1682 )
...
fixes #1679
2017-03-26 13:32:43 +08:00
Alex Lam S.L
8a4f86528f
fix side-effects detection on switch statements ( #1678 )
...
extension of #1675
2017-03-26 12:05:44 +08:00
Alex Lam S.L
f83d370f57
improve switch optimisations ( #1677 )
...
- correctly determine reachability of (default) branches
- gracefully handle multiple default branches
- optimise branches with duplicate bodies
fixes #376
fixes #441
fixes #1674
2017-03-26 05:15:46 +08:00