aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMihai Bazon <mihai.bazon@gmail.com>2015-03-20 10:28:51 +0200
committerMihai Bazon <mihai.bazon@gmail.com>2015-03-20 10:28:51 +0200
commitecfd881ac6f4f62b5e8a15664fccc86271c0d003 (patch)
tree25f175908811bb2b4d7452dd0b566eeedd6ba6fb
parentd36faffecae72e40ad71585334fd93d56479b820 (diff)
downloadtracifyjs-ecfd881ac6f4f62b5e8a15664fccc86271c0d003.tar.gz
tracifyjs-ecfd881ac6f4f62b5e8a15664fccc86271c0d003.zip
Keep unused function arguments by default
Discarding unused function arguments affects function.length, which can lead to some hard to debug issues. This optimization is now done only in "unsafe mode". Fix #121
-rw-r--r--README.md5
-rw-r--r--lib/compress.js2
-rw-r--r--test/compress/drop-unused.js8
3 files changed, 8 insertions, 7 deletions
diff --git a/README.md b/README.md
index 2bb21385..a84fce88 100644
--- a/README.md
+++ b/README.md
@@ -272,14 +272,15 @@ contrived cases, but should be fine for most code. You might want to try it
on your own code, it should reduce the minified size. Here's what happens
when this flag is on:
-- `new Array(1, 2, 3)` or `Array(1, 2, 3)` → `[1, 2, 3 ]`
+- `new Array(1, 2, 3)` or `Array(1, 2, 3)` → `[ 1, 2, 3 ]`
- `new Object()` → `{}`
- `String(exp)` or `exp.toString()` → `"" + exp`
- `new Object/RegExp/Function/Error/Array (...)` → we discard the `new`
- `typeof foo == "undefined"` → `foo === void 0`
- `void 0` → `undefined` (if there is a variable named "undefined" in
scope; we do it because the variable name will be mangled, typically
- reduced to a single character).
+ reduced to a single character)
+- discards unused function arguments (affects `function.length`)
### Conditional compilation
diff --git a/lib/compress.js b/lib/compress.js
index b77b5ff3..4636716e 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1086,7 +1086,7 @@ merge(Compressor.prototype, {
var tt = new TreeTransformer(
function before(node, descend, in_list) {
if (node instanceof AST_Lambda && !(node instanceof AST_Accessor)) {
- if (!compressor.option("keep_fargs")) {
+ if (compressor.option("unsafe") && !compressor.option("keep_fargs")) {
for (var a = node.argnames, i = a.length; --i >= 0;) {
var sym = a[i];
if (sym.unreferenced()) {
diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js
index de4b2220..c1cf5c3c 100644
--- a/test/compress/drop-unused.js
+++ b/test/compress/drop-unused.js
@@ -1,5 +1,5 @@
unused_funarg_1: {
- options = { unused: true };
+ options = { unused: true, unsafe: true };
input: {
function f(a, b, c, d, e) {
return a + b;
@@ -13,7 +13,7 @@ unused_funarg_1: {
}
unused_funarg_2: {
- options = { unused: true };
+ options = { unused: true, unsafe: true };
input: {
function f(a, b, c, d, e) {
return a + c;
@@ -165,7 +165,7 @@ used_var_in_catch: {
}
keep_fnames: {
- options = { unused: true, keep_fnames: true };
+ options = { unused: true, keep_fnames: true, unsafe: true };
input: {
function foo() {
return function bar(baz) {};
@@ -176,4 +176,4 @@ keep_fnames: {
return function bar() {};
}
}
-} \ No newline at end of file
+}