fix corner case in hoist_funs (#4790)
This commit is contained in:
@@ -6801,21 +6801,25 @@ merge(Compressor.prototype, {
|
|||||||
var dirs = [];
|
var dirs = [];
|
||||||
var hoisted = [];
|
var hoisted = [];
|
||||||
var vars = new Dictionary(), vars_found = 0;
|
var vars = new Dictionary(), vars_found = 0;
|
||||||
var tt = new TreeTransformer(function(node) {
|
var tt = new TreeTransformer(function(node, descend, in_list) {
|
||||||
if (node === self) return;
|
if (node === self) return;
|
||||||
if (node instanceof AST_Directive) {
|
if (node instanceof AST_Directive) {
|
||||||
dirs.push(node);
|
dirs.push(node);
|
||||||
return make_node(AST_EmptyStatement, node);
|
return in_list ? List.skip : make_node(AST_EmptyStatement, node);
|
||||||
}
|
}
|
||||||
if (node instanceof AST_Defun) {
|
if (node instanceof AST_LambdaDefinition) {
|
||||||
if (!hoist_funs) return node;
|
if (!hoist_funs) return node;
|
||||||
if (tt.parent() !== self && compressor.has_directive("use strict")) return node;
|
var p = tt.parent();
|
||||||
|
if (p instanceof AST_ExportDeclaration) return node;
|
||||||
|
if (p instanceof AST_ExportDefault) return node;
|
||||||
|
if (p !== self && compressor.has_directive("use strict")) return node;
|
||||||
hoisted.push(node);
|
hoisted.push(node);
|
||||||
return make_node(AST_EmptyStatement, node);
|
return in_list ? List.skip : make_node(AST_EmptyStatement, node);
|
||||||
}
|
}
|
||||||
if (node instanceof AST_Var) {
|
if (node instanceof AST_Var) {
|
||||||
if (!hoist_vars) return node;
|
if (!hoist_vars) return node;
|
||||||
if (tt.parent() instanceof AST_ExportDeclaration) return node;
|
var p = tt.parent();
|
||||||
|
if (p instanceof AST_ExportDeclaration) return node;
|
||||||
if (!all(node.definitions, function(defn) {
|
if (!all(node.definitions, function(defn) {
|
||||||
var sym = defn.name;
|
var sym = defn.name;
|
||||||
return sym instanceof AST_SymbolVar
|
return sym instanceof AST_SymbolVar
|
||||||
@@ -6827,17 +6831,14 @@ merge(Compressor.prototype, {
|
|||||||
++vars_found;
|
++vars_found;
|
||||||
});
|
});
|
||||||
var seq = node.to_assignments();
|
var seq = node.to_assignments();
|
||||||
var p = tt.parent();
|
|
||||||
if (p instanceof AST_ForEnumeration && p.init === node) {
|
if (p instanceof AST_ForEnumeration && p.init === node) {
|
||||||
if (seq) return seq;
|
if (seq) return seq;
|
||||||
var def = node.definitions[0].name;
|
var def = node.definitions[0].name;
|
||||||
return make_node(AST_SymbolRef, def, def);
|
return make_node(AST_SymbolRef, def, def);
|
||||||
}
|
}
|
||||||
if (p instanceof AST_For && p.init === node) return seq;
|
if (p instanceof AST_For && p.init === node) return seq;
|
||||||
if (!seq) return make_node(AST_EmptyStatement, node);
|
if (!seq) return in_list ? List.skip : make_node(AST_EmptyStatement, node);
|
||||||
return make_node(AST_SimpleStatement, node, {
|
return make_node(AST_SimpleStatement, node, { body: seq });
|
||||||
body: seq
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
if (node instanceof AST_Scope) return node;
|
if (node instanceof AST_Scope) return node;
|
||||||
if (node instanceof AST_SymbolConst) {
|
if (node instanceof AST_SymbolConst) {
|
||||||
|
|||||||
@@ -399,6 +399,17 @@ single_use_class_default: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hoist_funs: {
|
||||||
|
options = {
|
||||||
|
hoist_funs: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
export function f() {}
|
||||||
|
export default async function* g() {}
|
||||||
|
}
|
||||||
|
expect_exact: "export function f(){}export default async function*g(){}"
|
||||||
|
}
|
||||||
|
|
||||||
issue_4742_join_vars_1: {
|
issue_4742_join_vars_1: {
|
||||||
options = {
|
options = {
|
||||||
join_vars: true,
|
join_vars: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user