shipshapecode / tether

A positioning engine to make overlays, tooltips and dropdowns better

Home Page:https://tetherjs.dev/docs/welcome

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

minify failure with latest versions of uglify-js, uglify-es and terser

kzc opened this issue · comments

commented

There's a common bug in the 3.x versions of the uglify-derived minifiers (uglify-js, uglify-es and terser) that prevents javascript bundlers from working with tether@1.4.5:

ERROR: Cannot read property '_walk' of null
terser/terser#120 (comment)

NOTE: There's nothing wrong with Tether's code! This is solely an uglify/terser problem.

You can see the bug if you apply this patch and run npm install && npm run check-dist:

--- a/package.json
+++ b/package.json
@@ -13,7 +13,8 @@
   "scripts": {
     "reinstall": "del node_modules && npm install",
     "watch": "gulp watch",
-    "build": "gulp build"
+    "build": "gulp build",
+    "check-dist": "gulp build && terser dist/js/tether.js -mc && echo SUCCESS"
   },
   "repository": {
     "type": "git",
@@ -35,6 +36,7 @@
     "gulp-rename": "^1.2.2",
     "gulp-sass": "^2.0.4",
     "gulp-uglify": "^1.4.3",
-    "gulp-wrap-umd": "^0.2.1"
+    "gulp-wrap-umd": "^0.2.1",
+    "terser": "^3.9.2"
   }
 }

Would you consider applying the following patch so that the uglify-derived minifiers can avoid this error? Hopefully this would be a temporary measure until these minifiers can be fixed.

--- a/src/js/tether.js
+++ b/src/js/tether.js
@@ -766,9 +766,4 @@ class TetherClass extends Evented {
       } else {
         let offsetParentIsBody = true;
-        function isFullscreenElement(e) {
-          let d = e.ownerDocument;
-          let fe = d.fullscreenElement || d.webkitFullscreenElement || d.mozFullScreenElement || d.msFullscreenElement;
-          return fe === e;
-        }
         let currentNode = this.element.parentNode;
         while (currentNode && currentNode.nodeType === 1 && currentNode.tagName !== 'BODY' && !isFullscreenElement(currentNode)) {
@@ -807,4 +802,10 @@ class TetherClass extends Evented {
       });
     }
+
+    function isFullscreenElement(e) {
+      let d = e.ownerDocument;
+      let fe = d.fullscreenElement || d.webkitFullscreenElement || d.mozFullScreenElement || d.msFullscreenElement;
+      return fe === e;
+    }
   }
 }

I think there is a simple workaround for this issue by simply moving out variable d one layer up. PR is here #292

Does uglify have an issue tracker with this for those of us who would like to follow it? For now I'm having to force tether version 1.4.4 in my projects and would like to know when I can remove that restriction.

I think this is it:

mishoo/UglifyJS#3274

commented

This bug was fixed in Terser.

Could you share which PR/version of terser that fixes it? @kzc

commented

These two patches fixed it:

terser/terser#152
terser/terser#154

Everyone should be using terser@3.10.11 or a later version.

Thanks!

This should now be fixed in uglify-js@3.4.10