Compare commits

...

74 Commits

Author SHA1 Message Date
Alex Lam S.L
a9ef659bcb v3.15.5 2022-05-11 05:26:10 +08:00
Alex Lam S.L
35c2149dbd fix corner case in merge_vars (#5437)
fixes #5436
2022-05-08 04:16:28 +08:00
Alex Lam S.L
89a35f9fcd fix corner case in reduce_vars (#5435)
fixes #5434
2022-05-06 09:32:47 +08:00
Alex Lam S.L
1a4e99dc2d avoid v8 quirks in ufuzz (#5431)
closes #5428
closes #5429
2022-04-25 21:33:31 +08:00
Alex Lam S.L
cb870f6fd6 document v8 quirks (#5430)
closes #5428
closes #5429
2022-04-21 02:51:53 +08:00
Alex Lam S.L
a0c0c294c5 fix corner case in assignments (#5426)
fixes #5425
2022-04-19 13:19:30 +08:00
Alex Lam S.L
fbdb7eeda3 fix corner case in merge_vars (#5424)
fixes #5423
2022-04-19 09:04:06 +08:00
Alex Lam S.L
1bc0fccc8c improve ufuzz resilience (#5422) 2022-04-18 13:03:01 +08:00
Alex Lam S.L
20252c6483 fix corner case in merge_vars (#5421)
fixes #5420
2022-04-18 06:38:08 +08:00
Alex Lam S.L
e396912ea2 suppress false positives with export & import (#5418) 2022-04-16 04:27:50 +08:00
Alex Lam S.L
5ebfa78f56 fix corner case with arguments (#5417)
fixes #5416
2022-04-15 06:52:10 +08:00
Alex Lam S.L
950609f578 fix corner case in inline (#5415)
fixes #5414
2022-04-13 06:19:37 +08:00
Alex Lam S.L
4a44d95f09 v3.15.4 2022-04-10 01:16:11 +08:00
David Luhmer
36718948be rename reserved keyword await (#5413) 2022-04-08 00:31:29 +08:00
Alex Lam S.L
21bd4c4a9d fix corner cases in collapse_vars & hoist_vars (#5412)
fixes #5411
2022-04-07 04:12:03 +08:00
Alex Lam S.L
998c9792da fix corner case in inline (#5410)
fixes #5409
2022-04-06 12:23:47 +08:00
Alex Lam S.L
ccd77d70db fix corner case in reduce_vars (#5408)
fixes #5407
2022-04-05 10:09:25 +08:00
Alex Lam S.L
d75a946707 fix corner case in reduce_vars (#5406)
fixes #5405
2022-04-03 21:57:37 +08:00
Alex Lam S.L
696a20f10d patch export default within sandbox correctly (#5404)
fixes #5403
2022-04-03 19:56:19 +08:00
Alex Lam S.L
224c91b6c1 fix corner case in inline (#5402)
fixes #5401
2022-04-03 01:12:53 +08:00
Alex Lam S.L
8065e27a7d patch export default within sandbox correctly (#5400)
fixes #5399
2022-04-02 21:59:28 +08:00
Alex Lam S.L
584e253f33 enahnce collapse_vars (#5398) 2022-04-01 20:26:27 +08:00
Alex Lam S.L
fb5e08e4ec fix corner case in collapse_vars (#5397)
fixes #5396
2022-03-31 20:02:56 +08:00
Alex Lam S.L
e3d328f741 fix corner case in collapse_vars (#5395)
fixes #5394
2022-03-30 01:22:57 +08:00
Alex Lam S.L
8922f08fbf fix corner cases in keep_fnames (#5393) 2022-03-29 03:01:01 +08:00
Alex Lam S.L
15a4074d1a fix corner case in unused (#5392)
fixes #5391
2022-03-28 05:46:43 +08:00
Alex Lam S.L
c624b43739 fix corner case in collapse_vars (#5390)
fixes #5389
2022-03-22 13:05:57 +08:00
Alex Lam S.L
a8e040b133 fix corner case in properties (#5388)
fixes #5387
2022-03-21 00:01:42 +08:00
Alex Lam S.L
5e30f3a48b fix corner case in inline (#5386)
fixes #5385
2022-03-20 22:50:28 +08:00
Alex Lam S.L
46570a4eb6 fix corner case in side_effects (#5383)
fixes #5382
2022-03-12 14:14:30 +08:00
Alex Lam S.L
01b84074d7 fix corner case in evaluate (#5381)
fixes #5380
2022-03-12 13:08:29 +08:00
Alex Lam S.L
7aba2dc5f2 v3.15.3 2022-03-10 12:50:19 +08:00
Alex Lam S.L
12a6728c4e fix corner case in hoist_vars (#5379)
fixes #5378
2022-03-06 17:56:00 +08:00
Alex Lam S.L
042c228c7b fix corner case in inline (#5377)
fixes #5376
2022-03-06 03:29:56 +08:00
Alex Lam S.L
e2b00814a8 fix corner cases in inline (#5375) 2022-03-04 04:05:31 +08:00
Alex Lam S.L
104d385ba9 fix corner case in ie (#5372)
fixes #5370
2022-03-02 13:52:27 +08:00
Alex Lam S.L
fdbbef2991 enhance conditionals (#5371) 2022-03-02 11:00:37 +08:00
Alex Lam S.L
f8edf05c3c v3.15.2 2022-02-26 20:41:02 +08:00
Alex Lam S.L
a9d0ddea9d fix corner case in directives & expression (#5369)
fixes #5368
2022-02-24 05:04:04 +08:00
Alex Lam S.L
313e4974a4 fix corner case in inline (#5367)
fixes #5366
2022-02-21 11:31:29 +08:00
Alex Lam S.L
dd3b81dec6 enhance booleans (#5365) 2022-02-21 11:02:19 +08:00
Alex Lam S.L
d5afe16bc8 enhance booleans & evaluate (#5364) 2022-02-21 01:25:37 +08:00
Alex Lam S.L
212ce4608e fix corner case in evaluate (#5363)
fixes #5362
2022-02-20 21:38:04 +08:00
Alex Lam S.L
fbc5ecf75a fix corner case in unused (#5361)
fixes #5360
2022-02-20 02:26:51 +08:00
Alex Lam S.L
a7d06167a0 enhance mangle (#5359) 2022-02-19 14:02:40 +08:00
Alex Lam S.L
9686379884 enhance comparisons (#5358) 2022-02-19 04:27:17 +08:00
Alex Lam S.L
82e8ebd77d fix corner case in evaluate (#5357)
fixes #5356
2022-02-15 16:28:49 +00:00
Alex Lam S.L
0b50880b4f fix corner case in evaluate & unsafe (#5355)
fixes #5354
2022-02-15 14:47:22 +08:00
Alex Lam S.L
316245ee12 fix corner case in merge_vars (#5353)
fixes #5352
2022-02-13 08:22:34 +08:00
Alex Lam S.L
63b92ead4e fix corner case in properties (#5351)
fixes #5350
2022-02-13 06:09:33 +08:00
Alex Lam S.L
a14555a39e enhance conditionals, if_return & side_effects (#5348) 2022-02-12 23:18:07 +08:00
Alex Lam S.L
6d0bb58d68 enhance merge_vars (#5349) 2022-02-12 20:41:02 +08:00
Alex Lam S.L
33c163f648 patch export default within sandbox correctly (#5346)
fixes #5345
2022-02-10 16:07:40 +08:00
Alex Lam S.L
b6c72c84d4 reduce overlap of sequences & side_effects (#5344) 2022-02-08 00:29:04 +08:00
Alex Lam S.L
327e94a759 v3.15.1 2022-02-07 10:15:48 +08:00
Alex Lam S.L
6fb7de7787 fix corner case in inline (#5343)
fixes #5342
2022-02-05 13:19:42 +08:00
Alex Lam S.L
d338e45033 add test case for unused (#5341)
closes #5340
2022-02-04 10:36:54 +08:00
Alex Lam S.L
b106cd9476 fix corner case in unused (#5339)
fixes #5338
2022-02-04 07:13:23 +08:00
Alex Lam S.L
9a91a7a4dc fix corner case in default_values (#5337)
fixes #5336
2022-02-04 05:44:25 +08:00
Alex Lam S.L
fa30960b8b fix corner case in conditionals (#5335)
fixes #5334
2022-02-04 01:48:30 +08:00
Alex Lam S.L
8ceb4b0492 fix corner case in inline (#5333)
fixes #5332
2022-02-03 13:13:35 +08:00
Alex Lam S.L
aad5d6e122 enhance if_return (#5330) 2022-02-02 08:13:38 +08:00
Alex Lam S.L
77552d9e69 fix corner case in inline (#5329)
fixes #5328
2022-02-01 19:35:03 +08:00
Alex Lam S.L
93105f1a6d suppress false positives in ufuzz (#5327) 2022-02-01 12:17:47 +08:00
Alex Lam S.L
d7eb80b050 enhance if_return (#5326) 2022-01-31 06:32:25 +08:00
Alex Lam S.L
0a5a1f3687 fix corner case in reduce_vars (#5325)
fixes #5324
2022-01-29 21:39:30 +08:00
Alex Lam S.L
e7d6dd2ea2 fix corner case in unused (#5323)
fixes #5322
2022-01-29 19:28:19 +08:00
Alex Lam S.L
28943bcebb fix corner cases in collapse_vars (#5321)
fixes #5319
2022-01-29 15:57:53 +08:00
Alex Lam S.L
18f00457f6 fix corner case in merge_vars (#5320)
fixes #5319
2022-01-28 16:05:57 +08:00
Alex Lam S.L
e4a91a89e0 support custom indentation (#5318)
closes #50
2022-01-28 08:38:11 +08:00
Alex Lam S.L
3693bde2dd fix corner case in inline (#5317)
fixes #5316
2022-01-28 07:17:17 +08:00
Alex Lam S.L
67438f3ff9 fix corner case in side_effects (#5315)
fixes #5314
2022-01-27 08:13:19 +08:00
Alex Lam S.L
371d25944d fix corner case in max_line_len (#5313)
- speed up `max_line_len` & `preserve_line`
2022-01-26 23:47:21 +08:00
Alex Lam S.L
5c863b74d7 enhance collapse_vars (#5312) 2022-01-26 04:18:58 +08:00
57 changed files with 4445 additions and 1513 deletions

View File

@@ -917,9 +917,11 @@ can pass additional arguments that control the code output:
- `galio` (default: `false`) — enable workarounds for ANT Galio bugs
- `indent_level` (default: `4`)
- `indent_level` (default: `4`) — indent by specified number of spaces or the
exact whitespace sequence supplied, e.g. `"\t"`.
- `indent_start` (default: `0`) — prefix all lines by that many spaces
- `indent_start` (default: `0`) — prefix all lines by whitespace sequence
specified in the same format as `indent_level`.
- `inline_script` (default: `true`) — escape HTML comments and the slash in
occurrences of `</script>` in strings
@@ -1371,3 +1373,19 @@ To allow for better optimizations, the compiler makes various assumptions:
// TypeError: const 'a' has already been declared
```
UglifyJS may modify the input which in turn may suppress those errors.
- Later versions of Chrome and Node.js will give incorrect results with the
following:
```javascript
try {
class A {
static 42;
static get 42() {}
}
console.log("PASS");
} catch (e) {
console.log("FAIL");
}
// Expected: "PASS"
// Actual: "FAIL"
```
UglifyJS may modify the input which in turn may suppress those errors.

View File

@@ -851,6 +851,9 @@ var AST_DefClass = DEFNODE("DefClass", null, {
$propdoc: {
name: "[AST_SymbolDefClass] the name of this class",
},
resolve: function(def_class) {
return def_class ? this : this.parent_scope.resolve();
},
_validate: function() {
if (!(this.name instanceof AST_SymbolDefClass)) throw new Error("name must be AST_SymbolDefClass");
},
@@ -2085,33 +2088,40 @@ TreeWalker.prototype = {
}
},
in_boolean_context: function() {
var self = this.self();
for (var i = 0, p; p = this.parent(i); i++) {
if (p instanceof AST_Conditional && p.condition === self
|| p instanceof AST_DWLoop && p.condition === self
|| p instanceof AST_For && p.condition === self
|| p instanceof AST_If && p.condition === self
|| p instanceof AST_Return && p.in_bool
|| p instanceof AST_Sequence && p.tail_node() !== self
|| p instanceof AST_SimpleStatement
|| p instanceof AST_UnaryPrefix && p.operator == "!" && p.expression === self) {
return true;
}
if (p instanceof AST_Binary && (p.operator == "&&" || p.operator == "||")
|| p instanceof AST_Conditional
|| p.tail_node() === self) {
self = p;
} else if (p instanceof AST_Return) {
for (var call, fn = p; call = this.parent(++i); fn = call) {
if (call.TYPE == "Call") {
if (!(fn instanceof AST_Lambda) || fn.name) return false;
} else if (fn instanceof AST_Lambda) {
return false;
}
}
} else {
for (var drop = true, level = 0, parent, self = this.self(); parent = this.parent(level++); self = parent) {
if (parent instanceof AST_Binary) switch (parent.operator) {
case "&&":
case "||":
if (parent.left === self) drop = false;
continue;
default:
return false;
}
if (parent instanceof AST_Conditional) {
if (parent.condition === self) return true;
continue;
}
if (parent instanceof AST_DWLoop) return parent.condition === self;
if (parent instanceof AST_For) return parent.condition === self;
if (parent instanceof AST_If) return parent.condition === self;
if (parent instanceof AST_Return) {
if (parent.in_bool) return true;
while (parent = this.parent(level++)) {
if (parent instanceof AST_Lambda) {
if (parent.name) return false;
parent = this.parent(level++);
if (parent.TYPE != "Call") return false;
break;
}
}
}
if (parent instanceof AST_Sequence) {
if (parent.tail_node() === self) continue;
return drop ? "d" : true;
}
if (parent instanceof AST_SimpleStatement) return drop ? "d" : true;
if (parent instanceof AST_UnaryPrefix) return parent.operator == "!";
return false;
}
}
};

File diff suppressed because it is too large Load Diff

View File

@@ -96,15 +96,14 @@ function minify(files, options) {
}, true);
if (options.validate) AST_Node.enable_validation();
var timings = options.timings && { start: Date.now() };
if (options.rename === undefined) options.rename = options.compress && options.mangle;
if (options.annotations !== undefined) set_shorthand("annotations", options, [ "compress", "output" ]);
if (options.ie8) options.ie = options.ie || options.ie8;
if (options.ie) set_shorthand("ie", options, [ "compress", "mangle", "output" ]);
if (options.keep_fargs) set_shorthand("keep_fargs", options, [ "compress", "mangle" ]);
if (options.keep_fnames) set_shorthand("keep_fnames", options, [ "compress", "mangle" ]);
if (options.toplevel) set_shorthand("toplevel", options, [ "compress", "mangle" ]);
if (options.v8) set_shorthand("v8", options, [ "mangle", "output" ]);
if (options.webkit) set_shorthand("webkit", options, [ "compress", "mangle", "output" ]);
if (options.ie) set_shorthand("ie", options, [ "compress", "mangle", "output", "rename" ]);
if (options.keep_fargs) set_shorthand("keep_fargs", options, [ "compress", "mangle", "rename" ]);
if (options.keep_fnames) set_shorthand("keep_fnames", options, [ "compress", "mangle", "rename" ]);
if (options.toplevel) set_shorthand("toplevel", options, [ "compress", "mangle", "rename" ]);
if (options.v8) set_shorthand("v8", options, [ "mangle", "output", "rename" ]);
if (options.webkit) set_shorthand("webkit", options, [ "compress", "mangle", "output", "rename" ]);
var quoted_props;
if (options.mangle) {
options.mangle = defaults(options.mangle, {
@@ -135,6 +134,7 @@ function minify(files, options) {
init_cache(options.mangle.cache);
init_cache(options.mangle.properties.cache);
}
if (options.rename === undefined) options.rename = options.compress && options.mangle;
if (options.sourceMap) {
options.sourceMap = defaults(options.sourceMap, {
content: null,
@@ -190,8 +190,8 @@ function minify(files, options) {
if (options.validate) toplevel.validate_ast();
if (timings) timings.rename = Date.now();
if (options.rename) {
toplevel.figure_out_scope(options.mangle);
toplevel.expand_names(options.mangle);
toplevel.figure_out_scope(options.rename);
toplevel.expand_names(options.rename);
}
if (timings) timings.compress = Date.now();
if (options.compress) {

View File

@@ -101,10 +101,18 @@ function OutputStream(options) {
}
}
function make_indent(value) {
if (typeof value == "number") return new Array(value + 1).join(" ");
if (!value) return "";
if (!/^\s*$/.test(value)) throw new Error("unsupported indentation: " + JSON.stringify("" + value));
return value;
}
var current_col = 0;
var current_line = 1;
var current_pos = 0;
var indentation = options.indent_start;
var current_indent = make_indent(options.indent_start);
var full_indent = make_indent(options.indent_level);
var half_indent = full_indent.length + 1 >> 1;
var last;
var line_end = 0;
var line_fixed = true;
@@ -115,17 +123,17 @@ function OutputStream(options) {
var might_need_semicolon;
var need_newline_indented = false;
var need_space = false;
var newline_insert = -1;
var output;
var stack;
var OUTPUT;
var stored = "";
function reset() {
last = "";
might_need_space = false;
might_need_semicolon = false;
stack = [];
var str = OUTPUT;
OUTPUT = "";
var str = output;
output = "";
return str;
}
@@ -227,32 +235,30 @@ function OutputStream(options) {
} : noop;
function insert_newlines(count) {
var index = OUTPUT.lastIndexOf("\n");
if (line_end < index) line_end = index;
var left = OUTPUT.slice(0, line_end);
var right = OUTPUT.slice(line_end);
adjust_mappings(count, right.length - current_col);
stored += output.slice(0, line_end);
output = output.slice(line_end);
var new_col = output.length;
adjust_mappings(count, new_col - current_col);
current_line += count;
current_pos += count;
current_col = right.length;
OUTPUT = left;
while (count--) OUTPUT += "\n";
OUTPUT += right;
current_col = new_col;
while (count--) stored += "\n";
}
var fix_line = options.max_line_len ? function() {
var fix_line = options.max_line_len ? function(flush) {
if (line_fixed) {
if (current_col > options.max_line_len) {
AST_Node.warn("Output exceeds {max_line_len} characters", options);
}
return;
}
if (current_col > options.max_line_len) insert_newlines(1);
line_fixed = true;
flush_mappings();
if (current_col > options.max_line_len) {
insert_newlines(1);
line_fixed = true;
}
if (line_fixed || flush) flush_mappings();
} : noop;
var requireSemicolonChars = makePredicate("( [ + * / - , .");
var require_semicolon = makePredicate("( [ + * / - , .");
var print = options.beautify
|| options.comments
@@ -276,32 +282,32 @@ function OutputStream(options) {
space();
}
}
newline_insert = -1;
var prev = last.slice(-1);
if (might_need_semicolon) {
might_need_semicolon = false;
if (prev == ":" && ch == "}" || (!ch || ";}".indexOf(ch) < 0) && prev != ";") {
if (options.semicolons || requireSemicolonChars[ch]) {
OUTPUT += ";";
if (prev == ":" && ch == "}" || prev != ";" && (!ch || ";}".indexOf(ch) < 0)) {
var need_semicolon = require_semicolon[ch];
if (need_semicolon || options.semicolons) {
output += ";";
current_col++;
current_pos++;
if (!line_fixed) {
fix_line();
if (line_fixed && !need_semicolon && output == ";") {
output = "";
current_col = 0;
}
}
if (line_end == output.length - 1) line_end++;
} else {
fix_line();
OUTPUT += "\n";
current_pos++;
output += "\n";
current_line++;
current_col = 0;
if (/^\s+$/.test(str)) {
// reset the semicolon flag, since we didn't print one
// now and might still have to later
might_need_semicolon = true;
}
// reset the semicolon flag, since we didn't print one
// now and might still have to later
if (/^\s+$/.test(str)) might_need_semicolon = true;
}
if (!options.beautify)
might_need_space = false;
if (!options.beautify) might_need_space = false;
}
}
@@ -312,9 +318,8 @@ function OutputStream(options) {
|| str == "--" && last == "!"
|| str == "in" && prev == "/"
|| last == "--" && ch == ">") {
OUTPUT += " ";
output += " ";
current_col++;
current_pos++;
}
if (prev != "<" || str != "!") might_need_space = false;
}
@@ -324,14 +329,13 @@ function OutputStream(options) {
token: mapping_token,
name: mapping_name,
line: current_line,
col: current_col
col: current_col,
});
mapping_token = false;
if (line_fixed) flush_mappings();
}
OUTPUT += str;
current_pos += str.length;
output += str;
var a = str.split(/\r?\n/), n = a.length - 1;
current_line += n;
current_col += a[0].length;
@@ -346,7 +350,7 @@ function OutputStream(options) {
if (might_need_semicolon) {
might_need_semicolon = false;
if (prev == ":" && ch == "}" || (!ch || ";}".indexOf(ch) < 0) && prev != ";") {
OUTPUT += ";";
output += ";";
might_need_space = false;
}
}
@@ -357,11 +361,11 @@ function OutputStream(options) {
|| str == "--" && last == "!"
|| str == "in" && prev == "/"
|| last == "--" && ch == ">") {
OUTPUT += " ";
output += " ";
}
if (prev != "<" || str != "!") might_need_space = false;
}
OUTPUT += str;
output += str;
last = str;
};
@@ -373,30 +377,25 @@ function OutputStream(options) {
var indent = options.beautify ? function(half) {
if (need_newline_indented) print("\n");
print(repeat_string(" ", half ? indentation - (options.indent_level >> 1) : indentation));
print(half ? current_indent.slice(0, -half_indent) : current_indent);
} : noop;
var with_indent = options.beautify ? function(cont) {
var save_indentation = indentation;
indentation += options.indent_level;
var save_indentation = current_indent;
current_indent += full_indent;
cont();
indentation = save_indentation;
current_indent = save_indentation;
} : function(cont) { cont() };
var may_add_newline = options.max_line_len || options.preserve_line ? function() {
fix_line();
line_end = OUTPUT.length;
line_end = output.length;
line_fixed = false;
} : noop;
var newline = options.beautify ? function() {
if (newline_insert < 0) return print("\n");
if (OUTPUT[newline_insert] != "\n") {
OUTPUT = OUTPUT.slice(0, newline_insert) + "\n" + OUTPUT.slice(newline_insert);
current_pos++;
current_line++;
}
newline_insert++;
print("\n");
line_end = output.length;
} : may_add_newline;
var semicolon = options.beautify ? function() {
@@ -452,13 +451,12 @@ function OutputStream(options) {
} : noop;
function get() {
if (!line_fixed) fix_line();
return OUTPUT;
if (!line_fixed) fix_line(true);
return stored + output;
}
function has_nlb() {
var index = OUTPUT.lastIndexOf("\n");
return /^ *$/.test(OUTPUT.slice(index + 1));
return /(^|\n) *$/.test(output);
}
function pad_comment(token, force) {
@@ -515,7 +513,7 @@ function OutputStream(options) {
scan.walk(tw);
}
if (current_pos == 0) {
if (current_line == 1 && current_col == 0) {
if (comments.length > 0 && options.shebang && comments[0].type == "comment5") {
print("#!" + comments.shift().value + "\n");
indent();
@@ -559,20 +557,18 @@ function OutputStream(options) {
return !/comment[134]/.test(c.type);
}))) return;
comments._dumped = self;
var insert = OUTPUT.length;
comments.filter(comment_filter, node).forEach(function(comment, index) {
pad_comment(comment, index || !tail);
print_comment(comment);
});
if (OUTPUT.length > insert) newline_insert = insert;
}
return {
get : get,
reset : reset,
indent : indent,
should_break : options.width ? function() {
return current_col - indentation >= options.width;
should_break : options.beautify && options.width ? function() {
return current_col >= options.width;
} : return_false,
has_parens : function() { return last.slice(-1) == "(" },
newline : newline,

View File

@@ -1194,10 +1194,10 @@ function parse($TEXT, options) {
}
function for_() {
var await = is("name", "await") && next();
var await_token = is("name", "await") && next();
expect("(");
var init = null;
if (await || !is("punc", ";")) {
if (await_token || !is("punc", ";")) {
init = is("keyword", "const")
? (next(), const_(true))
: is("name", "let") && is_vardefs()
@@ -1206,7 +1206,7 @@ function parse($TEXT, options) {
? (next(), var_(true))
: expression(true);
var ctor;
if (await) {
if (await_token) {
expect_token("name", "of");
ctor = AST_ForAwaitOf;
} else if (is("operator", "in")) {

View File

@@ -226,7 +226,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
defun.def_variable(node);
} else if (node instanceof AST_SymbolLambda) {
var def = defun.def_function(node, node.name == "arguments" ? undefined : defun);
if (options.ie) def.defun = defun.parent_scope.resolve();
if (options.ie && node.name != "arguments") def.defun = defun.parent_scope.resolve();
} else if (node instanceof AST_SymbolLet) {
var def = scope.def_variable(node);
if (exported) def.exported = true;
@@ -469,6 +469,7 @@ AST_Lambda.DEFMETHOD("init_vars", function(parent_scope) {
this.uses_arguments = false;
this.def_variable(new AST_SymbolFunarg({
name: "arguments",
scope: this,
start: this.start,
end: this.end,
}));
@@ -616,7 +617,7 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
mangled_names.set(mangled_name, true);
});
}
var cutoff = 10;
var cutoff = 36;
var lname = -1;
var redefined = [];
var tw = new TreeWalker(function(node, descend) {

View File

@@ -55,14 +55,6 @@ function find_if(func, array) {
for (var i = array.length; --i >= 0;) if (func(array[i])) return array[i];
}
function repeat_string(str, i) {
if (i <= 0) return "";
if (i == 1) return str;
var d = repeat_string(str, i >> 1);
d += d;
return i & 1 ? d + str : d;
}
function configure_error_stack(fn) {
Object.defineProperty(fn.prototype, "stack", {
get: function() {

View File

@@ -3,7 +3,7 @@
"description": "JavaScript parser, mangler/compressor and beautifier toolkit",
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
"license": "BSD-2-Clause",
"version": "3.15.0",
"version": "3.15.5",
"engines": {
"node": ">=0.8.0"
},

View File

@@ -17,6 +17,7 @@ var urls = [
"https://unpkg.com/mathjs@6.2.3/dist/math.js",
"https://unpkg.com/react@15.3.2/dist/react.js",
"https://cdnjs.cloudflare.com/ajax/libs/d3/6.7.0/d3.js",
"https://cdnjs.cloudflare.com/ajax/libs/antd/4.18.7/antd.js",
"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.js",
"https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.js",
"https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.12.2/ember.prod.js",

View File

@@ -183,13 +183,11 @@ function parse_test(file) {
function reminify(orig_options, input_code, input_formatted, stdout) {
for (var i = 0; i < minify_options.length; i++) {
var options = JSON.parse(minify_options[i]);
if (options.compress) [
[
"keep_fargs",
"keep_fnames",
].forEach(function(name) {
if (name in orig_options) {
options.compress[name] = orig_options[name];
}
if (name in orig_options) options[name] = orig_options[name];
});
var options_formatted = JSON.stringify(options, null, 4);
options.validate = true;

View File

@@ -927,3 +927,182 @@ issue_5251: {
expect_stdout: true
node_version: ">=4"
}
issue_5342_1: {
options = {
dead_code: true,
inline: true,
toplevel: true,
unused: true,
}
input: {
for (var a in 0) {
(() => {
while (1);
})(new function(NaN) {
a.p;
}());
}
console.log(function() {
return b;
try {
b;
} catch (e) {
var b;
}
}());
}
expect: {
for (var a in 0) {
(function(NaN) {
a.p;
})();
while (1);
}
console.log(b);
var b;
}
expect_stdout: "undefined"
node_version: ">=4"
}
issue_5342_2: {
rename = true
options = {
dead_code: true,
inline: true,
toplevel: true,
unused: true,
}
input: {
for (var a in 0) {
(() => {
while (1);
})(new function(NaN) {
a.p;
}());
}
console.log(function() {
return b;
try {
b;
} catch (e) {
var b;
}
}());
}
expect: {
for (var a in 0) {
a.p;
while (1);
}
console.log(c);
var c;
}
expect_stdout: "undefined"
node_version: ">=4"
}
issue_5356: {
options = {
evaluate: true,
reduce_vars: true,
unused: true,
}
input: {
console.log((a => a++)(console));
}
expect: {
console.log((a => +a)(console));
}
expect_stdout: "NaN"
node_version: ">=4"
}
issue_5414_1: {
options = {
arrows: true,
if_return: true,
inline: true,
toplevel: true,
}
input: {
(() => {
(() => {
if (!console)
var arguments = 42;
while (console.log(arguments));
})();
})();
}
expect: {
(() => {
if (!console)
var arguments = 42;
while (console.log(arguments));
})();
}
expect_stdout: true
node_version: ">=4"
}
issue_5414_2: {
options = {
arrows: true,
inline: true,
side_effects: true,
toplevel: true,
}
input: {
(() => {
(() => {
if (!console)
var arguments = 42;
while (console.log(arguments));
})();
})();
}
expect: {
(() => {
if (!console)
var arguments = 42;
while (console.log(arguments));
})();
}
expect_stdout: true
node_version: ">=4"
}
issue_5416: {
options = {
dead_code: true,
evaluate: true,
inline: true,
loops: true,
unused: true,
}
input: {
var f = () => {
while ((() => {
console;
var a = function g(arguments) {
console.log(arguments);
}();
})());
};
f();
}
expect: {
var f = () => {
{
arguments = void 0;
console;
console.log(arguments);
var arguments;
}
};
f();
}
expect_stdout: "undefined"
node_version: ">=4"
}

View File

@@ -673,8 +673,7 @@ issue_4827_1: {
c &&= b = a, console.log(b);
}
expect: {
A = "FAIL";
var a = A, b = "PASS", c;
var a = A = "FAIL", b = "PASS", c;
c &&= b = a, console.log(b);
}
expect_stdout: "PASS"

View File

@@ -427,6 +427,44 @@ negated_if: {
expect_stdout: "PASS"
}
concat_truthy: {
options = {
booleans: true,
evaluate: true,
}
input: {
console.log("foo") + (console.log("bar"), "baz") || console.log("moo");
}
expect: {
console.log("foo") + (console.log("bar"), "baz");
}
expect_stdout: [
"foo",
"bar",
]
expect_warnings: [
"WARN: + in boolean context always true [test/compress/booleans.js:1,8]",
"WARN: Condition left of || always true [test/compress/booleans.js:1,8]",
]
}
process_returns: {
options = {
booleans: true,
}
input: {
(function() {
return 42;
})() && console.log("PASS");
}
expect: {
(function() {
return 42;
})() && console.log("PASS");
}
expect_stdout: "PASS"
}
issue_3465_1: {
options = {
booleans: true,

View File

@@ -939,6 +939,8 @@ keep_fnames: {
class Foo {}
console.log(Foo.name, class Bar {}.name);
}
expect_stdout: "Foo Bar"
node_version: ">=4"
}
issue_805_1: {
@@ -2449,3 +2451,153 @@ issue_5294_4: {
expect_stdout: "PASS"
node_version: ">=12"
}
issue_5322: {
options = {
toplevel: true,
unused: true,
}
input: {
var a = 41;
class A {
static p() {
console.log(++a);
}
static q = this.p();
}
}
expect: {
var a = 41;
(class {
static p() {
console.log(++a);
}
static q = this.p();
});
}
expect_stdout: "42"
node_version: ">=12"
}
issue_5352: {
options = {
merge_vars: true,
}
input: {
function f(a) {
var b;
new class {
[b = console.log(a)] = b;
}(a.p);
}
f("PASS");
}
expect: {
function f(a) {
var b;
new class {
[b = console.log(a)] = b;
}(a.p);
}
f("PASS");
}
expect_stdout: "PASS"
node_version: ">=12"
}
issue_5387: {
options = {
properties: true,
}
input: {
"use strict";
(function(a) {
try {
class A extends a {}
} catch (e) {
console.log("PASS");
}
})({
f() {
return this;
}
}.f);
}
expect: {
"use strict";
(function(a) {
try {
class A extends a {}
} catch (e) {
console.log("PASS");
}
})({
f() {
return this;
}
}.f);
}
expect_stdout: "PASS"
node_version: ">=4"
}
issue_5389: {
options = {
collapse_vars: true,
toplevel: true,
}
input: {
function log(m, n) {
console.log(m, n);
}
var a = log;
class A {
[a = "FAIL"] = a = "PASS";
}
var b = new A();
log(a, b.FAIL);
}
expect: {
function log(m, n) {
console.log(m, n);
}
var a = log;
class A {
[a = "FAIL"] = a = "PASS";
}
var b = new A();
log(a, b.FAIL);
}
expect_stdout: "PASS PASS"
node_version: ">=12"
}
issue_5436: {
options = {
merge_vars: true,
}
input: {
function f(a) {
class A {
p = a;
}
var b = "FAIL";
A == b && b();
return new A();
}
console.log(f("PASS").p);
}
expect: {
function f(a) {
class A {
p = a;
}
var b = "FAIL";
A == b && b();
return new A();
}
console.log(f("PASS").p);
}
expect_stdout: "PASS"
node_version: ">=12"
}

View File

@@ -2579,7 +2579,7 @@ side_effects_property: {
expect_stdout: true
}
undeclared: {
undeclared_1: {
options = {
collapse_vars: true,
unused: true,
@@ -2594,8 +2594,68 @@ undeclared: {
}
expect: {
function f(x, y) {
return (b = y) + x;
}
}
}
undeclared_2: {
options = {
collapse_vars: true,
unused: true,
}
input: {
function f(x, y) {
var a;
a = x;
b = y;
return b + x;
return a + b;
}
}
expect: {
function f(x, y) {
return x + (b = y);
}
}
}
undeclared_3: {
options = {
collapse_vars: true,
unused: true,
}
input: {
function f(x, y) {
var a;
a = x;
b = y;
return b + a();
}
}
expect: {
function f(x, y) {
return (b = y) + x();
}
}
}
undeclared_4: {
options = {
collapse_vars: true,
unused: true,
}
input: {
function f(x, y) {
var a;
a = x;
b = y;
return a() + b;
}
}
expect: {
function f(x, y) {
b = y;
return x() + b;
}
}
}
@@ -2987,9 +3047,8 @@ compound_assignment_4: {
console.log(a);
}
expect: {
A = "PASS";
var a = "";
(a += (a = "FAIL", A)).p;
(a += (a = "FAIL", A = "PASS")).p;
console.log(a);
}
expect_stdout: "PASS"
@@ -8955,6 +9014,27 @@ collapse_and_assign: {
expect_stdout: "PASS"
}
collapse_and_assign_property: {
options = {
collapse_vars: true,
pure_getters: "strict",
reduce_vars: true,
unused: true,
}
input: {
console.log(function f() {
f && (f.p = "PASS");
return f.p;
}());
}
expect: {
console.log(function f() {
return f.p = f ? "PASS" : f.p;
}());
}
expect_stdout: "PASS"
}
collapse_or_assign: {
options = {
collapse_vars: true,
@@ -8972,7 +9052,7 @@ collapse_or_assign: {
var a = {
p: "PASS",
};
log(a = !a.q ? a.p : a);
log(a = a.q ? a: a.p);
}
expect_stdout: "PASS"
}
@@ -9845,3 +9925,57 @@ issue_5309_2: {
}
expect_stdout: "PASS"
}
issue_5394: {
options = {
collapse_vars: true,
evaluate: true,
}
input: {
try {
throw A.p = (console.log("FAIL"), []), !1;
} catch (e) {
console.log(typeof e);
}
}
expect: {
try {
throw !(A.p = (console.log("FAIL"), []));
} catch (e) {
console.log(typeof e);
}
}
expect_stdout: "object"
}
issue_5396: {
options = {
collapse_vars: true,
merge_vars: true,
reduce_vars: true,
side_effects: true,
unused: true,
}
input: {
var a, b;
function f() {}
b = 0;
new function g(c) {
var d = a && g(e), e = ++d, i = [ 42 ];
for (var j in i)
console.log("PASS"),
i;
}();
}
expect: {
var a, b;
function f() {}
b = 0;
(function g(c) {
a && g();
for (var j in [ 42 ])
console.log("PASS");
})();
}
expect_stdout: "PASS"
}

View File

@@ -489,7 +489,36 @@ issue_3413: {
}
expect: {
var b;
void 0 !== ("" < b || void 0) || console.log("PASS");
void 0 === ("" < b || void 0) && console.log("PASS");
}
expect_stdout: "PASS"
}
nullish_assign: {
options = {
comparisons: true,
}
input: {
var a;
void 0 !== (a = "PASS".split("")) && null !== a && console.log(a.join("-"));
}
expect: {
var a;
null != (a = "PASS".split("")) && console.log(a.join("-"));
}
expect_stdout: "P-A-S-S"
}
nullish_chain: {
options = {
comparisons: true,
}
input: {
var a;
A || B || void 0 === a || null === a || C;
}
expect: {
var a;
A || B || null == a || C;
}
}

View File

@@ -82,14 +82,14 @@ ifs_3_should_warn: {
"WARN: Boolean && always false [test/compress/conditionals.js:3,12]",
"WARN: Condition left of && always false [test/compress/conditionals.js:3,12]",
"WARN: Condition always false [test/compress/conditionals.js:3,12]",
"WARN: Dropping side-effect-free statement [test/compress/conditionals.js:3,12]",
"WARN: Dropping unreachable code [test/compress/conditionals.js:3,34]",
"WARN: + in boolean context always true [test/compress/conditionals.js:10,19]",
"WARN: Boolean || always true [test/compress/conditionals.js:10,12]",
"WARN: Condition left of || always true [test/compress/conditionals.js:10,12]",
"WARN: Condition always true [test/compress/conditionals.js:10,12]",
"WARN: Dropping unreachable code [test/compress/conditionals.js:12,15]",
"WARN: Dropping side-effect-free statement [test/compress/conditionals.js:3,12]",
"WARN: Dropping side-effect-free statement [test/compress/conditionals.js:10,12]",
"WARN: Dropping unreachable code [test/compress/conditionals.js:12,15]",
]
}
@@ -2007,3 +2007,58 @@ issue_5232_3: {
"undefined",
]
}
issue_5334_1: {
options = {
conditionals: true,
hoist_props: true,
reduce_vars: true,
side_effects: true,
toplevel: true,
unused: true,
}
input: {
function f() {
if (console.log("PASS"))
var o = true, o = {
p: o += console.log("FAIL"),
};
}
f();
}
expect: {
(function() {
var o;
console.log("PASS") && (o = true, o = {
p: o += console.log("FAIL"),
});
})();
}
expect_stdout: "PASS"
}
issue_5334_2: {
options = {
conditionals: true,
hoist_props: true,
inline: true,
passes: 3,
reduce_vars: true,
side_effects: true,
toplevel: true,
unused: true,
}
input: {
function f() {
if (console.log("PASS"))
var o = true, o = {
p: o += console.log("FAIL"),
};
}
f();
}
expect: {
console.log("PASS") && console.log("FAIL");
}
expect_stdout: "PASS"
}

View File

@@ -597,8 +597,7 @@ do_if_continue_1: {
}
expect: {
do {
if (!console);
else {
if (console) {
console.log("PASS");
{
const a = 0;
@@ -628,8 +627,7 @@ do_if_continue_2: {
}
expect: {
do {
if (!console);
else {
if (console) {
console.log("PASS");
{
const a = 0;
@@ -1518,6 +1516,7 @@ issue_4689: {
issue_4691: {
options = {
conditionals: true,
if_return: true,
toplevel: true,
}
@@ -1813,3 +1812,46 @@ issue_5260: {
]
node_version: ">=4"
}
issue_5319: {
options = {
collapse_vars: true,
merge_vars: true,
}
input: {
(function(a, c) {
var b = a, c = b;
{
const a = c;
console.log(c());
}
})(function() {
return "PASS";
});
}
expect: {
(function(a, c) {
var b = a, c;
{
const a = c = b;
console.log(c());
}
})(function() {
return "PASS";
});
}
expect_stdout: true
}
issue_5338: {
options = {
unused: true,
}
input: {
const a = a;
}
expect: {
const a = a;
}
expect_stdout: true
}

View File

@@ -2007,6 +2007,7 @@ issue_5192: {
issue_5246_1: {
options = {
keep_fargs: false,
pure_getters: true,
unused: true,
}
@@ -2016,20 +2017,20 @@ issue_5246_1: {
}("foo"));
}
expect: {
console.log(function({} = 0) {
console.log(function() {
return "PASS";
}("foo"));
}());
}
expect_stdout: "PASS"
expect_warnings: [
"INFO: Dropping unused default argument value {}=42 [test/compress/default-values.js:1,29]",
"INFO: Dropping unused default argument value {}=0 [test/compress/default-values.js:1,29]",
"INFO: Dropping unused default argument {}=42 [test/compress/default-values.js:1,29]",
]
node_version: ">=6"
}
issue_5246_2: {
options = {
keep_fargs: false,
unused: true,
}
input: {
@@ -2038,9 +2039,9 @@ issue_5246_2: {
})("PASS", []);
}
expect: {
(function(a = "FAIL", []) {
(function(a = "FAIL") {
console.log(a);
})("PASS", []);
})("PASS");
}
expect_stdout: "PASS"
node_version: ">=6"
@@ -2049,6 +2050,7 @@ issue_5246_2: {
issue_5246_3: {
options = {
default_values: true,
keep_fargs: false,
unused: true,
}
input: {
@@ -2081,3 +2083,159 @@ issue_5256: {
expect_stdout: "undefined"
node_version: ">=8"
}
issue_5314_1: {
options = {
side_effects: true,
}
input: {
A = this;
new function() {
(function(a = console.log(this === A ? "PASS" : "FAIL")) {})();
}();
}
expect: {
A = this;
(function() {
(function(a = console.log(this === A ? "PASS" : "FAIL")) {})();
})();
}
expect_stdout: "PASS"
node_version: ">=6"
}
issue_5314_2: {
options = {
side_effects: true,
}
input: {
A = this;
new function() {
((a = console.log(this === A ? "FAIL" : "PASS")) => {})();
}();
}
expect: {
A = this;
new function() {
console.log(this === A ? "FAIL" : "PASS");
}();
}
expect_stdout: "PASS"
node_version: ">=6"
}
issue_5336: {
options = {
default_values: true,
unused: true,
}
input: {
var a;
do {
(function f(b = console.log("PASS")) {
a = f;
})(42);
} while (a());
}
expect: {
var a;
do {
(function f(b = console.log("PASS")) {
a = f;
})(42);
} while (a());
}
expect_stdout: "PASS"
node_version: ">=6"
}
issue_5340_1: {
options = {
keep_fargs: true,
pure_getters: "strict",
unused: true,
}
input: {
var a;
(function(b = 42) {})(({ p: a } = true).q);
console.log(a);
}
expect: {
var a;
(function(b = 0) {})(({ p: a } = true).q);
console.log(a);
}
expect_stdout: "undefined"
node_version: ">=6"
}
issue_5340_2: {
options = {
keep_fargs: true,
pure_getters: "strict",
side_effects: true,
unused: true,
}
input: {
var a;
(function(b = 42) {})(({ p: a } = true).q);
console.log(a);
}
expect: {
var a;
[ [].e = 0 ] = [ ({ p: a } = true).q ];
console.log(a);
}
expect_stdout: "undefined"
node_version: ">=6"
}
issue_5340_3: {
options = {
keep_fargs: false,
pure_getters: "strict",
unused: true,
}
input: {
var a;
(function(b = 42) {})(({ p: a } = true).q);
console.log(a);
}
expect: {
var a;
(function() {})(a = true["p"]);
console.log(a);
}
expect_stdout: "undefined"
node_version: ">=6"
}
issue_5407: {
options = {
evaluate: true,
reduce_vars: true,
}
input: {
(function(a) {
for (var i = 0; i < 2; i++)
(function(b = 4) {
console.log(b);
a = 2;
})(a);
})();
}
expect: {
(function(a) {
for (var i = 0; i < 2; i++)
(function(b = 4) {
console.log(b);
a = 2;
})(a);
})();
}
expect_stdout: [
"4",
"2",
]
node_version: ">=6"
}

View File

@@ -692,7 +692,7 @@ funarg_inline: {
node_version: ">=6"
}
process_boolean_returns: {
process_returns: {
options = {
booleans: true,
}
@@ -706,9 +706,7 @@ process_boolean_returns: {
expect: {
console.log(function({ length }) {
return length ? "FAIL" : "PASS";
}(function() {
return 42;
}));
}(function() {}));
}
expect_stdout: "PASS"
node_version: ">=6"
@@ -1130,7 +1128,7 @@ drop_unused_2: {
}
f();
}
expect:{
expect: {
(function(a) {
console.log("PASS");
})();
@@ -3406,6 +3404,7 @@ issue_5288: {
options = {
conditionals: true,
inline: true,
keep_fargs: false,
reduce_vars: true,
toplevel: true,
unused: true,
@@ -3421,8 +3420,149 @@ issue_5288: {
}() ]));
}
expect: {
while ([ [ console ? console.log("PASS") : 0 ] ], void 0);
while (console ? console.log("PASS") : 0, void 0);
}
expect_stdout: "PASS"
node_version: ">=6"
}
issue_5314_1: {
options = {
side_effects: true,
}
input: {
A = this;
new function() {
(function({
[console.log(this === A ? "PASS" : "FAIL")]: a,
}) {})(42);
}();
}
expect: {
A = this;
(function() {
(function({
[console.log(this === A ? "PASS" : "FAIL")]: a,
}) {})(42);
})();
}
expect_stdout: "PASS"
node_version: ">=6"
}
issue_5314_2: {
options = {
side_effects: true,
}
input: {
A = this;
new function() {
(({
[console.log(this === A ? "FAIL" : "PASS")]: a,
}) => {})(42);
}();
}
expect: {
A = this;
new function() {
[ {
[console.log(this === A ? "FAIL" : "PASS")]: [].e,
} ] = [ 42 ];
}();
}
expect_stdout: "PASS"
node_version: ">=6"
}
issue_5370: {
options = {
dead_code: true,
ie: true,
unused: true,
}
input: {
console.log(function arguments({}) {
return arguments;
try {} catch (e) {
var arguments;
}
}(42));
}
expect: {
console.log(function arguments({}) {
return arguments;
var arguments;
}(42));
}
expect_stdout: true
node_version: ">=6"
}
issue_5405_1: {
options = {
evaluate: true,
reduce_vars: true,
toplevel: true,
unsafe: true,
}
input: {
var [ a ] = [ {} ];
console.log(a === a ? "PASS" : "FAIL");
}
expect: {
var [ a ] = [ {} ];
console.log(true ? "PASS" : "FAIL");
}
expect_stdout: "PASS"
node_version: ">=6"
}
issue_5405_2: {
options = {
evaluate: true,
reduce_vars: true,
toplevel: true,
unsafe: true,
}
input: {
var { p: a } = { p: [] };
console.log(a === a ? "PASS" : "FAIL");
}
expect: {
var { p: a } = { p: [] };
console.log(true ? "PASS" : "FAIL");
}
expect_stdout: "PASS"
node_version: ">=6"
}
issue_5423: {
options = {
merge_vars: true,
toplevel: true,
}
input: {
var a, b;
function f({
[function() {
if (++a)
return 42;
}()]: c
}) {}
f(b = f);
console.log(typeof b);
}
expect: {
var a, b;
function f({
[function() {
if (++a)
return 42;
}()]: c
}) {}
f(b = f);
console.log(typeof b);
}
expect_stdout: "function"
node_version: ">=6"
}

View File

@@ -129,3 +129,32 @@ valid_after_invalid_2: {
}
expect_stdout: "undefined"
}
issue_5368_1: {
options = {
directives: true,
expression: true,
}
input: {
"foo";
}
expect: {
"foo";
}
}
issue_5368_2: {
options = {
directives: true,
expression: true,
}
input: {
"foo";
(function() {
"bar";
})();
}
expect: {
(function() {})();
}
}

View File

@@ -2656,7 +2656,7 @@ issue_3956: {
collapse_vars: true,
evaluate: true,
inline: true,
passes: 2,
passes: 3,
reduce_vars: true,
sequences: true,
side_effects: true,
@@ -2787,7 +2787,7 @@ issue_3986: {
expect_stdout: "0"
}
issue_4017: {
issue_4017_1: {
options = {
pure_getters: "strict",
reduce_vars: true,
@@ -2805,7 +2805,31 @@ issue_4017: {
var a = 0;
console.log(function() {
c &= 0;
var c;
var c = a++ + (A = a);
}());
}
expect_stdout: "undefined"
}
issue_4017_2: {
options = {
passes: 2,
pure_getters: "strict",
reduce_vars: true,
unused: true,
}
input: {
var a = 0;
console.log(function f() {
var b = c &= 0;
var c = a++ + (A = a);
var d = c && c[f];
}());
}
expect: {
var a = 0;
console.log(function() {
0;
a++,
A = a;
}());
@@ -3248,7 +3272,7 @@ issue_4558_1: {
expect: {
var a = 0;
var b = c >>>= a;
var c;
var c = 0;
b && a++,
console.log(a);
}
@@ -3334,6 +3358,7 @@ issue_4806_1: {
issue_4806_2: {
options = {
sequences: true,
side_effects: true,
toplevel: true,
unused: true,
}

View File

@@ -745,7 +745,7 @@ call_args: {
expect: {
var a = 1;
console.log(1);
+(1, 1);
1, 1;
}
expect_stdout: true
}
@@ -769,7 +769,7 @@ call_args_drop_param: {
}
expect: {
console.log(1);
+(b, 1);
b, 1;
}
expect_stdout: true
}
@@ -888,6 +888,25 @@ unsafe_charAt_noop: {
expect_stdout: "f n"
}
chained_side_effects: {
options = {
evaluate: true,
}
input: {
console.log("foo") || (console.log("bar"), "baz") || console.log("moo");
}
expect: {
console.log("foo") || (console.log("bar"), "baz");
}
expect_stdout: [
"foo",
"bar",
]
expect_warnings: [
"WARN: Condition left of || always true [test/compress/evaluate.js:1,8]",
]
}
issue_1649: {
options = {
evaluate: true,
@@ -3241,3 +3260,119 @@ issue_4886_2: {
}
expect_stdout: "true"
}
issue_5354: {
options = {
evaluate: true,
unsafe: true,
}
input: {
function f(a) {
return +a.toExponential(1);
}
function g(b) {
return 0 + b.toFixed(2);
}
function h(c) {
return 1 * c.toPrecision(3);
}
console.log(typeof f(45), typeof g(67), typeof h(89));
}
expect: {
function f(a) {
return +a.toExponential(1);
}
function g(b) {
return 0 + b.toFixed(2);
}
function h(c) {
return +c.toPrecision(3);
}
console.log(typeof f(45), typeof g(67), typeof h(89));
}
expect_stdout: "number string number"
}
issue_5356: {
options = {
evaluate: true,
inline: true,
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
console.log(function() {
return a++;
var a = a;
}());
}
expect: {
console.log(+a);
var a;
}
expect_stdout: "NaN"
}
issue_5362_1: {
options = {
evaluate: true,
reduce_vars: true,
toplevel: true,
}
input: {
var a = -console;
console.log(delete +a);
}
expect: {
var a = -console;
console.log((+a, true));
}
expect_stdout: "true"
}
issue_5362_2: {
options = {
evaluate: true,
reduce_vars: true,
side_effects: true,
toplevel: true,
unsafe: true,
unused: true,
}
input: {
var a = -console;
console.log(delete +a);
}
expect: {
console.log(true);
}
expect_stdout: "true"
}
issue_5380: {
options = {
evaluate: true,
keep_fnames: true,
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
var a = function f(b) {
return function g() {
for (b in { PASS: 42 });
}(), b;
}("FAIL");
console.log(a);
}
expect: {
var a = function f(b) {
return function g() {
for (b in { PASS: 42 });
}(), b;
}("FAIL");
console.log(a);
}
expect_stdout: "PASS"
}

View File

@@ -1508,6 +1508,48 @@ unsafe_call_3: {
expect_stdout: "3"
}
inline_eval_inner: {
options = {
inline: true,
}
input: {
(function() {
console.log(typeof eval("arguments"));
})();
}
expect: {
(function() {
console.log(typeof eval("arguments"));
})();
}
expect_stdout: "object"
}
inline_eval_outer: {
options = {
inline: true,
toplevel: true,
}
input: {
A = 42;
(function(a) {
console.log(a);
})(A);
console.log(eval("typeof a"));
}
expect: {
A = 42;
(function(a) {
console.log(a);
})(A);
console.log(eval("typeof a"));
}
expect_stdout: [
"42",
"undefined",
]
}
issue_2616: {
options = {
evaluate: true,
@@ -1713,16 +1755,14 @@ issue_2620_5: {
}
expect: {
var c = "FAIL";
(function() {
var a = 0/0;
var NaN = void 0;
!function(a, NaN) {
switch (a) {
case a:
break;
case c = "PASS", NaN:
break;
}
})();
}(NaN);
console.log(c);
}
expect_stdout: "PASS"
@@ -3517,6 +3557,27 @@ functions_inner_var: {
expect_stdout: "undefined undefined"
}
functions_keep_fnames: {
options = {
functions: true,
keep_fnames: true,
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
var FAIL = function PASS() {};
FAIL.p = 42;
console.log(FAIL.name, FAIL.p);
}
expect: {
var FAIL = function PASS() {};
FAIL.p = 42;
console.log(FAIL.name, FAIL.p);
}
expect_stdout: "PASS 42"
}
issue_2437: {
options = {
collapse_vars: true,
@@ -6137,6 +6198,7 @@ issue_4265: {
dead_code: true,
inline: true,
sequences: true,
side_effects: true,
}
input: {
function f() {
@@ -6342,7 +6404,7 @@ issue_4612_4: {
expect: {
console.log(function() {
function f() {
return h();
h();
}
function g() {
return h();
@@ -7635,9 +7697,10 @@ issue_5237: {
}
expect: {
function f() {
while (console.log(0/0));
var NaN = console && console.log(NaN);
return;
while (console.log(NaN));
(function() {
var NaN = console && console.log(NaN);
})();
}
f();
}
@@ -7981,6 +8044,7 @@ issue_5264_2: {
issue_5283: {
options = {
conditionals: true,
if_return: true,
inline: true,
pure_getters: "strict",
@@ -8005,11 +8069,10 @@ issue_5283: {
var a = "FAIL 1";
(function() {
a = "PASS";
if (!console)
(function(a) {
console.log("FAIL 2");
a.p;
})();
console || function(a) {
console.log("FAIL 2");
a.p;
}();
})();
console.log(a);
}
@@ -8084,3 +8147,254 @@ issue_5296: {
}
expect_stdout: "PASS"
}
issue_5316_1: {
options = {
collapse_vars: true,
evaluate: true,
inline: true,
reduce_vars: true,
toplevel: true,
}
input: {
do {
console.log("PASS");
} while (function() {
var a, b = 42 && (console[a = b] = a++);
}());
}
expect: {
do {
console.log("PASS");
} while (b = a = void 0, b = (42, console[a = a] = a++), void 0);
var a, b;
}
expect_stdout: "PASS"
}
issue_5316_2: {
options = {
collapse_vars: true,
evaluate: true,
inline: true,
reduce_vars: true,
toplevel: true,
}
input: {
do {
(function() {
var a, b = 42 && (console[a = b] = a++);
while (console.log("PASS"));
})();
} while (!console);
}
expect: {
do {
a = void 0;
var a, b = (42, console[a = b = void 0] = a++);
while (console.log("PASS"));
} while (!console);
}
expect_stdout: "PASS"
}
issue_5328: {
options = {
inline: true,
}
input: {
(function(arguments) {
console.log(Object.keys(arguments).join());
})(this);
}
expect: {
(function(arguments) {
console.log(Object.keys(arguments).join());
})(this);
}
expect_stdout: ""
}
issue_5332_1: {
options = {
inline: true,
merge_vars: true,
reduce_vars: true,
side_effects: true,
toplevel: true,
unused: true,
}
input: {
do {
var a = {};
for (A in a)
a;
} while (function() {
console.log(b);
var b = b;
}());
}
expect: {
do {
var a = {};
for (A in a);
} while (a = void 0, void console.log(a));
}
expect_stdout: "undefined"
}
issue_5332_2: {
options = {
inline: true,
merge_vars: true,
reduce_vars: true,
side_effects: true,
toplevel: true,
unused: true,
}
input: {
do {
var a = 42 in [];
for (A in a)
a;
} while (function() {
console.log(++b);
var b = b;
}());
}
expect: {
do {
var a = 42 in [];
for (A in a);
} while (a = void 0, void console.log(++a));
}
expect_stdout: "NaN"
}
issue_5366: {
options = {
inline: true,
}
input: {
for (console.log("foo") || function() {
while (console.log("bar"));
}(); console.log("baz") ;);
}
expect: {
if (!console.log("foo"))
while (console.log("bar"));
for (;console.log("baz"););
}
expect_stdout: [
"foo",
"bar",
"baz",
]
}
issue_5376_1: {
options = {
evaluate: true,
inline: true,
join_vars: true,
loops: true,
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
"use strict";
var a;
for (;42;)
var b = function() {
var c;
throw new Error(c++);
}();
}
expect: {
"use strict";
for (;;) {
42;
throw new Error(NaN);
}
}
expect_stdout: Error("NaN")
}
issue_5376_2: {
options = {
evaluate: true,
inline: true,
join_vars: true,
loops: true,
side_effects: true,
toplevel: true,
unused: true,
}
input: {
"use strict";
var a;
for (;42;)
var b = function() {
var c;
c++;
throw new Error("PASS");
}();
}
expect: {
"use strict";
for (;;) {
0;
throw new Error("PASS");
}
}
expect_stdout: Error("PASS")
}
issue_5401: {
options = {
inline: true,
}
input: {
L: for (var a in function() {
while (console.log("PASS"));
}(), a) do {
continue L;
} while (console.log("FAIL"));
}
expect: {
while (console.log("PASS"));
L: for (var a in a) do {
continue L;
} while (console.log("FAIL"));
}
expect_stdout: "PASS"
}
issue_5409: {
options = {
inline: true,
merge_vars: true,
reduce_vars: true,
unused: true,
}
input: {
(function(a) {
(a = console) || FAIL(a);
(function(b) {
console.log(b && b);
while (!console);
})();
})();
}
expect: {
(function(a) {
(a = console) || FAIL(a);
a = void 0;
console.log(a && a);
while (!console);
return;
})();
}
expect_stdout: "undefined"
}

View File

@@ -224,8 +224,7 @@ issue_4489: {
console.log(k);
}
expect: {
!(A = 0);
for (var k in true);
for (var k in !(A = 0));
console.log(k);
}
expect_stdout: "undefined"
@@ -250,8 +249,7 @@ issue_4517: {
expect: {
console.log(function() {
var a = 2;
A = a;
return A + typeof !1;
return (A = a) + typeof !1;
}());
}
expect_stdout: "2boolean"
@@ -408,9 +406,9 @@ issue_4893_2: {
expect: {
try{
(function() {
var b;
b = null;
b.p += 42;
var a;
a = null;
a.p += 42;
})();
} catch (e) {
console.log("PASS");
@@ -500,3 +498,108 @@ issue_5195: {
}
expect_stdout: "[object Object]"
}
issue_5378: {
options = {
hoist_vars: true,
inline: true,
toplevel: true,
}
input: {
var a = 2;
while (a--)
(function() {
var b;
var c;
while (console.log(b));
--b;
})();
}
expect: {
var a = 2;
while (a--) {
b = void 0;
var b, c;
while (console.log(b));
--b;
}
}
expect_stdout: [
"undefined",
"undefined",
]
}
issue_5411_1: {
options = {
collapse_vars: true,
dead_code: true,
hoist_vars: true,
reduce_vars: true,
side_effects: true,
toplevel: true,
}
input: {
var a = "PASS";
b++;
b = a;
var b = b, c = c && c[b];
console.log(b);
}
expect: {
var b, c, a = "PASS";
b++;
b = a;
c = c && c[b];
console.log(b);
}
expect_stdout: "PASS"
}
issue_5411_2: {
options = {
collapse_vars: true,
dead_code: true,
evaluate: true,
hoist_vars: true,
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
var a = "PASS";
b++;
b = a;
var b = b, c = c && c[b];
console.log(b);
}
expect: {
var b, c;
b++;
b = "PASS",
c = c && c[b];
console.log(b);
}
expect_stdout: "PASS"
}
issue_5411_3: {
options = {
collapse_vars: true,
hoist_vars: true,
reduce_vars: true,
toplevel: true,
}
input: {
var a = console;
a++;
var a = A = a;
console.log(A);
}
expect: {
var a = console;
a = A = ++a;
console.log(A);
}
expect_stdout: "NaN"
}

View File

@@ -2631,13 +2631,14 @@ issue_3999: {
]
}
issue_4001: {
issue_4001_1: {
options = {
collapse_vars: true,
ie: true,
inline: true,
reduce_vars: true,
sequences: true,
side_effects: false,
toplevel: true,
unused: true,
}
@@ -2660,7 +2661,42 @@ issue_4001: {
return a;
}
var a;
console.log((a = 42, void f()[42], void function a() {}));
console.log((a = 42, f()[42], void f, void function a() {}));
}
expect_stdout: "undefined"
}
issue_4001_2: {
options = {
collapse_vars: true,
ie: true,
inline: true,
reduce_vars: true,
sequences: true,
side_effects: true,
toplevel: true,
unused: true,
}
input: {
console.log(function(a) {
function f() {
return a;
var b;
}
var c = f();
(function g() {
c[42];
f;
})();
(function a() {});
}(42));
}
expect: {
function f() {
return a;
}
var a;
console.log((a = 42, void f()[42]));
}
expect_stdout: "undefined"
}
@@ -3408,3 +3444,33 @@ issue_5269_3_ie: {
"bar",
]
}
issue_5350: {
options = {
ie: false,
properties: true,
side_effects: true,
}
input: {
console.log(typeof f, [ 42, function f() {} ][0]);
}
expect: {
console.log(typeof f, 42);
}
expect_stdout: "undefined 42"
}
issue_5350_ie: {
options = {
ie: true,
properties: true,
side_effects: true,
}
input: {
console.log(typeof f, [ 42, function f() {} ][0]);
}
expect: {
console.log(typeof f, (function f() {}, 42));
}
expect_stdout: "undefined 42"
}

View File

@@ -327,7 +327,7 @@ issue_512: {
}
}
if_var_return: {
if_var_return_1: {
options = {
conditionals: true,
if_return: true,
@@ -373,6 +373,76 @@ if_var_return: {
}
}
if_var_return_2: {
options = {
conditionals: true,
if_return: true,
sequences: true,
}
input: {
(function() {
var a = w();
if (x())
return y();
z();
})();
}
expect: {
(function() {
var a = w();
return x() ? y() : (z(), void 0);
})();
}
}
if_var_retrn_3: {
options = {
conditionals: true,
if_return: true,
sequences: true,
}
input: {
f(function() {
var a = w();
if (x())
return y(a);
z();
});
}
expect: {
f(function() {
var a = w();
if (x())
return y(a);
z();
});
}
}
if_var_return_4: {
options = {
conditionals: true,
if_return: true,
sequences: true,
}
input: {
function f() {
if (u())
return v();
var a = w();
if (x())
return y();
z();
}
}
expect: {
function f() {
return u() ? v() : (a = w(), x() ? y() : (z(), void 0));
var a;
}
}
}
if_if_return_return: {
options = {
conditionals: true,
@@ -628,7 +698,9 @@ iife_if_return_simple: {
nested_if_break: {
options = {
conditionals: true,
if_return: true,
side_effects: true,
}
input: {
for (var i = 0; i < 3; i++)
@@ -639,8 +711,7 @@ nested_if_break: {
}
expect: {
for (var i = 0; i < 3; i++)
L1: if ("number" == typeof i)
if (0 !== i) console.log(i);
L1: "number" == typeof i && 0 !== i && console.log(i);
}
expect_stdout: [
"1",
@@ -679,11 +750,11 @@ nested_if_continue: {
function f(n) {
for (var i = 0;
"number" == typeof n
&& (0 !== n
? 1 !== n
? i++
: console.log("odd", i)
: console.log("even", i)),
&& (0 === n
? console.log("even", i)
: 1 === n
? console.log("odd", i)
: i++),
0 <= (n -= 2););
}
f(37);

View File

@@ -0,0 +1,100 @@
numeric: {
beautify = {
beautify: true,
indent_start: 1,
indent_level: 3,
}
input: {
switch (42) {
case null:
console.log("FAIL");
}
console.log("PASS");
}
expect_exact: [
" switch (42) {",
" case null:",
' console.log("FAIL");',
" }",
"",
' console.log("PASS");',
]
expect_stdout: "PASS"
}
spaces: {
beautify = {
beautify: true,
indent_start: " ",
indent_level: " ",
}
input: {
switch (42) {
case null:
console.log("FAIL");
}
console.log("PASS");
}
expect_exact: [
" switch (42) {",
" case null:",
' console.log("FAIL");',
" }",
"",
' console.log("PASS");',
]
expect_stdout: "PASS"
}
tabs: {
beautify = {
beautify: true,
indent_start: "\t",
indent_level: "\t",
}
input: {
switch (42) {
case null:
console.log("FAIL");
}
console.log("PASS");
}
expect_exact: [
"\tswitch (42) {",
"\tcase null:",
'\t\tconsole.log("FAIL");',
"\t}",
"",
'\tconsole.log("PASS");',
]
expect_stdout: "PASS"
}
mixed: {
beautify = {
beautify: true,
indent_start: "\n",
indent_level: " \t",
}
input: {
switch (42) {
case null:
console.log("FAIL");
}
console.log("PASS");
}
expect_exact: [
"",
"switch (42) {",
"",
" case null:",
"",
' \tconsole.log("FAIL");',
"",
"}",
"",
"",
'console.log("PASS");',
]
expect_stdout: "PASS"
}

View File

@@ -4,22 +4,21 @@ multiple_functions: {
if_return: true,
}
input: {
( function() {
if ( !window ) {
(function() {
if (!window)
return;
}
function f() {}
function g() {}
} )();
})();
}
expect: {
( function() {
(function() {
// NOTE: other compression steps will reduce this
// down to just `window`.
if ( !window );
if (!window);
function f() {}
function g() {}
} )();
})();
}
}
@@ -29,18 +28,17 @@ single_function: {
if_return: true,
}
input: {
( function() {
if ( !window ) {
(function() {
if (!window)
return;
}
function f() {}
} )();
})();
}
expect: {
( function() {
if ( !window );
(function() {
if (!window);
function f() {}
} )();
})();
}
}
@@ -50,28 +48,26 @@ deeply_nested: {
if_return: true,
}
input: {
( function() {
if ( !window ) {
(function() {
if (!window)
return;
}
function f() {}
function g() {}
if ( !document ) {
if (!document)
return;
}
function h() {}
} )();
})();
}
expect: {
( function() {
(function() {
// NOTE: other compression steps will reduce this
// down to just `window`.
if ( window )
if ( !document );
if (!window);
else if (!document);
function f() {}
function g() {}
function h() {}
} )();
})();
}
}
@@ -81,18 +77,18 @@ not_hoisted_when_already_nested: {
if_return: true,
}
input: {
( function() {
if ( !window ) {
(function() {
if (!window)
return;
}
if ( foo ) function f() {}
} )();
if (foo) function f() {}
})();
}
expect: {
( function() {
if ( window )
if ( foo ) function f() {}
} )();
(function() {
if (!window);
else if (foo)
function f() {}
})();
}
}
@@ -104,15 +100,19 @@ defun_if_return: {
input: {
function e() {
function f() {}
if (!window) return;
else function g() {}
if (!window)
return;
else
function g() {}
function h() {}
}
}
expect: {
function e() {
function f() {}
if (window) function g() {}
if (!window);
else
function g() {}
function h() {}
}
}
@@ -126,8 +126,10 @@ defun_hoist_funs: {
input: {
function e() {
function f() {}
if (!window) return;
else function g() {}
if (!window)
return;
else
function g() {}
function h() {}
}
}
@@ -136,7 +138,7 @@ defun_hoist_funs: {
function f() {}
function g() {}
function h() {}
if (window);
if (!window);
}
}
}
@@ -149,15 +151,18 @@ defun_else_if_return: {
input: {
function e() {
function f() {}
if (window) function g() {}
else return;
if (window)
function g() {}
else
return;
function h() {}
}
}
expect: {
function e() {
function f() {}
if (window) function g() {}
if (window)
function g() {}
function h() {}
}
}

View File

@@ -40,6 +40,9 @@ conditional_false_stray_else_in_loop: {
console.log(i);
}
}
expect_exact: "for(var i=1;i<=4;++i)if(!(i<=2))console.log(i);"
expect_stdout: true
expect_exact: "for(var i=1;i<=4;++i)if(i<=2);else console.log(i);"
expect_stdout: [
"3",
"4",
]
}

View File

@@ -317,7 +317,35 @@ iife: {
typeof function g() {}();
}
expect: {
x = 42, function a() {}(), function b() {}(), function c() {}(),
function d() {}(), function e() {}(), function f() {}(), typeof function g() {}();
x = 42,
function a() {}(),
!function b() {}(),
~function c() {}(),
+function d() {}(),
-function e() {}(),
void function f() {}(),
typeof function g() {}();
}
}
iife_drop_side_effect_free: {
options = {
expression: true,
sequences: true,
side_effects: true,
}
input: {
x = 42;
(function a() {})();
!function b() {}();
~function c() {}();
+function d() {}();
-function e() {}();
void function f() {}();
typeof function g() {}();
}
expect: {
x = 42,
typeof void 0;
}
}

View File

@@ -1,4 +1,4 @@
issue979_reported: {
reported: {
options = {
booleans: true,
comparisons: true,
@@ -17,29 +17,26 @@ issue979_reported: {
}
input: {
function f1() {
if (a == 1 || b == 2) {
if (a == 1 || b == 2)
foo();
}
}
function f2() {
if (!(a == 1 || b == 2)) {
}
else {
if (!(a == 1 || b == 2));
else
foo();
}
}
}
expect: {
function f1() {
1!=a&&2!=b||foo();
1 != a && 2 != b || foo();
}
function f2() {
1!=a&&2!=b||foo();
1 != a && 2 != b || foo();
}
}
}
issue979_test_negated_is_best: {
test_negated_is_best: {
options = {
booleans: true,
comparisons: true,
@@ -58,53 +55,47 @@ issue979_test_negated_is_best: {
}
input: {
function f3() {
if (a == 1 | b == 2) {
if (a == 1 | b == 2)
foo();
}
}
function f4() {
if (!(a == 1 | b == 2)) {
}
else {
if (!(a == 1 | b == 2));
else
foo();
}
}
function f5() {
if (a == 1 && b == 2) {
if (a == 1 && b == 2)
foo();
}
}
function f6() {
if (!(a == 1 && b == 2)) {
}
else {
if (!(a == 1 && b == 2));
else
foo();
}
}
function f7() {
if (a == 1 || b == 2) {
if (a == 1 || b == 2)
foo();
}
else {
else
return bar();
}
}
}
expect: {
function f3() {
1==a|2==b&&foo();
1 == a | 2 == b && foo();
}
function f4() {
1==a|2==b&&foo();
1 == a | 2 == b && foo();
}
function f5() {
1==a&&2==b&&foo();
1 == a && 2 == b && foo();
}
function f6() {
1!=a||2!=b||foo();
1 == a && 2 == b && foo();
}
function f7() {
if(1!=a&&2!=b)return bar();foo()
if (1 != a && 2 != b)
return bar();
foo();
}
}
}

View File

@@ -1144,7 +1144,7 @@ conditional_assignments_3: {
expect_stdout: "PASS"
}
issue_3856: {
issue_3856_1: {
options = {
booleans: true,
conditionals: true,
@@ -1169,9 +1169,46 @@ issue_3856: {
console.log(function() {
(function() {
var a, b;
if (a) return a, 1;
for (a = 0; !console;);
return 0;
if (a) a;
else {
a = 0;
for (; !console;);
}
})();
}());
}
expect_stdout: "undefined"
}
issue_3856_2: {
options = {
booleans: true,
conditionals: true,
if_return: true,
join_vars: true,
passes: 2,
sequences: true,
side_effects: true,
}
input: {
console.log(function() {
(function() {
var a;
if (!a) {
a = 0;
for (var b; !console;);
return 0;
}
if (a) return 1;
})();
}());
}
expect: {
console.log(function() {
(function() {
var a, b;
if (!a)
for (a = 0; !console;);
})();
}());
}

View File

@@ -1258,8 +1258,7 @@ issues_3267_1: {
}
expect: {
!function() {
var i = Object();
if (i)
if (Object())
return console.log("PASS");
throw "FAIL";
}();

View File

@@ -912,8 +912,7 @@ do_if_continue_1: {
expect: {
"use strict";
do {
if (!console);
else {
if (console) {
console.log("PASS");
{
let a = 0;
@@ -946,8 +945,7 @@ do_if_continue_2: {
expect: {
"use strict";
do {
if (!console);
else {
if (console) {
console.log("FAIL");
{
let a = 0;
@@ -1667,9 +1665,7 @@ issue_4438: {
expect: {
"use strict";
function f() {
if (!console)
;
else {
if (console) {
let a = console.log;
void a("PASS");
}
@@ -1757,6 +1753,7 @@ issue_4689: {
issue_4691: {
options = {
conditionals: true,
if_return: true,
toplevel: true,
}
@@ -1973,3 +1970,53 @@ issue_5260: {
]
node_version: ">=4"
}
issue_5319: {
options = {
collapse_vars: true,
merge_vars: true,
}
input: {
"use strict";
(function(a, c) {
var b = a, c = b;
{
let a = c;
console.log(c());
}
})(function() {
return "PASS";
});
}
expect: {
"use strict";
(function(a, c) {
var b = a, c;
{
let a = c = b;
console.log(c());
}
})(function() {
return "PASS";
});
}
expect_stdout: "PASS"
node_version: ">=4"
}
issue_5338: {
options = {
unused: true,
}
input: {
"use strict";
let a = a;
}
expect: {
"use strict";
a;
let a;
}
expect_stdout: ReferenceError("a is not defined")
node_version: ">=4"
}

View File

@@ -37,6 +37,51 @@ just_enough: {
expect_warnings: []
}
drop_semicolon: {
beautify = {
max_line_len: 5,
semicolons: true,
}
input: {
var a;
console.log(a || 42);
}
expect_exact: [
"var a",
"console.log(",
"a||42",
");",
]
expect_stdout: "42"
expect_warnings: [
"WARN: Output exceeds 5 characters",
]
}
template_newline: {
beautify = {
max_line_len: 2,
}
input: {
console.log(`foo
bar`);
}
expect_exact: [
"console.log(",
"`foo",
"bar`",
");",
]
expect_stdout: [
"foo",
"bar",
]
expect_warnings: [
"WARN: Output exceeds 2 characters",
]
node_version: ">=4"
}
issue_304: {
beautify = {
max_line_len: 10,

View File

@@ -169,6 +169,158 @@ conditional_branch: {
expect_stdout: "PASS"
}
conditional_chain_1: {
options = {
merge_vars: true,
}
input: {
function f(a, b) {
var c, d;
if (a && (c = a))
console.log(c);
else
b || (d = b) ? console.log("foo") : console.log(d);
}
f("", null);
f("", true);
f(42, null);
f(42, true);
}
expect: {
function f(a, b) {
var a, a;
if (a && (a = a))
console.log(a);
else
b || (a = b) ? console.log("foo") : console.log(a);
}
f("", null);
f("", true);
f(42, null);
f(42, true);
}
expect_stdout: [
"null",
"foo",
"42",
"42",
]
}
conditional_chain_2: {
options = {
merge_vars: true,
}
input: {
function f(a, b) {
var c, d;
if (a && (c = a))
console.log(c);
else
b || (d = b) ? console.log(c) : console.log(d);
}
f("", null);
f("", true);
f(42, null);
f(42, true);
}
expect: {
function f(a, b) {
var c, a;
if (a && (c = a))
console.log(c);
else
b || (a = b) ? console.log(c) : console.log(a);
}
f("", null);
f("", true);
f(42, null);
f(42, true);
}
expect_stdout: [
"null",
"undefined",
"42",
"42",
]
}
conditional_chain_3: {
options = {
merge_vars: true,
}
input: {
function f(a, b) {
var c, d;
if (a && (c = a) || b || (d = b))
console.log(c);
else
console.log(d);
}
f("", null);
f("", true);
f(42, null);
f(42, true);
}
expect: {
function f(a, b) {
var c, a;
if (a && (c = a) || b || (a = b))
console.log(c);
else
console.log(a);
}
f("", null);
f("", true);
f(42, null);
f(42, true);
}
expect_stdout: [
"null",
"undefined",
"42",
"42",
]
}
conditional_chain_4: {
options = {
merge_vars: true,
}
input: {
function f(a, b) {
var c, d;
if (a && b ? c = a : d = b)
console.log(c);
else
console.log(d);
}
f("", null);
f("", true);
f(42, null);
f(42, true);
}
expect: {
function f(a, b) {
var c, d;
if (a && b ? c = a : d = b)
console.log(c);
else
console.log(d);
}
f("", null);
f("", true);
f(42, null);
f(42, true);
}
expect_stdout: [
"null",
"undefined",
"null",
"42",
]
}
if_branch: {
options = {
merge_vars: true,
@@ -253,6 +405,7 @@ read_before_assign_1: {
inline: true,
merge_vars: true,
sequences: true,
side_effects: true,
toplevel: true,
}
input: {
@@ -3549,3 +3702,33 @@ issue_5182: {
]
node_version: ">=4"
}
issue_5420: {
options = {
merge_vars: true,
toplevel: true,
}
input: {
do {
var a = "FAIL 1";
a && a.p;
a = "FAIL 2";
try {
continue;
} catch (e) {}
var b = "FAIL 3";
} while (console.log(b || "PASS"));
}
expect: {
do {
var a = "FAIL 1";
a && a.p;
a = "FAIL 2";
try {
continue;
} catch (e) {}
var b = "FAIL 3";
} while (console.log(b || "PASS"));
}
expect_stdout: "PASS"
}

View File

@@ -122,13 +122,41 @@ negate_iife_4: {
sequences: true,
}
input: {
(function(){ return t })() ? console.log(true) : console.log(false);
(function(){
(function() {
return t;
})() ? console.log(true) : console.log(false);
(function() {
console.log("something");
})();
}
expect: {
!function(){ return t }() ? console.log(false) : console.log(true), function(){
!function() {
return t;
}() ? console.log(false) : console.log(true), !function() {
console.log("something");
}();
}
}
negate_iife_4_drop_side_effect_free: {
options = {
conditionals: true,
negate_iife: true,
sequences: true,
side_effects: true,
}
input: {
(function() {
return t;
})() ? console.log(true) : console.log(false);
(function() {
console.log("something");
})();
}
expect: {
!function() {
return t;
}() ? console.log(false) : console.log(true), function() {
console.log("something");
}();
}
@@ -176,17 +204,49 @@ negate_iife_5: {
sequences: true,
}
input: {
if ((function(){ return t })()) {
if (function() {
return t;
}()) {
foo(true);
} else {
bar(false);
}
(function(){
(function() {
console.log("something");
})();
}
expect: {
!function(){ return t }() ? bar(false) : foo(true), function(){
!function() {
return t;
}() ? bar(false) : foo(true), !function() {
console.log("something");
}();
}
}
negate_iife_5_drop_side_effect_free: {
options = {
conditionals: true,
negate_iife: true,
sequences: true,
side_effects: true,
}
input: {
if (function() {
return t;
}()) {
foo(true);
} else {
bar(false);
}
(function() {
console.log("something");
})();
}
expect: {
!function() {
return t;
}() ? bar(false) : foo(true), function() {
console.log("something");
}();
}

View File

@@ -842,9 +842,9 @@ unary_binary_parentheses: {
v.forEach(function(x) {
v.forEach(function(y) {
console.log(
+x*y,
+x/y,
+x%y,
x*y,
x/y,
x%y,
-x*y,
-x/y,
-x%y
@@ -1397,7 +1397,7 @@ issue_3695: {
}
expect: {
var a = [];
console.log(+(a * (a[0] = false)));
console.log(a * (a[0] = false));
}
expect_stdout: "NaN"
}

View File

@@ -97,10 +97,10 @@ return_5: {
}
expect_exact: [
"_is_selected=function(tags,slug){",
"var ref",
"var ref;",
"",
"",
";return null!=(ref=_.find(tags,{slug:slug}))?ref.selected:void 0};",
"return null!=(ref=_.find(tags,{slug:slug}))?ref.selected:void 0};",
]
}
@@ -146,10 +146,10 @@ return_7: {
}
expect_exact: [
"_is_selected=function(e,l){",
"var n",
"var n;",
"",
"",
";return null!=(n=_.find(e,{slug:l}))?n.selected:void 0};",
"return null!=(n=_.find(e,{slug:l}))?n.selected:void 0};",
]
}

View File

@@ -1289,6 +1289,7 @@ issue_2878: {
collapse_vars: true,
pure_getters: true,
sequences: true,
side_effects: true,
}
input: {
var c = 0;

View File

@@ -6,6 +6,7 @@ reduce_vars: {
C: 0,
},
inline: true,
passes: 2,
reduce_funcs: true,
reduce_vars: true,
toplevel: true,
@@ -6688,8 +6689,7 @@ issues_3267_1: {
}
expect: {
!function(x) {
var i = Object();
if (i)
if (Object())
return console.log("PASS");
throw "FAIL";
}();
@@ -7832,3 +7832,67 @@ issue_5055_2: {
}
expect_stdout: "PASS"
}
issue_5324: {
options = {
inline: true,
merge_vars: true,
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
A = 0;
do {
var a, b = A;
for (a in b)
var c = b;
} while (function() {
var d;
console.log(d *= A);
}());
}
expect: {
A = 0;
do {
var a, b = A;
for (a in b);
} while (b = void 0, void console.log(b *= A));
}
expect_stdout: "NaN"
}
issue_5434: {
options = {
evaluate: true,
reduce_vars: true,
unused: true,
}
input: {
console.log(function(a) {
for (var i = 0; i < 2; i++) {
var b = "FAIL";
f && f();
a = b;
var f = function() {
b = "PASS";
};
}
return a;
}());
}
expect: {
console.log(function(a) {
for (var i = 0; i < 2; i++) {
var b = "FAIL";
f && f();
a = b;
var f = function() {
b = "PASS";
};
}
return a;
}());
}
expect_stdout: "PASS"
}

View File

@@ -349,6 +349,7 @@ retain_funarg_destructured_object_1: {
retain_funarg_destructured_object_2: {
options = {
keep_fargs: false,
unused: true,
}
input: {
@@ -1048,7 +1049,9 @@ issue_5100_1: {
p: {},
...a
} = [ {
p: [ a = 42["q"] ],
p: {
q: a,
} = 42,
r: "PASS",
} ][0]);
console.log(a.r);
@@ -1081,7 +1084,9 @@ issue_5100_2: {
p: {},
...a
} = [ {
p: [ console.log("PASS"), a = 42["q"] ],
p: (console.log("PASS"), {
q: a,
} = 42),
} ][0]);
}
expect_stdout: "PASS"
@@ -1091,6 +1096,7 @@ issue_5100_2: {
issue_5108: {
options = {
evaluate: true,
keep_fargs: false,
reduce_vars: true,
rests: true,
unsafe: true,
@@ -1102,9 +1108,7 @@ issue_5108: {
}([ "PASS", "FAIL" ]));
}
expect: {
console.log(function([]) {
return "PASS";
}([]));
console.log("PASS");
}
expect_stdout: "PASS"
node_version: ">=6"
@@ -1208,6 +1212,7 @@ issue_5165_2: {
issue_5246_1: {
options = {
keep_fargs: false,
reduce_vars: true,
rests: true,
unused: true,
@@ -1218,9 +1223,9 @@ issue_5246_1: {
}([ , function(){} ])[0]);
}
expect: {
console.log(typeof function([]) {
console.log(typeof function() {
return this && [ function(){} ];
}([])[0]);
}()[0]);
}
expect_stdout: "function"
node_version: ">=6"
@@ -1228,6 +1233,7 @@ issue_5246_1: {
issue_5246_2: {
options = {
keep_fargs: false,
reduce_vars: true,
rests: true,
toplevel: true,
@@ -1249,6 +1255,7 @@ issue_5246_2: {
issue_5246_3: {
options = {
keep_fargs: false,
unused: true,
}
input: {
@@ -1264,3 +1271,95 @@ issue_5246_3: {
expect_stdout: "PASS"
node_version: ">=6"
}
issue_5360: {
options = {
keep_fargs: false,
pure_getters: "strict",
unused: true,
}
input: {
var a;
console.log(function({ p: {}, ...b }) {
return b.q;
}({
p: ~a && ([ a ] = []),
q: "PASS",
}));
}
expect: {
var a;
console.log(function({ p: {}, ...b }) {
return b.q;
}({
p: ~a && ([ a ] = []),
q: "PASS",
}));
}
expect_stdout: "PASS"
node_version: ">=8.3.0"
}
issue_5370: {
options = {
dead_code: true,
ie: true,
unused: true,
}
input: {
console.log(function arguments(...a) {
return arguments;
try {} catch (e) {
var arguments;
}
}());
}
expect: {
console.log(function arguments(...a) {
return arguments;
var arguments;
}());
}
expect_stdout: true
node_version: ">=6"
}
issue_5391: {
options = {
evaluate: true,
keep_fargs: false,
objects: true,
pure_getters: "strict",
reduce_vars: true,
side_effects: true,
toplevel: true,
unused: true,
}
input: {
var a, b = function f({
p: {},
...c
}) {
while (c.q);
}({
p: {
r: a++,
r: 0,
}
});
console.log(a);
}
expect: {
(function({
p: {},
...c
}) {
while (c.q);
})({
p: 0,
});
console.log(NaN);
}
expect_stdout: "NaN"
node_version: ">=8.3.0"
}

View File

@@ -289,8 +289,34 @@ iife: {
typeof function g() {}();
}
expect: {
x = 42, function a() {}(), function b() {}(), function c() {}(),
function d() {}(), function e() {}(), function f() {}(), function g() {}();
x = 42,
function a() {}(),
!function b() {}(),
~function c() {}(),
+function d() {}(),
-function e() {}(),
void function f() {}(),
typeof function g() {}();
}
}
iife_drop_side_effect_free: {
options = {
sequences: true,
side_effects: true,
}
input: {
x = 42;
(function a() {})();
!function b() {}();
~function c() {}();
+function d() {}();
-function e() {}();
void function f() {}();
typeof function g() {}();
}
expect: {
x = 42;
}
}
@@ -1045,11 +1071,102 @@ call: {
b.c = function() {
console.log(this === b ? "bar" : "baz");
},
a,
b(),
a,
b.c(),
(a, b.c)(),
a,
b["c"](),
(a, b["c"])(),
a,
function() {
console.log(this === a);
}(),
a,
new b(),
a,
new b.c(),
a,
new b.c(),
a,
new b["c"](),
a,
new b["c"](),
a,
new function() {
console.log(this === a);
}(),
console.log((a, typeof b.c)),
console.log((a, typeof b["c"]));
}
expect_stdout: [
"foo",
"bar",
"baz",
"bar",
"baz",
"true",
"foo",
"baz",
"baz",
"baz",
"baz",
"false",
"function",
"function",
]
}
call_drop_side_effect_free: {
options = {
sequences: true,
side_effects: true,
}
input: {
var a = function() {
return this;
}();
function b() {
console.log("foo");
}
b.c = function() {
console.log(this === b ? "bar" : "baz");
};
(a, b)();
(a, b).c();
(a, b.c)();
(a, b)["c"]();
(a, b["c"])();
(a, function() {
console.log(this === a);
})();
new (a, b)();
new (a, b).c();
new (a, b.c)();
new (a, b)["c"]();
new (a, b["c"])();
new (a, function() {
console.log(this === a);
})();
console.log(typeof (a, b).c);
console.log(typeof (a, b)["c"]);
}
expect: {
var a = function() {
return this;
}();
function b() {
console.log("foo");
}
b.c = function() {
console.log(this === b ? "bar" : "baz");
},
b(),
b.c(),
(0, b.c)(),
b["c"](),
(0, b["c"])(),
function() {
console.log(this === a);
}(),
@@ -1061,8 +1178,8 @@ call: {
new function() {
console.log(this === a);
}(),
console.log((a, typeof b.c)),
console.log((a, typeof b["c"]));
console.log(typeof b.c),
console.log(typeof b["c"]);
}
expect_stdout: [
"foo",
@@ -1097,6 +1214,26 @@ missing_link: {
expect: {
var a = 100;
a,
a++ + (0, 1),
console.log(a);
}
}
missing_link_drop_side_effect_free: {
options = {
conditionals: true,
evaluate: true,
sequences: true,
side_effects: true,
}
input: {
var a = 100;
a;
a++ + (0 ? 2 : 1);
console.log(a);
}
expect: {
var a = 100;
a++,
console.log(a);
}
@@ -1192,7 +1329,7 @@ issue_3490_2: {
expect: {
var b = 42, c = "FAIL";
var a;
for (c = "PASS", b; "" == typeof d;);
for (c = "PASS"; "" == typeof d;);
console.log(c, b);
}
expect_stdout: "PASS 42"

View File

@@ -617,7 +617,7 @@ issue_4730_2: {
}
expect: {
var a;
!console.log("PASS") || a && a[a.p];
console.log("PASS") && a && a[a.p];
}
expect_stdout: "PASS"
}

View File

@@ -1166,3 +1166,31 @@ issue_5006: {
expect_stdout: "PASS"
node_version: ">=6"
}
issue_5382: {
options = {
side_effects: true,
}
input: {
({
f() {
({ ...this });
},
get p() {
console.log("PASS");
},
}).f();
}
expect: {
({
f() {
({ ...this });
},
get p() {
console.log("PASS");
},
}).f();
}
expect_stdout: "PASS"
node_version: ">=8.3.0"
}

View File

@@ -307,7 +307,7 @@ typeof_defined_1: {
}
expect: {
"undefined" == typeof A && A;
"undefined" != typeof A || A;
"undefined" == typeof A && A;
}
}
@@ -324,7 +324,7 @@ typeof_defined_2: {
}
expect: {
"function" != typeof A && A;
"function" == typeof A || A;
"function" != typeof A && A;
}
}
@@ -355,16 +355,19 @@ typeof_defined_3: {
"undefined" == typeof A && "undefined" == typeof B && (A, B);
"undefined" == typeof A && "undefined" != typeof B && A;
"undefined" != typeof A && "undefined" == typeof B && B;
// dropped
"undefined" == typeof A && "undefined" == typeof B || (A, B);
"undefined" == typeof A && "undefined" != typeof B || (A, B);
"undefined" != typeof A && "undefined" == typeof B || (A, B);
"undefined" != typeof A && "undefined" != typeof B || (A, B);
"undefined" == typeof A || "undefined" == typeof B && B;
"undefined" != typeof A || "undefined" == typeof B && (A, B);
"undefined" != typeof A || "undefined" != typeof B && A;
"undefined" == typeof A || "undefined" != typeof B || B;
"undefined" != typeof A || "undefined" == typeof B || A;
"undefined" != typeof A || "undefined" != typeof B || (A, B);
"undefined" != typeof A && "undefined" == typeof B && B;
// dropped
"undefined" == typeof A && "undefined" == typeof B && (A, B);
"undefined" == typeof A && "undefined" != typeof B && A;
// dropped
"undefined" != typeof A && "undefined" == typeof B && B;
"undefined" == typeof A && "undefined" != typeof B && A;
"undefined" == typeof A && "undefined" == typeof B && (A, B);
}
}
@@ -392,6 +395,7 @@ typeof_defined_4: {
"object" != typeof A || "object" != typeof B || (A, B);
}
expect: {
// dropped
"object" == typeof A && "object" != typeof B && B;
"object" != typeof A && "object" == typeof B && A;
"object" != typeof A && "object" != typeof B && (A, B);
@@ -399,12 +403,14 @@ typeof_defined_4: {
"object" == typeof A && "object" != typeof B || (A, B);
"object" != typeof A && "object" == typeof B || (A, B);
"object" != typeof A && "object" != typeof B || (A, B);
"object" == typeof A || "object" == typeof B && A;
"object" == typeof A || "object" != typeof B && (A, B);
"object" != typeof A || "object" != typeof B && B;
"object" == typeof A || "object" == typeof B || (A, B);
"object" == typeof A || "object" != typeof B || A;
"object" != typeof A || "object" == typeof B || B;
"object" != typeof A && "object" == typeof B && A;
"object" != typeof A && "object" != typeof B && (A, B);
// dropped
"object" == typeof A && "object" != typeof B && B;
"object" != typeof A && "object" != typeof B && (A, B);
"object" != typeof A && "object" == typeof B && A;
"object" == typeof A && "object" != typeof B && B;
// dropped
}
}

View File

@@ -1375,6 +1375,7 @@ issue_5076_1: {
options = {
evaluate: true,
hoist_vars: true,
keep_fargs: false,
pure_getters: "strict",
sequences: true,
side_effects: true,
@@ -1404,6 +1405,7 @@ issue_5076_2: {
options = {
evaluate: true,
hoist_vars: true,
keep_fargs: false,
passes: 2,
pure_getters: "strict",
sequences: true,
@@ -1449,3 +1451,99 @@ issue_5177: {
expect_stdout: "function"
node_version: ">=4"
}
issue_5385_1: {
options = {
inline: true,
}
input: {
(async function*() {
(function() {
try {
return console.log("foo");
} finally {
return console.log("bar");
}
console.log("baz");
})();
})().next();
console.log("moo");
}
expect: {
(async function*() {
(function() {
try {
return console.log("foo");
} finally {
return console.log("bar");
}
console.log("baz");
})();
})().next();
console.log("moo");
}
expect_stdout: [
"foo",
"bar",
"moo",
]
node_version: ">=10"
}
issue_5385_2: {
options = {
inline: true,
}
input: {
(async function*() {
return function() {
try {
return console.log("foo");
} finally {
return console.log("bar");
}
}();
})().next();
console.log("moo");
}
expect: {
(async function*() {
return function() {
try {
return console.log("foo");
} finally {
return console.log("bar");
}
}();
})().next();
console.log("moo");
}
expect_stdout: [
"foo",
"bar",
"moo",
]
node_version: ">=10"
}
issue_5425: {
options = {
assignments: true,
ie: true,
toplevel: true,
unused: true,
yields: true,
}
input: {
var a = "FAIL";
var b = function* f() {}(a ? a = "PASS" : 42);
console.log(a, typeof f);
}
expect: {
var a = "FAIL";
(function* f() {})(a && (a = "PASS"));
console.log(a, typeof f);
}
expect_stdout: "PASS undefined"
node_version: ">=4"
}

View File

@@ -1,5 +1,5 @@
function test(a){
"aaaaaaaaaaaaaaaa"
;a(err,data),a(err,
"aaaaaaaaaaaaaaaa";
a(err,data),a(err,
data)}
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIjAiXSwibmFtZXMiOlsidGVzdCIsImNhbGxiYWNrIiwiZXJyIiwiZGF0YSJdLCJtYXBwaW5ncyI6IkFBQUEsU0FBU0EsS0FBS0M7O0NBRVZBLEVBQVNDLElBQUtDLE1BQ2RGLEVBQVNDO0FBQUtDIn0=
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIjAiXSwibmFtZXMiOlsidGVzdCIsImNhbGxiYWNrIiwiZXJyIiwiZGF0YSJdLCJtYXBwaW5ncyI6IkFBQUEsU0FBU0E7SEFBS0M7QUFFVkE7aEJBQVNDLElBQUtDLE1BQ2RGLEVBQVNDLElBQUtDIn0=

View File

@@ -0,0 +1,17 @@
var unused;
export default class {
____11111() {
a, b, c, d, e;
f, g, h, i, j;
k, l, m, n, o;
p, q, r, s, t;
u, v, w, x, y, z;
A, B, C, D, E;
F, G, H, I, J;
K, L, M, N, O;
P, Q, R, S, T;
U, V, W, X, Y, Z;
$, _;
unused;
}
}

View File

@@ -7,7 +7,7 @@ describe("async", function() {
"function await() {}",
"function(await) {}",
"function() { await; }",
"function() { await:{} }",
"function() { await: {} }",
"function() { var await; }",
"function() { function await() {} }",
"function() { try {} catch (await) {} }",

View File

@@ -434,4 +434,55 @@ describe("test/reduce.js", function() {
"// }",
].join("\n"));
});
it("Should transform `export default class` correctly", function() {
var result = reduce_test(read("test/input/reduce/export_default.js"), {
compress: false,
toplevel: true,
});
if (result.error) throw result.error;
assert.strictEqual(result.code, [
"// Can't reproduce test failure",
"// minify options: {",
'// "compress": false,',
'// "toplevel": true',
"// }",
].join("\n"));
});
it("Should transform `export default function` correctly", function() {
var code = [
"for (var k in this)",
" console.log(k);",
"export default (function f() {});",
"console.log(k);",
].join("\n");
var result = reduce_test(code, {
mangle: false,
});
if (result.error) throw result.error;
assert.strictEqual(result.code, [
"// Can't reproduce test failure",
"// minify options: {",
'// "mangle": false',
"// }",
].join("\n"));
});
it("Should transform `export default (42)` correctly", function() {
var code = [
"export default (42);",
"for (var k in this)",
" console.log(k);",
].join("\n");
var result = reduce_test(code, {
compress: false,
mangle: false,
});
if (result.error) throw result.error;
assert.strictEqual(result.code, [
"// Can't reproduce test failure",
"// minify options: {",
'// "compress": false,',
'// "mangle": false',
"// }",
].join("\n"));
});
});

View File

@@ -6,7 +6,7 @@ describe("generator", function() {
[
"function yield() {}",
"function(yield) {}",
"function() { yield:{} }",
"function() { yield: {} }",
"function() { var yield; }",
"function() { function yield() {} }",
"function() { try {} catch (yield) {} }",

File diff suppressed because it is too large Load Diff

View File

@@ -52,11 +52,19 @@ exports.same_stdout = semver.satisfies(process.version, "0.12") ? function(expec
return typeof expected == typeof actual && strip_func_ids(expected) == strip_func_ids(actual);
};
exports.patch_module_statements = function(code) {
var count = 0, imports = [];
code = code.replace(/\bexport(?:\s*\{[^{}]*}\s*?(?:$|\n|;)|\s+default\b(?:\s*(\(|\{|class\s*\{|class\s+(?=extends\b)|(?:async\s+)?function\s*(?:\*\s*)?\())?|\b)/g, function(match, header) {
var count = 0, has_default = "", imports = [], strict_mode = "";
code = code.replace(/^\s*("|')use strict\1\s*;?/, function(match) {
strict_mode = match;
return "";
}).replace(/\bexport(?:\s*\{[^{}]*}\s*?(?:$|\n|;)|\s+default\b(?:\s*(\(|\{|class\s*\{|class\s+(?=extends\b)|(?:async\s+)?function\s*(?:\*\s*)?\())?|\b)/g, function(match, header) {
if (/^export\s+default/.test(match)) has_default = "var _uglify_export_default_;";
if (!header) return "";
if (header.length == 1) return "0, " + header;
return header.slice(0, -1) + " _" + ++count + header.slice(-1);
var name = "_uglify_export_default_";
if (/^class\b/.test(header)) do {
name = "_uglify_export_default_" + ++count;
} while (code.indexOf(name) >= 0);
return header.slice(0, -1) + " " + name + header.slice(-1);
}).replace(/\bimport\.meta\b/g, function() {
return '({ url: "https://example.com/path/index.html" })';
}).replace(/\bimport\b(?:\s*([^\s('"][^('"]*)\bfrom\b)?\s*(['"]).*?\2(?:$|\n|;)/g, function(match, symbols) {
@@ -73,7 +81,7 @@ exports.patch_module_statements = function(code) {
return "";
});
imports.push("");
return imports.join("\n") + code;
return strict_mode + has_default + imports.join("\n") + code;
};
function is_error(result) {

View File

@@ -128,7 +128,7 @@ for (var i = 2; i < process.argv.length; ++i) {
var SUPPORT = function(matrix) {
for (var name in matrix) {
matrix[name] = typeof sandbox.run_code(matrix[name]) == "string";
matrix[name] = !sandbox.is_error(sandbox.run_code(matrix[name]));
}
return matrix;
}({
@@ -1824,7 +1824,13 @@ function createClassLiteral(recurmax, stmtDepth, canThrow, name) {
declared.push(internal);
}
if (SUPPORT.class_field && rng(2)) {
s += internal || createObjectKey(recurmax, stmtDepth, canThrow);
if (internal) {
s += internal;
} else if (fixed && bug_static_class_field) {
s += getDotKey();
} else {
s += createObjectKey(recurmax, stmtDepth, canThrow);
}
if (rng(5)) {
async = bug_async_class_await && fixed && 0;
generator = false;
@@ -2110,7 +2116,7 @@ function try_beautify(code, toplevel, result, printfn, options) {
} else if (options) {
var uglified = UglifyJS.minify(beautified.code, JSON.parse(options));
var expected, actual;
if (typeof uglify_code != "string" || uglified.error) {
if (sandbox.is_error(uglify_code) || uglified.error) {
expected = uglify_code;
actual = uglified.error;
} else {
@@ -2139,7 +2145,7 @@ function log_suspects(minify_options, component) {
var defs = default_options[component];
var toplevel = sandbox.has_toplevel(minify_options);
var suspects = Object.keys(defs).filter(function(name) {
var flip = name == "keep_fargs";
var flip = component == "compress" && name == "keep_fargs";
if (flip !== (name in options ? options : defs)[name]) {
var m = JSON.parse(JSON.stringify(minify_options));
var o = JSON.parse(JSON.stringify(options));
@@ -2147,7 +2153,7 @@ function log_suspects(minify_options, component) {
m[component] = o;
m.validate = true;
var result = UglifyJS.minify(original_code, m);
if (typeof uglify_code != "string") {
if (sandbox.is_error(uglify_code)) {
return !sandbox.same_stdout(uglify_code, result.error);
} else if (result.error) {
errorln("Error testing options." + component + "." + name);
@@ -2175,7 +2181,7 @@ function log_suspects_global(options, toplevel) {
m[component] = false;
m.validate = true;
var result = UglifyJS.minify(original_code, m);
if (typeof uglify_code != "string") {
if (sandbox.is_error(uglify_code)) {
return !sandbox.same_stdout(uglify_code, result.error);
} else if (result.error) {
errorln("Error testing options." + component);
@@ -2204,7 +2210,16 @@ function log(options) {
errorln();
errorln();
errorln("//-------------------------------------------------------------");
if (typeof uglify_code == "string") {
if (sandbox.is_error(uglify_code)) {
errorln("// !!! uglify failed !!!");
errorln(uglify_code);
if (original_erred) {
errorln();
errorln();
errorln("original stacktrace:");
errorln(original_result);
}
} else {
errorln("// uglified code");
try_beautify(uglify_code, toplevel, uglify_result, errorln);
errorln();
@@ -2213,15 +2228,6 @@ function log(options) {
errorln(original_result);
errorln("uglified result:");
errorln(uglify_result);
} else {
errorln("// !!! uglify failed !!!");
errorln(uglify_code);
if (errored) {
errorln();
errorln();
errorln("original stacktrace:");
errorln(original_result);
}
}
errorln("//-------------------------------------------------------------");
if (!ok) {
@@ -2426,22 +2432,23 @@ var beautify_options = {
},
};
var minify_options = require("./options.json");
if (typeof sandbox.run_code("A:if (0) B:; else B:;") != "string") {
if (sandbox.is_error(sandbox.run_code("A:if (0) B:; else B:;"))) {
minify_options.forEach(function(o) {
if (!("mangle" in o)) o.mangle = {};
if (o.mangle) o.mangle.v8 = true;
});
}
var bug_async_arrow_rest = function() {};
if (SUPPORT.arrow && SUPPORT.async && SUPPORT.rest && typeof sandbox.run_code("async (a = f(...[], b)) => 0;") != "string") {
if (SUPPORT.arrow && SUPPORT.async && SUPPORT.rest && sandbox.is_error(sandbox.run_code("async (a = f(...[], b)) => 0;"))) {
bug_async_arrow_rest = function(ex) {
return ex.name == "SyntaxError" && ex.message == "Rest parameter must be last formal parameter";
};
}
var bug_async_class_await = SUPPORT.async && SUPPORT.class_field && typeof sandbox.run_code("var await; async function f() { class A { static p = await; } }") != "string";
var bug_for_of_async = SUPPORT.for_await_of && typeof sandbox.run_code("var async; for (async of []);") != "string";
var bug_for_of_var = SUPPORT.for_of && SUPPORT.let && typeof sandbox.run_code("try {} catch (e) { for (var e of []); }") != "string";
if (SUPPORT.destructuring && typeof sandbox.run_code("console.log([ 1 ], {} = 2);") != "string") {
var bug_async_class_await = SUPPORT.async && SUPPORT.class_field && sandbox.is_error(sandbox.run_code("var await; async function f() { class A { static p = await; } }"));
var bug_for_of_async = SUPPORT.for_await_of && sandbox.is_error(sandbox.run_code("var async; for (async of []);"));
var bug_for_of_var = SUPPORT.for_of && SUPPORT.let && sandbox.is_error(sandbox.run_code("try {} catch (e) { for (var e of []); }"));
var bug_static_class_field = SUPPORT.class_field && sandbox.is_error(sandbox.run_code("class A { static 42; static get 42() {} }"));
if (SUPPORT.destructuring && sandbox.is_error(sandbox.run_code("console.log([ 1 ], {} = 2);"))) {
beautify_options.output.v8 = true;
minify_options.forEach(function(o) {
if (!("output" in o)) o.output = {};
@@ -2450,7 +2457,7 @@ if (SUPPORT.destructuring && typeof sandbox.run_code("console.log([ 1 ], {} = 2)
}
beautify_options = JSON.stringify(beautify_options);
minify_options = minify_options.map(JSON.stringify);
var original_code, original_result, errored;
var original_code, original_result, original_erred;
var uglify_code, uglify_result, ok;
for (var round = 1; round <= num_iterations; round++) {
process.stdout.write(round + " of " + num_iterations + "\r");
@@ -2458,7 +2465,7 @@ for (var round = 1; round <= num_iterations; round++) {
original_code = createTopLevelCode();
var orig_result = [ run_code(original_code), run_code(original_code, true) ];
if (orig_result.some(function(result, toplevel) {
if (typeof result == "string") return;
if (!sandbox.is_error(result)) return;
println();
println();
println("//=============================================================");
@@ -2480,35 +2487,44 @@ for (var round = 1; round <= num_iterations; round++) {
o.validate = true;
uglify_code = UglifyJS.minify(original_code, o);
original_result = orig_result[toplevel ? 1 : 0];
errored = typeof original_result != "string";
original_erred = sandbox.is_error(original_result);
if (!uglify_code.error) {
uglify_code = uglify_code.code;
uglify_result = run_code(uglify_code, toplevel);
ok = sandbox.same_stdout(original_result, uglify_result);
var uglify_erred = sandbox.is_error(uglify_result);
// ignore v8 parser bug
if (!ok && bug_async_arrow_rest(uglify_result)) ok = true;
if (!ok && uglify_erred && bug_async_arrow_rest(uglify_result)) ok = true;
// ignore runtime platform bugs
if (!ok && uglify_result.message == "Script execution aborted.") ok = true;
if (!ok && uglify_erred && uglify_result.message == "Script execution aborted.") ok = true;
// handle difference caused by time-outs
if (!ok && errored && is_error_timeout(original_result)) {
if (is_error_timeout(uglify_result)) {
// ignore difference in error message
ok = true;
} else {
if (!ok) {
if (original_erred && is_error_timeout(original_result)) {
if (uglify_erred && is_error_timeout(uglify_result)) {
// ignore difference in error message
ok = true;
} else {
// ignore spurious time-outs
if (!orig_result[toplevel ? 3 : 2]) orig_result[toplevel ? 3 : 2] = run_code(original_code, toplevel, 10000);
ok = sandbox.same_stdout(orig_result[toplevel ? 3 : 2], uglify_result);
}
} else if (uglify_erred && is_error_timeout(uglify_result)) {
// ignore spurious time-outs
if (!orig_result[toplevel ? 3 : 2]) orig_result[toplevel ? 3 : 2] = run_code(original_code, toplevel, 10000);
ok = sandbox.same_stdout(orig_result[toplevel ? 3 : 2], uglify_result);
var waited_result = run_code(uglify_code, toplevel, 10000);
ok = sandbox.same_stdout(original_result, waited_result);
}
}
// ignore declaration order of global variables
if (!ok && !toplevel && uglify_result.name != "SyntaxError" && original_result.name != "SyntaxError") {
ok = sandbox.same_stdout(run_code(sort_globals(original_code)), run_code(sort_globals(uglify_code)));
if (!ok && !toplevel) {
if (!(original_erred && original_result.name == "SyntaxError") && !(uglify_erred && uglify_result.name == "SyntaxError")) {
ok = sandbox.same_stdout(run_code(sort_globals(original_code)), run_code(sort_globals(uglify_code)));
}
}
// ignore numerical imprecision caused by `unsafe_math`
if (!ok && o.compress && o.compress.unsafe_math && typeof original_result == typeof uglify_result) {
if (typeof original_result == "string") {
if (!ok && o.compress && o.compress.unsafe_math) {
if (typeof original_result == "string" && typeof uglify_result == "string") {
ok = fuzzy_match(original_result, uglify_result);
} else if (sandbox.is_error(original_result)) {
} else if (original_erred && uglify_erred) {
ok = original_result.name == uglify_result.name && fuzzy_match(original_result.message, uglify_result.message);
}
if (!ok) {
@@ -2517,19 +2533,19 @@ for (var round = 1; round <= num_iterations; round++) {
}
}
// ignore difference in error message caused by Temporal Dead Zone
if (!ok && errored && uglify_result.name == "ReferenceError" && original_result.name == "ReferenceError") ok = true;
if (!ok && original_erred && uglify_erred && original_result.name == "ReferenceError" && uglify_result.name == "ReferenceError") ok = true;
// ignore difference due to implicit strict-mode in `class`
if (!ok && /\bclass\b/.test(original_code)) {
var original_strict = run_code('"use strict";\n' + original_code, toplevel);
if (/^(Syntax|Type)Error$/.test(uglify_result.name)) {
ok = typeof original_strict != "string";
if (uglify_erred && /^(Syntax|Type)Error$/.test(uglify_result.name)) {
ok = sandbox.is_error(original_strict);
} else {
ok = sandbox.same_stdout(original_strict, uglify_result);
}
}
// ignore difference in error message caused by `import` symbol redeclaration
if (!ok && errored && /\bimport\b/.test(original_code)) {
if (is_error_redeclaration(uglify_result) && is_error_redeclaration(original_result)) ok = true;
if (!ok && original_erred && uglify_erred && /\bimport\b/.test(original_code)) {
if (is_error_redeclaration(original_result) && is_error_redeclaration(uglify_result)) ok = true;
}
// ignore difference due to `__proto__` assignment
if (!ok && /\b__proto__\b/.test(original_code)) {
@@ -2538,24 +2554,32 @@ for (var round = 1; round <= num_iterations; round++) {
ok = sandbox.same_stdout(original_proto, uglify_proto);
}
// ignore difference in error message caused by `in`
if (!ok && errored && is_error_in(uglify_result) && is_error_in(original_result)) ok = true;
if (!ok && original_erred && uglify_erred) {
if (is_error_in(original_result) && is_error_in(uglify_result)) ok = true;
}
// ignore difference in error message caused by spread syntax
if (!ok && errored && is_error_spread(uglify_result) && is_error_spread(original_result)) ok = true;
if (!ok && original_erred && uglify_erred) {
if (is_error_spread(original_result) && is_error_spread(uglify_result)) ok = true;
}
// ignore difference in depth of termination caused by infinite recursion
if (!ok && errored && is_error_recursion(original_result)) {
if (is_error_recursion(uglify_result) || typeof uglify_result == "string") ok = true;
if (!ok && original_erred && is_error_recursion(original_result)) {
if (!uglify_erred || is_error_recursion(uglify_result)) ok = true;
}
// ignore difference in error message caused by destructuring
if (!ok && errored && is_error_destructuring(uglify_result) && is_error_destructuring(original_result)) {
ok = true;
if (!ok && original_erred && uglify_erred) {
if (is_error_destructuring(original_result) && is_error_destructuring(uglify_result)) ok = true;
}
// ignore difference in error message caused by call on class
if (!ok && errored && is_error_class_constructor(uglify_result) && is_error_class_constructor(original_result)) {
ok = true;
if (!ok && original_erred && uglify_erred) {
if (is_error_class_constructor(original_result) && is_error_class_constructor(uglify_result)) {
ok = true;
}
}
// ignore difference in error message caused by setting getter-only property
if (!ok && errored && is_error_getter_only_property(uglify_result) && is_error_getter_only_property(original_result)) {
ok = true;
if (!ok && original_erred && uglify_erred) {
if (is_error_getter_only_property(original_result) && is_error_getter_only_property(uglify_result)) {
ok = true;
}
}
// ignore errors above when caught by try-catch
if (!ok) {
@@ -2567,7 +2591,7 @@ for (var round = 1; round <= num_iterations; round++) {
}
} else {
uglify_code = uglify_code.error;
ok = errored && uglify_code.name == original_result.name;
ok = original_erred && uglify_code.name == original_result.name;
}
if (verbose || (verbose_interval && !(round % INTERVAL_COUNT)) || !ok) log(options);
if (!ok && isFinite(num_iterations)) {