From 6ab091801ae4e9a0ef59dcab950717a98923a037 Mon Sep 17 00:00:00 2001 From: Evilebot Tnawi Date: Fri, 15 Jun 2018 21:49:48 +0300 Subject: [PATCH] fix: disable inline optimization by default (#308) --- README.md | 4 +- src/index.js | 3 + src/uglify/minify.js | 9 +- .../__snapshots__/uglify-options.test.js.snap | 427 ++++++------------ test/fixtures/inline-optimization.js | 3 + test/uglify-options.test.js | 335 +++++++++++++- 6 files changed, 454 insertions(+), 327 deletions(-) create mode 100644 test/fixtures/inline-optimization.js diff --git a/README.md b/README.md index 32ab2ea0..1884e929 100644 --- a/README.md +++ b/README.md @@ -164,8 +164,8 @@ Number of concurrent runs. |**`warnings`**|`{Boolean}`|`false`|Display Warnings| |**[`parse`](https://github.com/mishoo/UglifyJS2/tree/harmony#parse-options)**|`{Object}`|`{}`|Additional Parse Options| |**[`compress`](https://github.com/mishoo/UglifyJS2/tree/harmony#compress-options)**|`{Boolean\|Object}`|`true`|Additional Compress Options| -|**[`mangle`](https://github.com/mishoo/UglifyJS2/tree/harmony#mangle-options)**|`{Boolean\|Object}`|`true`|Enable Name Mangling (See [Mangle Properties](https://github.com/mishoo/UglifyJS2/tree/harmony#mangle-properties-options) for advanced setups, use with ⚠️)| -|**[`output`](https://github.com/mishoo/UglifyJS2/tree/harmony#output-options)**|`{Object}`|`{}`|Additional Output Options (The defaults are optimized for best compression)| +|**[`mangle`](https://github.com/mishoo/UglifyJS2/tree/harmony#mangle-options)**|`{Boolean\|Object}`|`{inline: false}`|Enable Name Mangling (See [Mangle Properties](https://github.com/mishoo/UglifyJS2/tree/harmony#mangle-properties-options) for advanced setups, use with ⚠️)| +|**[`output`](https://github.com/mishoo/UglifyJS2/tree/harmony#output-options)**|`{Object}`|`{comments: extractComments ? false : /^\**!|@preserve|@license|@cc_on/,}`|Additional Output Options (The defaults are optimized for best compression)| |**`toplevel`**|`{Boolean}`|`false`|Enable top level variable and function name mangling and to drop unused variables and functions| |**`nameCache`**|`{Object}`|`null`|Enable cache of mangled variable and property names across multiple invocations| |**`ie8`**|`{Boolean}`|`false`|Enable IE8 Support| diff --git a/src/index.js b/src/index.js index 22213a55..098dcc27 100644 --- a/src/index.js +++ b/src/index.js @@ -42,6 +42,9 @@ class UglifyJsPlugin { include, exclude, uglifyOptions: { + compress: { + inline: 1, + }, output: { comments: extractComments ? false : /^\**!|@preserve|@license|@cc_on/, }, diff --git a/src/uglify/minify.js b/src/uglify/minify.js index 94f7e1b1..5993a31c 100644 --- a/src/uglify/minify.js +++ b/src/uglify/minify.js @@ -21,9 +21,10 @@ const buildUglifyOptions = ({ } = {}) => ({ ecma, warnings, - parse, - compress, - mangle: mangle == null ? true : mangle, + parse: { ...parse }, + compress: typeof compress === 'boolean' ? compress : { ...compress }, + // eslint-disable-next-line no-nested-ternary + mangle: mangle == null ? true : typeof mangle === 'boolean' ? mangle : { ...mangle }, output: { shebang: true, comments: false, @@ -31,7 +32,7 @@ const buildUglifyOptions = ({ semicolons: true, ...output, }, - // Ignoring sourcemap from options + // Ignoring sourceMap from options sourceMap: null, toplevel, nameCache, diff --git a/test/__snapshots__/uglify-options.test.js.snap b/test/__snapshots__/uglify-options.test.js.snap index 6c642bbe..54773369 100644 --- a/test/__snapshots__/uglify-options.test.js.snap +++ b/test/__snapshots__/uglify-options.test.js.snap @@ -1,351 +1,182 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`when applied with uglify-es options disable inline optimization by default (have a lot of problems): errors 1`] = `Array []`; + +exports[`when applied with uglify-es options disable inline optimization by default (have a lot of problems): main.js 1`] = `"webpackJsonp([0],[function(o,c,n){\\"use strict\\";console.log(42)}],[0]);"`; + +exports[`when applied with uglify-es options disable inline optimization by default (have a lot of problems): manifest.js 1`] = `"!function(r){var n=window.webpackJsonp;window.webpackJsonp=function(e,u,c){for(var f,i,p,a=0,l=[];a{return{a:t+a[\\"a\\"]+e,b:t,baz:e}}}e[\\"default\\"]=o},function(t,e,n){\\"use strict\\";const a=\\"bar\\";e[\\"a\\"]=a;e[\\"b\\"]=\\"foo\\"}],[0]);"`; + +exports[`when applied with uglify-es options matches snapshot for \`compress\` option (boolean false): manifest.js 1`] = `"(function(r){var e=window[\\"webpackJsonp\\"];window[\\"webpackJsonp\\"]=function n(f,i,u){var c,a,l=0,p=[],s;for(;l({a:t+n.a+a,b:t,baz:a})}},function(t,a,e){\\"use strict\\";a.a=\\"bar\\",a.b=\\"foo\\"}],[0]);"`; + +exports[`when applied with uglify-es options matches snapshot for \`compress\` option (boolean true): manifest.js 1`] = `"!function(r){var n=window.webpackJsonp;window.webpackJsonp=function(e,u,c){for(var f,i,p,a=0,l=[];a({a:t+n.a+a,b:t,baz:a})}},function(t,a,e){\\"use strict\\";a.a=\\"bar\\",a.b=\\"foo\\"}],[0]);"`; + +exports[`when applied with uglify-es options matches snapshot for \`compress\` option (object): manifest.js 1`] = `"!function(r){var n=window.webpackJsonp;window.webpackJsonp=function(e,u,c){var f,i,p,a=0,l=[];for(;a({a:t+n.a+a,b:t,baz:a})}},function(t,a,e){\\"use strict\\";a.a=\\"bar\\",a.b=\\"foo\\"}],[0]);"`; + +exports[`when applied with uglify-es options matches snapshot for \`ie8\` option: manifest.js 1`] = `"!function(r){var n=window.webpackJsonp;window.webpackJsonp=function(e,u,c){for(var f,i,p,a=0,l=[];a ({ - a: b + __WEBPACK_IMPORTED_MODULE_0__dep__.a + baz, - b: b, - baz: baz - }); - }; -}, function(module, __webpack_exports__, __webpack_require__) { - \\"use strict\\"; - __webpack_exports__.a = \\"bar\\", __webpack_exports__.b = \\"foo\\"; -} ], [ 0 ]);" -`; +exports[`when applied with uglify-es options matches snapshot for \`keep_classnames\` option: main.js 1`] = `"webpackJsonp([0],[function(t,a,e){\\"use strict\\";Object.defineProperty(a,\\"__esModule\\",{value:!0});var n=e(1);a.default=function(){const t=n.b,a=\`baz\${Math.random()}\`;return()=>({a:t+n.a+a,b:t,baz:a})}},function(t,a,e){\\"use strict\\";a.a=\\"bar\\",a.b=\\"foo\\"}],[0]);"`; -exports[`when applied with uglify-es options matches snapshot for \`keep_classnames\` option: manifest.js 1`] = ` -"!function(modules) { - var parentJsonpFunction = window.webpackJsonp; - window.webpackJsonp = function(chunkIds, moreModules, executeModules) { - for (var moduleId, chunkId, result, i = 0, resolves = []; i < chunkIds.length; i++) chunkId = chunkIds[i], - installedChunks[chunkId] && resolves.push(installedChunks[chunkId][0]), installedChunks[chunkId] = 0; - for (moduleId in moreModules) Object.prototype.hasOwnProperty.call(moreModules, moduleId) && (modules[moduleId] = moreModules[moduleId]); - for (parentJsonpFunction && parentJsonpFunction(chunkIds, moreModules, executeModules); resolves.length; ) resolves.shift()(); - if (executeModules) for (i = 0; i < executeModules.length; i++) result = __webpack_require__(__webpack_require__.s = executeModules[i]); - return result; - }; - var installedModules = {}, installedChunks = { - 1: 0 - }; - function __webpack_require__(moduleId) { - if (installedModules[moduleId]) return installedModules[moduleId].exports; - var module = installedModules[moduleId] = { - i: moduleId, - l: !1, - exports: {} - }; - return modules[moduleId].call(module.exports, module, module.exports, __webpack_require__), - module.l = !0, module.exports; - } - __webpack_require__.m = modules, __webpack_require__.c = installedModules, __webpack_require__.d = function(exports, name, getter) { - __webpack_require__.o(exports, name) || Object.defineProperty(exports, name, { - configurable: !1, - enumerable: !0, - get: getter - }); - }, __webpack_require__.n = function(module) { - var getter = module && module.__esModule ? function() { - return module.default; - } : function() { - return module; - }; - return __webpack_require__.d(getter, \\"a\\", getter), getter; - }, __webpack_require__.o = function(object, property) { - return Object.prototype.hasOwnProperty.call(object, property); - }, __webpack_require__.p = \\"\\", __webpack_require__.oe = function(err) { - throw console.error(err), err; - }; -}([]);" -`; +exports[`when applied with uglify-es options matches snapshot for \`keep_classnames\` option: manifest.js 1`] = `"!function(r){var n=window.webpackJsonp;window.webpackJsonp=function(e,u,c){for(var f,i,p,a=0,l=[];a ({ - a: b + __WEBPACK_IMPORTED_MODULE_0__dep__.a + baz, - b: b, - baz: baz - }); - }; -}, function(module, __webpack_exports__, __webpack_require__) { - \\"use strict\\"; - __webpack_exports__.a = \\"bar\\", __webpack_exports__.b = \\"foo\\"; -} ], [ 0 ]);" -`; +exports[`when applied with uglify-es options matches snapshot for \`keep_fnames\` option: main.js 1`] = `"webpackJsonp([0],[function(t,a,e){\\"use strict\\";Object.defineProperty(a,\\"__esModule\\",{value:!0});var o=e(1);a.default=function Foo(){const t=o.b,a=\`baz\${Math.random()}\`;return()=>({a:t+o.a+a,b:t,baz:a})}},function(t,a,e){\\"use strict\\";a.a=\\"bar\\",a.b=\\"foo\\"}],[0]);"`; -exports[`when applied with uglify-es options matches snapshot for \`keep_fnames\` option: manifest.js 1`] = ` -"!function(modules) { - var parentJsonpFunction = window.webpackJsonp; - window.webpackJsonp = function webpackJsonpCallback(chunkIds, moreModules, executeModules) { - for (var moduleId, chunkId, result, i = 0, resolves = []; i < chunkIds.length; i++) chunkId = chunkIds[i], - installedChunks[chunkId] && resolves.push(installedChunks[chunkId][0]), installedChunks[chunkId] = 0; - for (moduleId in moreModules) Object.prototype.hasOwnProperty.call(moreModules, moduleId) && (modules[moduleId] = moreModules[moduleId]); - for (parentJsonpFunction && parentJsonpFunction(chunkIds, moreModules, executeModules); resolves.length; ) resolves.shift()(); - if (executeModules) for (i = 0; i < executeModules.length; i++) result = __webpack_require__(__webpack_require__.s = executeModules[i]); - return result; - }; - var installedModules = {}, installedChunks = { - 1: 0 - }; - function __webpack_require__(moduleId) { - if (installedModules[moduleId]) return installedModules[moduleId].exports; - var module = installedModules[moduleId] = { - i: moduleId, - l: !1, - exports: {} - }; - return modules[moduleId].call(module.exports, module, module.exports, __webpack_require__), - module.l = !0, module.exports; - } - __webpack_require__.m = modules, __webpack_require__.c = installedModules, __webpack_require__.d = function(exports, name, getter) { - __webpack_require__.o(exports, name) || Object.defineProperty(exports, name, { - configurable: !1, - enumerable: !0, - get: getter - }); - }, __webpack_require__.n = function(module) { - var getter = module && module.__esModule ? function getDefault() { - return module.default; - } : function getModuleExports() { - return module; - }; - return __webpack_require__.d(getter, \\"a\\", getter), getter; - }, __webpack_require__.o = function(object, property) { - return Object.prototype.hasOwnProperty.call(object, property); - }, __webpack_require__.p = \\"\\", __webpack_require__.oe = function(err) { - throw console.error(err), err; - }; -}([]);" -`; +exports[`when applied with uglify-es options matches snapshot for \`keep_fnames\` option: manifest.js 1`] = `"!function(e){var r=window.webpackJsonp;window.webpackJsonp=function webpackJsonpCallback(_,n,o){for(var u,c,p,a=0,i=[];a<_.length;a++)c=_[a],t[c]&&i.push(t[c][0]),t[c]=0;for(u in n)Object.prototype.hasOwnProperty.call(n,u)&&(e[u]=n[u]);for(r&&r(_,n,o);i.length;)i.shift()();if(o)for(a=0;a({a:b+__WEBPACK_IMPORTED_MODULE_0__dep__.a+baz,b:b,baz:baz})}},function(module,__webpack_exports__,__webpack_require__){\\"use strict\\";__webpack_exports__.a=\\"bar\\",__webpack_exports__.b=\\"foo\\"}],[0]);"`; + +exports[`when applied with uglify-es options matches snapshot for \`mangle\` option (false): manifest.js 1`] = `"!function(modules){var parentJsonpFunction=window.webpackJsonp;window.webpackJsonp=function(chunkIds,moreModules,executeModules){for(var moduleId,chunkId,result,i=0,resolves=[];i({a:t+n.a+baz,b:t,baz:baz})}},function(t,a,e){\\"use strict\\";a.a=\\"bar\\",a.b=\\"foo\\"}],[0]);"`; + +exports[`when applied with uglify-es options matches snapshot for \`mangle\` option (object): manifest.js 1`] = `"!function(r){var n=window.webpackJsonp;window.webpackJsonp=function(e,u,c){for(var f,i,p,a=0,l=[];a({a:t+n.a+a,b:t,baz:a})}},function(t,a,e){\\"use strict\\";a.a=\\"bar\\",a.b=\\"foo\\"}],[0]);"`; + +exports[`when applied with uglify-es options matches snapshot for \`mangle\` option (true): manifest.js 1`] = `"!function(r){var n=window.webpackJsonp;window.webpackJsonp=function(e,u,c){for(var f,i,p,a=0,l=[];a ({ - a: b + __WEBPACK_IMPORTED_MODULE_0__dep__.a + baz, - b: b, - baz: baz - }); - }; -}, function(module, __webpack_exports__, __webpack_require__) { - \\"use strict\\"; - __webpack_exports__.a = \\"bar\\", __webpack_exports__.b = \\"foo\\"; -} ], [ 0 ]);" -`; +exports[`when applied with uglify-es options matches snapshot for \`nameCache\` option: main.js 1`] = `"webpackJsonp([0],[function(t,a,e){\\"use strict\\";Object.defineProperty(a,\\"__esModule\\",{value:!0});var n=e(1);a.default=function(){const t=n.b,a=\`baz\${Math.random()}\`;return()=>({a:t+n.a+a,b:t,baz:a})}},function(t,a,e){\\"use strict\\";a.a=\\"bar\\",a.b=\\"foo\\"}],[0]);"`; -exports[`when applied with uglify-es options matches snapshot for \`nameCache\` option: manifest.js 1`] = ` -"!function(modules) { - var parentJsonpFunction = window.webpackJsonp; - window.webpackJsonp = function(chunkIds, moreModules, executeModules) { - for (var moduleId, chunkId, result, i = 0, resolves = []; i < chunkIds.length; i++) chunkId = chunkIds[i], - installedChunks[chunkId] && resolves.push(installedChunks[chunkId][0]), installedChunks[chunkId] = 0; - for (moduleId in moreModules) Object.prototype.hasOwnProperty.call(moreModules, moduleId) && (modules[moduleId] = moreModules[moduleId]); - for (parentJsonpFunction && parentJsonpFunction(chunkIds, moreModules, executeModules); resolves.length; ) resolves.shift()(); - if (executeModules) for (i = 0; i < executeModules.length; i++) result = __webpack_require__(__webpack_require__.s = executeModules[i]); - return result; - }; - var installedModules = {}, installedChunks = { - 1: 0 - }; - function __webpack_require__(moduleId) { - if (installedModules[moduleId]) return installedModules[moduleId].exports; - var module = installedModules[moduleId] = { - i: moduleId, - l: !1, - exports: {} - }; - return modules[moduleId].call(module.exports, module, module.exports, __webpack_require__), - module.l = !0, module.exports; - } - __webpack_require__.m = modules, __webpack_require__.c = installedModules, __webpack_require__.d = function(exports, name, getter) { - __webpack_require__.o(exports, name) || Object.defineProperty(exports, name, { - configurable: !1, - enumerable: !0, - get: getter - }); - }, __webpack_require__.n = function(module) { - var getter = module && module.__esModule ? function() { - return module.default; - } : function() { - return module; - }; - return __webpack_require__.d(getter, \\"a\\", getter), getter; - }, __webpack_require__.o = function(object, property) { - return Object.prototype.hasOwnProperty.call(object, property); - }, __webpack_require__.p = \\"\\", __webpack_require__.oe = function(err) { - throw console.error(err), err; - }; -}([]);" -`; +exports[`when applied with uglify-es options matches snapshot for \`nameCache\` option: manifest.js 1`] = `"!function(r){var n=window.webpackJsonp;window.webpackJsonp=function(e,u,c){for(var f,i,p,a=0,l=[];a ({ - a: b + __WEBPACK_IMPORTED_MODULE_0__dep__.a + baz, - b: b, - baz: baz + a: t + n.a + a, + b: t, + baz: a }); }; -}, function(module, __webpack_exports__, __webpack_require__) { +}, function(t, a, e) { \\"use strict\\"; - __webpack_exports__.a = \\"bar\\", __webpack_exports__.b = \\"foo\\"; + a.a = \\"bar\\", a.b = \\"foo\\"; } ], [ 0 ]);" `; -exports[`when applied with uglify-es options matches snapshot for \`safari10\` option: manifest.js 1`] = ` -"!function(modules) { - var parentJsonpFunction = window.webpackJsonp; - window.webpackJsonp = function(chunkIds, moreModules, executeModules) { - for (var moduleId, chunkId, result, i = 0, resolves = []; i < chunkIds.length; i++) chunkId = chunkIds[i], - installedChunks[chunkId] && resolves.push(installedChunks[chunkId][0]), installedChunks[chunkId] = 0; - for (moduleId in moreModules) Object.prototype.hasOwnProperty.call(moreModules, moduleId) && (modules[moduleId] = moreModules[moduleId]); - for (parentJsonpFunction && parentJsonpFunction(chunkIds, moreModules, executeModules); resolves.length; ) resolves.shift()(); - if (executeModules) for (i = 0; i < executeModules.length; i++) result = __webpack_require__(__webpack_require__.s = executeModules[i]); - return result; - }; - var installedModules = {}, installedChunks = { +exports[`when applied with uglify-es options matches snapshot for \`output\` option: manifest.js 1`] = ` +"!function(r) { + var n = window.webpackJsonp; + window.webpackJsonp = function(e, u, c) { + for (var f, i, p, a = 0, l = []; a < e.length; a++) i = e[a], o[i] && l.push(o[i][0]), + o[i] = 0; + for (f in u) Object.prototype.hasOwnProperty.call(u, f) && (r[f] = u[f]); + for (n && n(e, u, c); l.length; ) l.shift()(); + if (c) for (a = 0; a < c.length; a++) p = t(t.s = c[a]); + return p; + }; + var e = {}, o = { 1: 0 }; - function __webpack_require__(moduleId) { - if (installedModules[moduleId]) return installedModules[moduleId].exports; - var module = installedModules[moduleId] = { - i: moduleId, + function t(n) { + if (e[n]) return e[n].exports; + var o = e[n] = { + i: n, l: !1, exports: {} }; - return modules[moduleId].call(module.exports, module, module.exports, __webpack_require__), - module.l = !0, module.exports; + return r[n].call(o.exports, o, o.exports, t), o.l = !0, o.exports; } - __webpack_require__.m = modules, __webpack_require__.c = installedModules, __webpack_require__.d = function(exports, name, getter) { - __webpack_require__.o(exports, name) || Object.defineProperty(exports, name, { + t.m = r, t.c = e, t.d = function(r, n, e) { + t.o(r, n) || Object.defineProperty(r, n, { configurable: !1, enumerable: !0, - get: getter + get: e }); - }, __webpack_require__.n = function(module) { - var getter = module && module.__esModule ? function() { - return module.default; + }, t.n = function(r) { + var n = r && r.__esModule ? function() { + return r.default; } : function() { - return module; + return r; }; - return __webpack_require__.d(getter, \\"a\\", getter), getter; - }, __webpack_require__.o = function(object, property) { - return Object.prototype.hasOwnProperty.call(object, property); - }, __webpack_require__.p = \\"\\", __webpack_require__.oe = function(err) { - throw console.error(err), err; + return t.d(n, \\"a\\", n), n; + }, t.o = function(r, n) { + return Object.prototype.hasOwnProperty.call(r, n); + }, t.p = \\"\\", t.oe = function(r) { + throw console.error(r), r; }; }([]);" `; +exports[`when applied with uglify-es options matches snapshot for \`output\` option: warnings 1`] = `Array []`; + +exports[`when applied with uglify-es options matches snapshot for \`parse\` options: errors 1`] = `Array []`; + +exports[`when applied with uglify-es options matches snapshot for \`parse\` options: main.js 1`] = `"webpackJsonp([0],[function(t,a,e){\\"use strict\\";Object.defineProperty(a,\\"__esModule\\",{value:!0});var n=e(1);a.default=function(){const t=n.b,a=\`baz\${Math.random()}\`;return()=>({a:t+n.a+a,b:t,baz:a})}},function(t,a,e){\\"use strict\\";a.a=\\"bar\\",a.b=\\"foo\\"}],[0]);"`; + +exports[`when applied with uglify-es options matches snapshot for \`parse\` options: manifest.js 1`] = `"!function(r){var n=window.webpackJsonp;window.webpackJsonp=function(e,u,c){for(var f,i,p,a=0,l=[];a({a:t+n.a+a,b:t,baz:a})}},function(t,a,e){\\"use strict\\";a.a=\\"bar\\",a.b=\\"foo\\"}],[0]);"`; + +exports[`when applied with uglify-es options matches snapshot for \`safari10\` option: manifest.js 1`] = `"!function(r){var n=window.webpackJsonp;window.webpackJsonp=function(e,u,c){for(var f,i,p,a=0,l=[];a ({ - a: b + __WEBPACK_IMPORTED_MODULE_0__dep__.a + baz, - b: b, - baz: baz - }); - }; -}, function(module, __webpack_exports__, __webpack_require__) { - \\"use strict\\"; - __webpack_exports__.a = \\"bar\\", __webpack_exports__.b = \\"foo\\"; -} ], [ 0 ]);" -`; +exports[`when applied with uglify-es options matches snapshot for \`toplevel\` option: main.js 1`] = `"webpackJsonp([0],[function(t,a,e){\\"use strict\\";Object.defineProperty(a,\\"__esModule\\",{value:!0});var n=e(1);a.default=function(){const t=n.b,a=\`baz\${Math.random()}\`;return()=>({a:t+n.a+a,b:t,baz:a})}},function(t,a,e){\\"use strict\\";a.a=\\"bar\\",a.b=\\"foo\\"}],[0]);"`; -exports[`when applied with uglify-es options matches snapshot for \`toplevel\` option: manifest.js 1`] = ` -"!function(modules) { - var parentJsonpFunction = window.webpackJsonp; - window.webpackJsonp = function(chunkIds, moreModules, executeModules) { - for (var moduleId, chunkId, result, i = 0, resolves = []; i < chunkIds.length; i++) chunkId = chunkIds[i], - installedChunks[chunkId] && resolves.push(installedChunks[chunkId][0]), installedChunks[chunkId] = 0; - for (moduleId in moreModules) Object.prototype.hasOwnProperty.call(moreModules, moduleId) && (modules[moduleId] = moreModules[moduleId]); - for (parentJsonpFunction && parentJsonpFunction(chunkIds, moreModules, executeModules); resolves.length; ) resolves.shift()(); - if (executeModules) for (i = 0; i < executeModules.length; i++) result = __webpack_require__(__webpack_require__.s = executeModules[i]); - return result; - }; - var installedModules = {}, installedChunks = { - 1: 0 - }; - function __webpack_require__(moduleId) { - if (installedModules[moduleId]) return installedModules[moduleId].exports; - var module = installedModules[moduleId] = { - i: moduleId, - l: !1, - exports: {} - }; - return modules[moduleId].call(module.exports, module, module.exports, __webpack_require__), - module.l = !0, module.exports; - } - __webpack_require__.m = modules, __webpack_require__.c = installedModules, __webpack_require__.d = function(exports, name, getter) { - __webpack_require__.o(exports, name) || Object.defineProperty(exports, name, { - configurable: !1, - enumerable: !0, - get: getter - }); - }, __webpack_require__.n = function(module) { - var getter = module && module.__esModule ? function() { - return module.default; - } : function() { - return module; - }; - return __webpack_require__.d(getter, \\"a\\", getter), getter; - }, __webpack_require__.o = function(object, property) { - return Object.prototype.hasOwnProperty.call(object, property); - }, __webpack_require__.p = \\"\\", __webpack_require__.oe = function(err) { - throw console.error(err), err; - }; -}([]);" -`; +exports[`when applied with uglify-es options matches snapshot for \`toplevel\` option: manifest.js 1`] = `"!function(r){var n=window.webpackJsonp;window.webpackJsonp=function(e,u,c){for(var f,i,p,a=0,l=[];a { - it('matches snapshot for `toplevel` option', () => { + it('matches snapshot for `parse` options', () => { + const compiler = createCompiler({ + entry: `${__dirname}/fixtures/import-export/entry.js`, + output: { + path: `${__dirname}/dist-import-export`, + filename: '[name].js', + chunkFilename: '[id].[name].js', + }, + }); + + new UglifyJsPlugin({ + uglifyOptions: { + parse: { + ecma: 8, + }, + }, + }).apply(compiler); + + return compile(compiler).then((stats) => { + const errors = stats.compilation.errors.map(cleanErrorStack); + const warnings = stats.compilation.warnings.map(cleanErrorStack); + + expect(errors).toMatchSnapshot('errors'); + expect(warnings).toMatchSnapshot('warnings'); + + for (const file in stats.compilation.assets) { + if (Object.prototype.hasOwnProperty.call(stats.compilation.assets, file)) { + expect(stats.compilation.assets[file].source()).toMatchSnapshot(file); + } + } + }); + }); + + it('matches snapshot for `compress` option (boolean true)', () => { + const compiler = createCompiler({ + entry: `${__dirname}/fixtures/import-export/entry.js`, + output: { + path: `${__dirname}/dist-import-export`, + filename: '[name].js', + chunkFilename: '[id].[name].js', + }, + }); + + new UglifyJsPlugin({ + uglifyOptions: { + compress: true, + }, + }).apply(compiler); + + return compile(compiler).then((stats) => { + const errors = stats.compilation.errors.map(cleanErrorStack); + const warnings = stats.compilation.warnings.map(cleanErrorStack); + + expect(errors).toMatchSnapshot('errors'); + expect(warnings).toMatchSnapshot('warnings'); + + for (const file in stats.compilation.assets) { + if (Object.prototype.hasOwnProperty.call(stats.compilation.assets, file)) { + expect(stats.compilation.assets[file].source()).toMatchSnapshot(file); + } + } + }); + }); + + it('matches snapshot for `compress` option (boolean false)', () => { + const compiler = createCompiler({ + entry: `${__dirname}/fixtures/import-export/entry.js`, + output: { + path: `${__dirname}/dist-import-export`, + filename: '[name].js', + chunkFilename: '[id].[name].js', + }, + }); + + new UglifyJsPlugin({ + uglifyOptions: { + compress: false, + }, + }).apply(compiler); + + return compile(compiler).then((stats) => { + const errors = stats.compilation.errors.map(cleanErrorStack); + const warnings = stats.compilation.warnings.map(cleanErrorStack); + + expect(errors).toMatchSnapshot('errors'); + expect(warnings).toMatchSnapshot('warnings'); + + for (const file in stats.compilation.assets) { + if (Object.prototype.hasOwnProperty.call(stats.compilation.assets, file)) { + expect(stats.compilation.assets[file].source()).toMatchSnapshot(file); + } + } + }); + }); + + it('matches snapshot for `compress` option (object)', () => { + const compiler = createCompiler({ + entry: `${__dirname}/fixtures/import-export/entry.js`, + output: { + path: `${__dirname}/dist-import-export`, + filename: '[name].js', + chunkFilename: '[id].[name].js', + }, + }); + + new UglifyJsPlugin({ + uglifyOptions: { + compress: { + join_vars: false, + }, + }, + }).apply(compiler); + + return compile(compiler).then((stats) => { + const errors = stats.compilation.errors.map(cleanErrorStack); + const warnings = stats.compilation.warnings.map(cleanErrorStack); + + expect(errors).toMatchSnapshot('errors'); + expect(warnings).toMatchSnapshot('warnings'); + + for (const file in stats.compilation.assets) { + if (Object.prototype.hasOwnProperty.call(stats.compilation.assets, file)) { + expect(stats.compilation.assets[file].source()).toMatchSnapshot(file); + } + } + }); + }); + + it('matches snapshot for `mangle` option (true)', () => { + const compiler = createCompiler({ + entry: `${__dirname}/fixtures/import-export/entry.js`, + output: { + path: `${__dirname}/dist-import-export`, + filename: '[name].js', + chunkFilename: '[id].[name].js', + }, + }); + + new UglifyJsPlugin({ + uglifyOptions: { + mangle: true, + }, + }).apply(compiler); + + return compile(compiler).then((stats) => { + const errors = stats.compilation.errors.map(cleanErrorStack); + const warnings = stats.compilation.warnings.map(cleanErrorStack); + + expect(errors).toMatchSnapshot('errors'); + expect(warnings).toMatchSnapshot('warnings'); + + for (const file in stats.compilation.assets) { + if (Object.prototype.hasOwnProperty.call(stats.compilation.assets, file)) { + expect(stats.compilation.assets[file].source()).toMatchSnapshot(file); + } + } + }); + }); + + it('matches snapshot for `mangle` option (false)', () => { const compiler = createCompiler({ entry: `${__dirname}/fixtures/import-export/entry.js`, output: { @@ -18,9 +177,70 @@ describe('when applied with uglify-es options', () => { new UglifyJsPlugin({ uglifyOptions: { - toplevel: true, mangle: false, - warnings: true, + }, + }).apply(compiler); + + return compile(compiler).then((stats) => { + const errors = stats.compilation.errors.map(cleanErrorStack); + const warnings = stats.compilation.warnings.map(cleanErrorStack); + + expect(errors).toMatchSnapshot('errors'); + expect(warnings).toMatchSnapshot('warnings'); + + for (const file in stats.compilation.assets) { + if (Object.prototype.hasOwnProperty.call(stats.compilation.assets, file)) { + expect(stats.compilation.assets[file].source()).toMatchSnapshot(file); + } + } + }); + }); + + it('matches snapshot for `mangle` option (object)', () => { + const compiler = createCompiler({ + entry: `${__dirname}/fixtures/import-export/entry.js`, + output: { + path: `${__dirname}/dist-import-export`, + filename: '[name].js', + chunkFilename: '[id].[name].js', + }, + }); + + new UglifyJsPlugin({ + uglifyOptions: { + mangle: { + reserved: ['baz'], + }, + }, + }).apply(compiler); + + return compile(compiler).then((stats) => { + const errors = stats.compilation.errors.map(cleanErrorStack); + const warnings = stats.compilation.warnings.map(cleanErrorStack); + + expect(errors).toMatchSnapshot('errors'); + expect(warnings).toMatchSnapshot('warnings'); + + for (const file in stats.compilation.assets) { + if (Object.prototype.hasOwnProperty.call(stats.compilation.assets, file)) { + expect(stats.compilation.assets[file].source()).toMatchSnapshot(file); + } + } + }); + }); + + it('matches snapshot for `output` option', () => { + const compiler = createCompiler({ + entry: `${__dirname}/fixtures/import-export/entry.js`, + output: { + path: `${__dirname}/dist-import-export`, + filename: '[name].js', + chunkFilename: '[id].[name].js', + }, + }); + + new UglifyJsPlugin({ + uglifyOptions: { output: { beautify: true, }, @@ -42,6 +262,37 @@ describe('when applied with uglify-es options', () => { }); }); + it('matches snapshot for `toplevel` option', () => { + const compiler = createCompiler({ + entry: `${__dirname}/fixtures/import-export/entry.js`, + output: { + path: `${__dirname}/dist-import-export`, + filename: '[name].js', + chunkFilename: '[id].[name].js', + }, + }); + + new UglifyJsPlugin({ + uglifyOptions: { + toplevel: true, + }, + }).apply(compiler); + + return compile(compiler).then((stats) => { + const errors = stats.compilation.errors.map(cleanErrorStack); + const warnings = stats.compilation.warnings.map(cleanErrorStack); + + expect(errors).toMatchSnapshot('errors'); + expect(warnings).toMatchSnapshot('warnings'); + + for (const file in stats.compilation.assets) { + if (Object.prototype.hasOwnProperty.call(stats.compilation.assets, file)) { + expect(stats.compilation.assets[file].source()).toMatchSnapshot(file); + } + } + }); + }); + it('matches snapshot for `nameCache` option', () => { const compiler = createCompiler({ entry: `${__dirname}/fixtures/import-export/entry.js`, @@ -55,11 +306,37 @@ describe('when applied with uglify-es options', () => { new UglifyJsPlugin({ uglifyOptions: { nameCache: {}, - mangle: false, - warnings: true, - output: { - beautify: true, - }, + }, + }).apply(compiler); + + return compile(compiler).then((stats) => { + const errors = stats.compilation.errors.map(cleanErrorStack); + const warnings = stats.compilation.warnings.map(cleanErrorStack); + + expect(errors).toMatchSnapshot('errors'); + expect(warnings).toMatchSnapshot('warnings'); + + for (const file in stats.compilation.assets) { + if (Object.prototype.hasOwnProperty.call(stats.compilation.assets, file)) { + expect(stats.compilation.assets[file].source()).toMatchSnapshot(file); + } + } + }); + }); + + it('matches snapshot for `ie8` option', () => { + const compiler = createCompiler({ + entry: `${__dirname}/fixtures/import-export/entry.js`, + output: { + path: `${__dirname}/dist-import-export`, + filename: '[name].js', + chunkFilename: '[id].[name].js', + }, + }); + + new UglifyJsPlugin({ + uglifyOptions: { + ie8: true, }, }).apply(compiler); @@ -91,11 +368,6 @@ describe('when applied with uglify-es options', () => { new UglifyJsPlugin({ uglifyOptions: { keep_classnames: true, - mangle: false, - warnings: true, - output: { - beautify: true, - }, }, }).apply(compiler); @@ -127,11 +399,6 @@ describe('when applied with uglify-es options', () => { new UglifyJsPlugin({ uglifyOptions: { keep_fnames: true, - mangle: false, - warnings: true, - output: { - beautify: true, - }, }, }).apply(compiler); @@ -163,11 +430,6 @@ describe('when applied with uglify-es options', () => { new UglifyJsPlugin({ uglifyOptions: { safari10: true, - mangle: false, - warnings: true, - output: { - beautify: true, - }, }, }).apply(compiler); @@ -185,4 +447,31 @@ describe('when applied with uglify-es options', () => { } }); }); + + it('disable inline optimization by default (have a lot of problems)', () => { + const compiler = createCompiler({ + entry: `${__dirname}/fixtures/inline-optimization.js`, + output: { + path: `${__dirname}/dist-inline-optimization`, + filename: '[name].js', + chunkFilename: '[id].[name].js', + }, + }); + + new UglifyJsPlugin().apply(compiler); + + return compile(compiler).then((stats) => { + const errors = stats.compilation.errors.map(cleanErrorStack); + const warnings = stats.compilation.warnings.map(cleanErrorStack); + + expect(errors).toMatchSnapshot('errors'); + expect(warnings).toMatchSnapshot('warnings'); + + for (const file in stats.compilation.assets) { + if (Object.prototype.hasOwnProperty.call(stats.compilation.assets, file)) { + expect(stats.compilation.assets[file].source()).toMatchSnapshot(file); + } + } + }); + }); });