Anthony Van de Gejuchte
2377171200
Fix walker not able to handle destr pattern in spread when compressing ( #1438 )
2017-04-04 01:23:22 +08:00
Anthony Van de Gejuchte
603d92effc
Allow AST_DefaultAssign as parameter ( #1778 )
...
This may be the case for parsing arrow functions,
as left side expressions are converted to destructuring patterns
before being converted to parameters.
2017-04-04 00:46:05 +08:00
Anthony Van de Gejuchte
17f0cc359f
Allow empty destructuring ( #1773 )
2017-04-03 17:21:27 +08:00
alexlamsl
4614b5b46e
Merge branch 'master' into harmony-v2.8.21
2017-04-02 17:25:20 +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
Ondřej Španěl
2f93058c6e
More variants of import added ( #1738 )
...
- `import * from "x.js"`
- `import * as Name from "x.js"`
2017-03-31 17:52:56 +08:00
Ondřej Španěl
a729c43e87
Another variant of export added - export {Name}. ( #1737 )
2017-03-31 17:51:27 +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
alexlamsl
d717bf9ce8
Merge branch 'master' into harmony
2017-03-31 12:54:03 +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
Ondřej Španěl
5dea52266b
[ES6] Implemented parse for export Name from Module variants. ( #1701 )
...
- add `AST_Export` new variants output
- add tests to `test/compress/`
- update `$propdoc` of `AST_Export` ("exported_names" & "module_name")
- add tests for `export ... as ...` variants
2017-03-30 17:07:50 +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
alexlamsl
1e2b0aaa04
Merge branch 'master' into harmony-v2.8.17
2017-03-28 22:03:46 +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
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
kzc
6a54de79b5
optimize trivial arrow functions with a return statement in braces ( #1681 )
...
fixes #1676
2017-03-26 12:03:11 +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
Alex Lam S.L
b19aa58cff
fix has_side_effects() ( #1675 )
...
`AST_Try` is an `AST_Block`, so besides try block we also need to inspect catch and finally blocks for possible side effects.
Also extend this functionality to handle `AST_If` and `AST_LabeledStatement` while we are at it.
fixes #1673
2017-03-25 23:03:26 +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
Alex Lam S.L
6e86ee950d
fix typeof side-effects ( #1669 )
...
`has_side_effects()` does not take `typeof`'s magical power of not tripping over undeclared variable into account.
fixes #1668
2017-03-25 17:40:18 +08:00
Alex Lam S.L
8ca2401ebe
fix dead_code on AST_Switch ( #1667 )
...
Need to call `extract_declarations_from_unreachable_code()`.
fixes #1663
2017-03-25 16:21:42 +08:00
Alex Lam S.L
a30092e20f
fix invalid AST_For.init ( #1657 )
...
Turns out the only place in `Compressor` which can generate invalid `AST_For.init` is within `drop_unused()`, so focus the fix-up efforts.
supercedes #1652
fixes #1656
2017-03-25 03:18:36 +08:00