Compare commits
67 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6de708af37 | ||
|
|
b9b2a4f7f8 | ||
|
|
b46c7944c6 | ||
|
|
866cd4a975 | ||
|
|
e24b255350 | ||
|
|
efed55f42d | ||
|
|
8c2b76eff9 | ||
|
|
b636e97e3b | ||
|
|
35d7f316ef | ||
|
|
43807c26fb | ||
|
|
774feeadb8 | ||
|
|
d96c59f9e6 | ||
|
|
dfd6418878 | ||
|
|
87e8aca245 | ||
|
|
14e1311bdf | ||
|
|
ff3c2ed7a2 | ||
|
|
f8602aca96 | ||
|
|
9a58270b70 | ||
|
|
f639a30bd2 | ||
|
|
082013c20f | ||
|
|
c7d2837184 | ||
|
|
caaa753861 | ||
|
|
4b949f6686 | ||
|
|
e9d9d5a9d2 | ||
|
|
f473b4db38 | ||
|
|
b0df5d7b55 | ||
|
|
be8c75bae1 | ||
|
|
58bea676ac | ||
|
|
9aab1f3661 | ||
|
|
10a1523ee6 | ||
|
|
d46eb69320 | ||
|
|
3a3666a94e | ||
|
|
2f568b9357 | ||
|
|
c94624f36c | ||
|
|
dec359ce58 | ||
|
|
1a054e869e | ||
|
|
7889192cae | ||
|
|
f7841bc8b8 | ||
|
|
aa6eb0d5be | ||
|
|
87a7426598 | ||
|
|
8d0422b6f3 | ||
|
|
e7ce1051fe | ||
|
|
80d5f23fee | ||
|
|
d51caaf358 | ||
|
|
835d130ccf | ||
|
|
e1013bd56d | ||
|
|
13d41778b3 | ||
|
|
bab416465f | ||
|
|
29a1e71705 | ||
|
|
7b2eb4b5ff | ||
|
|
343bf6d7a5 | ||
|
|
ba42cbad3f | ||
|
|
86406e71ec | ||
|
|
9e927ecc9a | ||
|
|
509896a410 | ||
|
|
7fe7c39a01 | ||
|
|
2c5e23506b | ||
|
|
07f35ea2c9 | ||
|
|
57a9519c3d | ||
|
|
9e4c4c995c | ||
|
|
d11c82f8ca | ||
|
|
bc27966a19 | ||
|
|
8f39491e96 | ||
|
|
065c50ebde | ||
|
|
d2e7c4af20 | ||
|
|
033d8d9405 | ||
|
|
b0799105c2 |
10
README.md
10
README.md
@@ -115,6 +115,7 @@ a double dash to prevent input files being used as option arguments:
|
||||
Equivalent to setting `ie: true` in `minify()`
|
||||
for `compress`, `mangle` and `output` options.
|
||||
By default UglifyJS will not try to be IE-proof.
|
||||
--keep-fargs Do not mangle/drop function arguments.
|
||||
--keep-fnames Do not mangle/drop function names. Useful for
|
||||
code relying on Function.prototype.name.
|
||||
--name-cache <file> File to hold mangled name mappings.
|
||||
@@ -504,6 +505,9 @@ if (result.error) throw result.error;
|
||||
|
||||
- `ie` (default: `false`) — enable workarounds for Internet Explorer bugs.
|
||||
|
||||
- `keep_fargs` (default: `false`) — pass `true` to prevent discarding or mangling
|
||||
of function arguments.
|
||||
|
||||
- `keep_fnames` (default: `false`) — pass `true` to prevent discarding or mangling
|
||||
of function names. Useful for code relying on `Function.prototype.name`.
|
||||
|
||||
@@ -707,7 +711,8 @@ to be `false` and all symbol names will be omitted.
|
||||
- `1` — inline simple functions
|
||||
- `2` — inline functions with arguments
|
||||
- `3` — inline functions with arguments and variables
|
||||
- `true` — same as `3`
|
||||
- `4` — inline functions with arguments, variables and statements
|
||||
- `true` — same as `4`
|
||||
|
||||
- `join_vars` (default: `true`) — join consecutive `var` statements
|
||||
|
||||
@@ -867,6 +872,9 @@ UglifyJS.minify(code, { mangle: { toplevel: true } }).code;
|
||||
- `debug` (default: `false`) — Mangle names with the original name still present.
|
||||
Pass an empty string `""` to enable, or a non-empty string to set the debug suffix.
|
||||
|
||||
- `keep_fargs` (default: `false`) — Use `true` to prevent mangling of function
|
||||
arguments.
|
||||
|
||||
- `keep_quoted` (default: `false`) — Only mangle unquoted property names.
|
||||
|
||||
- `regex` (default: `null`) — Pass a RegExp literal to only mangle property
|
||||
|
||||
19
bin/uglifyjs
19
bin/uglifyjs
@@ -10,7 +10,9 @@ var info = require("../package.json");
|
||||
var path = require("path");
|
||||
var UglifyJS = require("../tools/node");
|
||||
|
||||
var skip_keys = [ "cname", "fixed", "inlined", "parent_scope", "scope", "uses_eval", "uses_with" ];
|
||||
var skip_keys = [ "cname", "fixed", "in_arg", "inlined", "length_read", "parent_scope", "redef", "scope", "unused" ];
|
||||
var truthy_keys = [ "optional", "pure", "terminal", "uses_arguments", "uses_eval", "uses_with" ];
|
||||
|
||||
var files = {};
|
||||
var options = {};
|
||||
var short_forms = {
|
||||
@@ -70,6 +72,7 @@ function process_option(name, no_value) {
|
||||
} else {
|
||||
if (padding.length < name.length) padding = Array(name.length + 1).join(" ");
|
||||
toplevels.push([ {
|
||||
keep_fargs: "keep-fargs",
|
||||
keep_fnames: "keep-fnames",
|
||||
nameCache: "name-cache",
|
||||
}[name] || name, option ]);
|
||||
@@ -102,6 +105,7 @@ function process_option(name, no_value) {
|
||||
" -d, --define <expr>[=value] Global definitions.",
|
||||
" -e, --enclose [arg[,...][:value[,...]]] Embed everything in a big function, with configurable argument(s) & value(s).",
|
||||
" --ie Support non-standard Internet Explorer.",
|
||||
" --keep-fargs Do not mangle/drop function arguments.",
|
||||
" --keep-fnames Do not mangle/drop function names. Useful for code relying on Function.prototype.name.",
|
||||
" --name-cache <file> File to hold mangled name mappings.",
|
||||
" --rename Force symbol expansion.",
|
||||
@@ -158,6 +162,9 @@ function process_option(name, no_value) {
|
||||
case "no-annotations":
|
||||
options.annotations = false;
|
||||
break;
|
||||
case "keep-fargs":
|
||||
options.keep_fargs = true;
|
||||
break;
|
||||
case "keep-fnames":
|
||||
options.keep_fnames = true;
|
||||
break;
|
||||
@@ -430,7 +437,7 @@ function run() {
|
||||
case "thedef":
|
||||
return symdef(value);
|
||||
}
|
||||
if (skip_key(key)) return;
|
||||
if (skip_property(key, value)) return;
|
||||
if (value instanceof UglifyJS.AST_Token) return;
|
||||
if (value instanceof UglifyJS.Dictionary) return;
|
||||
if (value instanceof UglifyJS.AST_Node) {
|
||||
@@ -519,7 +526,7 @@ function read_file(path, default_value) {
|
||||
}
|
||||
|
||||
function parse_js(value, options, flag) {
|
||||
if (!options || typeof options != "object") options = {};
|
||||
if (!options || typeof options != "object") options = Object.create(null);
|
||||
if (typeof value == "string") try {
|
||||
UglifyJS.parse(value, {
|
||||
expression: true
|
||||
@@ -559,8 +566,10 @@ function parse_js(value, options, flag) {
|
||||
return options;
|
||||
}
|
||||
|
||||
function skip_key(key) {
|
||||
return skip_keys.indexOf(key) >= 0;
|
||||
function skip_property(key, value) {
|
||||
return skip_keys.indexOf(key) >= 0
|
||||
// only skip truthy_keys if their value is falsy
|
||||
|| truthy_keys.indexOf(key) >= 0 && !value;
|
||||
}
|
||||
|
||||
function symdef(def) {
|
||||
|
||||
81
lib/ast.js
81
lib/ast.js
@@ -50,6 +50,8 @@ function DEFNODE(type, props, methods, base) {
|
||||
if (base && base.PROPS) props = props.concat(base.PROPS);
|
||||
var code = [
|
||||
"return function AST_", type, "(props){",
|
||||
// not essential, but speeds up compress by a few percent
|
||||
"this._bits=0;",
|
||||
"if(props){",
|
||||
];
|
||||
props.forEach(function(prop) {
|
||||
@@ -135,6 +137,53 @@ var AST_Node = DEFNODE("Node", "start end", {
|
||||
},
|
||||
}, null);
|
||||
|
||||
DEF_BITPROPS(AST_Node, [
|
||||
"_optimized",
|
||||
"_squeezed",
|
||||
// AST_Call
|
||||
"call_only",
|
||||
// AST_Lambda
|
||||
"collapse_scanning",
|
||||
// AST_SymbolRef
|
||||
"defined",
|
||||
"evaluating",
|
||||
"falsy",
|
||||
// AST_SymbolRef
|
||||
"in_arg",
|
||||
// AST_Return
|
||||
"in_bool",
|
||||
// AST_SymbolRef
|
||||
"is_undefined",
|
||||
// AST_LambdaExpression
|
||||
// AST_LambdaDefinition
|
||||
"inlined",
|
||||
// AST_Lambda
|
||||
"length_read",
|
||||
// AST_Yield
|
||||
"nested",
|
||||
// AST_Lambda
|
||||
"new",
|
||||
// AST_Call
|
||||
// AST_PropAccess
|
||||
"optional",
|
||||
// AST_ClassProperty
|
||||
"private",
|
||||
// AST_Call
|
||||
"pure",
|
||||
// AST_Assign
|
||||
"redundant",
|
||||
// AST_ClassProperty
|
||||
"static",
|
||||
// AST_Call
|
||||
// AST_PropAccess
|
||||
"terminal",
|
||||
"truthy",
|
||||
// AST_Scope
|
||||
"uses_eval",
|
||||
// AST_Scope
|
||||
"uses_with",
|
||||
]);
|
||||
|
||||
(AST_Node.log_function = function(fn, verbose) {
|
||||
if (typeof fn != "function") {
|
||||
AST_Node.info = AST_Node.warn = noop;
|
||||
@@ -253,7 +302,7 @@ var AST_SimpleStatement = DEFNODE("SimpleStatement", "body", {
|
||||
},
|
||||
}, AST_Statement);
|
||||
|
||||
var AST_BlockScope = DEFNODE("BlockScope", "enclosed functions make_def parent_scope variables", {
|
||||
var AST_BlockScope = DEFNODE("BlockScope", "_var_names enclosed functions make_def parent_scope variables", {
|
||||
$documentation: "Base class for all statements introducing a lexical scope",
|
||||
$propdoc: {
|
||||
enclosed: "[SymbolDef*/S] a list of all symbol definitions that are accessed from this scope or any subscopes",
|
||||
@@ -484,7 +533,7 @@ var AST_With = DEFNODE("With", "expression", {
|
||||
|
||||
/* -----[ scope and functions ]----- */
|
||||
|
||||
var AST_Scope = DEFNODE("Scope", "uses_eval uses_with", {
|
||||
var AST_Scope = DEFNODE("Scope", "fn_defs may_call_this uses_eval uses_with", {
|
||||
$documentation: "Base class for all statements introducing a lexical scope",
|
||||
$propdoc: {
|
||||
uses_eval: "[boolean/S] tells whether this scope contains a direct call to the global `eval`",
|
||||
@@ -543,13 +592,13 @@ var AST_Toplevel = DEFNODE("Toplevel", "globals", {
|
||||
}
|
||||
}, AST_Scope);
|
||||
|
||||
var AST_Lambda = DEFNODE("Lambda", "argnames length_read rest uses_arguments", {
|
||||
var AST_Lambda = DEFNODE("Lambda", "argnames length_read rest safe_ids uses_arguments", {
|
||||
$documentation: "Base class for functions",
|
||||
$propdoc: {
|
||||
argnames: "[(AST_DefaultValue|AST_Destructured|AST_SymbolFunarg)*] array of function arguments and/or destructured literals",
|
||||
length_read: "[boolean/S] whether length property of this function is accessed",
|
||||
rest: "[(AST_Destructured|AST_SymbolFunarg)?] rest parameter, or null if absent",
|
||||
uses_arguments: "[boolean/S] whether this function accesses the arguments array",
|
||||
uses_arguments: "[boolean|number/S] whether this function accesses the arguments array",
|
||||
},
|
||||
each_argname: function(visit) {
|
||||
var tw = new TreeWalker(function(node) {
|
||||
@@ -1295,7 +1344,7 @@ var AST_Call = DEFNODE("Call", "args expression optional pure terminal", {
|
||||
args: "[AST_Node*] array of arguments",
|
||||
expression: "[AST_Node] expression to invoke as function",
|
||||
optional: "[boolean] whether the expression is optional chaining",
|
||||
pure: "[string/S] marker for side-effect-free call expression",
|
||||
pure: "[boolean/S] marker for side-effect-free call expression",
|
||||
terminal: "[boolean] whether the chain has ended",
|
||||
},
|
||||
walk: function(visitor) {
|
||||
@@ -1489,6 +1538,12 @@ var AST_Assign = DEFNODE("Assign", null, {
|
||||
throw new Error("left must be assignable: " + node.TYPE);
|
||||
}
|
||||
});
|
||||
} else if (!(this.left instanceof AST_Infinity
|
||||
|| this.left instanceof AST_NaN
|
||||
|| this.left instanceof AST_PropAccess && !this.left.optional
|
||||
|| this.left instanceof AST_SymbolRef
|
||||
|| this.left instanceof AST_Undefined)) {
|
||||
throw new Error("left must be assignable");
|
||||
}
|
||||
},
|
||||
}, AST_Binary);
|
||||
@@ -1747,7 +1802,7 @@ var AST_SymbolVar = DEFNODE("SymbolVar", null, {
|
||||
$documentation: "Symbol defining a variable",
|
||||
}, AST_SymbolDeclaration);
|
||||
|
||||
var AST_SymbolFunarg = DEFNODE("SymbolFunarg", null, {
|
||||
var AST_SymbolFunarg = DEFNODE("SymbolFunarg", "unused", {
|
||||
$documentation: "Symbol naming a function argument",
|
||||
}, AST_SymbolVar);
|
||||
|
||||
@@ -1923,27 +1978,27 @@ var AST_Atom = DEFNODE("Atom", null, {
|
||||
|
||||
var AST_Null = DEFNODE("Null", null, {
|
||||
$documentation: "The `null` atom",
|
||||
value: null
|
||||
value: null,
|
||||
}, AST_Atom);
|
||||
|
||||
var AST_NaN = DEFNODE("NaN", null, {
|
||||
$documentation: "The impossible value",
|
||||
value: 0/0
|
||||
value: 0/0,
|
||||
}, AST_Atom);
|
||||
|
||||
var AST_Undefined = DEFNODE("Undefined", null, {
|
||||
$documentation: "The `undefined` value",
|
||||
value: function(){}()
|
||||
value: function(){}(),
|
||||
}, AST_Atom);
|
||||
|
||||
var AST_Hole = DEFNODE("Hole", null, {
|
||||
$documentation: "A hole in an array",
|
||||
value: function(){}()
|
||||
value: function(){}(),
|
||||
}, AST_Atom);
|
||||
|
||||
var AST_Infinity = DEFNODE("Infinity", null, {
|
||||
$documentation: "The `Infinity` value",
|
||||
value: 1/0
|
||||
value: 1/0,
|
||||
}, AST_Atom);
|
||||
|
||||
var AST_Boolean = DEFNODE("Boolean", null, {
|
||||
@@ -1955,12 +2010,12 @@ var AST_Boolean = DEFNODE("Boolean", null, {
|
||||
|
||||
var AST_False = DEFNODE("False", null, {
|
||||
$documentation: "The `false` atom",
|
||||
value: false
|
||||
value: false,
|
||||
}, AST_Boolean);
|
||||
|
||||
var AST_True = DEFNODE("True", null, {
|
||||
$documentation: "The `true` atom",
|
||||
value: true
|
||||
value: true,
|
||||
}, AST_Boolean);
|
||||
|
||||
/* -----[ TreeWalker ]----- */
|
||||
|
||||
2488
lib/compress.js
2488
lib/compress.js
File diff suppressed because it is too large
Load Diff
@@ -28,7 +28,7 @@ function read_source_map(name, toplevel) {
|
||||
var match = /^# ([^\s=]+)=(\S+)\s*$/.exec(comment.value);
|
||||
if (!match) break;
|
||||
if (match[1] == "sourceMappingURL") {
|
||||
match = /^data:application\/json(;.*?)?;base64,(\S+)$/.exec(match[2]);
|
||||
match = /^data:application\/json(;.*?)?;base64,([^,]+)$/.exec(match[2]);
|
||||
if (!match) break;
|
||||
return to_ascii(match[2]);
|
||||
}
|
||||
@@ -78,6 +78,7 @@ function minify(files, options) {
|
||||
enclose: false,
|
||||
ie: false,
|
||||
ie8: false,
|
||||
keep_fargs: false,
|
||||
keep_fnames: false,
|
||||
mangle: {},
|
||||
nameCache: null,
|
||||
@@ -99,6 +100,7 @@ function minify(files, options) {
|
||||
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" ]);
|
||||
@@ -109,6 +111,7 @@ function minify(files, options) {
|
||||
cache: options.nameCache && (options.nameCache.vars || {}),
|
||||
eval: false,
|
||||
ie: false,
|
||||
keep_fargs: false,
|
||||
keep_fnames: false,
|
||||
properties: false,
|
||||
reserved: [],
|
||||
|
||||
@@ -1005,7 +1005,7 @@
|
||||
});
|
||||
|
||||
def_to_moz(AST_RegExp, function To_Moz_RegExpLiteral(M) {
|
||||
var flags = M.value.toString().match(/[gimuy]*$/)[0];
|
||||
var flags = M.value.toString().match(/\/([gimuy]*)$/)[1];
|
||||
var value = "/" + M.value.raw_source + "/" + flags;
|
||||
return {
|
||||
type: "Literal",
|
||||
@@ -1013,8 +1013,8 @@
|
||||
raw: value,
|
||||
regex: {
|
||||
pattern: M.value.raw_source,
|
||||
flags: flags
|
||||
}
|
||||
flags: flags,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -521,9 +521,7 @@ function OutputStream(options) {
|
||||
indent();
|
||||
}
|
||||
var preamble = options.preamble;
|
||||
if (preamble) {
|
||||
print(preamble.replace(/\r\n?|[\n\u2028\u2029]|\s*$/g, "\n"));
|
||||
}
|
||||
if (preamble) print(preamble.replace(/\r\n?|\u2028|\u2029|(^|\S)\s*$/g, "$1\n"));
|
||||
}
|
||||
|
||||
comments = comments.filter(comment_filter, node);
|
||||
@@ -1465,7 +1463,7 @@ function OutputStream(options) {
|
||||
parent = output.parent(level++);
|
||||
if (parent instanceof AST_Call && parent.expression === node) return;
|
||||
} while (parent instanceof AST_PropAccess && parent.expression === node);
|
||||
output.print(typeof self.pure == "string" ? "/*" + self.pure + "*/" : "/*@__PURE__*/");
|
||||
output.print("/*@__PURE__*/");
|
||||
}
|
||||
function print_call_args(self, output) {
|
||||
if (self.expression instanceof AST_Call || self.expression instanceof AST_Lambda) {
|
||||
@@ -1870,8 +1868,8 @@ function OutputStream(options) {
|
||||
len = match[0].length;
|
||||
digits = str.slice(len);
|
||||
candidates.push(digits + "e-" + (digits.length + len - 1));
|
||||
} else if (match = /0+$/.exec(str)) {
|
||||
len = match[0].length;
|
||||
} else if (match = /[^0]0+$/.exec(str)) {
|
||||
len = match[0].length - 1;
|
||||
candidates.push(str.slice(0, -len) + "e" + len);
|
||||
} else if (match = /^(\d)\.(\d+)e(-?\d+)$/.exec(str)) {
|
||||
candidates.push(match[1] + match[2] + "e" + (match[3] - match[2].length));
|
||||
|
||||
@@ -2316,9 +2316,8 @@ function parse($TEXT, options) {
|
||||
var comments = start.comments_before;
|
||||
var i = HOP(start, "comments_before_length") ? start.comments_before_length : comments.length;
|
||||
while (--i >= 0) {
|
||||
var match = /[@#]__PURE__/.exec(comments[i].value);
|
||||
if (match) {
|
||||
expr.pure = match[0];
|
||||
if (/[@#]__PURE__/.test(comments[i].value)) {
|
||||
expr.pure = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
"use strict";
|
||||
|
||||
var builtins = function() {
|
||||
var names = [];
|
||||
var names = new Dictionary();
|
||||
// NaN will be included due to Number.NaN
|
||||
[
|
||||
"null",
|
||||
@@ -72,10 +72,10 @@ var builtins = function() {
|
||||
Object.getOwnPropertyNames(ctor.prototype).map(add);
|
||||
}
|
||||
});
|
||||
return makePredicate(names);
|
||||
return names;
|
||||
|
||||
function add(name) {
|
||||
names.push(name);
|
||||
names.set(name, true);
|
||||
}
|
||||
}();
|
||||
|
||||
@@ -116,9 +116,9 @@ function mangle_properties(ast, options) {
|
||||
reserved: null,
|
||||
}, true);
|
||||
|
||||
var reserved = Object.create(options.builtins ? null : builtins);
|
||||
var reserved = options.builtins ? new Dictionary() : builtins.clone();
|
||||
if (Array.isArray(options.reserved)) options.reserved.forEach(function(name) {
|
||||
reserved[name] = true;
|
||||
reserved.set(name, true);
|
||||
});
|
||||
|
||||
var cname = -1;
|
||||
@@ -126,7 +126,7 @@ function mangle_properties(ast, options) {
|
||||
if (options.cache) {
|
||||
cache = options.cache.props;
|
||||
cache.each(function(name) {
|
||||
reserved[name] = true;
|
||||
reserved.set(name, true);
|
||||
});
|
||||
} else {
|
||||
cache = new Dictionary();
|
||||
@@ -141,8 +141,8 @@ function mangle_properties(ast, options) {
|
||||
var debug_suffix;
|
||||
if (debug) debug_suffix = options.debug === true ? "" : options.debug;
|
||||
|
||||
var names_to_mangle = Object.create(null);
|
||||
var unmangleable = Object.create(reserved);
|
||||
var names_to_mangle = new Dictionary();
|
||||
var unmangleable = reserved.clone();
|
||||
|
||||
// step 1: find candidates to mangle
|
||||
ast.walk(new TreeWalker(function(node) {
|
||||
@@ -211,20 +211,20 @@ function mangle_properties(ast, options) {
|
||||
// only function declarations after this line
|
||||
|
||||
function can_mangle(name) {
|
||||
if (unmangleable[name]) return false;
|
||||
if (unmangleable.has(name)) return false;
|
||||
if (/^-?[0-9]+(\.[0-9]+)?(e[+-][0-9]+)?$/.test(name)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
function should_mangle(name) {
|
||||
if (reserved[name]) return false;
|
||||
if (reserved.has(name)) return false;
|
||||
if (regex && !regex.test(name)) return false;
|
||||
return cache.has(name) || names_to_mangle[name];
|
||||
return cache.has(name) || names_to_mangle.has(name);
|
||||
}
|
||||
|
||||
function add(name) {
|
||||
if (can_mangle(name)) names_to_mangle[name] = true;
|
||||
if (!should_mangle(name)) unmangleable[name] = true;
|
||||
if (can_mangle(name)) names_to_mangle.set(name, true);
|
||||
if (!should_mangle(name)) unmangleable.set(name, true);
|
||||
}
|
||||
|
||||
function mangle(name) {
|
||||
|
||||
148
lib/scope.js
148
lib/scope.js
@@ -44,9 +44,9 @@
|
||||
"use strict";
|
||||
|
||||
function SymbolDef(id, scope, orig, init) {
|
||||
this._bits = 0;
|
||||
this.defun = undefined;
|
||||
this.eliminated = 0;
|
||||
this.exported = false;
|
||||
this.global = false;
|
||||
this.id = id;
|
||||
this.init = init;
|
||||
this.mangled_name = null;
|
||||
@@ -54,8 +54,8 @@ function SymbolDef(id, scope, orig, init) {
|
||||
this.orig = [ orig ];
|
||||
this.references = [];
|
||||
this.replaced = 0;
|
||||
this.safe_ids = undefined;
|
||||
this.scope = scope;
|
||||
this.undeclared = false;
|
||||
}
|
||||
|
||||
SymbolDef.prototype = {
|
||||
@@ -92,18 +92,35 @@ SymbolDef.prototype = {
|
||||
if (def && def !== self) return def.redefined() || def;
|
||||
},
|
||||
unmangleable: function(options) {
|
||||
return this.global && !options.toplevel
|
||||
|| this.exported
|
||||
|| this.undeclared
|
||||
|| !options.eval && this.scope.pinned()
|
||||
|| options.keep_fnames
|
||||
&& (this.orig[0] instanceof AST_SymbolClass
|
||||
|| this.orig[0] instanceof AST_SymbolDefClass
|
||||
|| this.orig[0] instanceof AST_SymbolDefun
|
||||
|| this.orig[0] instanceof AST_SymbolLambda);
|
||||
if (this.exported) return true;
|
||||
if (this.undeclared) return true;
|
||||
if (!options.eval && this.scope.pinned()) return true;
|
||||
if (options.keep_fargs && is_funarg(this)) return true;
|
||||
if (options.keep_fnames) {
|
||||
var sym = this.orig[0];
|
||||
if (sym instanceof AST_SymbolClass) return true;
|
||||
if (sym instanceof AST_SymbolDefClass) return true;
|
||||
if (sym instanceof AST_SymbolDefun) return true;
|
||||
if (sym instanceof AST_SymbolLambda) return true;
|
||||
}
|
||||
if (!options.toplevel && this.global) return true;
|
||||
return false;
|
||||
},
|
||||
};
|
||||
|
||||
DEF_BITPROPS(SymbolDef, [
|
||||
"const_redefs",
|
||||
"cross_loop",
|
||||
"direct_access",
|
||||
"exported",
|
||||
"global",
|
||||
"undeclared",
|
||||
]);
|
||||
|
||||
function is_funarg(def) {
|
||||
return def.orig[0] instanceof AST_SymbolFunarg || def.orig[1] instanceof AST_SymbolFunarg;
|
||||
}
|
||||
|
||||
var unary_side_effects = makePredicate("delete ++ --");
|
||||
|
||||
function is_lhs(node, parent) {
|
||||
@@ -205,10 +222,8 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
||||
} else if (node instanceof AST_SymbolDefun) {
|
||||
var def = defun.def_function(node, tw.parent());
|
||||
if (exported) def.exported = true;
|
||||
entangle(defun, scope);
|
||||
} else if (node instanceof AST_SymbolFunarg) {
|
||||
defun.def_variable(node);
|
||||
entangle(defun, scope);
|
||||
} 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();
|
||||
@@ -218,7 +233,6 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
||||
} else if (node instanceof AST_SymbolVar) {
|
||||
var def = defun.def_variable(node, node instanceof AST_SymbolImport ? undefined : null);
|
||||
if (exported) def.exported = true;
|
||||
entangle(defun, scope);
|
||||
}
|
||||
|
||||
function walk_scope(descend) {
|
||||
@@ -231,16 +245,6 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
||||
scope = save_scope;
|
||||
defun = save_defun;
|
||||
}
|
||||
|
||||
function entangle(defun, scope) {
|
||||
if (defun === scope) return;
|
||||
node.mark_enclosed(options);
|
||||
var def = scope.find_variable(node.name);
|
||||
if (node.thedef === def) return;
|
||||
node.thedef = def;
|
||||
def.orig.push(node);
|
||||
node.mark_enclosed(options);
|
||||
}
|
||||
});
|
||||
self.make_def = function(orig, init) {
|
||||
return new SymbolDef(++next_def_id, this, orig, init);
|
||||
@@ -261,6 +265,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
||||
}
|
||||
if (node instanceof AST_Lambda) {
|
||||
in_arg.push(node);
|
||||
if (node.name) node.name.walk(tw);
|
||||
node.argnames.forEach(function(argname) {
|
||||
argname.walk(tw);
|
||||
});
|
||||
@@ -287,6 +292,16 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
||||
// ensure compression works if `const` reuses a scope variable
|
||||
var redef = def.redefined();
|
||||
if (redef) redef.const_redefs = true;
|
||||
} else if (def.scope !== node.scope && (node instanceof AST_SymbolDefun
|
||||
|| node instanceof AST_SymbolFunarg
|
||||
|| node instanceof AST_SymbolVar)) {
|
||||
node.mark_enclosed(options);
|
||||
var redef = node.scope.find_variable(node.name);
|
||||
if (node.thedef !== redef) {
|
||||
node.thedef = redef;
|
||||
redef.orig.push(node);
|
||||
node.mark_enclosed(options);
|
||||
}
|
||||
}
|
||||
if (node.name != "arguments") return true;
|
||||
var parent = node instanceof AST_SymbolVar && tw.parent();
|
||||
@@ -363,7 +378,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
||||
if (node instanceof AST_SymbolLambda) {
|
||||
var def = node.thedef;
|
||||
if (!redefine(node, node.scope.parent_scope.resolve())) {
|
||||
delete def.defun;
|
||||
def.defun = undefined;
|
||||
} else if (typeof node.thedef.init !== "undefined") {
|
||||
node.thedef.init = false;
|
||||
} else if (def.init) {
|
||||
@@ -465,9 +480,12 @@ AST_Symbol.DEFMETHOD("mark_enclosed", function(options) {
|
||||
for (var s = this.scope; s; s = s.parent_scope) {
|
||||
push_uniq(s.enclosed, def);
|
||||
if (!options) {
|
||||
delete s._var_names;
|
||||
} else if (options.keep_fnames) {
|
||||
s.functions.each(function(d) {
|
||||
s._var_names = undefined;
|
||||
} else {
|
||||
if (options.keep_fargs && s instanceof AST_Lambda) s.each_argname(function(arg) {
|
||||
push_uniq(def.scope.enclosed, arg.definition());
|
||||
});
|
||||
if (options.keep_fnames) s.functions.each(function(d) {
|
||||
push_uniq(def.scope.enclosed, d);
|
||||
});
|
||||
}
|
||||
@@ -510,12 +528,12 @@ function names_in_use(scope, options) {
|
||||
if (!names) {
|
||||
scope.cname = -1;
|
||||
scope.cname_holes = [];
|
||||
scope.names_in_use = names = Object.create(null);
|
||||
scope.names_in_use = names = new Dictionary();
|
||||
var cache = options.cache && options.cache.props;
|
||||
scope.enclosed.forEach(function(def) {
|
||||
if (def.unmangleable(options)) names[def.name] = true;
|
||||
if (def.unmangleable(options)) names.set(def.name, true);
|
||||
if (def.global && cache && cache.has(def.name)) {
|
||||
names[cache.get(def.name)] = true;
|
||||
names.set(cache.get(def.name), true);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -526,34 +544,33 @@ function next_mangled_name(def, options) {
|
||||
var scope = def.scope;
|
||||
var in_use = names_in_use(scope, options);
|
||||
var holes = scope.cname_holes;
|
||||
var names = Object.create(null);
|
||||
var names = new Dictionary();
|
||||
var scopes = [ scope ];
|
||||
def.forEach(function(sym) {
|
||||
var scope = sym.scope;
|
||||
do {
|
||||
if (scopes.indexOf(scope) < 0) {
|
||||
for (var name in names_in_use(scope, options)) {
|
||||
names[name] = true;
|
||||
}
|
||||
scopes.push(scope);
|
||||
} else break;
|
||||
if (member(scope, scopes)) break;
|
||||
names_in_use(scope, options).each(function(marker, name) {
|
||||
names.set(name, marker);
|
||||
});
|
||||
scopes.push(scope);
|
||||
} while (scope = scope.parent_scope);
|
||||
});
|
||||
var name;
|
||||
for (var i = 0; i < holes.length; i++) {
|
||||
name = base54(holes[i]);
|
||||
if (names[name]) continue;
|
||||
if (names.has(name)) continue;
|
||||
holes.splice(i, 1);
|
||||
in_use[name] = true;
|
||||
in_use.set(name, true);
|
||||
return name;
|
||||
}
|
||||
while (true) {
|
||||
name = base54(++scope.cname);
|
||||
if (in_use[name] || RESERVED_WORDS[name] || options.reserved.has[name]) continue;
|
||||
if (!names[name]) break;
|
||||
if (in_use.has(name) || RESERVED_WORDS[name] || options.reserved.has[name]) continue;
|
||||
if (!names.has(name)) break;
|
||||
holes.push(scope.cname);
|
||||
}
|
||||
in_use[name] = true;
|
||||
in_use.set(name, true);
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -573,6 +590,7 @@ function _default_mangler_options(options) {
|
||||
options = defaults(options, {
|
||||
eval : false,
|
||||
ie : false,
|
||||
keep_fargs : false,
|
||||
keep_fnames : false,
|
||||
reserved : [],
|
||||
toplevel : false,
|
||||
@@ -580,32 +598,30 @@ function _default_mangler_options(options) {
|
||||
webkit : false,
|
||||
});
|
||||
if (!Array.isArray(options.reserved)) options.reserved = [];
|
||||
// Never mangle arguments
|
||||
// Never mangle `arguments`
|
||||
push_uniq(options.reserved, "arguments");
|
||||
options.reserved.has = makePredicate(options.reserved);
|
||||
return options;
|
||||
}
|
||||
|
||||
// We only need to mangle declaration nodes. Special logic wired into the code
|
||||
// generator will display the mangled name if it is present (and for
|
||||
// `AST_SymbolRef`s it will use the mangled name of the `AST_SymbolDeclaration`
|
||||
// that it points to).
|
||||
AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
|
||||
options = _default_mangler_options(options);
|
||||
|
||||
// We only need to mangle declaration nodes. Special logic wired
|
||||
// into the code generator will display the mangled name if it's
|
||||
// present (and for AST_SymbolRef-s it'll use the mangled name of
|
||||
// the AST_SymbolDeclaration that it points to).
|
||||
var lname = -1;
|
||||
|
||||
if (options.cache && options.cache.props) {
|
||||
var mangled_names = names_in_use(this, options);
|
||||
options.cache.props.each(function(mangled_name) {
|
||||
mangled_names[mangled_name] = true;
|
||||
mangled_names.set(mangled_name, true);
|
||||
});
|
||||
}
|
||||
|
||||
var cutoff = 10;
|
||||
var lname = -1;
|
||||
var redefined = [];
|
||||
var tw = new TreeWalker(function(node, descend) {
|
||||
if (node instanceof AST_LabeledStatement) {
|
||||
// lname is incremented when we get to the AST_Label
|
||||
// `lname` is incremented when we get to the `AST_Label`
|
||||
var save_nesting = lname;
|
||||
descend();
|
||||
if (!options.v8 || !in_label(tw)) lname = save_nesting;
|
||||
@@ -627,9 +643,9 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
|
||||
});
|
||||
}, true);
|
||||
}
|
||||
node.to_mangle = [];
|
||||
var to_mangle = node.to_mangle = [];
|
||||
node.variables.each(function(def) {
|
||||
if (!defer_redef(def)) node.to_mangle.push(def);
|
||||
if (!defer_redef(def)) to_mangle.push(def);
|
||||
});
|
||||
descend();
|
||||
if (options.cache && node instanceof AST_Toplevel) {
|
||||
@@ -640,7 +656,23 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
|
||||
sym.scope = node;
|
||||
sym.reference(options);
|
||||
}
|
||||
node.to_mangle.forEach(mangle);
|
||||
if (to_mangle.length > cutoff) {
|
||||
var indices = to_mangle.map(function(def, index) {
|
||||
return index;
|
||||
}).sort(function(i, j) {
|
||||
return to_mangle[j].references.length - to_mangle[i].references.length || i - j;
|
||||
});
|
||||
to_mangle = indices.slice(0, cutoff).sort(function(i, j) {
|
||||
return i - j;
|
||||
}).map(function(index) {
|
||||
return to_mangle[index];
|
||||
}).concat(indices.slice(cutoff).sort(function(i, j) {
|
||||
return i - j;
|
||||
}).map(function(index) {
|
||||
return to_mangle[index];
|
||||
}));
|
||||
}
|
||||
to_mangle.forEach(mangle);
|
||||
return true;
|
||||
}
|
||||
if (node instanceof AST_Label) {
|
||||
|
||||
@@ -77,21 +77,23 @@ function vlq_encode(num) {
|
||||
}
|
||||
|
||||
function create_array_map() {
|
||||
var map = Object.create(null);
|
||||
var map = new Dictionary();
|
||||
var array = [];
|
||||
array.index = function(name) {
|
||||
if (!HOP(map, name)) {
|
||||
map[name] = array.length;
|
||||
var index = map.get(name);
|
||||
if (!(index >= 0)) {
|
||||
index = array.length;
|
||||
array.push(name);
|
||||
map.set(name, index);
|
||||
}
|
||||
return map[name];
|
||||
return index;
|
||||
};
|
||||
return array;
|
||||
}
|
||||
|
||||
function SourceMap(options) {
|
||||
var sources = create_array_map();
|
||||
var sources_content = options.includeSources && Object.create(null);
|
||||
var sources_content = options.includeSources && new Dictionary();
|
||||
var names = create_array_map();
|
||||
var mappings = "";
|
||||
if (options.orig) Object.keys(options.orig).forEach(function(name) {
|
||||
@@ -110,7 +112,7 @@ function SourceMap(options) {
|
||||
if (!sources_content || !map.sourcesContent) return;
|
||||
for (var i = 0; i < map.sources.length; i++) {
|
||||
var content = map.sourcesContent[i];
|
||||
if (content) sources_content[map.sources[i]] = content;
|
||||
if (content) sources_content.set(map.sources[i], content);
|
||||
}
|
||||
});
|
||||
var prev_source;
|
||||
@@ -144,8 +146,8 @@ function SourceMap(options) {
|
||||
add(source, gen_line, gen_col, orig_line, orig_col, name);
|
||||
} : add,
|
||||
setSourceContent: sources_content ? function(source, content) {
|
||||
if (!(source in sources_content)) {
|
||||
sources_content[source] = content;
|
||||
if (!sources_content.has(source)) {
|
||||
sources_content.set(source, content);
|
||||
}
|
||||
} : noop,
|
||||
toString: function() {
|
||||
@@ -155,7 +157,7 @@ function SourceMap(options) {
|
||||
sourceRoot: options.root || undefined,
|
||||
sources: sources,
|
||||
sourcesContent: sources_content ? sources.map(function(source) {
|
||||
return sources_content[source] || null;
|
||||
return sources_content.get(source) || null;
|
||||
}) : undefined,
|
||||
names: names,
|
||||
mappings: mappings,
|
||||
|
||||
92
lib/utils.js
92
lib/utils.js
@@ -96,15 +96,6 @@ function defaults(args, defs, croak) {
|
||||
return defs;
|
||||
}
|
||||
|
||||
function merge(obj, ext) {
|
||||
var count = 0;
|
||||
for (var i in ext) if (HOP(ext, i)) {
|
||||
obj[i] = ext[i];
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
function noop() {}
|
||||
function return_false() { return false; }
|
||||
function return_true() { return true; }
|
||||
@@ -171,63 +162,80 @@ function all(array, predicate) {
|
||||
}
|
||||
|
||||
function Dictionary() {
|
||||
this._values = Object.create(null);
|
||||
this._size = 0;
|
||||
this.values = Object.create(null);
|
||||
}
|
||||
Dictionary.prototype = {
|
||||
set: function(key, val) {
|
||||
if (!this.has(key)) ++this._size;
|
||||
this._values["$" + key] = val;
|
||||
if (key == "__proto__") {
|
||||
this.proto_value = val;
|
||||
} else {
|
||||
this.values[key] = val;
|
||||
}
|
||||
return this;
|
||||
},
|
||||
add: function(key, val) {
|
||||
if (this.has(key)) {
|
||||
this.get(key).push(val);
|
||||
var list = this.get(key);
|
||||
if (list) {
|
||||
list.push(val);
|
||||
} else {
|
||||
this.set(key, [ val ]);
|
||||
}
|
||||
return this;
|
||||
},
|
||||
get: function(key) { return this._values["$" + key] },
|
||||
get: function(key) {
|
||||
return key == "__proto__" ? this.proto_value : this.values[key];
|
||||
},
|
||||
del: function(key) {
|
||||
if (this.has(key)) {
|
||||
--this._size;
|
||||
delete this._values["$" + key];
|
||||
if (key == "__proto__") {
|
||||
delete this.proto_value;
|
||||
} else {
|
||||
delete this.values[key];
|
||||
}
|
||||
return this;
|
||||
},
|
||||
has: function(key) { return ("$" + key) in this._values },
|
||||
has: function(key) {
|
||||
return key == "__proto__" ? "proto_value" in this : key in this.values;
|
||||
},
|
||||
all: function(predicate) {
|
||||
for (var i in this._values)
|
||||
if (!predicate(this._values[i], i.substr(1)))
|
||||
return false;
|
||||
for (var i in this.values)
|
||||
if (!predicate(this.values[i], i)) return false;
|
||||
if ("proto_value" in this && !predicate(this.proto_value, "__proto__")) return false;
|
||||
return true;
|
||||
},
|
||||
each: function(f) {
|
||||
for (var i in this._values)
|
||||
f(this._values[i], i.substr(1));
|
||||
for (var i in this.values)
|
||||
f(this.values[i], i);
|
||||
if ("proto_value" in this) f(this.proto_value, "__proto__");
|
||||
},
|
||||
size: function() {
|
||||
return this._size;
|
||||
return Object.keys(this.values).length + ("proto_value" in this);
|
||||
},
|
||||
map: function(f) {
|
||||
var ret = [];
|
||||
for (var i in this._values)
|
||||
ret.push(f(this._values[i], i.substr(1)));
|
||||
for (var i in this.values)
|
||||
ret.push(f(this.values[i], i));
|
||||
if ("proto_value" in this) ret.push(f(this.proto_value, "__proto__"));
|
||||
return ret;
|
||||
},
|
||||
clone: function() {
|
||||
var ret = new Dictionary();
|
||||
for (var i in this._values)
|
||||
ret._values[i] = this._values[i];
|
||||
ret._size = this._size;
|
||||
this.each(function(value, i) {
|
||||
ret.set(i, value);
|
||||
});
|
||||
return ret;
|
||||
},
|
||||
toObject: function() { return this._values }
|
||||
toObject: function() {
|
||||
var obj = {};
|
||||
this.each(function(value, i) {
|
||||
obj["$" + i] = value;
|
||||
});
|
||||
return obj;
|
||||
},
|
||||
};
|
||||
Dictionary.fromObject = function(obj) {
|
||||
var dict = new Dictionary();
|
||||
dict._size = merge(dict._values, obj);
|
||||
for (var i in obj)
|
||||
if (HOP(obj, i)) dict.set(i.slice(1), obj[i]);
|
||||
return dict;
|
||||
};
|
||||
|
||||
@@ -265,3 +273,21 @@ function first_in_statement(stack, arrow, export_default) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function DEF_BITPROPS(ctor, props) {
|
||||
if (props.length > 31) throw new Error("Too many properties: " + props.length + "\n" + props.join(", "));
|
||||
props.forEach(function(name, pos) {
|
||||
var mask = 1 << pos;
|
||||
Object.defineProperty(ctor.prototype, name, {
|
||||
get: function() {
|
||||
return !!(this._bits & mask);
|
||||
},
|
||||
set: function(val) {
|
||||
if (val)
|
||||
this._bits |= mask;
|
||||
else
|
||||
this._bits &= ~mask;
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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.14.4",
|
||||
"version": "3.15.0",
|
||||
"engines": {
|
||||
"node": ">=0.8.0"
|
||||
},
|
||||
|
||||
@@ -442,9 +442,9 @@ compress_annotations_disabled_output_annotations_enabled: {
|
||||
}
|
||||
expect_exact: [
|
||||
"/*@__PURE__*/a(3),",
|
||||
"/*#__PURE__*/b(5),",
|
||||
"/*@__PURE__*/b(5),",
|
||||
"c(side_effect),",
|
||||
"/*#__PURE__*/d(effect());",
|
||||
"/*@__PURE__*/d(effect());",
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -363,6 +363,28 @@ negate: {
|
||||
}
|
||||
|
||||
inline_this: {
|
||||
options = {
|
||||
inline: true,
|
||||
}
|
||||
input: {
|
||||
var p = "PASS";
|
||||
console.log({
|
||||
p: "FAIL",
|
||||
q: (() => this.p)(),
|
||||
}.q);
|
||||
}
|
||||
expect: {
|
||||
var p = "PASS";
|
||||
console.log({
|
||||
p: "FAIL",
|
||||
q: this.p,
|
||||
}.q);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
dont_inline_this: {
|
||||
options = {
|
||||
inline: true,
|
||||
}
|
||||
@@ -486,7 +508,7 @@ drop_value: {
|
||||
((a, b) => a + b)(console.log(42));
|
||||
}
|
||||
expect: {
|
||||
((a, b) => {})(console.log(42));
|
||||
void console.log(42);
|
||||
}
|
||||
expect_stdout: "42"
|
||||
node_version: ">=4"
|
||||
@@ -884,3 +906,24 @@ issue_4772: {
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5251: {
|
||||
options = {
|
||||
inline: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
(() => {
|
||||
while (console.log(arguments))
|
||||
var arguments = "FAIL";
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
(() => {
|
||||
while (console.log(arguments))
|
||||
var arguments = "FAIL";
|
||||
})();
|
||||
}
|
||||
expect_stdout: true
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
@@ -489,7 +489,7 @@ logical_assignments: {
|
||||
node_version: ">=15"
|
||||
}
|
||||
|
||||
logical_collapse_vars: {
|
||||
logical_collapse_vars_1: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
}
|
||||
@@ -509,6 +509,46 @@ logical_collapse_vars: {
|
||||
node_version: ">=15"
|
||||
}
|
||||
|
||||
logical_collapse_vars_2: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
}
|
||||
input: {
|
||||
var a = "PASS";
|
||||
(function(b) {
|
||||
b ||= (a = "FAIL", {});
|
||||
return b;
|
||||
})(console).log(a);
|
||||
}
|
||||
expect: {
|
||||
var a = "PASS";
|
||||
(function(b) {
|
||||
return b ||= (a = "FAIL", {});
|
||||
})(console).log(a);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=15"
|
||||
}
|
||||
|
||||
logical_collapse_vars_3: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
}
|
||||
input: {
|
||||
var a = 6;
|
||||
a *= 7;
|
||||
a ??= "FAIL";
|
||||
console.log(a);
|
||||
}
|
||||
expect: {
|
||||
var a = 6;
|
||||
a = a * 7 ?? "FAIL";
|
||||
console.log(a);
|
||||
}
|
||||
expect_stdout: "42"
|
||||
node_version: ">=15"
|
||||
}
|
||||
|
||||
logical_reduce_vars: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
|
||||
@@ -11,6 +11,21 @@ async_arrow: {
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
async_computed: {
|
||||
input: {
|
||||
var o = {
|
||||
async [42]() {
|
||||
return this.p;
|
||||
},
|
||||
p: "PASS",
|
||||
};
|
||||
o[42]().then(console.log);
|
||||
}
|
||||
expect_exact: 'var o={async[42](){return this.p},p:"PASS"};o[42]().then(console.log);'
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
async_label: {
|
||||
input: {
|
||||
(async function() {
|
||||
@@ -182,6 +197,34 @@ dont_inline: {
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
dont_inline_nested: {
|
||||
options = {
|
||||
inline: true,
|
||||
}
|
||||
input: {
|
||||
function await() {
|
||||
return "PASS";
|
||||
}
|
||||
(async function() {
|
||||
(function() {
|
||||
console.log(await("FAIL"));
|
||||
})();
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
function await() {
|
||||
return "PASS";
|
||||
}
|
||||
(async function() {
|
||||
(function() {
|
||||
console.log(await("FAIL"));
|
||||
})();
|
||||
})();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
inline_await_1: {
|
||||
options = {
|
||||
awaits: true,
|
||||
@@ -340,7 +383,436 @@ inline_await_3_trim: {
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
await_unary: {
|
||||
inline_await_this: {
|
||||
options = {
|
||||
awaits: true,
|
||||
inline: true,
|
||||
}
|
||||
input: {
|
||||
var p = "FAIL";
|
||||
({
|
||||
p: "PASS",
|
||||
async f() {
|
||||
return await (async () => this.p)();
|
||||
},
|
||||
}).f().then(console.log);
|
||||
}
|
||||
expect: {
|
||||
var p = "FAIL";
|
||||
({
|
||||
p: "PASS",
|
||||
async f() {
|
||||
return await this.p;
|
||||
},
|
||||
}).f().then(console.log);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
inline_block: {
|
||||
options = {
|
||||
awaits: true,
|
||||
if_return: true,
|
||||
inline: true,
|
||||
}
|
||||
input: {
|
||||
console.log("foo");
|
||||
(async function() {
|
||||
console.log("bar");
|
||||
(async function() {
|
||||
for (var a of [ "baz" ])
|
||||
return a;
|
||||
})();
|
||||
})().then(console.log);
|
||||
console.log("moo");
|
||||
}
|
||||
expect: {
|
||||
console.log("foo");
|
||||
(async function() {
|
||||
console.log("bar");
|
||||
for (var a of [ "baz" ])
|
||||
return void await a;
|
||||
})().then(console.log);
|
||||
console.log("moo");
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
"moo",
|
||||
"undefined",
|
||||
]
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
inline_block_async: {
|
||||
options = {
|
||||
awaits: true,
|
||||
if_return: true,
|
||||
inline: true,
|
||||
}
|
||||
input: {
|
||||
console.log("foo");
|
||||
(async function() {
|
||||
console.log("bar");
|
||||
(async function() {
|
||||
for (var a of [ "baz" ])
|
||||
return {
|
||||
then(r) {
|
||||
console.log("moo");
|
||||
r(a);
|
||||
},
|
||||
};
|
||||
})();
|
||||
})().then(console.log);
|
||||
console.log("moz");
|
||||
}
|
||||
expect: {
|
||||
console.log("foo");
|
||||
(async function() {
|
||||
console.log("bar");
|
||||
for (var a of [ "baz" ])
|
||||
return void await {
|
||||
then(r) {
|
||||
console.log("moo");
|
||||
r(a);
|
||||
},
|
||||
};
|
||||
})().then(console.log);
|
||||
console.log("moz");
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
"moz",
|
||||
"moo",
|
||||
"undefined",
|
||||
]
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
inline_block_await: {
|
||||
options = {
|
||||
awaits: true,
|
||||
if_return: true,
|
||||
inline: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
console.log("foo");
|
||||
(async function() {
|
||||
console.log("bar");
|
||||
await async function() {
|
||||
for (var a of [ "baz" ])
|
||||
return a;
|
||||
}();
|
||||
})().then(console.log);
|
||||
console.log("moo");
|
||||
}
|
||||
expect: {
|
||||
console.log("foo");
|
||||
(async function() {
|
||||
console.log("bar");
|
||||
for (var a of [ "baz" ])
|
||||
return void await a;
|
||||
})().then(console.log);
|
||||
console.log("moo");
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
"moo",
|
||||
"undefined",
|
||||
]
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
inline_block_await_async: {
|
||||
options = {
|
||||
inline: true,
|
||||
}
|
||||
input: {
|
||||
(async function() {
|
||||
console.log("foo");
|
||||
await (async function() {
|
||||
while (await console.log("bar"));
|
||||
console.log("baz");
|
||||
})();
|
||||
console.log("moo");
|
||||
})().then(console.log);
|
||||
console.log("moz");
|
||||
}
|
||||
expect: {
|
||||
(async function() {
|
||||
console.log("foo");
|
||||
while (await console.log("bar"));
|
||||
console.log("baz");
|
||||
await 0;
|
||||
console.log("moo");
|
||||
})().then(console.log);
|
||||
console.log("moz");
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
"moz",
|
||||
"baz",
|
||||
"moo",
|
||||
"undefined",
|
||||
]
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
inline_block_await_async_return: {
|
||||
options = {
|
||||
awaits: true,
|
||||
if_return: true,
|
||||
inline: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
console.log("foo");
|
||||
(async function() {
|
||||
console.log("bar");
|
||||
await async function() {
|
||||
for (var a of [ "baz" ])
|
||||
return {
|
||||
then(r) {
|
||||
console.log("moo");
|
||||
r(a);
|
||||
},
|
||||
};
|
||||
}();
|
||||
})().then(console.log);
|
||||
console.log("moz");
|
||||
}
|
||||
expect: {
|
||||
console.log("foo");
|
||||
(async function() {
|
||||
console.log("bar");
|
||||
for (var a of [ "baz" ])
|
||||
return void await {
|
||||
then(r) {
|
||||
console.log("moo");
|
||||
r(a);
|
||||
},
|
||||
};;
|
||||
})().then(console.log);
|
||||
console.log("moz");
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
"moz",
|
||||
"moo",
|
||||
"undefined",
|
||||
]
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
inline_block_return: {
|
||||
options = {
|
||||
awaits: true,
|
||||
if_return: true,
|
||||
inline: true,
|
||||
passes: 2,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
console.log("foo");
|
||||
(async function() {
|
||||
console.log("bar");
|
||||
return async function() {
|
||||
for (var a of [ "baz" ])
|
||||
return a;
|
||||
}();
|
||||
})().then(console.log);
|
||||
console.log("moo");
|
||||
}
|
||||
expect: {
|
||||
console.log("foo");
|
||||
(async function() {
|
||||
console.log("bar");
|
||||
for (var a of [ "baz" ])
|
||||
return a;
|
||||
})().then(console.log);
|
||||
console.log("moo");
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
"moo",
|
||||
"baz",
|
||||
]
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
inline_block_return_async: {
|
||||
options = {
|
||||
awaits: true,
|
||||
if_return: true,
|
||||
inline: true,
|
||||
passes: 2,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
console.log("foo");
|
||||
(async function() {
|
||||
console.log("bar");
|
||||
return async function() {
|
||||
for (var a of [ "baz" ])
|
||||
return {
|
||||
then(r) {
|
||||
console.log("moo");
|
||||
r(a);
|
||||
},
|
||||
};
|
||||
}();
|
||||
})().then(console.log);
|
||||
console.log("moz");
|
||||
}
|
||||
expect: {
|
||||
console.log("foo");
|
||||
(async function() {
|
||||
console.log("bar");
|
||||
for (var a of [ "baz" ])
|
||||
return {
|
||||
then(r) {
|
||||
console.log("moo");
|
||||
r(a);
|
||||
},
|
||||
};
|
||||
})().then(console.log);
|
||||
console.log("moz");
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
"moz",
|
||||
"moo",
|
||||
"baz",
|
||||
]
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
await_then: {
|
||||
options = {
|
||||
awaits: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
var a = "PASS";
|
||||
function f() {
|
||||
return {
|
||||
then: function(r) {
|
||||
a = "FAIL";
|
||||
r();
|
||||
},
|
||||
};
|
||||
}
|
||||
(async function() {
|
||||
f(), await 42;
|
||||
while (console.log(a));
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
var a = "PASS";
|
||||
function f() {
|
||||
return {
|
||||
then: function(r) {
|
||||
a = "FAIL";
|
||||
r();
|
||||
},
|
||||
};
|
||||
}
|
||||
(async function() {
|
||||
await !f();
|
||||
while (console.log(a));
|
||||
})();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
await_unary_1: {
|
||||
options = {
|
||||
awaits: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
var a = "PASS";
|
||||
function f() {
|
||||
return {
|
||||
then: function(r) {
|
||||
a = "FAIL";
|
||||
r();
|
||||
},
|
||||
};
|
||||
}
|
||||
(async function() {
|
||||
await !f();
|
||||
while (console.log(a));
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
var a = "PASS";
|
||||
function f() {
|
||||
return {
|
||||
then: function(r) {
|
||||
a = "FAIL";
|
||||
r();
|
||||
},
|
||||
};
|
||||
}
|
||||
(async function() {
|
||||
await !f();
|
||||
while (console.log(a));
|
||||
})();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
await_unary_2: {
|
||||
options = {
|
||||
awaits: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
var a = "PASS";
|
||||
function f() {
|
||||
return {
|
||||
then: function(r) {
|
||||
a = "FAIL";
|
||||
r();
|
||||
},
|
||||
};
|
||||
}
|
||||
(async function() {
|
||||
await ~f();
|
||||
while (console.log(a));
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
var a = "PASS";
|
||||
function f() {
|
||||
return {
|
||||
then: function(r) {
|
||||
a = "FAIL";
|
||||
r();
|
||||
},
|
||||
};
|
||||
}
|
||||
(async function() {
|
||||
await !f();
|
||||
while (console.log(a));
|
||||
})();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
await_unary_3: {
|
||||
options = {
|
||||
awaits: true,
|
||||
side_effects: true,
|
||||
@@ -367,7 +839,46 @@ await_unary: {
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
await_void: {
|
||||
await_void_1: {
|
||||
options = {
|
||||
awaits: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
var a = "PASS";
|
||||
function f() {
|
||||
return {
|
||||
then: function(r) {
|
||||
a = "FAIL";
|
||||
r();
|
||||
},
|
||||
};
|
||||
}
|
||||
(async function() {
|
||||
await void f();
|
||||
while (console.log(a));
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
var a = "PASS";
|
||||
function f() {
|
||||
return {
|
||||
then: function(r) {
|
||||
a = "FAIL";
|
||||
r();
|
||||
},
|
||||
};
|
||||
}
|
||||
(async function() {
|
||||
await !f();
|
||||
while (console.log(a));
|
||||
})();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
await_void_2: {
|
||||
options = {
|
||||
awaits: true,
|
||||
if_return: true,
|
||||
@@ -382,7 +893,7 @@ await_void: {
|
||||
}
|
||||
expect: {
|
||||
(async function() {
|
||||
await console.log("PASS");
|
||||
console.log("PASS");
|
||||
})();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
@@ -1235,10 +1746,10 @@ issue_4454_2: {
|
||||
f("PASS");
|
||||
}
|
||||
expect: {
|
||||
function f(b) {
|
||||
(async function(c = console.log(b)) {})();
|
||||
var b = 42..toString();
|
||||
console.log(b);
|
||||
function f(a) {
|
||||
(async function(c = console.log(a)) {})();
|
||||
var a = 42..toString();
|
||||
console.log(a);
|
||||
}
|
||||
f("PASS");
|
||||
}
|
||||
@@ -1938,9 +2449,9 @@ issue_5032_normal: {
|
||||
console.log(value);
|
||||
return value;
|
||||
}
|
||||
async function f(c) {
|
||||
var b = log(c), c = b;
|
||||
log(b);
|
||||
async function f(a) {
|
||||
var a = log(a), c = a;
|
||||
log(a);
|
||||
log(c);
|
||||
}
|
||||
f("PASS");
|
||||
@@ -2238,3 +2749,213 @@ issue_5177: {
|
||||
expect_stdout: "function"
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
issue_5250: {
|
||||
options = {
|
||||
inline: true,
|
||||
}
|
||||
input: {
|
||||
(async function() {
|
||||
await function() {
|
||||
while (console.log("foo"));
|
||||
}();
|
||||
console.log("bar");
|
||||
})();
|
||||
console.log("baz");
|
||||
}
|
||||
expect: {
|
||||
(async function() {
|
||||
while (console.log("foo"));
|
||||
await 0;
|
||||
console.log("bar");
|
||||
})();
|
||||
console.log("baz");
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"baz",
|
||||
"bar",
|
||||
]
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
issue_5258_1: {
|
||||
options = {
|
||||
awaits: true,
|
||||
inline: true,
|
||||
}
|
||||
input: {
|
||||
(async function() {
|
||||
(async function() {
|
||||
throw "FAIL";
|
||||
})();
|
||||
return "PASS";
|
||||
})().catch(console.log).then(console.log);
|
||||
}
|
||||
expect: {
|
||||
(async function() {
|
||||
(async function() {
|
||||
throw "FAIL";
|
||||
})();
|
||||
return "PASS";
|
||||
})().catch(console.log).then(console.log);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
issue_5258_2: {
|
||||
options = {
|
||||
awaits: true,
|
||||
inline: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
throw "FAIL";
|
||||
}
|
||||
(async function() {
|
||||
(async function() {
|
||||
f();
|
||||
})();
|
||||
return "PASS";
|
||||
})().catch(console.log).then(console.log);
|
||||
}
|
||||
expect: {
|
||||
function f() {
|
||||
throw "FAIL";
|
||||
}
|
||||
(async function() {
|
||||
(async function() {
|
||||
f();
|
||||
})();
|
||||
return "PASS";
|
||||
})().catch(console.log).then(console.log);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
issue_5298: {
|
||||
options = {
|
||||
awaits: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
var a = "PASS";
|
||||
(async function() {
|
||||
for (a in [ 42 in null ]);
|
||||
})();
|
||||
console.log(a);
|
||||
}
|
||||
expect: {
|
||||
var a = "PASS";
|
||||
(async function() {
|
||||
for (a in [ 42 in null ]);
|
||||
})();
|
||||
console.log(a);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
issue_5305_1: {
|
||||
options = {
|
||||
inline: true,
|
||||
}
|
||||
input: {
|
||||
var a = "PASS";
|
||||
(async function() {
|
||||
try {
|
||||
return await function() {
|
||||
while (!console);
|
||||
}();
|
||||
} finally {
|
||||
a = "FAIL";
|
||||
}
|
||||
})();
|
||||
console.log(a);
|
||||
}
|
||||
expect: {
|
||||
var a = "PASS";
|
||||
(async function() {
|
||||
try {
|
||||
while (!console);
|
||||
return await void 0;
|
||||
} finally {
|
||||
a = "FAIL";
|
||||
}
|
||||
})();
|
||||
console.log(a);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
issue_5305_2: {
|
||||
options = {
|
||||
inline: true,
|
||||
}
|
||||
input: {
|
||||
var a = "PASS";
|
||||
(async function() {
|
||||
try {
|
||||
throw null;
|
||||
} catch (e) {
|
||||
return await function() {
|
||||
while (!console);
|
||||
}();
|
||||
} finally {
|
||||
a = "FAIL";
|
||||
}
|
||||
})();
|
||||
console.log(a);
|
||||
}
|
||||
expect: {
|
||||
var a = "PASS";
|
||||
(async function() {
|
||||
try {
|
||||
throw null;
|
||||
} catch (e) {
|
||||
while (!console);
|
||||
return await void 0;
|
||||
} finally {
|
||||
a = "FAIL";
|
||||
}
|
||||
})();
|
||||
console.log(a);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
issue_5305_3: {
|
||||
options = {
|
||||
awaits: true,
|
||||
inline: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
var a = "PASS";
|
||||
(async function() {
|
||||
try {
|
||||
await function() {
|
||||
while (!console);
|
||||
}();
|
||||
} catch (e) {
|
||||
a = "FAIL";
|
||||
}
|
||||
})();
|
||||
console.log(a);
|
||||
}
|
||||
expect: {
|
||||
var a = "PASS";
|
||||
try {
|
||||
while (!console);
|
||||
} catch (e) {
|
||||
a = "FAIL";
|
||||
}
|
||||
console.log(a);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ arithmetic: {
|
||||
}
|
||||
expect_exact: "console.log((1n+0x2n)*(0o3n- -4n)>>5n-6n);"
|
||||
expect_stdout: "42n"
|
||||
node_version: ">=10"
|
||||
node_version: ">=10.4.0"
|
||||
}
|
||||
|
||||
minus_dot: {
|
||||
@@ -13,7 +13,7 @@ minus_dot: {
|
||||
}
|
||||
expect_exact: "console.log(typeof-42n.toString(),typeof(-42n).toString());"
|
||||
expect_stdout: "number string"
|
||||
node_version: ">=10"
|
||||
node_version: ">=10.4.0"
|
||||
}
|
||||
|
||||
evaluate: {
|
||||
@@ -28,7 +28,7 @@ evaluate: {
|
||||
console.log(0xdeadbeefn.toString(16));
|
||||
}
|
||||
expect_stdout: "deadbeef"
|
||||
node_version: ">=10"
|
||||
node_version: ">=10.4.0"
|
||||
}
|
||||
|
||||
Number: {
|
||||
@@ -42,7 +42,7 @@ Number: {
|
||||
console.log(+("" + -0xfeed_dead_beef_badn));
|
||||
}
|
||||
expect_stdout: "-1148098955808013200"
|
||||
node_version: ">=10"
|
||||
node_version: ">=10.4.0"
|
||||
}
|
||||
|
||||
issue_4590: {
|
||||
@@ -58,7 +58,7 @@ issue_4590: {
|
||||
0n || console.log("PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=10"
|
||||
node_version: ">=10.4.0"
|
||||
}
|
||||
|
||||
issue_4801: {
|
||||
@@ -88,5 +88,5 @@ issue_4801: {
|
||||
}
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=10"
|
||||
node_version: ">=10.4.0"
|
||||
}
|
||||
|
||||
@@ -697,3 +697,30 @@ issue_5041_2: {
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5228: {
|
||||
options = {
|
||||
booleans: true,
|
||||
evaluate: true,
|
||||
inline: true,
|
||||
passes: 2,
|
||||
}
|
||||
input: {
|
||||
console.log(function() {
|
||||
return !function() {
|
||||
do {
|
||||
return null;
|
||||
} while (console);
|
||||
}();
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
console.log(function() {
|
||||
do {
|
||||
return !0;
|
||||
} while (console);
|
||||
return !0;
|
||||
}());
|
||||
}
|
||||
expect_stdout: "true"
|
||||
}
|
||||
|
||||
@@ -434,6 +434,33 @@ static_side_effects: {
|
||||
console.log(a);
|
||||
}
|
||||
expect: {
|
||||
var a = "FAIL 1";
|
||||
(class {
|
||||
static c = a = "PASS";
|
||||
});
|
||||
console.log(a);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=12"
|
||||
}
|
||||
|
||||
static_side_effects_strict: {
|
||||
options = {
|
||||
inline: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
var a = "FAIL 1";
|
||||
class A {
|
||||
static p = a = "PASS";
|
||||
q = a = "FAIL 2";
|
||||
}
|
||||
console.log(a);
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
var a = "FAIL 1";
|
||||
a = "PASS";
|
||||
console.log(a);
|
||||
@@ -807,6 +834,33 @@ unused_await: {
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
var await = "PASS";
|
||||
(async function() {
|
||||
(class {
|
||||
static c = console.log(await);
|
||||
});
|
||||
})();
|
||||
}
|
||||
expect_stdout: true
|
||||
node_version: ">=12 <16"
|
||||
}
|
||||
|
||||
unused_await_strict: {
|
||||
options = {
|
||||
inline: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
var await = "PASS";
|
||||
(async function() {
|
||||
class A {
|
||||
static p = console.log(await);
|
||||
}
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
var await = "PASS";
|
||||
(async function() {
|
||||
(() => console.log(await))();
|
||||
@@ -890,7 +944,7 @@ keep_fnames: {
|
||||
issue_805_1: {
|
||||
options = {
|
||||
inline: true,
|
||||
passes: 2,
|
||||
passes: 3,
|
||||
pure_getters: "strict",
|
||||
reduce_vars: true,
|
||||
sequences: true,
|
||||
@@ -926,7 +980,7 @@ issue_805_1: {
|
||||
issue_805_2: {
|
||||
options = {
|
||||
inline: true,
|
||||
passes: 2,
|
||||
passes: 3,
|
||||
pure_getters: "strict",
|
||||
reduce_vars: true,
|
||||
sequences: true,
|
||||
@@ -1149,6 +1203,31 @@ issue_4705: {
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
(class {
|
||||
[console.log("PASS")]() {}
|
||||
});
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=12"
|
||||
}
|
||||
|
||||
issue_4705_strict: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
var a = "PASS";
|
||||
class A {
|
||||
p = a = "FAIL";
|
||||
[console.log(a)];
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
console.log("PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
@@ -1310,6 +1389,7 @@ issue_4725_1: {
|
||||
|
||||
issue_4725_2: {
|
||||
options = {
|
||||
if_return: true,
|
||||
inline: true,
|
||||
}
|
||||
input: {
|
||||
@@ -1370,9 +1450,40 @@ issue_4756: {
|
||||
expect: {
|
||||
try {
|
||||
(class extends 42 {
|
||||
[console.log("foo")]() {}
|
||||
}),
|
||||
(() => console.log("bar"))();
|
||||
static [console.log("foo")] = console.log("bar");
|
||||
});
|
||||
} catch (e) {
|
||||
console.log("baz");
|
||||
}
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"baz",
|
||||
]
|
||||
node_version: ">=12"
|
||||
}
|
||||
|
||||
issue_4756_strict: {
|
||||
options = {
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
try {
|
||||
class A extends 42 {
|
||||
static [console.log("foo")] = console.log("bar");
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("baz");
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
try {
|
||||
(class extends 42 {
|
||||
static [console.log("foo")] = console.log("bar");
|
||||
});
|
||||
} catch (e) {
|
||||
console.log("baz");
|
||||
}
|
||||
@@ -1439,7 +1550,7 @@ issue_4829_1: {
|
||||
input: {
|
||||
"use strict";
|
||||
try {
|
||||
class A extends { f(){} }.f {}
|
||||
class A extends { f() {} }.f {}
|
||||
} catch (e) {
|
||||
console.log("PASS");
|
||||
}
|
||||
@@ -1646,9 +1757,38 @@ issue_4962_1: {
|
||||
}
|
||||
expect: {
|
||||
(function g() {}),
|
||||
void function() {
|
||||
while (console.log(typeof g));
|
||||
}();
|
||||
void class {
|
||||
static c = function() {
|
||||
while (console.log(typeof g));
|
||||
}();
|
||||
};
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
node_version: ">=12"
|
||||
}
|
||||
|
||||
issue_4962_1_strict: {
|
||||
options = {
|
||||
ie: true,
|
||||
inline: true,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
(function() {
|
||||
function f() {
|
||||
while (console.log(typeof g));
|
||||
}
|
||||
class A {
|
||||
static p = f();
|
||||
}
|
||||
})(function g() {});
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
(function g() {});
|
||||
while (console.log(typeof g));
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
node_version: ">=12"
|
||||
@@ -1672,6 +1812,36 @@ issue_4962_2: {
|
||||
}, typeof g));
|
||||
}
|
||||
expect: {
|
||||
console.log(function f() {}(function g() {
|
||||
(class {
|
||||
static c = f;
|
||||
});
|
||||
}));
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
node_version: ">=12"
|
||||
}
|
||||
|
||||
issue_4962_2_strict: {
|
||||
options = {
|
||||
ie: true,
|
||||
inline: true,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
console.log(function f() {}(function g() {
|
||||
function h() {
|
||||
f;
|
||||
}
|
||||
class A {
|
||||
static p = h();
|
||||
}
|
||||
}, typeof g));
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
console.log(function f() {}(function g() {
|
||||
f;
|
||||
}));
|
||||
@@ -1868,6 +2038,32 @@ issue_5015_3: {
|
||||
});
|
||||
console.log("PASS");
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
(class A {});
|
||||
console.log("PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5015_4: {
|
||||
options = {
|
||||
reduce_vars: true,
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
(class A {
|
||||
static f() {
|
||||
return A;
|
||||
}
|
||||
});
|
||||
console.log("PASS");
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
console.log("PASS");
|
||||
@@ -2027,6 +2223,40 @@ issue_5082_1: {
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
(function() {
|
||||
class A {
|
||||
p = console.log("PASS");
|
||||
q() {}
|
||||
}
|
||||
(class {
|
||||
static c = new A();
|
||||
});
|
||||
})();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=12"
|
||||
}
|
||||
|
||||
issue_5082_1_strict: {
|
||||
options = {
|
||||
inline: true,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
(function() {
|
||||
class A {
|
||||
p = console.log("PASS");
|
||||
q() {}
|
||||
}
|
||||
class B {
|
||||
static P = new A();
|
||||
}
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
(function() {
|
||||
class A {
|
||||
p = console.log("PASS");
|
||||
@@ -2058,6 +2288,41 @@ issue_5082_2: {
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
(function() {
|
||||
class A {
|
||||
p = console.log("PASS");
|
||||
q() {}
|
||||
}
|
||||
(class {
|
||||
static c = new A();
|
||||
});
|
||||
})();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=12"
|
||||
}
|
||||
|
||||
issue_5082_2_static: {
|
||||
options = {
|
||||
inline: true,
|
||||
passes: 2,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
(function() {
|
||||
class A {
|
||||
p = console.log("PASS");
|
||||
q() {}
|
||||
}
|
||||
class B {
|
||||
static P = new A();
|
||||
}
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
void new class {
|
||||
p = console.log("PASS");
|
||||
q() {}
|
||||
@@ -2097,3 +2362,90 @@ issue_5142: {
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=12"
|
||||
}
|
||||
|
||||
issue_5294_1: {
|
||||
options = {
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
(class A {
|
||||
static p = console.log(typeof A);
|
||||
});
|
||||
}
|
||||
expect: {
|
||||
(class A {
|
||||
static c = console.log(typeof A);
|
||||
});
|
||||
}
|
||||
expect_stdout: "function"
|
||||
node_version: ">=12"
|
||||
}
|
||||
|
||||
issue_5294_2: {
|
||||
options = {
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
class A {
|
||||
static p = console.log(typeof A);
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
class A {
|
||||
static p = console.log(typeof A);
|
||||
}
|
||||
}
|
||||
expect_stdout: "function"
|
||||
node_version: ">=12"
|
||||
}
|
||||
|
||||
issue_5294_3: {
|
||||
options = {
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var a = this;
|
||||
(class A {
|
||||
static p = console.log(a === A ? "FAIL" : "PASS");
|
||||
});
|
||||
}
|
||||
expect: {
|
||||
var a = this;
|
||||
(class A {
|
||||
static p = console.log(a === A ? "FAIL" : "PASS");
|
||||
});
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=12"
|
||||
}
|
||||
|
||||
issue_5294_4: {
|
||||
options = {
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(class A {
|
||||
static p = function() {
|
||||
var a = this;
|
||||
console.log(a === A ? "FAIL" : "PASS");
|
||||
}();
|
||||
});
|
||||
}
|
||||
expect: {
|
||||
(class A {
|
||||
static p = function() {
|
||||
console.log(this === A ? "FAIL" : "PASS");
|
||||
}();
|
||||
});
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=12"
|
||||
}
|
||||
|
||||
@@ -346,9 +346,7 @@ collapse_vars_if: {
|
||||
return "x" != "Bar" + x / 4 ? g9 : g5;
|
||||
}
|
||||
function f3(x) {
|
||||
if (x)
|
||||
return 1;
|
||||
return 2;
|
||||
return x ? 1 : 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1912,6 +1910,42 @@ collapse_vars_regexp: {
|
||||
]
|
||||
}
|
||||
|
||||
collapse_arg_sequence: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function(a) {
|
||||
a("foo");
|
||||
})((console.log("bar"), console.log));
|
||||
}
|
||||
expect: {
|
||||
(function(a) {
|
||||
(0, console.log)("foo");
|
||||
})(console.log("bar"));
|
||||
}
|
||||
expect_stdout: [
|
||||
"bar",
|
||||
"foo",
|
||||
]
|
||||
}
|
||||
|
||||
collapse_for_init: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
for (var a = (Math, console), b = a.log("PASS"); b;);
|
||||
}
|
||||
expect: {
|
||||
Math;
|
||||
for (var a, b = console.log("PASS"); b;);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_1537: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
@@ -2667,6 +2701,24 @@ chained_4: {
|
||||
expect_stdout: "foo undefined"
|
||||
}
|
||||
|
||||
chained_5: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
}
|
||||
input: {
|
||||
var a = "PASS";
|
||||
var a = (console, console.log(a));
|
||||
a && ++a;
|
||||
}
|
||||
expect: {
|
||||
var a = "PASS";
|
||||
console;
|
||||
var a;
|
||||
(a = console.log(a)) && ++a;
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
boolean_binary_1: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
@@ -2906,6 +2958,128 @@ compound_assignment_2: {
|
||||
expect_stdout: "4"
|
||||
}
|
||||
|
||||
compound_assignment_3: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
}
|
||||
input: {
|
||||
var a = 1;
|
||||
a += (console.log("PASS"), 2);
|
||||
a.p;
|
||||
}
|
||||
expect: {
|
||||
var a = 1;
|
||||
(a += (console.log("PASS"), 2)).p;
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
compound_assignment_4: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
evaluate: true,
|
||||
}
|
||||
input: {
|
||||
A = "PASS";
|
||||
var a = "";
|
||||
a += (a = "FAIL", A);
|
||||
a.p;
|
||||
console.log(a);
|
||||
}
|
||||
expect: {
|
||||
A = "PASS";
|
||||
var a = "";
|
||||
(a += (a = "FAIL", A)).p;
|
||||
console.log(a);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
compound_assignment_5: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
}
|
||||
input: {
|
||||
var a = 0, b;
|
||||
a += 42;
|
||||
b && (a *= null);
|
||||
console.log(a);
|
||||
}
|
||||
expect: {
|
||||
var a = 0, b;
|
||||
a += 42;
|
||||
b && (a *= null);
|
||||
console.log(a);
|
||||
}
|
||||
expect_stdout: "42"
|
||||
}
|
||||
|
||||
compound_assignment_6: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
}
|
||||
input: {
|
||||
var a;
|
||||
a ^= 6;
|
||||
a *= a + 1;
|
||||
console.log(a);
|
||||
}
|
||||
expect: {
|
||||
var a;
|
||||
a = (a ^= 6) * (a + 1);
|
||||
console.log(a);
|
||||
}
|
||||
expect_stdout: "42"
|
||||
}
|
||||
|
||||
compound_assignment_7: {
|
||||
options = {
|
||||
assignments: true,
|
||||
collapse_vars: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
var a = "FA";
|
||||
a = a + "I";
|
||||
a = a + "L";
|
||||
if (console)
|
||||
a = "PASS";
|
||||
console.log(a);
|
||||
}
|
||||
expect: {
|
||||
var a = "FA";
|
||||
a = a + "I" + "L";
|
||||
if (console)
|
||||
a = "PASS";
|
||||
console.log(a);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
compound_assignment_8: {
|
||||
options = {
|
||||
assignments: true,
|
||||
collapse_vars: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
var a = 2;
|
||||
a = 3 * a;
|
||||
a = 7 * a;
|
||||
console || (a = "FAIL");
|
||||
console.log(a);
|
||||
}
|
||||
expect: {
|
||||
var a = 2;
|
||||
a = a * 3 * 7;
|
||||
console || (a = "FAIL");
|
||||
console.log(a);
|
||||
}
|
||||
expect_stdout: "42"
|
||||
}
|
||||
|
||||
issue_2187_1: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
@@ -3030,10 +3204,10 @@ issue_2203_2: {
|
||||
a: "FAIL",
|
||||
b: function() {
|
||||
return function(c) {
|
||||
return (String, (Object, function() {
|
||||
return (Object, function() {
|
||||
return this;
|
||||
}())).a;
|
||||
}();
|
||||
}()).a;
|
||||
}(String);
|
||||
}
|
||||
}.b());
|
||||
}
|
||||
@@ -3731,6 +3905,7 @@ issue_2437_1: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
conditionals: true,
|
||||
if_return: true,
|
||||
inline: true,
|
||||
join_vars: true,
|
||||
passes: 2,
|
||||
@@ -3763,17 +3938,17 @@ issue_2437_1: {
|
||||
console.log(foo());
|
||||
}
|
||||
expect: {
|
||||
console.log(function() {
|
||||
if (xhrDesc) {
|
||||
var result = !!(req = new XMLHttpRequest()).onreadystatechange;
|
||||
return Object.defineProperty(XMLHttpRequest.prototype, "onreadystatechange", xhrDesc || {}),
|
||||
result;
|
||||
}
|
||||
var req = new XMLHttpRequest(), detectFunc = function(){};
|
||||
return req.onreadystatechange = detectFunc,
|
||||
result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc,
|
||||
req.onreadystatechange = null, result;
|
||||
}());
|
||||
var req, detectFunc, result;
|
||||
console.log((
|
||||
xhrDesc ? (result = !!(req = new XMLHttpRequest).onreadystatechange,
|
||||
Object.defineProperty(XMLHttpRequest.prototype, "onreadystatechange", xhrDesc||{})
|
||||
) : (
|
||||
(req = new XMLHttpRequest).onreadystatechange = detectFunc = function(){},
|
||||
result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc,
|
||||
req.onreadystatechange = null
|
||||
),
|
||||
result
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3783,6 +3958,7 @@ issue_2437_2: {
|
||||
conditionals: true,
|
||||
inline: true,
|
||||
join_vars: true,
|
||||
negate_iife: true,
|
||||
passes: 3,
|
||||
reduce_funcs: true,
|
||||
reduce_vars: true,
|
||||
@@ -3813,15 +3989,15 @@ issue_2437_2: {
|
||||
foo();
|
||||
}
|
||||
expect: {
|
||||
!function() {
|
||||
if (xhrDesc)
|
||||
return (req = new XMLHttpRequest()).onreadystatechange,
|
||||
Object.defineProperty(XMLHttpRequest.prototype, "onreadystatechange", xhrDesc || {});
|
||||
var req = new XMLHttpRequest();
|
||||
req.onreadystatechange = function(){},
|
||||
var req;
|
||||
xhrDesc ? (
|
||||
(req = new XMLHttpRequest).onreadystatechange,
|
||||
Object.defineProperty(XMLHttpRequest.prototype, "onreadystatechange", xhrDesc || {})
|
||||
) : (
|
||||
(req = new XMLHttpRequest).onreadystatechange = function(){},
|
||||
req[SYMBOL_FAKE_ONREADYSTATECHANGE_1],
|
||||
req.onreadystatechange = null;
|
||||
}();
|
||||
req.onreadystatechange = null
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6443,7 +6619,8 @@ assign_undeclared: {
|
||||
console.log(typeof B);
|
||||
}
|
||||
expect: {
|
||||
B = new (console.log(42), function() {})();
|
||||
console.log(42);
|
||||
B = new function() {}();
|
||||
console.log(typeof B);
|
||||
}
|
||||
expect_stdout: [
|
||||
@@ -8156,9 +8333,9 @@ issue_3884_1: {
|
||||
console.log(a, b);
|
||||
}
|
||||
expect: {
|
||||
var a = 100, b = 1;
|
||||
b <<= ++a;
|
||||
console.log(a, b);
|
||||
var a = 100;
|
||||
++a;
|
||||
console.log(a, 32);
|
||||
}
|
||||
expect_stdout: "101 32"
|
||||
}
|
||||
@@ -9139,9 +9316,7 @@ issue_4908: {
|
||||
console.log(d[1]);
|
||||
}
|
||||
expect: {
|
||||
var a = 0, b;
|
||||
console || a++;
|
||||
var c = a, d = [ (d = a) && d, d += 42 ];
|
||||
var a = 0, b, c = (console || a++, a), d = [ (d = a) && d, d += 42 ];
|
||||
console.log(d[1]);
|
||||
}
|
||||
expect_stdout: "42"
|
||||
@@ -9374,9 +9549,8 @@ inline_throw: {
|
||||
expect: {
|
||||
try {
|
||||
(function(a) {
|
||||
return function() {
|
||||
throw a;
|
||||
}();
|
||||
throw a;
|
||||
return;
|
||||
})("PASS");
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
@@ -9566,3 +9740,108 @@ issue_5182: {
|
||||
]
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5273: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
evaluate: true,
|
||||
inline: true,
|
||||
reduce_vars: true,
|
||||
sequences: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
var a = "10", b = 1;
|
||||
function f(c, d) {
|
||||
return d;
|
||||
}
|
||||
f((b += a, b *= a), f);
|
||||
console.log(b);
|
||||
}
|
||||
expect: {
|
||||
var a = "10", b = 1;
|
||||
function f(c, d) {
|
||||
return d;
|
||||
}
|
||||
b = 1100,
|
||||
f,
|
||||
console.log(b);
|
||||
}
|
||||
expect_stdout: "1100"
|
||||
}
|
||||
|
||||
issue_5276: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
pure_getters: "strict",
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
var a = A = "PASS";
|
||||
a.p += null;
|
||||
a.p -= 42;
|
||||
console.log(a);
|
||||
}
|
||||
expect: {
|
||||
var a = A = "PASS";
|
||||
a.p = a.p + null - 42;
|
||||
console.log(a);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5277: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function() {
|
||||
var a = function() {
|
||||
a += null;
|
||||
a -= 42;
|
||||
};
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
console.log(function() {}());
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
}
|
||||
|
||||
issue_5309_1: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
conditionals: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
if (console)
|
||||
var a = (console.log("PASS"), b), b = a;
|
||||
else
|
||||
console.log("FAIL");
|
||||
}
|
||||
expect: {
|
||||
var a, b;
|
||||
console ? (console.log("PASS"), b = b) : console.log("FAIL");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5309_2: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
var a, b;
|
||||
console ? (a = (console.log("PASS"), b), b = a) : console.log("FAIL");
|
||||
}
|
||||
expect: {
|
||||
var a, b;
|
||||
console ? (console.log("PASS"), b = b) : console.log("FAIL");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
@@ -1924,3 +1924,86 @@ object_super: {
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5232_1: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
}
|
||||
input: {
|
||||
(function() {
|
||||
if (Math) {
|
||||
function f() {}
|
||||
for (var a in [ 42 ])
|
||||
console.log(typeof f);
|
||||
} else {
|
||||
var b = null;
|
||||
return true;
|
||||
}
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
(function() {
|
||||
var b;
|
||||
if (!Math)
|
||||
return b = null, true;
|
||||
function f() {}
|
||||
for (var a in [ 42 ]) console.log(typeof f);
|
||||
})();
|
||||
}
|
||||
expect_stdout: "function"
|
||||
}
|
||||
|
||||
issue_5232_2: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function() {
|
||||
if (!Math);
|
||||
else {
|
||||
var b = null;
|
||||
return "PASS";
|
||||
}
|
||||
}());
|
||||
}
|
||||
expect: {
|
||||
console.log(function() {
|
||||
var b;
|
||||
if (Math)
|
||||
return b = null, "PASS";
|
||||
}());
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5232_3: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function() {
|
||||
return function() {
|
||||
if (console)
|
||||
console.log("PASS");
|
||||
else {
|
||||
var a = null;
|
||||
return "FAIL";
|
||||
}
|
||||
};
|
||||
}()());
|
||||
}
|
||||
expect: {
|
||||
console.log(function() {
|
||||
return function() {
|
||||
var a;
|
||||
if (!console)
|
||||
return a = null, "FAIL";
|
||||
console.log("PASS");
|
||||
};
|
||||
}()());
|
||||
}
|
||||
expect_stdout: [
|
||||
"PASS",
|
||||
"undefined",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -220,6 +220,32 @@ merge_vars_3: {
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
merge_vars_4: {
|
||||
options = {
|
||||
merge_vars: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
var a = 1;
|
||||
console.log(typeof a);
|
||||
{
|
||||
var b = console;
|
||||
console.log(typeof b);
|
||||
const a = 0;
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
var a = 1;
|
||||
console.log(typeof a);
|
||||
{
|
||||
var b = console;
|
||||
console.log(typeof b);
|
||||
const a = 0;
|
||||
}
|
||||
}
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
use_before_init_1: {
|
||||
options = {
|
||||
reduce_vars: true,
|
||||
@@ -838,12 +864,10 @@ issue_4202: {
|
||||
expect: {
|
||||
{
|
||||
const o = {};
|
||||
(function() {
|
||||
function f() {
|
||||
o.p = 42;
|
||||
}
|
||||
f(f);
|
||||
})();
|
||||
function f() {
|
||||
o.p = 42;
|
||||
}
|
||||
f(f);
|
||||
console.log(o.p++);
|
||||
}
|
||||
}
|
||||
@@ -1219,9 +1243,9 @@ issue_4248: {
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_4261: {
|
||||
issue_4261_1: {
|
||||
options = {
|
||||
inline: true,
|
||||
inline: 3,
|
||||
reduce_funcs: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
@@ -1259,6 +1283,43 @@ issue_4261: {
|
||||
expect_stdout: "42"
|
||||
}
|
||||
|
||||
issue_4261_2: {
|
||||
options = {
|
||||
if_return: true,
|
||||
inline: true,
|
||||
reduce_funcs: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
{
|
||||
const a = 42;
|
||||
(function() {
|
||||
function f() {
|
||||
console.log(a);
|
||||
}
|
||||
function g() {
|
||||
while (f());
|
||||
}
|
||||
(function() {
|
||||
while (g());
|
||||
})();
|
||||
})();
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
{
|
||||
const a = 42;
|
||||
function g() {
|
||||
while (void console.log(a));
|
||||
}
|
||||
while (g());
|
||||
}
|
||||
}
|
||||
expect_stdout: "42"
|
||||
}
|
||||
|
||||
issue_4274_1: {
|
||||
options = {
|
||||
loops: true,
|
||||
@@ -1692,3 +1753,63 @@ issue_4965_2: {
|
||||
expect_stdout: "undefined"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5254: {
|
||||
options = {
|
||||
inline: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
do {
|
||||
(function() {
|
||||
const a = console.log;
|
||||
a && a("foo");
|
||||
})();
|
||||
} while (console.log("bar"));
|
||||
}
|
||||
expect: {
|
||||
do {
|
||||
const a = console.log;
|
||||
a && a("foo");
|
||||
} while (console.log("bar"));
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
]
|
||||
}
|
||||
|
||||
issue_5260: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
var a = "foo", o;
|
||||
while (console.log("bar"));
|
||||
o = {
|
||||
baz: function(b) {
|
||||
console.log(a, b);
|
||||
},
|
||||
};
|
||||
for (const a in o)
|
||||
o[a](a);
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
var a = "foo", o;
|
||||
while (console.log("bar"));
|
||||
o = {
|
||||
baz: function(b) {
|
||||
console.log(a, b);
|
||||
},
|
||||
};
|
||||
for (const a in o)
|
||||
o[a](a);
|
||||
}
|
||||
expect_stdout: [
|
||||
"bar",
|
||||
"foo baz",
|
||||
]
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
@@ -158,6 +158,28 @@ process_boolean_returns: {
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
collapse_arg_sequence: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function(a = (console.log("bar"), console.log)) {
|
||||
a("foo");
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
(function(a = console.log("bar")) {
|
||||
(0, console.log)("foo");
|
||||
})();
|
||||
}
|
||||
expect_stdout: [
|
||||
"bar",
|
||||
"foo",
|
||||
]
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
collapse_value_1: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
@@ -1037,7 +1059,7 @@ mangle_arrow_1: {
|
||||
});
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
node_version: ">=6.9.3"
|
||||
}
|
||||
|
||||
mangle_arrow_1_toplevel: {
|
||||
@@ -1073,7 +1095,7 @@ mangle_arrow_1_toplevel: {
|
||||
});
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
node_version: ">=6.9.3"
|
||||
}
|
||||
|
||||
mangle_arrow_2: {
|
||||
@@ -1109,7 +1131,7 @@ mangle_arrow_2: {
|
||||
});
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
node_version: ">=6.9.3"
|
||||
}
|
||||
|
||||
mangle_arrow_2_toplevel: {
|
||||
@@ -1145,7 +1167,7 @@ mangle_arrow_2_toplevel: {
|
||||
});
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
node_version: ">=6.9.3"
|
||||
}
|
||||
|
||||
issue_4444: {
|
||||
@@ -1587,7 +1609,7 @@ issue_4510_2: {
|
||||
};
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
issue_4523: {
|
||||
@@ -1866,7 +1888,7 @@ issue_5057_2: {
|
||||
|
||||
issue_5057_3: {
|
||||
options = {
|
||||
inline: true,
|
||||
inline: 3,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
@@ -1889,6 +1911,31 @@ issue_5057_3: {
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5057_4: {
|
||||
options = {
|
||||
if_return: true,
|
||||
inline: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function(a) {
|
||||
(function f(b) {
|
||||
(function(a = console.log("FAIL 1")) {})(b);
|
||||
console.log(a);
|
||||
})("FAIL 2");
|
||||
})("PASS");
|
||||
}
|
||||
expect: {
|
||||
(function(a) {
|
||||
var b = "FAIL 2";
|
||||
(function(a = console.log("FAIL 1")) {})(b);
|
||||
console.log(a);
|
||||
})("PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5065: {
|
||||
options = {
|
||||
pure_getters: "strict",
|
||||
@@ -1957,3 +2004,80 @@ issue_5192: {
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5246_1: {
|
||||
options = {
|
||||
pure_getters: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function({} = 42) {
|
||||
return "PASS";
|
||||
}("foo"));
|
||||
}
|
||||
expect: {
|
||||
console.log(function({} = 0) {
|
||||
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]",
|
||||
]
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5246_2: {
|
||||
options = {
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function f(a = "FAIL", [] = 42) {
|
||||
console.log(a);
|
||||
})("PASS", []);
|
||||
}
|
||||
expect: {
|
||||
(function(a = "FAIL", []) {
|
||||
console.log(a);
|
||||
})("PASS", []);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5246_3: {
|
||||
options = {
|
||||
default_values: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
console.log(function f([ , {} ] = null){}([ , {} ]));
|
||||
}
|
||||
expect: {
|
||||
console.log(function([ {} ]){}([ {} ]));
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5256: {
|
||||
options = {
|
||||
inline: true,
|
||||
}
|
||||
input: {
|
||||
(function(arguments = console.log) {
|
||||
console;
|
||||
})();
|
||||
console.log(typeof arguments);
|
||||
}
|
||||
expect: {
|
||||
// Syntax error on Node.js v6
|
||||
(function(arguments = console.log) {
|
||||
console;
|
||||
})();
|
||||
console.log(typeof arguments);
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
node_version: ">=8"
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ funarg_side_effects_2: {
|
||||
}
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
node_version: ">=6.9.2"
|
||||
}
|
||||
|
||||
funarg_side_effects_3: {
|
||||
@@ -254,7 +254,7 @@ funarg_side_effects_3: {
|
||||
}
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
node_version: ">=6.9.2"
|
||||
}
|
||||
|
||||
funarg_unused_1: {
|
||||
@@ -395,7 +395,8 @@ funarg_unused_6_keep_fargs: {
|
||||
}
|
||||
expect: {
|
||||
(function() {
|
||||
var {} = (console, 42);
|
||||
console;
|
||||
var {} = 42;
|
||||
})();
|
||||
console.log(typeof a);
|
||||
}
|
||||
@@ -1844,13 +1845,13 @@ issue_4294: {
|
||||
expect: {
|
||||
A = "PASS";
|
||||
(function() {
|
||||
var b = function({
|
||||
[b]: {},
|
||||
var a = function({
|
||||
[a]: {},
|
||||
}) {}({
|
||||
[b]: 0,
|
||||
[a]: 0,
|
||||
});
|
||||
var b = A;
|
||||
console.log(b);
|
||||
var a = A;
|
||||
console.log(a);
|
||||
})();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
@@ -2069,7 +2070,7 @@ issue_4319: {
|
||||
|
||||
issue_4321: {
|
||||
options = {
|
||||
inline: true,
|
||||
inline: 3,
|
||||
keep_fargs: false,
|
||||
}
|
||||
input: {
|
||||
@@ -3366,3 +3367,62 @@ issue_5189_2: {
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5222: {
|
||||
options = {
|
||||
hoist_props: true,
|
||||
inline: true,
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
do {
|
||||
(function() {
|
||||
var a = {
|
||||
p: [ a ] = [],
|
||||
};
|
||||
})();
|
||||
} while (console.log("PASS"));
|
||||
}
|
||||
f();
|
||||
}
|
||||
expect: {
|
||||
do {
|
||||
a = void 0,
|
||||
a = {
|
||||
p: [ a ] = [],
|
||||
};
|
||||
} while (console.log("PASS"));
|
||||
var a;
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5288: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
inline: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
varify: true,
|
||||
}
|
||||
input: {
|
||||
while (function([]) {}([ function f() {
|
||||
if (console)
|
||||
return console.log("PASS");
|
||||
else {
|
||||
let a = 0;
|
||||
}
|
||||
}() ]));
|
||||
}
|
||||
expect: {
|
||||
while ([ [ console ? console.log("PASS") : 0 ] ], void 0);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
@@ -1233,8 +1233,11 @@ issue_2105_2: {
|
||||
issue_2105_3: {
|
||||
options = {
|
||||
inline: true,
|
||||
passes: 2,
|
||||
join_vars: true,
|
||||
passes: 3,
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
sequences: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
@@ -1258,12 +1261,12 @@ issue_2105_3: {
|
||||
});
|
||||
}
|
||||
expect: {
|
||||
!void void {
|
||||
({
|
||||
prop: function() {
|
||||
console.log;
|
||||
void console.log("PASS");
|
||||
}
|
||||
}.prop();
|
||||
console.log,
|
||||
console.log("PASS");
|
||||
},
|
||||
}).prop();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
@@ -1728,7 +1731,8 @@ issue_2768: {
|
||||
}
|
||||
expect: {
|
||||
var a = "FAIL";
|
||||
var c = (d = a, void (d && (a = "PASS")));
|
||||
d = a;
|
||||
var c = void (d && (a = "PASS"));
|
||||
var d;
|
||||
console.log(a, typeof c);
|
||||
}
|
||||
@@ -1765,7 +1769,7 @@ issue_2846: {
|
||||
issue_805_1: {
|
||||
options = {
|
||||
inline: true,
|
||||
passes: 2,
|
||||
passes: 3,
|
||||
pure_getters: "strict",
|
||||
reduce_vars: true,
|
||||
sequences: true,
|
||||
@@ -1798,7 +1802,7 @@ issue_805_1: {
|
||||
issue_805_2: {
|
||||
options = {
|
||||
inline: true,
|
||||
passes: 2,
|
||||
passes: 3,
|
||||
pure_getters: "strict",
|
||||
reduce_vars: true,
|
||||
sequences: true,
|
||||
@@ -2382,7 +2386,8 @@ issue_3664: {
|
||||
}
|
||||
expect: {
|
||||
console.log(function() {
|
||||
var a, b = (a = (a = [ b && console.log("FAIL") ]).p = 0, 0);
|
||||
a = (a = [ b && console.log("FAIL") ]).p = 0;
|
||||
var a, b = 0;
|
||||
return "PASS";
|
||||
}());
|
||||
}
|
||||
@@ -2551,10 +2556,9 @@ issue_3899: {
|
||||
console.log(typeof a);
|
||||
}
|
||||
expect: {
|
||||
function a() {
|
||||
console.log(typeof function() {
|
||||
return 2;
|
||||
}
|
||||
console.log(typeof a);
|
||||
});
|
||||
}
|
||||
expect_stdout: "function"
|
||||
}
|
||||
@@ -3516,3 +3520,73 @@ issue_5079: {
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5224: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
keep_fargs: false,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
try {
|
||||
var b = function() {
|
||||
var a = "FAIL 1";
|
||||
null && a;
|
||||
a = console.log(a);
|
||||
}(new function(c, d) {
|
||||
console.log(d);
|
||||
a;
|
||||
}("FAIL 2", Infinity));
|
||||
} finally {
|
||||
return f;
|
||||
}
|
||||
}
|
||||
f();
|
||||
}
|
||||
expect: {
|
||||
(function f() {
|
||||
try {
|
||||
(function() {
|
||||
var a = "FAIL 1";
|
||||
null;
|
||||
a = console.log(a);
|
||||
})(function() {
|
||||
console.log(1 / 0);
|
||||
a;
|
||||
}());
|
||||
} finally {
|
||||
return f;
|
||||
}
|
||||
})();
|
||||
}
|
||||
expect_stdout: "Infinity"
|
||||
}
|
||||
|
||||
issue_5271: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
function f() {
|
||||
do {
|
||||
var a = b = 0 ^ f, b = b;
|
||||
} while (console.log(42 - b));
|
||||
}
|
||||
f();
|
||||
}
|
||||
expect: {
|
||||
(function f() {
|
||||
do {
|
||||
var b;
|
||||
b = 0 ^ f;
|
||||
} while (console.log(42 - b));
|
||||
})();
|
||||
}
|
||||
expect_stdout: "42"
|
||||
}
|
||||
|
||||
@@ -2752,8 +2752,7 @@ issue_3944: {
|
||||
}
|
||||
expect: {
|
||||
void function f() {
|
||||
while (a = 0 == (a = void 0), console.log(a), void 0);
|
||||
var a;
|
||||
while (0 == void 0, console.log(false), void 0);
|
||||
f;
|
||||
}();
|
||||
}
|
||||
@@ -3203,7 +3202,7 @@ issue_4552: {
|
||||
expect_stdout: "NaN"
|
||||
}
|
||||
|
||||
issue_4886: {
|
||||
issue_4886_1: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
unsafe: true,
|
||||
@@ -3222,3 +3221,23 @@ issue_4886: {
|
||||
}
|
||||
expect_stdout: "true"
|
||||
}
|
||||
|
||||
issue_4886_2: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
unsafe: true,
|
||||
}
|
||||
input: {
|
||||
console.log("foo" in {
|
||||
"foo": null,
|
||||
__proto__: 42,
|
||||
});
|
||||
}
|
||||
expect: {
|
||||
console.log("foo" in {
|
||||
"foo": null,
|
||||
__proto__: 42,
|
||||
});
|
||||
}
|
||||
expect_stdout: "true"
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ assignment_2: {
|
||||
}
|
||||
expect_exact: "var a=8n;a**=a;console.log(a);"
|
||||
expect_stdout: "16777216n"
|
||||
node_version: ">=10"
|
||||
node_version: ">=10.4.0"
|
||||
}
|
||||
|
||||
evaluate: {
|
||||
@@ -99,8 +99,8 @@ issue_4664: {
|
||||
expect: {
|
||||
(function f() {
|
||||
new function(a) {
|
||||
console.log(typeof f, a, typeof this);
|
||||
}((A = 0, 2 ** 30));
|
||||
console.log(typeof f, 2 ** 30, typeof this);
|
||||
}(A = 0);
|
||||
})();
|
||||
}
|
||||
expect_stdout: "function 1073741824 object"
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1163,13 +1163,13 @@ issue_5182: {
|
||||
log(o.p(42));
|
||||
}
|
||||
expect: {
|
||||
var o_p = console;
|
||||
log = o_p.log;
|
||||
o_p = function(a) {
|
||||
var o = console;
|
||||
log = o.log;
|
||||
o = function(a) {
|
||||
console.log(a ? "PASS" : "FAIL");
|
||||
return a;
|
||||
};
|
||||
log(o_p(42));
|
||||
log(o(42));
|
||||
}
|
||||
expect_stdout: [
|
||||
"PASS",
|
||||
|
||||
@@ -282,7 +282,7 @@ issue_4736: {
|
||||
(function() {
|
||||
(function() {
|
||||
0,
|
||||
console.log(1073741824);
|
||||
console.log(1 << 30);
|
||||
})();
|
||||
})();
|
||||
}
|
||||
@@ -336,7 +336,7 @@ issue_4859: {
|
||||
}
|
||||
expect: {
|
||||
(function f(a) {
|
||||
console.log(Infinity);
|
||||
console.log(2 + 1 / 0);
|
||||
return f;
|
||||
})();
|
||||
}
|
||||
|
||||
@@ -3109,9 +3109,9 @@ issue_5081_call: {
|
||||
}));
|
||||
}
|
||||
expect: {
|
||||
function f(b) {
|
||||
function f(a) {
|
||||
// IE5-10: TypeError: Function expected
|
||||
return b(b = "A") + (b += "SS");
|
||||
return a(a = "A") + (a += "SS");
|
||||
}
|
||||
console.log(f(function() {
|
||||
return "P";
|
||||
@@ -3161,8 +3161,8 @@ issue_5081_property_access: {
|
||||
console.log(f({ A: "P" }));
|
||||
}
|
||||
expect: {
|
||||
function f(b) {
|
||||
return b[b = "A"] + (b += "SS");
|
||||
function f(a) {
|
||||
return a[a = "A"] + (a += "SS");
|
||||
}
|
||||
// IE9-11: undefinedASS
|
||||
console.log(f({ A: "P" }));
|
||||
@@ -3192,3 +3192,219 @@ issue_5081_property_access_ie: {
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5269_1: {
|
||||
options = {
|
||||
ie: false,
|
||||
inline: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
do {
|
||||
(function() {
|
||||
try {
|
||||
throw "PASS";
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
})();
|
||||
} while (!console);
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
do {
|
||||
try {
|
||||
throw "PASS";
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
} while (!console);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5269_1_ie: {
|
||||
options = {
|
||||
ie: true,
|
||||
inline: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
do {
|
||||
(function() {
|
||||
try {
|
||||
throw "PASS";
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
})();
|
||||
} while (!console);
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
do {
|
||||
try {
|
||||
throw "PASS";
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
} while (!console);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_5269_2: {
|
||||
options = {
|
||||
ie: false,
|
||||
inline: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
for (var i = 0; i < 2; i++)
|
||||
(function() {
|
||||
console.log(e);
|
||||
try {
|
||||
console;
|
||||
} catch (e) {
|
||||
var e = "FAIL 1";
|
||||
}
|
||||
e = "FAIL 2";
|
||||
console;
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
for (var i = 0; i < 2; i++) {
|
||||
e = void 0;
|
||||
console.log(e);
|
||||
try {
|
||||
console;
|
||||
} catch (e) {
|
||||
var e = "FAIL 1";
|
||||
}
|
||||
e = "FAIL 2";
|
||||
console;
|
||||
}
|
||||
}
|
||||
expect_stdout: [
|
||||
"undefined",
|
||||
"undefined",
|
||||
]
|
||||
}
|
||||
|
||||
issue_5269_2_ie: {
|
||||
options = {
|
||||
ie: true,
|
||||
inline: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
for (var i = 0; i < 2; i++)
|
||||
(function() {
|
||||
console.log(e);
|
||||
try {
|
||||
console;
|
||||
} catch (e) {
|
||||
var e = "FAIL 1";
|
||||
}
|
||||
e = "FAIL 2";
|
||||
console;
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
for (var i = 0; i < 2; i++) {
|
||||
e = void 0;
|
||||
console.log(e);
|
||||
try {
|
||||
console;
|
||||
} catch (e) {
|
||||
var e = "FAIL 1";
|
||||
}
|
||||
e = "FAIL 2";
|
||||
console;
|
||||
}
|
||||
}
|
||||
expect_stdout: [
|
||||
"undefined",
|
||||
"undefined",
|
||||
]
|
||||
}
|
||||
|
||||
issue_5269_3: {
|
||||
options = {
|
||||
ie: false,
|
||||
inline: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
e = "foo";
|
||||
for (var i = 0; i < 2; i++)
|
||||
(function() {
|
||||
console.log(e);
|
||||
try {
|
||||
console;
|
||||
} catch (e) {
|
||||
e = "FAIL";
|
||||
}
|
||||
e = "bar";
|
||||
console;
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
e = "foo";
|
||||
for (var i = 0; i < 2; i++) {
|
||||
console.log(e);
|
||||
try {
|
||||
console;
|
||||
} catch (e) {
|
||||
e = "FAIL";
|
||||
}
|
||||
e = "bar";
|
||||
console;
|
||||
}
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
]
|
||||
}
|
||||
|
||||
issue_5269_3_ie: {
|
||||
options = {
|
||||
ie: true,
|
||||
inline: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
e = "foo";
|
||||
for (var i = 0; i < 2; i++)
|
||||
(function() {
|
||||
console.log(e);
|
||||
try {
|
||||
console;
|
||||
} catch (e) {
|
||||
e = "FAIL";
|
||||
}
|
||||
e = "bar";
|
||||
console;
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
e = "foo";
|
||||
for (var i = 0; i < 2; i++) {
|
||||
console.log(e);
|
||||
try {
|
||||
console;
|
||||
} catch (e) {
|
||||
e = "FAIL";
|
||||
}
|
||||
e = "bar";
|
||||
console;
|
||||
}
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -545,7 +545,36 @@ if_body_return_3: {
|
||||
]
|
||||
}
|
||||
|
||||
issue_3600: {
|
||||
issue_3600_1: {
|
||||
options = {
|
||||
if_return: true,
|
||||
inline: 3,
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var c = 0;
|
||||
(function() {
|
||||
if ([ ][c++]); else return;
|
||||
return void function() {
|
||||
var b = --b, a = c = 42;
|
||||
return c;
|
||||
}();
|
||||
})();
|
||||
console.log(c);
|
||||
}
|
||||
expect: {
|
||||
var c = 0;
|
||||
(function() {
|
||||
if ([][c++]) b = --b, c = 42;
|
||||
var b;
|
||||
})();
|
||||
console.log(c);
|
||||
}
|
||||
expect_stdout: "1"
|
||||
}
|
||||
|
||||
issue_3600_2: {
|
||||
options = {
|
||||
if_return: true,
|
||||
inline: true,
|
||||
@@ -566,7 +595,9 @@ issue_3600: {
|
||||
expect: {
|
||||
var c = 0;
|
||||
(function() {
|
||||
if ([][c++]) b = --b, c = 42;
|
||||
if ([][c++])
|
||||
b = --b,
|
||||
c = 42;
|
||||
var b;
|
||||
})();
|
||||
console.log(c);
|
||||
|
||||
@@ -106,6 +106,22 @@ drop_unused: {
|
||||
}
|
||||
}
|
||||
|
||||
drop_side_effect_free: {
|
||||
options = {
|
||||
imports: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
import foo from "bar";
|
||||
var a = foo;
|
||||
}
|
||||
expect: {
|
||||
import "bar";
|
||||
}
|
||||
}
|
||||
|
||||
mangle: {
|
||||
rename = false
|
||||
mangle = {
|
||||
|
||||
@@ -356,6 +356,7 @@ mangle_catch_redef_3: {
|
||||
try {
|
||||
throw 0;
|
||||
} catch (o) {
|
||||
// prints "FAIL" if inlined on Node.js v4-
|
||||
(function() {
|
||||
function f() {
|
||||
o = "FAIL";
|
||||
@@ -366,7 +367,8 @@ mangle_catch_redef_3: {
|
||||
console.log(o);
|
||||
}
|
||||
expect_exact: 'var o="PASS";try{throw 0}catch(o){(function(){function c(){o="FAIL"}c(),c()})()}console.log(o);'
|
||||
expect_stdout: true
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
mangle_catch_redef_3_toplevel: {
|
||||
@@ -379,6 +381,7 @@ mangle_catch_redef_3_toplevel: {
|
||||
try {
|
||||
throw 0;
|
||||
} catch (o) {
|
||||
// prints "FAIL" if inlined on Node.js v4-
|
||||
(function() {
|
||||
function f() {
|
||||
o = "FAIL";
|
||||
@@ -389,7 +392,8 @@ mangle_catch_redef_3_toplevel: {
|
||||
console.log(o);
|
||||
}
|
||||
expect_exact: 'var c="PASS";try{throw 0}catch(c){(function(){function o(){c="FAIL"}o(),o()})()}console.log(c);'
|
||||
expect_stdout: true
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
mangle_catch_redef_3_ie8: {
|
||||
@@ -402,6 +406,7 @@ mangle_catch_redef_3_ie8: {
|
||||
try {
|
||||
throw 0;
|
||||
} catch (o) {
|
||||
// prints "FAIL" if inlined on Node.js v4-
|
||||
(function() {
|
||||
function f() {
|
||||
o = "FAIL";
|
||||
@@ -412,7 +417,8 @@ mangle_catch_redef_3_ie8: {
|
||||
console.log(o);
|
||||
}
|
||||
expect_exact: 'var o="PASS";try{throw 0}catch(o){(function(){function c(){o="FAIL"}c(),c()})()}console.log(o);'
|
||||
expect_stdout: true
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
mangle_catch_redef_3_ie8_toplevel: {
|
||||
@@ -425,6 +431,7 @@ mangle_catch_redef_3_ie8_toplevel: {
|
||||
try {
|
||||
throw 0;
|
||||
} catch (o) {
|
||||
// prints "FAIL" if inlined on Node.js v4-
|
||||
(function() {
|
||||
function f() {
|
||||
o = "FAIL";
|
||||
@@ -435,5 +442,6 @@ mangle_catch_redef_3_ie8_toplevel: {
|
||||
console.log(o);
|
||||
}
|
||||
expect_exact: 'var c="PASS";try{throw 0}catch(c){(function(){function o(){c="FAIL"}o(),o()})()}console.log(c);'
|
||||
expect_stdout: true
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
dont_mangle_arguments: {
|
||||
mangle = {
|
||||
};
|
||||
options = {
|
||||
booleans: true,
|
||||
comparisons: true,
|
||||
@@ -21,12 +19,13 @@ dont_mangle_arguments: {
|
||||
side_effects: true,
|
||||
unused: true,
|
||||
}
|
||||
mangle = {}
|
||||
input: {
|
||||
(function(){
|
||||
var arguments = arguments, not_arguments = 9;
|
||||
console.log(not_arguments, arguments);
|
||||
})(5,6,7);
|
||||
})(5, 6, 7);
|
||||
}
|
||||
expect_exact: "(function(){var arguments=arguments,o=9;console.log(o,arguments)})(5,6,7);"
|
||||
expect_exact: "(function(){var arguments,o=9;console.log(o,arguments)})(5,6,7);"
|
||||
expect_stdout: true
|
||||
}
|
||||
|
||||
@@ -570,6 +570,50 @@ inlined_assignments: {
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
inilne_for: {
|
||||
options = {
|
||||
inline: true,
|
||||
join_vars: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var a = function() {
|
||||
for (; console.log("PASS"););
|
||||
};
|
||||
a();
|
||||
}
|
||||
expect: {
|
||||
for (; console.log("PASS"););
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
inilne_var: {
|
||||
options = {
|
||||
inline: true,
|
||||
join_vars: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
A = "PASS";
|
||||
var a = function() {
|
||||
var b = A;
|
||||
for (b in console.log(b));
|
||||
};
|
||||
a();
|
||||
}
|
||||
expect: {
|
||||
A = "PASS";
|
||||
var b = A;
|
||||
for (b in console.log(b));
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
typescript_enum: {
|
||||
rename = true
|
||||
options = {
|
||||
@@ -1282,10 +1326,7 @@ assign_sequence_var: {
|
||||
console.log(a, b, c);
|
||||
}
|
||||
expect: {
|
||||
var a = 0, b = 1;
|
||||
console.log(a),
|
||||
a++;
|
||||
var b = 2, c = 3;
|
||||
var a = 0, b = 1, c = (console.log(a), a++, b = 2, 3);
|
||||
console.log(a, b, c);
|
||||
}
|
||||
expect_stdout: [
|
||||
|
||||
@@ -181,10 +181,10 @@ issue_2203_2: {
|
||||
a: "FAIL",
|
||||
b: function() {
|
||||
return function() {
|
||||
return (String, (Object, function() {
|
||||
return (Object, function() {
|
||||
return this;
|
||||
}())).a;
|
||||
}();
|
||||
}()).a;
|
||||
}(String);
|
||||
}
|
||||
}.b());
|
||||
}
|
||||
@@ -925,6 +925,28 @@ duplicate_lambda_defun_name_2: {
|
||||
expect_stdout: "0"
|
||||
}
|
||||
|
||||
function_argument_mangle: {
|
||||
mangle = {
|
||||
keep_fargs: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
A = "PASS";
|
||||
var a = A;
|
||||
(function(o) {
|
||||
console.log(a);
|
||||
})("FAIL");
|
||||
}
|
||||
expect: {
|
||||
A = "PASS";
|
||||
var n = A;
|
||||
(function(o) {
|
||||
console.log(n);
|
||||
})("FAIL");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
function_name_mangle: {
|
||||
options = {
|
||||
keep_fargs: false,
|
||||
@@ -1217,6 +1239,7 @@ issues_3267_1: {
|
||||
evaluate: true,
|
||||
inline: true,
|
||||
keep_fargs: false,
|
||||
negate_iife: true,
|
||||
reduce_vars: true,
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
@@ -1235,7 +1258,8 @@ issues_3267_1: {
|
||||
}
|
||||
expect: {
|
||||
!function() {
|
||||
if (Object())
|
||||
var i = Object();
|
||||
if (i)
|
||||
return console.log("PASS");
|
||||
throw "FAIL";
|
||||
}();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
retain_block: {
|
||||
retain_block_1: {
|
||||
options = {}
|
||||
input: {
|
||||
"use strict";
|
||||
@@ -20,6 +20,94 @@ retain_block: {
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
retain_block_2: {
|
||||
options = {
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
{
|
||||
var a;
|
||||
let a;
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
{
|
||||
var a;
|
||||
let a;
|
||||
}
|
||||
}
|
||||
expect_stdout: true
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
retain_block_2_mangle: {
|
||||
rename = true
|
||||
mangle = {
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
{
|
||||
var a;
|
||||
let a;
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
{
|
||||
var t;
|
||||
let t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
retain_block_3: {
|
||||
options = {
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
{
|
||||
let a;
|
||||
var a;
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
{
|
||||
let a;
|
||||
var a;
|
||||
}
|
||||
}
|
||||
expect_stdout: true
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
retain_block_3_mangle: {
|
||||
rename = true
|
||||
mangle = {
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
{
|
||||
let a;
|
||||
var a;
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
{
|
||||
let t;
|
||||
var t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
retain_assignment: {
|
||||
options = {
|
||||
dead_code: true,
|
||||
@@ -182,8 +270,8 @@ merge_vars_3: {
|
||||
var b = console;
|
||||
console.log(typeof b);
|
||||
}
|
||||
var a = 1;
|
||||
console.log(typeof a);
|
||||
var b = 1;
|
||||
console.log(typeof b);
|
||||
}
|
||||
expect_stdout: [
|
||||
"object",
|
||||
@@ -192,6 +280,38 @@ merge_vars_3: {
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
merge_vars_4: {
|
||||
options = {
|
||||
merge_vars: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
var a = 1;
|
||||
console.log(typeof a);
|
||||
{
|
||||
var b = console;
|
||||
console.log(typeof b);
|
||||
let a = 0;
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
var a = 1;
|
||||
console.log(typeof a);
|
||||
{
|
||||
var b = console;
|
||||
console.log(typeof b);
|
||||
let a = 0;
|
||||
}
|
||||
}
|
||||
expect_stdout: [
|
||||
"number",
|
||||
"object",
|
||||
]
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
use_before_init_1: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
@@ -966,12 +1086,10 @@ issue_4202: {
|
||||
"use strict";
|
||||
{
|
||||
let o = {};
|
||||
(function() {
|
||||
function f() {
|
||||
o.p = 42;
|
||||
}
|
||||
f(f);
|
||||
})();
|
||||
function f() {
|
||||
o.p = 42;
|
||||
}
|
||||
f(f);
|
||||
console.log(o.p++);
|
||||
}
|
||||
}
|
||||
@@ -1553,7 +1671,7 @@ issue_4438: {
|
||||
;
|
||||
else {
|
||||
let a = console.log;
|
||||
a("PASS");
|
||||
void a("PASS");
|
||||
}
|
||||
}
|
||||
f();
|
||||
@@ -1747,3 +1865,111 @@ issue_4985: {
|
||||
expect_stdout: "undefined"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5240: {
|
||||
options = {
|
||||
inline: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
function f() {
|
||||
if (console) {
|
||||
let g = function() {
|
||||
e;
|
||||
}, e;
|
||||
(function() {
|
||||
if (console) {
|
||||
console.log(e);
|
||||
var e = "FAIL";
|
||||
}
|
||||
})(console.log(e));
|
||||
}
|
||||
}
|
||||
f();
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
function f() {
|
||||
if (console) {
|
||||
let g = function() {
|
||||
e;
|
||||
}, e;
|
||||
(function() {
|
||||
if (console) {
|
||||
console.log(e);
|
||||
var e = "FAIL";
|
||||
}
|
||||
})(console.log(e));
|
||||
}
|
||||
}
|
||||
f();
|
||||
}
|
||||
expect_stdout: [
|
||||
"undefined",
|
||||
"undefined",
|
||||
]
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5254: {
|
||||
options = {
|
||||
inline: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
do {
|
||||
(function() {
|
||||
let a = console.log;
|
||||
a && a("foo");
|
||||
})();
|
||||
} while (console.log("bar"));
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
do {
|
||||
let a = console.log;
|
||||
a && a("foo");
|
||||
} while (console.log("bar"));
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
]
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5260: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
var a = "foo", o;
|
||||
while (console.log("bar"));
|
||||
o = {
|
||||
baz: function(b) {
|
||||
console.log(a, b);
|
||||
},
|
||||
};
|
||||
for (let a in o)
|
||||
o[a](a);
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
var a = "foo", o;
|
||||
while (console.log("bar"));
|
||||
o = {
|
||||
baz: function(b) {
|
||||
console.log(a, b);
|
||||
},
|
||||
};
|
||||
for (let a in o)
|
||||
o[a](a);
|
||||
}
|
||||
expect_stdout: [
|
||||
"bar",
|
||||
"foo baz",
|
||||
]
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
@@ -19,11 +19,11 @@ merge: {
|
||||
expect: {
|
||||
var a = "foo";
|
||||
console.log(a);
|
||||
function f(c) {
|
||||
var c;
|
||||
console.log(c);
|
||||
c = "bar";
|
||||
console.log(c);
|
||||
function f(b) {
|
||||
var b;
|
||||
console.log(b);
|
||||
b = "bar";
|
||||
console.log(b);
|
||||
}
|
||||
f("baz");
|
||||
var d = "moo";
|
||||
@@ -56,17 +56,17 @@ merge_toplevel: {
|
||||
console.log(d);
|
||||
}
|
||||
expect: {
|
||||
var d = "foo";
|
||||
console.log(d);
|
||||
function f(c) {
|
||||
var c;
|
||||
console.log(c);
|
||||
c = "bar";
|
||||
console.log(c);
|
||||
var a = "foo";
|
||||
console.log(a);
|
||||
function f(b) {
|
||||
var b;
|
||||
console.log(b);
|
||||
b = "bar";
|
||||
console.log(b);
|
||||
}
|
||||
f("baz");
|
||||
var d = "moo";
|
||||
console.log(d);
|
||||
var a = "moo";
|
||||
console.log(a);
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
@@ -94,16 +94,16 @@ segment: {
|
||||
console.log(d);
|
||||
}
|
||||
expect: {
|
||||
var d = "foo";
|
||||
console.log(d);
|
||||
for (var c, i = 0; i < 1; i++) {
|
||||
var c = "bar";
|
||||
console.log(c);
|
||||
c = "baz";
|
||||
console.log(c);
|
||||
var a = "foo";
|
||||
console.log(a);
|
||||
for (var b, i = 0; i < 1; i++) {
|
||||
var b = "bar";
|
||||
console.log(b);
|
||||
b = "baz";
|
||||
console.log(b);
|
||||
}
|
||||
var d = "moo";
|
||||
console.log(d);
|
||||
var a = "moo";
|
||||
console.log(a);
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
@@ -298,6 +298,89 @@ read_before_assign_2: {
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
collapse_vars_1: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
merge_vars: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
var a = a && a.p;
|
||||
var b = "PASS";
|
||||
var b = b && console.log(b);
|
||||
}
|
||||
expect: {
|
||||
var a = a && a.p;
|
||||
var a;
|
||||
var a = (a = "PASS") && console.log(a);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
collapse_vars_2: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
merge_vars: true,
|
||||
}
|
||||
input: {
|
||||
"use strict";
|
||||
var log = console.log;
|
||||
(function g(a) {
|
||||
var b = a;
|
||||
var c = Math.random();
|
||||
var c = b;
|
||||
log(c);
|
||||
return c;
|
||||
})("PASS");
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
var log = console.log;
|
||||
(function g(a) {
|
||||
var a = a;
|
||||
var c = Math.random();
|
||||
var c;
|
||||
log(c = a);
|
||||
return c;
|
||||
})("PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
not_redefined: {
|
||||
options = {
|
||||
inline: true,
|
||||
join_vars: true,
|
||||
merge_vars: true,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
varify: true,
|
||||
}
|
||||
input: {
|
||||
var log = console.log;
|
||||
(function() {
|
||||
return f("PASS");
|
||||
function f(a) {
|
||||
const b = a;
|
||||
const c = log(b);
|
||||
const d = log;
|
||||
c && log(d);
|
||||
}
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
var log = console.log;
|
||||
(function() {
|
||||
return a = "PASS",
|
||||
a = log(a),
|
||||
d = log,
|
||||
void (a && log(d));
|
||||
var a, d;
|
||||
})();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_4103: {
|
||||
options = {
|
||||
merge_vars: true,
|
||||
@@ -325,7 +408,7 @@ issue_4103: {
|
||||
]
|
||||
}
|
||||
|
||||
issue_4107: {
|
||||
issue_4107_1: {
|
||||
options = {
|
||||
keep_fargs: false,
|
||||
merge_vars: true,
|
||||
@@ -342,6 +425,38 @@ issue_4107: {
|
||||
})();
|
||||
console.log(typeof a);
|
||||
}
|
||||
expect: {
|
||||
(function() {
|
||||
(function(c) {
|
||||
c = console || c;
|
||||
console.log(typeof c);
|
||||
})();
|
||||
})();
|
||||
console.log(typeof a);
|
||||
}
|
||||
expect_stdout: [
|
||||
"object",
|
||||
"undefined",
|
||||
]
|
||||
}
|
||||
|
||||
issue_4107_2: {
|
||||
options = {
|
||||
keep_fargs: false,
|
||||
merge_vars: true,
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function() {
|
||||
function f(b, b, a) {
|
||||
var d = 1 && c, c = console || a;
|
||||
console.log(typeof c);
|
||||
}
|
||||
f();
|
||||
})();
|
||||
console.log(typeof a);
|
||||
}
|
||||
expect: {
|
||||
(function() {
|
||||
(function(a) {
|
||||
@@ -538,12 +653,12 @@ cross_branch_1_1: {
|
||||
expect: {
|
||||
var a;
|
||||
function f() {
|
||||
var y, y;
|
||||
var x, x;
|
||||
if (a)
|
||||
y = "foo";
|
||||
console.log(y);
|
||||
y = "bar";
|
||||
console.log(y);
|
||||
x = "foo";
|
||||
console.log(x);
|
||||
x = "bar";
|
||||
console.log(x);
|
||||
}
|
||||
a = 0;
|
||||
f();
|
||||
@@ -581,13 +696,13 @@ cross_branch_1_2: {
|
||||
expect: {
|
||||
var a;
|
||||
function f() {
|
||||
var y, y;
|
||||
var x, x;
|
||||
if (a) {
|
||||
y = "foo";
|
||||
console.log(y);
|
||||
x = "foo";
|
||||
console.log(x);
|
||||
}
|
||||
y = "bar";
|
||||
console.log(y);
|
||||
x = "bar";
|
||||
console.log(x);
|
||||
}
|
||||
a = 0;
|
||||
f();
|
||||
@@ -624,13 +739,13 @@ cross_branch_1_3: {
|
||||
expect: {
|
||||
var a;
|
||||
function f() {
|
||||
var y, y;
|
||||
var x, x;
|
||||
if (a) {
|
||||
y = "foo";
|
||||
console.log(y);
|
||||
y = "bar";
|
||||
x = "foo";
|
||||
console.log(x);
|
||||
x = "bar";
|
||||
}
|
||||
console.log(y);
|
||||
console.log(x);
|
||||
}
|
||||
a = 0;
|
||||
f();
|
||||
@@ -666,12 +781,12 @@ cross_branch_1_4: {
|
||||
expect: {
|
||||
var a;
|
||||
function f() {
|
||||
var y, y;
|
||||
y = "foo";
|
||||
var x, x;
|
||||
x = "foo";
|
||||
if (a)
|
||||
console.log(y);
|
||||
y = "bar";
|
||||
console.log(y);
|
||||
console.log(x);
|
||||
x = "bar";
|
||||
console.log(x);
|
||||
}
|
||||
a = 0;
|
||||
f();
|
||||
@@ -751,12 +866,12 @@ cross_branch_1_6: {
|
||||
expect: {
|
||||
var a;
|
||||
function f() {
|
||||
var y, y;
|
||||
y = "foo";
|
||||
var x, x;
|
||||
x = "foo";
|
||||
if (a) {
|
||||
console.log(y);
|
||||
y = "bar";
|
||||
console.log(y);
|
||||
console.log(x);
|
||||
x = "bar";
|
||||
console.log(x);
|
||||
}
|
||||
}
|
||||
a = 0;
|
||||
@@ -835,12 +950,12 @@ cross_branch_1_8: {
|
||||
expect: {
|
||||
var a;
|
||||
function f() {
|
||||
var y, y;
|
||||
y = "foo";
|
||||
console.log(y);
|
||||
var x, x;
|
||||
x = "foo";
|
||||
console.log(x);
|
||||
if (a) {
|
||||
y = "bar";
|
||||
console.log(y);
|
||||
x = "bar";
|
||||
console.log(x);
|
||||
}
|
||||
}
|
||||
a = 0;
|
||||
@@ -877,12 +992,12 @@ cross_branch_1_9: {
|
||||
expect: {
|
||||
var a;
|
||||
function f() {
|
||||
var y, y;
|
||||
y = "foo";
|
||||
console.log(y);
|
||||
y = "bar";
|
||||
var x, x;
|
||||
x = "foo";
|
||||
console.log(x);
|
||||
x = "bar";
|
||||
if (a)
|
||||
console.log(y);
|
||||
console.log(x);
|
||||
}
|
||||
a = 0;
|
||||
f();
|
||||
@@ -924,14 +1039,14 @@ cross_branch_2a_1: {
|
||||
expect: {
|
||||
var a, b;
|
||||
function f() {
|
||||
var y, y;
|
||||
var x, x;
|
||||
if (a) {
|
||||
if (b)
|
||||
y = "foo";
|
||||
console.log(y);
|
||||
x = "foo";
|
||||
console.log(x);
|
||||
}
|
||||
y = "bar";
|
||||
console.log(y);
|
||||
x = "bar";
|
||||
console.log(x);
|
||||
}
|
||||
a = 0, b = 0;
|
||||
f();
|
||||
@@ -980,14 +1095,14 @@ cross_branch_2a_2: {
|
||||
expect: {
|
||||
var a, b;
|
||||
function f() {
|
||||
var y, y;
|
||||
var x, x;
|
||||
if (a) {
|
||||
y = "foo";
|
||||
x = "foo";
|
||||
if (b)
|
||||
console.log(y);
|
||||
console.log(x);
|
||||
}
|
||||
y = "bar";
|
||||
console.log(y);
|
||||
x = "bar";
|
||||
console.log(x);
|
||||
}
|
||||
a = 0, b = 0;
|
||||
f();
|
||||
@@ -1035,14 +1150,14 @@ cross_branch_2a_3: {
|
||||
expect: {
|
||||
var a, b;
|
||||
function f() {
|
||||
var y, y;
|
||||
var x, x;
|
||||
if (a) {
|
||||
if (b)
|
||||
y = "foo";
|
||||
console.log(y);
|
||||
y = "bar";
|
||||
x = "foo";
|
||||
console.log(x);
|
||||
x = "bar";
|
||||
}
|
||||
console.log(y);
|
||||
console.log(x);
|
||||
}
|
||||
a = 0, b = 0;
|
||||
f();
|
||||
@@ -1092,15 +1207,15 @@ cross_branch_2a_4: {
|
||||
expect: {
|
||||
var a, b;
|
||||
function f() {
|
||||
var y, y;
|
||||
var x, x;
|
||||
if (a) {
|
||||
if (b) {
|
||||
y = "foo";
|
||||
console.log(y);
|
||||
x = "foo";
|
||||
console.log(x);
|
||||
}
|
||||
y = "bar";
|
||||
x = "bar";
|
||||
}
|
||||
console.log(y);
|
||||
console.log(x);
|
||||
}
|
||||
a = 0, b = 0;
|
||||
f();
|
||||
@@ -1148,14 +1263,14 @@ cross_branch_2a_5: {
|
||||
expect: {
|
||||
var a, b;
|
||||
function f() {
|
||||
var y, y;
|
||||
var x, x;
|
||||
if (a) {
|
||||
y = "foo";
|
||||
x = "foo";
|
||||
if (b)
|
||||
console.log(y);
|
||||
y = "bar";
|
||||
console.log(x);
|
||||
x = "bar";
|
||||
}
|
||||
console.log(y);
|
||||
console.log(x);
|
||||
}
|
||||
a = 0, b = 0;
|
||||
f();
|
||||
@@ -1427,13 +1542,13 @@ cross_branch_2a_10: {
|
||||
expect: {
|
||||
var a, b;
|
||||
function f() {
|
||||
var y, y;
|
||||
y = "foo";
|
||||
var x, x;
|
||||
x = "foo";
|
||||
if (a) {
|
||||
if (b)
|
||||
console.log(y);
|
||||
y = "bar";
|
||||
console.log(y);
|
||||
console.log(x);
|
||||
x = "bar";
|
||||
console.log(x);
|
||||
}
|
||||
}
|
||||
a = 0, b = 0;
|
||||
@@ -1590,13 +1705,13 @@ cross_branch_2a_13: {
|
||||
expect: {
|
||||
var a, b;
|
||||
function f() {
|
||||
var y, y;
|
||||
y = "foo";
|
||||
var x, x;
|
||||
x = "foo";
|
||||
if (a) {
|
||||
console.log(y);
|
||||
console.log(x);
|
||||
if (b) {
|
||||
y = "bar";
|
||||
console.log(y);
|
||||
x = "bar";
|
||||
console.log(x);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1644,13 +1759,13 @@ cross_branch_2a_14: {
|
||||
expect: {
|
||||
var a, b;
|
||||
function f() {
|
||||
var y, y;
|
||||
y = "foo";
|
||||
var x, x;
|
||||
x = "foo";
|
||||
if (a) {
|
||||
console.log(y);
|
||||
y = "bar";
|
||||
console.log(x);
|
||||
x = "bar";
|
||||
if (b)
|
||||
console.log(y);
|
||||
console.log(x);
|
||||
}
|
||||
}
|
||||
a = 0, b = 0;
|
||||
@@ -1753,13 +1868,13 @@ cross_branch_2a_16: {
|
||||
expect: {
|
||||
var a, b;
|
||||
function f() {
|
||||
var y, y;
|
||||
y = "foo";
|
||||
console.log(y);
|
||||
var x, x;
|
||||
x = "foo";
|
||||
console.log(x);
|
||||
if (a) {
|
||||
y = "bar";
|
||||
x = "bar";
|
||||
if (b)
|
||||
console.log(y);
|
||||
console.log(x);
|
||||
}
|
||||
}
|
||||
a = 0, b = 0;
|
||||
@@ -1807,13 +1922,13 @@ cross_branch_2b_1: {
|
||||
expect: {
|
||||
var a, b;
|
||||
function f() {
|
||||
var y, y;
|
||||
var x, x;
|
||||
if (a)
|
||||
y = "foo";
|
||||
x = "foo";
|
||||
if (b)
|
||||
console.log(y);
|
||||
y = "bar";
|
||||
console.log(y);
|
||||
console.log(x);
|
||||
x = "bar";
|
||||
console.log(x);
|
||||
}
|
||||
a = 0, b = 0;
|
||||
f();
|
||||
@@ -1918,13 +2033,13 @@ cross_branch_2b_3: {
|
||||
expect: {
|
||||
var a, b;
|
||||
function f() {
|
||||
var y, y;
|
||||
var x, x;
|
||||
if (a)
|
||||
y = "foo";
|
||||
x = "foo";
|
||||
if (b) {
|
||||
console.log(y);
|
||||
y = "bar";
|
||||
console.log(y);
|
||||
console.log(x);
|
||||
x = "bar";
|
||||
console.log(x);
|
||||
}
|
||||
}
|
||||
a = 0, b = 0;
|
||||
@@ -2028,13 +2143,13 @@ cross_branch_2b_5: {
|
||||
expect: {
|
||||
var a, b;
|
||||
function f() {
|
||||
var y, y;
|
||||
var x, x;
|
||||
if (a)
|
||||
y = "foo";
|
||||
console.log(y);
|
||||
x = "foo";
|
||||
console.log(x);
|
||||
if (b) {
|
||||
y = "bar";
|
||||
console.log(y);
|
||||
x = "bar";
|
||||
console.log(x);
|
||||
}
|
||||
}
|
||||
a = 0, b = 0;
|
||||
@@ -2141,14 +2256,14 @@ cross_branch_2b_7: {
|
||||
expect: {
|
||||
var a, b;
|
||||
function f() {
|
||||
var y, y;
|
||||
var x, x;
|
||||
if (a) {
|
||||
y = "foo";
|
||||
console.log(y);
|
||||
x = "foo";
|
||||
console.log(x);
|
||||
}
|
||||
if (b) {
|
||||
y = "bar";
|
||||
console.log(y);
|
||||
x = "bar";
|
||||
console.log(x);
|
||||
}
|
||||
}
|
||||
a = 0, b = 0;
|
||||
@@ -2195,13 +2310,13 @@ cross_branch_2b_8: {
|
||||
expect: {
|
||||
var a, b;
|
||||
function f() {
|
||||
var y, y;
|
||||
var x, x;
|
||||
if (a)
|
||||
y = "foo";
|
||||
console.log(y);
|
||||
y = "bar";
|
||||
x = "foo";
|
||||
console.log(x);
|
||||
x = "bar";
|
||||
if (b)
|
||||
console.log(y);
|
||||
console.log(x);
|
||||
}
|
||||
a = 0, b = 0;
|
||||
f();
|
||||
@@ -2250,14 +2365,14 @@ cross_branch_2b_9: {
|
||||
expect: {
|
||||
var a, b;
|
||||
function f() {
|
||||
var y, y;
|
||||
var x, x;
|
||||
if (a) {
|
||||
y = "foo";
|
||||
console.log(y);
|
||||
x = "foo";
|
||||
console.log(x);
|
||||
}
|
||||
y = "bar";
|
||||
x = "bar";
|
||||
if (b)
|
||||
console.log(y);
|
||||
console.log(x);
|
||||
}
|
||||
a = 0, b = 0;
|
||||
f();
|
||||
@@ -2304,14 +2419,14 @@ cross_branch_2b_10: {
|
||||
expect: {
|
||||
var a, b;
|
||||
function f() {
|
||||
var y, y;
|
||||
var x, x;
|
||||
if (a) {
|
||||
y = "foo";
|
||||
console.log(y);
|
||||
y = "bar";
|
||||
x = "foo";
|
||||
console.log(x);
|
||||
x = "bar";
|
||||
}
|
||||
if (b)
|
||||
console.log(y);
|
||||
console.log(x);
|
||||
}
|
||||
a = 0, b = 0;
|
||||
f();
|
||||
@@ -2412,13 +2527,13 @@ cross_branch_2b_12: {
|
||||
expect: {
|
||||
var a, b;
|
||||
function f() {
|
||||
var y, y;
|
||||
y = "foo";
|
||||
var x, x;
|
||||
x = "foo";
|
||||
if (a)
|
||||
console.log(y);
|
||||
console.log(x);
|
||||
if (b) {
|
||||
y = "bar";
|
||||
console.log(y);
|
||||
x = "bar";
|
||||
console.log(x);
|
||||
}
|
||||
}
|
||||
a = 0, b = 0;
|
||||
@@ -2465,13 +2580,13 @@ cross_branch_2b_13: {
|
||||
expect: {
|
||||
var a, b;
|
||||
function f() {
|
||||
var y, y;
|
||||
y = "foo";
|
||||
var x, x;
|
||||
x = "foo";
|
||||
if (a)
|
||||
console.log(y);
|
||||
y = "bar";
|
||||
console.log(x);
|
||||
x = "bar";
|
||||
if (b)
|
||||
console.log(y);
|
||||
console.log(x);
|
||||
}
|
||||
a = 0, b = 0;
|
||||
f();
|
||||
@@ -2620,11 +2735,11 @@ issue_4126_1: {
|
||||
try {
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
var c = a;
|
||||
var b = a;
|
||||
} finally {
|
||||
var c = c;
|
||||
var a = b;
|
||||
}
|
||||
console.log(c);
|
||||
console.log(a);
|
||||
}
|
||||
f("FAIL");
|
||||
}
|
||||
@@ -2816,11 +2931,11 @@ conditional_write: {
|
||||
console.log(b);
|
||||
}
|
||||
expect: {
|
||||
var b = "FAIL", b;
|
||||
var a = "FAIL", a;
|
||||
if (console)
|
||||
b = "PASS";
|
||||
b = [b, 42].join();
|
||||
console.log(b);
|
||||
a = "PASS";
|
||||
a = [a, 42].join();
|
||||
console.log(a);
|
||||
}
|
||||
expect_stdout: "PASS,42"
|
||||
}
|
||||
@@ -2994,13 +3109,13 @@ issue_4168_use_strict: {
|
||||
expect: {
|
||||
"use strict";
|
||||
var o = {
|
||||
f: function(d, e, f) {
|
||||
var d = d.d;
|
||||
var e = e.e;
|
||||
var f = f.f;
|
||||
f: function(a, b, c) {
|
||||
var a = a.d;
|
||||
var b = b.e;
|
||||
var c = c.f;
|
||||
this.g(arguments);
|
||||
if (d)
|
||||
console.log(e, f);
|
||||
if (a)
|
||||
console.log(b, c);
|
||||
},
|
||||
g: function(args) {
|
||||
console.log(args[0], args[1], args[2]);
|
||||
@@ -3228,10 +3343,10 @@ issue_4653: {
|
||||
f(a++ + (b = b), b |= console.log(a));
|
||||
}
|
||||
expect: {
|
||||
var b = 1;
|
||||
var b, a = 1;
|
||||
(function(c, d) {
|
||||
c || console.log(d);
|
||||
})(+b + (b = void 0), b |= console.log(2));
|
||||
})(+a + (b = b), b |= console.log(2));
|
||||
}
|
||||
expect_stdout: [
|
||||
"2",
|
||||
|
||||
@@ -389,6 +389,7 @@ issue_1288_side_effects: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
negate_iife: true,
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
@@ -409,10 +410,10 @@ issue_1288_side_effects: {
|
||||
})(0);
|
||||
}
|
||||
expect: {
|
||||
w;
|
||||
w,
|
||||
x || function() {
|
||||
x = {};
|
||||
}();
|
||||
}(),
|
||||
y;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,6 +262,30 @@ de_morgan_2e: {
|
||||
node_version: ">=14"
|
||||
}
|
||||
|
||||
inline_binary_nullish: {
|
||||
options = {
|
||||
inline: true,
|
||||
}
|
||||
input: {
|
||||
(function() {
|
||||
while (console.log("foo"));
|
||||
})() ?? (function() {
|
||||
while (console.log("bar"));
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
if (null == function() {
|
||||
while (console.log("foo"));
|
||||
}())
|
||||
while (console.log("bar"));
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
]
|
||||
node_version: ">=14"
|
||||
}
|
||||
|
||||
issue_4679: {
|
||||
options = {
|
||||
comparisons: true,
|
||||
@@ -280,3 +304,42 @@ issue_4679: {
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=14"
|
||||
}
|
||||
|
||||
issue_5266: {
|
||||
options = {
|
||||
inline: true,
|
||||
}
|
||||
input: {
|
||||
[
|
||||
42,
|
||||
null,
|
||||
false,
|
||||
void 0,
|
||||
"FAIL",
|
||||
].forEach(function (a) {
|
||||
a ?? function() {
|
||||
while (console.log(a));
|
||||
}();
|
||||
});
|
||||
}
|
||||
expect: {
|
||||
[
|
||||
42,
|
||||
null,
|
||||
false,
|
||||
void 0,
|
||||
"FAIL",
|
||||
].forEach(function (a) {
|
||||
if (null == a) {
|
||||
while (console.log(a));
|
||||
return;
|
||||
} else
|
||||
return;
|
||||
});
|
||||
}
|
||||
expect_stdout: [
|
||||
"null",
|
||||
"undefined",
|
||||
]
|
||||
node_version: ">=14"
|
||||
}
|
||||
|
||||
@@ -521,3 +521,25 @@ issue_4415: {
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5213: {
|
||||
options = {
|
||||
objects: true,
|
||||
}
|
||||
input: {
|
||||
var a = "FAIL";
|
||||
console.log({
|
||||
p: a = "PASS",
|
||||
0: a,
|
||||
p: null,
|
||||
}[0]);
|
||||
}
|
||||
expect: {
|
||||
var a = "FAIL";
|
||||
console.log({
|
||||
p: (a = "PASS", null),
|
||||
0: a,
|
||||
}[0]);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
@@ -361,7 +361,9 @@ issue_4906: {
|
||||
} while (console.log("PASS"));
|
||||
}
|
||||
expect: {
|
||||
do {} while (console.log("PASS"));
|
||||
do {
|
||||
var a = a?.[42];
|
||||
} while (console.log("PASS"));
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=14"
|
||||
@@ -434,7 +436,7 @@ issue_5039: {
|
||||
console.log("PASS");
|
||||
}
|
||||
expect: {
|
||||
(function f() {});
|
||||
var a = a?.[function f() {}];
|
||||
console.log("PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
@@ -455,14 +457,163 @@ issue_5091: {
|
||||
console.log(f("FAIL 1") || "PASS");
|
||||
}
|
||||
expect: {
|
||||
function f(b) {
|
||||
var b = b.p;
|
||||
function f(a) {
|
||||
var a = a.p;
|
||||
var c;
|
||||
b?.[c = "FAIL 2"];
|
||||
return b || c;
|
||||
a?.[c = "FAIL 2"];
|
||||
return a || c;
|
||||
}
|
||||
console.log(f("FAIL 1") || "PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=14"
|
||||
}
|
||||
|
||||
issue_5292_dot: {
|
||||
options = {
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
var o = {
|
||||
get p() {
|
||||
console.log("PASS");
|
||||
}
|
||||
};
|
||||
o?.p;
|
||||
}
|
||||
expect: {
|
||||
var o = {
|
||||
get p() {
|
||||
console.log("PASS");
|
||||
}
|
||||
};
|
||||
o?.p;
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=14"
|
||||
}
|
||||
|
||||
issue_5292_dot_pure_getters: {
|
||||
options = {
|
||||
pure_getters: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
var o = {
|
||||
get p() {
|
||||
console.log("PASS");
|
||||
}
|
||||
};
|
||||
o?.p;
|
||||
}
|
||||
expect: {
|
||||
var o = {
|
||||
get p() {
|
||||
console.log("PASS");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
issue_5292_dot_pure_getters_strict: {
|
||||
options = {
|
||||
pure_getters: "strict",
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
var o = {
|
||||
get p() {
|
||||
console.log("PASS");
|
||||
}
|
||||
};
|
||||
o?.p;
|
||||
}
|
||||
expect: {
|
||||
var o = {
|
||||
get p() {
|
||||
console.log("PASS");
|
||||
}
|
||||
};
|
||||
o?.p;
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=14"
|
||||
}
|
||||
|
||||
issue_5292_sub: {
|
||||
options = {
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
var o = {
|
||||
get p() {
|
||||
console.log("foo");
|
||||
}
|
||||
};
|
||||
o?.[console.log("bar"), "p"];
|
||||
}
|
||||
expect: {
|
||||
var o = {
|
||||
get p() {
|
||||
console.log("foo");
|
||||
}
|
||||
};
|
||||
o?.[console.log("bar"), "p"];
|
||||
}
|
||||
expect_stdout: [
|
||||
"bar",
|
||||
"foo",
|
||||
]
|
||||
node_version: ">=14"
|
||||
}
|
||||
|
||||
issue_5292_sub_pure_getters: {
|
||||
options = {
|
||||
pure_getters: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
var o = {
|
||||
get p() {
|
||||
console.log("foo");
|
||||
}
|
||||
};
|
||||
o?.[console.log("bar"), "p"];
|
||||
}
|
||||
expect: {
|
||||
var o = {
|
||||
get p() {
|
||||
console.log("foo");
|
||||
}
|
||||
};
|
||||
console.log("bar");
|
||||
}
|
||||
}
|
||||
|
||||
issue_5292_sub_pure_getters_strict: {
|
||||
options = {
|
||||
pure_getters: "strict",
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
var o = {
|
||||
get p() {
|
||||
console.log("foo");
|
||||
}
|
||||
};
|
||||
o?.[console.log("bar"), "p"];
|
||||
}
|
||||
expect: {
|
||||
var o = {
|
||||
get p() {
|
||||
console.log("foo");
|
||||
}
|
||||
};
|
||||
o?.[console.log("bar"), "p"];
|
||||
}
|
||||
expect_stdout: [
|
||||
"bar",
|
||||
"foo",
|
||||
]
|
||||
node_version: ">=14"
|
||||
}
|
||||
|
||||
@@ -1363,9 +1363,8 @@ issue_3490_1: {
|
||||
}
|
||||
expect: {
|
||||
var b = 42, c = "FAIL";
|
||||
if (function() {
|
||||
var a;
|
||||
}(), c = "PASS", b) while ("" == typeof d);
|
||||
var a;
|
||||
if (c = "PASS", b) while ("" == typeof d);
|
||||
console.log(c, b);
|
||||
}
|
||||
expect_stdout: "PASS 42"
|
||||
|
||||
@@ -41,10 +41,8 @@ reduce_vars: {
|
||||
}
|
||||
expect: {
|
||||
var A = 1;
|
||||
(function() {
|
||||
console.log(-3);
|
||||
console.log(A - 5);
|
||||
})();
|
||||
console.log(-3);
|
||||
console.log(A - 5);
|
||||
(function f1() {
|
||||
var a = 2;
|
||||
console.log(a - 5);
|
||||
@@ -905,7 +903,7 @@ use_before_var: {
|
||||
}
|
||||
expect: {
|
||||
function f(){
|
||||
console.log(void 0);
|
||||
console.log(t);
|
||||
var t = 1;
|
||||
}
|
||||
}
|
||||
@@ -981,7 +979,7 @@ inner_var_for_1: {
|
||||
expect: {
|
||||
function f() {
|
||||
var a = 1;
|
||||
x(1, void 0, d);
|
||||
x(1, b, d);
|
||||
for (var b = 2, c = 3; x(1, 2, 3, d); x(1, 2, 3, d)) {
|
||||
var d = 4, e = 5;
|
||||
x(1, 2, 3, d, e);
|
||||
@@ -6671,6 +6669,7 @@ issues_3267_1: {
|
||||
dead_code: true,
|
||||
evaluate: true,
|
||||
inline: true,
|
||||
negate_iife: true,
|
||||
reduce_vars: true,
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
@@ -6688,8 +6687,9 @@ issues_3267_1: {
|
||||
});
|
||||
}
|
||||
expect: {
|
||||
!function(i) {
|
||||
if (Object())
|
||||
!function(x) {
|
||||
var i = Object();
|
||||
if (i)
|
||||
return console.log("PASS");
|
||||
throw "FAIL";
|
||||
}();
|
||||
@@ -6705,6 +6705,7 @@ issues_3267_2: {
|
||||
evaluate: true,
|
||||
inline: true,
|
||||
keep_fargs: false,
|
||||
negate_iife: true,
|
||||
passes: 2,
|
||||
reduce_vars: true,
|
||||
sequences: true,
|
||||
|
||||
@@ -51,7 +51,7 @@ arrow_destructured_object_1: {
|
||||
}
|
||||
expect_exact: "var f=({...a})=>a,o=f({PASS:42});for(var k in o)console.log(k,o[k]);"
|
||||
expect_stdout: "PASS 42"
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
arrow_destructured_object_2: {
|
||||
@@ -62,7 +62,7 @@ arrow_destructured_object_2: {
|
||||
}
|
||||
expect_exact: "var f=({FAIL:a,...b})=>b,o=f({PASS:42,FAIL:null});for(var k in o)console.log(k,o[k]);"
|
||||
expect_stdout: "PASS 42"
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
arrow_destructured_object_3: {
|
||||
@@ -79,7 +79,7 @@ arrow_destructured_object_3: {
|
||||
"2 S",
|
||||
"3 S",
|
||||
]
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
funarg_1: {
|
||||
@@ -131,7 +131,7 @@ destructured_object_1: {
|
||||
}
|
||||
expect_exact: 'var{...a}=["FAIL","PASS",42];console.log(a[1],a[2]);'
|
||||
expect_stdout: "PASS 42"
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
destructured_object_2: {
|
||||
@@ -141,7 +141,7 @@ destructured_object_2: {
|
||||
}
|
||||
expect_exact: 'var{0:a,...b}=["FAIL","PASS",42];console.log(b[1],b[2]);'
|
||||
expect_stdout: "PASS 42"
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
drop_fargs: {
|
||||
@@ -231,7 +231,7 @@ reduce_destructured_object: {
|
||||
console.log(a[0]);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
retain_destructured_array: {
|
||||
@@ -270,7 +270,7 @@ retain_destructured_object_1: {
|
||||
"1 PASS",
|
||||
"2 42",
|
||||
]
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
retain_destructured_object_2: {
|
||||
@@ -292,7 +292,7 @@ retain_destructured_object_2: {
|
||||
"bar PASS",
|
||||
"baz 42",
|
||||
]
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
retain_funarg_destructured_array_1: {
|
||||
@@ -344,7 +344,7 @@ retain_funarg_destructured_object_1: {
|
||||
console.log((({ ...a }) => a)([ "PASS" ])[0]);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
retain_funarg_destructured_object_2: {
|
||||
@@ -359,10 +359,10 @@ retain_funarg_destructured_object_2: {
|
||||
expect: {
|
||||
console.log(function({ p: a, ... b }) {
|
||||
return b;
|
||||
}({ p: "FAIL" }).p || "PASS");
|
||||
}({}).p || "PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
drop_unused_call_args_1: {
|
||||
@@ -436,9 +436,9 @@ merge_funarg: {
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
(function(...b) {
|
||||
var b = b.length;
|
||||
console.log(b);
|
||||
(function(...a) {
|
||||
var a = a.length;
|
||||
console.log(a);
|
||||
})();
|
||||
}
|
||||
expect_stdout: "0"
|
||||
@@ -456,9 +456,9 @@ merge_funarg_destructured_array: {
|
||||
})([]);
|
||||
}
|
||||
expect: {
|
||||
(function([ ...b ]) {
|
||||
var b = b.length;
|
||||
console.log(b);
|
||||
(function([ ...a ]) {
|
||||
var a = a.length;
|
||||
console.log(a);
|
||||
})([]);
|
||||
}
|
||||
expect_stdout: "0"
|
||||
@@ -476,13 +476,13 @@ merge_funarg_destructured_object: {
|
||||
})([ "PASS" ]);
|
||||
}
|
||||
expect: {
|
||||
(function({ ...b }) {
|
||||
var b = b[0];
|
||||
console.log(b);
|
||||
(function({ ...a }) {
|
||||
var a = a[0];
|
||||
console.log(a);
|
||||
})([ "PASS" ]);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
keep_arguments: {
|
||||
@@ -866,9 +866,9 @@ issue_4575: {
|
||||
}
|
||||
expect: {
|
||||
(function(a) {
|
||||
(function a(...d) {
|
||||
(function(d) {
|
||||
console.log(d.length);
|
||||
})();
|
||||
})([]);
|
||||
})();
|
||||
}
|
||||
expect_stdout: "0"
|
||||
@@ -992,7 +992,7 @@ issue_5089_1: {
|
||||
console.log(o.p);
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
issue_5089_2: {
|
||||
@@ -1019,7 +1019,7 @@ issue_5089_2: {
|
||||
console.log(o.p);
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
issue_5100_1: {
|
||||
@@ -1054,7 +1054,7 @@ issue_5100_1: {
|
||||
console.log(a.r);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
issue_5100_2: {
|
||||
@@ -1085,7 +1085,7 @@ issue_5100_2: {
|
||||
} ][0]);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=10"
|
||||
node_version: ">=10.22.0"
|
||||
}
|
||||
|
||||
issue_5108: {
|
||||
@@ -1104,7 +1104,7 @@ issue_5108: {
|
||||
expect: {
|
||||
console.log(function([]) {
|
||||
return "PASS";
|
||||
}([ "PASS", "FAIL" ]));
|
||||
}([]));
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
@@ -1205,3 +1205,62 @@ issue_5165_2: {
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5246_1: {
|
||||
options = {
|
||||
reduce_vars: true,
|
||||
rests: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
console.log(typeof function([ , ...a ]) {
|
||||
return this && a;
|
||||
}([ , function(){} ])[0]);
|
||||
}
|
||||
expect: {
|
||||
console.log(typeof function([]) {
|
||||
return this && [ function(){} ];
|
||||
}([])[0]);
|
||||
}
|
||||
expect_stdout: "function"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5246_2: {
|
||||
options = {
|
||||
reduce_vars: true,
|
||||
rests: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
A = [ , "PASS", "FAIL" ];
|
||||
var [ , ...a ] = [ ... A ];
|
||||
console.log(a[0]);
|
||||
}
|
||||
expect: {
|
||||
A = [ , "PASS", "FAIL" ];
|
||||
var [ , ...a ] = [ ... A ];
|
||||
console.log(a[0]);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5246_3: {
|
||||
options = {
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function f(...[ [ a ] ]) {
|
||||
console.log(a);
|
||||
})([ "PASS" ]);
|
||||
}
|
||||
expect: {
|
||||
(function(...[ a ]) {
|
||||
console.log(a);
|
||||
})([ "PASS" ][0]);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
@@ -774,7 +774,7 @@ side_effects_cascade_3: {
|
||||
}
|
||||
expect: {
|
||||
function f(a, b) {
|
||||
(b += a) || (b = a) || (b -= a, b ^= a),
|
||||
(b += a) || (b = a) || (b = b - a ^ a),
|
||||
a--;
|
||||
}
|
||||
}
|
||||
@@ -910,9 +910,7 @@ hoist_decl: {
|
||||
var d;
|
||||
}
|
||||
expect: {
|
||||
var a;
|
||||
w();
|
||||
var b = x(), c, d;
|
||||
var a, b = (w(), x()), c, d;
|
||||
for (y(); 0;) z();
|
||||
}
|
||||
}
|
||||
@@ -1162,10 +1160,8 @@ issue_3490_1: {
|
||||
}
|
||||
expect: {
|
||||
var b = 42, c = "FAIL";
|
||||
if (function() {
|
||||
var a;
|
||||
a && a.p;
|
||||
}(), c = "PASS", b) while ("" == typeof d);
|
||||
var a;
|
||||
if (a && a.p, c = "PASS", b) while ("" == typeof d);
|
||||
console.log(c, b);
|
||||
}
|
||||
expect_stdout: "PASS 42"
|
||||
@@ -1195,9 +1191,8 @@ issue_3490_2: {
|
||||
}
|
||||
expect: {
|
||||
var b = 42, c = "FAIL";
|
||||
for (function() {
|
||||
var a;
|
||||
}(), c = "PASS", b; "" == typeof d;);
|
||||
var a;
|
||||
for (c = "PASS", b; "" == typeof d;);
|
||||
console.log(c, b);
|
||||
}
|
||||
expect_stdout: "PASS 42"
|
||||
|
||||
@@ -147,7 +147,7 @@ dont_inline: {
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
do_inline: {
|
||||
do_inline_1: {
|
||||
options = {
|
||||
inline: true,
|
||||
spreads: true,
|
||||
@@ -164,6 +164,46 @@ do_inline: {
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
do_inline_2: {
|
||||
options = {
|
||||
inline: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
(function() {
|
||||
(function() {
|
||||
console.log("PASS");
|
||||
})(..."");
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
[] = [ ..."" ],
|
||||
console.log("PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
do_inline_3: {
|
||||
options = {
|
||||
if_return: true,
|
||||
inline: true,
|
||||
}
|
||||
input: {
|
||||
(function() {
|
||||
(function() {
|
||||
while (console.log("PASS"));
|
||||
})(..."");
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
var [] = [ ..."" ];
|
||||
while (console.log("PASS"));
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
drop_empty_call_1: {
|
||||
options = {
|
||||
side_effects: true,
|
||||
@@ -201,7 +241,29 @@ drop_empty_call_2: {
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
convert_hole: {
|
||||
convert_hole_array: {
|
||||
options = {
|
||||
spreads: true,
|
||||
}
|
||||
input: {
|
||||
[ ...[ "PASS", , 42 ] ].forEach(function(a) {
|
||||
console.log(a);
|
||||
});
|
||||
}
|
||||
expect: {
|
||||
[ "PASS", void 0, 42 ].forEach(function(a) {
|
||||
console.log(a);
|
||||
});
|
||||
}
|
||||
expect_stdout: [
|
||||
"PASS",
|
||||
"undefined",
|
||||
"42",
|
||||
]
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
convert_hole_call: {
|
||||
options = {
|
||||
spreads: true,
|
||||
}
|
||||
@@ -341,7 +403,7 @@ convert_setter: {
|
||||
console.log(k, o[k]);
|
||||
}
|
||||
expect_stdout: "PASS undefined"
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
keep_getter_1: {
|
||||
@@ -370,7 +432,7 @@ keep_getter_1: {
|
||||
});
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
keep_getter_2: {
|
||||
@@ -399,7 +461,7 @@ keep_getter_2: {
|
||||
"foo",
|
||||
"bar",
|
||||
]
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
keep_getter_3: {
|
||||
@@ -429,7 +491,7 @@ keep_getter_3: {
|
||||
});
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
keep_getter_4: {
|
||||
@@ -460,7 +522,7 @@ keep_getter_4: {
|
||||
});
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
keep_accessor: {
|
||||
@@ -508,7 +570,7 @@ keep_accessor: {
|
||||
"q undefined",
|
||||
"r null",
|
||||
]
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
object_key_order_1: {
|
||||
@@ -538,7 +600,7 @@ object_key_order_1: {
|
||||
"a 3",
|
||||
"b 2",
|
||||
]
|
||||
node_version: ">=8 <=10"
|
||||
node_version: ">=8.3.0 <=10"
|
||||
}
|
||||
|
||||
object_key_order_2: {
|
||||
@@ -568,7 +630,7 @@ object_key_order_2: {
|
||||
"a 3",
|
||||
"b 2",
|
||||
]
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
object_key_order_3: {
|
||||
@@ -598,7 +660,7 @@ object_key_order_3: {
|
||||
"a 3",
|
||||
"b 2",
|
||||
]
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
object_key_order_4: {
|
||||
@@ -628,7 +690,7 @@ object_key_order_4: {
|
||||
"a 3",
|
||||
"b 2",
|
||||
]
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
object_spread_array: {
|
||||
@@ -654,7 +716,7 @@ object_spread_array: {
|
||||
"0 foo",
|
||||
"1 bar",
|
||||
]
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
object_spread_string: {
|
||||
@@ -681,7 +743,7 @@ object_spread_string: {
|
||||
"1 o",
|
||||
"2 o",
|
||||
]
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
unused_var_side_effects: {
|
||||
@@ -711,7 +773,7 @@ unused_var_side_effects: {
|
||||
});
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
unsafe_join_1: {
|
||||
@@ -793,7 +855,7 @@ issue_4329: {
|
||||
}[0]);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
issue_4331: {
|
||||
@@ -871,7 +933,7 @@ issue_4345: {
|
||||
}[42]);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
issue_4361: {
|
||||
@@ -901,7 +963,7 @@ issue_4361: {
|
||||
"foo",
|
||||
"undefined",
|
||||
]
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
issue_4363: {
|
||||
@@ -922,7 +984,7 @@ issue_4363: {
|
||||
});
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
issue_4556: {
|
||||
@@ -994,7 +1056,7 @@ issue_4849: {
|
||||
}()));
|
||||
}
|
||||
expect_stdout: "object"
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
issue_4882_1: {
|
||||
@@ -1026,7 +1088,7 @@ issue_4882_1: {
|
||||
"PASS",
|
||||
"undefined",
|
||||
]
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
issue_4882_2: {
|
||||
@@ -1052,7 +1114,7 @@ issue_4882_2: {
|
||||
"42",
|
||||
"PASS",
|
||||
]
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
issue_4882_3: {
|
||||
@@ -1082,7 +1144,7 @@ issue_4882_3: {
|
||||
"PASS",
|
||||
"42",
|
||||
]
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.3.0"
|
||||
}
|
||||
|
||||
issue_5006: {
|
||||
|
||||
@@ -337,7 +337,7 @@ malformed_evaluate_4: {
|
||||
console.log("\\u00b5");
|
||||
}
|
||||
expect_stdout: "\\u00b5"
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.10.0"
|
||||
}
|
||||
|
||||
unsafe_evaluate: {
|
||||
@@ -353,7 +353,7 @@ unsafe_evaluate: {
|
||||
console.log("\\uFo");
|
||||
}
|
||||
expect_stdout: "\\uFo"
|
||||
node_version: ">=8"
|
||||
node_version: ">=8.10.0"
|
||||
}
|
||||
|
||||
side_effects_1: {
|
||||
|
||||
@@ -436,6 +436,245 @@ emberjs_global: {
|
||||
expect_stdout: Error("PASS")
|
||||
}
|
||||
|
||||
reassign: {
|
||||
options = {
|
||||
comparisons: true,
|
||||
conditionals: true,
|
||||
passes: 2,
|
||||
typeofs: true,
|
||||
}
|
||||
input: {
|
||||
A = console;
|
||||
if ("undefined" == typeof A)
|
||||
console.log("FAIL 1");
|
||||
else {
|
||||
A = void 0;
|
||||
while (console.log(void 0 === A ? "PASS" : "FAIL 2"));
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
A = console;
|
||||
if ("undefined" == typeof A)
|
||||
console.log("FAIL 1");
|
||||
else {
|
||||
A = void 0;
|
||||
while (console.log(void 0 === A ? "PASS" : "FAIL 2"));
|
||||
}
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
reassign_call: {
|
||||
options = {
|
||||
comparisons: true,
|
||||
conditionals: true,
|
||||
passes: 2,
|
||||
typeofs: true,
|
||||
}
|
||||
input: {
|
||||
A = console;
|
||||
function f() {
|
||||
A = void 0;
|
||||
}
|
||||
if ("undefined" == typeof A)
|
||||
console.log("FAIL 1");
|
||||
else {
|
||||
f();
|
||||
while (console.log(void 0 === A ? "PASS" : "FAIL 2"));
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
A = console;
|
||||
function f() {
|
||||
A = void 0;
|
||||
}
|
||||
if ("undefined" == typeof A)
|
||||
console.log("FAIL 1");
|
||||
else {
|
||||
f();
|
||||
while (console.log(void 0 === A ? "PASS" : "FAIL 2"));
|
||||
}
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
reassign_conditional: {
|
||||
options = {
|
||||
comparisons: true,
|
||||
conditionals: true,
|
||||
passes: 2,
|
||||
typeofs: true,
|
||||
}
|
||||
input: {
|
||||
A = console;
|
||||
if ("undefined" == typeof A)
|
||||
console.log("FAIL 1");
|
||||
else {
|
||||
A &&= void 0;
|
||||
while (console.log(void 0 === A ? "PASS" : "FAIL 2"));
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
A = console;
|
||||
if ("undefined" == typeof A)
|
||||
console.log("FAIL 1");
|
||||
else {
|
||||
A &&= void 0;
|
||||
while (console.log(void 0 === A ? "PASS" : "FAIL 2"));
|
||||
}
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=15"
|
||||
}
|
||||
|
||||
reassign_do: {
|
||||
options = {
|
||||
comparisons: true,
|
||||
conditionals: true,
|
||||
if_return: true,
|
||||
passes: 2,
|
||||
reduce_vars: true,
|
||||
typeofs: true,
|
||||
}
|
||||
input: {
|
||||
A = console;
|
||||
(function() {
|
||||
if ("undefined" == typeof A)
|
||||
return;
|
||||
var a = A, i = 2;
|
||||
do {
|
||||
console.log(void 0 === A, void 0 === a);
|
||||
A = void 0;
|
||||
} while (--i);
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
A = console;
|
||||
(function() {
|
||||
if ("undefined" != typeof A) {
|
||||
var a = A, i = 2;
|
||||
do {
|
||||
console.log(void 0 === A, (a, false));
|
||||
A = void 0;
|
||||
} while (--i);
|
||||
}
|
||||
})();
|
||||
}
|
||||
expect_stdout: [
|
||||
"false false",
|
||||
"true false",
|
||||
]
|
||||
}
|
||||
|
||||
reassign_for: {
|
||||
options = {
|
||||
comparisons: true,
|
||||
conditionals: true,
|
||||
passes: 2,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
typeofs: true,
|
||||
}
|
||||
input: {
|
||||
if (A = console, "undefined" != typeof A)
|
||||
for (var a = A, i = 0; i < 2; i++)
|
||||
console.log(void 0 === A, void 0 === a),
|
||||
A = void 0;
|
||||
}
|
||||
expect: {
|
||||
if (A = console, "undefined" != typeof A)
|
||||
for (var a = A, i = 0; i < 2; i++)
|
||||
console.log(void 0 === A, (a, false)),
|
||||
A = void 0;
|
||||
}
|
||||
expect_stdout: [
|
||||
"false false",
|
||||
"true false",
|
||||
]
|
||||
}
|
||||
|
||||
reassign_for_in: {
|
||||
options = {
|
||||
comparisons: true,
|
||||
conditionals: true,
|
||||
passes: 2,
|
||||
reduce_vars: true,
|
||||
typeofs: true,
|
||||
}
|
||||
input: {
|
||||
(A = console) && "undefined" != typeof A && function(a) {
|
||||
for (var k in [ a = A, 42 ]) {
|
||||
console.log(void 0 === A, void 0 === a);
|
||||
A = void 0;
|
||||
}
|
||||
}();
|
||||
}
|
||||
expect: {
|
||||
(A = console) && "undefined" != typeof A && function(a) {
|
||||
for (var k in [ a = A, 42 ]) {
|
||||
console.log(void 0 === A, (a, false));
|
||||
A = void 0;
|
||||
}
|
||||
}();
|
||||
}
|
||||
expect_stdout: [
|
||||
"false false",
|
||||
"true false",
|
||||
]
|
||||
}
|
||||
|
||||
reassign_iife: {
|
||||
options = {
|
||||
comparisons: true,
|
||||
conditionals: true,
|
||||
passes: 2,
|
||||
typeofs: true,
|
||||
}
|
||||
input: {
|
||||
A = console;
|
||||
if ("undefined" == typeof A)
|
||||
console.log("FAIL 1");
|
||||
else (function() {
|
||||
A = void 0;
|
||||
})(console.log(void 0 === A ? "FAIL 2" : "PASS"));
|
||||
}
|
||||
expect: {
|
||||
A = console;
|
||||
"undefined" == typeof A ? console.log("FAIL 1") : function() {
|
||||
A = void 0;
|
||||
}(console.log((A, false) ? "FAIL 2" : "PASS"));
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
reassign_property: {
|
||||
options = {
|
||||
comparisons: true,
|
||||
conditionals: true,
|
||||
passes: 2,
|
||||
typeofs: true,
|
||||
}
|
||||
input: {
|
||||
A = console;
|
||||
if ("undefined" == typeof A)
|
||||
console.log("FAIL 1");
|
||||
else {
|
||||
A.p = void 0;
|
||||
console.log(void 0 === A ? "FAIL 2" : "PASS");
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
A = console;
|
||||
if ("undefined" == typeof A)
|
||||
console.log("FAIL 1");
|
||||
else {
|
||||
A.p = void 0;
|
||||
console.log((A, false) ? "FAIL 2" : "PASS");
|
||||
}
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_3817: {
|
||||
options = {
|
||||
comparisons: true,
|
||||
|
||||
@@ -67,7 +67,8 @@ unicode_escaped_identifier_2: {
|
||||
}
|
||||
expect_exact: 'var a="foo";var \u{10000}="bar";console.log(a,\u{10000});'
|
||||
expect_stdout: "foo bar"
|
||||
node_version: ">=4"
|
||||
// non-BMP support is platform-dependent on Node.js v4
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
unicode_identifier_ascii_only: {
|
||||
@@ -200,7 +201,8 @@ surrogate_pair: {
|
||||
}
|
||||
expect_exact: 'var \ud87e\udc00={"\ud87e\udc01":"\udbc0\udc00"};\ud87e\udc00.\ud87e\udc02="\udbc0\udc01";console.log(typeof \ud87e\udc00,\ud87e\udc00.\ud87e\udc01,\ud87e\udc00["\ud87e\udc02"]);'
|
||||
expect_stdout: "object \udbc0\udc00 \udbc0\udc01"
|
||||
node_version: ">=4"
|
||||
// non-BMP support is platform-dependent on Node.js v4
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
surrogate_pair_ascii: {
|
||||
@@ -216,5 +218,6 @@ surrogate_pair_ascii: {
|
||||
}
|
||||
expect_exact: 'var \\u{2f800}={"\\ud87e\\udc01":"\\udbc0\\udc00"};\\u{2f800}.\\u{2f802}="\\udbc0\\udc01";console.log(typeof \\u{2f800},\\u{2f800}.\\u{2f801},\\u{2f800}["\\ud87e\\udc02"]);'
|
||||
expect_stdout: "object \udbc0\udc00 \udbc0\udc01"
|
||||
node_version: ">=4"
|
||||
// non-BMP support is platform-dependent on Node.js v4
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
@@ -13,10 +13,10 @@ reduce_merge_const: {
|
||||
console.log(b);
|
||||
}
|
||||
expect: {
|
||||
var b = console;
|
||||
console.log(typeof b);
|
||||
b = typeof b;
|
||||
console.log(b);
|
||||
var a = console;
|
||||
console.log(typeof a);
|
||||
a = typeof a;
|
||||
console.log(a);
|
||||
}
|
||||
expect_stdout: [
|
||||
"object",
|
||||
@@ -41,10 +41,10 @@ reduce_merge_let: {
|
||||
}
|
||||
expect: {
|
||||
"use strict";
|
||||
var b = console;
|
||||
console.log(typeof b);
|
||||
b = typeof b;
|
||||
console.log(b);
|
||||
var a = console;
|
||||
console.log(typeof a);
|
||||
a = typeof a;
|
||||
console.log(a);
|
||||
}
|
||||
expect_stdout: [
|
||||
"object",
|
||||
|
||||
@@ -749,7 +749,7 @@ lift_sequence: {
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
inline_nested_yield: {
|
||||
inline_nested: {
|
||||
options = {
|
||||
inline: true,
|
||||
sequences: true,
|
||||
@@ -784,6 +784,118 @@ inline_nested_yield: {
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
inline_nested_async: {
|
||||
options = {
|
||||
awaits: true,
|
||||
inline: true,
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
yields: true,
|
||||
}
|
||||
input: {
|
||||
console.log("foo");
|
||||
var a = async function*() {
|
||||
console.log(await(yield* async function*() {
|
||||
yield {
|
||||
then: r => r("bar"),
|
||||
};
|
||||
return "baz";
|
||||
}()));
|
||||
}();
|
||||
console.log("moo");
|
||||
a.next().then(function f(b) {
|
||||
console.log(b.value);
|
||||
b.done || a.next().then(f);
|
||||
});
|
||||
console.log("moz");
|
||||
}
|
||||
expect: {
|
||||
console.log("foo");
|
||||
var a = async function*() {
|
||||
console.log((yield {
|
||||
then: r => r("bar"),
|
||||
}, await "baz"));
|
||||
}();
|
||||
console.log("moo"),
|
||||
a.next().then(function f(b) {
|
||||
console.log(b.value),
|
||||
b.done || a.next().then(f);
|
||||
}),
|
||||
console.log("moz");
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"moo",
|
||||
"moz",
|
||||
"bar",
|
||||
"baz",
|
||||
"undefined",
|
||||
]
|
||||
node_version: ">=10"
|
||||
}
|
||||
|
||||
inline_nested_block: {
|
||||
options = {
|
||||
if_return: true,
|
||||
inline: true,
|
||||
yields: true,
|
||||
}
|
||||
input: {
|
||||
var a = function*() {
|
||||
yield* function*() {
|
||||
for (var a of [ "foo", "bar" ])
|
||||
yield a;
|
||||
return "FAIL";
|
||||
}();
|
||||
}(), b;
|
||||
do {
|
||||
b = a.next();
|
||||
console.log(b.value);
|
||||
} while (!b.done);
|
||||
}
|
||||
expect: {
|
||||
var a = function*() {
|
||||
for (var a of [ "foo", "bar" ])
|
||||
yield a;
|
||||
"FAIL";
|
||||
}(), b;
|
||||
do {
|
||||
b = a.next();
|
||||
console.log(b.value);
|
||||
} while (!b.done);
|
||||
}
|
||||
expect_stdout: [
|
||||
"foo",
|
||||
"bar",
|
||||
"undefined",
|
||||
]
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
dont_inline_nested: {
|
||||
options = {
|
||||
inline: true,
|
||||
}
|
||||
input: {
|
||||
var yield = "PASS";
|
||||
(function*() {
|
||||
(function() {
|
||||
console.log(yield);
|
||||
})();
|
||||
})().next();
|
||||
}
|
||||
expect: {
|
||||
var yield = "PASS";
|
||||
(function*() {
|
||||
(function() {
|
||||
console.log(yield);
|
||||
})();
|
||||
})().next();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
drop_body: {
|
||||
options = {
|
||||
side_effects: true,
|
||||
@@ -864,10 +976,10 @@ issue_4454_2: {
|
||||
f("PASS");
|
||||
}
|
||||
expect: {
|
||||
function f(b) {
|
||||
(function*(c = console.log(b)) {})();
|
||||
var b = 42..toString();
|
||||
console.log(b);
|
||||
function f(a) {
|
||||
(function*(c = console.log(a)) {})();
|
||||
var a = 42..toString();
|
||||
console.log(a);
|
||||
}
|
||||
f("PASS");
|
||||
}
|
||||
@@ -970,7 +1082,7 @@ issue_4639_1: {
|
||||
}().next().value());
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=4"
|
||||
node_version: ">=4 <7 || >=8.7.0"
|
||||
}
|
||||
|
||||
issue_4639_2: {
|
||||
@@ -1177,9 +1289,9 @@ issue_5032_normal: {
|
||||
console.log(value);
|
||||
return value;
|
||||
}
|
||||
function *f(c) {
|
||||
var b = log(c), c = b;
|
||||
log(b);
|
||||
function *f(a) {
|
||||
var a = log(a), c = a;
|
||||
log(a);
|
||||
log(c);
|
||||
}
|
||||
f("PASS").next();
|
||||
@@ -1259,12 +1371,12 @@ issue_5034: {
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
issue_5076: {
|
||||
issue_5076_1: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
hoist_vars: true,
|
||||
passes: 2,
|
||||
pure_getters: "strict",
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
@@ -1281,13 +1393,41 @@ issue_5076: {
|
||||
}
|
||||
expect: {
|
||||
var a;
|
||||
console.log("PASS");
|
||||
console.log("PASS"),
|
||||
a = 42["a"];
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5076_2: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
hoist_vars: true,
|
||||
passes: 2,
|
||||
pure_getters: "strict",
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
yields: true,
|
||||
}
|
||||
input: {
|
||||
var a;
|
||||
console.log("PASS");
|
||||
var b = function*({
|
||||
p: {},
|
||||
}) {}({
|
||||
p: { a } = 42,
|
||||
});
|
||||
}
|
||||
expect: {
|
||||
console.log("PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_5177: {
|
||||
options = {
|
||||
properties: true,
|
||||
|
||||
@@ -2,6 +2,7 @@ var assert = require("assert");
|
||||
var exec = require("child_process").exec;
|
||||
var fs = require("fs");
|
||||
var run_code = require("../sandbox").run_code;
|
||||
var semver = require("semver");
|
||||
var to_ascii = require("../node").to_ascii;
|
||||
|
||||
function read(path) {
|
||||
@@ -12,10 +13,13 @@ describe("bin/uglifyjs", function() {
|
||||
var uglifyjscmd = '"' + process.argv[0] + '" bin/uglifyjs';
|
||||
it("Should produce a functional build when using --self", function(done) {
|
||||
this.timeout(30000);
|
||||
var command = uglifyjscmd + ' --self -cm --wrap WrappedUglifyJS';
|
||||
exec(command, {
|
||||
maxBuffer: 1048576
|
||||
}, function(err, stdout) {
|
||||
var command = [
|
||||
uglifyjscmd,
|
||||
"--self",
|
||||
semver.satisfies(process.version, "<=0.12") ? "-mc hoist_funs" : "-mc",
|
||||
"--wrap WrappedUglifyJS",
|
||||
].join(" ");
|
||||
exec(command, { maxBuffer: 1048576 }, function(err, stdout) {
|
||||
if (err) throw err;
|
||||
eval(stdout);
|
||||
assert.strictEqual(typeof WrappedUglifyJS, "object");
|
||||
@@ -184,6 +188,30 @@ describe("bin/uglifyjs", function() {
|
||||
child.stdin.end(read("test/input/issue-3040/input.js"));
|
||||
}, 1000);
|
||||
});
|
||||
it("Should work with --keep-fargs (mangle only)", function(done) {
|
||||
var command = uglifyjscmd + ' test/input/issue-1431/sample.js --keep-fargs -m';
|
||||
exec(command, function(err, stdout) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(stdout, "function f(x){return function(){function n(a){return a*a}return x(n)}}function g(op){return op(1)+op(2)}console.log(f(g)()==5);\n");
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("Should work with --keep-fargs (mangle & compress)", function(done) {
|
||||
var command = uglifyjscmd + ' test/input/issue-1431/sample.js --keep-fargs -m -c';
|
||||
exec(command, function(err, stdout) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(stdout, "function f(x){return function(){return x(function(a){return a*a})}}function g(op){return op(1)+op(2)}console.log(5==f(g)());\n");
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("Should work with keep_fargs under mangler options", function(done) {
|
||||
var command = uglifyjscmd + ' test/input/issue-1431/sample.js -m keep_fargs=true';
|
||||
exec(command, function(err, stdout) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(stdout, "function f(x){return function(){function n(a){return a*a}return x(n)}}function g(op){return op(1)+op(2)}console.log(f(g)()==5);\n");
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("Should work with --keep-fnames (mangle only)", function(done) {
|
||||
var command = uglifyjscmd + ' test/input/issue-1431/sample.js --keep-fnames -m';
|
||||
exec(command, function(err, stdout) {
|
||||
@@ -193,10 +221,10 @@ describe("bin/uglifyjs", function() {
|
||||
});
|
||||
});
|
||||
it("Should work with --keep-fnames (mangle & compress)", function(done) {
|
||||
var command = uglifyjscmd + ' test/input/issue-1431/sample.js --keep-fnames -m -c unused=false';
|
||||
var command = uglifyjscmd + ' test/input/issue-1431/sample.js --keep-fnames -m -c';
|
||||
exec(command, function(err, stdout) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(stdout, "function f(r){return function(){function n(n){return n*n}return r(n)}}function g(n){return n(1)+n(2)}console.log(5==f(g)());\n");
|
||||
assert.strictEqual(stdout, "function f(n){return function(){return n(function n(r){return r*r})}}function g(n){return n(1)+n(2)}console.log(5==f(g)());\n");
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -418,4 +418,20 @@ describe("test/reduce.js", function() {
|
||||
if (result.error) throw result.error;
|
||||
assert.deepEqual(result.warnings, []);
|
||||
});
|
||||
it("Should handle thrown falsy values gracefully", function() {
|
||||
var code = [
|
||||
"throw 0;",
|
||||
"setTimeout(null, 42);",
|
||||
].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"));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -205,8 +205,8 @@ describe("sourcemaps", function() {
|
||||
});
|
||||
if (result.error) throw result.error;
|
||||
assert.strictEqual(result.code, [
|
||||
"var Foo=function(){console.log(3)};new Foo;var bar=function(o){return o};",
|
||||
"//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0ZGluIiwiMSJdLCJuYW1lcyI6WyJGb28iLCJjb25zb2xlIiwibG9nIiwiYmFyIl0sIm1hcHBpbmdzIjoiQUFBQSxJQUFNQSxJQUFJLFdBQWdCQyxRQUFRQyxJQUFJLElBQVMsSUFBSUYsSUNBbkQsSUFBSUcsSUFDQSxTQUFjQSxHQUNWLE9BQU9BIn0=",
|
||||
"var Foo=function(){console.log(3)},bar=(new Foo,function(o){return o});",
|
||||
"//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0ZGluIiwiMSJdLCJuYW1lcyI6WyJGb28iLCJjb25zb2xlIiwibG9nIiwiYmFyIl0sIm1hcHBpbmdzIjoiQUFBQSxJQUFNQSxJQUFJLFdBQWdCQyxRQUFRQyxJQUFJLElDQWxDQyxLREEyQyxJQUFJSCxJQ0MvQyxTQUFjRyxHQUNWLE9BQU9BIn0=",
|
||||
].join("\n"));
|
||||
assert.deepEqual(result.warnings, [ "WARN: inline source map not found: 1" ]);
|
||||
});
|
||||
|
||||
@@ -1,14 +1,26 @@
|
||||
var assert = require("assert");
|
||||
var exec = require("child_process").exec;
|
||||
var semver = require("semver");
|
||||
var UglifyJS = require("../..");
|
||||
|
||||
describe("spidermonkey export/import sanity test", function() {
|
||||
it("Should produce a functional build when using --self with spidermonkey", function(done) {
|
||||
this.timeout(120000);
|
||||
var uglifyjs = '"' + process.argv[0] + '" bin/uglifyjs';
|
||||
var options = semver.satisfies(process.version, "<=0.12") ? "-mc hoist_funs" : "-mc";
|
||||
var command = [
|
||||
uglifyjs + " --self -cm --wrap SpiderUglify -o spidermonkey",
|
||||
uglifyjs + " -p spidermonkey -cm",
|
||||
[
|
||||
uglifyjs,
|
||||
"--self",
|
||||
options,
|
||||
"--wrap SpiderUglify",
|
||||
"-o spidermonkey",
|
||||
].join(" "),
|
||||
[
|
||||
uglifyjs,
|
||||
"-p spidermonkey",
|
||||
options,
|
||||
].join(" "),
|
||||
].join(" | ");
|
||||
exec(command, { maxBuffer: 1048576 }, function(err, stdout) {
|
||||
if (err) throw err;
|
||||
|
||||
@@ -548,7 +548,7 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
|
||||
}));
|
||||
var before_iterations = testcase;
|
||||
for (var c = 0; c < max_iterations; ++c) {
|
||||
if (verbose && pass == 1 && c % 25 == 0) {
|
||||
if (verbose && c % (pass == 1 ? 25 : 100) == 0) {
|
||||
log("// reduce test pass " + pass + ", iteration " + c + ": " + testcase.length + " bytes");
|
||||
}
|
||||
var CHANGED = false;
|
||||
|
||||
@@ -26,9 +26,11 @@ exports.run_code = semver.satisfies(process.version, "0.8") ? function(code, top
|
||||
return stdout;
|
||||
} : semver.satisfies(process.version, "<0.12") ? run_code_vm : function(code, toplevel, timeout) {
|
||||
if ([
|
||||
/\basync[ \t]*\([\s\S]*?\)[ \t]*=>/,
|
||||
/\b(async[ \t]+function|Promise|setImmediate|setInterval|setTimeout)\b/,
|
||||
/\basync([ \t]+|[ \t]*#|[ \t]*\*[ \t]*)[^\s()[\]{}#:;,.&|!~=*%/+-]+(\s*\(|[ \t]*=>)/,
|
||||
/\basync([ \t]+|[ \t]*#)[^\s()[\]{}#:;,.&|!~=*%/+-]+(\s*\(|[ \t]*=>)/,
|
||||
/\basync[ \t]*\*[ \t]*[^\s()[\]{}#:;,.&|!~=*%/+-]+\s*\(/,
|
||||
/\basync([ \t]*\*)?[ \t]*\[[\s\S]*?\]\s*\(/,
|
||||
/\basync[ \t]*\([\s\S]*?\)[ \t]*=>/,
|
||||
].some(function(pattern) {
|
||||
return pattern.test(code);
|
||||
})) {
|
||||
@@ -146,7 +148,8 @@ function setup(global, builtins, setup_log, setup_tty) {
|
||||
delete ex[name];
|
||||
}
|
||||
}
|
||||
process.stderr.write(inspect(value) + "\n\n-----===== UNCAUGHT EXCEPTION =====-----\n\n");
|
||||
var marker = "\n\n-----===== UNCAUGHT EXCEPTION =====-----\n\n";
|
||||
process.stderr.write(marker + inspect(value) + marker);
|
||||
throw ex;
|
||||
}).on("unhandledRejection", function() {});
|
||||
}
|
||||
@@ -252,8 +255,11 @@ function run_code_vm(code, toplevel, timeout) {
|
||||
var ctx = vm.createContext({ console: console });
|
||||
// for Node.js v6
|
||||
vm.runInContext(setup_code, ctx);
|
||||
vm.runInContext(toplevel ? "(function(){" + code + "})();" : code, ctx, { timeout: timeout });
|
||||
return strip_color_codes(stdout);
|
||||
vm.runInContext(toplevel ? "(function(){\n" + code + "\n})();" : code, ctx, { timeout: timeout });
|
||||
// for Node.js v4
|
||||
return strip_color_codes(stdout.replace(/\b(Array \[|Object {)/g, function(match) {
|
||||
return match.slice(-1);
|
||||
}));
|
||||
} catch (ex) {
|
||||
return ex;
|
||||
} finally {
|
||||
@@ -263,7 +269,7 @@ function run_code_vm(code, toplevel, timeout) {
|
||||
|
||||
function run_code_exec(code, toplevel, timeout) {
|
||||
if (toplevel) {
|
||||
code = setup_code + "(function(){" + code + "})();";
|
||||
code = setup_code + "(function(){\n" + code + "\n})();";
|
||||
} else {
|
||||
code = code.replace(/^((["'])[^"']*\2(;|$))?/, function(directive) {
|
||||
return directive + setup_code;
|
||||
@@ -281,17 +287,21 @@ function run_code_exec(code, toplevel, timeout) {
|
||||
return new Error("Script execution timed out.");
|
||||
}
|
||||
if (result.error) return result.error;
|
||||
var end = msg.indexOf("\n\n-----===== UNCAUGHT EXCEPTION =====-----\n\n");
|
||||
var match = /\n([^:\s]*Error)(?:: ([\s\S]+?))?\n( at [\s\S]+)\n$/.exec(msg);
|
||||
var marker = "\n\n-----===== UNCAUGHT EXCEPTION =====-----\n\n";
|
||||
var start = msg.indexOf(marker) + marker.length;
|
||||
var end = msg.indexOf(marker, start);
|
||||
var details;
|
||||
if (end >= 0) {
|
||||
details = msg.slice(0, end).replace(/<([1-9][0-9]*) empty items?>/g, function(match, count) {
|
||||
details = msg.slice(start, end).replace(/<([1-9][0-9]*) empty items?>/g, function(match, count) {
|
||||
return new Array(+count).join();
|
||||
});
|
||||
try {
|
||||
details = vm.runInNewContext("(" + details + ")");
|
||||
} catch (e) {}
|
||||
} else if (!match) {
|
||||
return new Error("Script execution aborted.");
|
||||
}
|
||||
var match = /\n([^:\s]*Error)(?:: ([\s\S]+?))?\n( at [\s\S]+)\n$/.exec(msg);
|
||||
if (!match) return details;
|
||||
var ex = new global[match[1]](match[2]);
|
||||
ex.stack = ex.stack.slice(0, ex.stack.indexOf(" at ")) + match[3];
|
||||
|
||||
@@ -2290,7 +2290,7 @@ function fuzzy_match(original, uglified) {
|
||||
return true;
|
||||
|
||||
function collect(input, nums) {
|
||||
return input.replace(/-?([1-9][0-9]*(\.[0-9]+)?|0\.[0-9]+)(e-?[1-9][0-9]*)?/ig, function(num) {
|
||||
return input.replace(/-?([1-9][0-9]*(\.[0-9]+)?|0\.[0-9]+)(e-?[1-9][0-9]*)?/gi, function(num) {
|
||||
return "<|" + nums.push(+num) + "|>";
|
||||
});
|
||||
}
|
||||
@@ -2469,8 +2469,10 @@ for (var round = 1; round <= num_iterations; round++) {
|
||||
println("original result:");
|
||||
println(result);
|
||||
println();
|
||||
// ignore v8 parser bug
|
||||
return bug_async_arrow_rest(result);
|
||||
// ignore v8 parser bug
|
||||
return bug_async_arrow_rest(result)
|
||||
// ignore runtime platform bugs
|
||||
|| result.message == "Script execution aborted.";
|
||||
})) continue;
|
||||
minify_options.forEach(function(options) {
|
||||
var o = JSON.parse(options);
|
||||
@@ -2485,6 +2487,8 @@ for (var round = 1; round <= num_iterations; round++) {
|
||||
ok = sandbox.same_stdout(original_result, uglify_result);
|
||||
// ignore v8 parser bug
|
||||
if (!ok && bug_async_arrow_rest(uglify_result)) ok = true;
|
||||
// ignore runtime platform bugs
|
||||
if (!ok && 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)) {
|
||||
@@ -2497,7 +2501,7 @@ for (var round = 1; round <= num_iterations; round++) {
|
||||
}
|
||||
}
|
||||
// ignore declaration order of global variables
|
||||
if (!ok && !toplevel) {
|
||||
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)));
|
||||
}
|
||||
// ignore numerical imprecision caused by `unsafe_math`
|
||||
@@ -2517,11 +2521,10 @@ for (var round = 1; round <= num_iterations; round++) {
|
||||
// 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);
|
||||
var uglify_strict = run_code('"use strict";\n' + uglify_code, toplevel);
|
||||
if (typeof original_strict != "string") {
|
||||
ok = typeof uglify_strict != "string";
|
||||
if (/^(Syntax|Type)Error$/.test(uglify_result.name)) {
|
||||
ok = typeof original_strict != "string";
|
||||
} else {
|
||||
ok = sandbox.same_stdout(original_strict, uglify_strict);
|
||||
ok = sandbox.same_stdout(original_strict, uglify_result);
|
||||
}
|
||||
}
|
||||
// ignore difference in error message caused by `import` symbol redeclaration
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
"passes": 1e6,
|
||||
"unsafe": true
|
||||
},
|
||||
"keep_fargs": true,
|
||||
"keep_fnames": true,
|
||||
"toplevel": true
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user