minor clean-up (#5210)
authorAlex Lam S.L <alexlamsl@gmail.com>
Thu, 9 Dec 2021 20:48:06 +0000 (20:48 +0000)
committerGitHub <noreply@github.com>
Thu, 9 Dec 2021 20:48:06 +0000 (04:48 +0800)
lib/compress.js

index 3a58f35..b06186e 100644 (file)
@@ -6659,7 +6659,7 @@ Compressor.prototype.compress = function(node) {
                         if (value && indexOf_assign(sym, def) < 0) {
                             value = value.drop_side_effect_free(compressor);
                             if (value) {
-                                AST_Node.warn("Side effects in last use of variable {name} [{file}:{line},{col}]", template(def.name));
+                                AST_Node.warn("Side effects in definition of variable {name} [{file}:{line},{col}]", template(def.name));
                                 side_effects.push(value);
                             }
                             value = null;
@@ -6823,7 +6823,7 @@ Compressor.prototype.compress = function(node) {
                             var assign = make_node(AST_Assign, def, {
                                 operator: "=",
                                 left: ref,
-                                right: def.value
+                                right: def.value,
                             });
                             var index = indexOf_assign(sym, def);
                             if (index >= 0) assign_in_use[sym.id][index] = assign;
@@ -12391,7 +12391,7 @@ Compressor.prototype.compress = function(node) {
     });
 
     AST_LambdaExpression.DEFMETHOD("contains_super", function() {
-        var result;
+        var result = false;
         var self = this;
         self.walk(new TreeWalker(function(node) {
             if (result) return true;
@@ -12401,17 +12401,25 @@ Compressor.prototype.compress = function(node) {
         return result;
     });
 
-    AST_Arrow.DEFMETHOD("contains_this", return_false);
-    AST_AsyncArrow.DEFMETHOD("contains_this", return_false);
-    AST_Node.DEFMETHOD("contains_this", function() {
-        var result;
-        var self = this;
-        self.walk(new TreeWalker(function(node) {
-            if (result) return true;
-            if (node instanceof AST_This) return result = true;
-            if (node !== self && node instanceof AST_Scope && !is_arrow(node)) return true;
-        }));
-        return result;
+    // contains_this()
+    // returns false only if context bound by the specified scope (or scope
+    // containing the specified expression) is not referenced by `this`
+    (function(def) {
+        // scope of arrow function cannot bind to any context
+        def(AST_Arrow, return_false);
+        def(AST_AsyncArrow, return_false);
+        def(AST_Node, function() {
+            var result = false;
+            var self = this;
+            self.walk(new TreeWalker(function(node) {
+                if (result) return true;
+                if (node instanceof AST_This) return result = true;
+                if (node !== self && node instanceof AST_Scope && !is_arrow(node)) return true;
+            }));
+            return result;
+        });
+    })(function(node, func) {
+        node.DEFMETHOD("contains_this", func);
     });
 
     function can_hoist_property(prop) {