aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-03-05 20:25:44 +0000
committerGitHub <noreply@github.com>2021-03-06 04:25:44 +0800
commit83c3838b07ed9ff32a83a39d5c1cbf40155c46f2 (patch)
tree5a1f0982f68f4002e4e877ce8cb99192e69984ca /lib
parentfa09f87589015cf7056d9d0296d2df9c10483331 (diff)
downloadtracifyjs-83c3838b07ed9ff32a83a39d5c1cbf40155c46f2.tar.gz
tracifyjs-83c3838b07ed9ff32a83a39d5c1cbf40155c46f2.zip
fix corner case in `awaits` (#4740)
fixes #4738
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js25
1 files changed, 22 insertions, 3 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 9d390d09..20558ba8 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -7205,10 +7205,10 @@ merge(Compressor.prototype, {
});
def(AST_Await, function(compressor) {
if (!compressor.option("awaits")) return this;
- var exp = this.expression.drop_side_effect_free(compressor);
- if (exp === this.expression) return this;
+ var exp = this.expression;
+ if (!is_primitive(compressor, exp)) return this;
var node = this.clone();
- node.expression = exp || make_node(AST_Number, this, { value: 0 });
+ node.expression = exp.drop_side_effect_free(compressor) || make_node(AST_Number, this, { value: 0 });
return node;
});
def(AST_Binary, function(compressor, first_in_statement) {
@@ -9555,6 +9555,25 @@ merge(Compressor.prototype, {
|| node instanceof AST_Object;
}
+ function is_primitive(compressor, node) {
+ if (node.is_constant()) return true;
+ if (node instanceof AST_Assign) return node.operator != "=" || is_primitive(compressor, node.right);
+ if (node instanceof AST_Binary) {
+ return !lazy_op[node.operator]
+ || is_primitive(compressor, node.left) && is_primitive(compressor, node.right);
+ }
+ if (node instanceof AST_Conditional) {
+ return is_primitive(compressor, node.consequent) && is_primitive(compressor, node.alternative);
+ }
+ if (node instanceof AST_Sequence) return is_primitive(compressor, node.tail_node());
+ if (node instanceof AST_SymbolRef) {
+ var fixed = node.fixed_value();
+ return fixed && is_primitive(compressor, fixed);
+ }
+ if (node instanceof AST_Template) return !node.tag || is_raw_tag(compressor, node.tag);
+ if (node instanceof AST_Unary) return true;
+ }
+
function repeatable(compressor, node) {
if (node instanceof AST_Dot) return repeatable(compressor, node.expression);
if (node instanceof AST_Sub) {