Compare commits

...

3 Commits

Author SHA1 Message Date
Alex Lam S.L
ae740b933f v2.8.18 2017-03-29 03:13:30 +08:00
Alex Lam S.L
ec7f37f314 remove UGLIFY_DEBUG (#1720)
fixes #1719
2017-03-29 01:27:24 +08:00
Alex Lam S.L
eb48a035e7 fix corner case in unused (#1718)
When fixing catch-related issue in #1715, it tries to optimise for duplicate definitions but did not take anonymous functions into account.

Remove such optimisation for now and we can cover this as a more general rule later.
2017-03-29 01:00:21 +08:00
6 changed files with 36 additions and 15 deletions

View File

@@ -1896,8 +1896,7 @@ merge(Compressor.prototype, {
if (def.value) def.value = def.value.transform(tt); if (def.value) def.value = def.value.transform(tt);
var sym = def.name.definition(); var sym = def.name.definition();
if (sym.id in in_use_ids) return true; if (sym.id in in_use_ids) return true;
if (sym.orig[0] instanceof AST_SymbolCatch if (sym.orig[0] instanceof AST_SymbolCatch) {
&& sym.scope.parent_scope.find_variable(def.name).orig[0] === def.name) {
def.value = def.value && def.value.drop_side_effect_free(compressor); def.value = def.value && def.value.drop_side_effect_free(compressor);
return true; return true;
} }

View File

@@ -4,7 +4,7 @@
"homepage": "http://lisperator.net/uglifyjs", "homepage": "http://lisperator.net/uglifyjs",
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)", "author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
"license": "BSD-2-Clause", "license": "BSD-2-Clause",
"version": "2.8.17", "version": "2.8.18",
"engines": { "engines": {
"node": ">=0.8.0" "node": ">=0.8.0"
}, },

View File

@@ -931,3 +931,30 @@ issue_1715_3: {
} }
expect_stdout: "1" expect_stdout: "1"
} }
issue_1715_4: {
options = {
unused: true,
}
input: {
var a = 1;
!function a() {
a++;
try {} catch (a) {
var a;
}
}();
console.log(a);
}
expect: {
var a = 1;
!function() {
a++;
try {} catch (a) {
var a;
}
}();
console.log(a);
}
expect_stdout: "1"
}

View File

@@ -176,7 +176,7 @@ describe("Directives", function() {
}); });
it("Should test EXPECT_DIRECTIVE RegExp", function() { it("Should test EXPECT_DIRECTIVE RegExp", function() {
var tests = [ [
["", true], ["", true],
["'test';", true], ["'test';", true],
["'test';;", true], ["'test';;", true],
@@ -185,11 +185,12 @@ describe("Directives", function() {
["'tests'; \n\t", true], ["'tests'; \n\t", true],
["'tests';\n\n", true], ["'tests';\n\n", true],
["\n\n\"use strict\";\n\n", true] ["\n\n\"use strict\";\n\n", true]
]; ].forEach(function(test) {
var out = uglify.OutputStream();
for (var i = 0; i < tests.length; i++) { out.print(test[0]);
assert.strictEqual(uglify.EXPECT_DIRECTIVE.test(tests[i][0]), tests[i][1], tests[i][0]); out.print_string("", null, true);
} assert.strictEqual(out.get() === test[0] + ';""', test[1], test[0]);
});
}); });
it("Should only print 2 semicolons spread over 2 lines in beautify mode", function() { it("Should only print 2 semicolons spread over 2 lines in beautify mode", function() {

View File

@@ -1,7 +1,5 @@
#! /usr/bin/env node #! /usr/bin/env node
global.UGLIFY_DEBUG = true;
var U = require("../tools/node"); var U = require("../tools/node");
var path = require("path"); var path = require("path");
var fs = require("fs"); var fs = require("fs");

View File

@@ -17,7 +17,3 @@ exports["string_template"] = string_template;
exports["tokenizer"] = tokenizer; exports["tokenizer"] = tokenizer;
exports["is_identifier"] = is_identifier; exports["is_identifier"] = is_identifier;
exports["SymbolDef"] = SymbolDef; exports["SymbolDef"] = SymbolDef;
if (global.UGLIFY_DEBUG) {
exports["EXPECT_DIRECTIVE"] = EXPECT_DIRECTIVE;
}