aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/compress.js4
-rw-r--r--test/compress/functions.js2
-rw-r--r--test/compress/issue-1321.js18
-rw-r--r--test/compress/issue-1770.js66
-rw-r--r--test/compress/issue-747.js14
-rw-r--r--test/compress/properties.js22
-rw-r--r--test/mocha/let.js28
-rwxr-xr-xtest/run-tests.js12
8 files changed, 91 insertions, 75 deletions
diff --git a/lib/compress.js b/lib/compress.js
index c24510f6..b9922e18 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -3114,7 +3114,9 @@ merge(Compressor.prototype, {
var comp = new Compressor(compressor.options);
ast = ast.transform(comp);
ast.figure_out_scope(mangle);
- ast.mangle_names();
+ base54.reset();
+ ast.compute_char_frequency(mangle);
+ ast.mangle_names(mangle);
var fun;
ast.walk(new TreeWalker(function(node) {
if (fun) return true;
diff --git a/test/compress/functions.js b/test/compress/functions.js
index d2640bb9..b5def8e1 100644
--- a/test/compress/functions.js
+++ b/test/compress/functions.js
@@ -265,7 +265,7 @@ issue_203: {
}
expect: {
var m = {};
- var fn = Function("a", "b", "b.exports=42");
+ var fn = Function("n", "o", "o.exports=42");
fn(null, m, m.exports);
console.log(m.exports);
}
diff --git a/test/compress/issue-1321.js b/test/compress/issue-1321.js
index dcbfde64..6b92291d 100644
--- a/test/compress/issue-1321.js
+++ b/test/compress/issue-1321.js
@@ -10,9 +10,9 @@ issue_1321_no_debug: {
}
expect: {
var x = {};
- x.b = 1;
- x["a"] = 2 * x.b;
- console.log(x.b, x["a"]);
+ x.o = 1;
+ x["a"] = 2 * x.o;
+ console.log(x.o, x["a"]);
}
expect_stdout: true
}
@@ -30,9 +30,9 @@ issue_1321_debug: {
}
expect: {
var x = {};
- x.a = 1;
- x["_$foo$_"] = 2 * x.a;
- console.log(x.a, x["_$foo$_"]);
+ x.o = 1;
+ x["_$foo$_"] = 2 * x.o;
+ console.log(x.o, x["_$foo$_"]);
}
expect_stdout: true
}
@@ -49,9 +49,9 @@ issue_1321_with_quoted: {
}
expect: {
var x = {};
- x.a = 1;
- x["b"] = 2 * x.a;
- console.log(x.a, x["b"]);
+ x.o = 1;
+ x["x"] = 2 * x.o;
+ console.log(x.o, x["x"]);
}
expect_stdout: true
}
diff --git a/test/compress/issue-1770.js b/test/compress/issue-1770.js
index 24134f81..f296a403 100644
--- a/test/compress/issue-1770.js
+++ b/test/compress/issue-1770.js
@@ -82,7 +82,7 @@ numeric_literal: {
' 42: 2,',
' "42": 3,',
' 37: 4,',
- ' a: 5,',
+ ' o: 5,',
' 1e42: 6,',
' b: 7,',
' "1e+42": 8',
@@ -92,7 +92,7 @@ numeric_literal: {
'',
'console.log(obj[42], obj["42"]);',
'',
- 'console.log(obj[37], obj["a"], obj[37], obj["37"]);',
+ 'console.log(obj[37], obj["o"], obj[37], obj["37"]);',
'',
'console.log(obj[1e42], obj["b"], obj["1e+42"]);',
]
@@ -173,32 +173,32 @@ identifier: {
}
expect: {
var obj = {
- a: 1,
- b: 2,
- c: 3,
- d: 4,
- e: 5,
- f: 6,
- g: 7,
- h: 8,
- i: 9,
- j: 10,
- k: 11,
- l: 12,
- m: 13,
- n: 14,
- o: 15,
- p: 16,
- q: 17,
- r: 18,
- s: 19,
- t: 20,
- u: 21,
- v: 22,
- w: 23,
- x: 24,
- y: 25,
- z: 26,
+ e: 1,
+ t: 2,
+ n: 3,
+ a: 4,
+ i: 5,
+ o: 6,
+ r: 7,
+ l: 8,
+ s: 9,
+ c: 10,
+ f: 11,
+ u: 12,
+ d: 13,
+ h: 14,
+ p: 15,
+ b: 16,
+ v: 17,
+ w: 18,
+ y: 19,
+ g: 20,
+ m: 21,
+ k: 22,
+ x: 23,
+ j: 24,
+ z: 25,
+ q: 26,
A: 27,
B: 28,
C: 29,
@@ -229,11 +229,11 @@ identifier: {
Z: 54,
$: 55,
_: 56,
- aa: 57,
- ba: 58,
- ca: 59,
- da: 60,
- ea: 61,
+ ee: 57,
+ te: 58,
+ ne: 59,
+ ae: 60,
+ ie: 61,
};
}
}
diff --git a/test/compress/issue-747.js b/test/compress/issue-747.js
index 0a4e4502..1f7079c2 100644
--- a/test/compress/issue-747.js
+++ b/test/compress/issue-747.js
@@ -1,37 +1,41 @@
dont_reuse_prop: {
mangle_props = {
regex: /asd/
- };
-
+ }
input: {
+ "aaaaaaaaaabbbbb";
var obj = {};
obj.a = 123;
obj.asd = 256;
console.log(obj.a);
}
expect: {
+ "aaaaaaaaaabbbbb";
var obj = {};
obj.a = 123;
obj.b = 256;
console.log(obj.a);
}
+ expect_stdout: "123"
}
unmangleable_props_should_always_be_reserved: {
mangle_props = {
regex: /asd/
- };
-
+ }
input: {
+ "aaaaaaaaaabbbbb";
var obj = {};
obj.asd = 256;
obj.a = 123;
console.log(obj.a);
}
expect: {
+ "aaaaaaaaaabbbbb";
var obj = {};
obj.b = 256;
obj.a = 123;
console.log(obj.a);
}
-} \ No newline at end of file
+ expect_stdout: "123"
+}
diff --git a/test/compress/properties.js b/test/compress/properties.js
index a83acc10..8126d6c6 100644
--- a/test/compress/properties.js
+++ b/test/compress/properties.js
@@ -135,11 +135,11 @@ mangle_properties: {
a['run']({color: "blue", foo: "baz"});
}
expect: {
- a["a"] = "bar";
- a.b = "red";
- x = {c: 10};
- a.d(x.c, a.a);
- a['d']({b: "blue", a: "baz"});
+ a["o"] = "bar";
+ a.a = "red";
+ x = {r: 10};
+ a.b(x.r, a.o);
+ a['b']({a: "blue", o: "baz"});
}
}
@@ -177,16 +177,16 @@ mangle_unquoted_properties: {
function f1() {
a["foo"] = "bar";
a.color = "red";
- a.b = 2;
- x = {"bar": 10, c: 7};
- a.c = 9;
+ a.o = 2;
+ x = {"bar": 10, f: 7};
+ a.f = 9;
}
function f2() {
a.foo = "bar";
a['color'] = "red";
- x = {bar: 10, c: 7};
- a.c = 9;
- a.b = 3;
+ x = {bar: 10, f: 7};
+ a.f = 9;
+ a.o = 3;
}
}
}
diff --git a/test/mocha/let.js b/test/mocha/let.js
index f41fd59b..23909986 100644
--- a/test/mocha/let.js
+++ b/test/mocha/let.js
@@ -2,29 +2,37 @@ var Uglify = require('../../');
var assert = require("assert");
describe("let", function() {
- it("Should not produce `let` as a variable name in mangle", function(done) {
+ it("Should not produce reserved keywords as variable name in mangle", function(done) {
this.timeout(10000);
// Produce a lot of variables in a function and run it through mangle.
- var s = '"use strict"; function foo() {';
- for (var i = 0; i < 21000; ++i) {
+ var s = '"dddddeeeeelllllooooottttt"; function foo() {';
+ for (var i = 0; i < 18000; i++) {
s += "var v" + i + "=0;";
}
s += '}';
var result = Uglify.minify(s, {compress: false});
// Verify that select keywords and reserved keywords not produced
- assert.strictEqual(result.code.indexOf("var let="), -1);
- assert.strictEqual(result.code.indexOf("var do="), -1);
- assert.strictEqual(result.code.indexOf("var var="), -1);
+ [
+ "do",
+ "let",
+ "var",
+ ].forEach(function(name) {
+ assert.strictEqual(result.code.indexOf("var " + name + "="), -1);
+ });
// Verify that the variable names that appeared immediately before
- // and after the erroneously generated `let` variable name still exist
+ // and after the erroneously generated variable name still exist
// to show the test generated enough symbols.
- assert(result.code.indexOf("var ket=") >= 0);
- assert(result.code.indexOf("var met=") >= 0);
+ [
+ "to", "eo",
+ "eet", "fet",
+ "rar", "oar",
+ ].forEach(function(name) {
+ assert.ok(result.code.indexOf("var " + name + "=") >= 0);
+ });
done();
});
});
-
diff --git a/test/run-tests.js b/test/run-tests.js
index 71ffe72a..6b8c9ddf 100755
--- a/test/run-tests.js
+++ b/test/run-tests.js
@@ -86,7 +86,6 @@ function run_compress_tests() {
log_start_file(file);
function test_case(test) {
log_test(test.name);
- U.base54.reset();
var output_options = test.beautify || {};
var expect;
if (test.expect) {
@@ -101,9 +100,6 @@ function run_compress_tests() {
quote_style: 3,
keep_quoted_props: true
});
- if (test.mangle_props) {
- input = U.mangle_properties(input, test.mangle_props);
- }
var options = U.defaults(test.options, {
warnings: false
});
@@ -118,10 +114,16 @@ function run_compress_tests() {
var cmp = new U.Compressor(options, true);
var output = cmp.compress(input);
output.figure_out_scope(test.mangle);
- if (test.mangle) {
+ if (test.mangle || test.mangle_props) {
+ U.base54.reset();
output.compute_char_frequency(test.mangle);
+ }
+ if (test.mangle) {
output.mangle_names(test.mangle);
}
+ if (test.mangle_props) {
+ output = U.mangle_properties(output, test.mangle_props);
+ }
output = make_code(output, output_options);
if (expect != output) {
log("!!! failed\n---INPUT---\n{input}\n---OUTPUT---\n{output}\n---EXPECTED---\n{expected}\n\n", {