alexlamsl
8f7ab602e2
Merge branch 'master' into harmony-v2.8.12
2017-03-14 13:17:42 +08:00
Alex Lam S.L
1dd339f95e
fix unused crashes ( #1599 )
...
- `AST_DefaultAssign` on `keep_fargs`
- `AST_Expansion on` `keep_fargs`
- `AST_Destructuring` on top-level declarations without `toplevel`
2017-03-14 13:13:43 +08:00
Alex Lam S.L
d9344f30b8
disallow parameter substitution for named IIFEs ( #1596 )
...
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
2017-03-11 03:34:55 +08:00
Alex Lam S.L
be80f7e706
support multi-line string in tests ( #1590 )
...
`expect_exact` sometimes have multiple lines and `\n` are hard to read.
Use array of strings to emulate line breaks and improve readability.
2017-03-10 11:27:30 +08:00
alexlamsl
f4a12b34f2
Merge branch 'master' into harmony-v2.8.11
2017-03-10 11:17:49 +08:00
Alex Lam S.L
cf45e2f79b
fixup for #1585 ( #1589 )
...
As patched on `harmony`, `statement()` is the only user of `embed_tokens()` with a missing error branch.
Updated test case and match up with `harmony` to facilitate future merging.
2017-03-10 10:49:41 +08:00
Alex Lam S.L
9e6b128374
fix catch variable reference in IE8 ( #1587 )
...
`AST_Scope.def_variable()` will overwrite `AST_Symbol.thedef`, so save a copy before calling.
fixes #1586
2017-03-10 03:15:21 +08:00
Michael Mior
93cdb194f4
Correctly raise a parse exception with a missing loop body ( #1585 )
2017-03-10 03:08:43 +08:00
Alex Lam S.L
b633706ce4
fix & improve function argument compression ( #1584 )
...
- one-use function call => IIFE should take `eval()` & `arguments` into account
- if unused parameter cannot be eliminated, replace it with `0`
fixes #1583
2017-03-09 19:11:05 +08:00
alexlamsl
8f4b45f4f8
Merge branch 'master' into harmony-v2.8.10
2017-03-09 06:02:28 +08:00
Alex Lam S.L
7e465d4a01
scan RHS of dropped assignments ( #1581 )
...
- similar case as #1578 but against #1450 instead
- fix `this` binding in #1450 as well
closes #1580
2017-03-09 05:22:27 +08:00
Alex Lam S.L
711f88dcb4
scan assignment value in drop_unused() ( #1578 )
...
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
2017-03-08 18:37:32 +08:00
Alex Lam S.L
c7cdcf06a6
fix function name eliminiation ( #1576 )
...
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 #1573
fixes #1575
2017-03-08 12:39:57 +08:00
Alex Lam S.L
3ee55748d4
only run benchmark & jetstream on CI ( #1571 )
2017-03-08 06:00:51 +08:00
Alex Lam S.L
dedbeeff15
plan B for IE8 do-while semi-colon fix ( #1572 )
...
- omitting trailing semi-colon in do-while breaks non-browser parser, e.g. uglify-js 1.x
- trailing semi-colon only breaks IE8 if followed by `else` or `while`
- always use braces in do-while body to workaround 2nd case with no size loss in compression
fixes #1568
2017-03-08 05:07:05 +08:00
Alex Lam S.L
bd6dee52ab
fix return from recursive IIFE ( #1570 )
...
`side-effects` did not account for IIFEs being able to reference itself thus making its return value potentially significant
2017-03-08 03:31:51 +08:00
Alex Lam S.L
952e2656eb
Merge pull request #1567 from alexlamsl/harmony-v2.8.8
...
Merging from master for 2.8.8
2017-03-07 23:56:23 +08:00
qinayi
240383a314
is_block_scope return true when current node is an instance of AST_IterationStatement. then the scope of let variable can be figured out accurately ( #1561 )
2017-03-07 23:50:58 +08:00
alexlamsl
250b782b1e
Merge branch 'master' into harmony-v2.8.8
2017-03-07 20:25:52 +08:00
Alex Lam S.L
65c848cc6f
include benchmark.js in test suite ( #1564 )
...
- report file sizes and overall run time
- exit with non-zero code upon error
2017-03-07 19:25:12 +08:00
Alex Lam S.L
8a8a94a596
fix deep cloning of labels ( #1565 )
...
`AST_Label.references` get `.initialize()` to `[]` every time after `.clone()`
So walk down the tree to pick up the cloned `AST_LoopControl` pieces and put it back together.
2017-03-07 18:38:27 +08:00
Alex Lam S.L
8153b7bd8a
transform function calls to IIFEs ( #1560 )
...
- expose function body to call sites for potential optimisations
- suppress substitution of variable used within `AST_Defun`
2017-03-07 15:37:52 +08:00
Alex Lam S.L
d787d70127
avoid substitution of global variables ( #1557 )
...
- unless `toplevel` is enabled
- global `const` works as before
2017-03-07 03:11:03 +08:00
kzc
3ac2421932
collapse_vars: do not replace a constant in loop condition or init ( #1562 )
2017-03-07 01:42:33 +08:00
Alex Lam S.L
a9fc9ddc33
suppress semicolons after do/while ( #1556 )
...
- unless both `beautify` & `screw-ie8` are enabled
- deprecate workaround for if-do-while-else
fixes #186
2017-03-06 17:31:35 +08:00
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
eb98a7f2f3
fix handling of shebang and preamble ( #1545 )
...
fixes #1332
2017-03-05 12:16:02 +08:00
Alex Lam S.L
78d1bb92d4
fix a corner case in #1530 ( #1552 )
2017-03-05 12:12:59 +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
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
alexlamsl
8a7a4749c7
Merge branch 'master' into harmony-v2.8.2
2017-03-01 11:06:33 +08:00