alexlamsl
aa605495f8
Merge branch 'master' into harmony-v2.8.6
2017-03-05 21:42:34 +08:00
kzc
33a26d456b
patch up #1543 for harmony
...
fixes #1537
2017-03-05 21:39:31 +08:00
Alex Lam S.L
067e5a5762
fixup for #1553 ( #1555 )
...
- `++a` is the one that is foldable
- transform `a++` into `++a` for better optimisation
2017-03-05 17:15:37 +08:00
alexlamsl
49d9ac1c43
Merge branch 'master' into harmony-v2.8.6
2017-03-05 16:03:56 +08:00
Alex Lam S.L
35a849dc48
collapse assignment with adjacent subsequent usage ( #1553 )
...
- consolidate `cascade` optimisations
- support ++/-- postfixes
- remove redundant optimisation identified in #1460
fixes #368
2017-03-05 14:56:14 +08:00
Alex Lam S.L
b70591be1a
handle variable declaration within catch blocks ( #1546 )
...
accounts for IE8- scoping
2017-03-05 13:13:44 +08:00
Alex Lam S.L
b33e7f88e6
improve unsafe on undefined ( #1548 )
...
`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.
2017-03-05 13:09:27 +08:00
Alex Lam S.L
1f0333e9f1
stay safe with constants in IE8- ( #1547 )
...
- `undefined` etc. can be redefined at top-level for IE8-, so disable related optimisations
- fixed `--support-ie8` catch mangle bug
2017-03-05 12:51:11 +08:00
Alex Lam S.L
78d1bb92d4
fix a corner case in #1530 ( #1552 )
2017-03-05 12:12:59 +08:00
kzc
ce54c9ccee
disallow collapse_vars constant replacement in for-in statements ( #1543 )
2017-03-04 02:39:54 +08:00
Alex Lam S.L
07accd2fbb
process code with implicit return statement ( #1522 )
...
Bookmarklet for instance implicitedly assumes a "completion value" without using `return`.
The `expression` option now supports such use cases.
Optimisations on IIFEs also enhanced.
fixes #354
fixes #543
fixes #625
fixes #628
fixes #640
closes #1293
2017-03-03 18:13:07 +08:00
Alex Lam S.L
18059cc94f
compress numerical expressions ( #1513 )
...
safe operations
- `a === b` => `a == b`
- `a + -b` => `a - b`
- `-a + b` => `b - a`
- `a+ +b` => `+b+a`
associative operations
(bit-wise operations are safe, otherwise `unsafe_math`)
- `a + (b + c)` => `(a + b) + c`
- `(n + 2) + 3` => `5 + n`
- `(2 * n) * 3` => `6 * n`
- `(a | 1) | (2 | d)` => `(3 | a) | b`
fixes #412
2017-03-03 18:04:32 +08:00
alexlamsl
f704e9b65c
fix destructing crash in reduce_vars
...
fixes #1531
2017-03-03 07:23:46 +08:00
alexlamsl
0b77d861a8
Merge branch 'master' into harmony-v2.8.5
2017-03-03 07:17:52 +08:00
Alex Lam S.L
b5e0e8c203
facilitate fix for #1531 ( #1542 )
2017-03-03 07:12:24 +08:00
Alex Lam S.L
17b81350d4
fix chained assignment with unused ( #1540 )
...
When #1450 optimises `a=b=42`, it stops after the first variable even if both are unused.
fixes #1539
2017-03-03 04:45:20 +08:00
kzc
4d63d4f5b3
collapse_vars should not replace constant in for-in init section ( #1538 )
...
fixes #1537
2017-03-03 03:51:15 +08:00
Alex Lam S.L
70d72ad806
properly cover all cases of for-in loop variables ( #1536 )
2017-03-03 02:39:57 +08:00
Alex Lam S.L
fe9227a41b
fix reference marking in for-in loops ( #1535 )
...
fixes #1533
2017-03-03 00:56:06 +08:00
Alex Lam S.L
b49e142a26
disable do{...}while(false) optimisation ( #1534 )
...
- fails to handle `break` in body
fixes #1532
2017-03-03 00:54:41 +08:00
kzc
ee3b39b909
optimize trivial IIFEs returning constants ( #1530 )
2017-03-02 15:11:40 +08:00
Alex Lam S.L
9699ffb1af
trim unused invocation parameters ( #1526 )
2017-03-02 11:33:59 +08:00
Alex Lam S.L
fdc9b9413b
minor improvement to string optimisation ( #1514 )
...
- "" + "a" => "a"
- "" + a + "b" => a + "b"
- "a" + "" => "a" (improving on #45 )
2017-03-02 11:31:39 +08:00
alexlamsl
80f3ad3ce0
Merge branch 'master' into harmony-v2.8.4
2017-03-02 11:16:55 +08:00
Alex Lam S.L
7aa69117e1
fix corner cases in reduce_vars ( #1524 )
...
Avoid variable substitution in the following cases:
- use of variable before declaration
- declaration within conditional code blocks
- declaration within loop body
fixes #1518
fixes #1525
2017-03-02 00:20:53 +08:00
Alex Lam S.L
c2334baa48
fix crash on missing props to string_template() ( #1523 )
...
Patched up `make_node()` without `orig`.
There may be other cases where `start` could be missing, so make it print "undefined" instead of crashing.
fixes #1518
2017-03-01 15:25:26 +08:00
alexlamsl
8a7a4749c7
Merge branch 'master' into harmony-v2.8.2
2017-03-01 11:06:33 +08:00
Alex Lam S.L
f5cbe19b75
invert reduce_vars tracking flag ( #1519 )
...
Modules like webpack and grunt-contrib-uglify still uses `ast.transform(compressor)` before `Compressor.compress(ast)` was introduced.
Workaround this compatibility issue by deactivating `reduce_vars` in such case.
Also fix use case with omitted `options` when calling `Compressor()`.
fixes #1516
2017-03-01 04:12:10 +08:00
Alex Lam S.L
b34fa11a13
fix evaluate on object getter & setter ( #1515 )
2017-03-01 02:03:47 +08:00
Alex Lam S.L
4365a51237
temporarily disables reduce_vars ( #1517 )
...
... as we investigate #1516
2017-03-01 00:25:43 +08:00
alexlamsl
57777b6cfa
Merge branch 'master' into harmony-2.8.0
2017-02-28 02:28:58 +08:00
Alex Lam S.L
858e6c78a4
warn & drop #__PURE__ iff IIFE is dropped ( #1511 )
...
- consolidate `side-effects` optimisations
- improve string `+` optimisation
- enhance literal & `conditionals` optimisations
2017-02-28 02:25:44 +08:00
alexlamsl
b3a987b0df
fix up drop_unused()
2017-02-27 05:11:01 +08:00
alexlamsl
88a338f29e
Merge branch 'master' into harmony-2.8.0
2017-02-27 04:37:48 +08:00
Alex Lam S.L
13be50a4a9
faster tree transversal ( #1462 )
...
- convert `[].forEach()` to for-loops
2017-02-26 05:58:26 +08:00
Alex Lam S.L
16cd5d57a5
consolidate evaluate & reduce_vars ( #1505 )
...
- improve marking efficiency
- apply smarter `const` replacement to `var`
fixes #1501
2017-02-26 00:40:33 +08:00
Anthony Van de Gejuchte
07734b000a
Destructuring consistency fixes ( #1417 )
...
- Use AST_Destructuring for lhf assignment patterns
- Use AST_DefaultAssign for default assignments
- Add more checks for lhs expressions
- Add lots of testing
- Cleanup ast (e.g. remove default property)
- Fix #1402 based on a patch from @kzc
- Refine spread allowance in array destructring pattern
- Add destructuring AST tree checker
2017-02-24 08:49:19 +08:00
alexlamsl
4e49302916
enable collapse_vars & reduce_vars by default
...
- fix corner cases in `const` optimisation
- deprecate `/*@const*/`
fixes #1497
closes #1498
2017-02-24 01:46:57 +08:00
kzc
1e51586996
Support marking a call as pure
...
A function call or IIFE with an immediately preceding comment
containing `@__PURE__` or `#__PURE__` is deemed to be a
side-effect-free pure function call and can potentially be
dropped.
Depends on `side_effects` option.
`[#@]__PURE__` hint will be removed from comment when pure
call is dropped.
fixes #1261
closes #1448
2017-02-21 14:24:18 +08:00
alexlamsl
26fbeece1c
fix pure_funcs & improve side_effects
...
- only drops side-effect-free arguments
- drop side-effect-free parts with discarded value from `AST_Seq` & `AST_SimpleStatement`
closes #1494
2017-02-21 13:31:59 +08:00
alexlamsl
ec64acd2c8
introduce unsafe_proto
...
- `Array.prototype.slice` => `[].slice`
closes #1491
2017-02-21 13:29:58 +08:00
alexlamsl
e275148998
enhance global_defs
...
- support arrays, objects & AST_Node
- support `"a.b":1` on both cli & API
- emit warning if variable is modified
- override top-level variables
fixes #1416
closes #1198
closes #1469
2017-02-21 13:29:58 +08:00
alexlamsl
974247c8c0
evaluate AST_SymbolRef as parameter
...
fix invalid boolean conversion now exposed in `make_node_from_constant()`
closes #1477
2017-02-21 13:29:58 +08:00
alexlamsl
a0f4fd390a
improve reduce_vars and fix a bug
...
- update modified flag between compress() passes
- support IIFE arguments
- fix corner case with multiple definitions
closes #1473
2017-02-21 13:29:58 +08:00
alexlamsl
b8b133d91a
improve keep_fargs & keep_fnames
...
- utilise in_use_ids instead of unreferenced()
- drop_unused now up-to-date for subsequent passes
closes #1476
2017-02-21 13:29:58 +08:00
kzc
6ffbecb72b
smarter const replacement taking name length into account
...
closes #1459
2017-02-21 13:29:58 +08:00
alexlamsl
f0ff6189be
clean up negate_iife
...
- remove extra tree scanning phase for `negate_iife`
- `negate_iife` now only deals with the narrowest form, i.e. IIFE sitting directly under `AST_SimpleStatement`
- `booleans`, `conditionals` etc. will now take care the rest via more accurate accounting
- `a(); void b();` => `a(); b();`
fixes #1288
closes #1451
2017-02-21 13:29:58 +08:00
alexlamsl
6b3c49e458
improve string concatenation
...
shuffle associative operations to minimise parentheses and aid other uglification efforts
closes #1454
2017-02-21 13:29:57 +08:00
alexlamsl
f584ca8d07
-c sequences=N suboptimal at N expression cutoff
...
N = 2:
a;
b;
c;
d;
was:
a, b;
c;
d;
now:
a, b;
c, d;
fixes #1455
closes #1457
2017-02-21 13:29:57 +08:00
alexlamsl
ae4db00991
tweak do-while loops
...
- `do{...}while(false)` => `{...}`
- clean up `AST_While` logic
closes #1452
2017-02-21 13:29:57 +08:00