matthiasmullie / minify

CSS & JavaScript minifier, in PHP. Removes whitespace, strips comments, combines files (incl. @import statements and small assets in CSS files), and optimizes/shortens a few common programming patterns.
https://matthiasmullie.github.io/minify/
MIT License
1.97k stars 309 forks source link

Syntax error on minified Elementor Pro library #360

Open therealgilles opened 3 years ago

therealgilles commented 3 years ago

The following library gets incorrectly minified:

https://swinginatthesavoy.com/wp-content/plugins/elementor-pro/assets/js/webpack-pro.runtime.js

/*! elementor-pro - v3.1.0 - 14-02-2021 */
/******/ (() => { // webpackBootstrap
/******/    "use strict";
/******/    var __webpack_modules__ = ({});
/************************************************************************/
/******/    // The module cache
/******/    var __webpack_module_cache__ = {};
/******/    
/******/    // The require function
/******/    function __webpack_require__(moduleId) {
/******/        // Check if module is in cache
/******/        if(__webpack_module_cache__[moduleId]) {
/******/            return __webpack_module_cache__[moduleId].exports;
/******/        }
/******/        // Create a new module (and put it into the cache)
/******/        var module = __webpack_module_cache__[moduleId] = {
/******/            // no module.id needed
/******/            // no module.loaded needed
/******/            exports: {}
/******/        };
/******/    
/******/        // Execute the module function
/******/        __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/    
/******/        // Return the exports of the module
/******/        return module.exports;
/******/    }
/******/    
/******/    // expose the modules object (__webpack_modules__)
/******/    __webpack_require__.m = __webpack_modules__;
/******/    
/******/    // the startup function
/******/    // It's empty as some runtime module handles the default behavior
/******/    __webpack_require__.x = x => {}
/************************************************************************/
/******/    /* webpack/runtime/create fake namespace object */
/******/    (() => {
/******/        var getProto = Object.getPrototypeOf ? (obj) => Object.getPrototypeOf(obj) : (obj) => obj.__proto__;
/******/        var leafPrototypes;
/******/        // create a fake namespace object
/******/        // mode & 1: value is a module id, require it
/******/        // mode & 2: merge all properties of value into the ns
/******/        // mode & 4: return value when already ns object
/******/        // mode & 16: return value when it's Promise-like
/******/        // mode & 8|1: behave like require
/******/        __webpack_require__.t = function(value, mode) {
/******/            if(mode & 1) value = this(value);
/******/            if(mode & 8) return value;
/******/            if(typeof value === 'object' && value) {
/******/                if((mode & 4) && value.__esModule) return value;
/******/                if((mode & 16) && typeof value.then === 'function') return value;
/******/            }
/******/            var ns = Object.create(null);
/******/            __webpack_require__.r(ns);
/******/            var def = {};
/******/            leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)];
/******/            for(var current = mode & 2 && value; typeof current == 'object' && !~leafPrototypes.indexOf(current); current = getProto(current)) {
/******/                Object.getOwnPropertyNames(current).forEach(key => def[key] = () => value[key]);
/******/            }
/******/            def['default'] = () => value;
/******/            __webpack_require__.d(ns, def);
/******/            return ns;
/******/        };
/******/    })();
/******/    
/******/    /* webpack/runtime/define property getters */
/******/    (() => {
/******/        // define getter functions for harmony exports
/******/        __webpack_require__.d = (exports, definition) => {
/******/            for(var key in definition) {
/******/                if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/                    Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/                }
/******/            }
/******/        };
/******/    })();
/******/    
/******/    /* webpack/runtime/ensure chunk */
/******/    (() => {
/******/        __webpack_require__.f = {};
/******/        // This file contains only the entry chunk.
/******/        // The chunk loading function for additional chunks
/******/        __webpack_require__.e = (chunkId) => {
/******/            return Promise.all(Object.keys(__webpack_require__.f).reduce((promises, key) => {
/******/                __webpack_require__.f[key](chunkId, promises);
/******/                return promises;
/******/            }, []));
/******/        };
/******/    })();
/******/    
/******/    /* webpack/runtime/get javascript chunk filename */
/******/    (() => {
/******/        // This function allow to reference async chunks
/******/        __webpack_require__.u = (chunkId) => {
/******/            // return url for filenames not based on template
/******/            if (chunkId === "code-highlight") return "" + chunkId + ".9f87a4e2747cd21130f2.bundle.js";
/******/            if (chunkId === "animated-headline") return "" + chunkId + ".2f8aa69eb835a7705004.bundle.js";
/******/            if (chunkId === "vendors-node_modules_babel_runtime-corejs2_helpers_asyncToGenerator_js-node_modules_babel_run-fdf909") return "555de94d3d45395fb64c.bundle.js";
/******/            if (chunkId === "modules_carousel_assets_js_frontend_handlers_base_js") return "f7edf46ee23c04733c35.bundle.js";
/******/            if (chunkId === "media-carousel") return "" + chunkId + ".4c0492dde4e7dcd5cc9d.bundle.js";
/******/            if (chunkId === "carousel") return "" + chunkId + ".bb4c8274de83e045027f.bundle.js";
/******/            if (chunkId === "countdown") return "" + chunkId + ".fdb92c684b8e3ab88c82.bundle.js";
/******/            if (chunkId === "form") return "form.7b8b0e25d066322571d3.bundle.js";
/******/            if (chunkId === "gallery") return "" + chunkId + ".d7dd275ca3eddcfb9d65.bundle.js";
/******/            if (chunkId === "lottie") return "" + chunkId + ".e98d89812034d54404b0.bundle.js";
/******/            if (chunkId === "nav-menu") return "" + chunkId + ".dc9954b5562a6a182c99.bundle.js";
/******/            if (chunkId === "popup") return "" + chunkId + ".578217b3d93e8efb2299.bundle.js";
/******/            if (chunkId === "posts") return "" + chunkId + ".d74d398bbd5332eec332.bundle.js";
/******/            if (chunkId === "portfolio") return "" + chunkId + ".89b8364078e0e54495a6.bundle.js";
/******/            if (chunkId === "share-buttons") return "" + chunkId + ".9512609e0867a17e5e8a.bundle.js";
/******/            if (chunkId === "slides") return "" + chunkId + ".a4197378419486376c60.bundle.js";
/******/            if (chunkId === "social") return "" + chunkId + ".3d098e67c2733abd1e00.bundle.js";
/******/            if (chunkId === "table-of-contents") return "" + chunkId + ".b6d30918ee290abdc725.bundle.js";
/******/            if (chunkId === "archive-posts") return "" + chunkId + ".ad6245c6d6e01e236d1a.bundle.js";
/******/            if (chunkId === "search-form") return "" + chunkId + ".3a9594b565e888bd1c56.bundle.js";
/******/            if (chunkId === "woocommerce-menu-cart") return "" + chunkId + ".e78271ddd87116469809.bundle.js";
/******/            // return url for filenames based on template
/******/            return "" + chunkId + ".js";
/******/        };
/******/    })();
/******/    
/******/    /* webpack/runtime/global */
/******/    (() => {
/******/        __webpack_require__.g = (function() {
/******/            if (typeof globalThis === 'object') return globalThis;
/******/            try {
/******/                return this || new Function('return this')();
/******/            } catch (e) {
/******/                if (typeof window === 'object') return window;
/******/            }
/******/        })();
/******/    })();
/******/    
/******/    /* webpack/runtime/hasOwnProperty shorthand */
/******/    (() => {
/******/        __webpack_require__.o = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop)
/******/    })();
/******/    
/******/    /* webpack/runtime/load script */
/******/    (() => {
/******/        var inProgress = {};
/******/        var dataWebpackPrefix = "elementor-pro:";
/******/        // loadScript function to load a script via script tag
/******/        __webpack_require__.l = (url, done, key) => {
/******/            if(inProgress[url]) { inProgress[url].push(done); return; }
/******/            var script, needAttach;
/******/            if(key !== undefined) {
/******/                var scripts = document.getElementsByTagName("script");
/******/                for(var i = 0; i < scripts.length; i++) {
/******/                    var s = scripts[i];
/******/                    if(s.getAttribute("src") == url || s.getAttribute("data-webpack") == dataWebpackPrefix + key) { script = s; break; }
/******/                }
/******/            }
/******/            if(!script) {
/******/                needAttach = true;
/******/                script = document.createElement('script');
/******/        
/******/                script.charset = 'utf-8';
/******/                script.timeout = 120;
/******/                if (__webpack_require__.nc) {
/******/                    script.setAttribute("nonce", __webpack_require__.nc);
/******/                }
/******/                script.setAttribute("data-webpack", dataWebpackPrefix + key);
/******/                script.src = url;
/******/            }
/******/            inProgress[url] = [done];
/******/            var onScriptComplete = (prev, event) => {
/******/                // avoid mem leaks in IE.
/******/                script.onerror = script.onload = null;
/******/                clearTimeout(timeout);
/******/                var doneFns = inProgress[url];
/******/                delete inProgress[url];
/******/                script.parentNode && script.parentNode.removeChild(script);
/******/                doneFns && doneFns.forEach((fn) => fn(event));
/******/                if(prev) return prev(event);
/******/            }
/******/            ;
/******/            var timeout = setTimeout(onScriptComplete.bind(null, undefined, { type: 'timeout', target: script }), 120000);
/******/            script.onerror = onScriptComplete.bind(null, script.onerror);
/******/            script.onload = onScriptComplete.bind(null, script.onload);
/******/            needAttach && document.head.appendChild(script);
/******/        };
/******/    })();
/******/    
/******/    /* webpack/runtime/make namespace object */
/******/    (() => {
/******/        // define __esModule on exports
/******/        __webpack_require__.r = (exports) => {
/******/            if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/                Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/            }
/******/            Object.defineProperty(exports, '__esModule', { value: true });
/******/        };
/******/    })();
/******/    
/******/    /* webpack/runtime/publicPath */
/******/    (() => {
/******/        var scriptUrl;
/******/        if (__webpack_require__.g.importScripts) scriptUrl = __webpack_require__.g.location + "";
/******/        var document = __webpack_require__.g.document;
/******/        if (!scriptUrl && document) {
/******/            if (document.currentScript)
/******/                scriptUrl = document.currentScript.src
/******/            if (!scriptUrl) {
/******/                var scripts = document.getElementsByTagName("script");
/******/                if(scripts.length) scriptUrl = scripts[scripts.length - 1].src
/******/            }
/******/        }
/******/        // When supporting browsers where an automatic publicPath is not supported you must specify an output.publicPath manually via configuration
/******/        // or pass an empty string ("") and set the __webpack_public_path__ variable from your code to use your own logic.
/******/        if (!scriptUrl) throw new Error("Automatic publicPath is not supported in this browser");
/******/        scriptUrl = scriptUrl.replace(/#.*$/, "").replace(/\?.*$/, "").replace(/\/[^\/]+$/, "/");
/******/        __webpack_require__.p = scriptUrl;
/******/    })();
/******/    
/******/    /* webpack/runtime/jsonp chunk loading */
/******/    (() => {
/******/        // no baseURI
/******/        
/******/        // object to store loaded and loading chunks
/******/        // undefined = chunk not loaded, null = chunk preloaded/prefetched
/******/        // Promise = chunk loading, 0 = chunk loaded
/******/        var installedChunks = {
/******/            "webpack-pro.runtime": 0
/******/        };
/******/        
/******/        var deferredModules = [
/******/        
/******/        ];
/******/        __webpack_require__.f.j = (chunkId, promises) => {
/******/                // JSONP chunk loading for javascript
/******/                var installedChunkData = __webpack_require__.o(installedChunks, chunkId) ? installedChunks[chunkId] : undefined;
/******/                if(installedChunkData !== 0) { // 0 means "already installed".
/******/        
/******/                    // a Promise means "currently loading".
/******/                    if(installedChunkData) {
/******/                        promises.push(installedChunkData[2]);
/******/                    } else {
/******/                        if(true) { // all chunks have JS
/******/                            // setup Promise in chunk cache
/******/                            var promise = new Promise((resolve, reject) => {
/******/                                installedChunkData = installedChunks[chunkId] = [resolve, reject];
/******/                            });
/******/                            promises.push(installedChunkData[2] = promise);
/******/        
/******/                            // start chunk loading
/******/                            var url = __webpack_require__.p + __webpack_require__.u(chunkId);
/******/                            // create error before stack unwound to get useful stacktrace later
/******/                            var error = new Error();
/******/                            var loadingEnded = (event) => {
/******/                                if(__webpack_require__.o(installedChunks, chunkId)) {
/******/                                    installedChunkData = installedChunks[chunkId];
/******/                                    if(installedChunkData !== 0) installedChunks[chunkId] = undefined;
/******/                                    if(installedChunkData) {
/******/                                        var errorType = event && (event.type === 'load' ? 'missing' : event.type);
/******/                                        var realSrc = event && event.target && event.target.src;
/******/                                        error.message = 'Loading chunk ' + chunkId + ' failed.\n(' + errorType + ': ' + realSrc + ')';
/******/                                        error.name = 'ChunkLoadError';
/******/                                        error.type = errorType;
/******/                                        error.request = realSrc;
/******/                                        installedChunkData[1](error);
/******/                                    }
/******/                                }
/******/                            };
/******/                            __webpack_require__.l(url, loadingEnded, "chunk-" + chunkId);
/******/                        } else installedChunks[chunkId] = 0;
/******/                    }
/******/                }
/******/        };
/******/        
/******/        // no prefetching
/******/        
/******/        // no preloaded
/******/        
/******/        // no HMR
/******/        
/******/        // no HMR manifest
/******/        
/******/        var checkDeferredModules = x => {};
/******/        
/******/        // install a JSONP callback for chunk loading
/******/        var webpackJsonpCallback = (parentChunkLoadingFunction, data) => {
/******/            var [chunkIds, moreModules, runtime, executeModules] = data;
/******/            // add "moreModules" to the modules object,
/******/            // then flag all "chunkIds" as loaded and fire callback
/******/            var moduleId, chunkId, i = 0, resolves = [];
/******/            for(;i < chunkIds.length; i++) {
/******/                chunkId = chunkIds[i];
/******/                if(__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) {
/******/                    resolves.push(installedChunks[chunkId][0]);
/******/                }
/******/                installedChunks[chunkId] = 0;
/******/            }
/******/            for(moduleId in moreModules) {
/******/                if(__webpack_require__.o(moreModules, moduleId)) {
/******/                    __webpack_require__.m[moduleId] = moreModules[moduleId];
/******/                }
/******/            }
/******/            if(runtime) runtime(__webpack_require__);
/******/            if(parentChunkLoadingFunction) parentChunkLoadingFunction(data);
/******/            while(resolves.length) {
/******/                resolves.shift()();
/******/            }
/******/        
/******/            // add entry modules from loaded chunk to deferred list
/******/            if(executeModules) deferredModules.push.apply(deferredModules, executeModules);
/******/        
/******/            // run deferred modules when all chunks ready
/******/            return checkDeferredModules();
/******/        }
/******/        
/******/        var chunkLoadingGlobal = self["webpackChunkelementor_pro"] = self["webpackChunkelementor_pro"] || [];
/******/        chunkLoadingGlobal.forEach(webpackJsonpCallback.bind(null, 0));
/******/        chunkLoadingGlobal.push = webpackJsonpCallback.bind(null, chunkLoadingGlobal.push.bind(chunkLoadingGlobal));
/******/        
/******/        function checkDeferredModulesImpl() {
/******/            var result;
/******/            for(var i = 0; i < deferredModules.length; i++) {
/******/                var deferredModule = deferredModules[i];
/******/                var fulfilled = true;
/******/                for(var j = 1; j < deferredModule.length; j++) {
/******/                    var depId = deferredModule[j];
/******/                    if(installedChunks[depId] !== 0) fulfilled = false;
/******/                }
/******/                if(fulfilled) {
/******/                    deferredModules.splice(i--, 1);
/******/                    result = __webpack_require__(__webpack_require__.s = deferredModule[0]);
/******/                }
/******/            }
/******/            if(deferredModules.length === 0) {
/******/                __webpack_require__.x();
/******/                __webpack_require__.x = x => {};
/******/            }
/******/            return result;
/******/        }
/******/        var startup = __webpack_require__.x;
/******/        __webpack_require__.x = () => {
/******/            // reset startup function so it can be called again when more startup code is added
/******/            __webpack_require__.x = startup || (x => {});
/******/            return (checkDeferredModules = checkDeferredModulesImpl)();
/******/        };
/******/    })();
/******/    
/************************************************************************/
/******/    // run startup
/******/    return __webpack_require__.x();
/******/ })()
;
//# sourceMappingURL=webpack-pro.runtime.js.map

The minification does not insert a semi-colon or comma before (()=>{ ... })() statement, which results in the syntax error as:

var bla = {}(()=>{ ... })()

gets interpreted differently than:

var bla = {}
(()=>{ ... })()

due to javascript auto semi-colon insertion on newline.

nise commented 2 years ago

Any updates on this issue?

nise commented 2 years ago

I found a solution. Webpacke needs to use babel in order to transpile a version of javascript the minify can work with.

See the babel manual: https://babeljs.io/docs/en/babel-plugin-proposal-async-generator-functions

Babel configuration file .babelrc should contain those transpile options that you require. { "plugins": ["@babel/plugin-proposal-async-generator-functions"] }

However, it would be nice to know the ES/JS versions that are supported by minfy.

xzax commented 1 month ago

This error is causing chaos with cache plugins. Testet with WP Rocket & LiteSpeed. Have rolled back the Elementor versions on large sites.