@@ -4638,7 +4638,7 @@ merge(Compressor.prototype, {
|
|||||||
if (self.name && self.name.definition() === fn.definition()) break;
|
if (self.name && self.name.definition() === fn.definition()) break;
|
||||||
fn = fn.fixed_value();
|
fn = fn.fixed_value();
|
||||||
}
|
}
|
||||||
if (!(fn instanceof AST_Lambda)) break;
|
if (!(fn instanceof AST_Defun || fn instanceof AST_Function)) break;
|
||||||
if (fn.uses_arguments) break;
|
if (fn.uses_arguments) break;
|
||||||
if (fn === call.expression) {
|
if (fn === call.expression) {
|
||||||
if (fn.parent_scope !== self) break;
|
if (fn.parent_scope !== self) break;
|
||||||
@@ -7776,7 +7776,9 @@ merge(Compressor.prototype, {
|
|||||||
var_assigned = true;
|
var_assigned = true;
|
||||||
if (stat) return false;
|
if (stat) return false;
|
||||||
}
|
}
|
||||||
} else if (line instanceof AST_Defun || line instanceof AST_EmptyStatement) {
|
} else if (line instanceof AST_AsyncDefun
|
||||||
|
|| line instanceof AST_Defun
|
||||||
|
|| line instanceof AST_EmptyStatement) {
|
||||||
continue;
|
continue;
|
||||||
} else if (stat) {
|
} else if (stat) {
|
||||||
return false;
|
return false;
|
||||||
@@ -7803,6 +7805,7 @@ merge(Compressor.prototype, {
|
|||||||
var begin;
|
var begin;
|
||||||
var in_order = [];
|
var in_order = [];
|
||||||
var side_effects = false;
|
var side_effects = false;
|
||||||
|
var verify_await = true;
|
||||||
value.walk(new TreeWalker(function(node, descend) {
|
value.walk(new TreeWalker(function(node, descend) {
|
||||||
if (abort) return true;
|
if (abort) return true;
|
||||||
if (node instanceof AST_Binary && lazy_op[node.operator]
|
if (node instanceof AST_Binary && lazy_op[node.operator]
|
||||||
@@ -7811,13 +7814,18 @@ merge(Compressor.prototype, {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (node instanceof AST_Scope) return abort = true;
|
if (node instanceof AST_Scope) return abort = true;
|
||||||
|
if (verify_await && node instanceof AST_Symbol && node.name == "await") {
|
||||||
|
var scope = compressor.find_parent(AST_Scope);
|
||||||
|
if (scope instanceof AST_AsyncDefun || scope instanceof AST_AsyncFunction) return abort = true;
|
||||||
|
verify_await = false;
|
||||||
|
}
|
||||||
if (node instanceof AST_SymbolRef) {
|
if (node instanceof AST_SymbolRef) {
|
||||||
var def = node.definition();
|
var def = node.definition();
|
||||||
if (fn.variables.get(node.name) !== def) {
|
if (fn.variables.get(node.name) !== def) {
|
||||||
in_order = null;
|
in_order = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (def.init instanceof AST_Defun) return abort = true;
|
if (def.init instanceof AST_AsyncDefun || def.init instanceof AST_Defun) return abort = true;
|
||||||
if (is_lhs(node, this.parent())) return abort = true;
|
if (is_lhs(node, this.parent())) return abort = true;
|
||||||
var index = resolve_index(def);
|
var index = resolve_index(def);
|
||||||
if (!(begin < index)) begin = index;
|
if (!(begin < index)) begin = index;
|
||||||
@@ -7868,7 +7876,7 @@ merge(Compressor.prototype, {
|
|||||||
function can_inject_vars(defined, used, safe_to_inject) {
|
function can_inject_vars(defined, used, 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 (stat instanceof AST_AsyncDefun || stat instanceof AST_Defun) {
|
||||||
if (!safe_to_inject || var_exists(used, stat.name.name)) return false;
|
if (!safe_to_inject || var_exists(used, stat.name.name)) return false;
|
||||||
if (!all(stat.enclosed, function(def) {
|
if (!all(stat.enclosed, function(def) {
|
||||||
return def.scope === stat || !defined[def.name];
|
return def.scope === stat || !defined[def.name];
|
||||||
@@ -7890,7 +7898,7 @@ merge(Compressor.prototype, {
|
|||||||
var defined = Object.create(null);
|
var defined = Object.create(null);
|
||||||
var level = 0, child;
|
var level = 0, child;
|
||||||
scope = compressor.self();
|
scope = compressor.self();
|
||||||
while (!(scope instanceof AST_Scope)) {
|
do {
|
||||||
if (scope.variables) scope.variables.each(function(def) {
|
if (scope.variables) scope.variables.each(function(def) {
|
||||||
defined[def.name] = true;
|
defined[def.name] = true;
|
||||||
});
|
});
|
||||||
@@ -7908,11 +7916,25 @@ merge(Compressor.prototype, {
|
|||||||
} else if (scope instanceof AST_SymbolRef) {
|
} else if (scope instanceof AST_SymbolRef) {
|
||||||
if (scope.fixed_value() instanceof AST_Scope) return false;
|
if (scope.fixed_value() instanceof AST_Scope) return false;
|
||||||
}
|
}
|
||||||
}
|
} while (!(scope instanceof AST_Scope));
|
||||||
insert = scope.body.indexOf(child) + 1;
|
insert = scope.body.indexOf(child) + 1;
|
||||||
if (!insert) return false;
|
if (!insert) return false;
|
||||||
|
if (scope instanceof AST_AsyncDefun || scope instanceof AST_AsyncFunction) {
|
||||||
|
var found = false;
|
||||||
|
fn.walk(new TreeWalker(function(node) {
|
||||||
|
if (found) return true;
|
||||||
|
if (node instanceof AST_Scope && node !== fn) {
|
||||||
|
if (node instanceof AST_AsyncDefun || node instanceof AST_Defun) {
|
||||||
|
if (node.name.name == "await") found = true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (node instanceof AST_Symbol && node.name == "await" && node !== fn.name) return found = true;
|
||||||
|
}));
|
||||||
|
if (found) return false;
|
||||||
|
}
|
||||||
var safe_to_inject = (!(scope instanceof AST_Toplevel) || compressor.toplevel.vars)
|
var safe_to_inject = (!(scope instanceof AST_Toplevel) || compressor.toplevel.vars)
|
||||||
&& (exp !== fn || fn.parent_scope.resolve() === compressor.find_parent(AST_Scope));
|
&& (exp !== fn || fn.parent_scope.resolve() === scope);
|
||||||
var inline = compressor.option("inline");
|
var inline = compressor.option("inline");
|
||||||
var used = Object.create(defined);
|
var used = Object.create(defined);
|
||||||
if (!can_inject_args(defined, used, inline >= 2 && safe_to_inject)) return false;
|
if (!can_inject_args(defined, used, inline >= 2 && safe_to_inject)) return false;
|
||||||
@@ -8004,7 +8026,7 @@ merge(Compressor.prototype, {
|
|||||||
flatten_vars(decls, expressions);
|
flatten_vars(decls, expressions);
|
||||||
expressions.push(value);
|
expressions.push(value);
|
||||||
var args = fn.body.filter(function(stat) {
|
var args = fn.body.filter(function(stat) {
|
||||||
if (stat instanceof AST_Defun) {
|
if (stat instanceof AST_AsyncDefun || stat instanceof AST_Defun) {
|
||||||
var def = stat.name.definition();
|
var def = stat.name.definition();
|
||||||
scope.functions.set(def.name, def);
|
scope.functions.set(def.name, def);
|
||||||
scope.variables.set(def.name, def);
|
scope.variables.set(def.name, def);
|
||||||
|
|||||||
@@ -216,3 +216,51 @@ collapse_vars_3: {
|
|||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
node_version: ">=8"
|
node_version: ">=8"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_4335_1: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var await = "PASS";
|
||||||
|
(async function() {
|
||||||
|
console.log(function() {
|
||||||
|
return await;
|
||||||
|
}());
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var await = "PASS";
|
||||||
|
(async function() {
|
||||||
|
console.log(function() {
|
||||||
|
return await;
|
||||||
|
}());
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
node_version: ">=8"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_4335_2: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(async function() {
|
||||||
|
console.log(function() {
|
||||||
|
function await() {}
|
||||||
|
return "PASS";
|
||||||
|
}());
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(async function() {
|
||||||
|
console.log(function() {
|
||||||
|
function await() {}
|
||||||
|
return "PASS";
|
||||||
|
}());
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
node_version: ">=8"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user