aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-01-02 01:43:05 +0000
committerGitHub <noreply@github.com>2021-01-02 09:43:05 +0800
commitcc2d7acaf0ed2479c8d3a5d3cbbce15a3cb2333b (patch)
treefcd83b713f22071052fbb1a4319d486fa16489ab /lib/compress.js
parentdfb86ccdd1dfe6f07953afc8c308b00c9c6856b1 (diff)
downloadtracifyjs-cc2d7acaf0ed2479c8d3a5d3cbbce15a3cb2333b.tar.gz
tracifyjs-cc2d7acaf0ed2479c8d3a5d3cbbce15a3cb2333b.zip
enhance `inline`, `sequences` & `side_effects` (#4493)
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js15
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 5f8f3736..0a46fb26 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -8018,7 +8018,7 @@ merge(Compressor.prototype, {
}
}
var fn = exp instanceof AST_SymbolRef ? exp.fixed_value() : exp;
- var is_func = fn instanceof AST_Arrow || fn instanceof AST_Defun || fn instanceof AST_Function;
+ var is_func = fn instanceof AST_Lambda && (!is_async(fn) || compressor.parent() instanceof AST_Await);
var stat = is_func && fn.first_statement();
var has_default = false;
var can_drop = is_func && all(fn.argnames, function(argname, index) {
@@ -8649,6 +8649,19 @@ merge(Compressor.prototype, {
? self : try_evaluate(compressor, self);
});
+ OPT(AST_Await, function(self, compressor) {
+ if (compressor.option("sequences")) {
+ var seq = lift_sequence_in_expression(self, compressor);
+ if (seq !== self) return seq.optimize(compressor);
+ }
+ if (compressor.option("side_effects")) {
+ var exp = self.expression;
+ if (exp instanceof AST_Await) return exp;
+ if (exp instanceof AST_UnaryPrefix && exp.expression instanceof AST_Await) return exp;
+ }
+ return self;
+ });
+
AST_Binary.DEFMETHOD("lift_sequences", function(compressor) {
if (this.left instanceof AST_PropAccess) {
if (!(this.left.expression instanceof AST_Sequence)) return this;