UglifyJS.git
7 years agoextend `test/run-tests.js` to optionally execute uglified output (#1604)
Alex Lam S.L [Thu, 16 Mar 2017 15:20:06 +0000 (23:20 +0800)]
extend `test/run-tests.js` to optionally execute uglified output (#1604)

fixes #1588

7 years agomake `collapse_vars` consistent with `toplevel` (#1608)
Alex Lam S.L [Thu, 16 Mar 2017 05:22:26 +0000 (13:22 +0800)]
make `collapse_vars` consistent with `toplevel` (#1608)

fixes #1605

7 years agofix `hoist_vars` on `reduce_vars` (#1607)
Alex Lam S.L [Thu, 16 Mar 2017 04:03:30 +0000 (12:03 +0800)]
fix `hoist_vars` on `reduce_vars` (#1607)

`hoist_vars` converts variable declarations into plain assignments, which then confuses `reduce_vars`

fixes #1606

7 years agofix stack issues with `AST_Node.evaluate()` (#1603)
Alex Lam S.L [Wed, 15 Mar 2017 17:02:59 +0000 (01:02 +0800)]
fix stack issues with `AST_Node.evaluate()` (#1603)

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`.

7 years agofix `AST_Node.optimize()` (#1602)
Alex Lam S.L [Wed, 15 Mar 2017 10:44:13 +0000 (18:44 +0800)]
fix `AST_Node.optimize()` (#1602)

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.

7 years agominor clean-ups (#1600)
Alex Lam S.L [Tue, 14 Mar 2017 05:19:05 +0000 (13:19 +0800)]
minor clean-ups (#1600)

- remove obsolete optimisation in `AST_Binary` after #1477
- improve `TreeWalker.has_directive()` readability and resilience against multiple visits

7 years agov2.8.12
Alex Lam S.L [Fri, 10 Mar 2017 21:00:55 +0000 (05:00 +0800)]
v2.8.12

7 years agotemporary fix for boolean bug (#1597)
Alex Lam S.L [Fri, 10 Mar 2017 20:59:55 +0000 (04:59 +0800)]
temporary fix for boolean bug (#1597)

fixes #1592

7 years agodisallow parameter substitution for named IIFEs (#1596)
Alex Lam S.L [Fri, 10 Mar 2017 19:34:55 +0000 (03:34 +0800)]
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

7 years agosupport multi-line string in tests (#1590)
Alex Lam S.L [Fri, 10 Mar 2017 03:27:30 +0000 (11:27 +0800)]
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.

7 years agofixup for #1585 (#1589)
Alex Lam S.L [Fri, 10 Mar 2017 02:49:41 +0000 (10:49 +0800)]
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.

7 years agov2.8.11
Alex Lam S.L [Thu, 9 Mar 2017 20:17:21 +0000 (04:17 +0800)]
v2.8.11

7 years agofix catch variable reference in IE8 (#1587)
Alex Lam S.L [Thu, 9 Mar 2017 19:15:21 +0000 (03:15 +0800)]
fix catch variable reference in IE8 (#1587)

`AST_Scope.def_variable()` will overwrite `AST_Symbol.thedef`, so save a copy before calling.

fixes #1586

7 years agoCorrectly raise a parse exception with a missing loop body (#1585)
Michael Mior [Thu, 9 Mar 2017 19:08:43 +0000 (14:08 -0500)]
Correctly raise a parse exception with a missing loop body (#1585)

7 years agofix & improve function argument compression (#1584)
Alex Lam S.L [Thu, 9 Mar 2017 11:11:05 +0000 (19:11 +0800)]
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

7 years agov2.8.10
Alex Lam S.L [Wed, 8 Mar 2017 21:48:06 +0000 (05:48 +0800)]
v2.8.10

7 years agoscan RHS of dropped assignments (#1581)
Alex Lam S.L [Wed, 8 Mar 2017 21:22:27 +0000 (05:22 +0800)]
scan RHS of dropped assignments (#1581)

- similar case as #1578 but against #1450 instead
- fix `this` binding in #1450 as well

closes #1580

7 years agoremove checkboxes from Issues template
Alex Lam S.L [Wed, 8 Mar 2017 11:19:54 +0000 (19:19 +0800)]
remove checkboxes from Issues template

7 years agoexplain how to make a proper bug report (#1579)
Alex Lam S.L [Wed, 8 Mar 2017 10:56:01 +0000 (18:56 +0800)]
explain how to make a proper bug report (#1579)

fixes #1574

7 years agoscan assignment value in drop_unused() (#1578)
Alex Lam S.L [Wed, 8 Mar 2017 10:37:32 +0000 (18:37 +0800)]
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

7 years agov2.8.9
Alex Lam S.L [Wed, 8 Mar 2017 04:41:22 +0000 (12:41 +0800)]
v2.8.9

7 years agofix function name eliminiation (#1576)
Alex Lam S.L [Wed, 8 Mar 2017 04:39:57 +0000 (12:39 +0800)]
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

7 years agoonly run benchmark & jetstream on CI (#1571)
Alex Lam S.L [Tue, 7 Mar 2017 22:00:51 +0000 (06:00 +0800)]
only run benchmark & jetstream on CI (#1571)

7 years agoplan B for IE8 do-while semi-colon fix (#1572)
Alex Lam S.L [Tue, 7 Mar 2017 21:07:05 +0000 (05:07 +0800)]
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

7 years agofix return from recursive IIFE (#1570)
Alex Lam S.L [Tue, 7 Mar 2017 19:31:51 +0000 (03:31 +0800)]
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

7 years agov2.8.8
Alex Lam S.L [Tue, 7 Mar 2017 11:58:41 +0000 (19:58 +0800)]
v2.8.8

7 years agoinclude benchmark.js in test suite (#1564)
Alex Lam S.L [Tue, 7 Mar 2017 11:25:12 +0000 (19:25 +0800)]
include benchmark.js in test suite (#1564)

- report file sizes and overall run time
- exit with non-zero code upon error

7 years agofix deep cloning of labels (#1565)
Alex Lam S.L [Tue, 7 Mar 2017 10:38:27 +0000 (18:38 +0800)]
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.

7 years agotransform function calls to IIFEs (#1560)
Alex Lam S.L [Tue, 7 Mar 2017 07:37:52 +0000 (15:37 +0800)]
transform function calls to IIFEs (#1560)

- expose function body to call sites for potential optimisations
- suppress substitution of variable used within `AST_Defun`

7 years agoavoid substitution of global variables (#1557)
Alex Lam S.L [Mon, 6 Mar 2017 19:11:03 +0000 (03:11 +0800)]
avoid substitution of global variables (#1557)

- unless `toplevel` is enabled
- global `const` works as before

7 years agocollapse_vars: do not replace a constant in loop condition or init (#1562)
kzc [Mon, 6 Mar 2017 17:42:33 +0000 (12:42 -0500)]
collapse_vars: do not replace a constant in loop condition or init (#1562)

7 years agosuppress semicolons after do/while (#1556)
Alex Lam S.L [Mon, 6 Mar 2017 09:31:35 +0000 (17:31 +0800)]
suppress semicolons after do/while (#1556)

- unless both `beautify` & `screw-ie8` are enabled
- deprecate workaround for if-do-while-else

fixes #186

7 years agov2.8.7
Alex Lam S.L [Sun, 5 Mar 2017 09:17:08 +0000 (17:17 +0800)]
v2.8.7

7 years agofixup for #1553 (#1555)
Alex Lam S.L [Sun, 5 Mar 2017 09:15:37 +0000 (17:15 +0800)]
fixup for #1553 (#1555)

- `++a` is the one that is foldable
- transform `a++` into `++a` for better optimisation

7 years agov2.8.6
Alex Lam S.L [Sun, 5 Mar 2017 07:48:28 +0000 (15:48 +0800)]
v2.8.6

7 years agocollapse assignment with adjacent subsequent usage (#1553)
Alex Lam S.L [Sun, 5 Mar 2017 06:56:14 +0000 (14:56 +0800)]
collapse assignment with adjacent subsequent usage (#1553)

- consolidate `cascade` optimisations
- support ++/-- postfixes
- remove redundant optimisation identified in #1460

fixes #368

7 years agohandle variable declaration within catch blocks (#1546)
Alex Lam S.L [Sun, 5 Mar 2017 05:13:44 +0000 (13:13 +0800)]
handle variable declaration within catch blocks (#1546)

accounts for IE8- scoping

7 years agoimprove `unsafe` on undefined (#1548)
Alex Lam S.L [Sun, 5 Mar 2017 05:09:27 +0000 (13:09 +0800)]
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.

7 years agostay safe with constants in IE8- (#1547)
Alex Lam S.L [Sun, 5 Mar 2017 04:51:11 +0000 (12:51 +0800)]
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

7 years agofix handling of shebang and preamble (#1545)
Alex Lam S.L [Sun, 5 Mar 2017 04:16:02 +0000 (12:16 +0800)]
fix handling of shebang and preamble (#1545)

fixes #1332

7 years agofix a corner case in #1530 (#1552)
Alex Lam S.L [Sun, 5 Mar 2017 04:12:59 +0000 (12:12 +0800)]
fix a corner case in #1530 (#1552)

7 years agoresolve issue with outdated version of async (#1549)
Alex Lam S.L [Sat, 4 Mar 2017 17:54:20 +0000 (01:54 +0800)]
resolve issue with outdated version of async (#1549)

fixes #746

7 years agodisallow collapse_vars constant replacement in for-in statements (#1543)
kzc [Fri, 3 Mar 2017 18:39:54 +0000 (13:39 -0500)]
disallow collapse_vars constant replacement in for-in statements (#1543)

7 years agoprocess code with implicit return statement (#1522)
Alex Lam S.L [Fri, 3 Mar 2017 10:13:07 +0000 (18:13 +0800)]
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

7 years agocompress numerical expressions (#1513)
Alex Lam S.L [Fri, 3 Mar 2017 10:04:32 +0000 (18:04 +0800)]
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

7 years agofacilitate fix for #1531 (#1542)
Alex Lam S.L [Thu, 2 Mar 2017 23:12:24 +0000 (07:12 +0800)]
facilitate fix for #1531 (#1542)

7 years agov2.8.5
Alex Lam S.L [Thu, 2 Mar 2017 21:14:21 +0000 (05:14 +0800)]
v2.8.5

7 years agofix chained assignment with `unused` (#1540)
Alex Lam S.L [Thu, 2 Mar 2017 20:45:20 +0000 (04:45 +0800)]
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

7 years agocollapse_vars should not replace constant in for-in init section (#1538)
kzc [Thu, 2 Mar 2017 19:51:15 +0000 (14:51 -0500)]
collapse_vars should not replace constant in for-in init section (#1538)

fixes #1537

7 years agoproperly cover all cases of for-in loop variables (#1536)
Alex Lam S.L [Thu, 2 Mar 2017 18:39:57 +0000 (02:39 +0800)]
properly cover all cases of for-in loop variables (#1536)

7 years agofix reference marking in for-in loops (#1535)
Alex Lam S.L [Thu, 2 Mar 2017 16:56:06 +0000 (00:56 +0800)]
fix reference marking in for-in loops (#1535)

fixes #1533

7 years agodisable do{...}while(false) optimisation (#1534)
Alex Lam S.L [Thu, 2 Mar 2017 16:54:41 +0000 (00:54 +0800)]
disable do{...}while(false) optimisation (#1534)

- fails to handle `break` in body

fixes #1532

7 years agooptimize trivial IIFEs returning constants (#1530)
kzc [Thu, 2 Mar 2017 07:11:40 +0000 (02:11 -0500)]
optimize trivial IIFEs returning constants (#1530)

7 years agotrim unused invocation parameters (#1526)
Alex Lam S.L [Thu, 2 Mar 2017 03:33:59 +0000 (11:33 +0800)]
trim unused invocation parameters (#1526)

7 years agominor improvement to string optimisation (#1514)
Alex Lam S.L [Thu, 2 Mar 2017 03:31:39 +0000 (11:31 +0800)]
minor improvement to string optimisation (#1514)

- "" + "a"     => "a"
- "" + a + "b" => a + "b"
- "a" + ""     => "a" (improving on #45)

7 years agov2.8.4
Alex Lam S.L [Wed, 1 Mar 2017 16:24:49 +0000 (00:24 +0800)]
v2.8.4

7 years agofix corner cases in `reduce_vars` (#1524)
Alex Lam S.L [Wed, 1 Mar 2017 16:20:53 +0000 (00:20 +0800)]
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

7 years agov2.8.3
Alex Lam S.L [Wed, 1 Mar 2017 07:28:46 +0000 (15:28 +0800)]
v2.8.3

7 years agofix crash on missing `props` to `string_template()` (#1523)
Alex Lam S.L [Wed, 1 Mar 2017 07:25:26 +0000 (15:25 +0800)]
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

7 years agov2.8.2
Alex Lam S.L [Tue, 28 Feb 2017 20:46:12 +0000 (04:46 +0800)]
v2.8.2

7 years agoinvert `reduce_vars` tracking flag (#1519)
Alex Lam S.L [Tue, 28 Feb 2017 20:12:10 +0000 (04:12 +0800)]
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

7 years agofix `evaluate` on object getter & setter (#1515)
Alex Lam S.L [Tue, 28 Feb 2017 18:03:47 +0000 (02:03 +0800)]
fix `evaluate` on object getter & setter (#1515)

7 years agov2.8.1
Alex Lam S.L [Tue, 28 Feb 2017 16:27:08 +0000 (00:27 +0800)]
v2.8.1

7 years agotemporarily disables `reduce_vars` (#1517)
Alex Lam S.L [Tue, 28 Feb 2017 16:25:43 +0000 (00:25 +0800)]
temporarily disables `reduce_vars` (#1517)

... as we investigate #1516

7 years agowarn & drop `#__PURE__` iff IIFE is dropped (#1511)
Alex Lam S.L [Mon, 27 Feb 2017 18:25:44 +0000 (02:25 +0800)]
warn & drop `#__PURE__` iff IIFE is dropped (#1511)

- consolidate `side-effects` optimisations
- improve string `+` optimisation
- enhance literal & `conditionals` optimisations

7 years agov2.8.0
Alex Lam S.L [Sun, 26 Feb 2017 19:47:54 +0000 (03:47 +0800)]
v2.8.0

7 years agoimprove error messages (#1506)
Alex Lam S.L [Sun, 26 Feb 2017 19:40:54 +0000 (03:40 +0800)]
improve error messages (#1506)

- better inheritance of `Error` sub-classes
- mark parse error against source in CLI

closes #235
closes #348
closes #524
closes #1356
closes #1405

7 years agoadd harmony branch details in README (#1507)
kzc [Sun, 26 Feb 2017 17:55:24 +0000 (12:55 -0500)]
add harmony branch details in README (#1507)

7 years agofaster tree transversal (#1462)
Alex Lam S.L [Sat, 25 Feb 2017 21:58:26 +0000 (05:58 +0800)]
faster tree transversal (#1462)

- convert `[].forEach()` to for-loops

7 years agoconsolidate `evaluate` & `reduce_vars` (#1505)
Alex Lam S.L [Sat, 25 Feb 2017 16:40:33 +0000 (00:40 +0800)]
consolidate `evaluate` & `reduce_vars` (#1505)

- improve marking efficiency
- apply smarter `const` replacement to `var`

fixes #1501

7 years agoupdate docs for `pure_funcs` & `drop_console` (#1503)
Alex Lam S.L [Fri, 24 Feb 2017 20:13:10 +0000 (04:13 +0800)]
update docs for `pure_funcs` & `drop_console` (#1503)

closes #1362
closes #1399

7 years agoallow --in-source-map inline (#1490)
Alex Lam S.L [Fri, 24 Feb 2017 20:11:21 +0000 (04:11 +0800)]
allow --in-source-map inline (#1490)

- limited to one input file (or `stdin`)
- only works with built-in parser

fixes #520

7 years agoAvoid using exports when undefined (#1471)
Ondřej Španěl [Fri, 24 Feb 2017 00:51:24 +0000 (01:51 +0100)]
Avoid using exports when undefined (#1471)

Makes direct usage within web browser easier, even if officially unsupported.

7 years agoMerge pull request #1485 from alexlamsl/merge-2.8.0
Alex Lam S.L [Thu, 23 Feb 2017 23:33:57 +0000 (07:33 +0800)]
Merge pull request #1485 from alexlamsl/merge-2.8.0

2.8.0 staging

7 years agoenable `collapse_vars` & `reduce_vars` by default
alexlamsl [Thu, 23 Feb 2017 17:46:57 +0000 (01:46 +0800)]
enable `collapse_vars` & `reduce_vars` by default
- fix corner cases in `const` optimisation
- deprecate `/*@const*/`

fixes #1497
closes #1498

7 years agoSupport marking a call as pure
kzc [Tue, 21 Feb 2017 06:24:18 +0000 (14:24 +0800)]
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

7 years agoFix: AST_Accessor missing start / end tokens
Ondřej Španěl [Mon, 20 Feb 2017 09:14:53 +0000 (17:14 +0800)]
Fix: AST_Accessor missing start / end tokens

fixes #1492
closes #1493

7 years agofix `pure_funcs` & improve `side_effects`
alexlamsl [Sun, 19 Feb 2017 17:46:59 +0000 (01:46 +0800)]
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

7 years agoclean up `max_line_len`
alexlamsl [Sat, 18 Feb 2017 14:44:53 +0000 (22:44 +0800)]
clean up `max_line_len`
- never exceed specified limit
- otherwise warning is shown
- enabled only for final output

closes #1496

7 years agointroduce `unsafe_proto`
alexlamsl [Sat, 18 Feb 2017 11:34:54 +0000 (19:34 +0800)]
introduce `unsafe_proto`
- `Array.prototype.slice` => `[].slice`

closes #1491

7 years agoremove extraneous spaces between ++/+/--/-
alexlamsl [Sat, 18 Feb 2017 11:33:53 +0000 (19:33 +0800)]
remove extraneous spaces between ++/+/--/-

fixes #1377
closes #1488

7 years agoAdd .gitattributes to checkout lf eol style
Anthony Van de Gejuchte [Sat, 18 Feb 2017 11:33:05 +0000 (19:33 +0800)]
Add .gitattributes to checkout lf eol style

closes #1487

7 years agoimprove `--beautify bracketize`
alexlamsl [Sat, 18 Feb 2017 11:30:33 +0000 (19:30 +0800)]
improve `--beautify bracketize`
reduce whitespaces from if-else statements

fixes #1482
closes #1483

7 years agoadd benchmark & JetStream tests
alexlamsl [Sat, 18 Feb 2017 11:28:25 +0000 (19:28 +0800)]
add benchmark & JetStream tests
- `test/benchmark.js` measures performance
- `test/jetstream.js` verifies correctness
- configurable mangle/compress/output options

closes #1479

7 years agoenhance `global_defs`
alexlamsl [Sat, 18 Feb 2017 11:27:31 +0000 (19:27 +0800)]
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

7 years agoevaluate AST_SymbolRef as parameter
alexlamsl [Sat, 18 Feb 2017 11:22:24 +0000 (19:22 +0800)]
evaluate AST_SymbolRef as parameter
fix invalid boolean conversion now exposed in `make_node_from_constant()`

closes #1477

7 years agoimprove reduce_vars and fix a bug
alexlamsl [Sat, 18 Feb 2017 11:19:55 +0000 (19:19 +0800)]
improve reduce_vars and fix a bug
- update modified flag between compress() passes
- support IIFE arguments
- fix corner case with multiple definitions

closes #1473

7 years agoimprove keep_fargs & keep_fnames
alexlamsl [Sat, 18 Feb 2017 11:19:12 +0000 (19:19 +0800)]
improve keep_fargs & keep_fnames
- utilise in_use_ids instead of unreferenced()
- drop_unused now up-to-date for subsequent passes

closes #1476

7 years agofix duplicated test names
alexlamsl [Sat, 18 Feb 2017 11:15:09 +0000 (19:15 +0800)]
fix duplicated test names

previously test cases with the same name would be skipped except for the last one

`test/run-test.js` will now report duplicated names as errors

closes #1461

7 years agosmarter const replacement taking name length into account
kzc [Sat, 18 Feb 2017 11:12:57 +0000 (19:12 +0800)]
smarter const replacement taking name length into account

closes #1459

7 years agoclean up `negate_iife`
alexlamsl [Sat, 18 Feb 2017 11:11:57 +0000 (19:11 +0800)]
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

7 years agoimprove string concatenation
alexlamsl [Sat, 18 Feb 2017 11:07:52 +0000 (19:07 +0800)]
improve string concatenation
shuffle associative operations to minimise parentheses and aid other uglification efforts

closes #1454

7 years ago`-c sequences=N` suboptimal at N expression cutoff
alexlamsl [Sat, 18 Feb 2017 11:07:03 +0000 (19:07 +0800)]
`-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

7 years agotweak do-while loops
alexlamsl [Sat, 18 Feb 2017 11:05:54 +0000 (19:05 +0800)]
tweak do-while loops
- `do{...}while(false)` => `{...}`
- clean up `AST_While` logic

closes #1452

7 years agofixes & improvements to [].join()
alexlamsl [Sat, 18 Feb 2017 11:05:11 +0000 (19:05 +0800)]
fixes & improvements to [].join()

fixes
- [a].join() => "" + a
- ["a", , "b"].join() => "a,,b"
- ["a", null, "b"].join() => "a,,b"
- ["a", undefined, "b"].join() => "a,,b"

improvements
- ["a", "b"].join(null) => "anullb"
- ["a", "b"].join(undefined) => "a,b"
- [a + "b", c].join("") => a + "b" + c

closes #1453

7 years agodrop unused: toplevel, assign-only
alexlamsl [Sat, 18 Feb 2017 11:03:53 +0000 (19:03 +0800)]
drop unused: toplevel, assign-only
- assign statement does not count towards variable usage by default
- only works with assignments on the same scope level as declaration
- can be disabled with `unused` set to "keep_assign"
- `toplevel` to drop unused top-level variables and/or functions
- `top_retain` to whitelist top-level exceptions

closes #1450

7 years agofix stray else in compress with conditionals=false
kzc [Sat, 18 Feb 2017 11:02:59 +0000 (19:02 +0800)]
fix stray else in compress with conditionals=false

closes #1449

7 years agoenable typeof "undefined" for general use
alexlamsl [Sat, 18 Feb 2017 11:01:42 +0000 (19:01 +0800)]
enable typeof "undefined" for general use
move out of unsafe, guard corner case with screw_id8 instead

closes #1446

7 years agofix corner case in keep_fnames
alexlamsl [Sat, 18 Feb 2017 11:00:54 +0000 (19:00 +0800)]
fix corner case in keep_fnames
happens when inner function:
- just below top level
- not referenced
- `unused` is disabled

closes #1445

7 years agoremove unused AST_Scope.nesting & AST_SymbolRef.frame
alexlamsl [Sat, 18 Feb 2017 10:59:40 +0000 (18:59 +0800)]
remove unused AST_Scope.nesting & AST_SymbolRef.frame
they are computed but never used

closes #1444