`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
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 #1652fixes#1656
- #1634 bars variables with cross-scope references in between to collapse
- but if assigned value is side-effect-free, no states can be modified, so it is safe to move
The following is wrong:
`a == (b ? a : c)` => `b`
Because:
- `b` may not be boolean
- `a` might have side effects
- `a == a` is not always `true` (think `NaN`)
- `a == c` is not always `false`
`reduce_vars` enables substitution of variables but did not clone the value's `AST_Node`.
This confuses `collapse_vars` and result in invalid AST and subsequent crash.
fixes#1609
As patched in #1597, `make_node_from_constant()` makes inconsistent and sometimes incorrect calls to `optimize()` and `transform()`.
Fix those issues properly by changing the semantics of `evaluate()` and `make_node_from_constant()`, with the side effect that `evaluate()` no longer eagerly converts constant to `AST_Node`.
Liberal use of `Compressor.transform()` and `AST_Node.optimize()` presents an issue for look-up operations like `TreeWalker.in_boolean_context()` and `TreeWalker.parent()`.
This is an incremental fix such that `AST_Node.optimize()` would now contain the correct stack information when called correctly.
Self-referenced function has non-fixed values assigned to its parameters.
Let `unused` & `!keep_fnames` do the scanning, then apply `reduce_vars` only to unnamed functions.
fixes#1595
- one-use function call => IIFE should take `eval()` & `arguments` into account
- if unused parameter cannot be eliminated, replace it with `0`
fixes#1583
those were not optimised for `unused` before, which made it necessary for `reduce_vars` to have separate steps for `keep_fnames`
docs update by @kzc
closes#1577
Function expression can be assigned to a variable and be given a name. Ensure function name is the reduced variable before clearing it out.
fixes#1573fixes#1575
`unsafe` turns undefined keyword into a variable of the same name if found, but that interferes with other related optimisations.
Keep track of such transformations to ensure zero information loss in the process.