diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-02-06 04:39:46 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-06 12:39:46 +0800 |
commit | 5359900b78fdf3006dafc13a206332d2fb2b1ea4 (patch) | |
tree | 3f6878238a8c69655820811b6c25cede25866d94 /lib | |
parent | 739fa266f80802f75838cc4053e615b27abcf361 (diff) | |
download | tracifyjs-5359900b78fdf3006dafc13a206332d2fb2b1ea4.tar.gz tracifyjs-5359900b78fdf3006dafc13a206332d2fb2b1ea4.zip |
enhance `compress` on arrow and `async` functions (#4616)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/compress.js b/lib/compress.js index 781b59f3..d4cf0da9 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1843,7 +1843,7 @@ merge(Compressor.prototype, { if (node instanceof AST_Call) { if (!(lhs instanceof AST_PropAccess)) return false; if (!lhs.equivalent_to(node.expression)) return false; - return !(rvalue instanceof AST_Function && !rvalue.contains_this()); + return !(is_function(rvalue) && !rvalue.contains_this()); } if (node instanceof AST_Debugger) return true; if (node instanceof AST_Defun) return funarg && lhs.name === node.name.name; @@ -2482,7 +2482,7 @@ merge(Compressor.prototype, { if (modify_toplevel) return; var exp = node.expression; if (exp instanceof AST_PropAccess) return; - if (exp instanceof AST_Function && !exp.contains_this()) return; + if (is_function(exp) && !exp.contains_this()) return; modify_toplevel = true; } else if (node instanceof AST_PropAccess && may_be_global(node.expression)) { if (node === lhs && !(expr instanceof AST_Unary)) { @@ -4060,7 +4060,7 @@ merge(Compressor.prototype, { key = key._eval(compressor, ignore_side_effects, cached, depth); if (key === prop.key) return this; } - if (prop.value instanceof AST_Function && typeof Object.prototype[key] == "function") return this; + if (key == "toString" || key == "valueOf") return this; val[key] = prop.value._eval(compressor, ignore_side_effects, cached, depth); if (val[key] === prop.value) return this; } @@ -5850,10 +5850,10 @@ merge(Compressor.prototype, { } } else if (compressor.option("functions") && !compressor.option("ie8") - && !(node instanceof AST_Const || node instanceof AST_Let) + && node instanceof AST_Var && var_defs[sym.id] == 1 && sym.assignments == 0 - && value instanceof AST_Function + && (value instanceof AST_AsyncFunction || value instanceof AST_Function) && (sym.references.length ? all(sym.references, function(ref) { return value === ref.fixed_value(); }) : value === def.name.fixed_value()) @@ -5864,7 +5864,7 @@ merge(Compressor.prototype, { && can_declare_defun() && can_rename(value, def.name.name)) { AST_Node.warn("Declaring {name} as function [{file}:{line},{col}]", template(def.name)); - var defun = make_node(AST_Defun, def, value); + var defun = make_node(value instanceof AST_Function ? AST_Defun : AST_AsyncDefun, def, value); defun.name = make_node(AST_SymbolDefun, def.name, def.name); var name_def = def.name.scope.resolve().def_function(defun.name); if (old_def) old_def.forEach(function(node) { @@ -6902,7 +6902,7 @@ merge(Compressor.prototype, { return exprs && make_sequence(self, exprs.map(convert_spread)); } var def; - if (exp instanceof AST_Function + if ((is_arrow(exp) && !exp.value || exp instanceof AST_AsyncFunction || exp instanceof AST_Function) && !(exp.name && (def = exp.name.definition()).references.length > def.replaced)) { exp.process_expression(false, function(node) { var value = node.value && node.value.drop_side_effect_free(compressor, true); |