@@ -1287,7 +1287,9 @@ merge(Compressor.prototype, {
|
|||||||
if (node instanceof AST_Try) return true;
|
if (node instanceof AST_Try) return true;
|
||||||
if (node instanceof AST_With) return true;
|
if (node instanceof AST_With) return true;
|
||||||
if (replace_all) return false;
|
if (replace_all) return false;
|
||||||
return node instanceof AST_SymbolRef && !node.is_declared(compressor);
|
return node instanceof AST_SymbolRef
|
||||||
|
&& !node.is_declared(compressor)
|
||||||
|
&& !(parent instanceof AST_Assign && parent.left === node);
|
||||||
}
|
}
|
||||||
|
|
||||||
function in_conditional(node, parent) {
|
function in_conditional(node, parent) {
|
||||||
@@ -5102,7 +5104,7 @@ merge(Compressor.prototype, {
|
|||||||
})) {
|
})) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (line instanceof AST_EmptyStatement) {
|
} else if (line instanceof AST_Defun || line instanceof AST_EmptyStatement) {
|
||||||
continue;
|
continue;
|
||||||
} else if (stat) {
|
} else if (stat) {
|
||||||
return false;
|
return false;
|
||||||
@@ -5113,16 +5115,15 @@ merge(Compressor.prototype, {
|
|||||||
return return_value(stat);
|
return return_value(stat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function var_exists(catches, name) {
|
||||||
|
return catches[name] || identifier_atom[name] || scope.var_names()[name];
|
||||||
|
}
|
||||||
|
|
||||||
function can_inject_args(catches, safe_to_inject) {
|
function can_inject_args(catches, safe_to_inject) {
|
||||||
for (var i = 0; i < fn.argnames.length; i++) {
|
for (var i = 0; i < fn.argnames.length; i++) {
|
||||||
var arg = fn.argnames[i];
|
var arg = fn.argnames[i];
|
||||||
if (arg.__unused) continue;
|
if (arg.__unused) continue;
|
||||||
if (!safe_to_inject
|
if (!safe_to_inject || var_exists(catches, arg.name)) return false;
|
||||||
|| catches[arg.name]
|
|
||||||
|| identifier_atom[arg.name]
|
|
||||||
|| scope.var_names()[arg.name]) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (in_loop) in_loop.push(arg.definition());
|
if (in_loop) in_loop.push(arg.definition());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -5131,15 +5132,15 @@ merge(Compressor.prototype, {
|
|||||||
function can_inject_vars(catches, safe_to_inject) {
|
function can_inject_vars(catches, safe_to_inject) {
|
||||||
for (var i = 0; i < fn.body.length; i++) {
|
for (var i = 0; i < fn.body.length; i++) {
|
||||||
var stat = fn.body[i];
|
var stat = fn.body[i];
|
||||||
|
if (stat instanceof AST_Defun) {
|
||||||
|
if (!safe_to_inject || var_exists(catches, stat.name.name)) return false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (!(stat instanceof AST_Var)) continue;
|
if (!(stat instanceof AST_Var)) continue;
|
||||||
if (!safe_to_inject) return false;
|
if (!safe_to_inject) return false;
|
||||||
for (var j = stat.definitions.length; --j >= 0;) {
|
for (var j = stat.definitions.length; --j >= 0;) {
|
||||||
var name = stat.definitions[j].name;
|
var name = stat.definitions[j].name;
|
||||||
if (catches[name.name]
|
if (var_exists(catches, name.name)) return false;
|
||||||
|| identifier_atom[name.name]
|
|
||||||
|| scope.var_names()[name.name]) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (in_loop) in_loop.push(name.definition());
|
if (in_loop) in_loop.push(name.definition());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5243,12 +5244,21 @@ merge(Compressor.prototype, {
|
|||||||
flatten_args(decls, expressions);
|
flatten_args(decls, expressions);
|
||||||
flatten_vars(decls, expressions);
|
flatten_vars(decls, expressions);
|
||||||
expressions.push(value);
|
expressions.push(value);
|
||||||
if (decls.length) {
|
var args = fn.body.filter(function(stat) {
|
||||||
i = scope.body.indexOf(compressor.parent(level - 1)) + 1;
|
if (stat instanceof AST_Defun) {
|
||||||
scope.body.splice(i, 0, make_node(AST_Var, fn, {
|
var def = stat.name.definition();
|
||||||
definitions: decls
|
scope.functions.set(def.name, def);
|
||||||
}));
|
scope.variables.set(def.name, def);
|
||||||
}
|
scope.enclosed.push(def);
|
||||||
|
scope.var_names()[def.name] = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
args.unshift(scope.body.indexOf(compressor.parent(level - 1)) + 1, 0);
|
||||||
|
if (decls.length) args.push(make_node(AST_Var, fn, {
|
||||||
|
definitions: decls
|
||||||
|
}));
|
||||||
|
[].splice.apply(scope.body, args);
|
||||||
return expressions;
|
return expressions;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6157,3 +6157,24 @@ sub_property: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assign_undeclared: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var A = (console.log(42), function() {});
|
||||||
|
B = new A();
|
||||||
|
console.log(typeof B);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
B = new (console.log(42), function() {})();
|
||||||
|
console.log(typeof B);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"42",
|
||||||
|
"object",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|||||||
@@ -3003,12 +3003,10 @@ issue_3366: {
|
|||||||
f();
|
f();
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
(function() {
|
void function() {
|
||||||
function a() {}
|
this && a && console.log("PASS");
|
||||||
(function() {
|
}();
|
||||||
this && a && console.log("PASS");
|
function a() {}
|
||||||
})();
|
|
||||||
})();
|
|
||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
@@ -3041,3 +3039,29 @@ issue_3371: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "function"
|
expect_stdout: "function"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class_iife: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
sequences: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var A = function() {
|
||||||
|
function B() {}
|
||||||
|
B.prototype.m = function() {
|
||||||
|
console.log("PASS");
|
||||||
|
};
|
||||||
|
return B;
|
||||||
|
}();
|
||||||
|
new A().m();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var A = (B.prototype.m = function() {
|
||||||
|
console.log("PASS");
|
||||||
|
}, B);
|
||||||
|
function B() {}
|
||||||
|
new A().m();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user