Compare commits
32 Commits
harmony-v3
...
harmony-v3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9632f79e46 | ||
|
|
a3fbb27194 | ||
|
|
11c0b1e1f9 | ||
|
|
346fa12e0e | ||
|
|
cda27b0970 | ||
|
|
3c74047368 | ||
|
|
650d5d5c9b | ||
|
|
94525d859f | ||
|
|
1127a2caf3 | ||
|
|
246d9d4e83 | ||
|
|
4c0b0177b6 | ||
|
|
dd0a36119b | ||
|
|
94b19a9c46 | ||
|
|
bcf95ac02c | ||
|
|
e11cec1ab8 | ||
|
|
38bfb73f06 | ||
|
|
bbedbf4ea0 | ||
|
|
2cfb5aa7da | ||
|
|
6c45101870 | ||
|
|
2c2fd89e34 | ||
|
|
0c43519097 | ||
|
|
352a7de204 | ||
|
|
df9c8dfd72 | ||
|
|
f46281e2b7 | ||
|
|
25a18883f5 | ||
|
|
5b4b07e9a7 | ||
|
|
a8aa28a7a6 | ||
|
|
fe5a68f9d5 | ||
|
|
71e61153b1 | ||
|
|
c8b6f4733d | ||
|
|
29bbc41dfe | ||
|
|
a48f87abf2 |
@@ -706,6 +706,11 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|||||||
Specify `"strict"` to treat `foo.bar` as side-effect-free only when
|
Specify `"strict"` to treat `foo.bar` as side-effect-free only when
|
||||||
`foo` is certain to not throw, i.e. not `null` or `undefined`.
|
`foo` is certain to not throw, i.e. not `null` or `undefined`.
|
||||||
|
|
||||||
|
- `reduce_funcs` (default: `true`) -- Allows single-use functions
|
||||||
|
to be inlined as function expressions when permissible.
|
||||||
|
Enabled by default. Option depends on `reduce_vars` being enabled.
|
||||||
|
For speed critical code this option should be disabled.
|
||||||
|
|
||||||
- `reduce_vars` (default: `true`) -- Improve optimization on variables assigned with and
|
- `reduce_vars` (default: `true`) -- Improve optimization on variables assigned with and
|
||||||
used as constant values.
|
used as constant values.
|
||||||
|
|
||||||
|
|||||||
426
lib/compress.js
426
lib/compress.js
@@ -78,6 +78,7 @@ function Compressor(options, false_by_default) {
|
|||||||
properties : !false_by_default,
|
properties : !false_by_default,
|
||||||
pure_getters : !false_by_default && "strict",
|
pure_getters : !false_by_default && "strict",
|
||||||
pure_funcs : null,
|
pure_funcs : null,
|
||||||
|
reduce_funcs : !false_by_default,
|
||||||
reduce_vars : !false_by_default,
|
reduce_vars : !false_by_default,
|
||||||
sequences : !false_by_default,
|
sequences : !false_by_default,
|
||||||
side_effects : !false_by_default,
|
side_effects : !false_by_default,
|
||||||
@@ -156,7 +157,9 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
var passes = +this.options.passes || 1;
|
var passes = +this.options.passes || 1;
|
||||||
var last_count = 1 / 0;
|
var last_count = 1 / 0;
|
||||||
|
var mangle = { ie8: this.option("ie8") };
|
||||||
for (var pass = 0; pass < passes; pass++) {
|
for (var pass = 0; pass < passes; pass++) {
|
||||||
|
node.figure_out_scope(mangle);
|
||||||
if (pass > 0 || this.option("reduce_vars"))
|
if (pass > 0 || this.option("reduce_vars"))
|
||||||
node.reset_opt_flags(this);
|
node.reset_opt_flags(this);
|
||||||
node = node.transform(this);
|
node = node.transform(this);
|
||||||
@@ -291,7 +294,7 @@ merge(Compressor.prototype, {
|
|||||||
self.transform(tt);
|
self.transform(tt);
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_Node.DEFMETHOD("reset_opt_flags", function(compressor) {
|
AST_Toplevel.DEFMETHOD("reset_opt_flags", function(compressor) {
|
||||||
var reduce_vars = compressor.option("reduce_vars");
|
var reduce_vars = compressor.option("reduce_vars");
|
||||||
var unused = compressor.option("unused");
|
var unused = compressor.option("unused");
|
||||||
// Stack of look-up tables to keep track of whether a `SymbolDef` has been
|
// Stack of look-up tables to keep track of whether a `SymbolDef` has been
|
||||||
@@ -318,16 +321,16 @@ merge(Compressor.prototype, {
|
|||||||
if (node instanceof AST_SymbolRef) {
|
if (node instanceof AST_SymbolRef) {
|
||||||
var d = node.definition();
|
var d = node.definition();
|
||||||
d.references.push(node);
|
d.references.push(node);
|
||||||
|
var value;
|
||||||
if (d.fixed === undefined || !safe_to_read(d) || d.single_use == "m") {
|
if (d.fixed === undefined || !safe_to_read(d) || d.single_use == "m") {
|
||||||
d.fixed = false;
|
d.fixed = false;
|
||||||
} else if (d.fixed) {
|
} else if (d.fixed) {
|
||||||
var value = node.fixed_value();
|
value = node.fixed_value();
|
||||||
if (unused && !compressor.exposed(d)) {
|
if (value && ref_once(d) && !compressor.exposed(d)) {
|
||||||
d.single_use = value
|
d.single_use = value instanceof AST_Lambda
|
||||||
&& d.references.length == 1
|
|| d.scope === node.scope && value.is_constant_expression();
|
||||||
&& loop_ids[d.id] === in_loop
|
} else {
|
||||||
&& d.scope === node.scope
|
d.single_use = false;
|
||||||
&& value.is_constant_expression();
|
|
||||||
}
|
}
|
||||||
if (is_modified(node, value, 0, is_immutable(value))) {
|
if (is_modified(node, value, 0, is_immutable(value))) {
|
||||||
if (d.single_use) {
|
if (d.single_use) {
|
||||||
@@ -335,10 +338,9 @@ merge(Compressor.prototype, {
|
|||||||
} else {
|
} else {
|
||||||
d.fixed = false;
|
d.fixed = false;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
mark_escaped(d, node, value, 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mark_escaped(d, node, value, 0);
|
||||||
}
|
}
|
||||||
if (node instanceof AST_SymbolCatch) {
|
if (node instanceof AST_SymbolCatch) {
|
||||||
node.definition().fixed = false;
|
node.definition().fixed = false;
|
||||||
@@ -389,7 +391,9 @@ merge(Compressor.prototype, {
|
|||||||
d.fixed = false;
|
d.fixed = false;
|
||||||
} else {
|
} else {
|
||||||
d.fixed = node;
|
d.fixed = node;
|
||||||
|
loop_ids[d.id] = in_loop;
|
||||||
mark(d, true);
|
mark(d, true);
|
||||||
|
d.single_use = ref_once(d);
|
||||||
}
|
}
|
||||||
var save_ids = safe_ids;
|
var save_ids = safe_ids;
|
||||||
safe_ids = Object.create(null);
|
safe_ids = Object.create(null);
|
||||||
@@ -542,6 +546,7 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
return def.fixed instanceof AST_Defun;
|
||||||
}
|
}
|
||||||
|
|
||||||
function safe_to_assign(def, value) {
|
function safe_to_assign(def, value) {
|
||||||
@@ -567,7 +572,7 @@ merge(Compressor.prototype, {
|
|||||||
function reset_def(def) {
|
function reset_def(def) {
|
||||||
def.direct_access = false;
|
def.direct_access = false;
|
||||||
def.escaped = false;
|
def.escaped = false;
|
||||||
if (def.scope.uses_eval) {
|
if (def.scope.uses_eval || def.scope.uses_with) {
|
||||||
def.fixed = false;
|
def.fixed = false;
|
||||||
} else if (def.orig[0] instanceof AST_SymbolConst || !compressor.exposed(def)) {
|
} else if (def.orig[0] instanceof AST_SymbolConst || !compressor.exposed(def)) {
|
||||||
def.fixed = undefined;
|
def.fixed = undefined;
|
||||||
@@ -579,8 +584,19 @@ merge(Compressor.prototype, {
|
|||||||
def.single_use = undefined;
|
def.single_use = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ref_once(def) {
|
||||||
|
return unused
|
||||||
|
&& !def.scope.uses_eval
|
||||||
|
&& !def.scope.uses_with
|
||||||
|
&& def.references.length == 1
|
||||||
|
&& loop_ids[def.id] === in_loop;
|
||||||
|
}
|
||||||
|
|
||||||
function is_immutable(value) {
|
function is_immutable(value) {
|
||||||
return value && (value.is_constant() || value instanceof AST_Lambda);
|
if (!value) return false;
|
||||||
|
return value.is_constant()
|
||||||
|
|| value instanceof AST_Lambda
|
||||||
|
|| value instanceof AST_This;
|
||||||
}
|
}
|
||||||
|
|
||||||
function read_property(obj, key) {
|
function read_property(obj, key) {
|
||||||
@@ -608,10 +624,13 @@ merge(Compressor.prototype, {
|
|||||||
|| !immutable
|
|| !immutable
|
||||||
&& parent instanceof AST_Call
|
&& parent instanceof AST_Call
|
||||||
&& parent.expression === node
|
&& parent.expression === node
|
||||||
&& (!(value instanceof AST_Function) || value.contains_this())) {
|
&& (!(value instanceof AST_Function) || value.contains_this(parent))) {
|
||||||
return true;
|
return true;
|
||||||
} else if (parent instanceof AST_Array || parent instanceof AST_Object) {
|
} else if (parent instanceof AST_Array) {
|
||||||
return is_modified(parent, parent, level + 1);
|
return is_modified(parent, parent, level + 1);
|
||||||
|
} else if (parent instanceof AST_ObjectKeyVal && node === parent.value) {
|
||||||
|
var obj = tw.parent(level + 1);
|
||||||
|
return is_modified(obj, obj, level + 2);
|
||||||
} else if (parent instanceof AST_PropAccess && parent.expression === node) {
|
} else if (parent instanceof AST_PropAccess && parent.expression === node) {
|
||||||
return !immutable && is_modified(parent, read_property(value, parent.property), level + 1);
|
return !immutable && is_modified(parent, read_property(value, parent.property), level + 1);
|
||||||
}
|
}
|
||||||
@@ -619,15 +638,19 @@ merge(Compressor.prototype, {
|
|||||||
|
|
||||||
function mark_escaped(d, node, value, level) {
|
function mark_escaped(d, node, value, level) {
|
||||||
var parent = tw.parent(level);
|
var parent = tw.parent(level);
|
||||||
if (value instanceof AST_Constant || value instanceof AST_Function) return;
|
if (value instanceof AST_Constant || value instanceof AST_ClassExpression) return;
|
||||||
|
if (level > 0 && value instanceof AST_Function) return;
|
||||||
if (parent instanceof AST_Assign && parent.operator == "=" && node === parent.right
|
if (parent instanceof AST_Assign && parent.operator == "=" && node === parent.right
|
||||||
|| parent instanceof AST_Call && node !== parent.expression
|
|| parent instanceof AST_Call && node !== parent.expression
|
||||||
|| parent instanceof AST_Return && node === parent.value && node.scope !== d.scope
|
|| parent instanceof AST_Return && node === parent.value && node.scope !== d.scope
|
||||||
|| parent instanceof AST_VarDef && node === parent.value) {
|
|| parent instanceof AST_VarDef && node === parent.value) {
|
||||||
d.escaped = true;
|
d.escaped = true;
|
||||||
return;
|
return;
|
||||||
} else if (parent instanceof AST_Array || parent instanceof AST_Object) {
|
} else if (parent instanceof AST_Array) {
|
||||||
mark_escaped(d, parent, parent, level + 1);
|
mark_escaped(d, parent, parent, level + 1);
|
||||||
|
} else if (parent instanceof AST_ObjectKeyVal && node === parent.value) {
|
||||||
|
var obj = tw.parent(level + 1);
|
||||||
|
mark_escaped(d, obj, obj, level + 2);
|
||||||
} else if (parent instanceof AST_PropAccess && node === parent.expression) {
|
} else if (parent instanceof AST_PropAccess && node === parent.expression) {
|
||||||
value = read_property(value, parent.property);
|
value = read_property(value, parent.property);
|
||||||
mark_escaped(d, parent, value, level + 1);
|
mark_escaped(d, parent, value, level + 1);
|
||||||
@@ -811,6 +834,14 @@ merge(Compressor.prototype, {
|
|||||||
|| compressor.option("unsafe") && global_names(this.name);
|
|| compressor.option("unsafe") && global_names(this.name);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function drop_decl(def) {
|
||||||
|
def._eliminiated = (def._eliminiated || 0) + 1;
|
||||||
|
if (def.orig.length == def._eliminiated) {
|
||||||
|
def.scope.functions.del(def.name);
|
||||||
|
def.scope.variables.del(def.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function tighten_body(statements, compressor) {
|
function tighten_body(statements, compressor) {
|
||||||
var CHANGED, max_iter = 10;
|
var CHANGED, max_iter = 10;
|
||||||
do {
|
do {
|
||||||
@@ -844,6 +875,7 @@ merge(Compressor.prototype, {
|
|||||||
function collapse(statements, compressor) {
|
function collapse(statements, compressor) {
|
||||||
var scope = compressor.find_parent(AST_Scope).get_defun_scope();
|
var scope = compressor.find_parent(AST_Scope).get_defun_scope();
|
||||||
if (scope.uses_eval || scope.uses_with) return statements;
|
if (scope.uses_eval || scope.uses_with) return statements;
|
||||||
|
var args;
|
||||||
var candidates = [];
|
var candidates = [];
|
||||||
var stat_index = statements.length;
|
var stat_index = statements.length;
|
||||||
while (--stat_index >= 0) {
|
while (--stat_index >= 0) {
|
||||||
@@ -864,7 +896,7 @@ merge(Compressor.prototype, {
|
|||||||
var one_off = lhs instanceof AST_Symbol && lhs.definition().references.length == 1;
|
var one_off = lhs instanceof AST_Symbol && lhs.definition().references.length == 1;
|
||||||
var side_effects = value_has_side_effects(candidate);
|
var side_effects = value_has_side_effects(candidate);
|
||||||
var hit = candidate.name instanceof AST_SymbolFunarg;
|
var hit = candidate.name instanceof AST_SymbolFunarg;
|
||||||
var abort = false, replaced = false;
|
var abort = false, replaced = false, can_replace = !args || !hit;
|
||||||
var tt = new TreeTransformer(function(node, descend) {
|
var tt = new TreeTransformer(function(node, descend) {
|
||||||
if (abort) return node;
|
if (abort) return node;
|
||||||
// Skip nodes before `candidate` as quickly as possible
|
// Skip nodes before `candidate` as quickly as possible
|
||||||
@@ -891,7 +923,8 @@ merge(Compressor.prototype, {
|
|||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
// Replace variable with assignment when found
|
// Replace variable with assignment when found
|
||||||
if (!(node instanceof AST_SymbolDeclaration)
|
if (can_replace
|
||||||
|
&& !(node instanceof AST_SymbolDeclaration)
|
||||||
&& !is_lhs(node, parent)
|
&& !is_lhs(node, parent)
|
||||||
&& lhs.equivalent_to(node)) {
|
&& lhs.equivalent_to(node)) {
|
||||||
CHANGED = replaced = abort = true;
|
CHANGED = replaced = abort = true;
|
||||||
@@ -942,6 +975,12 @@ merge(Compressor.prototype, {
|
|||||||
// Skip (non-executed) functions and (leading) default case in switch statements
|
// Skip (non-executed) functions and (leading) default case in switch statements
|
||||||
if (node instanceof AST_Default || node instanceof AST_Scope) return node;
|
if (node instanceof AST_Default || node instanceof AST_Scope) return node;
|
||||||
});
|
});
|
||||||
|
if (!can_replace) {
|
||||||
|
for (var j = compressor.self().argnames.lastIndexOf(candidate.__name || candidate.name) + 1; j < args.length; j++) {
|
||||||
|
args[j].transform(tt);
|
||||||
|
}
|
||||||
|
can_replace = true;
|
||||||
|
}
|
||||||
for (var i = stat_index; !abort && i < statements.length; i++) {
|
for (var i = stat_index; !abort && i < statements.length; i++) {
|
||||||
statements[i].transform(tt);
|
statements[i].transform(tt);
|
||||||
}
|
}
|
||||||
@@ -987,9 +1026,16 @@ merge(Compressor.prototype, {
|
|||||||
})) {
|
})) {
|
||||||
var fn_strict = compressor.has_directive("use strict");
|
var fn_strict = compressor.has_directive("use strict");
|
||||||
if (fn_strict && fn.body.indexOf(fn_strict) < 0) fn_strict = false;
|
if (fn_strict && fn.body.indexOf(fn_strict) < 0) fn_strict = false;
|
||||||
|
var len = fn.argnames.length;
|
||||||
|
args = iife.args.slice(len);
|
||||||
var names = Object.create(null);
|
var names = Object.create(null);
|
||||||
for (var i = fn.argnames.length; --i >= 0;) {
|
for (var i = len; --i >= 0;) {
|
||||||
var sym = fn.argnames[i];
|
var sym = fn.argnames[i];
|
||||||
|
var arg = iife.args[i];
|
||||||
|
args.unshift(make_node(AST_VarDef, sym, {
|
||||||
|
name: sym,
|
||||||
|
value: arg
|
||||||
|
}));
|
||||||
if (sym.name in names) continue;
|
if (sym.name in names) continue;
|
||||||
names[sym.name] = true;
|
names[sym.name] = true;
|
||||||
if (sym instanceof AST_Expansion) {
|
if (sym instanceof AST_Expansion) {
|
||||||
@@ -1003,9 +1049,9 @@ merge(Compressor.prototype, {
|
|||||||
elements: elements
|
elements: elements
|
||||||
})
|
})
|
||||||
}));
|
}));
|
||||||
|
candidates[0].__name = sym;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var arg = iife.args[i];
|
|
||||||
if (!arg) arg = make_node(AST_Undefined, sym).transform(compressor);
|
if (!arg) arg = make_node(AST_Undefined, sym).transform(compressor);
|
||||||
else if (has_overlapping_symbol(fn, arg, fn_strict)) arg = null;
|
else if (has_overlapping_symbol(fn, arg, fn_strict)) arg = null;
|
||||||
if (arg) candidates.unshift(make_node(AST_VarDef, sym, {
|
if (arg) candidates.unshift(make_node(AST_VarDef, sym, {
|
||||||
@@ -1023,7 +1069,8 @@ merge(Compressor.prototype, {
|
|||||||
candidates.push(expr);
|
candidates.push(expr);
|
||||||
} else if (expr instanceof AST_Sequence) {
|
} else if (expr instanceof AST_Sequence) {
|
||||||
expr.expressions.forEach(extract_candidates);
|
expr.expressions.forEach(extract_candidates);
|
||||||
} else if (expr instanceof AST_Definitions) {
|
} else if (expr instanceof AST_Definitions
|
||||||
|
&& (compressor.option("unused") || !(expr instanceof AST_Const))) {
|
||||||
expr.definitions.forEach(function(var_def) {
|
expr.definitions.forEach(function(var_def) {
|
||||||
if (var_def.value) candidates.push(var_def);
|
if (var_def.value) candidates.push(var_def);
|
||||||
});
|
});
|
||||||
@@ -1037,7 +1084,8 @@ merge(Compressor.prototype, {
|
|||||||
function get_lhs(expr) {
|
function get_lhs(expr) {
|
||||||
if (expr instanceof AST_VarDef && expr.name instanceof AST_SymbolDeclaration) {
|
if (expr instanceof AST_VarDef && expr.name instanceof AST_SymbolDeclaration) {
|
||||||
var def = expr.name.definition();
|
var def = expr.name.definition();
|
||||||
if (def.orig.length > 1 && !(expr.name instanceof AST_SymbolFunarg)
|
if (def.orig.length - (def._eliminiated || 0) > 1
|
||||||
|
&& !(expr.name instanceof AST_SymbolFunarg)
|
||||||
|| def.references.length == 1 && !compressor.exposed(def)) {
|
|| def.references.length == 1 && !compressor.exposed(def)) {
|
||||||
return make_node(AST_SymbolRef, expr.name, expr.name);
|
return make_node(AST_SymbolRef, expr.name, expr.name);
|
||||||
}
|
}
|
||||||
@@ -1047,6 +1095,10 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_rvalue(expr) {
|
||||||
|
return expr[expr instanceof AST_Assign ? "right" : "value"];
|
||||||
|
}
|
||||||
|
|
||||||
function get_lvalues(expr) {
|
function get_lvalues(expr) {
|
||||||
var lvalues = Object.create(null);
|
var lvalues = Object.create(null);
|
||||||
if (expr instanceof AST_Unary) return lvalues;
|
if (expr instanceof AST_Unary) return lvalues;
|
||||||
@@ -1057,7 +1109,7 @@ merge(Compressor.prototype, {
|
|||||||
lvalues[sym.name] = lvalues[sym.name] || is_lhs(node, tw.parent());
|
lvalues[sym.name] = lvalues[sym.name] || is_lhs(node, tw.parent());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
expr[expr instanceof AST_Assign ? "right" : "value"].walk(tw);
|
get_rvalue(expr).walk(tw);
|
||||||
return lvalues;
|
return lvalues;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1083,10 +1135,12 @@ merge(Compressor.prototype, {
|
|||||||
var found = false;
|
var found = false;
|
||||||
return statements[stat_index].transform(new TreeTransformer(function(node, descend, in_list) {
|
return statements[stat_index].transform(new TreeTransformer(function(node, descend, in_list) {
|
||||||
if (found) return node;
|
if (found) return node;
|
||||||
if (node === expr) {
|
if (node === expr || node.body === expr) {
|
||||||
found = true;
|
found = true;
|
||||||
if (node instanceof AST_VarDef) {
|
if (node instanceof AST_VarDef) {
|
||||||
remove(node.name.definition().orig, node.name);
|
drop_decl(node.name.definition());
|
||||||
|
node.value = null;
|
||||||
|
return node;
|
||||||
}
|
}
|
||||||
return in_list ? MAP.skip : null;
|
return in_list ? MAP.skip : null;
|
||||||
}
|
}
|
||||||
@@ -1095,16 +1149,12 @@ merge(Compressor.prototype, {
|
|||||||
case 0: return null;
|
case 0: return null;
|
||||||
case 1: return node.expressions[0];
|
case 1: return node.expressions[0];
|
||||||
}
|
}
|
||||||
if (node instanceof AST_Definitions && node.definitions.length == 0
|
|
||||||
|| node instanceof AST_SimpleStatement && !node.body) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
function value_has_side_effects(expr) {
|
function value_has_side_effects(expr) {
|
||||||
if (expr instanceof AST_Unary) return false;
|
if (expr instanceof AST_Unary) return false;
|
||||||
return expr[expr instanceof AST_Assign ? "right" : "value"].has_side_effects(compressor);
|
return get_rvalue(expr).has_side_effects(compressor);
|
||||||
}
|
}
|
||||||
|
|
||||||
function references_in_scope(def) {
|
function references_in_scope(def) {
|
||||||
@@ -2261,18 +2311,25 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
def(AST_Node, return_false);
|
def(AST_Node, return_false);
|
||||||
def(AST_Constant, return_true);
|
def(AST_Constant, return_true);
|
||||||
def(AST_Function, function(){
|
def(AST_Lambda, function(scope){
|
||||||
var self = this;
|
var self = this;
|
||||||
var result = true;
|
var result = true;
|
||||||
self.walk(new TreeWalker(function(node) {
|
self.walk(new TreeWalker(function(node) {
|
||||||
if (!result) return true;
|
if (!result) return true;
|
||||||
if (node instanceof AST_SymbolRef) {
|
if (node instanceof AST_SymbolRef) {
|
||||||
var def = node.definition();
|
var def = node.definition();
|
||||||
if (self.enclosed.indexOf(def) >= 0
|
if (member(def, self.enclosed)
|
||||||
&& self.variables.get(def.name) !== def) {
|
&& !self.variables.has(def.name)) {
|
||||||
|
if (scope) {
|
||||||
|
var scope_def = scope.find_variable(node);
|
||||||
|
if (def.undeclared ? !scope_def : scope_def === def) {
|
||||||
|
result = "f";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
result = false;
|
result = false;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
return result;
|
return result;
|
||||||
@@ -2353,7 +2410,7 @@ merge(Compressor.prototype, {
|
|||||||
|| can_be_evicted_from_block(self.body[0])) {
|
|| can_be_evicted_from_block(self.body[0])) {
|
||||||
return self.body[0];
|
return self.body[0];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0: return make_node(AST_EmptyStatement, self);
|
case 0: return make_node(AST_EmptyStatement, self);
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
@@ -2389,75 +2446,80 @@ merge(Compressor.prototype, {
|
|||||||
// this scope (not in nested scopes).
|
// this scope (not in nested scopes).
|
||||||
var scope = this;
|
var scope = this;
|
||||||
var tw = new TreeWalker(function(node, descend){
|
var tw = new TreeWalker(function(node, descend){
|
||||||
if (node !== self) {
|
if (node === self) return;
|
||||||
if (node instanceof AST_Defun || node instanceof AST_DefClass) {
|
if (node instanceof AST_Defun || node instanceof AST_DefClass) {
|
||||||
var in_export = tw.parent() instanceof AST_Export;
|
var in_export = tw.parent() instanceof AST_Export;
|
||||||
if (in_export || !drop_funcs && scope === self) {
|
if (in_export || !drop_funcs && scope === self) {
|
||||||
var node_def = node.name.definition();
|
var node_def = node.name.definition();
|
||||||
if (node_def.global && !(node_def.id in in_use_ids)) {
|
if (node_def.global && !(node_def.id in in_use_ids)) {
|
||||||
in_use_ids[node_def.id] = true;
|
|
||||||
in_use.push(node_def);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
initializations.add(node.name.name, node);
|
|
||||||
return true; // don't go in nested scopes
|
|
||||||
}
|
|
||||||
if (node instanceof AST_Definitions && scope === self) {
|
|
||||||
var in_export = tw.parent() instanceof AST_Export;
|
|
||||||
node.definitions.forEach(function(def){
|
|
||||||
if (def.name instanceof AST_SymbolVar) {
|
|
||||||
var_defs_by_id.add(def.name.definition().id, def);
|
|
||||||
}
|
|
||||||
if (in_export || !drop_vars) {
|
|
||||||
def.name.walk(new TreeWalker(function(node) {
|
|
||||||
if (node instanceof AST_SymbolDeclaration) {
|
|
||||||
var def = node.definition();
|
|
||||||
if ((in_export || def.global) && !(def.id in in_use_ids)) {
|
|
||||||
in_use_ids[def.id] = true;
|
|
||||||
in_use.push(def);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
if (def.value) {
|
|
||||||
if (def.name instanceof AST_Destructuring) {
|
|
||||||
var destructuring_cache = destructuring_value;
|
|
||||||
destructuring_value = def.value;
|
|
||||||
def.walk(tw);
|
|
||||||
destructuring_value = destructuring_cache;
|
|
||||||
} else {
|
|
||||||
initializations.add(def.name.name, def.value);
|
|
||||||
}
|
|
||||||
if (def.value.has_side_effects(compressor)) {
|
|
||||||
def.value.walk(tw);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (assign_as_unused(node) instanceof AST_SymbolRef && scope === self
|
|
||||||
&& !is_ref_of(node.left, AST_SymbolBlockDeclaration)) {
|
|
||||||
if (node instanceof AST_Assign) node.right.walk(tw);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (node instanceof AST_SymbolRef) {
|
|
||||||
var node_def = node.definition();
|
|
||||||
if (!(node_def.id in in_use_ids)) {
|
|
||||||
in_use_ids[node_def.id] = true;
|
in_use_ids[node_def.id] = true;
|
||||||
in_use.push(node_def);
|
in_use.push(node_def);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
if (node instanceof AST_Scope) {
|
initializations.add(node.name.name, node);
|
||||||
var save_scope = scope;
|
return true; // don't go in nested scopes
|
||||||
scope = node;
|
}
|
||||||
descend();
|
if (node instanceof AST_SymbolFunarg && scope === self) {
|
||||||
scope = save_scope;
|
var_defs_by_id.add(node.definition().id, node);
|
||||||
return true;
|
}
|
||||||
}
|
if (node instanceof AST_Definitions && scope === self) {
|
||||||
if (node.destructuring && destructuring_value) {
|
var in_export = tw.parent() instanceof AST_Export;
|
||||||
initializations.add(node.name, destructuring_value);
|
node.definitions.forEach(function(def){
|
||||||
|
if (def.name instanceof AST_SymbolVar) {
|
||||||
|
var_defs_by_id.add(def.name.definition().id, def);
|
||||||
|
}
|
||||||
|
if (in_export || !drop_vars) {
|
||||||
|
def.name.walk(new TreeWalker(function(node) {
|
||||||
|
if (node instanceof AST_SymbolDeclaration) {
|
||||||
|
var def = node.definition();
|
||||||
|
if ((in_export || def.global) && !(def.id in in_use_ids)) {
|
||||||
|
in_use_ids[def.id] = true;
|
||||||
|
in_use.push(def);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
if (def.value) {
|
||||||
|
if (def.name instanceof AST_Destructuring) {
|
||||||
|
var destructuring_cache = destructuring_value;
|
||||||
|
destructuring_value = def.value;
|
||||||
|
def.walk(tw);
|
||||||
|
destructuring_value = destructuring_cache;
|
||||||
|
} else {
|
||||||
|
initializations.add(def.name.name, def.value);
|
||||||
|
}
|
||||||
|
if (def.value.has_side_effects(compressor)) {
|
||||||
|
def.value.walk(tw);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
var sym;
|
||||||
|
if (scope === self
|
||||||
|
&& (sym = assign_as_unused(node)) instanceof AST_SymbolRef
|
||||||
|
&& !is_ref_of(node.left, AST_SymbolBlockDeclaration)
|
||||||
|
&& self.variables.get(sym.name) === sym.definition()) {
|
||||||
|
if (node instanceof AST_Assign) node.right.walk(tw);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (node instanceof AST_SymbolRef) {
|
||||||
|
var node_def = node.definition();
|
||||||
|
if (!(node_def.id in in_use_ids)) {
|
||||||
|
in_use_ids[node_def.id] = true;
|
||||||
|
in_use.push(node_def);
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (node instanceof AST_Scope) {
|
||||||
|
var save_scope = scope;
|
||||||
|
scope = node;
|
||||||
|
descend();
|
||||||
|
scope = save_scope;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (node.destructuring && destructuring_value) {
|
||||||
|
initializations.add(node.name, destructuring_value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
self.walk(tw);
|
self.walk(tw);
|
||||||
@@ -2522,9 +2584,11 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((node instanceof AST_Defun || node instanceof AST_DefClass) && node !== self) {
|
if ((node instanceof AST_Defun || node instanceof AST_DefClass) && node !== self) {
|
||||||
var keep = (node.name.definition().id in in_use_ids) || !drop_funcs && node.name.definition().global;
|
var def = node.name.definition();
|
||||||
|
var keep = (def.id in in_use_ids) || !drop_funcs && def.global;
|
||||||
if (!keep) {
|
if (!keep) {
|
||||||
compressor[node.name.unreferenced() ? "warn" : "info"]("Dropping unused function {name} [{file}:{line},{col}]", template(node.name));
|
compressor[node.name.unreferenced() ? "warn" : "info"]("Dropping unused function {name} [{file}:{line},{col}]", template(node.name));
|
||||||
|
drop_decl(def);
|
||||||
return make_node(AST_EmptyStatement, node);
|
return make_node(AST_EmptyStatement, node);
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
@@ -2549,7 +2613,7 @@ merge(Compressor.prototype, {
|
|||||||
if (var_defs.length > 1 && !def.value) {
|
if (var_defs.length > 1 && !def.value) {
|
||||||
compressor.warn("Dropping duplicated definition of variable {name} [{file}:{line},{col}]", template(def.name));
|
compressor.warn("Dropping duplicated definition of variable {name} [{file}:{line},{col}]", template(def.name));
|
||||||
remove(var_defs, def);
|
remove(var_defs, def);
|
||||||
remove(sym.orig, def.name);
|
drop_decl(sym);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2582,7 +2646,7 @@ merge(Compressor.prototype, {
|
|||||||
} else {
|
} else {
|
||||||
compressor[def.name.unreferenced() ? "warn" : "info"]("Dropping unused variable {name} [{file}:{line},{col}]", template(def.name));
|
compressor[def.name.unreferenced() ? "warn" : "info"]("Dropping unused variable {name} [{file}:{line},{col}]", template(def.name));
|
||||||
}
|
}
|
||||||
remove(sym.orig, def.name);
|
drop_decl(sym);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (head.length == 0 && tail.length == 1 && tail[0].name instanceof AST_SymbolVar) {
|
if (head.length == 0 && tail.length == 1 && tail[0].name instanceof AST_SymbolVar) {
|
||||||
@@ -2591,7 +2655,7 @@ merge(Compressor.prototype, {
|
|||||||
var def = tail.pop();
|
var def = tail.pop();
|
||||||
compressor.warn("Converting duplicated definition of variable {name} to assignment [{file}:{line},{col}]", template(def.name));
|
compressor.warn("Converting duplicated definition of variable {name} to assignment [{file}:{line},{col}]", template(def.name));
|
||||||
remove(var_defs, def);
|
remove(var_defs, def);
|
||||||
remove(def.name.definition().orig, def.name);
|
drop_decl(def.name.definition());
|
||||||
side_effects.unshift(make_node(AST_Assign, def, {
|
side_effects.unshift(make_node(AST_Assign, def, {
|
||||||
operator: "=",
|
operator: "=",
|
||||||
left: make_node(AST_SymbolRef, def.name, def.name),
|
left: make_node(AST_SymbolRef, def.name, def.name),
|
||||||
@@ -2623,8 +2687,7 @@ merge(Compressor.prototype, {
|
|||||||
var def = assign_as_unused(node);
|
var def = assign_as_unused(node);
|
||||||
if (def instanceof AST_SymbolRef
|
if (def instanceof AST_SymbolRef
|
||||||
&& !((def = def.definition()).id in in_use_ids)
|
&& !((def = def.definition()).id in in_use_ids)
|
||||||
&& (drop_vars || !def.global)
|
&& (drop_vars || !def.global)) {
|
||||||
&& self.variables.get(def.name) === def) {
|
|
||||||
if (node instanceof AST_Assign) {
|
if (node instanceof AST_Assign) {
|
||||||
return maintain_this_binding(parent, node, node.right.transform(tt));
|
return maintain_this_binding(parent, node, node.right.transform(tt));
|
||||||
}
|
}
|
||||||
@@ -2833,7 +2896,8 @@ merge(Compressor.prototype, {
|
|||||||
self.variables.each(function(def, name) {
|
self.variables.each(function(def, name) {
|
||||||
var_names[name] = true;
|
var_names[name] = true;
|
||||||
});
|
});
|
||||||
return self.transform(new TreeTransformer(function(node) {
|
var tt = new TreeTransformer(function(node) {
|
||||||
|
if (node instanceof AST_Definitions && tt.parent() instanceof AST_Export) return node;
|
||||||
if (node instanceof AST_VarDef) {
|
if (node instanceof AST_VarDef) {
|
||||||
var sym = node.name, def, value;
|
var sym = node.name, def, value;
|
||||||
if (sym.scope === self
|
if (sym.scope === self
|
||||||
@@ -2884,7 +2948,8 @@ merge(Compressor.prototype, {
|
|||||||
var_names[name] = true;
|
var_names[name] = true;
|
||||||
return new_var;
|
return new_var;
|
||||||
}
|
}
|
||||||
}));
|
});
|
||||||
|
return self.transform(tt);
|
||||||
});
|
});
|
||||||
|
|
||||||
// drop_side_effect_free()
|
// drop_side_effect_free()
|
||||||
@@ -3440,7 +3505,7 @@ merge(Compressor.prototype, {
|
|||||||
});
|
});
|
||||||
a.push(var_);
|
a.push(var_);
|
||||||
}
|
}
|
||||||
remove(def.name.definition().orig, def.name);
|
drop_decl(def.name.definition());
|
||||||
return a;
|
return a;
|
||||||
}, []);
|
}, []);
|
||||||
if (assignments.length == 0) return null;
|
if (assignments.length == 0) return null;
|
||||||
@@ -3723,6 +3788,7 @@ merge(Compressor.prototype, {
|
|||||||
&& !exp.uses_arguments
|
&& !exp.uses_arguments
|
||||||
&& !exp.uses_eval
|
&& !exp.uses_eval
|
||||||
&& (exp.body instanceof AST_Node || exp.body.length == 1)
|
&& (exp.body instanceof AST_Node || exp.body.length == 1)
|
||||||
|
&& !exp.contains_this()
|
||||||
&& all(exp.argnames, function(arg) {
|
&& all(exp.argnames, function(arg) {
|
||||||
if (arg instanceof AST_Expansion) return arg.expression.__unused;
|
if (arg instanceof AST_Expansion) return arg.expression.__unused;
|
||||||
return arg.__unused;
|
return arg.__unused;
|
||||||
@@ -3737,23 +3803,6 @@ merge(Compressor.prototype, {
|
|||||||
expression: stat.body
|
expression: stat.body
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (value) {
|
|
||||||
var tw = new TreeWalker(function(node) {
|
|
||||||
if (!value) return true;
|
|
||||||
if (node instanceof AST_SymbolRef) {
|
|
||||||
var ref = node.scope.find_variable(node);
|
|
||||||
if (ref && ref.scope.parent_scope === fn.parent_scope) {
|
|
||||||
value = null;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (node instanceof AST_This && !tw.find_parent(AST_Scope)) {
|
|
||||||
value = null;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
value.walk(tw);
|
|
||||||
}
|
|
||||||
if (value) {
|
if (value) {
|
||||||
var args = self.args.concat(value);
|
var args = self.args.concat(value);
|
||||||
return make_sequence(self, args).optimize(compressor);
|
return make_sequence(self, args).optimize(compressor);
|
||||||
@@ -4043,7 +4092,8 @@ merge(Compressor.prototype, {
|
|||||||
function is_object(node) {
|
function is_object(node) {
|
||||||
return node instanceof AST_Array
|
return node instanceof AST_Array
|
||||||
|| node instanceof AST_Lambda
|
|| node instanceof AST_Lambda
|
||||||
|| node instanceof AST_Object;
|
|| node instanceof AST_Object
|
||||||
|
|| node instanceof AST_Class;
|
||||||
}
|
}
|
||||||
|
|
||||||
OPT(AST_Binary, function(self, compressor){
|
OPT(AST_Binary, function(self, compressor){
|
||||||
@@ -4423,6 +4473,17 @@ merge(Compressor.prototype, {
|
|||||||
return self;
|
return self;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function recursive_ref(compressor, def) {
|
||||||
|
var node;
|
||||||
|
for (var i = 0; node = compressor.parent(i); i++) {
|
||||||
|
if (node instanceof AST_Lambda) {
|
||||||
|
var name = node.name;
|
||||||
|
if (name && name.definition() === def) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
OPT(AST_SymbolRef, function(self, compressor){
|
OPT(AST_SymbolRef, function(self, compressor){
|
||||||
var def = self.resolve_defines(compressor);
|
var def = self.resolve_defines(compressor);
|
||||||
if (def) {
|
if (def) {
|
||||||
@@ -4448,49 +4509,68 @@ merge(Compressor.prototype, {
|
|||||||
if (fixed instanceof AST_Defun) {
|
if (fixed instanceof AST_Defun) {
|
||||||
d.fixed = fixed = make_node(AST_Function, fixed, fixed);
|
d.fixed = fixed = make_node(AST_Function, fixed, fixed);
|
||||||
}
|
}
|
||||||
if (compressor.option("unused")
|
if (d.single_use && fixed instanceof AST_Function) {
|
||||||
&& fixed
|
if (!compressor.option("reduce_funcs") && d.scope !== self.scope) {
|
||||||
&& d.references.length == 1
|
d.single_use = false;
|
||||||
&& (d.single_use || is_func_expr(fixed)
|
} else if (d.escaped && d.scope !== self.scope || recursive_ref(compressor, d)) {
|
||||||
&& !(d.scope.uses_arguments && d.orig[0] instanceof AST_SymbolFunarg)
|
d.single_use = false;
|
||||||
&& !d.scope.uses_eval
|
} else if (d.scope !== self.scope || d.orig[0] instanceof AST_SymbolFunarg) {
|
||||||
&& compressor.find_parent(AST_Scope) === fixed.parent_scope)) {
|
d.single_use = fixed.is_constant_expression(self.scope);
|
||||||
|
if (d.single_use == "f") {
|
||||||
|
var scope = self.scope;
|
||||||
|
do {
|
||||||
|
if (scope.name) scope.name.definition().single_use = false;
|
||||||
|
} while (scope = scope.parent_scope);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (d.single_use && fixed) {
|
||||||
var value = fixed.optimize(compressor);
|
var value = fixed.optimize(compressor);
|
||||||
return value === fixed ? fixed.clone(true) : value;
|
return value === fixed ? fixed.clone(true) : value;
|
||||||
}
|
}
|
||||||
if (compressor.option("evaluate") && fixed) {
|
if (fixed && d.should_replace === undefined) {
|
||||||
if (d.should_replace === undefined) {
|
var init;
|
||||||
var init = fixed.evaluate(compressor);
|
if (fixed instanceof AST_This) {
|
||||||
if (init !== fixed && (compressor.option("unsafe_regexp") || !(init instanceof RegExp))) {
|
if (!(d.orig[0] instanceof AST_SymbolFunarg)
|
||||||
init = make_node_from_constant(init, fixed);
|
&& all(d.references, function(ref) {
|
||||||
var value_length = init.optimize(compressor).print_to_string().length;
|
return d.scope === ref.scope;
|
||||||
var fn;
|
})) {
|
||||||
if (has_symbol_ref(fixed)) {
|
init = fixed;
|
||||||
fn = function() {
|
}
|
||||||
var result = init.optimize(compressor);
|
} else {
|
||||||
return result === init ? result.clone(true) : result;
|
var ev = fixed.evaluate(compressor);
|
||||||
};
|
if (ev !== fixed && (compressor.option("unsafe_regexp") || !(ev instanceof RegExp))) {
|
||||||
} else {
|
init = make_node_from_constant(ev, fixed);
|
||||||
value_length = Math.min(value_length, fixed.print_to_string().length);
|
|
||||||
fn = function() {
|
|
||||||
var result = best_of_expression(init.optimize(compressor), fixed);
|
|
||||||
return result === init || result === fixed ? result.clone(true) : result;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
var name_length = d.name.length;
|
|
||||||
var overhead = 0;
|
|
||||||
if (compressor.option("unused") && !compressor.exposed(d)) {
|
|
||||||
overhead = (name_length + 2 + value_length) / d.references.length;
|
|
||||||
}
|
|
||||||
d.should_replace = value_length <= name_length + overhead ? fn : false;
|
|
||||||
} else {
|
|
||||||
d.should_replace = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (d.should_replace) {
|
if (init) {
|
||||||
return d.should_replace();
|
var value_length = init.optimize(compressor).print_to_string().length;
|
||||||
|
var fn;
|
||||||
|
if (has_symbol_ref(fixed)) {
|
||||||
|
fn = function() {
|
||||||
|
var result = init.optimize(compressor);
|
||||||
|
return result === init ? result.clone(true) : result;
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
value_length = Math.min(value_length, fixed.print_to_string().length);
|
||||||
|
fn = function() {
|
||||||
|
var result = best_of_expression(init.optimize(compressor), fixed);
|
||||||
|
return result === init || result === fixed ? result.clone(true) : result;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
var name_length = d.name.length;
|
||||||
|
var overhead = 0;
|
||||||
|
if (compressor.option("unused") && !compressor.exposed(d)) {
|
||||||
|
overhead = (name_length + 2 + value_length) / d.references.length;
|
||||||
|
}
|
||||||
|
d.should_replace = value_length <= name_length + overhead ? fn : false;
|
||||||
|
} else {
|
||||||
|
d.should_replace = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (d.should_replace) {
|
||||||
|
return d.should_replace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
|
|
||||||
@@ -4827,11 +4907,11 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is_lhs(self, compressor.parent())) return self;
|
if (is_lhs(self, compressor.parent())) return self;
|
||||||
if (compressor.option("properties") && key !== prop) {
|
if (key !== prop) {
|
||||||
var node = self.flatten_object(property, compressor);
|
var sub = self.flatten_object(property, compressor);
|
||||||
if (node) {
|
if (sub) {
|
||||||
expr = self.expression = node.expression;
|
expr = self.expression = sub.expression;
|
||||||
prop = self.property = node.property;
|
prop = self.property = sub.property;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (compressor.option("properties") && compressor.option("side_effects")
|
if (compressor.option("properties") && compressor.option("side_effects")
|
||||||
@@ -4877,7 +4957,8 @@ merge(Compressor.prototype, {
|
|||||||
return self;
|
return self;
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_Lambda.DEFMETHOD("contains_this", function() {
|
AST_Lambda.DEFMETHOD("contains_this", function(grandparent) {
|
||||||
|
if (grandparent instanceof AST_New) return false;
|
||||||
var result;
|
var result;
|
||||||
var self = this;
|
var self = this;
|
||||||
self.walk(new TreeWalker(function(node) {
|
self.walk(new TreeWalker(function(node) {
|
||||||
@@ -4889,6 +4970,7 @@ merge(Compressor.prototype, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
AST_PropAccess.DEFMETHOD("flatten_object", function(key, compressor) {
|
AST_PropAccess.DEFMETHOD("flatten_object", function(key, compressor) {
|
||||||
|
if (!compressor.option("properties")) return;
|
||||||
var arrows = compressor.option("unsafe_arrows") && compressor.option("ecma") >= 6;
|
var arrows = compressor.option("unsafe_arrows") && compressor.option("ecma") >= 6;
|
||||||
var expr = this.expression;
|
var expr = this.expression;
|
||||||
if (expr instanceof AST_Object) {
|
if (expr instanceof AST_Object) {
|
||||||
@@ -4902,7 +4984,7 @@ merge(Compressor.prototype, {
|
|||||||
})) break;
|
})) break;
|
||||||
var value = prop.value;
|
var value = prop.value;
|
||||||
if ((value instanceof AST_Accessor || value instanceof AST_Function)
|
if ((value instanceof AST_Accessor || value instanceof AST_Function)
|
||||||
&& value.contains_this()) break;
|
&& value.contains_this(compressor.parent())) break;
|
||||||
return make_node(AST_Sub, this, {
|
return make_node(AST_Sub, this, {
|
||||||
expression: make_node(AST_Array, expr, {
|
expression: make_node(AST_Array, expr, {
|
||||||
elements: props.map(function(prop) {
|
elements: props.map(function(prop) {
|
||||||
@@ -4952,10 +5034,8 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is_lhs(self, compressor.parent())) return self;
|
if (is_lhs(self, compressor.parent())) return self;
|
||||||
if (compressor.option("properties")) {
|
var sub = self.flatten_object(self.property, compressor);
|
||||||
var node = self.flatten_object(self.property, compressor);
|
if (sub) return sub.optimize(compressor);
|
||||||
if (node) return node.optimize(compressor);
|
|
||||||
}
|
|
||||||
var ev = self.evaluate(compressor);
|
var ev = self.evaluate(compressor);
|
||||||
if (ev !== self) {
|
if (ev !== self) {
|
||||||
ev = make_node_from_constant(ev, self).optimize(compressor);
|
ev = make_node_from_constant(ev, self).optimize(compressor);
|
||||||
|
|||||||
@@ -141,11 +141,9 @@ function minify(files, options) {
|
|||||||
if (options.wrap) {
|
if (options.wrap) {
|
||||||
toplevel = toplevel.wrap_commonjs(options.wrap);
|
toplevel = toplevel.wrap_commonjs(options.wrap);
|
||||||
}
|
}
|
||||||
if (timings) timings.scope1 = Date.now();
|
|
||||||
if (options.compress) toplevel.figure_out_scope(options.mangle);
|
|
||||||
if (timings) timings.compress = Date.now();
|
if (timings) timings.compress = Date.now();
|
||||||
if (options.compress) toplevel = new Compressor(options.compress).compress(toplevel);
|
if (options.compress) toplevel = new Compressor(options.compress).compress(toplevel);
|
||||||
if (timings) timings.scope2 = Date.now();
|
if (timings) timings.scope = Date.now();
|
||||||
if (options.mangle) toplevel.figure_out_scope(options.mangle);
|
if (options.mangle) toplevel.figure_out_scope(options.mangle);
|
||||||
if (timings) timings.mangle = Date.now();
|
if (timings) timings.mangle = Date.now();
|
||||||
if (options.mangle) {
|
if (options.mangle) {
|
||||||
@@ -203,9 +201,9 @@ function minify(files, options) {
|
|||||||
if (timings) {
|
if (timings) {
|
||||||
timings.end = Date.now();
|
timings.end = Date.now();
|
||||||
result.timings = {
|
result.timings = {
|
||||||
parse: 1e-3 * (timings.scope1 - timings.parse),
|
parse: 1e-3 * (timings.compress - timings.parse),
|
||||||
scope: 1e-3 * (timings.compress - timings.scope1 + timings.mangle - timings.scope2),
|
compress: 1e-3 * (timings.scope - timings.compress),
|
||||||
compress: 1e-3 * (timings.scope2 - timings.compress),
|
scope: 1e-3 * (timings.mangle - timings.scope),
|
||||||
mangle: 1e-3 * (timings.properties - timings.mangle),
|
mangle: 1e-3 * (timings.properties - timings.mangle),
|
||||||
properties: 1e-3 * (timings.output - timings.properties),
|
properties: 1e-3 * (timings.output - timings.properties),
|
||||||
output: 1e-3 * (timings.end - timings.output),
|
output: 1e-3 * (timings.end - timings.output),
|
||||||
|
|||||||
@@ -1361,6 +1361,7 @@ function OutputStream(options) {
|
|||||||
self.exported_value.print(output);
|
self.exported_value.print(output);
|
||||||
} else if (self.exported_definition) {
|
} else if (self.exported_definition) {
|
||||||
self.exported_definition.print(output);
|
self.exported_definition.print(output);
|
||||||
|
if (self.exported_definition instanceof AST_Definitions) return;
|
||||||
}
|
}
|
||||||
if (self.module_name) {
|
if (self.module_name) {
|
||||||
output.space();
|
output.space();
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"homepage": "https://github.com/mishoo/UglifyJS2/tree/harmony",
|
"homepage": "https://github.com/mishoo/UglifyJS2/tree/harmony",
|
||||||
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
||||||
"license": "BSD-2-Clause",
|
"license": "BSD-2-Clause",
|
||||||
"version": "3.1.6",
|
"version": "3.1.9",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.8.0"
|
"node": ">=0.8.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -204,6 +204,7 @@ constant_join_3: {
|
|||||||
for_loop: {
|
for_loop: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unsafe: true,
|
unsafe: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -260,6 +261,7 @@ for_loop: {
|
|||||||
index: {
|
index: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unsafe: true,
|
unsafe: true,
|
||||||
@@ -278,6 +280,7 @@ index: {
|
|||||||
length: {
|
length: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unsafe: true,
|
unsafe: true,
|
||||||
@@ -296,6 +299,7 @@ length: {
|
|||||||
index_length: {
|
index_length: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unsafe: true,
|
unsafe: true,
|
||||||
|
|||||||
@@ -288,6 +288,7 @@ issue_2105_1: {
|
|||||||
ecma: 6,
|
ecma: 6,
|
||||||
inline: true,
|
inline: true,
|
||||||
passes: 3,
|
passes: 3,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
unsafe_methods: true,
|
unsafe_methods: true,
|
||||||
@@ -314,17 +315,12 @@ issue_2105_1: {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
(() => {
|
({
|
||||||
var quux = () => {
|
prop() {
|
||||||
|
console.log;
|
||||||
console.log("PASS");
|
console.log("PASS");
|
||||||
};
|
}
|
||||||
return {
|
}).prop();
|
||||||
prop() {
|
|
||||||
console.log;
|
|
||||||
quux();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
})().prop();
|
|
||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
node_version: ">=4"
|
node_version: ">=4"
|
||||||
@@ -335,6 +331,7 @@ issue_2105_2: {
|
|||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
passes: 2,
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -360,17 +357,12 @@ issue_2105_2: {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
(() => {
|
({
|
||||||
var quux = () => {
|
prop: () => {
|
||||||
|
console.log;
|
||||||
console.log("PASS");
|
console.log("PASS");
|
||||||
};
|
}
|
||||||
return {
|
}).prop();
|
||||||
prop: () => {
|
|
||||||
console.log;
|
|
||||||
quux();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
})().prop();
|
|
||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
node_version: ">=6"
|
node_version: ">=6"
|
||||||
@@ -411,6 +403,7 @@ issue_2136_3: {
|
|||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
passes: 3,
|
passes: 3,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
@@ -438,6 +431,7 @@ call_args: {
|
|||||||
ecma: 6,
|
ecma: 6,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -462,6 +456,7 @@ call_args_drop_param: {
|
|||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
keep_fargs: false,
|
keep_fargs: false,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -509,6 +504,7 @@ issue_2084: {
|
|||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
passes: 2,
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
|
|||||||
@@ -141,6 +141,7 @@ async_inline: {
|
|||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
negate_iife: true,
|
negate_iife: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ collapse_vars_side_effects_1: {
|
|||||||
options = {
|
options = {
|
||||||
collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true,
|
collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true,
|
||||||
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
||||||
keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true, reduce_vars:true
|
keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true,
|
||||||
|
reduce_funcs: true, reduce_vars:true
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f1() {
|
function f1() {
|
||||||
@@ -150,7 +151,8 @@ collapse_vars_issue_721: {
|
|||||||
options = {
|
options = {
|
||||||
collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true,
|
collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true,
|
||||||
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
||||||
keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true, reduce_vars:true
|
keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true,
|
||||||
|
reduce_funcs: true, reduce_vars:true
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
define(["require", "exports", 'handlebars'], function (require, exports, hb) {
|
define(["require", "exports", 'handlebars'], function (require, exports, hb) {
|
||||||
@@ -216,7 +218,8 @@ collapse_vars_properties: {
|
|||||||
options = {
|
options = {
|
||||||
collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true,
|
collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true,
|
||||||
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
||||||
keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true, reduce_vars:true
|
keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true,
|
||||||
|
reduce_funcs: true, reduce_vars:true
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f1(obj) {
|
function f1(obj) {
|
||||||
@@ -243,7 +246,8 @@ collapse_vars_if: {
|
|||||||
options = {
|
options = {
|
||||||
collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true,
|
collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true,
|
||||||
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
||||||
keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true, reduce_vars:true
|
keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true,
|
||||||
|
reduce_funcs: true, reduce_vars:true
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f1() {
|
function f1() {
|
||||||
@@ -293,7 +297,8 @@ collapse_vars_while: {
|
|||||||
options = {
|
options = {
|
||||||
collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true,
|
collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true,
|
||||||
comparisons:true, evaluate:true, booleans:true, loops:false, unused:true, hoist_funs:true,
|
comparisons:true, evaluate:true, booleans:true, loops:false, unused:true, hoist_funs:true,
|
||||||
keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true, reduce_vars:true
|
keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true,
|
||||||
|
reduce_funcs: true, reduce_vars:true
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f1(y) {
|
function f1(y) {
|
||||||
@@ -712,7 +717,8 @@ collapse_vars_misc1: {
|
|||||||
options = {
|
options = {
|
||||||
collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true,
|
collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true,
|
||||||
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
||||||
keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true, reduce_vars:true
|
keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true,
|
||||||
|
reduce_funcs: true, reduce_vars:true
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f0(o, a, h) {
|
function f0(o, a, h) {
|
||||||
@@ -789,7 +795,8 @@ collapse_vars_repeated: {
|
|||||||
options = {
|
options = {
|
||||||
collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true,
|
collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true,
|
||||||
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
||||||
keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true, reduce_vars:true
|
keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true,
|
||||||
|
reduce_funcs: true, reduce_vars:true
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f1() {
|
function f1() {
|
||||||
@@ -831,7 +838,8 @@ collapse_vars_closures: {
|
|||||||
options = {
|
options = {
|
||||||
collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true,
|
collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true,
|
||||||
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
||||||
keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true, reduce_vars:true
|
keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true,
|
||||||
|
reduce_funcs: true, reduce_vars:true
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function constant_vars_can_be_replaced_in_any_scope() {
|
function constant_vars_can_be_replaced_in_any_scope() {
|
||||||
@@ -921,7 +929,8 @@ collapse_vars_try: {
|
|||||||
options = {
|
options = {
|
||||||
collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true,
|
collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true,
|
||||||
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
||||||
keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true, reduce_vars:true
|
keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true,
|
||||||
|
reduce_funcs: true, reduce_vars:true
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f1() {
|
function f1() {
|
||||||
@@ -1118,7 +1127,8 @@ collapse_vars_constants: {
|
|||||||
options = {
|
options = {
|
||||||
collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true,
|
collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true,
|
||||||
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
||||||
keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true, reduce_vars:true
|
keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true,
|
||||||
|
reduce_funcs: true, reduce_vars:true
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f1(x) {
|
function f1(x) {
|
||||||
@@ -1156,7 +1166,7 @@ collapse_vars_arguments: {
|
|||||||
collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true,
|
collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true,
|
||||||
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true,
|
||||||
keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true,
|
keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true,
|
||||||
toplevel:true, reduce_vars:true
|
toplevel:true, reduce_funcs: true, reduce_vars:true
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var outer = function() {
|
var outer = function() {
|
||||||
@@ -1280,6 +1290,7 @@ collapse_vars_regexp: {
|
|||||||
hoist_funs: true,
|
hoist_funs: true,
|
||||||
keep_fargs: true,
|
keep_fargs: true,
|
||||||
loops: false,
|
loops: false,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -1454,6 +1465,7 @@ issue_1562: {
|
|||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -1487,6 +1499,7 @@ issue_1605_1: {
|
|||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
toplevel: false,
|
toplevel: false,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function foo(x) {
|
function foo(x) {
|
||||||
@@ -1509,6 +1522,7 @@ issue_1605_2: {
|
|||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
toplevel: "vars",
|
toplevel: "vars",
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function foo(x) {
|
function foo(x) {
|
||||||
@@ -1636,6 +1650,7 @@ issue_1631_3: {
|
|||||||
var_side_effects_1: {
|
var_side_effects_1: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var print = console.log.bind(console);
|
var print = console.log.bind(console);
|
||||||
@@ -1658,6 +1673,7 @@ var_side_effects_1: {
|
|||||||
var_side_effects_2: {
|
var_side_effects_2: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var print = console.log.bind(console);
|
var print = console.log.bind(console);
|
||||||
@@ -1683,6 +1699,7 @@ var_side_effects_3: {
|
|||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
pure_getters: true,
|
pure_getters: true,
|
||||||
unsafe: true,
|
unsafe: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var print = console.log.bind(console);
|
var print = console.log.bind(console);
|
||||||
@@ -1705,6 +1722,7 @@ var_side_effects_3: {
|
|||||||
reduce_vars_assign: {
|
reduce_vars_assign: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -1727,6 +1745,7 @@ reduce_vars_assign: {
|
|||||||
iife_1: {
|
iife_1: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -1747,6 +1766,7 @@ iife_1: {
|
|||||||
iife_2: {
|
iife_2: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
|
reduce_funcs: false,
|
||||||
reduce_vars: false,
|
reduce_vars: false,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: false,
|
unused: false,
|
||||||
@@ -1758,6 +1778,7 @@ iife_2: {
|
|||||||
}(foo);
|
}(foo);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
|
var foo;
|
||||||
!function(x) {
|
!function(x) {
|
||||||
console.log(x);
|
console.log(x);
|
||||||
}(bar());
|
}(bar());
|
||||||
@@ -2044,6 +2065,7 @@ ref_scope: {
|
|||||||
chained_1: {
|
chained_1: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var a = 2;
|
var a = 2;
|
||||||
@@ -2060,6 +2082,7 @@ chained_1: {
|
|||||||
chained_2: {
|
chained_2: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var a;
|
var a;
|
||||||
@@ -2160,6 +2183,7 @@ inner_lvalues: {
|
|||||||
double_def: {
|
double_def: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var a = x, a = a && y;
|
var a = x, a = a && y;
|
||||||
@@ -2174,6 +2198,7 @@ double_def: {
|
|||||||
toplevel_single_reference: {
|
toplevel_single_reference: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var a;
|
var a;
|
||||||
@@ -2183,9 +2208,10 @@ toplevel_single_reference: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var a;
|
for (var b in x) {
|
||||||
for (var b in x)
|
var a;
|
||||||
b(a = b);
|
b(a = b);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2193,6 +2219,7 @@ unused_orig: {
|
|||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
passes: 2,
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -2215,10 +2242,11 @@ unused_orig: {
|
|||||||
expect: {
|
expect: {
|
||||||
var a = 1;
|
var a = 1;
|
||||||
console.log(function(b) {
|
console.log(function(b) {
|
||||||
var a;
|
|
||||||
var c = b;
|
var c = b;
|
||||||
for (var d in c)
|
for (var d in c) {
|
||||||
|
var a;
|
||||||
return --b + (a = c[0]);
|
return --b + (a = c[0]);
|
||||||
|
}
|
||||||
a && a.NaN;
|
a && a.NaN;
|
||||||
}([2]), a);
|
}([2]), a);
|
||||||
}
|
}
|
||||||
@@ -2230,6 +2258,7 @@ issue_315: {
|
|||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
keep_fargs: false,
|
keep_fargs: false,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -2565,7 +2594,10 @@ issue_2250_1: {
|
|||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f(x) {
|
function f(x) {
|
||||||
@@ -2604,9 +2636,11 @@ issue_2250_2: {
|
|||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
passes: 2,
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
{
|
{
|
||||||
@@ -2632,6 +2666,7 @@ issue_2250_2: {
|
|||||||
issue_2298: {
|
issue_2298: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -2997,6 +3032,7 @@ issue_2364_5: {
|
|||||||
evaluate: true,
|
evaluate: true,
|
||||||
pure_getters: true,
|
pure_getters: true,
|
||||||
properties: true,
|
properties: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -3163,6 +3199,7 @@ pure_getters_chain: {
|
|||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
pure_getters: true,
|
pure_getters: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function o(t, r) {
|
function o(t, r) {
|
||||||
@@ -3183,6 +3220,7 @@ pure_getters_chain: {
|
|||||||
conditional_1: {
|
conditional_1: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f(a, b) {
|
function f(a, b) {
|
||||||
@@ -3207,6 +3245,7 @@ conditional_1: {
|
|||||||
conditional_2: {
|
conditional_2: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function f(a, b) {
|
function f(a, b) {
|
||||||
@@ -3223,3 +3262,141 @@ conditional_2: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "5 5"
|
expect_stdout: "5 5"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2425_1: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 8;
|
||||||
|
(function(b) {
|
||||||
|
b.toString();
|
||||||
|
})(--a, a |= 10);
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 8;
|
||||||
|
(function(b) {
|
||||||
|
b.toString();
|
||||||
|
})(--a, a |= 10);
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "15"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2425_2: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 8;
|
||||||
|
(function(b, c) {
|
||||||
|
b.toString();
|
||||||
|
})(--a, a |= 10);
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 8;
|
||||||
|
(function(b, c) {
|
||||||
|
b.toString();
|
||||||
|
})(--a, a |= 10);
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "15"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2425_3: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 8;
|
||||||
|
(function(b, b) {
|
||||||
|
b.toString();
|
||||||
|
})(--a, a |= 10);
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 8;
|
||||||
|
(function(b, b) {
|
||||||
|
(a |= 10).toString();
|
||||||
|
})(--a);
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "15"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2437: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
conditionals: true,
|
||||||
|
inline: true,
|
||||||
|
join_vars: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
sequences: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function foo() {
|
||||||
|
bar();
|
||||||
|
}
|
||||||
|
function bar() {
|
||||||
|
if (xhrDesc) {
|
||||||
|
var req = new XMLHttpRequest();
|
||||||
|
var result = !!req.onreadystatechange;
|
||||||
|
Object.defineProperty(XMLHttpRequest.prototype, 'onreadystatechange', xhrDesc || {});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var req = new XMLHttpRequest();
|
||||||
|
var detectFunc = function () { };
|
||||||
|
req.onreadystatechange = detectFunc;
|
||||||
|
var result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc;
|
||||||
|
req.onreadystatechange = null;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foo();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
!function() {
|
||||||
|
if (xhrDesc)
|
||||||
|
return result = !!(req = new XMLHttpRequest()).onreadystatechange,
|
||||||
|
Object.defineProperty(XMLHttpRequest.prototype, "onreadystatechange", xhrDesc || {}),
|
||||||
|
result;
|
||||||
|
var req = new XMLHttpRequest(), detectFunc = function() {};
|
||||||
|
req.onreadystatechange = detectFunc;
|
||||||
|
var result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc;
|
||||||
|
req.onreadystatechange = null;
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2453: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function log(n) {
|
||||||
|
console.log(n);
|
||||||
|
}
|
||||||
|
const a = 42;
|
||||||
|
log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function log(n) {
|
||||||
|
console.log(n);
|
||||||
|
}
|
||||||
|
const a = 42;
|
||||||
|
log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "42"
|
||||||
|
}
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ self_comparison_1: {
|
|||||||
self_comparison_2: {
|
self_comparison_2: {
|
||||||
options = {
|
options = {
|
||||||
comparisons: true,
|
comparisons: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ issue_1191: {
|
|||||||
join_vars : true,
|
join_vars : true,
|
||||||
sequences : false,
|
sequences : false,
|
||||||
collapse_vars : false,
|
collapse_vars : false,
|
||||||
|
reduce_funcs : true,
|
||||||
reduce_vars : true,
|
reduce_vars : true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -44,6 +45,7 @@ issue_1194: {
|
|||||||
join_vars : true,
|
join_vars : true,
|
||||||
sequences : false,
|
sequences : false,
|
||||||
collapse_vars : false,
|
collapse_vars : false,
|
||||||
|
reduce_funcs : true,
|
||||||
reduce_vars : true,
|
reduce_vars : true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -72,6 +74,7 @@ issue_1396: {
|
|||||||
join_vars : true,
|
join_vars : true,
|
||||||
sequences : false,
|
sequences : false,
|
||||||
collapse_vars : false,
|
collapse_vars : false,
|
||||||
|
reduce_funcs : true,
|
||||||
reduce_vars : true,
|
reduce_vars : true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -143,6 +146,7 @@ regexp_literal_not_const: {
|
|||||||
join_vars : true,
|
join_vars : true,
|
||||||
sequences : false,
|
sequences : false,
|
||||||
collapse_vars : false,
|
collapse_vars : false,
|
||||||
|
reduce_funcs : true,
|
||||||
reduce_vars : true,
|
reduce_vars : true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
|
|||||||
@@ -202,6 +202,7 @@ dead_code_const_declaration: {
|
|||||||
booleans : true,
|
booleans : true,
|
||||||
conditionals : true,
|
conditionals : true,
|
||||||
evaluate : true,
|
evaluate : true,
|
||||||
|
reduce_funcs : true,
|
||||||
reduce_vars : true,
|
reduce_vars : true,
|
||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
@@ -229,6 +230,7 @@ dead_code_const_annotation: {
|
|||||||
booleans : true,
|
booleans : true,
|
||||||
conditionals : true,
|
conditionals : true,
|
||||||
evaluate : true,
|
evaluate : true,
|
||||||
|
reduce_funcs : true,
|
||||||
reduce_vars : true,
|
reduce_vars : true,
|
||||||
toplevel : true,
|
toplevel : true,
|
||||||
};
|
};
|
||||||
@@ -281,6 +283,7 @@ dead_code_const_annotation_complex_scope: {
|
|||||||
booleans : true,
|
booleans : true,
|
||||||
conditionals : true,
|
conditionals : true,
|
||||||
evaluate : true,
|
evaluate : true,
|
||||||
|
reduce_funcs : true,
|
||||||
reduce_vars : true,
|
reduce_vars : true,
|
||||||
toplevel : true,
|
toplevel : true,
|
||||||
};
|
};
|
||||||
@@ -439,6 +442,7 @@ global_timeout_and_interval_symbols: {
|
|||||||
issue_2233_2: {
|
issue_2233_2: {
|
||||||
options = {
|
options = {
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
unsafe: true,
|
unsafe: true,
|
||||||
@@ -470,6 +474,7 @@ issue_2233_2: {
|
|||||||
issue_2233_3: {
|
issue_2233_3: {
|
||||||
options = {
|
options = {
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
|
|||||||
@@ -262,6 +262,7 @@ destructuring_dont_evaluate_with_undefined_as_default_assignment: {
|
|||||||
|
|
||||||
reduce_vars: {
|
reduce_vars: {
|
||||||
options = {
|
options = {
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
|
|||||||
@@ -733,6 +733,7 @@ drop_value: {
|
|||||||
const_assign: {
|
const_assign: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -785,6 +786,7 @@ issue_1539: {
|
|||||||
vardef_value: {
|
vardef_value: {
|
||||||
options = {
|
options = {
|
||||||
keep_fnames: false,
|
keep_fnames: false,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -846,6 +848,7 @@ assign_chain: {
|
|||||||
issue_1583: {
|
issue_1583: {
|
||||||
options = {
|
options = {
|
||||||
keep_fargs: true,
|
keep_fargs: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -1200,6 +1203,7 @@ var_catch_toplevel: {
|
|||||||
options = {
|
options = {
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
negate_iife: true,
|
negate_iife: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
@@ -1294,11 +1298,12 @@ issue_2063: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_2105: {
|
issue_2105_1: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
passes: 3,
|
passes: 3,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -1324,17 +1329,51 @@ issue_2105: {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
(function() {
|
({
|
||||||
var quux = function() {
|
prop: function() {
|
||||||
|
console.log;
|
||||||
console.log("PASS");
|
console.log("PASS");
|
||||||
};
|
}
|
||||||
return {
|
}).prop();
|
||||||
prop: function() {
|
}
|
||||||
console.log;
|
expect_stdout: "PASS"
|
||||||
quux();
|
}
|
||||||
|
|
||||||
|
issue_2105_2: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
inline: true,
|
||||||
|
passes: 3,
|
||||||
|
properties: true,
|
||||||
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unsafe: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
!function(factory) {
|
||||||
|
factory();
|
||||||
|
}( function() {
|
||||||
|
return function(fn) {
|
||||||
|
fn()().prop();
|
||||||
|
}( function() {
|
||||||
|
function bar() {
|
||||||
|
var quux = function() {
|
||||||
|
console.log("PASS");
|
||||||
|
}, foo = function() {
|
||||||
|
console.log;
|
||||||
|
quux();
|
||||||
|
};
|
||||||
|
return { prop: foo };
|
||||||
}
|
}
|
||||||
};
|
return bar;
|
||||||
})().prop();
|
} );
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log("PASS");
|
||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
@@ -1389,6 +1428,7 @@ issue_2136_3: {
|
|||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
passes: 3,
|
passes: 3,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
|
|||||||
@@ -345,6 +345,7 @@ unsafe_constant: {
|
|||||||
unsafe_object: {
|
unsafe_object: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unsafe: true,
|
unsafe: true,
|
||||||
@@ -373,6 +374,7 @@ unsafe_object: {
|
|||||||
unsafe_object_nested: {
|
unsafe_object_nested: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unsafe: true,
|
unsafe: true,
|
||||||
@@ -401,6 +403,7 @@ unsafe_object_nested: {
|
|||||||
unsafe_object_complex: {
|
unsafe_object_complex: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unsafe: true,
|
unsafe: true,
|
||||||
@@ -429,6 +432,7 @@ unsafe_object_complex: {
|
|||||||
unsafe_object_repeated: {
|
unsafe_object_repeated: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unsafe: true,
|
unsafe: true,
|
||||||
@@ -457,6 +461,7 @@ unsafe_object_repeated: {
|
|||||||
unsafe_object_accessor: {
|
unsafe_object_accessor: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unsafe: true,
|
unsafe: true,
|
||||||
}
|
}
|
||||||
@@ -757,6 +762,7 @@ call_args: {
|
|||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -779,6 +785,7 @@ call_args_drop_param: {
|
|||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
keep_fargs: false,
|
keep_fargs: false,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -1109,6 +1116,7 @@ Infinity_NaN_undefined_LHS: {
|
|||||||
issue_1964_1: {
|
issue_1964_1: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unsafe_regexp: false,
|
unsafe_regexp: false,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -1138,6 +1146,7 @@ issue_1964_1: {
|
|||||||
issue_1964_2: {
|
issue_1964_2: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unsafe_regexp: true,
|
unsafe_regexp: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -1294,6 +1303,7 @@ issue_2231_2: {
|
|||||||
self_comparison_1: {
|
self_comparison_1: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unsafe: true,
|
unsafe: true,
|
||||||
@@ -1314,6 +1324,7 @@ self_comparison_2: {
|
|||||||
evaluate: true,
|
evaluate: true,
|
||||||
hoist_props: true,
|
hoist_props: true,
|
||||||
passes: 2,
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
|
|||||||
@@ -124,6 +124,7 @@ async_func: {
|
|||||||
issue_2134_1: {
|
issue_2134_1: {
|
||||||
options = {
|
options = {
|
||||||
keep_fargs: false,
|
keep_fargs: false,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -141,6 +142,7 @@ issue_2134_1: {
|
|||||||
issue_2134_2: {
|
issue_2134_2: {
|
||||||
options = {
|
options = {
|
||||||
keep_fargs: false,
|
keep_fargs: false,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -250,3 +252,13 @@ dynamic_import: {
|
|||||||
r.foo();
|
r.foo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trailing_comma: {
|
||||||
|
beautify = {
|
||||||
|
beautify: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
export const a = 1;
|
||||||
|
}
|
||||||
|
expect_exact: "export const a = 1;"
|
||||||
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ iifes_returning_constants_keep_fargs_true: {
|
|||||||
booleans : true,
|
booleans : true,
|
||||||
if_return : true,
|
if_return : true,
|
||||||
join_vars : true,
|
join_vars : true,
|
||||||
|
reduce_funcs : true,
|
||||||
reduce_vars : true,
|
reduce_vars : true,
|
||||||
cascade : true,
|
cascade : true,
|
||||||
inline : true,
|
inline : true,
|
||||||
@@ -55,6 +56,7 @@ iifes_returning_constants_keep_fargs_false: {
|
|||||||
booleans : true,
|
booleans : true,
|
||||||
if_return : true,
|
if_return : true,
|
||||||
join_vars : true,
|
join_vars : true,
|
||||||
|
reduce_funcs : true,
|
||||||
reduce_vars : true,
|
reduce_vars : true,
|
||||||
cascade : true,
|
cascade : true,
|
||||||
inline : true,
|
inline : true,
|
||||||
@@ -101,6 +103,7 @@ issue_1841_1: {
|
|||||||
options = {
|
options = {
|
||||||
keep_fargs: false,
|
keep_fargs: false,
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -127,6 +130,7 @@ issue_1841_2: {
|
|||||||
options = {
|
options = {
|
||||||
keep_fargs: false,
|
keep_fargs: false,
|
||||||
pure_getters: false,
|
pure_getters: false,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -154,6 +158,7 @@ function_returning_constant_literal: {
|
|||||||
inline: true,
|
inline: true,
|
||||||
passes: 2,
|
passes: 2,
|
||||||
properties: true,
|
properties: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
@@ -305,6 +310,7 @@ issue_2084: {
|
|||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
passes: 2,
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
@@ -340,6 +346,7 @@ issue_2084: {
|
|||||||
issue_2097: {
|
issue_2097: {
|
||||||
options = {
|
options = {
|
||||||
negate_iife: true,
|
negate_iife: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -508,3 +515,42 @@ issue_2114_2: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "2"
|
expect_stdout: "2"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2428: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
inline: true,
|
||||||
|
passes: 3,
|
||||||
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
unsafe: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function bar(k) {
|
||||||
|
console.log(k);
|
||||||
|
}
|
||||||
|
function foo(x) {
|
||||||
|
return bar(x);
|
||||||
|
}
|
||||||
|
function baz(a) {
|
||||||
|
foo(a);
|
||||||
|
}
|
||||||
|
baz(42);
|
||||||
|
baz("PASS");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function baz(a) {
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
baz(42);
|
||||||
|
baz("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"42",
|
||||||
|
"PASS",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|||||||
@@ -736,6 +736,7 @@ object_spread_unsafe: {
|
|||||||
evaluate: true,
|
evaluate: true,
|
||||||
join_vars: true,
|
join_vars: true,
|
||||||
passes: 3,
|
passes: 3,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
@@ -903,6 +904,7 @@ issue_2349b: {
|
|||||||
inline: true,
|
inline: true,
|
||||||
passes: 3,
|
passes: 3,
|
||||||
properties: true,
|
properties: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ issue_2377_1: {
|
|||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
hoist_props: true,
|
hoist_props: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -35,6 +36,7 @@ issue_2377_2: {
|
|||||||
inline: true,
|
inline: true,
|
||||||
hoist_props: true,
|
hoist_props: true,
|
||||||
passes: 2,
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -66,6 +68,7 @@ issue_2377_3: {
|
|||||||
inline: true,
|
inline: true,
|
||||||
hoist_props: true,
|
hoist_props: true,
|
||||||
passes: 3,
|
passes: 3,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -92,6 +95,7 @@ issue_2377_3: {
|
|||||||
direct_access_1: {
|
direct_access_1: {
|
||||||
options = {
|
options = {
|
||||||
hoist_props: true,
|
hoist_props: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -120,6 +124,7 @@ direct_access_1: {
|
|||||||
direct_access_2: {
|
direct_access_2: {
|
||||||
options = {
|
options = {
|
||||||
hoist_props: true,
|
hoist_props: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -143,6 +148,7 @@ direct_access_2: {
|
|||||||
direct_access_3: {
|
direct_access_3: {
|
||||||
options = {
|
options = {
|
||||||
hoist_props: true,
|
hoist_props: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -163,6 +169,7 @@ direct_access_3: {
|
|||||||
single_use: {
|
single_use: {
|
||||||
options = {
|
options = {
|
||||||
hoist_props: true,
|
hoist_props: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -187,6 +194,7 @@ single_use: {
|
|||||||
name_collision_1: {
|
name_collision_1: {
|
||||||
options = {
|
options = {
|
||||||
hoist_props: true,
|
hoist_props: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
}
|
}
|
||||||
@@ -224,6 +232,7 @@ name_collision_1: {
|
|||||||
name_collision_2: {
|
name_collision_2: {
|
||||||
options = {
|
options = {
|
||||||
hoist_props: true,
|
hoist_props: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
}
|
}
|
||||||
@@ -257,6 +266,7 @@ name_collision_2: {
|
|||||||
name_collision_3: {
|
name_collision_3: {
|
||||||
options = {
|
options = {
|
||||||
hoist_props: true,
|
hoist_props: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
}
|
}
|
||||||
@@ -293,6 +303,7 @@ contains_this_1: {
|
|||||||
hoist_props: true,
|
hoist_props: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
passes: 2,
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -318,6 +329,7 @@ contains_this_2: {
|
|||||||
hoist_props: true,
|
hoist_props: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
passes: 2,
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -345,6 +357,7 @@ contains_this_3: {
|
|||||||
hoist_props: true,
|
hoist_props: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
passes: 2,
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -369,3 +382,169 @@ contains_this_3: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "1 1 true"
|
expect_stdout: "1 1 true"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hoist_class: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
evaluate: true,
|
||||||
|
hoist_props: true,
|
||||||
|
inline: true,
|
||||||
|
keep_fnames: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function run(c, v) {
|
||||||
|
return new c(v).value;
|
||||||
|
}
|
||||||
|
var o = {
|
||||||
|
p: class Foo {
|
||||||
|
constructor(value) {
|
||||||
|
this.value = value * 10;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
x: 1,
|
||||||
|
y: 2,
|
||||||
|
};
|
||||||
|
console.log(o.p.name, o.p === o.p, run(o.p, o.x), run(o.p, o.y));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function run(c, v) {
|
||||||
|
return new c(v).value;
|
||||||
|
}
|
||||||
|
var o_p = class Foo {
|
||||||
|
constructor(value) {
|
||||||
|
this.value = 10 * value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
console.log(o_p.name, true, run(o_p, 1), run(o_p, 2));
|
||||||
|
}
|
||||||
|
node_version: ">=6"
|
||||||
|
expect_stdout: "Foo true 10 20"
|
||||||
|
}
|
||||||
|
|
||||||
|
hoist_class_with_new: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
evaluate: true,
|
||||||
|
hoist_props: true,
|
||||||
|
inline: true,
|
||||||
|
keep_fnames: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {
|
||||||
|
p: class Foo {
|
||||||
|
constructor(value) {
|
||||||
|
this.value = value * 10;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
x: 1,
|
||||||
|
y: 2,
|
||||||
|
};
|
||||||
|
console.log(o.p.name, o.p === o.p, new o.p(o.x).value, new o.p(o.y).value);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
// FIXME: class `o.p` not hoisted due to `new`
|
||||||
|
var o = {
|
||||||
|
p: class Foo {
|
||||||
|
constructor(value) {
|
||||||
|
this.value = 10 * value;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
x: 1,
|
||||||
|
y: 2
|
||||||
|
};
|
||||||
|
console.log(o.p.name, o.p == o.p, new o.p(o.x).value, new o.p(o.y).value);
|
||||||
|
}
|
||||||
|
node_version: ">=6"
|
||||||
|
expect_stdout: "Foo true 10 20"
|
||||||
|
}
|
||||||
|
|
||||||
|
hoist_function_with_call: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
evaluate: true,
|
||||||
|
hoist_props: true,
|
||||||
|
inline: true,
|
||||||
|
keep_fnames: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {
|
||||||
|
p: function Foo(value) {
|
||||||
|
return 10 * value;
|
||||||
|
},
|
||||||
|
x: 1,
|
||||||
|
y: 2
|
||||||
|
};
|
||||||
|
console.log(o.p.name, o.p === o.p, o.p(o.x), o.p(o.y));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var o_p = function Foo(value){
|
||||||
|
return 10 * value
|
||||||
|
};
|
||||||
|
console.log(o_p.name, true, o_p(1), o_p(2));
|
||||||
|
}
|
||||||
|
expect_stdout: "Foo true 10 20"
|
||||||
|
}
|
||||||
|
|
||||||
|
new_this: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
hoist_props: true,
|
||||||
|
inline: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {
|
||||||
|
a: 1,
|
||||||
|
b: 2,
|
||||||
|
f: function(a) {
|
||||||
|
this.b = a;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
console.log(new o.f(o.a).b, o.b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(new function(a) {
|
||||||
|
this.b = a;
|
||||||
|
}(1).b, 2);
|
||||||
|
}
|
||||||
|
expect_stdout: "1 2"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2462: {
|
||||||
|
options = {
|
||||||
|
hoist_props: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
export const Foo = {
|
||||||
|
a: 1,
|
||||||
|
b: () => 2
|
||||||
|
};
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
export const Foo = {
|
||||||
|
a: 1,
|
||||||
|
b: () => 2
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ const_declaration: {
|
|||||||
const_pragma: {
|
const_pragma: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -29,6 +30,7 @@ const_pragma: {
|
|||||||
not_const: {
|
not_const: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ chained_evaluation_1: {
|
|||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -28,6 +29,7 @@ chained_evaluation_2: {
|
|||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ f7: {
|
|||||||
negate_iife: true,
|
negate_iife: true,
|
||||||
passes: 3,
|
passes: 3,
|
||||||
properties: true,
|
properties: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
side_effects_catch: {
|
side_effects_catch: {
|
||||||
options = {
|
options = {
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -34,6 +35,7 @@ side_effects_catch: {
|
|||||||
|
|
||||||
side_effects_else: {
|
side_effects_else: {
|
||||||
options = {
|
options = {
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -62,6 +64,7 @@ side_effects_else: {
|
|||||||
|
|
||||||
side_effects_finally: {
|
side_effects_finally: {
|
||||||
options = {
|
options = {
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -98,6 +101,7 @@ side_effects_finally: {
|
|||||||
|
|
||||||
side_effects_label: {
|
side_effects_label: {
|
||||||
options = {
|
options = {
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -130,6 +134,7 @@ side_effects_label: {
|
|||||||
|
|
||||||
side_effects_switch: {
|
side_effects_switch: {
|
||||||
options = {
|
options = {
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ unary_prefix: {
|
|||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
iife_for: {
|
iife_for: {
|
||||||
options = {
|
options = {
|
||||||
negate_iife: true,
|
negate_iife: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -26,6 +27,7 @@ iife_for: {
|
|||||||
iife_for_in: {
|
iife_for_in: {
|
||||||
options = {
|
options = {
|
||||||
negate_iife: true,
|
negate_iife: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -51,6 +53,7 @@ iife_for_in: {
|
|||||||
iife_do: {
|
iife_do: {
|
||||||
options = {
|
options = {
|
||||||
negate_iife: true,
|
negate_iife: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -80,6 +83,7 @@ iife_do: {
|
|||||||
iife_while: {
|
iife_while: {
|
||||||
options = {
|
options = {
|
||||||
negate_iife: true,
|
negate_iife: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
|
|||||||
@@ -177,6 +177,7 @@ export_mangle_2: {
|
|||||||
export_mangle_3: {
|
export_mangle_3: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
mangle = {
|
mangle = {
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
@@ -195,6 +196,7 @@ export_mangle_3: {
|
|||||||
export_mangle_4: {
|
export_mangle_4: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
|
unused: true,
|
||||||
}
|
}
|
||||||
mangle = {
|
mangle = {
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ collapse_vars_constants: {
|
|||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -240,6 +241,7 @@ negate_iife_issue_1073: {
|
|||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
negate_iife: true,
|
negate_iife: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -267,6 +269,7 @@ issue_1288_side_effects: {
|
|||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
negate_iife: true,
|
negate_iife: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -299,6 +302,7 @@ inner_var_for_in_1: {
|
|||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -330,6 +334,7 @@ issue_1595_3: {
|
|||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
passes: 2,
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ this_binding_collapse_vars: {
|
|||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
};
|
};
|
||||||
input: {
|
input: {
|
||||||
var c = a; c();
|
var c = a; c();
|
||||||
|
|||||||
@@ -940,6 +940,7 @@ methods_keep_quoted_from_dead_code: {
|
|||||||
dead_code: true,
|
dead_code: true,
|
||||||
ecma: 6,
|
ecma: 6,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
unsafe_methods: true,
|
unsafe_methods: true,
|
||||||
@@ -1085,6 +1086,7 @@ lhs_prop_2: {
|
|||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
properties: true,
|
properties: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -1131,6 +1133,7 @@ prop_side_effects_1: {
|
|||||||
evaluate: true,
|
evaluate: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
properties: true,
|
properties: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
@@ -1167,6 +1170,7 @@ prop_side_effects_2: {
|
|||||||
inline: true,
|
inline: true,
|
||||||
passes: 2,
|
passes: 2,
|
||||||
properties: true,
|
properties: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
@@ -1282,3 +1286,22 @@ computed_property: {
|
|||||||
]
|
]
|
||||||
node_version: ">=4"
|
node_version: ">=4"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new_this: {
|
||||||
|
options = {
|
||||||
|
properties: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
new {
|
||||||
|
f: function(a) {
|
||||||
|
this.a = a;
|
||||||
|
}
|
||||||
|
}.f(42);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
new function(a) {
|
||||||
|
this.a = a;
|
||||||
|
}(42);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
strict: {
|
strict: {
|
||||||
options = {
|
options = {
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: false,
|
||||||
reduce_vars: false,
|
reduce_vars: false,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
@@ -30,6 +31,7 @@ strict: {
|
|||||||
strict_reduce_vars: {
|
strict_reduce_vars: {
|
||||||
options = {
|
options = {
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
@@ -58,6 +60,7 @@ strict_reduce_vars: {
|
|||||||
unsafe: {
|
unsafe: {
|
||||||
options = {
|
options = {
|
||||||
pure_getters: true,
|
pure_getters: true,
|
||||||
|
reduce_funcs: false,
|
||||||
reduce_vars: false,
|
reduce_vars: false,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
@@ -84,6 +87,7 @@ unsafe: {
|
|||||||
unsafe_reduce_vars: {
|
unsafe_reduce_vars: {
|
||||||
options = {
|
options = {
|
||||||
pure_getters: true,
|
pure_getters: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
@@ -185,6 +189,7 @@ issue_2110_1: {
|
|||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -215,6 +220,7 @@ issue_2110_2: {
|
|||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -247,6 +253,7 @@ set_immutable_1: {
|
|||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -270,6 +277,7 @@ set_immutable_2: {
|
|||||||
cascade: true,
|
cascade: true,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
@@ -293,6 +301,7 @@ set_immutable_3: {
|
|||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -318,6 +327,7 @@ set_immutable_4: {
|
|||||||
cascade: true,
|
cascade: true,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
@@ -343,6 +353,7 @@ set_mutable_1: {
|
|||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -367,6 +378,7 @@ set_mutable_2: {
|
|||||||
cascade: true,
|
cascade: true,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
@@ -403,6 +415,7 @@ issue_2265_1: {
|
|||||||
issue_2265_2: {
|
issue_2265_2: {
|
||||||
options = {
|
options = {
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
@@ -428,6 +441,7 @@ issue_2265_2: {
|
|||||||
issue_2265_3: {
|
issue_2265_3: {
|
||||||
options = {
|
options = {
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
@@ -447,6 +461,7 @@ issue_2265_3: {
|
|||||||
issue_2265_4: {
|
issue_2265_4: {
|
||||||
options = {
|
options = {
|
||||||
pure_getters: "strict",
|
pure_getters: "strict",
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -187,6 +187,7 @@ dont_screw_try_catch_undefined: {
|
|||||||
reduce_vars: {
|
reduce_vars: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
ie8: true,
|
ie8: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
|
|||||||
@@ -714,6 +714,7 @@ issue_1705_2: {
|
|||||||
options = {
|
options = {
|
||||||
dead_code: true,
|
dead_code: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
|
|||||||
@@ -328,4 +328,36 @@ describe("minify", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("collapse_vars", function() {
|
||||||
|
it("Should not produce invalid AST", function() {
|
||||||
|
var code = [
|
||||||
|
"function f(a) {",
|
||||||
|
" a = x();",
|
||||||
|
" return a;",
|
||||||
|
"}",
|
||||||
|
"f();",
|
||||||
|
].join("\n");
|
||||||
|
var ast = Uglify.minify(code, {
|
||||||
|
compress: false,
|
||||||
|
mangle: false,
|
||||||
|
output: {
|
||||||
|
ast: true
|
||||||
|
},
|
||||||
|
}).ast;
|
||||||
|
assert.strictEqual(ast.TYPE, "Toplevel");
|
||||||
|
assert.strictEqual(ast.body.length, 2);
|
||||||
|
assert.strictEqual(ast.body[0].TYPE, "Defun");
|
||||||
|
assert.strictEqual(ast.body[0].body.length, 2);
|
||||||
|
assert.strictEqual(ast.body[0].body[0].TYPE, "SimpleStatement");
|
||||||
|
var stat = ast.body[0].body[0];
|
||||||
|
Uglify.minify(ast, {
|
||||||
|
compress: {
|
||||||
|
sequences: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
assert.ok(stat.body);
|
||||||
|
assert.strictEqual(stat.print_to_string(), "a=x()");
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -162,6 +162,7 @@ var VALUES = [
|
|||||||
'"object"',
|
'"object"',
|
||||||
'"number"',
|
'"number"',
|
||||||
'"function"',
|
'"function"',
|
||||||
|
'this',
|
||||||
];
|
];
|
||||||
|
|
||||||
var BINARY_OPS_NO_COMMA = [
|
var BINARY_OPS_NO_COMMA = [
|
||||||
@@ -349,10 +350,10 @@ function createParams() {
|
|||||||
return params.join(', ');
|
return params.join(', ');
|
||||||
}
|
}
|
||||||
|
|
||||||
function createArgs() {
|
function createArgs(recurmax, stmtDepth, canThrow) {
|
||||||
var args = [];
|
var args = [];
|
||||||
for (var n = rng(4); --n >= 0;) {
|
for (var n = rng(4); --n >= 0;) {
|
||||||
args.push(createValue());
|
args.push(rng(2) ? createValue() : createExpression(recurmax - 1, COMMA_OK, stmtDepth, canThrow));
|
||||||
}
|
}
|
||||||
return args.join(', ');
|
return args.join(', ');
|
||||||
}
|
}
|
||||||
@@ -390,9 +391,10 @@ function createFunction(recurmax, inGlobal, noDecl, canThrow, stmtDepth) {
|
|||||||
|
|
||||||
VAR_NAMES.length = namesLenBefore;
|
VAR_NAMES.length = namesLenBefore;
|
||||||
|
|
||||||
if (noDecl) s = 'var ' + createVarName(MANDATORY) + ' = ' + s + '(' + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ');';
|
if (noDecl) s = 'var ' + createVarName(MANDATORY) + ' = ' + s;
|
||||||
// avoid "function statements" (decl inside statements)
|
// avoid "function statements" (decl inside statements)
|
||||||
else if (inGlobal || rng(10) > 0) s += 'var ' + createVarName(MANDATORY) + ' = ' + name + '(' + createArgs() + ');';
|
else if (inGlobal || rng(10) > 0) s += 'var ' + createVarName(MANDATORY) + ' = ' + name;
|
||||||
|
s += '(' + createArgs(recurmax, stmtDepth, canThrow) + ');';
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
@@ -626,6 +628,9 @@ function _createExpression(recurmax, noComma, stmtDepth, canThrow) {
|
|||||||
case p++:
|
case p++:
|
||||||
case p++:
|
case p++:
|
||||||
return createValue();
|
return createValue();
|
||||||
|
case p++:
|
||||||
|
case p++:
|
||||||
|
return getVarName();
|
||||||
case p++:
|
case p++:
|
||||||
return createExpression(recurmax, COMMA_OK, stmtDepth, canThrow);
|
return createExpression(recurmax, COMMA_OK, stmtDepth, canThrow);
|
||||||
case p++:
|
case p++:
|
||||||
|
|||||||
Reference in New Issue
Block a user