Skip to content

Commit

Permalink
Merge pull request #1601 from alexlamsl/harmony-v2.8.12
Browse files Browse the repository at this point in the history
Merging from master for 2.8.12
  • Loading branch information
alexlamsl authored Mar 14, 2017
2 parents 1dd339f + 8f7ab60 commit 2fd86d3
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 14 deletions.
3 changes: 2 additions & 1 deletion lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ merge(Compressor.prototype, {
}
var iife;
if (node instanceof AST_Function
&& !node.name
&& (iife = tw.parent()) instanceof AST_Call
&& iife.expression === node) {
// Virtually turn IIFE parameters into variable definitions:
Expand Down Expand Up @@ -408,7 +409,7 @@ merge(Compressor.prototype, {

return make_node(AST_Number, orig, { value: val });
case "boolean":
return make_node(val ? AST_True : AST_False, orig).transform(compressor);
return make_node(val ? AST_True : AST_False, orig).optimize(compressor);
case "undefined":
return make_node(AST_Undefined, orig).transform(compressor);
default:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"homepage": "http://lisperator.net/uglifyjs",
"author": "Mihai Bazon <[email protected]> (http://lisperator.net/)",
"license": "BSD-2-Clause",
"version": "2.8.11",
"version": "2.8.12",
"engines": {
"node": ">=0.8.0"
},
Expand Down
50 changes: 46 additions & 4 deletions test/compress/loops.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,15 @@ issue_186_beautify: {
else
bar();
}
expect_exact: 'var x = 3;\n\nif (foo()) do {\n do {\n alert(x);\n } while (--x);\n} while (x); else bar();'
expect_exact: [
'var x = 3;',
'',
'if (foo()) do {',
' do {',
' alert(x);',
' } while (--x);',
'} while (x); else bar();',
]
}

issue_186_beautify_ie8: {
Expand All @@ -314,7 +322,17 @@ issue_186_beautify_ie8: {
else
bar();
}
expect_exact: 'var x = 3;\n\nif (foo()) {\n do {\n do {\n alert(x);\n } while (--x);\n } while (x);\n} else bar();'
expect_exact: [
'var x = 3;',
'',
'if (foo()) {',
' do {',
' do {',
' alert(x);',
' } while (--x);',
' } while (x);',
'} else bar();',
]
}

issue_186_bracketize: {
Expand Down Expand Up @@ -374,7 +392,19 @@ issue_186_beautify_bracketize: {
else
bar();
}
expect_exact: 'var x = 3;\n\nif (foo()) {\n do {\n do {\n alert(x);\n } while (--x);\n } while (x);\n} else {\n bar();\n}'
expect_exact: [
'var x = 3;',
'',
'if (foo()) {',
' do {',
' do {',
' alert(x);',
' } while (--x);',
' } while (x);',
'} else {',
' bar();',
'}',
]
}

issue_186_beautify_bracketize_ie8: {
Expand All @@ -394,5 +424,17 @@ issue_186_beautify_bracketize_ie8: {
else
bar();
}
expect_exact: 'var x = 3;\n\nif (foo()) {\n do {\n do {\n alert(x);\n } while (--x);\n } while (x);\n} else {\n bar();\n}'
expect_exact: [
'var x = 3;',
'',
'if (foo()) {',
' do {',
' do {',
' alert(x);',
' } while (--x);',
' } while (x);',
'} else {',
' bar();',
'}',
]
}
15 changes: 13 additions & 2 deletions test/compress/max_line_len.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ too_short: {
return { c: 42, d: a(), e: "foo"};
}
}
expect_exact: 'function f(a){\nreturn{\nc:42,\nd:a(),\ne:"foo"}}'
expect_exact: [
'function f(a){',
'return{',
'c:42,',
'd:a(),',
'e:"foo"}}',
]
expect_warnings: [
"WARN: Output exceeds 10 characters"
]
Expand All @@ -22,7 +28,12 @@ just_enough: {
return { c: 42, d: a(), e: "foo"};
}
}
expect_exact: 'function f(a){\nreturn{c:42,\nd:a(),e:"foo"}\n}'
expect_exact: [
'function f(a){',
'return{c:42,',
'd:a(),e:"foo"}',
'}',
]
expect_warnings: [
]
}
75 changes: 75 additions & 0 deletions test/compress/reduce_vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -1252,3 +1252,78 @@ iife_func_side_effects: {
})(x(), 0, z());
}
}

issue_1595_1: {
options = {
evaluate: true,
reduce_vars: true,
unused: true,
}
input: {
(function f(a) {
return f(a + 1);
})(2);
}
expect: {
(function f(a) {
return f(a + 1);
})(2);
}
}

issue_1595_2: {
options = {
evaluate: true,
reduce_vars: true,
unused: true,
}
input: {
(function f(a) {
return g(a + 1);
})(2);
}
expect: {
(function(a) {
return g(a + 1);
})(2);
}
}

issue_1595_3: {
options = {
evaluate: true,
passes: 2,
reduce_vars: true,
unused: true,
}
input: {
(function f(a) {
return g(a + 1);
})(2);
}
expect: {
(function(a) {
return g(3);
})();
}
}

issue_1595_4: {
options = {
evaluate: true,
reduce_vars: true,
unused: true,
}
input: {
(function iife(a, b, c) {
console.log(a, b, c);
if (a) iife(a - 1, b, c);
})(3, 4, 5);
}
expect: {
(function iife(a, b, c) {
console.log(a, b, c);
if (a) iife(a - 1, b, c);
})(3, 4, 5);
}
}
24 changes: 18 additions & 6 deletions test/run-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,23 @@ function parse_test(file) {
}));
}

function read_string(stat) {
if (stat.TYPE === "SimpleStatement") {
var body = stat.body;
out: switch(body.TYPE) {
case "String":
return body.value;
case "Array":
return body.elements.map(function(element) {
if (element.TYPE !== "String")
throw new Error("Should be array of strings");
return element.value;
}).join("\n");
}
}
throw new Error("Should be string or array of strings");
}

function get_one_test(name, block) {
var test = { name: name, options: {} };
var tw = new U.TreeWalker(function(node, descend){
Expand All @@ -240,12 +257,7 @@ function parse_test(file) {
else if (stat.body.length == 0) stat = new U.AST_EmptyStatement();
}
if (node.label.name === "expect_exact") {
if (!(stat.TYPE === "SimpleStatement" && stat.body.TYPE === "String")) {
throw new Error(
"The value of the expect_exact clause should be a string, " +
"like `expect_exact: \"some.exact.javascript;\"`");
}
test[node.label.name] = stat.body.start.value
test[node.label.name] = read_string(stat);
} else {
test[node.label.name] = stat;
}
Expand Down

0 comments on commit 2fd86d3

Please sign in to comment.