Alex Lam S.L
09b320e8a5
convert to number under boolean context ( #2545 )
2017-12-01 12:52:36 +08:00
Alex Lam S.L
b762f2d6f4
improve compression of loop conditions ( #2543 )
2017-12-01 05:52:33 +08:00
Alex Lam S.L
18302bf8e9
backport test from #2526 ( #2534 )
2017-11-29 13:32:00 +08:00
Alex Lam S.L
32def5ebf5
improve synergy between collapse_vars & unused ( #2521 )
2017-11-28 14:02:39 +08:00
Alex Lam S.L
ae28a24c7f
fix cross-scope inlining of AST_Functions ( #2486 )
...
fixes #2485
2017-11-16 10:04:30 +08:00
Alex Lam S.L
cda27b0970
extend reduce_funcs to cover cross-scope substitutions ( #2469 )
...
fixes #2468
2017-11-11 15:30:17 +08:00
Alex Lam S.L
3c74047368
implement compress option reduce_funcs ( #2466 )
...
- inline single-use function declarations as expressions when permissible
- depend on `reduce_vars`
- enabled by default
- disable for speed critical code
fixes #2464
2017-11-11 05:59:35 +08:00
Alex Lam S.L
94525d859f
fix object literal tracing in reduce_vars ( #2461 )
2017-11-10 05:47:10 +08:00
Alex Lam S.L
1127a2caf3
fix multiple nested function substitutions ( #2458 )
...
fixes #2449
2017-11-09 23:30:00 +08:00
Alex Lam S.L
4c0b0177b6
preserve function identity in reduce_vars ( #2451 )
...
fixes #2450
2017-11-08 03:28:46 +08:00
Alex Lam S.L
bbedbf4ea0
handle circular function reference gracefully ( #2446 )
...
fixes #2442
2017-11-07 02:37:23 +08:00
Alex Lam S.L
2cfb5aa7da
account for eval & with in reduce_vars ( #2441 )
...
fixes #2440
2017-11-06 16:10:57 +08:00
Alex Lam S.L
6c45101870
consolidate & enhance unused ( #2439 )
...
- defer declaration removal in `collapse_vars`
- account for `AST_SymbolFunarg` in deduplication
- private accounting for `collapse_vars`
- avoid issues with identity reference due to deep cloning
fixes #2437
2017-11-06 14:25:10 +08:00
Alex Lam S.L
5b4b07e9a7
extend function inlining safety checks ( #2430 )
2017-11-05 06:18:45 +08:00
Alex Lam S.L
a8aa28a7a6
consolidate single-use function reduction ( #2427 )
...
fixes #2423
2017-11-05 04:27:01 +08:00
Alex Lam S.L
c8b6f4733d
reduce this within functions ( #2421 )
...
- only replace same-scope usages
- augment `test/ufuzz.js` to test for `this`
fixes #2420
2017-11-04 00:31:37 +08:00
Alex Lam S.L
8428326ea1
enhance properties ( #2412 )
...
- trim array items only if `side_effects`
- extend to non-identifier properties
2017-10-29 04:11:26 +08:00
Alex Lam S.L
74ae16f9f8
fix unsafe reduce_vars on arrays & objects ( #2397 )
2017-10-24 22:10:36 +08:00
Alex Lam S.L
86ea38a259
enhance unsafe evaluate of arrays & objects ( #2394 )
2017-10-24 02:58:30 +08:00
Alex Lam S.L
24aa07855b
safer properties transform ( #2391 )
...
`{ a: x, b: y }.a` => `[ x, y ][0]`
- `x` cannot be function containing `this`
`[ x, y, z ][1]` => `(x, z, y)`
- only if `z` is side-effect-free
2017-10-22 20:10:13 +08:00
Alex Lam S.L
011123223b
fix unsafe escape analysis in reduce_vars ( #2387 )
2017-10-22 03:23:31 +08:00
Alex Lam S.L
c927cea632
unsafe fix-ups for #2351 ( #2379 )
2017-10-21 04:08:26 +08:00
Alex Lam S.L
eba0f93bc0
more tests for #2351 ( #2357 )
2017-10-12 02:58:25 +08:00
Alex Lam S.L
b810e2f8da
perform reduce_vars on safe literals ( #2351 )
...
- constant expression
- single reference
- same scope
- not across loop body
2017-10-09 12:25:06 +08:00
Alex Lam S.L
dd71639264
enhance reduce_vars for AST_Accessor ( #2339 )
...
fixes #2336
2017-10-01 03:01:50 +08:00
Alex Lam S.L
1ac25fc032
improve compress granularity through typeofs ( #2201 )
...
fixes #2198
2017-07-05 19:20:33 +08:00
Alex Lam S.L
3d5bc08185
fix reduce_vars on this ( #2145 )
...
fixes #2140
2017-06-23 04:44:57 +08:00
Alex Lam S.L
3493a182b2
implement function inlining ( #2053 )
...
- empty body
- single `AST_Return`
- single `AST_SimpleStatement`
- avoid `/*#__PURE__*/`
Miscellaneous
- enhance single-use function substitution
fixes #281
2017-06-06 05:49:53 +08:00
Alex Lam S.L
540220b91b
fix AST_Function scope invariance ( #2052 )
...
improve function name hack in `run_code()`
2017-06-04 19:27:43 +08:00
Alex Lam S.L
3ca902258c
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-14 02:10:34 +08:00
Alex Lam S.L
c391576d52
remove support for const ( #1910 )
...
As this is not part of ES5.
2017-05-12 14:57:41 +08:00
Alex Lam S.L
ac73c5d421
avoid arguments and eval in reduce_vars ( #1924 )
...
fixes #1922
2017-05-12 12:34:55 +08:00
Alex Lam S.L
98cf95e5b5
fix test for #1865 ( #1873 )
2017-05-07 02:56:02 +08:00
Alex Lam S.L
2c7ee956fd
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:18:55 +08:00
Alex Lam S.L
2cb55b2ad0
enforce toplevel on other compress options ( #1855 )
...
Respect "funcs" and "vars" properly.
fixes #1850
2017-04-30 22:52:36 +08:00
Alex Lam S.L
f05d4f7af3
improve unused ( #1832 )
...
- extract leading value with side-effects out of `var` statement
- reduce scanning of `AST_Definitions` from 3 passes to just once
2017-04-20 13:06:14 +08:00
Alex Lam S.L
5d9f1da3ab
support safe reassignments in reduce_vars ( #1823 )
...
`var a=1;a=2;x(a)` => `x(2)`
fix pre-existing issues
- reference counting on assignment
- walking of anonymous functions
- chained assignment
2017-04-18 13:38:42 +08:00
Alex Lam S.L
d1aa09c5c7
fix reduce_vars on conditionals ( #1822 )
2017-04-18 01:44:23 +08:00
Alex Lam S.L
6d5f341999
fix reduce_vars on boolean binary expressions ( #1819 )
...
Side effects of `&&` and `||` have not mattered until #1814 , which takes assignment expressions into account.
2017-04-17 17:24:29 +08:00
Alex Lam S.L
4ffb6fce76
compress duplicated variable definitions ( #1817 )
...
These are surprisingly common, as people reuse the same variable name within loops or switch branches.
2017-04-17 17:11:29 +08:00
Alex Lam S.L
71a8d0d236
fix reduce_vars within try-block ( #1818 )
...
Possible partial execution due to exceptions.
2017-04-17 14:03:29 +08:00
Alex Lam S.L
1a498db2d3
enhance reduce_vars ( #1814 )
...
- allow immediate assignment after declaration of variable
- relax modification rule for immutable value
- fix order of visit for TreeWalker
- remove extraneous code
2017-04-17 01:36:50 +08:00
Alex Lam S.L
44dfa5a318
fix variable substitution ( #1816 )
...
- let `collapse_vars` take care of value containing any symbols
- improve overhead accounting
2017-04-16 17:25:39 +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
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
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
0a65de89b9
fix reduce_vars on AST_Switch ( #1671 )
...
Take conditional nature of switch branches into account.
fixes #1670
2017-03-25 21:17:30 +08:00