From 99b12912f93a95e9feba95847ff935d8d41fee80 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Sat, 9 Jun 2018 15:05:39 +0300 Subject: [PATCH] fix: disable inline optimization by default --- README.md | 4 +- src/index.js | 3 + src/uglify/minify.js | 14 +- test/__snapshots__/all-options.test.js.snap | 59 ++- test/__snapshots__/ecma.test.js.snap | 363 ++++++++--------- .../__snapshots__/uglify-options.test.js.snap | 383 +++++++++--------- test/fixtures/inline-optimization.js | 23 ++ test/uglify-options.test.js | 27 ++ 8 files changed, 466 insertions(+), 410 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..a4674926 100644 --- a/src/index.js +++ b/src/index.js @@ -42,6 +42,9 @@ class UglifyJsPlugin { include, exclude, uglifyOptions: { + compress: { + inline: false, + }, output: { comments: extractComments ? false : /^\**!|@preserve|@license|@cc_on/, }, diff --git a/src/uglify/minify.js b/src/uglify/minify.js index 94f7e1b1..b063ba5d 100644 --- a/src/uglify/minify.js +++ b/src/uglify/minify.js @@ -21,9 +21,15 @@ const buildUglifyOptions = ({ } = {}) => ({ ecma, warnings, - parse, - compress, - mangle: mangle == null ? true : mangle, + parse: { + ...parse, + }, + compress: { + ...compress, + }, + mangle: mangle == null ? true : { + ...mangle, + }, output: { shebang: true, comments: false, @@ -31,7 +37,7 @@ const buildUglifyOptions = ({ semicolons: true, ...output, }, - // Ignoring sourcemap from options + // Ignoring sourceMap from options sourceMap: null, toplevel, nameCache, diff --git a/test/__snapshots__/all-options.test.js.snap b/test/__snapshots__/all-options.test.js.snap index b5c2c576..c501056b 100644 --- a/test/__snapshots__/all-options.test.js.snap +++ b/test/__snapshots__/all-options.test.js.snap @@ -3,54 +3,53 @@ exports[`when applied with all options matches snapshot: errors 1`] = `Array []`; exports[`when applied with all options matches snapshot: main.0c220ec66316af2c1b24.js 1`] = ` -"webpackJsonp([ 0 ], [ function(module, exports) { - module.exports = function() { +"webpackJsonp([ 0 ], [ function(o, n) { + o.exports = function() { console.log(7); }; } ], [ 0 ]);" `; exports[`when applied with all options matches snapshot: manifest.d6857f782c13a99b5917.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; +"!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 installedModules = {}, installedChunks = { + 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; }; }([]);" `; diff --git a/test/__snapshots__/ecma.test.js.snap b/test/__snapshots__/ecma.test.js.snap index 15a3f5e2..6cf20384 100644 --- a/test/__snapshots__/ecma.test.js.snap +++ b/test/__snapshots__/ecma.test.js.snap @@ -3,18 +3,18 @@ exports[`when applied with uglifyOptions.ecma matches snapshot for ecma 5: errors 1`] = `Array []`; exports[`when applied with uglifyOptions.ecma matches snapshot for ecma 5: main.js 1`] = ` -"webpackJsonp([ 0 ], [ function(module, exports) { - var Person = { +"webpackJsonp([ 0 ], [ function(e, a) { + var l = { firstName: null, lastName: null - }, Employee = Object.create(Person, { + }, n = Object.create(l, { id: { value: null, enumerable: !0, configurable: !0, writable: !0 } - }), Manager = Object.create(Employee, { + }), r = Object.create(n, { department: { value: null, enumerable: !0, @@ -22,55 +22,54 @@ exports[`when applied with uglifyOptions.ecma matches snapshot for ecma 5: main. writable: !0 } }); - module.exports = { - Person: Person, - Employee: Employee, - Manager: Manager + e.exports = { + Person: l, + Employee: n, + Manager: r }; } ], [ 0 ]);" `; exports[`when applied with uglifyOptions.ecma matches snapshot for ecma 5: 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; +"!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 installedModules = {}, installedChunks = { + 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; }; }([]);" `; @@ -80,76 +79,75 @@ exports[`when applied with uglifyOptions.ecma matches snapshot for ecma 5: warni exports[`when applied with uglifyOptions.ecma matches snapshot for ecma 6: errors 1`] = `Array []`; exports[`when applied with uglifyOptions.ecma matches snapshot for ecma 6: main.js 1`] = ` -"webpackJsonp([ 0 ], [ function(module, exports) { - module.exports = class { - constructor(principal, years, rate) { - this.principal = principal, this.years = years, this.rate = rate; +"webpackJsonp([ 0 ], [ function(t, e) { + t.exports = class { + constructor(t, e, i) { + this.principal = t, this.years = e, this.rate = i; } get monthlyPayment() { - let monthlyRate = this.rate / 100 / 12; - return this.principal * monthlyRate / (1 - Math.pow(1 / (1 + monthlyRate), 12 * this.years)); + let t = this.rate / 100 / 12; + return this.principal * t / (1 - Math.pow(1 / (1 + t), 12 * this.years)); } get amortization() { - let monthlyPayment = this.monthlyPayment, monthlyRate = this.rate / 100 / 12, balance = this.principal, amortization = []; - for (let y = 0; y < this.years; y++) { - let interestY = 0, principalY = 0; - for (let m = 0; m < 12; m++) { - let interestM = balance * monthlyRate, principalM = monthlyPayment - interestM; - interestY += interestM, principalY += principalM, balance -= principalM; + let t = this.monthlyPayment, e = this.rate / 100 / 12, i = this.principal, r = []; + for (let s = 0; s < this.years; s++) { + let s = 0, a = 0; + for (let r = 0; r < 12; r++) { + let r = i * e, n = t - r; + s += r, a += n, i -= n; } - amortization.push({ - principalY, - interestY, - balance + r.push({ + principalY: a, + interestY: s, + balance: i }); } - return amortization; + return r; } }; } ], [ 0 ]);" `; exports[`when applied with uglifyOptions.ecma matches snapshot for ecma 6: 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; +"!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 installedModules = {}, installedChunks = { + 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; }; }([]);" `; @@ -159,54 +157,53 @@ exports[`when applied with uglifyOptions.ecma matches snapshot for ecma 6: warni exports[`when applied with uglifyOptions.ecma matches snapshot for ecma 7: errors 1`] = `Array []`; exports[`when applied with uglifyOptions.ecma matches snapshot for ecma 7: main.js 1`] = ` -"webpackJsonp([ 0 ], [ function(module, exports) { - module.exports = function(base, exponent) { - return base ** exponent; +"webpackJsonp([ 0 ], [ function(n, o) { + n.exports = function(n, o) { + return n ** o; }; } ], [ 0 ]);" `; exports[`when applied with uglifyOptions.ecma matches snapshot for ecma 7: 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; +"!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 installedModules = {}, installedChunks = { + 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; }; }([]);" `; @@ -216,59 +213,58 @@ exports[`when applied with uglifyOptions.ecma matches snapshot for ecma 7: warni exports[`when applied with uglifyOptions.ecma matches snapshot for ecma 8: errors 1`] = `Array []`; exports[`when applied with uglifyOptions.ecma matches snapshot for ecma 8: main.js 1`] = ` -"webpackJsonp([ 0 ], [ function(module, exports) { - module.exports = async function(url) { +"webpackJsonp([ 0 ], [ function(t, a) { + t.exports = async function(t) { try { - let request = await fetch(url), text = await request.text(); - return JSON.parse(text); - } catch (error) { - console.log(\`ERROR: \${error.stack}\`); + let a = await fetch(t), c = await a.text(); + return JSON.parse(c); + } catch (t) { + console.log(\`ERROR: \${t.stack}\`); } }; } ], [ 0 ]);" `; exports[`when applied with uglifyOptions.ecma matches snapshot for ecma 8: 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; +"!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 installedModules = {}, installedChunks = { + 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; }; }([]);" `; @@ -278,67 +274,66 @@ exports[`when applied with uglifyOptions.ecma matches snapshot for ecma 8: warni exports[`when applied with uglifyOptions.ecma matches snapshot for import and export: errors 1`] = `Array []`; exports[`when applied with uglifyOptions.ecma matches snapshot for import and export: main.js 1`] = ` -"webpackJsonp([ 0 ], [ function(module, __webpack_exports__, __webpack_require__) { +"webpackJsonp([ 0 ], [ function(t, a, e) { \\"use strict\\"; - Object.defineProperty(__webpack_exports__, \\"__esModule\\", { + Object.defineProperty(a, \\"__esModule\\", { value: !0 }); - var __WEBPACK_IMPORTED_MODULE_0__dep__ = __webpack_require__(1); - __webpack_exports__.default = function() { - const b = __WEBPACK_IMPORTED_MODULE_0__dep__.b, baz = \`baz\${Math.random()}\`; + var n = e(1); + a.default = function() { + const t = n.b, a = \`baz\${Math.random()}\`; return () => ({ - 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 uglifyOptions.ecma matches snapshot for import and export: 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; +"!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 installedModules = {}, installedChunks = { + 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; }; }([]);" `; diff --git a/test/__snapshots__/uglify-options.test.js.snap b/test/__snapshots__/uglify-options.test.js.snap index 6c642bbe..56bf3e1d 100644 --- a/test/__snapshots__/uglify-options.test.js.snap +++ b/test/__snapshots__/uglify-options.test.js.snap @@ -1,69 +1,76 @@ // 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(e,n,s){\\"use strict\\";function t(e){return!e.fatal&&!e.ruleId&&e.message.includes(\\"eslint-disable\\")}e.exports=(e=>{for(let n=e.length-1;n>=0;--n){const s=e[n];t(s)&&console.log(s)}})}],[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 ({ - 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 \`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; +"!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 installedModules = {}, installedChunks = { + 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; }; }([]);" `; @@ -73,67 +80,66 @@ exports[`when applied with uglify-es options matches snapshot for \`keep_classna exports[`when applied with uglify-es options matches snapshot for \`keep_fnames\` option: errors 1`] = `Array []`; exports[`when applied with uglify-es options matches snapshot for \`keep_fnames\` option: main.js 1`] = ` -"webpackJsonp([ 0 ], [ function(module, __webpack_exports__, __webpack_require__) { +"webpackJsonp([ 0 ], [ function(t, a, e) { \\"use strict\\"; - Object.defineProperty(__webpack_exports__, \\"__esModule\\", { + Object.defineProperty(a, \\"__esModule\\", { value: !0 }); - var __WEBPACK_IMPORTED_MODULE_0__dep__ = __webpack_require__(1); - __webpack_exports__.default = function Foo() { - const b = __WEBPACK_IMPORTED_MODULE_0__dep__.b, baz = \`baz\${Math.random()}\`; + var o = e(1); + a.default = function Foo() { + const t = o.b, a = \`baz\${Math.random()}\`; return () => ({ - a: b + __WEBPACK_IMPORTED_MODULE_0__dep__.a + baz, - b: b, - baz: baz + a: t + o.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 \`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; +"!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 < o.length; a++) p = __webpack_require__(__webpack_require__.s = o[a]); + return p; }; - var installedModules = {}, installedChunks = { + var _ = {}, t = { 1: 0 }; - function __webpack_require__(moduleId) { - if (installedModules[moduleId]) return installedModules[moduleId].exports; - var module = installedModules[moduleId] = { - i: moduleId, + function __webpack_require__(r) { + if (_[r]) return _[r].exports; + var t = _[r] = { + i: r, l: !1, exports: {} }; - return modules[moduleId].call(module.exports, module, module.exports, __webpack_require__), - module.l = !0, module.exports; + return e[r].call(t.exports, t, t.exports, __webpack_require__), t.l = !0, t.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, { + __webpack_require__.m = e, __webpack_require__.c = _, __webpack_require__.d = function(e, r, _) { + __webpack_require__.o(e, r) || Object.defineProperty(e, r, { configurable: !1, enumerable: !0, - get: getter + get: _ }); - }, __webpack_require__.n = function(module) { - var getter = module && module.__esModule ? function getDefault() { - return module.default; + }, __webpack_require__.n = function(e) { + var r = e && e.__esModule ? function getDefault() { + return e.default; } : function getModuleExports() { - return module; + return e; }; - 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 __webpack_require__.d(r, \\"a\\", r), r; + }, __webpack_require__.o = function(e, r) { + return Object.prototype.hasOwnProperty.call(e, r); + }, __webpack_require__.p = \\"\\", __webpack_require__.oe = function(e) { + throw console.error(e), e; }; }([]);" `; @@ -143,67 +149,66 @@ exports[`when applied with uglify-es options matches snapshot for \`keep_fnames\ exports[`when applied with uglify-es options matches snapshot for \`nameCache\` option: errors 1`] = `Array []`; exports[`when applied with uglify-es options matches snapshot for \`nameCache\` option: main.js 1`] = ` -"webpackJsonp([ 0 ], [ function(module, __webpack_exports__, __webpack_require__) { +"webpackJsonp([ 0 ], [ function(t, a, e) { \\"use strict\\"; - Object.defineProperty(__webpack_exports__, \\"__esModule\\", { + Object.defineProperty(a, \\"__esModule\\", { value: !0 }); - var __WEBPACK_IMPORTED_MODULE_0__dep__ = __webpack_require__(1); - __webpack_exports__.default = function() { - const b = __WEBPACK_IMPORTED_MODULE_0__dep__.b, baz = \`baz\${Math.random()}\`; + var n = e(1); + a.default = function() { + const t = n.b, a = \`baz\${Math.random()}\`; return () => ({ - 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 \`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; +"!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 installedModules = {}, installedChunks = { + 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; }; }([]);" `; @@ -213,67 +218,66 @@ exports[`when applied with uglify-es options matches snapshot for \`nameCache\` exports[`when applied with uglify-es options matches snapshot for \`safari10\` option: errors 1`] = `Array []`; exports[`when applied with uglify-es options matches snapshot for \`safari10\` option: main.js 1`] = ` -"webpackJsonp([ 0 ], [ function(module, __webpack_exports__, __webpack_require__) { +"webpackJsonp([ 0 ], [ function(t, a, e) { \\"use strict\\"; - Object.defineProperty(__webpack_exports__, \\"__esModule\\", { + Object.defineProperty(a, \\"__esModule\\", { value: !0 }); - var __WEBPACK_IMPORTED_MODULE_0__dep__ = __webpack_require__(1); - __webpack_exports__.default = function() { - const b = __WEBPACK_IMPORTED_MODULE_0__dep__.b, baz = \`baz\${Math.random()}\`; + var n = e(1); + a.default = function() { + const t = n.b, a = \`baz\${Math.random()}\`; return () => ({ - 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; +"!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 installedModules = {}, installedChunks = { + 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; }; }([]);" `; @@ -283,67 +287,66 @@ exports[`when applied with uglify-es options matches snapshot for \`safari10\` o exports[`when applied with uglify-es options matches snapshot for \`toplevel\` option: errors 1`] = `Array []`; exports[`when applied with uglify-es options matches snapshot for \`toplevel\` option: main.js 1`] = ` -"webpackJsonp([ 0 ], [ function(module, __webpack_exports__, __webpack_require__) { +"webpackJsonp([ 0 ], [ function(t, a, e) { \\"use strict\\"; - Object.defineProperty(__webpack_exports__, \\"__esModule\\", { + Object.defineProperty(a, \\"__esModule\\", { value: !0 }); - var __WEBPACK_IMPORTED_MODULE_0__dep__ = __webpack_require__(1); - __webpack_exports__.default = function() { - const b = __WEBPACK_IMPORTED_MODULE_0__dep__.b, baz = \`baz\${Math.random()}\`; + var n = e(1); + a.default = function() { + const t = n.b, a = \`baz\${Math.random()}\`; return () => ({ - 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 \`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; +"!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 installedModules = {}, installedChunks = { + 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; }; }([]);" `; diff --git a/test/fixtures/inline-optimization.js b/test/fixtures/inline-optimization.js new file mode 100644 index 00000000..a568ae98 --- /dev/null +++ b/test/fixtures/inline-optimization.js @@ -0,0 +1,23 @@ +/** + * @author Toru Nagashima + * See LICENSE file in root directory for full license. + */ +"use strict" + +function isUnusedDisableDirectiveError(message) { + return ( + !message.fatal && + !message.ruleId && + message.message.includes("eslint-disable") + ) +} + +module.exports = (messages) => { + for (let i = messages.length - 1; i >= 0; --i) { + const message = messages[i] + if (!isUnusedDisableDirectiveError(message)) { + continue + } + console.log(message) + } +} diff --git a/test/uglify-options.test.js b/test/uglify-options.test.js index d48a7ea3..bdc7d2ca 100644 --- a/test/uglify-options.test.js +++ b/test/uglify-options.test.js @@ -185,4 +185,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); + } + } + }); + }); });